diff --git a/src/Collections/EcsGroup.cs b/src/Collections/EcsGroup.cs index 09c4be3..7bbcd74 100644 --- a/src/Collections/EcsGroup.cs +++ b/src/Collections/EcsGroup.cs @@ -197,7 +197,7 @@ namespace DCFApixels.DragonECS public short WorldID { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get { return _source.id; } + get { return _source.ID; } } public EcsWorld World { @@ -477,7 +477,7 @@ namespace DCFApixels.DragonECS public void UnionWith(EcsSpan span) { #if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS - if (_source.id != span.WorldID) Throw.Group_ArgumentDifferentWorldsException(); + if (_source.ID != span.WorldID) Throw.Group_ArgumentDifferentWorldsException(); #endif foreach (var entityID in span) { UnionWithStep(entityID); } } @@ -525,7 +525,7 @@ namespace DCFApixels.DragonECS public void ExceptWith(EcsSpan span) { #if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS - if (_source.id != span.WorldID) { Throw.Group_ArgumentDifferentWorldsException(); } + if (_source.ID != span.WorldID) { Throw.Group_ArgumentDifferentWorldsException(); } #endif foreach (var entityID in span) { ExceptWithStep_Internal(entityID); } } @@ -563,10 +563,10 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] public void IntersectWith(EcsReadonlyGroup group) { IntersectWith(group.GetSource_Internal()); } /// as Intersect sets - public void IntersectWith(EcsSpan span) //TODO протестировать + public void IntersectWith(EcsSpan span) { #if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS - if (_source.id != span.WorldID) { Throw.Group_ArgumentDifferentWorldsException(); } + if (_source.ID != span.WorldID) { Throw.Group_ArgumentDifferentWorldsException(); } #endif foreach (var entityID in span) { @@ -621,7 +621,7 @@ namespace DCFApixels.DragonECS public void SymmetricExceptWith(EcsSpan span) { #if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS - if (_source.id != span.WorldID) { Throw.Group_ArgumentDifferentWorldsException(); } + if (_source.ID != span.WorldID) { Throw.Group_ArgumentDifferentWorldsException(); } #endif foreach (var entityID in span) { SymmetricExceptWithStep_Internal(entityID); } } @@ -688,7 +688,7 @@ namespace DCFApixels.DragonECS public bool SetEquals(EcsSpan span) { #if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS - if (_source.id != span.WorldID) { Throw.Group_ArgumentDifferentWorldsException(); } + if (_source.ID != span.WorldID) { Throw.Group_ArgumentDifferentWorldsException(); } #endif if (span.Count != Count) { return false; } foreach (var entityID in span) @@ -747,7 +747,7 @@ namespace DCFApixels.DragonECS public bool Overlaps(EcsSpan span) { #if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS - if (_source.id != span.WorldID) Throw.Group_ArgumentDifferentWorldsException(); + if (_source.ID != span.WorldID) Throw.Group_ArgumentDifferentWorldsException(); #endif foreach (var entityID in span) { @@ -786,7 +786,7 @@ namespace DCFApixels.DragonECS public bool IsSubsetOf(EcsSpan span) { #if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS - if (_source.id != span.WorldID) Throw.Group_ArgumentDifferentWorldsException(); + if (_source.ID != span.WorldID) Throw.Group_ArgumentDifferentWorldsException(); #endif if (Count == 0) { return true; } if (span.Count < Count) { return false; } @@ -815,7 +815,7 @@ namespace DCFApixels.DragonECS public bool IsProperSubsetOf(EcsSpan span) { #if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS - if (_source.id != span.WorldID) Throw.Group_ArgumentDifferentWorldsException(); + if (_source.ID != span.WorldID) Throw.Group_ArgumentDifferentWorldsException(); #endif if (Count == 0) { return true; } if (span.Count <= Count) { return false; } @@ -884,7 +884,7 @@ namespace DCFApixels.DragonECS public bool IsSupersetOf(EcsSpan span) { #if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS - if (_source.id != span.WorldID) Throw.Group_ArgumentDifferentWorldsException(); + if (_source.ID != span.WorldID) Throw.Group_ArgumentDifferentWorldsException(); #endif if (span.Count > Count) { return false; } return IsSupersetOf_Internal(span); @@ -910,7 +910,7 @@ namespace DCFApixels.DragonECS public bool IsProperSupersetOf(EcsSpan span) { #if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS - if (_source.id != span.WorldID) Throw.Group_ArgumentDifferentWorldsException(); + if (_source.ID != span.WorldID) Throw.Group_ArgumentDifferentWorldsException(); #endif if (span.Count >= Count) { return false; } return IsSupersetOf_Internal(span); @@ -1030,7 +1030,7 @@ namespace DCFApixels.DragonECS public static EcsGroup Except(EcsSpan a, EcsGroup b) { #if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS - if (a.WorldID != b._source.id) { Throw.Group_ArgumentDifferentWorldsException(); } + if (a.WorldID != b._source.ID) { Throw.Group_ArgumentDifferentWorldsException(); } #endif EcsGroup result = b._source.GetFreeGroup(); foreach (var entityID in a) @@ -1085,7 +1085,7 @@ namespace DCFApixels.DragonECS public static EcsGroup Intersect(EcsSpan a, EcsGroup b) { #if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS - if (a.WorldID != b._source.id) { Throw.Group_ArgumentDifferentWorldsException(); } + if (a.WorldID != b._source.ID) { Throw.Group_ArgumentDifferentWorldsException(); } #endif EcsGroup result = b._source.GetFreeGroup(); foreach (var entityID in a) diff --git a/src/EcsAspect.cs b/src/EcsAspect.cs index baf381b..b5aae81 100644 --- a/src/EcsAspect.cs +++ b/src/EcsAspect.cs @@ -225,7 +225,7 @@ namespace DCFApixels.DragonECS public Iterator(EcsMaskIterator iterator, EcsSpan span) { - worldID = iterator.World.id; + worldID = iterator.World.ID; _span = span; this.iterator = iterator.Iterate(span); } diff --git a/src/EcsMask.cs b/src/EcsMask.cs index 597b015..5e8b051 100644 --- a/src/EcsMask.cs +++ b/src/EcsMask.cs @@ -379,9 +379,9 @@ namespace DCFApixels.DragonECS - EmptyMask = CreateEmpty(_staticMasks.Count, world.id); + EmptyMask = CreateEmpty(_staticMasks.Count, world.ID); _staticMasks.Add(EmptyMask._staticMask.ID, EmptyMask); - BrokenMask = CreateBroken(_staticMasks.Count, world.id); + BrokenMask = CreateBroken(_staticMasks.Count, world.ID); _staticMasks.Add(BrokenMask._staticMask.ID, BrokenMask); } public void Init(ref WorldMaskComponent component, EcsWorld world) @@ -444,7 +444,7 @@ namespace DCFApixels.DragonECS int[] incs = ConvertTypeCodeToComponentTypeID(staticMask.IncTypeCodes, _world); int[] excs = ConvertTypeCodeToComponentTypeID(staticMask.ExcTypeCodes, _world); - result = new EcsMask(staticMask, _staticMasks.Count, _world.id, incs, excs); + result = new EcsMask(staticMask, _staticMasks.Count, _world.ID, incs, excs); _staticMasks.Add(staticMask.ID, result); } diff --git a/src/EcsStaticMask.cs b/src/EcsStaticMask.cs index 08bb49f..edbb639 100644 --- a/src/EcsStaticMask.cs +++ b/src/EcsStaticMask.cs @@ -355,7 +355,6 @@ namespace DCFApixels.DragonECS return $"Inc({string.Join(", ", inc)}) Exc({string.Join(", ", exc)})"; // Release optimization #endif } - internal class DebuggerProxy { private EcsStaticMask _source; @@ -388,28 +387,49 @@ namespace DCFApixels.DragonECS #if DEBUG //TODO оптимизировать, так как списки сортированны, наверняка есть способ без хешсета пройтись и не локать треды - private static HashSet _dummyHashSet = new HashSet(); - private static void CheckConstraints(int[] inc, int[] exc) + private static void CheckConstraints(EcsTypeCode[] incs, EcsTypeCode[] excs) { - lock (_dummyHashSet) - { - if (CheckRepeats(inc)) { throw new EcsFrameworkException("The values in the Include constraints are repeated."); } - if (CheckRepeats(exc)) { throw new EcsFrameworkException("The values in the Exclude constraints are repeated."); } - _dummyHashSet.Clear(); - _dummyHashSet.UnionWith(inc); - if (_dummyHashSet.Overlaps(exc)) { throw new EcsFrameworkException("Conflicting Include and Exclude constraints."); } - } + if (CheckRepeats(incs)) { throw new EcsFrameworkException("The values in the Include constraints are repeated."); } + if (CheckRepeats(excs)) { throw new EcsFrameworkException("The values in the Exclude constraints are repeated."); } + if (HasCommonElements(incs, excs)) { throw new EcsFrameworkException("Conflicting Include and Exclude constraints."); } } - private static bool CheckRepeats(int[] array) + private static bool HasCommonElements(EcsTypeCode[] a, EcsTypeCode[] b) { - _dummyHashSet.Clear(); - foreach (var item in array) + int i = 0; + int j = 0; + + while (i < a.Length && j < b.Length) { - if (_dummyHashSet.Contains(item)) + if (a[i] == b[j]) + { + return true; + } + else if (a[i] < b[j]) + { + i++; + } + else + { + j++; + } + } + return false; + } + private static bool CheckRepeats(EcsTypeCode[] array) + { + if(array.Length <= 0) + { + return false; + } + EcsTypeCode lastValue = array[0]; + for (int i = 1; i < array.Length; i++) + { + EcsTypeCode value = array[i]; + if(value == lastValue) { return true; } - _dummyHashSet.Add(item); + lastValue = value; } return false; } diff --git a/src/EcsWorld.cs b/src/EcsWorld.cs index 131598f..369c192 100644 --- a/src/EcsWorld.cs +++ b/src/EcsWorld.cs @@ -42,7 +42,7 @@ namespace DCFApixels.DragonECS [DebuggerTypeProxy(typeof(DebuggerProxy))] public partial class EcsWorld : IEntityStorage, IEcsMember { - public readonly short id; + public readonly short ID; private IConfigContainer _configs; private bool _isDestroyed = false; @@ -73,6 +73,12 @@ namespace DCFApixels.DragonECS private List _entityListeners = new List(); #region Properties + [Obsolete("Use EcsWorld.ID")] + public short id + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get { return ID; } + } EcsWorld IEntityStorage.World { get { return this; } @@ -119,7 +125,7 @@ namespace DCFApixels.DragonECS get { ReleaseDelEntityBufferAll(); - return _entityDispenser.UsedToEcsSpan(id); + return _entityDispenser.UsedToEcsSpan(ID); } } public int PoolsCount @@ -166,7 +172,7 @@ namespace DCFApixels.DragonECS Throw.Exception("The world with the specified ID has already been created\r\n"); } } - id = worldID; + ID = worldID; _worlds[worldID] = this; _poolsMediator = new PoolsMediator(this); @@ -191,7 +197,7 @@ namespace DCFApixels.DragonECS EcsDebug.PrintWarning("The world is already destroyed"); return; } - if (id == NULL_WORLD_ID) + if (ID == NULL_WORLD_ID) { #if (DEBUG && !DISABLE_DEBUG) Throw.World_WorldCantBeDestroyed(); @@ -202,9 +208,9 @@ namespace DCFApixels.DragonECS _entityDispenser = null; _pools = null; _nullPool = null; - _worlds[id] = null; - ReleaseData(id); - _worldIdDispenser.Release(id); + _worlds[ID] = null; + ReleaseData(ID); + _worldIdDispenser.Release(ID); _isDestroyed = true; _poolTypeCode_2_CmpTypeIDs = null; _cmpTypeCode_2_CmpTypeIDs = null; @@ -241,12 +247,12 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] public ref T Get() where T : struct { - return ref WorldComponentPool.GetForWorld(id); + return ref WorldComponentPool.GetForWorld(ID); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public ref T GetUnchecked() where T : struct { - return ref WorldComponentPool.GetForWorldUnchecked(id); + return ref WorldComponentPool.GetForWorldUnchecked(ID); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ref T Get(int worldID) where T : struct @@ -341,18 +347,18 @@ namespace DCFApixels.DragonECS { ReleaseDelEntityBufferAll(); } - return _entityDispenser.UsedToEcsSpan(id); + return _entityDispenser.UsedToEcsSpan(ID); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe entlong GetEntityLong(int entityID) { - long x = (long)id << 48 | (long)GetGen(entityID) << 32 | (long)entityID; + long x = (long)ID << 48 | (long)GetGen(entityID) << 32 | (long)entityID; return *(entlong*)&x; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe EntitySlotInfo GetEntitySlotInfoDebug(int entityID) { - return new EntitySlotInfo(entityID, _entities[entityID].gen, id); + return new EntitySlotInfo(entityID, _entities[entityID].gen, ID); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool IsAlive(int entityID, short gen) @@ -392,7 +398,7 @@ namespace DCFApixels.DragonECS public bool IsMatchesMask(EcsMask mask, int entityID) { #if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS - if (mask._worldID != id) { Throw.World_MaskDoesntBelongWorld(); } + if (mask._worldID != ID) { Throw.World_MaskDoesntBelongWorld(); } #endif for (int i = 0, iMax = mask._inc.Length; i < iMax; i++) { @@ -821,7 +827,7 @@ namespace DCFApixels.DragonECS #region DebuggerProxy private EcsSpan GetSpan_Debug() { - return _entityDispenser.UsedToEcsSpan(id); + return _entityDispenser.UsedToEcsSpan(ID); } protected class DebuggerProxy { @@ -841,7 +847,7 @@ namespace DCFApixels.DragonECS } public long Version { get { return _world.Version; } } public IEcsPool[] Pools { get { return _world._pools; } } - public short ID { get { return _world.id; } } + public short ID { get { return _world.ID; } } public DebuggerProxy(EcsWorld world) { _world = world; diff --git a/src/Executors/EcsQueryExecutor.cs b/src/Executors/EcsQueryExecutor.cs index 42197dc..b7a13e7 100644 --- a/src/Executors/EcsQueryExecutor.cs +++ b/src/Executors/EcsQueryExecutor.cs @@ -28,7 +28,7 @@ namespace DCFApixels.DragonECS public short WorldID { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get { return _source.id; } + get { return _source.ID; } } public EcsWorld World { diff --git a/src/Executors/EcsWhereExecutor.cs b/src/Executors/EcsWhereExecutor.cs index 9928811..46283cc 100644 --- a/src/Executors/EcsWhereExecutor.cs +++ b/src/Executors/EcsWhereExecutor.cs @@ -58,7 +58,7 @@ namespace DCFApixels.DragonECS.Internal { #if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS if (span.IsNull) { Throw.ArgumentNull(nameof(span)); } - if (span.WorldID != World.id) { Throw.Quiery_ArgumentDifferentWorldsException(); } + if (span.WorldID != World.ID) { Throw.Quiery_ArgumentDifferentWorldsException(); } #endif if (_filteredEntities == null) { @@ -71,13 +71,13 @@ namespace DCFApixels.DragonECS.Internal public EcsSpan Execute() { Execute_Iternal(); - return new EcsSpan(World.id, _filteredAllEntities, _filteredAllEntitiesCount); + return new EcsSpan(World.ID, _filteredAllEntities, _filteredAllEntitiesCount); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public EcsSpan ExecuteFor(EcsSpan span) { ExecuteFor_Iternal(span); - return new EcsSpan(World.id, _filteredEntities, _filteredEntitiesCount); + return new EcsSpan(World.ID, _filteredEntities, _filteredEntitiesCount); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -85,14 +85,14 @@ namespace DCFApixels.DragonECS.Internal { Execute_Iternal(); ArraySortHalperX.Sort(_filteredAllEntities, comparison, _filteredAllEntitiesCount); - return new EcsSpan(World.id, _filteredAllEntities, _filteredAllEntitiesCount); + return new EcsSpan(World.ID, _filteredAllEntities, _filteredAllEntitiesCount); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public EcsSpan ExecuteFor(EcsSpan span, Comparison comparison) { ExecuteFor_Iternal(span); ArraySortHalperX.Sort(_filteredEntities, comparison, _filteredEntitiesCount); - return new EcsSpan(World.id, _filteredEntities, _filteredEntitiesCount); + return new EcsSpan(World.ID, _filteredEntities, _filteredEntitiesCount); } #endregion } diff --git a/src/Executors/EcsWhereToGroupExecutor.cs b/src/Executors/EcsWhereToGroupExecutor.cs index 111798d..cb2ab97 100644 --- a/src/Executors/EcsWhereToGroupExecutor.cs +++ b/src/Executors/EcsWhereToGroupExecutor.cs @@ -57,7 +57,7 @@ namespace DCFApixels.DragonECS.Internal { #if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS if (span.IsNull) { Throw.ArgumentNull(nameof(span)); } - if (span.WorldID != World.id) { Throw.Quiery_ArgumentDifferentWorldsException(); } + if (span.WorldID != World.ID) { Throw.Quiery_ArgumentDifferentWorldsException(); } #endif if (_filteredGroup == null) { diff --git a/src/Utils/EcsTypeCode.cs b/src/Utils/EcsTypeCode.cs index c487938..46501c4 100644 --- a/src/Utils/EcsTypeCode.cs +++ b/src/Utils/EcsTypeCode.cs @@ -1,4 +1,7 @@ namespace DCFApixels.DragonECS { - public enum EcsTypeCode : int { } + public enum EcsTypeCode : int + { + NULL = 0, + } } diff --git a/src/Utils/ITemplateNode.cs b/src/Utils/ITemplateNode.cs index e88fa6c..887dcfc 100644 --- a/src/Utils/ITemplateNode.cs +++ b/src/Utils/ITemplateNode.cs @@ -9,13 +9,13 @@ namespace DCFApixels.DragonECS public static int NewEntity(this EcsWorld world, ITemplateNode template) { int e = world.NewEntity(); - template.Apply(world.id, e); + template.Apply(world.ID, e); return e; } public static entlong NewEntityLong(this EcsWorld world, ITemplateNode template) { entlong e = world.NewEntityLong(); - template.Apply(world.id, e.ID); + template.Apply(world.ID, e.ID); return e; } }