diff --git a/src/EcsGroup.cs b/src/EcsGroup.cs index d1eb690..6411181 100644 --- a/src/EcsGroup.cs +++ b/src/EcsGroup.cs @@ -429,7 +429,7 @@ namespace DCFApixels.DragonECS { // source = group; _dense = group._dense; - _count = group.Count; + _count = group._count; _index = 0; } public int Current diff --git a/src/EcsJoinQuery.cs b/src/EcsJoinQuery.cs index cae2d11..3c375bb 100644 --- a/src/EcsJoinQuery.cs +++ b/src/EcsJoinQuery.cs @@ -11,7 +11,6 @@ namespace DCFApixels.DragonECS { private EcsWorld _targetWorld; private EcsAttachPool _targetPool; - public EcsAttachPool Attach => _targetPool; private int _targetWorldCapacity = -1; @@ -22,19 +21,26 @@ namespace DCFApixels.DragonECS private EntityLinkedList _linkedBasket; private bool _isJoinExecuted = false; - public bool IsJoinExecuted => _isJoinExecuted; private bool _isInitTargetWorlds = false; + private ProfilerMarker _execute = new ProfilerMarker("Query.ExecuteJoin"); + + #region Properties + public EcsWorld AttachWorld => _targetWorld; + public EcsAttachPool Attach => _targetPool; + public bool IsJoinExecuted => _isJoinExecuted; + #endregion + protected sealed override void OnBuild(Builder b) { _targetPool = b.Include(); } public sealed override void ExecuteWhere() { - ExecuteWhere(_targetPool.Entites, groupFilter); + //ExecuteWhere(_targetPool.Entities, groupFilter); + ExecuteWhere(World.Entities, groupFilter); } - private ProfilerMarker _execute = new ProfilerMarker("Query.ExecuteJoin"); public sealed override void ExecuteJoin() { @@ -70,11 +76,11 @@ namespace DCFApixels.DragonECS foreach (var attachID in groupFilter) { EcsEntity attachTarget = _targetPool.Read(attachID).Target; - // if (!attachTarget.IsAlive)//TODO пофиксить IsAlive - //{ - // _targetPool.Del(attachID); - // continue; - //} + if (!attachTarget.IsAlive)//TODO пофиксить IsAlive + { + //_targetPool.Del(attachID); + continue; + } int attachTargetID = attachTarget.id; ref int nodeIndex = ref _mapping[attachTargetID]; @@ -88,10 +94,9 @@ namespace DCFApixels.DragonECS _isJoinExecuted = true; _execute.End(); } - public EntityLinkedList.EnumerableSpan GetNodes(int entityID) => _linkedBasket.Span(_mapping[entityID], _counts[entityID]); private void InitTargetWorlds() { - foreach (var e in _targetPool.Entites) + foreach (var e in _targetPool.Entities) { ref readonly var rel = ref _targetPool.Read(e); //if (rel.Target.IsNotNull) @@ -119,6 +124,7 @@ namespace DCFApixels.DragonECS { return groupFilter.GetEnumerator(); } + public EntityLinkedList.EnumerableSpan GetNodes(int entityID) => _linkedBasket.Span(_mapping[entityID], _counts[entityID]); } public abstract class EcsJoinRelationQuery : EcsJoinQueryBase where TRelationComponent : struct, IEcsRelationComponent @@ -126,10 +132,14 @@ namespace DCFApixels.DragonECS private EcsWorld _firstWorld; private EcsWorld _secondWorld; private EcsRelationPool _targetPool; - public EcsRelationPool Relation => _targetPool; - private bool _isInitTargetWorlds = false; + #region Properties + public EcsWorld RelationFirstWorld => _firstWorld; + public EcsWorld RelationSecondWorld => _secondWorld; + public EcsRelationPool Relation => _targetPool; + public bool IsMonoWorldRelation => _firstWorld == _secondWorld; + #endregion protected sealed override void OnBuild(Builder b) { diff --git a/src/EcsQuery.cs b/src/EcsQuery.cs index e554a71..21c0c25 100644 --- a/src/EcsQuery.cs +++ b/src/EcsQuery.cs @@ -10,7 +10,11 @@ namespace DCFApixels.DragonECS internal EcsWorld source; internal EcsGroup groupFilter; internal EcsQueryMask mask; + + #region Properties + internal EcsQueryMask Mask => mask; public EcsWorld World => source; + #endregion #region Builder protected virtual void Init(Builder b) { } @@ -81,7 +85,7 @@ namespace DCFApixels.DragonECS protected void ExecuteWhere(EcsReadonlyGroup group, EcsGroup result) { - var pools = World.GetAllPools(); + var pools = World.Pools; result.Clear(); foreach (var e in group) { @@ -98,7 +102,6 @@ namespace DCFApixels.DragonECS result.AggressiveAdd(e); next: continue; } - result.Sort(); } protected void ExecuteWhereAndSort(EcsReadonlyGroup group, EcsGroup result) { diff --git a/src/EcsWorld.cs b/src/EcsWorld.cs index d7e24f9..38121ce 100644 --- a/src/EcsWorld.cs +++ b/src/EcsWorld.cs @@ -72,6 +72,14 @@ namespace DCFApixels.DragonECS public EcsReadonlyGroup Entities => _allEntites.Readonly; #endregion + #region Internal Properties + internal EcsPoolBase[] Pools + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => _pools; + } + #endregion + #region Constructors/Destroy public EcsWorld(EcsPipeline pipline) { @@ -219,7 +227,7 @@ namespace DCFApixels.DragonECS } _gens[entityID] &= GEN_BITS; EcsEntity entity = new EcsEntity(entityID, ++_gens[entityID], uniqueID); - UnityEngine.Debug.Log($"{entityID} {_gens[entityID]} {uniqueID}"); + // UnityEngine.Debug.Log($"{entityID} {_gens[entityID]} {uniqueID}"); _entityCreate.OnEntityCreate(entity); _allEntites.Add(entityID); return entity; diff --git a/src/Pools/EcsAttachPool.cs b/src/Pools/EcsAttachPool.cs index ec2cb8d..3bd6479 100644 --- a/src/Pools/EcsAttachPool.cs +++ b/src/Pools/EcsAttachPool.cs @@ -15,7 +15,7 @@ namespace DCFApixels.DragonECS private PoolRunners _poolRunners; private EcsGroup _entities; - public EcsReadonlyGroup Entites => _entities.Readonly; + public EcsReadonlyGroup Entities => _entities.Readonly; #if (DEBUG && !DISABLE_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS private short _sanitizeTargetWorld = -1; diff --git a/src/Utils/IntDispenser.cs b/src/Utils/IntDispenser.cs index 113109f..c0b0b25 100644 --- a/src/Utils/IntDispenser.cs +++ b/src/Utils/IntDispenser.cs @@ -5,7 +5,7 @@ namespace DCFApixels.DragonECS { internal sealed class IntDispenser { - private readonly ConcurrentStack _freeInts; + private readonly ConcurrentQueue _freeInts; private int _increment; #region Properties @@ -16,12 +16,12 @@ namespace DCFApixels.DragonECS #region Constructor public IntDispenser() { - _freeInts = new ConcurrentStack(); + _freeInts = new ConcurrentQueue(); _increment = 0; } public IntDispenser(int startIncrement) { - _freeInts = new ConcurrentStack(); + _freeInts = new ConcurrentQueue(); _increment = startIncrement; } #endregion @@ -29,7 +29,7 @@ namespace DCFApixels.DragonECS #region GetFree/Release public int GetFree() { - if (!_freeInts.TryPop(out int result)) + if (!_freeInts.TryDequeue(out int result)) { result = Interlocked.Increment(ref _increment); } @@ -38,7 +38,7 @@ namespace DCFApixels.DragonECS public void Release(int released) { - _freeInts.Push(released); + _freeInts.Enqueue(released); } #endregion }