2022-03-05 02:01:44 +00:00
|
|
|
|
namespace MoonTools.ECS;
|
|
|
|
|
|
|
|
|
|
public abstract class EntityComponentReader
|
|
|
|
|
{
|
|
|
|
|
internal EntityStorage EntityStorage;
|
|
|
|
|
internal ComponentDepot ComponentDepot;
|
2022-03-08 23:23:07 +00:00
|
|
|
|
protected FilterBuilder FilterBuilder => new FilterBuilder(ComponentDepot);
|
2022-03-05 02:01:44 +00:00
|
|
|
|
|
|
|
|
|
internal void RegisterEntityStorage(EntityStorage entityStorage)
|
|
|
|
|
{
|
|
|
|
|
EntityStorage = entityStorage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void RegisterComponentDepot(ComponentDepot componentDepot)
|
|
|
|
|
{
|
|
|
|
|
ComponentDepot = componentDepot;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected ReadOnlySpan<TComponent> ReadComponents<TComponent>() where TComponent : struct
|
|
|
|
|
{
|
|
|
|
|
return ComponentDepot.ReadComponents<TComponent>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected bool Has<TComponent>(in Entity entity) where TComponent : struct
|
|
|
|
|
{
|
|
|
|
|
return ComponentDepot.Has<TComponent>(entity.ID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected bool Some<TComponent>() where TComponent : struct
|
|
|
|
|
{
|
|
|
|
|
return ComponentDepot.Some<TComponent>();
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-21 23:21:42 +00:00
|
|
|
|
protected ref readonly TComponent Get<TComponent>(in Entity entity) where TComponent : struct
|
2022-03-05 02:01:44 +00:00
|
|
|
|
{
|
2022-03-21 23:21:42 +00:00
|
|
|
|
return ref ComponentDepot.Get<TComponent>(entity.ID);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-01 02:55:01 +00:00
|
|
|
|
protected ref readonly TComponent GetSingleton<TComponent>() where TComponent : struct
|
2022-03-21 23:21:42 +00:00
|
|
|
|
{
|
|
|
|
|
return ref ComponentDepot.Get<TComponent>();
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-03 21:46:52 +00:00
|
|
|
|
protected Entity GetSingletonEntity<TComponent>() where TComponent : struct
|
2022-03-21 23:21:42 +00:00
|
|
|
|
{
|
2022-04-03 21:46:52 +00:00
|
|
|
|
return ComponentDepot.GetSingletonEntity<TComponent>();
|
2022-03-05 02:01:44 +00:00
|
|
|
|
}
|
2022-03-31 23:15:30 +00:00
|
|
|
|
|
|
|
|
|
protected bool Exists(in Entity entity)
|
|
|
|
|
{
|
|
|
|
|
return EntityStorage.Exists(entity);
|
|
|
|
|
}
|
2022-03-05 02:01:44 +00:00
|
|
|
|
}
|