using DCFApixels.DragonECS.Utils; using System; namespace DCFApixels.DragonECS { public partial class EcsWorld { internal readonly struct PoolCache : IEcsWorldComponent> where TPool : IEcsPoolImplementation, new() { public readonly TPool instance; public PoolCache(TPool instance) => this.instance = instance; void IEcsWorldComponent>.Init(ref PoolCache component, EcsWorld world) { component = new PoolCache(world.CreatePool()); } void IEcsWorldComponent>.OnDestroy(ref PoolCache component, EcsWorld world) { component = default; } } private TPool CreatePool() where TPool : IEcsPoolImplementation, new() { int index = WorldMetaStorage.GetPoolID(_worldTypeID); if (index >= _pools.Length) { int oldCapacity = _pools.Length; Array.Resize(ref _pools, _pools.Length << 1); ArrayUtility.Fill(_pools, _nullPool, oldCapacity, oldCapacity - _pools.Length); } if (_pools[index] == _nullPool) { var pool = new TPool(); _pools[index] = pool; pool.OnInit(this, index); } return (TPool)_pools[index]; } } }