mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 01:44:35 +08:00
remove & rework EcsAnonymousPool
This commit is contained in:
parent
ed40b87e9f
commit
234fc89711
@ -23,14 +23,11 @@ namespace DCFApixels.DragonECS
|
|||||||
public IEcsPool GetPool(Type componentType)
|
public IEcsPool GetPool(Type componentType)
|
||||||
//TODO. Есть проблема, возврат виртуального пула и последующая девиртуализация сделает ссылку невалидной. Одно из решений возвращать обертку
|
//TODO. Есть проблема, возврат виртуального пула и последующая девиртуализация сделает ссылку невалидной. Одно из решений возвращать обертку
|
||||||
{
|
{
|
||||||
#if DEBUG
|
|
||||||
#endif
|
|
||||||
int componentTypeID = GetComponentTypeID(componentType);
|
int componentTypeID = GetComponentTypeID(componentType);
|
||||||
ref var pool = ref _pools[componentTypeID];
|
ref var pool = ref _pools[componentTypeID];
|
||||||
if (pool == _nullPool)
|
if (pool == _nullPool)
|
||||||
{
|
{
|
||||||
pool = new EcsAnonymousPool();
|
return null;
|
||||||
pool.OnInit(this, _poolsMediator, componentTypeID);
|
|
||||||
}
|
}
|
||||||
return pool;
|
return pool;
|
||||||
}
|
}
|
||||||
@ -191,18 +188,13 @@ namespace DCFApixels.DragonECS
|
|||||||
|
|
||||||
var oldPool = _pools[componentTypeID];
|
var oldPool = _pools[componentTypeID];
|
||||||
|
|
||||||
//if (oldPool.IsNullOrDummy() == false)
|
if (oldPool != _nullPool)
|
||||||
//{
|
{
|
||||||
// Throw.UndefinedException();
|
Throw.UndefinedException();
|
||||||
//}
|
}
|
||||||
|
|
||||||
_pools[componentTypeID] = newPool;
|
_pools[componentTypeID] = newPool;
|
||||||
newPool.OnInit(this, _poolsMediator, componentTypeID);
|
newPool.OnInit(this, _poolsMediator, componentTypeID);
|
||||||
if (oldPool is EcsAnonymousPool virtualPool)
|
|
||||||
{
|
|
||||||
var data = virtualPool.GetDevirtualizationData();
|
|
||||||
newPool.OnDevirtualize(data);
|
|
||||||
}
|
|
||||||
return newPool;
|
return newPool;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -210,22 +210,6 @@ namespace DCFApixels.DragonECS
|
|||||||
_entities = new int[capacity];
|
_entities = new int[capacity];
|
||||||
_itemsCount = 0;
|
_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)
|
void IEcsPoolImplementation.OnWorldResize(int newSize)
|
||||||
{
|
{
|
||||||
Array.Resize(ref _mapping, newSize);
|
Array.Resize(ref _mapping, newSize);
|
||||||
@ -428,7 +412,7 @@ public class HybridTypeMapping
|
|||||||
|
|
||||||
public void AddIntsanceType(object instance)
|
public void AddIntsanceType(object instance)
|
||||||
{
|
{
|
||||||
_canInstantiatedTypes.Add(instance.GetType());
|
// _canInstantiatedTypes.Add(instance.GetType());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Declare<T>()
|
public void Declare<T>()
|
||||||
|
@ -178,22 +178,6 @@ namespace DCFApixels.DragonECS
|
|||||||
_items = new T[ArrayUtility.NormalizeSizeToPowerOfTwo(world.Config.Get_PoolComponentsCapacity())];
|
_items = new T[ArrayUtility.NormalizeSizeToPowerOfTwo(world.Config.Get_PoolComponentsCapacity())];
|
||||||
_itemsCount = 0;
|
_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)
|
void IEcsPoolImplementation.OnWorldResize(int newSize)
|
||||||
{
|
{
|
||||||
Array.Resize(ref _mapping, newSize);
|
Array.Resize(ref _mapping, newSize);
|
||||||
|
@ -53,7 +53,6 @@ namespace DCFApixels.DragonECS
|
|||||||
public interface IEcsPoolImplementation : IEcsPool
|
public interface IEcsPoolImplementation : IEcsPool
|
||||||
{
|
{
|
||||||
void OnInit(EcsWorld world, EcsWorld.PoolsMediator mediator, int componentTypeID);
|
void OnInit(EcsWorld world, EcsWorld.PoolsMediator mediator, int componentTypeID);
|
||||||
void OnDevirtualize(EcsAnonymousPool.Data data);
|
|
||||||
void OnWorldResize(int newSize);
|
void OnWorldResize(int newSize);
|
||||||
void OnReleaseDelEntityBuffer(ReadOnlySpan<int> buffer);
|
void OnReleaseDelEntityBuffer(ReadOnlySpan<int> buffer);
|
||||||
void OnWorldDestroy();
|
void OnWorldDestroy();
|
||||||
@ -114,10 +113,6 @@ namespace DCFApixels.DragonECS
|
|||||||
void IEcsPool.SetRaw(int entity, object dataRaw) => throw new NotImplementedException();
|
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, int toEntityID) => throw new NotImplementedException();
|
||||||
void IEcsPool.Copy(int fromEntityID, EcsWorld toWorld, 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
|
#endregion
|
||||||
|
|
||||||
#region Callbacks
|
#region Callbacks
|
||||||
|
@ -159,18 +159,6 @@ namespace DCFApixels.DragonECS
|
|||||||
_mapping = new bool[world.Capacity];
|
_mapping = new bool[world.Capacity];
|
||||||
_count = 0;
|
_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)
|
void IEcsPoolImplementation.OnWorldResize(int newSize)
|
||||||
{
|
{
|
||||||
Array.Resize(ref _mapping, newSize);
|
Array.Resize(ref _mapping, newSize);
|
||||||
|
@ -5,8 +5,8 @@ using System.Collections;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
//EcsAnonymousPool > EcsVirtualPool<T> > EcsPool<T>
|
|
||||||
public class EcsAnonymousPool : IEcsPoolImplementation, IEnumerable
|
internal class VirtualPool : IEcsPoolImplementation, IEnumerable
|
||||||
{
|
{
|
||||||
private EcsWorld _source;
|
private EcsWorld _source;
|
||||||
private Type _componentType;
|
private Type _componentType;
|
||||||
@ -200,7 +200,7 @@ public class EcsAnonymousPool : IEcsPoolImplementation, IEnumerable
|
|||||||
}
|
}
|
||||||
public readonly ref struct Data
|
public readonly ref struct Data
|
||||||
{
|
{
|
||||||
private readonly EcsAnonymousPool _target;
|
private readonly VirtualPool _target;
|
||||||
|
|
||||||
public int ComponentsCount
|
public int ComponentsCount
|
||||||
{
|
{
|
||||||
@ -216,16 +216,16 @@ public class EcsAnonymousPool : IEcsPoolImplementation, IEnumerable
|
|||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public Data(EcsAnonymousPool target)
|
public Data(VirtualPool target)
|
||||||
{
|
{
|
||||||
_target = target;
|
_target = target;
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly ref struct ListenersIterator
|
public readonly ref struct ListenersIterator
|
||||||
{
|
{
|
||||||
private readonly EcsAnonymousPool _target;
|
private readonly VirtualPool _target;
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public ListenersIterator(EcsAnonymousPool target)
|
public ListenersIterator(VirtualPool target)
|
||||||
{
|
{
|
||||||
_target = target;
|
_target = target;
|
||||||
}
|
}
|
||||||
@ -235,9 +235,9 @@ public class EcsAnonymousPool : IEcsPoolImplementation, IEnumerable
|
|||||||
|
|
||||||
public readonly ref struct RawDataIterator
|
public readonly ref struct RawDataIterator
|
||||||
{
|
{
|
||||||
private readonly EcsAnonymousPool _target;
|
private readonly VirtualPool _target;
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public RawDataIterator(EcsAnonymousPool target)
|
public RawDataIterator(VirtualPool target)
|
||||||
{
|
{
|
||||||
_target = target;
|
_target = target;
|
||||||
}
|
}
|
||||||
@ -309,6 +309,6 @@ public static class VirtualPoolExtensions
|
|||||||
{
|
{
|
||||||
public static bool IsVirtual(this IEcsPool self)
|
public static bool IsVirtual(this IEcsPool self)
|
||||||
{
|
{
|
||||||
return self is EcsAnonymousPool;
|
return self is VirtualPool;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user