MoonTools.ECS/src/Rev2/FilterBuilder.cs

44 lines
898 B
C#
Raw Normal View History

2023-10-25 01:44:41 +00:00
using System.Collections.Generic;
2023-10-31 18:10:42 +00:00
namespace MoonTools.ECS.Rev2;
public ref struct FilterBuilder
2023-10-25 01:44:41 +00:00
{
2023-10-31 18:10:42 +00:00
World World;
HashSet<Id> Included;
HashSet<Id> Excluded;
2023-10-25 01:44:41 +00:00
2023-10-31 18:10:42 +00:00
internal FilterBuilder(World world)
{
World = world;
Included = new HashSet<Id>();
Excluded = new HashSet<Id>();
}
2023-10-25 01:44:41 +00:00
2023-10-31 18:10:42 +00:00
private FilterBuilder(World world, HashSet<Id> included, HashSet<Id> excluded)
{
World = world;
Included = included;
Excluded = excluded;
}
2023-10-25 01:44:41 +00:00
2023-10-31 18:10:42 +00:00
public FilterBuilder Include<T>() where T : unmanaged
{
World.GetTypeId<T>();
Included.Add(World.TypeToId[typeof(T)]);
return new FilterBuilder(World, Included, Excluded);
}
2023-10-25 01:44:41 +00:00
2023-10-31 18:10:42 +00:00
public FilterBuilder Exclude<T>() where T : unmanaged
{
World.GetTypeId<T>();
Excluded.Add(World.TypeToId[typeof(T)]);
return new FilterBuilder(World, Included, Excluded);
}
2023-10-25 01:44:41 +00:00
2023-10-31 18:10:42 +00:00
public Filter Build()
{
return new Filter(World.EmptyArchetype, Included, Excluded);
2023-10-25 01:44:41 +00:00
}
}