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-07-13 00:37:31 +00:00
|
|
|
|
protected bool EntityExists(Guid entityID)
|
|
|
|
|
{
|
|
|
|
|
return entityManager.EntityExists(entityID);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-19 21:14:44 +00:00
|
|
|
|
protected Entity GetEntity(Guid entityID)
|
|
|
|
|
{
|
|
|
|
|
return entityManager.GetEntity(entityID);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-13 04:48:08 +00:00
|
|
|
|
protected Guid GetEntityIDByComponentID(Guid componentID)
|
|
|
|
|
{
|
|
|
|
|
return componentManager.GetEntityIDByComponentID(componentID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected Entity GetEntityByComponentID(Guid componentID)
|
|
|
|
|
{
|
|
|
|
|
return GetEntity(GetEntityIDByComponentID(componentID));
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-27 23:55:12 +00:00
|
|
|
|
protected IEnumerable<ValueTuple<Guid, TComponent>> ReadComponents<TComponent>() where TComponent : struct, IComponent
|
2019-06-19 21:14:44 +00:00
|
|
|
|
{
|
2019-08-01 23:44:29 +00:00
|
|
|
|
return componentManager.GetComponentsByType<TComponent>();
|
2019-06-19 21:14:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-27 23:55:12 +00:00
|
|
|
|
protected ValueTuple<Guid, TComponent> ReadComponent<TComponent>() where TComponent : struct, IComponent
|
2019-06-19 21:14:44 +00:00
|
|
|
|
{
|
2019-08-01 23:44:29 +00:00
|
|
|
|
return ReadComponents<TComponent>().First();
|
2019-06-19 21:14:44 +00:00
|
|
|
|
}
|
2019-07-17 18:24:21 +00:00
|
|
|
|
|
|
|
|
|
protected ValueTuple<Guid, TComponent> GetComponent<TComponent>(Entity entity) where TComponent : struct, IComponent
|
|
|
|
|
{
|
2019-08-11 00:34:00 +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
|
|
|
|
}
|
|
|
|
|
}
|