diff --git a/src/EcsWorld.cs b/src/EcsWorld.cs index 0800dfa..0f650ef 100644 --- a/src/EcsWorld.cs +++ b/src/EcsWorld.cs @@ -30,7 +30,7 @@ namespace DCFApixels.DragonECS public readonly short id; private IConfigContainer _configs; - private bool _isDestroyed = false; + private bool _isDestroyed = false; private IdDispenser _entityDispenser; private int _entitiesCount = 0; @@ -45,6 +45,10 @@ namespace DCFApixels.DragonECS internal int[] _entityComponentMasks = Array.Empty(); private const int COMPONENT_MASK_CHUNK_SIZE = 32; + private bool[] _isDirtyEntitiesMapping = Array.Empty(); + private int[] _dirtyEntitiesDense = Array.Empty(); + private int _dirtyEntitiesDenseCount = 0; + //"лениво" обновляется только для NewEntity private long _deleteLeakedEntitesLastVersion = 0; //обновляется в NewEntity и в DelEntity @@ -565,6 +569,9 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.NoInlining)] private void OnEntityDispenserResized(int newSize) { + Array.Resize(ref _dirtyEntitiesDense, newSize); + Array.Resize(ref _isDirtyEntitiesMapping, newSize); + Array.Resize(ref _entities, newSize); Array.Resize(ref _delEntBuffer, newSize); _entityComponentMaskLength = CalcEntityComponentMaskLastIndex(); //_pools.Length / COMPONENT_MASK_CHUNK_SIZE + 1; @@ -775,6 +782,22 @@ namespace DCFApixels.DragonECS } } #endregion + + #region DirtyEntities + public EcsSpan GetDirtyEntities() + { + return new EcsSpan(id, _dirtyEntitiesDense, _dirtyEntitiesDenseCount); + } + public void SetEntityDirty(int entityID) + { + bool lastValue = _isDirtyEntitiesMapping[entityID]; + if (lastValue) + { + _isDirtyEntitiesMapping[entityID] = true; + _dirtyEntitiesDense[_dirtyEntitiesDenseCount++] = entityID; + } + } + #endregion } public static class EcsWorldExtenssions diff --git a/src/Executors/EcsFilter.cs b/src/Executors/EcsFilter.cs new file mode 100644 index 0000000..7faa7c5 --- /dev/null +++ b/src/Executors/EcsFilter.cs @@ -0,0 +1,59 @@ +using DCFApixels.DragonECS.Internal; +using System; +using System.Reflection.Emit; + +namespace DCFApixels.DragonECS +{ + public abstract class EcsFilter : EcsQueryExecutor + { + public abstract EcsAspect AspectRaw { get; } + } + public class EcsFilter : EcsFilter + where TAspect : EcsAspect + { + private long _version; + + private EcsGroup _filterGroup; + + private TAspect _aspect; + + public override long Version { get { return _version; } } + public TAspect Aspect { get { return _aspect; } } + public override EcsAspect AspectRaw { get { return _aspect; } } + + private bool IsMatches(int entityID) + { + //int _entityComponentMaskBitShift = BitsUtility.GetHighBitNumber(World._entityComponentMaskLength); + // + //int[] _entityComponentMasks = World._entityComponentMasks; + //int chunck = entityID << _entityComponentMaskBitShift; + //for (int i = 0; i < _sortIncChunckBuffer.Length; i++) + //{ + // var bit = _sortIncChunckBuffer.ptr[i]; + // if ((_entityComponentMasks[chunck + bit.chankIndex] & bit.mask) != bit.mask) + // { + // goto skip; + // } + //} + //for (int i = 0; i < _sortExcChunckBuffer.Length; i++) + //{ + // var bit = _sortExcChunckBuffer.ptr[i]; + // if ((_entityComponentMasks[chunck + bit.chankIndex] & bit.mask) != 0) + // { + // goto skip; + // } + //} + //return true; + //skip: continue; + throw new System.NotImplementedException(); + } + protected override void OnInitialize() + { + _aspect = World.GetAspect(); + } + protected override void OnDestroy() + { + + } + } +}