archetype-ecs-lib 0.5.0 → 0.6.1

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.
@@ -1,7 +1,8 @@
1
1
  import { Commands } from "./Commands";
2
2
  import { EventChannel } from "./Events";
3
- import type { ComponentCtor, ComponentCtorBundleItem, Entity, QueryRow1, QueryRow2, QueryRow3, QueryRow4, QueryRow5, QueryRow6, SystemFn, WorldApi } from "./Types";
4
- export declare class World implements WorldApi {
3
+ import type { ComponentCtor, ComponentCtorBundleItem, Entity, QueryRow1, QueryRow2, QueryRow3, QueryRow4, QueryRow5, QueryRow6, QueryTable1, QueryTable2, QueryTable3, QueryTable4, QueryTable5, QueryTable6, SnapshotCodec, SystemFn, WorldApi, WorldSnapshot, WorldStats, WorldStatsHistory } from "./Types";
4
+ import { StatsOverlay, type StatsOverlayOptions } from "./stats/StatsOverlay";
5
+ export declare class World extends StatsOverlay implements WorldApi {
5
6
  private readonly entities;
6
7
  private readonly archetypes;
7
8
  private readonly archByKey;
@@ -10,17 +11,51 @@ export declare class World implements WorldApi {
10
11
  private _iterateDepth;
11
12
  private readonly resources;
12
13
  private readonly eventChannels;
13
- constructor();
14
+ private readonly snapshotStore;
15
+ /** @internal Phase -> systems mapping for Schedule */
16
+ readonly _scheduleSystems: Map<string, SystemFn[]>;
17
+ constructor(options?: {
18
+ statsOverlayOptions: StatsOverlayOptions;
19
+ });
20
+ statsHistory(): WorldStatsHistory;
21
+ /**
22
+ * Rich runtime statistics (counts + last-frame timings).
23
+ * Note: `aliveEntities` is computed on demand (O(n) over entity meta).
24
+ */
25
+ stats(): WorldStats;
14
26
  /** Queue structural changes to apply safely after systems run. */
15
27
  cmd(): Commands;
16
28
  addSystem(fn: SystemFn): this;
17
29
  /**
18
- * Run a frame:
19
- * - run systems in order
20
- * - flush queued commands (structural changes)
30
+ * Simple single-phase update.
31
+ * Runs all systems added via `addSystem()`, flushes commands, and swaps events once.
32
+ *
33
+ * This is the recommended approach for:
34
+ * - Simple applications with basic game loops
35
+ * - Single-phase system execution
36
+ * - Rapid prototyping
37
+ *
38
+ * @example
39
+ * ```TypeScript
40
+ * // Simple game loop
41
+ * function gameLoop(dt: number) {
42
+ * world.update(dt);
43
+ * }
44
+ * ```
45
+ *
46
+ * @note If you are using `Schedule` for multiphase updates, do NOT use this method.
47
+ * Use `schedule.run(world, dt, phases)` instead.
48
+ *
49
+ * @throws {Error} If both World.update() and Schedule.run() are used on the same World instance
21
50
  */
22
51
  update(dt: number): void;
23
52
  flush(): void;
53
+ registerComponentSnapshot<T, D = unknown>(key: ComponentCtor<T>, codec: SnapshotCodec<T, D>): this;
54
+ unregisterComponentSnapshot<T>(key: ComponentCtor<T>): boolean;
55
+ registerResourceSnapshot<T, D = unknown>(key: ComponentCtor<T>, codec: SnapshotCodec<T, D>): this;
56
+ unregisterResourceSnapshot<T>(key: ComponentCtor<T>): boolean;
57
+ snapshot(): WorldSnapshot;
58
+ restore(snapshot: WorldSnapshot): void;
24
59
  setResource<T>(key: ComponentCtor<T>, value: T): void;
25
60
  getResource<T>(key: ComponentCtor<T>): T | undefined;
26
61
  requireResource<T>(key: ComponentCtor<T>): T;
@@ -55,6 +90,28 @@ export declare class World implements WorldApi {
55
90
  query<A, B, C, D>(c1: ComponentCtor<A>, c2: ComponentCtor<B>, c3: ComponentCtor<C>, c4: ComponentCtor<D>): Iterable<QueryRow4<A, B, C, D>>;
56
91
  query<A, B, C, D, E>(c1: ComponentCtor<A>, c2: ComponentCtor<B>, c3: ComponentCtor<C>, c4: ComponentCtor<D>, c5: ComponentCtor<E>): Iterable<QueryRow5<A, B, C, D, E>>;
57
92
  query<A, B, C, D, E, F>(c1: ComponentCtor<A>, c2: ComponentCtor<B>, c3: ComponentCtor<C>, c4: ComponentCtor<D>, c5: ComponentCtor<E>, c6: ComponentCtor<F>): Iterable<QueryRow6<A, B, C, D, E, F>>;
93
+ /**
94
+ * Table query: yields one item per matching archetype (SoA columns + entity array).
95
+ * This avoids allocating one object per entity row.
96
+ */
97
+ queryTables<A>(c1: ComponentCtor<A>): Iterable<QueryTable1<A>>;
98
+ queryTables<A, B>(c1: ComponentCtor<A>, c2: ComponentCtor<B>): Iterable<QueryTable2<A, B>>;
99
+ queryTables<A, B, C>(c1: ComponentCtor<A>, c2: ComponentCtor<B>, c3: ComponentCtor<C>): Iterable<QueryTable3<A, B, C>>;
100
+ queryTables<A, B, C, D>(c1: ComponentCtor<A>, c2: ComponentCtor<B>, c3: ComponentCtor<C>, c4: ComponentCtor<D>): Iterable<QueryTable4<A, B, C, D>>;
101
+ queryTables<A, B, C, D, E>(c1: ComponentCtor<A>, c2: ComponentCtor<B>, c3: ComponentCtor<C>, c4: ComponentCtor<D>, c5: ComponentCtor<E>): Iterable<QueryTable5<A, B, C, D, E>>;
102
+ queryTables<A, B, C, D, E, F>(c1: ComponentCtor<A>, c2: ComponentCtor<B>, c3: ComponentCtor<C>, c4: ComponentCtor<D>, c5: ComponentCtor<E>, c6: ComponentCtor<F>): Iterable<QueryTable6<A, B, C, D, E, F>>;
103
+ /**
104
+ * Callback query: calls `fn` for each matching entity row (no yield object allocations).
105
+ */
106
+ queryEach<A>(c1: ComponentCtor<A>, fn: (e: Entity, c1: A) => void): void;
107
+ queryEach<A, B>(c1: ComponentCtor<A>, c2: ComponentCtor<B>, fn: (e: Entity, c1: A, c2: B) => void): void;
108
+ queryEach<A, B, C>(c1: ComponentCtor<A>, c2: ComponentCtor<B>, c3: ComponentCtor<C>, fn: (e: Entity, c1: A, c2: B, c3: C) => void): void;
109
+ queryEach<A, B, C, D>(c1: ComponentCtor<A>, c2: ComponentCtor<B>, c3: ComponentCtor<C>, c4: ComponentCtor<D>, fn: (e: Entity, c1: A, c2: B, c3: C, c4: D) => void): void;
110
+ queryEach<A, B, C, D, E>(c1: ComponentCtor<A>, c2: ComponentCtor<B>, c3: ComponentCtor<C>, c4: ComponentCtor<D>, c5: ComponentCtor<E>, fn: (e: Entity, c1: A, c2: B, c3: C, c4: D, c5: E) => void): void;
111
+ queryEach<A, B, C, D, E, F>(c1: ComponentCtor<A>, c2: ComponentCtor<B>, c3: ComponentCtor<C>, c4: ComponentCtor<D>, c5: ComponentCtor<E>, c6: ComponentCtor<F>, fn: (e: Entity, c1: A, c2: B, c3: C, c4: D, c5: E, c6: F) => void): void;
112
+ private _snapshotRuntime;
113
+ private _resetArchetypes;
114
+ private static _buildQueryTypeIds;
58
115
  private _ensureNotIterating;
59
116
  private _getOrCreateArchetype;
60
117
  private _removeFromArchetype;
@@ -71,4 +128,12 @@ export declare class World implements WorldApi {
71
128
  */
72
129
  private _assertAlive;
73
130
  private _events;
131
+ /**
132
+ * @internal Warns about lifecycle method conflicts in development mode
133
+ */
134
+ _warnAboutLifecycleConflict(method: "World.update" | "Schedule.run"): void;
135
+ /**
136
+ * @internal Returns the number of systems registered via addSystem()
137
+ */
138
+ _getSystemCount(): number;
74
139
  }