From 62ceb3384e9af688b8eaca6798805942a3a4d9d4 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Sun, 28 May 2023 06:35:33 +0800 Subject: [PATCH] refactoring --- src/EcsPipeline.cs | 24 +----------------------- src/EcsWorld.cs | 8 ++++++++ src/Utils/IntExtensions.cs | 10 ---------- 3 files changed, 9 insertions(+), 33 deletions(-) delete mode 100644 src/Utils/IntExtensions.cs diff --git a/src/EcsPipeline.cs b/src/EcsPipeline.cs index 2af0ecd..ab1e3fe 100644 --- a/src/EcsPipeline.cs +++ b/src/EcsPipeline.cs @@ -20,7 +20,6 @@ namespace DCFApixels.DragonECS private bool _isInit; private bool _isDestoryed; - private bool _isEmptyDummy; #region Properties public ReadOnlyCollection AllSystems => _allSystemsSealed; @@ -39,7 +38,6 @@ namespace DCFApixels.DragonECS _allRunnersSealed = new ReadOnlyDictionary(_runners); _isInit = false; - _isEmptyDummy = false; _isDestoryed = false; } #endregion @@ -64,9 +62,6 @@ namespace DCFApixels.DragonECS #region LifeCycle public void Init() { - if (_isEmptyDummy) - return; - if (_isInit == true) { EcsDebug.Print("[Warning]", $"This {nameof(EcsPipeline)} has already been initialized"); @@ -98,9 +93,6 @@ namespace DCFApixels.DragonECS } public void Destroy() { - if (_isEmptyDummy) - return; - #if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS CheckBeforeInitForMethod(nameof(Run)); #endif @@ -135,10 +127,7 @@ namespace DCFApixels.DragonECS #endregion #region Builder - public static Builder New() - { - return new Builder(); - } + public static Builder New() => new Builder(); public class Builder { private const int KEYS_CAPACITY = 4; @@ -149,16 +138,12 @@ namespace DCFApixels.DragonECS public Builder() { _basicLayer = EcsConsts.BASIC_LAYER; - Layers = new LayerList(this, _basicLayer); - 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); } - public Builder Add(IEcsSystem system, string layerName = null) { AddInternal(system, layerName, false); @@ -192,20 +177,16 @@ namespace DCFApixels.DragonECS if (system is IEcsModule module)//если система одновременно явялется и системой и модулем то за один Add будет вызван Add и AddModule AddModule(module); } - public Builder AddModule(IEcsModule module) { module.ImportSystems(this); return this; } - public EcsPipeline Build() { Add(new DeleteEmptyEntitesSystem(), EcsConsts.POST_END_LAYER); - List result = new List(32); List basicBlockList = _systems[_basicLayer]; - foreach (var item in _systems) { if (!Layers.Has(item.Key)) @@ -216,17 +197,14 @@ namespace DCFApixels.DragonECS if(_systems.TryGetValue(item, out var list)) result.AddRange(list); } - return new EcsPipeline(result.ToArray()); } - public class LayerList : IEnumerable { private const string ADD_LAYER = nameof(ADD_LAYER); // автоматический слой нужный только для метода Add private Builder _source; private List _layers; - private string _basicLayerName; public LayerList(Builder source, string basicLayerName) diff --git a/src/EcsWorld.cs b/src/EcsWorld.cs index 1d88b3c..ccae5fa 100644 --- a/src/EcsWorld.cs +++ b/src/EcsWorld.cs @@ -566,4 +566,12 @@ namespace DCFApixels.DragonECS } } #endregion + + #region Extensions + public static class IntExtensions + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static entlong ToEntityLong(this int self, EcsWorld world) => world.GetEntityLong(self); + } + #endregion } diff --git a/src/Utils/IntExtensions.cs b/src/Utils/IntExtensions.cs deleted file mode 100644 index 2c42f57..0000000 --- a/src/Utils/IntExtensions.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace DCFApixels.DragonECS -{ - public static class IntExtensions - { - public static entlong ToEntityLong(this int self, EcsWorld world) - { - return world.GetEntityLong(self); - } - } -}