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.
- package/CHANGELOG.md +20 -0
- package/README.md +4 -4
- package/core/assets/Animator.js +66 -12
- package/core/assets/ik.js +144 -18
- package/core/assets/maskLayer.js +377 -0
- package/core/assets/rootMotion.js +148 -0
- package/core/audio/Audio.js +100 -4
- package/core/base/errorCodes.js +6 -369
- package/core/base/errorCodesModules.js +378 -0
- package/core/engine/Engine.js +8 -5
- package/core/engine/Loading.js +8 -4
- package/core/engine/copies.js +1 -1
- package/core/engine/headlessLoad.js +15 -4
- package/core/engine/lifecycle.js +1 -0
- package/core/engine/loop.js +22 -3
- package/core/engine/moduleSlots.js +3 -7
- package/core/engine/modules.js +30 -58
- package/core/engine/startup.js +3 -3
- package/core/input/Input.js +7 -3
- package/core/input/inputContext.js +3 -2
- package/core/input/inputSeat.js +1 -1
- package/core/inspect/DebugOverrides.js +1 -1
- package/core/inspect/Describe.js +7 -2
- package/core/inspect/describeRender.js +4 -1
- package/core/inspect/describeText.js +2 -2
- package/core/inspect/metadata.generated.js +371 -74
- package/core/inspect/pictureMenu.js +2 -0
- package/core/inspect/pictureWriters.js +4 -3
- package/core/ops/Ops.js +9 -3
- package/core/ops/actor.js +10 -0
- package/core/ops/control.js +17 -6
- package/core/ops/holds.js +1 -1
- package/core/ops/opsAtomic.js +6 -1
- package/core/ops/opsGuard.js +2 -2
- package/core/ops/owned.js +37 -11
- package/core/ops/sharedPoint.js +5 -1
- package/core/ops/stacks.js +30 -7
- package/core/saves/Saves.js +0 -2
- package/core/saves/saveApply.js +7 -7
- package/core/saves/session.js +6 -3
- package/core/saves/stateReplace.js +71 -41
- package/core/scene/Rays.js +74 -26
- package/core/scene/gameLights.js +19 -11
- package/core/scene/sceneDelta.js +8 -4
- package/core/stream/chunkStream.js +21 -0
- package/core/stream/dirtyWatch.js +37 -0
- package/core/time/skip.js +9 -6
- package/core/time/time.js +72 -18
- package/docs/AI.md +22 -21
- package/docs/API.md +5 -4
- package/docs/CODEMAP.md +16 -10
- package/docs/COMMANDS.md +5 -5
- package/docs/CONVENTIONS.md +9 -25
- package/docs/api/ambience.md +1 -0
- package/docs/api/assets.md +10 -3
- package/docs/api/audio.md +5 -3
- package/docs/api/decals.md +16 -0
- package/docs/api/engine.md +1 -0
- package/docs/api/tools.md +3 -1
- package/docs/api/water.md +3 -0
- package/docs/recipes/09-materials-lights-models.md +15 -1
- package/docs/recipes/13-animation.md +51 -10
- package/docs/recipes/16-dev-bridge.md +1 -1
- package/docs/recipes/31-audio.md +15 -9
- package/docs/recipes/34-environment-lighting.md +11 -1
- package/docs/recipes/44-water-weather-hooks.md +1 -0
- package/examples/action/.threedog/content-index.json +1 -0
- package/examples/perf-island/.threedog/content-index.json +1 -0
- package/examples/plain-picture/.threedog/content-index.json +1 -0
- package/examples/rc2d/.threedog/content-index.json +1 -0
- package/examples/styletest/.threedog/content-index.json +1 -0
- package/examples/techniques/outlines-and-rim/main.js +1 -1
- package/examples/techniques/procedural-surface/main.js +1 -1
- package/examples/techniques/stylized-shading/main.js +1 -1
- package/examples/webgpu-tsl/.threedog/content-index.json +1 -0
- package/examples/world/.threedog/content-index.json +1 -0
- package/index.d.ts +6 -2
- package/index.js +3 -2
- package/llms.txt +11 -10
- package/modules/ambience/Ambience.js +97 -15
- package/modules/camera/common.js +18 -12
- package/modules/characters/Character.js +30 -3
- package/modules/characters/NPC.js +2 -5
- package/modules/characters/astar.js +45 -14
- package/modules/characters/movers/rapier.js +53 -41
- package/modules/characters/movers/simple.js +37 -24
- package/modules/characters/npcView.js +2 -2
- package/modules/characters/pathAsync.js +3 -3
- package/modules/collision/contract.js +2 -2
- package/modules/content/index.js +3 -0
- package/modules/content/models.js +11 -4
- package/modules/content/templates.js +11 -11
- package/modules/debug/DebugPanel.js +1 -0
- package/modules/decals/Decals.js +393 -0
- package/modules/decals/index.js +1 -0
- package/modules/gameplay/Container.js +2 -0
- package/modules/gameplay/Containers.js +17 -3
- package/modules/gameplay/Dialogue.js +1 -1
- package/modules/gameplay/Interactions.js +7 -6
- package/modules/gameplay/Inventory.js +5 -1
- package/modules/gameplay/Quests.js +4 -3
- package/modules/gameplay/inventoryOps.js +2 -2
- package/modules/gameplay/pickups.js +32 -12
- package/modules/gameplay/questSave.js +2 -2
- package/modules/grid/index.js +8 -2
- package/modules/hud/index.js +1 -1
- package/modules/level/heightfield.js +1 -0
- package/modules/level/index.js +3 -2
- package/modules/level/nodes.js +2 -1
- package/modules/lights/index.js +27 -4
- package/modules/lights/slots.js +33 -16
- package/modules/nav/contract.js +4 -4
- package/modules/nav/index.js +6 -2
- package/modules/net/Client.js +24 -11
- package/modules/net/Host.js +73 -20
- package/modules/net/index.js +33 -21
- package/modules/net/sync.js +38 -8
- package/modules/net/transports.js +7 -3
- package/modules/particles/Particles.js +11 -4
- package/modules/particles/contract.js +6 -6
- package/modules/particles/effect.js +0 -1
- package/modules/rigid/RigidBodies.js +69 -57
- package/modules/rigid/Vehicles.js +8 -7
- package/modules/rigid/ragdoll.js +4 -6
- package/modules/rigid/rapierCompat.js +90 -0
- package/modules/rigid/sync.js +2 -5
- package/modules/settings/Settings.js +10 -4
- package/modules/sky/Sky.js +10 -2
- package/modules/sky/environment.js +29 -13
- package/modules/sky/frame.js +2 -2
- package/modules/sky/shader.js +5 -2
- package/modules/sky/skyModule.js +2 -2
- package/modules/swarm/Swarm.js +3 -2
- package/modules/swarm/grid.js +12 -7
- package/modules/terrain/ChunkManager.js +16 -26
- package/modules/triggers/index.js +5 -6
- package/modules/vegetation/draw.js +62 -26
- package/modules/vegetation/groundChunks.js +8 -22
- package/modules/water/Water.js +152 -24
- package/modules/water/surface.js +43 -20
- package/modules/weather/weatherDraw.js +4 -1
- package/modules/world/World.js +21 -2
- package/modules/world/index.js +5 -0
- package/modules/world/persist.js +1 -0
- package/modules/world/records.js +3 -1
- package/modules/world/sim.js +3 -2
- package/modules/world/simFar.js +4 -2
- package/modules/world/state.js +7 -1
- package/package.json +2 -2
- package/presets.js +30 -0
- package/render/PostFX.js +24 -17
- package/render/backend.js +72 -31
- package/render/cascades.js +25 -14
- package/render/cascades.tsl.js +32 -21
- package/render/fogLook.js +2 -1
- package/render/fx/library.tsl.js +1 -1
- package/render/fx/particles.tsl.js +4 -18
- package/render/fx/pcss.tsl.js +2 -2
- package/render/fx/postWebGPU.tsl.js +47 -25
- package/render/fx/sky.tsl.js +6 -18
- package/render/fx/uniforms.tsl.js +16 -0
- package/render/fx/water.tsl.js +24 -5
- package/render/fxNumbers.js +2 -0
- package/render/impostor.tsl.js +10 -6
- package/render/lights.js +6 -6
- package/render/occlusion.js +17 -6
- package/render/patches.js +40 -28
- package/render/postWebGL.js +6 -4
- package/render/reflectionProbes.js +302 -0
- package/render/shaderErrors.js +18 -8
- package/render/shadowCache.tsl.js +10 -5
- package/render/shadows.js +70 -49
- package/render/threeCompat.js +166 -0
- package/types/core.d.ts +33 -3
- package/types/gameplay.d.ts +80 -0
- package/types/generated/core/audio/Audio.d.ts +18 -1
- package/types/generated/core/ops/Ops.d.ts +2 -1
- package/types/generated/core/ops/control.d.ts +7 -3
- package/types/generated/core/saves/session.d.ts +4 -1
- package/types/generated/modules/ambience/Ambience.d.ts +6 -0
- package/types/generated/modules/debug/DebugPanel.d.ts +1 -0
- package/types/generated/modules/grid/index.d.ts +27 -3
- package/types/generated/modules/net/index.d.ts +8 -3
- package/types/generated/modules/sky/Sky.d.ts +1 -0
- package/types/generated/modules/water/Water.d.ts +15 -0
- package/types/generated/modules/world/index.d.ts +5 -0
- package/types/generated/render/patches.d.ts +5 -0
- package/types/physics.d.ts +66 -9
- package/types/tsl.d.ts +2 -0
- package/types/world.d.ts +2 -0
- package/ui/Parts.js +3 -2
- package/docs/MIGRATING-0.7.md +0 -39
- package/docs/MIGRATING-0.8.md +0 -171
- 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
|
|
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.
|
|
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.
|
|
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
|
},
|
package/core/engine/modules.js
CHANGED
|
@@ -1,51 +1,9 @@
|
|
|
1
|
-
// Module installation
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
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
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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
|
},
|
package/core/engine/startup.js
CHANGED
|
@@ -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 =
|
|
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); } };
|
package/core/input/Input.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
90
|
-
input.keys.
|
|
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) });
|
package/core/input/inputSeat.js
CHANGED
|
@@ -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
|
|
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
|
package/core/inspect/Describe.js
CHANGED
|
@@ -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) {
|
|
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> / --
|
|
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) */
|