2024-04-30 16:09:57 +08:00
|
|
|
|
using DCFApixels.DragonECS.PoolsCore;
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2023-06-27 05:30:45 +08:00
|
|
|
|
component = new PoolCache<T>(world.CreatePool<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>>
|
2024-07-05 22:13:17 +08:00
|
|
|
|
where T : EcsAspect, new()
|
2023-06-27 05:30:45 +08:00
|
|
|
|
{
|
2024-10-03 08:20:22 +08:00
|
|
|
|
public readonly T Instance;
|
|
|
|
|
public AspectCache(T instance) { Instance = instance; }
|
2023-06-27 05:30:45 +08:00
|
|
|
|
void IEcsWorldComponent<AspectCache<T>>.Init(ref AspectCache<T> component, EcsWorld world)
|
|
|
|
|
{
|
2024-01-07 19:32:16 +08:00
|
|
|
|
component = new AspectCache<T>(EcsAspect.Builder.New<T>(world));
|
2023-06-27 05:30:45 +08:00
|
|
|
|
}
|
|
|
|
|
void IEcsWorldComponent<AspectCache<T>>.OnDestroy(ref AspectCache<T> component, EcsWorld world)
|
|
|
|
|
{
|
|
|
|
|
component = default;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-03 08:20:22 +08:00
|
|
|
|
internal readonly struct QueryCache<TExecutor, TAspcet> : IEcsWorldComponent<QueryCache<TExecutor, TAspcet>>
|
|
|
|
|
where TExecutor : EcsQueryExecutor, new()
|
|
|
|
|
where TAspcet : EcsAspect, 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;
|
|
|
|
|
public QueryCache(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-10-03 08:20:22 +08:00
|
|
|
|
void IEcsWorldComponent<QueryCache<TExecutor, TAspcet>>.Init(ref QueryCache<TExecutor, TAspcet> component, EcsWorld world)
|
|
|
|
|
{
|
|
|
|
|
TExecutor instance = new TExecutor();
|
|
|
|
|
TAspcet aspect = world.GetAspect<TAspcet>();
|
|
|
|
|
instance.Initialize(world, aspect.Mask);
|
|
|
|
|
component = new QueryCache<TExecutor, TAspcet>(instance, aspect);
|
|
|
|
|
}
|
|
|
|
|
void IEcsWorldComponent<QueryCache<TExecutor, TAspcet>>.OnDestroy(ref QueryCache<TExecutor, TAspcet> component, EcsWorld world)
|
2023-06-27 05:30:45 +08:00
|
|
|
|
{
|
|
|
|
|
component = default;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-06-27 05:09:41 +08:00
|
|
|
|
}
|
|
|
|
|
}
|