diff --git a/src/EcsWorld.cs b/src/EcsWorld.cs index c4e725a..60beb5b 100644 --- a/src/EcsWorld.cs +++ b/src/EcsWorld.cs @@ -44,6 +44,11 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return _config; } } + public long Version + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get { return _version; } + } public bool IsDestroyed { [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -56,7 +61,6 @@ namespace DCFApixels.DragonECS } public int Capacity { - //_denseEntities.Length; [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return _entitesCapacity; } } @@ -203,6 +207,7 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] public int NewEntity() { + unchecked { _version++; } int entityID = _entityDispenser.GetFree(); _freeSpace--; _entitiesCount++; @@ -367,6 +372,7 @@ namespace DCFApixels.DragonECS { return; } + unchecked { _version++; } count = Math.Clamp(count, 0, _delEntBufferCount); _delEntBufferCount -= count; ReadOnlySpan buffser = new ReadOnlySpan(_delEntBuffer, _delEntBufferCount, count); diff --git a/src/Executors/EcsWhereExecutor.cs b/src/Executors/EcsWhereExecutor.cs index 03e4405..d0f42b7 100644 --- a/src/Executors/EcsWhereExecutor.cs +++ b/src/Executors/EcsWhereExecutor.cs @@ -7,7 +7,7 @@ namespace DCFApixels.DragonECS private TAspect _aspect; private int[] _filteredEntities; - private long _version; + private long _lastWorldVersion; #if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS private readonly EcsProfilerMarker _executeMarker = new EcsProfilerMarker("Where"); @@ -22,7 +22,7 @@ namespace DCFApixels.DragonECS public sealed override long Version { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => _version; + get => _lastWorldVersion; } #endregion @@ -46,8 +46,16 @@ namespace DCFApixels.DragonECS if (span.IsNull) throw new System.ArgumentNullException();//TODO составить текст исключения. if (span.WorldID != WorldID) throw new System.ArgumentException();//TODO составить текст исключения. #endif - unchecked { _version++; } - EcsSpan result = _aspect.GetIteratorFor(span).CopyToSpan(ref _filteredEntities); + EcsSpan result; + if (_lastWorldVersion != World.Version) + { + result = _aspect.GetIteratorFor(span).CopyToSpan(ref _filteredEntities); + _lastWorldVersion = World.Version; + } + else + { + result = new EcsSpan(WorldID, _filteredEntities); + } #if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS _executeMarker.End(); #endif diff --git a/src/Executors/EcsWhereToGroupExecutor.cs b/src/Executors/EcsWhereToGroupExecutor.cs index 107151b..74c4fa3 100644 --- a/src/Executors/EcsWhereToGroupExecutor.cs +++ b/src/Executors/EcsWhereToGroupExecutor.cs @@ -7,7 +7,7 @@ namespace DCFApixels.DragonECS private TAspect _aspect; private EcsGroup _filteredGroup; - private long _version; + private long _lastWorldVersion; #if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS private readonly EcsProfilerMarker _executeMarker = new EcsProfilerMarker("Where"); @@ -22,7 +22,7 @@ namespace DCFApixels.DragonECS public sealed override long Version { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => _version; + get => _lastWorldVersion; } #endregion @@ -49,8 +49,11 @@ namespace DCFApixels.DragonECS if (span.IsNull) throw new System.ArgumentNullException();//TODO составить текст исключения. if (span.WorldID != WorldID) throw new System.ArgumentException();//TODO составить текст исключения. #endif - unchecked { _version++; } - _aspect.GetIteratorFor(span).CopyTo(_filteredGroup); + if (_lastWorldVersion != World.Version) + { + _aspect.GetIteratorFor(span).CopyTo(_filteredGroup); + _lastWorldVersion = World.Version; + } #if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS _executeMarker.End(); #endif