From df833a5b3949b275cf41e8b74b46122d88b2128a Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Thu, 20 Apr 2023 19:23:58 +0800 Subject: [PATCH] fix changes --- src/EcsComponentMask.cs | 2 +- src/EcsPool.cs | 13 ++++++------- src/EcsQuery.cs | 4 ++-- src/EcsWorld.cs | 26 ++++++++++++++++++-------- src/Interfaces/IEcsTable.cs | 2 +- 5 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/EcsComponentMask.cs b/src/EcsComponentMask.cs index 91544a0..71ce604 100644 --- a/src/EcsComponentMask.cs +++ b/src/EcsComponentMask.cs @@ -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() diff --git a/src/EcsPool.cs b/src/EcsPool.cs index 4b2470c..c659e3e 100644 --- a/src/EcsPool.cs +++ b/src/EcsPool.cs @@ -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 : 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 { @@ -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) { diff --git a/src/EcsQuery.cs b/src/EcsQuery.cs index 30ae684..83cfa5d 100644 --- a/src/EcsQuery.cs +++ b/src/EcsQuery.cs @@ -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; } diff --git a/src/EcsWorld.cs b/src/EcsWorld.cs index 3056aa0..be97a7c 100644 --- a/src/EcsWorld.cs +++ b/src/EcsWorld.cs @@ -38,7 +38,7 @@ namespace DCFApixels.DragonECS _worldIdDispenser.Release(uniqueID); } } - + public abstract class EcsWorld : EcsWorld, IEcsWorld where TWorldArchetype : EcsWorld { @@ -73,12 +73,12 @@ namespace DCFApixels.DragonECS #region GetterMethods public ReadOnlySpan GetAllPools() => new ReadOnlySpan(_pools); - public int GetComponentID() => WorldMetaStorage.GetComponentId(_worldArchetypeID);////ComponentType.uniqueID; + public int GetComponentID() => WorldMetaStorage.GetComponentId(_worldArchetypeID);////ComponentType.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(); _entityDestry = _pipeline.GetRunner(); - _pipeline.GetRunner>().Inject((TWorldArchetype)this); _pipeline.GetRunner>().Inject(this); _pipeline.GetRunner().OnWorldCreate(this); } #endregion #region GetPool - public EcsPool GetPool() - where TComponent : struct + public EcsPool GetPool() where TComponent : struct { int uniqueID = WorldMetaStorage.GetComponentId(_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 _worldIds = new Dictionary(); + private static class WorldIndex { - 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() => WorldIndex.id; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int GetComponentId(int worldID) => Component.Get(worldID); diff --git a/src/Interfaces/IEcsTable.cs b/src/Interfaces/IEcsTable.cs index d2d9909..3842ab6 100644 --- a/src/Interfaces/IEcsTable.cs +++ b/src/Interfaces/IEcsTable.cs @@ -7,7 +7,7 @@ namespace DCFApixels.DragonECS { #region Properties /// Table Archetype - public Type ArchetypeType { get; } + public Type Archetype { get; } public int Count { get; } public int Capacity { get; } public EcsReadonlyGroup Entities => default;