mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2026-04-22 01:45:55 +08:00
Update EcsPool.cs
This commit is contained in:
parent
111ac473b6
commit
1953680eb2
@ -10,6 +10,7 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using static DCFApixels.DragonECS.Core.Internal.MemoryAllocator;
|
||||
#if ENABLE_IL2CPP
|
||||
using Unity.IL2CPP.CompilerServices;
|
||||
#endif
|
||||
@ -46,8 +47,7 @@ namespace DCFApixels.DragonECS
|
||||
private MappingSlot[] _mapping;// index = entityID / value = itemIndex;/ value = 0 = no entityID.
|
||||
private T[] _items; // dense; _items[0] - fake component.
|
||||
private int _itemsCount = 0;
|
||||
private int[] _recycledItems;
|
||||
private int _recycledItemsCount = 0;
|
||||
private int _recycledItemsCount;
|
||||
|
||||
private readonly IEcsComponentLifecycle<T> _customLifecycle = EcsComponentLifecycle<T>.CustomHandler;
|
||||
private readonly bool _isCustomLifecycle = EcsComponentLifecycle<T>.IsCustom;
|
||||
@ -105,7 +105,6 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
_items = new T[capacity];
|
||||
_dense = new int[capacity];
|
||||
_recycledItems = new int[recycledCapacity];
|
||||
}
|
||||
void IEcsPoolImplementation.OnInit(EcsWorld world, EcsWorld.PoolsMediator mediator, int componentTypeID)
|
||||
{
|
||||
@ -122,10 +121,6 @@ namespace DCFApixels.DragonECS
|
||||
_items = new T[ArrayUtility.CeilPow2Safe(worldConfig.PoolComponentsCapacity)];
|
||||
_dense = new int[ArrayUtility.CeilPow2Safe(worldConfig.PoolComponentsCapacity)];
|
||||
}
|
||||
if (_recycledItems == null)
|
||||
{
|
||||
_recycledItems = new int[worldConfig.PoolRecycledComponentsCapacity];
|
||||
}
|
||||
}
|
||||
void IEcsPoolImplementation.OnWorldDestroy() { }
|
||||
#endregion
|
||||
@ -145,7 +140,10 @@ namespace DCFApixels.DragonECS
|
||||
#endif
|
||||
if (_recycledItemsCount > 0)
|
||||
{
|
||||
mappingSlot.ComponentPosIndex = _recycledItems[--_recycledItemsCount];
|
||||
//mappingSlot.ComponentPosIndex = _recycledItems[--_recycledItemsCount];
|
||||
//mappingSlot.ComponentPosIndex = _dense[_dense.Length - _recycledItemsCount] & int.MaxValue;
|
||||
mappingSlot.ComponentPosIndex = _dense[_dense.Length - _recycledItemsCount];
|
||||
_recycledItemsCount--;
|
||||
_itemsCount++;
|
||||
}
|
||||
else
|
||||
@ -201,7 +199,9 @@ namespace DCFApixels.DragonECS
|
||||
#endif
|
||||
if (_recycledItemsCount > 0)
|
||||
{
|
||||
mappingSlot.ComponentPosIndex = _recycledItems[--_recycledItemsCount];
|
||||
//mappingSlot.ComponentPosIndex = _dense[_dense.Length - _recycledItemsCount] & int.MaxValue;
|
||||
mappingSlot.ComponentPosIndex = _dense[_dense.Length - _recycledItemsCount];
|
||||
_recycledItemsCount--;
|
||||
_itemsCount++;
|
||||
}
|
||||
else
|
||||
@ -229,7 +229,7 @@ namespace DCFApixels.DragonECS
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool Has(int entityID)
|
||||
{
|
||||
return _mapping[entityID].ComponentPosIndex != 0;
|
||||
return _mapping[entityID].ComponentPosIndex > 0;
|
||||
}
|
||||
public void Del(int entityID)
|
||||
{
|
||||
@ -243,21 +243,27 @@ namespace DCFApixels.DragonECS
|
||||
if (_isLocked) { return; }
|
||||
#endif
|
||||
EcsComponentLifecycle<T>.OnDel(_isCustomLifecycle, _customLifecycle, ref _items[mappingSlot.ComponentPosIndex], _worldID, entityID);
|
||||
if (_recycledItemsCount >= _recycledItems.Length)
|
||||
{
|
||||
Array.Resize(ref _recycledItems, ArrayUtility.NextPow2Safe(_recycledItemsCount));
|
||||
}
|
||||
|
||||
//_dense[_sparse[entityID]] = _dense[_count];
|
||||
//_sparse[_dense[_count--]] = _sparse[entityID];
|
||||
|
||||
//_dense[_mapping[entityID].EntityPosIndex] = _dense[_denseCount];
|
||||
//_mapping[_dense[_denseCount--]].EntityPosIndex = _mapping[entityID].EntityPosIndex;
|
||||
_dense[mappingSlot.EntityPosIndex] = _dense[_denseCount];
|
||||
_mapping[_dense[_denseCount--]].EntityPosIndex = mappingSlot.EntityPosIndex;
|
||||
|
||||
//_dense[mappingSlot.EntityPosIndex] = _dense[_denseCount];
|
||||
//_mapping[_dense[_denseCount--]].EntityPosIndex = mappingSlot.EntityPosIndex;
|
||||
|
||||
|
||||
_recycledItems[_recycledItemsCount++] = mappingSlot.ComponentPosIndex;
|
||||
_dense[mappingSlot.EntityPosIndex] = _dense[--_denseCount];
|
||||
_mapping[_dense[_denseCount]].EntityPosIndex = mappingSlot.EntityPosIndex;
|
||||
|
||||
_recycledItemsCount++;
|
||||
//_dense[_dense.Length - _recycledItemsCount] = mappingSlot.ComponentPosIndex | int.MinValue;
|
||||
_dense[_dense.Length - _recycledItemsCount] = mappingSlot.ComponentPosIndex;
|
||||
mappingSlot.ComponentPosIndex = 0;
|
||||
_itemsCount--;
|
||||
_mediator.UnregisterComponent(entityID, _componentTypeID, _maskBit);
|
||||
|
||||
#if !DRAGONECS_DISABLE_POOLS_EVENTS
|
||||
if (_hasAnyListener) { _listeners.InvokeOnDel(entityID); }
|
||||
#endif
|
||||
|
||||
Loading…
Reference in New Issue
Block a user