2025-03-14 16:53:25 +08:00
|
|
|
|
#if DISABLE_DEBUG
|
|
|
|
|
#undef DEBUG
|
|
|
|
|
#endif
|
|
|
|
|
using DCFApixels.DragonECS.Core;
|
2024-11-05 15:50:03 +08:00
|
|
|
|
using DCFApixels.DragonECS.PoolsCore;
|
2024-04-30 16:09:57 +08:00
|
|
|
|
|
|
|
|
|
namespace DCFApixels.DragonECS
|
2023-06-27 05:09:41 +08:00
|
|
|
|
{
|
2024-02-22 15:39:37 +08:00
|
|
|
|
public partial class EcsWorld
|
2023-06-27 05:09:41 +08:00
|
|
|
|
{
|
2023-06-27 05:30:45 +08:00
|
|
|
|
internal readonly struct PoolCache<T> : IEcsWorldComponent<PoolCache<T>>
|
|
|
|
|
where T : IEcsPoolImplementation, new()
|
2023-06-27 05:09:41 +08:00
|
|
|
|
{
|
2024-10-03 08:20:22 +08:00
|
|
|
|
public readonly T Instance;
|
|
|
|
|
public PoolCache(T instance) { Instance = instance; }
|
2023-06-27 05:30:45 +08:00
|
|
|
|
void IEcsWorldComponent<PoolCache<T>>.Init(ref PoolCache<T> component, EcsWorld world)
|
2023-06-27 05:09:41 +08:00
|
|
|
|
{
|
2024-12-18 16:18:44 +08:00
|
|
|
|
component = new PoolCache<T>(world.FindOrAutoCreatePool<T>());
|
2023-06-27 05:09:41 +08:00
|
|
|
|
}
|
2023-06-27 05:30:45 +08:00
|
|
|
|
void IEcsWorldComponent<PoolCache<T>>.OnDestroy(ref PoolCache<T> component, EcsWorld world)
|
2023-06-27 05:09:41 +08:00
|
|
|
|
{
|
|
|
|
|
component = default;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-06-27 05:30:45 +08:00
|
|
|
|
internal readonly struct AspectCache<T> : IEcsWorldComponent<AspectCache<T>>
|
2025-03-10 13:00:30 +08:00
|
|
|
|
where T : new()
|
2023-06-27 05:30:45 +08:00
|
|
|
|
{
|
2024-10-03 08:20:22 +08:00
|
|
|
|
public readonly T Instance;
|
2025-03-10 13:00:30 +08:00
|
|
|
|
public readonly EcsMask Mask;
|
|
|
|
|
public AspectCache(T instance, EcsMask mask)
|
|
|
|
|
{
|
|
|
|
|
Instance = instance;
|
|
|
|
|
Mask = mask;
|
|
|
|
|
}
|
2023-06-27 05:30:45 +08:00
|
|
|
|
void IEcsWorldComponent<AspectCache<T>>.Init(ref AspectCache<T> component, EcsWorld world)
|
|
|
|
|
{
|
2025-03-10 13:00:30 +08:00
|
|
|
|
#if DEBUG
|
2025-05-19 14:41:05 +08:00
|
|
|
|
AllowedInWorldsAttribute.CheckAllows(world, typeof(T));
|
2025-03-10 13:00:30 +08:00
|
|
|
|
#endif
|
|
|
|
|
var result = EcsAspect.Builder.New<T>(world);
|
|
|
|
|
component = new AspectCache<T>(result.aspect, result.mask);
|
2023-06-27 05:30:45 +08:00
|
|
|
|
}
|
|
|
|
|
void IEcsWorldComponent<AspectCache<T>>.OnDestroy(ref AspectCache<T> component, EcsWorld world)
|
|
|
|
|
{
|
|
|
|
|
component = default;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-03 18:57:56 +08:00
|
|
|
|
|
|
|
|
|
internal readonly struct WhereQueryCache<TExecutor, TAspcet> : IEcsWorldComponent<WhereQueryCache<TExecutor, TAspcet>>
|
2024-11-05 15:50:03 +08:00
|
|
|
|
where TExecutor : MaskQueryExecutor, new()
|
2025-03-10 13:00:30 +08:00
|
|
|
|
where TAspcet : new()
|
2023-06-27 05:30:45 +08:00
|
|
|
|
{
|
2024-10-03 08:20:22 +08:00
|
|
|
|
public readonly TExecutor Executor;
|
|
|
|
|
public readonly TAspcet Aspcet;
|
2024-11-03 18:57:56 +08:00
|
|
|
|
public WhereQueryCache(TExecutor executor, TAspcet aspcet)
|
2023-06-27 05:30:45 +08:00
|
|
|
|
{
|
2024-10-03 08:20:22 +08:00
|
|
|
|
Executor = executor;
|
|
|
|
|
Aspcet = aspcet;
|
2023-06-27 05:30:45 +08:00
|
|
|
|
}
|
2024-11-03 18:57:56 +08:00
|
|
|
|
void IEcsWorldComponent<WhereQueryCache<TExecutor, TAspcet>>.Init(ref WhereQueryCache<TExecutor, TAspcet> component, EcsWorld world)
|
2024-10-03 08:20:22 +08:00
|
|
|
|
{
|
2025-03-10 13:00:30 +08:00
|
|
|
|
TAspcet aspect = world.GetAspect<TAspcet>(out EcsMask mask);
|
|
|
|
|
TExecutor instance = world.GetExecutorForMask<TExecutor>(mask);
|
|
|
|
|
instance.Initialize(world, mask);
|
2024-11-03 18:57:56 +08:00
|
|
|
|
component = new WhereQueryCache<TExecutor, TAspcet>(instance, aspect);
|
2024-10-03 08:20:22 +08:00
|
|
|
|
}
|
2024-11-03 18:57:56 +08:00
|
|
|
|
void IEcsWorldComponent<WhereQueryCache<TExecutor, TAspcet>>.OnDestroy(ref WhereQueryCache<TExecutor, TAspcet> component, EcsWorld world)
|
2023-06-27 05:30:45 +08:00
|
|
|
|
{
|
|
|
|
|
component = default;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-06-27 05:09:41 +08:00
|
|
|
|
}
|
|
|
|
|
}
|