slight entity manager optimization
parent
db8964b54c
commit
f6d93c7579
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
@ -151,17 +151,6 @@ namespace Encompass
|
|||
return entityManager.EntityExists(entity.ID);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the Entity with the specified ID.
|
||||
/// </summary>
|
||||
/// <exception cref="Encompass.Exceptions.EntityNotFoundException">
|
||||
/// Thrown when an Entity with the given ID does not exist.
|
||||
/// </exception>
|
||||
internal Entity GetEntity(Guid entityID)
|
||||
{
|
||||
return entityManager.GetEntity(entityID);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an Entity containing the specified Component type.
|
||||
/// </summary>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System.Linq;
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Encompass.Exceptions;
|
||||
|
@ -7,7 +7,7 @@ namespace Encompass
|
|||
{
|
||||
internal class EntityManager
|
||||
{
|
||||
private readonly Dictionary<Guid, Entity> IDToEntity = new Dictionary<Guid, Entity>(1024);
|
||||
private readonly HashSet<Guid> IDs = new HashSet<Guid>();
|
||||
|
||||
private readonly HashSet<Entity> entitiesMarkedForDestroy = new HashSet<Entity>();
|
||||
|
||||
|
@ -22,25 +22,13 @@ namespace Encompass
|
|||
{
|
||||
var id = NextID();
|
||||
var entity = new Entity(id);
|
||||
IDToEntity[id] = entity;
|
||||
IDs.Add(id);
|
||||
return entity;
|
||||
}
|
||||
|
||||
public bool EntityExists(Guid id)
|
||||
{
|
||||
return IDToEntity.ContainsKey(id);
|
||||
}
|
||||
|
||||
public Entity GetEntity(Guid id)
|
||||
{
|
||||
if (IDToEntity.ContainsKey(id))
|
||||
{
|
||||
return IDToEntity[id];
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new EntityNotFoundException("Entity with ID {0} does not exist.", id);
|
||||
}
|
||||
return IDs.Contains(id);
|
||||
}
|
||||
|
||||
public void MarkForDestroy(Entity entity)
|
||||
|
@ -53,7 +41,7 @@ namespace Encompass
|
|||
foreach (var entity in entitiesMarkedForDestroy)
|
||||
{
|
||||
componentManager.MarkAllComponentsOnEntityForRemoval(entity);
|
||||
IDToEntity.Remove(entity.ID);
|
||||
IDs.Remove(entity.ID);
|
||||
}
|
||||
|
||||
entitiesMarkedForDestroy.Clear();
|
||||
|
|
|
@ -19,11 +19,6 @@ namespace Encompass
|
|||
this.componentManager = componentManager;
|
||||
}
|
||||
|
||||
internal Entity GetEntity(Guid entityID)
|
||||
{
|
||||
return entityManager.GetEntity(entityID);
|
||||
}
|
||||
|
||||
protected IEnumerable<Entity> ReadEntities<TComponent>() where TComponent : struct, IComponent
|
||||
{
|
||||
return ReadComponentsIncludingEntity<TComponent>().Select(tuple => tuple.Item2);
|
||||
|
|
Loading…
Reference in New Issue