threedog 0.8.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +223 -4
- package/README.md +6 -6
- package/core/assets/Animator.js +2 -0
- package/core/assets/Assets.js +44 -13
- package/core/assets/assetEntry.js +87 -22
- package/core/assets/assetHot.js +2 -1
- package/core/assets/assetReport.js +1 -2
- package/core/audio/Audio.js +24 -5
- package/core/base/I18n.js +6 -3
- package/core/base/Random.js +3 -1
- package/core/base/Vars.js +14 -4
- package/core/base/errorCodes.js +54 -16
- package/core/base/errorHints.js +12 -1
- package/core/base/errors.js +6 -4
- package/core/base/events.generated.js +10 -0
- package/core/base/follows.js +26 -0
- package/core/base/math.js +15 -8
- package/core/base/params.js +2 -2
- package/core/{saves → base}/saveValues.js +24 -6
- package/core/base/sections.js +97 -0
- package/core/base/spelling.js +32 -0
- package/core/base/validate.js +8 -29
- package/core/engine/Engine.js +61 -18
- package/core/engine/Loading.js +30 -3
- package/core/engine/copies.js +1 -1
- package/core/engine/headlessLoad.js +30 -13
- package/core/engine/lifecycle.js +30 -25
- package/core/engine/loop.js +22 -4
- package/core/engine/moduleSlots.js +91 -15
- package/core/engine/moduleTypes.js +13 -0
- package/core/engine/modules.js +248 -62
- package/core/engine/page.js +25 -8
- package/core/engine/plugins.js +15 -3
- package/core/engine/services.js +3 -0
- package/core/engine/startup.js +46 -36
- package/core/input/Input.js +39 -19
- package/core/input/inputKeyboard.js +39 -0
- package/core/input/inputPad.js +23 -2
- package/core/input/inputPointer.js +3 -1
- package/core/input/inputSeat.js +66 -0
- package/core/input/inputTouch.js +23 -6
- package/core/inspect/DebugOverrides.js +13 -2
- package/core/inspect/Describe.js +10 -6
- package/core/inspect/Inspect.js +31 -4
- package/core/inspect/UrlState.js +14 -10
- package/core/inspect/catalog.js +12 -5
- package/core/inspect/describeRender.js +3 -2
- package/core/inspect/describeText.js +6 -2
- package/core/inspect/metadata.generated.js +4140 -0
- package/core/inspect/pictureWriters.js +117 -33
- package/core/inspect/toolDoor.js +21 -0
- package/core/inspect/valueHistory.js +35 -0
- package/core/ops/Ops.js +32 -7
- package/core/ops/control.js +48 -23
- package/core/ops/holds.js +4 -3
- package/core/ops/opsAtomic.js +18 -6
- package/core/ops/opsCheck.js +7 -5
- package/core/ops/opsFail.js +5 -7
- package/core/ops/opsRun.js +2 -2
- package/core/ops/owned.js +20 -3
- package/core/ops/sharedPoint.js +7 -10
- package/core/ops/stacks.js +22 -1
- package/core/saves/SaveStore.js +52 -26
- package/core/saves/Saves.js +122 -27
- package/core/saves/saveApply.js +159 -61
- package/core/saves/saveFiles.js +30 -25
- package/core/saves/saveVersions.js +20 -6
- package/core/saves/session.js +76 -33
- package/core/saves/stateReplace.js +184 -0
- package/core/scene/Rays.js +21 -5
- package/core/scene/Views.js +6 -6
- package/core/scene/adaptive.js +13 -10
- package/core/scene/canvasBox.js +2 -0
- package/core/scene/compositeGround.js +72 -0
- package/core/scene/floor.js +17 -0
- package/core/scene/grid.js +2 -0
- package/core/scene/ground.contract.js +14 -0
- package/core/scene/ground.js +52 -17
- package/core/scene/pixel.js +154 -0
- package/core/scene/pixelRatio.js +167 -0
- package/core/scene/sceneDelta.js +3 -3
- package/core/scene/sceneMethods.js +11 -6
- package/core/scene/stepPoses.js +6 -1
- package/core/scene/thingExplain.js +1 -1
- package/core/scene/thingOps.js +22 -14
- package/core/scene/things.js +1 -1
- package/core/scene/tier.js +10 -0
- package/core/scene/view.js +126 -9
- package/core/stream/Batching.js +0 -1
- package/core/stream/Stream.js +24 -12
- package/core/stream/batchGroups.js +1 -0
- package/core/stream/scatter.js +5 -2
- package/core/stream/streamSources.js +2 -1
- package/core/threads/Commits.js +12 -7
- package/core/threads/Jobs.js +15 -5
- package/core/threads/Threads.js +5 -2
- package/core/time/Clock.js +3 -1
- package/core/time/skip.js +10 -4
- package/core/time/time.js +16 -10
- package/docs/AI.md +89 -72
- package/docs/API.md +18 -14
- package/docs/CODEMAP.md +68 -40
- package/docs/COMMANDS.md +22 -23
- package/docs/CONVENTIONS.md +120 -17
- package/docs/MIGRATING-0.8.md +2 -0
- package/docs/MIGRATING-1.0.md +101 -0
- package/docs/THREE.md +65 -12
- package/docs/api/cameraRig.md +3 -0
- package/docs/api/characters.md +13 -7
- package/docs/api/collider3d.md +9 -0
- package/docs/api/content.md +16 -15
- package/docs/api/dialogue.md +2 -1
- package/docs/api/engine.md +18 -16
- package/docs/api/events.md +14 -4
- package/docs/api/ground.md +2 -2
- package/docs/api/i18n.md +1 -1
- package/docs/api/input.md +2 -1
- package/docs/api/interactions.md +1 -1
- package/docs/api/inventory.md +1 -1
- package/docs/api/level.md +3 -2
- package/docs/api/nav.md +4 -2
- package/docs/api/particles.md +8 -5
- package/docs/api/pickups.md +1 -1
- package/docs/api/post.md +3 -4
- package/docs/api/quests.md +4 -2
- package/docs/api/rays.md +2 -0
- package/docs/api/rigid.md +3 -2
- package/docs/api/saves.md +8 -7
- package/docs/api/stream.md +4 -5
- package/docs/api/terrain.md +3 -4
- package/docs/api/terrainDraw.md +1 -1
- package/docs/api/timeline.md +2 -2
- package/docs/api/tools.md +3 -1
- package/docs/api/triggers.md +2 -0
- package/docs/api/vegetationDraw.md +1 -1
- package/docs/api/water.md +6 -2
- package/docs/api/weather.md +19 -4
- package/docs/api/weatherDraw.md +1 -1
- package/docs/api/world.md +1 -1
- package/docs/recipes/01-new-game.md +3 -3
- package/docs/recipes/02-npc.md +3 -4
- package/docs/recipes/03-items-pickups.md +11 -11
- package/docs/recipes/04-quests.md +2 -0
- package/docs/recipes/05-props-bake.md +9 -9
- package/docs/recipes/06-clock-events.md +6 -6
- package/docs/recipes/07-flow-scenes-pause.md +18 -15
- package/docs/recipes/08-weather-sky.md +5 -5
- package/docs/recipes/09-materials-lights-models.md +3 -3
- package/docs/recipes/10-blender-level.md +16 -4
- package/docs/recipes/11-vehicles.md +18 -6
- package/docs/recipes/12-navmesh.md +52 -8
- package/docs/recipes/13-animation.md +34 -8
- package/docs/recipes/14-custom-module.md +20 -8
- package/docs/recipes/15-perf.md +4 -4
- package/docs/recipes/16-dev-bridge.md +9 -8
- package/docs/recipes/18-world.md +13 -5
- package/docs/recipes/19-shooting-picking.md +3 -2
- package/docs/recipes/20-content-actions-save.md +26 -6
- package/docs/recipes/21-camera.md +17 -23
- package/docs/recipes/22-shop-gold.md +21 -12
- package/docs/recipes/23-ops.md +19 -15
- package/docs/recipes/26-ui-parts.md +3 -2
- package/docs/recipes/27-net.md +3 -3
- package/docs/recipes/28-terrain.md +3 -3
- package/docs/recipes/29-grid.md +1 -1
- package/docs/recipes/30-templates.md +10 -13
- package/docs/recipes/31-audio.md +2 -2
- package/docs/recipes/32-action-game.md +6 -5
- package/docs/recipes/33-stream-sources.md +4 -1
- package/docs/recipes/34-environment-lighting.md +7 -8
- package/docs/recipes/35-picture-from-reference.md +13 -9
- package/docs/recipes/36-ground-plants.md +3 -2
- package/docs/recipes/40-scene.md +11 -10
- package/docs/recipes/43-shader-patches-surfaces.md +7 -7
- package/docs/recipes/44-water-weather-hooks.md +9 -8
- package/docs/recipes/45-cascaded-shadows.md +3 -4
- package/docs/recipes/46-blender-art-route.md +3 -3
- package/docs/recipes/49-game-module-contract.md +2 -1
- package/docs/recipes/50-own-renderer.md +1 -0
- package/docs/recipes/51-capability-catalog.md +14 -8
- package/docs/recipes/52-around-the-picture.md +4 -4
- package/docs/recipes/55-mods-time-wrap.md +5 -4
- package/docs/recipes/56-webgpu-tsl.md +12 -1
- package/docs/recipes/57-control.md +30 -10
- package/docs/recipes/58-input.md +13 -0
- package/docs/recipes/60-judge-the-picture.md +1 -1
- package/docs/recipes/62-picture-code.md +106 -48
- package/docs/recipes/63-third-person-start.md +2 -1
- package/docs/recipes/64-particles.md +53 -4
- package/docs/recipes/65-swarm.md +2 -2
- package/docs/recipes/66-common-tasks.md +313 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +3 -3
- package/examples/perf-island/.threedog/content-index.json +1 -1
- package/examples/perf-island/GAMEMAP.md +3 -3
- package/examples/perf-island/main.js +2 -2
- package/examples/plain-picture/GAMEMAP.md +3 -1
- package/examples/rc2d/GAMEMAP.md +1 -1
- package/examples/rc2d/rc2d.js +1 -1
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +3 -3
- package/examples/webgpu-tsl/GAMEMAP.md +1 -1
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +5 -4
- package/examples/world/main.js +3 -3
- package/index.d.ts +8 -5
- package/index.js +22 -1
- package/llms.txt +2 -1
- package/modules/ambience/Ambience.js +5 -3
- package/modules/calendar/index.js +7 -5
- package/modules/camera/FirstPersonCamera.js +3 -3
- package/modules/camera/FixedCamera.js +34 -20
- package/modules/camera/FollowCamera.js +20 -11
- package/modules/camera/RtsCamera.js +1 -0
- package/modules/camera/common.js +33 -22
- package/modules/camera/pixelSnap.js +62 -0
- package/modules/characters/Character.js +136 -43
- package/modules/characters/NPC.js +60 -28
- package/modules/characters/assetModel.js +2 -2
- package/modules/characters/astar.js +47 -28
- package/modules/characters/character.contract.js +21 -0
- package/modules/characters/contract.js +17 -3
- package/modules/characters/index.js +94 -34
- package/modules/characters/moveHelpers.js +80 -15
- package/modules/characters/mover.contract.js +14 -0
- package/modules/characters/movers/common.js +6 -4
- package/modules/characters/movers/rapier.js +12 -5
- package/modules/characters/movers/simple.js +25 -12
- package/modules/characters/movers/support.js +18 -7
- package/modules/characters/npcAvoid.js +15 -12
- package/modules/characters/npcSim.js +75 -25
- package/modules/characters/npcView.js +13 -6
- package/modules/characters/pathAsync.js +74 -24
- package/modules/characters/pathJob.js +38 -21
- package/modules/characters/player.js +59 -47
- package/modules/characters/seat.js +56 -0
- package/modules/characters/vehicle.contract.js +8 -5
- package/modules/characters/walkTo.js +31 -18
- package/modules/collision/Collision.js +44 -26
- package/modules/collision/contract.js +2 -2
- package/modules/collision/grid.js +6 -1
- package/modules/content/explain.js +1 -1
- package/modules/content/fields.js +3 -3
- package/modules/content/ids.js +3 -1
- package/modules/content/index.js +83 -27
- package/modules/content/loader.js +110 -130
- package/modules/content/markers.js +1 -1
- package/modules/content/models.js +48 -14
- package/modules/content/packs.js +2 -1
- package/modules/content/places.js +5 -4
- package/modules/content/props.js +8 -6
- package/modules/content/rules.js +29 -47
- package/modules/content/templates.js +66 -35
- package/modules/content/words.js +19 -6
- package/modules/debug/DebugPanel.js +4 -2
- package/modules/flow/contract.js +1 -0
- package/modules/flow/index.js +24 -14
- package/modules/gameplay/Container.js +5 -2
- package/modules/gameplay/Containers.js +9 -1
- package/modules/gameplay/Dialogue.js +82 -25
- package/modules/gameplay/Interactions.js +61 -32
- package/modules/gameplay/Inventory.js +56 -13
- package/modules/gameplay/Quests.js +133 -24
- package/modules/gameplay/boxOps.js +7 -0
- package/modules/gameplay/dialogueBubbles.js +14 -9
- package/modules/gameplay/inventoryOps.js +11 -7
- package/modules/gameplay/pickups.js +43 -16
- package/modules/gameplay/questLog.js +4 -2
- package/modules/gameplay/questSave.js +6 -1
- package/modules/gameplay/quests.contract.js +1 -1
- package/modules/grid/Grid.js +1 -1
- package/modules/grid/Layer.js +8 -4
- package/modules/grid/index.js +21 -15
- package/modules/grid/ops.js +43 -46
- package/modules/grid/tiles.js +1 -1
- package/modules/hlod/index.js +6 -3
- package/modules/hud/index.js +6 -4
- package/modules/hud/parts.js +4 -4
- package/modules/level/contract.js +2 -2
- package/modules/level/heightfield.js +17 -21
- package/modules/level/index.js +83 -26
- package/modules/level/load.js +165 -48
- package/modules/level/nodes.js +34 -16
- package/modules/lights/index.js +6 -3
- package/modules/lights/sources.js +3 -1
- package/modules/music/Music.js +4 -2
- package/modules/nav/contract.js +7 -5
- package/modules/nav/index.js +174 -44
- package/modules/nav/navPath.js +45 -10
- package/modules/net/index.js +1 -1
- package/modules/particles/Particles.js +85 -22
- package/modules/particles/effect.js +80 -28
- package/modules/particles/shaders.js +17 -0
- package/modules/photo/Photo.js +12 -10
- package/modules/rigid/RigidBodies.js +200 -57
- package/modules/rigid/Vehicles.js +15 -5
- package/modules/rigid/collider3d.contract.js +26 -0
- package/modules/rigid/ragdoll.js +55 -44
- package/modules/rigid/ragdollBones.js +83 -33
- package/modules/rigid/refresh.js +10 -0
- package/modules/rigid/sync.js +46 -15
- package/modules/settings/Settings.js +84 -37
- package/modules/settings/apply.js +15 -8
- package/modules/settings/sections.js +7 -4
- package/modules/settings/strings.js +2 -2
- package/modules/sky/skyModule.js +3 -1
- package/modules/swarm/Swarm.js +16 -6
- package/modules/terrain/ChunkManager.js +10 -16
- package/modules/terrain/index.js +17 -11
- package/modules/terrain/terrainEdit.js +13 -2
- package/modules/terrain/terrainGen.js +5 -3
- package/modules/terrain/terrainShape.js +1 -1
- package/modules/timeline/Timeline.js +58 -26
- package/modules/timeline/Tween.js +19 -13
- package/modules/timeline/shots.js +19 -10
- package/modules/triggers/index.js +87 -20
- package/modules/vegetation/Vegetation.js +4 -3
- package/modules/vegetation/draw.js +16 -0
- package/modules/vegetation/groundChunks.js +10 -7
- package/modules/vegetation/index.js +30 -7
- package/modules/water/Water.js +6 -2
- package/modules/weather/Weather.js +16 -15
- package/modules/weather/weatherDraw.js +7 -6
- package/modules/world/World.js +20 -7
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +13 -6
- package/modules/world/persist.js +23 -8
- package/modules/world/pos.js +4 -4
- package/modules/world/records.js +13 -7
- package/modules/world/sim.js +74 -23
- package/modules/world/simFar.js +2 -2
- package/modules/world/state.js +31 -6
- package/modules/world/thingSource.js +16 -3
- package/modules/world/views.js +19 -8
- package/package.json +7 -1
- package/render/PostFX.js +47 -29
- package/render/backend.js +5 -1
- package/render/fx/particles.tsl.js +8 -6
- package/render/fx/postWebGPU.tsl.js +3 -3
- package/render/layers.js +1 -1
- package/render/lightmap.js +23 -3
- package/render/occlusion.js +43 -12
- package/render/patches.js +2 -2
- package/render/postWebGL.js +4 -3
- package/render/probes.js +25 -0
- package/render/shadows.js +2 -2
- package/types/core.d.ts +142 -55
- package/types/gameplay.d.ts +92 -40
- package/types/generated/core/base/I18n.d.ts +2 -2
- package/types/generated/core/input/Input.d.ts +16 -2
- package/types/generated/core/input/inputSeat.d.ts +26 -0
- package/types/generated/core/inspect/DebugOverrides.d.ts +15 -1
- package/types/generated/core/ops/Ops.d.ts +2 -1
- package/types/generated/core/ops/control.d.ts +12 -2
- package/types/generated/core/saves/Saves.d.ts +26 -6
- package/types/generated/core/saves/session.d.ts +1 -1
- package/types/generated/core/scene/Views.d.ts +1 -1
- package/types/generated/core/stream/Stream.d.ts +6 -4
- package/types/generated/modules/grid/Grid.d.ts +1 -0
- package/types/generated/modules/particles/Particles.d.ts +4 -3
- package/types/generated/modules/timeline/Timeline.d.ts +5 -4
- package/types/generated/modules/weather/Weather.d.ts +1 -7
- package/types/generated/modules/world/World.d.ts +6 -4
- package/types/generated/render/PostFX.d.ts +6 -14
- package/types/nav.d.ts +36 -4
- package/types/physics.d.ts +55 -7
- package/types/pixel.d.ts +75 -0
- package/types/world.d.ts +14 -8
- package/ui/Parts.js +9 -2
- package/ui/theme.js +2 -2
- package/core/scene/engineCamera.js +0 -32
- package/modules/camera/projection.js +0 -21
package/core/time/Clock.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// Clock-time / season timers (daily 18:00, time-window switches, season change) belong to the calendar module (modules/calendar, a gameplay
|
|
6
6
|
// module, so core never names it): engine.calendar.at / between / daily / onSeason; the sky only draws that time.
|
|
7
7
|
// engine.clock.after(120, 'bread:ready') // emit an event after 120 calendar seconds (saveable: still fires after a load)
|
|
8
|
-
// engine.clock.after(5, () => door.close())
|
|
8
|
+
// engine.clock.after(5, () => door.close(), { channel: 'real' }) // a function works too, but functions cannot be saved
|
|
9
9
|
// engine.clock.every(30, () => spawnBird()) // every 30 calendar seconds
|
|
10
10
|
// engine.clock.after(1, 'poison:tick', { data: { id }, channel: 'enemies' }) // channel seconds instead: slows down with bullet time
|
|
11
11
|
// engine.clock.after(3, () => respawn(), { channel: 'real' }) // real seconds: ignores bullet time and the calendar rate
|
|
@@ -59,3 +59,5 @@ export class Clock {
|
|
|
59
59
|
/** Number of registered timers on every channel, used by engine.counts() */
|
|
60
60
|
get size() { return this.engine.time.size; }
|
|
61
61
|
}
|
|
62
|
+
|
|
63
|
+
export const handRolled = [{ kind: 'timers', seen: 'setInterval / setTimeout used for game timing', use: 'engine.clock.after(seconds, fn) / engine.clock.every(seconds, fn), or accumulate dt in engine.onFixed (they follow pause, step and saves); to await one: new Promise(r => engine.clock.after(s, r))', code: /\b(setInterval|setTimeout)\s*\(/, not: /setTimeout\s*\([^,]*,\s*0\s*\)/ }]; // debug: words for the tools, no timer runs here
|
package/core/time/skip.js
CHANGED
|
@@ -86,17 +86,23 @@ export const skipMethods = {
|
|
|
86
86
|
* @example await engine.skip({ to: '06:00' }); // sleep: until the calendar clock next reads 06:00
|
|
87
87
|
* @example engine.skip({ seconds: 600 }); // wait 600 calendar seconds
|
|
88
88
|
* @example await engine.skip({ to: '06:00', fade: 0.6, save: 'auto' }); // fade to black, jump, autosave, fade in
|
|
89
|
+
* Bad arguments throw at the call, before any fade (`[skip-amount]`, `[module-params]`); a skip already under way rejects.
|
|
89
90
|
* @param {{ to?: string | number, seconds?: number, fade?: number, save?: string | boolean }} opts
|
|
90
|
-
* Cancelled cleanly by session.newGame / load / quit (the skip resolves null and time stays where the new playthrough put it).
|
|
91
|
+
* Cancelled cleanly by session.newGame / load / quit and by saves.load (the skip resolves null and time stays where the new playthrough put it).
|
|
91
92
|
* @returns {Promise<{ seconds: number, clock: string | null, day: number | null } | null>}
|
|
92
93
|
*/
|
|
93
|
-
skip(opts
|
|
94
|
+
skip(opts) {
|
|
95
|
+
opts ??= {}; // skip(null) reads as no amount, the coded error below, not a TypeError on .fade
|
|
94
96
|
readParams('engine.skip()', keysSchema(['to', 'seconds', 'fade', 'save']), opts);
|
|
95
97
|
const { fade = 0, save = null } = opts;
|
|
96
98
|
amount(this, opts); // throw on bad arguments now, not after the fade
|
|
99
|
+
// one at a time: the end of a second one unfroze the game during the first one's fade
|
|
100
|
+
if (this._skipping) return Promise.reject(codedError('skip-busy', 'engine.skip(): a skip is already under way; await the first one, then skip again'));
|
|
101
|
+
this._skipping = true;
|
|
97
102
|
let out = null, ended = false;
|
|
103
|
+
const generation = this.saves.generation;
|
|
98
104
|
const go = () => {
|
|
99
|
-
if (ended) return; // the playthrough ended during the fade out: nothing to skip in the new one
|
|
105
|
+
if (ended || this.saves.generation !== generation) return; // the playthrough ended, or a quick load replaced the state, during the fade out: nothing to skip in the new one
|
|
100
106
|
const r = this.ops.run('time.skip', { seconds: amount(this, opts) }); // measured at jump time: a queued transition may have moved the clock
|
|
101
107
|
if (!r.ok) throw codedError('skip-amount', `engine.skip(): the time.skip op was refused (${r.code}); read it with engine.ops.can('time.skip', { seconds })`);
|
|
102
108
|
out = r.value;
|
|
@@ -104,7 +110,7 @@ export const skipMethods = {
|
|
|
104
110
|
};
|
|
105
111
|
const ctx = this.input.push('skip'); const fz = this.freeze('skip'); // opaque 'skip' context: gameplay input blocked until the skip ends
|
|
106
112
|
const off = this.events.on('session:end', () => { ended = true; }); // newGame / load / quit cancel the skip cleanly (it resolves null)
|
|
107
|
-
const end = () => { ctx.remove(); fz.remove(); off.remove(); };
|
|
113
|
+
const end = () => { this._skipping = false; ctx.remove(); fz.remove(); off.remove(); };
|
|
108
114
|
if (!(fade > 0)) { try { go(); } finally { end(); } return Promise.resolve(out); }
|
|
109
115
|
const run = this.flow ? this.flow.transition(go, { fade, autosave: false, music: false })
|
|
110
116
|
: (async () => { try { await fadeScreen(this, 1, { seconds: fade }); go(); } finally { await fadeScreen(this, 0, { seconds: fade }); } })();
|
package/core/time/time.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
// Built in: world (the root), player (parent world), calendar (parent world, speed 'clock.rate'). Physics (rapier) steps with dt('world'): to slow enemies and leave bodies alone, slow a channel of their own, not world.
|
|
19
19
|
import { codedError } from '../base/errorHints.js';
|
|
20
20
|
import { reportError } from '../base/errors.js';
|
|
21
|
-
import { saveValues } from '../
|
|
21
|
+
import { saveValues, SAVE_MAX_SECONDS } from '../base/saveValues.js';
|
|
22
22
|
|
|
23
23
|
export const STEP = 1 / 60;
|
|
24
24
|
const STRINGS = { where: 'clock timer', onMove: 'time.onMove listener' };
|
|
@@ -40,7 +40,7 @@ export class Time {
|
|
|
40
40
|
this.channel('world', { parent: null });
|
|
41
41
|
this.channel('player');
|
|
42
42
|
this.channel('calendar', { stack: 'clock.rate' });
|
|
43
|
-
engine.saves.register('time', {
|
|
43
|
+
engine.saves.register('time', { notAtomic: 'time goes on through a failed op: going back would run timers twice',
|
|
44
44
|
version: 2,
|
|
45
45
|
// v1 kept the calendar in its own 'clock' part ({ now, timers }); v2 has it as the 'calendar' channel of this part
|
|
46
46
|
migrate: { 1: (d, save) => {
|
|
@@ -49,7 +49,8 @@ export class Time {
|
|
|
49
49
|
timers: [...(d?.timers ?? []), ...(Array.isArray(c.timers) ? c.timers : []).map(t => ({ ...t, channel: 'calendar' }))] };
|
|
50
50
|
} },
|
|
51
51
|
// real: 'real' timers count on a clock no save restores (a new playthrough starts it from 0), so load shifts them by how far it moved
|
|
52
|
-
|
|
52
|
+
// _pending: channels of the loaded save the game has not defined yet stay in the next save
|
|
53
|
+
save: () => ({ channels: { ...this._pending, ...Object.fromEntries([...this._ch.values()].map(c => [c.name, c.now])) }, real: this.now('real'),
|
|
53
54
|
timers: this._timers.filter(t => t.event && !t.dead).map(({ ch, due, event, data, every }) => ({ channel: ch, due, event, data, ...(every ? { every } : null) })) }),
|
|
54
55
|
load: d => this._load(d),
|
|
55
56
|
});
|
|
@@ -58,7 +59,7 @@ export class Time {
|
|
|
58
59
|
_load(d) {
|
|
59
60
|
// saved seconds pass saveValues first: a negative / non-finite channel time ran its timers backwards (durability audit); clamped to >= 0, one warning
|
|
60
61
|
const v = saveValues('time'), chans = {};
|
|
61
|
-
for (const [name, now] of Object.entries(d?.channels ?? {})) chans[name] = v.num(now, `channels.${name}`, { min: 0, fallback: 0 });
|
|
62
|
+
for (const [name, now] of Object.entries(d?.channels ?? {})) chans[name] = v.num(now, `channels.${name}`, { min: 0, max: SAVE_MAX_SECONDS, fallback: 0 });
|
|
62
63
|
const timers = (Array.isArray(d?.timers) ? d.timers : []).filter(t => {
|
|
63
64
|
if (Number.isFinite(t?.due) && typeof t.event === 'string' && typeof t.channel === 'string') return true;
|
|
64
65
|
v.drop('timers[]', t); return false;
|
|
@@ -141,7 +142,7 @@ export class Time {
|
|
|
141
142
|
const t = typeof fnOrEvent === 'string' ? { ch, due: this.now(ch) + seconds, event: fnOrEvent, data, every, dead: false }
|
|
142
143
|
: { ch, due: this.now(ch) + seconds, fn: fnOrEvent, every, dead: false };
|
|
143
144
|
this._timers.push(t);
|
|
144
|
-
return { remove: () => { t.dead = true; this._timers = this._timers.filter(x => x !== t); } };
|
|
145
|
+
return { _timer: t, remove: () => { t.dead = true; this._timers = this._timers.filter(x => x !== t); } }; // _timer: ctx.track files it with its module (Session._keepTimer)
|
|
145
146
|
}
|
|
146
147
|
/** Timers in the queue (engine.counts) */
|
|
147
148
|
get size() { return this._timers.length; }
|
|
@@ -156,6 +157,7 @@ export class Time {
|
|
|
156
157
|
if (!due.length) continue;
|
|
157
158
|
this._timers = this._timers.filter(t => !(t.ch === ch && t.due <= at) || t.every);
|
|
158
159
|
for (const t of due) {
|
|
160
|
+
if (this.engine.disposed) return; // a callback of this list disposed the engine: dispose cannot reach the ones already taken out of the queue
|
|
159
161
|
if (t.every) { while (!t.dead && t.due <= at) { t.due += t.every; this._call(t); } continue; }
|
|
160
162
|
if (!t.dead) { t.dead = true; this._call(t); }
|
|
161
163
|
}
|
|
@@ -168,8 +170,11 @@ export class Time {
|
|
|
168
170
|
}
|
|
169
171
|
/** @internal engine.session: the function timers now, each with its time left (what a new playthrough starts with) @returns {{ t: any, rem: number }[]} */
|
|
170
172
|
_snapshotFn() { return this._timers.filter(t => !t.event && !t.dead).map(t => ({ t, rem: t.due - this.now(t.ch) })); }
|
|
171
|
-
/** @internal engine.session: keep the event timers (they came with the save), put back
|
|
172
|
-
_restoreFn(list
|
|
173
|
+
/** @internal engine.session: keep the event timers (they came with the save) and function timers set since `old` was taken, drop the rest, put back the snapshotted `list` with its original delay */
|
|
174
|
+
_restoreFn(list, old) {
|
|
175
|
+
const gone = new Set([...old, ...list].map(x => x.t));
|
|
176
|
+
this._timers = this._timers.filter(t => t.event || !gone.has(t)).concat(list.map(({ t, rem }) => Object.assign(t, { due: this.now(t.ch) + rem, dead: false })));
|
|
177
|
+
}
|
|
173
178
|
|
|
174
179
|
// ---------- the three ways time moves ----------
|
|
175
180
|
/** @internal loop.js, at the start of a fixed step: count it, so this step's commits, ops and input records carry the new tick */
|
|
@@ -210,7 +215,8 @@ export class Time {
|
|
|
210
215
|
const scales = [...this._ch.values()].map(c => [c, this.scale(c.name)]);
|
|
211
216
|
this._setAmbient(this._amb + fixed);
|
|
212
217
|
for (const [c, s] of scales) c.now += c.name === 'calendar' && calendar != null ? calendar : fixed * s;
|
|
213
|
-
for (const fn of [...this._onMove]) { try { fn(); } catch (err) { reportError(this.engine, err, STRINGS.onMove); } }
|
|
218
|
+
for (const fn of [...this._onMove]) { if (!this._onMove.includes(fn)) continue; /* removed earlier in this pass, or by a dispose */ try { fn(); } catch (err) { reportError(this.engine, err, STRINGS.onMove); } }
|
|
219
|
+
if (this.engine.disposed) return;
|
|
214
220
|
this.engine.stacks._expire();
|
|
215
221
|
this._runTimers();
|
|
216
222
|
}
|
|
@@ -237,6 +243,6 @@ export class Time {
|
|
|
237
243
|
}
|
|
238
244
|
return out;
|
|
239
245
|
}
|
|
240
|
-
/** Clear all timers (engine.dispose) */
|
|
241
|
-
dispose() { for (const t of this._timers) t.dead = true; this._timers = []; }
|
|
246
|
+
/** Clear all timers and move listeners (engine.dispose) */
|
|
247
|
+
dispose() { for (const t of this._timers) t.dead = true; this._timers = []; this._onMove = []; }
|
|
242
248
|
}
|
package/docs/AI.md
CHANGED
|
@@ -1,56 +1,82 @@
|
|
|
1
1
|
# Using threedog.js (read first)
|
|
2
2
|
|
|
3
|
-
threedog.js
|
|
4
|
-
`
|
|
5
|
-
Paths: `node_modules/threedog/docs/`. `threedog how "<2-4 English words>"` finds the section.
|
|
3
|
+
threedog.js: a web 3D game engine on plain three.js 0.187, **core** -> **modules** (`engine.use`); all art is the game's own (else gray placeholders).
|
|
4
|
+
Paths: `node_modules/threedog/docs/`. `threedog how "<2-4 English words>"`; no words: browse.
|
|
6
5
|
|
|
7
|
-
##
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
## Start by task
|
|
7
|
+
| The task | Where it goes |
|
|
8
|
+
|---|---|
|
|
9
|
+
| Lights, materials, models, shaders, fog, picture effects | Native three.js on `engine.scene / camera / renderer` (`THREE.md`), joined up with `onFrame`, `onRender`, `post.add` |
|
|
10
|
+
| Time, input, asset loading, saving, pausing, streaming | Check the engine first: rows below |
|
|
11
|
+
| Buying, picking up, attacking, opening doors: anything validated and recorded | `engine.ops` |
|
|
12
|
+
| Facts that persist, exist far away or keep changing | `engine.world`, `content` |
|
|
13
|
+
| Game-specific rules and looks | The game writes them; the engine coordinates (`engine.mod`) |
|
|
14
|
+
| Composing modules | `engine.use`, `requires` / `provides` when needed, `ctx.track`. A simple module may omit `type` |
|
|
15
|
+
| Troubleshooting | `describe`: state; `explain`: why; `catalog`: what exists; `inspect`: what can be done here; `thing`: one object |
|
|
10
16
|
|
|
11
|
-
|
|
12
|
-
|
|
17
|
+
**The engine lacks it?** Plain JS and three.js, joined through modules, events, ops, assets and saves, is the expected path; a small feature needs no provider protocol.
|
|
18
|
+
|
|
19
|
+
## Common mistakes
|
|
13
20
|
- `Math.random()`, `setTimeout`, `performance.now()`, `addEventListener('keydown')` in game logic: `engine.random.next()`, `engine.clock.after`, fixed `dt`, `input.bind`.
|
|
14
21
|
- Changing gameplay state from a frame hook or a raw callback: do it in `onFixed`, in an op, or via `engine.nextFixed(fn)`.
|
|
15
22
|
- Saving positions or object references: save stable ids; `await` every `saves.*` call; a mesh a save must know about gets `engine.add(obj, { id })`.
|
|
23
|
+
- Awaiting `level.load` / `content.load` in a save part's `load(data, turn)`: pass `{ turn }`, or it waits for ever.
|
|
16
24
|
- Editing generated docs (API.md, api/, CODEMAP, `types/generated/`): change the code, `npm run map`.
|
|
17
|
-
- Guessing a name:
|
|
25
|
+
- Guessing a name: see `api/<module>.md`; errors carry `err.code` / `fix` / `docs`.
|
|
18
26
|
|
|
19
27
|
## What to read, in order
|
|
20
|
-
|
|
28
|
+
Taking over a game: `STATUS.md` first. A new feature: a row or `threedog how` -> recipe -> `api/<module>.md`. Several entries: `CONVENTIONS.md`. Also: `THREE.md`, `COMMANDS.md`; upgrading: `MIGRATING-1.0.md`.
|
|
21
29
|
|
|
30
|
+
## What exists: look here first
|
|
31
|
+
Recommendations. Your own code wires in time by `onFixed` and `engine.clock`, saving by `engine.saves.register`, cleanup by handles (`ctx.track`).
|
|
32
|
+
### Picture and sound
|
|
33
|
+
| To do | Use | Recipe |
|
|
34
|
+
|---|---|---|
|
|
35
|
+
| The picture in three.js (`picture/`): lights, fog, exposure, parts | `lights: false`, `engine.uniforms` | 62-picture-code.md, 34-environment-lighting.md |
|
|
36
|
+
| Picture, writers; try a value | `describe().picture`, `explain({ value })`, `debug.watch`, `debug.override` | 52-around-the-picture.md, 62-picture-code.md |
|
|
37
|
+
| Materials, textures, a module's picture | `engine.water.material` | 09-materials-lights-models.md |
|
|
38
|
+
| Own material or shader (toon, cel shading) | TSL (WebGPU), `ShaderMaterial` (WebGL), `rampTexture`, `celLighting` | 43-shader-patches-surfaces.md, 56-webgpu-tsl.md |
|
|
39
|
+
| WebGPU (new games' default), TSL node materials, WebGL fallback | `renderer: 'webgpu'`, `import 'threedog/tsl'` | 56-webgpu-tsl.md |
|
|
40
|
+
| three.js idioms, own renderer | the idiom table in `THREE.md`, `createEngine({ renderer })` | 50-own-renderer.md |
|
|
41
|
+
| Dust, smoke | `engine.particles` | 64-particles.md |
|
|
42
|
+
| Sky, season tints, weather, wet roads | `engine.sky`, `engine.weather`, `engine.weatherDraw` | 08-weather-sky.md |
|
|
43
|
+
| Water, rain / snow, snow cover (own rain: `THREE.md`) | `engine.water`, `weather({ rain, snow })` | 44-water-weather-hooks.md |
|
|
44
|
+
| Shadows: blur, follow, cost | `engine.shadows` | 45-cascaded-shadows.md |
|
|
45
|
+
| Own far, fov; clouds | `engine.autoView`, `engine.shaderTerms` | 52-around-the-picture.md |
|
|
46
|
+
| Environment light, reflections, probes, lightmaps, GI, culling | `engine.sky.environment`, `engine.bakeProbes`, `engine.loadLightmap`, `engine.occlusion` | 34-environment-lighting.md |
|
|
47
|
+
| Post passes: color grading, bloom, outline, depth, AO | `engine.post.add(pass)`, `@threedog/post-effects` | 52-around-the-picture.md#post-effect-chain, 59-depth-post-effects.md |
|
|
48
|
+
| Many lights (torches); windows, signs at night | `engine.lightPool`, `uNight` | 09-materials-lights-models.md §1b |
|
|
49
|
+
| Picture from a reference; judge | `threedog picture palette`, `threedog examples list` | 35-picture-from-reference.md, 60-judge-the-picture.md |
|
|
50
|
+
| Reuse effects, models of old games | `threedog lib` | 05-props-bake.md |
|
|
51
|
+
| Sound, music, ambience | `engine.audio`, `engine.music`, `engine.ambience` | 31-audio.md |
|
|
22
52
|
|
|
23
|
-
|
|
24
|
-
### Project, world, content
|
|
53
|
+
### Rules, state, time
|
|
25
54
|
| To do | Use | Recipe |
|
|
26
55
|
|---|---|---|
|
|
27
|
-
|
|
|
28
|
-
|
|
|
29
|
-
|
|
|
30
|
-
|
|
|
31
|
-
|
|
|
32
|
-
|
|
|
33
|
-
|
|
|
34
|
-
|
|
|
35
|
-
|
|
|
36
|
-
|
|
|
37
|
-
|
|
|
38
|
-
| Grid placement, plots, build on cells; a grid from a PNG | `engine.grids`, `layer.material`, `sampleGrid`, `assets.gridFromImage` | 29-grid.md, 28-terrain.md §9 |
|
|
39
|
-
| Asset packs, loading; code-made models; far detail | `engine.assets.manifest`, `.palette`, `.lod`, `engine.loading` | 05-props-bake.md, 15-perf.md |
|
|
40
|
-
| Blender -> GLB art; fixed views before / after | `threedog assets check`, `engine.views` | 46-blender-art-route.md |
|
|
56
|
+
| Items, chests, shops, gold; things to pick up | `engine.inventory`, `engine.pickups` (`.material`) | 03-items-pickups.md, 22-shop-gold.md |
|
|
57
|
+
| Quests, objective markers | `engine.quests`, `engine.hud.marker()` | 04-quests.md |
|
|
58
|
+
| Player actions, UI buttons | `engine.ops.define` | 23-ops.md |
|
|
59
|
+
| What can the player do here, why not | `engine.inspect`, `engine.explain`, `engine.catalog` | 51-capability-catalog.md |
|
|
60
|
+
| Save game, load game, autosave, story flags, counters | `engine.saves.register` (`load(data, turn)`), `engine.vars` | 20-content-actions-save.md |
|
|
61
|
+
| New game / continue, scene flow, fades, pause for a menu, cutscenes | `engine.session`, `engine.flow`, `engine.freeze`, `engine.timeline` | 07-flow-scenes-pause.md |
|
|
62
|
+
| Timers, read / skip time | `engine.clock` (after, every), `engine.time.now(…)` | 06-clock-events.md |
|
|
63
|
+
| Slow or speed up time, bullet time | `engine.mod('clock.rate')` | 55-mods-time-wrap.md |
|
|
64
|
+
| Time of day, day / night, seasons | `engine.calendar` | 06-clock-events.md |
|
|
65
|
+
| Events, cause chain, randomness | `engine.events`, `engine.random.next()` | 06-clock-events.md |
|
|
66
|
+
| Multiplayer | `engine.net` | 27-net.md |
|
|
41
67
|
|
|
42
68
|
### Characters, input, UI
|
|
43
69
|
| To do | Use | Recipe |
|
|
44
70
|
|---|---|---|
|
|
45
71
|
| Third-person start (walk, pause, menu) | `createPlayer` | 63-third-person-start.md |
|
|
46
72
|
| Player, characters, who steers one | `engine.player`, `engine.characters` (`.material`), `engine.control` | 57-control.md, 13-animation.md |
|
|
47
|
-
| Keys, gamepad
|
|
48
|
-
| Camera:
|
|
49
|
-
| 2D, side-scroller, orthographic; 2D lights | `presets.player.sideScroller`;
|
|
50
|
-
| Pixel art |
|
|
73
|
+
| Keys, gamepad, rebinding, seats | `engine.input` | 58-input.md |
|
|
74
|
+
| Camera: followCamera (third person), first person, fixedCamera, rts; switch: setCamera | `engine.cameraRig`, `engine.page` | 21-camera.md |
|
|
75
|
+
| 2D, side-scroller, orthographic; 2D lights | `presets.player.sideScroller`; example `rc2d` | 21-camera.md §6 |
|
|
76
|
+
| Pixel art, pixel perfect camera | `pixelSize`, `pixelSnap` | 62-picture-code.md §4b |
|
|
51
77
|
| Skeletal animation | `engine.assets.animate`, `engine.hlod` | 13-animation.md, 15-perf.md |
|
|
52
|
-
| Pathfinding, navmesh,
|
|
53
|
-
| Physics
|
|
78
|
+
| Pathfinding, navmesh, NPC jumps and gaps | `engine.characters.findPath`, `engine.nav` | 12-navmesh.md |
|
|
79
|
+
| Physics, ragdoll, collision, vehicles | `engine.collision`, `engine.rigid`, `engine.collider3d` | 11-vehicles.md |
|
|
54
80
|
| Ray / mouse picking, shooting, lock-on | `engine.rays` | 19-shooting-picking.md |
|
|
55
81
|
| Prompts, trigger zones | `engine.interactions`, `engine.triggers` | 20-content-actions-save.md |
|
|
56
82
|
| Press E on a mesh | `interactions.add(mesh, { once, counter })` | 03-items-pickups.md |
|
|
@@ -59,64 +85,55 @@ The row -> its recipe (`recipes/NN-*.md`) -> `api/<module>.md`. Several entries
|
|
|
59
85
|
| NPCs and what they do, dialogue | `engine.npcs`, `engine.dialogue` | 02-npc.md |
|
|
60
86
|
| Barks over an NPC | `dialogue.say(text, { channel: 'bubble' })` | 26-ui-parts.md "Two channels" |
|
|
61
87
|
| UI, menus, HUD, popup message, languages, settings, photo mode | `engine.ui`, `makeWindow`, `toast(engine, text)`, `engine.hud`, `engine.i18n`, `engine.settings`, `engine.photo` | 26-ui-parts.md |
|
|
62
|
-
|
|
|
88
|
+
| Ambient occlusion, soft shadows | `engine.post.add(ao())`, `bakeVertexAO` | 52-around-the-picture.md |
|
|
89
|
+
| Settings turn off my effect | `settings.define(k, true, { limits: 'post.<name>.enabled' })` | 26-ui-parts.md |
|
|
63
90
|
| Action game: hp, attacks, enemy AI, drops | your ops + `world.simulate` | 32-action-game.md |
|
|
64
|
-
| Many bullets, debris
|
|
91
|
+
| Many bullets, debris | `engine.swarm` | 65-swarm.md |
|
|
65
92
|
| Enemy crowds, hordes, flocks | `engine.swarm` | 65-swarm.md |
|
|
66
93
|
|
|
67
|
-
###
|
|
94
|
+
### Project, world, content
|
|
95
|
+
| To do | Use | Recipe |
|
|
96
|
+
|---|---|---|
|
|
97
|
+
| New game, project layout, preset start | `npx threedog init` (repo: `new-game`), `createEngine`, `openWorld()` | 01-new-game.md |
|
|
98
|
+
| Put something in the scene | `scene.add(obj)`; saved: `engine.add(obj, { id })` | 40-scene.md |
|
|
99
|
+
| Content data, packs, change an entry for good | `engine.content`, `threedog content set` | 20-content-actions-save.md |
|
|
100
|
+
| Reusable objects (prefabs), groups of them | `templates`, flat `props` | 30-templates.md |
|
|
101
|
+
| Props, many repeated objects, static batching | content `props`, `engine.batching` | 05-props-bake.md |
|
|
102
|
+
| What is this thing, does it persist | `engine.pick(x, y)`, `engine.explain({ thing: id })` | 30-templates.md §5, 40-scene.md |
|
|
103
|
+
| Teleport the player, far-away and saved objects, streaming | `player.placeAt`, `engine.stream.teleport`, `engine.world` | 18-world.md, 33-stream-sources.md |
|
|
104
|
+
| Blender level | `engine.level`; `engine.vegetation.define` | 10-blender-level.md |
|
|
105
|
+
| Terrain, height, edits | `engine.terrain`, `engine.ground` | 28-terrain.md |
|
|
106
|
+
| Ground picture | `engine.terrain.material`, `terrain({ detail, shape })` | 36-ground-plants.md, 53-ground-up-close.md |
|
|
107
|
+
| Grid placement, plots, build on cells; a grid from a PNG | `engine.grids`, `sampleGrid`, `assets.gridFromImage` | 29-grid.md, 28-terrain.md §9 |
|
|
108
|
+
| Assets, loading; code-made models; LOD | `engine.assets.manifest`, `.palette`, `.lod`, `engine.loading` | 05-props-bake.md, 15-perf.md |
|
|
109
|
+
| Blender -> GLB art; fixed views before / after | `threedog assets check`, `engine.views` | 46-blender-art-route.md |
|
|
110
|
+
|
|
111
|
+
### Composing modules
|
|
68
112
|
| To do | Use | Recipe |
|
|
69
113
|
|---|---|---|
|
|
70
|
-
| Items, chests, shops, gold; things to pick up | `engine.inventory`, `engine.pickups` (`.material`) | 03-items-pickups.md, 22-shop-gold.md |
|
|
71
|
-
| Quests, objective markers | `engine.quests`, `engine.hud.marker()` | 04-quests.md |
|
|
72
|
-
| Player actions, UI buttons | `engine.ops.define` | 23-ops.md |
|
|
73
|
-
| What can the player do here, why not | `engine.catalog`, `engine.explain`, `engine.inspect`, `engine.describe` | 51-capability-catalog.md |
|
|
74
|
-
| Save game, load game, autosave, story flags, counters | `engine.saves.register`, `engine.vars` | 20-content-actions-save.md |
|
|
75
|
-
| New game / continue, scene flow, fades, pause for a menu, cutscenes | `engine.session`, `engine.flow`, `engine.freeze`, `engine.timeline` | 07-flow-scenes-pause.md |
|
|
76
|
-
| Timers, read / skip time | `engine.clock` (after, every), `engine.time.now(…)` | 06-clock-events.md |
|
|
77
|
-
| Slow or speed up time, bullet time | `engine.mod('clock.rate')`, `engine.mod('time.<channel>', …)` | 55-mods-time-wrap.md |
|
|
78
|
-
| Time of day, day / night, seasons | `engine.calendar` | 06-clock-events.md |
|
|
79
114
|
| A value several systems change; one-holder parts | `engine.mod`, `engine.stacks`, `provides`, `wrap` | 55-mods-time-wrap.md |
|
|
80
115
|
| Replace a module (dialogue, camera) | `replaces`, `runContract` | 55-mods-time-wrap.md "Replacing a module" |
|
|
81
|
-
| Events, cause chain, randomness | `engine.events`, `engine.random.next()` | 06-clock-events.md |
|
|
82
|
-
| Multiplayer | `engine.net` | 27-net.md |
|
|
83
116
|
| Your own module: `type`, `requires`, swap a part (`provides` + `{ replaces }`) | `engine.use`, `.unuse` | 14-custom-module.md, 49-game-module-contract.md |
|
|
117
|
+
| Drop-in file per piece, no main.js | `plugins/`, `engine.plugins`, `describe().slots` | 40-scene.md |
|
|
84
118
|
|
|
85
|
-
###
|
|
119
|
+
### Advanced
|
|
86
120
|
| To do | Use | Recipe |
|
|
87
121
|
|---|---|---|
|
|
88
|
-
|
|
|
89
|
-
|
|
|
90
|
-
| Materials, textures, a module's picture | `engine.water.material` | 09-materials-lights-models.md |
|
|
91
|
-
| Own material or shader (toon, cel shading) | TSL (WebGPU), `ShaderMaterial` (WebGL), `rampTexture`, `celLighting` | 43-shader-patches-surfaces.md, 56-webgpu-tsl.md |
|
|
92
|
-
| WebGPU renderer, TSL node materials, WebGL fallback | `renderer: 'webgpu'`, `import 'threedog/tsl'` | 56-webgpu-tsl.md |
|
|
93
|
-
| Drop-in file per piece, no main.js | `plugins/`, `engine.plugins`, `describe().slots` | 40-scene.md |
|
|
94
|
-
| three.js idioms, own renderer | the idiom table in `THREE.md`, `createEngine({ renderer })` | 50-own-renderer.md |
|
|
95
|
-
| Dust, smoke | `particles({ effects })`, `engine.particles` | 64-particles.md |
|
|
96
|
-
| Sky (`replace`, `clouds`, `layer`, `keyframes`), season tints, weather, wet roads | `engine.sky`, `engine.weather`, `engine.weatherDraw` | 08-weather-sky.md |
|
|
97
|
-
| Water, rain / snow, snow cover | `engine.water`, `weather({ rain, snow })`, `weather.defineField` | 44-water-weather-hooks.md |
|
|
98
|
-
| Shadows: blur, follow, cost | `engine.shadows.cascades(light)`, `.box(light)`, `.budget(light)`, `.cache(light, { static })`, `.mapSize(light, n)`, `.enabled` | 45-cascaded-shadows.md |
|
|
99
|
-
| Own far, fov; clouds | `engine.autoView`, `engine.shaderTerms` | 52-around-the-picture.md |
|
|
100
|
-
| Environment light, reflections, probes, lightmaps, GI, culling | `engine.sky.environment`, `engine.bakeProbes`, `engine.loadLightmap`, `engine.occlusion` | 34-environment-lighting.md |
|
|
101
|
-
| Post passes: color grading, bloom, outline, depth | `post.add(pass)`: `lut`, `paletteLut`, `outline` of `@threedog/post-effects` | 52-around-the-picture.md#post-effect-chain, 59-depth-post-effects.md |
|
|
102
|
-
| Ambient occlusion, soft shadows | `engine.post.add(ao())`, `bakeVertexAO` | 52-around-the-picture.md |
|
|
103
|
-
| Many lights (torches); windows, signs at night | `engine.lightPool`, `uNight` | 09-materials-lights-models.md §1b |
|
|
104
|
-
| Picture from a reference; judge | `threedog picture palette`, `threedog examples list` | 35-picture-from-reference.md, 60-judge-the-picture.md |
|
|
105
|
-
| Reuse effects, models of old games | `threedog lib list` / `lib pull` | 05-props-bake.md |
|
|
106
|
-
| Sound, music, ambience | `engine.audio`, `engine.music`, `engine.ambience` | 31-audio.md |
|
|
122
|
+
| Own ground or plant drawing, keep collision | `engine.terrain.view`, `engine.terrainDraw`, `engine.vegetationDraw` | 28-terrain.md §6 |
|
|
123
|
+
| Worker results, far records' models, raw navmesh or physics, content sections, own mover | `engine.commits`, `world.present`, `nav.query`, `rigid.world`, module `content`, `characters.kit` | 15-perf.md, 18-world.md, 12-navmesh.md, 11-vehicles.md, 14-custom-module.md, 57-control.md |
|
|
107
124
|
|
|
108
|
-
###
|
|
125
|
+
### Troubleshooting and speed
|
|
109
126
|
| To do | Use | Recipe |
|
|
110
127
|
|---|---|---|
|
|
111
|
-
|
|
|
128
|
+
| Broke, looks wrong or slow: which tool | `.threedog/errors.log`, `engine.describe`, `engine.explain` | 16-dev-bridge.md §11 |
|
|
112
129
|
| Drive and check the live game | the dev bridge (`verify <scenario>`) | 16-dev-bridge.md |
|
|
113
130
|
| Slow, low fps, workers, budgets | `engine.jobs`, `engine.threads`, `engine.commits`, `engine.budget`, `engine.debug`, `threedog stress` | 15-perf.md |
|
|
114
131
|
| Deploy | `npm run build` | 61-deploy.md |
|
|
115
132
|
|
|
116
133
|
## Conventions (`CONVENTIONS.md`)
|
|
117
|
-
- **A position is one argument
|
|
118
|
-
- **Registrations return a handle** (`h.remove()`). **Ready is `ready`**. **Events are `noun:action`**. **`owner`** is the name you pass
|
|
119
|
-
-
|
|
134
|
+
- **A position is one argument**, then an options object. **Units** are meters, Y up, north -Z; characters face +Z.
|
|
135
|
+
- **Registrations return a handle** (`h.remove()`, `ctx.track` takes it). **Ready is `ready`**. **Events are `noun:action`**. **`owner`** is the name you pass.
|
|
136
|
+
- **`onFixed`** is game time, **`onFrame`** presentation; draw what `onFixed` moves with `engine.stepBlend`, or it stutters.
|
|
120
137
|
|
|
121
138
|
## Stability
|
|
122
|
-
`@experimental
|
|
139
|
+
`@experimental`: may change or go with no migration note.
|
package/docs/API.md
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
# Engine API index (generated, do not edit by hand; produced by npm run map)
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> A new feature starts at `AI.md` or `threedog how`; this page is for looking up a name.
|
|
4
4
|
> The api pages are generated too, do not edit them by hand; `?` in a signature means optional, what follows `→` is the return value; the full types are in `types/*.d.ts`.
|
|
5
|
-
>
|
|
6
|
-
> Paths are relative to the package (`node_modules/threedog/`). Entry: `import { createEngine, openWorld, … } from 'threedog'` (the engine package's own examples use relative paths); a module
|
|
5
|
+
> One line per core object / module; for the one you need, **read only that page** `api/<name>.md`.
|
|
6
|
+
> Paths are relative to the package (`node_modules/threedog/`). Entry: `import { createEngine, openWorld, … } from 'threedog'` (the engine package's own examples use relative paths); a module the game needs is installed with `engine.use` before `await engine.start()`; `engine.xxx?.method()` is only for a feature the game works without, and a required module left out that way fails in silence.
|
|
7
|
+
> By task: ordinary picture is plain three.js (`THREE.md`); game rules are `onFixed`, `ops`, `world`; modules are `use` and `ctx.track`; drawing of your own is at the end of the module list; to troubleshoot, `describe` gives state and `explain` why.
|
|
7
8
|
|
|
8
9
|
## Core everyday API (all methods, properties, createEngine options and how to write a module are in [api/engine.md](api/engine.md))
|
|
9
10
|
- `createEngine(opts: EngineOptions) → Engine` — creates the engine (core only); options: canvas ui loading saveKey headless budget …
|
|
@@ -27,11 +28,11 @@
|
|
|
27
28
|
- `engine.ready` — phase is 'ready' or 'running': the world is built and the loading screen is gone…
|
|
28
29
|
- `engine.player` — The player (exists only after characters.createPlayer())
|
|
29
30
|
- `engine.scene` — three.js scene
|
|
30
|
-
- `engine.camera` —
|
|
31
|
+
- `engine.camera` — The camera the engine draws with, a plain THREE.PerspectiveCamera to begin with
|
|
31
32
|
|
|
32
33
|
## Core objects (engine.xxx, no install needed)
|
|
33
34
|
- [`engine.events`](api/events.md) the event bus: traceFocus note trace recent on once emit; event table
|
|
34
|
-
- [`engine.input`](api/input.md) Input: read by "action": action bind touchButton simulate rebind rebound keysOf isUnbound label down pressed released pressedRaw
|
|
35
|
+
- [`engine.input`](api/input.md) Input: read by "action": action bind touchButton simulate seat rebind rebound keysOf isUnbound label down pressed released pressedRaw …
|
|
35
36
|
- [`engine.clock`](api/clock.md) calendar seconds and "after how long / every how long": after every
|
|
36
37
|
- [`engine.vars`](api/vars.md) story flags and counters (autosaved): flag setFlag counter bump
|
|
37
38
|
- [`engine.saves`](api/saves.md) engine.saves handles saving: register putAttachment removeAttachment attachments storageKey flush collect check apply save load list remove export …
|
|
@@ -40,27 +41,25 @@
|
|
|
40
41
|
- [`engine.i18n`](api/i18n.md) string tables: add setLocale has
|
|
41
42
|
- [`engine.rays`](api/rays.md) engine.rays is the ray registry…: addStatic forget addProvider
|
|
42
43
|
- [`engine.jobs`](api/jobs.md) engine.jobs queues build work in a binary heap: add run
|
|
43
|
-
- [`engine.stream`](api/stream.md) engine.stream builds on demand by space: only entries n…: add
|
|
44
|
+
- [`engine.stream`](api/stream.md) engine.stream builds on demand by space: only entries n…: add source teleport addReadyCheck sources
|
|
44
45
|
- [`engine.budget`](api/budget.md) performance budget (turned on by createEngine: enable disable metric limitOf report checkStartup values byTag
|
|
45
|
-
- [`engine.post`](api/post.md) PostFX: object targets add get own
|
|
46
|
+
- [`engine.post`](api/post.md) PostFX: object targets add get own list render
|
|
46
47
|
- [`engine.occlusion`](api/occlusion.md) Occlusion
|
|
47
48
|
- [`engine.ground`](api/ground.md) Ground: whoever provides the ground height is the "terr…: height slope type has voidY forEachCollider viewRange chunkCollision staticTrimeshes staticVersion
|
|
48
49
|
|
|
49
50
|
## Modules (installed with engine.use; the openWorld preset installs only world and environment, see [api/openWorld.md](api/openWorld.md))
|
|
50
|
-
- [`engine.terrain`](api/terrain.md) terrain() Procedural terrain, data part: recolor
|
|
51
|
-
- [`engine.terrainDraw`](api/terrainDraw.md) terrainDraw: recolor
|
|
51
|
+
- [`engine.terrain`](api/terrain.md) terrain() Procedural terrain, data part: recolor view retry rebuild edit
|
|
52
52
|
- [`engine.vegetation`](api/vegetation.md) vegetation() Vegetation: sway color view rebuild setShadowRing define get list isRemoved removeInstance restoreInstance instanceAt
|
|
53
|
-
- [`engine.vegetationDraw`](api/vegetationDraw.md) vegetationDraw: mesh kind
|
|
54
53
|
- [`engine.sky`](api/sky.md) sky() Sky dome and the sun / daylight / sky-color signals, from the calendar's time; it writes no light or fog: keyframes clouds layer replace environment
|
|
55
54
|
- [`engine.calendar`](api/calendar.md) calendar() Time of day, day, seasons and clock-time timers: at between daily onSeason untilMark
|
|
56
|
-
- [`engine.weather`](api/weather.md)
|
|
57
|
-
- [`engine.weatherDraw`](api/weatherDraw.md) weatherDraw
|
|
55
|
+
- [`engine.weather`](api/weather.md) weather() Weather state: defineField set label
|
|
58
56
|
- [`engine.water`](api/water.md) water() Water surface: shader normalMap
|
|
59
57
|
- [`engine.world`](api/world.md) World data: add origin idOf get set move remove query forEachNear present view refresh …
|
|
60
58
|
- [`engine.net`](api/net.md) net: reconnect
|
|
61
59
|
- [`engine.grids`](api/grids.md) grids: add get list define preview
|
|
62
60
|
- [`engine.collision`](api/collision.md) collision() Lightweight collision: addCircle addBox addSegment addBlocked blockedAt addObject forEachStatic mirror walkable walkableAt lineClear
|
|
63
61
|
- [`engine.rigid`](api/rigid.md) rigid() Real physics, Rapier: addBox addBall addHull ragdoll impulse setPosition addWheeled
|
|
62
|
+
- [`engine.collider3d`](api/collider3d.md) collider3d: addSolid overlap sweep
|
|
64
63
|
- [`engine.cameraRig`](api/cameraRig.md) followCamera() / firstPersonCamera() / fixedCamera() / rtsCamera() Current camera: follow forward right focusPoint screenToGround update onOverride onEnter onExit
|
|
65
64
|
- [`engine.timeline`](api/timeline.md) timeline() Cutscenes, tweens: tween play skip
|
|
66
65
|
- [`engine.level`](api/level.md) level() Hand-built level: marker markersWith unload load track
|
|
@@ -69,7 +68,7 @@
|
|
|
69
68
|
- [`engine.swarm`](api/swarm.md) swarm
|
|
70
69
|
- [`engine.settings`](api/settings.md) settings() Settings menu: get set preset define addSection open close toggle reset resetBindings rebind actionList …
|
|
71
70
|
- [`engine.music`](api/music.md) music() Background music: define play stop stinger rules override pick
|
|
72
|
-
- [`engine.characters`](api/characters.md) characters() Characters: findSpawn createPlayer moveInput support removePlayer findPath findPathAsync; Character, NPC; engine.npcs: list add remove behavior tiers get character avoid (behavior and avoid: see recipes/02-npc)
|
|
71
|
+
- [`engine.characters`](api/characters.md) characters() Characters: findSpawn createPlayer moveInput addVehicle support removePlayer findPath findPathAsync; Character, NPC; engine.npcs: list add remove behavior tiers get character avoid (behavior and avoid: see recipes/02-npc)
|
|
73
72
|
- [`engine.interactions`](api/interactions.md) interactions() Interaction prompts: add get
|
|
74
73
|
- [`engine.dialogue`](api/dialogue.md) dialogue() Dialogue: define start say bubbles end
|
|
75
74
|
- [`engine.inventory`](api/inventory.md) inventory() Inventory: of define item count has list get add remove trade setData container …
|
|
@@ -84,5 +83,10 @@
|
|
|
84
83
|
- [`engine.flow`](api/flow.md) flow() Game flow and scene transitions: define go transition
|
|
85
84
|
- [`engine.hud`](api/hud.md) hud() Objective markers, counters, progress bars: marker counter bump value bar remove
|
|
86
85
|
|
|
86
|
+
## Custom drawing (only to replace how a module draws: the facades above are the entry; `engine.use(mine, { replaces })`, recipe 28 §6)
|
|
87
|
+
- [`engine.terrainDraw`](api/terrainDraw.md) terrain() terrainDraw: recolor
|
|
88
|
+
- [`engine.vegetationDraw`](api/vegetationDraw.md) vegetation() vegetationDraw: mesh kind
|
|
89
|
+
- [`engine.weatherDraw`](api/weatherDraw.md) weather() weatherDraw
|
|
90
|
+
|
|
87
91
|
## Other
|
|
88
|
-
- [Utility functions](api/tools.md): PICTURE_SLOTS
|
|
92
|
+
- [Utility functions](api/tools.md): PICTURE_SLOTS presets world net fakeNetwork webSocket grids swarm screenToGround sampleGrid ease checkOptions contentParts readParams threePatches createTerrain terrainMaterial mergeColored applyEffects rampTexture bakeVertexAO materialPatches toast makeWindow …
|