mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-17 17:34:36 +08:00
refactoring
This commit is contained in:
parent
79238733d7
commit
aa220f17e6
@ -429,7 +429,7 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
// source = group;
|
||||
_dense = group._dense;
|
||||
_count = group.Count;
|
||||
_count = group._count;
|
||||
_index = 0;
|
||||
}
|
||||
public int Current
|
||||
|
@ -11,7 +11,6 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
private EcsWorld _targetWorld;
|
||||
private EcsAttachPool<TAttachComponent> _targetPool;
|
||||
public EcsAttachPool<TAttachComponent> 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<TAttachComponent> Attach => _targetPool;
|
||||
public bool IsJoinExecuted => _isJoinExecuted;
|
||||
#endregion
|
||||
|
||||
protected sealed override void OnBuild(Builder b)
|
||||
{
|
||||
_targetPool = b.Include<TAttachComponent>();
|
||||
}
|
||||
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<TRelationComponent> : EcsJoinQueryBase
|
||||
where TRelationComponent : struct, IEcsRelationComponent
|
||||
@ -126,10 +132,14 @@ namespace DCFApixels.DragonECS
|
||||
private EcsWorld _firstWorld;
|
||||
private EcsWorld _secondWorld;
|
||||
private EcsRelationPool<TRelationComponent> _targetPool;
|
||||
public EcsRelationPool<TRelationComponent> Relation => _targetPool;
|
||||
|
||||
private bool _isInitTargetWorlds = false;
|
||||
|
||||
#region Properties
|
||||
public EcsWorld RelationFirstWorld => _firstWorld;
|
||||
public EcsWorld RelationSecondWorld => _secondWorld;
|
||||
public EcsRelationPool<TRelationComponent> Relation => _targetPool;
|
||||
public bool IsMonoWorldRelation => _firstWorld == _secondWorld;
|
||||
#endregion
|
||||
|
||||
protected sealed override void OnBuild(Builder b)
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -5,7 +5,7 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
internal sealed class IntDispenser
|
||||
{
|
||||
private readonly ConcurrentStack<int> _freeInts;
|
||||
private readonly ConcurrentQueue<int> _freeInts;
|
||||
private int _increment;
|
||||
|
||||
#region Properties
|
||||
@ -16,12 +16,12 @@ namespace DCFApixels.DragonECS
|
||||
#region Constructor
|
||||
public IntDispenser()
|
||||
{
|
||||
_freeInts = new ConcurrentStack<int>();
|
||||
_freeInts = new ConcurrentQueue<int>();
|
||||
_increment = 0;
|
||||
}
|
||||
public IntDispenser(int startIncrement)
|
||||
{
|
||||
_freeInts = new ConcurrentStack<int>();
|
||||
_freeInts = new ConcurrentQueue<int>();
|
||||
_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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user