MoonTools.ECS/src/FilterBuilder.cs

46 lines
1.1 KiB
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 struct FilterBuilder
2022-03-06 06:12:27 +00:00
{
2022-04-08 05:52:03 +00:00
private ComponentDepot ComponentDepot;
private HashSet<Type> Included;
private HashSet<Type> Excluded;
2022-03-06 06:12:27 +00:00
2022-04-08 05:52:03 +00:00
internal FilterBuilder(ComponentDepot componentDepot)
{
ComponentDepot = componentDepot;
Included = new HashSet<Type>();
Excluded = new HashSet<Type>();
}
2022-03-06 06:12:27 +00:00
2022-04-08 05:52:03 +00:00
private FilterBuilder(ComponentDepot componentDepot, HashSet<Type> included, HashSet<Type> excluded)
{
ComponentDepot = componentDepot;
Included = included;
Excluded = excluded;
}
2022-03-06 06:12:27 +00:00
public FilterBuilder Include<TComponent>() where TComponent : unmanaged
2022-04-08 05:52:03 +00:00
{
ComponentDepot.Register<TComponent>();
Included.Add(typeof(TComponent));
return new FilterBuilder(ComponentDepot, Included, Excluded);
}
2022-03-06 06:12:27 +00:00
public FilterBuilder Exclude<TComponent>() where TComponent : unmanaged
2022-04-08 05:52:03 +00:00
{
ComponentDepot.Register<TComponent>();
Excluded.Add(typeof(TComponent));
return new FilterBuilder(ComponentDepot, Included, Excluded);
}
public Filter Build()
{
return ComponentDepot.CreateFilter(Included, Excluded);
}
2022-03-06 06:12:27 +00:00
}
}