fix changes

This commit is contained in:
Mikhail 2023-04-20 19:23:58 +08:00
parent b8fb3011b0
commit df833a5b39
5 changed files with 28 additions and 19 deletions

View File

@ -4,7 +4,7 @@ namespace DCFApixels.DragonECS
{
public class EcsComponentMask
{
internal Type WorldArchetypeType;
internal Type WorldArchetype;
internal int[] Inc;
internal int[] Exc;
public override string ToString()

View File

@ -15,7 +15,7 @@ namespace DCFApixels.DragonECS
#region Methods
public void Add(int entityID);
public void Write(int entityID);
public void Write(int entityID, object data);
public bool Has(int entityID);
public void Del(int entityID);
#endregion
@ -27,10 +27,9 @@ namespace DCFApixels.DragonECS
public interface IEcsPool<T> : IEcsPool where T : struct
{
public new ref T Add(int entityID);
public ref T Read(int entityID);
public new ref T Write(int entityID);
}
public ref T Write(int entityID);
}
public struct NullComponent { }
public sealed class EcsNullPool : IEcsPool<NullComponent>
{
@ -53,7 +52,7 @@ namespace DCFApixels.DragonECS
public ref NullComponent Read(int entity) => ref fakeComponent;
public ref NullComponent Write(int entity) => ref fakeComponent;
public void Del(int index) { }
void IEcsPool.Write(int entityID) { }
void IEcsPool.Write(int entityID, object data) { }
void IEcsPool.Add(int entityID) { }
void IEcsPool.OnWorldResize(int newSize) { }
#endregion
@ -169,9 +168,9 @@ namespace DCFApixels.DragonECS
#endregion
#region IEcsPool
void IEcsPool.Write(int entityID)
void IEcsPool.Write(int entityID, object data)
{
Write(entityID);
Write(entityID) = (T)data;
}
void IEcsPool.Add(int entityID)
{

View File

@ -69,7 +69,7 @@ namespace DCFApixels.DragonECS
{
_inc.Sort();
_exc.Sort();
mask = new EcsQueryMask(_world.ArchetypeType, _inc.ToArray(), _exc.ToArray());
mask = new EcsQueryMask(_world.Archetype, _inc.ToArray(), _exc.ToArray());
_world = null;
_inc = null;
_exc = null;
@ -148,7 +148,7 @@ namespace DCFApixels.DragonECS
{
public EcsQueryMask(Type worldArchetypeType, int[] inc, int[] exc)
{
WorldArchetypeType = worldArchetypeType;
WorldArchetype = worldArchetypeType;
Inc = inc;
Exc = exc;
}

View File

@ -38,7 +38,7 @@ namespace DCFApixels.DragonECS
_worldIdDispenser.Release(uniqueID);
}
}
public abstract class EcsWorld<TWorldArchetype> : EcsWorld, IEcsWorld
where TWorldArchetype : EcsWorld<TWorldArchetype>
{
@ -73,12 +73,12 @@ namespace DCFApixels.DragonECS
#region GetterMethods
public ReadOnlySpan<IEcsPool> GetAllPools() => new ReadOnlySpan<IEcsPool>(_pools);
public int GetComponentID<T>() => WorldMetaStorage.GetComponentId<T>(_worldArchetypeID);////ComponentType<T>.uniqueID;
public int GetComponentID<T>() => WorldMetaStorage.GetComponentId<T>(_worldArchetypeID);////ComponentType<TWorldArchetype>.uniqueID;
#endregion
#region Properties
public Type ArchetypeType => typeof(TWorldArchetype);
public Type Archetype => typeof(TWorldArchetype);
public int UniqueID => uniqueID;
public int Count => _entitiesCount;
public int Capacity => _entitesCapacity; //_denseEntities.Length;
@ -109,15 +109,13 @@ namespace DCFApixels.DragonECS
_poolRunners = new PoolRunners(_pipeline);
_entityCreate = _pipeline.GetRunner<IEcsEntityCreate>();
_entityDestry = _pipeline.GetRunner<IEcsEntityDestroy>();
_pipeline.GetRunner<IEcsInject<TWorldArchetype>>().Inject((TWorldArchetype)this);
_pipeline.GetRunner<IEcsInject<IEcsWorld>>().Inject(this);
_pipeline.GetRunner<IEcsWorldCreate>().OnWorldCreate(this);
}
#endregion
#region GetPool
public EcsPool<TComponent> GetPool<TComponent>()
where TComponent : struct
public EcsPool<TComponent> GetPool<TComponent>() where TComponent : struct
{
int uniqueID = WorldMetaStorage.GetComponentId<TComponent>(_worldArchetypeID);
@ -157,7 +155,7 @@ namespace DCFApixels.DragonECS
public bool IsMaskCompatible(EcsComponentMask mask, int entityID)
{
#if (DEBUG && !DISABLE_DRAGONECS_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS
if (mask.WorldArchetypeType != typeof(TWorldArchetype))
if (mask.WorldArchetype != Archetype)
throw new EcsFrameworkException("mask.WorldArchetypeType != typeof(TTableArhetype)");
#endif
for (int i = 0, iMax = mask.Inc.Length; i < iMax; i++)
@ -301,9 +299,11 @@ namespace DCFApixels.DragonECS
private static int[] componentCounts = new int[0];
private static int[] queryCounts = new int[0];
private static Dictionary<Type, int> _worldIds = new Dictionary<Type, int>();
private static class WorldIndex<TWorldArchetype>
{
public static int id = GetToken();
public static int id = GetWorldId(typeof(TWorldArchetype));
}
private static int GetToken()
{
@ -315,6 +315,16 @@ namespace DCFApixels.DragonECS
return tokenCount - 1;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int GetWorldId(Type archetype)
{
if(_worldIds.TryGetValue(archetype, out int id) == false)
{
id = GetToken();
_worldIds.Add(archetype, id);
}
return id;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int GetWorldId<TWorldArchetype>() => WorldIndex<TWorldArchetype>.id;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int GetComponentId<T>(int worldID) => Component<T>.Get(worldID);

View File

@ -7,7 +7,7 @@ namespace DCFApixels.DragonECS
{
#region Properties
/// <summary>Table Archetype</summary>
public Type ArchetypeType { get; }
public Type Archetype { get; }
public int Count { get; }
public int Capacity { get; }
public EcsReadonlyGroup Entities => default;