Commit Graph

28 Commits

Author SHA1 Message Date
hypercross 968672da06 fix(blackjack): update payout function signature 2026-06-02 18:08:01 +08:00
hypercross 365b2c4d13 fix: handle edge object in serialization tests
Add `typecheck` script to package.json, expand tsconfig include
paths to cover tests and examples, and update serialization tests
to correctly resolve player IDs from relationship edges.
2026-06-02 18:05:47 +08:00
hypercross cd6350e0b1 feat: add support for data-carrying relationships
Introduce the ability to attach optional data payloads to
relationships. This includes:

- Updating `defineRelationship` to accept default values.
- Adding `getRelData` and `setRelData` to the `World` class.
- Allowing `relate` to accept an optional data override.
- Updating serialization to include relationship data in snapshots.
- Implementing lazy storage for relationship data using `SparseSet`.
2026-06-02 17:56:12 +08:00
hypercross a97488e8d6 refactor(examples): reorganized code
Move code to avoid big main.ts and changed the bt to match the pattern
2026-06-02 10:39:27 +08:00
hypercross 5d125167cc refactor: make getRelatedTo return an iterator
Convert `getRelatedTo` from returning an array to returning an
`IterableIterator`. This improves memory efficiency by yielding
entities lazily instead of allocating a new array on every call.
2026-06-02 06:39:07 +08:00
hypercross 2469cdc7cb feat(examples): add blackjack game example 2026-06-02 00:57:22 +08:00
hypercross ef9abf03c6 docs: add singleton components, commands, and behaviour trees 2026-06-02 00:38:26 +08:00
hypercross 4182bc1578 feat(bt): support generator leaves and delta time
Introduce support for generator functions in leaf tasks, allowing
them to yield for multi-frame execution. The `TaskRunner` now accepts
a delta time (`dt`) parameter, which is passed through to leaf
handlers.

Additionally, a `Cancel` symbol is introduced to allow leaf tasks to
explicitly cancel their subtree via a thrown error.
2026-06-02 00:10:18 +08:00
hypercross ec8f668392 feat(bt): add declarative tree builder
Introduce `buildTree` to allow defining behaviour trees using a
declarative `TreeDef` object instead of manual entity spawning and
relationship wiring. This simplifies tree construction and manages
leaf handlers internally.
2026-06-01 23:57:19 +08:00
hypercross ccd0e3afb4 feat(world): add singleton component support
Introduce a mechanism to manage components on a shared, lazily-created
singleton entity. This simplifies access to global state by providing
dedicated methods for adding, removing, getting, and checking for
singleton components.

Refactor the Tetris example to utilize this new singleton pattern for
game state components like Board, Score, and Piece.
2026-06-01 23:52:47 +08:00
hypercross efa92be5ab feat(bt): implement subtree status clearing in TaskRunner
Introduce `clearSubtree` to recursively reset status for an entity and
all its descendants. This ensures that when a task reaches a terminal
state, its entire branch is properly reset.

Also refactor the Tetris example to use a sequential task node within
the behavior tree.
2026-06-01 23:24:43 +08:00
hypercross c3c24d2350 feat(examples): add Tetris game example 2026-06-01 23:18:07 +08:00
hypercross 3620e80807 feat(bt): add repeat and selector task kinds 2026-06-01 22:57:14 +08:00
hypercross 4e37e03d3f feat: add behavior tree implementation
Introduces a `TaskRunner` for executing behavior trees within the
ECS world. Supports leaf, sequential, parallel, and random task
kinds, along with status propagation (succeeded, failed, cancelled).
2026-06-01 22:52:10 +08:00
hypercross 2fe9203be9 perf: track component and relationship counts per entity
Introduce component and relationship counters to optimize entity
destruction and component checks. This allows for short-circuiting
the destruction process for bare entities and provides an O(1)
check for `hasAnyComponent`.
2026-06-01 14:34:51 +08:00
hypercross 9e788b135b feat: add CommandQueue for pull-based command processing
Introduces a `CommandQueue` to handle command components. It allows
registering handlers that are executed when `execute()` is called,
automatically removing the command component and cleaning up empty
entities. Includes an interruption mechanism to pause processing
during asynchronous operations.
2026-06-01 14:20:56 +08:00
hypercross fd78e9ce6d docs: add USAGE.md documentation 2026-05-31 17:31:21 +08:00
hypercross 46da8abbe1 refactor: remove rxjs dependency
Replace rxjs with a lightweight internal Subject implementation
to reduce package size and complexity.
2026-05-31 16:38:27 +08:00
hypercross 87c01858e7 test: add missing types to serialization tests 2026-05-31 16:36:25 +08:00
hypercross 81efb6cb0a refactor: split WorldEvent into EntityEvent and RelEvent 2026-05-31 16:31:27 +08:00
hypercross 05674a349f refactor: improve type safety in World and tests
Replace `any` types with specific interfaces like `WorldEvent`,
`QueryUpdate`, and `Entity` to strengthen type checking. This includes
refining the deserialization logic in `World.fromSnapshot` to use
properly typed component definitions.
2026-05-31 16:24:59 +08:00
hypercross 9953c7c556 test: expand serialization test coverage 2026-05-31 16:13:01 +08:00
hypercross 24616a0855 perf(observable): index observers by component for faster dispatch
Introduce a component-to-observer index to avoid iterating over all
observers for every world event. This optimizes event dispatching by
only notifying observers whose queries are relevant to the specific
component being added, removed, or changed.
2026-05-31 16:10:51 +08:00
hypercross 1c55485f9f feat: add world serialization support
Introduce `toJSON` and `fromJSON` methods to the `World` class to
allow saving and restoring world states. This requires components and
relationships to have human-readable names for stable serialization.
2026-05-31 16:10:19 +08:00
hypercross d0bb119911 feat: implement relationship system 2026-05-31 15:54:29 +08:00
hypercross 32f8f29912 feat: add relationship support and observability
Introduces relationship management to the World, including
storage for forward and reverse relationships. Adds new observable
events and a `RelationshipUpdate` stream to track when relationships
are added or removed.
2026-05-31 15:54:21 +08:00
hypercross ba4a688f57 test: add vitest and implement unit tests 2026-05-31 15:47:19 +08:00
hypercross 4ede2d7f3b feat: implement core ECS engine with RxJS observability
Initial implementation of an Entity-Component-System (ECS) featuring:
- Sparse set-based component storage for efficient access.
- Entity lifecycle management with generation-based recycling.
- Reactive query system using RxJS for change tracking.
- Batched event flushing to support frame-based updates.
- Type-safe component definitions via TypeScript inference.
2026-05-31 15:45:20 +08:00