threedog 0.5.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +276 -1
- package/README.md +18 -13
- package/core/{Animator.js → assets/Animator.js} +28 -18
- package/core/{Assets.js → assets/Assets.js} +116 -61
- package/core/{Baked.js → assets/Baked.js} +16 -25
- package/core/assets/assetEntry.js +237 -0
- package/core/{assetHot.js → assets/assetHot.js} +7 -6
- package/core/{assetLoad.js → assets/assetLoad.js} +66 -29
- package/core/assets/assetLod.js +113 -0
- package/core/{assetManifest.js → assets/assetManifest.js} +23 -12
- package/core/{assetReport.js → assets/assetReport.js} +9 -15
- package/core/{namedModel.js → assets/namedModel.js} +24 -16
- package/core/{Audio.js → audio/Audio.js} +27 -24
- package/core/{audioRules.js → audio/audioRules.js} +8 -5
- package/core/{audioVoice.js → audio/audioVoice.js} +17 -30
- package/core/{Events.js → base/Events.js} +3 -3
- package/core/{I18n.js → base/I18n.js} +10 -10
- package/core/{Random.js → base/Random.js} +5 -4
- package/core/{easing.js → base/easing.js} +1 -1
- package/core/{errorCodes.js → base/errorCodes.js} +154 -139
- package/core/{errorHints.js → base/errorHints.js} +9 -10
- package/core/{errors.js → base/errors.js} +9 -9
- package/core/{events.generated.js → base/events.generated.js} +2 -0
- package/core/{math.js → base/math.js} +22 -4
- package/core/{params.js → base/params.js} +3 -4
- package/core/base/util.js +32 -0
- package/core/{validate.js → base/validate.js} +29 -8
- package/core/{Engine.js → engine/Engine.js} +112 -105
- package/core/{Loading.js → engine/Loading.js} +4 -2
- package/core/{copies.js → engine/copies.js} +4 -4
- package/core/{headlessLoad.js → engine/headlessLoad.js} +4 -4
- package/core/{lifecycle.js → engine/lifecycle.js} +16 -16
- package/core/{loop.js → engine/loop.js} +80 -52
- package/core/{moduleSlots.js → engine/moduleSlots.js} +35 -10
- package/core/{moduleTypes.js → engine/moduleTypes.js} +30 -18
- package/core/{modules.js → engine/modules.js} +20 -17
- package/core/engine/page.js +125 -0
- package/core/{plugins.js → engine/plugins.js} +68 -103
- package/core/{services.js → engine/services.js} +47 -40
- package/core/{startup.js → engine/startup.js} +35 -35
- package/core/{Input.js → input/Input.js} +41 -27
- package/core/{inputContext.js → input/inputContext.js} +14 -5
- package/core/{inputPad.js → input/inputPad.js} +1 -1
- package/core/{inputPointer.js → input/inputPointer.js} +8 -2
- package/core/{inputTouch.js → input/inputTouch.js} +1 -1
- package/core/{Budget.js → inspect/Budget.js} +23 -22
- package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +60 -31
- package/core/{Describe.js → inspect/Describe.js} +33 -30
- package/core/{Inspect.js → inspect/Inspect.js} +14 -9
- package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +8 -10
- package/core/{InspectPerf.js → inspect/InspectPerf.js} +29 -16
- package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
- package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +9 -6
- package/core/inspect/UrlState.js +182 -0
- package/core/{catalog.js → inspect/catalog.js} +18 -5
- package/core/{checks.js → inspect/checks.js} +7 -5
- package/core/{debugView.js → inspect/debugView.js} +8 -8
- package/core/inspect/describeRender.js +148 -0
- package/core/{describeText.js → inspect/describeText.js} +17 -12
- package/core/inspect/geometryWatch.js +38 -0
- package/core/{lightWatch.js → inspect/lightWatch.js} +11 -9
- package/core/inspect/pictureWriters.js +342 -0
- package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
- package/core/{Ops.js → ops/Ops.js} +16 -11
- package/core/{control.js → ops/control.js} +13 -12
- package/core/ops/holds.js +139 -0
- package/core/{opsAtomic.js → ops/opsAtomic.js} +2 -1
- package/core/{opsCheck.js → ops/opsCheck.js} +4 -5
- package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
- package/core/{opsRun.js → ops/opsRun.js} +7 -4
- package/core/{owned.js → ops/owned.js} +37 -37
- package/core/{sharedPoint.js → ops/sharedPoint.js} +13 -27
- package/core/{stackFrames.js → ops/stackFrames.js} +17 -6
- package/core/{stacks.js → ops/stacks.js} +18 -20
- package/core/{wrap.js → ops/wrap.js} +8 -6
- package/core/{SaveStore.js → saves/SaveStore.js} +1 -1
- package/core/{Saves.js → saves/Saves.js} +58 -36
- package/core/{saveApply.js → saves/saveApply.js} +13 -9
- package/core/{saveFiles.js → saves/saveFiles.js} +17 -15
- package/core/{saveValues.js → saves/saveValues.js} +20 -3
- package/core/{saveVersions.js → saves/saveVersions.js} +4 -17
- package/core/{session.js → saves/session.js} +31 -17
- package/core/{Rays.js → scene/Rays.js} +27 -24
- package/core/{Views.js → scene/Views.js} +15 -6
- package/core/{adaptive.js → scene/adaptive.js} +15 -8
- package/core/{canvasBox.js → scene/canvasBox.js} +2 -3
- package/core/{engineCamera.js → scene/engineCamera.js} +1 -1
- package/core/{gameLights.js → scene/gameLights.js} +24 -7
- package/core/{grayMap.js → scene/grayMap.js} +8 -2
- package/core/{grid.js → scene/grid.js} +4 -4
- package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
- package/core/{ground.js → scene/ground.js} +9 -9
- package/core/{movement.js → scene/movement.js} +3 -3
- package/core/scene/pictureSlots.js +33 -0
- package/core/{sceneDelta.js → scene/sceneDelta.js} +14 -6
- package/core/{sceneMethods.js → scene/sceneMethods.js} +36 -20
- package/core/scene/stepPoses.js +55 -0
- package/core/{targeting.js → scene/targeting.js} +4 -5
- package/core/{thingExplain.js → scene/thingExplain.js} +7 -6
- package/core/{thingOps.js → scene/thingOps.js} +4 -3
- package/core/{things.js → scene/things.js} +19 -6
- package/core/{threePatches.js → scene/threePatches.js} +1 -1
- package/core/{tier.js → scene/tier.js} +1 -1
- package/core/scene/view.js +44 -0
- package/core/{Batching.js → stream/Batching.js} +85 -27
- package/core/{Stream.js → stream/Stream.js} +62 -33
- package/core/{batchGroups.js → stream/batchGroups.js} +18 -9
- package/core/{chunkStream.js → stream/chunkStream.js} +41 -1
- package/core/{scatter.js → stream/scatter.js} +2 -2
- package/core/{streamSources.js → stream/streamSources.js} +12 -7
- package/core/{Commits.js → threads/Commits.js} +6 -5
- package/core/{Jobs.js → threads/Jobs.js} +12 -10
- package/core/{Threads.js → threads/Threads.js} +16 -16
- package/core/{threadPure.js → threads/threadPure.js} +7 -5
- package/core/{threadServe.js → threads/threadServe.js} +3 -3
- package/core/{Clock.js → time/Clock.js} +17 -10
- package/core/{dayTime.js → time/dayTime.js} +5 -1
- package/core/{skip.js → time/skip.js} +18 -17
- package/core/{time.js → time/time.js} +18 -12
- package/core/{uiClock.js → time/uiClock.js} +4 -4
- package/docs/AI.md +70 -63
- package/docs/API.md +30 -29
- package/docs/CODEMAP.md +98 -223
- package/docs/COMMANDS.md +80 -69
- package/docs/CONVENTIONS.md +87 -41
- package/docs/MIGRATING-0.7.md +39 -0
- package/docs/MIGRATING-0.8.md +169 -0
- package/docs/THREE.md +100 -49
- package/docs/api/assets.md +17 -16
- package/docs/api/audio.md +8 -7
- package/docs/api/budget.md +8 -4
- package/docs/api/calendar.md +10 -11
- package/docs/api/cameraRig.md +29 -29
- package/docs/api/characters.md +26 -19
- package/docs/api/clock.md +1 -1
- package/docs/api/collision.md +14 -11
- package/docs/api/content.md +6 -6
- package/docs/api/dialogue.md +3 -3
- package/docs/api/engine.md +82 -53
- package/docs/api/events.md +5 -3
- package/docs/api/flow.md +1 -1
- package/docs/api/grids.md +9 -2
- package/docs/api/ground.md +4 -5
- package/docs/api/hud.md +4 -1
- package/docs/api/i18n.md +6 -6
- package/docs/api/input.md +10 -9
- package/docs/api/interactions.md +6 -4
- package/docs/api/inventory.md +10 -11
- package/docs/api/jobs.md +5 -5
- package/docs/api/level.md +7 -8
- package/docs/api/lightPool.md +2 -7
- package/docs/api/music.md +3 -3
- package/docs/api/nav.md +10 -10
- package/docs/api/occlusion.md +5 -0
- package/docs/api/openWorld.md +1 -1
- package/docs/api/particles.md +8 -5
- package/docs/api/photo.md +4 -2
- package/docs/api/pickups.md +7 -1
- package/docs/api/post.md +24 -5
- package/docs/api/quests.md +3 -3
- package/docs/api/rays.md +5 -7
- package/docs/api/rigid.md +27 -18
- package/docs/api/saves.md +8 -7
- package/docs/api/settings.md +9 -8
- package/docs/api/sky.md +17 -14
- package/docs/api/stream.md +7 -7
- package/docs/api/swarm.md +34 -0
- package/docs/api/terrain.md +17 -12
- package/docs/api/terrainDraw.md +12 -0
- package/docs/api/timeline.md +2 -2
- package/docs/api/tools.md +30 -26
- package/docs/api/triggers.md +2 -0
- package/docs/api/vars.md +1 -1
- package/docs/api/vegetation.md +11 -5
- package/docs/api/vegetationDraw.md +10 -0
- package/docs/api/water.md +7 -3
- package/docs/api/weather.md +11 -6
- package/docs/api/weatherDraw.md +10 -0
- package/docs/api/world.md +6 -6
- package/docs/recipes/01-new-game.md +38 -57
- package/docs/recipes/02-npc.md +19 -20
- package/docs/recipes/03-items-pickups.md +47 -42
- package/docs/recipes/04-quests.md +3 -4
- package/docs/recipes/05-props-bake.md +72 -66
- package/docs/recipes/06-clock-events.md +30 -21
- package/docs/recipes/07-flow-scenes-pause.md +21 -17
- package/docs/recipes/08-weather-sky.md +117 -75
- package/docs/recipes/09-materials-lights-models.md +171 -0
- package/docs/recipes/10-blender-level.md +6 -7
- package/docs/recipes/11-vehicles.md +33 -25
- package/docs/recipes/12-navmesh.md +9 -8
- package/docs/recipes/13-animation.md +50 -22
- package/docs/recipes/14-custom-module.md +20 -17
- package/docs/recipes/15-perf.md +52 -29
- package/docs/recipes/16-dev-bridge.md +47 -57
- package/docs/recipes/18-world.md +45 -30
- package/docs/recipes/19-shooting-picking.md +11 -7
- package/docs/recipes/20-content-actions-save.md +36 -37
- package/docs/recipes/21-camera.md +41 -8
- package/docs/recipes/22-shop-gold.md +0 -4
- package/docs/recipes/23-ops.md +11 -11
- package/docs/recipes/26-ui-parts.md +56 -22
- package/docs/recipes/27-net.md +0 -2
- package/docs/recipes/28-terrain.md +126 -30
- package/docs/recipes/29-grid.md +16 -7
- package/docs/recipes/30-templates.md +62 -21
- package/docs/recipes/31-audio.md +9 -9
- package/docs/recipes/32-action-game.md +32 -9
- package/docs/recipes/33-stream-sources.md +2 -2
- package/docs/recipes/34-environment-lighting.md +164 -52
- package/docs/recipes/35-picture-from-reference.md +140 -0
- package/docs/recipes/36-ground-plants.md +105 -0
- package/docs/recipes/40-scene.md +105 -30
- package/docs/recipes/{43-shader-patches-surface-looks.md → 43-shader-patches-surfaces.md} +74 -106
- package/docs/recipes/44-water-weather-hooks.md +196 -0
- package/docs/recipes/45-cascaded-shadows.md +145 -25
- package/docs/recipes/46-blender-art-route.md +21 -25
- package/docs/recipes/49-game-module-contract.md +5 -5
- package/docs/recipes/50-own-renderer.md +3 -3
- package/docs/recipes/52-around-the-picture.md +137 -0
- package/docs/recipes/53-ground-up-close.md +65 -28
- package/docs/recipes/55-mods-time-wrap.md +25 -17
- package/docs/recipes/56-webgpu-tsl.md +73 -28
- package/docs/recipes/57-control.md +47 -1
- package/docs/recipes/58-input.md +3 -0
- package/docs/recipes/59-depth-post-effects.md +5 -5
- package/docs/recipes/60-judge-the-picture.md +47 -27
- package/docs/recipes/61-deploy.md +27 -0
- package/docs/recipes/62-picture-code.md +276 -0
- package/docs/recipes/63-third-person-start.md +90 -0
- package/docs/recipes/64-particles.md +35 -0
- package/docs/recipes/65-swarm.md +140 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +9 -7
- package/examples/action/main.js +5 -4
- package/examples/action/models.js +12 -14
- package/examples/action/picture/index.js +13 -0
- package/examples/action/picture/lights.js +35 -0
- package/examples/action/picture/materials.js +8 -0
- package/examples/action/picture/palette.js +33 -0
- package/examples/perf-island/.threedog/content-index.json +1 -0
- package/examples/{sheepisland → perf-island}/GAMEMAP.md +18 -14
- package/examples/{sheepisland → perf-island}/assets.js +2 -2
- package/examples/{sheepisland → perf-island}/content/templates.js +1 -1
- package/examples/{sheepisland → perf-island}/content/vegetation.js +3 -1
- package/examples/{sheepisland → perf-island}/main.js +22 -16
- package/examples/{sheepisland/style → perf-island}/models.js +13 -24
- package/examples/{sheepisland → perf-island}/params.js +1 -1
- package/examples/perf-island/picture/index.js +20 -0
- package/examples/perf-island/picture/lights.js +34 -0
- package/examples/perf-island/picture/materials.js +61 -0
- package/examples/perf-island/picture/palette.js +60 -0
- package/examples/perf-island/picture/sky.js +20 -0
- package/examples/{sheepisland → perf-island}/views.js +1 -1
- package/examples/plain-picture/.threedog/content-index.json +1 -0
- package/examples/plain-picture/GAMEMAP.md +91 -0
- package/examples/plain-picture/main.js +48 -0
- package/examples/plain-picture/picture/index.js +21 -0
- package/examples/plain-picture/picture/lights.js +54 -0
- package/examples/plain-picture/picture/materials.js +24 -0
- package/examples/plain-picture/picture/palette.js +16 -0
- package/examples/plain-picture/picture/sky.js +37 -0
- package/examples/pullable.json +31 -9
- package/examples/rc2d/GAMEMAP.md +10 -4
- package/examples/rc2d/README.md +11 -6
- package/examples/rc2d/main.js +26 -36
- package/examples/rc2d/picture/index.js +18 -0
- package/examples/rc2d/picture/lights.js +11 -0
- package/examples/rc2d/picture/materials.js +18 -0
- package/examples/rc2d/picture/palette.js +15 -0
- package/examples/rc2d/picture/post.js +11 -0
- package/examples/rc2d/rc2d.js +18 -28
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +15 -10
- package/examples/styletest/main.js +20 -30
- package/examples/styletest/models.js +29 -29
- package/examples/styletest/params.js +1 -4
- package/examples/styletest/picture/env.js +38 -0
- package/examples/styletest/picture/index.js +16 -0
- package/examples/styletest/picture/lights.js +9 -0
- package/examples/styletest/picture/materials.js +28 -0
- package/examples/styletest/picture/palette.js +22 -0
- package/examples/techniques/contact-shadows/README.md +22 -23
- package/examples/techniques/contact-shadows/contactShadows.js +32 -16
- package/examples/techniques/contact-shadows/main.js +20 -18
- package/examples/techniques/contact-shadows/picture/index.js +14 -0
- package/examples/techniques/contact-shadows/picture/lights.js +34 -0
- package/examples/techniques/contact-shadows/picture/materials.js +12 -0
- package/examples/techniques/contact-shadows/picture/palette.js +17 -0
- package/examples/techniques/day-night-grade/README.md +13 -16
- package/examples/techniques/day-night-grade/main.js +15 -25
- package/examples/techniques/day-night-grade/picture/index.js +20 -0
- package/examples/techniques/day-night-grade/picture/lights.js +45 -0
- package/examples/techniques/day-night-grade/picture/materials.js +15 -0
- package/examples/techniques/day-night-grade/picture/palette.js +59 -0
- package/examples/techniques/day-night-grade/picture/post.js +25 -0
- package/examples/techniques/day-night-grade/picture/sky.js +33 -0
- package/examples/techniques/interior-light/README.md +16 -13
- package/examples/techniques/interior-light/interiorLight.js +19 -17
- package/examples/techniques/interior-light/main.js +31 -68
- package/examples/techniques/interior-light/picture/index.js +24 -0
- package/examples/techniques/interior-light/picture/lights.js +52 -0
- package/examples/techniques/interior-light/picture/materials.js +13 -0
- package/examples/techniques/interior-light/picture/palette.js +32 -0
- package/examples/techniques/interior-light/picture/sky.js +40 -0
- package/examples/techniques/modular-building/README.md +8 -6
- package/examples/techniques/modular-building/kit.js +2 -2
- package/examples/techniques/modular-building/main.js +9 -17
- package/examples/techniques/modular-building/picture/index.js +17 -0
- package/examples/techniques/modular-building/picture/lights.js +26 -0
- package/examples/techniques/modular-building/picture/materials.js +13 -0
- package/examples/techniques/modular-building/picture/palette.js +23 -0
- package/examples/techniques/night-lights/README.md +15 -14
- package/examples/techniques/night-lights/main.js +20 -43
- package/examples/techniques/night-lights/nightLights.js +25 -21
- package/examples/techniques/night-lights/picture/index.js +18 -0
- package/examples/techniques/night-lights/picture/lights.js +44 -0
- package/examples/techniques/night-lights/picture/materials.js +15 -0
- package/examples/techniques/night-lights/picture/palette.js +34 -0
- package/examples/techniques/night-lights/picture/post.js +9 -0
- package/examples/techniques/night-lights/picture/sky.js +36 -0
- package/examples/techniques/outlines-and-rim/README.md +2 -2
- package/examples/techniques/outlines-and-rim/main.js +15 -38
- package/examples/techniques/outlines-and-rim/outlines.js +3 -3
- package/examples/techniques/outlines-and-rim/picture/index.js +16 -0
- package/examples/techniques/outlines-and-rim/picture/lights.js +18 -0
- package/examples/techniques/outlines-and-rim/picture/materials.js +11 -0
- package/examples/techniques/outlines-and-rim/picture/palette.js +16 -0
- package/examples/techniques/outlines-and-rim/picture/post.js +10 -0
- package/examples/techniques/procedural-animation/README.md +6 -4
- package/examples/techniques/procedural-animation/main.js +9 -7
- package/examples/techniques/procedural-animation/picture/index.js +15 -0
- package/examples/techniques/procedural-animation/picture/lights.js +35 -0
- package/examples/techniques/procedural-animation/picture/materials.js +10 -0
- package/examples/techniques/procedural-animation/picture/palette.js +16 -0
- package/examples/techniques/procedural-animation/picture/sky.js +31 -0
- package/examples/techniques/procedural-animation/proceduralAnim.js +1 -1
- package/examples/techniques/procedural-surface/README.md +2 -0
- package/examples/techniques/procedural-surface/main.js +17 -55
- package/examples/techniques/procedural-surface/picture/index.js +14 -0
- package/examples/techniques/procedural-surface/picture/lights.js +18 -0
- package/examples/techniques/procedural-surface/picture/materials.js +34 -0
- package/examples/techniques/procedural-surface/picture/palette.js +15 -0
- package/examples/techniques/stylized-shading/README.md +13 -14
- package/examples/techniques/stylized-shading/main.js +11 -42
- package/examples/techniques/stylized-shading/picture/index.js +14 -0
- package/examples/techniques/stylized-shading/picture/lights.js +23 -0
- package/examples/techniques/stylized-shading/picture/materials.js +18 -0
- package/examples/techniques/stylized-shading/picture/palette.js +19 -0
- package/examples/techniques/stylized-shading/shading.js +2 -2
- package/examples/techniques/sun-and-key-light/README.md +20 -22
- package/examples/techniques/sun-and-key-light/keyLight.js +47 -29
- package/examples/techniques/sun-and-key-light/main.js +19 -63
- package/examples/techniques/sun-and-key-light/picture/index.js +13 -0
- package/examples/techniques/sun-and-key-light/picture/lights.js +33 -0
- package/examples/techniques/sun-and-key-light/picture/materials.js +9 -0
- package/examples/techniques/sun-and-key-light/picture/palette.js +29 -0
- package/examples/techniques/sun-and-key-light/picture/sky.js +16 -0
- package/examples/techniques/three-looks/README.md +21 -0
- package/examples/techniques/three-looks/main.js +58 -0
- package/examples/techniques/three-looks/picture/cartoon.js +23 -0
- package/examples/techniques/three-looks/picture/cinematic.js +27 -0
- package/examples/techniques/three-looks/picture/comic.js +27 -0
- package/examples/techniques/three-looks/picture/index.js +14 -0
- package/examples/techniques/three-looks/picture/sun.js +23 -0
- package/examples/techniques/wet-road/README.md +7 -4
- package/examples/techniques/wet-road/main.js +18 -38
- package/examples/techniques/wet-road/picture/index.js +17 -0
- package/examples/techniques/wet-road/picture/lights.js +57 -0
- package/examples/techniques/wet-road/picture/materials.js +16 -0
- package/examples/techniques/wet-road/picture/palette.js +24 -0
- package/examples/techniques/wet-road/picture/sky.js +46 -0
- package/examples/webgpu-tsl/GAMEMAP.md +10 -4
- package/examples/webgpu-tsl/README.md +13 -10
- package/examples/webgpu-tsl/main.js +30 -7
- package/examples/webgpu-tsl/picture/index.js +18 -0
- package/examples/webgpu-tsl/picture/lights.js +25 -0
- package/examples/webgpu-tsl/picture/materials.js +36 -0
- package/examples/webgpu-tsl/picture/palette.js +23 -0
- package/examples/webgpu-tsl/picture/post.js +16 -0
- package/examples/webgpu-tsl/picture/sky.js +30 -0
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +16 -12
- package/examples/world/art/humanoid.js +9 -13
- package/examples/world/art/index.js +2 -2
- package/examples/world/art/models.js +3 -4
- package/examples/world/art/shapes.js +2 -2
- package/examples/world/assets.js +2 -2
- package/examples/world/content/audio.js +1 -1
- package/examples/world/content/items.js +1 -1
- package/examples/world/content/props.js +1 -1
- package/examples/world/content/templates.js +1 -1
- package/examples/world/content/vegetation.js +1 -1
- package/examples/world/main.js +10 -10
- package/examples/world/models.js +17 -7
- package/examples/world/picture/index.js +20 -0
- package/examples/world/picture/lights.js +41 -0
- package/examples/world/picture/materials.js +34 -0
- package/examples/world/picture/palette.js +74 -0
- package/examples/world/picture/post.js +9 -0
- package/examples/world/picture/sky.js +39 -0
- package/index.d.ts +14 -22
- package/index.js +36 -36
- package/llms.txt +19 -21
- package/modules/ambience/Ambience.js +12 -9
- package/modules/calendar/Calendar.js +20 -20
- package/modules/calendar/index.js +14 -13
- package/modules/calendar/schedule.js +11 -6
- package/modules/calendar/seasons.js +7 -7
- package/modules/camera/FirstPersonCamera.js +2 -2
- package/modules/camera/FixedCamera.js +14 -15
- package/modules/camera/FollowCamera.js +4 -4
- package/modules/camera/RtsCamera.js +11 -11
- package/modules/camera/common.js +51 -25
- package/modules/camera/contract.js +1 -0
- package/modules/camera/projection.js +2 -2
- package/modules/characters/Character.js +47 -39
- package/modules/characters/NPC.js +30 -22
- package/modules/characters/assetModel.js +18 -13
- package/modules/characters/astar.js +7 -5
- package/modules/characters/behaviors.js +4 -5
- package/modules/characters/contract.js +2 -2
- package/modules/characters/index.js +172 -193
- package/modules/characters/moveHelpers.js +14 -3
- package/modules/characters/movers/common.js +22 -15
- package/modules/characters/movers/manual.js +4 -1
- package/modules/characters/movers/rapier.js +7 -6
- package/modules/characters/movers/simple.js +3 -3
- package/modules/characters/movers/support.js +32 -18
- package/modules/characters/npcAvoid.js +4 -4
- package/modules/characters/npcSim.js +28 -18
- package/modules/characters/npcView.js +6 -5
- package/modules/characters/pathAsync.js +12 -10
- package/modules/characters/pathWorker.js +1 -1
- package/modules/characters/player.js +108 -0
- package/modules/characters/playerStrings.js +2 -2
- package/modules/characters/proceduralRig.js +19 -5
- package/modules/characters/useModel.js +5 -5
- package/modules/characters/walkTo.js +11 -17
- package/modules/collision/Collision.js +30 -22
- package/modules/collision/contract.js +15 -0
- package/modules/content/explain.js +1 -2
- package/modules/content/fields.js +24 -3
- package/modules/content/ids.js +2 -2
- package/modules/content/index.js +68 -98
- package/modules/content/loader.js +14 -17
- package/modules/content/markers.js +25 -0
- package/modules/content/models.js +66 -18
- package/modules/content/packs.js +3 -3
- package/modules/content/parts.js +2 -2
- package/modules/content/places.js +35 -0
- package/modules/content/props.js +19 -14
- package/modules/content/rules.js +34 -22
- package/modules/content/stages.js +7 -7
- package/modules/content/templates.js +24 -22
- package/modules/content/words.js +34 -0
- package/modules/debug/DebugPanel.js +10 -43
- package/modules/flow/contract.js +1 -1
- package/modules/flow/index.js +11 -7
- package/modules/gameplay/Container.js +12 -11
- package/modules/gameplay/Containers.js +14 -5
- package/modules/gameplay/Dialogue.js +13 -11
- package/modules/gameplay/Interactions.js +115 -27
- package/modules/gameplay/Inventory.js +11 -12
- package/modules/gameplay/Quests.js +16 -9
- package/modules/gameplay/boxOps.js +1 -1
- package/modules/gameplay/dialogueBox.js +1 -1
- package/modules/gameplay/dialogueBubbles.js +4 -5
- package/modules/gameplay/interactionPrompt.js +1 -1
- package/modules/gameplay/interactions.contract.js +1 -1
- package/modules/gameplay/inventoryOps.js +2 -3
- package/modules/gameplay/pickups.js +81 -44
- package/modules/gameplay/questLog.js +2 -2
- package/modules/gameplay/questSave.js +3 -3
- package/modules/grid/Grid.js +1 -1
- package/modules/grid/Layer.js +16 -3
- package/modules/grid/index.js +47 -19
- package/modules/grid/preview.js +29 -20
- package/modules/grid/tiles.js +19 -23
- package/modules/hlod/index.js +38 -55
- package/modules/hud/index.js +27 -8
- package/modules/hud/parts.js +13 -11
- package/modules/level/contract.js +16 -0
- package/modules/level/heightfield.js +12 -10
- package/modules/level/index.js +48 -152
- package/modules/level/load.js +79 -0
- package/modules/level/meshes.js +65 -0
- package/modules/level/nodes.js +6 -7
- package/modules/lights/index.js +34 -183
- package/modules/lights/slots.js +93 -0
- package/modules/lights/sources.js +88 -0
- package/modules/music/Music.js +31 -27
- package/modules/music/rules.js +1 -1
- package/modules/nav/contract.js +14 -0
- package/modules/nav/index.js +11 -10
- package/modules/net/Client.js +7 -7
- package/modules/net/Host.js +7 -7
- package/modules/net/Net.js +1 -1
- package/modules/net/index.js +5 -4
- package/modules/net/sync.js +2 -2
- package/modules/net/transports.js +2 -2
- package/modules/particles/Particles.js +49 -25
- package/modules/particles/effect.js +27 -10
- package/modules/particles/shaders.js +2 -1
- package/modules/photo/Photo.js +26 -27
- package/modules/rigid/RigidBodies.js +66 -43
- package/modules/rigid/Vehicles.js +2 -3
- package/modules/rigid/ragdoll.js +287 -0
- package/modules/rigid/ragdollBones.js +159 -0
- package/modules/rigid/sync.js +6 -6
- package/modules/settings/Settings.js +114 -45
- package/modules/settings/apply.js +10 -10
- package/modules/settings/sections.js +16 -14
- package/modules/settings/strings.js +1 -1
- package/modules/settings/view.js +3 -3
- package/modules/sky/Sky.js +125 -103
- package/modules/sky/clouds.js +22 -23
- package/modules/sky/dome.js +113 -0
- package/modules/sky/domeLayers.js +13 -13
- package/modules/sky/environment.js +47 -171
- package/modules/sky/fog.js +5 -180
- package/modules/sky/frame.js +42 -97
- package/modules/sky/season.js +9 -3
- package/modules/sky/shader.js +49 -44
- package/modules/sky/skyModule.js +25 -35
- package/modules/sky/tint.js +9 -11
- package/modules/swarm/Swarm.js +346 -0
- package/modules/swarm/draw.js +68 -0
- package/modules/swarm/grid.js +63 -0
- package/modules/terrain/ChunkManager.js +97 -62
- package/modules/terrain/chunkQueries.js +7 -24
- package/modules/terrain/chunkWorker.js +1 -1
- package/modules/terrain/draw.js +157 -0
- package/modules/terrain/index.js +60 -88
- package/modules/terrain/terrainColorMap.js +6 -3
- package/modules/terrain/terrainDefaults.js +4 -3
- package/modules/terrain/terrainEdit.js +32 -27
- package/modules/terrain/terrainGen.js +19 -14
- package/modules/terrain/terrainIsland.js +2 -2
- package/modules/terrain/terrainMesh.js +7 -6
- package/modules/terrain/terrainShape.js +8 -10
- package/modules/terrain/terrainShapeMain.js +3 -3
- package/modules/timeline/Timeline.js +27 -19
- package/modules/timeline/Tween.js +6 -6
- package/modules/timeline/shots.js +5 -7
- package/modules/triggers/index.js +19 -15
- package/modules/vegetation/Vegetation.js +87 -39
- package/modules/vegetation/densityMap.js +4 -7
- package/modules/vegetation/draw.js +196 -0
- package/modules/vegetation/groundChunks.js +11 -31
- package/modules/vegetation/index.js +18 -16
- package/modules/vegetation/modelGeometry.js +3 -6
- package/modules/vegetation/nearFade.js +1 -1
- package/modules/water/Water.js +140 -93
- package/modules/water/surface.js +56 -56
- package/modules/weather/Weather.js +84 -38
- package/modules/weather/particles.js +18 -10
- package/modules/weather/shaders.js +1 -1
- package/modules/weather/weatherDraw.js +145 -0
- package/modules/world/World.js +10 -10
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +18 -12
- package/modules/world/persist.js +73 -25
- package/modules/world/pos.js +4 -4
- package/modules/world/records.js +28 -8
- package/modules/world/sim.js +4 -4
- package/modules/world/state.js +12 -5
- package/modules/world/thingSource.js +4 -2
- package/modules/world/views.js +12 -10
- package/package.json +44 -8
- package/presets.js +3 -5
- package/render/PostFX.js +233 -63
- package/render/backend.js +72 -32
- package/render/cascades.js +200 -0
- package/render/cascades.tsl.js +93 -0
- package/render/daylight.js +56 -0
- package/render/detail.js +13 -12
- package/render/effects.js +60 -42
- package/render/fuse.js +3 -3
- package/render/fx/cel.tsl.js +42 -0
- package/render/fx/cloudShadow.tsl.js +3 -3
- package/render/fx/detail.tsl.js +1 -1
- package/render/fx/index.js +10 -13
- package/render/fx/library.tsl.js +11 -0
- package/render/fx/lighting.tsl.js +2 -1
- package/render/fx/nodeErrors.tsl.js +2 -2
- package/render/fx/objectOrigin.tsl.js +1 -2
- package/render/fx/patchNodes.tsl.js +6 -16
- package/render/fx/postWebGPU.tsl.js +55 -28
- package/render/fx/sky.tsl.js +34 -109
- package/render/fx/uniforms.tsl.js +4 -4
- package/render/fx/water.tsl.js +1 -1
- package/render/fx/wind.tsl.js +1 -1
- package/render/fxNumbers.js +3 -0
- package/render/layers.js +14 -0
- package/render/lighting.js +11 -8
- package/render/lightmap.js +142 -0
- package/render/lights.js +26 -204
- package/render/lit.js +24 -0
- package/render/materials.js +47 -162
- package/render/mergeCommon.js +22 -0
- package/render/modeling.js +2 -2
- package/render/neutral.js +23 -0
- package/render/occlusion.js +200 -0
- package/render/ownFrame.js +5 -5
- package/render/patches.js +46 -41
- package/render/postWebGL.js +19 -9
- package/render/probes.js +182 -128
- package/render/recordSweep.js +117 -0
- package/render/shaderErrors.js +10 -9
- package/render/shadowCache.tsl.js +107 -0
- package/render/shadowTypes.js +9 -0
- package/render/shadows.js +451 -0
- package/render/slots.js +11 -11
- package/render/terms.js +63 -113
- package/render/uniformDecl.js +2 -2
- package/types/core.d.ts +489 -405
- package/types/gameplay.d.ts +225 -114
- package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +23 -8
- package/types/generated/core/{audioVoice.d.ts → audio/audioVoice.d.ts} +2 -2
- package/types/generated/core/{Events.d.ts → base/Events.d.ts} +4 -4
- package/types/generated/core/{I18n.d.ts → base/I18n.d.ts} +7 -15
- package/types/generated/core/{Random.d.ts → base/Random.d.ts} +4 -3
- package/types/generated/core/engine/page.d.ts +24 -0
- package/types/generated/core/{Input.d.ts → input/Input.d.ts} +21 -10
- package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
- package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +16 -8
- package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +4 -3
- package/types/generated/core/{control.d.ts → ops/control.d.ts} +4 -10
- package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +37 -13
- package/types/generated/core/{session.d.ts → saves/session.d.ts} +2 -1
- package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
- package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +1 -1
- package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
- package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +18 -16
- package/types/generated/core/{Commits.d.ts → threads/Commits.d.ts} +1 -1
- package/types/generated/core/{Jobs.d.ts → threads/Jobs.d.ts} +6 -6
- package/types/generated/core/{Threads.d.ts → threads/Threads.d.ts} +4 -4
- package/types/generated/modules/calendar/Calendar.d.ts +10 -11
- package/types/generated/modules/debug/DebugPanel.d.ts +1 -9
- package/types/generated/modules/grid/Layer.d.ts +9 -1
- package/types/generated/modules/grid/index.d.ts +32 -8
- package/types/generated/modules/music/Music.d.ts +7 -5
- package/types/generated/modules/particles/Particles.d.ts +14 -7
- package/types/generated/modules/sky/Sky.d.ts +101 -23
- package/types/generated/modules/sky/skyModule.d.ts +1 -1
- package/types/generated/modules/swarm/Swarm.d.ts +80 -0
- package/types/generated/modules/timeline/Timeline.d.ts +2 -1
- package/types/generated/modules/water/Water.d.ts +51 -3
- package/types/generated/modules/weather/Weather.d.ts +44 -10
- package/types/generated/modules/weather/weatherDraw.d.ts +11 -0
- package/types/generated/modules/world/World.d.ts +7 -5
- package/types/generated/render/PostFX.d.ts +69 -20
- package/types/generated/render/lighting.d.ts +29 -0
- package/types/generated/render/materials.d.ts +20 -44
- package/types/generated/render/occlusion.d.ts +22 -0
- package/types/generated/render/patches.d.ts +1 -0
- package/types/generated/ui/Focus.d.ts +1 -0
- package/types/generated/ui/UI.d.ts +1 -0
- package/types/nav.d.ts +11 -11
- package/types/physics.d.ts +104 -73
- package/types/tsl.d.ts +45 -4
- package/types/world.d.ts +372 -86
- package/ui/Focus.js +21 -10
- package/ui/LoadingScreen.js +2 -2
- package/ui/Parts.js +12 -7
- package/ui/UI.js +17 -17
- package/ui/cursor.js +1 -1
- package/ui/defaults.js +3 -2
- package/ui/theme.js +36 -28
- package/ui/touchPart.js +1 -1
- package/core/UrlState.js +0 -110
- package/core/assetEntry.js +0 -106
- package/core/describeRender.js +0 -71
- package/core/holds.js +0 -134
- package/core/look/coreParts.js +0 -219
- package/core/look/part.js +0 -253
- package/core/look/points.js +0 -255
- package/core/look/report.js +0 -96
- package/core/look/shadowPart.js +0 -63
- package/core/look/state.js +0 -45
- package/core/look/write.js +0 -70
- package/core/page.js +0 -79
- package/core/shadowTypes.js +0 -16
- package/core/styleParts.js +0 -114
- package/core/util.js +0 -17
- package/docs/MIGRATING-0.3.md +0 -248
- package/docs/MIGRATING-0.4.md +0 -228
- package/docs/MIGRATING-0.5.md +0 -68
- package/docs/PERF.md +0 -245
- package/docs/api/style.md +0 -136
- package/docs/api/terrainLook.md +0 -10
- package/docs/api/vegetationLook.md +0 -10
- package/docs/api/weatherLook.md +0 -10
- package/docs/recipes/09-style.md +0 -218
- package/docs/recipes/35-style-from-reference.md +0 -153
- package/docs/recipes/36-sky-ground-plant-looks.md +0 -118
- package/docs/recipes/37-terrain-look-hooks.md +0 -119
- package/docs/recipes/38-environment-look-hooks.md +0 -99
- package/docs/recipes/41-thing-registry.md +0 -97
- package/docs/recipes/42-terrain-shape.md +0 -64
- package/docs/recipes/44-water-weather-look-hooks.md +0 -144
- package/docs/recipes/47-island-snow-backdrop.md +0 -45
- package/docs/recipes/48-make-material.md +0 -75
- package/docs/recipes/52-look.md +0 -282
- package/docs/recipes/54-three-idioms.md +0 -88
- package/examples/action/look.js +0 -5
- package/examples/sheepisland/.threedog/content-index.json +0 -1
- package/examples/sheepisland/style/index.js +0 -79
- package/examples/styletest/look.js +0 -11
- package/examples/techniques/day-night-grade/dayNightGrade.js +0 -76
- package/examples/webgpu-tsl/tslScene.js +0 -75
- package/examples/world/style/index.js +0 -61
- package/examples/world/style/plugins/10-bloom.js +0 -5
- package/modules/sky/cascades.js +0 -186
- package/modules/sky/cascades.tsl.js +0 -82
- package/modules/sky/look.js +0 -54
- package/modules/sky/lookFog.js +0 -76
- package/modules/sky/lookShadow.js +0 -62
- package/modules/sky/lookSky.js +0 -169
- package/modules/sky/shadow.js +0 -98
- package/modules/terrain/look.js +0 -83
- package/modules/terrain/lookGround.js +0 -66
- package/modules/vegetation/look.js +0 -119
- package/modules/vegetation/lookWind.js +0 -98
- package/modules/water/look.js +0 -91
- package/modules/water/surfaceDefaults.js +0 -3
- package/modules/weather/look.js +0 -74
- package/modules/weather/weatherLook.js +0 -135
- package/render/lookGlow.js +0 -139
- package/render/lookSurface.js +0 -224
- package/render/postLook.js +0 -164
- package/render/surface.js +0 -105
- package/types/generated/core/page.d.ts +0 -18
- package/types/generated/modules/weather/weatherLook.d.ts +0 -12
- package/types/style.d.ts +0 -671
- /package/core/{Vars.js → base/Vars.js} +0 -0
- /package/core/{mulberry32.js → base/mulberry32.js} +0 -0
- /package/core/{inputDefaults.js → input/inputDefaults.js} +0 -0
- /package/core/{textureBytes.js → inspect/textureBytes.js} +0 -0
- /package/core/{actor.js → ops/actor.js} +0 -0
- /package/core/{opsFail.js → ops/opsFail.js} +0 -0
- /package/core/{opsHistory.js → ops/opsHistory.js} +0 -0
- /package/core/{saveIds.js → saves/saveIds.js} +0 -0
- /package/core/{screenToGround.js → scene/screenToGround.js} +0 -0
- /package/core/{cells.js → stream/cells.js} +0 -0
- /package/core/{streamCells.js → stream/streamCells.js} +0 -0
- /package/core/{pureWorker.js → threads/pureWorker.js} +0 -0
- /package/examples/{sheepisland → perf-island}/content/index.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/props.js +0 -0
package/docs/recipes/18-world.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# World data: things that must be saved, grow, and keep changing while far away
|
|
2
2
|
|
|
3
|
-
**In this recipe**: 1. Three steps · 2. How to change data · 3. Example: a crop grows
|
|
4
|
-
5. Example: something that wanders · 6. Near, far, camera, player · 7. Time and ordering rules · 8. Querying nearby things ·
|
|
5
|
-
9. zone and data limits
|
|
3
|
+
**In this recipe**: 1. Three steps · 2. How to change data · 3. Example: a crop grows on the calendar, press E to… · 4. Data written in content ·
|
|
4
|
+
4b. One object from start to end · 5. Example: something that wanders · 6. Near, far, camera, player · 7. Time and ordering rules · 8. Querying nearby things ·
|
|
5
|
+
9. zone and data limits
|
|
6
6
|
|
|
7
7
|
Requires module `world()` (already included in the `openWorld()` preset). The interaction prompts in the examples need
|
|
8
8
|
`interactions({ ...presets.interactions.nearest })`, the inventory needs `inventory()` (keys: `presets.bindings.interact` / `.inventory`). The API list is in
|
|
@@ -17,13 +17,13 @@ transient effects. Everything placed in a level comes from content, so a new gam
|
|
|
17
17
|
Many copies of one interactive object (chests, beds, campfires) with the same model, interaction and container: define it once as a content template
|
|
18
18
|
and place instances (recipe 30-templates.md); the template is the shared read-only definition, the record holds only the instance state.
|
|
19
19
|
|
|
20
|
-
## 1. Three steps: data,
|
|
20
|
+
## 1. Three steps: data, picture, change
|
|
21
21
|
```js
|
|
22
22
|
const W = engine.world;
|
|
23
23
|
W.add({ id: 'zombie_1', kind: 'zombie', position: [10, 0, -4], hp: 10 }); // fields must be plain values; without an id one is numbered automatically (saved)
|
|
24
24
|
W.present('zombie', {
|
|
25
25
|
build: rec => new THREE.Mesh(zombieGeo, zombieMat), // required: built when the camera is near (may be async); world adds it to the scene at rec.position
|
|
26
|
-
update: (rec, obj, dt) => { obj.visible = rec.hp > 0; }, // optional: called every frame for records that have a model; change the
|
|
26
|
+
update: (rec, obj, dt) => { obj.visible = rec.hp > 0; }, // optional: called every frame for records that have a model; change the picture from the data
|
|
27
27
|
dispose: (rec, obj) => engine.remove(obj), // optional: first argument is the data, second the model; this is the default
|
|
28
28
|
show: rec => rec.hp > 0, // optional: false = this record has no model right now (picked up, waiting to respawn)
|
|
29
29
|
radius: 40, // optional: how near to build the model (meters or a function); default world.radius (60)
|
|
@@ -37,32 +37,34 @@ W.simulate('zombie', {
|
|
|
37
37
|
(`world.ready`); it retries when you walk away and come back.
|
|
38
38
|
- `show` is re-evaluated when `world.set` changes data of that kind. Calling `present` again for the same kind tears down old models with the old
|
|
39
39
|
dispose and rebuilds them with the new one.
|
|
40
|
-
- Animation, particles and other things that only matter per frame go in `present.update`, not in simulate.
|
|
40
|
+
- Animation, particles and other things that only matter per frame go in `present.update`, not in simulate. It runs after world placed the model
|
|
41
|
+
on its record, so picture-only motion written there stays: `update: (rec, obj, dt) => { obj.getObjectByName('legL').rotation.x = Math.sin(rec.walk * 9) * 0.5;
|
|
42
|
+
obj.position.x += rec.stagger * 0.1; }` (a leg swing, a stagger offset). Moving the model from anywhere else is put back next frame, with a warning.
|
|
41
43
|
|
|
42
44
|
## 2. How to change data
|
|
43
45
|
- Discrete changes (open a chest, switch growth stage, get picked up, change direction) use `W.set(id, { opened: true })`: it emits `world:change` and
|
|
44
46
|
re-evaluates `show`. Don't `set` every step. id / kind cannot be changed (to change the kind, remove then add).
|
|
45
47
|
- Things that change every step (position, timers, pathfinding state) are changed directly on the rec's fields inside simulate, and position with
|
|
46
48
|
`W.move`: no event, cheap.
|
|
47
|
-
- Both ways are saved (a save compares contents, it does not rely on events). `move` emits no event: if the
|
|
48
|
-
`update
|
|
49
|
+
- Both ways are saved (a save compares contents, it does not rely on events). `move` emits no event: if the picture needs to follow position, compare in
|
|
50
|
+
`update`.
|
|
49
51
|
- Don't hold a rec object for long: loading a save replaces it with a new object. Keep the id and call `W.get(id)` when you need it.
|
|
50
52
|
- Position forms: Vector3 / object / `[x, y, z]` / `{ x, z }` (a missing y keeps the old one). In development NaN or an array with only two numbers
|
|
51
53
|
throws immediately.
|
|
52
54
|
|
|
53
|
-
## 3. Example: a crop grows
|
|
55
|
+
## 3. Example: a crop grows on the calendar, press E to harvest when ripe
|
|
54
56
|
The key idea: **don't accumulate every step; record the time it was planted, `plantedAt = clock.now`, and growth = now - planted time**. Whether the
|
|
55
57
|
player walked away, loaded a save, or fast-forwarded with `engine.step(60)`, the result is right, and no simulate is needed.
|
|
56
58
|
```js
|
|
57
|
-
import { presets, THREE
|
|
59
|
+
import { presets, THREE } from 'threedog';
|
|
58
60
|
|
|
59
|
-
const GROW = 120; // ripe after 120
|
|
61
|
+
const GROW = 120; // ripe after 120 calendar seconds (the unit of clock.now)
|
|
60
62
|
const growth = rec => Math.min(1, (engine.clock.now - rec.plantedAt) / GROW); // 0..1
|
|
61
63
|
const geo = new THREE.ConeGeometry(0.25, 0.8, 6);
|
|
62
64
|
|
|
63
65
|
engine.world.present('crop', {
|
|
64
66
|
build(rec) {
|
|
65
|
-
const m = new THREE.Mesh(geo,
|
|
67
|
+
const m = new THREE.Mesh(geo, new THREE.MeshLambertMaterial({ color: 0x6aa84f }));
|
|
66
68
|
m.castShadow = true;
|
|
67
69
|
m.userData.use = engine.interactions.add(m, { label: 'Harvest', radius: 2, enabled: () => growth(rec) >= 1, onUse: () => harvest(rec) }); // can be harvested only when ripe
|
|
68
70
|
return m;
|
|
@@ -90,7 +92,7 @@ engine.ops.define('crop.plant', {
|
|
|
90
92
|
The same "store when, derive the rest" pattern fits any timed thing: an enemy camp that respawns (`clearedAt`), a turret or machine cooldown
|
|
91
93
|
(`usedAt`), a door that shuts again (`openedAt`):
|
|
92
94
|
`const ready = rec => engine.clock.now - rec.usedAt >= rec.cooldown; // no per-step counter, correct after skip and load`
|
|
93
|
-
Test: `engine.ops.run('crop.plant', { x: 2, z: 2 })` -> `engine.step(130)` (
|
|
95
|
+
Test: `engine.ops.run('crop.plant', { x: 2, z: 2 })` -> `engine.step(130)` (130 real seconds, 130 calendar seconds at `clock.rate` 1) -> the player walks next to it -> `engine.ops.run('interaction.use')` ->
|
|
94
96
|
`engine.inventory.count('carrot')`.
|
|
95
97
|
|
|
96
98
|
## 4. Data written in content: `initial`
|
|
@@ -113,11 +115,31 @@ Gameplay randomness (drops, lightning, wander turns) still uses `engine.random`
|
|
|
113
115
|
generated at runtime (planted by the player, spawned) are saved whole; `add(def, { save: false })` is not saved (temporary things). The rules are
|
|
114
116
|
described at the top of `modules/world/persist.js`.
|
|
115
117
|
World models are in the thing registry too (`engine.thing(id)` answers with the record, saved `'record'`): do not move them from code. Change the
|
|
116
|
-
record (`ops.run('thing.set', { id, position })`, `world.set` / `world.move`); dev reports code that moves a `positionFrom: 'record'` model, and
|
|
117
|
-
`engine.add` of a model throws (recipe
|
|
118
|
+
record (`ops.run('thing.set', { id, position })`, `world.set` / `world.move`) and the model follows; dev reports code that moves a `positionFrom: 'record'` model, and
|
|
119
|
+
`engine.add` of a model throws (recipe 40).
|
|
118
120
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
+
## 4b. One object from start to end: who owns what
|
|
122
|
+
Four questions meet in every object: where its state lives, when it may change, who owns each part, what a save keeps. Here one chest answers all four; a door,
|
|
123
|
+
a switch or a parked vehicle goes the same way. It is a flat content entry (recipe 30 §2 and §7) with the `chest` template and `chest.toggle` op of recipe 30 §1:
|
|
124
|
+
`content/places.js`:
|
|
125
|
+
```js
|
|
126
|
+
export default { yard: { x: 12, z: -6 } };
|
|
127
|
+
```
|
|
128
|
+
`content/props.js`:
|
|
129
|
+
```js
|
|
130
|
+
export default [{ id: 'yard-chest', template: 'chest', place: 'yard', x: 1 }];
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
| Step | What happens | Who owns what | What a save keeps |
|
|
134
|
+
|---|---|---|---|
|
|
135
|
+
| Creation | `content.load` makes the record `yard-chest` from the entry and the template's `state` | The content files own the definition and the starting position; `engine.world` owns the record | Nothing: the record equals the content |
|
|
136
|
+
| Near | The model is built at the record's position | The record owns position and `opened`; the model only shows them. Geometry and materials belong to `engine.assets`, shared by every chest | Nothing: models are not saved |
|
|
137
|
+
| Interaction | Using it runs the op: `e.world.set(id, { opened: true })` | Only an op or a fixed step changes the record; `animate` reads it. Nothing writes to the model | `opened: true`, the one changed field |
|
|
138
|
+
| Leaving the area | The model is torn down; the record stays, and `simulate.far` still runs if the kind has it | The world still owns the record; there is nothing to clean up. The shared model data outlives this copy | The same |
|
|
139
|
+
| Loading a save | The record becomes a new object with the saved change on top of today's content; the model is built again when near | Code keeps the id and calls `W.get(id)`: a rec or a model held from before is stale | The same; a place moved since the save moves the chest too |
|
|
140
|
+
| Removal | An op calls `e.world.remove(id)`; the model goes with the record | The record is gone. The shared model data stays until nothing uses it and `assets.trim()` runs (a level change does) | The deletion: the chest stays gone after loading, while a new game has it again |
|
|
141
|
+
|
|
142
|
+
The one habit that follows: hold `'yard-chest'`, never the record or the model, across any of these steps.
|
|
121
143
|
|
|
122
144
|
## 5. Example: something that wanders
|
|
123
145
|
For enemies that chase the player / wandering NPCs there is the ready-made `engine.npcs.behavior(name, { near, far })` + `engine.npcs.avoid` (mutual
|
|
@@ -144,7 +166,7 @@ function wander(rec, dt) {
|
|
|
144
166
|
grounded...) and which vehicle it is on (vehicle) live in the record and are saved, and it is never torn down by walking away. Only the character's
|
|
145
167
|
mover changes the position and then writes it back to the record; **move the player with `player.placeAt(position)`, not `world.move('player')`**
|
|
146
168
|
(the mover would overwrite it on the next step). On load the player is put back from the record.
|
|
147
|
-
- **Models are built around the stream sources** (
|
|
169
|
+
- **Models are built around the stream sources** (`33-stream-sources.md`): by default the player (`engine.stream.player`, follows
|
|
148
170
|
`world.anchor`) and the camera
|
|
149
171
|
focus (`engine.stream.camera`). Built inside the radius of any source, torn down beyond 1.25x of all of them, with an error of at most 8 meters; at
|
|
150
172
|
most `world.buildPerFrame` are built per frame (default 8, unlimited while loading), and `ready` waits until all are built. Tearing a model down
|
|
@@ -169,20 +191,16 @@ function wander(rec, dt) {
|
|
|
169
191
|
(default 500); the rest queue for the next step, and dt keeps accumulating without loss. It counts records, not milliseconds, so the result does not
|
|
170
192
|
depend on how fast the machine is.
|
|
171
193
|
- The owed time and the simulation step count are saved: after loading they are caught up the same way, and the same save gives the same result
|
|
172
|
-
however many fixed steps run per frame. For things measured
|
|
173
|
-
- **Far in workers** (
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
those 4 steps are kept). `far` must be self-contained: it is recompiled from source and sees only `(rec, dt)` and globals like `Math`; an outside
|
|
177
|
-
variable throws `... x is not defined. Put constants inside the function, or store the value on the record` (also with `threads: false`, so you find
|
|
194
|
+
however many fixed steps run per frame. For things measured on the calendar (grows in a few days, respawns at a time), record `engine.clock.now` and compare.
|
|
195
|
+
- **Far in workers** (thousands of crops, spawners or machines): `W.simulate('crop', { far, worker: true })`. Each step's far batch runs in `engine.threads` workers and is written
|
|
196
|
+
back 4 fixed steps later through `engine.commits`; a late reply runs on the main thread, so threads on / off / slow give **bit-identical** records, and only fields far changed are written
|
|
197
|
+
back. `far` must be self-contained: it is recompiled from source and sees only `(rec, dt)` and globals like `Math`; an outside variable throws (also with `threads: false`, so you find
|
|
178
198
|
it in development). Limit: a save taken while a batch is in flight re-simulates that stretch after loading (equal within float tolerance, not bit-identical).
|
|
179
199
|
|
|
180
200
|
## 8. Querying nearby things
|
|
181
201
|
```js
|
|
182
|
-
const list = engine.world.query({ kind: 'zombie', near: engine.player, radius: 30, where: z => z.hp > 0 }); // array, nearest first
|
|
183
202
|
let crowd = 0;
|
|
184
|
-
engine.world.forEachNear(engine.player, 5, (rec, d2) => { if (rec.kind === 'zombie') crowd++; }); // no allocation, no sorting
|
|
185
|
-
engine.world.get(id); engine.world.view(id); // the data / the current model (null when far)
|
|
203
|
+
engine.world.forEachNear(engine.player, 5, (rec, d2) => { if (rec.kind === 'zombie') crowd++; }); // no allocation, no sorting; world.query sorts nearest first and returns an array
|
|
186
204
|
```
|
|
187
205
|
For things that query neighbors every step (hundreds of zombies avoiding each other) use `forEachNear`; inside the callback don't add / remove / move,
|
|
188
206
|
note them down and change them after the loop.
|
|
@@ -193,6 +211,3 @@ note them down and change them after the loop.
|
|
|
193
211
|
- Data must be plain values (numbers, strings, booleans, arrays, plain objects): in development, putting a three.js object or a function in it throws
|
|
194
212
|
immediately and explains the fix — models go in present, logic goes in simulate.
|
|
195
213
|
|
|
196
|
-
## 10. Stream sources: what is loaded where (teleport, far camera)
|
|
197
|
-
Moved to `33-stream-sources.md`: the shared source list of `engine.stream`, `await engine.stream.teleport(p)`, `engine.stream.source(...)` for a photo
|
|
198
|
-
camera or a far view.
|
|
@@ -8,20 +8,22 @@ ray registration is needed.**
|
|
|
8
8
|
|
|
9
9
|
## 1. A first-person shooting range (copy it and it runs)
|
|
10
10
|
```js
|
|
11
|
-
import { createEngine, presets, openWorld, hud, THREE
|
|
12
|
-
import
|
|
11
|
+
import { createEngine, presets, openWorld, hud, THREE } from 'threedog';
|
|
12
|
+
import { createPicture } from './picture/index.js'; // the game's own picture, plain three.js (recipe 62)
|
|
13
13
|
import { terrainPreset } from '@threedog/terrain-noise';
|
|
14
14
|
|
|
15
|
-
const engine = createEngine({ canvas: document.getElementById('view'),
|
|
15
|
+
const engine = createEngine({ canvas: document.getElementById('view'), lights: false, saveKey: 'range' });
|
|
16
16
|
engine.use(openWorld({ seed: 7, terrain: terrainPreset(), camera: 'firstPerson' }), hud()); // camera (required): 'follow' | 'firstPerson' | 'rts' | 'fixed', or pass a module like firstPersonCamera({ height: 1.7 })
|
|
17
|
+
const picture = createPicture(engine);
|
|
17
18
|
engine.input.action('shoot', { label: 'Shoot', keys: ['Mouse0', 'KeyF'] }); // the left mouse button is a key too (Mouse0 / Mouse1 / Mouse2); either it or KeyF works
|
|
18
19
|
engine.characters.createPlayer({ ...presets.player.aim, spawn: engine.characters.findSpawn([0, 0, 0], { minH: 3, maxH: 14 }) });
|
|
20
|
+
Object.assign(window, { engine, picture });
|
|
19
21
|
await engine.start(); // place targets after the terrain is generated
|
|
20
22
|
|
|
21
23
|
// Targets: ordinary three.js objects. Put your own data in target.userData; managing them with a Map / Set is faster than traversing the scene
|
|
22
24
|
const targets = [];
|
|
23
25
|
function addTarget(x, z) {
|
|
24
|
-
const t = new THREE.Mesh(new THREE.CylinderGeometry(0.5, 0.5, 0.1, 16),
|
|
26
|
+
const t = new THREE.Mesh(new THREE.CylinderGeometry(0.5, 0.5, 0.1, 16), new THREE.MeshLambertMaterial({ color: 0xd9534f }));
|
|
25
27
|
t.rotation.x = Math.PI / 2;
|
|
26
28
|
t.position.set(x, engine.surface(x, z) + 1.5, z);
|
|
27
29
|
engine.add(t); targets.push(t);
|
|
@@ -31,7 +33,7 @@ for (let i = 0; i < 6; i++) addTarget(p0.x + (i - 2.5) * 3, p0.z - 15);
|
|
|
31
33
|
|
|
32
34
|
let score = 0;
|
|
33
35
|
engine.hud.counter('score', { label: 'Hits', value: 0 });
|
|
34
|
-
engine.describe.add('range', () => ({ score, targets: targets.length })); //
|
|
36
|
+
engine.describe.add('range', () => ({ score, targets: targets.length })); // dev bridge: threedog describe range; in code the part sits under its name: engine.describe('range').range.score
|
|
35
37
|
|
|
36
38
|
engine.onFixed(() => { // firing is gameplay: read it in fixed so the result is independent of frame rate
|
|
37
39
|
if (!engine.input.pressed('shoot')) return; // "just pressed" from the fixed-step snapshot; one click counts once
|
|
@@ -42,6 +44,7 @@ engine.onFixed(() => { // firing is gameplay:
|
|
|
42
44
|
engine.hud.counter('score', { value: ++score }); // calling again with the same id = update
|
|
43
45
|
});
|
|
44
46
|
```
|
|
47
|
+
- **Where fire and reload live**: the engine has no weapon system. In a game with ammo they are the game's ops (`engine.ops.define('weapon.fire', ...)`, recipe 23), so a key, a test and the dev bridge run one path; the fixed step above only calls `engine.ops.run`.
|
|
45
48
|
- **Finding the target again**: when a target is made of several meshes, `hit.object` is the piece that was hit. Set `userData.target = true` on the
|
|
46
49
|
target's root object, then `let o = hit.object; while (o && !o.userData.target) o = o.parent;`.
|
|
47
50
|
- **Why not read `pointer.clicked`**: it is true only for "this frame" and requires no dragging; a fixed step can miss that frame (at a high frame
|
|
@@ -58,15 +61,16 @@ engine.onFixed(() => { // firing is gameplay:
|
|
|
58
61
|
bodies too, pass `targets: 'all'`.
|
|
59
62
|
|
|
60
63
|
## 2. What happens after a hit
|
|
61
|
-
- Hit-point effect: `engine.particles.emit(name, hit.point)` (install `particles()` first).
|
|
64
|
+
- Hit-point effect: `engine.particles.emit(name, hit.point)` (install `particles()` first, recipe 64).
|
|
62
65
|
- For bullets with flight time (arcs, enemies dodging): don't use a ray; write `world.add({ kind: 'bullet', ... })` + `world.simulate`, see `18-world.md`.
|
|
63
66
|
- Distance limit: `engine.pick(0, 0, { targets, far: 60 })`.
|
|
67
|
+
- Recoil: `pick` casts from the camera as last drawn, so a `rig.yaw` / `rig.pitch` write reaches it on the next drawn step. For several shots in one step with recoil between them, build the direction from the rig's angles and use `engine.raycast`.
|
|
64
68
|
- Score, ammo: `hud.counter` / `hud.bar`; numbers that must be saved go in `engine.vars` (`engine.vars.bump('score')`); after changing them call
|
|
65
69
|
`hud.counter` again to sync the display.
|
|
66
70
|
|
|
67
71
|
## 3. Testing
|
|
68
72
|
```js
|
|
69
|
-
engine.
|
|
73
|
+
engine.haltLoop();
|
|
70
74
|
engine.input.simulate('shoot'); engine.step(0.1); engine.input.simulate('shoot', false); // simulate a click on the action bound to Mouse0 (use your action name)
|
|
71
75
|
// To hit a specific target: first aim the camera at it with engine.cameraRig.lookAt(target), then click
|
|
72
76
|
```
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Content vocabulary, key actions in actions.js, saving and loading at startup
|
|
2
2
|
|
|
3
3
|
**In this recipe**: 1. Condition words / effect words · 1b. Content packs · 2. actions.js: a game's own key actions · 3. Interact keys ·
|
|
4
|
-
4. Continue and new game · Save failures and versions · Save format
|
|
4
|
+
4. Continue and new game · 4b. Best times and high scores · Save failures and versions · Save format
|
|
5
5
|
|
|
6
6
|
## 1. Condition words / effect words
|
|
7
7
|
The full vocabulary is in the last section of `../api/content.md` (**generated from `modules/content/rules.js`**, so it never goes stale):
|
|
@@ -32,7 +32,7 @@ export default {
|
|
|
32
32
|
for (const [id, r] of Object.entries(data)) if (!ctx.data.items?.[r.makes]) ctx.err(`recipe ${id} makes unknown item ${r.makes}`);
|
|
33
33
|
},
|
|
34
34
|
map: data => Object.entries(data).map(([id, r]) => `${id} -> ${r.makes}`), // optional GAMEMAP lines
|
|
35
|
-
// optional: the keys of each entry (core/params.js format, no default); threedog check reports unknown keys, wrong types, out of range
|
|
35
|
+
// optional: the keys of each entry (core/base/params.js format, no default); threedog check reports unknown keys, wrong types, out of range
|
|
36
36
|
fields: { needs: 'object', makes: 'string', seconds: { type: 'number', min: 0, optional: true, desc: 'crafting time' } },
|
|
37
37
|
},
|
|
38
38
|
},
|
|
@@ -42,13 +42,15 @@ export default {
|
|
|
42
42
|
// content/recipes.js
|
|
43
43
|
export default { bread: { needs: { flour: 2 }, makes: 'bread' } };
|
|
44
44
|
```
|
|
45
|
-
Add `recipes` to `content/index.js` like any other file
|
|
46
|
-
|
|
45
|
+
Add `recipes` to `content/index.js` like any other file, and `rules` too: the loader knows a kind only from the `rules` it is handed (`threedog check`
|
|
46
|
+
says so when one is missing). `load` is optional: a game that imports the file itself leaves it out and still gets the check and the map entry.
|
|
47
|
+
A name `content/index.js` lists that is neither an engine file nor a registered kind is an error, and so is `content.load({ enemies })` without the kind:
|
|
48
|
+
both say how to register it. A kind may not reuse an engine file name. A file the index does not list is no content, so `threedog check` gives one warning.
|
|
49
|
+
A game's own data that the engine never reads, such as translated story text, belongs outside `content/`: a folder of its own that the game
|
|
50
|
+
imports itself, or `engine.i18n.add()` when it is text the UI fetches with `engine.t`. To have it checked and on the map, register a kind with no `load`.
|
|
47
51
|
|
|
48
|
-
**Field tables.** Every content entry has one: the engine
|
|
49
|
-
|
|
50
|
-
a kind adds `fields` as above. `threedog check` validates every entry against its table (a misspelled `scael` names `scale`), and
|
|
51
|
-
`engine.content.fields(name)` returns the same table for tools such as an editor panel, so the two cannot disagree.
|
|
52
|
+
**Field tables.** Every content entry has one: the engine's own, a template's `fields` (recipes/30-templates.md) or a kind's `fields` as above. `threedog check` validates every entry
|
|
53
|
+
against its table (a misspelled `scael` names `scale`), and `engine.content.fields(name)` returns the same table for tools such as an editor panel.
|
|
52
54
|
|
|
53
55
|
## 1b. Content packs: several data sets in one load
|
|
54
56
|
A content pack is the same object `content/index.js` exports (`{ items, templates, props, quests, ... }`, optional `name` for messages), shipped as a
|
|
@@ -60,7 +62,7 @@ import packs from './assets.js'; // export default [f
|
|
|
60
62
|
engine.assets.manifest(packs); // the same objects `npm run check` reads the names from
|
|
61
63
|
engine.content.load([base, forest], { places: { home } });
|
|
62
64
|
```
|
|
63
|
-
- Packs load in list order, so a pack may use what an earlier one defines.
|
|
65
|
+
- Packs load in list order, so a pack may use what an earlier one defines. A pack's own `places` load with it; the `places` option goes on top (a place computed at startup).
|
|
64
66
|
- Within one call an id may live in one pack only: `items.apple` in two packs, or the same prop / pickup id, is an error naming both packs. A later,
|
|
65
67
|
separate `load` call still overrides by name on purpose (hot reload, a chapter replacing a quest).
|
|
66
68
|
- A pack may carry its sounds: `audio: { sounds, ambience, music, footsteps }` (`recipes/31-audio.md` section 8). Sounds, footsteps and music tracks
|
|
@@ -96,13 +98,16 @@ engine.saves.autosave(3); // autosave to 'auto' every 3 minutes of play (wai
|
|
|
96
98
|
```
|
|
97
99
|
|
|
98
100
|
## 3. Interact keys: which object, and who acts
|
|
99
|
-
`interactions({ pick })` decides what the interact key uses (no default, `[interaction-setup]` names the fix)
|
|
101
|
+
`interactions({ pick })` decides what the interact key uses (no default, `[interaction-setup]` names the fix). It takes no key: bind one in `createEngine({ bindings: presets.bindings.interact })`, or with `engine.input.bind`.
|
|
102
|
+
`radius` is measured from the object's origin, not its edge. For a large object (a boat, a house) raise it, or add the interaction to a small marker
|
|
103
|
+
object at the spot where it is used.
|
|
104
|
+
|
|
100
105
|
Pick the rule that fits the camera, not the genre default:
|
|
101
106
|
```js
|
|
102
107
|
engine.use(interactions({ ...presets.interactions.nearest })); // E, nearest within 2.5 m (top-down, third person)
|
|
103
108
|
engine.use(interactions({ pick: 'facing' })); // only what the actor faces (within 60°): the door behind you stays dark
|
|
104
109
|
engine.use(interactions({ pick: 'aim', radius: 2 })); // closest to the screen-center ray: first person, shooters
|
|
105
|
-
engine.use(interactions({ pick: (list, ctx) => list.find(c => c.id.startsWith('npc')) ?? list[0]
|
|
110
|
+
engine.use(interactions({ pick: (list, ctx) => list.find(c => c.id.startsWith('npc')) ?? list[0] })); // own rule; list = enabled ones in range, nearest first
|
|
106
111
|
engine.interactions.pickMode = 'aim'; // switch at runtime (entering a first-person mode)
|
|
107
112
|
```
|
|
108
113
|
One object with two verbs = two interactions with different key actions; each key picks among its own action, and `engine.interactions.options` lists
|
|
@@ -120,6 +125,7 @@ when the key is released, the actor leaves the radius, `enabled()` turns false o
|
|
|
120
125
|
skip the hold; an approach returns `{ approaching }`, a promise of onUse's result).
|
|
121
126
|
```js
|
|
122
127
|
engine.interactions.add(well, { label: 'Pump', hold: 1.5, onUse: fill });
|
|
128
|
+
engine.interactions.add(shell, { id: 'shell-1', label: 'Pick up', once: true, counter: 'shells' }); // mesh gone after E, counted: recipe 03 "Pick and count"
|
|
123
129
|
engine.interactions.add(clerk, { label: 'Talk', radius: Infinity, approach: true, onUse: talk });
|
|
124
130
|
```
|
|
125
131
|
**Who acts** is `engine.actor` (a world record id, default `'player'`). Interactions, trigger zones, objective-marker distances, the world simulation
|
|
@@ -144,7 +150,7 @@ if (engine.saves.check('auto') === null) await engine.session.load('auto'); //
|
|
|
144
150
|
- `engine.session.load(slot)` and `engine.session.newGame()` both return `Promise<boolean>`: always `await`. `session.load` starts from the new-game
|
|
145
151
|
state and puts the save on top, so a part the save lacks (a module added in a later version) starts fresh instead of keeping the current run's
|
|
146
152
|
state. `engine.saves.load(slot)` is a quick load onto the running playthrough; never build Continue from it.
|
|
147
|
-
- Loading restores the player, world data (world changes and deletions), inventory, quests, clock and random state; initial data in content files
|
|
153
|
+
- Loading restores the player, the view (the camera rig's yaw and pitch: a first-person game needs no save code for it), world data (world changes and deletions), inventory, quests, clock and random state; initial data in content files
|
|
148
154
|
(`initial`) is the same whether it is loaded before or after the save, so ignore the order.
|
|
149
155
|
- A load rebuilds the props and other world records: an Object3D your code kept from before (a door mesh, a lamp) is gone afterwards. Keep the
|
|
150
156
|
record id, not the mesh, and look it up again on `save:loaded`: `engine.world.get(id)` for the record, `engine.world.view(id)` for its model
|
|
@@ -154,6 +160,14 @@ if (engine.saves.check('auto') === null) await engine.session.load('auto'); //
|
|
|
154
160
|
- During development, to jump straight into a save: URL `?save=slot1` (`threedog state` also understands `save=`).
|
|
155
161
|
- In tests, `engine.saves.save('x'); await engine.saves.flush();` writes before reading back.
|
|
156
162
|
|
|
163
|
+
## 4b. Best times and high scores: data that outlives saves
|
|
164
|
+
Best lap times, a leaderboard or high scores belong to the player, not to one playthrough: in a save part a new game would wipe them. Persist them beside the saves, in `localStorage` under `engine.saves.storageKey(name)`, a key that shares the game's name and stays out of the save slots:
|
|
165
|
+
```js
|
|
166
|
+
const key = engine.saves.storageKey('records');
|
|
167
|
+
const records = () => JSON.parse(localStorage.getItem(key) ?? '{ "laps": [] }');
|
|
168
|
+
const addLap = time => { const r = records(); r.laps.push(time); localStorage.setItem(key, JSON.stringify(r)); };
|
|
169
|
+
```
|
|
170
|
+
|
|
157
171
|
## Save failures and versions
|
|
158
172
|
- `await engine.saves.save(slot)` is `true` only after the write is on disk; show "saved" only then. On a failed write (storage full, IndexedDB /
|
|
159
173
|
localStorage refused) it is `false`, the player already saw why, and the previous save of that slot is kept (memory follows the disk).
|
|
@@ -167,22 +181,21 @@ if (engine.saves.check('auto') === null) await engine.session.load('auto'); //
|
|
|
167
181
|
channels, random state or item counts is clamped or dropped with one `save-value` warning per part, and the rest loads.
|
|
168
182
|
- Two tabs of one game: a tab overwrites a slot only while it holds the copy it last read, wrote or loaded. A save over a newer one another tab
|
|
169
183
|
wrote returns `false` (toast, `save-stale`); that tab then lists the newer save, and loading it lets it save there again.
|
|
170
|
-
- `engine.saves.versions` lists the version of every part this build reads (`{ world:
|
|
184
|
+
- `engine.saves.versions` lists the version of every part this build reads (`{ world: 5, clock: 1, ... }`); raise a part's `version` with a `migrate`
|
|
171
185
|
step when its data changes shape.
|
|
172
|
-
- Import is offline and checked: `saves.import(text)` and `saves.importFile(file)`
|
|
173
|
-
attachments must be `data:` URLs (nothing is fetched).
|
|
186
|
+
- Import is offline and checked: `saves.import(text)` and `saves.importFile(file)` refuse anything that is not a save, and attachments must be `data:` URLs (nothing is fetched).
|
|
174
187
|
|
|
175
|
-
## Save format
|
|
188
|
+
## Save format
|
|
176
189
|
A save is one envelope; `engine.saves.collect()` returns it and `export` / `exportFile` carry it unchanged:
|
|
177
190
|
```js fragment
|
|
178
191
|
{ format: 1, // the envelope's own version: a save with a higher format is refused as tooNew (none = 1)
|
|
179
192
|
savedAt: 1730000000000, // real time of the save
|
|
180
|
-
versions: { world:
|
|
193
|
+
versions: { world: 5, quests: 2, clock: 1 }, // each part's version (none = 1)
|
|
181
194
|
parts: { world: {...}, quests: {...}, clock: {...}, vars: {...} } } // each saves.register part's data, by key
|
|
182
195
|
```
|
|
183
|
-
- **Parts and versions**: each `engine.saves.register(key, { version, migrate, save, load })` owns one part. When `save()` changes shape, raise
|
|
196
|
+
- **Parts and versions**: each `engine.saves.register(key, { version, migrate, save, load })` owns one part. `load` takes one argument, the data: `load: data => …`, never `load(engine, data)`, the shape of a module hook (`npm run check` warns, rule R33). When `save()` changes shape, raise
|
|
184
197
|
`version` by 1 and add `migrate[oldVersion] = data => newData`; load runs the steps in order on a copy, so `load` only sees the current shape. A
|
|
185
|
-
part from a newer build, or a missing step, refuses the whole load before anything changes.
|
|
198
|
+
part from a newer build, or a missing step, refuses the whole load before anything changes. This is how a game's own saved data migrates across its releases (there is no other system): keep one saved file per released game version, never edit it, and load each in a test with `engine.saves.apply(sample)` (the engine does the same for its own parts in `tests/specs/save-compat.mjs`).
|
|
186
199
|
- **Parts nobody owns are kept**: a part in the loaded save whose module is not installed in this run (a feature turned off for a version) is written
|
|
187
200
|
back unchanged on every save, and handed to the module if it registers later. Only a new game drops it.
|
|
188
201
|
- **Authored baseline + per-id diff**: everything placed in a level comes from content (props, template instances, pickups, NPCs, grid items in
|
|
@@ -190,25 +203,11 @@ A save is one envelope; `engine.saves.collect()` returns it and `export` / `expo
|
|
|
190
203
|
`changed` (fields of an authored record that differ), `removed` (authored records removed), `records` (records created during play, such as
|
|
191
204
|
`engine.content.spawn`, drops and built walls, saved whole), `owed` (seconds owed, only for kinds simulated with `far`). The same content gives the same
|
|
192
205
|
world, and a new game's world part is empty: in dev, start warns about records that code created or changed before it, naming them.
|
|
193
|
-
- **Orphans are kept**: a saved change whose id the content no longer defines (an entry renamed or deleted) stays in the save and is written
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
would <!-- r18-ignore-line -->
|
|
197
|
-
move it; `describe().world.orphans` lists them. A rename in `content/renames.js` moves the state to the new id (recipe 30, "Writing the ids, <!--
|
|
198
|
-
r18-ignore-line -->
|
|
199
|
-
renaming them"). <!-- r18-ignore-line -->
|
|
200
|
-
- **Runtime ids and migration**: records made during play are `<kind>#<n>` (world part version 3). An older save's `<kind>-<n>` ids are renamed when
|
|
201
|
-
it loads, together with the owed time, container goods and fields that name them; only ids the counter could have made are touched (own kind, `n` up
|
|
202
|
-
to the saved counter, each `n` once), so an authored `crate-2` stays as it is. A migrate step that needs another part gets the whole save as its
|
|
203
|
-
second argument: `migrate: { 1: (data, save) => … }`. <!-- r18-ignore-line -->
|
|
204
|
-
- **Grid layers diff too**: cells authored in `content/grids.js` (`plot: { …, layers: { soil: [[i, j, { tilled: true }]] } }`) are the baseline;
|
|
205
|
-
the <!-- r18-ignore-line -->
|
|
206
|
-
`grids` part (version 2) stores only changed cells (`set`) and emptied authored ones (`clear`), and keeps a diff for a grid the run does not
|
|
207
|
-
have. <!-- r18-ignore-line -->
|
|
206
|
+
- **Orphans are kept**: a saved change whose id the content no longer defines (an entry renamed or deleted) stays in the save and is written back, never dropped, so reverting the content change gets the data back. Dev warns once with the closest id and the `content/renames.js` pair that would move it; `describe().world.orphans` lists them. A rename in `content/renames.js` moves the state to the new id (recipe 30, "Writing the ids, renaming them"). <!-- r18-ignore-line -->
|
|
207
|
+
- **Runtime ids**: records made during play are `<kind>#<n>`, so a runtime id never equals an authored one. A migrate step that needs another part gets the whole save as its second argument: `migrate: { 1: (data, save) => … }`. <!-- r18-ignore-line -->
|
|
208
|
+
- **Grid layers diff too**: cells authored in `content/grids.js` (`plot: { …, layers: { soil: [[i, j, { tilled: true }]] } }`) are the baseline; the `grids` part stores only changed cells (`set`) and emptied authored ones (`clear`), and keeps a diff for a grid the run does not have. <!-- r18-ignore-line -->
|
|
208
209
|
- **Stable ids, never positions**: saved data names things by stable ids. The player's vehicle is saved by `rigid.addWheeled(mesh, { id })`; quest
|
|
209
210
|
progress by step ids (`steps: [{ id: 'talk-mayor', ... }]`, recipe 04). Content edits (a new step, a new prop) then never shift an old save.
|
|
210
|
-
- **Built-in part versions**: `world` 3 (version 1 kept `records` as an array, version 2 the `<kind>-<n>` runtime ids), `quests` 2 (version 1 kept
|
|
211
|
-
step positions; the migrate step maps them to ids through the quest definitions), `containers` 2 and `grids` 2, every other part 1.
|
|
212
211
|
- The export file wraps the envelope:
|
|
213
212
|
`{ threedog: 'save', format: 1, game, slot, savedAt, data: <envelope>, files: [{ group, id, at, meta, type, url: 'data:...' }] }`.
|
|
214
|
-
- Tests: `
|
|
213
|
+
- Tests: `threedog test "Save failure"`.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Camera: first / third person, top-down strategy, fixed shots, switched at runtime
|
|
2
2
|
|
|
3
3
|
**In this recipe**: 1. Press V to switch between first and third person · 2. What the engine does for you when switching · 3. Other common things ·
|
|
4
|
-
4. Over the shoulder, lock-on framing, mouse lock · 4b. Looking up, ground and walls, driving the view yourself · 5. Take over the player ·
|
|
4
|
+
4. Over the shoulder, lock-on framing, mouse lock · 4b. Looking up, ground and walls, driving the view yourself · 4c. Chase camera behind a car · 5. Take over the player ·
|
|
5
5
|
6. Orthographic view, and taking the camera over yourself · 7. Your own camera module
|
|
6
6
|
|
|
7
7
|
Four cameras; the kind names are always: `'follow'` third-person follow · `'firstPerson'` first person · `'rts'` top-down strategy · `'fixed'` fixed shots.
|
|
@@ -39,11 +39,12 @@ engine.setCamera('follow', { distance: 8, pitch: 0.3 });
|
|
|
39
39
|
## 3. Other common things
|
|
40
40
|
- **Cycling through several**:
|
|
41
41
|
`const VIEWS = ['follow', 'firstPerson', 'rts']; engine.setCamera(VIEWS[(VIEWS.indexOf(engine.cameraRig.kind) + 1) % VIEWS.length]);`
|
|
42
|
-
- **A fixed camera needs shots first**: `engine.setCamera('fixed', { shots: { hall: { position: [0, 6, 12], lookAt: [0, 0, 0] } }, start: 'hall' })`.
|
|
42
|
+
- **A fixed camera needs shots first**: `engine.setCamera('fixed', { shots: { hall: { position: [0, 6, 12], lookAt: [0, 0, 0] } }, start: 'hall' })`. A shot stays where it was placed; a view that pans at a fixed angle is the follow camera (section 6).
|
|
43
43
|
- **Camera-specific methods** exist only after switching: `engine.cameraRig.lookAt(position)` (first person), `cut('name')` (fixed shots),
|
|
44
44
|
`screenToGround(...)` (rts). Check `kind` before calling.
|
|
45
45
|
- **Teleport, then lookAt**: `await engine.stream.teleport(p); engine.cameraRig.lookAt(target);` works in that order: `lookAt` aims from the body's
|
|
46
46
|
current position, not from the last drawn frame. Call it after the move (the angles do not follow later moves).
|
|
47
|
+
- **Saves and new games**: a save holds the view (`yaw`, `pitch`), and `session.load` / `saves.load` put it back. A new playthrough rebuilds the installed camera on the same object, so a kept `const rig = engine.cameraRig` stays valid (one from `setCamera` with options does not). A kind switched to with `setCamera` is not restored: only the heading carries, so call `setCamera` again on `session:start` if the game keeps that choice.
|
|
47
48
|
- **Player movement direction follows the camera**: `engine.cameraRig.forward()` / `right()` change automatically after switching.
|
|
48
49
|
- **Cutscene takeover**: while anyone holds `engine.takeCamera(owner)` (`engine.cameraOverride` is not null) the camera module leaves the camera alone; see [the engine API](../api/engine.md).
|
|
49
50
|
- **Shooting games**: bind first-person firing to a mouse-button action, see `19-shooting-picking.md`.
|
|
@@ -52,10 +53,10 @@ engine.setCamera('follow', { distance: 8, pitch: 0.3 });
|
|
|
52
53
|
```js
|
|
53
54
|
engine.use(followCamera({ distance: 3, shoulder: 0.7, pitch: 0.15, pointerLock: true })); // shooter / action-adventure view
|
|
54
55
|
engine.cameraRig.shoulder = -0.7; // switch shoulders at any time (plain property)
|
|
55
|
-
engine.cameraRig.frame(enemy.
|
|
56
|
+
engine.cameraRig.frame(enemy.root); // lock-on: turn to "behind the player, looking at the enemy"; frame(null) lets go
|
|
56
57
|
```
|
|
57
58
|
- **`shoulder`**: meters the aim point (and so the camera) moves to the right along `right()`; negative = left, 0 = centered (default).
|
|
58
|
-
- **`pointerLock`** (default false): a click on the canvas locks the mouse, so moving it turns the view with no dragging; Esc releases. Not on phones. If the browser refuses the lock the camera falls back to dragging; `describe().camera.pointerLock` is a state machine: `state` is `off` / `unsupported` / `waiting-click` / `requesting` / `locked` / `refused`, plus `covered` (what sits on the canvas centre and eats the click), `cameraOverride` (a takeover blocks locking) and `lastFailure { reason, agoSec }`; the text line shows the same.
|
|
59
|
+
- **`pointerLock`** (default false): a click on the canvas locks the mouse, so moving it turns the view with no dragging; Esc releases, and `engine.page.releaseLock()` releases from code without opening the pause menu. Not on phones. If the browser refuses the lock the camera falls back to dragging; `describe().camera.pointerLock` is a state machine: `state` is `off` / `unsupported` / `waiting-click` / `requesting` / `locked` / `refused`, plus `covered` (what sits on the canvas centre and eats the click), `cameraOverride` (a takeover blocks locking) and `lastFailure { reason, agoSec }`; the text line shows the same.
|
|
59
60
|
The press that locks is swallowed (no `Mouse0`, no click) so it cannot attack or fire; `swallowLockClick: false` delivers it.
|
|
60
61
|
Leave it off when the mouse buttons are for UI or clicking the ground.
|
|
61
62
|
- **`yaw` means which side of the player the camera is on**: `camera = focus + (sin yaw, cos yaw) * distance`, so the camera looks along
|
|
@@ -75,10 +76,15 @@ engine.use(followCamera({ minPitch: -0.9, ground: 'shorten' })); // or the sam
|
|
|
75
76
|
`'shorten'` slides it along the arm toward the player (the view direction is kept, so you really look up);
|
|
76
77
|
`'raise'` lifts it straight up (the view direction changes: from flat ground you cannot look up);
|
|
77
78
|
`'none'` leaves it; a function `facts => position | null` gets `{ position, lookPoint, dir, arm, distance, groundY, clearance, surface, rig }`.
|
|
78
|
-
Default: `'shorten'` when `minPitch < 0`, otherwise `'raise'
|
|
79
|
+
Default: `'shorten'` when `minPitch < 0`, otherwise `'raise'`.
|
|
79
80
|
- **Walls** (with `collision()` installed) pull the arm in at once and let it out slowly; the shortest arm is `collision({ cameraMin })` (default 1.5 m).
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
**What blocks by default**: every `addCircle` / `addBox` / `addSegment` collider, over its footprint and up to its height, and every mesh registered
|
|
82
|
+
with `engine.rays.addStatic(mesh, { occluder: true })` (`level()` registers its buildings and `col_` meshes). A mesh alone blocks nothing, so a tree
|
|
83
|
+
crown or an eave that reaches past its collider lets the camera inside. Register that mesh: it stops the arm and adds no gameplay collider (it does
|
|
84
|
+
join `engine.raycast`). `collision({ cameraOcclusion: 'colliders' })` tests colliders only.
|
|
85
|
+
A content prop or template with `collide` blocks with its whole mesh, crown and eaves included, with no game code. A hand-written mesh stays opt-in: `addStatic(mesh, { occluder: true })`. In a level, `userData.occluder = false` on a node (or a parent) keeps it from blocking, and a hidden mesh does not block (`col_` meshes do). `addStatic` skips `InstancedMesh` and `SkinnedMesh` (dev warns once): rays do not hit them, so give them a collider or register a plain stand-in mesh.
|
|
86
|
+
Give the colliders the camera may pass through `occluder: false`
|
|
87
|
+
(`engine.collision.addCircle(tree, { radius: 0.4, occluder: false })`, or `collide: { circle: 0.4, occluder: false }` / `occluder: false` on a content prop or template): walkers are still stopped, the arm ignores them. A dense forest of
|
|
82
88
|
blocking trunks collapses the camera onto the player; `collision({ canopyHeight })` covers only the terrain's own trees.
|
|
83
89
|
- **Close-up**: when the camera ends up nearer than `hideTargetNear` (default 0.9 m) to the look point, the followed object is hidden from the
|
|
84
90
|
camera (shadow stays, layer `hideLayer`); `hideTargetNear: 0` turns it off.
|
|
@@ -86,6 +92,19 @@ engine.use(followCamera({ minPitch: -0.9, ground: 'shorten' })); // or the sam
|
|
|
86
92
|
`getView()` → `{ yaw, pitch, distance, arm, lookPoint, look }` (`look` is the 3D view direction, `arm` the actual length this frame).
|
|
87
93
|
With `mouseLook: false` the built-in mouse / stick look and wheel zoom are off and the game owns yaw and pitch (call `setView` every frame from `onFrame`).
|
|
88
94
|
|
|
95
|
+
## 4c. Chase camera behind a car
|
|
96
|
+
`addWheeled({ camera })` sets the follow camera's distance and height while seated, but the camera keeps its own yaw, so nothing swings the view behind the car. A racing view is a few lines of game code with `followCamera({ mouseLook: false })`:
|
|
97
|
+
```js
|
|
98
|
+
let yaw = null;
|
|
99
|
+
engine.onFrame(dt => {
|
|
100
|
+
const q = car.body.rotation(); // car: what addWheeled returned
|
|
101
|
+
const want = Math.atan2(2 * (q.x * q.z + q.w * q.y), 1 - 2 * (q.x * q.x + q.y * q.y)) + Math.PI; // a car drives along its +z; the view looks along -z at yaw 0
|
|
102
|
+
yaw ??= want;
|
|
103
|
+
yaw += Math.atan2(Math.sin(want - yaw), Math.cos(want - yaw)) * Math.min(1, 5 * dt); // the shortest way round, catching up at 5 per second
|
|
104
|
+
engine.cameraRig.setView({ yaw });
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
89
108
|
## 5. Take over the player: your own movement, facing and lock-on
|
|
90
109
|
The engine has no default here: `createPlayer` needs `control` (a preset such as `presets.player.thirdPerson` gives keys relative to the camera, Shift
|
|
91
110
|
run, Space jump, turning toward where it walks and `cameraFollow: true`). Each piece below replaces one part and keeps the rest (world record, saving,
|
|
@@ -140,8 +159,17 @@ The default stays perspective. On resize the view height stays `size` and the wi
|
|
|
140
159
|
engine.setCamera('fixed', { position: [14, 14, 14], lookAt: [0, 0, 0], projection: 'orthographic', size: 16 });
|
|
141
160
|
// per shot: shots: { hall: { position, lookAt, projection: 'orthographic', size: 12 }, yard: { position, lookAt } } // yard stays perspective
|
|
142
161
|
// follow the player from a fixed angle
|
|
143
|
-
engine.setCamera('follow', { pitch: 0.6, yaw: 0.8, distance: 20, projection: 'orthographic', size: 14 });
|
|
162
|
+
engine.setCamera('follow', { pitch: 0.6, yaw: 0.8, distance: 20, projection: 'orthographic', size: 14, mouseLook: false, ground: 'none' });
|
|
163
|
+
```
|
|
164
|
+
**A view that pans at a fixed angle** (isometric, tactics, city builders) is that follow camera, not a fixed shot. `mouseLook: false` stops the drag and the wheel from moving the view, and `ground: 'none'` stops hills from tilting it. It follows the player, or with no player any object the game moves:
|
|
165
|
+
```js
|
|
166
|
+
const view = new THREE.Object3D(); // the point the view is centered on
|
|
167
|
+
engine.cameraRig.follow(view); // again on 'session:start': a new playthrough follows the player or nothing
|
|
168
|
+
engine.onFrame(dt => { view.position.x += engine.input.axis.x * 12 * dt; view.position.z -= engine.input.axis.y * 12 * dt; });
|
|
144
169
|
```
|
|
170
|
+
`smoothing` sets how tightly the view keeps up (higher is tighter).
|
|
171
|
+
|
|
172
|
+
A `setCamera` before play (boot code, or with the title up) is the camera every playthrough starts from, the same as passing the options to the camera module. During play it is a switch: a new playthrough goes back.
|
|
145
173
|
|
|
146
174
|
- `engine.camera` stays the one object everything holds (render, post, shadows, sky); it is flipped to an orthographic matrix, so `camera.isOrthographicCamera`
|
|
147
175
|
is true, `camera.left/right/top/bottom` are set, and `camera.zoom` still zooms. `camera.fov` is ignored while it is on.
|
|
@@ -179,6 +207,11 @@ ortho.position.set(10, 10, 10); ortho.lookAt(0, 0, 0); fit(); addEventListener('
|
|
|
179
207
|
Swapping the object only works while no post effect is active: the post chain's scene pass keeps the camera it was built with. With post effects, use
|
|
180
208
|
`projection: 'orthographic'` above instead.
|
|
181
209
|
|
|
210
|
+
**Side view (side-scroller).** `presets.player.sideScroller` moves the player along world X only (A / D, `z` stays) and turns it toward the move. Face the camera along -Z with `yaw: 0`, so +X is screen right (`yaw: Math.PI` looks from the far side and flips left and right), on `followCamera`:
|
|
211
|
+
```js
|
|
212
|
+
engine.use(followCamera({ projection: 'orthographic', size: 15, yaw: 0, pitch: 0, lockPitch: true, distance: 40, ground: 'none', mouseLook: false }));
|
|
213
|
+
```
|
|
214
|
+
|
|
182
215
|
## 7. Your own camera module
|
|
183
216
|
Everything else in the engine reads only what `modules/camera/contract.js` lists from `engine.cameraRig`: `forward()` / `right()` (control: 'camera',
|
|
184
217
|
faceMode 'camera', targeting), `follow(object, opts?)` (createPlayer, getting in and out of a vehicle), `focusPoint()` (photo, where the world loads)
|
|
@@ -101,7 +101,3 @@ Loading a save replaces the whole inventory, and refreshing every frame follows
|
|
|
101
101
|
## 5. Saving
|
|
102
102
|
The inventory (gold included) and every container with contents are saved automatically; a shelf that was sold out is remembered too (`{}`), and
|
|
103
103
|
loading does not restock it. You write nothing.
|
|
104
|
-
|
|
105
|
-
## 6. Verification
|
|
106
|
-
The "shop" case in `tests/specs/containers.mjs` runs the whole flow: buy -> consign -> choice disappears when money is short -> save -> refresh and
|
|
107
|
-
load, with the shelf and gold consistent.
|
package/docs/recipes/23-ops.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Ops: one entry point for what players and NPCs do (engine.ops)
|
|
2
2
|
|
|
3
3
|
**In this recipe**: 1. Define and run · 2. Who calls it, and when · 3. Built-in ops · 4. Read the log · 5. The guard · 6. Testing ·
|
|
4
|
-
7. Scenario tests · 8. Inspect and explain · 9. Randomness ·
|
|
4
|
+
7. Scenario tests · 8. Inspect and explain · 9. Randomness · 11. Structured failures, nextFixed, and who halted the loop ·
|
|
5
5
|
12. Failing in run, atomic ops, revision
|
|
6
6
|
|
|
7
7
|
**What is an op**: one discrete thing an actor decides to do: buy, talk, attack, roll, fire, reload, craft, build, demolish. Write one with
|
|
@@ -68,8 +68,12 @@ returns `'halted'`.
|
|
|
68
68
|
| `inventory.trade` | `{ take, give, takeN?, giveN?, container? }` (all or nothing in `ctx.actor`'s container; reversible with `engine.ops.undo`, recipe 03) | `noContainer` `notEnough` `full` |
|
|
69
69
|
| `inventory.use` | `{ item }` (from `ctx.actor`'s container; runs the item's `use`, see recipe 03) | `notEnough` `notUsable` or the item's `canUse` reason |
|
|
70
70
|
| `inventory.drop` | `{ item, n? }` (a pickup at the actor's feet, data kept) | `notEnough` `noWorld` `noPosition` |
|
|
71
|
-
| `thing.set` | `{ id, position?, rotation?, scale?, visible? }` (core; a world record via `world.set` / `move`, an `engine.add` object saved as an override when it has an id; undoable, recipe
|
|
71
|
+
| `thing.set` | `{ id, position?, rotation?, scale?, visible? }` (core; a world record via `world.set` / `move`, an `engine.add` object saved as an override when it has an id; undoable, recipe 40) | `noThing` `engineOwned` `recordVisible` |
|
|
72
72
|
| `thing.remove` | `{ id }` (core; undoable: an `engine.add` object is detached and kept, a record re-added) | `noThing` `engineOwned` |
|
|
73
|
+
| `pickup.take` | `{ id }` (the item goes into `ctx.actor`'s container, or its give function runs) | `unknown` `respawning` `noPosition` `tooFar` and more; `ops.list()` has them all |
|
|
74
|
+
| `npc.talk` | `{ npc, script?, channel? }` (`channel` `main` locks input, `bubble` shows lines over the NPC) | `noDialogue` `unknown` |
|
|
75
|
+
| `grid.place` · `grid.remove` · `grid.move` | `{ grid, item, cell, rotation?, level?, fields?, id? }` · `{ id }` · `{ id, cell, rotation?, grid?, level? }` (recipe 29) | `noGrid` `unknown` `notPlaced` and more; `ops.list()` has them all |
|
|
76
|
+
| `time.skip` | `{ seconds }` (core; timers, calendar events and far simulation catch up in order) | `notForward` |
|
|
73
77
|
| `photo.take` | none (`r.value` is the shot; can = `photo.canTake()`, the key emits `photo:denied { reason }`) | `denied` or yours |
|
|
74
78
|
|
|
75
79
|
## 4. Read the log
|
|
@@ -116,11 +120,12 @@ Put `<workspace>/tests/scenarios/<name>.json` in the engine package or a game; `
|
|
|
116
120
|
{ "snapshot": "after-barter", "only": ["inventory"] }
|
|
117
121
|
] }
|
|
118
122
|
```
|
|
119
|
-
- `state` is `engine.applyState` params; `"pos": "@id"` stands 1 m beside a world record. The
|
|
123
|
+
- `state` is `engine.applyState` params; `"pos": "@id"` stands 1 m beside a world record. The loop is halted first, so game time moves only in `step`
|
|
120
124
|
(seconds) and `press`.
|
|
121
125
|
- `op` steps run with `source: 'test'` (`actor` optional); `expect` is `"ok"` (default) or the failure code. A failure prints the `engine.explain` sentence.
|
|
122
126
|
- `expect` maps `describe()` paths to values (`nearby[0].name` works; numbers within 0.01; `null` = absent). `snapshot` compares with
|
|
123
127
|
`tests/snapshots/<name>.describe.json` (`only` / `ignore` / `tolerance`; write it with `threedog test <name> --update-snapshots`).
|
|
128
|
+
- A file has 120 s under `threedog test`; a long one sets `"timeout"` at the top, in milliseconds, as a spec does.
|
|
124
129
|
- Before any step runs, every op name and step field is checked; a typo fails with "did you mean". The run stops at the first failed step.
|
|
125
130
|
- Use `press` only for the one test per key that proves "key -> op". Examples in the engine repository: `packages/engine/tests/scenarios/`.
|
|
126
131
|
|
|
@@ -143,12 +148,7 @@ op's `run` emitted it, seq is the history seq); `chain` walks up to the root as
|
|
|
143
148
|
Gameplay randomness uses `engine.random` (`next / range / int / pick / chance`): it is saved with the game and `createEngine({ seed })` fixes it, so a
|
|
144
149
|
scenario replays the same. `Math.random` breaks both.
|
|
145
150
|
|
|
146
|
-
##
|
|
147
|
-
The engine repository's `Properties` specs (fast-check, a devDependency) runs random sequences of ops / saves / newGame inside the page in one `ev()` and checks the state rules (item totals kept, a refused op changes nothing, save then load is identical, newGame leaves nothing behind, a failed `engine.use` batch changes nothing).
|
|
148
|
-
A failure prints the shrunk minimal sequence and the seed. Replay: `FC_SEED=<seed> npm test -- "Properties: random op"`; more cases: `FC_RUNS=300` (default 25). Without fast-check installed the specs skip and say why.
|
|
149
|
-
To check a new rule, add a step kind to `stepArb` and a check in `pageRun`; turn every found sequence into a fixed regression spec.
|
|
150
|
-
|
|
151
|
-
## 11. Structured failures, nextFixed, and who paused
|
|
151
|
+
## 11. Structured failures, nextFixed, and who halted the loop
|
|
152
152
|
`can` may return a reason string (`'noMoney'`) or a structured failure. Every failed result from `run` / `can` / `undo` has `{ ok: false, code, facts, nextActions }`; a string failure becomes `code = that string`, `facts = {}`, `nextActions = []`, so read `.code` without checking the shape. `engine.inspect()`, `ops.list({ available: true })`, `engine.describe()` actions and `engine.explain({ op })` carry `facts` / `nextActions` too.
|
|
153
153
|
```js
|
|
154
154
|
engine.ops.define('shop.buy', {
|
|
@@ -159,7 +159,7 @@ const r = engine.ops.run('shop.buy', {}); // r.ok === false, r.code === 'noMon
|
|
|
159
159
|
```
|
|
160
160
|
`engine.nextFixed(fn)` runs `fn` at the start of the next fixed step and returns a Promise of its value, so a UI click or a promise callback can safely write gameplay state: `await engine.nextFixed(() => engine.ops.run('door.open', { id: 'gate' }))`. It is built on `engine.commits` and waits while frozen or loading.
|
|
161
161
|
|
|
162
|
-
Tests that
|
|
162
|
+
Tests that halt the loop name themselves (default `'game'`) and end their own halt with the handle: `const h = engine.haltLoop('my-test'); ... h.remove()`. The loop stays halted until every owner has removed theirs, so one helper cannot end another's halt.
|
|
163
163
|
|
|
164
164
|
## 12. Failing in run, atomic ops, revision
|
|
165
165
|
`run` can fail like `can`: return or throw `{ ok: false, code, facts, nextActions }` (a value that merely has a `code` field is not a failure; `ok: false` is required). `facts` is an object (`{ need: 5 }`) or a list of `{ id, field, actual, expected? }` naming the record and field that were wrong. The engine never invents `nextActions`; only the op definition declares them. Every result carries `revision` (`engine.ops.revision`), a counter bumped once per committed op: "did anything change since I looked" is one compare.
|
|
@@ -174,7 +174,7 @@ engine.ops.define('craft.bread', {
|
|
|
174
174
|
after: (e) => e.audio.sfx('ding'), // sound / animation: runs only after the op committed
|
|
175
175
|
});
|
|
176
176
|
```
|
|
177
|
-
What atomic covers
|
|
177
|
+
What atomic covers: it copies the save parts that declared `saves.register(key, { atomic: true })` (the built-ins above; a game's own part can opt in) before `run` and loads them back on failure, so it costs one save of those per run (fine for a craft op, wrong for a per-frame op in a huge world). Events already emitted, sound, animation and any other module's state are not undone; keep such effects in `after`. Ops called from an atomic run join it (their `after` hooks wait for the outermost commit, and a rolled-back outer also takes back their revision). `ops.list()` and `engine.explain({ op })` report `atomic`.
|
|
178
178
|
|
|
179
179
|
Causal trace (`events.traceSize > 0`, recipe 06): failed ops are noted as `op:<name>` with their `code`; `collision.lineClear(a, b, { who })` as `sight` (blocked lines always, clear ones for the focused object only); NPC state changes as `npc:state`. A game's behavior notes its own mode switch with `engine.events.note('npc:mode', { obj: rec.id, data: { from: 'patrol', to: 'investigate' } })`; `events.traceFocus('guard-1')` makes one object verbose.
|
|
180
180
|
|