mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 01:44:35 +08:00
add devirtualization for virtual pool
This commit is contained in:
parent
a7276ce966
commit
281281f5f3
@ -100,7 +100,7 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Declare/Create
|
||||
#region Declare
|
||||
private int DeclareOrGetComponentTypeID(int componentTypeCode)
|
||||
{
|
||||
if (_cmpTypeCode_2_CmpTypeIDs.TryGetValue(componentTypeCode, out int ComponentTypeID) == false)
|
||||
@ -120,6 +120,9 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Create
|
||||
private TPool CreatePool<TPool>() where TPool : IEcsPoolImplementation, new()
|
||||
{
|
||||
int poolTypeCode = EcsTypeCode.Get<TPool>();
|
||||
@ -186,7 +189,13 @@ namespace DCFApixels.DragonECS
|
||||
|
||||
}
|
||||
|
||||
if (_pools[componentTypeID] != _nullPool)
|
||||
var oldPool = _pools[componentTypeID];
|
||||
if (oldPool is EcsVirtualPool virtualPool)
|
||||
{
|
||||
var data = virtualPool.GetDevirtualizationData();
|
||||
newPool.OnDevirtualize(data);
|
||||
}
|
||||
if (oldPool.IsNullOrDummy() == false)
|
||||
{
|
||||
Throw.UndefinedException();
|
||||
}
|
||||
@ -197,7 +206,6 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region Pools mediation
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private void RegisterEntityComponent(int entityID, int componentTypeID, EcsMaskChunck maskBit)
|
||||
|
@ -201,7 +201,7 @@ namespace DCFApixels.DragonECS
|
||||
_componentTypeID = componentTypeID;
|
||||
_maskBit = EcsMaskChunck.FromID(componentTypeID);
|
||||
|
||||
const int capacity = 512;
|
||||
const int capacity = 512;//TODO заменить на значение из конфига
|
||||
|
||||
_mapping = new int[world.Capacity];
|
||||
_recycledItems = new int[128];
|
||||
|
@ -22,6 +22,8 @@ public class EcsVirtualPool : IEcsPoolImplementation, IEnumerable
|
||||
|
||||
private EcsWorld.PoolsMediator _mediator;
|
||||
|
||||
private bool _isDevirtualized = false;
|
||||
|
||||
#region Properties
|
||||
public int ComponentID
|
||||
{
|
||||
@ -43,6 +45,10 @@ public class EcsVirtualPool : IEcsPoolImplementation, IEnumerable
|
||||
{
|
||||
get { return _mapping.Length; }
|
||||
}
|
||||
public bool IsDevirtualized
|
||||
{
|
||||
get { return _isDevirtualized; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Callbacks
|
||||
@ -187,6 +193,10 @@ public class EcsVirtualPool : IEcsPoolImplementation, IEnumerable
|
||||
#endregion
|
||||
|
||||
#region Devirtualization
|
||||
public Data GetDevirtualizationData()
|
||||
{
|
||||
return new Data(this);
|
||||
}
|
||||
public readonly ref struct Data
|
||||
{
|
||||
private readonly EcsVirtualPool _target;
|
||||
|
Loading…
Reference in New Issue
Block a user