oecs-sharp/OECS/Query.cs

100 lines
2.7 KiB
C#

namespace OECS;
/// <summary>
/// Describes a query over the ECS world with one required component type.
/// Add optional <c>Without</c> filters via the fluent API.
/// </summary>
public struct Query<T1> where T1 : struct
{
internal HashSet<Type>? WithoutTypes;
/// <summary>
/// Excludes entities that have a component of type <typeparamref name="W"/>.
/// </summary>
public Query<T1> Without<W>() where W : struct
{
WithoutTypes ??= new HashSet<Type>();
WithoutTypes.Add(typeof(W));
return this;
}
}
/// <summary>
/// Describes a query over the ECS world with two required component types.
/// </summary>
public struct Query<T1, T2> where T1 : struct where T2 : struct
{
internal HashSet<Type>? WithoutTypes;
public Query<T1, T2> Without<W>() where W : struct
{
WithoutTypes ??= new HashSet<Type>();
WithoutTypes.Add(typeof(W));
return this;
}
}
/// <summary>
/// Describes a query over the ECS world with three required component types.
/// </summary>
public struct Query<T1, T2, T3>
where T1 : struct where T2 : struct where T3 : struct
{
internal HashSet<Type>? WithoutTypes;
public Query<T1, T2, T3> Without<W>() where W : struct
{
WithoutTypes ??= new HashSet<Type>();
WithoutTypes.Add(typeof(W));
return this;
}
}
/// <summary>
/// Describes a query over the ECS world with four required component types.
/// </summary>
public struct Query<T1, T2, T3, T4>
where T1 : struct where T2 : struct where T3 : struct where T4 : struct
{
internal HashSet<Type>? WithoutTypes;
public Query<T1, T2, T3, T4> Without<W>() where W : struct
{
WithoutTypes ??= new HashSet<Type>();
WithoutTypes.Add(typeof(W));
return this;
}
}
/// <summary>
/// Describes a query over the ECS world with five required component types.
/// </summary>
public struct Query<T1, T2, T3, T4, T5>
where T1 : struct where T2 : struct where T3 : struct where T4 : struct where T5 : struct
{
internal HashSet<Type>? WithoutTypes;
public Query<T1, T2, T3, T4, T5> Without<W>() where W : struct
{
WithoutTypes ??= new HashSet<Type>();
WithoutTypes.Add(typeof(W));
return this;
}
}
/// <summary>
/// Describes a query over the ECS world with six required component types.
/// </summary>
public struct Query<T1, T2, T3, T4, T5, T6>
where T1 : struct where T2 : struct where T3 : struct
where T4 : struct where T5 : struct where T6 : struct
{
internal HashSet<Type>? WithoutTypes;
public Query<T1, T2, T3, T4, T5, T6> Without<W>() where W : struct
{
WithoutTypes ??= new HashSet<Type>();
WithoutTypes.Add(typeof(W));
return this;
}
}