From 1ecad4de1df72a8e51ba200dcffbe501702c54b6 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Sun, 31 Dec 2023 13:07:53 +0800 Subject: [PATCH] Update entity lifecycle/collcetions update auto release DelEntBuffer replace ReadnolySpan to EcsSpan --- src/Builtin/Aspects.cs | 30 +++--- src/Builtin/Systems.cs | 4 +- src/Collections/EcsGroup.cs | 66 ++++++------- src/Collections/EcsSpan.cs | 23 ++++- src/EcsAspect.cs | 26 +++--- src/EcsWorld.cs | 149 +++++++++++++++++++++++------- src/EcsWorld.pools.cs | 4 +- src/EcsWorld.static.cs | 21 ++++- src/Executors/EcsWhereExecutor.cs | 16 ++-- 9 files changed, 221 insertions(+), 118 deletions(-) diff --git a/src/Builtin/Aspects.cs b/src/Builtin/Aspects.cs index 4844048..0e9c607 100644 --- a/src/Builtin/Aspects.cs +++ b/src/Builtin/Aspects.cs @@ -121,20 +121,20 @@ var combined = self.GetAspect>(); a0 = combined.a0; a1 = combined.a1; - return self.WhereFor>(sourceGroup); + return self.WhereToGroupFor>(sourceGroup); } public static EcsReadonlyGroup Where(this EcsWorld self) where A0 : EcsAspect where A1 : EcsAspect { - return self.Where>(); + return self.WhereToGroup>(); } public static EcsReadonlyGroup WhereFor(this EcsWorld self, EcsReadonlyGroup sourceGroup) where A0 : EcsAspect where A1 : EcsAspect { - return self.WhereFor>(sourceGroup); + return self.WhereToGroupFor>(sourceGroup); } #endregion @@ -155,7 +155,7 @@ a0 = combined.a0; a1 = combined.a1; a2 = combined.a2; - return self.WhereFor>(sourceGroup); + return self.WhereToGroupFor>(sourceGroup); } public static EcsReadonlyGroup Where(this EcsWorld self) @@ -163,14 +163,14 @@ where A1 : EcsAspect where A2 : EcsAspect { - return self.Where>(); + return self.WhereToGroup>(); } public static EcsReadonlyGroup WhereFor(this EcsWorld self, EcsReadonlyGroup sourceGroup) where A0 : EcsAspect where A1 : EcsAspect where A2 : EcsAspect { - return self.WhereFor>(sourceGroup); + return self.WhereToGroupFor>(sourceGroup); } #endregion @@ -194,7 +194,7 @@ a1 = combined.a1; a2 = combined.a2; a3 = combined.a3; - return self.WhereFor>(sourceGroup); + return self.WhereToGroupFor>(sourceGroup); } public static EcsReadonlyGroup Where(this EcsWorld self) @@ -203,7 +203,7 @@ where A2 : EcsAspect where A3 : EcsAspect { - return self.Where>(); + return self.WhereToGroup>(); } public static EcsReadonlyGroup WhereFor(this EcsWorld self, EcsReadonlyGroup sourceGroup) where A0 : EcsAspect @@ -211,7 +211,7 @@ where A2 : EcsAspect where A3 : EcsAspect { - return self.WhereFor>(sourceGroup); + return self.WhereToGroupFor>(sourceGroup); } #endregion @@ -238,7 +238,7 @@ a2 = combined.a2; a3 = combined.a3; a4 = combined.a4; - return self.WhereFor>(sourceGroup); + return self.WhereToGroupFor>(sourceGroup); } @@ -249,7 +249,7 @@ where A3 : EcsAspect where A4 : EcsAspect { - return self.Where>(); + return self.WhereToGroup>(); } public static EcsReadonlyGroup WhereFor(this EcsWorld self, EcsReadonlyGroup sourceGroup) where A0 : EcsAspect @@ -258,7 +258,7 @@ where A3 : EcsAspect where A4 : EcsAspect { - return self.WhereFor>(sourceGroup); + return self.WhereToGroupFor>(sourceGroup); } #endregion @@ -288,7 +288,7 @@ a3 = combined.a3; a4 = combined.a4; a5 = combined.a5; - return self.WhereFor>(sourceGroup); + return self.WhereToGroupFor>(sourceGroup); } @@ -300,7 +300,7 @@ where A4 : EcsAspect where A5 : EcsAspect { - return self.Where>(); + return self.WhereToGroup>(); } public static EcsReadonlyGroup WhereFor(this EcsWorld self, EcsReadonlyGroup sourceGroup) where A0 : EcsAspect @@ -310,7 +310,7 @@ where A4 : EcsAspect where A5 : EcsAspect { - return self.WhereFor>(sourceGroup); + return self.WhereToGroupFor>(sourceGroup); } #endregion } diff --git a/src/Builtin/Systems.cs b/src/Builtin/Systems.cs index 7f1e2ca..5428395 100644 --- a/src/Builtin/Systems.cs +++ b/src/Builtin/Systems.cs @@ -23,7 +23,7 @@ namespace DCFApixels.DragonECS foreach (var world in _worlds) { world.DeleteEmptyEntites(); - world.ReleaseDelEntityBuffer(); + world.ReleaseDelEntityBufferAll(); } } } @@ -47,7 +47,7 @@ namespace DCFApixels.DragonECS EcsWorld world = _worlds[i]; if (world.IsComponentTypeDeclared()) { - foreach (var e in world.Where(out Aspect a)) + foreach (var e in world.WhereToGroup(out Aspect a)) a.pool.Del(e); } } diff --git a/src/Collections/EcsGroup.cs b/src/Collections/EcsGroup.cs index 50d5fb7..fba66cb 100644 --- a/src/Collections/EcsGroup.cs +++ b/src/Collections/EcsGroup.cs @@ -77,9 +77,9 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Bake(List entities) => _source.Bake(entities); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ReadOnlySpan ToSpan() => _source.ToSpan(); + public EcsSpan ToSpan() => _source.ToSpan(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ReadOnlySpan ToSpan(int start, int length) => _source.ToSpan(start, length); + public EcsSpan ToSpan(int start, int length) => _source.ToSpan(start, length); [MethodImpl(MethodImplOptions.AggressiveInlining)] public EcsGroup.LongsIterator GetLongs() => _source.GetLongs(); @@ -121,12 +121,9 @@ namespace DCFApixels.DragonECS #endregion - #region Convertions + #region Other [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static implicit operator ReadOnlySpan(EcsReadonlyGroup a) => a.ToSpan(); - #endregion - - #region DebuggerProxy + public static implicit operator EcsSpan(EcsReadonlyGroup a) => a.ToSpan(); internal class DebuggerProxy : EcsGroup.DebuggerProxy { public DebuggerProxy(EcsReadonlyGroup group) : base(group._source) { } @@ -321,13 +318,16 @@ namespace DCFApixels.DragonECS foreach (var e in this) entities.Add(e); } - public ReadOnlySpan ToSpan() => new ReadOnlySpan(_dense, 0, _count); - public ReadOnlySpan ToSpan(int start, int length) + public EcsSpan ToSpan() + { + return new EcsSpan(WorldID, _dense); + } + public EcsSpan ToSpan(int start, int length) { #if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS if (start + length > _count) Throw.ArgumentOutOfRange(); #endif - return new ReadOnlySpan(_dense, start, length); + return new EcsSpan(WorldID, _dense, start, length); } #endregion @@ -637,28 +637,18 @@ namespace DCFApixels.DragonECS #region Enumerator [MethodImpl(MethodImplOptions.AggressiveInlining)] public Enumerator GetEnumerator() => new Enumerator(this); - IEnumerator IEnumerable.GetEnumerator() - { - for (int i = 0; i < _count; i++) - yield return _dense[i]; - } - IEnumerator IEnumerable.GetEnumerator() - { - for (int i = 0; i < _count; i++) - yield return _dense[i]; - } + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); public LongsIterator GetLongs() => new LongsIterator(this); public struct Enumerator : IEnumerator { private readonly int[] _dense; - private readonly int _count; - private int _index; + private uint _index; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Enumerator(EcsGroup group) { _dense = group._dense; - _count = group._count > _dense.Length ? _dense.Length : group._count; - _index = 0; + _index = (uint)(group._count > _dense.Length ? _dense.Length : group._count); } public int Current { @@ -667,7 +657,7 @@ namespace DCFApixels.DragonECS } object IEnumerator.Current => Current; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() => ++_index <= _count; // <= потму что отсчет начинается с индекса 1 //_count < _dense.Length дает среде понять что проверки на выход за границы не нужны + public bool MoveNext() => --_index > 0; // <= потму что отсчет начинается с индекса 1 //_count < _dense.Length дает среде понять что проверки на выход за границы не нужны [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Dispose() { } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -689,38 +679,34 @@ namespace DCFApixels.DragonECS for (int i = 0; i < _group._count; i++) yield return _group.World.GetEntityLong(_group._dense[i]); } - public ref struct Enumerator + public struct Enumerator : IEnumerator { private readonly EcsWorld world; private readonly int[] _dense; - private readonly int _count; - private int _index; + private uint _index; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Enumerator(EcsGroup group) { world = group.World; _dense = group._dense; - _count = group._count > _dense.Length ? _dense.Length : group._count; - _index = 0; + _index = (uint)(group._count > _dense.Length ? _dense.Length : group._count); } public entlong Current { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => world.GetEntityLong(_dense[_index]); } + object IEnumerator.Current => Current; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() => ++_index <= _count; // <= потму что отсчет начинается с индекса 1 //_count < _dense.Length дает среде понять что проверки на выход за границы не нужны + public bool MoveNext() => ++_index > 0; // <= потму что отсчет начинается с индекса 1 //_count < _dense.Length дает среде понять что проверки на выход за границы не нужны + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Dispose() { } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Reset() { } } } #endregion - #region Convertions - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static implicit operator EcsReadonlyGroup(EcsGroup a) => a.Readonly; - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static implicit operator ReadOnlySpan(EcsGroup a) => a.ToSpan(); - #endregion - #region Other public override string ToString() { @@ -741,6 +727,10 @@ namespace DCFApixels.DragonECS { Array.Resize(ref _sparse, newSize); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static implicit operator EcsReadonlyGroup(EcsGroup a) => a.Readonly; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static implicit operator EcsSpan(EcsGroup a) => a.ToSpan(); internal class DebuggerProxy { private EcsGroup _group; diff --git a/src/Collections/EcsSpan.cs b/src/Collections/EcsSpan.cs index f7b011f..5306b9e 100644 --- a/src/Collections/EcsSpan.cs +++ b/src/Collections/EcsSpan.cs @@ -10,15 +10,30 @@ namespace DCFApixels.DragonECS private readonly ReadOnlySpan _values; #region Properties - public int WorldID => _worldID; - public EcsWorld World => EcsWorld.GetWorld(_worldID); - public int Length => _values.Length; - public bool IsEmpty => _values.IsEmpty; + public int WorldID + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => _worldID; + } + public EcsWorld World + { + get => EcsWorld.GetWorld(_worldID); + } + public int Length + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => _values.Length; + } public readonly int this[int index] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => _values[index]; } + public bool IsNull + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => _values.IsEmpty; + } #endregion #region Constructors diff --git a/src/EcsAspect.cs b/src/EcsAspect.cs index b7c7411..abadc2a 100644 --- a/src/EcsAspect.cs +++ b/src/EcsAspect.cs @@ -188,9 +188,9 @@ namespace DCFApixels.DragonECS { return new EcsAspectIterator(this, source.Entities); } - public EcsAspectIterator GetIteratorFor(EcsReadonlyGroup sourceGroup) + public EcsAspectIterator GetIteratorFor(EcsSpan span) { - return new EcsAspectIterator(this, sourceGroup); + return new EcsAspectIterator(this, span); } #endregion @@ -336,14 +336,14 @@ namespace DCFApixels.DragonECS { public readonly int worldID; public readonly EcsMask mask; - private EcsReadonlyGroup _sourceGroup; + private EcsSpan _span; private Enumerator _enumerator; - public EcsAspectIterator(EcsAspect aspect, EcsReadonlyGroup sourceGroup) + public EcsAspectIterator(EcsAspect aspect, EcsSpan span) { worldID = aspect.World.id; mask = aspect.mask; - _sourceGroup = sourceGroup; + _span = span; _enumerator = default; } @@ -403,33 +403,33 @@ namespace DCFApixels.DragonECS #region Enumerator [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Enumerator GetEnumerator() => new Enumerator(_sourceGroup, mask); + public Enumerator GetEnumerator() => new Enumerator(_span, mask); public ref struct Enumerator { - private EcsGroup.Enumerator _sourceGroup; + private ReadOnlySpan.Enumerator _span; private readonly EcsMaskBit[] _inc; private readonly EcsMaskBit[] _exc; private readonly int[][] _entitiesComponentMasks; - public Enumerator(EcsReadonlyGroup sourceGroup, EcsMask mask) + public Enumerator(EcsSpan span, EcsMask mask) { - _sourceGroup = sourceGroup.GetEnumerator(); + _span = span.GetEnumerator(); _inc = mask.incChunckMasks; _exc = mask.excChunckMasks; - _entitiesComponentMasks = sourceGroup.World._entitiesComponentMasks; + _entitiesComponentMasks = span.World._entitiesComponentMasks; } public int Current { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => _sourceGroup.Current; + get => _span.Current; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool MoveNext() { - while (_sourceGroup.MoveNext()) + while (_span.MoveNext()) { - int e = _sourceGroup.Current; + int e = _span.Current; EcsMaskBit bit; for (int i = 0, iMax = _inc.Length; i < iMax; i++) { diff --git a/src/EcsWorld.cs b/src/EcsWorld.cs index cae19ab..544f4e8 100644 --- a/src/EcsWorld.cs +++ b/src/EcsWorld.cs @@ -23,6 +23,7 @@ namespace DCFApixels.DragonECS private int _delEntBufferCount; private int _delEntBufferMinCount; private int _freeSpace; + //private bool _isEnableReleaseDelEntBuffer = true; private List> _groups = new List>(); private Stack _groupsPool = new Stack(64); @@ -111,38 +112,75 @@ namespace DCFApixels.DragonECS } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ref T Get() where T : struct => ref WorldComponentPool.GetForWorld(id); + public ref T Get() where T : struct + { + return ref WorldComponentPool.GetForWorld(id); + } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ref T UncheckedGet() where T : struct => ref WorldComponentPool.UncheckedGetForWorld(id); + public ref T GetUnchecked() where T : struct + { + return ref WorldComponentPool.GetForWorldUnchecked(id); + } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ref T Get(int worldID) where T : struct => ref WorldComponentPool.GetForWorld(worldID); + public static ref T Get(int worldID) where T : struct + { + return ref WorldComponentPool.GetForWorld(worldID); + } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ref T UncheckedGet(int worldID) where T : struct => ref WorldComponentPool.UncheckedGetForWorld(worldID); + public static ref T GetUnchecked(int worldID) where T : struct + { + return ref WorldComponentPool.GetForWorldUnchecked(worldID); + } #endregion #region Where Query - public EcsReadonlyGroup WhereFor(EcsReadonlyGroup sourceGroup, out TAspect aspect) where TAspect : EcsAspect + public EcsReadonlyGroup WhereToGroupFor(EcsSpan span, out TAspect aspect) where TAspect : EcsAspect { + ReleaseDelEntityBufferAll(); var executor = GetExecutor>(); aspect = executor.Aspect; - return executor.ExecuteFor(sourceGroup); + return executor.ExecuteFor(span); } - public EcsReadonlyGroup WhereFor(EcsReadonlyGroup sourceGroup) where TAspect : EcsAspect + public EcsReadonlyGroup WhereToGroupFor(EcsSpan span) where TAspect : EcsAspect { - return GetExecutor>().ExecuteFor(sourceGroup); + ReleaseDelEntityBufferAll(); + return GetExecutor>().ExecuteFor(span); } - public EcsReadonlyGroup Where(out TAspect aspect) where TAspect : EcsAspect + public EcsReadonlyGroup WhereToGroup(out TAspect aspect) where TAspect : EcsAspect { + ReleaseDelEntityBufferAll(); var executor = GetExecutor>(); aspect = executor.Aspect; return executor.Execute(); } - public EcsReadonlyGroup Where() where TAspect : EcsAspect + public EcsReadonlyGroup WhereToGroup() where TAspect : EcsAspect { + ReleaseDelEntityBufferAll(); return GetExecutor>().Execute(); } - public EcsSpan WhereSpan() where TAspect : EcsAspect + + public EcsSpan WhereFor(EcsSpan span, out TAspect aspect) where TAspect : EcsAspect { + ReleaseDelEntityBufferAll(); + var executor = GetExecutor>(); + aspect = executor.Aspect; + return executor.ExecuteFor(span); + } + public EcsSpan WhereFor(EcsSpan span) where TAspect : EcsAspect + { + ReleaseDelEntityBufferAll(); + return GetExecutor>().ExecuteFor(span); + } + public EcsSpan Where(out TAspect aspect) where TAspect : EcsAspect + { + ReleaseDelEntityBufferAll(); + var executor = GetExecutor>(); + aspect = executor.Aspect; + return executor.Execute(); + } + public EcsSpan Where() where TAspect : EcsAspect + { + ReleaseDelEntityBufferAll(); return GetExecutor>().Execute(); } #endregion @@ -150,8 +188,8 @@ namespace DCFApixels.DragonECS #region Entity public int NewEntity() { - if (_freeSpace <= 1 && _delEntBufferCount > _delEntBufferMinCount) - ReleaseDelEntityBuffer(); + //if (_isEnableReleaseDelEntBuffer && _freeSpace <= 1 && _delEntBufferCount > _delEntBufferMinCount) + // ReleaseDelEntityBufferAll(); int entityID = _entityDispenser.GetFree(); _freeSpace--; @@ -177,9 +215,8 @@ namespace DCFApixels.DragonECS _gens[entityID] |= DEATH_GEN_BIT; _entitiesCount--; _entityListeners.InvokeOnDelEntity(entityID); - - if (_delEntBufferCount >= _delEntBuffer.Length) - ReleaseDelEntityBuffer(); + //if (_delEntBufferCount >= _delEntBuffer.Length) + // ReleaseDelEntityBufferAll(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe entlong GetEntityLong(int entityID) @@ -214,24 +251,15 @@ namespace DCFApixels.DragonECS } return true; } - public void ReleaseDelEntityBuffer() - { - if (_delEntBufferCount <= 0) - return; - ReadOnlySpan buffser = new ReadOnlySpan(_delEntBuffer, 0, _delEntBufferCount); - foreach (var pool in _pools) - pool.OnReleaseDelEntityBuffer(buffser); - _listeners.InvokeOnReleaseDelEntityBuffer(buffser); - for (int i = 0; i < _delEntBufferCount; i++) - _entityDispenser.Release(_delEntBuffer[i]); - _freeSpace = _entitesCapacity - _entitiesCount; - _delEntBufferCount = 0; - } + public void DeleteEmptyEntites() { foreach (var e in _allEntites) { - if (_componentCounts[e] <= 0) DelEntity(e); + if (_componentCounts[e] <= 0) + { + DelEntity(e); + } } } @@ -304,8 +332,64 @@ namespace DCFApixels.DragonECS #endregion + #region DelEntBuffer + //public AutoReleaseDelEntBufferLonkUnloker DisableAutoReleaseDelEntBuffer() + //{ + // _isEnableReleaseDelEntBuffer = false; + // return new AutoReleaseDelEntBufferLonkUnloker(this); + //} + //public void EnableAutoReleaseDelEntBuffer() + //{ + // _isEnableReleaseDelEntBuffer = true; + //} + //public readonly struct AutoReleaseDelEntBufferLonkUnloker : IDisposable + //{ + // private readonly EcsWorld _source; + // public AutoReleaseDelEntBufferLonkUnloker(EcsWorld source) + // { + // _source = source; + // } + // public void Dispose() + // { + // _source.EnableAutoReleaseDelEntBuffer(); + // } + //} + public void ReleaseDelEntityBufferAll() + { + ReleaseDelEntityBuffer(-1); + } + public void ReleaseDelEntityBuffer(int count) + { + if (_delEntBufferCount <= 0) + { + return; + } + + if (count < 0) + { + count = _delEntBufferCount; + } + else if (count > _delEntBufferCount) + { + count = _delEntBufferCount; + } + _delEntBufferCount -= count; + ReadOnlySpan buffser = new ReadOnlySpan(_delEntBuffer, _delEntBufferCount, count); + for (int i = 0; i < _poolsCount; i++) + { + _pools[i].OnReleaseDelEntityBuffer(buffser); + } + _listeners.InvokeOnReleaseDelEntityBuffer(buffser); + for (int i = 0; i < buffser.Length; i++) + { + _entityDispenser.Release(buffser[i]); + } + _freeSpace += count;// _entitesCapacity - _entitiesCount; + } + #endregion + #region Upsize - //[MethodImpl(MethodImplOptions.NoInlining)] + [MethodImpl(MethodImplOptions.NoInlining)] private void Upsize() { Array.Resize(ref _gens, _gens.Length << 1); @@ -394,6 +478,7 @@ namespace DCFApixels.DragonECS } #endregion + #region PoolsMediator public readonly struct PoolsMediator { private readonly EcsWorld _world; @@ -409,7 +494,6 @@ namespace DCFApixels.DragonECS } _world = world; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public void RegisterComponent(int entityID, int componentTypeID, EcsMaskBit maskBit) { @@ -426,6 +510,7 @@ namespace DCFApixels.DragonECS return _world.HasEntityComponent(entityID, maskBit); } } + #endregion } #region Callbacks Interface diff --git a/src/EcsWorld.pools.cs b/src/EcsWorld.pools.cs index ad4dda0..dd2a53c 100644 --- a/src/EcsWorld.pools.cs +++ b/src/EcsWorld.pools.cs @@ -38,7 +38,7 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] public TPool GetPoolUnchecked() where TPool : IEcsPoolImplementation, new() { - return UncheckedGet>().instance; + return GetUnchecked>().instance; } #if UNITY_2020_3_OR_NEWER [UnityEngine.Scripting.Preserve] @@ -54,7 +54,7 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TPool UncheckedGetPool(int worldID) where TPool : IEcsPoolImplementation, new() { - return UncheckedGet>(worldID).instance; + return GetUnchecked>(worldID).instance; } #endregion diff --git a/src/EcsWorld.static.cs b/src/EcsWorld.static.cs index 558804e..fdea0e9 100644 --- a/src/EcsWorld.static.cs +++ b/src/EcsWorld.static.cs @@ -41,7 +41,7 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ref T GetData(int worldID) => ref WorldComponentPool.GetForWorld(worldID); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ref T UncheckedGetData(int worldID) => ref WorldComponentPool.UncheckedGetForWorld(worldID); + public static ref T UncheckedGetData(int worldID) => ref WorldComponentPool.GetForWorldUnchecked(worldID); private abstract class DataReleaser { @@ -57,11 +57,24 @@ namespace DCFApixels.DragonECS private static IEcsWorldComponent _interface = EcsWorldComponentHandler.instance; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ref T Get(int itemIndex) => ref _items[itemIndex]; + public static ref T Get(int itemIndex) + { + return ref _items[itemIndex]; + } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ref T GetForWorld(int worldID) => ref _items[GetItemIndex(worldID)]; + public static ref T GetForWorld(int worldID) + { + return ref _items[GetItemIndex(worldID)]; + } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ref T UncheckedGetForWorld(int worldID) => ref _items[_mapping[worldID]]; + public static ref T GetForWorldUnchecked(int worldID) + { +#if (DEBUG && !DISABLE_DEBUG) + if (_mapping[worldID] <= 0) + throw new Exception(); +#endif + return ref _items[_mapping[worldID]]; + } public static int GetItemIndex(int worldID) { if (_mapping.Length < Worlds.Length) diff --git a/src/Executors/EcsWhereExecutor.cs b/src/Executors/EcsWhereExecutor.cs index a1be62a..df3df19 100644 --- a/src/Executors/EcsWhereExecutor.cs +++ b/src/Executors/EcsWhereExecutor.cs @@ -42,15 +42,15 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] public EcsReadonlyGroup Execute() => ExecuteFor(_aspect.World.Entities); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public EcsReadonlyGroup ExecuteFor(EcsReadonlyGroup sourceGroup) + public EcsReadonlyGroup ExecuteFor(EcsSpan span) { #if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS _executeMarker.Begin(); - if (sourceGroup.IsNull) throw new System.ArgumentNullException();//TODO составить текст исключения. - if (sourceGroup.WorldID != WorldID) throw new System.ArgumentException();//TODO составить текст исключения. + if (span.IsNull) throw new System.ArgumentNullException();//TODO составить текст исключения. + if (span.WorldID != WorldID) throw new System.ArgumentException();//TODO составить текст исключения. #endif unchecked { _version++; } - _aspect.GetIteratorFor(sourceGroup).CopyTo(_filteredGroup); + _aspect.GetIteratorFor(span).CopyTo(_filteredGroup); #if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS _executeMarker.End(); #endif @@ -99,15 +99,15 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] public EcsSpan Execute() => ExecuteFor(_aspect.World.Entities); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public EcsSpan ExecuteFor(EcsReadonlyGroup sourceGroup) + public EcsSpan ExecuteFor(EcsSpan span) { #if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS _executeMarker.Begin(); - if (sourceGroup.IsNull) throw new System.ArgumentNullException();//TODO составить текст исключения. - if (sourceGroup.WorldID != WorldID) throw new System.ArgumentException();//TODO составить текст исключения. + if (span.IsNull) throw new System.ArgumentNullException();//TODO составить текст исключения. + if (span.WorldID != WorldID) throw new System.ArgumentException();//TODO составить текст исключения. #endif unchecked { _version++; } - EcsSpan result = _aspect.GetIteratorFor(sourceGroup).CopyToSpan(ref _filteredEntities); + EcsSpan result = _aspect.GetIteratorFor(span).CopyToSpan(ref _filteredEntities); #if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS _executeMarker.End(); #endif