iterate indexable set backwards in case of destruction

filter_relations
cosmonaut 2022-05-16 18:12:42 -07:00
parent ad4dfd9249
commit 47758f20d1
2 changed files with 3 additions and 2 deletions

View File

@ -66,7 +66,7 @@ namespace MoonTools.ECS
public IEnumerator<T> GetEnumerator()
{
for (var i = 0; i < Count; i += 1)
for (var i = Count - 1; i >= 0; i -= 1)
{
yield return array[i];
}
@ -74,7 +74,7 @@ namespace MoonTools.ECS
IEnumerator IEnumerable.GetEnumerator()
{
for (var i = 0; i < Count; i += 1)
for (var i = Count - 1; i >= 0; i -= 1)
{
yield return array[i];
}

View File

@ -78,6 +78,7 @@ namespace MoonTools.ECS
RelationDepot.Remove<TRelationKind>(new Relation(entityA, entityB));
}
// FIXME: this is insanely inefficient
protected void Destroy(in Entity entity)
{
ComponentDepot.OnEntityDestroy(entity.ID);