2023-10-13 20:42:22 +00:00
|
|
|
|
using MoonTools.ECS.Collections;
|
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 struct FilterBuilder
|
2022-03-06 06:12:27 +00:00
|
|
|
|
{
|
2023-11-21 19:50:17 +00:00
|
|
|
|
World World;
|
|
|
|
|
IndexableSet<TypeId> Included;
|
|
|
|
|
IndexableSet<TypeId> Excluded;
|
2022-03-06 06:12:27 +00:00
|
|
|
|
|
2023-11-21 19:50:17 +00:00
|
|
|
|
internal FilterBuilder(World world)
|
2022-04-08 05:52:03 +00:00
|
|
|
|
{
|
2023-11-21 19:50:17 +00:00
|
|
|
|
World = world;
|
|
|
|
|
Included = new IndexableSet<TypeId>();
|
|
|
|
|
Excluded = new IndexableSet<TypeId>();
|
2022-04-08 05:52:03 +00:00
|
|
|
|
}
|
2022-03-06 06:12:27 +00:00
|
|
|
|
|
2023-11-21 19:50:17 +00:00
|
|
|
|
private FilterBuilder(World world, IndexableSet<TypeId> included, IndexableSet<TypeId> excluded)
|
2022-04-08 05:52:03 +00:00
|
|
|
|
{
|
2023-11-21 19:50:17 +00:00
|
|
|
|
World = world;
|
2022-04-08 05:52:03 +00:00
|
|
|
|
Included = included;
|
|
|
|
|
Excluded = excluded;
|
|
|
|
|
}
|
2022-03-06 06:12:27 +00:00
|
|
|
|
|
2023-11-21 19:50:17 +00:00
|
|
|
|
public FilterBuilder Include<T>() where T : unmanaged
|
2022-04-08 05:52:03 +00:00
|
|
|
|
{
|
2023-11-21 19:50:17 +00:00
|
|
|
|
Included.Add(World.GetComponentTypeId<T>());
|
|
|
|
|
return new FilterBuilder(World, Included, Excluded);
|
2022-04-08 05:52:03 +00:00
|
|
|
|
}
|
2022-03-06 06:12:27 +00:00
|
|
|
|
|
2023-11-21 19:50:17 +00:00
|
|
|
|
public FilterBuilder Exclude<T>() where T : unmanaged
|
2022-04-08 05:52:03 +00:00
|
|
|
|
{
|
2023-11-21 19:50:17 +00:00
|
|
|
|
Excluded.Add(World.GetComponentTypeId<T>());
|
|
|
|
|
return new FilterBuilder(World, Included, Excluded);
|
2022-04-08 05:52:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Filter Build()
|
|
|
|
|
{
|
2023-11-21 19:50:17 +00:00
|
|
|
|
var signature = new FilterSignature(Included, Excluded);
|
|
|
|
|
return World.GetFilter(signature);
|
2022-04-08 05:52:03 +00:00
|
|
|
|
}
|
2022-03-06 06:12:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|