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;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-07 07:27:35 +00:00
|
|
|
|
// TODO: is this faster or slower than a single-component Filter?
|
2022-03-05 02:01:44 +00:00
|
|
|
|
protected ReadOnlySpan<Entity> ReadEntities<TComponent>() where TComponent : struct
|
|
|
|
|
{
|
|
|
|
|
return ComponentDepot.ReadEntities<TComponent>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected ref readonly TComponent Get<TComponent>() where TComponent : struct
|
|
|
|
|
{
|
|
|
|
|
return ref ComponentDepot.Get<TComponent>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected ref readonly Entity GetEntity<TComponent>() where TComponent : struct
|
|
|
|
|
{
|
|
|
|
|
return ref ComponentDepot.GetEntity<TComponent>();
|
2022-03-05 02:01:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|