mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 18:14:37 +08:00
fix changes
This commit is contained in:
parent
b8fb3011b0
commit
df833a5b39
@ -4,7 +4,7 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
public class EcsComponentMask
|
public class EcsComponentMask
|
||||||
{
|
{
|
||||||
internal Type WorldArchetypeType;
|
internal Type WorldArchetype;
|
||||||
internal int[] Inc;
|
internal int[] Inc;
|
||||||
internal int[] Exc;
|
internal int[] Exc;
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
|
@ -15,7 +15,7 @@ namespace DCFApixels.DragonECS
|
|||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
public void Add(int entityID);
|
public void Add(int entityID);
|
||||||
public void Write(int entityID);
|
public void Write(int entityID, object data);
|
||||||
public bool Has(int entityID);
|
public bool Has(int entityID);
|
||||||
public void Del(int entityID);
|
public void Del(int entityID);
|
||||||
#endregion
|
#endregion
|
||||||
@ -27,10 +27,9 @@ namespace DCFApixels.DragonECS
|
|||||||
public interface IEcsPool<T> : IEcsPool where T : struct
|
public interface IEcsPool<T> : IEcsPool where T : struct
|
||||||
{
|
{
|
||||||
public new ref T Add(int entityID);
|
public new ref T Add(int entityID);
|
||||||
public ref T Read(int entityID);
|
public ref T Write(int entityID);
|
||||||
public new ref T Write(int entityID);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
public struct NullComponent { }
|
public struct NullComponent { }
|
||||||
public sealed class EcsNullPool : IEcsPool<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 Read(int entity) => ref fakeComponent;
|
||||||
public ref NullComponent Write(int entity) => ref fakeComponent;
|
public ref NullComponent Write(int entity) => ref fakeComponent;
|
||||||
public void Del(int index) { }
|
public void Del(int index) { }
|
||||||
void IEcsPool.Write(int entityID) { }
|
void IEcsPool.Write(int entityID, object data) { }
|
||||||
void IEcsPool.Add(int entityID) { }
|
void IEcsPool.Add(int entityID) { }
|
||||||
void IEcsPool.OnWorldResize(int newSize) { }
|
void IEcsPool.OnWorldResize(int newSize) { }
|
||||||
#endregion
|
#endregion
|
||||||
@ -169,9 +168,9 @@ namespace DCFApixels.DragonECS
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region IEcsPool
|
#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)
|
void IEcsPool.Add(int entityID)
|
||||||
{
|
{
|
||||||
|
@ -69,7 +69,7 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
_inc.Sort();
|
_inc.Sort();
|
||||||
_exc.Sort();
|
_exc.Sort();
|
||||||
mask = new EcsQueryMask(_world.ArchetypeType, _inc.ToArray(), _exc.ToArray());
|
mask = new EcsQueryMask(_world.Archetype, _inc.ToArray(), _exc.ToArray());
|
||||||
_world = null;
|
_world = null;
|
||||||
_inc = null;
|
_inc = null;
|
||||||
_exc = null;
|
_exc = null;
|
||||||
@ -148,7 +148,7 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
public EcsQueryMask(Type worldArchetypeType, int[] inc, int[] exc)
|
public EcsQueryMask(Type worldArchetypeType, int[] inc, int[] exc)
|
||||||
{
|
{
|
||||||
WorldArchetypeType = worldArchetypeType;
|
WorldArchetype = worldArchetypeType;
|
||||||
Inc = inc;
|
Inc = inc;
|
||||||
Exc = exc;
|
Exc = exc;
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ namespace DCFApixels.DragonECS
|
|||||||
_worldIdDispenser.Release(uniqueID);
|
_worldIdDispenser.Release(uniqueID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class EcsWorld<TWorldArchetype> : EcsWorld, IEcsWorld
|
public abstract class EcsWorld<TWorldArchetype> : EcsWorld, IEcsWorld
|
||||||
where TWorldArchetype : EcsWorld<TWorldArchetype>
|
where TWorldArchetype : EcsWorld<TWorldArchetype>
|
||||||
{
|
{
|
||||||
@ -73,12 +73,12 @@ namespace DCFApixels.DragonECS
|
|||||||
|
|
||||||
#region GetterMethods
|
#region GetterMethods
|
||||||
public ReadOnlySpan<IEcsPool> GetAllPools() => new ReadOnlySpan<IEcsPool>(_pools);
|
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
|
#endregion
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
public Type ArchetypeType => typeof(TWorldArchetype);
|
public Type Archetype => typeof(TWorldArchetype);
|
||||||
public int UniqueID => uniqueID;
|
public int UniqueID => uniqueID;
|
||||||
public int Count => _entitiesCount;
|
public int Count => _entitiesCount;
|
||||||
public int Capacity => _entitesCapacity; //_denseEntities.Length;
|
public int Capacity => _entitesCapacity; //_denseEntities.Length;
|
||||||
@ -109,15 +109,13 @@ namespace DCFApixels.DragonECS
|
|||||||
_poolRunners = new PoolRunners(_pipeline);
|
_poolRunners = new PoolRunners(_pipeline);
|
||||||
_entityCreate = _pipeline.GetRunner<IEcsEntityCreate>();
|
_entityCreate = _pipeline.GetRunner<IEcsEntityCreate>();
|
||||||
_entityDestry = _pipeline.GetRunner<IEcsEntityDestroy>();
|
_entityDestry = _pipeline.GetRunner<IEcsEntityDestroy>();
|
||||||
_pipeline.GetRunner<IEcsInject<TWorldArchetype>>().Inject((TWorldArchetype)this);
|
|
||||||
_pipeline.GetRunner<IEcsInject<IEcsWorld>>().Inject(this);
|
_pipeline.GetRunner<IEcsInject<IEcsWorld>>().Inject(this);
|
||||||
_pipeline.GetRunner<IEcsWorldCreate>().OnWorldCreate(this);
|
_pipeline.GetRunner<IEcsWorldCreate>().OnWorldCreate(this);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region GetPool
|
#region GetPool
|
||||||
public EcsPool<TComponent> GetPool<TComponent>()
|
public EcsPool<TComponent> GetPool<TComponent>() where TComponent : struct
|
||||||
where TComponent : struct
|
|
||||||
{
|
{
|
||||||
int uniqueID = WorldMetaStorage.GetComponentId<TComponent>(_worldArchetypeID);
|
int uniqueID = WorldMetaStorage.GetComponentId<TComponent>(_worldArchetypeID);
|
||||||
|
|
||||||
@ -157,7 +155,7 @@ namespace DCFApixels.DragonECS
|
|||||||
public bool IsMaskCompatible(EcsComponentMask mask, int entityID)
|
public bool IsMaskCompatible(EcsComponentMask mask, int entityID)
|
||||||
{
|
{
|
||||||
#if (DEBUG && !DISABLE_DRAGONECS_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS
|
#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)");
|
throw new EcsFrameworkException("mask.WorldArchetypeType != typeof(TTableArhetype)");
|
||||||
#endif
|
#endif
|
||||||
for (int i = 0, iMax = mask.Inc.Length; i < iMax; i++)
|
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[] componentCounts = new int[0];
|
||||||
private static int[] queryCounts = 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>
|
private static class WorldIndex<TWorldArchetype>
|
||||||
{
|
{
|
||||||
public static int id = GetToken();
|
public static int id = GetWorldId(typeof(TWorldArchetype));
|
||||||
}
|
}
|
||||||
private static int GetToken()
|
private static int GetToken()
|
||||||
{
|
{
|
||||||
@ -315,6 +315,16 @@ namespace DCFApixels.DragonECS
|
|||||||
return tokenCount - 1;
|
return tokenCount - 1;
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[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;
|
public static int GetWorldId<TWorldArchetype>() => WorldIndex<TWorldArchetype>.id;
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static int GetComponentId<T>(int worldID) => Component<T>.Get(worldID);
|
public static int GetComponentId<T>(int worldID) => Component<T>.Get(worldID);
|
||||||
|
@ -7,7 +7,7 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
#region Properties
|
#region Properties
|
||||||
/// <summary>Table Archetype</summary>
|
/// <summary>Table Archetype</summary>
|
||||||
public Type ArchetypeType { get; }
|
public Type Archetype { get; }
|
||||||
public int Count { get; }
|
public int Count { get; }
|
||||||
public int Capacity { get; }
|
public int Capacity { get; }
|
||||||
public EcsReadonlyGroup Entities => default;
|
public EcsReadonlyGroup Entities => default;
|
||||||
|
Loading…
Reference in New Issue
Block a user