From e6adde27607fc8f041d2a3303230749a48471339 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Sun, 28 May 2023 09:00:47 +0800 Subject: [PATCH 1/4] Create package.json --- package.json | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 package.json diff --git a/package.json b/package.json new file mode 100644 index 0000000..606735d --- /dev/null +++ b/package.json @@ -0,0 +1,23 @@ +{ + "name": "com.dcfa_pixels.dragonecs", + "author": + { + "name": "DCFApixels", + "url": "https://github.com/DCFApixels" + }, + "displayName": "DragonECS", + "description": "C# Entity Component System Framework", + "unity": "2020.3", + "version": "0.7.0", + "repository": { + "type": "git", + "url": "https://github.com/DCFApixels/DragonECS.git" + }, + "keywords": + [ + "ecs", + "performance", + "dragonecs", + "framework" + ] +} \ No newline at end of file From 8b0f4631290d2b1e3ee9ff8256b4eea86fc07bbf Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Mon, 29 May 2023 23:03:02 +0800 Subject: [PATCH 2/4] refactoring --- src/EcsSubject.cs | 4 ++-- src/EcsWorld.cs | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/EcsSubject.cs b/src/EcsSubject.cs index a1f60b3..9efb761 100644 --- a/src/EcsSubject.cs +++ b/src/EcsSubject.cs @@ -82,7 +82,7 @@ namespace DCFApixels.DragonECS { return _world.GetPool(); } - public void IncludeImplicit() + private void IncludeImplicit() { int id = _world.GetComponentID(); #if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS @@ -90,7 +90,7 @@ namespace DCFApixels.DragonECS #endif _inc.Add(_world.GetComponentID()); } - public void ExcludeImplicit() + private void ExcludeImplicit() { int id = _world.GetComponentID(); #if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS diff --git a/src/EcsWorld.cs b/src/EcsWorld.cs index ccae5fa..194da51 100644 --- a/src/EcsWorld.cs +++ b/src/EcsWorld.cs @@ -108,7 +108,8 @@ namespace DCFApixels.DragonECS #endregion #region GetComponentID - public int GetComponentID() => WorldMetaStorage.GetComponentId(_worldTypeID);////ComponentType.uniqueID; + public int GetComponentID() => WorldMetaStorage.GetComponentId(_worldTypeID); + public bool IsComponentTypeDeclared() => WorldMetaStorage.IsComponentTypeDeclared(_worldTypeID); #endregion @@ -380,7 +381,7 @@ namespace DCFApixels.DragonECS } #region WorldMetaStorage - public static class WorldMetaStorage + internal static class WorldMetaStorage { private static List _resizer = new List(); private static int _tokenCount = 0; @@ -421,6 +422,7 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int GetExecutorId(int worldID) => Executor.Get(worldID); + public static bool IsComponentTypeDeclared(int worldID) => IsComponentTypeDeclared(worldID, typeof(TComponent)); public static bool IsComponentTypeDeclared(int worldID, Type type) => _metas[worldID].IsDeclaredType(type); public static Type GetComponentType(int worldID, int componentID) => _metas[worldID].GetComponentType(componentID); From bf8f6518dff5b0eb8c961c406e24db1843baad06 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Tue, 30 May 2023 00:13:05 +0800 Subject: [PATCH 3/4] rename method --- src/EcsPipeline.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/EcsPipeline.cs b/src/EcsPipeline.cs index ab1e3fe..c9e9c47 100644 --- a/src/EcsPipeline.cs +++ b/src/EcsPipeline.cs @@ -189,7 +189,7 @@ namespace DCFApixels.DragonECS List basicBlockList = _systems[_basicLayer]; foreach (var item in _systems) { - if (!Layers.Has(item.Key)) + if (!Layers.Contains(item.Key)) basicBlockList.AddRange(item.Value); } foreach (var item in Layers) @@ -217,7 +217,7 @@ namespace DCFApixels.DragonECS public Builder Add(string newLayer) => Insert(ADD_LAYER, newLayer); public Builder Insert(string targetLayer, string newLayer) { - if (Has(newLayer)) return _source; + if (Contains(newLayer)) return _source; int index = _layers.IndexOf(targetLayer); if (index < 0) @@ -227,7 +227,7 @@ namespace DCFApixels.DragonECS } public Builder InsertAfter(string targetLayer, string newLayer) { - if (Has(newLayer)) return _source; + if (Contains(newLayer)) return _source; if (targetLayer == _basicLayerName) // нужно чтобы метод Add работал правильно. _basicLayerName и ADD_LAYER считается одним слоем, поэтому Before = _basicLayerName After = ADD_LAYER targetLayer = ADD_LAYER; @@ -262,7 +262,7 @@ namespace DCFApixels.DragonECS int index = _layers.IndexOf(targetLayer); if (index < 0) throw new KeyNotFoundException($"Layer {targetLayer} not found"); - _layers.InsertRange(index, newLayers.Where(o => !Has(o))); + _layers.InsertRange(index, newLayers.Where(o => !Contains(o))); return _source; } public Builder InsertAfter(string targetLayer, params string[] newLayers) @@ -275,9 +275,9 @@ namespace DCFApixels.DragonECS targetLayer = ADD_LAYER; if (++index >= _layers.Count) - _layers.AddRange(newLayers.Where(o => !Has(o))); + _layers.AddRange(newLayers.Where(o => !Contains(o))); else - _layers.InsertRange(index, newLayers.Where(o => !Has(o))); + _layers.InsertRange(index, newLayers.Where(o => !Contains(o))); return _source; } public Builder Move(string targetLayer, params string[] movingLayers) @@ -296,7 +296,7 @@ namespace DCFApixels.DragonECS return InsertAfter(targetLayer, movingLayers); } - public bool Has(string layer) => _layers.Contains(layer); + public bool Contains(string layer) => _layers.Contains(layer); public List.Enumerator GetEnumerator() => _layers.GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => _layers.GetEnumerator(); From d7494648c9a34bcbd2933c639ff2060785b3f3a4 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Tue, 30 May 2023 00:13:50 +0800 Subject: [PATCH 4/4] update DeleteOneFrameComponentSystem --- src/Builtin/Systems.cs | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/Builtin/Systems.cs b/src/Builtin/Systems.cs index 5f2fc45..612cbfc 100644 --- a/src/Builtin/Systems.cs +++ b/src/Builtin/Systems.cs @@ -27,8 +27,7 @@ namespace DCFApixels.DragonECS } } [DebugHide, DebugColor(DebugColor.Grey)] - public class DeleteOneFrameComponentSystem : IEcsRunProcess, IEcsInject - where TWorld : EcsWorld + public class DeleteOneFrameComponentSystem : IEcsRunProcess, IEcsPreInject where TComponent : struct, IEcsComponent { private sealed class Subject : EcsSubject @@ -36,32 +35,35 @@ namespace DCFApixels.DragonECS public EcsPool pool; public Subject(Builder b) => pool = b.Include(); } - private TWorld _world; - public void Inject(TWorld obj) => _world = obj; + List _worlds = new List(); + public void PreInject(object obj) + { + if (obj is EcsWorld world) + _worlds.Add(world); + } public void Run(EcsPipeline pipeline) { - foreach (var e in _world.Where(out Subject s)) - s.pool.Del(e); + for (int i = 0, iMax = _worlds.Count; i < iMax; i++) + { + EcsWorld world = _worlds[i]; + if (world.IsComponentTypeDeclared()) + { + foreach (var e in world.Where(out Subject s)) + s.pool.Del(e); + } + } } } } public static class DeleteOneFrameComponentSystemExtensions { private const string AUTO_DEL_LAYER = nameof(AUTO_DEL_LAYER); - public static EcsPipeline.Builder AutoDel(this EcsPipeline.Builder b) - where TWorld : EcsWorld + public static EcsPipeline.Builder AutoDel(this EcsPipeline.Builder b, string layerName = AUTO_DEL_LAYER) where TComponent : struct, IEcsComponent { - b.Layers.Insert(EcsConsts.POST_END_LAYER, AUTO_DEL_LAYER); - b.AddUnique(new DeleteOneFrameComponentSystem(), AUTO_DEL_LAYER); - return b; - } - /// for EcsDefaultWorld - public static EcsPipeline.Builder AutoDel(this EcsPipeline.Builder b) - where TComponent : struct, IEcsComponent - { - b.Layers.Insert(EcsConsts.POST_END_LAYER, AUTO_DEL_LAYER); - b.AddUnique(new DeleteOneFrameComponentSystem(), AUTO_DEL_LAYER); + if(AUTO_DEL_LAYER == layerName) + b.Layers.Insert(EcsConsts.POST_END_LAYER, AUTO_DEL_LAYER); + b.AddUnique(new DeleteOneFrameComponentSystem(), layerName); return b; } }