mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-19 02:24:37 +08:00
add devirtualization for virtual pool
This commit is contained in:
parent
a7276ce966
commit
281281f5f3
@ -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)
|
||||||
|
@ -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];
|
||||||
|
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user