mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-19 02:24:37 +08:00
refactoring
This commit is contained in:
parent
79238733d7
commit
aa220f17e6
@ -429,7 +429,7 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
// source = group;
|
// source = group;
|
||||||
_dense = group._dense;
|
_dense = group._dense;
|
||||||
_count = group.Count;
|
_count = group._count;
|
||||||
_index = 0;
|
_index = 0;
|
||||||
}
|
}
|
||||||
public int Current
|
public int Current
|
||||||
|
@ -11,7 +11,6 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
private EcsWorld _targetWorld;
|
private EcsWorld _targetWorld;
|
||||||
private EcsAttachPool<TAttachComponent> _targetPool;
|
private EcsAttachPool<TAttachComponent> _targetPool;
|
||||||
public EcsAttachPool<TAttachComponent> Attach => _targetPool;
|
|
||||||
|
|
||||||
|
|
||||||
private int _targetWorldCapacity = -1;
|
private int _targetWorldCapacity = -1;
|
||||||
@ -22,19 +21,26 @@ namespace DCFApixels.DragonECS
|
|||||||
private EntityLinkedList _linkedBasket;
|
private EntityLinkedList _linkedBasket;
|
||||||
|
|
||||||
private bool _isJoinExecuted = false;
|
private bool _isJoinExecuted = false;
|
||||||
public bool IsJoinExecuted => _isJoinExecuted;
|
|
||||||
|
|
||||||
private bool _isInitTargetWorlds = false;
|
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)
|
protected sealed override void OnBuild(Builder b)
|
||||||
{
|
{
|
||||||
_targetPool = b.Include<TAttachComponent>();
|
_targetPool = b.Include<TAttachComponent>();
|
||||||
}
|
}
|
||||||
public sealed override void ExecuteWhere()
|
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()
|
public sealed override void ExecuteJoin()
|
||||||
{
|
{
|
||||||
@ -70,11 +76,11 @@ namespace DCFApixels.DragonECS
|
|||||||
foreach (var attachID in groupFilter)
|
foreach (var attachID in groupFilter)
|
||||||
{
|
{
|
||||||
EcsEntity attachTarget = _targetPool.Read(attachID).Target;
|
EcsEntity attachTarget = _targetPool.Read(attachID).Target;
|
||||||
// if (!attachTarget.IsAlive)//TODO пофиксить IsAlive
|
if (!attachTarget.IsAlive)//TODO пофиксить IsAlive
|
||||||
//{
|
{
|
||||||
// _targetPool.Del(attachID);
|
//_targetPool.Del(attachID);
|
||||||
// continue;
|
continue;
|
||||||
//}
|
}
|
||||||
int attachTargetID = attachTarget.id;
|
int attachTargetID = attachTarget.id;
|
||||||
|
|
||||||
ref int nodeIndex = ref _mapping[attachTargetID];
|
ref int nodeIndex = ref _mapping[attachTargetID];
|
||||||
@ -88,10 +94,9 @@ namespace DCFApixels.DragonECS
|
|||||||
_isJoinExecuted = true;
|
_isJoinExecuted = true;
|
||||||
_execute.End();
|
_execute.End();
|
||||||
}
|
}
|
||||||
public EntityLinkedList.EnumerableSpan GetNodes(int entityID) => _linkedBasket.Span(_mapping[entityID], _counts[entityID]);
|
|
||||||
private void InitTargetWorlds()
|
private void InitTargetWorlds()
|
||||||
{
|
{
|
||||||
foreach (var e in _targetPool.Entites)
|
foreach (var e in _targetPool.Entities)
|
||||||
{
|
{
|
||||||
ref readonly var rel = ref _targetPool.Read(e);
|
ref readonly var rel = ref _targetPool.Read(e);
|
||||||
//if (rel.Target.IsNotNull)
|
//if (rel.Target.IsNotNull)
|
||||||
@ -119,6 +124,7 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return groupFilter.GetEnumerator();
|
return groupFilter.GetEnumerator();
|
||||||
}
|
}
|
||||||
|
public EntityLinkedList.EnumerableSpan GetNodes(int entityID) => _linkedBasket.Span(_mapping[entityID], _counts[entityID]);
|
||||||
}
|
}
|
||||||
public abstract class EcsJoinRelationQuery<TRelationComponent> : EcsJoinQueryBase
|
public abstract class EcsJoinRelationQuery<TRelationComponent> : EcsJoinQueryBase
|
||||||
where TRelationComponent : struct, IEcsRelationComponent
|
where TRelationComponent : struct, IEcsRelationComponent
|
||||||
@ -126,10 +132,14 @@ namespace DCFApixels.DragonECS
|
|||||||
private EcsWorld _firstWorld;
|
private EcsWorld _firstWorld;
|
||||||
private EcsWorld _secondWorld;
|
private EcsWorld _secondWorld;
|
||||||
private EcsRelationPool<TRelationComponent> _targetPool;
|
private EcsRelationPool<TRelationComponent> _targetPool;
|
||||||
public EcsRelationPool<TRelationComponent> Relation => _targetPool;
|
|
||||||
|
|
||||||
private bool _isInitTargetWorlds = false;
|
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)
|
protected sealed override void OnBuild(Builder b)
|
||||||
{
|
{
|
||||||
|
@ -10,7 +10,11 @@ namespace DCFApixels.DragonECS
|
|||||||
internal EcsWorld source;
|
internal EcsWorld source;
|
||||||
internal EcsGroup groupFilter;
|
internal EcsGroup groupFilter;
|
||||||
internal EcsQueryMask mask;
|
internal EcsQueryMask mask;
|
||||||
|
|
||||||
|
#region Properties
|
||||||
|
internal EcsQueryMask Mask => mask;
|
||||||
public EcsWorld World => source;
|
public EcsWorld World => source;
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Builder
|
#region Builder
|
||||||
protected virtual void Init(Builder b) { }
|
protected virtual void Init(Builder b) { }
|
||||||
@ -81,7 +85,7 @@ namespace DCFApixels.DragonECS
|
|||||||
|
|
||||||
protected void ExecuteWhere(EcsReadonlyGroup group, EcsGroup result)
|
protected void ExecuteWhere(EcsReadonlyGroup group, EcsGroup result)
|
||||||
{
|
{
|
||||||
var pools = World.GetAllPools();
|
var pools = World.Pools;
|
||||||
result.Clear();
|
result.Clear();
|
||||||
foreach (var e in group)
|
foreach (var e in group)
|
||||||
{
|
{
|
||||||
@ -98,7 +102,6 @@ namespace DCFApixels.DragonECS
|
|||||||
result.AggressiveAdd(e);
|
result.AggressiveAdd(e);
|
||||||
next: continue;
|
next: continue;
|
||||||
}
|
}
|
||||||
result.Sort();
|
|
||||||
}
|
}
|
||||||
protected void ExecuteWhereAndSort(EcsReadonlyGroup group, EcsGroup result)
|
protected void ExecuteWhereAndSort(EcsReadonlyGroup group, EcsGroup result)
|
||||||
{
|
{
|
||||||
|
@ -72,6 +72,14 @@ namespace DCFApixels.DragonECS
|
|||||||
public EcsReadonlyGroup Entities => _allEntites.Readonly;
|
public EcsReadonlyGroup Entities => _allEntites.Readonly;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Internal Properties
|
||||||
|
internal EcsPoolBase[] Pools
|
||||||
|
{
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
get => _pools;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Constructors/Destroy
|
#region Constructors/Destroy
|
||||||
public EcsWorld(EcsPipeline pipline)
|
public EcsWorld(EcsPipeline pipline)
|
||||||
{
|
{
|
||||||
@ -219,7 +227,7 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
_gens[entityID] &= GEN_BITS;
|
_gens[entityID] &= GEN_BITS;
|
||||||
EcsEntity entity = new EcsEntity(entityID, ++_gens[entityID], uniqueID);
|
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);
|
_entityCreate.OnEntityCreate(entity);
|
||||||
_allEntites.Add(entityID);
|
_allEntites.Add(entityID);
|
||||||
return entity;
|
return entity;
|
||||||
|
@ -15,7 +15,7 @@ namespace DCFApixels.DragonECS
|
|||||||
private PoolRunners _poolRunners;
|
private PoolRunners _poolRunners;
|
||||||
|
|
||||||
private EcsGroup _entities;
|
private EcsGroup _entities;
|
||||||
public EcsReadonlyGroup Entites => _entities.Readonly;
|
public EcsReadonlyGroup Entities => _entities.Readonly;
|
||||||
|
|
||||||
#if (DEBUG && !DISABLE_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS
|
#if (DEBUG && !DISABLE_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS
|
||||||
private short _sanitizeTargetWorld = -1;
|
private short _sanitizeTargetWorld = -1;
|
||||||
|
@ -5,7 +5,7 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
internal sealed class IntDispenser
|
internal sealed class IntDispenser
|
||||||
{
|
{
|
||||||
private readonly ConcurrentStack<int> _freeInts;
|
private readonly ConcurrentQueue<int> _freeInts;
|
||||||
private int _increment;
|
private int _increment;
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
@ -16,12 +16,12 @@ namespace DCFApixels.DragonECS
|
|||||||
#region Constructor
|
#region Constructor
|
||||||
public IntDispenser()
|
public IntDispenser()
|
||||||
{
|
{
|
||||||
_freeInts = new ConcurrentStack<int>();
|
_freeInts = new ConcurrentQueue<int>();
|
||||||
_increment = 0;
|
_increment = 0;
|
||||||
}
|
}
|
||||||
public IntDispenser(int startIncrement)
|
public IntDispenser(int startIncrement)
|
||||||
{
|
{
|
||||||
_freeInts = new ConcurrentStack<int>();
|
_freeInts = new ConcurrentQueue<int>();
|
||||||
_increment = startIncrement;
|
_increment = startIncrement;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
@ -29,7 +29,7 @@ namespace DCFApixels.DragonECS
|
|||||||
#region GetFree/Release
|
#region GetFree/Release
|
||||||
public int GetFree()
|
public int GetFree()
|
||||||
{
|
{
|
||||||
if (!_freeInts.TryPop(out int result))
|
if (!_freeInts.TryDequeue(out int result))
|
||||||
{
|
{
|
||||||
result = Interlocked.Increment(ref _increment);
|
result = Interlocked.Increment(ref _increment);
|
||||||
}
|
}
|
||||||
@ -38,7 +38,7 @@ namespace DCFApixels.DragonECS
|
|||||||
|
|
||||||
public void Release(int released)
|
public void Release(int released)
|
||||||
{
|
{
|
||||||
_freeInts.Push(released);
|
_freeInts.Enqueue(released);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user