diff --git a/src/EcsWorld.cache.cs b/src/EcsWorld.cache.cs index 56ae21c..6862d0b 100644 --- a/src/EcsWorld.cache.cs +++ b/src/EcsWorld.cache.cs @@ -1,20 +1,21 @@ using DCFApixels.DragonECS.Utils; using System; +using System.Reflection; namespace DCFApixels.DragonECS { public partial class EcsWorld { - internal readonly struct PoolCache : IEcsWorldComponent> - where TPool : IEcsPoolImplementation, new() + internal readonly struct PoolCache : IEcsWorldComponent> + where T : IEcsPoolImplementation, new() { - public readonly TPool instance; - public PoolCache(TPool instance) => this.instance = instance; - void IEcsWorldComponent>.Init(ref PoolCache component, EcsWorld world) + public readonly T instance; + public PoolCache(T instance) => this.instance = instance; + void IEcsWorldComponent>.Init(ref PoolCache component, EcsWorld world) { - component = new PoolCache(world.CreatePool()); + component = new PoolCache(world.CreatePool()); } - void IEcsWorldComponent>.OnDestroy(ref PoolCache component, EcsWorld world) + void IEcsWorldComponent>.OnDestroy(ref PoolCache component, EcsWorld world) { component = default; } @@ -36,5 +37,35 @@ namespace DCFApixels.DragonECS } return (TPool)_pools[index]; } + internal readonly struct AspectCache : IEcsWorldComponent> + where T : EcsAspect + { + public readonly T instance; + public AspectCache(T instance) => this.instance = instance; + void IEcsWorldComponent>.Init(ref AspectCache component, EcsWorld world) + { + component = new AspectCache(EcsAspect.Builder.Build(world)); + } + void IEcsWorldComponent>.OnDestroy(ref AspectCache component, EcsWorld world) + { + component = default; + } + } + internal readonly struct ExcecutorCache : IEcsWorldComponent> + where T : EcsQueryExecutor, new() + { + public readonly T instance; + public ExcecutorCache(T instance) => this.instance = instance; + void IEcsWorldComponent>.Init(ref ExcecutorCache component, EcsWorld world) + { + T instance = new T(); + instance.Initialize(world); + component = new ExcecutorCache(instance); + } + void IEcsWorldComponent>.OnDestroy(ref ExcecutorCache component, EcsWorld world) + { + component = default; + } + } } } diff --git a/src/EcsWorld.cs b/src/EcsWorld.cs index d3f2c21..797abdb 100644 --- a/src/EcsWorld.cs +++ b/src/EcsWorld.cs @@ -27,9 +27,6 @@ namespace DCFApixels.DragonECS internal IEcsPoolImplementation[] _pools; private EcsNullPool _nullPool = EcsNullPool.instance; - private EcsAspect[] _aspects; - private EcsQueryExecutor[] _executors; - private List> _groups = new List>(); private Stack _groupsPool = new Stack(64); @@ -73,9 +70,6 @@ namespace DCFApixels.DragonECS _delEntBuffer = new int[_entitesCapacity >> DEL_ENT_BUFFER_SIZE_OFFSET]; _allEntites = GetFreeGroup(); - - _aspects = new EcsAspect[128]; - _executors = new EcsQueryExecutor[128]; } public void Destroy() { @@ -83,8 +77,6 @@ namespace DCFApixels.DragonECS _gens = null; _pools = null; _nullPool = null; - _aspects = null; - _executors = null; Worlds[id] = null; ReleaseData(id); _worldIdDispenser.Release(id); @@ -108,28 +100,15 @@ namespace DCFApixels.DragonECS { return Get>().instance; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public TAspect GetAspect() where TAspect : EcsAspect { - int index = WorldMetaStorage.GetAspectID(_worldTypeID); - if (index >= _aspects.Length) - Array.Resize(ref _aspects, _aspects.Length << 1); - if (_aspects[index] == null) - _aspects[index] = EcsAspect.Builder.Build(this); - return (TAspect)_aspects[index]; + return Get>().instance; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public TExecutor GetExecutor() where TExecutor : EcsQueryExecutor, new() { - int index = WorldMetaStorage.GetExecutorID(_worldTypeID); - if (index >= _executors.Length) - Array.Resize(ref _executors, _executors.Length << 1); - var result = _executors[index]; - if (result == null) - { - result = new TExecutor(); - _executors[index] = result; - result.Initialize(this); - } - return (TExecutor)result; + return Get>().instance; } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/Pools/EcsPoolBase.cs b/src/Pools/EcsPoolBase.cs index 6237eda..459c01f 100644 --- a/src/Pools/EcsPoolBase.cs +++ b/src/Pools/EcsPoolBase.cs @@ -1,5 +1,4 @@ using DCFApixels.DragonECS.Internal; -using DCFApixels.DragonECS.Internal; using System; using System.Collections.Generic; using System.Runtime.CompilerServices;