- High-performance ECS in TypeScript + Bun (Archetype storage + Query cache + CommandBuffer deferred structural changes).
- No built-in System/Scheduler; the game loop is recommended to use
@codehz/pipeline, withworld.sync()called in the last pass.
- Core implementation:
src/core(world, archetype, entity, query, command-buffer). - Entry exports:
src/index.tsunified external API. - Examples:
examples/simple/demo.tsandexamples/advanced-scheduling/demo.ts. - Build/Release:
scripts/build.ts,scripts/release.ts.
- Install:
bun install - Test:
bun test(*.test.ts, performance with*.perf.test.ts) - Type check:
bunx tsc --noEmit - Example:
bun run examples/simple/demo.ts - Build:
bun run scripts/build.ts
- Structural changes (
set/remove/delete/spawn/build) enter the command buffer;world.sync()must be called for them to take effect. - Queries should be reused long-term: pre-create and cache via
world.createQuery(...), then useforEachdirectly in the loop. - Entity/Component ID rules: Component IDs 1–1023, Entity IDs 1024+, Relation IDs are negative-encoded (relation).
world.get()throws an error if the component does not exist;undefinedis a valid value. Always usehas()first or usegetOptional().- Serialization is an "in-memory snapshot":
world.serialize()returns an object,new World(snapshot)restores it; for persistence, custom encode/decode is needed. - Relation components:
relation(componentId, targetId); wildcard relations userelation(componentId, "*")to listen to all targets. - Exclusive relations: declare
exclusive: truein the component definition; same-type relations automatically exclude each other.
- Unified
world.sync()at the end of a Pipeline: seeexamples/simple/demo.ts. - Multi-component/optional component hooks: see README.md "Multi-Component Lifecycle Hooks".
- EntityBuilder:
world.spawn().with(...).build(); world.sync();.
- Keep the public API:
World,component,relation, etc. exports should not be renamed or removed. - Entry is ESM;
.tsextension imports are allowed. - Prioritize adding core logic in
src/core, and expose new APIs insrc/index.ts.