feat: add component discovery source generator

Introduce an incremental source generator that automatically discovers
component types used with the World API. This allows the
WorldSerializer to perform serialization and deserialization without
relying on reflection, improving performance and stability.
This commit is contained in:
2026-07-18 23:41:28 +08:00
parent 713d578179
commit 96ba037432
12 changed files with 468 additions and 21 deletions
+2 -2
View File
@@ -50,8 +50,8 @@ public static class Program
// ── Wire up systems ───────────────────────────────────────────
var group = new SystemGroup(world);
group.Add(new WinCheckSystem(world));
group.Add(new RenderSystem(world));
group.Add(new WinCheckSystem());
group.Add(new RenderSystem());
// ── Game loop ─────────────────────────────────────────────────
+5 -3
View File
@@ -10,11 +10,13 @@ public class WinCheckSystem : ISystem
{
public void Run(World world)
{
ref var state = ref world.GetSingleton<GameState>();
if (state.Status != GameStatus.Playing)
// Check game status before doing any work. Use ReadSingleton
// to avoid auto-marking GameState as modified when we bail early.
if (world.ReadSingleton<GameState>().Status != GameStatus.Playing)
return;
ref var state = ref world.GetSingleton<GameState>();
// Build a 3×3 grid of marks using the iterator API.
var grid = new Player[3, 3];
+6 -1
View File
@@ -12,10 +12,15 @@
<ProjectReference Include="..\..\src\OECS\OECS.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\OECS.SourceGen\OECS.SourceGen.csproj"
OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>
<ItemGroup>
<None Update="Data\board.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
</Project>