From f5654991382d7ff483ac9ac69d607fb24347fd09 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Tue, 30 May 2023 15:15:37 +0800 Subject: [PATCH 1/8] add world components --- src/EcsWorld.cs | 166 +++------------------------- src/Utils/WorldMetaStorage.cs | 198 ++++++++++++++++++++++++++++++++++ 2 files changed, 215 insertions(+), 149 deletions(-) create mode 100644 src/Utils/WorldMetaStorage.cs diff --git a/src/EcsWorld.cs b/src/EcsWorld.cs index 1227d6a..eb53348 100644 --- a/src/EcsWorld.cs +++ b/src/EcsWorld.cs @@ -40,6 +40,8 @@ namespace DCFApixels.DragonECS private List _listeners; + private object[] _components; + #region Properties public abstract Type Archetype { get; } public int UniqueID => uniqueID; @@ -85,6 +87,8 @@ namespace DCFApixels.DragonECS _subjects = new EcsSubject[128]; _executors = new EcsQueryExecutor[128]; + + _components = new object[0]; } public void Destroy() { @@ -99,6 +103,19 @@ namespace DCFApixels.DragonECS } #endregion + #region WorldComponent + public T Get() where T : class, new() + { + var result = _components[WorldMetaStorage.GetWorldComponentId(_worldTypeID)]; + if(result == null) + { + result = new T(); + _components[WorldMetaStorage.GetWorldComponentId(_worldTypeID)] = result; + } + return (T)result; + } + #endregion + #region ComponentInfo public int GetComponentID() => WorldMetaStorage.GetComponentId(_worldTypeID); public Type GetComponentType(int componentID) => WorldMetaStorage.GetComponentType(_worldTypeID, componentID); @@ -369,155 +386,6 @@ namespace DCFApixels.DragonECS internal EcsWorld(bool isIndexable) : base(isIndexable) { } } - #region WorldMetaStorage - internal static class WorldMetaStorage - { - private static List _resizer = new List(); - private static int _tokenCount = 0; - - private static WorldTypeMeta[] _metas = new WorldTypeMeta[0]; - private static Dictionary _worldIds = new Dictionary(); - private static class WorldIndex - { - public static int id = GetWorldID(typeof(TWorldArchetype)); - } - private static int GetToken() - { - WorldTypeMeta meta = new WorldTypeMeta(); - meta.id = _tokenCount; - Array.Resize(ref _metas, ++_tokenCount); - _metas[_tokenCount - 1] = meta; - - foreach (var item in _resizer) - item.Resize(_tokenCount); - return _tokenCount - 1; - } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int GetWorldID(Type archetype) - { - if(!_worldIds.TryGetValue(archetype, out int id)) - { - 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); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int GetSubjectId(int worldID) => Subject.Get(worldID); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int GetExecutorId(int worldID) => Executor.Get(worldID); - - public static bool IsComponentTypeDeclared(int worldID, Type type) => _metas[worldID].IsDeclaredType(type); - public static Type GetComponentType(int worldID, int componentID) => _metas[worldID].GetComponentType(componentID); - - #region Resizer - private abstract class Resizer - { - public abstract void Resize(int size); - } - private sealed class Resizer : Resizer - { - public override void Resize(int size) - { - Array.Resize(ref Component.ids, size); - Array.Resize(ref Subject.ids, size); - Array.Resize(ref Executor.ids, size); - } - } - #endregion - private static class Component - { - public static int[] ids; - static Component() - { - ids = new int[_tokenCount]; - for (int i = 0; i < ids.Length; i++) - ids[i] = -1; - _resizer.Add(new Resizer()); - } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Get(int token) - { - ref int id = ref ids[token]; - if (id < 0) - { - var meta = _metas[token]; - id = meta.componentCount++; - meta.AddType(id, typeof(T)); - } - return id; - } - } - private static class Subject - { - public static int[] ids; - static Subject() - { - ids = new int[_tokenCount]; - for (int i = 0; i < ids.Length; i++) - ids[i] = -1; - _resizer.Add(new Resizer()); - } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Get(int token) - { - ref int id = ref ids[token]; - if (id < 0) - id = _metas[token].subjectsCount++; - return id; - } - } - private static class Executor - { - public static int[] ids; - static Executor() - { - ids = new int[_tokenCount]; - for (int i = 0; i < ids.Length; i++) - ids[i] = -1; - _resizer.Add(new Resizer()); - } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Get(int token) - { - ref int id = ref ids[token]; - if (id < 0) - id = _metas[token].executorsCount++; - return id; - } - } - - private class WorldTypeMeta - { - public int id; - public int componentCount; - public int subjectsCount; - public int executorsCount; - private Type[] types; - private HashSet declaredComponentTypes; - public void AddType(int id, Type type) - { - if(types.Length <= id) - Array.Resize(ref types, id + 10); - types[id] = type; - - declaredComponentTypes.Add(type); - } - public Type GetComponentType(int componentID) => types[componentID]; - public bool IsDeclaredType(Type type) => declaredComponentTypes.Contains(type); - public WorldTypeMeta() - { - types = new Type[10]; - declaredComponentTypes = new HashSet(); - } - } - } - #endregion - #region Callbacks Interface public interface IEcsWorldEventListener { diff --git a/src/Utils/WorldMetaStorage.cs b/src/Utils/WorldMetaStorage.cs new file mode 100644 index 0000000..7a460d3 --- /dev/null +++ b/src/Utils/WorldMetaStorage.cs @@ -0,0 +1,198 @@ +using DCFApixels.DragonECS.Utils; +using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace DCFApixels.DragonECS +{ + internal static class WorldMetaStorage + { + private static int _tokenCount = 0; + private static List _resizers = new List(); + private static WorldTypeMeta[] _metas = new WorldTypeMeta[0]; + private static Dictionary _worldIds = new Dictionary(); + private static class WorldIndex + { + public static int id = GetWorldID(typeof(TWorldArchetype)); + } + private static int GetToken() + { + WorldTypeMeta meta = new WorldTypeMeta(); + meta.id = _tokenCount; + Array.Resize(ref _metas, ++_tokenCount); + _metas[_tokenCount - 1] = meta; + + foreach (var item in _resizers) + item.Resize(_tokenCount); + return _tokenCount - 1; + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int GetWorldID(Type archetype) + { + if (!_worldIds.TryGetValue(archetype, out int id)) + { + 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); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int GetSubjectId(int worldID) => Subject.Get(worldID); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int GetExecutorId(int worldID) => Executor.Get(worldID); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int GetWorldComponentId(int worldID) => WorldComponent.Get(worldID); + public static bool IsComponentTypeDeclared(int worldID, Type type) => _metas[worldID].IsDeclaredType(type); + public static Type GetComponentType(int worldID, int componentID) => _metas[worldID].GetComponentType(componentID); + + private abstract class ResizerBase + { + public abstract void Resize(int size); + } + private static class Component + { + public static int[] ids; + static Component() + { + ids = new int[_tokenCount]; + for (int i = 0; i < ids.Length; i++) + ids[i] = -1; + _resizers.Add(new Resizer()); + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Get(int token) + { + ref int id = ref ids[token]; + if (id < 0) + { + var meta = _metas[token]; + id = (ushort)meta.componentCount++; + meta.AddType(id, typeof(T)); + } + return id; + } + private sealed class Resizer : ResizerBase + { + public override void Resize(int size) + { + int oldSize = ids.Length; + Array.Resize(ref ids, size); + ArrayUtility.Fill(ids, -1, oldSize, size); + } + } + } + private static class Subject + { + public static int[] ids; + static Subject() + { + ids = new int[_tokenCount]; + for (int i = 0; i < ids.Length; i++) + ids[i] = -1; + _resizers.Add(new Resizer()); + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Get(int token) + { + ref int id = ref ids[token]; + if (id < 0) + id = _metas[token].subjectsCount++; + return id; + } + private sealed class Resizer : ResizerBase + { + public override void Resize(int size) + { + int oldSize = ids.Length; + Array.Resize(ref ids, size); + ArrayUtility.Fill(ids, -1, oldSize, size); + } + } + } + private static class Executor + { + public static int[] ids; + static Executor() + { + ids = new int[_tokenCount]; + for (int i = 0; i < ids.Length; i++) + ids[i] = -1; + _resizers.Add(new Resizer()); + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Get(int token) + { + ref int id = ref ids[token]; + if (id < 0) + id = _metas[token].executorsCount++; + return id; + } + private sealed class Resizer : ResizerBase + { + public override void Resize(int size) + { + int oldSize = ids.Length; + Array.Resize(ref ids, size); + ArrayUtility.Fill(ids, -1, oldSize, size); + } + } + } + private static class WorldComponent + { + public static int[] ids; + static WorldComponent() + { + ids = new int[_tokenCount]; + for (int i = 0; i < ids.Length; i++) + ids[i] = -1; + _resizers.Add(new Resizer()); + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Get(int token) + { + ref int id = ref ids[token]; + if (id < 0) + id = _metas[token].worldComponentCount++; + return id; + } + private sealed class Resizer : ResizerBase + { + public override void Resize(int size) + { + int oldSize = ids.Length; + Array.Resize(ref ids, size); + ArrayUtility.Fill(ids, -1, oldSize, size); + } + } + } + private class WorldTypeMeta + { + public int id; + public int componentCount; + public int subjectsCount; + public int executorsCount; + public int worldComponentCount; + private Type[] _types; + private HashSet _declaredComponentTypes; + public void AddType(int id, Type type) + { + if (_types.Length <= id) + Array.Resize(ref _types, id + 10); + _types[id] = type; + + _declaredComponentTypes.Add(type); + } + public Type GetComponentType(int componentID) => _types[componentID]; + public bool IsDeclaredType(Type type) => _declaredComponentTypes.Contains(type); + public WorldTypeMeta() + { + _types = new Type[10]; + _declaredComponentTypes = new HashSet(); + } + } + } +} From b73101d18c014990db342b1797f8e8b9a5984622 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Tue, 30 May 2023 15:20:27 +0800 Subject: [PATCH 2/8] fix --- src/EcsWorld.cs | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/EcsWorld.cs b/src/EcsWorld.cs index eb53348..60aa869 100644 --- a/src/EcsWorld.cs +++ b/src/EcsWorld.cs @@ -88,7 +88,7 @@ namespace DCFApixels.DragonECS _subjects = new EcsSubject[128]; _executors = new EcsQueryExecutor[128]; - _components = new object[0]; + _components = new object[2]; } public void Destroy() { @@ -103,19 +103,6 @@ namespace DCFApixels.DragonECS } #endregion - #region WorldComponent - public T Get() where T : class, new() - { - var result = _components[WorldMetaStorage.GetWorldComponentId(_worldTypeID)]; - if(result == null) - { - result = new T(); - _components[WorldMetaStorage.GetWorldComponentId(_worldTypeID)] = result; - } - return (T)result; - } - #endregion - #region ComponentInfo public int GetComponentID() => WorldMetaStorage.GetComponentId(_worldTypeID); public Type GetComponentType(int componentID) => WorldMetaStorage.GetComponentType(_worldTypeID, componentID); @@ -155,16 +142,30 @@ namespace DCFApixels.DragonECS } public TExecutor GetExecutor() where TExecutor : EcsQueryExecutor, new() { - int id = WorldMetaStorage.GetExecutorId(_worldTypeID); - if (id >= _executors.Length) + int index = WorldMetaStorage.GetExecutorId(_worldTypeID); + if (index >= _executors.Length) Array.Resize(ref _executors, _executors.Length << 1); - if (_executors[id] == null) + if (_executors[index] == null) { var executor = new TExecutor(); executor.Initialize(this); - _executors[id] = executor; + _executors[index] = executor; } - return (TExecutor)_executors[id]; + return (TExecutor)_executors[index]; + } + public T Get() where T : class, new() + { + int index = WorldMetaStorage.GetWorldComponentId(_worldTypeID); + if (index >= _components.Length) + Array.Resize(ref _executors, _executors.Length << 1); + + var result = _components[index]; + if (result == null) + { + result = new T(); + _components[index] = result; + } + return (T)result; } #endregion From 8dc8236f7e4ced97fe9f57ca043e4815ef4db178 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Tue, 30 May 2023 16:01:16 +0800 Subject: [PATCH 3/8] rename write methods to get --- src/Pools/EcsPool.cs | 18 +++++++++--------- src/Pools/EcsPoolBase.cs | 16 ++++++++-------- src/Pools/EcsTagPool.cs | 2 +- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Pools/EcsPool.cs b/src/Pools/EcsPool.cs index 2fff699..0cc1082 100644 --- a/src/Pools/EcsPool.cs +++ b/src/Pools/EcsPool.cs @@ -74,18 +74,18 @@ namespace DCFApixels.DragonECS Array.Resize(ref _items, _items.Length << 1); } this.IncrementEntityComponentCount(entityID); - _listeners.InvokeOnAddAndWrite(entityID); + _listeners.InvokeOnAddAndGet(entityID); return ref _items[itemIndex]; // } } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ref T Write(int entityID) + public ref T Get(int entityID) { // using (_writeMark.Auto()) #if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS if (!Has(entityID)) ThrowNotHaveComponent(entityID); #endif - _listeners.InvokeOnWrite(entityID); + _listeners.InvokeOnGet(entityID); return ref _items[_mapping[entityID]]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -97,7 +97,7 @@ namespace DCFApixels.DragonECS #endif return ref _items[_mapping[entityID]]; } - public ref T TryAddOrWrite(int entityID) + public ref T TryAddOrGet(int entityID) { ref int itemIndex = ref _mapping[entityID]; if (itemIndex <= 0) @@ -116,7 +116,7 @@ namespace DCFApixels.DragonECS this.IncrementEntityComponentCount(entityID); _listeners.InvokeOnAdd(entityID); } - _listeners.InvokeOnWrite(entityID); + _listeners.InvokeOnGet(entityID); return ref _items[itemIndex]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -148,14 +148,14 @@ namespace DCFApixels.DragonECS #if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS if (!Has(fromEntityID)) ThrowNotHaveComponent(fromEntityID); #endif - _componentCopyHandler.Copy(ref Write(fromEntityID), ref TryAddOrWrite(toEntityID)); + _componentCopyHandler.Copy(ref Get(fromEntityID), ref TryAddOrGet(toEntityID)); } public void Copy(int fromEntityID, EcsWorld toWorld, int toEntityID) { #if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS if (!Has(fromEntityID)) ThrowNotHaveComponent(fromEntityID); #endif - _componentCopyHandler.Copy(ref Write(fromEntityID), ref toWorld.GetPool().TryAddOrWrite(toEntityID)); + _componentCopyHandler.Copy(ref Get(fromEntityID), ref toWorld.GetPool().TryAddOrGet(toEntityID)); } #endregion @@ -175,9 +175,9 @@ namespace DCFApixels.DragonECS #region Other void IEcsPool.AddRaw(int entityID, object dataRaw) => Add(entityID) = (T)dataRaw; object IEcsPool.GetRaw(int entityID) => Read(entityID); - void IEcsPool.SetRaw(int entityID, object dataRaw) => Write(entityID) = (T)dataRaw; + void IEcsPool.SetRaw(int entityID, object dataRaw) => Get(entityID) = (T)dataRaw; ref readonly T IEcsPool.Read(int entityID) => ref Read(entityID); - ref T IEcsPool.Write(int entityID) => ref Write(entityID); + ref T IEcsPool.Get(int entityID) => ref Get(entityID); #endregion #region Listeners diff --git a/src/Pools/EcsPoolBase.cs b/src/Pools/EcsPoolBase.cs index 155a477..5dfe6c6 100644 --- a/src/Pools/EcsPoolBase.cs +++ b/src/Pools/EcsPoolBase.cs @@ -35,7 +35,7 @@ namespace DCFApixels.DragonECS { ref T Add(int entityID); ref readonly T Read(int entityID); - ref T Write(int entityID); + ref T Get(int entityID); } /// Only used to implement a custom pool. In other contexts use IEcsPool or IEcsPool. public interface IEcsPoolImplementation : IEcsPool @@ -106,7 +106,7 @@ namespace DCFApixels.DragonECS void IEcsPool.Copy(int fromEntityID, EcsWorld toWorld, int toEntityID) => throw new NotImplementedException(); ref NullComponent IEcsPool.Add(int entityID) => throw new NotImplementedException(); ref readonly NullComponent IEcsPool.Read(int entityID) => throw new NotImplementedException(); - ref NullComponent IEcsPool.Write(int entityID) => throw new NotImplementedException(); + ref NullComponent IEcsPool.Get(int entityID) => throw new NotImplementedException(); #endregion #region Callbacks @@ -203,8 +203,8 @@ namespace DCFApixels.DragonECS { /// Called after adding an entity to the pool, but before changing values. void OnAdd(int entityID); - /// Is called when EcsPool.Write or EcsPool.Add is called, but before changing values. - void OnWrite(int entityID); + /// Is called when EcsPool.Get or EcsPool.Add is called, but before changing values. + void OnGet(int entityID); /// Called after deleting an entity from the pool void OnDel(int entityID); } @@ -216,18 +216,18 @@ namespace DCFApixels.DragonECS for (int i = 0, iMax = self.Count; i < iMax; i++) self[i].OnAdd(entityID); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void InvokeOnAddAndWrite(this List self, int entityID) + public static void InvokeOnAddAndGet(this List self, int entityID) { for (int i = 0, iMax = self.Count; i < iMax; i++) { self[i].OnAdd(entityID); - self[i].OnWrite(entityID); + self[i].OnGet(entityID); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void InvokeOnWrite(this List self, int entityID) + public static void InvokeOnGet(this List self, int entityID) { - for (int i = 0, iMax = self.Count; i < iMax; i++) self[i].OnWrite(entityID); + for (int i = 0, iMax = self.Count; i < iMax; i++) self[i].OnGet(entityID); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void InvokeOnDel(this List self, int entityID) diff --git a/src/Pools/EcsTagPool.cs b/src/Pools/EcsTagPool.cs index 75a670b..7d5708e 100644 --- a/src/Pools/EcsTagPool.cs +++ b/src/Pools/EcsTagPool.cs @@ -143,7 +143,7 @@ namespace DCFApixels.DragonECS #endif return ref _fakeComponent; } - ref T IEcsPool.Write(int entityID) + ref T IEcsPool.Get(int entityID) { #if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS if (!Has(entityID)) ThrowNotHaveComponent(entityID); From dd562986f03cb91b7a9d6fd4e7e594a5f393b27e Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Tue, 30 May 2023 16:07:45 +0800 Subject: [PATCH 4/8] remove useless --- src/Pools/EcsPool.cs | 5 -- src/Pools/EcsPoolBase.cs | 4 +- src/Utils/EntityLinkedList.cs | 132 ---------------------------------- 3 files changed, 2 insertions(+), 139 deletions(-) delete mode 100644 src/Utils/EntityLinkedList.cs diff --git a/src/Pools/EcsPool.cs b/src/Pools/EcsPool.cs index 0cc1082..bf3dfac 100644 --- a/src/Pools/EcsPool.cs +++ b/src/Pools/EcsPool.cs @@ -56,8 +56,6 @@ namespace DCFApixels.DragonECS #region Methods public ref T Add(int entityID) { - // using (_addMark.Auto()) - // { ref int itemIndex = ref _mapping[entityID]; #if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS if (itemIndex > 0) ThrowAlreadyHasComponent(entityID); @@ -76,12 +74,10 @@ namespace DCFApixels.DragonECS this.IncrementEntityComponentCount(entityID); _listeners.InvokeOnAddAndGet(entityID); return ref _items[itemIndex]; - // } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public ref T Get(int entityID) { - // using (_writeMark.Auto()) #if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS if (!Has(entityID)) ThrowNotHaveComponent(entityID); #endif @@ -91,7 +87,6 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] public ref readonly T Read(int entityID) { - // using (_readMark.Auto()) #if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS if (!Has(entityID)) ThrowNotHaveComponent(entityID); #endif diff --git a/src/Pools/EcsPoolBase.cs b/src/Pools/EcsPoolBase.cs index 5dfe6c6..853226f 100644 --- a/src/Pools/EcsPoolBase.cs +++ b/src/Pools/EcsPoolBase.cs @@ -201,9 +201,9 @@ namespace DCFApixels.DragonECS #region Callbacks Interface public interface IEcsPoolEventListener { - /// Called after adding an entity to the pool, but before changing values. + /// Called after adding an entity to the pool, but before changing values void OnAdd(int entityID); - /// Is called when EcsPool.Get or EcsPool.Add is called, but before changing values. + /// Is called when EcsPool.Get or EcsPool.Add is called, but before changing values void OnGet(int entityID); /// Called after deleting an entity from the pool void OnDel(int entityID); diff --git a/src/Utils/EntityLinkedList.cs b/src/Utils/EntityLinkedList.cs deleted file mode 100644 index bafe85f..0000000 --- a/src/Utils/EntityLinkedList.cs +++ /dev/null @@ -1,132 +0,0 @@ -using System; -using System.Runtime.InteropServices; - -namespace DCFApixels.DragonECS -{ - public class EntityLinkedList - { - private const int ENTER = 0; - - private Node[] _nodes; - private int _count; - private int _lastNodeIndex; - - #region Properties - public int Count => _count; - public int Capacity => _nodes.Length; - public int Last => _lastNodeIndex; - #endregion - - #region Constructors - public EntityLinkedList(int capacity) - { - _nodes = new Node[capacity + 10]; - Clear(); - } - #endregion - - public void Resize(int newCapacity) - { - Array.Resize(ref _nodes, newCapacity + 10); - } - - public void Clear() - { - //ArrayUtility.Fill(_nodes, Node.Empty); - for (int i = 0; i < _nodes.Length; i++) - _nodes[i].next = 0; - _lastNodeIndex = ENTER; - _count = 0; - } - - public void Set(int nodeIndex, int entityID) => _nodes[nodeIndex].entityID = entityID; - public int Get(int nodeIndex) => _nodes[nodeIndex].entityID; - - /// Insert after - /// new node index - public int Insert(int nodeIndex, int entityID) - { - _nodes[++_count].Set(entityID, _nodes[nodeIndex].next); - _nodes[nodeIndex].next = _count; - _lastNodeIndex = _count; - return _count; - } - - public int Add(int entityID) => Insert(_lastNodeIndex, entityID); - - public Enumerator GetEnumerator() => new Enumerator(_nodes); - public EnumerableSpan Span(int startNodeIndex, int count) => new EnumerableSpan(this, startNodeIndex, count); - - #region Utils - [StructLayout(LayoutKind.Sequential, Pack = 4, Size = 8)] - public struct Node - { - public static readonly Node Empty = new Node() { entityID = 0, next = -1 }; - public int entityID; - /// next node index - public int next; - - public void Set(int entityID, int next) - { - this.entityID = entityID; - this.next = next; - } - } - - public struct Enumerator - { - private readonly Node[] _nodes; - private int _index; - private int _next; - public Enumerator(Node[] nodes) - { - _nodes = nodes; - _index = -1; - _next = ENTER; - } - public int Current => _nodes[_index].entityID; - public bool MoveNext() - { - _index = _next; - _next = _nodes[_next].next; - return _index > 0; - } - } - - public readonly ref struct EnumerableSpan - { - private readonly EntityLinkedList _source; - private readonly int _startNodeIndex; - private readonly int _count; - public EnumerableSpan(EntityLinkedList source, int startNodeIndex, int count) - { - _source = source; - _startNodeIndex = startNodeIndex; - _count = count; - } - public SpanEnumerator GetEnumerator() => new SpanEnumerator(_source._nodes, _startNodeIndex, _count); - } - public struct SpanEnumerator - { - private readonly Node[] _nodes; - private int _index; - private int _count; - private int _next; - public SpanEnumerator(Node[] nodes, int startIndex, int count) - { - _nodes = nodes; - _index = -1; - _count = count; - _next = startIndex; - } - public int Current => _nodes[_index].entityID; - public bool MoveNext() - { - _index = _next; - _next = _nodes[_next].next; - return _index > 0 && _count-- > 0; - } - } - #endregion - } -} From 9d35096f097f3135a68c0e5ea6ff99c4ef47a22c Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Tue, 30 May 2023 17:56:53 +0800 Subject: [PATCH 5/8] rename ImportSystems method to Import --- src/EcsPipeline.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/EcsPipeline.cs b/src/EcsPipeline.cs index c9e9c47..39cdc8d 100644 --- a/src/EcsPipeline.cs +++ b/src/EcsPipeline.cs @@ -179,7 +179,7 @@ namespace DCFApixels.DragonECS } public Builder AddModule(IEcsModule module) { - module.ImportSystems(this); + module.Import(this); return this; } public EcsPipeline Build() @@ -308,7 +308,7 @@ namespace DCFApixels.DragonECS public interface IEcsModule { - void ImportSystems(EcsPipeline.Builder b); + void Import(EcsPipeline.Builder b); } #region Extensions From 5661d1e6d93f9a01f8cda0d284ed75f7f3a10e77 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Tue, 30 May 2023 18:27:30 +0800 Subject: [PATCH 6/8] rename IEcsSystem to IEcsProcess --- src/Builtin/BaseProcesses.cs | 8 ++++---- src/Builtin/InjectSystem.cs | 6 +++--- src/Builtin/Systems.cs | 2 +- src/EcsPipeline.cs | 34 +++++++++++++++++----------------- src/EcsRunner.cs | 24 ++++++++++++------------ 5 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/Builtin/BaseProcesses.cs b/src/Builtin/BaseProcesses.cs index 76ac5db..a84d757 100644 --- a/src/Builtin/BaseProcesses.cs +++ b/src/Builtin/BaseProcesses.cs @@ -3,19 +3,19 @@ namespace DCFApixels.DragonECS { #region Interfaces - public interface IEcsPreInitProcess : IEcsSystem + public interface IEcsPreInitProcess : IEcsProcess { void PreInit(EcsPipeline pipeline); } - public interface IEcsInitProcess : IEcsSystem + public interface IEcsInitProcess : IEcsProcess { void Init(EcsPipeline pipeline); } - public interface IEcsRunProcess : IEcsSystem + public interface IEcsRunProcess : IEcsProcess { void Run(EcsPipeline pipeline); } - public interface IEcsDestroyProcess : IEcsSystem + public interface IEcsDestroyProcess : IEcsProcess { void Destroy(EcsPipeline pipeline); } diff --git a/src/Builtin/InjectSystem.cs b/src/Builtin/InjectSystem.cs index 856670b..88654f2 100644 --- a/src/Builtin/InjectSystem.cs +++ b/src/Builtin/InjectSystem.cs @@ -5,15 +5,15 @@ using System.Linq; namespace DCFApixels.DragonECS { - public interface IEcsPreInject : IEcsSystem + public interface IEcsPreInject : IEcsProcess { void PreInject(object obj); } - public interface IEcsInject : IEcsSystem + public interface IEcsInject : IEcsProcess { void Inject(T obj); } - public interface IEcsPreInitInjectProcess : IEcsSystem + public interface IEcsPreInitInjectProcess : IEcsProcess { void OnPreInitInjectionBefore(); void OnPreInitInjectionAfter(); diff --git a/src/Builtin/Systems.cs b/src/Builtin/Systems.cs index c4eab58..1d6bc1e 100644 --- a/src/Builtin/Systems.cs +++ b/src/Builtin/Systems.cs @@ -6,7 +6,7 @@ namespace DCFApixels.DragonECS namespace Internal { [DebugHide, DebugColor(DebugColor.Black)] - public class SystemsLayerMarkerSystem : IEcsSystem + public class SystemsLayerMarkerSystem : IEcsProcess { public readonly string name; public SystemsLayerMarkerSystem(string name) => this.name = name; diff --git a/src/EcsPipeline.cs b/src/EcsPipeline.cs index 39cdc8d..e160021 100644 --- a/src/EcsPipeline.cs +++ b/src/EcsPipeline.cs @@ -11,30 +11,30 @@ namespace DCFApixels.DragonECS { public sealed class EcsPipeline { - private IEcsSystem[] _allSystems; + private IEcsProcess[] _allSystems; private Dictionary _runners; private IEcsRunProcess _runRunnerCache; - private ReadOnlyCollection _allSystemsSealed; + private ReadOnlyCollection _allSystemsSealed; private ReadOnlyDictionary _allRunnersSealed; private bool _isInit; private bool _isDestoryed; #region Properties - public ReadOnlyCollection AllSystems => _allSystemsSealed; + public ReadOnlyCollection AllSystems => _allSystemsSealed; public ReadOnlyDictionary AllRunners => _allRunnersSealed; public bool IsInit => _isInit; public bool IsDestoryed => _isDestoryed; #endregion #region Constructors - private EcsPipeline(IEcsSystem[] systems) + private EcsPipeline(IEcsProcess[] systems) { _allSystems = systems; _runners = new Dictionary(); - _allSystemsSealed = new ReadOnlyCollection(_allSystems); + _allSystemsSealed = new ReadOnlyCollection(_allSystems); _allRunnersSealed = new ReadOnlyDictionary(_runners); _isInit = false; @@ -43,7 +43,7 @@ namespace DCFApixels.DragonECS #endregion #region Runners - public T GetRunner() where T : IEcsSystem + public T GetRunner() where T : IEcsProcess { Type type = typeof(T); if (_runners.TryGetValue(type, out IEcsRunner result)) @@ -132,7 +132,7 @@ namespace DCFApixels.DragonECS { private const int KEYS_CAPACITY = 4; private HashSet _uniqueTypes; - private readonly Dictionary> _systems; + private readonly Dictionary> _systems; private readonly string _basicLayer; public readonly LayerList Layers; public Builder() @@ -142,14 +142,14 @@ namespace DCFApixels.DragonECS Layers.Insert(EcsConsts.BASIC_LAYER, EcsConsts.PRE_BEGIN_LAYER, EcsConsts.BEGIN_LAYER); Layers.InsertAfter(EcsConsts.BASIC_LAYER, EcsConsts.END_LAYER, EcsConsts.POST_END_LAYER); _uniqueTypes = new HashSet(); - _systems = new Dictionary>(KEYS_CAPACITY); + _systems = new Dictionary>(KEYS_CAPACITY); } - public Builder Add(IEcsSystem system, string layerName = null) + public Builder Add(IEcsProcess system, string layerName = null) { AddInternal(system, layerName, false); return this; } - public Builder AddUnique(IEcsSystem system, string layerName = null) + public Builder AddUnique(IEcsProcess system, string layerName = null) { AddInternal(system, layerName, true); return this; @@ -161,13 +161,13 @@ namespace DCFApixels.DragonECS list.RemoveAll(o => o is TSystem); return this; } - private void AddInternal(IEcsSystem system, string layerName, bool isUnique) + private void AddInternal(IEcsProcess system, string layerName, bool isUnique) { if (layerName == null) layerName = _basicLayer; - List list; + List list; if (!_systems.TryGetValue(layerName, out list)) { - list = new List { new SystemsLayerMarkerSystem(layerName.ToString()) }; + list = new List { new SystemsLayerMarkerSystem(layerName.ToString()) }; _systems.Add(layerName, list); } if ((_uniqueTypes.Add(system.GetType()) == false && isUnique)) @@ -185,8 +185,8 @@ namespace DCFApixels.DragonECS public EcsPipeline Build() { Add(new DeleteEmptyEntitesSystem(), EcsConsts.POST_END_LAYER); - List result = new List(32); - List basicBlockList = _systems[_basicLayer]; + List result = new List(32); + List basicBlockList = _systems[_basicLayer]; foreach (var item in _systems) { if (!Layers.Contains(item.Key)) @@ -315,12 +315,12 @@ namespace DCFApixels.DragonECS public static class EcsPipelineExtensions { public static bool IsNullOrDestroyed(this EcsPipeline self) => self == null || self.IsDestoryed; - public static EcsPipeline.Builder Add(this EcsPipeline.Builder self, IEnumerable range, string layerName = null) + public static EcsPipeline.Builder Add(this EcsPipeline.Builder self, IEnumerable range, string layerName = null) { foreach (var item in range) self.Add(item, layerName); return self; } - public static EcsPipeline.Builder AddUnique(this EcsPipeline.Builder self, IEnumerable range, string layerName = null) + public static EcsPipeline.Builder AddUnique(this EcsPipeline.Builder self, IEnumerable range, string layerName = null) { foreach (var item in range) self.AddUnique(item, layerName); return self; diff --git a/src/EcsRunner.cs b/src/EcsRunner.cs index 40fd715..b3b8b7f 100644 --- a/src/EcsRunner.cs +++ b/src/EcsRunner.cs @@ -23,7 +23,7 @@ namespace DCFApixels.DragonECS public EcsRunnerFilterAttribute(object filter) : this(null, filter) { } } - public interface IEcsSystem { } + public interface IEcsProcess { } namespace RunnersCore { @@ -103,7 +103,7 @@ namespace DCFApixels.DragonECS } [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static void InitFor() where TInterface : IEcsSystem + internal static void InitFor() where TInterface : IEcsProcess { Type interfaceType = typeof(TInterface); @@ -122,8 +122,8 @@ namespace DCFApixels.DragonECS #if UNITY_2020_3_OR_NEWER [UnityEngine.Scripting.RequireDerived, UnityEngine.Scripting.Preserve] #endif - public abstract class EcsRunner : IEcsSystem, IEcsRunner - where TInterface : IEcsSystem + public abstract class EcsRunner : IEcsProcess, IEcsRunner + where TInterface : IEcsProcess { #region Register private static Type _subclass; @@ -142,9 +142,9 @@ namespace DCFApixels.DragonECS { throw new ArgumentException($"{typeof(TInterface).FullName} is not interface"); } - if (interfaces.Length != 1 || interfaces[0] != typeof(IEcsSystem)) + if (interfaces.Length != 1 || interfaces[0] != typeof(IEcsProcess)) { - throw new ArgumentException($"{typeof(TInterface).FullName} does not directly inherit the {nameof(IEcsSystem)} interface"); + throw new ArgumentException($"{typeof(TInterface).FullName} does not directly inherit the {nameof(IEcsProcess)} interface"); } #endif _subclass = subclass; @@ -152,15 +152,15 @@ namespace DCFApixels.DragonECS #endregion #region FilterSystems - private static TInterface[] FilterSystems(IEnumerable targets) + private static TInterface[] FilterSystems(IEnumerable targets) { return targets.Where(o => o is TInterface).Select(o => (TInterface)o).ToArray(); } - private static TInterface[] FilterSystems(IEnumerable targets, object filter) + private static TInterface[] FilterSystems(IEnumerable targets, object filter) { Type interfaceType = typeof(TInterface); - IEnumerable newTargets; + IEnumerable newTargets; if (filter != null) { @@ -189,7 +189,7 @@ namespace DCFApixels.DragonECS { if (_subclass == null) EcsRunnerActivator.InitFor(); var instance = (EcsRunner)Activator.CreateInstance(_subclass); - return (TInterface)(IEcsSystem)instance.Set(source, targets, isHasFilter, filter); + return (TInterface)(IEcsProcess)instance.Set(source, targets, isHasFilter, filter); } public static TInterface Instantiate(EcsPipeline source) { @@ -253,11 +253,11 @@ namespace DCFApixels.DragonECS #region Extensions public static class EcsRunner { - public static void Destroy(IEcsSystem runner) => ((IEcsRunner)runner).Destroy(); + public static void Destroy(IEcsProcess runner) => ((IEcsRunner)runner).Destroy(); } public static class IEcsSystemExtensions { - public static bool IsRunner(this IEcsSystem self) + public static bool IsRunner(this IEcsProcess self) { return self is IEcsRunner; } From 33f1f03294a2e3a109ccf18ddf0dd8aae19c9ee2 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Tue, 30 May 2023 18:30:10 +0800 Subject: [PATCH 7/8] refactoring --- src/Builtin/Systems.cs | 2 +- src/Consts.cs | 2 +- src/Debug/Attributes/DebugColorAttribute.cs | 2 +- src/Debug/EcsDebug.cs | 4 ++-- src/EcsGroup.cs | 10 +++++----- src/EcsPipeline.cs | 4 ++-- src/EcsRunner.cs | 2 +- src/EcsWorld.cs | 4 ++-- src/Executors/EcsWhereExecutor.cs | 2 +- src/Pools/EcsPool.cs | 6 +++--- 10 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/Builtin/Systems.cs b/src/Builtin/Systems.cs index 1d6bc1e..4e6e95c 100644 --- a/src/Builtin/Systems.cs +++ b/src/Builtin/Systems.cs @@ -53,7 +53,7 @@ namespace DCFApixels.DragonECS public static EcsPipeline.Builder AutoDel(this EcsPipeline.Builder b, string layerName = AUTO_DEL_LAYER) where TComponent : struct, IEcsComponent { - if(AUTO_DEL_LAYER == layerName) + if (AUTO_DEL_LAYER == layerName) b.Layers.Insert(EcsConsts.POST_END_LAYER, AUTO_DEL_LAYER); b.AddUnique(new DeleteOneFrameComponentSystem(), layerName); return b; diff --git a/src/Consts.cs b/src/Consts.cs index b21827b..41bfb71 100644 --- a/src/Consts.cs +++ b/src/Consts.cs @@ -4,7 +4,7 @@ { public const string FRAMEWORK_NAME = "DragonECS"; - public const string EXCEPTION_MESSAGE_PREFIX = "["+ FRAMEWORK_NAME + "] "; + public const string EXCEPTION_MESSAGE_PREFIX = "[" + FRAMEWORK_NAME + "] "; public const string DEBUG_PREFIX = "[DEBUG] "; public const string DEBUG_WARNING_TAG = "WARNING"; public const string DEBUG_ERROR_TAG = "ERROR"; diff --git a/src/Debug/Attributes/DebugColorAttribute.cs b/src/Debug/Attributes/DebugColorAttribute.cs index 378a02b..4e9ebb7 100644 --- a/src/Debug/Attributes/DebugColorAttribute.cs +++ b/src/Debug/Attributes/DebugColorAttribute.cs @@ -69,7 +69,7 @@ namespace DCFApixels.DragonECS BlueViolet = (138 << 24) + (43 << 16) + (226 << 8), /// Yellow. RGB is (255, 3, 62) AmericanRose = (255 << 24) + (3 << 16) + (62 << 8), - + /// Grey/Gray. RGB is (127, 127, 127) Gray = (127 << 24) + (127 << 16) + (127 << 8), /// Grey/Gray. RGB is (127, 127, 127) diff --git a/src/Debug/EcsDebug.cs b/src/Debug/EcsDebug.cs index a2f8d2a..70bdf50 100644 --- a/src/Debug/EcsDebug.cs +++ b/src/Debug/EcsDebug.cs @@ -117,7 +117,7 @@ namespace DCFApixels.DragonECS public int RegisterMark(string name) { int id; - if(!_nameIdTable.TryGetValue(name, out id)) + if (!_nameIdTable.TryGetValue(name, out id)) { id = _idDispenser.GetFree(); _nameIdTable.Add(name, id); @@ -149,7 +149,7 @@ namespace DCFApixels.DragonECS { #if !DISABLE_DRAGONECS_DEBUGGER _stopwatchs = new Stopwatch[64]; - _stopwatchsNames= new string[64]; + _stopwatchsNames = new string[64]; #endif } public override void Print(string tag, object v) diff --git a/src/EcsGroup.cs b/src/EcsGroup.cs index 2f0ee31..53b4c67 100644 --- a/src/EcsGroup.cs +++ b/src/EcsGroup.cs @@ -242,7 +242,7 @@ namespace DCFApixels.DragonECS #if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS if (group.World != _source) throw new ArgumentException("groupFilter.WorldIndex != WorldIndex"); #endif - if(_count > 0) + if (_count > 0) Clear(); foreach (var item in group) AddInternal(item); @@ -371,14 +371,14 @@ namespace DCFApixels.DragonECS #region Enumerator public ref struct Enumerator// : IDisposable { - // private readonly EcsGroup source; + // private readonly EcsGroup source; private readonly int[] _dense; private readonly int _count; private int _index; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Enumerator(EcsGroup group) { - // source = group; + // source = group; _dense = group._dense; _count = group._count; _index = 0; @@ -389,7 +389,7 @@ namespace DCFApixels.DragonECS get => _dense[_index]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() => ++_index <= _count && _count<_dense.Length; // <= потму что отсчет начинается с индекса 1 //_count < _dense.Length дает среде понять что проверки на выход за границы не нужны + public bool MoveNext() => ++_index <= _count && _count < _dense.Length; // <= потму что отсчет начинается с индекса 1 //_count < _dense.Length дает среде понять что проверки на выход за границы не нужны //[MethodImpl(MethodImplOptions.AggressiveInlining)] //public void Dispose() => source.Unlock(); } @@ -410,7 +410,7 @@ namespace DCFApixels.DragonECS return false; return true; } - public override int GetHashCode() + public override int GetHashCode() { int hash = 0; foreach (var item in this) diff --git a/src/EcsPipeline.cs b/src/EcsPipeline.cs index e160021..52ee7db 100644 --- a/src/EcsPipeline.cs +++ b/src/EcsPipeline.cs @@ -194,7 +194,7 @@ namespace DCFApixels.DragonECS } foreach (var item in Layers) { - if(_systems.TryGetValue(item, out var list)) + if (_systems.TryGetValue(item, out var list)) result.AddRange(list); } return new EcsPipeline(result.ToArray()); @@ -211,7 +211,7 @@ namespace DCFApixels.DragonECS { _source = source; _layers = new List(16) { basicLayerName, ADD_LAYER }; - _basicLayerName = basicLayerName; + _basicLayerName = basicLayerName; } public Builder Add(string newLayer) => Insert(ADD_LAYER, newLayer); diff --git a/src/EcsRunner.cs b/src/EcsRunner.cs index b3b8b7f..9d634a4 100644 --- a/src/EcsRunner.cs +++ b/src/EcsRunner.cs @@ -122,7 +122,7 @@ namespace DCFApixels.DragonECS #if UNITY_2020_3_OR_NEWER [UnityEngine.Scripting.RequireDerived, UnityEngine.Scripting.Preserve] #endif - public abstract class EcsRunner : IEcsProcess, IEcsRunner + public abstract class EcsRunner : IEcsProcess, IEcsRunner where TInterface : IEcsProcess { #region Register diff --git a/src/EcsWorld.cs b/src/EcsWorld.cs index 60aa869..ef9ec9d 100644 --- a/src/EcsWorld.cs +++ b/src/EcsWorld.cs @@ -360,13 +360,13 @@ namespace DCFApixels.DragonECS { list.Clear(); var itemsCount = GetComponentsCount(entityID); - if (itemsCount == 0) + if (itemsCount == 0) return; for (var i = 0; i < _pools.Length; i++) { if (_pools[i].Has(entityID)) - list.Add(_pools[i].GetRaw(entityID)); + list.Add(_pools[i].GetRaw(entityID)); if (list.Count >= itemsCount) break; } diff --git a/src/Executors/EcsWhereExecutor.cs b/src/Executors/EcsWhereExecutor.cs index 4673825..37a614c 100644 --- a/src/Executors/EcsWhereExecutor.cs +++ b/src/Executors/EcsWhereExecutor.cs @@ -33,7 +33,7 @@ using (_executeWhere.Auto()) { #if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS - if (sourceGroup.IsNull) throw new System.ArgumentNullException();//TODO составить текст исключения. + if (sourceGroup.IsNull) throw new System.ArgumentNullException();//TODO составить текст исключения. #endif _subject.GetIteratorFor(sourceGroup).CopyTo(_filteredGroup); return new EcsWhereResult(this, _filteredGroup.Readonly); diff --git a/src/Pools/EcsPool.cs b/src/Pools/EcsPool.cs index bf3dfac..75cd0eb 100644 --- a/src/Pools/EcsPool.cs +++ b/src/Pools/EcsPool.cs @@ -36,7 +36,7 @@ namespace DCFApixels.DragonECS void IEcsPoolImplementation.OnInit(EcsWorld world, int componentID) { _source = world; - _id = componentID; + _id = componentID; const int capacity = 512; @@ -178,12 +178,12 @@ namespace DCFApixels.DragonECS #region Listeners public void AddListener(IEcsPoolEventListener listener) { - if(listener == null) { throw new ArgumentNullException("listener is null"); } + if (listener == null) { throw new ArgumentNullException("listener is null"); } _listeners.Add(listener); } public void RemoveListener(IEcsPoolEventListener listener) { - if(listener == null) { throw new ArgumentNullException("listener is null"); } + if (listener == null) { throw new ArgumentNullException("listener is null"); } _listeners.Remove(listener); } #endregion From 5f047a45078b3c18ff925a4d521a20b9085de7c7 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Wed, 31 May 2023 04:09:55 +0800 Subject: [PATCH 8/8] refactoring/update debug utility --- src/Builtin/InjectSystem.cs | 1 + src/Debug/EcsDebugUtility.cs | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/Builtin/InjectSystem.cs b/src/Builtin/InjectSystem.cs index 88654f2..c7fdf6a 100644 --- a/src/Builtin/InjectSystem.cs +++ b/src/Builtin/InjectSystem.cs @@ -129,6 +129,7 @@ namespace DCFApixels.DragonECS injectCallbacksRunner.OnPreInitInjectionAfter(); EcsRunner.Destroy(injectCallbacksRunner); } + _injectedData = default; } public void OnPreInitInjectionBefore() { } public void OnPreInitInjectionAfter() => _injectController = null; diff --git a/src/Debug/EcsDebugUtility.cs b/src/Debug/EcsDebugUtility.cs index 341d969..e6f6bf3 100644 --- a/src/Debug/EcsDebugUtility.cs +++ b/src/Debug/EcsDebugUtility.cs @@ -54,5 +54,11 @@ namespace DCFApixels.DragonECS var atr = type.GetCustomAttribute(); return atr != null ? (atr.r, atr.g, atr.b) : ((byte)255, (byte)255, (byte)255); } + + public static bool IsHidden() => IsHidden(typeof(T)); + public static bool IsHidden(Type type) + { + return type.GetCustomAttribute() != null; + } } }