From b551a67915c9a930bcd553d2cd1ca8598431814e Mon Sep 17 00:00:00 2001 From: hypercross Date: Sat, 18 Jul 2026 22:27:14 +0800 Subject: [PATCH] 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. --- examples/TicTacToe/Systems/RenderSystem.cs | 3 +- examples/TicTacToe/Systems/WinCheckSystem.cs | 3 +- src/OECS/EntityIterator.cs | 35 ++++++++++++++++++++ 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/examples/TicTacToe/Systems/RenderSystem.cs b/examples/TicTacToe/Systems/RenderSystem.cs index ad061da..5c4e25f 100644 --- a/examples/TicTacToe/Systems/RenderSystem.cs +++ b/examples/TicTacToe/Systems/RenderSystem.cs @@ -18,8 +18,7 @@ public class RenderSystem : ISystem grid[r, c] = '.'; // Fill in placed marks using the iterator API. - var markQuery = world.Query().With().With().Build(); - using var markIter = world.Select(markQuery); + using var markIter = world.Select(); while (markIter.MoveNext()) { grid[markIter.Current1.Row, markIter.Current1.Col] = diff --git a/examples/TicTacToe/Systems/WinCheckSystem.cs b/examples/TicTacToe/Systems/WinCheckSystem.cs index cb56ec1..58b7137 100644 --- a/examples/TicTacToe/Systems/WinCheckSystem.cs +++ b/examples/TicTacToe/Systems/WinCheckSystem.cs @@ -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().With().Build(); - using var iter = world.Select(query); + using var iter = world.Select(); while (iter.MoveNext()) { grid[iter.Current1.Row, iter.Current1.Col] = iter.Current2.Player; diff --git a/src/OECS/EntityIterator.cs b/src/OECS/EntityIterator.cs index 95352f3..052fd89 100644 --- a/src/OECS/EntityIterator.cs +++ b/src/OECS/EntityIterator.cs @@ -20,6 +20,17 @@ public static class EntityIterator return new Select1(world, query); } + /// + /// Returns an iterator over entities that have a component of type + /// . No Without filter is applied. + /// + public static Select1 Select( + this World world) + where T1 : struct + { + return new Select1(world, new QueryDescriptor(new HashSet(), new HashSet())); + } + /// /// 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(world, query); } + /// + /// Returns an iterator over entities that have both components of type + /// and . + /// No Without filter is applied. + /// + public static Select2 Select( + this World world) + where T1 : struct where T2 : struct + { + return new Select2(world, new QueryDescriptor(new HashSet(), new HashSet())); + } + /// /// 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(world, query); } + + /// + /// Returns an iterator over entities that have all three components of type + /// , , and + /// . No Without filter is applied. + /// + public static Select3 Select( + this World world) + where T1 : struct where T2 : struct where T3 : struct + { + return new Select3(world, new QueryDescriptor(new HashSet(), new HashSet())); + } } ///