2019-06-17 18:33:38 +00:00
|
|
|
using System;
|
2019-06-14 03:28:26 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
2019-06-16 01:05:56 +00:00
|
|
|
namespace Encompass
|
|
|
|
{
|
|
|
|
internal class EntityManager
|
|
|
|
{
|
2019-06-14 03:28:26 +00:00
|
|
|
private List<Entity> entities = new List<Entity>();
|
2019-06-17 18:33:38 +00:00
|
|
|
private Dictionary<Guid, Entity> IDToEntity = new Dictionary<Guid, Entity>();
|
2019-06-14 03:28:26 +00:00
|
|
|
|
|
|
|
private List<Entity> entitiesMarkedForDestroy = new List<Entity>();
|
|
|
|
|
|
|
|
private ComponentManager componentManager;
|
|
|
|
|
|
|
|
public EntityManager(
|
|
|
|
ComponentManager componentManager
|
2019-06-16 01:05:56 +00:00
|
|
|
)
|
|
|
|
{
|
2019-06-14 03:28:26 +00:00
|
|
|
this.componentManager = componentManager;
|
|
|
|
}
|
|
|
|
|
2019-06-16 01:05:56 +00:00
|
|
|
public Entity CreateEntity()
|
|
|
|
{
|
2019-06-14 03:28:26 +00:00
|
|
|
return new Entity(NextID(), componentManager);
|
|
|
|
}
|
|
|
|
|
2019-06-17 18:33:38 +00:00
|
|
|
public Entity GetEntity(Guid id)
|
2019-06-16 01:05:56 +00:00
|
|
|
{
|
2019-06-19 21:14:44 +00:00
|
|
|
return IDToEntity[id];
|
2019-06-14 03:28:26 +00:00
|
|
|
}
|
|
|
|
|
2019-06-16 01:05:56 +00:00
|
|
|
public void MarkForDestroy(Entity entity)
|
|
|
|
{
|
2019-06-14 03:28:26 +00:00
|
|
|
entitiesMarkedForDestroy.Add(entity);
|
|
|
|
}
|
|
|
|
|
2019-06-16 01:05:56 +00:00
|
|
|
internal void DestroyMarkedEntities()
|
|
|
|
{
|
|
|
|
foreach (var entity in entitiesMarkedForDestroy)
|
|
|
|
{
|
2019-06-14 03:28:26 +00:00
|
|
|
entity.RemoveAllComponents();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-17 18:33:38 +00:00
|
|
|
private Guid NextID()
|
2019-06-16 01:05:56 +00:00
|
|
|
{
|
2019-06-17 18:33:38 +00:00
|
|
|
return Guid.NewGuid();
|
2019-06-14 03:28:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|