From 50ea02f9676626cb1fad0a50140de6b735e1f22b Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Fri, 7 Apr 2023 18:16:13 +0800 Subject: [PATCH] refactoring --- src/EcsMask.cs | 4 ++-- src/EcsQuery.cs | 14 ++++---------- src/EcsWorld.cs | 20 +++----------------- src/Interfaces/IEcsReadonlyTable.cs | 4 ++-- 4 files changed, 11 insertions(+), 31 deletions(-) diff --git a/src/EcsMask.cs b/src/EcsMask.cs index f643767..2298bae 100644 --- a/src/EcsMask.cs +++ b/src/EcsMask.cs @@ -289,7 +289,7 @@ namespace DCFApixels.DragonECS #endregion #region EcsMask - public class EcsMaskBase + public class EcsComponentMask { internal Type WorldArchetypeType; internal int[] Inc; @@ -308,7 +308,7 @@ namespace DCFApixels.DragonECS } - public sealed class EcsMask : EcsMaskBase + public sealed class EcsMask : EcsComponentMask { // internal readonly Type WorldArchetypeType; internal readonly int UniqueID; diff --git a/src/EcsQuery.cs b/src/EcsQuery.cs index 54bb4f0..07761fd 100644 --- a/src/EcsQuery.cs +++ b/src/EcsQuery.cs @@ -1,12 +1,7 @@ -using DCFApixels.DragonECS; -using System; +using System; using System.Collections.Generic; -using System.IO; -using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Threading.Tasks; namespace DCFApixels.DragonECS { @@ -45,13 +40,10 @@ namespace DCFApixels.DragonECS get => group.Readonly; } - public EcsGroup.Enumerator GetEnumerator() => group.GetEnumerator(); - protected virtual void Init(Builder b) { } - #region Builder public sealed class Builder : EcsQueryBuilder { @@ -88,6 +80,7 @@ namespace DCFApixels.DragonECS _exc = new List(4); } + #region Init query member methods public override inc Include() where TComponent : struct { _inc.Add(_world.GetComponentID()); @@ -102,6 +95,7 @@ namespace DCFApixels.DragonECS { return new opt(_world.GetPool()); } + #endregion private void End(out EcsQueryMask mask) { @@ -119,7 +113,7 @@ namespace DCFApixels.DragonECS #endregion } - public class EcsQueryMask : EcsMaskBase + public class EcsQueryMask : EcsComponentMask { public EcsQueryMask(Type worldArchetypeType, int[] inc, int[] exc) { diff --git a/src/EcsWorld.cs b/src/EcsWorld.cs index 53b5ec4..2a7ecb4 100644 --- a/src/EcsWorld.cs +++ b/src/EcsWorld.cs @@ -203,27 +203,13 @@ namespace DCFApixels.DragonECS for (int i = 0; i < _entitiesCount && _entitiesCount <= _denseEntities.Length; i++) { int entity = _denseEntities[i]; - if (IsMaskCompatible(mask.Inc, mask.Exc, entity)) + if (IsMaskCompatible(mask, entity)) filter.AddEntity(entity); } } entities = (TQuery)_queries[uniqueID]; return entities; } - private bool IsMaskCompatible(int[] inc, int[] exc, int entity) - { - for (int i = 0, iMax = inc.Length; i < iMax; i++) - { - if (!_pools[inc[i]].Has(entity)) - return false; - } - for (int i = 0, iMax = exc.Length; i < iMax; i++) - { - if (_pools[exc[i]].Has(entity)) - return false; - } - return true; - } #endregion #region IsMaskCompatible/IsMaskCompatibleWithout @@ -238,7 +224,7 @@ namespace DCFApixels.DragonECS return IsMaskCompatible(EcsMaskMap.GetMask(), entityID); } - public bool IsMaskCompatible(EcsMaskBase mask, int entity) + public bool IsMaskCompatible(EcsComponentMask mask, int entity) { #if (DEBUG && !DISABLE_DRAGONECS_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS if (mask.WorldArchetypeType != typeof(TWorldArchetype)) @@ -257,7 +243,7 @@ namespace DCFApixels.DragonECS return true; } - public bool IsMaskCompatibleWithout(EcsMaskBase mask, int entity, int otherComponentID) + public bool IsMaskCompatibleWithout(EcsComponentMask mask, int entity, int otherComponentID) { #if (DEBUG && !DISABLE_DRAGONECS_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS if (mask.WorldArchetypeType != typeof(TWorldArchetype)) diff --git a/src/Interfaces/IEcsReadonlyTable.cs b/src/Interfaces/IEcsReadonlyTable.cs index 48652ff..55ae41b 100644 --- a/src/Interfaces/IEcsReadonlyTable.cs +++ b/src/Interfaces/IEcsReadonlyTable.cs @@ -22,8 +22,8 @@ namespace DCFApixels.DragonECS public bool IsMaskCompatible(int entity) where TInc : struct, IInc; public bool IsMaskCompatible(int entity) where TInc : struct, IInc where TExc : struct, IExc; - public bool IsMaskCompatible(EcsMaskBase mask, int entity); - public bool IsMaskCompatibleWithout(EcsMaskBase mask, int entity, int otherPoolID); + public bool IsMaskCompatible(EcsComponentMask mask, int entity); + public bool IsMaskCompatibleWithout(EcsComponentMask mask, int entity, int otherPoolID); #endregion #region Properties