MoonTools.ECS/src/Filter.cs

28 lines
871 B
C#
Raw Normal View History

2022-04-08 05:52:03 +00:00
using System;
using System.Collections.Generic;
2022-03-06 06:12:27 +00:00
2022-04-08 05:52:03 +00:00
namespace MoonTools.ECS
2022-03-06 06:12:27 +00:00
{
2022-04-08 05:52:03 +00:00
public class Filter
2022-03-06 06:12:27 +00:00
{
2022-04-08 05:52:03 +00:00
internal FilterSignature Signature;
private ComponentDepot ComponentDepot;
2022-03-06 06:12:27 +00:00
2022-04-08 05:52:03 +00:00
internal Filter(ComponentDepot componentDepot, HashSet<Type> included, HashSet<Type> excluded)
{
ComponentDepot = componentDepot;
Signature = new FilterSignature(included, excluded);
}
2022-04-08 05:52:03 +00:00
public IEnumerable<Entity> Entities => ComponentDepot.FilterEntities(this);
public IEnumerable<Entity> EntitiesInRandomOrder => ComponentDepot.FilterEntitiesRandom(this);
public Entity RandomEntity => ComponentDepot.FilterRandomEntity(this);
public int Count => ComponentDepot.FilterCount(this);
public bool Empty => Count == 0;
2022-08-17 22:29:38 +00:00
// WARNING: this WILL crash if the index is out of range!
public Entity NthEntity(int index) => ComponentDepot.FilterNthEntity(this, index);
2022-04-08 05:52:03 +00:00
}
2022-03-06 06:12:27 +00:00
}