refactor: remove QueryDescriptor from ISystem interface

Remove the mandatory Query property from the ISystem interface,
allowing systems to manage their own queries locally or via other
means. Update all implementing systems and tests to use local
query descriptors instead.
This commit is contained in:
2026-07-18 22:22:52 +08:00
parent ac7cd80a6f
commit df388ee9b3
7 changed files with 11 additions and 44 deletions
+1 -8
View File
@@ -7,13 +7,6 @@ namespace TicTacToe;
/// </summary>
public class RenderSystem : ISystem
{
public QueryDescriptor Query { get; }
public RenderSystem(World world)
{
Query = world.Query().With<Cell>().Build();
}
public void Run(World world)
{
var state = world.ReadSingleton<GameState>();
@@ -66,4 +59,4 @@ public class RenderSystem : ISystem
Console.WriteLine();
Console.Write(" Enter row col (e.g. \"1 2\"): ");
}
}
}
+3 -9
View File
@@ -8,13 +8,6 @@ namespace TicTacToe;
/// </summary>
public class WinCheckSystem : ISystem
{
public QueryDescriptor Query { get; }
public WinCheckSystem(World world)
{
Query = world.Query().With<Cell>().With<Mark>().Build();
}
public void Run(World world)
{
ref var state = ref world.GetSingleton<GameState>();
@@ -25,7 +18,8 @@ public class WinCheckSystem : ISystem
// Build a 3×3 grid of marks using the iterator API.
var grid = new Player[3, 3];
using var iter = world.Select<Cell, Mark>(Query);
var query = world.Query().With<Cell>().With<Mark>().Build();
using var iter = world.Select<Cell, Mark>(query);
while (iter.MoveNext())
{
grid[iter.Current1.Row, iter.Current1.Col] = iter.Current2.Player;
@@ -87,4 +81,4 @@ public class WinCheckSystem : ISystem
state.Status = winner == Player.X ? GameStatus.XWon : GameStatus.OWon;
world.MarkModified<GameState>(World.SingletonEntity);
}
}
}