Commit Graph

41 Commits

Author SHA1 Message Date
hypercross e460c0e70f refactor: rename iteration to batching and expand scope
Rename `BeginIteration`/`EndIteration` to `BeginBatching`/`EndBatching`
to reflect that the mechanism now covers both entity iteration and
system execution.

- Update `ISystem` and `ITickedSystem` to use `RunImpl` for logic.
- Add `SystemExtensions.Run` to wrap system execution in a batching
  scope.
- Update `SystemGroup` to wrap system execution in a batching scope.
- Update `WorldQueryExtensions` to use the new batching terminology.
2026-07-21 09:49:53 +08:00
hypercross 96d732d6ab refactor: simplify component iteration and singleton handling
Update the ECS engine to support automatic mutation tracking for
singletons during iteration, removing the need for manual
`MarkModified` calls.

- Update `ComponentDiscoveryGenerator` to detect singleton components.
- Refactor `PlaceMarkCommand` and `WinCheckSystem` to leverage
  automatic mutation marking.
- Replace `ForEach` usage with `Select` and `ItemN` access in tests
  and systems to align with the updated iterator API.
2026-07-21 09:15:27 +08:00
hypercross b98e8d66af refactor: replace QueryBuilder with generic Query and Select iterators
Replace the old `QueryBuilder` and `ForEach` callback pattern with a
more
performant, zero-allocation `Select` API using `ref struct` iterators.
This change also updates the singleton implementation to use dedicated
entities per component type rather than a single reserved entity.

- Replace `QueryBuilder`/`QueryDescriptor` with generic `Query<T1..T6>`
- Replace `ForEach` callbacks with `world.Select<T1..T6>()` iterators
- Replace `EntityIterator` with `WorldQueryExtensions`
- Update singleton logic to allocate one entity per component type
- Add `FindEntity<T>` and `FindEntities<T>` lookup methods
2026-07-21 00:24:10 +08:00
hypercross 737136e2ef refactor: replace ForEach with Select iterators
Replace the delegate-based ForEach pattern with zero-allocation ref
struct Select iterators. This change moves iteration logic from
QueryExecutor to WorldQueryExtensions and introduces a new fluent
Query<T> API.

Other changes:
- Update singleton handling to use a dictionary instead of a reserved
  ID.
- Add IsSingleton flag to ComponentDescriptor.
- Replace QueryDescriptor with type-safe Query<T> structs.
- Update tests to use the new Select API.
2026-07-21 00:21:01 +08:00
hypercross 91c6f4aa2c refactor: remove Source property from IRelationship
Remove the redundant `Source` property from `IRelationship` and its
implementations. Since the relationship component is inherently
stored on the source entity, the `Source` field was unnecessary and
required manual synchronization during deserialization.

This change simplifies the relationship model, reduces memory usage,
and removes the need for reflection-based fixups in the serializer.
2026-07-20 22:59:27 +08:00
hypercross 2de735498c feat: implement CardWars game engine
Implement the core CardWars game logic using an ECS-based architecture.
This includes:
- Card effect registry and various card effect implementations.
- Game phase management (Setup, Play, Flip, Scoring, Cleanup).
- Command system for player actions (PlayCard, FlipCard, etc.).
- Component-based game state and entity relationships.
- Automated game setup and scoring systems.
- Unit tests for game setup, card effects, and play logs.
2026-07-20 22:52:28 +08:00
hypercross 3b08138580 feat: add agent skill documentation
Add new skill documentation files for developing OECS, testing games,
and writing games. Also update the API surface documentation to include
guidance on component and command definitions.
2026-07-20 18:01:46 +08:00
hypercross b066ac2eba docs: update documentation and implementation plan
Update the API surface and implementation plan to reflect architectural
changes, including new iterator overloads, system design refinements,
and the introduction of a source generator.
2026-07-20 17:44:25 +08:00
hypercross 10c4caed90 test: improve blackjack play tests and logging
Refactor `RunRound` to `RunUntilDone` to allow for multi-round
simulations
until a win/loss condition is met. Added round summaries, win/loss/push
tracking, and improved log formatting to provide better visibility into
agent performance.
2026-07-20 17:37:23 +08:00
hypercross f8d0fe314c test: add play tests for Blackjack and TicTacToe
Implement play tests for Blackjack and TicTacToe that simulate games
using various AI agents (Basic Strategy, Random, Greedy) and record
the results, decisions, and reactivity into playlogs for debugging
and LLM analysis. Update documentation to reflect the purpose of
these tests.
2026-07-20 17:22:07 +08:00
hypercross 343bcd5b2e refactor: convert component structs to record structs 2026-07-20 17:15:17 +08:00
hypercross e1fb197474 feat(oecs): improve serialization and add snapshot tests
Enhance the OECS framework to support more robust component
deserialization during world serialization. This includes adding
boxed component support and a runtime fallback for component
discovery.

Additionally, introduces snapshot testing patterns for Blackjack
and TicTacToe to allow for manual verification of world state and
reactivity logs.
2026-07-20 17:05:17 +08:00
hypercross b4661e714e test: add unit tests for Blackjack and TicTacToe
- Add xUnit test projects for both games
- Implement game flow tests for Blackjack
- Implement game flow tests for TicTacToe
- Rename namespaces and projects to follow `Game.*` convention
- Add documentation for testing games
2026-07-20 16:41:10 +08:00
hypercross 7946f4bafd refactor: reorganize project structure and move examples
- Move examples (Blackjack, TicTacToe) to the root directory
- Convert example projects from Console applications to Libraries
- Add Directory.Build.props for shared build settings
- Update solution file and project references to reflect new paths
2026-07-20 16:30:02 +08:00
hypercross 5594515a53 feat: add local NuGet development workflow
Add a local NuGet feed configuration, a Directory.Build.props
template for Godot users, and automate source generator bundling
into the NuGet package.
2026-07-19 00:30:36 +08:00
hypercross 1da0ca30d3 refactor: replace boxed component addition with typed delegate 2026-07-18 23:44:10 +08:00
hypercross 96ba037432 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.
2026-07-18 23:41:28 +08:00
hypercross 713d578179 feat: add Blackjack example 2026-07-18 23:26:56 +08:00
hypercross b551a67915 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.
2026-07-18 22:27:14 +08:00
hypercross df388ee9b3 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.
2026-07-18 22:22:52 +08:00
hypercross ac7cd80a6f fix(oecs): clear dense entities array on reset 2026-07-18 22:06:33 +08:00
hypercross b6e64d2871 refactor: add struct constraint to Relationship
Add `where TSelf : struct where TTarget : struct` constraints to
the `Relationship` struct to ensure type safety and consistency with
the ECS architecture. Also remove unused `IterateThree` method in
`QueryExecutor`.
2026-07-18 22:05:29 +08:00
hypercross 58477aec50 docs: update API surface documentation 2026-07-18 21:59:09 +08:00
hypercross 32f4aa3e35 refactor: optimize query execution and improve change tracking
- Optimize `QueryExecutor` to use the smallest sparse set as a driver
  for multi-component queries, reducing iteration overhead.
- Implement automatic cleanup of unused `Subject` instances in
  `ChangeBuffer` using a subscriber count.
- Improve `ChangeSet` deduplication to correctly handle rapid
  add/remove transitions for the same component.
- Add validation to ensure `IRelationship` components are added to
  their declared `Source` entity.
- Update documentation to reflect correct `Entity` bit layout.
2026-07-18 21:42:08 +08:00
hypercross 339e850e10 perf: optimize iteration and command enqueuing
- Optimize Select2 and Select3 iterators to drive from the smallest
  sparse set to minimize probes.
- Use a constrained generic in CommandQueue.Enqueue to avoid boxing
  struct commands at the call site.
- Ensure singleton infrastructure is initialized during world
  deserialization if the singleton entity is loaded.
- Change EnsureSingleton to internal.
2026-07-18 21:32:29 +08:00
hypercross da84605b2f refactor: use ReadSingleton for GameState in RenderSystem 2026-07-18 21:24:11 +08:00
hypercross 910fd00a03 feat: add ReadComponent and ReadSingleton methods
Introduce read-only access methods that return copies of components
to avoid unnecessary modification marking during iteration.
2026-07-18 21:24:03 +08:00
hypercross f1eddc75ae feat: add deferred structural mutations and entity iterators
Implement deferred structural mutations (AddComponent, RemoveComponent,
DestroyEntity) to allow safe modification of the world during
iteration.

Additionally, introduce a new `EntityIterator` API providing zero-
allocation `ref struct` iterators (`Select<T1>`, `Select<T1, T2>`, etc.)
to support manual iteration with early-exit capabilities.

As part of these changes, component access via `GetComponent<T>` during
iteration now automatically marks components as modified.
2026-07-18 21:22:23 +08:00
hypercross 9aa2a71257 feat: add WorldSerializer for saving and loading world state 2026-07-18 21:07:05 +08:00
hypercross 0a28890f2c feat: implement game saving and loading in TicTacToe
- Add serialization support to `World`, `EntityAllocator`, and
  `SparseSet`
- Implement `SaveGame` and `LoadGame` functionality in the TicTacToe
  example
- Add ability to resume a game from a saved state
- Implement auto-save after every move in the game loop
2026-07-18 21:06:57 +08:00
hypercross a19861c080 feat: add TicTacToe example project
Implement a complete Tic-Tac-Toe game using OECS to demonstrate
ECS patterns, including:
- Command pattern for placing marks
- System groups for logical updates and rendering
- CSV loading for initial board state
- Reactivity logging for observing entity and component changes
2026-07-18 20:43:13 +08:00
hypercross dddddbdbd6 perf: cache hash code in QueryDescriptor
fix: notify change buffer when removing components in World

docs: add caution about structural changes during ForEach

fix: prevent multiple disposals in World
2026-07-18 20:13:25 +08:00
hypercross 6f9efc050b feat: add component validation and TryGetComponent
- Implement `TryGetComponent<T>` in `World` and `SparseSet<T>`
- Add validation to ensure `ForEach` type parameters match the
  `QueryDescriptor`
- Improve error handling in `SparseSet<T>.Get` to throw
  `InvalidOperationException`
- Use `GUID` instead of `FullName` for `QueryDescriptor` hash stability
2026-07-18 20:07:43 +08:00
hypercross 25789e7c9d fix: improve stability and add edge case tests
- Fix SparseSet resize logic to correctly initialize new slots
- Implement Equals and GetHashCode for QueryDescriptor
- Prevent collection modification exceptions in World.DestroyEntity
- Update CommandQueue to accumulate errors across drain cycles
- Add comprehensive edge case tests in EdgeCaseTests.cs
2026-07-18 19:58:23 +08:00
hypercross 8557fc864d feat: add singleton support to World
Introduces a mechanism to store and access singleton components on a
reserved entity. The singleton entity is automatically excluded from
all standard queries to prevent it from being processed like regular
entities.

- Added `SetSingleton`, `GetSingleton`, `HasSingleton`, and
  `RemoveSingleton` to `World`.
- Added `RegisterSingleton` to `EntityAllocator` to support the
  reserved entity.
- Updated `QueryExecutor` to skip the singleton entity during
  iteration.
- Added unit tests for singleton functionality.
2026-07-18 19:53:58 +08:00
hypercross 01eb5aa5f6 feat: add reactivity via change buffering and R3 observables 2026-07-18 19:50:31 +08:00
hypercross 48f3319615 feat: add relationship components and reverse indexing
Introduces a relationship system to allow entities to point to other
entities. Includes a `Relationship<TSelf, TTarget>` component and a
`RelationshipIndex` to enable efficient reverse lookups (finding all
sources pointing to a specific target).

The `World.DestroyEntity` method now performs cascading removals:
- Relationships where the entity is the source are removed.
- Relationships where the entity is the target are removed from their
  respective source entities.

Also adds MessagePack support to `Entity` and `Relationship`.
2026-07-18 19:42:59 +08:00
hypercross c5578d4412 feat: add deferred command queue system 2026-07-18 19:38:10 +08:00
hypercross e4afaafd02 feat: add query system and system execution logic
Introduces a complete query system for iterating over entities with
specific component combinations, including support for "with" and
"without" filters.

Also adds:
- `ISystem` and `ITickedSystem` interfaces for defining logic.
- `SystemGroup` for managing and running groups of systems.
- `QueryBuilder` for a fluent API to construct queries.
- `QueryExecutor` for high-performance iteration using ref parameters.
- `Tick` and `TickType` to support timed and logical updates.
2026-07-18 19:33:05 +08:00
hypercross 6739cf4ac9 docs: add ADR-012 and MessagePack serialization guidelines
- Update design.md with MessagePack component requirements
- Add ADR-012 to architecture.md regarding public type requirements
- Add MessagePackAnalyzer to OECS.csproj for compile-time validation
2026-07-18 19:07:22 +08:00
hypercross 34439e0f95 feat: initialize OECS project structure
Initializes the OECS repository with the core foundation, including:

- Entity management with 24-bit IDs and 8-bit versioning
- Sparse set-based component storage
- Entity allocation and recycling logic
- Core World API for entity and component lifecycle
- Project scaffolding for source and unit tests
- Design documentation and architecture decision records (ADRs)
2026-07-18 19:03:37 +08:00