From 281281f5f3b4816ee25251975077ee6f6dc54660 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Sat, 24 Feb 2024 03:30:23 +0800 Subject: [PATCH] add devirtualization for virtual pool --- src/EcsWorld.pools.cs | 14 +++++++++++--- src/Pools/EcsHybridPool.cs | 2 +- src/Pools/EcsVirtualPool.cs | 10 ++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/EcsWorld.pools.cs b/src/EcsWorld.pools.cs index 2c8b49b..b1b2815 100644 --- a/src/EcsWorld.pools.cs +++ b/src/EcsWorld.pools.cs @@ -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() where TPool : IEcsPoolImplementation, new() { int poolTypeCode = EcsTypeCode.Get(); @@ -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) diff --git a/src/Pools/EcsHybridPool.cs b/src/Pools/EcsHybridPool.cs index 838ea92..57a7d33 100644 --- a/src/Pools/EcsHybridPool.cs +++ b/src/Pools/EcsHybridPool.cs @@ -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]; diff --git a/src/Pools/EcsVirtualPool.cs b/src/Pools/EcsVirtualPool.cs index 45e57cc..4f9a166 100644 --- a/src/Pools/EcsVirtualPool.cs +++ b/src/Pools/EcsVirtualPool.cs @@ -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;