add devirtualization for virtual pool

This commit is contained in:
Mikhail 2024-02-24 03:30:23 +08:00
parent a7276ce966
commit 281281f5f3
3 changed files with 22 additions and 4 deletions

View File

@ -100,7 +100,7 @@ namespace DCFApixels.DragonECS
} }
#endregion #endregion
#region Declare/Create #region Declare
private int DeclareOrGetComponentTypeID(int componentTypeCode) private int DeclareOrGetComponentTypeID(int componentTypeCode)
{ {
if (_cmpTypeCode_2_CmpTypeIDs.TryGetValue(componentTypeCode, out int ComponentTypeID) == false) if (_cmpTypeCode_2_CmpTypeIDs.TryGetValue(componentTypeCode, out int ComponentTypeID) == false)
@ -120,6 +120,9 @@ namespace DCFApixels.DragonECS
} }
return false; return false;
} }
#endregion
#region Create
private TPool CreatePool<TPool>() where TPool : IEcsPoolImplementation, new() private TPool CreatePool<TPool>() where TPool : IEcsPoolImplementation, new()
{ {
int poolTypeCode = EcsTypeCode.Get<TPool>(); 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(); Throw.UndefinedException();
} }
@ -197,7 +206,6 @@ namespace DCFApixels.DragonECS
} }
#endregion #endregion
#region Pools mediation #region Pools mediation
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private void RegisterEntityComponent(int entityID, int componentTypeID, EcsMaskChunck maskBit) private void RegisterEntityComponent(int entityID, int componentTypeID, EcsMaskChunck maskBit)

View File

@ -201,7 +201,7 @@ namespace DCFApixels.DragonECS
_componentTypeID = componentTypeID; _componentTypeID = componentTypeID;
_maskBit = EcsMaskChunck.FromID(componentTypeID); _maskBit = EcsMaskChunck.FromID(componentTypeID);
const int capacity = 512; const int capacity = 512;//TODO заменить на значение из конфига
_mapping = new int[world.Capacity]; _mapping = new int[world.Capacity];
_recycledItems = new int[128]; _recycledItems = new int[128];

View File

@ -22,6 +22,8 @@ public class EcsVirtualPool : IEcsPoolImplementation, IEnumerable
private EcsWorld.PoolsMediator _mediator; private EcsWorld.PoolsMediator _mediator;
private bool _isDevirtualized = false;
#region Properties #region Properties
public int ComponentID public int ComponentID
{ {
@ -43,6 +45,10 @@ public class EcsVirtualPool : IEcsPoolImplementation, IEnumerable
{ {
get { return _mapping.Length; } get { return _mapping.Length; }
} }
public bool IsDevirtualized
{
get { return _isDevirtualized; }
}
#endregion #endregion
#region Callbacks #region Callbacks
@ -187,6 +193,10 @@ public class EcsVirtualPool : IEcsPoolImplementation, IEnumerable
#endregion #endregion
#region Devirtualization #region Devirtualization
public Data GetDevirtualizationData()
{
return new Data(this);
}
public readonly ref struct Data public readonly ref struct Data
{ {
private readonly EcsVirtualPool _target; private readonly EcsVirtualPool _target;