iris-ecs 0.0.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.
- package/LICENSE +21 -0
- package/README.md +721 -0
- package/dist/actions.d.ts +43 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +35 -0
- package/dist/actions.js.map +1 -0
- package/dist/archetype.d.ts +194 -0
- package/dist/archetype.d.ts.map +1 -0
- package/dist/archetype.js +412 -0
- package/dist/archetype.js.map +1 -0
- package/dist/component.d.ts +89 -0
- package/dist/component.d.ts.map +1 -0
- package/dist/component.js +237 -0
- package/dist/component.js.map +1 -0
- package/dist/encoding.d.ts +204 -0
- package/dist/encoding.d.ts.map +1 -0
- package/dist/encoding.js +215 -0
- package/dist/encoding.js.map +1 -0
- package/dist/entity.d.ts +129 -0
- package/dist/entity.d.ts.map +1 -0
- package/dist/entity.js +243 -0
- package/dist/entity.js.map +1 -0
- package/dist/event.d.ts +237 -0
- package/dist/event.d.ts.map +1 -0
- package/dist/event.js +293 -0
- package/dist/event.js.map +1 -0
- package/dist/filters.d.ts +121 -0
- package/dist/filters.d.ts.map +1 -0
- package/dist/filters.js +202 -0
- package/dist/filters.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +54 -0
- package/dist/index.js.map +1 -0
- package/dist/name.d.ts +70 -0
- package/dist/name.d.ts.map +1 -0
- package/dist/name.js +172 -0
- package/dist/name.js.map +1 -0
- package/dist/observer.d.ts +83 -0
- package/dist/observer.d.ts.map +1 -0
- package/dist/observer.js +62 -0
- package/dist/observer.js.map +1 -0
- package/dist/query.d.ts +198 -0
- package/dist/query.d.ts.map +1 -0
- package/dist/query.js +299 -0
- package/dist/query.js.map +1 -0
- package/dist/registry.d.ts +118 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +112 -0
- package/dist/registry.js.map +1 -0
- package/dist/relation.d.ts +60 -0
- package/dist/relation.d.ts.map +1 -0
- package/dist/relation.js +171 -0
- package/dist/relation.js.map +1 -0
- package/dist/removal.d.ts +27 -0
- package/dist/removal.d.ts.map +1 -0
- package/dist/removal.js +66 -0
- package/dist/removal.js.map +1 -0
- package/dist/resource.d.ts +78 -0
- package/dist/resource.d.ts.map +1 -0
- package/dist/resource.js +86 -0
- package/dist/resource.js.map +1 -0
- package/dist/scheduler.d.ts +106 -0
- package/dist/scheduler.d.ts.map +1 -0
- package/dist/scheduler.js +204 -0
- package/dist/scheduler.js.map +1 -0
- package/dist/schema.d.ts +117 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +113 -0
- package/dist/schema.js.map +1 -0
- package/dist/world.d.ts +172 -0
- package/dist/world.d.ts.map +1 -0
- package/dist/world.js +127 -0
- package/dist/world.js.map +1 -0
- package/package.json +52 -0
package/dist/resource.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { addComponent, getComponentValue, hasComponent, removeComponent, setComponentValue } from "./component.js";
|
|
2
|
+
/**
|
|
3
|
+
* Adds a global resource (singleton) to the world using the component-on-self pattern.
|
|
4
|
+
*
|
|
5
|
+
* Resources are stored by adding the component to itself as an entity. Idempotent if already present.
|
|
6
|
+
*
|
|
7
|
+
* @param world - World instance
|
|
8
|
+
* @param component - Component definition to use as resource
|
|
9
|
+
* @param data - Initial values for the resource
|
|
10
|
+
* @returns void
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const Time = defineComponent("Time", { delta: Type.f32() });
|
|
15
|
+
* addResource(world, Time, { delta: 0.016 });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export function addResource(world, component, data) {
|
|
19
|
+
addComponent(world, component, component, data);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Removes a global resource from the world.
|
|
23
|
+
*
|
|
24
|
+
* @param world - World instance
|
|
25
|
+
* @param component - Component definition (acting as resource handle)
|
|
26
|
+
* @returns void
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* removeResource(world, Time);
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export function removeResource(world, component) {
|
|
34
|
+
removeComponent(world, component, component);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Checks if a global resource exists in the world.
|
|
38
|
+
*
|
|
39
|
+
* @param world - World instance
|
|
40
|
+
* @param component - Component definition (acting as resource handle)
|
|
41
|
+
* @returns True if the resource exists, false otherwise
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* if (hasResource(world, Time)) {
|
|
46
|
+
* // Time resource is available
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export function hasResource(world, component) {
|
|
51
|
+
return hasComponent(world, component, component);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Gets the value of a specific field on a global resource.
|
|
55
|
+
*
|
|
56
|
+
* @param world - World instance
|
|
57
|
+
* @param component - Component definition
|
|
58
|
+
* @param key - Field name to retrieve
|
|
59
|
+
* @returns The field value, or undefined if the resource is not present
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const dt = getResourceValue(world, Time, "delta");
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export function getResourceValue(world, component, key) {
|
|
67
|
+
return getComponentValue(world, component, component, key);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Sets the value of a specific field on a global resource.
|
|
71
|
+
*
|
|
72
|
+
* @param world - World instance
|
|
73
|
+
* @param component - Component definition
|
|
74
|
+
* @param key - Field name to set
|
|
75
|
+
* @param value - New value for the field
|
|
76
|
+
* @returns void
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* setResourceValue(world, Time, "delta", 0.033);
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export function setResourceValue(world, component, key, value) {
|
|
84
|
+
setComponentValue(world, component, component, key, value);
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=resource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource.js","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,YAAY,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAKnH;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,WAAW,CACzB,KAAY,EACZ,SAAuB,EACvB,IAA0B;IAE1B,YAAY,CAAC,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;AAClD,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,cAAc,CAAC,KAAY,EAAE,SAAmB;IAC9D,eAAe,CAAC,KAAK,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;AAC/C,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,WAAW,CAAC,KAAY,EAAE,SAAmB;IAC3D,OAAO,YAAY,CAAC,KAAK,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;AACnD,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,gBAAgB,CAC9B,KAAY,EACZ,SAAuB,EACvB,GAAM;IAEN,OAAO,iBAAiB,CAAC,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,CAAC,CAAC;AAC7D,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,gBAAgB,CAC9B,KAAY,EACZ,SAAuB,EACvB,GAAM,EACN,KAAwB;IAExB,iBAAiB,CAAC,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;AAC7D,CAAC"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { World } from "./world.js";
|
|
2
|
+
/**
|
|
3
|
+
* Schedule identifier.
|
|
4
|
+
*
|
|
5
|
+
* Provides autocomplete for common schedules while allowing custom names.
|
|
6
|
+
*/
|
|
7
|
+
export type ScheduleId = "runtime" | "startup" | "shutdown" | (string & {});
|
|
8
|
+
/**
|
|
9
|
+
* System function signature.
|
|
10
|
+
*
|
|
11
|
+
* Takes world, returns void or Promise for async systems.
|
|
12
|
+
*/
|
|
13
|
+
export type SystemRunner = (world: World) => void | Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Options for system registration.
|
|
16
|
+
*/
|
|
17
|
+
export type SystemOptions = {
|
|
18
|
+
/**
|
|
19
|
+
* Custom name (overrides function.name). Required for anonymous functions.
|
|
20
|
+
*/
|
|
21
|
+
name?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Schedule this system belongs to. Defaults to 'runtime'.
|
|
24
|
+
*/
|
|
25
|
+
schedule?: ScheduleId;
|
|
26
|
+
/**
|
|
27
|
+
* Run before these systems (within same schedule).
|
|
28
|
+
*/
|
|
29
|
+
before?: string | string[];
|
|
30
|
+
/**
|
|
31
|
+
* Run after these systems (within same schedule).
|
|
32
|
+
*/
|
|
33
|
+
after?: string | string[];
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* System metadata stored in registry.
|
|
37
|
+
*/
|
|
38
|
+
export type SystemMeta = {
|
|
39
|
+
/**
|
|
40
|
+
* Function to execute.
|
|
41
|
+
*/
|
|
42
|
+
runner: SystemRunner;
|
|
43
|
+
/**
|
|
44
|
+
* Schedule this system belongs to.
|
|
45
|
+
*/
|
|
46
|
+
schedule: ScheduleId;
|
|
47
|
+
/**
|
|
48
|
+
* Registration order (for stable sort).
|
|
49
|
+
*/
|
|
50
|
+
index: number;
|
|
51
|
+
/**
|
|
52
|
+
* Systems this one must execute before (these run after this system).
|
|
53
|
+
*/
|
|
54
|
+
before: string[];
|
|
55
|
+
/**
|
|
56
|
+
* Systems this one must execute after (these run before this system).
|
|
57
|
+
*/
|
|
58
|
+
after: string[];
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Registers a system in the world for later scheduling.
|
|
62
|
+
*
|
|
63
|
+
* @param world - World instance
|
|
64
|
+
* @param runner - System function (must be named unless name option provided)
|
|
65
|
+
* @param options - Registration options (name, schedule, before, after)
|
|
66
|
+
* @returns void
|
|
67
|
+
* @example
|
|
68
|
+
* addSystem(world, physicsSystem);
|
|
69
|
+
* addSystem(world, renderSystem, { after: "physicsSystem" });
|
|
70
|
+
*/
|
|
71
|
+
export declare function addSystem(world: World, runner: SystemRunner, options?: SystemOptions): void;
|
|
72
|
+
/**
|
|
73
|
+
* Builds an execution order from registered systems using topological sort.
|
|
74
|
+
* Systems are ordered by before/after constraints, with registration order as tiebreaker.
|
|
75
|
+
*
|
|
76
|
+
* @param world - World instance
|
|
77
|
+
* @param scheduleId - Schedule identifier (defaults to "runtime")
|
|
78
|
+
* @returns void
|
|
79
|
+
* @example
|
|
80
|
+
* buildSchedule(world);
|
|
81
|
+
* buildSchedule(world, "startup");
|
|
82
|
+
*/
|
|
83
|
+
export declare function buildSchedule(world: World, scheduleId?: ScheduleId): void;
|
|
84
|
+
/**
|
|
85
|
+
* Executes a schedule synchronously. Throws if any system returns a Promise.
|
|
86
|
+
*
|
|
87
|
+
* @param world - World instance
|
|
88
|
+
* @param scheduleId - Schedule identifier (defaults to "runtime")
|
|
89
|
+
* @returns void
|
|
90
|
+
* @example
|
|
91
|
+
* executeSchedule(world);
|
|
92
|
+
* executeSchedule(world, "startup");
|
|
93
|
+
*/
|
|
94
|
+
export declare function executeSchedule(world: World, scheduleId?: ScheduleId): void;
|
|
95
|
+
/**
|
|
96
|
+
* Executes a schedule with async support. Awaits systems that return Promises.
|
|
97
|
+
*
|
|
98
|
+
* @param world - World instance
|
|
99
|
+
* @param scheduleId - Schedule identifier (defaults to "runtime")
|
|
100
|
+
* @returns Promise that resolves when all systems complete
|
|
101
|
+
* @example
|
|
102
|
+
* await executeScheduleAsync(world);
|
|
103
|
+
* await executeScheduleAsync(world, "startup");
|
|
104
|
+
*/
|
|
105
|
+
export declare function executeScheduleAsync(world: World, scheduleId?: ScheduleId): Promise<void>;
|
|
106
|
+
//# sourceMappingURL=scheduler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAMxC;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,SAAS,GAAG,UAAU,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;AAE5E;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAElE;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,QAAQ,CAAC,EAAE,UAAU,CAAC;IAEtB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAE3B;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC3B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB;;OAEG;IACH,MAAM,EAAE,YAAY,CAAC;IAErB;;OAEG;IACH,QAAQ,EAAE,UAAU,CAAC;IAErB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,MAAM,EAAE,MAAM,EAAE,CAAC;IAEjB;;OAEG;IACH,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,IAAI,CAuB3F;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,UAAU,GAAE,UAAsB,GAAG,IAAI,CAwFpF;AA0BD;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,EAAE,UAAU,GAAE,UAAsB,GAAG,IAAI,CA2BtF;AAED;;;;;;;;;GASG;AACH,wBAAsB,oBAAoB,CAAC,KAAK,EAAE,KAAK,EAAE,UAAU,GAAE,UAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CA2B1G"}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Registers a system in the world for later scheduling.
|
|
3
|
+
*
|
|
4
|
+
* @param world - World instance
|
|
5
|
+
* @param runner - System function (must be named unless name option provided)
|
|
6
|
+
* @param options - Registration options (name, schedule, before, after)
|
|
7
|
+
* @returns void
|
|
8
|
+
* @example
|
|
9
|
+
* addSystem(world, physicsSystem);
|
|
10
|
+
* addSystem(world, renderSystem, { after: "physicsSystem" });
|
|
11
|
+
*/
|
|
12
|
+
export function addSystem(world, runner, options) {
|
|
13
|
+
// Derive system name from function name or explicit option
|
|
14
|
+
const name = options?.name ?? runner.name;
|
|
15
|
+
if (!name || name === "anonymous") {
|
|
16
|
+
throw new TypeError("System function must be named or provide name option");
|
|
17
|
+
}
|
|
18
|
+
if (world.systems.byId.has(name)) {
|
|
19
|
+
throw new Error(`System "${name}" already registered`);
|
|
20
|
+
}
|
|
21
|
+
// Normalize before/after constraints to arrays for consistent handling
|
|
22
|
+
const before = options?.before;
|
|
23
|
+
const after = options?.after;
|
|
24
|
+
world.systems.byId.set(name, {
|
|
25
|
+
runner,
|
|
26
|
+
schedule: options?.schedule ?? "runtime",
|
|
27
|
+
index: world.systems.nextIndex++,
|
|
28
|
+
before: !before ? [] : Array.isArray(before) ? before : [before],
|
|
29
|
+
after: !after ? [] : Array.isArray(after) ? after : [after],
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Builds an execution order from registered systems using topological sort.
|
|
34
|
+
* Systems are ordered by before/after constraints, with registration order as tiebreaker.
|
|
35
|
+
*
|
|
36
|
+
* @param world - World instance
|
|
37
|
+
* @param scheduleId - Schedule identifier (defaults to "runtime")
|
|
38
|
+
* @returns void
|
|
39
|
+
* @example
|
|
40
|
+
* buildSchedule(world);
|
|
41
|
+
* buildSchedule(world, "startup");
|
|
42
|
+
*/
|
|
43
|
+
export function buildSchedule(world, scheduleId = "runtime") {
|
|
44
|
+
// Filter systems belonging to this schedule
|
|
45
|
+
const scheduleSystems = new Map();
|
|
46
|
+
for (const [name, meta] of world.systems.byId) {
|
|
47
|
+
if (meta.schedule === scheduleId) {
|
|
48
|
+
scheduleSystems.set(name, meta);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (scheduleSystems.size === 0) {
|
|
52
|
+
world.schedules.byId.set(scheduleId, []);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
// Build dependency graph for Kahn's algorithm
|
|
56
|
+
const adjacency = new Map();
|
|
57
|
+
const inDegree = new Map();
|
|
58
|
+
for (const name of scheduleSystems.keys()) {
|
|
59
|
+
adjacency.set(name, []);
|
|
60
|
+
inDegree.set(name, 0);
|
|
61
|
+
}
|
|
62
|
+
// Convert before/after constraints into directed edges
|
|
63
|
+
for (const [name, meta] of scheduleSystems) {
|
|
64
|
+
for (const beforeName of meta.before) {
|
|
65
|
+
if (!scheduleSystems.has(beforeName)) {
|
|
66
|
+
throw new Error(`System "${name}" references unknown system "${beforeName}" in schedule "${scheduleId}"`);
|
|
67
|
+
}
|
|
68
|
+
// "A before B" means edge A -> B (A must run first)
|
|
69
|
+
adjacency.get(name).push(beforeName);
|
|
70
|
+
inDegree.set(beforeName, inDegree.get(beforeName) + 1);
|
|
71
|
+
}
|
|
72
|
+
for (const afterName of meta.after) {
|
|
73
|
+
if (!scheduleSystems.has(afterName)) {
|
|
74
|
+
throw new Error(`System "${name}" references unknown system "${afterName}" in schedule "${scheduleId}"`);
|
|
75
|
+
}
|
|
76
|
+
// "A after B" means edge B -> A (B must run first)
|
|
77
|
+
adjacency.get(afterName).push(name);
|
|
78
|
+
inDegree.set(name, inDegree.get(name) + 1);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// Initialize queue with systems having no dependencies
|
|
82
|
+
const queue = [];
|
|
83
|
+
for (const [name, degree] of inDegree) {
|
|
84
|
+
if (degree === 0) {
|
|
85
|
+
insertSorted(queue, name, scheduleSystems);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// Process queue, maintaining sorted order by registration index
|
|
89
|
+
const result = [];
|
|
90
|
+
while (queue.length > 0) {
|
|
91
|
+
const current = queue.shift();
|
|
92
|
+
result.push(current);
|
|
93
|
+
for (const dependent of adjacency.get(current)) {
|
|
94
|
+
const newDegree = inDegree.get(dependent) - 1;
|
|
95
|
+
inDegree.set(dependent, newDegree);
|
|
96
|
+
if (newDegree === 0) {
|
|
97
|
+
insertSorted(queue, dependent, scheduleSystems);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// Detect circular dependencies (remaining systems with non-zero in-degree)
|
|
102
|
+
if (result.length !== scheduleSystems.size) {
|
|
103
|
+
const remaining = [];
|
|
104
|
+
for (const [name, degree] of inDegree) {
|
|
105
|
+
if (degree > 0) {
|
|
106
|
+
remaining.push(name);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
throw new Error(`Circular dependency in schedule "${scheduleId}": ${remaining.join(", ")}`);
|
|
110
|
+
}
|
|
111
|
+
world.schedules.byId.set(scheduleId, result);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Inserts a system name into the queue maintaining sorted order by registration index.
|
|
115
|
+
* Uses binary search for O(log n) insertion position lookup.
|
|
116
|
+
* This ensures deterministic ordering when multiple systems have no dependency constraints.
|
|
117
|
+
*/
|
|
118
|
+
function insertSorted(queue, name, systems) {
|
|
119
|
+
const index = systems.get(name).index;
|
|
120
|
+
let low = 0;
|
|
121
|
+
let high = queue.length;
|
|
122
|
+
// Binary search for correct insertion position
|
|
123
|
+
while (low < high) {
|
|
124
|
+
const mid = (low + high) >>> 1;
|
|
125
|
+
if (systems.get(queue[mid]).index < index) {
|
|
126
|
+
low = mid + 1;
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
high = mid;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
queue.splice(low, 0, name);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Executes a schedule synchronously. Throws if any system returns a Promise.
|
|
136
|
+
*
|
|
137
|
+
* @param world - World instance
|
|
138
|
+
* @param scheduleId - Schedule identifier (defaults to "runtime")
|
|
139
|
+
* @returns void
|
|
140
|
+
* @example
|
|
141
|
+
* executeSchedule(world);
|
|
142
|
+
* executeSchedule(world, "startup");
|
|
143
|
+
*/
|
|
144
|
+
export function executeSchedule(world, scheduleId = "runtime") {
|
|
145
|
+
const order = world.schedules.byId.get(scheduleId);
|
|
146
|
+
if (!order) {
|
|
147
|
+
throw new Error(`Schedule "${scheduleId}" not built`);
|
|
148
|
+
}
|
|
149
|
+
// Track execution context for systems that need to know their environment
|
|
150
|
+
world.execution.scheduleId = scheduleId;
|
|
151
|
+
world.execution.tick++;
|
|
152
|
+
try {
|
|
153
|
+
for (const systemId of order) {
|
|
154
|
+
world.execution.systemId = systemId;
|
|
155
|
+
const meta = world.systems.byId.get(systemId);
|
|
156
|
+
const result = meta.runner(world);
|
|
157
|
+
// Fail fast if async system detected in sync execution
|
|
158
|
+
if (result instanceof Promise) {
|
|
159
|
+
throw new Error(`System "${systemId}" returned Promise - use runScheduleAsync`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
finally {
|
|
164
|
+
// Always clear execution context, even on error
|
|
165
|
+
world.execution.scheduleId = null;
|
|
166
|
+
world.execution.systemId = null;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Executes a schedule with async support. Awaits systems that return Promises.
|
|
171
|
+
*
|
|
172
|
+
* @param world - World instance
|
|
173
|
+
* @param scheduleId - Schedule identifier (defaults to "runtime")
|
|
174
|
+
* @returns Promise that resolves when all systems complete
|
|
175
|
+
* @example
|
|
176
|
+
* await executeScheduleAsync(world);
|
|
177
|
+
* await executeScheduleAsync(world, "startup");
|
|
178
|
+
*/
|
|
179
|
+
export async function executeScheduleAsync(world, scheduleId = "runtime") {
|
|
180
|
+
const order = world.schedules.byId.get(scheduleId);
|
|
181
|
+
if (!order) {
|
|
182
|
+
throw new Error(`Schedule "${scheduleId}" not built`);
|
|
183
|
+
}
|
|
184
|
+
// Track execution context for systems that need to know their environment
|
|
185
|
+
world.execution.scheduleId = scheduleId;
|
|
186
|
+
world.execution.tick++;
|
|
187
|
+
try {
|
|
188
|
+
for (const systemId of order) {
|
|
189
|
+
world.execution.systemId = systemId;
|
|
190
|
+
const meta = world.systems.byId.get(systemId);
|
|
191
|
+
const result = meta.runner(world);
|
|
192
|
+
// Await async systems, sync systems pass through unchanged
|
|
193
|
+
if (result instanceof Promise) {
|
|
194
|
+
await result;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
finally {
|
|
199
|
+
// Always clear execution context, even on error
|
|
200
|
+
world.execution.scheduleId = null;
|
|
201
|
+
world.execution.systemId = null;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
//# sourceMappingURL=scheduler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":"AA2EA;;;;;;;;;;GAUG;AACH,MAAM,UAAU,SAAS,CAAC,KAAY,EAAE,MAAoB,EAAE,OAAuB;IACnF,2DAA2D;IAC3D,MAAM,IAAI,GAAG,OAAO,EAAE,IAAI,IAAI,MAAM,CAAC,IAAI,CA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I,EAAE,CAAC;IAEvB,IAAI,CAAC;QACH,KAAK,MAAM,QAAQ,IAAI,KAAK,EAAE,CAAC;YAC7B,KAAK,CAAC,SAAS,CAAC,QAAQ,GAAG,QAAQ,CAAC;YACpC,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAE,CAAC;YAC/C,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAElC,2DAA2D;YAC3D,IAAI,MAAM,YAAY,OAAO,EAAE,CAAC;gBAC9B,MAAM,MAAM,CAAC;YACf,CAAC;QACH,CAAC;IACH,CAAC;YAAS,CAAC;QACT,gDAAgD;QAChD,KAAK,CAAC,SAAS,CAAC,UAAU,GAAG,IAAI,CAAC;QAClC,KAAK,CAAC,SAAS,CAAC,QAAQ,GAAG,IAAI,CAAC;IAClC,CAAC;AACH,CAAC"}
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed array constructor type.
|
|
3
|
+
*
|
|
4
|
+
* Union of all typed array constructors that can be used for numeric storage.
|
|
5
|
+
*/
|
|
6
|
+
export type TypedArrayConstructor = Int8ArrayConstructor | Int16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor;
|
|
7
|
+
/**
|
|
8
|
+
* Type descriptor for columnar storage.
|
|
9
|
+
*
|
|
10
|
+
* Describes how component data should be stored (typed arrays for numbers,
|
|
11
|
+
* regular arrays for primitives/objects). Created via Type namespace factories.
|
|
12
|
+
*
|
|
13
|
+
* @template T - TypeScript type of stored values (inferred via phantom __type field)
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const posX: Schema<number> = Type.f32();
|
|
18
|
+
* const name: Schema<string> = Type.string();
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export type Schema<T = unknown> = {
|
|
22
|
+
kind: "typed" | "primitive" | "generic";
|
|
23
|
+
arrayConstructor: TypedArrayConstructor | ArrayConstructor;
|
|
24
|
+
typeName: string;
|
|
25
|
+
__type?: T;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Schema factory namespace for defining component storage types.
|
|
29
|
+
*
|
|
30
|
+
* Provides constructors for typed arrays (i8, f32, etc.), primitives (bool, string),
|
|
31
|
+
* and generic objects. Use these to define component schemas.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const Position = { x: Type.f32(), y: Type.f32() };
|
|
36
|
+
* const Health = { hp: Type.i32() };
|
|
37
|
+
* const Name = { value: Type.string() };
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare const Type: {
|
|
41
|
+
/**
|
|
42
|
+
* 8-bit signed integer schema (Int8Array).
|
|
43
|
+
*
|
|
44
|
+
* @returns Schema for Int8Array storage
|
|
45
|
+
*/
|
|
46
|
+
i8: () => Schema<number>;
|
|
47
|
+
/**
|
|
48
|
+
* 16-bit signed integer schema (Int16Array).
|
|
49
|
+
*
|
|
50
|
+
* @returns Schema for Int16Array storage
|
|
51
|
+
*/
|
|
52
|
+
i16: () => Schema<number>;
|
|
53
|
+
/**
|
|
54
|
+
* 32-bit signed integer schema (Int32Array).
|
|
55
|
+
*
|
|
56
|
+
* @returns Schema for Int32Array storage
|
|
57
|
+
*/
|
|
58
|
+
i32: () => Schema<number>;
|
|
59
|
+
/**
|
|
60
|
+
* 32-bit unsigned integer schema (Uint32Array).
|
|
61
|
+
*
|
|
62
|
+
* @returns Schema for Uint32Array storage
|
|
63
|
+
*/
|
|
64
|
+
u32: () => Schema<number>;
|
|
65
|
+
/**
|
|
66
|
+
* 32-bit floating point schema (Float32Array).
|
|
67
|
+
*
|
|
68
|
+
* @returns Schema for Float32Array storage
|
|
69
|
+
*/
|
|
70
|
+
f32: () => Schema<number>;
|
|
71
|
+
/**
|
|
72
|
+
* 64-bit floating point schema (Float64Array).
|
|
73
|
+
*
|
|
74
|
+
* @returns Schema for Float64Array storage
|
|
75
|
+
*/
|
|
76
|
+
f64: () => Schema<number>;
|
|
77
|
+
/**
|
|
78
|
+
* Boolean schema (Array<boolean>).
|
|
79
|
+
*
|
|
80
|
+
* @returns Schema for Array<boolean> storage
|
|
81
|
+
*/
|
|
82
|
+
bool: () => Schema<boolean>;
|
|
83
|
+
/**
|
|
84
|
+
* String schema (Array<string>).
|
|
85
|
+
*
|
|
86
|
+
* @returns Schema for Array<string> storage
|
|
87
|
+
*/
|
|
88
|
+
string: () => Schema<string>;
|
|
89
|
+
/**
|
|
90
|
+
* Generic object schema (Array<T>).
|
|
91
|
+
*
|
|
92
|
+
* @template T - TypeScript type of objects stored
|
|
93
|
+
* @returns Schema for Array<T> storage
|
|
94
|
+
*/
|
|
95
|
+
object: <T>() => Schema<T>;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Infer TypeScript type from a schema using the phantom __type field.
|
|
99
|
+
*
|
|
100
|
+
* @template S - Schema type to infer from
|
|
101
|
+
*/
|
|
102
|
+
export type InferSchema<S extends Schema> = S extends Schema<infer T> ? T : never;
|
|
103
|
+
/**
|
|
104
|
+
* Schema record for component fields.
|
|
105
|
+
*
|
|
106
|
+
* Maps field names to their schema definitions.
|
|
107
|
+
*/
|
|
108
|
+
export type SchemaRecord = Record<string, Schema>;
|
|
109
|
+
/**
|
|
110
|
+
* Infer TypeScript types from component schema record.
|
|
111
|
+
*
|
|
112
|
+
* Maps each schema field to its inferred type via phantom __type field.
|
|
113
|
+
*/
|
|
114
|
+
export type InferSchemaRecord<S extends SchemaRecord> = {
|
|
115
|
+
[K in keyof S]: S[K] extends Schema<infer T> ? T : never;
|
|
116
|
+
};
|
|
117
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[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AC,CAAC,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK;CACzD,CAAC"}
|
package/dist/schema.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// Type Definitions
|
|
3
|
+
// ============================================================================
|
|
4
|
+
// ============================================================================
|
|
5
|
+
// Schema Factories
|
|
6
|
+
// ============================================================================
|
|
7
|
+
/**
|
|
8
|
+
* Schema factory namespace for defining component storage types.
|
|
9
|
+
*
|
|
10
|
+
* Provides constructors for typed arrays (i8, f32, etc.), primitives (bool, string),
|
|
11
|
+
* and generic objects. Use these to define component schemas.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const Position = { x: Type.f32(), y: Type.f32() };
|
|
16
|
+
* const Health = { hp: Type.i32() };
|
|
17
|
+
* const Name = { value: Type.string() };
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export const Type = {
|
|
21
|
+
/**
|
|
22
|
+
* 8-bit signed integer schema (Int8Array).
|
|
23
|
+
*
|
|
24
|
+
* @returns Schema for Int8Array storage
|
|
25
|
+
*/
|
|
26
|
+
i8: () => ({
|
|
27
|
+
kind: "typed",
|
|
28
|
+
arrayConstructor: Int8Array,
|
|
29
|
+
typeName: "number",
|
|
30
|
+
}),
|
|
31
|
+
/**
|
|
32
|
+
* 16-bit signed integer schema (Int16Array).
|
|
33
|
+
*
|
|
34
|
+
* @returns Schema for Int16Array storage
|
|
35
|
+
*/
|
|
36
|
+
i16: () => ({
|
|
37
|
+
kind: "typed",
|
|
38
|
+
arrayConstructor: Int16Array,
|
|
39
|
+
typeName: "number",
|
|
40
|
+
}),
|
|
41
|
+
/**
|
|
42
|
+
* 32-bit signed integer schema (Int32Array).
|
|
43
|
+
*
|
|
44
|
+
* @returns Schema for Int32Array storage
|
|
45
|
+
*/
|
|
46
|
+
i32: () => ({
|
|
47
|
+
kind: "typed",
|
|
48
|
+
arrayConstructor: Int32Array,
|
|
49
|
+
typeName: "number",
|
|
50
|
+
}),
|
|
51
|
+
/**
|
|
52
|
+
* 32-bit unsigned integer schema (Uint32Array).
|
|
53
|
+
*
|
|
54
|
+
* @returns Schema for Uint32Array storage
|
|
55
|
+
*/
|
|
56
|
+
u32: () => ({
|
|
57
|
+
kind: "typed",
|
|
58
|
+
arrayConstructor: Uint32Array,
|
|
59
|
+
typeName: "number",
|
|
60
|
+
}),
|
|
61
|
+
/**
|
|
62
|
+
* 32-bit floating point schema (Float32Array).
|
|
63
|
+
*
|
|
64
|
+
* @returns Schema for Float32Array storage
|
|
65
|
+
*/
|
|
66
|
+
f32: () => ({
|
|
67
|
+
kind: "typed",
|
|
68
|
+
arrayConstructor: Float32Array,
|
|
69
|
+
typeName: "number",
|
|
70
|
+
}),
|
|
71
|
+
/**
|
|
72
|
+
* 64-bit floating point schema (Float64Array).
|
|
73
|
+
*
|
|
74
|
+
* @returns Schema for Float64Array storage
|
|
75
|
+
*/
|
|
76
|
+
f64: () => ({
|
|
77
|
+
kind: "typed",
|
|
78
|
+
arrayConstructor: Float64Array,
|
|
79
|
+
typeName: "number",
|
|
80
|
+
}),
|
|
81
|
+
/**
|
|
82
|
+
* Boolean schema (Array<boolean>).
|
|
83
|
+
*
|
|
84
|
+
* @returns Schema for Array<boolean> storage
|
|
85
|
+
*/
|
|
86
|
+
bool: () => ({
|
|
87
|
+
kind: "primitive",
|
|
88
|
+
arrayConstructor: Array,
|
|
89
|
+
typeName: "boolean",
|
|
90
|
+
}),
|
|
91
|
+
/**
|
|
92
|
+
* String schema (Array<string>).
|
|
93
|
+
*
|
|
94
|
+
* @returns Schema for Array<string> storage
|
|
95
|
+
*/
|
|
96
|
+
string: () => ({
|
|
97
|
+
kind: "primitive",
|
|
98
|
+
arrayConstructor: Array,
|
|
99
|
+
typeName: "string",
|
|
100
|
+
}),
|
|
101
|
+
/**
|
|
102
|
+
* Generic object schema (Array<T>).
|
|
103
|
+
*
|
|
104
|
+
* @template T - TypeScript type of objects stored
|
|
105
|
+
* @returns Schema for Array<T> storage
|
|
106
|
+
*/
|
|
107
|
+
object: () => ({
|
|
108
|
+
kind: "generic",
|
|
109
|
+
arrayConstructor: Array,
|
|
110
|
+
typeName: "unknown",
|
|
111
|
+
}),
|
|
112
|
+
};
|
|
113
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,mBAAmB;AACnB,+EAA+E;AAoC/E,+EAA+E;AAC/E,mBAAmB;AACnB,+EAA+E;AAE/E;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG;IAClB;;;;OAIG;IACH,EAAE,EAAE,GAAmB,EAAE,CAAC,CAAC;QACzB,IAAI,EAAE,OAAO;QACb,gBAAgB,EAAE,SAAS;QAC3B,QAAQ,EAAE,QAAQ;KACnB,CAAC;IAEF;;;;OAIG;IACH,GAAG,EAAE,GAAmB,EAAE,CAAC,CAAC;QAC1B,IAAI,EAAE,OAAO;QACb,gBAAgB,EAAE,UAAU;QAC5B,QAAQ,EAAE,QAAQ;KACnB,CAAC;IAEF;;;;OAIG;IACH,GAAG,EAAE,GAAmB,EAAE,CAAC,CAAC;QAC1B,IAAI,EAAE,OAAO;QACb,gBAAgB,EAAE,UAAU;QAC5B,QAAQ,EAAE,QAAQ;KACnB,CAAC;IAEF;;;;OAIG;IACH,GAAG,EAAE,GAAmB,EAAE,CAAC,CAAC;QAC1B,IAAI,EAAE,OAAO;QACb,gBAAgB,EAAE,WAAW;QAC7B,QAAQ,EAAE,QAAQ;KACnB,CAAC;IAEF;;;;OAIG;IACH,GAAG,EAAE,GAAmB,EAAE,CAAC,CAAC;QAC1B,IAAI,EAAE,OAAO;QACb,gBAAgB,EAAE,YAAY;QAC9B,QAAQ,EAAE,QAAQ;KACnB,CAAC;IAE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