add Filter.NthEntity

filter_relations
cosmonaut 2022-08-17 15:29:38 -07:00
parent bb359d339b
commit a9032603ec
2 changed files with 8 additions and 0 deletions

View File

@ -185,6 +185,11 @@ namespace MoonTools.ECS
}
}
public Entity FilterNthEntity(Filter filter, int index)
{
return new Entity(filterSignatureToEntityIDs[filter.Signature][index]);
}
public Entity FilterRandomEntity(Filter filter)
{
var randomIndex = RandomGenerator.Next(FilterCount(filter));

View File

@ -20,5 +20,8 @@ namespace MoonTools.ECS
public int Count => ComponentDepot.FilterCount(this);
public bool Empty => Count == 0;
// WARNING: this WILL crash if the index is out of range!
public Entity NthEntity(int index) => ComponentDepot.FilterNthEntity(this, index);
}
}