threedog 1.4.0 → 2.1.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 +48 -0
- package/README.md +13 -7
- package/bin/threedog.mjs +42 -0
- package/core/assets/assetEntry.js +1 -1
- package/core/assets/assetPart.js +1 -1
- package/core/base/Events.js +7 -1
- package/core/base/errorCodes.js +1 -1
- package/core/base/events.generated.js +2 -2
- package/core/engine/Engine.js +11 -7
- package/core/engine/copies.js +1 -1
- package/core/engine/moduleTypes.js +1 -1
- package/core/engine/modules.js +23 -6
- package/core/engine/page.js +1 -0
- package/core/engine/services.js +5 -3
- package/core/engine/startup.js +4 -1
- package/core/inspect/DebugOverrides.js +2 -2
- package/core/inspect/InspectPerf.js +1 -1
- package/core/inspect/describeRender.js +0 -7
- package/core/inspect/metadata.generated.js +139 -50
- package/core/inspect/pictureChecks.js +2 -27
- package/core/ops/control.js +3 -3
- package/core/ops/holds.js +8 -3
- package/core/ops/sharedPoint.js +11 -2
- package/core/saves/saveApply.js +3 -3
- package/core/saves/session.js +20 -4
- package/core/scene/adaptive.js +5 -2
- package/core/scene/pixelRatio.js +39 -17
- package/core/scene/sceneMethods.js +1 -1
- package/core/scene/things.js +3 -2
- package/core/scene/tier.js +2 -16
- package/core/scene/view.js +14 -0
- package/core/time/skip.js +1 -1
- package/docs/AI.md +2 -2
- package/docs/CODEMAP.md +8 -8
- package/docs/COMMANDS.md +2 -2
- package/docs/CONVENTIONS.md +1 -0
- package/docs/THREE.md +1 -1
- package/docs/api/ambience.md +2 -2
- package/docs/api/cameraRig.md +7 -0
- package/docs/api/engine.md +6 -3
- package/docs/api/events.md +3 -3
- package/docs/api/particles.md +1 -1
- package/docs/api/photo.md +5 -0
- package/docs/api/pickups.md +1 -1
- package/docs/api/post.md +1 -1
- package/docs/api/rigid.md +1 -1
- package/docs/api/sky.md +11 -1
- package/docs/api/terrain.md +19 -0
- package/docs/api/tools.md +1 -1
- package/docs/recipes/01-new-game.md +1 -1
- package/docs/recipes/03-items-pickups.md +1 -1
- package/docs/recipes/05-props-bake.md +1 -1
- package/docs/recipes/06-clock-events.md +3 -10
- package/docs/recipes/07-flow-scenes-pause.md +3 -4
- package/docs/recipes/09-materials-lights-models.md +1 -1
- package/docs/recipes/10-blender-level.md +2 -2
- package/docs/recipes/{11-vehicles.md → 11-physics.md} +13 -5
- package/docs/recipes/12-navmesh.md +3 -3
- package/docs/recipes/14-custom-module.md +6 -5
- package/docs/recipes/15-perf.md +1 -1
- package/docs/recipes/16-dev-bridge.md +1 -1
- package/docs/recipes/18-world.md +1 -1
- package/docs/recipes/20-content-actions-save.md +0 -1
- package/docs/recipes/21-camera.md +11 -1
- package/docs/recipes/26-ui-parts.md +2 -2
- package/docs/recipes/27-net.md +1 -1
- package/docs/recipes/29-grid.md +1 -1
- package/docs/recipes/34-environment-lighting.md +5 -3
- package/docs/recipes/40-scene.md +1 -1
- package/docs/recipes/44-water-weather-hooks.md +1 -1
- package/docs/recipes/45-cascaded-shadows.md +6 -3
- package/docs/recipes/51-capability-catalog.md +1 -1
- package/docs/recipes/52-around-the-picture.md +8 -8
- package/docs/recipes/53-ground-up-close.md +2 -2
- package/docs/recipes/55-mods-time-wrap.md +6 -8
- package/docs/recipes/57-control.md +1 -1
- package/docs/recipes/59-depth-post-effects.md +1 -1
- package/docs/recipes/60-judge-the-picture.md +7 -7
- package/docs/recipes/62-picture-code.md +13 -17
- package/examples/action/GAMEMAP.md +4 -2
- package/examples/action/picture/lights.js +3 -2
- package/examples/perf-island/GAMEMAP.md +2 -1
- package/examples/perf-island/picture/lights.js +3 -2
- package/examples/styletest/GAMEMAP.md +2 -2
- package/examples/styletest/picture/env.js +1 -2
- package/examples/techniques/contact-shadows/README.md +1 -1
- package/examples/techniques/day-night-grade/picture/lights.js +3 -1
- package/examples/techniques/interior-light/README.md +1 -1
- package/examples/techniques/interior-light/picture/lights.js +4 -2
- package/examples/techniques/modular-building/picture/lights.js +3 -2
- package/examples/techniques/night-lights/README.md +1 -1
- package/examples/techniques/night-lights/picture/lights.js +3 -1
- package/examples/techniques/night-lights/picture/post.js +2 -2
- package/examples/techniques/outlines-and-rim/README.md +1 -1
- package/examples/techniques/outlines-and-rim/picture/lights.js +3 -2
- package/examples/techniques/procedural-animation/README.md +1 -1
- package/examples/techniques/procedural-animation/picture/lights.js +3 -1
- package/examples/techniques/procedural-surface/README.md +1 -1
- package/examples/techniques/procedural-surface/picture/lights.js +3 -1
- package/examples/techniques/stylized-shading/picture/lights.js +3 -1
- package/examples/techniques/wet-road/README.md +1 -1
- package/examples/techniques/wet-road/picture/lights.js +3 -1
- package/examples/webgpu-tsl/GAMEMAP.md +4 -2
- package/examples/webgpu-tsl/picture/lights.js +3 -1
- package/examples/world/GAMEMAP.md +4 -3
- package/examples/world/picture/lights.js +3 -1
- package/examples/world/picture/post.js +2 -2
- package/llms.txt +33 -7
- package/modules/camera/common.js +22 -20
- package/modules/camera/contract.js +1 -1
- package/modules/characters/Character.js +2 -2
- package/modules/characters/NPC.js +7 -8
- package/modules/characters/index.js +8 -8
- package/modules/characters/mover.contract.js +1 -1
- package/modules/characters/movers/rapier.js +7 -9
- package/modules/characters/npcAvoid.js +2 -2
- package/modules/characters/player.js +11 -15
- package/modules/characters/playerStrings.js +1 -2
- package/modules/characters/seat.js +1 -1
- package/modules/collision/Collision.js +1 -1
- package/modules/collision/grid.js +1 -1
- package/modules/content/index.js +4 -3
- package/modules/content/models.js +1 -1
- package/modules/content/templates.js +3 -2
- package/modules/flow/index.js +8 -8
- package/modules/gameplay/Dialogue.js +1 -1
- package/modules/gameplay/Inventory.js +3 -3
- package/modules/gameplay/Quests.js +1 -0
- package/modules/gameplay/inventory.contract.js +1 -1
- package/modules/gameplay/pickups.js +1 -1
- package/modules/gameplay/questLog.js +0 -1
- package/modules/grid/index.js +1 -1
- package/modules/grid/tiles.js +6 -3
- package/modules/hud/index.js +2 -2
- package/modules/level/contract.js +2 -2
- package/modules/level/index.js +1 -1
- package/modules/music/Music.js +1 -1
- package/modules/nav/index.js +1 -1
- package/modules/net/sync.js +1 -1
- package/modules/particles/Particles.js +12 -5
- package/modules/particles/effect.js +17 -3
- package/modules/photo/pathTrace.js +1 -1
- package/modules/rigid/RigidBodies.js +23 -9
- package/modules/rigid/ragdoll.js +1 -1
- package/modules/rigid/sync.js +14 -0
- package/modules/settings/Settings.js +3 -2
- package/modules/settings/apply.js +4 -3
- package/modules/settings/sections.js +1 -1
- package/modules/sky/Sky.js +9 -4
- package/modules/sky/environment.js +5 -3
- package/modules/terrain/index.js +1 -2
- package/modules/timeline/Timeline.js +9 -6
- package/modules/vegetation/Vegetation.js +1 -1
- package/modules/vegetation/index.js +1 -1
- package/modules/weather/weatherDraw.js +1 -2
- package/modules/world/World.js +1 -0
- package/modules/world/index.js +1 -0
- package/modules/world/persist.js +1 -1
- package/package.json +6 -2
- package/render/PostFX.js +17 -12
- package/render/fx/postWebGPU.tsl.js +2 -1
- package/render/lightmap.js +1 -1
- package/render/lights.js +1 -2
- package/render/neutral.js +1 -1
- package/render/patches.js +3 -3
- package/render/probes.js +27 -2
- package/render/shaderErrors.js +1 -1
- package/render/shadows.js +1 -3
- package/types/core.d.ts +16 -9
- package/types/gameplay.d.ts +8 -3
- package/types/generated/modules/sky/Sky.d.ts +4 -4
- package/types/generated/render/PostFX.d.ts +2 -2
- package/types/generated/ui/UI.d.ts +2 -1
- package/types/physics.d.ts +1 -1
- package/types/world.d.ts +4 -2
- package/ui/UI.js +18 -14
- package/ui/cursor.js +2 -2
- package/examples/action/.threedog/content-index.json +0 -1
- package/examples/perf-island/.threedog/content-index.json +0 -1
- package/examples/plain-picture/.threedog/content-index.json +0 -1
- package/examples/rc2d/.threedog/content-index.json +0 -1
- package/examples/styletest/.threedog/content-index.json +0 -1
- package/examples/webgpu-tsl/.threedog/content-index.json +0 -1
- package/examples/world/.threedog/content-index.json +0 -1
package/modules/grid/tiles.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
// Crisp per-cell tiles for a layer (a painted floor, a buildable zone, tilled soil): one mesh per layer, each non-empty cell a quad
|
|
2
2
|
// whose four corners sit on engine.surface + lift, so tiles hug a ramp or terrain and work on any ground provider
|
|
3
3
|
// (procedural terrain, a Blender level, a flat greenhouse floor). One merged mesh = one draw call; it is rebuilt only when
|
|
4
|
-
// the layer version or the ground (level
|
|
4
|
+
// the layer version or the ground changes: another ground provider (a level, or engine.setGround) or a terrain edit's ground:change.
|
|
5
5
|
// Picture: layer option tiles.color(data, cell) -> color | null, else tiles.colors = { field: color }, else the module's table grids({ tiles: { layer: { field: color } } })
|
|
6
6
|
// (first truthy field in the table's order wins), else neutral gray. tiles: false = off; a function = your own part. layer.material is the three.js material they draw with.
|
|
7
7
|
import * as THREE from 'three';
|
|
8
8
|
import { neutralMaterial } from '../../render/neutral.js';
|
|
9
9
|
import { surfaceOr } from '../../core/scene/ground.js';
|
|
10
10
|
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
11
|
+
import { follows } from '../../core/base/follows.js';
|
|
11
12
|
|
|
12
13
|
const GAP = 0.03; // fraction of a cell left between tiles: keeps tiles visibly separate (crisp edges)
|
|
13
14
|
const FALLBACK = 0x9a9a9a;
|
|
@@ -34,7 +35,8 @@ export function layerTiles(e, layer, st) {
|
|
|
34
35
|
mesh.name = `grid:${layer.grid.name}.${name}`; mesh.receiveShadow = true; mesh.frustumCulled = false;
|
|
35
36
|
e.add(mesh, { owner: 'engine:grid' });
|
|
36
37
|
let ver = -1, ground = 0, built = -1;
|
|
37
|
-
const
|
|
38
|
+
const off = e.events.on('ground:change', () => { ground++; }); // dug / raised terrain: the same ground, new heights
|
|
39
|
+
const src = follows(() => e.ground, G => G.staticVersion?.()); // another ground provider (a level came or left, setGround): the same check the ground chunks use
|
|
38
40
|
const col = new THREE.Color(), g = layer.grid;
|
|
39
41
|
function rebuild() {
|
|
40
42
|
const cells = layer.query(), pos = [], clr = [], idx = [];
|
|
@@ -59,9 +61,10 @@ export function layerTiles(e, layer, st) {
|
|
|
59
61
|
mesh,
|
|
60
62
|
frame() {
|
|
61
63
|
mesh.visible = e.world?.inZone(g) ?? true;
|
|
64
|
+
if (src.sync(() => {})) ground++;
|
|
62
65
|
if (layer._ver !== ver || ground !== built) { ver = layer._ver; built = ground; rebuild(); }
|
|
63
66
|
},
|
|
64
|
-
dispose() {
|
|
67
|
+
dispose() { off.remove(); mesh.material = own; e.remove(mesh); }, // one free through e.remove (design 6.2): the part's own geometry and material go with it; a material the game set is taken off first, so it stays the game's
|
|
65
68
|
};
|
|
66
69
|
}
|
|
67
70
|
|
package/modules/hud/index.js
CHANGED
|
@@ -211,11 +211,11 @@ export function hud(opts = {}) {
|
|
|
211
211
|
e.i18n.add(STRINGS);
|
|
212
212
|
defineHudParts(e, ctx, containers);
|
|
213
213
|
for (const ev of ['quest:start', 'quest:step', 'quest:part', 'quest:done', 'quest:fail', 'state:replaced', 'op:rolledBack']) ctx.track(e.events.on(ev, syncQuests));
|
|
214
|
-
// quest markers are derived from the quests save part: they belong to the old quests, and session:start / save:loaded rebuild them; session:failed too, the quests stayed
|
|
215
|
-
ctx.track(e.events.on('session:end', () => { for (const m of quest.values()) m.remove(); quest.clear(); }));
|
|
216
214
|
ctx.track(e.events.on('i18n:change', () => { for (const [id, it] of items) it.part?.update({ id, ...it.o }); }));
|
|
217
215
|
return api;
|
|
218
216
|
},
|
|
217
|
+
// quest markers are derived from the quests save part: they belong to the old quests, and session:start / save:loaded rebuild them; session:failed too, the quests stayed
|
|
218
|
+
sessionEnd() { for (const m of quest.values()) m.remove(); quest.clear(); },
|
|
219
219
|
frame() {
|
|
220
220
|
for (const m of api.markers) updateMarker(m);
|
|
221
221
|
// input has no event for a device switch or bind(), so a hint compares its key text each frame and redraws only on a change. Not through item():
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
// Exactly what other code reads from engine.level: marker(name) (content places, the HUD), track(handle) (a handle that goes when the level unloads),
|
|
3
3
|
// load (a level change); root / ready (hlod), markers (triggers), heightfield (vegetation's area; null when there is none).
|
|
4
4
|
// A replacement also claims provides: ['level', 'ground'] and gives the ground with ctx.ground.provide({ height, slope, type }) and emits 'level:loaded' after each load and 'level:unloaded' when a level leaves: nav and the path caches rebuild on
|
|
5
|
-
// it (not exercised by the shared check: it needs a scene).
|
|
5
|
+
// it (not exercised by the shared check: it needs a scene). The module registers the 'level' save (first: true, so the level is up before the player lands); a replacement does the same or the contract fails.
|
|
6
6
|
export default {
|
|
7
7
|
name: 'level',
|
|
8
8
|
api: ['marker', 'track', 'load'],
|
|
9
9
|
fields: ['root', 'markers', 'ready', 'heightfield'],
|
|
10
10
|
ops: [],
|
|
11
11
|
events: ['level:loaded', 'level:unloaded', 'level:failed'],
|
|
12
|
-
saves: {},
|
|
12
|
+
saves: { level: 1 },
|
|
13
13
|
describe: true,
|
|
14
14
|
options: {},
|
|
15
15
|
probe: { setup: [], emits: [], state: null },
|
package/modules/level/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// - collision: meshes named col_* (or userData.collider) become walls the character cannot cross; col_ meshes themselves are hidden
|
|
4
4
|
// - markers: objects named spawn, spawn_*, npc_*, trigger_*, marker_* (usually Blender empties) have their positions recorded
|
|
5
5
|
//
|
|
6
|
-
// engine.use(collision(), rigid(), followCamera(), characters(), level({ url: '/models/town.glb' }), triggers());
|
|
6
|
+
// engine.use(world(), collision(), rigid(), followCamera(), characters(), level({ url: '/models/town.glb' }), triggers());
|
|
7
7
|
// engine.events.on('level:loaded', ({ markers }) => {
|
|
8
8
|
// const s = engine.level.spawn; // spawn point { x, y, z }
|
|
9
9
|
// engine.characters.addPlayer({ spawn: { x: s.x, z: s.z } });
|
package/modules/music/Music.js
CHANGED
|
@@ -321,11 +321,11 @@ export function music(opts = {}) {
|
|
|
321
321
|
name: 'music', skipKind: 'none', type: 'picture', params: MUSIC_PARAMS, options: opts, label: 'Music', optional: ['dialogue'], stage: 'audio',
|
|
322
322
|
install(e, ctx) { e.i18n.add({ 'zh-CN': { 'module.music': '音乐' }, en: { 'module.music': 'music' } });
|
|
323
323
|
m = new Music(e, opts, ctx.track);
|
|
324
|
-
ctx.track(e.events.on('session:end', () => m.stop({ fade: 0 }))); // a playthrough ends: its music stops at once
|
|
325
324
|
ctx.saves.define('music', { notAtomic: 'sound, which an atomic op leaves alone: side effects go in after', save: () => ({ override: m._override ?? null, intensity: m.intensity }), load: d => m._load(d) });
|
|
326
325
|
return m;
|
|
327
326
|
},
|
|
328
327
|
frame(dt) { m.frame(dt); },
|
|
328
|
+
sessionEnd() { m.stop({ fade: 0 }); }, // a playthrough ends: its music stops at once
|
|
329
329
|
dispose() { m._close(); }, // nothing would stop a looping track once the module is gone
|
|
330
330
|
// the same state the tests read (music.state) plus why nothing may sound: audio still locked (ready false, the track waits in pending), rules on, ducked by dialogue
|
|
331
331
|
describe() { return { ...m.state, ready: m.ready, ruled: m.ruled, ducked: !!m._duck, tracks: m.tracks.size }; },
|
package/modules/nav/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Navmesh (Recast): generated after a level loads; engine.characters.findPath switches to it automatically (falls back to A* when not installed).
|
|
2
|
-
// engine.use(level({ url }), collision(), characters(), nav({ agentRadius: 0.4 }));
|
|
2
|
+
// engine.use(level({ url }), world(), collision(), characters(), nav({ agentRadius: 0.4 }));
|
|
3
3
|
// Once installed, engine.nav offers findPath(from, to) and the native objects navMesh / query / tileCache / crowd / helper.
|
|
4
4
|
// version: +1 on every rebuild / unload. Native objects (crowd agents etc.) are destroyed on rebuild; code that cached them keeps the object and compares it (NPCs compare crowd): version counts per module, so a replaced nav can show the same number.
|
|
5
5
|
//
|
package/modules/net/sync.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// at the wire (toLocal / toHost). Record fields that hold actor ids (owner...) are listed in net({ actorFields }) and swapped too.
|
|
10
10
|
|
|
11
11
|
// random/level stay per machine; inventory is the home bag 'player', sent inside containers with every other bag; rigid (body velocities, for loads)
|
|
12
|
-
// stays per machine too: each machine simulates its own physics, clients follow the host through world records (docs/recipes/11-
|
|
12
|
+
// stays per machine too: each machine simulates its own physics, clients follow the host through world records (docs/recipes/11-physics.md, section 3)
|
|
13
13
|
const SKIP = ['random', 'level', 'inventory', 'containers', 'world', 'vars', 'rigid'];
|
|
14
14
|
const GENERIC = '=';
|
|
15
15
|
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// engine.particles.count('dust') // live particle count; no name = all
|
|
13
13
|
//
|
|
14
14
|
// Params (all optional; below are the neutral fallback values):
|
|
15
|
-
// max 120 max particles alive at once (the default is 60
|
|
15
|
+
// max 120 max particles alive at once (the default is 60 while engine.tier is 'low' and follows a tier change; a number the game gives stands)
|
|
16
16
|
// lifetime [1,2] seconds each particle lives (random range)
|
|
17
17
|
// rate 10 particles per second by default for attach
|
|
18
18
|
// speed [0.5,1.5] initial speed (m/s); direction [0,1,0] emit direction; spread 0.5 max angle off the direction (radians, pi = all directions)
|
|
@@ -108,13 +108,20 @@ export class Particles {
|
|
|
108
108
|
define(name, opts = {}) {
|
|
109
109
|
readFx(`particles.define('${name}')`, opts);
|
|
110
110
|
const old = this.effects.get(name);
|
|
111
|
-
const o = { ...NEUTRAL, max: this.
|
|
112
|
-
|
|
111
|
+
const o = { ...NEUTRAL, max: this._tierMax(), ...this._fallback, ...this._given[name], ...opts };
|
|
112
|
+
// no max given anywhere: the default follows engine.tier (_tierChanged), so the buffers hold the high tier's count from the start
|
|
113
|
+
const follows = [this._fallback, this._given[name], opts].every(g => g?.max == null);
|
|
114
|
+
const fx = new Effect(this, name, o, follows ? NEUTRAL.max : undefined);
|
|
115
|
+
/** @internal */ fx._maxFollows = follows;
|
|
113
116
|
this.effects.set(name, fx);
|
|
114
117
|
// emitters attached to the old effect keep running on the new one (redefining tunes an effect, it does not stop it)
|
|
115
118
|
if (old) { for (const h of this.emitters) if (h.fx === old) h.fx = fx; old.dispose(); }
|
|
116
119
|
return fx;
|
|
117
120
|
}
|
|
121
|
+
/** @internal the default max: half on a low-tier device */
|
|
122
|
+
_tierMax() { return this.engine.tier === 'low' ? NEUTRAL.max / 2 : NEUTRAL.max; }
|
|
123
|
+
/** @internal engine.tier changed (a preset, often a stored one arriving after the effects are defined): a default max follows it in place (Effect._resize); a max the game gave stays */
|
|
124
|
+
_tierChanged() { for (const fx of this.effects.values()) if (fx._maxFollows) fx._resize(this._tierMax()); }
|
|
118
125
|
/**
|
|
119
126
|
* Whether this effect has been defined
|
|
120
127
|
* @param {string} name
|
|
@@ -174,7 +181,7 @@ export class Particles {
|
|
|
174
181
|
* @param {string} [name]
|
|
175
182
|
* @returns {void}
|
|
176
183
|
*/
|
|
177
|
-
clear(name) { for (const fx of name ? [this.effects.get(name)].filter(Boolean) : this.effects.values()) { fx.life.fill(0); fx.aAlpha.array.fill(0); fx.alive = 0; fx._stale = fx.
|
|
184
|
+
clear(name) { for (const fx of name ? [this.effects.get(name)].filter(Boolean) : this.effects.values()) { fx.life.fill(0); fx.aAlpha.array.fill(0); fx.alive = 0; fx._stale = fx.cap; fx.points.visible = false; } }
|
|
178
185
|
|
|
179
186
|
/** @internal Where the emitter is in the world (written into this._o) */
|
|
180
187
|
_at(h) {
|
|
@@ -278,7 +285,7 @@ export function particles(opts = {}) {
|
|
|
278
285
|
}
|
|
279
286
|
if (opts.default) readFx('particles({ default })', opts.default);
|
|
280
287
|
let p = null;
|
|
281
|
-
return { name: 'particles', skipKind: 'none', type: 'picture', provides: ['particles'], label: 'Particles', params: PARTICLES_PARAMS, options: opts, stage: 'effects', install(e) { e.i18n.add({ 'zh-CN': { 'module.particles': '粒子' }, en: { 'module.particles': 'particles' } }); p = new Particles(e, opts); return p; }, frame(dt) { p.update(dt); },
|
|
288
|
+
return { name: 'particles', skipKind: 'none', type: 'picture', provides: ['particles'], label: 'Particles', params: PARTICLES_PARAMS, options: opts, stage: 'effects', install(e, ctx) { e.i18n.add({ 'zh-CN': { 'module.particles': '粒子' }, en: { 'module.particles': 'particles' } }); p = new Particles(e, opts); ctx.track(e.stacks.get('tier').watch(() => p._tierChanged())); return p; }, frame(dt) { p.update(dt); },
|
|
282
289
|
dispose() { for (const fx of p.effects.values()) fx.dispose(); p.effects.clear(); p.emitters.clear(); p._depth?.target.depthTexture.dispose(); p._depth?.target.dispose(); p._depth?.material.dispose(); },
|
|
283
290
|
counts() { return { alive: p.count(), emitters: p.emitters.size }; }, // engine.counts().particles
|
|
284
291
|
// "did the dust burst fire": live particles in total and per effect that has any (idle effects left out to stay short). Kept under `alive`
|
|
@@ -48,9 +48,11 @@ function nodeSide(engine, name) {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
export class Effect {
|
|
51
|
-
|
|
51
|
+
/** @param {any} sys @param {string} name @param {any} o @param {number} [cap] buffer slots, at least o.max: room for a default max that follows engine.tier (_resize) */
|
|
52
|
+
constructor(sys, name, o, cap) {
|
|
52
53
|
this.sys = sys; this.name = name; this.o = o;
|
|
53
|
-
const N = this.
|
|
54
|
+
const N = this.cap = Math.max(1, Math.round(Math.max(cap ?? 0, o.max)));
|
|
55
|
+
/** slots in use (spawn's ring, the update loop): o.max, at most cap */ this.max = Math.max(1, Math.round(o.max));
|
|
54
56
|
this.pos = new Float32Array(N * 3); this.vel = new Float32Array(N * 3);
|
|
55
57
|
this.age = new Float32Array(N); this.life = new Float32Array(N).fill(0); // life 0 = empty slot
|
|
56
58
|
this.spinV = new Float32Array(N);
|
|
@@ -93,7 +95,7 @@ export class Effect {
|
|
|
93
95
|
|
|
94
96
|
/** @internal The geometry, material and draw object for the engine's current renderer (sprite quads on WebGPU, points on WebGL) */
|
|
95
97
|
_build() {
|
|
96
|
-
const sys = this.sys, o = this.o, N = this.
|
|
98
|
+
const sys = this.sys, o = this.o, N = this.cap, name = this.name;
|
|
97
99
|
const g = this.geometry = new THREE.BufferGeometry();
|
|
98
100
|
const gpu = nodeSide(sys.engine, name); // WebGPU: the same attributes, read per instance by sprite quads
|
|
99
101
|
const attr = (n, size) => { const a = new (gpu ? THREE.InstancedBufferAttribute : THREE.BufferAttribute)(new Float32Array(N * size), size); a.setUsage(THREE.DynamicDrawUsage); g.setAttribute(n, a); return a; };
|
|
@@ -220,5 +222,17 @@ export class Effect {
|
|
|
220
222
|
}
|
|
221
223
|
}
|
|
222
224
|
|
|
225
|
+
/**
|
|
226
|
+
* @internal a default max following engine.tier: only the slots in use change, inside buffers built for the larger count, so nothing the game holds
|
|
227
|
+
* (points, material, the uniforms its own material shares, the WebGPU nodes reading the attributes) is replaced. Particles above the new count go
|
|
228
|
+
*/
|
|
229
|
+
_resize(max) {
|
|
230
|
+
const n = Math.min(this.cap, Math.max(1, Math.round(max)));
|
|
231
|
+
if (n === this.max) return;
|
|
232
|
+
for (let i = n; i < this.max; i++) if (this.life[i] !== 0) { this.life[i] = 0; this.aAlpha.array[i] = 0; this.alive--; }
|
|
233
|
+
this.max = n; this.head %= n; this._stale = this.cap; // the next upload clears the dropped slots on the GPU too
|
|
234
|
+
this.o.max = n; // fx.o is the effect's resolved options (public): it says the count in use, a fresh object per define (Particles.js), not the game's
|
|
235
|
+
}
|
|
236
|
+
|
|
223
237
|
dispose() { this._swap.remove(); this._drop(); }
|
|
224
238
|
}
|
|
@@ -17,7 +17,7 @@ const SHOWN = 5; // the untraced list names this many, then "+N more": a line,
|
|
|
17
17
|
/** What the tracer will not draw as the game does: it reads Standard / Physical fields by name (any other model becomes a plain Standard surface),
|
|
18
18
|
* ignores TSL node slots (colorNode, positionNode…) and onBeforeCompile, needs normals, and traces meshes only (on WebGL one instance per InstancedMesh).
|
|
19
19
|
* skip: the drawOnly parts traceSnapshot hides; each one's own words say what the photo lacks */
|
|
20
|
-
|
|
20
|
+
function untracedLine(scene, skip, gpu) {
|
|
21
21
|
const why = new Map(), flat = new Set(); let other = 0, inst = 0;
|
|
22
22
|
scene.traverseVisible(o => {
|
|
23
23
|
if (skip.includes(o)) return;
|
|
@@ -21,7 +21,7 @@ import { vec3, xzOf } from '../../core/base/math.js';
|
|
|
21
21
|
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
22
22
|
import { cellsChanged } from '../../core/stream/streamCells.js';
|
|
23
23
|
import { createVehicle, VEHICLE_KEYS, STRINGS } from './Vehicles.js';
|
|
24
|
-
import { syncTerrain, syncTrees, treesChanged, syncGroundTrees, syncStatics, restandStatics, syncLevel, syncFloor, dropChunks, wantsFloor, recordLocks, carryBody, carryCollider } from './sync.js';
|
|
24
|
+
import { syncTerrain, syncTrees, treesChanged, syncGroundTrees, syncStatics, restandStatics, syncLevel, syncFloor, dropChunks, wantsFloor, recordLocks, carryBody, carryCollider, carryWorld } from './sync.js';
|
|
25
25
|
import { refreshQueries } from './refresh.js';
|
|
26
26
|
import { Ragdolls } from './ragdoll.js';
|
|
27
27
|
import { codedError, coded } from '../../core/base/errorHints.js';
|
|
@@ -167,6 +167,19 @@ export class RigidBodies {
|
|
|
167
167
|
for (const s of this._solids) this._buildSolid(s);
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
+
/** @internal some collider has a collision layer: the rapier mover only builds its pass-through filter then */
|
|
171
|
+
get layered() { return this._layered.size > 0; }
|
|
172
|
+
/** @internal the collision-module data behind a collider that has a layer, or undefined */
|
|
173
|
+
layerOf(collider) { return this._layered.get(collider); }
|
|
174
|
+
/** @internal The rapier mover asks for the player capsule to follow the character's radius; a radius the game set in rigid({ playerCapsule }) wins. Returns the radius in use */
|
|
175
|
+
fitPlayerCapsule(radius) {
|
|
176
|
+
if (this._capsuleRadiusGiven || radius === this.playerCapsule.radius) return this.playerCapsule.radius;
|
|
177
|
+
// Written back, so a rebuilt world (_newWorld) makes the same capsule
|
|
178
|
+
this.playerCapsule = { ...this.playerCapsule, radius };
|
|
179
|
+
this.playerCollider.setRadius(radius); this.playerCollider.setTranslationWrtParent({ x: 0, y: this.playerCapsule.halfHeight + radius, z: 0 });
|
|
180
|
+
return radius;
|
|
181
|
+
}
|
|
182
|
+
|
|
170
183
|
/** @internal Copies of what others own are current, as any read needs them. Every step runs it; a frozen engine runs no step, and queries still ask */
|
|
171
184
|
_upkeep() { if (syncStatics(this) | syncLevel(this) | syncFloor(this) | dropChunks(this)) this._behind = true; }
|
|
172
185
|
/**
|
|
@@ -186,7 +199,7 @@ export class RigidBodies {
|
|
|
186
199
|
* crate pushed the same way after newGame landed a few millimetres off the fresh-page result (durability audit). The world is rebuilt: the
|
|
187
200
|
* player capsule first, every body still here (bodies of world records were already removed by the load and come back with their views) at its
|
|
188
201
|
* pose with no velocity, and terrain / tree / static colliders on the next step, the order a fresh page builds them in. What the game wrote on a
|
|
189
|
-
* body or collider itself (gravityScale, axis locks, ccd, dominance, sensor, groups, enabled) is carried onto the rebuilt one (carryBody / carryCollider in sync.js). Joints are not carried: Rapier has no getters for a joint's
|
|
202
|
+
* body or collider itself (gravityScale, axis locks, ccd, dominance, sensor, groups, enabled) is carried onto the rebuilt one (carryBody / carryCollider in sync.js), and so are the world's solver settings (carryWorld). Joints are not carried: Rapier has no getters for a joint's
|
|
190
203
|
* whole description (rope length, motor settings), and copying one would mean patching Rapier. The game re-creates its own joints on rigid:rebuilt,
|
|
191
204
|
* emitted once the bodies are back (the coordination point); a dev warning names a game whose joints vanished with no re-creation. Movers'
|
|
192
205
|
* character controllers are freed with the old world (World.free frees them; movers/rapier.js sees another world object and builds new ones).
|
|
@@ -201,6 +214,7 @@ export class RigidBodies {
|
|
|
201
214
|
}
|
|
202
215
|
const old = this.world, R = this.rapier, hadJoints = old.impulseJoints.len();
|
|
203
216
|
this._newWorld();
|
|
217
|
+
carryWorld(old.integrationParameters, this.world.integrationParameters); // solver settings are the game's, like what it wrote on a body
|
|
204
218
|
this.terrain.clear(); this.trees.clear(); this.groundTrees.clear(); this._statics?.clear(); this._onGround.clear(); this._layered.clear();
|
|
205
219
|
this._level.reset(); this._levelColliders = [];
|
|
206
220
|
this._srcMemo = null; this._srcPending = false; this._syncT = 0; this._anchors = []; this._treeMemo = [];
|
|
@@ -417,7 +431,7 @@ export class RigidBodies {
|
|
|
417
431
|
* @internal What a save keeps of each body with an id (addBox / addBall / addHull({ id }), vehicles always): pose, velocities, asleep. Without it a
|
|
418
432
|
* load put a toppling crate back upright and at rest wherever its record was, so the game after the load was not the game that was saved. A template
|
|
419
433
|
* body carries its record id, and atRest (content/templates.js): while it stands where content put it, content is its state and it stays out of the save.
|
|
420
|
-
* Bodies not built yet keep their loaded state (it is still the saved game). Not kept: Rapier's contact / warm-start caches (docs/recipes/11-
|
|
434
|
+
* Bodies not built yet keep their loaded state (it is still the saved game). Not kept: Rapier's contact / warm-start caches (docs/recipes/11-physics.md, section 3).
|
|
421
435
|
*/
|
|
422
436
|
_saveState() {
|
|
423
437
|
const out = {};
|
|
@@ -477,7 +491,7 @@ export class RigidBodies {
|
|
|
477
491
|
}
|
|
478
492
|
this._upkeep();
|
|
479
493
|
if (this._jointsGone) { // dev only (set in _fresh): the old world had the game's joints and nothing re-created one since the rebuild
|
|
480
|
-
if (!this.world.impulseJoints.len()) warnOnce(coded('rigid-misuse', `rigid: ${this._jointsGone} joint(s) were freed with the old physics world by newGame / load and none was re-created. The engine rebuilds the world and does not copy joints: re-create them in a rigid:rebuilt listener ({ world }), between entry.body of the rebuilt bodies (recipes/11-
|
|
494
|
+
if (!this.world.impulseJoints.len()) warnOnce(coded('rigid-misuse', `rigid: ${this._jointsGone} joint(s) were freed with the old physics world by newGame / load and none was re-created. The engine rebuilds the world and does not copy joints: re-create them in a rigid:rebuilt listener ({ world }), between entry.body of the rebuilt bodies (recipes/11-physics.md, Joints)`));
|
|
481
495
|
this._jointsGone = 0;
|
|
482
496
|
}
|
|
483
497
|
// player capsule follows the player (the rapier mover computes collision and writes the position itself); turned off while driving to avoid colliding with
|
|
@@ -573,17 +587,17 @@ export function rigid(opts = {}) {
|
|
|
573
587
|
ctx.budget.metric('rigidBodies', () => r.bodies.length);
|
|
574
588
|
ctx.stream.addReadyCheck('rigid', s => !s.physics || r.ready && r.readyAt(s)); // a physics stream source waits for the collider under it
|
|
575
589
|
ctx.track(e.rays.addProvider((o, d, far) => r._raycast(o, d, far))); // engine.raycast(..., { targets: 'all' }) includes rigid bodies
|
|
576
|
-
// a new playthrough / a load is a fresh page for physics too (_fresh), rebuilt once per load: session:end only marks it due. With the world
|
|
577
|
-
// module the rebuild runs on world:load, after the load removed the records' bodies, so the rebuilt world gets them back in view order; without
|
|
578
|
-
// it, afterLoad (newGame / load / quit all apply a save) runs it. Rebuilding on both events built the world twice per new game.
|
|
579
590
|
// A refused load (session:failed) leaves the game as it was, physics included: no afterLoad runs after a rollback, so the state its rigid part read back is claimed here.
|
|
580
591
|
ctx.track(e.events.on('ground:change', b => { r._srcPending = true; restandStatics(r, b); })); // dug or raised ground: colliders follow on the next step, not at the half-second check a body could fall through
|
|
581
|
-
ctx.track(e.events.on('session:end', () => { r._freshDue = true; }));
|
|
582
592
|
ctx.track(e.events.on('session:failed', () => { r._freshDue = false; r._claimSaved(); }));
|
|
583
|
-
ctx.track(e.events.on('world:load', () => r._fresh()));
|
|
584
593
|
ctx.saves.define('rigid', { notAtomic: 'the physics world is stepped, not written: a load cannot rewind what the bodies did', save: () => r._saveState(), load: d => r._loadState(d) });
|
|
585
594
|
return r;
|
|
586
595
|
},
|
|
596
|
+
// a new playthrough / a load is a fresh page for physics too (_fresh), rebuilt once per load: sessionEnd only marks it due. With the world
|
|
597
|
+
// module the rebuild runs in worldLoad, after the load removed the records' bodies, so the rebuilt world gets them back in view order; without
|
|
598
|
+
// it, afterLoad (newGame / load / quit all apply a save) runs it. Rebuilding in both steps built the world twice per new game.
|
|
599
|
+
sessionEnd() { r._freshDue = true; },
|
|
600
|
+
worldLoad() { r._fresh(); },
|
|
587
601
|
afterLoad() { if (r._freshDue) r._fresh(); r._claimSaved(); }, // after every part loaded and _fresh rebuilt the world (world:load is emitted inside the world part's load)
|
|
588
602
|
async init(e, ctx) { await r.init(ctx.signal); ctx.whileCompiling(() => warmRapier(r.rapier)); },
|
|
589
603
|
counts() { return r.bodies.length; }, // engine.counts().rigid
|
package/modules/rigid/ragdoll.js
CHANGED
|
@@ -264,7 +264,7 @@ export class Ragdolls {
|
|
|
264
264
|
if (rd.anchor) this._anchor(rd);
|
|
265
265
|
}
|
|
266
266
|
|
|
267
|
-
/** End: tear down the physics and give every slot back to its owner. gone: the character
|
|
267
|
+
/** End: tear down the physics and give every slot back to its owner. gone: the character was already removed, nothing to give back; place: put the character where the body lies */
|
|
268
268
|
_end(rd, gone = false, place = true) {
|
|
269
269
|
if (!this.live.delete(rd)) return;
|
|
270
270
|
const { ch, list, anim, anchor, hold } = rd;
|
package/modules/rigid/sync.js
CHANGED
|
@@ -224,6 +224,20 @@ export function carryBody(entry, o, n) {
|
|
|
224
224
|
if (!o.isEnabled()) n.setEnabled(false);
|
|
225
225
|
}
|
|
226
226
|
|
|
227
|
+
/** @internal Copy the solver settings a game wrote on the old world (numSolverIterations, maxCcdSubsteps, contact_natural_frequency...) onto the rebuilt one.
|
|
228
|
+
* Every Rapier setter with a getter but dt (the engine writes the timestep each step), read from the prototype so a setting a Rapier update adds is carried too.
|
|
229
|
+
* contact_natural_frequency has no getter in rapier3d-compat 0.21: it is read back from contact_erp (erp = a·f / (a·f + c), a = 2π·dt, c Rapier's
|
|
230
|
+
* hidden damping term), with c measured on the new world by setting a known frequency there, so no Rapier constant is copied here */
|
|
231
|
+
export function carryWorld(o, n) {
|
|
232
|
+
const proto = Object.getPrototypeOf(o), d = k => Object.getOwnPropertyDescriptor(proto, k);
|
|
233
|
+
for (const k of Object.getOwnPropertyNames(proto)) if (k !== 'dt' && d(k).set && d(k).get && o[k] !== n[k]) n[k] = o[k];
|
|
234
|
+
if (!d('contact_natural_frequency')?.set || !d('contact_erp')?.get) return;
|
|
235
|
+
const a0 = 2 * Math.PI * o.dt, a1 = 2 * Math.PI * n.dt, f1 = 30;
|
|
236
|
+
n.contact_natural_frequency = f1;
|
|
237
|
+
const e0 = o.contact_erp, e1 = n.contact_erp, c = a1 * f1 * (1 - e1) / e1;
|
|
238
|
+
if (e0 > 0 && e0 < 1) n.contact_natural_frequency = c * e0 / ((1 - e0) * a0);
|
|
239
|
+
}
|
|
240
|
+
|
|
227
241
|
/** @internal Copy game-set collider state from the old collider onto the one rebuilt from the entry's desc */
|
|
228
242
|
export function carryCollider(o, n) {
|
|
229
243
|
const pairs = [['isSensor', 'setSensor'], ['collisionGroups', 'setCollisionGroups'], ['solverGroups', 'setSolverGroups'], ['friction', 'setFriction'],
|
|
@@ -41,7 +41,7 @@ import { applySetting, allowed, checkLimits, releaseLimits, releaseRow, ROLE_ROW
|
|
|
41
41
|
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
42
42
|
import { codedError, coded } from '../../core/base/errorHints.js';
|
|
43
43
|
import { warnOnce } from '../../core/base/validate.js';
|
|
44
|
-
import { pixelSizeOn } from '../../core/scene/pixelRatio.js';
|
|
44
|
+
import { chooseRatio, pixelSizeOn } from '../../core/scene/pixelRatio.js';
|
|
45
45
|
import { trackForModule } from '../../core/engine/moduleTypes.js';
|
|
46
46
|
|
|
47
47
|
// Graphics presets. Values are performance steps, not art; a game can override with settings({ presets: { low: {...} } })
|
|
@@ -272,6 +272,7 @@ export class Settings extends SettingsView {
|
|
|
272
272
|
if (!(k in this._values) || def(k) === undefined) { if (key !== undefined) warnOnce(`settings.reset('${k}'): no setting with this key (known: ${Object.keys(this._values).join(', ')})`); continue; }
|
|
273
273
|
this.set(k, def(k), { save: false });
|
|
274
274
|
if (!(k in preset)) delete this._changed[k];
|
|
275
|
+
if (k === 'pixelRatio') chooseRatio(this.engine, null); // a reset hands the ratio back to the game, also where a kept preset stores the default
|
|
275
276
|
}
|
|
276
277
|
this.save();
|
|
277
278
|
}
|
|
@@ -373,7 +374,7 @@ export class Settings extends SettingsView {
|
|
|
373
374
|
this._ready = true;
|
|
374
375
|
const picked = this._picked(), e = this.engine;
|
|
375
376
|
for (const k of this._early) if (!this._hasRow(k)) warnOnce(coded('settings-row', `settings.set('${k}') before start: no row came for this key, so nothing applied it`));
|
|
376
|
-
// start() may have learned
|
|
377
|
+
// a preset's ratio is a share of the device default, which start() may have learned only now (the WebGPU route): worked out again from it
|
|
377
378
|
this._defaults.pixelRatio = +e.adaptive.base.toFixed(2);
|
|
378
379
|
this._values.pixelRatio = picked.pixelRatio ?? this._defaults.pixelRatio;
|
|
379
380
|
if ('pixelRatio' in picked) this._apply('pixelRatio', picked.pixelRatio);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { reportError } from '../../core/base/errors.js';
|
|
2
2
|
import { codedError } from '../../core/base/errorHints.js';
|
|
3
|
+
import { chooseRatio, topRatio } from '../../core/scene/pixelRatio.js';
|
|
3
4
|
// Apply one setting to the engine (helper of Settings.js): the built-in keys (pixel ratio, shadows, post effects, quality tier, audio buses) and the rows of modules and of
|
|
4
5
|
// the game (define). `s` is the Settings instance.
|
|
5
6
|
|
|
@@ -40,7 +41,7 @@ function limitRow(s, key, names, val) {
|
|
|
40
41
|
/** @internal a row leaves: no control is left to lift its limits, so it gives back every shared value it holds @param {any} s @param {string} key */
|
|
41
42
|
export function releaseRow(s, key) { for (const n of s._held.get(key) ?? []) lift(s.engine, n); s._held.delete(key); }
|
|
42
43
|
/** @internal the module leaves: so does every row, and the tier it chose */
|
|
43
|
-
export function releaseLimits(s) { for (const key of [...s._held.keys()]) releaseRow(s, key); lift(s.engine, 'tier'); }
|
|
44
|
+
export function releaseLimits(s) { for (const key of [...s._held.keys()]) releaseRow(s, key); lift(s.engine, 'tier'); chooseRatio(s.engine, null); }
|
|
44
45
|
/** @internal the row's value fits the points it limits: a switch row (boolean) limits switches or numbers, a number row (a factor) only numbers */
|
|
45
46
|
export function checkLimits(s, key, def, names) {
|
|
46
47
|
const e = s.engine;
|
|
@@ -64,10 +65,10 @@ export function applySetting(s, key, val) {
|
|
|
64
65
|
const limits = builtinLimits(e)[key] ?? s.custom.get(key)?.limits;
|
|
65
66
|
if (limits) limitRow(s, key, limits, typeof val === 'number' ? val : !!val);
|
|
66
67
|
switch (key) {
|
|
67
|
-
case 'pixelRatio': e
|
|
68
|
+
case 'pixelRatio': chooseRatio(e, val); break; // settings.reset hands the ratio back to the game (chooseRatio(e, null))
|
|
68
69
|
case 'antialias': e.post.nextAntialias(val); break;
|
|
69
70
|
case 'tier': if (val) e.mod('tier', { owner: 'settings', layer: 'settings', set: val }); else e.stacks.get('tier').release('settings'); break;
|
|
70
|
-
case 'adaptive': if (e.adaptive) { e.adaptive.on = val; if (!val
|
|
71
|
+
case 'adaptive': if (e.adaptive) { e.adaptive.on = val; if (!val) topRatio(e); } break;
|
|
71
72
|
default:
|
|
72
73
|
// a saved slider for a bus this build no longer has is skipped, not an error
|
|
73
74
|
if (key.startsWith('vol.')) { if (key.slice(4) in e.audio.levels) e.audio.setVolume(key.slice(4), val); }
|
|
@@ -51,7 +51,7 @@ export function settingsTools(engine, esc) {
|
|
|
51
51
|
const labelOf = (e, text) => e.i18n.has(text) ? e.t(text) : text;
|
|
52
52
|
/**
|
|
53
53
|
* The rows settings.define() draws itself, in the tab its menu option names (default 'options'). Why the engine draws them: a row defined
|
|
54
|
-
* and drawn by no tab was a setting the player could never reach, and nothing said so (
|
|
54
|
+
* and drawn by no tab was a setting the player could never reach, and nothing said so (e.g. a game's own quality rows). menu: false = the game draws it.
|
|
55
55
|
* @param {any} tools @param {any} e @param {any} s @param {string | null} tab @returns {string}
|
|
56
56
|
*/
|
|
57
57
|
export function definedRows(tools, e, s, tab) {
|
package/modules/sky/Sky.js
CHANGED
|
@@ -99,6 +99,7 @@ export class Sky {
|
|
|
99
99
|
|
|
100
100
|
/** The day's rows as colors (start, keyframes()) @internal */
|
|
101
101
|
_setKeyframes(rows) {
|
|
102
|
+
/** @internal the rows as given, for keyframes() with no argument (copied, so a later edit of the caller's array changes nothing here) */ this._rows = rows.map(r => [...r]);
|
|
102
103
|
/** @internal */ this.kf = rows.map(k => [k[0], new THREE.Color(k[1]), new THREE.Color(k[2]), new THREE.Color(k[3]), k[4]]);
|
|
103
104
|
// brightest row of the sky's ambient light (ambient column x the hemi color's brightness, frame.js skyLight): the sky's light now / this is
|
|
104
105
|
// the 0-1 scale the sky.tint color (weather grey) follows
|
|
@@ -108,12 +109,16 @@ export class Sky {
|
|
|
108
109
|
|
|
109
110
|
/**
|
|
110
111
|
* The day's colors, live: rows [time, zenith, horizon, sunColor, ambient] sorted from 0 to 1 (the same rows as sky({ keyframes })).
|
|
111
|
-
* Throws, changing nothing, on rows that are not sorted from 0 to 1.
|
|
112
|
+
* Throws, changing nothing, on rows that are not sorted from 0 to 1. No argument: a copy of the rows in use (a picture gives them back on leaving).
|
|
112
113
|
* @example engine.sky.keyframes([[0, 0x101828, 0x202838, 0x8090b0, 0.3], [0.5, 0x4080c0, 0xc0d8e8, 0xffffff, 1.2], [1, 0x101828, 0x202838, 0x8090b0, 0.3]]);
|
|
113
|
-
* @param {any[][]} rows
|
|
114
|
-
* @returns {
|
|
114
|
+
* @param {any[][]} [rows]
|
|
115
|
+
* @returns {any[][]} the rows in use
|
|
115
116
|
*/
|
|
116
|
-
keyframes(rows) {
|
|
117
|
+
keyframes(rows) {
|
|
118
|
+
if (rows === undefined) return this._rows.map(r => [...r]); // a copy: editing it changes nothing until it is passed back
|
|
119
|
+
checkKeyframes(rows); this._setKeyframes(rows);
|
|
120
|
+
return rows;
|
|
121
|
+
}
|
|
117
122
|
|
|
118
123
|
/**
|
|
119
124
|
* Sun direction (unit vector toward the sun): the same vector as engine.uniforms.uSunDir. Computed each frame from the time and orbit until a game writes either,
|
|
@@ -45,7 +45,7 @@ export const environmentMethods = {
|
|
|
45
45
|
const e = this.engine, env = this._env = { into, get interval() { return interval ?? (e.tier === 'low' ? DEFAULT_INTERVAL * LOW_TIER_SLOWER : DEFAULT_INTERVAL); }, key: null, since: 0, builds: 0, target: null, deferred: !this._envFramed };
|
|
46
46
|
// an explicit call takes the map back from a game write; the warning's way back then names this `into`
|
|
47
47
|
this._oEnv.manual(false); this._oEnv.levels = { ...this._oEnv.levels, back: `engine.sky.environment({ into: ${into === e.scene ? 'engine.scene' : 'into'} })` };
|
|
48
|
-
this._oEnv.mark(); // what `into` holds now is the reference: the first build replaces it
|
|
48
|
+
this._oEnv.mark(); // what `into` holds now is the reference: the first build replaces it, only a later write by the game is a takeover
|
|
49
49
|
if (!env.deferred) this._envBuild();
|
|
50
50
|
// a lost context takes the map's pixels with it, and the key cannot see that: with the sky standing still (a fixed hour) the map would stay black
|
|
51
51
|
env.restored = this.engine.events.on('page:contextrestored', () => { env.key = null; env.deferred = true; });
|
|
@@ -78,10 +78,12 @@ export const environmentMethods = {
|
|
|
78
78
|
this._envScene.add(copy);
|
|
79
79
|
}
|
|
80
80
|
/** @type {any} */ (this._envScene.children[0]).material = this.dome.material; // a game may have set engine.sky.dome.material
|
|
81
|
-
|
|
81
|
+
// WebGPU: the rebuild refills the same target. A new texture there made every material that reads the environment build again: a stall of 100 ms
|
|
82
|
+
// to seconds at each rebuild, measured on the open-world start. three 0.187's WebGL generator has no renderTarget option and returns a new one, which costs nothing there
|
|
83
|
+
const old = e.target, next = this._pmrem.fromScene(this._envScene, 0, 0.1, 100, { size: 256, renderTarget: old });
|
|
82
84
|
// a map the game wrote there is the game's: the owned check (frame.js) has yielded, and the sky writes it no more
|
|
83
85
|
if (e.into && this._oEnv.on) { e.into.environment = next.texture; this._oEnv.mark(); }
|
|
84
|
-
|
|
86
|
+
if (old !== next) old?.dispose(); e.target = next;
|
|
85
87
|
e.builds++; e.key = skyKey(this);
|
|
86
88
|
},
|
|
87
89
|
|
package/modules/terrain/index.js
CHANGED
|
@@ -30,7 +30,6 @@ import { loadGray } from '../../core/scene/grayMap.js';
|
|
|
30
30
|
import { prepareShape, voidWatcher } from './terrainShapeMain.js';
|
|
31
31
|
import { TerrainDraw, checkGround } from './draw.js';
|
|
32
32
|
import { codedError } from '../../core/base/errorHints.js';
|
|
33
|
-
import { onTierChange } from '../../core/scene/tier.js';
|
|
34
33
|
|
|
35
34
|
const NO_HEIGHT = 'terrain(): no height function or height map was given, so the ground is flat gray at y = 0 (a placeholder, not a picture). '
|
|
36
35
|
+ 'Pass terrain({ height, groundType }) or a preset, e.g. terrain({ ...terrainPreset() }) with terrainPreset from @threedog/terrain-noise';
|
|
@@ -129,7 +128,7 @@ export function terrain(opts = {}) {
|
|
|
129
128
|
// the low-tier color map follows the tier (a stored preset arrives after this install). A resolution the game gave in terrain({}) stays; recolor cannot set one
|
|
130
129
|
// (it is not in recolor's keys), so the only other writer is this listener. Followed by reinit, the path recolor takes too: every chunk is generated again, which is
|
|
131
130
|
// fine at a settings change (and before the first frame it is free). Only colorResolution is changed, on the live object: init above may still be loading images into it
|
|
132
|
-
ctx.track(
|
|
131
|
+
ctx.track(e.stacks.get('tier').watch(() => {
|
|
133
132
|
const c = state.cfg;
|
|
134
133
|
if (cfg.colorResolution != null) return;
|
|
135
134
|
const want = drawConfig(e, { ...c, colorResolution: undefined }).colorResolution;
|
|
@@ -132,7 +132,11 @@ export class Timeline {
|
|
|
132
132
|
run.error = err?.message ?? String(err);
|
|
133
133
|
this._stop(run, 'failed'); // a parallel branch beside the throw is still waiting
|
|
134
134
|
} finally {
|
|
135
|
-
if (run.faded
|
|
135
|
+
if (run.faded) { // the run still holds the screen dark
|
|
136
|
+
fadeScreen(e, 0, { seconds: 0, owner: `timeline:${run.id}` });
|
|
137
|
+
// dropped / failed: the steps that would have faded back in will not run. Finished / skipped on a dark step: the cover is handed to the scene change (owner 'flow'), the next flow.transition lifts it
|
|
138
|
+
if (!gone(run)) fadeScreen(e, run.faded, { seconds: 0, owner: 'flow' });
|
|
139
|
+
}
|
|
136
140
|
turn.remove();
|
|
137
141
|
releaseCamera(this, run);
|
|
138
142
|
run.focus.remove();
|
|
@@ -230,11 +234,11 @@ export class Timeline {
|
|
|
230
234
|
|
|
231
235
|
/** Full-screen fade: jumps to the target when skipped. faded: the run holds the screen, so an ending that drops the later steps gives it back @internal */
|
|
232
236
|
async _fade(seconds, to, run) {
|
|
233
|
-
const now = () => fadeScreen(this.engine, to, { seconds: 0 });
|
|
234
|
-
run.faded = to > 0;
|
|
237
|
+
const owner = `timeline:${run.id}`, now = () => fadeScreen(this.engine, to, { seconds: 0, owner });
|
|
238
|
+
run.faded = to > 0 ? to : 0;
|
|
235
239
|
if (run.ending) return now();
|
|
236
240
|
run.cancels.add(now);
|
|
237
|
-
await fadeScreen(this.engine, to, { seconds });
|
|
241
|
+
await fadeScreen(this.engine, to, { seconds, owner });
|
|
238
242
|
run.cancels.delete(now);
|
|
239
243
|
}
|
|
240
244
|
|
|
@@ -321,11 +325,10 @@ export function timeline(opts = {}) {
|
|
|
321
325
|
name: 'timeline', skipKind: 'none', type: 'rules', params: TIMELINE_PARAMS, options: opts, label: 'Timeline', stage: 'control', before: ['cameraRig'], optional: ['dialogue'], // before the camera, so the takeover applies on the same frame
|
|
322
326
|
install(e, ctx) {
|
|
323
327
|
e.i18n.add(STRINGS); t = new Timeline(e, ctx);
|
|
324
|
-
// a running cutscene ends with its playthrough (session waits one macrotask for its steps to settle)
|
|
325
|
-
ctx.track(e.events.on('session:end', () => t._drop()));
|
|
326
328
|
return t;
|
|
327
329
|
},
|
|
328
330
|
frame(dt) { t.frame(dt); },
|
|
331
|
+
sessionEnd() { t._drop(); }, // a running cutscene ends with its playthrough (session waits one macrotask for its steps to settle)
|
|
329
332
|
afterLoad() { t._drop(r => r.duringLoad); },
|
|
330
333
|
// unloaded mid-cutscene: every run ends through its finally (camera, focus, actors go back); nothing else would, the frame hook is gone
|
|
331
334
|
dispose() { t._drop(); t._tweener.cancelAll(); }, // also the tweens started with timeline.tween(): no run owns them
|
|
@@ -168,7 +168,7 @@ export class Vegetation {
|
|
|
168
168
|
if (o.positions != null) checkPositions(`vegetation.define('${name}')`, o.positions, o.rule);
|
|
169
169
|
const density = o.densityMap != null ? makeDensity(o.densityMap, `vegetation.define('${name}')`) : null;
|
|
170
170
|
// distance fade band of near-only species (nearFade.js), checked here so a bad band throws at define; the draw part draws it
|
|
171
|
-
// impostor and lodGeometry both say what is drawn beyond lodRing: one owner (docs/plans/2026-11-09-impostors.md)
|
|
171
|
+
// impostor and lodGeometry both say what is drawn beyond lodRing: one owner (docs/plans/done/2026-11-09-impostors.md)
|
|
172
172
|
if (o.impostor && o.lodGeometry) throw codedError('vegetation-option', `vegetation.define('${name}'): impostor and lodGeometry both say what is drawn beyond lodRing; keep one`);
|
|
173
173
|
if (o.impostor != null) checkImpostor(`vegetation.define('${name}')`, o.impostor);
|
|
174
174
|
if (o.fade && typeof o.fade === 'object') readParams(`vegetation.define('${name}').fade`, keysSchema(['start', 'end']), o.fade);
|
|
@@ -54,7 +54,7 @@ export function vegetation(opts = {}) {
|
|
|
54
54
|
install(e, ctx) {
|
|
55
55
|
e.i18n.add({ 'zh-CN': { 'module.vegetation': '植被' }, en: { 'module.vegetation': 'vegetation' } });
|
|
56
56
|
v = new Vegetation(e, opts, ctx);
|
|
57
|
-
ctx.track(e.
|
|
57
|
+
ctx.track(e.stacks.get('shadows.enabled').watch(() => v.host.refreshLevels())); // whichever chunks it grows on: each level pass rereads the shadow switch
|
|
58
58
|
if (v.host !== e.terrain) {
|
|
59
59
|
own = v.host;
|
|
60
60
|
ctx.ground.addColliders((x, z, range, fn) => own.forEachCollider(x, z, range, fn)); // collision and path planning see the trees
|
|
@@ -8,7 +8,6 @@ import { readParams, keysSchema } from '../../core/base/params.js';
|
|
|
8
8
|
import { isOptions } from '../../core/base/util.js';
|
|
9
9
|
import { codedError } from '../../core/base/errorHints.js';
|
|
10
10
|
import { onRendererSwap } from '../../render/backend.js';
|
|
11
|
-
import { onTierChange } from '../../core/scene/tier.js';
|
|
12
11
|
import { makeSystem, updateSystem, dropSystem, RAIN, SNOW } from './particles.js';
|
|
13
12
|
|
|
14
13
|
const DRAW_PARAMS = keysSchema(['particles', 'area', 'rain', 'snow']); // the picture options of weather(): the rest are the state's
|
|
@@ -144,7 +143,7 @@ export function weatherDrawModule(opts) {
|
|
|
144
143
|
L = new WeatherDraw(e, opts);
|
|
145
144
|
L._ctx = ctx; // the weather's entries on the shared points go with this module (ctx.mod)
|
|
146
145
|
ctx.track(onRendererSwap(e, () => L._rebuild()));
|
|
147
|
-
ctx.track(
|
|
146
|
+
ctx.track(e.stacks.get('tier').watch(() => L._tierChanged())); // the default particle count follows the tier
|
|
148
147
|
ctx.track(e.audio.condition('weather', v => [].concat(v).includes(e.weather.name))); // audio rule condition { weather: 'rain' | ['rain', 'storm'] }
|
|
149
148
|
for (const k of ['rain', 'snow', 'wind']) ctx.track(e.audio.measure(k, () => e.weather.current[k])); // data rules: { rain: { lt: 0.2 } }, volume add: { rain: 0.22 }
|
|
150
149
|
builtInSounds(e.assets, { thunder: (audio, p, out) => { const dur = p.duration ?? 3.5, delay = 0.4 + Math.random() * 1.5; // presentation: thunder delay
|
package/modules/world/World.js
CHANGED
|
@@ -28,6 +28,7 @@ export class World {
|
|
|
28
28
|
constructor(engine, opts = {}) {
|
|
29
29
|
const { cellSize = 32, radius = 60, farEvery = 1, farMaxPerTick = 500, buildPerFrame = 8 } = opts;
|
|
30
30
|
/** @internal */ this.engine = engine;
|
|
31
|
+
/** @internal ctx.things.recordsLoaded, set at install (index.js): the worldLoad reset step and 'world:load' after a wholesale replace (persist.js) @type {(info: { count: number }) => void} */ this._recordsLoaded = () => {};
|
|
31
32
|
initState(this, cellSize);
|
|
32
33
|
/** All records: id → record (read-only; use set to change fields, move to change position) @type {Map<string, WorldRecord>} @experimental */
|
|
33
34
|
this.records = new Map();
|
package/modules/world/index.js
CHANGED
|
@@ -50,6 +50,7 @@ export function world(opts = {}) {
|
|
|
50
50
|
ctx.track(e.onFixed(() => w._v.pull(), { phase: 'late' }));
|
|
51
51
|
ctx.track(e.time.onMove(() => w._s.moved()));
|
|
52
52
|
ctx.saves.define('world', { atomic: true, version: 5, migrate: WORLD_MIGRATE, save: () => w.toJSON(), load: d => w.fromJSON(d), checkNewGame: codePlaced });
|
|
53
|
+
w._recordsLoaded = ctx.things.recordsLoaded;
|
|
53
54
|
ctx.things.addSource(recordSource(w)); // engine.thing / thing.set / the shared id space reach the records through this
|
|
54
55
|
ctx.things.explainWith(worldExplain);
|
|
55
56
|
ctx.budget.metric('worldRecords', () => w.records.size);
|
package/modules/world/persist.js
CHANGED
|
@@ -209,7 +209,7 @@ export function loadWorld(w, d) {
|
|
|
209
209
|
for (const [id, base] of w._base) if (!w._removed.has(id)) w._insert(w._fromBase(id, base));
|
|
210
210
|
for (const [id, r] of Object.entries(d?.records || {})) w._insert({ id, ...r });
|
|
211
211
|
if (built) w._v.keepSame(built);
|
|
212
|
-
w.
|
|
212
|
+
w._recordsLoaded({ count: w.records.size }); // ctx.things.recordsLoaded: the modules' worldLoad step, then 'world:load' (core/saves/session.js step 2)
|
|
213
213
|
}
|
|
214
214
|
|
|
215
215
|
/**
|