#if DISABLE_DEBUG #undef DEBUG #endif using DCFApixels.DragonECS.Core; using DCFApixels.DragonECS.PoolsCore; namespace DCFApixels.DragonECS { public partial class EcsWorld { internal readonly struct PoolCache : IEcsWorldComponent> where T : IEcsPoolImplementation, new() { public readonly T Instance; public PoolCache(T instance) { Instance = instance; } void IEcsWorldComponent>.Init(ref PoolCache component, EcsWorld world) { component = new PoolCache(world.FindOrAutoCreatePool()); } void IEcsWorldComponent>.OnDestroy(ref PoolCache component, EcsWorld world) { component = default; } } internal readonly struct AspectCache : IEcsWorldComponent> where T : new() { public readonly T Instance; public readonly EcsMask Mask; public AspectCache(T instance, EcsMask mask) { Instance = instance; Mask = mask; } void IEcsWorldComponent>.Init(ref AspectCache component, EcsWorld world) { #if DEBUG AllowedInWorldsAttribute.CheckAllows(world); #endif var result = EcsAspect.Builder.New(world); component = new AspectCache(result.aspect, result.mask); } void IEcsWorldComponent>.OnDestroy(ref AspectCache component, EcsWorld world) { component = default; } } internal readonly struct WhereQueryCache : IEcsWorldComponent> where TExecutor : MaskQueryExecutor, new() where TAspcet : new() { public readonly TExecutor Executor; public readonly TAspcet Aspcet; public WhereQueryCache(TExecutor executor, TAspcet aspcet) { Executor = executor; Aspcet = aspcet; } void IEcsWorldComponent>.Init(ref WhereQueryCache component, EcsWorld world) { TAspcet aspect = world.GetAspect(out EcsMask mask); TExecutor instance = world.GetExecutorForMask(mask); instance.Initialize(world, mask); component = new WhereQueryCache(instance, aspect); } void IEcsWorldComponent>.OnDestroy(ref WhereQueryCache component, EcsWorld world) { component = default; } } } }