@flare-engine/ecs 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @flare-engine/ecs
2
2
 
3
- Archetype-bitmask ECS — `World`, `Query` with `onEntityAdded` / `onEntityRemoved` signals, `defineComponent`, `defineSystem`, `definePrefab`, `FSM`. Built-in `Position` / `Velocity` / `Rotation` / `Scale` / `Parent` components. Max 32 component types per world.
3
+ Archetype-bitmask ECS — `World`, `Query` with `onEntityAdded` / `onEntityRemoved` signals, `defineComponent`, `defineSystem`, `definePrefab`, `FSM`. Built-in components: `Position`, `Velocity`, `Rotation`, `Scale`, `Parent`, `Lifetime`, `Follower`. Five system factories: `createMovementSystem`, `createLifetimeSystem`, `createBoundsCullSystem`, `createFollowerSystem`, `createOrphanCullSystem`. Max 32 component types per world.
4
4
 
5
5
  ## Install
6
6
 
@@ -25,7 +25,7 @@ const movers = world.query(Position, Velocity);
25
25
  for (const id of movers) { /* ... */ }
26
26
  ```
27
27
 
28
- See [API spec](../../docs/design/api-specs.md#flare-engineecs--8kb-gzip) and [skill reference](../../.github/skills/flare-ecs/SKILL.md).
28
+ See [API spec](../../docs/design/api-specs.md#flare-engineecs--8kb-gzip).
29
29
 
30
30
  ## License
31
31
 
package/dist/index.d.mts CHANGED
@@ -212,5 +212,82 @@ declare const Scale: ComponentDef<Vec2>;
212
212
  declare const Parent: ComponentDef<{
213
213
  entity: number;
214
214
  }>;
215
+ /** Countdown timer in seconds; entity expires when remaining reaches 0. */
216
+ declare const Lifetime: ComponentDef<{
217
+ remaining: number;
218
+ }>;
219
+ /** Pins an entity's position to a target entity plus a fixed offset. */
220
+ declare const Follower: ComponentDef<{
221
+ target: number;
222
+ offsetX: number;
223
+ offsetY: number;
224
+ }>;
225
+
226
+ /**
227
+ * Plain camera-space bounding box used by createBoundsCullSystem.
228
+ * Keep plain numbers — do NOT import physics AABB/Bounds (layer inversion).
229
+ */
230
+ interface CullBounds {
231
+ readonly minX: number;
232
+ readonly minY: number;
233
+ readonly maxX: number;
234
+ readonly maxY: number;
235
+ }
236
+ /**
237
+ * createMovementSystem — integrates Position by Velocity * dt each frame.
238
+ *
239
+ * Recommended priority: run BEFORE createFollowerSystem (0).
240
+ */
241
+ declare function createMovementSystem(world: World): SystemDef;
242
+ /**
243
+ * createLifetimeSystem — decrements Lifetime.remaining each frame.
244
+ * Entities whose remaining reaches <= 0 are collected, then onExpire is called
245
+ * for each AFTER the read loop.
246
+ *
247
+ * Deferred removal: destroying inside a live for…of over query.entities splices
248
+ * the array mid-iteration and would skip entities. Collect first, act after.
249
+ *
250
+ * The scratch array is closure-owned and grow-only — zero steady-state alloc.
251
+ *
252
+ * @param onExpire Destroy / pool policy — ecs never destroys on its own.
253
+ */
254
+ declare function createLifetimeSystem(world: World, onExpire: (entity: number, world: World) => void): SystemDef;
255
+ /**
256
+ * createBoundsCullSystem — culls entities whose Position falls outside bounds.
257
+ * Reads bounds LIVE each frame so callers can mutate it to follow a camera.
258
+ * Entities outside are collected, then onCull is called for each after the read loop.
259
+ *
260
+ * Deferred removal: same splice-during-iteration reason as createLifetimeSystem.
261
+ *
262
+ * Recommended priority: run AFTER createMovementSystem and createFollowerSystem.
263
+ *
264
+ * @param bounds Mutable bounding box read each frame.
265
+ * @param onCull Destroy / pool policy — ecs never destroys on its own.
266
+ */
267
+ declare function createBoundsCullSystem(world: World, bounds: CullBounds, onCull: (entity: number, world: World) => void): SystemDef;
268
+ /**
269
+ * createFollowerSystem — pins each Follower entity's Position to
270
+ * target.Position + (offsetX, offsetY).
271
+ * If the target is gone or has no Position, the entity is silently skipped.
272
+ *
273
+ * Recommended priority: run AFTER createMovementSystem (1) so the target's
274
+ * position is already integrated before the follower snaps to it.
275
+ */
276
+ declare function createFollowerSystem(world: World): SystemDef;
277
+ /**
278
+ * createOrphanCullSystem — fires onOrphan for each Follower whose target entity
279
+ * no longer exists. Does NOT move or destroy anything itself.
280
+ *
281
+ * Split from createFollowerSystem so games that want to orphan-cull can opt in
282
+ * without coupling destruction to the follower pin logic.
283
+ *
284
+ * Recommended priority: run AFTER createFollowerSystem (2) so the follower is
285
+ * pinned before orphans are detected.
286
+ *
287
+ * Deferred removal: same splice-during-iteration reason as createLifetimeSystem.
288
+ *
289
+ * @param onOrphan Called once per orphaned entity after the read loop.
290
+ */
291
+ declare function createOrphanCullSystem(world: World, onOrphan: (entity: number, world: World) => void): SystemDef;
215
292
 
216
- export { type ComponentDef, FSM, Parent, Position, type Prefab, Query, QueryBuilder, Rotation, Scale, type State, type SystemDef, type SystemFn, Velocity, World, _resetComponentIds, defineComponent, definePrefab, defineSystem };
293
+ export { type ComponentDef, type CullBounds, FSM, Follower, Lifetime, Parent, Position, type Prefab, Query, QueryBuilder, Rotation, Scale, type State, type SystemDef, type SystemFn, Velocity, World, _resetComponentIds, createBoundsCullSystem, createFollowerSystem, createLifetimeSystem, createMovementSystem, createOrphanCullSystem, defineComponent, definePrefab, defineSystem };
package/dist/index.d.ts CHANGED
@@ -212,5 +212,82 @@ declare const Scale: ComponentDef<Vec2>;
212
212
  declare const Parent: ComponentDef<{
213
213
  entity: number;
214
214
  }>;
215
+ /** Countdown timer in seconds; entity expires when remaining reaches 0. */
216
+ declare const Lifetime: ComponentDef<{
217
+ remaining: number;
218
+ }>;
219
+ /** Pins an entity's position to a target entity plus a fixed offset. */
220
+ declare const Follower: ComponentDef<{
221
+ target: number;
222
+ offsetX: number;
223
+ offsetY: number;
224
+ }>;
225
+
226
+ /**
227
+ * Plain camera-space bounding box used by createBoundsCullSystem.
228
+ * Keep plain numbers — do NOT import physics AABB/Bounds (layer inversion).
229
+ */
230
+ interface CullBounds {
231
+ readonly minX: number;
232
+ readonly minY: number;
233
+ readonly maxX: number;
234
+ readonly maxY: number;
235
+ }
236
+ /**
237
+ * createMovementSystem — integrates Position by Velocity * dt each frame.
238
+ *
239
+ * Recommended priority: run BEFORE createFollowerSystem (0).
240
+ */
241
+ declare function createMovementSystem(world: World): SystemDef;
242
+ /**
243
+ * createLifetimeSystem — decrements Lifetime.remaining each frame.
244
+ * Entities whose remaining reaches <= 0 are collected, then onExpire is called
245
+ * for each AFTER the read loop.
246
+ *
247
+ * Deferred removal: destroying inside a live for…of over query.entities splices
248
+ * the array mid-iteration and would skip entities. Collect first, act after.
249
+ *
250
+ * The scratch array is closure-owned and grow-only — zero steady-state alloc.
251
+ *
252
+ * @param onExpire Destroy / pool policy — ecs never destroys on its own.
253
+ */
254
+ declare function createLifetimeSystem(world: World, onExpire: (entity: number, world: World) => void): SystemDef;
255
+ /**
256
+ * createBoundsCullSystem — culls entities whose Position falls outside bounds.
257
+ * Reads bounds LIVE each frame so callers can mutate it to follow a camera.
258
+ * Entities outside are collected, then onCull is called for each after the read loop.
259
+ *
260
+ * Deferred removal: same splice-during-iteration reason as createLifetimeSystem.
261
+ *
262
+ * Recommended priority: run AFTER createMovementSystem and createFollowerSystem.
263
+ *
264
+ * @param bounds Mutable bounding box read each frame.
265
+ * @param onCull Destroy / pool policy — ecs never destroys on its own.
266
+ */
267
+ declare function createBoundsCullSystem(world: World, bounds: CullBounds, onCull: (entity: number, world: World) => void): SystemDef;
268
+ /**
269
+ * createFollowerSystem — pins each Follower entity's Position to
270
+ * target.Position + (offsetX, offsetY).
271
+ * If the target is gone or has no Position, the entity is silently skipped.
272
+ *
273
+ * Recommended priority: run AFTER createMovementSystem (1) so the target's
274
+ * position is already integrated before the follower snaps to it.
275
+ */
276
+ declare function createFollowerSystem(world: World): SystemDef;
277
+ /**
278
+ * createOrphanCullSystem — fires onOrphan for each Follower whose target entity
279
+ * no longer exists. Does NOT move or destroy anything itself.
280
+ *
281
+ * Split from createFollowerSystem so games that want to orphan-cull can opt in
282
+ * without coupling destruction to the follower pin logic.
283
+ *
284
+ * Recommended priority: run AFTER createFollowerSystem (2) so the follower is
285
+ * pinned before orphans are detected.
286
+ *
287
+ * Deferred removal: same splice-during-iteration reason as createLifetimeSystem.
288
+ *
289
+ * @param onOrphan Called once per orphaned entity after the read loop.
290
+ */
291
+ declare function createOrphanCullSystem(world: World, onOrphan: (entity: number, world: World) => void): SystemDef;
215
292
 
216
- export { type ComponentDef, FSM, Parent, Position, type Prefab, Query, QueryBuilder, Rotation, Scale, type State, type SystemDef, type SystemFn, Velocity, World, _resetComponentIds, defineComponent, definePrefab, defineSystem };
293
+ export { type ComponentDef, type CullBounds, FSM, Follower, Lifetime, Parent, Position, type Prefab, Query, QueryBuilder, Rotation, Scale, type State, type SystemDef, type SystemFn, Velocity, World, _resetComponentIds, createBoundsCullSystem, createFollowerSystem, createLifetimeSystem, createMovementSystem, createOrphanCullSystem, defineComponent, definePrefab, defineSystem };
package/dist/index.js CHANGED
@@ -21,6 +21,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  FSM: () => FSM,
24
+ Follower: () => Follower,
25
+ Lifetime: () => Lifetime,
24
26
  Parent: () => Parent,
25
27
  Position: () => Position,
26
28
  Query: () => Query,
@@ -30,6 +32,11 @@ __export(index_exports, {
30
32
  Velocity: () => Velocity,
31
33
  World: () => World,
32
34
  _resetComponentIds: () => _resetComponentIds,
35
+ createBoundsCullSystem: () => createBoundsCullSystem,
36
+ createFollowerSystem: () => createFollowerSystem,
37
+ createLifetimeSystem: () => createLifetimeSystem,
38
+ createMovementSystem: () => createMovementSystem,
39
+ createOrphanCullSystem: () => createOrphanCullSystem,
33
40
  defineComponent: () => defineComponent,
34
41
  definePrefab: () => definePrefab,
35
42
  defineSystem: () => defineSystem
@@ -369,9 +376,93 @@ var Scale = defineComponent("Scale", () => ({ x: 1, y: 1 }));
369
376
  var Parent = defineComponent("Parent", () => ({
370
377
  entity: 0
371
378
  }));
379
+ var Lifetime = defineComponent("Lifetime", () => ({
380
+ remaining: 0
381
+ }));
382
+ var Follower = defineComponent(
383
+ "Follower",
384
+ () => ({ target: 0, offsetX: 0, offsetY: 0 })
385
+ );
386
+
387
+ // src/systems.ts
388
+ function createMovementSystem(world) {
389
+ const q = world.query(Position, Velocity);
390
+ return defineSystem(q, (entities, dt, w) => {
391
+ for (const id of entities) {
392
+ const pos = w.get(id, Position);
393
+ const vel = w.get(id, Velocity);
394
+ pos.x += vel.x * dt;
395
+ pos.y += vel.y * dt;
396
+ }
397
+ });
398
+ }
399
+ function createLifetimeSystem(world, onExpire) {
400
+ const q = world.query(Lifetime);
401
+ const scratch = [];
402
+ return defineSystem(q, (entities, dt, w) => {
403
+ scratch.length = 0;
404
+ for (const id of entities) {
405
+ const life = w.get(id, Lifetime);
406
+ life.remaining -= dt;
407
+ if (life.remaining <= 0) {
408
+ scratch.push(id);
409
+ }
410
+ }
411
+ for (let i = 0; i < scratch.length; i++) {
412
+ onExpire(scratch[i], w);
413
+ }
414
+ });
415
+ }
416
+ function createBoundsCullSystem(world, bounds, onCull) {
417
+ const q = world.query(Position);
418
+ const scratch = [];
419
+ return defineSystem(q, (entities, _dt, w) => {
420
+ scratch.length = 0;
421
+ for (const id of entities) {
422
+ const pos = w.get(id, Position);
423
+ if (pos.x < bounds.minX || pos.x > bounds.maxX || pos.y < bounds.minY || pos.y > bounds.maxY) {
424
+ scratch.push(id);
425
+ }
426
+ }
427
+ for (let i = 0; i < scratch.length; i++) {
428
+ onCull(scratch[i], w);
429
+ }
430
+ });
431
+ }
432
+ function createFollowerSystem(world) {
433
+ const q = world.query(Position, Follower);
434
+ return defineSystem(q, (entities, _dt, w) => {
435
+ for (const id of entities) {
436
+ const follower = w.get(id, Follower);
437
+ const t = w.get(follower.target, Position);
438
+ if (t === void 0) continue;
439
+ const pos = w.get(id, Position);
440
+ pos.x = t.x + follower.offsetX;
441
+ pos.y = t.y + follower.offsetY;
442
+ }
443
+ });
444
+ }
445
+ function createOrphanCullSystem(world, onOrphan) {
446
+ const q = world.query(Follower);
447
+ const scratch = [];
448
+ return defineSystem(q, (entities, _dt, w) => {
449
+ scratch.length = 0;
450
+ for (const id of entities) {
451
+ const follower = w.get(id, Follower);
452
+ if (!w.exists(follower.target)) {
453
+ scratch.push(id);
454
+ }
455
+ }
456
+ for (let i = 0; i < scratch.length; i++) {
457
+ onOrphan(scratch[i], w);
458
+ }
459
+ });
460
+ }
372
461
  // Annotate the CommonJS export names for ESM import in node:
373
462
  0 && (module.exports = {
374
463
  FSM,
464
+ Follower,
465
+ Lifetime,
375
466
  Parent,
376
467
  Position,
377
468
  Query,
@@ -381,6 +472,11 @@ var Parent = defineComponent("Parent", () => ({
381
472
  Velocity,
382
473
  World,
383
474
  _resetComponentIds,
475
+ createBoundsCullSystem,
476
+ createFollowerSystem,
477
+ createLifetimeSystem,
478
+ createMovementSystem,
479
+ createOrphanCullSystem,
384
480
  defineComponent,
385
481
  definePrefab,
386
482
  defineSystem
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/component.ts","../src/query.ts","../src/world.ts","../src/system.ts","../src/prefab.ts","../src/fsm.ts","../src/components.ts"],"sourcesContent":["export { defineComponent, _resetComponentIds } from './component.js';\nexport type { ComponentDef } from './component.js';\n\nexport { World } from './world.js';\n\nexport { Query, QueryBuilder } from './query.js';\n\nexport { defineSystem } from './system.js';\nexport type { SystemFn, SystemDef } from './system.js';\n\nexport { definePrefab } from './prefab.js';\nexport type { Prefab } from './prefab.js';\n\nexport { FSM } from './fsm.js';\nexport type { State } from './fsm.js';\n\nexport { Position, Velocity, Rotation, Scale, Parent } from './components.js';\n","/**\n * Component definition and factory.\n *\n * Components are plain data objects. Each component type gets a unique\n * bit for archetype-based query matching.\n */\n\n/** A unique component definition. */\nexport interface ComponentDef<T> {\n /** Internal unique ID (auto-assigned). */\n readonly id: number;\n /** Bitmask for this component (1 << id). */\n readonly bit: number;\n /** Component name for debugging. */\n readonly name: string;\n /** Create a new instance with default values. */\n create(): T;\n}\n\nlet nextComponentId = 0;\n\n/**\n * Define a new component type.\n *\n * @param name Debug name for the component.\n * @param defaults Factory function returning default values, or undefined for tag components.\n */\nexport function defineComponent<T = undefined>(name: string, defaults?: () => T): ComponentDef<T> {\n const id = nextComponentId++;\n if (id >= 32) {\n throw new Error(`Maximum 32 component types exceeded (defining \"${name}\")`);\n }\n return {\n id,\n bit: 1 << id,\n name,\n create: defaults ?? (() => undefined as T),\n };\n}\n\n/**\n * Reset the component ID counter. Only for testing.\n * @internal\n */\nexport function _resetComponentIds(): void {\n nextComponentId = 0;\n}\n","import { Signal } from '@flare-engine/events';\nimport type { ComponentDef } from './component.js';\n\n/**\n * Query matches entities based on component archetypes.\n *\n * Uses bitmask matching: entity archetype & requiredMask === requiredMask\n * and entity archetype & excludedMask === 0.\n */\nexport class Query {\n /** Bitmask of required components. */\n readonly requiredMask: number;\n /** Bitmask of excluded components. */\n readonly excludedMask: number;\n\n /** Fires when an entity is added to this query's results. */\n readonly onEntityAdded = new Signal<number>();\n /** Fires when an entity is removed from this query's results. */\n readonly onEntityRemoved = new Signal<number>();\n\n /** Sorted array of matching entity IDs. */\n private entities: number[] = [];\n /** Set for O(1) membership check. */\n private entitySet = new Set<number>();\n\n constructor(requiredMask: number, excludedMask: number) {\n this.requiredMask = requiredMask;\n this.excludedMask = excludedMask;\n }\n\n /** Check if an archetype matches this query. */\n matches(archetype: number): boolean {\n return (\n (archetype & this.requiredMask) === this.requiredMask && (archetype & this.excludedMask) === 0\n );\n }\n\n /** @internal — called by World when an entity's archetype changes. */\n _check(entityId: number, archetype: number): void {\n const isMatch = this.matches(archetype);\n const wasMatch = this.entitySet.has(entityId);\n\n if (isMatch && !wasMatch) {\n this.entitySet.add(entityId);\n this.entities.push(entityId);\n this.onEntityAdded.emit(entityId);\n } else if (!isMatch && wasMatch) {\n this.entitySet.delete(entityId);\n const idx = this.entities.indexOf(entityId);\n if (idx !== -1) this.entities.splice(idx, 1);\n this.onEntityRemoved.emit(entityId);\n }\n }\n\n /** @internal — called by World when an entity is removed entirely. */\n _remove(entityId: number): void {\n if (this.entitySet.has(entityId)) {\n this.entitySet.delete(entityId);\n const idx = this.entities.indexOf(entityId);\n if (idx !== -1) this.entities.splice(idx, 1);\n this.onEntityRemoved.emit(entityId);\n }\n }\n\n /** Iterate matching entity IDs. */\n [Symbol.iterator](): IterableIterator<number> {\n return this.entities[Symbol.iterator]();\n }\n\n /** Number of matching entities. */\n get count(): number {\n return this.entities.length;\n }\n\n /** Check if an entity matches this query. */\n has(entityId: number): boolean {\n return this.entitySet.has(entityId);\n }\n}\n\n/** Builder for creating queries with .with() / .without() chaining. */\nexport class QueryBuilder {\n private required = 0;\n private excluded = 0;\n\n with(...components: ComponentDef<unknown>[]): this {\n for (const c of components) {\n this.required |= c.bit;\n }\n return this;\n }\n\n without(...components: ComponentDef<unknown>[]): this {\n for (const c of components) {\n this.excluded |= c.bit;\n }\n return this;\n }\n\n /** Build the query (called internally by World). */\n build(): Query {\n return new Query(this.required, this.excluded);\n }\n}\n","import type { ComponentDef } from './component.js';\nimport { Query, QueryBuilder } from './query.js';\n\n/**\n * World is the central ECS container.\n *\n * Entities are integer IDs. Components are stored in per-component Maps.\n * Archetype bitmasks enable fast query matching.\n */\nexport class World {\n private nextId = 1;\n private archetypes = new Map<number, number>(); // entityId → bitmask\n private componentStores = new Map<number, Map<number, unknown>>(); // componentId → (entityId → data)\n private queries: Query[] = [];\n private systems: {\n fn: (world: World, dt: number) => void;\n priority: number;\n }[] = [];\n private systemsSorted = false;\n\n /** Create a new entity. Returns the entity ID. */\n spawn(): number {\n const id = this.nextId++;\n this.archetypes.set(id, 0);\n return id;\n }\n\n /** Remove an entity and all its components. */\n destroy(entityId: number): void {\n const arch = this.archetypes.get(entityId);\n if (arch === undefined) return;\n\n // Remove from all component stores\n for (const [, store] of this.componentStores) {\n store.delete(entityId);\n }\n\n this.archetypes.delete(entityId);\n\n // Notify queries\n for (const query of this.queries) {\n query._remove(entityId);\n }\n }\n\n /** Add a component to an entity. */\n add<T>(entityId: number, def: ComponentDef<T>, data?: T): void {\n const arch = this.archetypes.get(entityId);\n if (arch === undefined) return;\n\n // Store component data\n let store = this.componentStores.get(def.id);\n if (!store) {\n store = new Map();\n this.componentStores.set(def.id, store);\n }\n store.set(entityId, data !== undefined ? data : def.create());\n\n // Update archetype\n const newArch = arch | def.bit;\n this.archetypes.set(entityId, newArch);\n\n // Notify queries\n for (const query of this.queries) {\n query._check(entityId, newArch);\n }\n }\n\n /** Remove a component from an entity. */\n remove<T>(entityId: number, def: ComponentDef<T>): void {\n const arch = this.archetypes.get(entityId);\n if (arch === undefined) return;\n\n const store = this.componentStores.get(def.id);\n if (store) store.delete(entityId);\n\n const newArch = arch & ~def.bit;\n this.archetypes.set(entityId, newArch);\n\n // Notify queries\n for (const query of this.queries) {\n query._check(entityId, newArch);\n }\n }\n\n /** Get component data for an entity. */\n get<T>(entityId: number, def: ComponentDef<T>): T | undefined {\n const store = this.componentStores.get(def.id);\n return store?.get(entityId) as T | undefined;\n }\n\n /** Check if entity has a component. */\n has(entityId: number, def: ComponentDef<unknown>): boolean {\n const arch = this.archetypes.get(entityId);\n return arch !== undefined && (arch & def.bit) !== 0;\n }\n\n /** Check if entity exists. */\n exists(entityId: number): boolean {\n return this.archetypes.has(entityId);\n }\n\n /**\n * Create a query. Queries auto-update as entities change.\n * Use the QueryBuilder-style chaining:\n * world.query(Position, Velocity)\n * Or use the builder:\n * world.queryBuilder().with(Position).without(Dead).build()\n */\n query(...components: ComponentDef<unknown>[]): Query {\n let mask = 0;\n for (const c of components) {\n mask |= c.bit;\n }\n const q = new Query(mask, 0);\n this.queries.push(q);\n\n // Populate with existing entities\n for (const [entityId, arch] of this.archetypes) {\n q._check(entityId, arch);\n }\n\n return q;\n }\n\n /** Create a QueryBuilder for complex queries (with/without). */\n queryBuilder(): QueryBuilder {\n return new _WorldQueryBuilder(this);\n }\n\n /** Register a system function. Lower priority runs first. */\n addSystem(fn: (world: World, dt: number) => void, priority = 0): void {\n this.systems.push({ fn, priority });\n this.systemsSorted = false;\n }\n\n /** Remove a system. */\n removeSystem(fn: (world: World, dt: number) => void): void {\n const idx = this.systems.findIndex((s) => s.fn === fn);\n if (idx !== -1) this.systems.splice(idx, 1);\n }\n\n /** Run all systems in priority order. */\n step(dt: number): void {\n if (!this.systemsSorted) {\n this.systems.sort((a, b) => a.priority - b.priority);\n this.systemsSorted = true;\n }\n for (const sys of this.systems) {\n sys.fn(this, dt);\n }\n }\n\n /** @internal Register a query for auto-update. */\n _registerQuery(q: Query): void {\n this.queries.push(q);\n // Populate with existing entities\n for (const [entityId, arch] of this.archetypes) {\n q._check(entityId, arch);\n }\n }\n}\n\n/**\n * Internal query builder that auto-registers with a World.\n */\nclass _WorldQueryBuilder extends QueryBuilder {\n private world: World;\n\n constructor(world: World) {\n super();\n this.world = world;\n }\n\n override build(): Query {\n const q = super.build();\n this.world._registerQuery(q);\n return q;\n }\n}\n","import type { Query } from './query.js';\nimport type { World } from './world.js';\n\n/** A system function that processes entities matching a query. */\nexport type SystemFn = (entities: Query, dt: number, world: World) => void;\n\n/** A defined system with its query and function. */\nexport interface SystemDef {\n readonly query: Query;\n readonly fn: SystemFn;\n /** The wrapper registered on the World (used for removal). */\n readonly _worldFn: (world: World, dt: number) => void;\n}\n\n/**\n * Define a system that processes entities matching a query.\n *\n * Returns a SystemDef that can be added to a World via world.addSystem().\n * The system function receives the query's matching entities, dt, and world.\n *\n * Usage:\n * const q = world.query(Position, Velocity);\n * const moveSys = defineSystem(q, (entities, dt, world) => {\n * for (const id of entities) { ... }\n * });\n * world.addSystem(moveSys._worldFn);\n */\nexport function defineSystem(query: Query, fn: SystemFn): SystemDef {\n const worldFn = (world: World, dt: number) => {\n fn(query, dt, world);\n };\n return { query, fn, _worldFn: worldFn };\n}\n","import type { ComponentDef } from './component.js';\nimport type { World } from './world.js';\n\n/** A component entry in a prefab definition. */\ninterface PrefabEntry<T> {\n def: ComponentDef<T>;\n data?: T | (() => T);\n}\n\n/** A prefab factory that spawns entities with pre-defined components. */\nexport interface Prefab {\n readonly name: string;\n /** Spawn an entity with this prefab's components. */\n spawn(world: World, overrides?: Record<string, unknown>): number;\n}\n\n/**\n * Define a prefab — a template for spawning entities with a fixed set of components.\n *\n * @param name Debug name.\n * @param entries Array of [componentDef, data?] tuples.\n */\nexport function definePrefab(\n name: string,\n ...entries: [ComponentDef<unknown>, (unknown | (() => unknown))?][]\n): Prefab {\n const components: PrefabEntry<unknown>[] = entries.map(([def, data]) => ({\n def,\n data,\n }));\n\n return {\n name,\n spawn(world: World): number {\n const entity = world.spawn();\n for (const entry of components) {\n const data =\n typeof entry.data === 'function' ? (entry.data as () => unknown)() : entry.data;\n world.add(entity, entry.def, data);\n }\n return entity;\n },\n };\n}\n","/** A state in the FSM. */\nexport interface State<C = undefined> {\n readonly name: string;\n onEnter?(context: C): void;\n onExit?(context: C): void;\n onUpdate?(dt: number, context: C): void;\n}\n\n/**\n * Lightweight finite state machine. ~100 LOC.\n *\n * Manages named states with onEnter/onExit/onUpdate hooks\n * and string-keyed transitions.\n */\nexport class FSM<C = undefined> {\n private _current: State<C> | undefined;\n private _states = new Map<string, State<C>>();\n private _transitions = new Map<string, Map<string, string>>();\n private _context: C;\n\n constructor(...args: C extends undefined ? [] : [context: C]) {\n this._context = args[0] as C;\n }\n\n /** The currently active state, or undefined if none. */\n get current(): State<C> | undefined {\n return this._current;\n }\n\n /** Register a state. */\n addState(state: State<C>): this {\n this._states.set(state.name, state);\n return this;\n }\n\n /**\n * Register a transition.\n * When `trigger` fires in `fromState`, transition to `toState`.\n */\n addTransition(fromState: string, trigger: string, toState: string): this {\n let map = this._transitions.get(fromState);\n if (!map) {\n map = new Map();\n this._transitions.set(fromState, map);\n }\n map.set(trigger, toState);\n return this;\n }\n\n /** Set the initial state (calls onEnter). */\n start(stateName: string): void {\n const state = this._states.get(stateName);\n if (!state) return;\n this._current = state;\n state.onEnter?.(this._context);\n }\n\n /** Fire a trigger. If a matching transition exists, switch states. */\n trigger(name: string): void {\n if (!this._current) return;\n const transitions = this._transitions.get(this._current.name);\n if (!transitions) return;\n const target = transitions.get(name);\n if (target === undefined) return;\n const next = this._states.get(target);\n if (!next) return;\n this._current.onExit?.(this._context);\n this._current = next;\n next.onEnter?.(this._context);\n }\n\n /** Update the current state. */\n update(dt: number): void {\n this._current?.onUpdate?.(dt, this._context);\n }\n}\n","import type { Vec2 } from '@flare-engine/math';\nimport { defineComponent } from './component.js';\n\n/**\n * Built-in ECS components using @flare-engine/math types.\n */\n\n/** 2D position component. */\nexport const Position = defineComponent<Vec2>('Position', () => ({\n x: 0,\n y: 0,\n}));\n\n/** 2D velocity component. */\nexport const Velocity = defineComponent<Vec2>('Velocity', () => ({\n x: 0,\n y: 0,\n}));\n\n/** Rotation in radians. */\nexport const Rotation = defineComponent<{ angle: number }>('Rotation', () => ({\n angle: 0,\n}));\n\n/** 2D scale component. */\nexport const Scale = defineComponent<Vec2>('Scale', () => ({ x: 1, y: 1 }));\n\n/** Parent entity reference. */\nexport const Parent = defineComponent<{ entity: number }>('Parent', () => ({\n entity: 0,\n}));\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACmBA,IAAI,kBAAkB;AAQf,SAAS,gBAA+B,MAAc,UAAqC;AAChG,QAAM,KAAK;AACX,MAAI,MAAM,IAAI;AACZ,UAAM,IAAI,MAAM,kDAAkD,IAAI,IAAI;AAAA,EAC5E;AACA,SAAO;AAAA,IACL;AAAA,IACA,KAAK,KAAK;AAAA,IACV;AAAA,IACA,QAAQ,aAAa,MAAM;AAAA,EAC7B;AACF;AAMO,SAAS,qBAA2B;AACzC,oBAAkB;AACpB;;;AC9CA,oBAAuB;AAShB,IAAM,QAAN,MAAY;AAAA;AAAA,EAER;AAAA;AAAA,EAEA;AAAA;AAAA,EAGA,gBAAgB,IAAI,qBAAe;AAAA;AAAA,EAEnC,kBAAkB,IAAI,qBAAe;AAAA;AAAA,EAGtC,WAAqB,C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AI;AAC5D,QAAI,CAAC,YAAa;AAClB,UAAM,SAAS,YAAY,IAAI,IAAI;AACnC,QAAI,WAAW,OAAW;AAC1B,UAAM,OAAO,KAAK,QAAQ,IAAI,MAAM;AACpC,QAAI,CAAC,KAAM;AACX,SAAK,SAAS,SAAS,KAAK,QAAQ;AACpC,SAAK,WAAW;AAChB,SAAK,UAAU,KAAK,QAAQ;AAAA,EAC9B;AAAA;AAAA,EAGA,OAAO,IAAkB;AACvB,SAAK,UAAU,WAAW,IAAI,KAAK,QAAQ;AAAA,EAC7C;AACF;;;ACnEO,IAAM,WAAW,gBAAsB,YAAY,OAAO;AAAA,EAC/D,GAAG;AAAA,EACH,GAAG;AACL,EAAE;AAGK,IAAM,WAAW,gBAAsB,YAAY,OAAO;AAAA,EAC/D,GAAG;AAAA,EACH,GAAG;AACL,EAAE;AAGK,IAAM,WAAW,gBAAmC,YAAY,OAAO;AAAA,EAC5E,OAAO;AACT,EAAE;AAGK,IAAM,QAAQ,gBAAsB,SAAS,OAAO,EAAE,GAAG,GAAG,GAAG,EAAE,EAAE;AAGnE,IAAM,SAAS,gBAAoC,UAAU,OAAO;AAAA,EACzE,QAAQ;AACV,EAAE;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/component.ts","../src/query.ts","../src/world.ts","../src/system.ts","../src/prefab.ts","../src/fsm.ts","../src/components.ts","../src/systems.ts"],"sourcesContent":["export { defineComponent, _resetComponentIds } from './component.js';\nexport type { ComponentDef } from './component.js';\n\nexport { World } from './world.js';\n\nexport { Query, QueryBuilder } from './query.js';\n\nexport { defineSystem } from './system.js';\nexport type { SystemFn, SystemDef } from './system.js';\n\nexport { definePrefab } from './prefab.js';\nexport type { Prefab } from './prefab.js';\n\nexport { FSM } from './fsm.js';\nexport type { State } from './fsm.js';\n\nexport { Position, Velocity, Rotation, Scale, Parent, Lifetime, Follower } from './components.js';\n\nexport {\n createMovementSystem,\n createLifetimeSystem,\n createBoundsCullSystem,\n createFollowerSystem,\n createOrphanCullSystem,\n} from './systems.js';\nexport type { CullBounds } from './systems.js';\n","/**\n * Component definition and factory.\n *\n * Components are plain data objects. Each component type gets a unique\n * bit for archetype-based query matching.\n */\n\n/** A unique component definition. */\nexport interface ComponentDef<T> {\n /** Internal unique ID (auto-assigned). */\n readonly id: number;\n /** Bitmask for this component (1 << id). */\n readonly bit: number;\n /** Component name for debugging. */\n readonly name: string;\n /** Create a new instance with default values. */\n create(): T;\n}\n\nlet nextComponentId = 0;\n\n/**\n * Define a new component type.\n *\n * @param name Debug name for the component.\n * @param defaults Factory function returning default values, or undefined for tag components.\n */\nexport function defineComponent<T = undefined>(name: string, defaults?: () => T): ComponentDef<T> {\n const id = nextComponentId++;\n if (id >= 32) {\n throw new Error(`Maximum 32 component types exceeded (defining \"${name}\")`);\n }\n return {\n id,\n bit: 1 << id,\n name,\n create: defaults ?? (() => undefined as T),\n };\n}\n\n/**\n * Reset the component ID counter. Only for testing.\n * @internal\n */\nexport function _resetComponentIds(): void {\n nextComponentId = 0;\n}\n","import { Signal } from '@flare-engine/events';\nimport type { ComponentDef } from './component.js';\n\n/**\n * Query matches entities based on component archetypes.\n *\n * Uses bitmask matching: entity archetype & requiredMask === requiredMask\n * and entity archetype & excludedMask === 0.\n */\nexport class Query {\n /** Bitmask of required components. */\n readonly requiredMask: number;\n /** Bitmask of excluded components. */\n readonly excludedMask: number;\n\n /** Fires when an entity is added to this query's results. */\n readonly onEntityAdded = new Signal<number>();\n /** Fires when an entity is removed from this query's results. */\n readonly onEntityRemoved = new Signal<number>();\n\n /** Sorted array of matching entity IDs. */\n private entities: number[] = [];\n /** Set for O(1) membership check. */\n private entitySet = new Set<number>();\n\n constructor(requiredMask: number, excludedMask: number) {\n this.requiredMask = requiredMask;\n this.excludedMask = excludedMask;\n }\n\n /** Check if an archetype matches this query. */\n matches(archetype: number): boolean {\n return (\n (archetype & this.requiredMask) === this.requiredMask && (archetype & this.excludedMask) === 0\n );\n }\n\n /** @internal — called by World when an entity's archetype changes. */\n _check(entityId: number, archetype: number): void {\n const isMatch = this.matches(archetype);\n const wasMatch = this.entitySet.has(entityId);\n\n if (isMatch && !wasMatch) {\n this.entitySet.add(entityId);\n this.entities.push(entityId);\n this.onEntityAdded.emit(entityId);\n } else if (!isMatch && wasMatch) {\n this.entitySet.delete(entityId);\n const idx = this.entities.indexOf(entityId);\n if (idx !== -1) this.entities.splice(idx, 1);\n this.onEntityRemoved.emit(entityId);\n }\n }\n\n /** @internal — called by World when an entity is removed entirely. */\n _remove(entityId: number): void {\n if (this.entitySet.has(entityId)) {\n this.entitySet.delete(entityId);\n const idx = this.entities.indexOf(entityId);\n if (idx !== -1) this.entities.splice(idx, 1);\n this.onEntityRemoved.emit(entityId);\n }\n }\n\n /** Iterate matching entity IDs. */\n [Symbol.iterator](): IterableIterator<number> {\n return this.entities[Symbol.iterator]();\n }\n\n /** Number of matching entities. */\n get count(): number {\n return this.entities.length;\n }\n\n /** Check if an entity matches this query. */\n has(entityId: number): boolean {\n return this.entitySet.has(entityId);\n }\n}\n\n/** Builder for creating queries with .with() / .without() chaining. */\nexport class QueryBuilder {\n private required = 0;\n private excluded = 0;\n\n with(...components: ComponentDef<unknown>[]): this {\n for (const c of components) {\n this.required |= c.bit;\n }\n return this;\n }\n\n without(...components: ComponentDef<unknown>[]): this {\n for (const c of components) {\n this.excluded |= c.bit;\n }\n return this;\n }\n\n /** Build the query (called internally by World). */\n build(): Query {\n return new Query(this.required, this.excluded);\n }\n}\n","import type { ComponentDef } from './component.js';\nimport { Query, QueryBuilder } from './query.js';\n\n/**\n * World is the central ECS container.\n *\n * Entities are integer IDs. Components are stored in per-component Maps.\n * Archetype bitmasks enable fast query matching.\n */\nexport class World {\n private nextId = 1;\n private archetypes = new Map<number, number>(); // entityId → bitmask\n private componentStores = new Map<number, Map<number, unknown>>(); // componentId → (entityId → data)\n private queries: Query[] = [];\n private systems: {\n fn: (world: World, dt: number) => void;\n priority: number;\n }[] = [];\n private systemsSorted = false;\n\n /** Create a new entity. Returns the entity ID. */\n spawn(): number {\n const id = this.nextId++;\n this.archetypes.set(id, 0);\n return id;\n }\n\n /** Remove an entity and all its components. */\n destroy(entityId: number): void {\n const arch = this.archetypes.get(entityId);\n if (arch === undefined) return;\n\n // Remove from all component stores\n for (const [, store] of this.componentStores) {\n store.delete(entityId);\n }\n\n this.archetypes.delete(entityId);\n\n // Notify queries\n for (const query of this.queries) {\n query._remove(entityId);\n }\n }\n\n /** Add a component to an entity. */\n add<T>(entityId: number, def: ComponentDef<T>, data?: T): void {\n const arch = this.archetypes.get(entityId);\n if (arch === undefined) return;\n\n // Store component data\n let store = this.componentStores.get(def.id);\n if (!store) {\n store = new Map();\n this.componentStores.set(def.id, store);\n }\n store.set(entityId, data !== undefined ? data : def.create());\n\n // Update archetype\n const newArch = arch | def.bit;\n this.archetypes.set(entityId, newArch);\n\n // Notify queries\n for (const query of this.queries) {\n query._check(entityId, newArch);\n }\n }\n\n /** Remove a component from an entity. */\n remove<T>(entityId: number, def: ComponentDef<T>): void {\n const arch = this.archetypes.get(entityId);\n if (arch === undefined) return;\n\n const store = this.componentStores.get(def.id);\n if (store) store.delete(entityId);\n\n const newArch = arch & ~def.bit;\n this.archetypes.set(entityId, newArch);\n\n // Notify queries\n for (const query of this.queries) {\n query._check(entityId, newArch);\n }\n }\n\n /** Get component data for an entity. */\n get<T>(entityId: number, def: ComponentDef<T>): T | undefined {\n const store = this.componentStores.get(def.id);\n return store?.get(entityId) as T | undefined;\n }\n\n /** Check if entity has a component. */\n has(entityId: number, def: ComponentDef<unknown>): boolean {\n const arch = this.archetypes.get(entityId);\n return arch !== undefined && (arch & def.bit) !== 0;\n }\n\n /** Check if entity exists. */\n exists(entityId: number): boolean {\n return this.archetypes.has(entityId);\n }\n\n /**\n * Create a query. Queries auto-update as entities change.\n * Use the QueryBuilder-style chaining:\n * world.query(Position, Velocity)\n * Or use the builder:\n * world.queryBuilder().with(Position).without(Dead).build()\n */\n query(...components: ComponentDef<unknown>[]): Query {\n let mask = 0;\n for (const c of components) {\n mask |= c.bit;\n }\n const q = new Query(mask, 0);\n this.queries.push(q);\n\n // Populate with existing entities\n for (const [entityId, arch] of this.archetypes) {\n q._check(entityId, arch);\n }\n\n return q;\n }\n\n /** Create a QueryBuilder for complex queries (with/without). */\n queryBuilder(): QueryBuilder {\n return new _WorldQueryBuilder(this);\n }\n\n /** Register a system function. Lower priority runs first. */\n addSystem(fn: (world: World, dt: number) => void, priority = 0): void {\n this.systems.push({ fn, priority });\n this.systemsSorted = false;\n }\n\n /** Remove a system. */\n removeSystem(fn: (world: World, dt: number) => void): void {\n const idx = this.systems.findIndex((s) => s.fn === fn);\n if (idx !== -1) this.systems.splice(idx, 1);\n }\n\n /** Run all systems in priority order. */\n step(dt: number): void {\n if (!this.systemsSorted) {\n this.systems.sort((a, b) => a.priority - b.priority);\n this.systemsSorted = true;\n }\n for (const sys of this.systems) {\n sys.fn(this, dt);\n }\n }\n\n /** @internal Register a query for auto-update. */\n _registerQuery(q: Query): void {\n this.queries.push(q);\n // Populate with existing entities\n for (const [entityId, arch] of this.archetypes) {\n q._check(entityId, arch);\n }\n }\n}\n\n/**\n * Internal query builder that auto-registers with a World.\n */\nclass _WorldQueryBuilder extends QueryBuilder {\n private world: World;\n\n constructor(world: World) {\n super();\n this.world = world;\n }\n\n override build(): Query {\n const q = super.build();\n this.world._registerQuery(q);\n return q;\n }\n}\n","import type { Query } from './query.js';\nimport type { World } from './world.js';\n\n/** A system function that processes entities matching a query. */\nexport type SystemFn = (entities: Query, dt: number, world: World) => void;\n\n/** A defined system with its query and function. */\nexport interface SystemDef {\n readonly query: Query;\n readonly fn: SystemFn;\n /** The wrapper registered on the World (used for removal). */\n readonly _worldFn: (world: World, dt: number) => void;\n}\n\n/**\n * Define a system that processes entities matching a query.\n *\n * Returns a SystemDef that can be added to a World via world.addSystem().\n * The system function receives the query's matching entities, dt, and world.\n *\n * Usage:\n * const q = world.query(Position, Velocity);\n * const moveSys = defineSystem(q, (entities, dt, world) => {\n * for (const id of entities) { ... }\n * });\n * world.addSystem(moveSys._worldFn);\n */\nexport function defineSystem(query: Query, fn: SystemFn): SystemDef {\n const worldFn = (world: World, dt: number) => {\n fn(query, dt, world);\n };\n return { query, fn, _worldFn: worldFn };\n}\n","import type { ComponentDef } from './component.js';\nimport type { World } from './world.js';\n\n/** A component entry in a prefab definition. */\ninterface PrefabEntry<T> {\n def: ComponentDef<T>;\n data?: T | (() => T);\n}\n\n/** A prefab factory that spawns entities with pre-defined components. */\nexport interface Prefab {\n readonly name: string;\n /** Spawn an entity with this prefab's components. */\n spawn(world: World, overrides?: Record<string, unknown>): number;\n}\n\n/**\n * Define a prefab — a template for spawning entities with a fixed set of components.\n *\n * @param name Debug name.\n * @param entries Array of [componentDef, data?] tuples.\n */\nexport function definePrefab(\n name: string,\n ...entries: [ComponentDef<unknown>, (unknown | (() => unknown))?][]\n): Prefab {\n const components: PrefabEntry<unknown>[] = entries.map(([def, data]) => ({\n def,\n data,\n }));\n\n return {\n name,\n spawn(world: World): number {\n const entity = world.spawn();\n for (const entry of components) {\n const data =\n typeof entry.data === 'function' ? (entry.data as () => unknown)() : entry.data;\n world.add(entity, entry.def, data);\n }\n return entity;\n },\n };\n}\n","/** A state in the FSM. */\nexport interface State<C = undefined> {\n readonly name: string;\n onEnter?(context: C): void;\n onExit?(context: C): void;\n onUpdate?(dt: number, context: C): void;\n}\n\n/**\n * Lightweight finite state machine. ~100 LOC.\n *\n * Manages named states with onEnter/onExit/onUpdate hooks\n * and string-keyed transitions.\n */\nexport class FSM<C = undefined> {\n private _current: State<C> | undefined;\n private _states = new Map<string, State<C>>();\n private _transitions = new Map<string, Map<string, string>>();\n private _context: C;\n\n constructor(...args: C extends undefined ? [] : [context: C]) {\n this._context = args[0] as C;\n }\n\n /** The currently active state, or undefined if none. */\n get current(): State<C> | undefined {\n return this._current;\n }\n\n /** Register a state. */\n addState(state: State<C>): this {\n this._states.set(state.name, state);\n return this;\n }\n\n /**\n * Register a transition.\n * When `trigger` fires in `fromState`, transition to `toState`.\n */\n addTransition(fromState: string, trigger: string, toState: string): this {\n let map = this._transitions.get(fromState);\n if (!map) {\n map = new Map();\n this._transitions.set(fromState, map);\n }\n map.set(trigger, toState);\n return this;\n }\n\n /** Set the initial state (calls onEnter). */\n start(stateName: string): void {\n const state = this._states.get(stateName);\n if (!state) return;\n this._current = state;\n state.onEnter?.(this._context);\n }\n\n /** Fire a trigger. If a matching transition exists, switch states. */\n trigger(name: string): void {\n if (!this._current) return;\n const transitions = this._transitions.get(this._current.name);\n if (!transitions) return;\n const target = transitions.get(name);\n if (target === undefined) return;\n const next = this._states.get(target);\n if (!next) return;\n this._current.onExit?.(this._context);\n this._current = next;\n next.onEnter?.(this._context);\n }\n\n /** Update the current state. */\n update(dt: number): void {\n this._current?.onUpdate?.(dt, this._context);\n }\n}\n","import type { Vec2 } from '@flare-engine/math';\nimport { defineComponent } from './component.js';\n\n/**\n * Built-in ECS components using @flare-engine/math types.\n */\n\n/** 2D position component. */\nexport const Position = defineComponent<Vec2>('Position', () => ({\n x: 0,\n y: 0,\n}));\n\n/** 2D velocity component. */\nexport const Velocity = defineComponent<Vec2>('Velocity', () => ({\n x: 0,\n y: 0,\n}));\n\n/** Rotation in radians. */\nexport const Rotation = defineComponent<{ angle: number }>('Rotation', () => ({\n angle: 0,\n}));\n\n/** 2D scale component. */\nexport const Scale = defineComponent<Vec2>('Scale', () => ({ x: 1, y: 1 }));\n\n/** Parent entity reference. */\nexport const Parent = defineComponent<{ entity: number }>('Parent', () => ({\n entity: 0,\n}));\n\n/** Countdown timer in seconds; entity expires when remaining reaches 0. */\nexport const Lifetime = defineComponent<{ remaining: number }>('Lifetime', () => ({\n remaining: 0,\n}));\n\n/** Pins an entity's position to a target entity plus a fixed offset. */\nexport const Follower = defineComponent<{ target: number; offsetX: number; offsetY: number }>(\n 'Follower',\n () => ({ target: 0, offsetX: 0, offsetY: 0 }),\n);\n","import { Follower, Lifetime, Position, Velocity } from './components.js';\nimport { defineSystem } from './system.js';\nimport type { SystemDef } from './system.js';\nimport type { World } from './world.js';\n\n/**\n * Plain camera-space bounding box used by createBoundsCullSystem.\n * Keep plain numbers — do NOT import physics AABB/Bounds (layer inversion).\n */\nexport interface CullBounds {\n readonly minX: number;\n readonly minY: number;\n readonly maxX: number;\n readonly maxY: number;\n}\n\n/**\n * createMovementSystem — integrates Position by Velocity * dt each frame.\n *\n * Recommended priority: run BEFORE createFollowerSystem (0).\n */\nexport function createMovementSystem(world: World): SystemDef {\n const q = world.query(Position, Velocity);\n return defineSystem(q, (entities, dt, w) => {\n for (const id of entities) {\n const pos = w.get(id, Position)!;\n const vel = w.get(id, Velocity)!;\n pos.x += vel.x * dt;\n pos.y += vel.y * dt;\n }\n });\n}\n\n/**\n * createLifetimeSystem — decrements Lifetime.remaining each frame.\n * Entities whose remaining reaches <= 0 are collected, then onExpire is called\n * for each AFTER the read loop.\n *\n * Deferred removal: destroying inside a live for…of over query.entities splices\n * the array mid-iteration and would skip entities. Collect first, act after.\n *\n * The scratch array is closure-owned and grow-only — zero steady-state alloc.\n *\n * @param onExpire Destroy / pool policy — ecs never destroys on its own.\n */\nexport function createLifetimeSystem(\n world: World,\n onExpire: (entity: number, world: World) => void,\n): SystemDef {\n const q = world.query(Lifetime);\n const scratch: number[] = [];\n return defineSystem(q, (entities, dt, w) => {\n scratch.length = 0;\n for (const id of entities) {\n const life = w.get(id, Lifetime)!;\n life.remaining -= dt;\n if (life.remaining <= 0) {\n scratch.push(id);\n }\n }\n for (let i = 0; i < scratch.length; i++) {\n onExpire(scratch[i]!, w);\n }\n });\n}\n\n/**\n * createBoundsCullSystem — culls entities whose Position falls outside bounds.\n * Reads bounds LIVE each frame so callers can mutate it to follow a camera.\n * Entities outside are collected, then onCull is called for each after the read loop.\n *\n * Deferred removal: same splice-during-iteration reason as createLifetimeSystem.\n *\n * Recommended priority: run AFTER createMovementSystem and createFollowerSystem.\n *\n * @param bounds Mutable bounding box read each frame.\n * @param onCull Destroy / pool policy — ecs never destroys on its own.\n */\nexport function createBoundsCullSystem(\n world: World,\n bounds: CullBounds,\n onCull: (entity: number, world: World) => void,\n): SystemDef {\n const q = world.query(Position);\n const scratch: number[] = [];\n return defineSystem(q, (entities, _dt, w) => {\n scratch.length = 0;\n for (const id of entities) {\n const pos = w.get(id, Position)!;\n if (\n pos.x < bounds.minX ||\n pos.x > bounds.maxX ||\n pos.y < bounds.minY ||\n pos.y > bounds.maxY\n ) {\n scratch.push(id);\n }\n }\n for (let i = 0; i < scratch.length; i++) {\n onCull(scratch[i]!, w);\n }\n });\n}\n\n/**\n * createFollowerSystem — pins each Follower entity's Position to\n * target.Position + (offsetX, offsetY).\n * If the target is gone or has no Position, the entity is silently skipped.\n *\n * Recommended priority: run AFTER createMovementSystem (1) so the target's\n * position is already integrated before the follower snaps to it.\n */\nexport function createFollowerSystem(world: World): SystemDef {\n const q = world.query(Position, Follower);\n return defineSystem(q, (entities, _dt, w) => {\n for (const id of entities) {\n const follower = w.get(id, Follower)!;\n const t = w.get(follower.target, Position);\n if (t === undefined) continue;\n const pos = w.get(id, Position)!;\n pos.x = t.x + follower.offsetX;\n pos.y = t.y + follower.offsetY;\n }\n });\n}\n\n/**\n * createOrphanCullSystem — fires onOrphan for each Follower whose target entity\n * no longer exists. Does NOT move or destroy anything itself.\n *\n * Split from createFollowerSystem so games that want to orphan-cull can opt in\n * without coupling destruction to the follower pin logic.\n *\n * Recommended priority: run AFTER createFollowerSystem (2) so the follower is\n * pinned before orphans are detected.\n *\n * Deferred removal: same splice-during-iteration reason as createLifetimeSystem.\n *\n * @param onOrphan Called once per orphaned entity after the read loop.\n */\nexport function createOrphanCullSystem(\n world: World,\n onOrphan: (entity: number, world: World) => void,\n): SystemDef {\n const q = world.query(Follower);\n const scratch: number[] = [];\n return defineSystem(q, (entities, _dt, w) => {\n scratch.length = 0;\n for (const id of entities) {\n const follower = w.get(id, Follower)!;\n if (!w.exists(follower.target)) {\n scratch.push(id);\n }\n }\n for (let i = 0; i < scratch.length;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,CAAC,GAAI,CAAC;AAAA,IACzB;AAAA,EACF,CAAC;AACH;","names":[]}
package/dist/index.mjs CHANGED
@@ -331,8 +331,92 @@ var Scale = defineComponent("Scale", () => ({ x: 1, y: 1 }));
331
331
  var Parent = defineComponent("Parent", () => ({
332
332
  entity: 0
333
333
  }));
334
+ var Lifetime = defineComponent("Lifetime", () => ({
335
+ remaining: 0
336
+ }));
337
+ var Follower = defineComponent(
338
+ "Follower",
339
+ () => ({ target: 0, offsetX: 0, offsetY: 0 })
340
+ );
341
+
342
+ // src/systems.ts
343
+ function createMovementSystem(world) {
344
+ const q = world.query(Position, Velocity);
345
+ return defineSystem(q, (entities, dt, w) => {
346
+ for (const id of entities) {
347
+ const pos = w.get(id, Position);
348
+ const vel = w.get(id, Velocity);
349
+ pos.x += vel.x * dt;
350
+ pos.y += vel.y * dt;
351
+ }
352
+ });
353
+ }
354
+ function createLifetimeSystem(world, onExpire) {
355
+ const q = world.query(Lifetime);
356
+ const scratch = [];
357
+ return defineSystem(q, (entities, dt, w) => {
358
+ scratch.length = 0;
359
+ for (const id of entities) {
360
+ const life = w.get(id, Lifetime);
361
+ life.remaining -= dt;
362
+ if (life.remaining <= 0) {
363
+ scratch.push(id);
364
+ }
365
+ }
366
+ for (let i = 0; i < scratch.length; i++) {
367
+ onExpire(scratch[i], w);
368
+ }
369
+ });
370
+ }
371
+ function createBoundsCullSystem(world, bounds, onCull) {
372
+ const q = world.query(Position);
373
+ const scratch = [];
374
+ return defineSystem(q, (entities, _dt, w) => {
375
+ scratch.length = 0;
376
+ for (const id of entities) {
377
+ const pos = w.get(id, Position);
378
+ if (pos.x < bounds.minX || pos.x > bounds.maxX || pos.y < bounds.minY || pos.y > bounds.maxY) {
379
+ scratch.push(id);
380
+ }
381
+ }
382
+ for (let i = 0; i < scratch.length; i++) {
383
+ onCull(scratch[i], w);
384
+ }
385
+ });
386
+ }
387
+ function createFollowerSystem(world) {
388
+ const q = world.query(Position, Follower);
389
+ return defineSystem(q, (entities, _dt, w) => {
390
+ for (const id of entities) {
391
+ const follower = w.get(id, Follower);
392
+ const t = w.get(follower.target, Position);
393
+ if (t === void 0) continue;
394
+ const pos = w.get(id, Position);
395
+ pos.x = t.x + follower.offsetX;
396
+ pos.y = t.y + follower.offsetY;
397
+ }
398
+ });
399
+ }
400
+ function createOrphanCullSystem(world, onOrphan) {
401
+ const q = world.query(Follower);
402
+ const scratch = [];
403
+ return defineSystem(q, (entities, _dt, w) => {
404
+ scratch.length = 0;
405
+ for (const id of entities) {
406
+ const follower = w.get(id, Follower);
407
+ if (!w.exists(follower.target)) {
408
+ scratch.push(id);
409
+ }
410
+ }
411
+ for (let i = 0; i < scratch.length; i++) {
412
+ onOrphan(scratch[i], w);
413
+ }
414
+ });
415
+ }
334
416
  export {
335
417
  FSM,
418
+ Follower,
419
+ Lifetime,
336
420
  Parent,
337
421
  Position,
338
422
  Query,
@@ -342,6 +426,11 @@ export {
342
426
  Velocity,
343
427
  World,
344
428
  _resetComponentIds,
429
+ createBoundsCullSystem,
430
+ createFollowerSystem,
431
+ createLifetimeSystem,
432
+ createMovementSystem,
433
+ createOrphanCullSystem,
345
434
  defineComponent,
346
435
  definePrefab,
347
436
  defineSystem
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/component.ts","../src/query.ts","../src/world.ts","../src/system.ts","../src/prefab.ts","../src/fsm.ts","../src/components.ts"],"sourcesContent":["/**\n * Component definition and factory.\n *\n * Components are plain data objects. Each component type gets a unique\n * bit for archetype-based query matching.\n */\n\n/** A unique component definition. */\nexport interface ComponentDef<T> {\n /** Internal unique ID (auto-assigned). */\n readonly id: number;\n /** Bitmask for this component (1 << id). */\n readonly bit: number;\n /** Component name for debugging. */\n readonly name: string;\n /** Create a new instance with default values. */\n create(): T;\n}\n\nlet nextComponentId = 0;\n\n/**\n * Define a new component type.\n *\n * @param name Debug name for the component.\n * @param defaults Factory function returning default values, or undefined for tag components.\n */\nexport function defineComponent<T = undefined>(name: string, defaults?: () => T): ComponentDef<T> {\n const id = nextComponentId++;\n if (id >= 32) {\n throw new Error(`Maximum 32 component types exceeded (defining \"${name}\")`);\n }\n return {\n id,\n bit: 1 << id,\n name,\n create: defaults ?? (() => undefined as T),\n };\n}\n\n/**\n * Reset the component ID counter. Only for testing.\n * @internal\n */\nexport function _resetComponentIds(): void {\n nextComponentId = 0;\n}\n","import { Signal } from '@flare-engine/events';\nimport type { ComponentDef } from './component.js';\n\n/**\n * Query matches entities based on component archetypes.\n *\n * Uses bitmask matching: entity archetype & requiredMask === requiredMask\n * and entity archetype & excludedMask === 0.\n */\nexport class Query {\n /** Bitmask of required components. */\n readonly requiredMask: number;\n /** Bitmask of excluded components. */\n readonly excludedMask: number;\n\n /** Fires when an entity is added to this query's results. */\n readonly onEntityAdded = new Signal<number>();\n /** Fires when an entity is removed from this query's results. */\n readonly onEntityRemoved = new Signal<number>();\n\n /** Sorted array of matching entity IDs. */\n private entities: number[] = [];\n /** Set for O(1) membership check. */\n private entitySet = new Set<number>();\n\n constructor(requiredMask: number, excludedMask: number) {\n this.requiredMask = requiredMask;\n this.excludedMask = excludedMask;\n }\n\n /** Check if an archetype matches this query. */\n matches(archetype: number): boolean {\n return (\n (archetype & this.requiredMask) === this.requiredMask && (archetype & this.excludedMask) === 0\n );\n }\n\n /** @internal — called by World when an entity's archetype changes. */\n _check(entityId: number, archetype: number): void {\n const isMatch = this.matches(archetype);\n const wasMatch = this.entitySet.has(entityId);\n\n if (isMatch && !wasMatch) {\n this.entitySet.add(entityId);\n this.entities.push(entityId);\n this.onEntityAdded.emit(entityId);\n } else if (!isMatch && wasMatch) {\n this.entitySet.delete(entityId);\n const idx = this.entities.indexOf(entityId);\n if (idx !== -1) this.entities.splice(idx, 1);\n this.onEntityRemoved.emit(entityId);\n }\n }\n\n /** @internal — called by World when an entity is removed entirely. */\n _remove(entityId: number): void {\n if (this.entitySet.has(entityId)) {\n this.entitySet.delete(entityId);\n const idx = this.entities.indexOf(entityId);\n if (idx !== -1) this.entities.splice(idx, 1);\n this.onEntityRemoved.emit(entityId);\n }\n }\n\n /** Iterate matching entity IDs. */\n [Symbol.iterator](): IterableIterator<number> {\n return this.entities[Symbol.iterator]();\n }\n\n /** Number of matching entities. */\n get count(): number {\n return this.entities.length;\n }\n\n /** Check if an entity matches this query. */\n has(entityId: number): boolean {\n return this.entitySet.has(entityId);\n }\n}\n\n/** Builder for creating queries with .with() / .without() chaining. */\nexport class QueryBuilder {\n private required = 0;\n private excluded = 0;\n\n with(...components: ComponentDef<unknown>[]): this {\n for (const c of components) {\n this.required |= c.bit;\n }\n return this;\n }\n\n without(...components: ComponentDef<unknown>[]): this {\n for (const c of components) {\n this.excluded |= c.bit;\n }\n return this;\n }\n\n /** Build the query (called internally by World). */\n build(): Query {\n return new Query(this.required, this.excluded);\n }\n}\n","import type { ComponentDef } from './component.js';\nimport { Query, QueryBuilder } from './query.js';\n\n/**\n * World is the central ECS container.\n *\n * Entities are integer IDs. Components are stored in per-component Maps.\n * Archetype bitmasks enable fast query matching.\n */\nexport class World {\n private nextId = 1;\n private archetypes = new Map<number, number>(); // entityId → bitmask\n private componentStores = new Map<number, Map<number, unknown>>(); // componentId → (entityId → data)\n private queries: Query[] = [];\n private systems: {\n fn: (world: World, dt: number) => void;\n priority: number;\n }[] = [];\n private systemsSorted = false;\n\n /** Create a new entity. Returns the entity ID. */\n spawn(): number {\n const id = this.nextId++;\n this.archetypes.set(id, 0);\n return id;\n }\n\n /** Remove an entity and all its components. */\n destroy(entityId: number): void {\n const arch = this.archetypes.get(entityId);\n if (arch === undefined) return;\n\n // Remove from all component stores\n for (const [, store] of this.componentStores) {\n store.delete(entityId);\n }\n\n this.archetypes.delete(entityId);\n\n // Notify queries\n for (const query of this.queries) {\n query._remove(entityId);\n }\n }\n\n /** Add a component to an entity. */\n add<T>(entityId: number, def: ComponentDef<T>, data?: T): void {\n const arch = this.archetypes.get(entityId);\n if (arch === undefined) return;\n\n // Store component data\n let store = this.componentStores.get(def.id);\n if (!store) {\n store = new Map();\n this.componentStores.set(def.id, store);\n }\n store.set(entityId, data !== undefined ? data : def.create());\n\n // Update archetype\n const newArch = arch | def.bit;\n this.archetypes.set(entityId, newArch);\n\n // Notify queries\n for (const query of this.queries) {\n query._check(entityId, newArch);\n }\n }\n\n /** Remove a component from an entity. */\n remove<T>(entityId: number, def: ComponentDef<T>): void {\n const arch = this.archetypes.get(entityId);\n if (arch === undefined) return;\n\n const store = this.componentStores.get(def.id);\n if (store) store.delete(entityId);\n\n const newArch = arch & ~def.bit;\n this.archetypes.set(entityId, newArch);\n\n // Notify queries\n for (const query of this.queries) {\n query._check(entityId, newArch);\n }\n }\n\n /** Get component data for an entity. */\n get<T>(entityId: number, def: ComponentDef<T>): T | undefined {\n const store = this.componentStores.get(def.id);\n return store?.get(entityId) as T | undefined;\n }\n\n /** Check if entity has a component. */\n has(entityId: number, def: ComponentDef<unknown>): boolean {\n const arch = this.archetypes.get(entityId);\n return arch !== undefined && (arch & def.bit) !== 0;\n }\n\n /** Check if entity exists. */\n exists(entityId: number): boolean {\n return this.archetypes.has(entityId);\n }\n\n /**\n * Create a query. Queries auto-update as entities change.\n * Use the QueryBuilder-style chaining:\n * world.query(Position, Velocity)\n * Or use the builder:\n * world.queryBuilder().with(Position).without(Dead).build()\n */\n query(...components: ComponentDef<unknown>[]): Query {\n let mask = 0;\n for (const c of components) {\n mask |= c.bit;\n }\n const q = new Query(mask, 0);\n this.queries.push(q);\n\n // Populate with existing entities\n for (const [entityId, arch] of this.archetypes) {\n q._check(entityId, arch);\n }\n\n return q;\n }\n\n /** Create a QueryBuilder for complex queries (with/without). */\n queryBuilder(): QueryBuilder {\n return new _WorldQueryBuilder(this);\n }\n\n /** Register a system function. Lower priority runs first. */\n addSystem(fn: (world: World, dt: number) => void, priority = 0): void {\n this.systems.push({ fn, priority });\n this.systemsSorted = false;\n }\n\n /** Remove a system. */\n removeSystem(fn: (world: World, dt: number) => void): void {\n const idx = this.systems.findIndex((s) => s.fn === fn);\n if (idx !== -1) this.systems.splice(idx, 1);\n }\n\n /** Run all systems in priority order. */\n step(dt: number): void {\n if (!this.systemsSorted) {\n this.systems.sort((a, b) => a.priority - b.priority);\n this.systemsSorted = true;\n }\n for (const sys of this.systems) {\n sys.fn(this, dt);\n }\n }\n\n /** @internal Register a query for auto-update. */\n _registerQuery(q: Query): void {\n this.queries.push(q);\n // Populate with existing entities\n for (const [entityId, arch] of this.archetypes) {\n q._check(entityId, arch);\n }\n }\n}\n\n/**\n * Internal query builder that auto-registers with a World.\n */\nclass _WorldQueryBuilder extends QueryBuilder {\n private world: World;\n\n constructor(world: World) {\n super();\n this.world = world;\n }\n\n override build(): Query {\n const q = super.build();\n this.world._registerQuery(q);\n return q;\n }\n}\n","import type { Query } from './query.js';\nimport type { World } from './world.js';\n\n/** A system function that processes entities matching a query. */\nexport type SystemFn = (entities: Query, dt: number, world: World) => void;\n\n/** A defined system with its query and function. */\nexport interface SystemDef {\n readonly query: Query;\n readonly fn: SystemFn;\n /** The wrapper registered on the World (used for removal). */\n readonly _worldFn: (world: World, dt: number) => void;\n}\n\n/**\n * Define a system that processes entities matching a query.\n *\n * Returns a SystemDef that can be added to a World via world.addSystem().\n * The system function receives the query's matching entities, dt, and world.\n *\n * Usage:\n * const q = world.query(Position, Velocity);\n * const moveSys = defineSystem(q, (entities, dt, world) => {\n * for (const id of entities) { ... }\n * });\n * world.addSystem(moveSys._worldFn);\n */\nexport function defineSystem(query: Query, fn: SystemFn): SystemDef {\n const worldFn = (world: World, dt: number) => {\n fn(query, dt, world);\n };\n return { query, fn, _worldFn: worldFn };\n}\n","import type { ComponentDef } from './component.js';\nimport type { World } from './world.js';\n\n/** A component entry in a prefab definition. */\ninterface PrefabEntry<T> {\n def: ComponentDef<T>;\n data?: T | (() => T);\n}\n\n/** A prefab factory that spawns entities with pre-defined components. */\nexport interface Prefab {\n readonly name: string;\n /** Spawn an entity with this prefab's components. */\n spawn(world: World, overrides?: Record<string, unknown>): number;\n}\n\n/**\n * Define a prefab — a template for spawning entities with a fixed set of components.\n *\n * @param name Debug name.\n * @param entries Array of [componentDef, data?] tuples.\n */\nexport function definePrefab(\n name: string,\n ...entries: [ComponentDef<unknown>, (unknown | (() => unknown))?][]\n): Prefab {\n const components: PrefabEntry<unknown>[] = entries.map(([def, data]) => ({\n def,\n data,\n }));\n\n return {\n name,\n spawn(world: World): number {\n const entity = world.spawn();\n for (const entry of components) {\n const data =\n typeof entry.data === 'function' ? (entry.data as () => unknown)() : entry.data;\n world.add(entity, entry.def, data);\n }\n return entity;\n },\n };\n}\n","/** A state in the FSM. */\nexport interface State<C = undefined> {\n readonly name: string;\n onEnter?(context: C): void;\n onExit?(context: C): void;\n onUpdate?(dt: number, context: C): void;\n}\n\n/**\n * Lightweight finite state machine. ~100 LOC.\n *\n * Manages named states with onEnter/onExit/onUpdate hooks\n * and string-keyed transitions.\n */\nexport class FSM<C = undefined> {\n private _current: State<C> | undefined;\n private _states = new Map<string, State<C>>();\n private _transitions = new Map<string, Map<string, string>>();\n private _context: C;\n\n constructor(...args: C extends undefined ? [] : [context: C]) {\n this._context = args[0] as C;\n }\n\n /** The currently active state, or undefined if none. */\n get current(): State<C> | undefined {\n return this._current;\n }\n\n /** Register a state. */\n addState(state: State<C>): this {\n this._states.set(state.name, state);\n return this;\n }\n\n /**\n * Register a transition.\n * When `trigger` fires in `fromState`, transition to `toState`.\n */\n addTransition(fromState: string, trigger: string, toState: string): this {\n let map = this._transitions.get(fromState);\n if (!map) {\n map = new Map();\n this._transitions.set(fromState, map);\n }\n map.set(trigger, toState);\n return this;\n }\n\n /** Set the initial state (calls onEnter). */\n start(stateName: string): void {\n const state = this._states.get(stateName);\n if (!state) return;\n this._current = state;\n state.onEnter?.(this._context);\n }\n\n /** Fire a trigger. If a matching transition exists, switch states. */\n trigger(name: string): void {\n if (!this._current) return;\n const transitions = this._transitions.get(this._current.name);\n if (!transitions) return;\n const target = transitions.get(name);\n if (target === undefined) return;\n const next = this._states.get(target);\n if (!next) return;\n this._current.onExit?.(this._context);\n this._current = next;\n next.onEnter?.(this._context);\n }\n\n /** Update the current state. */\n update(dt: number): void {\n this._current?.onUpdate?.(dt, this._context);\n }\n}\n","import type { Vec2 } from '@flare-engine/math';\nimport { defineComponent } from './component.js';\n\n/**\n * Built-in ECS components using @flare-engine/math types.\n */\n\n/** 2D position component. */\nexport const Position = defineComponent<Vec2>('Position', () => ({\n x: 0,\n y: 0,\n}));\n\n/** 2D velocity component. */\nexport const Velocity = defineComponent<Vec2>('Velocity', () => ({\n x: 0,\n y: 0,\n}));\n\n/** Rotation in radians. */\nexport const Rotation = defineComponent<{ angle: number }>('Rotation', () => ({\n angle: 0,\n}));\n\n/** 2D scale component. */\nexport const Scale = defineComponent<Vec2>('Scale', () => ({ x: 1, y: 1 }));\n\n/** Parent entity reference. */\nexport const Parent = defineComponent<{ entity: number }>('Parent', () => ({\n entity: 0,\n}));\n"],"mappings":";AAmBA,IAAI,kBAAkB;AAQf,SAAS,gBAA+B,MAAc,UAAqC;AAChG,QAAM,KAAK;AACX,MAAI,MAAM,IAAI;AACZ,UAAM,IAAI,MAAM,kDAAkD,IAAI,IAAI;AAAA,EAC5E;AACA,SAAO;AAAA,IACL;AAAA,IACA,KAAK,KAAK;AAAA,IACV;AAAA,IACA,QAAQ,aAAa,MAAM;AAAA,EAC7B;AACF;AAMO,SAAS,qBAA2B;AACzC,oBAAkB;AACpB;;;AC9CA,SAAS,cAAc;AAShB,IAAM,QAAN,MAAY;AAAA;AAAA,EAER;AAAA;AAAA,EAEA;AAAA;AAAA,EAGA,gBAAgB,IAAI,OAAe;AAAA;AAAA,EAEnC,kBAAkB,IAAI,OAAe;AAAA;AAAA,EAGtC,WAAqB,CAAC;AAAA;AAAA,EAEtB,YAAY,oBAAI,IAAY;AAAA,EAEpC,YAAY,cAAsB,cAAsB;AACtD,SAAK,eAAe;AACpB,SAAK,eAAe;AAAA,EACtB;AAAA;AAAA,EAGA,QAAQ,WAA4B;AAClC,YACG,YAAY,KAAK,kBAAkB,KAAK,i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pC,SAAK,WAAW;AAChB,SAAK,UAAU,KAAK,QAAQ;AAAA,EAC9B;AAAA;AAAA,EAGA,OAAO,IAAkB;AACvB,SAAK,UAAU,WAAW,IAAI,KAAK,QAAQ;AAAA,EAC7C;AACF;;;ACnEO,IAAM,WAAW,gBAAsB,YAAY,OAAO;AAAA,EAC/D,GAAG;AAAA,EACH,GAAG;AACL,EAAE;AAGK,IAAM,WAAW,gBAAsB,YAAY,OAAO;AAAA,EAC/D,GAAG;AAAA,EACH,GAAG;AACL,EAAE;AAGK,IAAM,WAAW,gBAAmC,YAAY,OAAO;AAAA,EAC5E,OAAO;AACT,EAAE;AAGK,IAAM,QAAQ,gBAAsB,SAAS,OAAO,EAAE,GAAG,GAAG,GAAG,EAAE,EAAE;AAGnE,IAAM,SAAS,gBAAoC,UAAU,OAAO;AAAA,EACzE,QAAQ;AACV,EAAE;","names":[]}
1
+ {"version":3,"sources":["../src/component.ts","../src/query.ts","../src/world.ts","../src/system.ts","../src/prefab.ts","../src/fsm.ts","../src/components.ts","../src/systems.ts"],"sourcesContent":["/**\n * Component definition and factory.\n *\n * Components are plain data objects. Each component type gets a unique\n * bit for archetype-based query matching.\n */\n\n/** A unique component definition. */\nexport interface ComponentDef<T> {\n /** Internal unique ID (auto-assigned). */\n readonly id: number;\n /** Bitmask for this component (1 << id). */\n readonly bit: number;\n /** Component name for debugging. */\n readonly name: string;\n /** Create a new instance with default values. */\n create(): T;\n}\n\nlet nextComponentId = 0;\n\n/**\n * Define a new component type.\n *\n * @param name Debug name for the component.\n * @param defaults Factory function returning default values, or undefined for tag components.\n */\nexport function defineComponent<T = undefined>(name: string, defaults?: () => T): ComponentDef<T> {\n const id = nextComponentId++;\n if (id >= 32) {\n throw new Error(`Maximum 32 component types exceeded (defining \"${name}\")`);\n }\n return {\n id,\n bit: 1 << id,\n name,\n create: defaults ?? (() => undefined as T),\n };\n}\n\n/**\n * Reset the component ID counter. Only for testing.\n * @internal\n */\nexport function _resetComponentIds(): void {\n nextComponentId = 0;\n}\n","import { Signal } from '@flare-engine/events';\nimport type { ComponentDef } from './component.js';\n\n/**\n * Query matches entities based on component archetypes.\n *\n * Uses bitmask matching: entity archetype & requiredMask === requiredMask\n * and entity archetype & excludedMask === 0.\n */\nexport class Query {\n /** Bitmask of required components. */\n readonly requiredMask: number;\n /** Bitmask of excluded components. */\n readonly excludedMask: number;\n\n /** Fires when an entity is added to this query's results. */\n readonly onEntityAdded = new Signal<number>();\n /** Fires when an entity is removed from this query's results. */\n readonly onEntityRemoved = new Signal<number>();\n\n /** Sorted array of matching entity IDs. */\n private entities: number[] = [];\n /** Set for O(1) membership check. */\n private entitySet = new Set<number>();\n\n constructor(requiredMask: number, excludedMask: number) {\n this.requiredMask = requiredMask;\n this.excludedMask = excludedMask;\n }\n\n /** Check if an archetype matches this query. */\n matches(archetype: number): boolean {\n return (\n (archetype & this.requiredMask) === this.requiredMask && (archetype & this.excludedMask) === 0\n );\n }\n\n /** @internal — called by World when an entity's archetype changes. */\n _check(entityId: number, archetype: number): void {\n const isMatch = this.matches(archetype);\n const wasMatch = this.entitySet.has(entityId);\n\n if (isMatch && !wasMatch) {\n this.entitySet.add(entityId);\n this.entities.push(entityId);\n this.onEntityAdded.emit(entityId);\n } else if (!isMatch && wasMatch) {\n this.entitySet.delete(entityId);\n const idx = this.entities.indexOf(entityId);\n if (idx !== -1) this.entities.splice(idx, 1);\n this.onEntityRemoved.emit(entityId);\n }\n }\n\n /** @internal — called by World when an entity is removed entirely. */\n _remove(entityId: number): void {\n if (this.entitySet.has(entityId)) {\n this.entitySet.delete(entityId);\n const idx = this.entities.indexOf(entityId);\n if (idx !== -1) this.entities.splice(idx, 1);\n this.onEntityRemoved.emit(entityId);\n }\n }\n\n /** Iterate matching entity IDs. */\n [Symbol.iterator](): IterableIterator<number> {\n return this.entities[Symbol.iterator]();\n }\n\n /** Number of matching entities. */\n get count(): number {\n return this.entities.length;\n }\n\n /** Check if an entity matches this query. */\n has(entityId: number): boolean {\n return this.entitySet.has(entityId);\n }\n}\n\n/** Builder for creating queries with .with() / .without() chaining. */\nexport class QueryBuilder {\n private required = 0;\n private excluded = 0;\n\n with(...components: ComponentDef<unknown>[]): this {\n for (const c of components) {\n this.required |= c.bit;\n }\n return this;\n }\n\n without(...components: ComponentDef<unknown>[]): this {\n for (const c of components) {\n this.excluded |= c.bit;\n }\n return this;\n }\n\n /** Build the query (called internally by World). */\n build(): Query {\n return new Query(this.required, this.excluded);\n }\n}\n","import type { ComponentDef } from './component.js';\nimport { Query, QueryBuilder } from './query.js';\n\n/**\n * World is the central ECS container.\n *\n * Entities are integer IDs. Components are stored in per-component Maps.\n * Archetype bitmasks enable fast query matching.\n */\nexport class World {\n private nextId = 1;\n private archetypes = new Map<number, number>(); // entityId → bitmask\n private componentStores = new Map<number, Map<number, unknown>>(); // componentId → (entityId → data)\n private queries: Query[] = [];\n private systems: {\n fn: (world: World, dt: number) => void;\n priority: number;\n }[] = [];\n private systemsSorted = false;\n\n /** Create a new entity. Returns the entity ID. */\n spawn(): number {\n const id = this.nextId++;\n this.archetypes.set(id, 0);\n return id;\n }\n\n /** Remove an entity and all its components. */\n destroy(entityId: number): void {\n const arch = this.archetypes.get(entityId);\n if (arch === undefined) return;\n\n // Remove from all component stores\n for (const [, store] of this.componentStores) {\n store.delete(entityId);\n }\n\n this.archetypes.delete(entityId);\n\n // Notify queries\n for (const query of this.queries) {\n query._remove(entityId);\n }\n }\n\n /** Add a component to an entity. */\n add<T>(entityId: number, def: ComponentDef<T>, data?: T): void {\n const arch = this.archetypes.get(entityId);\n if (arch === undefined) return;\n\n // Store component data\n let store = this.componentStores.get(def.id);\n if (!store) {\n store = new Map();\n this.componentStores.set(def.id, store);\n }\n store.set(entityId, data !== undefined ? data : def.create());\n\n // Update archetype\n const newArch = arch | def.bit;\n this.archetypes.set(entityId, newArch);\n\n // Notify queries\n for (const query of this.queries) {\n query._check(entityId, newArch);\n }\n }\n\n /** Remove a component from an entity. */\n remove<T>(entityId: number, def: ComponentDef<T>): void {\n const arch = this.archetypes.get(entityId);\n if (arch === undefined) return;\n\n const store = this.componentStores.get(def.id);\n if (store) store.delete(entityId);\n\n const newArch = arch & ~def.bit;\n this.archetypes.set(entityId, newArch);\n\n // Notify queries\n for (const query of this.queries) {\n query._check(entityId, newArch);\n }\n }\n\n /** Get component data for an entity. */\n get<T>(entityId: number, def: ComponentDef<T>): T | undefined {\n const store = this.componentStores.get(def.id);\n return store?.get(entityId) as T | undefined;\n }\n\n /** Check if entity has a component. */\n has(entityId: number, def: ComponentDef<unknown>): boolean {\n const arch = this.archetypes.get(entityId);\n return arch !== undefined && (arch & def.bit) !== 0;\n }\n\n /** Check if entity exists. */\n exists(entityId: number): boolean {\n return this.archetypes.has(entityId);\n }\n\n /**\n * Create a query. Queries auto-update as entities change.\n * Use the QueryBuilder-style chaining:\n * world.query(Position, Velocity)\n * Or use the builder:\n * world.queryBuilder().with(Position).without(Dead).build()\n */\n query(...components: ComponentDef<unknown>[]): Query {\n let mask = 0;\n for (const c of components) {\n mask |= c.bit;\n }\n const q = new Query(mask, 0);\n this.queries.push(q);\n\n // Populate with existing entities\n for (const [entityId, arch] of this.archetypes) {\n q._check(entityId, arch);\n }\n\n return q;\n }\n\n /** Create a QueryBuilder for complex queries (with/without). */\n queryBuilder(): QueryBuilder {\n return new _WorldQueryBuilder(this);\n }\n\n /** Register a system function. Lower priority runs first. */\n addSystem(fn: (world: World, dt: number) => void, priority = 0): void {\n this.systems.push({ fn, priority });\n this.systemsSorted = false;\n }\n\n /** Remove a system. */\n removeSystem(fn: (world: World, dt: number) => void): void {\n const idx = this.systems.findIndex((s) => s.fn === fn);\n if (idx !== -1) this.systems.splice(idx, 1);\n }\n\n /** Run all systems in priority order. */\n step(dt: number): void {\n if (!this.systemsSorted) {\n this.systems.sort((a, b) => a.priority - b.priority);\n this.systemsSorted = true;\n }\n for (const sys of this.systems) {\n sys.fn(this, dt);\n }\n }\n\n /** @internal Register a query for auto-update. */\n _registerQuery(q: Query): void {\n this.queries.push(q);\n // Populate with existing entities\n for (const [entityId, arch] of this.archetypes) {\n q._check(entityId, arch);\n }\n }\n}\n\n/**\n * Internal query builder that auto-registers with a World.\n */\nclass _WorldQueryBuilder extends QueryBuilder {\n private world: World;\n\n constructor(world: World) {\n super();\n this.world = world;\n }\n\n override build(): Query {\n const q = super.build();\n this.world._registerQuery(q);\n return q;\n }\n}\n","import type { Query } from './query.js';\nimport type { World } from './world.js';\n\n/** A system function that processes entities matching a query. */\nexport type SystemFn = (entities: Query, dt: number, world: World) => void;\n\n/** A defined system with its query and function. */\nexport interface SystemDef {\n readonly query: Query;\n readonly fn: SystemFn;\n /** The wrapper registered on the World (used for removal). */\n readonly _worldFn: (world: World, dt: number) => void;\n}\n\n/**\n * Define a system that processes entities matching a query.\n *\n * Returns a SystemDef that can be added to a World via world.addSystem().\n * The system function receives the query's matching entities, dt, and world.\n *\n * Usage:\n * const q = world.query(Position, Velocity);\n * const moveSys = defineSystem(q, (entities, dt, world) => {\n * for (const id of entities) { ... }\n * });\n * world.addSystem(moveSys._worldFn);\n */\nexport function defineSystem(query: Query, fn: SystemFn): SystemDef {\n const worldFn = (world: World, dt: number) => {\n fn(query, dt, world);\n };\n return { query, fn, _worldFn: worldFn };\n}\n","import type { ComponentDef } from './component.js';\nimport type { World } from './world.js';\n\n/** A component entry in a prefab definition. */\ninterface PrefabEntry<T> {\n def: ComponentDef<T>;\n data?: T | (() => T);\n}\n\n/** A prefab factory that spawns entities with pre-defined components. */\nexport interface Prefab {\n readonly name: string;\n /** Spawn an entity with this prefab's components. */\n spawn(world: World, overrides?: Record<string, unknown>): number;\n}\n\n/**\n * Define a prefab — a template for spawning entities with a fixed set of components.\n *\n * @param name Debug name.\n * @param entries Array of [componentDef, data?] tuples.\n */\nexport function definePrefab(\n name: string,\n ...entries: [ComponentDef<unknown>, (unknown | (() => unknown))?][]\n): Prefab {\n const components: PrefabEntry<unknown>[] = entries.map(([def, data]) => ({\n def,\n data,\n }));\n\n return {\n name,\n spawn(world: World): number {\n const entity = world.spawn();\n for (const entry of components) {\n const data =\n typeof entry.data === 'function' ? (entry.data as () => unknown)() : entry.data;\n world.add(entity, entry.def, data);\n }\n return entity;\n },\n };\n}\n","/** A state in the FSM. */\nexport interface State<C = undefined> {\n readonly name: string;\n onEnter?(context: C): void;\n onExit?(context: C): void;\n onUpdate?(dt: number, context: C): void;\n}\n\n/**\n * Lightweight finite state machine. ~100 LOC.\n *\n * Manages named states with onEnter/onExit/onUpdate hooks\n * and string-keyed transitions.\n */\nexport class FSM<C = undefined> {\n private _current: State<C> | undefined;\n private _states = new Map<string, State<C>>();\n private _transitions = new Map<string, Map<string, string>>();\n private _context: C;\n\n constructor(...args: C extends undefined ? [] : [context: C]) {\n this._context = args[0] as C;\n }\n\n /** The currently active state, or undefined if none. */\n get current(): State<C> | undefined {\n return this._current;\n }\n\n /** Register a state. */\n addState(state: State<C>): this {\n this._states.set(state.name, state);\n return this;\n }\n\n /**\n * Register a transition.\n * When `trigger` fires in `fromState`, transition to `toState`.\n */\n addTransition(fromState: string, trigger: string, toState: string): this {\n let map = this._transitions.get(fromState);\n if (!map) {\n map = new Map();\n this._transitions.set(fromState, map);\n }\n map.set(trigger, toState);\n return this;\n }\n\n /** Set the initial state (calls onEnter). */\n start(stateName: string): void {\n const state = this._states.get(stateName);\n if (!state) return;\n this._current = state;\n state.onEnter?.(this._context);\n }\n\n /** Fire a trigger. If a matching transition exists, switch states. */\n trigger(name: string): void {\n if (!this._current) return;\n const transitions = this._transitions.get(this._current.name);\n if (!transitions) return;\n const target = transitions.get(name);\n if (target === undefined) return;\n const next = this._states.get(target);\n if (!next) return;\n this._current.onExit?.(this._context);\n this._current = next;\n next.onEnter?.(this._context);\n }\n\n /** Update the current state. */\n update(dt: number): void {\n this._current?.onUpdate?.(dt, this._context);\n }\n}\n","import type { Vec2 } from '@flare-engine/math';\nimport { defineComponent } from './component.js';\n\n/**\n * Built-in ECS components using @flare-engine/math types.\n */\n\n/** 2D position component. */\nexport const Position = defineComponent<Vec2>('Position', () => ({\n x: 0,\n y: 0,\n}));\n\n/** 2D velocity component. */\nexport const Velocity = defineComponent<Vec2>('Velocity', () => ({\n x: 0,\n y: 0,\n}));\n\n/** Rotation in radians. */\nexport const Rotation = defineComponent<{ angle: number }>('Rotation', () => ({\n angle: 0,\n}));\n\n/** 2D scale component. */\nexport const Scale = defineComponent<Vec2>('Scale', () => ({ x: 1, y: 1 }));\n\n/** Parent entity reference. */\nexport const Parent = defineComponent<{ entity: number }>('Parent', () => ({\n entity: 0,\n}));\n\n/** Countdown timer in seconds; entity expires when remaining reaches 0. */\nexport const Lifetime = defineComponent<{ remaining: number }>('Lifetime', () => ({\n remaining: 0,\n}));\n\n/** Pins an entity's position to a target entity plus a fixed offset. */\nexport const Follower = defineComponent<{ target: number; offsetX: number; offsetY: number }>(\n 'Follower',\n () => ({ target: 0, offsetX: 0, offsetY: 0 }),\n);\n","import { Follower, Lifetime, Position, Velocity } from './components.js';\nimport { defineSystem } from './system.js';\nimport type { SystemDef } from './system.js';\nimport type { World } from './world.js';\n\n/**\n * Plain camera-space bounding box used by createBoundsCullSystem.\n * Keep plain numbers — do NOT import physics AABB/Bounds (layer inversion).\n */\nexport interface CullBounds {\n readonly minX: number;\n readonly minY: number;\n readonly maxX: number;\n readonly maxY: number;\n}\n\n/**\n * createMovementSystem — integrates Position by Velocity * dt each frame.\n *\n * Recommended priority: run BEFORE createFollowerSystem (0).\n */\nexport function createMovementSystem(world: World): SystemDef {\n const q = world.query(Position, Velocity);\n return defineSystem(q, (entities, dt, w) => {\n for (const id of entities) {\n const pos = w.get(id, Position)!;\n const vel = w.get(id, Velocity)!;\n pos.x += vel.x * dt;\n pos.y += vel.y * dt;\n }\n });\n}\n\n/**\n * createLifetimeSystem — decrements Lifetime.remaining each frame.\n * Entities whose remaining reaches <= 0 are collected, then onExpire is called\n * for each AFTER the read loop.\n *\n * Deferred removal: destroying inside a live for…of over query.entities splices\n * the array mid-iteration and would skip entities. Collect first, act after.\n *\n * The scratch array is closure-owned and grow-only — zero steady-state alloc.\n *\n * @param onExpire Destroy / pool policy — ecs never destroys on its own.\n */\nexport function createLifetimeSystem(\n world: World,\n onExpire: (entity: number, world: World) => void,\n): SystemDef {\n const q = world.query(Lifetime);\n const scratch: number[] = [];\n return defineSystem(q, (entities, dt, w) => {\n scratch.length = 0;\n for (const id of entities) {\n const life = w.get(id, Lifetime)!;\n life.remaining -= dt;\n if (life.remaining <= 0) {\n scratch.push(id);\n }\n }\n for (let i = 0; i < scratch.length; i++) {\n onExpire(scratch[i]!, w);\n }\n });\n}\n\n/**\n * createBoundsCullSystem — culls entities whose Position falls outside bounds.\n * Reads bounds LIVE each frame so callers can mutate it to follow a camera.\n * Entities outside are collected, then onCull is called for each after the read loop.\n *\n * Deferred removal: same splice-during-iteration reason as createLifetimeSystem.\n *\n * Recommended priority: run AFTER createMovementSystem and createFollowerSystem.\n *\n * @param bounds Mutable bounding box read each frame.\n * @param onCull Destroy / pool policy — ecs never destroys on its own.\n */\nexport function createBoundsCullSystem(\n world: World,\n bounds: CullBounds,\n onCull: (entity: number, world: World) => void,\n): SystemDef {\n const q = world.query(Position);\n const scratch: number[] = [];\n return defineSystem(q, (entities, _dt, w) => {\n scratch.length = 0;\n for (const id of entities) {\n const pos = w.get(id, Position)!;\n if (\n pos.x < bounds.minX ||\n pos.x > bounds.maxX ||\n pos.y < bounds.minY ||\n pos.y > bounds.maxY\n ) {\n scratch.push(id);\n }\n }\n for (let i = 0; i < scratch.length; i++) {\n onCull(scratch[i]!, w);\n }\n });\n}\n\n/**\n * createFollowerSystem — pins each Follower entity's Position to\n * target.Position + (offsetX, offsetY).\n * If the target is gone or has no Position, the entity is silently skipped.\n *\n * Recommended priority: run AFTER createMovementSystem (1) so the target's\n * position is already integrated before the follower snaps to it.\n */\nexport function createFollowerSystem(world: World): SystemDef {\n const q = world.query(Position, Follower);\n return defineSystem(q, (entities, _dt, w) => {\n for (const id of entities) {\n const follower = w.get(id, Follower)!;\n const t = w.get(follower.target, Position);\n if (t === undefined) continue;\n const pos = w.get(id, Position)!;\n pos.x = t.x + follower.offsetX;\n pos.y = t.y + follower.offsetY;\n }\n });\n}\n\n/**\n * createOrphanCullSystem — fires onOrphan for each Follower whose target entity\n * no longer exists. Does NOT move or destroy anything itself.\n *\n * Split from createFollowerSystem so games that want to orphan-cull can opt in\n * without coupling destruction to the follower pin logic.\n *\n * Recommended priority: run AFTER createFollowerSystem (2) so the follower is\n * pinned before orphans are detected.\n *\n * Deferred removal: same splice-during-iteration reason as createLifetimeSystem.\n *\n * @param onOrphan Called once per orphaned entity after the read loop.\n */\nexport function createOrphanCullSystem(\n world: World,\n onOrphan: (entity: number, world: World) => void,\n): SystemDef {\n const q = world.query(Follower);\n const scratch: number[] = [];\n return defineSystem(q, (entities, _dt, w) => {\n scratch.length = 0;\n for (const id of entities) {\n const follower = w.get(id, Follower)!;\n if (!w.exists(follower.target)) {\n scratch.push(id);\n }\n }\n for (let i = 0; i < scratch.length; i++) {\n onOrphan(scratch[i]!, w);\n }\n });\n}\n"],"mappings":";AAmBA,IAAI,kBAAkB;AAQf,SAAS,gBAA+B,MAAc,UAAqC;AAChG,QAAM,KAAK;AACX,MAAI,MAAM,IAAI;AACZ,UAAM,IAAI,MAAM,kDAAkD,IAAI,IAAI;AAAA,EAC5E;AACA,SAAO;AAAA,IACL;AAAA,IACA,KAAK,KAAK;AAAA,IACV;AAAA,IACA,QAAQ,aAAa,MAAM;AAAA,EAC7B;AACF;AAMO,SAAS,qBAA2B;AACzC,oBAAkB;AACpB;;;AC9CA,SAAS,cAAc;AAShB,IAAM,QAAN,MAAY;AAAA;AAAA,EAER;AAAA;AAAA,EAEA;AAAA;AAAA,EAGA,gBAAgB,IAAI,OAAe;AAAA;AAAA,EAEnC,kBAAkB,IAAI,OAAe;AAAA;AAAA,EAGtC,WAAqB,CAAC;AAAA;AAAA,EAEtB,YAAY,oBAAI,IAAY;AAAA,EAEpC,YAAY,cAAsB,cAAsB;AACtD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,EAAE,IAAI,SAAS;AAAA,IACzB;AAAA,EACF,CAAC;AACH;AAgBO,SAAS,uBACd,OACA,UACW;AACX,QAAM,IAAI,MAAM,MAAM,QAAQ;AAC9B,QAAM,UAAoB,CAAC;AAC3B,SAAO,aAAa,GAAG,CAAC,UAAU,KAAK,MAAM;AAC3C,YAAQ,SAAS;AACjB,eAAW,MAAM,UAAU;AACzB,YAAM,WAAW,EAAE,IAAI,IAAI,QAAQ;AACnC,UAAI,CAAC,EAAE,OAAO,SAAS,MAAM,GAAG;AAC9B,gBAAQ,KAAK,EAAE;AAAA,MACjB;AAAA,IACF;AACA,aAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;AACvC,eAAS,QAAQ,CAAC,GAAI,CAAC;AAAA,IACzB;AAAA,EACF,CAAC;AACH;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flare-engine/ecs",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Entity-Component-System with archetype queries",
5
5
  "keywords": ["flare-engine", "ecs", "entity-component-system"],
6
6
  "license": "MIT",
@@ -32,8 +32,8 @@
32
32
  "typecheck": "tsc --noEmit"
33
33
  },
34
34
  "dependencies": {
35
- "@flare-engine/events": "^0.1.0",
36
- "@flare-engine/math": "^0.1.0"
35
+ "@flare-engine/events": "^0.2.0",
36
+ "@flare-engine/math": "^0.2.0"
37
37
  },
38
38
  "publishConfig": {
39
39
  "access": "restricted",