encompass-cs/encompass-cs/Renderer.cs

69 lines
2.3 KiB
C#
Raw Normal View History

2020-03-23 02:10:28 +00:00
using System;
using System.Collections.Generic;
2019-06-19 21:14:44 +00:00
namespace Encompass
{
public abstract class Renderer
{
2020-03-20 07:09:57 +00:00
internal EntityManager _entityManager;
internal ComponentManager _componentManager;
2019-06-19 21:14:44 +00:00
internal void AssignEntityManager(EntityManager entityManager)
{
2020-03-20 07:09:57 +00:00
_entityManager = entityManager;
2019-06-19 21:14:44 +00:00
}
internal void AssignComponentManager(ComponentManager componentManager)
{
2020-03-20 07:09:57 +00:00
_componentManager = componentManager;
2019-06-19 21:14:44 +00:00
}
2021-03-24 00:37:47 +00:00
public abstract void Render(double dt, double alpha);
protected ReadOnlySpan<Entity> ReadEntities<TComponent>() where TComponent : struct
{
2020-03-23 02:10:28 +00:00
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
{
2020-03-23 02:20:55 +00:00
return ref _componentManager.ExistingSingularEntity<TComponent>();
}
protected ReadOnlySpan<TComponent> ReadComponents<TComponent>() where TComponent : struct
{
2020-03-20 07:09:57 +00:00
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
{
2020-03-23 02:10:28 +00:00
return ref _componentManager.ExistingSingular<TComponent>();
2019-06-19 21:14:44 +00:00
}
2019-07-17 18:24:21 +00:00
protected ref readonly TComponent GetComponent<TComponent>(Entity entity) where TComponent : struct
2019-07-17 18:24:21 +00:00
{
2020-03-20 07:09:57 +00:00
return ref _componentManager.GetComponentByEntityAndType<TComponent>(entity.ID);
2019-07-17 18:24:21 +00:00
}
protected bool HasComponent<TComponent>(Entity entity) where TComponent : struct
{
2020-03-20 07:09:57 +00:00
return _componentManager.EntityHasComponentOfType<TComponent>(entity.ID);
}
protected bool SomeComponent<TComponent>() where TComponent : struct
{
2020-03-20 07:09:57 +00:00
return _componentManager.SomeExistingComponent<TComponent>();
}
2019-06-19 21:14:44 +00:00
}
}