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-01-10 00:41:00 +00:00
|
|
|
|
private TypeIndices ComponentTypeIndices;
|
|
|
|
|
private FilterStorage FilterStorage;
|
2023-10-13 20:42:22 +00:00
|
|
|
|
private IndexableSet<int> Included;
|
|
|
|
|
private IndexableSet<int> Excluded;
|
2022-03-06 06:12:27 +00:00
|
|
|
|
|
2023-01-10 00:41:00 +00:00
|
|
|
|
internal FilterBuilder(FilterStorage filterStorage, TypeIndices componentTypeIndices)
|
2022-04-08 05:52:03 +00:00
|
|
|
|
{
|
2023-01-10 00:41:00 +00:00
|
|
|
|
FilterStorage = filterStorage;
|
|
|
|
|
ComponentTypeIndices = componentTypeIndices;
|
2023-10-13 20:42:22 +00:00
|
|
|
|
Included = new IndexableSet<int>();
|
|
|
|
|
Excluded = new IndexableSet<int>();
|
2022-04-08 05:52:03 +00:00
|
|
|
|
}
|
2022-03-06 06:12:27 +00:00
|
|
|
|
|
2023-10-13 20:42:22 +00:00
|
|
|
|
private FilterBuilder(FilterStorage filterStorage, TypeIndices componentTypeIndices, IndexableSet<int> included, IndexableSet<int> excluded)
|
2022-04-08 05:52:03 +00:00
|
|
|
|
{
|
2023-01-10 00:41:00 +00:00
|
|
|
|
FilterStorage = filterStorage;
|
|
|
|
|
ComponentTypeIndices = componentTypeIndices;
|
2022-04-08 05:52:03 +00:00
|
|
|
|
Included = included;
|
|
|
|
|
Excluded = excluded;
|
|
|
|
|
}
|
2022-03-06 06:12:27 +00:00
|
|
|
|
|
2022-05-03 04:51:11 +00:00
|
|
|
|
public FilterBuilder Include<TComponent>() where TComponent : unmanaged
|
2022-04-08 05:52:03 +00:00
|
|
|
|
{
|
2023-01-10 00:41:00 +00:00
|
|
|
|
Included.Add(ComponentTypeIndices.GetIndex<TComponent>());
|
|
|
|
|
return new FilterBuilder(FilterStorage, ComponentTypeIndices, Included, Excluded);
|
2022-04-08 05:52:03 +00:00
|
|
|
|
}
|
2022-03-06 06:12:27 +00:00
|
|
|
|
|
2022-05-03 04:51:11 +00:00
|
|
|
|
public FilterBuilder Exclude<TComponent>() where TComponent : unmanaged
|
2022-04-08 05:52:03 +00:00
|
|
|
|
{
|
2023-01-10 00:41:00 +00:00
|
|
|
|
Excluded.Add(ComponentTypeIndices.GetIndex<TComponent>());
|
|
|
|
|
return new FilterBuilder(FilterStorage, ComponentTypeIndices, Included, Excluded);
|
2022-04-08 05:52:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Filter Build()
|
|
|
|
|
{
|
2023-01-10 00:41:00 +00:00
|
|
|
|
return FilterStorage.CreateFilter(Included, Excluded);
|
2022-04-08 05:52:03 +00:00
|
|
|
|
}
|
2022-03-06 06:12:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|