threedog 2.2.2 → 2.3.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.
Files changed (194) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +4 -4
  3. package/core/assets/Animator.js +66 -12
  4. package/core/assets/ik.js +144 -18
  5. package/core/assets/maskLayer.js +377 -0
  6. package/core/assets/rootMotion.js +148 -0
  7. package/core/audio/Audio.js +100 -4
  8. package/core/base/errorCodes.js +6 -369
  9. package/core/base/errorCodesModules.js +378 -0
  10. package/core/engine/Engine.js +8 -5
  11. package/core/engine/Loading.js +8 -4
  12. package/core/engine/copies.js +1 -1
  13. package/core/engine/headlessLoad.js +15 -4
  14. package/core/engine/lifecycle.js +1 -0
  15. package/core/engine/loop.js +22 -3
  16. package/core/engine/moduleSlots.js +3 -7
  17. package/core/engine/modules.js +30 -58
  18. package/core/engine/startup.js +3 -3
  19. package/core/input/Input.js +7 -3
  20. package/core/input/inputContext.js +3 -2
  21. package/core/input/inputSeat.js +1 -1
  22. package/core/inspect/DebugOverrides.js +1 -1
  23. package/core/inspect/Describe.js +7 -2
  24. package/core/inspect/describeRender.js +4 -1
  25. package/core/inspect/describeText.js +2 -2
  26. package/core/inspect/metadata.generated.js +371 -74
  27. package/core/inspect/pictureMenu.js +2 -0
  28. package/core/inspect/pictureWriters.js +4 -3
  29. package/core/ops/Ops.js +9 -3
  30. package/core/ops/actor.js +10 -0
  31. package/core/ops/control.js +17 -6
  32. package/core/ops/holds.js +1 -1
  33. package/core/ops/opsAtomic.js +6 -1
  34. package/core/ops/opsGuard.js +2 -2
  35. package/core/ops/owned.js +37 -11
  36. package/core/ops/sharedPoint.js +5 -1
  37. package/core/ops/stacks.js +30 -7
  38. package/core/saves/Saves.js +0 -2
  39. package/core/saves/saveApply.js +7 -7
  40. package/core/saves/session.js +6 -3
  41. package/core/saves/stateReplace.js +71 -41
  42. package/core/scene/Rays.js +74 -26
  43. package/core/scene/gameLights.js +19 -11
  44. package/core/scene/sceneDelta.js +8 -4
  45. package/core/stream/chunkStream.js +21 -0
  46. package/core/stream/dirtyWatch.js +37 -0
  47. package/core/time/skip.js +9 -6
  48. package/core/time/time.js +72 -18
  49. package/docs/AI.md +22 -21
  50. package/docs/API.md +5 -4
  51. package/docs/CODEMAP.md +16 -10
  52. package/docs/COMMANDS.md +5 -5
  53. package/docs/CONVENTIONS.md +9 -25
  54. package/docs/api/ambience.md +1 -0
  55. package/docs/api/assets.md +10 -3
  56. package/docs/api/audio.md +5 -3
  57. package/docs/api/decals.md +16 -0
  58. package/docs/api/engine.md +1 -0
  59. package/docs/api/tools.md +3 -1
  60. package/docs/api/water.md +3 -0
  61. package/docs/recipes/09-materials-lights-models.md +15 -1
  62. package/docs/recipes/13-animation.md +51 -10
  63. package/docs/recipes/16-dev-bridge.md +1 -1
  64. package/docs/recipes/31-audio.md +15 -9
  65. package/docs/recipes/34-environment-lighting.md +11 -1
  66. package/docs/recipes/44-water-weather-hooks.md +1 -0
  67. package/examples/action/.threedog/content-index.json +1 -0
  68. package/examples/perf-island/.threedog/content-index.json +1 -0
  69. package/examples/plain-picture/.threedog/content-index.json +1 -0
  70. package/examples/rc2d/.threedog/content-index.json +1 -0
  71. package/examples/styletest/.threedog/content-index.json +1 -0
  72. package/examples/techniques/outlines-and-rim/main.js +1 -1
  73. package/examples/techniques/procedural-surface/main.js +1 -1
  74. package/examples/techniques/stylized-shading/main.js +1 -1
  75. package/examples/webgpu-tsl/.threedog/content-index.json +1 -0
  76. package/examples/world/.threedog/content-index.json +1 -0
  77. package/index.d.ts +6 -2
  78. package/index.js +3 -2
  79. package/llms.txt +11 -10
  80. package/modules/ambience/Ambience.js +97 -15
  81. package/modules/camera/common.js +18 -12
  82. package/modules/characters/Character.js +30 -3
  83. package/modules/characters/NPC.js +2 -5
  84. package/modules/characters/astar.js +45 -14
  85. package/modules/characters/movers/rapier.js +53 -41
  86. package/modules/characters/movers/simple.js +37 -24
  87. package/modules/characters/npcView.js +2 -2
  88. package/modules/characters/pathAsync.js +3 -3
  89. package/modules/collision/contract.js +2 -2
  90. package/modules/content/index.js +3 -0
  91. package/modules/content/models.js +11 -4
  92. package/modules/content/templates.js +11 -11
  93. package/modules/debug/DebugPanel.js +1 -0
  94. package/modules/decals/Decals.js +393 -0
  95. package/modules/decals/index.js +1 -0
  96. package/modules/gameplay/Container.js +2 -0
  97. package/modules/gameplay/Containers.js +17 -3
  98. package/modules/gameplay/Dialogue.js +1 -1
  99. package/modules/gameplay/Interactions.js +7 -6
  100. package/modules/gameplay/Inventory.js +5 -1
  101. package/modules/gameplay/Quests.js +4 -3
  102. package/modules/gameplay/inventoryOps.js +2 -2
  103. package/modules/gameplay/pickups.js +32 -12
  104. package/modules/gameplay/questSave.js +2 -2
  105. package/modules/grid/index.js +8 -2
  106. package/modules/hud/index.js +1 -1
  107. package/modules/level/heightfield.js +1 -0
  108. package/modules/level/index.js +3 -2
  109. package/modules/level/nodes.js +2 -1
  110. package/modules/lights/index.js +27 -4
  111. package/modules/lights/slots.js +33 -16
  112. package/modules/nav/contract.js +4 -4
  113. package/modules/nav/index.js +6 -2
  114. package/modules/net/Client.js +24 -11
  115. package/modules/net/Host.js +73 -20
  116. package/modules/net/index.js +33 -21
  117. package/modules/net/sync.js +38 -8
  118. package/modules/net/transports.js +7 -3
  119. package/modules/particles/Particles.js +11 -4
  120. package/modules/particles/contract.js +6 -6
  121. package/modules/particles/effect.js +0 -1
  122. package/modules/rigid/RigidBodies.js +69 -57
  123. package/modules/rigid/Vehicles.js +8 -7
  124. package/modules/rigid/ragdoll.js +4 -6
  125. package/modules/rigid/rapierCompat.js +90 -0
  126. package/modules/rigid/sync.js +2 -5
  127. package/modules/settings/Settings.js +10 -4
  128. package/modules/sky/Sky.js +10 -2
  129. package/modules/sky/environment.js +29 -13
  130. package/modules/sky/frame.js +2 -2
  131. package/modules/sky/shader.js +5 -2
  132. package/modules/sky/skyModule.js +2 -2
  133. package/modules/swarm/Swarm.js +3 -2
  134. package/modules/swarm/grid.js +12 -7
  135. package/modules/terrain/ChunkManager.js +16 -26
  136. package/modules/triggers/index.js +5 -6
  137. package/modules/vegetation/draw.js +62 -26
  138. package/modules/vegetation/groundChunks.js +8 -22
  139. package/modules/water/Water.js +152 -24
  140. package/modules/water/surface.js +43 -20
  141. package/modules/weather/weatherDraw.js +4 -1
  142. package/modules/world/World.js +21 -2
  143. package/modules/world/index.js +5 -0
  144. package/modules/world/persist.js +1 -0
  145. package/modules/world/records.js +3 -1
  146. package/modules/world/sim.js +3 -2
  147. package/modules/world/simFar.js +4 -2
  148. package/modules/world/state.js +7 -1
  149. package/package.json +2 -2
  150. package/presets.js +30 -0
  151. package/render/PostFX.js +24 -17
  152. package/render/backend.js +72 -31
  153. package/render/cascades.js +25 -14
  154. package/render/cascades.tsl.js +32 -21
  155. package/render/fogLook.js +2 -1
  156. package/render/fx/library.tsl.js +1 -1
  157. package/render/fx/particles.tsl.js +4 -18
  158. package/render/fx/pcss.tsl.js +2 -2
  159. package/render/fx/postWebGPU.tsl.js +47 -25
  160. package/render/fx/sky.tsl.js +6 -18
  161. package/render/fx/uniforms.tsl.js +16 -0
  162. package/render/fx/water.tsl.js +24 -5
  163. package/render/fxNumbers.js +2 -0
  164. package/render/impostor.tsl.js +10 -6
  165. package/render/lights.js +6 -6
  166. package/render/occlusion.js +17 -6
  167. package/render/patches.js +40 -28
  168. package/render/postWebGL.js +6 -4
  169. package/render/reflectionProbes.js +302 -0
  170. package/render/shaderErrors.js +18 -8
  171. package/render/shadowCache.tsl.js +10 -5
  172. package/render/shadows.js +70 -49
  173. package/render/threeCompat.js +166 -0
  174. package/types/core.d.ts +33 -3
  175. package/types/gameplay.d.ts +80 -0
  176. package/types/generated/core/audio/Audio.d.ts +18 -1
  177. package/types/generated/core/ops/Ops.d.ts +2 -1
  178. package/types/generated/core/ops/control.d.ts +7 -3
  179. package/types/generated/core/saves/session.d.ts +4 -1
  180. package/types/generated/modules/ambience/Ambience.d.ts +6 -0
  181. package/types/generated/modules/debug/DebugPanel.d.ts +1 -0
  182. package/types/generated/modules/grid/index.d.ts +27 -3
  183. package/types/generated/modules/net/index.d.ts +8 -3
  184. package/types/generated/modules/sky/Sky.d.ts +1 -0
  185. package/types/generated/modules/water/Water.d.ts +15 -0
  186. package/types/generated/modules/world/index.d.ts +5 -0
  187. package/types/generated/render/patches.d.ts +5 -0
  188. package/types/physics.d.ts +66 -9
  189. package/types/tsl.d.ts +2 -0
  190. package/types/world.d.ts +2 -0
  191. package/ui/Parts.js +3 -2
  192. package/docs/MIGRATING-0.7.md +0 -39
  193. package/docs/MIGRATING-0.8.md +0 -171
  194. package/modules/rigid/refresh.js +0 -10
@@ -5,9 +5,8 @@
5
5
  // engine.use(mine(), { replaces: 'inventory' }) unload the holder first (its tracked handles, slot, ctx.mod entries, drawing parts, dispose)
6
6
  // Why the slot is a shared point and not a module-name table: one owner registry for everything (describe().shared shows the holder beside
7
7
  // every shared value, ctx.track releases it with the rest), so there is no second mechanism to learn. Kept apart from modules.js only for size.
8
- import { DEV, fmt, closest, warnOnce, syncOnly } from '../base/validate.js';
8
+ import { DEV, fmt, closest, warnOnce } from '../base/validate.js';
9
9
  import { codedError, coded } from '../base/errorHints.js';
10
- import { reportError } from '../base/errors.js';
11
10
  import { PICTURE_SLOTS } from '../scene/pictureSlots.js';
12
11
 
13
12
  const STRINGS = {
@@ -92,7 +91,7 @@ export const slotMethods = {
92
91
  _refuseLate(slot, holder, gone, code) {
93
92
  const names = m => [...(m.requires ?? []), ...(Array.isArray(m.optional) ? m.optional : Object.keys(m.optional ?? {}))];
94
93
  const users = [...this.modules.values()].filter(m => !gone.has(m.name) && names(m).some(n => n === slot || n === holder)).map(m => m.name);
95
- const why = users.length ? `${users.join(', ')} already use it` : this.ready || this._starting ? 'the game has started' : null;
94
+ const why = users.length ? `${users.join(', ')} already use it` : this.phase !== 'constructed' ? 'the game has started' : null;
96
95
  if (why) throw codedError(code, fmt(STRINGS.tooLate, { slot, why }));
97
96
  },
98
97
  /**
@@ -131,10 +130,7 @@ export const slotMethods = {
131
130
  */
132
131
  _unuse(name, swapping = false) {
133
132
  const m = this.modules.get(name);
134
- this._dropTracked(name);
135
- try { syncOnly(m.dispose?.(this), `dispose() of module ${name}`, true); } catch (err) { reportError(this, err, fmt(STRINGS.unuse, { name }), { soft: true }); }
136
- this._picture?.partGone(m, swapping);
137
- this.modules.delete(name); this._modState.delete(name); this._modInst.delete(name); delete this[name];
133
+ this._teardownModule(m, { keepSave: true, where: fmt(STRINGS.unuse, { name }), partGone: true, swapping });
138
134
  this._sortHooks();
139
135
  return m;
140
136
  },
@@ -1,51 +1,9 @@
1
- // Module installation (part of Engine, mixed into Engine.prototype): engine.use(...) / engine.has(name) / engine.moduleOrder.
2
- // See CLAUDE.md "writing a module" for the module shape; dispose is called by lifecycle.js in reverse install order.
3
- //
4
- // Run order (fixed / frame / afterRender / skip hooks): by stage first, then before / after within a stage, then install order.
5
- // stage only orders hooks; what a module may own and what happens when it throws come from its type (moduleTypes.js, errors.js).
6
- // Stages (first to last): control timeline, camera -> ground terrain, level -> environment weather, sky, water
7
- // -> gameplay interactions, dialogue, trigger zones -> effects particles, settings, objective markers
8
- // -> late (the default) characters, physics, navigation... -> audio music
9
- // The session reset steps (sessionEnd, worldLoad, afterLoad, sessionStart: the sequence is declared in core/saves/session.js) run in this same order, so an
10
- // order between two modules' resets is declared like any other (stage, before / after), never left to install order or to when a listener was added.
11
- // before / after: lists of module or capability names (not-installed names are ignored; a capability means whichever module provides it now, so the order follows a replaces);
12
- // they order modules only inside one stage. One that contradicts the stage order (a 'control' module with after: ['sky']) makes use() throw naming both modules and stages;
13
- // a cycle makes use() throw on the spot, naming the modules on it. A contradiction reached through provides throws the same way: an order must not turn into a hint after a replaces.
14
- // One change plan: use, unuse, replaces and plugin on / off all go through _planChange (moduleSlots.js), which works out the module graph after the change and checks every
15
- // consumer, new or kept, before anything is touched. Then install is all-or-nothing per engine.use(...) call: if a module's install() throws, the modules this call already
16
- // installed are removed again (engine.name, module table, hooks; their dispose() runs) and the error is rethrown.
17
- // Module state (engine.explain({ module })): registered -> initializing -> running | failed; disposed after engine.dispose(). Modules without init() are
18
- // running at once. fixed / frame / afterRender / skip hooks run only for running modules, so no module gets a hook before its init() finished
19
- // (during start() or when installed later).
20
- // requires is a promise that the provider works, not only that it is installed: a module whose required provider is not running (still initializing, failed, or blocked itself)
21
- // is 'blocked': its init waits, its hooks do not run, and engine.catalog(name).blockedBy says on what. It starts by itself when a provider comes up (a replaces of a failed one).
22
- // A critical module blocked by a failure stops start(), or is reported when it happens later. Modules that do not depend on the failed one go on.
23
- // Installed is not usable: engine.has(name) says a module of that name or a provider of that capability is in the module table; engine.usable(name), internal, says it can be called now
24
- // (running, not blocked, not disabled). A game waits with loading.settled and asks engine.explain({ module }).
25
- // A capability binds where provides meets requires: dev checks the provider's API against the capability's contract then, on a module change and never per frame (moduleSlots.js).
26
- // Ownership: install(e, ctx) and init(e, ctx) get ctx = { name, track(handle), mod(point, o), borrow(obj, values), control.take(character, o) }. A handle passed to ctx.track (events.on, onFixed, onFrame,
27
- // clock timers, audio.measure... anything with remove()) belongs to the module and is removed with it: when the use() batch rolls back,
28
- // when its init fails, and on engine.dispose() (before the module's own dispose). Listeners a module adds go through it, so an install
29
- // that fails halfway leaves no ghost listener behind (review 0.4 A; the rollback spec checks every built-in module).
30
- // ctx.mod(point, o) = ctx.track(engine.mod(point, { ...o, owner: ctx.name })): a module's changes to shared values go with it too.
31
- // ctx.rule(name, default, names?) = a replaceable rule on a plain shared point: .decide(id, facts) gives a built-in name, false for manual, or what the game's function answered.
32
- // ctx.input.define(name, { context }) / ctx.input.bind(name, keys): the module's input declarations and bindings, gone with it too.
33
- // ctx.ops.define, ctx.saves.define, ctx.ui.define, ctx.stream.addReadyCheck, ctx.budget.metric, ctx.things.addSource / explainWith / recordsLoaded, ctx.ground.provide / addColliders:
34
- // the same registrars, recorded in the one scope with kind, id, owner and instance (engine.catalog(name).resources reads it). Built-in modules register only through
35
- // these (tools/tests/module-boundaries). A save part leaving keeps its data as unattached data of the save (Saves.define), so a module unloaded for a while loses nothing.
36
- // Every install is its own instance (engine._modInst: name -> token): a ctx belongs to one install, not to a name. An async init that resumes after
37
- // its module was unloaded (replaces, a plugin removed) and a same-named one installed must not act on the newcomer: a stale ctx verb does nothing and gives a spent handle, because
38
- // the owner name is shared and doing it first would replace the newcomer's entry (dev warning naming the module); what it tracks is removed at once; its completion or failure
39
- // changes no state and drops no handle of the newcomer.
40
- // Exclusive slots: provides: ['inventory'] takes each named slot (a kind 'one' shared point, core/ops/sharedPoint.js) for the module before its install;
41
- // a second provider is shared-taken. requires may name a slot instead of a module. engine.use(mine(), { replaces: 'inventory' }) unloads the
42
- // holder first (its handles, slot, drawing parts, dispose), and puts it back if the new install fails, with its save data and content sections (_putBack). Either way the holder now is a fresh install that has none of what
43
- // others put into the old one, so 'module:fresh' tells whoever fed it, once its init is done: they feed it again. The word means "this module is back and holds nothing yet", not that its old state came back; its save data did, its definitions did not.
44
- // critical: true on a module makes a failed init() stop engine.start() with the reason; without it a failed init is reported (picture / ui: disabled;
45
- // other types: error tiers in errors.js) and start() goes on.
46
- // Dependencies: requires must be installed first (throws if missing). optional is a soft dependency: an array is only recorded (for GAMEMAP and rule R16);
47
- // written as { module: 'what is lost without it' }, start() warns once in dev when it is missing: use this form for optional dependencies
48
- // that change gameplay results, which must not be skipped silently.
1
+ // Module installation and lifecycle (mixed into Engine.prototype): engine.use(...) / engine.has(name) / engine.moduleOrder.
2
+ // - Ordering: hooks (fixed / frame / afterRender / skip) and session reset steps run by stage (control -> ground -> environment -> gameplay -> effects -> late -> audio), then before/after within a stage, then install order. Cross-stage conflicts and cycles throw at use().
3
+ // - Atomic changes: use / unuse / replaces / plugin toggles validate the post-change graph via _planChange (moduleSlots.js) before mutating state; a failed install rolls back all modules in the batch and restores any replaced modules (_putBack + module:fresh).
4
+ // - Lifecycle & readiness: states are registered -> initializing -> running | failed | disabled | disposed; modules with unavailable required providers are blocked. has(name) checks presence; usable(name) checks running and unblocked.
5
+ // - Scoped ownership: install(e, ctx) and init(e, ctx) receive an instance-scoped ctx whose tracked handles, mods, borrows, inputs, control holds, and registrations are removed on unload, rollback, failed init, or dispose; stale async callbacks from an unloaded install are ignored.
6
+ // - Dependencies: requires must be satisfied before install; optional may be an array or { module: reason } (warns once in dev at start() if missing); critical modules fail start() on init/block failure.
49
7
  import { warnOnce, DEV, fmt, closest, syncOnly } from '../base/validate.js';
50
8
  import { codedError, coded } from '../base/errorHints.js';
51
9
  import { reportError, removeEach } from '../base/errors.js';
@@ -183,12 +141,11 @@ export const moduleMethods = {
183
141
  this._feed(plan); // inside the try: a provider that cannot take what feeds it fails its install
184
142
  } catch (err) {
185
143
  for (const { m, had, prev } of done.reverse()) { // undo in reverse install order, like dispose
186
- const installed = this.modules.get(m.name) === m;
187
- this._modInst.get(m.name)?.ac.abort(); // before the token goes: ctx.signal of a rolled-back install
188
- this.modules.delete(m.name); this._modState.delete(m.name); this._modInst.delete(m.name);
189
- if (had) this[m.name] = prev; else delete this[m.name]; // put back what was there (an undefined slot stays undefined), never blank it
190
- this._dropTracked(m.name);
191
- if (installed) try { syncOnly(m.dispose?.(this), `dispose() of module ${m.name}`, true); } catch (e2) { reportError(this, e2, `dispose() of module ${m.name} after its install failed`, { soft: true }); } // reported, but the install error below stays the primary one
144
+ this._teardownModule(m, {
145
+ dispose: this.modules.get(m.name) === m,
146
+ where: `dispose() of module ${m.name} after its install failed`,
147
+ had, prev,
148
+ });
192
149
  }
193
150
  this._sortHooks();
194
151
  if (removed.length) this._putBack(removed, order, base);
@@ -197,6 +154,21 @@ export const moduleMethods = {
197
154
  this._sortHooks();
198
155
  if (removed.length && plan.length) this._tellRestored(plan);
199
156
  },
157
+ /** @internal Shared teardown for unloading or rolling back a module install */
158
+ _teardownModule(m, { keepSave = false, dispose = true, where, had = false, prev, partGone = false, swapping = false } = {}) {
159
+ const name = m.name;
160
+ if (!keepSave) {
161
+ this._modInst.get(name)?.ac.abort(); // before the token goes: ctx.signal of a rolled-back install
162
+ this.modules.delete(name); this._modState.delete(name); this._modInst.delete(name);
163
+ if (had) this[name] = prev; else delete this[name]; // put back what was there (an undefined slot stays undefined), never blank it
164
+ }
165
+ this._dropTracked(name);
166
+ if (dispose) try { syncOnly(m.dispose?.(this), `dispose() of module ${name}`, true); } catch (err) { reportError(this, err, where, { soft: true }); }
167
+ if (partGone) this._picture?.partGone(m, swapping);
168
+ if (keepSave) {
169
+ this.modules.delete(name); this._modState.delete(name); this._modInst.delete(name); delete this[name];
170
+ }
171
+ },
200
172
  /**
201
173
  * @internal 'module:fresh' for these fresh modules, after their init: what is fed then lands as it does on a running game, where content.load comes after init
202
174
  * (a level's own url would otherwise overtake the pack's level). Nothing in flight tells at once. One replaced again meanwhile is not told about
@@ -217,7 +189,7 @@ export const moduleMethods = {
217
189
  _putBack(removed, order, base) {
218
190
  this.session._base = base; // a newcomer's save part may have written over a part of the same key (session._late)
219
191
  try { this.use(...removed); } catch (e2) { return reportError(this, e2, 'putting back the module a failed replaces removed', { soft: true }); }
220
- for (const n of order) { const m = this.modules.get(n); this.modules.delete(n); this.modules.set(n, m); } // hooks of one stage run in install order: same places
192
+ for (const n of order) { const m = this.modules.get(n); if (!m) continue; this.modules.delete(n); this.modules.set(n, m); } // hooks of one stage run in install order: same places
221
193
  this._sortHooks();
222
194
  this._tellRestored(removed);
223
195
  },
@@ -422,11 +394,11 @@ export const moduleMethods = {
422
394
  return own('ground', 'ground', this._provideGround(g));
423
395
  });
424
396
  // feeds: this module puts data into whoever holds that capability. fn runs when a new holder arrives, before its use() returns, and leaves with this module
425
- const feeds = (capability, fn) => {
397
+ const feeds = ifLive((capability, fn) => {
426
398
  const f = { name: capability, fn };
427
399
  (this._feeders ??= []).push(f);
428
400
  return track({ remove: () => { const i = this._feeders.indexOf(f); if (i >= 0) this._feeders.splice(i, 1); } }); // a handle removed twice must not take the next feeder
429
- };
401
+ });
430
402
  // signal: aborts when this install ends (_dropTracked), the one lifecycle; an async init checks it after each await instead of keeping its own flag
431
403
  // commits: a module reaches the commit queue through its ctx; a game outside a module uses engine.nextFixed (engine.commits is internal)
432
404
  return { name, signal: inst?.ac.signal, track, mod, borrow, feeds, input, control, whileCompiling, commits: this.commits,
@@ -440,7 +412,7 @@ export const moduleMethods = {
440
412
  budget: { metric: owned('metric', (n, read, o) => this.budget.metric(n, read, o)) },
441
413
  things: { addSource: ifLive(src => own('source', name, this._things.addSource(src))), explainWith: ifLive(fn => own('explainer', name, this.explainWith(fn))),
442
414
  // the records source replaced its records wholesale (a load): core runs the worldLoad reset step, then tells the game (session.js step 2)
443
- recordsLoaded: info => { this._resetStep('worldLoad', info); this.events.emit('world:load', info); } },
415
+ recordsLoaded: info => { if (stale()) return; this._resetStep('worldLoad', info); this.events.emit('world:load', info); } },
444
416
  ground: { provide: provideGround, addColliders: ifLive(fn => own('colliders', name, this.addGroundColliders(fn))) },
445
417
  };
446
418
  },
@@ -5,7 +5,7 @@
5
5
  import { movedOwned } from '../ops/owned.js';
6
6
  import { reportError } from '../base/errors.js';
7
7
  import { asModule } from './moduleTypes.js';
8
- import { whenSettled } from './headlessLoad.js';
8
+ import { whenSettled, unreadyModules } from './headlessLoad.js';
9
9
  import { catalogSnap, catalogClaim } from '../inspect/catalog.js';
10
10
  import { codedError, coded } from '../base/errorHints.js';
11
11
  import { warnOnce, DEV_SERVER, fmt } from '../base/validate.js';
@@ -272,12 +272,12 @@ export const startupMethods = {
272
272
  this._alive();
273
273
  // Headless mode has no real-time loop: run one frame by hand (time does not advance, jobs ignore real time) so terrain and other modules keep loading
274
274
  if (this.headless) this._frameHooks(0, true);
275
- const waiting = [...this.modules.values()].filter(m => m.isReady && !m.isReady(this));
275
+ const waiting = unreadyModules(this);
276
276
  for (const m of this.modules.values()) if (m.isReady && !waiting.includes(m) && timing[m.name]?.ready == null) (timing[m.name] ||= {}).ready = ms(tr);
277
277
  if (this.stream.ready && getStream() == null) setStream(ms(tr));
278
278
  const fatal = this._fatal(); // a critical step tracked by a module can fail while we wait
279
279
  if (fatal.length || (!waiting.length && getStream() != null)) { done = true; this._afterTick = null; if (fatal.length) rej(fatal); else res(); return; }
280
- ls?.update({ progress: 0.5 + 0.5 * (1 - waiting.length / this.modules.size), text: this.loading.text() ?? this.t('common.generating', { name: this.t('common.world') }) });
280
+ ls?.update({ progress: 0.5 + 0.5 * (this.modules.size ? 1 - waiting.length / this.modules.size : 1), text: this.loading.text() ?? this.t('common.generating', { name: this.t('common.world') }) });
281
281
  };
282
282
  // a throw (a module's isReady) must end the wait: in a timer or a frame nothing would catch it, and start() would never settle
283
283
  const guarded = () => { try { check(); } catch (err) { done = true; this._afterTick = null; rej(err); } };
@@ -82,7 +82,7 @@ export class Input {
82
82
  /** Is this a touch device? @experimental */
83
83
  this.touch = matchMedia('(pointer: coarse)').matches;
84
84
  /** @internal touch buttons the game asked for [{ action, labelKey }]; drawn by the UI part 'touch' (inputTouch.js) */ this._touch = [];
85
- for (const a of Object.keys(BASIC_KEYS)) this.actions.set(a, { labelKey: BASIC_LABELS[a], context: BASE_CONTEXT, optional: false, by: 'engine' });
85
+ for (const a of Object.keys(BASIC_KEYS)) this.actions.set(a, { labelKey: BASIC_LABELS[a], context: BASE_CONTEXT, optional: false, by: 'engine', users: 1 });
86
86
  this.bind(bindings); // createEngine({ bindings }): the game's keys, owner 'game'
87
87
 
88
88
  const { signal } = engine; // engine.dispose() cancels all listeners at once
@@ -120,7 +120,7 @@ export class Input {
120
120
  // a second owner declaring the same action in the same context shares the first declaration (two modules may read one 'interact')
121
121
  const entry = cur?.by && cur.by !== owner ? cur : { labelKey: label || cur?.labelKey || name, context, optional, by: owner, users: 0 };
122
122
  if (entry !== cur) this.actions.set(name, entry);
123
- entry.users++;
123
+ entry.users = (entry.users ?? 0) + 1;
124
124
  this._readable = null;
125
125
  const bound = keys !== undefined ? this.bind(name, keys, { owner }) : null;
126
126
  let gone = false;
@@ -219,7 +219,11 @@ export class Input {
219
219
  */
220
220
  rebind(action, keys) {
221
221
  if (keys == null) this._keys.release('settings', { id: action });
222
- else this._keys.take({ owner: 'settings', id: action, set: Object.freeze([].concat(keys)), layer: 'settings' });
222
+ else {
223
+ const list = [].concat(keys);
224
+ if (list.some(k => typeof k !== 'string' || !k)) throw codedError('input-keys', `input.rebind('${action}', ${JSON.stringify(list)}): keys are key names like 'KeyE', 'Space', 'PadA', 'Mouse0'`, TypeError);
225
+ this._keys.take({ owner: 'settings', id: action, set: Object.freeze(list), layer: 'settings' });
226
+ }
223
227
  this.engine.events.emit('input:rebind', { action, keys: this.keysOf(action) });
224
228
  }
225
229
  /** The player's rebindings now in effect: { action: keys } (what the settings menu saves) @returns {Record<string, string[]>} */
@@ -86,8 +86,9 @@ export function applyContexts(input) {
86
86
  for (const [name, was] of before) {
87
87
  if (!was || after.get(name)) continue;
88
88
  for (const k of input._sourcesOf(name)) {
89
- if (!input.keys.has(k)) continue; // even if another action on this key becomes readable: it needs a fresh press (F that boards must not also exit)
90
- input.keys.delete(k); input._accP.delete(k); input._accR.delete(k); input._muted.add(k);
89
+ input._accP.delete(k); input._accR.delete(k); // same-frame tap (down + up) must not carry into the new context either
90
+ if (!input.keys.has(k)) continue; // even if another action on this key becomes readable: it needs a fresh press (F that boards must not also exit); only a held key is muted until keyup
91
+ input.keys.delete(k); input._muted.add(k);
91
92
  }
92
93
  }
93
94
  input.engine.events.emit('input:context', { stack: input._stack.map(c => c.name) });
@@ -61,6 +61,6 @@ export class Seat {
61
61
  const I = this.input, at = I.seats.indexOf(this);
62
62
  if (at < 0) return;
63
63
  I.seats.splice(at, 1);
64
- for (const k of [...I.keys]) if (k.endsWith(`@${this.pad}`)) I._keyUp(k);
64
+ if (this.pad !== undefined) for (const k of [...I.keys]) if (k.endsWith(`@${this.pad}`)) I._keyUp(k);
65
65
  }
66
66
  }
@@ -217,7 +217,7 @@ export class DebugOverrides {
217
217
  } catch (err) { undo(); throw err; }
218
218
  o.undo = undo;
219
219
  }
220
- /** @internal One cached unlit stand-in per material and kind. Beside the material, not on its userData: the stand-in points back (_dbgOf), and three's material.clone()
220
+ /** @internal One cached unlit stand-in per material and kind. Beside the material, not on its userData: the stand-in points back (_dbgOf), and cloning a material
221
221
  * writes userData through JSON, which threw on the circle for the rest of the session */
222
222
  _stand(m, kind, colorOf) {
223
223
  if (m.userData._dbgOf) m = m.userData._dbgOf; // already a stand-in (a view under an override): derive from the original, never stack copies
@@ -38,7 +38,7 @@ const NEAR_RADIUS = 30, NEAR_MAX = 15;
38
38
  const COMPASS = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW']; // north = -Z, east = +X
39
39
  const RELATIVE = ['front', 'front-right', 'right', 'back-right', 'back', 'back-left', 'left', 'front-left']; // relative to the camera heading
40
40
  // the core's own fields
41
- const STANDARD = new Set(['unhandled', 'warnings', 'holds', 'input', 'wraps', 'slots', 'threePatches', 'renderer', 'vars', 'ready', 'error', 'disabledModules', 'moduleStates', 'loading', 'audio', 'time', 'player', 'camera', 'nearbyRadius', 'nearby', 'actions', 'ui', 'cutscene', 'modules', 'perf', 'scene', 'render', 'picture', 'owned', 'shared', 'changed', 'control']);
41
+ const STANDARD = new Set(['unhandled', 'warnings', 'holds', 'input', 'wraps', 'slots', 'threePatches', 'renderer', 'vars', 'ready', 'error', 'disabledModules', 'moduleStates', 'loading', 'audio', 'time', 'player', 'spatial', 'camera', 'nearbyRadius', 'nearby', 'actions', 'ui', 'cutscene', 'modules', 'perf', 'scene', 'render', 'picture', 'owned', 'shared', 'changed', 'control']);
42
42
  const ACTIONS_MAX = 8; // what the player can do now, with why not: saves the AI a guess for a few dozen characters
43
43
  const sector = a => Math.round(((a % (Math.PI * 2)) + Math.PI * 2) / (Math.PI / 4)) % 8;
44
44
 
@@ -179,7 +179,12 @@ function describe(e, { radius = NEAR_RADIUS, center: at, only } = {}, extras) {
179
179
  if (!only || !only.every(k => TABLES.has(k) && !e.modules.has(k) && !extras.has(k))) hooks(e, out, radius, center, extras);
180
180
  if (!only) return out;
181
181
  const picked = {};
182
- for (const k of only) { const v = out[k]; if (!(k in out)) return null; picked[k] = v; }
182
+ for (const k of only) {
183
+ const v = out[k];
184
+ if (k in out) picked[k] = v;
185
+ else if (k in core || STANDARD.has(k)) picked[k] = null;
186
+ else return null;
187
+ }
183
188
  return picked;
184
189
  }
185
190
 
@@ -117,6 +117,9 @@ export function describeRender(e) {
117
117
  probes: ${probes.map(p => `${p.count} (${p.counts.join('x')}, step ${p.step.join('/')}) from ${p.source} by ${p.owner}`).join('; ')}`
118
118
  + (probes[0].outside.count ? `
119
119
  outside the probe grid (no probe light): ${probes[0].outside.count} lit object(s), ${probes[0].outside.names.join(', ')}` : '');
120
+ const reflectionProbes = [...(e._reflectionProbes ?? [])].filter(p => !p._dead).map(p => p.info());
121
+ if (reflectionProbes.length) text += `
122
+ reflection probes: ${reflectionProbes.map(p => `${p.resolution}px at [${p.position.join(',')}] (${p.materials} mat, by ${p.owner})`).join('; ')}`;
120
123
  const dv0 = e.debug?.viewState?.(), dv = dv0 && dv0.mode !== 'off' ? dv0 : null;
121
124
  if (dv) text = `DEBUG VIEW "${dv.mode}" (by ${dv.owner}) is ON: ${dv.what}. This is NOT the real picture; the debug view 'off' restores it.
122
125
  ` + text;
@@ -140,7 +143,7 @@ render scale: ${scale.current} of device pixel ratio ${dpr}${scale.pixelSize ? `
140
143
  // settings wrong together whatever the game wants (core/inspect/pictureChecks.js): one line each, last, so the fix is the last thing read
141
144
  const checks = pictureChecks(e);
142
145
  for (const c of checks) text += `\npicture ${c.kind === 'mistake' ? 'check' : 'note'} ${c.id}: ${c.text}`;
143
- return { debugView: dv, scale, toneMapping: tone, exposure, shadows, post, antialias, lights, defaults, probes, lightmap, occlusion, bundles, checks, text };
146
+ return { debugView: dv, scale, toneMapping: tone, exposure, shadows, post, antialias, lights, defaults, probes, reflectionProbes, lightmap, occlusion, bundles, checks, text };
144
147
  }
145
148
 
146
149
  /**
@@ -44,7 +44,7 @@ const STRINGS = {
44
44
  tables: 'Engine tables (entries; describe <name> for one): {list}',
45
45
  more: '... {n} more modules: {names} (describe <name> for one)',
46
46
  nearMore: ' ... {n} more',
47
- expand: 'More: describeText({ path: \'<module>\' }) for one part, describeText({ full: true }) for everything (CLI: threedog describe <path> / --full)',
47
+ expand: 'More: describeText({ path: \'<module>\' }) for one part, describeText({ full: true }) for everything (CLI: threedog describe <path> / --all)',
48
48
  noPath: 'describe() has no "{path}"; top-level keys: {keys}',
49
49
  none: 'none',
50
50
  state: { idle: 'standing', walk: 'walking', run: 'running', jump: 'jumping', fall: 'falling', swim: 'swimming' },
@@ -66,7 +66,7 @@ const n1 = v => (typeof v === 'number' ? r1(v) : v);
66
66
  const SHOWN = new Set(['nearbyRadius', 'ready', 'error', 'disabledModules', 'loading', 'audio', 'time', 'player', 'camera', 'nearby', 'actions', 'ui', 'cutscene',
67
67
  'modules', 'perf', 'changed', 'weather', 'render', 'threePatches']); // threePatches: page-wide, the same every call; describe() JSON carries it, the text stays short
68
68
  // engine bookkeeping in describe(): one count each in the summary, the content one describeText({ path }) away
69
- const TABLES = new Set(['holds', 'input', 'control', 'shared', 'wraps', 'slots', 'scene', 'owned', 'picture', 'renderer']);
69
+ const TABLES = new Set(['holds', 'input', 'control', 'shared', 'wraps', 'slots', 'scene', 'owned', 'picture', 'renderer', 'spatial']);
70
70
  const argText = a => Object.entries(a || {}).map(([k, v]) => `${k}=${Array.isArray(v) ? v.join(',') : v}`).join(' ');
71
71
 
72
72
  /** One module's data in a line: scalars as k=v, arrays as k[n], objects as k{n keys} (nested data is one describeText({ path }) away) */