remove & rework EcsAnonymousPool

This commit is contained in:
Mikhail 2024-02-24 16:59:09 +08:00
parent ed40b87e9f
commit 234fc89711
6 changed files with 15 additions and 72 deletions

View File

@ -23,14 +23,11 @@ namespace DCFApixels.DragonECS
public IEcsPool GetPool(Type componentType)
//TODO. Есть проблема, возврат виртуального пула и последующая девиртуализация сделает ссылку невалидной. Одно из решений возвращать обертку
{
#if DEBUG
#endif
int componentTypeID = GetComponentTypeID(componentType);
ref var pool = ref _pools[componentTypeID];
if (pool == _nullPool)
{
pool = new EcsAnonymousPool();
pool.OnInit(this, _poolsMediator, componentTypeID);
return null;
}
return pool;
}
@ -191,18 +188,13 @@ namespace DCFApixels.DragonECS
var oldPool = _pools[componentTypeID];
//if (oldPool.IsNullOrDummy() == false)
//{
// Throw.UndefinedException();
//}
if (oldPool != _nullPool)
{
Throw.UndefinedException();
}
_pools[componentTypeID] = newPool;
newPool.OnInit(this, _poolsMediator, componentTypeID);
if (oldPool is EcsAnonymousPool virtualPool)
{
var data = virtualPool.GetDevirtualizationData();
newPool.OnDevirtualize(data);
}
return newPool;
}
#endregion

View File

@ -210,22 +210,6 @@ namespace DCFApixels.DragonECS
_entities = new int[capacity];
_itemsCount = 0;
}
void IEcsPoolImplementation.OnDevirtualize(EcsAnonymousPool.Data data)
{
if (_items.Length < data.ComponentsCount)
{
Array.Resize(ref _items, ArrayUtility.NormalizeSizeToPowerOfTwo(data.ComponentsCount));
}
foreach (var item in data.RawComponents)
{
_mapping[item.EntityID] = ++_itemsCount;
_items[_itemsCount] = (T)item.RawData;
}
foreach (var item in data.Listeners)
{
_listeners.Add(item);
}
}
void IEcsPoolImplementation.OnWorldResize(int newSize)
{
Array.Resize(ref _mapping, newSize);
@ -428,7 +412,7 @@ public class HybridTypeMapping
public void AddIntsanceType(object instance)
{
_canInstantiatedTypes.Add(instance.GetType());
// _canInstantiatedTypes.Add(instance.GetType());
}
public void Declare<T>()

View File

@ -178,22 +178,6 @@ namespace DCFApixels.DragonECS
_items = new T[ArrayUtility.NormalizeSizeToPowerOfTwo(world.Config.Get_PoolComponentsCapacity())];
_itemsCount = 0;
}
void IEcsPoolImplementation.OnDevirtualize(EcsAnonymousPool.Data data)
{
if(_items.Length < data.ComponentsCount)
{
Array.Resize(ref _items, ArrayUtility.NormalizeSizeToPowerOfTwo(data.ComponentsCount));
}
foreach (var item in data.RawComponents)
{
_mapping[item.EntityID] = ++_itemsCount;
_items[_itemsCount] = (T)item.RawData;
}
foreach (var item in data.Listeners)
{
_listeners.Add(item);
}
}
void IEcsPoolImplementation.OnWorldResize(int newSize)
{
Array.Resize(ref _mapping, newSize);

View File

@ -53,7 +53,6 @@ namespace DCFApixels.DragonECS
public interface IEcsPoolImplementation : IEcsPool
{
void OnInit(EcsWorld world, EcsWorld.PoolsMediator mediator, int componentTypeID);
void OnDevirtualize(EcsAnonymousPool.Data data);
void OnWorldResize(int newSize);
void OnReleaseDelEntityBuffer(ReadOnlySpan<int> buffer);
void OnWorldDestroy();
@ -114,10 +113,6 @@ namespace DCFApixels.DragonECS
void IEcsPool.SetRaw(int entity, object dataRaw) => throw new NotImplementedException();
void IEcsPool.Copy(int fromEntityID, int toEntityID) => throw new NotImplementedException();
void IEcsPool.Copy(int fromEntityID, EcsWorld toWorld, int toEntityID) => throw new NotImplementedException();
void IEcsPoolImplementation.OnDevirtualize(EcsAnonymousPool.Data virtualPoolData)
{
Throw.UndefinedException();
}
#endregion
#region Callbacks

View File

@ -159,18 +159,6 @@ namespace DCFApixels.DragonECS
_mapping = new bool[world.Capacity];
_count = 0;
}
void IEcsPoolImplementation.OnDevirtualize(EcsAnonymousPool.Data data)
{
_count = data.ComponentsCount;
foreach (var item in data.RawComponents)
{
_mapping[item.EntityID] = true;
}
foreach (var item in data.Listeners)
{
_listeners.Add(item);
}
}
void IEcsPoolImplementation.OnWorldResize(int newSize)
{
Array.Resize(ref _mapping, newSize);

View File

@ -5,8 +5,8 @@ using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
//EcsAnonymousPool > EcsVirtualPool<T> > EcsPool<T>
public class EcsAnonymousPool : IEcsPoolImplementation, IEnumerable
internal class VirtualPool : IEcsPoolImplementation, IEnumerable
{
private EcsWorld _source;
private Type _componentType;
@ -200,7 +200,7 @@ public class EcsAnonymousPool : IEcsPoolImplementation, IEnumerable
}
public readonly ref struct Data
{
private readonly EcsAnonymousPool _target;
private readonly VirtualPool _target;
public int ComponentsCount
{
@ -216,16 +216,16 @@ public class EcsAnonymousPool : IEcsPoolImplementation, IEnumerable
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Data(EcsAnonymousPool target)
public Data(VirtualPool target)
{
_target = target;
}
public readonly ref struct ListenersIterator
{
private readonly EcsAnonymousPool _target;
private readonly VirtualPool _target;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ListenersIterator(EcsAnonymousPool target)
public ListenersIterator(VirtualPool target)
{
_target = target;
}
@ -235,9 +235,9 @@ public class EcsAnonymousPool : IEcsPoolImplementation, IEnumerable
public readonly ref struct RawDataIterator
{
private readonly EcsAnonymousPool _target;
private readonly VirtualPool _target;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public RawDataIterator(EcsAnonymousPool target)
public RawDataIterator(VirtualPool target)
{
_target = target;
}
@ -309,6 +309,6 @@ public static class VirtualPoolExtensions
{
public static bool IsVirtual(this IEcsPool self)
{
return self is EcsAnonymousPool;
return self is VirtualPool;
}
}