2019-06-19 21:14:44 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2019-07-17 18:24:21 +00:00
|
|
|
|
using System.Linq;
|
2019-06-19 21:14:44 +00:00
|
|
|
|
|
|
|
|
|
namespace Encompass
|
|
|
|
|
{
|
|
|
|
|
public abstract class Renderer
|
|
|
|
|
{
|
2019-07-17 18:24:21 +00:00
|
|
|
|
internal EntityManager entityManager;
|
|
|
|
|
internal ComponentManager componentManager;
|
2019-06-19 21:14:44 +00:00
|
|
|
|
|
|
|
|
|
internal void AssignEntityManager(EntityManager entityManager)
|
|
|
|
|
{
|
|
|
|
|
this.entityManager = entityManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void AssignComponentManager(ComponentManager componentManager)
|
|
|
|
|
{
|
|
|
|
|
this.componentManager = componentManager;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-22 21:14:36 +00:00
|
|
|
|
protected IEnumerable<Entity> ReadEntities<TComponent>() where TComponent : struct, IComponent
|
|
|
|
|
{
|
|
|
|
|
return ReadComponentsIncludingEntity<TComponent>().Select(tuple => tuple.Item2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected Entity ReadEntity<TComponent>() where TComponent : struct, IComponent
|
|
|
|
|
{
|
|
|
|
|
return ReadComponentIncludingEntity<TComponent>().Item2;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-21 03:01:29 +00:00
|
|
|
|
protected IEnumerable<TComponent> ReadComponents<TComponent>() where TComponent : struct, IComponent
|
2019-07-13 04:48:08 +00:00
|
|
|
|
{
|
2019-12-05 22:59:55 +00:00
|
|
|
|
return componentManager.GetComponentsByType<TComponent>();
|
2019-07-13 04:48:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-11-21 03:01:29 +00:00
|
|
|
|
protected IEnumerable<(TComponent, Entity)> ReadComponentsIncludingEntity<TComponent>() where TComponent : struct, IComponent
|
2019-07-13 04:48:08 +00:00
|
|
|
|
{
|
2019-12-05 22:59:55 +00:00
|
|
|
|
return componentManager.GetComponentsIncludingEntity<TComponent>();
|
2019-07-13 04:48:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-11-21 03:01:29 +00:00
|
|
|
|
protected TComponent ReadComponent<TComponent>() where TComponent : struct, IComponent
|
2019-06-19 21:14:44 +00:00
|
|
|
|
{
|
2019-11-21 03:01:29 +00:00
|
|
|
|
return ReadComponents<TComponent>().First();
|
2019-06-19 21:14:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-11-21 03:01:29 +00:00
|
|
|
|
protected (TComponent, Entity) ReadComponentIncludingEntity<TComponent>() where TComponent : struct, IComponent
|
2019-06-19 21:14:44 +00:00
|
|
|
|
{
|
2019-11-21 03:01:29 +00:00
|
|
|
|
return ReadComponentsIncludingEntity<TComponent>().First();
|
2019-06-19 21:14:44 +00:00
|
|
|
|
}
|
2019-07-17 18:24:21 +00:00
|
|
|
|
|
2019-11-21 03:01:29 +00:00
|
|
|
|
protected TComponent GetComponent<TComponent>(Entity entity) where TComponent : struct, IComponent
|
2019-07-17 18:24:21 +00:00
|
|
|
|
{
|
2019-12-05 22:59:55 +00:00
|
|
|
|
return componentManager.GetComponentByEntityAndType<TComponent>(entity);
|
2019-07-17 18:24:21 +00:00
|
|
|
|
}
|
2019-07-17 20:15:15 +00:00
|
|
|
|
|
|
|
|
|
protected bool HasComponent<TComponent>(Entity entity) where TComponent : struct, IComponent
|
|
|
|
|
{
|
2019-08-11 00:34:00 +00:00
|
|
|
|
return componentManager.EntityHasComponentOfType<TComponent>(entity);
|
2019-07-17 20:15:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected bool SomeComponent<TComponent>() where TComponent : struct, IComponent
|
|
|
|
|
{
|
2019-08-01 23:44:29 +00:00
|
|
|
|
return componentManager.ComponentOfTypeExists<TComponent>();
|
2019-07-17 20:15:15 +00:00
|
|
|
|
}
|
2019-06-19 21:14:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|