MoonTools.ECS/src/EntityComponentReader.cs

75 lines
1.9 KiB
C#
Raw Normal View History

2022-03-05 02:01:44 +00:00
namespace MoonTools.ECS;
public abstract class EntityComponentReader
{
internal EntityStorage EntityStorage;
internal ComponentDepot ComponentDepot;
2022-04-06 19:53:50 +00:00
internal RelationDepot RelationDepot;
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-04-06 19:53:50 +00:00
internal void RegisterRelationDepot(RelationDepot relationDepot)
{
RelationDepot = relationDepot;
}
2022-03-05 02:01:44 +00:00
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 GetSingleton<TComponent>() where TComponent : struct
2022-03-21 23:21:42 +00:00
{
return ref ComponentDepot.Get<TComponent>();
}
protected Entity GetSingletonEntity<TComponent>() where TComponent : struct
2022-03-21 23:21:42 +00:00
{
return ComponentDepot.GetSingletonEntity<TComponent>();
2022-03-05 02:01:44 +00:00
}
protected bool Exists(in Entity entity)
{
return EntityStorage.Exists(entity);
}
2022-04-06 19:53:50 +00:00
protected IEnumerable<Relation> Relations<TRelationKind>()
{
return RelationDepot.Relations<TRelationKind>();
}
protected IEnumerable<Entity> RelatedToA<TRelationKind>(in Entity entity)
{
return RelationDepot.RelatedToA<TRelationKind>(entity.ID);
}
protected IEnumerable<Entity> RelatedToB<TRelationKind>(in Entity entity)
{
return RelationDepot.RelatedToB<TRelationKind>(entity.ID);
}
2022-03-05 02:01:44 +00:00
}