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);
|
2021-03-12 08:25:25 +00:00
|
|
|
|
|
|
|
|
|
protected ReadOnlySpan<Entity> ReadEntities<TComponent>() where TComponent : struct
|
2019-11-22 21:14:36 +00:00
|
|
|
|
{
|
2020-03-23 02:10:28 +00:00
|
|
|
|
return _componentManager.GetExistingEntities<TComponent>();
|
2019-11-22 21:14:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-12 08:25:25 +00:00
|
|
|
|
protected IEnumerable<Entity> ReadEntitiesAsEnumerable<TComponent>() where TComponent : struct
|
2020-11-16 07:21:51 +00:00
|
|
|
|
{
|
|
|
|
|
return _componentManager.GetExistingEntitiesAsEnumerable<TComponent>();
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-12 08:25:25 +00:00
|
|
|
|
protected ref readonly Entity ReadEntity<TComponent>() where TComponent : struct
|
2019-11-22 21:14:36 +00:00
|
|
|
|
{
|
2020-03-23 02:20:55 +00:00
|
|
|
|
return ref _componentManager.ExistingSingularEntity<TComponent>();
|
2019-11-22 21:14:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-12 08:25:25 +00:00
|
|
|
|
protected ReadOnlySpan<TComponent> ReadComponents<TComponent>() where TComponent : struct
|
2019-07-13 04:48:08 +00:00
|
|
|
|
{
|
2020-03-20 07:09:57 +00:00
|
|
|
|
return _componentManager.GetComponentsByType<TComponent>();
|
2019-07-13 04:48:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-12 08:25:25 +00:00
|
|
|
|
protected IEnumerable<TComponent> ReadComponentsAsEnumerable<TComponent>() where TComponent : struct
|
2020-11-16 07:21:51 +00:00
|
|
|
|
{
|
|
|
|
|
return _componentManager.GetComponentsByTypeEnumerable<TComponent>();
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-12 08:25:25 +00:00
|
|
|
|
protected ref readonly TComponent ReadComponent<TComponent>() where TComponent : struct
|
2019-07-13 04:48:08 +00:00
|
|
|
|
{
|
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
|
|
|
|
|
2021-03-12 08:25:25 +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
|
|
|
|
}
|
2019-07-17 20:15:15 +00:00
|
|
|
|
|
2021-03-12 08:25:25 +00:00
|
|
|
|
protected bool HasComponent<TComponent>(Entity entity) where TComponent : struct
|
2019-07-17 20:15:15 +00:00
|
|
|
|
{
|
2020-03-20 07:09:57 +00:00
|
|
|
|
return _componentManager.EntityHasComponentOfType<TComponent>(entity.ID);
|
2019-07-17 20:15:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-12 08:25:25 +00:00
|
|
|
|
protected bool SomeComponent<TComponent>() where TComponent : struct
|
2019-07-17 20:15:15 +00:00
|
|
|
|
{
|
2020-03-20 07:09:57 +00:00
|
|
|
|
return _componentManager.SomeExistingComponent<TComponent>();
|
2019-07-17 20:15:15 +00:00
|
|
|
|
}
|
2019-06-19 21:14:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|