diff --git a/src/Builtin/BaseProcesses.cs b/src/Builtin/BaseProcesses.cs index f83fb09..c736ccc 100644 --- a/src/Builtin/BaseProcesses.cs +++ b/src/Builtin/BaseProcesses.cs @@ -149,7 +149,7 @@ namespace DCFApixels.DragonECS.Internal } catch (Exception e) { -#if DISABLE_CATH_EXCEPTIONS +#if DRAGONECS_DISABLE_CATH_EXCEPTIONS throw; #endif EcsDebug.PrintError(e); @@ -166,7 +166,7 @@ namespace DCFApixels.DragonECS.Internal try { item.Run(); } catch (Exception e) { -#if DISABLE_CATH_EXCEPTIONS +#if DRAGONECS_DISABLE_CATH_EXCEPTIONS throw; #endif EcsDebug.PrintError(e); diff --git a/src/Collections/EcsGroup.cs b/src/Collections/EcsGroup.cs index aaa2829..7334897 100644 --- a/src/Collections/EcsGroup.cs +++ b/src/Collections/EcsGroup.cs @@ -234,8 +234,16 @@ namespace DCFApixels.DragonECS } internal void ReleaseGroup(EcsGroup group) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (group.World != this) { Throw.World_GroupDoesNotBelongWorld(); } +#elif DRAGONECS_STABILITY_MODE + if (group.World != this) + { + if (TryGetWorld(group.WorldID, out EcsWorld sourceWorld)) + { + group.World.ReleaseGroup(group); + } + } #endif group._isReleased = true; group.Clear(); @@ -307,8 +315,10 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] get { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (index < 0 || index >= Count) { Throw.ArgumentOutOfRange(); } +#elif DRAGONECS_STABILITY_MODE + if (index < 0 || index >= Count) { return EcsConsts.NULL_ENTITY_ID; } #endif return _dense[++index]; } @@ -316,7 +326,7 @@ namespace DCFApixels.DragonECS // set // { // // TODO добавить лок енумератора на изменение - //#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS + //#if DEBUG || DRAGONECS_STABILITY_MODE // if (index < 0 || index >= Count) { Throw.ArgumentOutOfRange(); } //#endif // var oldValue = _dense[index]; @@ -369,8 +379,10 @@ namespace DCFApixels.DragonECS #region Add/Remove public void AddUnchecked(int entityID) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (Has(entityID)) { Throw.Group_AlreadyContains(entityID); } +#elif DRAGONECS_STABILITY_MODE + if (Has(entityID)) { return; } #endif Add_Internal(entityID); } @@ -413,8 +425,10 @@ namespace DCFApixels.DragonECS public void RemoveUnchecked(int entityID) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (Has(entityID) == false) { Throw.Group_DoesNotContain(entityID); } +#elif DRAGONECS_STABILITY_MODE + if (Has(entityID) == false) { return; } #endif Remove_Internal(entityID); } @@ -526,13 +540,16 @@ namespace DCFApixels.DragonECS #region CopyFrom/Clone/Slice/ToSpan/ToArray public void CopyFrom(EcsGroup group) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (group.World != _source) { Throw.Group_ArgumentDifferentWorldsException(); } -#endif - if (_count > 0) +#elif DRAGONECS_STABILITY_MODE + if (group.World != _source) { Clear(); + return; } +#endif + Clear(); foreach (var entityID in group) { Add_Internal(entityID); @@ -578,8 +595,11 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] public EcsSpan Slice(int start, int length) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (start < 0 || start + length > _count) { Throw.ArgumentOutOfRange(); } +#elif DRAGONECS_STABILITY_MODE + if (start < 0) { start = 0; } + if (start + length > _count) { length = _count - start; } #endif return new EcsSpan(WorldID, _dense, start + 1, length); } @@ -622,8 +642,10 @@ namespace DCFApixels.DragonECS /// as Union sets public void UnionWith(EcsGroup group) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS - if (_source != group._source) Throw.Group_ArgumentDifferentWorldsException(); +#if DEBUG + if (_source != group._source) { Throw.Group_ArgumentDifferentWorldsException(); } +#elif DRAGONECS_STABILITY_MODE + if (_source != group._source) { return; } #endif foreach (var entityID in group) { UnionWithStep(entityID); } } @@ -633,8 +655,10 @@ namespace DCFApixels.DragonECS /// as Union sets public void UnionWith(EcsSpan span) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS - if (_source.ID != span.WorldID) Throw.Group_ArgumentDifferentWorldsException(); +#if DEBUG + if (WorldID != span.WorldID) { Throw.Group_ArgumentDifferentWorldsException(); } +#elif DRAGONECS_STABILITY_MODE + if (WorldID != span.WorldID) { return; } #endif foreach (var entityID in span) { UnionWithStep(entityID); } } @@ -656,8 +680,10 @@ namespace DCFApixels.DragonECS /// as Except sets public void ExceptWith(EcsGroup group) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (_source != group._source) { Throw.Group_ArgumentDifferentWorldsException(); } +#elif DRAGONECS_STABILITY_MODE + if (_source != group._source) { return; } #endif if (group.Count > Count) //мини оптимизация, итеррируемся по короткому списку { @@ -681,8 +707,10 @@ namespace DCFApixels.DragonECS /// as Except sets public void ExceptWith(EcsSpan span) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS - if (_source.ID != span.WorldID) { Throw.Group_ArgumentDifferentWorldsException(); } +#if DEBUG + if (WorldID != span.WorldID) { Throw.Group_ArgumentDifferentWorldsException(); } +#elif DRAGONECS_STABILITY_MODE + if (WorldID != span.WorldID) { return; } #endif foreach (var entityID in span) { ExceptWithStep_Internal(entityID); } } @@ -704,8 +732,10 @@ namespace DCFApixels.DragonECS /// as Intersect sets public void IntersectWith(EcsGroup group) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (_source != group._source) { Throw.Group_ArgumentDifferentWorldsException(); } +#elif DRAGONECS_STABILITY_MODE + if (_source != group._source) { return; } #endif for (int i = _count; i > 0; i--)//итерация в обратном порядке исключает ошибки при удалении элементов { @@ -722,8 +752,10 @@ namespace DCFApixels.DragonECS /// as Intersect sets public void IntersectWith(EcsSpan span) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS - if (_source.ID != span.WorldID) { Throw.Group_ArgumentDifferentWorldsException(); } +#if DEBUG + if (WorldID != span.WorldID) { Throw.Group_ArgumentDifferentWorldsException(); } +#elif DRAGONECS_STABILITY_MODE + if (WorldID != span.WorldID) { return; } #endif foreach (var entityID in span) { @@ -765,8 +797,10 @@ namespace DCFApixels.DragonECS /// as Symmetric Except sets public void SymmetricExceptWith(EcsGroup group) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (_source != group._source) { Throw.Group_ArgumentDifferentWorldsException(); } +#elif DRAGONECS_STABILITY_MODE + if (_source != group._source) { return; } #endif foreach (var entityID in group) { SymmetricExceptWithStep_Internal(entityID); } } @@ -777,8 +811,10 @@ namespace DCFApixels.DragonECS /// as Symmetric Except sets public void SymmetricExceptWith(EcsSpan span) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS - if (_source.ID != span.WorldID) { Throw.Group_ArgumentDifferentWorldsException(); } +#if DEBUG + if (WorldID != span.WorldID) { Throw.Group_ArgumentDifferentWorldsException(); } +#elif DRAGONECS_STABILITY_MODE + if (WorldID != span.WorldID) { return; } #endif foreach (var entityID in span) { SymmetricExceptWithStep_Internal(entityID); } } @@ -827,8 +863,10 @@ namespace DCFApixels.DragonECS #region SetEquals public bool SetEquals(EcsGroup group) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS - if (_source != group.World) { Throw.Group_ArgumentDifferentWorldsException(); } +#if DEBUG + if (_source != group._source) { Throw.Group_ArgumentDifferentWorldsException(); } +#elif DRAGONECS_STABILITY_MODE + if (_source != group._source) { return false; } #endif if (group.Count != Count) { return false; } foreach (var entityID in group) @@ -844,8 +882,10 @@ namespace DCFApixels.DragonECS public bool SetEquals(EcsReadonlyGroup group) { return SetEquals(group.GetSource_Internal()); } public bool SetEquals(EcsSpan span) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS - if (_source.ID != span.WorldID) { Throw.Group_ArgumentDifferentWorldsException(); } +#if DEBUG + if (WorldID != span.WorldID) { Throw.Group_ArgumentDifferentWorldsException(); } +#elif DRAGONECS_STABILITY_MODE + if (WorldID != span.WorldID) { return false; } #endif if (span.Count != Count) { return false; } foreach (var entityID in span) @@ -874,8 +914,10 @@ namespace DCFApixels.DragonECS #region Overlaps public bool Overlaps(EcsGroup group) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS - if (_source != group.World) Throw.Group_ArgumentDifferentWorldsException(); +#if DEBUG + if (_source != group._source) { Throw.Group_ArgumentDifferentWorldsException(); } +#elif DRAGONECS_STABILITY_MODE + if (_source != group._source) { return false; } #endif if (group.Count > Count) { @@ -903,8 +945,10 @@ namespace DCFApixels.DragonECS public bool Overlaps(EcsReadonlyGroup group) { return Overlaps(group.GetSource_Internal()); } public bool Overlaps(EcsSpan span) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS - if (_source.ID != span.WorldID) Throw.Group_ArgumentDifferentWorldsException(); +#if DEBUG + if (WorldID != span.WorldID) { Throw.Group_ArgumentDifferentWorldsException(); } +#elif DRAGONECS_STABILITY_MODE + if (WorldID != span.WorldID) { return false; } #endif foreach (var entityID in span) { @@ -931,8 +975,10 @@ namespace DCFApixels.DragonECS #region IsSubsetOf/IsProperSubsetOf public bool IsSubsetOf(EcsGroup group) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS - if (_source != group._source) Throw.Group_ArgumentDifferentWorldsException(); +#if DEBUG + if (_source != group._source) { Throw.Group_ArgumentDifferentWorldsException(); } +#elif DRAGONECS_STABILITY_MODE + if (_source != group._source) { return false; } #endif if (Count == 0) { return true; } if (group.Count < Count) { return false; } @@ -942,8 +988,10 @@ namespace DCFApixels.DragonECS public bool IsSubsetOf(EcsReadonlyGroup group) { return IsSubsetOf(group.GetSource_Internal()); } public bool IsSubsetOf(EcsSpan span) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS - if (_source.ID != span.WorldID) Throw.Group_ArgumentDifferentWorldsException(); +#if DEBUG + if (WorldID != span.WorldID) { Throw.Group_ArgumentDifferentWorldsException(); } +#elif DRAGONECS_STABILITY_MODE + if (WorldID != span.WorldID) { return false; } #endif if (Count == 0) { return true; } if (span.Count < Count) { return false; } @@ -960,8 +1008,10 @@ namespace DCFApixels.DragonECS public bool IsProperSubsetOf(EcsGroup group) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS - if (_source != group._source) Throw.Group_ArgumentDifferentWorldsException(); +#if DEBUG + if (_source != group._source) { Throw.Group_ArgumentDifferentWorldsException(); } +#elif DRAGONECS_STABILITY_MODE + if (_source != group._source) { return false; } #endif if (Count == 0) { return true; } if (group.Count <= Count) { return false; } @@ -971,8 +1021,10 @@ namespace DCFApixels.DragonECS public bool IsProperSubsetOf(EcsReadonlyGroup group) { return IsProperSubsetOf(group.GetSource_Internal()); } public bool IsProperSubsetOf(EcsSpan span) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS - if (_source.ID != span.WorldID) Throw.Group_ArgumentDifferentWorldsException(); +#if DEBUG + if (WorldID != span.WorldID) { Throw.Group_ArgumentDifferentWorldsException(); } +#elif DRAGONECS_STABILITY_MODE + if (WorldID != span.WorldID) { return false; } #endif if (Count == 0) { return true; } if (span.Count <= Count) { return false; } @@ -1035,8 +1087,10 @@ namespace DCFApixels.DragonECS #region IsSupersetOf/IsProperSupersetOf public bool IsSupersetOf(EcsGroup group) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS - if (_source != group._source) Throw.Group_ArgumentDifferentWorldsException(); +#if DEBUG + if (_source != group._source) { Throw.Group_ArgumentDifferentWorldsException(); } +#elif DRAGONECS_STABILITY_MODE + if (_source != group._source) { return false; } #endif if (group.Count > Count) { return false; } return IsSupersetOf_Internal(group); @@ -1045,8 +1099,10 @@ namespace DCFApixels.DragonECS public bool IsSupersetOf(EcsReadonlyGroup group) { return IsSupersetOf(group.GetSource_Internal()); } public bool IsSupersetOf(EcsSpan span) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS - if (_source.ID != span.WorldID) Throw.Group_ArgumentDifferentWorldsException(); +#if DEBUG + if (WorldID != span.WorldID) { Throw.Group_ArgumentDifferentWorldsException(); } +#elif DRAGONECS_STABILITY_MODE + if (WorldID != span.WorldID) { return false; } #endif if (span.Count > Count) { return false; } return IsSupersetOf_Internal(span); @@ -1061,8 +1117,10 @@ namespace DCFApixels.DragonECS public bool IsProperSupersetOf(EcsGroup group) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS - if (_source != group._source) Throw.Group_ArgumentDifferentWorldsException(); +#if DEBUG + if (_source != group._source) { Throw.Group_ArgumentDifferentWorldsException(); } +#elif DRAGONECS_STABILITY_MODE + if (_source != group._source) { return false; } #endif if (group.Count >= Count) { return false; } return IsSupersetOf_Internal(group); @@ -1071,8 +1129,10 @@ namespace DCFApixels.DragonECS public bool IsProperSupersetOf(EcsReadonlyGroup group) { return IsProperSupersetOf(group.GetSource_Internal()); } public bool IsProperSupersetOf(EcsSpan span) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS - if (_source.ID != span.WorldID) Throw.Group_ArgumentDifferentWorldsException(); +#if DEBUG + if (WorldID != span.WorldID) { Throw.Group_ArgumentDifferentWorldsException(); } +#elif DRAGONECS_STABILITY_MODE + if (WorldID != span.WorldID) { return false; } #endif if (span.Count >= Count) { return false; } return IsSupersetOf_Internal(span); @@ -1129,8 +1189,10 @@ namespace DCFApixels.DragonECS /// new group from pool public static EcsGroup Union(EcsGroup a, EcsGroup b) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (a._source != b._source) { Throw.Group_ArgumentDifferentWorldsException(); } +#elif DRAGONECS_STABILITY_MODE + if (a._source != b._source) { return a.World.GetFreeGroup(); } #endif EcsGroup result = a._source.GetFreeGroup(); foreach (var entityID in a) @@ -1153,8 +1215,10 @@ namespace DCFApixels.DragonECS /// new group from pool public static EcsGroup Union(EcsSpan a, EcsSpan b) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (a.WorldID != b.WorldID) { Throw.Group_ArgumentDifferentWorldsException(); } +#elif DRAGONECS_STABILITY_MODE + if (a.WorldID != b.WorldID) { return a.World.GetFreeGroup(); } #endif EcsGroup result = a.World.GetFreeGroup(); foreach (var entityID in a) @@ -1174,8 +1238,10 @@ namespace DCFApixels.DragonECS /// new group from pool public static EcsGroup Except(EcsGroup a, EcsGroup b) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (a._source != b._source) { Throw.Group_ArgumentDifferentWorldsException(); } +#elif DRAGONECS_STABILITY_MODE + if (a._source != b._source) { return a.World.GetFreeGroup(); } #endif EcsGroup result = a._source.GetFreeGroup(); foreach (var entityID in a) @@ -1191,8 +1257,10 @@ namespace DCFApixels.DragonECS /// new group from pool public static EcsGroup Except(EcsSpan a, EcsGroup b) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS - if (a.WorldID != b._source.ID) { Throw.Group_ArgumentDifferentWorldsException(); } +#if DEBUG + if (a.WorldID != b.WorldID) { Throw.Group_ArgumentDifferentWorldsException(); } +#elif DRAGONECS_STABILITY_MODE + if (a.WorldID != b.WorldID) { return a.World.GetFreeGroup(); } #endif EcsGroup result = b._source.GetFreeGroup(); foreach (var entityID in a) @@ -1208,8 +1276,10 @@ namespace DCFApixels.DragonECS /// new group from pool public static EcsGroup Except(EcsSpan a, EcsSpan b) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (a.WorldID != b.WorldID) { Throw.Group_ArgumentDifferentWorldsException(); } +#elif DRAGONECS_STABILITY_MODE + if (a.WorldID != b.WorldID) { return a.World.GetFreeGroup(); } #endif EcsGroup result = a.World.GetFreeGroup(); result.CopyFrom(a); @@ -1229,8 +1299,10 @@ namespace DCFApixels.DragonECS /// new group from pool public static EcsGroup Intersect(EcsGroup a, EcsGroup b) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (a._source != b._source) { Throw.Group_ArgumentDifferentWorldsException(); } +#elif DRAGONECS_STABILITY_MODE + if (a._source != b._source) { return a.World.GetFreeGroup(); } #endif EcsGroup result = a._source.GetFreeGroup(); foreach (var entityID in a) @@ -1246,8 +1318,10 @@ namespace DCFApixels.DragonECS /// new group from pool public static EcsGroup Intersect(EcsSpan a, EcsGroup b) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS - if (a.WorldID != b._source.ID) { Throw.Group_ArgumentDifferentWorldsException(); } +#if DEBUG + if (a.WorldID != b.WorldID) { Throw.Group_ArgumentDifferentWorldsException(); } +#elif DRAGONECS_STABILITY_MODE + if (a.WorldID != b.WorldID) { return a.World.GetFreeGroup(); } #endif EcsGroup result = b._source.GetFreeGroup(); foreach (var entityID in a) @@ -1270,8 +1344,10 @@ namespace DCFApixels.DragonECS /// new group from pool public static EcsGroup Intersect(EcsSpan a, EcsSpan b) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (a.WorldID != b.WorldID) { Throw.Group_ArgumentDifferentWorldsException(); } +#elif DRAGONECS_STABILITY_MODE + if (a.WorldID != b.WorldID) { return a.World.GetFreeGroup(); } #endif EcsGroup result = b.World.GetFreeGroup(); result.CopyFrom(a); @@ -1291,8 +1367,10 @@ namespace DCFApixels.DragonECS /// new group from pool public static EcsGroup SymmetricExcept(EcsGroup a, EcsGroup b) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (a._source != b._source) { Throw.Group_ArgumentDifferentWorldsException(); } +#elif DRAGONECS_STABILITY_MODE + if (a._source != b._source) { return a.World.GetFreeGroup(); } #endif EcsGroup result = a._source.GetFreeGroup(); foreach (var entityID in a) @@ -1315,8 +1393,10 @@ namespace DCFApixels.DragonECS /// new group from pool public static EcsGroup SymmetricExcept(EcsSpan a, EcsSpan b) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (a.WorldID != b.WorldID) { Throw.Group_ArgumentDifferentWorldsException(); } +#elif DRAGONECS_STABILITY_MODE + if (a.WorldID != b.WorldID) { return a.World.GetFreeGroup(); } #endif EcsGroup result = a.World.GetFreeGroup(); result.CopyFrom(a); diff --git a/src/Consts.cs b/src/Consts.cs index 1cf09da..2fdd0f7 100644 --- a/src/Consts.cs +++ b/src/Consts.cs @@ -1,4 +1,6 @@ -namespace DCFApixels.DragonECS +using System; + +namespace DCFApixels.DragonECS { public static class EcsConsts { @@ -23,6 +25,8 @@ public const int MAGIC_PRIME = 314159; + public const int NULL_ENTITY_ID = 0; + public const short NULL_WORLD_ID = 0; /// meta subgroups public const string PACK_GROUP = "_" + FRAMEWORK_NAME + "/_Core"; @@ -44,27 +48,32 @@ //TODO заменить ENABLE_DRAGONECS_ASSERT_CHEKS на DEV_MODE и добавить еще PERF_MODE и STAB_MODE public static class EcsDefines { - public const bool DISABLE_POOLS_EVENTS = -#if DISABLE_POOLS_EVENTS - true; -#else - false; -#endif - public const bool ENABLE_DRAGONECS_DEBUGGER = -#if ENABLE_DRAGONECS_DEBUGGER + public const bool DRAGONECS_ENABLE_DRAGONECS_DEBUGGER = +#if DRAGONECS_ENABLE_DRAGONECS_DEBUGGER true; #else false; #endif - public const bool ENABLE_DRAGONECS_ASSERT_CHEKS = -#if ENABLE_DRAGONECS_ASSERT_CHEKS + public const bool DRAGONECS_DISABLE_POOLS_EVENTS = +#if DRAGONECS_DISABLE_POOLS_EVENTS true; #else false; #endif - - public const bool REFLECTION_DISABLED = -#if REFLECTION_DISABLED + public const bool DRAGONECS_DISABLE_CATH_EXCEPTIONS = +#if DRAGONECS_DISABLE_CATH_EXCEPTIONS + true; +#else + false; +#endif + public const bool DRAGONECS_STABILITY_MODE = +#if DRAGONECS_STABILITY_MODE + true; +#else + false; +#endif + public const bool DRAGONECS_DEEP_DEBUG = +#if DRAGONECS_DEEP_DEBUG true; #else false; @@ -75,35 +84,46 @@ #else false; #endif - - public const bool ENABLE_DUMMY_SPAN = -#if ENABLE_DUMMY_SPAN + public const bool REFLECTION_DISABLED = +#if REFLECTION_DISABLED true; #else false; #endif + + + + [Obsolete] + public const bool ENABLE_DRAGONECS_DEBUGGER = +#if DRAGONECS_ENABLE_DRAGONECS_DEBUGGER + true; +#else + false; +#endif + [Obsolete] + public const bool DISABLE_POOLS_EVENTS = +#if DRAGONECS_DISABLE_POOLS_EVENTS + true; +#else + false; +#endif + [Obsolete] public const bool DISABLE_CATH_EXCEPTIONS = #if DISABLE_CATH_EXCEPTIONS true; #else false; #endif - - - public const bool DRAGONECS_PERF_MODE = -#if DRAGONECS_PERF_MODE - true; + [Obsolete] + public const bool ENABLE_DRAGONECS_ASSERT_CHEKS = +#if ENABLE_DRAGONECS_ASSERT_CHEKS + true; #else false; #endif - public const bool DRAGONECS_STAB_MODE = -#if DRAGONECS_STAB_MODE - true; -#else - false; -#endif - public const bool DRAGONECS_DEEP_DEBUG = -#if DRAGONECS_DEEP_DEBUG + [Obsolete] + public const bool ENABLE_DUMMY_SPAN = +#if ENABLE_DUMMY_SPAN true; #else false; diff --git a/src/DebugUtils/EcsDebug.cs b/src/DebugUtils/EcsDebug.cs index 2fa721f..7b70d1e 100644 --- a/src/DebugUtils/EcsDebug.cs +++ b/src/DebugUtils/EcsDebug.cs @@ -13,39 +13,39 @@ namespace DCFApixels.DragonECS using static EcsConsts; public readonly struct EcsProfilerMarker { -#if DEBUG || ENABLE_DRAGONECS_DEBUGGER +#if DEBUG || DRAGONECS_ENABLE_DRAGONECS_DEBUGGER public readonly int id; #endif internal EcsProfilerMarker(int id) { -#if DEBUG || ENABLE_DRAGONECS_DEBUGGER +#if DEBUG || DRAGONECS_ENABLE_DRAGONECS_DEBUGGER this.id = id; #endif } public EcsProfilerMarker(string name) { -#if DEBUG || ENABLE_DRAGONECS_DEBUGGER +#if DEBUG || DRAGONECS_ENABLE_DRAGONECS_DEBUGGER id = DebugService.CurrentThreadInstance.RegisterMark(name); #endif } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Begin() { -#if DEBUG || ENABLE_DRAGONECS_DEBUGGER +#if DEBUG || DRAGONECS_ENABLE_DRAGONECS_DEBUGGER DebugService.CurrentThreadInstance.ProfilerMarkBegin(id); #endif } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void End() { -#if DEBUG || ENABLE_DRAGONECS_DEBUGGER +#if DEBUG || DRAGONECS_ENABLE_DRAGONECS_DEBUGGER DebugService.CurrentThreadInstance.ProfilerMarkEnd(id); #endif } [MethodImpl(MethodImplOptions.AggressiveInlining)] public AutoScope Auto() { -#if DEBUG || ENABLE_DRAGONECS_DEBUGGER +#if DEBUG || DRAGONECS_ENABLE_DRAGONECS_DEBUGGER return new AutoScope(id); #else return default; @@ -53,13 +53,13 @@ namespace DCFApixels.DragonECS } public readonly ref struct AutoScope { -#if DEBUG || ENABLE_DRAGONECS_DEBUGGER +#if DEBUG || DRAGONECS_ENABLE_DRAGONECS_DEBUGGER private readonly int _id; #endif [MethodImpl(MethodImplOptions.AggressiveInlining)] public AutoScope(int id) { -#if DEBUG || ENABLE_DRAGONECS_DEBUGGER +#if DEBUG || DRAGONECS_ENABLE_DRAGONECS_DEBUGGER _id = id; DebugService.CurrentThreadInstance.ProfilerMarkBegin(id); #endif @@ -67,7 +67,7 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Dispose() { -#if DEBUG || ENABLE_DRAGONECS_DEBUGGER +#if DEBUG || DRAGONECS_ENABLE_DRAGONECS_DEBUGGER DebugService.CurrentThreadInstance.ProfilerMarkEnd(_id); #endif } @@ -94,7 +94,7 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void PrintWarning(object v) { -#if DEBUG || ENABLE_DRAGONECS_DEBUGGER +#if DEBUG || DRAGONECS_ENABLE_DRAGONECS_DEBUGGER OnPrint(DEBUG_WARNING_TAG, v); DebugService.CurrentThreadInstance.PrintWarning(v); #endif @@ -102,7 +102,7 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void PrintError(object v) { -#if DEBUG || ENABLE_DRAGONECS_DEBUGGER +#if DEBUG || DRAGONECS_ENABLE_DRAGONECS_DEBUGGER OnPrint(DEBUG_ERROR_TAG, v); DebugService.CurrentThreadInstance.PrintError(v); #endif @@ -110,7 +110,7 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void PrintErrorAndBreak(object v) { -#if DEBUG || ENABLE_DRAGONECS_DEBUGGER +#if DEBUG || DRAGONECS_ENABLE_DRAGONECS_DEBUGGER OnPrint(DEBUG_ERROR_TAG, v); DebugService.CurrentThreadInstance.PrintErrorAndBreak(v); #endif @@ -118,7 +118,7 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void PrintPass(object v) { -#if DEBUG || ENABLE_DRAGONECS_DEBUGGER +#if DEBUG || DRAGONECS_ENABLE_DRAGONECS_DEBUGGER OnPrint(DEBUG_PASS_TAG, v); DebugService.CurrentThreadInstance.PrintPass(v); #endif @@ -126,7 +126,7 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Print() { -#if DEBUG || ENABLE_DRAGONECS_DEBUGGER +#if DEBUG || DRAGONECS_ENABLE_DRAGONECS_DEBUGGER OnPrint(string.Empty, null); DebugService.CurrentThreadInstance.Print(); #endif @@ -134,7 +134,7 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Print(object v) { -#if DEBUG || ENABLE_DRAGONECS_DEBUGGER +#if DEBUG || DRAGONECS_ENABLE_DRAGONECS_DEBUGGER OnPrint(string.Empty, v); DebugService.CurrentThreadInstance.Print(v); #endif @@ -142,7 +142,7 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Print(string tag, object v) { -#if DEBUG || ENABLE_DRAGONECS_DEBUGGER +#if DEBUG || DRAGONECS_ENABLE_DRAGONECS_DEBUGGER OnPrint(tag, v); DebugService.CurrentThreadInstance.Print(tag, v); #endif @@ -150,7 +150,7 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Break() { -#if DEBUG || ENABLE_DRAGONECS_DEBUGGER +#if DEBUG || DRAGONECS_ENABLE_DRAGONECS_DEBUGGER DebugService.CurrentThreadInstance.Break(); #endif } diff --git a/src/EcsPipeline.Builder.cs b/src/EcsPipeline.Builder.cs index a44a608..d66f6d3 100644 --- a/src/EcsPipeline.Builder.cs +++ b/src/EcsPipeline.Builder.cs @@ -301,12 +301,12 @@ namespace DCFApixels.DragonECS #endregion #region Build -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG private static EcsProfilerMarker _buildMarker = new EcsProfilerMarker("EcsPipeline.Build"); #endif public EcsPipeline Build() { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG _buildMarker.Begin(); #endif var it = new LinkedListIterator(_systemNodes, _systemNodesCount, _startIndex); @@ -372,7 +372,7 @@ namespace DCFApixels.DragonECS { item.Declare(pipeline); } -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG _buildMarker.End(); #endif return pipeline; diff --git a/src/EcsPipeline.cs b/src/EcsPipeline.cs index 3c0d1be..6ad2331 100644 --- a/src/EcsPipeline.cs +++ b/src/EcsPipeline.cs @@ -45,7 +45,7 @@ namespace DCFApixels.DragonECS private bool _isInit = false; private bool _isDestoryed = false; -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG private static EcsProfilerMarker _initMarker = new EcsProfilerMarker("EcsPipeline.Init"); #endif @@ -188,7 +188,7 @@ namespace DCFApixels.DragonECS EcsDebug.PrintWarning($"This {nameof(EcsPipeline)} has already been initialized"); return; } -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG _initMarker.Begin(); #endif @@ -199,7 +199,7 @@ namespace DCFApixels.DragonECS _isInit = true; GC.Collect(); -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG _initMarker.End(); #endif } @@ -207,7 +207,7 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Run() { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG || DRAGONECS_STABILITY_MODE if (!_isInit) { Throw.Pipeline_MethodCalledBeforeInitialisation(nameof(Run)); } if (_isDestoryed) { Throw.Pipeline_MethodCalledAfterDestruction(nameof(Run)); } #endif @@ -215,7 +215,7 @@ namespace DCFApixels.DragonECS } public void Destroy() { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG || DRAGONECS_STABILITY_MODE if (!_isInit) { Throw.Pipeline_MethodCalledBeforeInitialisation(nameof(Destroy)); } #endif if (_isDestoryed) diff --git a/src/EcsRunner.cs b/src/EcsRunner.cs index 47f2cff..757540d 100644 --- a/src/EcsRunner.cs +++ b/src/EcsRunner.cs @@ -210,7 +210,7 @@ namespace DCFApixels.DragonECS } catch (Exception e) { -#if DISABLE_CATH_EXCEPTIONS +#if DRAGONECS_DISABLE_CATH_EXCEPTIONS throw; #endif EcsDebug.PrintError(e); @@ -226,7 +226,7 @@ namespace DCFApixels.DragonECS } catch (Exception e) { -#if DISABLE_CATH_EXCEPTIONS +#if DRAGONECS_DISABLE_CATH_EXCEPTIONS throw; #endif EcsDebug.PrintError(e); @@ -249,7 +249,7 @@ namespace DCFApixels.DragonECS } catch (Exception e) { -#if DISABLE_CATH_EXCEPTIONS +#if DRAGONECS_DISABLE_CATH_EXCEPTIONS throw; #endif EcsDebug.PrintError(e); @@ -265,7 +265,7 @@ namespace DCFApixels.DragonECS } catch (Exception e) { -#if DISABLE_CATH_EXCEPTIONS +#if DRAGONECS_DISABLE_CATH_EXCEPTIONS throw; #endif EcsDebug.PrintError(e); @@ -375,7 +375,7 @@ namespace DCFApixels.DragonECS } catch (Exception e) { -#if DISABLE_CATH_EXCEPTIONS +#if DRAGONECS_DISABLE_CATH_EXCEPTIONS throw; #endif EcsDebug.PrintError(e); @@ -398,7 +398,7 @@ namespace DCFApixels.DragonECS } catch (Exception e) { -#if DISABLE_CATH_EXCEPTIONS +#if DRAGONECS_DISABLE_CATH_EXCEPTIONS throw; #endif EcsDebug.PrintError(e); @@ -429,7 +429,7 @@ namespace DCFApixels.DragonECS } catch (Exception e) { -#if DISABLE_CATH_EXCEPTIONS +#if DRAGONECS_DISABLE_CATH_EXCEPTIONS throw; #endif EcsDebug.PrintError(e); @@ -452,7 +452,7 @@ namespace DCFApixels.DragonECS } catch (Exception e) { -#if DISABLE_CATH_EXCEPTIONS +#if DRAGONECS_DISABLE_CATH_EXCEPTIONS throw; #endif EcsDebug.PrintError(e); diff --git a/src/EcsStaticMask.cs b/src/EcsStaticMask.cs index a84672f..b07197d 100644 --- a/src/EcsStaticMask.cs +++ b/src/EcsStaticMask.cs @@ -342,15 +342,19 @@ namespace DCFApixels.DragonECS #region Inc/Exc/Combine/Except public void Inc(EcsTypeCode typeCode) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (_inc.Contains(typeCode) || _exc.Contains(typeCode)) { Throw.ConstraintIsAlreadyContainedInMask(typeCode); } +#elif DRAGONECS_STABILITY_MODE + if (_inc.Contains(typeCode) || _exc.Contains(typeCode)) { return; } #endif _inc.Add(typeCode); } public void Exc(EcsTypeCode typeCode) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (_inc.Contains(typeCode) || _exc.Contains(typeCode)) { Throw.ConstraintIsAlreadyContainedInMask(typeCode); } +#elif DRAGONECS_STABILITY_MODE + if (_inc.Contains(typeCode) || _exc.Contains(typeCode)) { return; } #endif _exc.Add(typeCode); } diff --git a/src/EcsWorld.cs b/src/EcsWorld.cs index a99bab7..e4d6ff9 100644 --- a/src/EcsWorld.cs +++ b/src/EcsWorld.cs @@ -331,8 +331,10 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] public int NewEntity(int entityID) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS - if (entityID < _entities.Length && IsUsed(entityID)) { Throw.World_EntityIsAlreadyСontained(entityID); } +#if DEBUG + if (IsUsed(entityID)) { Throw.World_EntityIsAlreadyСontained(entityID); } +#elif DRAGONECS_STABILITY_MODE + if (IsUsed(entityID)) { return 0; } #endif _entityDispenser.Use(entityID); CreateConcreteEntity(entityID); @@ -381,8 +383,10 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] public void DelEntity(int entityID) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS - if (IsUsed(entityID) == false) { Throw.World_EntityIsNotContained(entityID); } +#if DEBUG + if (IsUsed(entityID) == false) { Throw.World_EntityIsAlreadyСontained(entityID); } +#elif DRAGONECS_STABILITY_MODE + if (IsUsed(entityID) == false) { return; } #endif UpVersion(); _delEntBuffer[_delEntBufferCount++] = entityID; @@ -411,8 +415,10 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] public void InitEntitySlot(int entityID, short gen) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (Count > 0) { Throw.World_MethodCalledAfterEntityCreation(nameof(InitEntitySlot)); } +#elif DRAGONECS_STABILITY_MODE + if (Count > 0) { return; } #endif _entityDispenser.Upsize(entityID); _entities[entityID].gen = gen; @@ -431,8 +437,10 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool IsAlive(entlong entity) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (entity.GetWorldIDUnchecked() != ID) { Throw.World_MaskDoesntBelongWorld(); } +#elif DRAGONECS_STABILITY_MODE + if (entity.GetWorldIDUnchecked() != ID) { return false; } #endif ref var slot = ref _entities[entity.GetIDUnchecked()]; return slot.gen == entity.GetIDUnchecked() && slot.isUsed; @@ -468,8 +476,10 @@ namespace DCFApixels.DragonECS } public bool IsMatchesMask(EcsMask mask, int entityID) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (mask.WorldID != ID) { Throw.World_MaskDoesntBelongWorld(); } +#elif DRAGONECS_STABILITY_MODE + if (mask.WorldID != ID) { return false; } #endif for (int i = 0, iMax = mask._incs.Length; i < iMax; i++) { diff --git a/src/EcsWorld.pools.cs b/src/EcsWorld.pools.cs index 6ed215b..178aa78 100644 --- a/src/EcsWorld.pools.cs +++ b/src/EcsWorld.pools.cs @@ -18,7 +18,7 @@ namespace DCFApixels.DragonECS internal PoolSlot[] _poolSlots; private int _poolsCount; -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG || DRAGONECS_STABILITY_MODE private int _lockedPoolCount = 0; #endif @@ -152,8 +152,10 @@ namespace DCFApixels.DragonECS #region FindOrAutoCreatePool/InitPool public void InitPool(IEcsPoolImplementation poolImplementation) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (Count > 0) { Throw.World_MethodCalledAfterEntityCreation(nameof(InitEntitySlot)); } +#elif DRAGONECS_STABILITY_MODE + if (Count > 0) { return; } #endif InitPool_Internal(poolImplementation); } @@ -165,7 +167,7 @@ namespace DCFApixels.DragonECS if (_poolTypeCode_2_CmpTypeIDs.TryGetValue(poolTypeCode, out int cmpTypeID)) { var pool = _pools[cmpTypeID]; -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG || DRAGONECS_STABILITY_MODE if ((pool is TPool) == false) { Throw.UndefinedException(); } #endif return (TPool)pool; @@ -282,11 +284,12 @@ namespace DCFApixels.DragonECS { DelEntity(entityID); } -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS - if (count < 0) Throw.World_InvalidIncrementComponentsBalance(); -#endif + CheckUnregisterValid(count, entityID); + } + private Span GetEntityComponentMask(int entityID) + { + return new Span(_entityComponentMasks, entityID << _entityComponentMaskLengthBitShift, _entityComponentMaskLength); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] private bool TryRegisterEntityComponent(int entityID, int componentTypeID, EcsMaskChunck maskBit) @@ -323,13 +326,26 @@ namespace DCFApixels.DragonECS { DelEntity(entityID); } -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS - if (count < 0) Throw.World_InvalidIncrementComponentsBalance(); -#endif + CheckUnregisterValid(count, entityID); return true; } return false; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private void CheckUnregisterValid(int count, int entityID) + { +#if DEBUG + if (count < 0) { Throw.World_InvalidIncrementComponentsBalance(); } +#elif DRAGONECS_STABILITY_MODE + if (count < 0) + { + var mask = GetEntityComponentMask(entityID); + for (int i = 0; i < mask.Length; i++) { mask[i] = 0; } + //TODO добавить очистку пулов + _entities[entityID].componentsCount = 0; + } +#endif + } [MethodImpl(MethodImplOptions.AggressiveInlining)] private int GetPoolComponentCount(int componentTypeID) @@ -402,7 +418,7 @@ namespace DCFApixels.DragonECS #region LockPool/UnLockPool public void LockPool_Debug(int componentTypeID) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG || DRAGONECS_STABILITY_MODE ref var slot = ref _poolSlots[componentTypeID]; if (slot.lockedCounter == 0) { @@ -416,7 +432,7 @@ namespace DCFApixels.DragonECS } public void UnlockPool_Debug(int componentTypeID) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG || DRAGONECS_STABILITY_MODE ref var slot = ref _poolSlots[componentTypeID]; slot.lockedCounter--; if (slot.lockedCounter <= 0) @@ -434,7 +450,7 @@ namespace DCFApixels.DragonECS } public bool CheckPoolLocked_Debug(int componentTypeID) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG || DRAGONECS_STABILITY_MODE return _poolSlots[componentTypeID].lockedCounter != 0; #else return false; @@ -447,7 +463,7 @@ namespace DCFApixels.DragonECS { public long version; public int count; -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG || DRAGONECS_STABILITY_MODE public int lockedCounter; #endif } diff --git a/src/EcsWorld.static.cs b/src/EcsWorld.static.cs index 8e76d0e..6e26f9f 100644 --- a/src/EcsWorld.static.cs +++ b/src/EcsWorld.static.cs @@ -41,6 +41,15 @@ namespace DCFApixels.DragonECS {// ts return _worlds[worldID]; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool TryGetWorld(short worldID, out EcsWorld world) + {// ts + world = _worlds[worldID]; + return + world != null && + world.IsDestroyed != false && + worldID != 0; + } private void ReleaseData(short worldID) {// ts @@ -146,7 +155,7 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ref T GetForWorldUnchecked(short worldID) {// ts -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (_mapping[worldID] <= 0) { Throw.ArgumentOutOfRange(); } #endif return ref _items[_mapping[worldID]]; diff --git a/src/Executors/EcsWhereExecutor.cs b/src/Executors/EcsWhereExecutor.cs index 9ee401c..c35a6d6 100644 --- a/src/Executors/EcsWhereExecutor.cs +++ b/src/Executors/EcsWhereExecutor.cs @@ -74,7 +74,7 @@ namespace DCFApixels.DragonECS.Internal [MethodImpl(MethodImplOptions.AggressiveInlining)] private void ExecuteFor_Iternal(EcsSpan span) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG || DRAGONECS_STABILITY_MODE if (span.IsNull) { Throw.ArgumentNull(nameof(span)); } if (span.WorldID != World.ID) { Throw.Quiery_ArgumentDifferentWorldsException(); } #endif diff --git a/src/Executors/EcsWhereToGroupExecutor.cs b/src/Executors/EcsWhereToGroupExecutor.cs index 150fde9..7765503 100644 --- a/src/Executors/EcsWhereToGroupExecutor.cs +++ b/src/Executors/EcsWhereToGroupExecutor.cs @@ -73,7 +73,7 @@ namespace DCFApixels.DragonECS.Internal [MethodImpl(MethodImplOptions.AggressiveInlining)] private void ExecuteFor_Iternal(EcsSpan span) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG || DRAGONECS_STABILITY_MODE if (span.IsNull) { Throw.ArgumentNull(nameof(span)); } if (span.WorldID != World.ID) { Throw.Quiery_ArgumentDifferentWorldsException(); } #endif diff --git a/src/Injections/Injector.cs b/src/Injections/Injector.cs index 151f612..7d3958f 100644 --- a/src/Injections/Injector.cs +++ b/src/Injections/Injector.cs @@ -16,7 +16,7 @@ namespace DCFApixels.DragonECS private Dictionary _nodes = new Dictionary(32); private bool _isInit = false; -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG private HashSet _requiredInjectionTypes = new HashSet(); #endif @@ -50,7 +50,7 @@ namespace DCFApixels.DragonECS branch = new InjectionBranch(this, objType); InitBranch(branch); -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG foreach (var requiredInjectionType in _requiredInjectionTypes) { if (requiredInjectionType.IsAssignableFrom(objType)) @@ -144,7 +144,7 @@ namespace DCFApixels.DragonECS } _isInit = true; -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG var systems = _pipeline.AllSystems; var injectType = typeof(IEcsInject<>); foreach (var system in systems) diff --git a/src/Pools/EcsPool.cs b/src/Pools/EcsPool.cs index 455e46f..f22a3a8 100644 --- a/src/Pools/EcsPool.cs +++ b/src/Pools/EcsPool.cs @@ -39,8 +39,8 @@ namespace DCFApixels.DragonECS private int _componentTypeID; private EcsMaskChunck _maskBit; - private int[] _mapping;// index = entityID / value = itemIndex;/ value = 0 = no entityID - private T[] _items; //dense + private int[] _mapping;// index = entityID / value = itemIndex;/ value = 0 = no entityID. + private T[] _items; // dense; _items[0] - fake component. private int _itemsCount = 0; private int[] _recycledItems; private int _recycledItemsCount = 0; @@ -50,7 +50,7 @@ namespace DCFApixels.DragonECS private readonly IEcsComponentCopy _componentCopyHandler = EcsComponentCopyHandler.instance; private readonly bool _isHasComponentCopyHandler = EcsComponentCopyHandler.isHasHandler; -#if !DISABLE_POOLS_EVENTS +#if !DRAGONECS_DISABLE_POOLS_EVENTS private StructList _listeners = new StructList(2); private int _listenersCachedCount = 0; #endif @@ -94,9 +94,12 @@ namespace DCFApixels.DragonECS public ref T Add(int entityID) { ref int itemIndex = ref _mapping[entityID]; -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (itemIndex > 0) { EcsPoolThrowHelper.ThrowAlreadyHasComponent(entityID); } if (_isLocked) { EcsPoolThrowHelper.ThrowPoolLocked(); } +#elif DRAGONECS_STABILITY_MODE + if (itemIndex > 0) { return ref Get(entityID); } + if (_isLocked) { return ref _items[0]; } #endif if (_recycledItemsCount > 0) { @@ -114,7 +117,7 @@ namespace DCFApixels.DragonECS _mediator.RegisterComponent(entityID, _componentTypeID, _maskBit); ref T result = ref _items[itemIndex]; EnableComponent(ref result); -#if !DISABLE_POOLS_EVENTS +#if !DRAGONECS_DISABLE_POOLS_EVENTS _listeners.InvokeOnAddAndGet(entityID, _listenersCachedCount); #endif return ref result; @@ -122,10 +125,10 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] public ref T Get(int entityID) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG // STAB_MODE if (!Has(entityID)) { EcsPoolThrowHelper.ThrowNotHaveComponent(entityID); } #endif -#if !DISABLE_POOLS_EVENTS +#if !DRAGONECS_DISABLE_POOLS_EVENTS _listeners.InvokeOnGet(entityID, _listenersCachedCount); #endif return ref _items[_mapping[entityID]]; @@ -133,7 +136,7 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] public ref readonly T Read(int entityID) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG // STAB_MODE if (!Has(entityID)) { EcsPoolThrowHelper.ThrowNotHaveComponent(entityID); } #endif return ref _items[_mapping[entityID]]; @@ -143,8 +146,10 @@ namespace DCFApixels.DragonECS ref int itemIndex = ref _mapping[entityID]; if (itemIndex <= 0) { //Add block -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (_isLocked) { EcsPoolThrowHelper.ThrowPoolLocked(); } +#elif DRAGONECS_STABILITY_MODE + if (_isLocked) { return ref _items[0]; } #endif if (_recycledItemsCount > 0) { @@ -161,11 +166,11 @@ namespace DCFApixels.DragonECS } _mediator.RegisterComponent(entityID, _componentTypeID, _maskBit); EnableComponent(ref _items[itemIndex]); -#if !DISABLE_POOLS_EVENTS +#if !DRAGONECS_DISABLE_POOLS_EVENTS _listeners.InvokeOnAdd(entityID, _listenersCachedCount); #endif } //Add block end -#if !DISABLE_POOLS_EVENTS +#if !DRAGONECS_DISABLE_POOLS_EVENTS _listeners.InvokeOnGet(entityID, _listenersCachedCount); #endif return ref _items[itemIndex]; @@ -177,12 +182,13 @@ namespace DCFApixels.DragonECS } public void Del(int entityID) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS - if (_isLocked) { EcsPoolThrowHelper.ThrowPoolLocked(); } -#endif ref int itemIndex = ref _mapping[entityID]; -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (itemIndex <= 0) { EcsPoolThrowHelper.ThrowNotHaveComponent(entityID); } + if (_isLocked) { EcsPoolThrowHelper.ThrowPoolLocked(); } +#elif DRAGONECS_STABILITY_MODE + if (itemIndex <= 0) { return; } + if (_isLocked) { return; } #endif DisableComponent(ref _items[itemIndex]); if (_recycledItemsCount >= _recycledItems.Length) @@ -193,7 +199,7 @@ namespace DCFApixels.DragonECS itemIndex = 0; _itemsCount--; _mediator.UnregisterComponent(entityID, _componentTypeID, _maskBit); -#if !DISABLE_POOLS_EVENTS +#if !DRAGONECS_DISABLE_POOLS_EVENTS _listeners.InvokeOnDel(entityID, _listenersCachedCount); #endif } @@ -206,23 +212,29 @@ namespace DCFApixels.DragonECS } public void Copy(int fromEntityID, int toEntityID) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (!Has(fromEntityID)) { EcsPoolThrowHelper.ThrowNotHaveComponent(fromEntityID); } +#elif DRAGONECS_STABILITY_MODE + if (!Has(fromEntityID)) { return; } #endif CopyComponent(ref Get(fromEntityID), ref TryAddOrGet(toEntityID)); } public void Copy(int fromEntityID, EcsWorld toWorld, int toEntityID) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (!Has(fromEntityID)) { EcsPoolThrowHelper.ThrowNotHaveComponent(fromEntityID); } +#elif DRAGONECS_STABILITY_MODE + if (!Has(fromEntityID)) { return; } #endif CopyComponent(ref Get(fromEntityID), ref toWorld.GetPool().TryAddOrGet(toEntityID)); } public void ClearAll() { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (_isLocked) { EcsPoolThrowHelper.ThrowPoolLocked(); } +#elif DRAGONECS_STABILITY_MODE + if (_isLocked) { return; } #endif _recycledItemsCount = 0; // , Del if (_itemsCount <= 0) { return; } @@ -234,7 +246,7 @@ namespace DCFApixels.DragonECS DisableComponent(ref _items[itemIndex]); itemIndex = 0; _mediator.UnregisterComponent(entityID, _componentTypeID, _maskBit); -#if !DISABLE_POOLS_EVENTS +#if !DRAGONECS_DISABLE_POOLS_EVENTS _listeners.InvokeOnDel(entityID, _listenersCachedCount); #endif } @@ -290,7 +302,7 @@ namespace DCFApixels.DragonECS #endregion #region Listeners -#if !DISABLE_POOLS_EVENTS +#if !DRAGONECS_DISABLE_POOLS_EVENTS public void AddListener(IEcsPoolEventListener listener) { if (listener == null) { EcsPoolThrowHelper.ThrowNullListener(); } diff --git a/src/Pools/EcsPoolBase.cs b/src/Pools/EcsPoolBase.cs index 8b2a067..a34e156 100644 --- a/src/Pools/EcsPoolBase.cs +++ b/src/Pools/EcsPoolBase.cs @@ -164,7 +164,7 @@ namespace DCFApixels.DragonECS.Internal #endregion #region Listeners -#if !DISABLE_POOLS_EVENTS +#if !DRAGONECS_DISABLE_POOLS_EVENTS void IEcsReadonlyPool.AddListener(IEcsPoolEventListener listener) { } void IEcsReadonlyPool.RemoveListener(IEcsPoolEventListener listener) { } #endif @@ -193,7 +193,7 @@ namespace DCFApixels.DragonECS void Copy(int fromEntityID, EcsWorld toWorld, int toEntityID); #endregion -#if !DISABLE_POOLS_EVENTS +#if !DRAGONECS_DISABLE_POOLS_EVENTS #region Add/Remove Listeners void AddListener(IEcsPoolEventListener listener); void RemoveListener(IEcsPoolEventListener listener); @@ -262,7 +262,7 @@ namespace DCFApixels.DragonECS /// Called after deleting an entity from the pool void OnDel(int entityID); } -#if !DISABLE_POOLS_EVENTS +#if !DRAGONECS_DISABLE_POOLS_EVENTS public static class PoolEventListExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/Pools/EcsTagPool.cs b/src/Pools/EcsTagPool.cs index 5bc9694..a438546 100644 --- a/src/Pools/EcsTagPool.cs +++ b/src/Pools/EcsTagPool.cs @@ -2,14 +2,14 @@ #undef DEBUG #endif using DCFApixels.DragonECS.Core; +using DCFApixels.DragonECS.Internal; using DCFApixels.DragonECS.PoolsCore; using System; using System.Collections; using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Diagnostics; -using DCFApixels.DragonECS.Internal; using System.ComponentModel; +using System.Diagnostics; +using System.Runtime.CompilerServices; #if ENABLE_IL2CPP using Unity.IL2CPP.CompilerServices; #endif @@ -42,7 +42,7 @@ namespace DCFApixels.DragonECS private bool[] _mapping;// index = entityID / value = itemIndex;/ value = 0 = no entityID private int _count = 0; -#if !DISABLE_POOLS_EVENTS +#if !DRAGONECS_DISABLE_POOLS_EVENTS private StructList _listeners = new StructList(2); private int _listenersCachedCount = 0; #endif @@ -103,14 +103,16 @@ namespace DCFApixels.DragonECS #region Method public void Add(int entityID) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (Has(entityID)) { EcsPoolThrowHelper.ThrowAlreadyHasComponent(entityID); } if (_isLocked) { EcsPoolThrowHelper.ThrowPoolLocked(); } +#elif DRAGONECS_STABILITY_MODE + if (Has(entityID) || _isLocked) { return; } #endif _count++; _mapping[entityID] = true; _mediator.RegisterComponent(entityID, _componentTypeID, _maskBit); -#if !DISABLE_POOLS_EVENTS +#if !DRAGONECS_DISABLE_POOLS_EVENTS _listeners.InvokeOnAdd(entityID, _listenersCachedCount); #endif } @@ -128,14 +130,16 @@ namespace DCFApixels.DragonECS } public void Del(int entityID) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (!Has(entityID)) { EcsPoolThrowHelper.ThrowNotHaveComponent(entityID); } if (_isLocked) { EcsPoolThrowHelper.ThrowPoolLocked(); } +#elif DRAGONECS_STABILITY_MODE + if (!Has(entityID) || _isLocked) { return; } #endif _mapping[entityID] = false; _count--; _mediator.UnregisterComponent(entityID, _componentTypeID, _maskBit); -#if !DISABLE_POOLS_EVENTS +#if !DRAGONECS_DISABLE_POOLS_EVENTS _listeners.InvokeOnDel(entityID, _listenersCachedCount); #endif } @@ -149,15 +153,19 @@ namespace DCFApixels.DragonECS } public void Copy(int fromEntityID, int toEntityID) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (!Has(fromEntityID)) { EcsPoolThrowHelper.ThrowNotHaveComponent(fromEntityID); } +#elif DRAGONECS_STABILITY_MODE + if (!Has(fromEntityID)) { return; } #endif TryAdd(toEntityID); } public void Copy(int fromEntityID, EcsWorld toWorld, int toEntityID) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (!Has(fromEntityID)) { EcsPoolThrowHelper.ThrowNotHaveComponent(fromEntityID); } +#elif DRAGONECS_STABILITY_MODE + if (!Has(fromEntityID)) { return; } #endif toWorld.GetPool().TryAdd(toEntityID); } @@ -189,8 +197,10 @@ namespace DCFApixels.DragonECS public void ClearAll() { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (_isLocked) { EcsPoolThrowHelper.ThrowPoolLocked(); } +#elif DRAGONECS_STABILITY_MODE + if (_isLocked) { return; } #endif if (_count <= 0) { return; } var span = _source.Where(out SingleTagAspect _); @@ -199,7 +209,7 @@ namespace DCFApixels.DragonECS { _mapping[entityID] = false; _mediator.UnregisterComponent(entityID, _componentTypeID, _maskBit); -#if !DISABLE_POOLS_EVENTS +#if !DRAGONECS_DISABLE_POOLS_EVENTS _listeners.InvokeOnDel(entityID, _listenersCachedCount); #endif } @@ -245,14 +255,14 @@ namespace DCFApixels.DragonECS void IEcsPool.AddRaw(int entityID, object dataRaw) { Add(entityID); } object IEcsReadonlyPool.GetRaw(int entityID) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (Has(entityID) == false) { EcsPoolThrowHelper.ThrowNotHaveComponent(entityID); } #endif return _fakeComponent; } void IEcsPool.SetRaw(int entityID, object dataRaw) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (Has(entityID) == false) { EcsPoolThrowHelper.ThrowNotHaveComponent(entityID); } #endif } @@ -263,14 +273,14 @@ namespace DCFApixels.DragonECS } ref readonly T IEcsStructPool.Read(int entityID) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (Has(entityID) == false) { EcsPoolThrowHelper.ThrowNotHaveComponent(entityID); } #endif return ref _fakeComponent; } ref T IEcsStructPool.Get(int entityID) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS +#if DEBUG if (Has(entityID) == false) { EcsPoolThrowHelper.ThrowNotHaveComponent(entityID); } #endif return ref _fakeComponent; @@ -278,7 +288,7 @@ namespace DCFApixels.DragonECS #endregion #region Listeners -#if !DISABLE_POOLS_EVENTS +#if !DRAGONECS_DISABLE_POOLS_EVENTS public void AddListener(IEcsPoolEventListener listener) { if (listener == null) { EcsPoolThrowHelper.ThrowNullListener(); } diff --git a/src/entlong.cs b/src/entlong.cs index 43994c1..d7e64d3 100644 --- a/src/entlong.cs +++ b/src/entlong.cs @@ -59,8 +59,10 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] get { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS - if (!IsAlive) { Throw.Ent_ThrowIsNotAlive(this); } +#if DEBUG + if (IsAlive == false) { Throw.Ent_ThrowIsNotAlive(this); } +#elif DRAGONECS_STABILITY_MODE + if (IsAlive == false) { return EcsConsts.NULL_ENTITY_ID; } #endif return _id; } @@ -70,8 +72,10 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] get { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS - if (!IsAlive) { Throw.Ent_ThrowIsNotAlive(this); } +#if DEBUG + if (IsAlive == false) { Throw.Ent_ThrowIsNotAlive(this); } +#elif DRAGONECS_STABILITY_MODE + if (IsAlive == false) { return default; } #endif return _gen; } @@ -81,8 +85,8 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] get { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS - if (!IsAlive) { Throw.Ent_ThrowIsNotAlive(this); } +#if DEBUG + if (IsAlive == false) { Throw.Ent_ThrowIsNotAlive(this); } #endif return GetWorld_Internal(); } @@ -92,8 +96,10 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] get { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS - if (!IsAlive) { Throw.Ent_ThrowIsNotAlive(this); } +#if DEBUG + if (IsAlive == false) { Throw.Ent_ThrowIsNotAlive(this); } +#elif DRAGONECS_STABILITY_MODE + if (IsAlive == false) { return EcsConsts.NULL_WORLD_ID; } #endif return _world; } @@ -144,8 +150,15 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Unpack(out int id, out EcsWorld world) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS - if (!IsAlive) { Throw.Ent_ThrowIsNotAlive(this); } +#if DEBUG + if (IsAlive == false) { Throw.Ent_ThrowIsNotAlive(this); } +#elif DRAGONECS_STABILITY_MODE + if (IsAlive == false) + { + world = EcsWorld.GetWorld(EcsConsts.NULL_WORLD_ID); + id = EcsConsts.NULL_ENTITY_ID; + return; + } #endif world = EcsWorld.GetWorld(_world); id = _id; @@ -153,8 +166,16 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Unpack(out int id, out short gen, out EcsWorld world) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS - if (!IsAlive) { Throw.Ent_ThrowIsNotAlive(this); } +#if DEBUG + if (IsAlive == false) { Throw.Ent_ThrowIsNotAlive(this); } +#elif DRAGONECS_STABILITY_MODE + if (IsAlive == false) + { + world = EcsWorld.GetWorld(EcsConsts.NULL_WORLD_ID); + gen = default; + id = EcsConsts.NULL_ENTITY_ID; + return; + } #endif world = EcsWorld.GetWorld(_world); gen = _gen; @@ -163,8 +184,15 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Unpack(out int id, out short worldID) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS - if (!IsAlive) { Throw.Ent_ThrowIsNotAlive(this); } +#if DEBUG + if (IsAlive == false) { Throw.Ent_ThrowIsNotAlive(this); } +#elif DRAGONECS_STABILITY_MODE + if (IsAlive == false) + { + worldID = EcsConsts.NULL_WORLD_ID; + id = EcsConsts.NULL_ENTITY_ID; + return; + } #endif worldID = _world; id = _id; @@ -172,8 +200,16 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Unpack(out int id, out short gen, out short worldID) { -#if DEBUG || ENABLE_DRAGONECS_ASSERT_CHEKS - if (!IsAlive) { Throw.Ent_ThrowIsNotAlive(this); } +#if DEBUG + if (IsAlive == false) { Throw.Ent_ThrowIsNotAlive(this); } +#elif DRAGONECS_STABILITY_MODE + if (IsAlive == false) + { + worldID = EcsConsts.NULL_WORLD_ID; + gen = default; + id = EcsConsts.NULL_ENTITY_ID; + return; + } #endif worldID = _world; gen = _gen; @@ -296,7 +332,13 @@ namespace DCFApixels.DragonECS #region Other [MethodImpl(MethodImplOptions.AggressiveInlining)] - private EcsWorld GetWorld_Internal() { return EcsWorld.GetWorld(_world); } + private EcsWorld GetWorld_Internal() + { +#if DRAGONECS_STABILITY_MODE + if (IsAlive == false) { EcsWorld.GetWorld(EcsConsts.NULL_WORLD_ID); } +#endif + return EcsWorld.GetWorld(_world); + } [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { return unchecked((int)_full) ^ (int)(_full >> 32); } [MethodImpl(MethodImplOptions.AggressiveInlining)]