removed the old ecs and refactored the platformer demo to use the new ecs

This commit is contained in:
Dylan Wilson
2018-06-19 21:24:56 +10:00
parent 4b8c80ec14
commit 89dbb71a1a
44 changed files with 213 additions and 2349 deletions
+23 -3
View File
@@ -11,18 +11,37 @@ namespace MonoGame.Extended.Entities
public Entity(int id, EntityManager entityManager, ComponentManager componentManager)
{
Id = id;
_componentBits = new BitArray(16);
_entityManager = entityManager;
_componentManager = componentManager;
}
public int Id { get; }
public BitArray ComponentBits => _componentManager.GetComponentBits(Id);
public int Id { get; internal set; }
private BitArray _componentBits;
private bool _componentsChanged;
public BitArray ComponentBits
{
get
{
if (_componentsChanged)
{
_componentManager.RefreshComponentBits(Id, ref _componentBits);
_componentsChanged = false;
}
return _componentBits;
}
}
public void Attach<T>(T component)
where T : class
{
var mapper = _componentManager.GetMapper<T>();
mapper.Put(Id, component);
_componentsChanged = true;
}
public void Detach<T>()
@@ -30,6 +49,7 @@ namespace MonoGame.Extended.Entities
{
var mapper = _componentManager.GetMapper<T>();
mapper.Delete(Id);
_componentsChanged = true;
}
public T Get<T>()
@@ -41,7 +61,7 @@ namespace MonoGame.Extended.Entities
public void Destory()
{
_entityManager.DestroyEntity(this);
_entityManager.DestroyEntity(Id);
}
public bool Equals(Entity other)