@typeonce/ritmo 0.6.0 → 0.8.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 +2 -0
- package/dist/Brand.d.ts +9 -4
- package/dist/Brand.d.ts.map +1 -1
- package/dist/Brand.js +9 -4
- package/dist/Brand.js.map +1 -1
- package/dist/Clock.d.ts +186 -0
- package/dist/Clock.d.ts.map +1 -0
- package/dist/Clock.js +111 -0
- package/dist/Clock.js.map +1 -0
- package/dist/Command.d.ts +250 -41
- package/dist/Command.d.ts.map +1 -1
- package/dist/Command.js +59 -23
- package/dist/Command.js.map +1 -1
- package/dist/Condition.d.ts +12 -1
- package/dist/Condition.d.ts.map +1 -1
- package/dist/Condition.js.map +1 -1
- package/dist/Debug.d.ts +163 -15
- package/dist/Debug.d.ts.map +1 -1
- package/dist/Debug.js.map +1 -1
- package/dist/Decode.d.ts +1 -1
- package/dist/Decode.js +1 -1
- package/dist/Descriptor.d.ts +67 -24
- package/dist/Descriptor.d.ts.map +1 -1
- package/dist/Descriptor.js +32 -15
- package/dist/Descriptor.js.map +1 -1
- package/dist/Entity.d.ts +22 -5
- package/dist/Entity.d.ts.map +1 -1
- package/dist/Entity.js +2 -2
- package/dist/Entity.js.map +1 -1
- package/dist/EntityScope.d.ts +26 -1
- package/dist/EntityScope.d.ts.map +1 -1
- package/dist/EntityScope.js +14 -2
- package/dist/EntityScope.js.map +1 -1
- package/dist/HostClock.d.ts +49 -0
- package/dist/HostClock.d.ts.map +1 -0
- package/dist/HostClock.js +46 -0
- package/dist/HostClock.js.map +1 -0
- package/dist/Inspector.d.ts +7 -1
- package/dist/Inspector.d.ts.map +1 -1
- package/dist/Inspector.js.map +1 -1
- package/dist/Machine.d.ts +67 -36
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +10 -3
- package/dist/Machine.js.map +1 -1
- package/dist/Query.d.ts +74 -26
- package/dist/Query.d.ts.map +1 -1
- package/dist/Query.js +32 -28
- package/dist/Query.js.map +1 -1
- package/dist/Runtime.d.ts +39 -16
- package/dist/Runtime.d.ts.map +1 -1
- package/dist/Runtime.js +556 -87
- package/dist/Runtime.js.map +1 -1
- package/dist/Schedule.d.ts +217 -10
- package/dist/Schedule.d.ts.map +1 -1
- package/dist/Schedule.js +5 -0
- package/dist/Schedule.js.map +1 -1
- package/dist/Schema.d.ts +196 -44
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +29 -11
- package/dist/Schema.js.map +1 -1
- package/dist/Snapshot.d.ts +14 -0
- package/dist/Snapshot.d.ts.map +1 -1
- package/dist/Snapshot.js.map +1 -1
- package/dist/System.d.ts +212 -58
- package/dist/System.d.ts.map +1 -1
- package/dist/System.js +84 -6
- package/dist/System.js.map +1 -1
- package/dist/index.d.ts +8 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -7
- package/dist/index.js.map +1 -1
- package/dist/internal/cells.d.ts +3 -3
- package/dist/internal/cells.d.ts.map +1 -1
- package/dist/internal/cells.js +9 -11
- package/dist/internal/cells.js.map +1 -1
- package/dist/internal/debug.d.ts +13 -0
- package/dist/internal/debug.d.ts.map +1 -1
- package/dist/internal/debug.js +192 -7
- package/dist/internal/debug.js.map +1 -1
- package/dist/internal/equal.d.ts +8 -0
- package/dist/internal/equal.d.ts.map +1 -0
- package/dist/internal/equal.js +38 -0
- package/dist/internal/equal.js.map +1 -0
- package/dist/internal/fragments.d.ts.map +1 -1
- package/dist/internal/fragments.js +11 -1
- package/dist/internal/fragments.js.map +1 -1
- package/dist/internal/game.d.ts.map +1 -1
- package/dist/internal/game.js +41 -6
- package/dist/internal/game.js.map +1 -1
- package/dist/internal/order.d.ts +10 -0
- package/dist/internal/order.d.ts.map +1 -0
- package/dist/internal/order.js +122 -0
- package/dist/internal/order.js.map +1 -0
- package/dist/internal/queries.d.ts.map +1 -1
- package/dist/internal/queries.js +32 -10
- package/dist/internal/queries.js.map +1 -1
- package/dist/internal/requirements.d.ts +26 -0
- package/dist/internal/requirements.d.ts.map +1 -0
- package/dist/internal/requirements.js +46 -0
- package/dist/internal/requirements.js.map +1 -0
- package/package.json +1 -1
- package/src/Brand.ts +9 -4
- package/src/Clock.ts +311 -0
- package/src/Command.ts +407 -89
- package/src/Condition.ts +17 -1
- package/src/Debug.ts +172 -14
- package/src/Decode.ts +1 -1
- package/src/Descriptor.ts +92 -37
- package/src/Entity.ts +24 -5
- package/src/EntityScope.ts +27 -2
- package/src/HostClock.ts +64 -0
- package/src/Inspector.ts +7 -2
- package/src/Machine.ts +81 -37
- package/src/Query.ts +110 -38
- package/src/Runtime.ts +607 -111
- package/src/Schedule.ts +380 -13
- package/src/Schema.ts +249 -63
- package/src/Snapshot.ts +4 -0
- package/src/System.ts +248 -93
- package/src/index.ts +8 -7
- package/src/internal/cells.ts +10 -12
- package/src/internal/debug.ts +208 -12
- package/src/internal/equal.ts +31 -0
- package/src/internal/fragments.ts +12 -2
- package/src/internal/game.ts +61 -7
- package/src/internal/order.ts +144 -0
- package/src/internal/queries.ts +37 -13
- package/src/internal/requirements.ts +71 -0
- package/dist/Definition.d.ts +0 -99
- package/dist/Definition.d.ts.map +0 -1
- package/dist/Definition.js +0 -68
- package/dist/Definition.js.map +0 -1
- package/dist/Feature.d.ts +0 -106
- package/dist/Feature.d.ts.map +0 -1
- package/dist/Feature.js +0 -87
- package/dist/Feature.js.map +0 -1
- package/dist/Fx.d.ts +0 -128
- package/dist/Fx.d.ts.map +0 -1
- package/dist/Fx.js +0 -112
- package/dist/Fx.js.map +0 -1
- package/dist/internal/definition.d.ts +0 -17
- package/dist/internal/definition.d.ts.map +0 -1
- package/dist/internal/definition.js +0 -25
- package/dist/internal/definition.js.map +0 -1
- package/src/Definition.ts +0 -106
- package/src/Feature.ts +0 -241
- package/src/Fx.ts +0 -176
- package/src/internal/definition.ts +0 -56
package/dist/Descriptor.d.ts
CHANGED
|
@@ -16,8 +16,9 @@
|
|
|
16
16
|
* 3. bind one `Game` with `Schema.bind(...)`
|
|
17
17
|
*
|
|
18
18
|
* Reach for this module first whenever you introduce a new component,
|
|
19
|
-
* resource, event, or service to the game.
|
|
20
|
-
* matter
|
|
19
|
+
* resource, event, or service to the game. A game-wide mode whose transitions
|
|
20
|
+
* matter is a state machine (`Game.StateMachine(...)`); a state each entity
|
|
21
|
+
* has on its own is a component (`Descriptor.EntityState(...)`).
|
|
21
22
|
*
|
|
22
23
|
* @module Descriptor
|
|
23
24
|
* @docGroup core
|
|
@@ -132,6 +133,37 @@ type ConstructedFor<Kind extends DescriptorKind, Name extends string, Value, Raw
|
|
|
132
133
|
export interface TransientDescriptor<out Kind extends "component" | "resource", out Name extends string, in out Value> extends Descriptor<Kind, Name, Value> {
|
|
133
134
|
readonly transient: true;
|
|
134
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Marks a component that is never edited in place: `Game.Query.write(...)`
|
|
138
|
+
* rejects it, and the only way to change its value is to replace it with
|
|
139
|
+
* `commands.insert(...)` (applied at `applyDeferred()`, seen by
|
|
140
|
+
* `Game.Query.changed(...)`).
|
|
141
|
+
*/
|
|
142
|
+
export interface Immutable {
|
|
143
|
+
readonly immutable: true;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Options of the component descriptor constructors (`Component`,
|
|
147
|
+
* `ConstructedComponent`, `TransientComponent`).
|
|
148
|
+
*/
|
|
149
|
+
export interface ComponentOptions {
|
|
150
|
+
/**
|
|
151
|
+
* `true` for data that says what an entity is (a kind, a team, a tile) and
|
|
152
|
+
* is replaced, never edited: queries can only read it, and
|
|
153
|
+
* `commands.insert(...)` replaces it. Leave it out for state that systems
|
|
154
|
+
* update every frame.
|
|
155
|
+
*/
|
|
156
|
+
readonly immutable?: true;
|
|
157
|
+
}
|
|
158
|
+
/** The descriptor a component constructor returns for `Options`: `D`, plus `Immutable` when `immutable: true`. */
|
|
159
|
+
export type WithComponentOptions<D, Options extends ComponentOptions> = Options extends {
|
|
160
|
+
readonly immutable: true;
|
|
161
|
+
} ? D & Immutable : D;
|
|
162
|
+
/**
|
|
163
|
+
* Whether a component descriptor was declared `immutable: true` (readable by
|
|
164
|
+
* queries, replaced only with `commands.insert(...)`).
|
|
165
|
+
*/
|
|
166
|
+
export declare const isImmutable: (descriptor: Descriptor.Any) => descriptor is Descriptor.Any & Immutable;
|
|
135
167
|
/**
|
|
136
168
|
* Type-level helpers for working with descriptors.
|
|
137
169
|
*/
|
|
@@ -166,9 +198,11 @@ export declare namespace Descriptor {
|
|
|
166
198
|
* @example
|
|
167
199
|
* ```ts
|
|
168
200
|
* const Position = Descriptor.Component<{ x: number; y: number }>()("Position")
|
|
201
|
+
* // What an entity is, replaced with commands.insert and never written by a query:
|
|
202
|
+
* const EnemyKind = Descriptor.Component<"grunt" | "boss">()("EnemyKind", { immutable: true })
|
|
169
203
|
* ```
|
|
170
204
|
*/
|
|
171
|
-
export declare const Component: <Value>() => <const Name extends string>(name: Name) => Descriptor<"component", Name, Value>;
|
|
205
|
+
export declare const Component: <Value>() => <const Name extends string, const Options extends ComponentOptions = {}>(name: Name, options?: Options) => WithComponentOptions<Descriptor<"component", Name, Value>, Options>;
|
|
172
206
|
/**
|
|
173
207
|
* Defines a component descriptor that also knows how to validate raw values.
|
|
174
208
|
*
|
|
@@ -182,7 +216,7 @@ export declare const Component: <Value>() => <const Name extends string>(name: N
|
|
|
182
216
|
* const Position = Descriptor.ConstructedComponent(Vector2)("Position")
|
|
183
217
|
* ```
|
|
184
218
|
*/
|
|
185
|
-
export declare const ConstructedComponent: <Value, Raw, Error, Constructor extends {} = {}>(constructor: ResultConstructor<Value, Raw, Error> & Constructor) => <const Name extends string>(name: Name) => ConstructedFor<"component", Name, Value, Raw, Error, Constructor>;
|
|
219
|
+
export declare const ConstructedComponent: <Value, Raw, Error, Constructor extends {} = {}>(constructor: ResultConstructor<Value, Raw, Error> & Constructor) => <const Name extends string, const Options extends ComponentOptions = {}>(name: Name, options?: Options) => WithComponentOptions<ConstructedFor<"component", Name, Value, Raw, Error, Constructor>, Options>;
|
|
186
220
|
/**
|
|
187
221
|
* Defines a component descriptor that snapshots skip.
|
|
188
222
|
*
|
|
@@ -194,7 +228,7 @@ export declare const ConstructedComponent: <Value, Raw, Error, Constructor exten
|
|
|
194
228
|
* const SpriteRef = Descriptor.TransientComponent<{ frame: number }>()("SpriteRef")
|
|
195
229
|
* ```
|
|
196
230
|
*/
|
|
197
|
-
export declare const TransientComponent: <Value>() => <const Name extends string>(name: Name) => TransientDescriptor<"component", Name, Value>;
|
|
231
|
+
export declare const TransientComponent: <Value>() => <const Name extends string, const Options extends ComponentOptions = {}>(name: Name, options?: Options) => WithComponentOptions<TransientDescriptor<"component", Name, Value>, Options>;
|
|
198
232
|
/**
|
|
199
233
|
* Defines a marker component: no data, only presence (`[Player, {}]`).
|
|
200
234
|
*
|
|
@@ -208,48 +242,55 @@ export declare const TransientComponent: <Value>() => <const Name extends string
|
|
|
208
242
|
* ```
|
|
209
243
|
*/
|
|
210
244
|
export declare const Tag: <const Name extends string>(name: Name) => DecodableDescriptor<"component", Name, {}, {}, DecodeModule.DecodeError>;
|
|
211
|
-
/** One state of a {@link
|
|
212
|
-
export type
|
|
245
|
+
/** One state of a {@link EntityState} component: a string or number literal. */
|
|
246
|
+
export type EntityStateValue = string | number;
|
|
213
247
|
/**
|
|
214
|
-
* The allowed moves of a {@link
|
|
248
|
+
* The allowed moves of a {@link EntityState} component: for every state, the
|
|
215
249
|
* states it may move to (`[]` for a state with no way out).
|
|
216
250
|
*/
|
|
217
|
-
export type
|
|
251
|
+
export type EntityStateTransitions<States extends readonly [EntityStateValue, ...Array<EntityStateValue>]> = {
|
|
218
252
|
readonly [From in States[number]]: ReadonlyArray<States[number]>;
|
|
219
253
|
};
|
|
220
254
|
/**
|
|
221
255
|
* A component whose value is one of a closed set of states, with an optional
|
|
222
|
-
* graph of allowed moves. Built with {@link
|
|
256
|
+
* graph of allowed moves. Built with {@link EntityState}.
|
|
223
257
|
*/
|
|
224
|
-
export interface
|
|
258
|
+
export interface EntityStateDescriptor<out Name extends string, in out States extends readonly [EntityStateValue, ...Array<EntityStateValue>], in out Transitions extends EntityStateTransitions<States> | undefined> extends DecodableDescriptor<"component", Name, States[number], States[number], DecodeModule.DecodeError> {
|
|
225
259
|
readonly states: States;
|
|
226
260
|
readonly transitions: Transitions;
|
|
227
261
|
}
|
|
228
262
|
/**
|
|
229
|
-
* Defines a state component
|
|
230
|
-
* snapshots reject unknown states),
|
|
231
|
-
* (storage, change detection, rollback, traces).
|
|
263
|
+
* Defines a per-entity state: a component whose value is one of `states`,
|
|
264
|
+
* validated (so snapshots reject unknown states), that behaves like any other
|
|
265
|
+
* component (storage, change detection, rollback, traces).
|
|
266
|
+
*
|
|
267
|
+
* Use this when each entity has its own state: an enemy's attack windup, a
|
|
268
|
+
* door's open/closed, a unit's AI mode. Use `Game.StateMachine(...)` instead
|
|
269
|
+
* for one game-wide mode (menu, playing, paused, game over): machines change
|
|
270
|
+
* only at `applyStateTransitions(...)`, run `onEnter`/`onExit` schedules, and
|
|
271
|
+
* gate systems with `Game.Condition.inState(...)`. An entity state does none
|
|
272
|
+
* of that; it is data on an entity.
|
|
232
273
|
*
|
|
233
274
|
* With `transitions`, its write cell gains `transition(from, to)`: the pair
|
|
234
275
|
* is checked against the graph at compile time, and at runtime the move
|
|
235
|
-
* happens only if the current state is still `from`, otherwise it returns
|
|
236
|
-
* `
|
|
276
|
+
* happens only if the current state is still `from`, otherwise it returns an
|
|
277
|
+
* `EntityStateMismatch` failure. Transitions are ordinary component writes:
|
|
237
278
|
* immediate, visible to later systems, rolled back with a failed system.
|
|
238
279
|
*
|
|
239
280
|
* @example
|
|
240
281
|
* ```ts
|
|
241
|
-
* const
|
|
282
|
+
* const Attack = Descriptor.EntityState("Attack", ["ready", "windup", "active"] as const, {
|
|
242
283
|
* transitions: { ready: ["windup"], windup: ["active", "ready"], active: ["ready"] }
|
|
243
284
|
* })
|
|
244
|
-
* // in a system with a write slot `
|
|
245
|
-
* const moved = data.
|
|
285
|
+
* // in a system with a write slot `attack`:
|
|
286
|
+
* const moved = data.attack.transition("windup", "active") // "ready" -> "active" does not compile
|
|
246
287
|
* ```
|
|
247
288
|
*/
|
|
248
|
-
export declare const
|
|
289
|
+
export declare const EntityState: <const Name extends string, const States extends readonly [EntityStateValue, ...Array<EntityStateValue>], const Transitions extends EntityStateTransitions<States> | undefined = undefined>(name: Name, states: States, options?: {
|
|
249
290
|
readonly transitions: Transitions & { readonly [Key in Exclude<keyof Transitions, States[number]>]: never; };
|
|
250
|
-
}) =>
|
|
251
|
-
/** Whether a descriptor was built with {@link
|
|
252
|
-
export declare const
|
|
291
|
+
}) => EntityStateDescriptor<Name, States, Transitions>;
|
|
292
|
+
/** Whether a descriptor was built with {@link EntityState}. */
|
|
293
|
+
export declare const isEntityState: (descriptor: Descriptor.Any) => descriptor is EntityStateDescriptor<string, readonly [EntityStateValue, ...Array<EntityStateValue>], EntityStateTransitions<readonly [EntityStateValue, ...Array<EntityStateValue>]> | undefined>;
|
|
253
294
|
/**
|
|
254
295
|
* Defines a resource descriptor.
|
|
255
296
|
*
|
|
@@ -391,7 +432,9 @@ export declare function constructorOf<D extends Descriptor.Any>(descriptor: D):
|
|
|
391
432
|
* `related` is the reverse collection maintained by the runtime.
|
|
392
433
|
*
|
|
393
434
|
* Use hierarchy when the relationship must support ordered children,
|
|
394
|
-
* ancestor/descendant traversal, and linked recursive despawn.
|
|
435
|
+
* ancestor/descendant traversal, and linked recursive despawn. Use
|
|
436
|
+
* `Game.EntityScope(...)` instead when entities only share a lifetime (a
|
|
437
|
+
* level, a menu) and need no tree, order, or traversal.
|
|
395
438
|
*/
|
|
396
439
|
export declare const Hierarchy: typeof RelationModule.Hierarchy;
|
|
397
440
|
/**
|
package/dist/Descriptor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Descriptor.d.ts","sourceRoot":"","sources":["../src/Descriptor.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"Descriptor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AAE,OAAO,KAAK,OAAO,aAAa,EAAE,MAAM,CAAC,OAAO,EAAE,OAAO,CAGhI,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,eAAgB,UAAU,CAAC,GAAG,KAAG,UAAU,IAAI,UAAU,CAAC,cAC/C,CAAA;AAEtC;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,UAAU,CAAC,cAAc,EAC/D,UAAU,EAAE,CAAC,GACZ,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAA;AAC5B,wBAAgB,aAAa,CAAC,CAAC,SAAS,UAAU,CAAC,GAAG,EACpD,UAAU,EAAE,CAAC,GACZ,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,SAAS,CAAA;AAOxC;;;;;;;;;;GAUG;AACH,eAAO,MAAM,SAAS,iCAA2B,CAAA;AAEjD;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,gCAA0B,CAAA;AAC/C,OAAO,KAAK,YAAY,MAAM,aAAa,CAAA;AAC3C,OAAO,KAAK,cAAc,MAAM,eAAe,CAAA"}
|
package/dist/Descriptor.js
CHANGED
|
@@ -5,6 +5,12 @@ const descriptorTypeId = "~ritmo/Descriptor";
|
|
|
5
5
|
const descriptorConstructionTypeId = "~ritmo/DescriptorConstruction";
|
|
6
6
|
const descriptorDecodeTypeId = "~ritmo/DescriptorDecode";
|
|
7
7
|
const descriptorConstruction = Symbol("ritmo/DescriptorConstruction");
|
|
8
|
+
const applyComponentOptions = (descriptor, options) => options?.immutable === true ? { ...descriptor, immutable: true } : descriptor;
|
|
9
|
+
/**
|
|
10
|
+
* Whether a component descriptor was declared `immutable: true` (readable by
|
|
11
|
+
* queries, replaced only with `commands.insert(...)`).
|
|
12
|
+
*/
|
|
13
|
+
export const isImmutable = (descriptor) => "immutable" in descriptor && descriptor.immutable === true;
|
|
8
14
|
/**
|
|
9
15
|
* Internal descriptor constructor shared by all descriptor helpers.
|
|
10
16
|
*
|
|
@@ -40,9 +46,11 @@ const makeConstructedDescriptor = (kind, name, constructor) => ({
|
|
|
40
46
|
* @example
|
|
41
47
|
* ```ts
|
|
42
48
|
* const Position = Descriptor.Component<{ x: number; y: number }>()("Position")
|
|
49
|
+
* // What an entity is, replaced with commands.insert and never written by a query:
|
|
50
|
+
* const EnemyKind = Descriptor.Component<"grunt" | "boss">()("EnemyKind", { immutable: true })
|
|
43
51
|
* ```
|
|
44
52
|
*/
|
|
45
|
-
export const Component = () => (name) => makeDescriptor("component", name);
|
|
53
|
+
export const Component = () => (name, options) => applyComponentOptions(makeDescriptor("component", name), options);
|
|
46
54
|
/**
|
|
47
55
|
* Defines a component descriptor that also knows how to validate raw values.
|
|
48
56
|
*
|
|
@@ -56,7 +64,7 @@ export const Component = () => (name) => makeDescriptor("component", name);
|
|
|
56
64
|
* const Position = Descriptor.ConstructedComponent(Vector2)("Position")
|
|
57
65
|
* ```
|
|
58
66
|
*/
|
|
59
|
-
export const ConstructedComponent = (constructor) => (name) => makeConstructedDescriptor("component", name, constructor);
|
|
67
|
+
export const ConstructedComponent = (constructor) => (name, options) => applyComponentOptions(makeConstructedDescriptor("component", name, constructor), options);
|
|
60
68
|
/**
|
|
61
69
|
* Defines a component descriptor that snapshots skip.
|
|
62
70
|
*
|
|
@@ -68,7 +76,7 @@ export const ConstructedComponent = (constructor) => (name) => makeConstructedDe
|
|
|
68
76
|
* const SpriteRef = Descriptor.TransientComponent<{ frame: number }>()("SpriteRef")
|
|
69
77
|
* ```
|
|
70
78
|
*/
|
|
71
|
-
export const TransientComponent = () => (name) => makeTransientDescriptor("component", name);
|
|
79
|
+
export const TransientComponent = () => (name, options) => applyComponentOptions(makeTransientDescriptor("component", name), options);
|
|
72
80
|
/**
|
|
73
81
|
* Defines a marker component: no data, only presence (`[Player, {}]`).
|
|
74
82
|
*
|
|
@@ -83,32 +91,39 @@ export const TransientComponent = () => (name) => makeTransientDescriptor("compo
|
|
|
83
91
|
*/
|
|
84
92
|
export const Tag = (name) => ConstructedComponent(DecodeModule.struct({}))(name);
|
|
85
93
|
/**
|
|
86
|
-
* Defines a state component
|
|
87
|
-
* snapshots reject unknown states),
|
|
88
|
-
* (storage, change detection, rollback, traces).
|
|
94
|
+
* Defines a per-entity state: a component whose value is one of `states`,
|
|
95
|
+
* validated (so snapshots reject unknown states), that behaves like any other
|
|
96
|
+
* component (storage, change detection, rollback, traces).
|
|
97
|
+
*
|
|
98
|
+
* Use this when each entity has its own state: an enemy's attack windup, a
|
|
99
|
+
* door's open/closed, a unit's AI mode. Use `Game.StateMachine(...)` instead
|
|
100
|
+
* for one game-wide mode (menu, playing, paused, game over): machines change
|
|
101
|
+
* only at `applyStateTransitions(...)`, run `onEnter`/`onExit` schedules, and
|
|
102
|
+
* gate systems with `Game.Condition.inState(...)`. An entity state does none
|
|
103
|
+
* of that; it is data on an entity.
|
|
89
104
|
*
|
|
90
105
|
* With `transitions`, its write cell gains `transition(from, to)`: the pair
|
|
91
106
|
* is checked against the graph at compile time, and at runtime the move
|
|
92
|
-
* happens only if the current state is still `from`, otherwise it returns
|
|
93
|
-
* `
|
|
107
|
+
* happens only if the current state is still `from`, otherwise it returns an
|
|
108
|
+
* `EntityStateMismatch` failure. Transitions are ordinary component writes:
|
|
94
109
|
* immediate, visible to later systems, rolled back with a failed system.
|
|
95
110
|
*
|
|
96
111
|
* @example
|
|
97
112
|
* ```ts
|
|
98
|
-
* const
|
|
113
|
+
* const Attack = Descriptor.EntityState("Attack", ["ready", "windup", "active"] as const, {
|
|
99
114
|
* transitions: { ready: ["windup"], windup: ["active", "ready"], active: ["ready"] }
|
|
100
115
|
* })
|
|
101
|
-
* // in a system with a write slot `
|
|
102
|
-
* const moved = data.
|
|
116
|
+
* // in a system with a write slot `attack`:
|
|
117
|
+
* const moved = data.attack.transition("windup", "active") // "ready" -> "active" does not compile
|
|
103
118
|
* ```
|
|
104
119
|
*/
|
|
105
|
-
export const
|
|
120
|
+
export const EntityState = (name, states, options) => ({
|
|
106
121
|
...makeConstructedDescriptor("component", name, DecodeModule.literal(...states)),
|
|
107
122
|
states,
|
|
108
123
|
transitions: options?.transitions
|
|
109
124
|
});
|
|
110
|
-
/** Whether a descriptor was built with {@link
|
|
111
|
-
export const
|
|
125
|
+
/** Whether a descriptor was built with {@link EntityState}. */
|
|
126
|
+
export const isEntityState = (descriptor) => "states" in descriptor;
|
|
112
127
|
/**
|
|
113
128
|
* Defines a resource descriptor.
|
|
114
129
|
*
|
|
@@ -235,7 +250,9 @@ export function constructorOf(descriptor) {
|
|
|
235
250
|
* `related` is the reverse collection maintained by the runtime.
|
|
236
251
|
*
|
|
237
252
|
* Use hierarchy when the relationship must support ordered children,
|
|
238
|
-
* ancestor/descendant traversal, and linked recursive despawn.
|
|
253
|
+
* ancestor/descendant traversal, and linked recursive despawn. Use
|
|
254
|
+
* `Game.EntityScope(...)` instead when entities only share a lifetime (a
|
|
255
|
+
* level, a menu) and need no tree, order, or traversal.
|
|
239
256
|
*/
|
|
240
257
|
export const Hierarchy = RelationModule.Hierarchy;
|
|
241
258
|
/**
|
package/dist/Descriptor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Descriptor.js","sourceRoot":"","sources":["../src/Descriptor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Descriptor.js","sourceRoot":"","sources":["../src/Descriptor.ts"],"names":[],"mappings":"AA2DA;;GAEG;AACH,MAAM,gBAAgB,GAAqB,mBAAmB,CAAA;AAC9D,MAAM,4BAA4B,GAAiC,+BAA+B,CAAA;AAClG,MAAM,sBAAsB,GAA2B,yBAAyB,CAAA;AAChF,MAAM,sBAAsB,GAAG,MAAM,CAAC,8BAA8B,CAAC,CAAA;AAmIrE,MAAM,qBAAqB,GAAG,CAAmB,UAAa,EAAE,OAAqC,EAAK,EAAE,CAC1G,OAAO,EAAE,SAAS,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,CA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O,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAA;AAC/C,CAAC,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,UAAqC,EAAoE,EAAE;IACnI,MAAM,WAAW,GAAG,UAAU,CAAC,sBAAsB,CAA6E,CAAA;IAClI,OAAO,OAAO,WAAW,CAAC,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM,CAAA;AAC3F,CAAC,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,UAA0B,EAA2C,EAAE,CACpG,sBAAsB,IAAI,UAAU,CAAA;AAatC,MAAM,UAAU,aAAa,CAC3B,UAAa;IAEb,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,SAAS,CAA0C,CAAA;AAC/H,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,cAAc,CAAC,SAAS,CAAA;AAEjD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,cAAc,CAAC,QAAQ,CAAA;AAC/C,OAAO,KAAK,YAAY,MAAM,aAAa,CAAA;AAC3C,OAAO,KAAK,cAAc,MAAM,eAAe,CAAA;AAC/C,OAAO,KAAK,YAAY,MAAM,aAAa,CAAA"}
|
package/dist/Entity.d.ts
CHANGED
|
@@ -55,7 +55,8 @@ import * as Result from "./Result.ts";
|
|
|
55
55
|
* @example
|
|
56
56
|
* ```ts
|
|
57
57
|
* const handle = Game.Entity.handle(playerId, Player)
|
|
58
|
-
*
|
|
58
|
+
* // `players` is a query the system declares: queries: { players: PlayerQuery }
|
|
59
|
+
* const resolved = queries.players.getHandle(handle)
|
|
59
60
|
* if (!resolved.ok) return
|
|
60
61
|
* ```
|
|
61
62
|
*/
|
|
@@ -148,11 +149,23 @@ export type StagedComponent = readonly [Descriptor<"component", string, any>, un
|
|
|
148
149
|
*
|
|
149
150
|
* Query execution is the main source of `EntityRef` values.
|
|
150
151
|
*/
|
|
151
|
-
export interface EntityRef<S extends Schema.Any, out P extends ComponentProof, Root = unknown> {
|
|
152
|
+
export interface EntityRef<S extends Schema.Any, out P extends ComponentProof, Root = unknown, out Proves = unknown, out Lacks = never> {
|
|
152
153
|
/**
|
|
153
154
|
* Runtime tag for debugging and pattern matching.
|
|
154
155
|
*/
|
|
155
156
|
readonly kind: "EntityRef";
|
|
157
|
+
/**
|
|
158
|
+
* The component descriptors the query that produced this ref proves (its
|
|
159
|
+
* required slots and `with`): what `commands.despawn`, `insert`, and
|
|
160
|
+
* `remove` check. Type-level only.
|
|
161
|
+
*/
|
|
162
|
+
readonly __proves?: (_: never) => Proves;
|
|
163
|
+
/**
|
|
164
|
+
* The component descriptors the producing query proves absent (its
|
|
165
|
+
* `without`): what `commands.remove` checks against `Schema.requires`.
|
|
166
|
+
* Type-level only.
|
|
167
|
+
*/
|
|
168
|
+
readonly __lacks?: (_: never) => Lacks;
|
|
156
169
|
/**
|
|
157
170
|
* The schema-bound entity identity.
|
|
158
171
|
*/
|
|
@@ -169,11 +182,15 @@ export interface EntityRef<S extends Schema.Any, out P extends ComponentProof, R
|
|
|
169
182
|
* `P` tracks readable components and `W` tracks the writable subset. This keeps
|
|
170
183
|
* mutation capabilities explicit in query results.
|
|
171
184
|
*/
|
|
172
|
-
export interface EntityMut<S extends Schema.Any, out P extends ComponentProof, out W extends ComponentProof, Root = unknown> {
|
|
185
|
+
export interface EntityMut<S extends Schema.Any, out P extends ComponentProof, out W extends ComponentProof, Root = unknown, out Proves = unknown, out Lacks = never> {
|
|
173
186
|
/**
|
|
174
187
|
* Runtime tag for debugging and pattern matching.
|
|
175
188
|
*/
|
|
176
189
|
readonly kind: "EntityMut";
|
|
190
|
+
/** The component descriptors the producing query proves; see `EntityRef`. */
|
|
191
|
+
readonly __proves?: (_: never) => Proves;
|
|
192
|
+
/** The component descriptors the producing query proves absent; see `EntityRef`. */
|
|
193
|
+
readonly __lacks?: (_: never) => Lacks;
|
|
177
194
|
/**
|
|
178
195
|
* The schema-bound entity identity.
|
|
179
196
|
*/
|
|
@@ -213,7 +230,7 @@ export type HandleTarget<S extends Schema.Any, Root = unknown> = EntityId<S, Roo
|
|
|
213
230
|
* Converts a current entity into a durable handle for storage.
|
|
214
231
|
*
|
|
215
232
|
* The handle is storage-safe, not a proof of liveness: resolve it later with
|
|
216
|
-
* `
|
|
233
|
+
* `queries.x.getHandle(...)` (through a declared query), which fails explicitly when the entity is gone.
|
|
217
234
|
*
|
|
218
235
|
* Pass an `intent` component when later code assumes a role such as "player"
|
|
219
236
|
* or "damage source". An intent does not prove the component is still present;
|
|
@@ -239,7 +256,7 @@ export interface InvalidHandle {
|
|
|
239
256
|
* handles, so restoring validates them like any other value.
|
|
240
257
|
*
|
|
241
258
|
* A handle only names an entity; it never proves the entity exists. Resolving
|
|
242
|
-
* it with `
|
|
259
|
+
* it with `queries.x.getHandle(...)` (through a declared query) stays the checked step, so any positive
|
|
243
260
|
* integer id decodes. Object-shaped handles and other non-numeric values
|
|
244
261
|
* are rejected.
|
|
245
262
|
*
|
package/dist/Entity.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Entity.d.ts","sourceRoot":"","sources":["../src/Entity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAChD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AACnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAEr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for storage.
|
|
23
23
|
*
|
|
24
24
|
* The handle is storage-safe, not a proof of liveness: resolve it later with
|
|
25
|
-
* `
|
|
25
|
+
* `queries.x.getHandle(...)` (through a declared query), which fails explicitly when the entity is gone.
|
|
26
26
|
*
|
|
27
27
|
* Pass an `intent` component when later code assumes a role such as "player"
|
|
28
28
|
* or "damage source". An intent does not prove the component is still present;
|
|
@@ -41,7 +41,7 @@ export const handle = (target, _intent) => makeHandle(typeof target === "number"
|
|
|
41
41
|
* handles, so restoring validates them like any other value.
|
|
42
42
|
*
|
|
43
43
|
* A handle only names an entity; it never proves the entity exists. Resolving
|
|
44
|
-
* it with `
|
|
44
|
+
* it with `queries.x.getHandle(...)` (through a declared query) stays the checked step, so any positive
|
|
45
45
|
* integer id decodes. Object-shaped handles and other non-numeric values
|
|
46
46
|
* are rejected.
|
|
47
47
|
*
|
package/dist/Entity.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Entity.js","sourceRoot":"","sources":["../src/Entity.ts"],"names":[],"mappings":"AAwCA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"Entity.js","sourceRoot":"","sources":["../src/Entity.ts"],"names":[],"mappings":"AAwCA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAyBrC;;GAEG;AACH,MAAM,YAAY,GAAiB,eAAe,CAAA;AAClD,MAAM,kBAAkB,GAAG,qBAA8B,CAAA;AAsKzD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAuC,KAAa,EAAqB,EAAE,CACrG,KAA0B,CAAA;AAE5B;;;;;GAKG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAGxB,KAAa,EAAwB,EAAE,CACvC,KAA6B,CAAA;AAU/B;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAKpB,MAA6B,EAC7B,OAAgB,EACM,EAAE,CACxB,UAAU,CAAe,OAAO,MA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|
|
7
7
|
* build scenes without teaching the ECS runtime about menus, levels, overlays,
|
|
8
8
|
* or any other game-specific scene model.
|
|
9
9
|
*
|
|
10
|
+
* Use a scope when a set of entities shares one lifetime and nothing else: a
|
|
11
|
+
* level's walls, a menu's buttons. Membership is flat, unordered, and not
|
|
12
|
+
* queryable. Use `Descriptor.Hierarchy(...)` instead when entities form a
|
|
13
|
+
* parent-child tree: ordered children, `lookup.parent` / `descendants`
|
|
14
|
+
* traversal, and children despawned with their parent.
|
|
15
|
+
*
|
|
16
|
+
* A scope whose lifetime is a game state declares it:
|
|
17
|
+
* `Game.EntityScope(name, { despawnOnExit: [Flow, "Playing"] })` despawns
|
|
18
|
+
* every member when `applyStateTransitions(...)` commits that state change,
|
|
19
|
+
* with no system, permission, or marker to place.
|
|
20
|
+
*
|
|
10
21
|
* @module EntityScope
|
|
11
22
|
* @docGroup core
|
|
12
23
|
*/
|
|
@@ -15,8 +26,22 @@ export interface EntityScope<out Name extends string = string, out Root = unknow
|
|
|
15
26
|
readonly kind: "entityScope";
|
|
16
27
|
readonly name: Name;
|
|
17
28
|
readonly key: symbol;
|
|
29
|
+
/** State changes that despawn every member, applied by `applyStateTransitions(...)`. */
|
|
30
|
+
readonly despawnOn: ReadonlyArray<Trigger>;
|
|
18
31
|
readonly __schemaRoot?: Root | undefined;
|
|
19
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* One state change that despawns a scope: leaving (`exit`) or entering
|
|
35
|
+
* (`enter`) `state` of `machine`.
|
|
36
|
+
*/
|
|
37
|
+
export interface Trigger {
|
|
38
|
+
readonly phase: "enter" | "exit";
|
|
39
|
+
readonly machine: {
|
|
40
|
+
readonly key: symbol;
|
|
41
|
+
readonly name: string;
|
|
42
|
+
};
|
|
43
|
+
readonly state: string | number;
|
|
44
|
+
}
|
|
20
45
|
/** Type-level helpers for entity scopes. */
|
|
21
46
|
export declare namespace EntityScope {
|
|
22
47
|
type Any = EntityScope<string, any>;
|
|
@@ -29,7 +54,7 @@ export declare namespace EntityScope {
|
|
|
29
54
|
* Normal game code should use `Game.EntityScope(...)` so the returned token is
|
|
30
55
|
* branded to that game's root.
|
|
31
56
|
*/
|
|
32
|
-
export declare const make: <const Name extends string, Root = unknown>(name: Name) => EntityScope<Name, Root>;
|
|
57
|
+
export declare const make: <const Name extends string, Root = unknown>(name: Name, despawnOn?: ReadonlyArray<Trigger>) => EntityScope<Name, Root>;
|
|
33
58
|
/** The storage key of the scope named `name`: the same for every scope value of that name. */
|
|
34
59
|
export declare const keyOf: (name: string) => symbol;
|
|
35
60
|
/** The name of the scope behind a storage key made by {@link keyOf}. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityScope.d.ts","sourceRoot":"","sources":["../src/EntityScope.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"EntityScope.d.ts","sourceRoot":"","sources":["../src/EntityScope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,mEAAmE;AACnE,MAAM,WAAW,WAAW,CAC1B,GAAG,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM,EAChC,GAAG,CAAC,IAAI,GAAG,OAAO;IAElB,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAA;IAC5B,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;IACnB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,wFAAwF;IACxF,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC,OAAO,CAAC,CAAA;IAC1C,QAAQ,CAAC,YAAY,CAAC,EAAE,IAAI,GAAG,SAAS,CAAA;CACzC;AAED;;;GAGG;AACH,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAAA;IAChC,QAAQ,CAAC,OAAO,EAAE;QAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;IACjE,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;CAChC;AAED,4CAA4C;AAC5C,yBAAiB,WAAW,CAAC;IAC3B,KAAY,GAAG,GAAG,WAAW,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC1C,KAAY,IAAI,CAAC,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC,MAAM,CAAC,CAAA;IAC3C,KAAY,IAAI,CAAC,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,WAAW,CAAC,MAAM,EAAE,MAAM,IAAI,CAAC,GAAG,IAAI,GAAG,KAAK,CAAA;CAC3F;AAED;;;;;GAKG;AACH,eAAO,MAAM,IAAI,GAAI,KAAK,CAAC,IAAI,SAAS,MAAM,EAAE,IAAI,GAAG,OAAO,QACtD,IAAI,cACC,aAAa,CAAC,OAAO,CAAC,KAChC,WAAW,CAAC,IAAI,EAAE,IAAI,CAKvB,CAAA;AAIF,8FAA8F;AAC9F,eAAO,MAAM,KAAK,SAAU,MAAM,KAAG,MAA2C,CAAA;AAEhF,wEAAwE;AACxE,eAAO,MAAM,MAAM,QAAS,MAAM,KAAG,MAAM,GAAG,SAG7C,CAAA"}
|
package/dist/EntityScope.js
CHANGED
|
@@ -7,6 +7,17 @@
|
|
|
7
7
|
* build scenes without teaching the ECS runtime about menus, levels, overlays,
|
|
8
8
|
* or any other game-specific scene model.
|
|
9
9
|
*
|
|
10
|
+
* Use a scope when a set of entities shares one lifetime and nothing else: a
|
|
11
|
+
* level's walls, a menu's buttons. Membership is flat, unordered, and not
|
|
12
|
+
* queryable. Use `Descriptor.Hierarchy(...)` instead when entities form a
|
|
13
|
+
* parent-child tree: ordered children, `lookup.parent` / `descendants`
|
|
14
|
+
* traversal, and children despawned with their parent.
|
|
15
|
+
*
|
|
16
|
+
* A scope whose lifetime is a game state declares it:
|
|
17
|
+
* `Game.EntityScope(name, { despawnOnExit: [Flow, "Playing"] })` despawns
|
|
18
|
+
* every member when `applyStateTransitions(...)` commits that state change,
|
|
19
|
+
* with no system, permission, or marker to place.
|
|
20
|
+
*
|
|
10
21
|
* @module EntityScope
|
|
11
22
|
* @docGroup core
|
|
12
23
|
*/
|
|
@@ -16,10 +27,11 @@
|
|
|
16
27
|
* Normal game code should use `Game.EntityScope(...)` so the returned token is
|
|
17
28
|
* branded to that game's root.
|
|
18
29
|
*/
|
|
19
|
-
export const make = (name) => ({
|
|
30
|
+
export const make = (name, despawnOn = []) => ({
|
|
20
31
|
kind: "entityScope",
|
|
21
32
|
name,
|
|
22
|
-
key: keyOf(name)
|
|
33
|
+
key: keyOf(name),
|
|
34
|
+
despawnOn
|
|
23
35
|
});
|
|
24
36
|
const keyPrefix = "ritmo/entityScope/";
|
|
25
37
|
/** The storage key of the scope named `name`: the same for every scope value of that name. */
|
package/dist/EntityScope.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityScope.js","sourceRoot":"","sources":["../src/EntityScope.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"EntityScope.js","sourceRoot":"","sources":["../src/EntityScope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAgCH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,CAClB,IAAU,EACV,SAAS,GAA2B,EAAE,EACb,EAAE,CAAC,CAAC;IAC7B,IAAI,EAAE,aAAa;IACnB,IAAI;IACJ,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC;IAChB,SAAS;CACV,CAAC,CAAA;AAEF,MAAM,SAAS,GAAG,oBAAoB,CAAA;AAEtC,8FAA8F;AAC9F,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,SAAS,GAAG,IAAI,EAAE,CAAC,CAAA;AAEhF,wEAAwE;AACxE,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,GAAW,EAAsB,EAAE;IACxD,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;IACtC,OAAO,WAAW,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;AAC7F,CAAC,CAAA"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The host's wall clock, as an injected contract.
|
|
3
|
+
*
|
|
4
|
+
* Core and the generic devtools modules never read a platform clock
|
|
5
|
+
* (`performance`, `Date`) themselves: whatever measures host time (debug
|
|
6
|
+
* trace durations, session timings, replay windows) takes a `HostClock`.
|
|
7
|
+
* Platform packages provide implementations (`BrowserHostClock.make(window)`
|
|
8
|
+
* in the browser package); `standard` works in every JavaScript engine, and
|
|
9
|
+
* `test()` is a manual clock for deterministic tests.
|
|
10
|
+
*
|
|
11
|
+
* Host time is for measuring the host (how long a tick took), never for game
|
|
12
|
+
* logic: simulation time is a resource the schedule advances.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const runtime = Game.Runtime.make({ services, debug: { hostClock: HostClock.standard } })
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @module HostClock
|
|
20
|
+
* @docGroup runtime
|
|
21
|
+
*/
|
|
22
|
+
import * as Result from "./Result.ts";
|
|
23
|
+
/** A host clock: `now()` in milliseconds, from an arbitrary origin. */
|
|
24
|
+
export interface HostClock {
|
|
25
|
+
readonly now: () => number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* `Date.now`, which every JavaScript engine provides. Its readings can jump
|
|
29
|
+
* (the system clock is adjusted, or the device sleeps), so a duration
|
|
30
|
+
* computed from two readings can be negative: consumers clamp durations to
|
|
31
|
+
* 0. Prefer a monotonic platform clock when there is one
|
|
32
|
+
* (`BrowserHostClock.make(window)`).
|
|
33
|
+
*/
|
|
34
|
+
export declare const standard: HostClock;
|
|
35
|
+
/** `adjust` must leave a finite clock reading and never move backwards. */
|
|
36
|
+
export interface InvalidAdjustment {
|
|
37
|
+
readonly _tag: "InvalidAdjustment";
|
|
38
|
+
readonly ms: number;
|
|
39
|
+
}
|
|
40
|
+
/** A manual clock for tests: starts at 0 and moves only through `adjust`. */
|
|
41
|
+
export interface TestHostClock extends HostClock {
|
|
42
|
+
/** Moves the clock forward by `ms` (0 or more). */
|
|
43
|
+
readonly adjust: (ms: number) => Result.Result<void, InvalidAdjustment>;
|
|
44
|
+
}
|
|
45
|
+
/** A test clock at 0. Every reading is the same until `adjust` moves it. */
|
|
46
|
+
export declare const test: () => TestHostClock;
|
|
47
|
+
/** A duration between two readings, clamped to 0 when the clock went backwards. */
|
|
48
|
+
export declare const elapsed: (from: number, to: number) => number;
|
|
49
|
+
//# sourceMappingURL=HostClock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HostClock.d.ts","sourceRoot":"","sources":["../src/HostClock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC,uEAAuE;AACvE,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,MAAM,CAAA;CAC3B;AAED;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,EAAE,SAAqC,CAAA;AAE5D,2EAA2E;AAC3E,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAA;IAClC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;CACpB;AAED,6EAA6E;AAC7E,MAAM,WAAW,aAAc,SAAQ,SAAS;IAC9C,mDAAmD;IACnD,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAA;CACxE;AAED,4EAA4E;AAC5E,eAAO,MAAM,IAAI,QAAO,aAUvB,CAAA;AAED,mFAAmF;AACnF,eAAO,MAAM,OAAO,SAAU,MAAM,MAAM,MAAM,KAAG,MAAgC,CAAA"}
|