51 lines
1.2 KiB
C#
51 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Encompass
|
|
{
|
|
internal class EntityManager
|
|
{
|
|
private List<Entity> entities = new List<Entity>();
|
|
private Dictionary<Guid, Entity> IDToEntity = new Dictionary<Guid, Entity>();
|
|
|
|
private List<Entity> entitiesMarkedForDestroy = new List<Entity>();
|
|
|
|
private ComponentManager componentManager;
|
|
|
|
public EntityManager(
|
|
ComponentManager componentManager
|
|
)
|
|
{
|
|
this.componentManager = componentManager;
|
|
}
|
|
|
|
public Entity CreateEntity()
|
|
{
|
|
return new Entity(NextID(), componentManager);
|
|
}
|
|
|
|
public Entity GetEntity(Guid id)
|
|
{
|
|
return this.IDToEntity[id];
|
|
}
|
|
|
|
public void MarkForDestroy(Entity entity)
|
|
{
|
|
entitiesMarkedForDestroy.Add(entity);
|
|
}
|
|
|
|
internal void DestroyMarkedEntities()
|
|
{
|
|
foreach (var entity in entitiesMarkedForDestroy)
|
|
{
|
|
entity.RemoveAllComponents();
|
|
}
|
|
}
|
|
|
|
private Guid NextID()
|
|
{
|
|
return Guid.NewGuid();
|
|
}
|
|
}
|
|
}
|