encompass-cs/encompass-cs/Renderer.cs

69 lines
2.3 KiB
C#

using System;
using System.Collections.Generic;
namespace Encompass
{
public abstract class Renderer
{
internal EntityManager _entityManager;
internal ComponentManager _componentManager;
internal void AssignEntityManager(EntityManager entityManager)
{
_entityManager = entityManager;
}
internal void AssignComponentManager(ComponentManager componentManager)
{
_componentManager = componentManager;
}
public abstract void Render(double dt, double alpha);
protected ReadOnlySpan<Entity> ReadEntities<TComponent>() where TComponent : struct
{
return _componentManager.GetExistingEntities<TComponent>();
}
protected IEnumerable<Entity> ReadEntitiesAsEnumerable<TComponent>() where TComponent : struct
{
return _componentManager.GetExistingEntitiesAsEnumerable<TComponent>();
}
protected ref readonly Entity ReadEntity<TComponent>() where TComponent : struct
{
return ref _componentManager.ExistingSingularEntity<TComponent>();
}
protected ReadOnlySpan<TComponent> ReadComponents<TComponent>() where TComponent : struct
{
return _componentManager.GetComponentsByType<TComponent>();
}
protected IEnumerable<TComponent> ReadComponentsAsEnumerable<TComponent>() where TComponent : struct
{
return _componentManager.GetComponentsByTypeEnumerable<TComponent>();
}
protected ref readonly TComponent ReadComponent<TComponent>() where TComponent : struct
{
return ref _componentManager.ExistingSingular<TComponent>();
}
protected ref readonly TComponent GetComponent<TComponent>(Entity entity) where TComponent : struct
{
return ref _componentManager.GetComponentByEntityAndType<TComponent>(entity.ID);
}
protected bool HasComponent<TComponent>(Entity entity) where TComponent : struct
{
return _componentManager.EntityHasComponentOfType<TComponent>(entity.ID);
}
protected bool SomeComponent<TComponent>() where TComponent : struct
{
return _componentManager.SomeExistingComponent<TComponent>();
}
}
}