using System; using System.Collections.Generic; namespace MoonTools.ECS { public abstract class EntityComponentReader { protected readonly World World; internal EntityStorage EntityStorage => World.EntityStorage; internal ComponentDepot ComponentDepot => World.ComponentDepot; internal RelationDepot RelationDepot => World.RelationDepot; protected FilterBuilder FilterBuilder => new FilterBuilder(ComponentDepot); public EntityComponentReader(World world) { World = world; } protected ReadOnlySpan ReadComponents() where TComponent : unmanaged { return ComponentDepot.ReadComponents(); } protected bool Has(in Entity entity) where TComponent : unmanaged { return ComponentDepot.Has(entity.ID); } protected bool Some() where TComponent : unmanaged { return ComponentDepot.Some(); } protected ref readonly TComponent Get(in Entity entity) where TComponent : unmanaged { return ref ComponentDepot.Get(entity.ID); } protected ref readonly TComponent GetSingleton() where TComponent : unmanaged { return ref ComponentDepot.Get(); } protected Entity GetSingletonEntity() where TComponent : unmanaged { return ComponentDepot.GetSingletonEntity(); } protected bool Exists(in Entity entity) { return EntityStorage.Exists(entity); } protected IEnumerable<(Entity, Entity, TRelationKind)> Relations() where TRelationKind : unmanaged { return RelationDepot.Relations(); } protected bool Related(in Entity a, in Entity b) where TRelationKind : unmanaged { return RelationDepot.Related(a.ID, b.ID); } protected IEnumerable<(Entity, TRelationKind)> RelatedToA(in Entity entity) where TRelationKind : unmanaged { return RelationDepot.RelatedToA(entity.ID); } protected IEnumerable<(Entity, TRelationKind)> RelatedToB(in Entity entity) where TRelationKind : unmanaged { return RelationDepot.RelatedToB(entity.ID); } } }