refactoring

This commit is contained in:
Mikhail 2023-05-28 06:35:33 +08:00
parent 72b344b3dd
commit 62ceb3384e
3 changed files with 9 additions and 33 deletions

View File

@ -20,7 +20,6 @@ namespace DCFApixels.DragonECS
private bool _isInit; private bool _isInit;
private bool _isDestoryed; private bool _isDestoryed;
private bool _isEmptyDummy;
#region Properties #region Properties
public ReadOnlyCollection<IEcsSystem> AllSystems => _allSystemsSealed; public ReadOnlyCollection<IEcsSystem> AllSystems => _allSystemsSealed;
@ -39,7 +38,6 @@ namespace DCFApixels.DragonECS
_allRunnersSealed = new ReadOnlyDictionary<Type, IEcsRunner>(_runners); _allRunnersSealed = new ReadOnlyDictionary<Type, IEcsRunner>(_runners);
_isInit = false; _isInit = false;
_isEmptyDummy = false;
_isDestoryed = false; _isDestoryed = false;
} }
#endregion #endregion
@ -64,9 +62,6 @@ namespace DCFApixels.DragonECS
#region LifeCycle #region LifeCycle
public void Init() public void Init()
{ {
if (_isEmptyDummy)
return;
if (_isInit == true) if (_isInit == true)
{ {
EcsDebug.Print("[Warning]", $"This {nameof(EcsPipeline)} has already been initialized"); EcsDebug.Print("[Warning]", $"This {nameof(EcsPipeline)} has already been initialized");
@ -98,9 +93,6 @@ namespace DCFApixels.DragonECS
} }
public void Destroy() public void Destroy()
{ {
if (_isEmptyDummy)
return;
#if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS #if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS
CheckBeforeInitForMethod(nameof(Run)); CheckBeforeInitForMethod(nameof(Run));
#endif #endif
@ -135,10 +127,7 @@ namespace DCFApixels.DragonECS
#endregion #endregion
#region Builder #region Builder
public static Builder New() public static Builder New() => new Builder();
{
return new Builder();
}
public class Builder public class Builder
{ {
private const int KEYS_CAPACITY = 4; private const int KEYS_CAPACITY = 4;
@ -149,16 +138,12 @@ namespace DCFApixels.DragonECS
public Builder() public Builder()
{ {
_basicLayer = EcsConsts.BASIC_LAYER; _basicLayer = EcsConsts.BASIC_LAYER;
Layers = new LayerList(this, _basicLayer); Layers = new LayerList(this, _basicLayer);
Layers.Insert(EcsConsts.BASIC_LAYER, EcsConsts.PRE_BEGIN_LAYER, EcsConsts.BEGIN_LAYER); Layers.Insert(EcsConsts.BASIC_LAYER, EcsConsts.PRE_BEGIN_LAYER, EcsConsts.BEGIN_LAYER);
Layers.InsertAfter(EcsConsts.BASIC_LAYER, EcsConsts.END_LAYER, EcsConsts.POST_END_LAYER); Layers.InsertAfter(EcsConsts.BASIC_LAYER, EcsConsts.END_LAYER, EcsConsts.POST_END_LAYER);
_uniqueTypes = new HashSet<Type>(); _uniqueTypes = new HashSet<Type>();
_systems = new Dictionary<string, List<IEcsSystem>>(KEYS_CAPACITY); _systems = new Dictionary<string, List<IEcsSystem>>(KEYS_CAPACITY);
} }
public Builder Add(IEcsSystem system, string layerName = null) public Builder Add(IEcsSystem system, string layerName = null)
{ {
AddInternal(system, layerName, false); AddInternal(system, layerName, false);
@ -192,20 +177,16 @@ namespace DCFApixels.DragonECS
if (system is IEcsModule module)//если система одновременно явялется и системой и модулем то за один Add будет вызван Add и AddModule if (system is IEcsModule module)//если система одновременно явялется и системой и модулем то за один Add будет вызван Add и AddModule
AddModule(module); AddModule(module);
} }
public Builder AddModule(IEcsModule module) public Builder AddModule(IEcsModule module)
{ {
module.ImportSystems(this); module.ImportSystems(this);
return this; return this;
} }
public EcsPipeline Build() public EcsPipeline Build()
{ {
Add(new DeleteEmptyEntitesSystem(), EcsConsts.POST_END_LAYER); Add(new DeleteEmptyEntitesSystem(), EcsConsts.POST_END_LAYER);
List<IEcsSystem> result = new List<IEcsSystem>(32); List<IEcsSystem> result = new List<IEcsSystem>(32);
List<IEcsSystem> basicBlockList = _systems[_basicLayer]; List<IEcsSystem> basicBlockList = _systems[_basicLayer];
foreach (var item in _systems) foreach (var item in _systems)
{ {
if (!Layers.Has(item.Key)) if (!Layers.Has(item.Key))
@ -216,17 +197,14 @@ namespace DCFApixels.DragonECS
if(_systems.TryGetValue(item, out var list)) if(_systems.TryGetValue(item, out var list))
result.AddRange(list); result.AddRange(list);
} }
return new EcsPipeline(result.ToArray()); return new EcsPipeline(result.ToArray());
} }
public class LayerList : IEnumerable<string> public class LayerList : IEnumerable<string>
{ {
private const string ADD_LAYER = nameof(ADD_LAYER); // автоматический слой нужный только для метода Add private const string ADD_LAYER = nameof(ADD_LAYER); // автоматический слой нужный только для метода Add
private Builder _source; private Builder _source;
private List<string> _layers; private List<string> _layers;
private string _basicLayerName; private string _basicLayerName;
public LayerList(Builder source, string basicLayerName) public LayerList(Builder source, string basicLayerName)

View File

@ -566,4 +566,12 @@ namespace DCFApixels.DragonECS
} }
} }
#endregion #endregion
#region Extensions
public static class IntExtensions
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static entlong ToEntityLong(this int self, EcsWorld world) => world.GetEntityLong(self);
}
#endregion
} }

View File

@ -1,10 +0,0 @@
namespace DCFApixels.DragonECS
{
public static class IntExtensions
{
public static entlong ToEntityLong(this int self, EcsWorld world)
{
return world.GetEntityLong(self);
}
}
}