From 4c236a11f3b51e99960d07c70d0e10c76bdbb674 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Wed, 22 Nov 2023 20:28:11 +0800 Subject: [PATCH] functional recovery --- src/EcsWorld.cs | 101 +++++++++++++++++++++++++++--------------------- 1 file changed, 56 insertions(+), 45 deletions(-) diff --git a/src/EcsWorld.cs b/src/EcsWorld.cs index 9b11153..3791d87 100644 --- a/src/EcsWorld.cs +++ b/src/EcsWorld.cs @@ -150,36 +150,8 @@ namespace DCFApixels.DragonECS _entitiesCount++; if (_gens.Length <= entityID) - { - Array.Resize(ref _gens, _gens.Length << 1); - Array.Resize(ref _componentCounts, _gens.Length); - Array.Resize(ref _delEntBuffer, _gens.Length); - Array.Resize(ref _entitiesComponentMasks, _gens.Length); - for (int i = _entitesCapacity; i < _gens.Length; i++) - _entitiesComponentMasks[i] = new int[_pools.Length / 32 + 1]; + Upsize(); - _delEntBufferMinCount = Math.Max(_delEntBuffer.Length >> DEL_ENT_BUFFER_SIZE_OFFSET, DEL_ENT_BUFFER_MIN_SIZE); - ArrayUtility.Fill(_gens, DEATH_GEN_BIT, _entitesCapacity); - _entitesCapacity = _gens.Length; - - for (int i = 0; i < _groups.Count; i++) - { - if (_groups[i].TryGetTarget(out EcsGroup group)) - { - group.OnWorldResize(_gens.Length); - } - else - { - int last = _groups.Count - 1; - _groups[i--] = _groups[last]; - _groups.RemoveAt(last); - } - } - foreach (var item in _pools) - item.OnWorldResize(_gens.Length); - - _listeners.InvokeOnWorldResize(_gens.Length); - } _gens[entityID] &= GEN_BITS; _allEntites.Add(entityID); _entityListeners.InvokeOnNewEntity(entityID); @@ -218,22 +190,21 @@ namespace DCFApixels.DragonECS public bool IsMatchesMask(EcsMask mask, int entityID) { - throw new NotImplementedException(); -//#if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS -// if (mask.worldID != id) -// throw new EcsFrameworkException("The types of the target world of the mask and this world are different."); -//#endif -// for (int i = 0, iMax = mask.incChunckMasks.Length; i < iMax; i++) -// { -// if (!_pools[mask.incChunckMasks[i]].Has(entityID)) -// return false; -// } -// for (int i = 0, iMax = mask.excChunckMasks.Length; i < iMax; i++) -// { -// if (_pools[mask.excChunckMasks[i]].Has(entityID)) -// return false; -// } -// return true; +#if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS + if (mask.worldID != id) + throw new EcsFrameworkException("The types of the target world of the mask and this world are different."); +#endif + for (int i = 0, iMax = mask.incChunckMasks.Length; i < iMax; i++) + { + if (!_pools[mask.inc[i]].Has(entityID)) + return false; + } + for (int i = 0, iMax = mask.excChunckMasks.Length; i < iMax; i++) + { + if (_pools[mask.exc[i]].Has(entityID)) + return false; + } + return true; } public void ReleaseDelEntityBuffer() { @@ -322,6 +293,41 @@ namespace DCFApixels.DragonECS #endregion + #region Upsize + //[MethodImpl(MethodImplOptions.NoInlining)] + private void Upsize() + { + Array.Resize(ref _gens, _gens.Length << 1); + Array.Resize(ref _componentCounts, _gens.Length); + Array.Resize(ref _delEntBuffer, _gens.Length); + Array.Resize(ref _entitiesComponentMasks, _gens.Length); + for (int i = _entitesCapacity; i < _gens.Length; i++) + _entitiesComponentMasks[i] = new int[_pools.Length / 32 + 1]; + + _delEntBufferMinCount = Math.Max(_delEntBuffer.Length >> DEL_ENT_BUFFER_SIZE_OFFSET, DEL_ENT_BUFFER_MIN_SIZE); + ArrayUtility.Fill(_gens, DEATH_GEN_BIT, _entitesCapacity); + _entitesCapacity = _gens.Length; + + for (int i = 0; i < _groups.Count; i++) + { + if (_groups[i].TryGetTarget(out EcsGroup group)) + { + group.OnWorldResize(_gens.Length); + } + else + { + int last = _groups.Count - 1; + _groups[i--] = _groups[last]; + _groups.RemoveAt(last); + } + } + foreach (var item in _pools) + item.OnWorldResize(_gens.Length); + + _listeners.InvokeOnWorldResize(_gens.Length); + } + #endregion + #region Groups Pool internal void RegisterGroup(EcsGroup group) { @@ -427,4 +433,9 @@ namespace DCFApixels.DragonECS public static entlong ToEntityLong(this int self, EcsWorld world) => world.GetEntityLong(self); } #endregion + + public class PoolsController + { + + } }