45 lines
1.2 KiB
C#
45 lines
1.2 KiB
C#
using System.Collections.Generic;
|
|
|
|
namespace Encompass {
|
|
internal class EntityManager {
|
|
private uint nextID = 1;
|
|
|
|
private List<Entity> entities = new List<Entity>();
|
|
private Dictionary<uint, Entity> IDToEntity = new Dictionary<uint, 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(uint id) {
|
|
return this.IDToEntity[id];
|
|
}
|
|
|
|
public void MarkForDestroy(Entity entity) {
|
|
entitiesMarkedForDestroy.Add(entity);
|
|
}
|
|
|
|
internal void DestroyMarkedEntities() {
|
|
foreach (var entity in entitiesMarkedForDestroy) {
|
|
entity.RemoveAllComponents();
|
|
}
|
|
}
|
|
|
|
private uint NextID() {
|
|
var id = this.nextID;
|
|
this.nextID++;
|
|
return id;
|
|
}
|
|
}
|
|
}
|