feat: add simplified Select extension methods to EntityIterator
Add overloads for Select that allow iterating over components without manually building a QueryDescriptor, simplifying usage in systems.
This commit is contained in:
parent
df388ee9b3
commit
b551a67915
|
|
@ -18,8 +18,7 @@ public class RenderSystem : ISystem
|
|||
grid[r, c] = '.';
|
||||
|
||||
// Fill in placed marks using the iterator API.
|
||||
var markQuery = world.Query().With<Cell>().With<Mark>().Build();
|
||||
using var markIter = world.Select<Cell, Mark>(markQuery);
|
||||
using var markIter = world.Select<Cell, Mark>();
|
||||
while (markIter.MoveNext())
|
||||
{
|
||||
grid[markIter.Current1.Row, markIter.Current1.Col] =
|
||||
|
|
|
|||
|
|
@ -18,8 +18,7 @@ public class WinCheckSystem : ISystem
|
|||
// Build a 3×3 grid of marks using the iterator API.
|
||||
var grid = new Player[3, 3];
|
||||
|
||||
var query = world.Query().With<Cell>().With<Mark>().Build();
|
||||
using var iter = world.Select<Cell, Mark>(query);
|
||||
using var iter = world.Select<Cell, Mark>();
|
||||
while (iter.MoveNext())
|
||||
{
|
||||
grid[iter.Current1.Row, iter.Current1.Col] = iter.Current2.Player;
|
||||
|
|
|
|||
|
|
@ -20,6 +20,17 @@ public static class EntityIterator
|
|||
return new Select1<T1>(world, query);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an iterator over entities that have a component of type
|
||||
/// <typeparamref name="T1"/>. No <c>Without</c> filter is applied.
|
||||
/// </summary>
|
||||
public static Select1<T1> Select<T1>(
|
||||
this World world)
|
||||
where T1 : struct
|
||||
{
|
||||
return new Select1<T1>(world, new QueryDescriptor(new HashSet<Type>(), new HashSet<Type>()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an iterator over entities matching the query, with ref access
|
||||
/// to two component types.
|
||||
|
|
@ -31,6 +42,18 @@ public static class EntityIterator
|
|||
return new Select2<T1, T2>(world, query);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an iterator over entities that have both components of type
|
||||
/// <typeparamref name="T1"/> and <typeparamref name="T2"/>.
|
||||
/// No <c>Without</c> filter is applied.
|
||||
/// </summary>
|
||||
public static Select2<T1, T2> Select<T1, T2>(
|
||||
this World world)
|
||||
where T1 : struct where T2 : struct
|
||||
{
|
||||
return new Select2<T1, T2>(world, new QueryDescriptor(new HashSet<Type>(), new HashSet<Type>()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an iterator over entities matching the query, with ref access
|
||||
/// to three component types.
|
||||
|
|
@ -41,6 +64,18 @@ public static class EntityIterator
|
|||
{
|
||||
return new Select3<T1, T2, T3>(world, query);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an iterator over entities that have all three components of type
|
||||
/// <typeparamref name="T1"/>, <typeparamref name="T2"/>, and
|
||||
/// <typeparamref name="T3"/>. No <c>Without</c> filter is applied.
|
||||
/// </summary>
|
||||
public static Select3<T1, T2, T3> Select<T1, T2, T3>(
|
||||
this World world)
|
||||
where T1 : struct where T2 : struct where T3 : struct
|
||||
{
|
||||
return new Select3<T1, T2, T3>(world, new QueryDescriptor(new HashSet<Type>(), new HashSet<Type>()));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Reference in New Issue