threedog 0.7.0 → 1.0.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 +411 -1
- package/README.md +8 -11
- package/core/{Animator.js → assets/Animator.js} +30 -18
- package/core/{Assets.js → assets/Assets.js} +131 -56
- package/core/{Baked.js → assets/Baked.js} +4 -4
- package/core/assets/assetEntry.js +302 -0
- package/core/{assetHot.js → assets/assetHot.js} +9 -7
- package/core/{assetLoad.js → assets/assetLoad.js} +55 -16
- package/core/assets/assetLod.js +113 -0
- package/core/{assetManifest.js → assets/assetManifest.js} +19 -11
- package/core/{assetReport.js → assets/assetReport.js} +7 -14
- package/core/{namedModel.js → assets/namedModel.js} +17 -13
- package/core/{Audio.js → audio/Audio.js} +47 -25
- 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} +15 -12
- package/core/{Random.js → base/Random.js} +7 -4
- package/core/{Vars.js → base/Vars.js} +14 -4
- package/core/{easing.js → base/easing.js} +1 -1
- package/core/{errorCodes.js → base/errorCodes.js} +151 -125
- package/core/{errorHints.js → base/errorHints.js} +17 -10
- package/core/{errors.js → base/errors.js} +12 -10
- package/core/{events.generated.js → base/events.generated.js} +11 -0
- package/core/base/follows.js +26 -0
- package/core/base/math.js +66 -0
- package/core/{params.js → base/params.js} +5 -6
- package/core/base/saveValues.js +81 -0
- package/core/base/sections.js +97 -0
- package/core/base/spelling.js +32 -0
- package/core/base/util.js +32 -0
- package/core/{validate.js → base/validate.js} +34 -34
- package/core/{Engine.js → engine/Engine.js} +137 -91
- package/core/{Loading.js → engine/Loading.js} +34 -5
- package/core/{copies.js → engine/copies.js} +4 -4
- package/core/{headlessLoad.js → engine/headlessLoad.js} +32 -15
- package/core/{lifecycle.js → engine/lifecycle.js} +41 -34
- package/core/{loop.js → engine/loop.js} +88 -49
- package/core/engine/moduleSlots.js +176 -0
- package/core/{moduleTypes.js → engine/moduleTypes.js} +26 -14
- package/core/engine/modules.js +503 -0
- package/core/{page.js → engine/page.js} +59 -29
- package/core/{plugins.js → engine/plugins.js} +21 -12
- package/core/{services.js → engine/services.js} +50 -40
- package/core/{startup.js → engine/startup.js} +66 -54
- package/core/{Input.js → input/Input.js} +67 -39
- package/core/{inputContext.js → input/inputContext.js} +14 -5
- package/core/input/inputKeyboard.js +39 -0
- package/core/{inputPad.js → input/inputPad.js} +24 -3
- package/core/{inputPointer.js → input/inputPointer.js} +11 -3
- package/core/input/inputSeat.js +66 -0
- package/core/{inputTouch.js → input/inputTouch.js} +24 -7
- package/core/{Budget.js → inspect/Budget.js} +21 -20
- package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +43 -18
- package/core/{Describe.js → inspect/Describe.js} +34 -26
- package/core/{Inspect.js → inspect/Inspect.js} +39 -10
- package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +7 -8
- package/core/{InspectPerf.js → inspect/InspectPerf.js} +19 -13
- package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
- package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +3 -2
- package/core/{UrlState.js → inspect/UrlState.js} +60 -24
- package/core/{catalog.js → inspect/catalog.js} +15 -8
- package/core/{checks.js → inspect/checks.js} +7 -5
- package/core/{debugView.js → inspect/debugView.js} +4 -4
- package/core/{describeRender.js → inspect/describeRender.js} +24 -22
- package/core/{describeText.js → inspect/describeText.js} +17 -8
- package/core/inspect/geometryWatch.js +38 -0
- package/core/{lightWatch.js → inspect/lightWatch.js} +8 -8
- package/core/inspect/metadata.generated.js +4140 -0
- package/core/{pictureWriters.js → inspect/pictureWriters.js} +130 -47
- package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
- package/core/inspect/toolDoor.js +21 -0
- package/core/inspect/valueHistory.js +35 -0
- package/core/{Ops.js → ops/Ops.js} +44 -14
- package/core/{control.js → ops/control.js} +57 -31
- package/core/ops/holds.js +140 -0
- package/core/{opsAtomic.js → ops/opsAtomic.js} +18 -5
- package/core/{opsCheck.js → ops/opsCheck.js} +11 -10
- package/core/{opsFail.js → ops/opsFail.js} +5 -7
- package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
- package/core/{opsRun.js → ops/opsRun.js} +9 -6
- package/core/{owned.js → ops/owned.js} +33 -19
- package/core/{sharedPoint.js → ops/sharedPoint.js} +13 -16
- package/core/{stackFrames.js → ops/stackFrames.js} +2 -2
- package/core/{stacks.js → ops/stacks.js} +34 -15
- package/core/{wrap.js → ops/wrap.js} +8 -6
- package/core/{SaveStore.js → saves/SaveStore.js} +53 -27
- package/core/{Saves.js → saves/Saves.js} +171 -54
- package/core/saves/saveApply.js +312 -0
- package/core/{saveFiles.js → saves/saveFiles.js} +45 -38
- package/core/{saveVersions.js → saves/saveVersions.js} +24 -23
- package/core/saves/session.js +231 -0
- package/core/saves/stateReplace.js +184 -0
- package/core/{Rays.js → scene/Rays.js} +44 -30
- package/core/{Views.js → scene/Views.js} +16 -8
- package/core/{adaptive.js → scene/adaptive.js} +19 -9
- package/core/{canvasBox.js → scene/canvasBox.js} +4 -3
- package/core/scene/compositeGround.js +72 -0
- package/core/scene/floor.js +17 -0
- package/core/{gameLights.js → scene/gameLights.js} +17 -7
- package/core/{grayMap.js → scene/grayMap.js} +8 -2
- package/core/{grid.js → scene/grid.js} +6 -4
- package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
- package/core/scene/ground.contract.js +14 -0
- package/core/scene/ground.js +139 -0
- package/core/{movement.js → scene/movement.js} +3 -3
- package/core/{pictureSlots.js → scene/pictureSlots.js} +2 -2
- package/core/scene/pixel.js +154 -0
- package/core/scene/pixelRatio.js +167 -0
- package/core/{sceneDelta.js → scene/sceneDelta.js} +5 -5
- package/core/{sceneMethods.js → scene/sceneMethods.js} +43 -15
- package/core/scene/stepPoses.js +60 -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} +25 -16
- package/core/{things.js → scene/things.js} +18 -5
- package/core/{threePatches.js → scene/threePatches.js} +1 -1
- package/core/{tier.js → scene/tier.js} +10 -0
- package/core/scene/view.js +161 -0
- package/core/{Batching.js → stream/Batching.js} +85 -28
- package/core/{Stream.js → stream/Stream.js} +80 -38
- package/core/{batchGroups.js → stream/batchGroups.js} +11 -9
- package/core/{chunkStream.js → stream/chunkStream.js} +40 -0
- package/core/{scatter.js → stream/scatter.js} +7 -4
- package/core/{streamSources.js → stream/streamSources.js} +14 -8
- package/core/{Commits.js → threads/Commits.js} +17 -11
- package/core/{Jobs.js → threads/Jobs.js} +25 -13
- package/core/{Threads.js → threads/Threads.js} +21 -18
- 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} +20 -11
- package/core/{dayTime.js → time/dayTime.js} +5 -1
- package/core/{skip.js → time/skip.js} +28 -21
- package/core/{time.js → time/time.js} +32 -20
- package/core/{uiClock.js → time/uiClock.js} +4 -4
- package/docs/AI.md +92 -72
- package/docs/API.md +33 -28
- package/docs/CODEMAP.md +121 -200
- package/docs/COMMANDS.md +77 -70
- package/docs/CONVENTIONS.md +167 -24
- package/docs/MIGRATING-0.8.md +171 -0
- package/docs/MIGRATING-1.0.md +101 -0
- package/docs/THREE.md +140 -38
- package/docs/api/assets.md +12 -13
- package/docs/api/audio.md +6 -5
- package/docs/api/budget.md +4 -4
- package/docs/api/calendar.md +10 -11
- package/docs/api/cameraRig.md +32 -29
- package/docs/api/characters.md +35 -24
- package/docs/api/clock.md +1 -1
- package/docs/api/collider3d.md +9 -0
- package/docs/api/collision.md +12 -9
- package/docs/api/content.md +18 -17
- package/docs/api/dialogue.md +5 -4
- package/docs/api/engine.md +58 -54
- package/docs/api/events.md +17 -6
- package/docs/api/flow.md +1 -1
- package/docs/api/grids.md +1 -1
- package/docs/api/ground.md +6 -7
- package/docs/api/hud.md +2 -2
- package/docs/api/i18n.md +6 -6
- package/docs/api/input.md +9 -8
- package/docs/api/interactions.md +5 -5
- package/docs/api/inventory.md +10 -10
- package/docs/api/jobs.md +5 -5
- package/docs/api/level.md +10 -9
- package/docs/api/lightPool.md +1 -6
- package/docs/api/music.md +3 -3
- package/docs/api/nav.md +14 -12
- package/docs/api/openWorld.md +1 -1
- package/docs/api/particles.md +10 -7
- package/docs/api/photo.md +4 -2
- package/docs/api/pickups.md +3 -3
- package/docs/api/post.md +21 -5
- package/docs/api/quests.md +7 -5
- package/docs/api/rays.md +7 -7
- package/docs/api/rigid.md +29 -19
- package/docs/api/saves.md +13 -11
- package/docs/api/settings.md +9 -8
- package/docs/api/sky.md +8 -7
- package/docs/api/stream.md +8 -9
- package/docs/api/swarm.md +34 -0
- package/docs/api/terrain.md +6 -8
- package/docs/api/terrainDraw.md +2 -2
- package/docs/api/timeline.md +4 -4
- package/docs/api/tools.md +27 -22
- package/docs/api/triggers.md +2 -0
- package/docs/api/vars.md +1 -1
- package/docs/api/vegetation.md +4 -3
- package/docs/api/vegetationDraw.md +2 -2
- package/docs/api/water.md +7 -3
- package/docs/api/weather.md +27 -12
- package/docs/api/weatherDraw.md +4 -4
- package/docs/api/world.md +6 -6
- package/docs/recipes/01-new-game.md +28 -43
- package/docs/recipes/02-npc.md +21 -23
- package/docs/recipes/03-items-pickups.md +37 -53
- package/docs/recipes/04-quests.md +5 -4
- package/docs/recipes/05-props-bake.md +34 -44
- package/docs/recipes/06-clock-events.md +31 -22
- package/docs/recipes/07-flow-scenes-pause.md +30 -32
- package/docs/recipes/08-weather-sky.md +91 -37
- package/docs/recipes/09-materials-lights-models.md +25 -39
- package/docs/recipes/10-blender-level.md +22 -11
- package/docs/recipes/11-vehicles.md +44 -24
- package/docs/recipes/12-navmesh.md +60 -15
- package/docs/recipes/13-animation.md +70 -22
- package/docs/recipes/14-custom-module.md +33 -20
- package/docs/recipes/15-perf.md +51 -28
- package/docs/recipes/16-dev-bridge.md +39 -58
- package/docs/recipes/18-world.md +49 -28
- package/docs/recipes/19-shooting-picking.md +7 -4
- package/docs/recipes/20-content-actions-save.md +55 -40
- package/docs/recipes/21-camera.md +47 -25
- package/docs/recipes/22-shop-gold.md +21 -16
- package/docs/recipes/23-ops.md +28 -24
- package/docs/recipes/26-ui-parts.md +25 -14
- package/docs/recipes/27-net.md +3 -5
- package/docs/recipes/28-terrain.md +119 -23
- package/docs/recipes/29-grid.md +3 -3
- package/docs/recipes/30-templates.md +63 -30
- package/docs/recipes/31-audio.md +7 -7
- package/docs/recipes/32-action-game.md +21 -11
- package/docs/recipes/33-stream-sources.md +6 -3
- package/docs/recipes/34-environment-lighting.md +72 -25
- package/docs/recipes/35-picture-from-reference.md +20 -23
- package/docs/recipes/36-ground-plants.md +106 -0
- package/docs/recipes/40-scene.md +18 -21
- package/docs/recipes/43-shader-patches-surfaces.md +27 -48
- package/docs/recipes/44-water-weather-hooks.md +56 -50
- package/docs/recipes/45-cascaded-shadows.md +41 -20
- package/docs/recipes/46-blender-art-route.md +9 -10
- package/docs/recipes/49-game-module-contract.md +7 -6
- package/docs/recipes/50-own-renderer.md +3 -2
- package/docs/recipes/51-capability-catalog.md +14 -8
- package/docs/recipes/52-around-the-picture.md +56 -100
- package/docs/recipes/53-ground-up-close.md +61 -24
- package/docs/recipes/55-mods-time-wrap.md +17 -20
- package/docs/recipes/56-webgpu-tsl.md +28 -15
- package/docs/recipes/57-control.md +39 -12
- package/docs/recipes/58-input.md +15 -2
- package/docs/recipes/59-depth-post-effects.md +1 -1
- package/docs/recipes/60-judge-the-picture.md +30 -25
- package/docs/recipes/62-picture-code.md +129 -39
- package/docs/recipes/63-third-person-start.md +19 -5
- package/docs/recipes/64-particles.md +54 -5
- package/docs/recipes/65-swarm.md +140 -0
- package/docs/recipes/66-common-tasks.md +313 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +5 -5
- package/examples/perf-island/.threedog/content-index.json +1 -0
- package/examples/{sheepisland → perf-island}/GAMEMAP.md +15 -14
- package/examples/{sheepisland → perf-island}/assets.js +1 -1
- package/examples/{sheepisland → perf-island}/main.js +8 -8
- package/examples/{sheepisland → perf-island}/models.js +1 -1
- package/examples/{sheepisland → perf-island}/params.js +1 -1
- package/examples/{sheepisland → perf-island}/picture/index.js +1 -1
- package/examples/{sheepisland → perf-island}/picture/palette.js +2 -2
- package/examples/{sheepisland → perf-island}/views.js +1 -1
- package/examples/plain-picture/GAMEMAP.md +4 -1
- package/examples/rc2d/GAMEMAP.md +4 -3
- package/examples/rc2d/main.js +1 -3
- package/examples/rc2d/rc2d.js +1 -1
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +6 -5
- package/examples/techniques/contact-shadows/contactShadows.js +1 -1
- package/examples/techniques/contact-shadows/main.js +1 -1
- package/examples/techniques/interior-light/main.js +1 -1
- package/examples/techniques/modular-building/README.md +7 -6
- package/examples/techniques/outlines-and-rim/picture/post.js +1 -1
- package/examples/techniques/procedural-animation/README.md +1 -1
- package/examples/webgpu-tsl/GAMEMAP.md +2 -1
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +9 -7
- package/examples/world/main.js +3 -3
- package/examples/world/picture/sky.js +1 -1
- package/index.d.ts +16 -12
- package/index.js +53 -32
- package/llms.txt +11 -14
- package/modules/ambience/Ambience.js +16 -11
- package/modules/calendar/Calendar.js +19 -19
- package/modules/calendar/index.js +18 -16
- package/modules/calendar/schedule.js +11 -6
- package/modules/calendar/seasons.js +7 -7
- package/modules/camera/FirstPersonCamera.js +5 -5
- package/modules/camera/FixedCamera.js +43 -30
- package/modules/camera/FollowCamera.js +24 -15
- package/modules/camera/RtsCamera.js +12 -11
- package/modules/camera/common.js +72 -37
- package/modules/camera/contract.js +1 -0
- package/modules/camera/pixelSnap.js +62 -0
- package/modules/characters/Character.js +166 -70
- package/modules/characters/NPC.js +84 -44
- package/modules/characters/assetModel.js +16 -12
- package/modules/characters/astar.js +48 -27
- package/modules/characters/behaviors.js +4 -5
- package/modules/characters/character.contract.js +21 -0
- package/modules/characters/contract.js +17 -3
- package/modules/characters/index.js +240 -226
- package/modules/characters/moveHelpers.js +88 -12
- package/modules/characters/mover.contract.js +14 -0
- package/modules/characters/movers/common.js +22 -18
- package/modules/characters/movers/manual.js +1 -1
- package/modules/characters/movers/rapier.js +18 -10
- package/modules/characters/movers/simple.js +26 -13
- package/modules/characters/movers/support.js +24 -13
- package/modules/characters/npcAvoid.js +19 -16
- package/modules/characters/npcSim.js +88 -32
- package/modules/characters/npcView.js +19 -11
- package/modules/characters/pathAsync.js +81 -29
- package/modules/characters/pathJob.js +38 -21
- package/modules/characters/pathWorker.js +1 -1
- package/modules/characters/player.js +120 -0
- package/modules/characters/playerStrings.js +2 -2
- package/modules/characters/proceduralRig.js +2 -2
- package/modules/characters/seat.js +56 -0
- package/modules/characters/useModel.js +3 -3
- package/modules/characters/vehicle.contract.js +8 -5
- package/modules/characters/walkTo.js +40 -33
- package/modules/collision/Collision.js +69 -45
- package/modules/collision/contract.js +15 -0
- package/modules/collision/grid.js +6 -1
- package/modules/content/explain.js +2 -3
- package/modules/content/fields.js +24 -3
- package/modules/content/ids.js +5 -3
- package/modules/content/index.js +132 -114
- package/modules/content/loader.js +117 -140
- package/modules/content/markers.js +25 -0
- package/modules/content/models.js +54 -17
- package/modules/content/packs.js +5 -4
- package/modules/content/parts.js +2 -2
- package/modules/content/places.js +36 -0
- package/modules/content/props.js +22 -17
- package/modules/content/rules.js +47 -61
- package/modules/content/stages.js +7 -7
- package/modules/content/templates.js +80 -49
- package/modules/content/words.js +47 -0
- package/modules/debug/DebugPanel.js +14 -45
- package/modules/flow/contract.js +2 -1
- package/modules/flow/index.js +30 -16
- package/modules/gameplay/Container.js +17 -13
- package/modules/gameplay/Containers.js +23 -6
- package/modules/gameplay/Dialogue.js +93 -34
- package/modules/gameplay/Interactions.js +93 -51
- package/modules/gameplay/Inventory.js +64 -22
- package/modules/gameplay/Quests.js +146 -30
- package/modules/gameplay/boxOps.js +8 -1
- package/modules/gameplay/dialogueBubbles.js +16 -12
- package/modules/gameplay/inventoryOps.js +11 -8
- package/modules/gameplay/pickups.js +63 -37
- package/modules/gameplay/questLog.js +4 -2
- package/modules/gameplay/questSave.js +9 -4
- package/modules/gameplay/quests.contract.js +1 -1
- package/modules/grid/Grid.js +2 -2
- package/modules/grid/Layer.js +12 -8
- package/modules/grid/index.js +28 -23
- package/modules/grid/ops.js +43 -46
- package/modules/grid/preview.js +7 -7
- package/modules/grid/tiles.js +6 -6
- package/modules/hlod/index.js +42 -57
- package/modules/hud/index.js +22 -14
- package/modules/hud/parts.js +8 -8
- package/modules/level/contract.js +16 -0
- package/modules/level/heightfield.js +29 -31
- package/modules/level/index.js +113 -161
- package/modules/level/load.js +196 -0
- package/modules/level/meshes.js +65 -0
- package/modules/level/nodes.js +40 -23
- package/modules/lights/index.js +33 -183
- package/modules/lights/slots.js +93 -0
- package/modules/lights/sources.js +90 -0
- package/modules/music/Music.js +34 -28
- package/modules/music/rules.js +1 -1
- package/modules/nav/contract.js +16 -0
- package/modules/nav/index.js +180 -49
- package/modules/nav/navPath.js +45 -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 +6 -5
- package/modules/net/sync.js +2 -2
- package/modules/net/transports.js +2 -2
- package/modules/particles/Particles.js +95 -29
- package/modules/particles/effect.js +86 -32
- package/modules/particles/shaders.js +19 -1
- package/modules/photo/Photo.js +23 -23
- package/modules/rigid/RigidBodies.js +255 -89
- package/modules/rigid/Vehicles.js +17 -8
- package/modules/rigid/collider3d.contract.js +26 -0
- package/modules/rigid/ragdoll.js +298 -0
- package/modules/rigid/ragdollBones.js +209 -0
- package/modules/rigid/refresh.js +10 -0
- package/modules/rigid/sync.js +51 -20
- package/modules/settings/Settings.js +177 -61
- package/modules/settings/apply.js +20 -13
- package/modules/settings/sections.js +19 -14
- package/modules/settings/strings.js +2 -2
- package/modules/settings/view.js +3 -3
- package/modules/sky/Sky.js +29 -22
- package/modules/sky/clouds.js +7 -7
- package/modules/sky/dome.js +33 -20
- package/modules/sky/domeLayers.js +9 -9
- package/modules/sky/environment.js +6 -6
- package/modules/sky/frame.js +19 -10
- package/modules/sky/season.js +7 -1
- package/modules/sky/shader.js +24 -25
- package/modules/sky/skyModule.js +17 -28
- package/modules/sky/tint.js +1 -1
- package/modules/swarm/Swarm.js +356 -0
- package/modules/swarm/draw.js +68 -0
- package/modules/swarm/grid.js +63 -0
- package/modules/terrain/ChunkManager.js +71 -59
- package/modules/terrain/chunkQueries.js +7 -24
- package/modules/terrain/chunkWorker.js +1 -1
- package/modules/terrain/draw.js +14 -11
- package/modules/terrain/index.js +42 -42
- package/modules/terrain/terrainColorMap.js +6 -3
- package/modules/terrain/terrainDefaults.js +2 -1
- package/modules/terrain/terrainEdit.js +45 -29
- package/modules/terrain/terrainGen.js +19 -12
- 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 +83 -43
- package/modules/timeline/Tween.js +25 -19
- package/modules/timeline/shots.js +24 -17
- package/modules/triggers/index.js +95 -28
- package/modules/vegetation/Vegetation.js +34 -26
- package/modules/vegetation/densityMap.js +4 -7
- package/modules/vegetation/draw.js +39 -18
- package/modules/vegetation/groundChunks.js +21 -38
- package/modules/vegetation/index.js +37 -12
- package/modules/vegetation/modelGeometry.js +3 -6
- package/modules/vegetation/nearFade.js +1 -1
- package/modules/water/Water.js +20 -16
- package/modules/water/surface.js +3 -3
- package/modules/weather/Weather.js +52 -40
- package/modules/weather/particles.js +8 -8
- package/modules/weather/weatherDraw.js +28 -23
- package/modules/world/World.js +28 -15
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +30 -17
- package/modules/world/persist.js +90 -27
- package/modules/world/pos.js +5 -5
- package/modules/world/records.js +37 -11
- package/modules/world/sim.js +78 -27
- package/modules/world/simFar.js +2 -2
- package/modules/world/state.js +43 -11
- package/modules/world/thingSource.js +20 -5
- package/modules/world/views.js +27 -14
- package/package.json +48 -7
- package/presets.js +1 -3
- package/render/PostFX.js +83 -53
- package/render/backend.js +31 -33
- package/render/cascades.js +17 -12
- package/render/cascades.tsl.js +5 -8
- package/render/daylight.js +20 -3
- package/render/detail.js +8 -7
- package/render/effects.js +28 -25
- package/render/fuse.js +3 -3
- package/render/fx/cloudShadow.tsl.js +3 -3
- package/render/fx/detail.tsl.js +1 -1
- package/render/fx/index.js +5 -10
- 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/particles.tsl.js +8 -6
- package/render/fx/patchNodes.tsl.js +5 -15
- package/render/fx/postWebGPU.tsl.js +30 -26
- package/render/fx/sky.tsl.js +15 -17
- package/render/fx/uniforms.tsl.js +4 -4
- package/render/fx/wind.tsl.js +1 -1
- package/render/fxNumbers.js +3 -0
- package/render/layers.js +2 -2
- package/render/lighting.js +5 -3
- package/render/lightmap.js +41 -21
- package/render/lights.js +6 -6
- package/render/lit.js +24 -0
- package/render/materials.js +8 -7
- package/render/mergeCommon.js +22 -0
- package/render/modeling.js +2 -2
- package/render/occlusion.js +62 -15
- package/render/ownFrame.js +4 -4
- package/render/patches.js +15 -15
- package/render/postWebGL.js +15 -12
- package/render/probes.js +41 -19
- 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/{core → render}/shadows.js +59 -13
- package/render/slots.js +7 -7
- package/render/terms.js +22 -24
- package/render/uniformDecl.js +1 -1
- package/types/core.d.ts +336 -202
- package/types/gameplay.d.ts +254 -130
- package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +22 -7
- 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} +8 -16
- package/types/generated/core/{Random.d.ts → base/Random.d.ts} +4 -3
- package/types/generated/core/{page.d.ts → engine/page.d.ts} +8 -9
- package/types/generated/core/{Input.d.ts → input/Input.d.ts} +28 -10
- package/types/generated/core/input/inputSeat.d.ts +26 -0
- package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
- package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +17 -3
- package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +6 -4
- package/types/generated/core/{control.d.ts → ops/control.d.ts} +14 -10
- package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +62 -18
- package/types/generated/core/{session.d.ts → saves/session.d.ts} +3 -2
- package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
- package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +2 -2
- package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
- package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +22 -18
- 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/Grid.d.ts +1 -0
- package/types/generated/modules/grid/Layer.d.ts +1 -1
- package/types/generated/modules/grid/index.d.ts +3 -3
- package/types/generated/modules/music/Music.d.ts +7 -5
- package/types/generated/modules/particles/Particles.d.ts +5 -4
- package/types/generated/modules/sky/Sky.d.ts +21 -10
- package/types/generated/modules/swarm/Swarm.d.ts +80 -0
- package/types/generated/modules/timeline/Timeline.d.ts +7 -5
- package/types/generated/modules/water/Water.d.ts +1 -0
- package/types/generated/modules/weather/Weather.d.ts +14 -16
- package/types/generated/modules/weather/weatherDraw.d.ts +3 -3
- package/types/generated/modules/world/World.d.ts +11 -7
- package/types/generated/render/PostFX.d.ts +21 -23
- package/types/generated/render/materials.d.ts +1 -0
- package/types/generated/render/occlusion.d.ts +9 -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 +47 -15
- package/types/physics.d.ts +150 -73
- package/types/pixel.d.ts +75 -0
- package/types/tsl.d.ts +37 -4
- package/types/world.d.ts +48 -75
- package/ui/Focus.js +10 -9
- package/ui/Parts.js +13 -5
- package/ui/UI.js +7 -7
- package/ui/defaults.js +3 -2
- package/ui/theme.js +7 -5
- package/core/assetEntry.js +0 -109
- package/core/engineCamera.js +0 -32
- package/core/ground.js +0 -104
- package/core/holds.js +0 -134
- package/core/math.js +0 -48
- package/core/moduleSlots.js +0 -100
- package/core/modules.js +0 -314
- package/core/saveApply.js +0 -210
- package/core/saveValues.js +0 -46
- package/core/session.js +0 -174
- package/core/shadowTypes.js +0 -16
- package/core/util.js +0 -17
- package/core/view.js +0 -43
- package/docs/MIGRATING-0.3.md +0 -248
- package/docs/MIGRATING-0.4.md +0 -320
- package/docs/MIGRATING-0.5.md +0 -68
- package/docs/MIGRATING-0.6.md +0 -126
- package/docs/PERF.md +0 -245
- package/docs/recipes/36-sky-ground-plants.md +0 -158
- package/docs/recipes/37-terrain-hooks.md +0 -115
- package/docs/recipes/38-environment-hooks.md +0 -67
- package/docs/recipes/42-terrain-shape.md +0 -64
- package/docs/recipes/47-island-snow-backdrop.md +0 -43
- package/docs/recipes/54-three-idioms.md +0 -88
- package/examples/plain-picture/FINDINGS.md +0 -53
- package/examples/sheepisland/.threedog/content-index.json +0 -1
- package/modules/camera/projection.js +0 -21
- /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/{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/examples/{sheepisland → perf-island}/content/templates.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/vegetation.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/lights.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/materials.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/sky.js +0 -0
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
// Weather particle systems (recipes/44). Built-in rain and snow are two specs of one falling-particle system; a game draws a field of its
|
|
2
|
-
// own table (ash, petals, sparks) with engine.weather.
|
|
2
|
+
// own table (ash, petals, sparks) with engine.weather.defineField(field, spec), and the same call replaces rain or snow. The amount each frame is
|
|
3
3
|
// weather.current[field], so the table's smooth blending drives particles too.
|
|
4
4
|
//
|
|
5
|
-
// spec (weather({ rain, snow }), or
|
|
5
|
+
// spec (weather({ rain, snow }), or defineField): shape 'line' (streaks that slant with the wind) | 'round' | 'soft' | 'square' (point sprites
|
|
6
6
|
// that drift), texture (asset name, sprites only), color, opacity, size / maxSize (sprite size and pixel cap), length (line meters),
|
|
7
7
|
// speed (fall m/s), slant (line lean per unit of wind), sway (sprite drift meters), count, density (amount 0..1 -> share of particles drawn),
|
|
8
8
|
// glsl: { vertex, fragment } (whole shader text; copy from shaders.js), uniforms (for your glsl);
|
|
9
9
|
// or create(engine, { area, count }) => { object, update?(amount, ctx) } for a system of your own (the engine adds it, shows it while the
|
|
10
10
|
// amount is above 0.02 and calls update every frame with ctx = { camera, time, wind }).
|
|
11
|
-
import { engineOwned } from '../../core/things.js';
|
|
11
|
+
import { engineOwned } from '../../core/scene/things.js';
|
|
12
12
|
import * as THREE from 'three';
|
|
13
|
-
import { closest } from '../../core/validate.js';
|
|
14
|
-
import { readParams, keysSchema } from '../../core/params.js';
|
|
13
|
+
import { closest, needMaterial } from '../../core/base/validate.js';
|
|
14
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
15
15
|
import { declareUniforms } from '../../render/uniformDecl.js';
|
|
16
16
|
import { lineVert, lineFrag, pointVert, pointFrag, SHAPES, shaderMat, scatter } from './shaders.js';
|
|
17
|
-
import { codedError } from '../../core/errorHints.js';
|
|
17
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
18
18
|
import { isWebGPU, webgpuPart } from '../../render/backend.js';
|
|
19
19
|
|
|
20
20
|
const SPEC_KEYS = ['shape', 'texture', 'color', 'opacity', 'size', 'maxSize', 'length', 'speed', 'slant', 'sway', 'count', 'density', 'glsl', 'uniforms', 'create'];
|
|
@@ -36,7 +36,7 @@ export function makeSystem(engine, field, spec, { area, count, base = DRIFT }) {
|
|
|
36
36
|
const where = `weather particles '${field}'`;
|
|
37
37
|
readParams(where, keysSchema(SPEC_KEYS), spec);
|
|
38
38
|
const s = { ...base, ...spec, shape: spec.shape ?? (spec.texture ? 'round' : base.shape) };
|
|
39
|
-
const n = Math.max(1, Math.round(spec.count
|
|
39
|
+
const n = Math.max(1, Math.round(spec.count || count));
|
|
40
40
|
if (s.create) {
|
|
41
41
|
const own = s.create(engine, { area, count: n });
|
|
42
42
|
if (!own?.object?.isObject3D) throw codedError('weather-option', `${where}: create must return { object: THREE.Object3D, update?(amount, { camera, time, wind }) }`);
|
|
@@ -83,7 +83,7 @@ function finish(engine, field, sys) {
|
|
|
83
83
|
sys.engineMaterial = mine;
|
|
84
84
|
Object.defineProperty(sys, 'material', { enumerable: true, get: () => o.material ?? null, set(m) {
|
|
85
85
|
if (sys.own) throw codedError('weather-option', `weather particles '${field}': this object came from create(), so its material is yours: write it on the object`);
|
|
86
|
-
if (m != null
|
|
86
|
+
if (m != null) needMaterial('weather-option', `weather particles '${field}': material`, m, " (null gives the engine's back)");
|
|
87
87
|
sys.given = m || null;
|
|
88
88
|
o.material = m ?? mine;
|
|
89
89
|
} });
|
|
@@ -3,39 +3,39 @@
|
|
|
3
3
|
// weather table, its save and its events.
|
|
4
4
|
// shared points: sky tint, lightning flash, snow cover
|
|
5
5
|
// rain / snow particles that follow the camera (particles.js), thunder, audio rule conditions
|
|
6
|
-
import { builtInSounds } from '../../core/assetManifest.js';
|
|
7
|
-
import { readParams, keysSchema
|
|
8
|
-
import {
|
|
6
|
+
import { builtInSounds } from '../../core/assets/assetManifest.js';
|
|
7
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
8
|
+
import { isOptions } from '../../core/base/util.js';
|
|
9
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
9
10
|
import { onRendererSwap } from '../../render/backend.js';
|
|
10
11
|
import { makeSystem, updateSystem, dropSystem, RAIN, SNOW } from './particles.js';
|
|
11
12
|
|
|
12
13
|
const DRAW_PARAMS = keysSchema(['particles', 'area', 'rain', 'snow']); // the picture options of weather(): the rest are the state's
|
|
13
14
|
const BASE = { rain: RAIN, snow: SNOW };
|
|
14
15
|
|
|
15
|
-
/** engine.weatherDraw: particles and picture effects of the current weather */
|
|
16
|
+
/** engine.weatherDraw: particles and picture effects of the current weather @experimental */
|
|
16
17
|
export class WeatherDraw {
|
|
17
18
|
/**
|
|
18
19
|
* @internal
|
|
19
20
|
* @param {any} engine
|
|
20
21
|
* @param {{ particles?: number, area?: number, rain?: any, snow?: any }} [opts]
|
|
21
22
|
*/
|
|
22
|
-
constructor(engine, { particles
|
|
23
|
+
constructor(engine, { particles, area = 40, rain = {}, snow = {} } = {}) {
|
|
23
24
|
/** @internal */ this.engine = engine;
|
|
24
|
-
/** @internal the state half: read only */ this.state = engine.weather;
|
|
25
25
|
/** Sky flash now, 1 at a strike (the weather:lightning event) fading to 0 @type {number} */
|
|
26
26
|
this.flash = 0;
|
|
27
27
|
// the weather's entries on the shared sky points: taken once through ctx.mod (owned by this module, gone with it) and rewritten every frame with
|
|
28
|
-
// handle.change (core/sharedPoint.js), so a frame adds no entry and no cleanup handle. ctx is set by the module's install
|
|
28
|
+
// handle.change (core/ops/sharedPoint.js), so a frame adds no entry and no cleanup handle. ctx is set by the module's install
|
|
29
29
|
/** @internal */ this._ctx = null; /** @internal */ this._h = {};
|
|
30
|
-
/** @internal */ this._tint = { color:
|
|
31
|
-
/** Default particle count per system (
|
|
32
|
-
this.particles = engine.tier === 'low' ?
|
|
30
|
+
/** @internal */ this._tint = { color: null, amount: 0, horizon: 0 };
|
|
31
|
+
/** Default particle count per system: weather({ particles }), else 6000 (3000 on low-tier devices) @type {number} */
|
|
32
|
+
this.particles = particles ?? (engine.tier === 'low' ? 3000 : 6000);
|
|
33
33
|
/** @internal */ this.area = area;
|
|
34
|
-
/** Particle systems drawn now: field -> { field, object, material, uniforms, spec } (rain / snow when the table has them, plus fields engine.weather.
|
|
34
|
+
/** Particle systems drawn now: field -> { field, object, material, uniforms, spec } (rain / snow when the table has them, plus fields engine.weather.defineField adds) @type {Map<string, any>} */
|
|
35
35
|
this.systems = new Map();
|
|
36
36
|
// zero cost when unused: a table where nothing ever rains or snows builds no particle meshes
|
|
37
37
|
const { cover, ...snowGiven } = snow;
|
|
38
|
-
/** @internal what weather({ rain, snow }) gave:
|
|
38
|
+
/** @internal what weather({ rain, snow }) gave: defineField(field, null) goes back to it */ this._given = { rain, snow: snowGiven };
|
|
39
39
|
for (const k of Object.keys(BASE)) if (this._used(k)) this._build(k, this._given[k], BASE[k]);
|
|
40
40
|
// snow cover: foliage / ground season tint moves toward the snow colors as current.snow rises (ground.cover)
|
|
41
41
|
if (cover !== undefined) {
|
|
@@ -48,14 +48,16 @@ export class WeatherDraw {
|
|
|
48
48
|
|
|
49
49
|
/** @internal the weather table (state half) */
|
|
50
50
|
get types() { return this.state.types; }
|
|
51
|
+
/** @internal the state half, read only and read live: a replaced weather module must not leave the picture on the old one */
|
|
52
|
+
get state() { return this.engine.weather; }
|
|
51
53
|
/** @internal does any type have this field above 0 */
|
|
52
54
|
_used(field) { return Object.values(this.types).some(v => v[field] > 0); }
|
|
53
55
|
|
|
54
|
-
/** @internal engine.weather.
|
|
55
|
-
|
|
56
|
+
/** @internal engine.weather.defineField */
|
|
57
|
+
defineField(field, spec) {
|
|
56
58
|
const fields = [...new Set(Object.values(this.types).flatMap(t => Object.keys(t)))];
|
|
57
|
-
if (!fields.includes(field)) throw codedError('weather-option', `weather.
|
|
58
|
-
if (spec !== null && (typeof spec !== 'object' || Array.isArray(spec))) throw codedError('weather-option', `weather.
|
|
59
|
+
if (!fields.includes(field)) throw codedError('weather-option', `weather.defineField('${field}'): no weather type has this field; add it to a type in weather({ types }) (e.g. ashfall: { ${field}: 1 }), or use one of ${fields.join(', ')}`);
|
|
60
|
+
if (spec !== null && (typeof spec !== 'object' || Array.isArray(spec))) throw codedError('weather-option', `weather.defineField('${field}', spec): spec is an object, e.g. { shape: 'soft', color: 0x555555 } or { create }, or null to give the field back; see recipes/44-water-weather-hooks.md`);
|
|
59
61
|
if (spec) return this._build(field, spec, BASE[field]);
|
|
60
62
|
if (BASE[field] && this._used(field)) return this._build(field, this._given[field], BASE[field]);
|
|
61
63
|
const s = this.systems.get(field);
|
|
@@ -65,9 +67,9 @@ export class WeatherDraw {
|
|
|
65
67
|
|
|
66
68
|
/** @internal */
|
|
67
69
|
_build(field, spec, base) {
|
|
70
|
+
const sys = makeSystem(this.engine, field, spec, { area: this.area, count: this.particles, base }); // first: a bad spec throws with the old system still drawn
|
|
68
71
|
const old = this.systems.get(field);
|
|
69
72
|
if (old) dropSystem(this.engine, old);
|
|
70
|
-
const sys = makeSystem(this.engine, field, spec, { area: this.area, count: this.particles, base });
|
|
71
73
|
sys.base = base; // the renderer swap builds it again over the same defaults
|
|
72
74
|
this.systems.set(field, sys);
|
|
73
75
|
return sys;
|
|
@@ -75,7 +77,7 @@ export class WeatherDraw {
|
|
|
75
77
|
|
|
76
78
|
/**
|
|
77
79
|
* @internal fallback 'webgl': systems built before start() carry WebGPURenderer node materials; rebuild them for the renderer in use, keeping what
|
|
78
|
-
* the game wrote since (spec numbers, uniforms, its material). A
|
|
80
|
+
* the game wrote since (spec numbers, uniforms, its material). A defineField() create(engine) object is the game's own and stays (the scene check names it
|
|
79
81
|
* if WebGL cannot draw it).
|
|
80
82
|
*/
|
|
81
83
|
_rendererSwapped() {
|
|
@@ -97,17 +99,20 @@ export class WeatherDraw {
|
|
|
97
99
|
*/
|
|
98
100
|
apply(camera, dt = 0) {
|
|
99
101
|
const c = this.state.current, e = this.engine, T = this._tint;
|
|
102
|
+
T.color = this.state.overcastColor;
|
|
100
103
|
const t = e.time.now('real');
|
|
101
104
|
this.flash = Math.max(0, this.flash - dt * 3);
|
|
102
105
|
T.amount = c.grey; T.horizon = c.grey * 0.8; this._put('sky.tint', 'value', T);
|
|
103
106
|
this._put('sky.flash', 'add', this.flash > 0 ? this.state.lightning(this.flash, e) * this.state.lightningBrightness : 0);
|
|
104
|
-
if (this._cover) { this._coverMod.amount = (c.snow ?? 0) * this._cover.strength; this._put('ground.cover', 'value', this._coverMod); }
|
|
107
|
+
if (this._cover) { this._coverMod.amount = (c.snow ?? 0) * this._cover.strength; this._put('ground.cover', 'value', this._coverMod); }
|
|
105
108
|
for (const sys of this.systems.values()) updateSystem(sys, c[sys.field] ?? 0, camera, t, c.wind);
|
|
106
109
|
}
|
|
107
110
|
/** @internal one contribution to a shared point: taken on first use, then changed in place */
|
|
108
111
|
_put(point, op, v) {
|
|
109
112
|
// change() is false when the entry is gone (a point cleared on a new session): take it again, as the old per-frame take did anyway
|
|
110
113
|
if (this._h[point]?.change(v)) return;
|
|
114
|
+
// no sky module: the point does not exist and nothing reads it; a game's own sky reads weather.current.grey and weatherDraw.flash, or defines the point itself
|
|
115
|
+
if (!this.engine.stacks.has(point)) return;
|
|
111
116
|
const o = op === 'value' ? { value: v } : { [op]: v, layer: 'effect' }; // tint / cover are data points (value), the flash an effect-layer number
|
|
112
117
|
this._h[point] = this._ctx ? this._ctx.mod(point, o) : this.engine.mod(point, { ...o, owner: 'weatherDraw' });
|
|
113
118
|
}
|
|
@@ -121,14 +126,13 @@ export function weatherDrawModule(opts) {
|
|
|
121
126
|
readParams('weather (drawing half)', DRAW_PARAMS, opts);
|
|
122
127
|
let L = null;
|
|
123
128
|
return {
|
|
124
|
-
name: 'weatherDraw', type: 'picture', provides: ['weatherDraw'], label: 'Weather drawing', params: DRAW_PARAMS, options: opts, requires: ['weather', 'sky'], stage: 'environment', before: ['sky'], after: ['weather'],
|
|
129
|
+
name: 'weatherDraw', skipKind: 'none', type: 'picture', provides: ['weatherDraw'], label: 'Weather drawing', params: DRAW_PARAMS, options: opts, requires: ['weather'], optional: ['sky'], stage: 'environment', before: ['sky'], after: ['weather'],
|
|
125
130
|
install(e, ctx) { e.i18n.add({ 'zh-CN': { 'module.weatherDraw': '天气外观' }, en: { 'module.weatherDraw': 'weather drawing' } });
|
|
126
131
|
L = new WeatherDraw(e, opts);
|
|
127
132
|
L._ctx = ctx; // the weather's entries on the shared points go with this module (ctx.mod)
|
|
128
133
|
ctx.track(onRendererSwap(e, () => L._rendererSwapped()));
|
|
129
|
-
|
|
130
|
-
ctx.track(e.audio.
|
|
131
|
-
for (const k of ['rain', 'snow', 'wind']) ctx.track(e.audio.measure(k, () => w.current[k])); // data rules: { rain: { lt: 0.2 } }, volume add: { rain: 0.22 }
|
|
134
|
+
ctx.track(e.audio.condition('weather', v => [].concat(v).includes(e.weather.name))); // audio rule condition { weather: 'rain' | ['rain', 'storm'] }
|
|
135
|
+
for (const k of ['rain', 'snow', 'wind']) ctx.track(e.audio.measure(k, () => e.weather.current[k])); // data rules: { rain: { lt: 0.2 } }, volume add: { rain: 0.22 }
|
|
132
136
|
builtInSounds(e.assets, { thunder: (audio, p, out) => { const dur = p.duration ?? 3.5, delay = 0.4 + Math.random() * 1.5; // presentation: thunder delay
|
|
133
137
|
audio.noiseBurst({ type: 'lowpass', freq: p.freq ?? 140, vol: p.volume ?? 0.9, dur, rate: 0.4 * p.pitch, delay, out }); return delay + dur; } },
|
|
134
138
|
{ bus: 'ambience' }); // sound asset 'thunder', silent until audio.sounds names it
|
|
@@ -136,6 +140,7 @@ export function weatherDrawModule(opts) {
|
|
|
136
140
|
return L;
|
|
137
141
|
},
|
|
138
142
|
frame(dt, e) { L.apply(e.camera, dt); },
|
|
143
|
+
dispose(e) { for (const s of L.systems.values()) dropSystem(e, s); L.systems.clear(); },
|
|
139
144
|
describe: () => ({ rainVisible: !!L.systems.get('rain')?.object.visible, snowVisible: !!L.systems.get('snow')?.object.visible, flash: Math.round(L.flash * 100) / 100 }),
|
|
140
145
|
};
|
|
141
146
|
}
|
package/modules/world/World.js
CHANGED
|
@@ -6,14 +6,14 @@
|
|
|
6
6
|
// of persist.js.
|
|
7
7
|
// Data must be plain values (putting a three.js object or a function in it throws in dev); position is a plain { x, y, z }. Don't hold on to rec: loading a
|
|
8
8
|
// save swaps in new objects, so keep the id and use world.get(id).
|
|
9
|
-
import { DEV, fmt } from '../../core/validate.js';
|
|
10
|
-
import { checkTypeRule } from '../../core/moduleTypes.js';
|
|
9
|
+
import { DEV, fmt } from '../../core/base/validate.js';
|
|
10
|
+
import { checkTypeRule } from '../../core/engine/moduleTypes.js';
|
|
11
11
|
import { addRecord, setRecord, removeRecord, queryRecords } from './records.js';
|
|
12
12
|
import { Views } from './views.js';
|
|
13
13
|
import { Sim } from './sim.js';
|
|
14
14
|
import { initState, mixInternals } from './state.js';
|
|
15
15
|
import { putPos, centerOf } from './pos.js';
|
|
16
|
-
import { codedError } from '../../core/errorHints.js';
|
|
16
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
17
17
|
|
|
18
18
|
const STRINGS = {
|
|
19
19
|
anchor: 'world.anchor must be null, an Object3D, a Vector3 / { x, z } or [x, y, z]; got {got}',
|
|
@@ -29,7 +29,7 @@ export class World {
|
|
|
29
29
|
const { cellSize = 32, radius = 60, farEvery = 1, farMaxPerTick = 500, buildPerFrame = 8 } = opts;
|
|
30
30
|
/** @internal */ this.engine = engine;
|
|
31
31
|
initState(this, cellSize);
|
|
32
|
-
/** All records: id → record (read-only; use set to change fields, move to change position) @type {Map<string, WorldRecord>} */
|
|
32
|
+
/** All records: id → record (read-only; use set to change fields, move to change position) @type {Map<string, WorldRecord>} @experimental */
|
|
33
33
|
this.records = new Map();
|
|
34
34
|
/**
|
|
35
35
|
* Default distance (meters) for building models and counting as near; present / simulate can override it. Changing it at runtime affects those without
|
|
@@ -61,7 +61,10 @@ export class World {
|
|
|
61
61
|
set anchor(a) {
|
|
62
62
|
const ok = a == null || a.isObject3D || (Array.isArray(a) ? a.length === 3 && a.every(Number.isFinite) : Number.isFinite(a.x) && Number.isFinite(a.z));
|
|
63
63
|
if (!ok) throw codedError('world-option', fmt(STRINGS.anchor, { got: JSON.stringify(a) }));
|
|
64
|
+
const boot = this._anchor, S = this.engine.session;
|
|
64
65
|
this._anchor = a ?? null;
|
|
66
|
+
// not saved (it may be an Object3D): set during play, it ends with the playthrough and what boot left comes back. Tracked, so a failed load keeps it
|
|
67
|
+
if (S.captured && !this._anchorEnd) this._anchorEnd = S.track({ remove: () => { this._anchor = boot; this._anchorEnd = null; } });
|
|
65
68
|
}
|
|
66
69
|
|
|
67
70
|
/**
|
|
@@ -76,7 +79,7 @@ export class World {
|
|
|
76
79
|
* Add a record and return it (a plain object). kind is required; without id one is numbered automatically (kind#1, kind#2…, saved; `#` never appears in an
|
|
77
80
|
* authored id, so the two can never collide).
|
|
78
81
|
* opts.initial: initial record written in content (needs an id); saves only keep its changes and removal; if the id already exists the existing one is
|
|
79
|
-
* returned (content may load twice);
|
|
82
|
+
* returned (content may load twice), after taking a new position / rot from the content unless play moved it;
|
|
80
83
|
* returns null if the save removed it (it is not added back). opts.save: false: not saved (temporary things).
|
|
81
84
|
* @example engine.world.add({ id: 'shop_owner', kind: 'npc', position: [12, 0, -30], name: '店主', mood: 'calm' }, { initial: true })
|
|
82
85
|
* @param {{ kind: string, id?: string, position?: any, [field: string]: any }} def
|
|
@@ -99,6 +102,7 @@ export class World {
|
|
|
99
102
|
* @example const h = engine.pick(0, 0); const id = h && engine.world.idOf(h.object);
|
|
100
103
|
* @param {any} obj a THREE.Object3D (a mesh of the model is fine)
|
|
101
104
|
* @returns {string | null}
|
|
105
|
+
* @experimental
|
|
102
106
|
*/
|
|
103
107
|
idOf(obj) {
|
|
104
108
|
for (let o = obj; o; o = o.parent) { const id = this._v.byObj.get(o); if (id !== undefined) return id; }
|
|
@@ -121,7 +125,9 @@ export class World {
|
|
|
121
125
|
set(id, patch) { checkTypeRule(this.engine, 'world.write', `set world record ${id}`); return setRecord(this, id, patch); }
|
|
122
126
|
/**
|
|
123
127
|
* Move a record (no event; use it in simulate for things that move every step); still saved (saves diff against content).
|
|
124
|
-
* The model of a positionFrom 'record' (default) record follows this frame; to do something else with the position in presentation, compare in update
|
|
128
|
+
* The model of a positionFrom 'record' (default) record follows this frame; to do something else with the position in presentation, compare in update.
|
|
129
|
+
* On a live character (the player, an NPC with a model) this is its placeAt: the character owns its position, so it goes there and the record says where it stands.
|
|
130
|
+
* A seated rider gets out to go there (placeAt ends a ride); a write equal to where it sits only follows the seat
|
|
125
131
|
* @example engine.world.move(rec.id, { x: rec.position.x + 1, z: rec.position.z })
|
|
126
132
|
* @param {string} id
|
|
127
133
|
* @param {any} position Vector3 / object / [x, y, z] / { x, z } (y stays unchanged if omitted)
|
|
@@ -129,10 +135,18 @@ export class World {
|
|
|
129
135
|
*/
|
|
130
136
|
move(id, position) {
|
|
131
137
|
DEV && this.engine.ops.guard('world.move');
|
|
132
|
-
const rec = this._need(id, 'move');
|
|
133
|
-
putPos(`world.move("${id}")`, position,
|
|
138
|
+
const rec = this._need(id, 'move'), live = this._character(rec), to = live ? { ...live.root.position } : rec.position;
|
|
139
|
+
putPos(`world.move("${id}")`, position, to);
|
|
140
|
+
if (live) { // design.md section 9: the character is the authority. A write that agrees with it is the record following (Character._store, npcSim); any other is a placement
|
|
141
|
+
const p = live.root.position;
|
|
142
|
+
if (p.x !== to.x || p.y !== to.y || p.z !== to.z) live.placeRecord(to);
|
|
143
|
+
rec.position.x = p.x; rec.position.y = p.y; rec.position.z = p.z;
|
|
144
|
+
}
|
|
145
|
+
this._v.placed(rec);
|
|
134
146
|
this._index(rec);
|
|
135
147
|
}
|
|
148
|
+
/** @internal The character that owns this record's pose, or null. A far record rules its own model, except a rider's: the seat would take the write back as it comes near */
|
|
149
|
+
_character(rec) { const ch = this.engine.control?.characterOf(rec.id); return ch && (ch.vehicle || !this._s.recordRules(rec)) ? ch : null; }
|
|
136
150
|
/**
|
|
137
151
|
* Remove a record (its model is torn down too) and emit the world:remove event. Does nothing if the id does not exist. Removing an initial record is saved,
|
|
138
152
|
* so it stays gone after loading
|
|
@@ -171,7 +185,7 @@ export class World {
|
|
|
171
185
|
* radius: meters, or a function (for distances that change, like terrain view distance); defaults to world.radius. Registering the same kind again: old
|
|
172
186
|
* models are torn down with the old dispose and rebuilt with the new one.
|
|
173
187
|
* positionFrom: 'record' (default, the model follows the record every frame) or 'view' (the model moves itself, e.g. driven by a character mover; model
|
|
174
|
-
* position is copied back to the record at the end of each fixed step).
|
|
188
|
+
* position is copied back to the record at the end of each fixed step, and a write to the record moves the model and a rigid body on it).
|
|
175
189
|
* @example engine.world.present('chest', { build: rec => new THREE.Mesh(boxGeo, new THREE.MeshStandardMaterial()), dispose: (rec, obj) => engine.remove(obj), show: rec
|
|
176
190
|
* => !rec.looted })
|
|
177
191
|
* @param {string} kind
|
|
@@ -213,8 +227,8 @@ export class World {
|
|
|
213
227
|
* far → near step, far runs first to pay back the owed time.
|
|
214
228
|
* With only far (crops), near also advances via far; with only near, far records are not simulated and owed time is not made up.
|
|
215
229
|
* Both dt are accumulated real (fixed-step) seconds (not multiplied by clock.rate). For things measured in game clock (grows over days) store engine.clock.now
|
|
216
|
-
* and compare. channel: a time channel name (or rec => name) the kind lives on; then both dt are
|
|
217
|
-
* engine.time.local stack), so bullet time on 'enemies' slows near and far records alike (NPCs use it with their own channel).
|
|
230
|
+
* and compare. channel: a time channel name (or rec => name) the kind lives on; then both dt are the channel time the record lived through (its
|
|
231
|
+
* engine.time.local stack too), whatever the speed when far settles, so bullet time on 'enemies' slows near and far records alike (NPCs use it with their own channel).
|
|
218
232
|
* radius defaults to the present radius ('view' widened by 1.25), or world.radius without present; may also be a function.
|
|
219
233
|
* fullRadius + nearEvery (tiers, for crowds): records within fullRadius m (number or function) run near every step; the rest of the near zone runs near
|
|
220
234
|
* once every nearEvery seconds, dt being the seconds since its last turn (deterministic: turns go by hashed id and step count, saved).
|
|
@@ -234,11 +248,10 @@ export class World {
|
|
|
234
248
|
* Stop running simulate() handlers on this machine until remove(): a multiplayer client lets the host simulate and only receives the records.
|
|
235
249
|
* Public so net() needs no world internals.
|
|
236
250
|
* @returns {{ remove(): void }}
|
|
251
|
+
* @experimental
|
|
237
252
|
*/
|
|
238
|
-
pauseSimulation() { const s = this._s; s.fixed = () => {}; return { remove: () => { delete s.fixed; } }; }
|
|
239
|
-
/** Number of fixed steps simulated */ get steps() { return this._s.n; }
|
|
240
|
-
|
|
241
|
-
|
|
253
|
+
pauseSimulation() { const s = this._s; s.fixed = () => {}; return { remove: () => { delete s.fixed; for (const e of s.ents.values()) e.ch = e.mark = undefined; } }; } // channels kept moving: no stretch of the pause is owed
|
|
254
|
+
/** Number of fixed steps simulated @experimental */ get steps() { return this._s.n; }
|
|
242
255
|
}
|
|
243
256
|
|
|
244
257
|
/**
|
package/modules/world/explain.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// World's contribution to
|
|
1
|
+
// World's contribution to engine.explain({ thing }) (core/scene/thingExplain.js): the record's fields as `state`, and the record's own collision / picking rules.
|
|
2
2
|
// Template rules come from the content module's explainer (content/explain.js), which runs after this and overrides these.
|
|
3
3
|
|
|
4
4
|
/** @internal Fill state and rules for a thing that has a world record */
|
package/modules/world/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// world() module: installed as engine.world (world data, see World.js). Models load around engine.stream sources; records stay when models unload. Independent of game type: slow-life NPCs, shooter enemies, survival zombies and containers all use it.
|
|
2
2
|
// engine.use(world()) // the openWorld() preset installs it by default
|
|
3
3
|
// engine.use(world({ radius: 80 })) // distance (meters) for building models and counting as near, default 60
|
|
4
|
-
// Save key world (runtime records whole, initial records only changes and removals, see the top of
|
|
4
|
+
// Save key world (runtime records whole, initial records only changes and removals, see the top of persist.js); emits world:load after loading. The loading screen waits for world.ready (nearby models all built). describe() reports world.total / byKind / presented, and nearby records with a name go into nearby.
|
|
5
5
|
import { recordSource } from './thingSource.js';
|
|
6
6
|
import { World } from './World.js';
|
|
7
|
-
import { WORLD_MIGRATE } from './persist.js';
|
|
7
|
+
import { WORLD_MIGRATE, worldChanges } from './persist.js';
|
|
8
8
|
import { worldExplain } from './explain.js';
|
|
9
|
-
import { closest, warnOnce, DEV } from '../../core/validate.js';
|
|
10
|
-
import { readParams, keysSchema } from '../../core/params.js';
|
|
9
|
+
import { closest, warnOnce, DEV, fmt } from '../../core/base/validate.js';
|
|
10
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
11
11
|
|
|
12
12
|
const PLACED = '[session] {n} world record(s) were created or removed by code before the game started ({ids}): a new game should equal the content. '
|
|
13
13
|
+ 'Move them to content (content/props.js with an id and a template from content/templates.js), or create them during play inside an op';
|
|
@@ -15,12 +15,12 @@ const PLACED = '[session] {n} world record(s) were created or removed by code be
|
|
|
15
15
|
/**
|
|
16
16
|
* Dev check on the new-game state (saves.register checkNewGame, run once start() finished): authored things come from content, so a new game has
|
|
17
17
|
* no runtime records but the player and removes nothing. Changed fields are not checked: simulation may already move authored records (an NPC
|
|
18
|
-
* walking its schedule) while loading runs in real time. Lives here, not in core/session.js: only the world knows its own save format.
|
|
18
|
+
* walking its schedule) while loading runs in real time. Lives here, not in core/saves/session.js: only the world knows its own save format.
|
|
19
19
|
* @param {any} d the world part of the new-game state
|
|
20
20
|
*/
|
|
21
21
|
function codePlaced(d) {
|
|
22
22
|
const ids = [...Object.entries(d?.records || {}).filter(([, r]) => r.kind !== 'player').map(([id]) => id), ...(d?.removed || [])];
|
|
23
|
-
if (ids.length) warnOnce(PLACED
|
|
23
|
+
if (ids.length) warnOnce(fmt(PLACED, { n: ids.length, ids: ids.slice(0, 8).join(', ') + (ids.length > 8 ? ', …' : '') }));
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
const ORPHAN = '[world] the save has changes for {n} id(s) that the content no longer defines: {list}. They are kept in the save (restoring the entry brings them back); '
|
|
@@ -39,15 +39,20 @@ export function world(opts = {}) {
|
|
|
39
39
|
readParams('world', WORLD_PARAMS, opts);
|
|
40
40
|
let w = null;
|
|
41
41
|
return {
|
|
42
|
-
name: 'world', type: 'world', provides: ['world'], label: 'World data', params: WORLD_PARAMS, options: opts, stage: 'ground',
|
|
42
|
+
name: 'world', skipKind: 'approx', type: 'world', provides: ['world'], label: 'World data', params: WORLD_PARAMS, options: opts, stage: 'ground',
|
|
43
43
|
install(e, ctx) { e.i18n.add({ 'zh-CN': { 'module.world': '世界数据' }, en: { 'module.world': 'world data' } });
|
|
44
44
|
w = new World(e, opts);
|
|
45
|
+
const followed = e.stream.player.pos;
|
|
45
46
|
e.stream.player.at(() => w.center); // the default stream source sits where gameplay is simulated (world.anchor, else the player)
|
|
46
|
-
e.stream.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
e.
|
|
50
|
-
e.
|
|
47
|
+
ctx.track({ remove: () => e.stream.player.at(followed) }); // no closure over this world stays behind
|
|
48
|
+
ctx.stream.addReadyCheck('world', s => s.detail !== 'full' || w.ready);
|
|
49
|
+
// after the modules, not in world's own step: physics writes the models at stage late, and a record must end the step on the solver's result, a save included
|
|
50
|
+
ctx.track(e.onFixed(() => w._v.pull(), { phase: 'late' }));
|
|
51
|
+
ctx.track(e.time.onMove(() => w._s.moved()));
|
|
52
|
+
ctx.saves.register('world', { atomic: true, version: 5, migrate: WORLD_MIGRATE, save: () => w.toJSON(), load: d => w.fromJSON(d), checkNewGame: codePlaced });
|
|
53
|
+
ctx.things.addSource(recordSource(w)); // engine.thing / thing.set / the shared id space reach the records through this
|
|
54
|
+
ctx.things.explainWith(worldExplain);
|
|
55
|
+
ctx.budget.metric('worldRecords', () => w.records.size);
|
|
51
56
|
if (DEV) { // orphans are known once content loaded (engine:ready), after a load, and per level for `<level>/<node>` ids
|
|
52
57
|
const warn = () => {
|
|
53
58
|
targets();
|
|
@@ -55,19 +60,19 @@ export function world(opts = {}) {
|
|
|
55
60
|
const ids = [...w._base.keys()];
|
|
56
61
|
// a near id the save has no data for is the likely new name: suggest the exact renames.js pair
|
|
57
62
|
const list = o.slice(0, 8).map(id => { const c = closest(id, ids); return c ? `${id} (did you mean ${c}? renames: { '${id}': '${c}' })` : id; });
|
|
58
|
-
warnOnce(ORPHAN
|
|
63
|
+
warnOnce(fmt(ORPHAN, { n: o.length, list: list.join(', ') + (o.length > 8 ? ', …' : '') }));
|
|
59
64
|
};
|
|
60
65
|
const targets = () => { // a rename target nothing defines moves the player's state into a void: name it (level-node targets once that level loaded)
|
|
61
66
|
const due = id => { const i = id.indexOf('/'); return i < 0 || w._levels.has(id.slice(0, i)); };
|
|
62
67
|
const bad = [...w._renames].filter(([, b]) => b != null && !w._base.has(b) && due(b));
|
|
63
|
-
if (bad.length) warnOnce(RENAME_TARGET
|
|
68
|
+
if (bad.length) warnOnce(fmt(RENAME_TARGET, { list: bad.map(([a, b]) => `${b} (from ${a})`).join(', '), near: closest(bad[0][1], [...w._base.keys()]) ?? '-' }));
|
|
64
69
|
};
|
|
65
70
|
for (const ev of ['engine:ready', 'save:loaded', 'level:loaded']) ctx.track(e.events.on(ev, () => { if (e.ready) warn(); }));
|
|
66
71
|
}
|
|
67
72
|
return w;
|
|
68
73
|
},
|
|
69
74
|
isReady() { return w.ready; },
|
|
70
|
-
afterLoad(e) { if (e.
|
|
75
|
+
afterLoad(e) { if (e.halted) w.refresh(); return w.whenReady; }, // a paused engine has no frames to build in: build now
|
|
71
76
|
counts() { let views = 0; for (const id of w.records.keys()) if (w.view(id)) views++; return { records: w.records.size, views }; }, // engine.counts().world
|
|
72
77
|
fixed(dt) { w.fixed(dt); },
|
|
73
78
|
skip(dt, e, done) { w._s.skip(dt, done); },
|
|
@@ -76,10 +81,18 @@ export function world(opts = {}) {
|
|
|
76
81
|
const byKind = {};
|
|
77
82
|
for (const r of w.records.values()) byKind[r.kind] = (byKind[r.kind] || 0) + 1;
|
|
78
83
|
// with a model, report by the model (merged with the interaction and other modules' reports on the same object into one entry); skip records of another zone (level)
|
|
79
|
-
|
|
84
|
+
// a record without a name (props, template instances) is listed by its id, nearest 8 only: 'kind' shows what it is, and the list is capped so a thick prop field cannot push NPCs out of nearby
|
|
85
|
+
let unnamed = 0;
|
|
86
|
+
for (const r of w.query({ near: ctx.center, radius: ctx.radius })) { // nearest first
|
|
87
|
+
if (!w.inZone(r) || (r.name == null && unnamed >= 8)) continue;
|
|
88
|
+
if (r.name == null) unnamed++;
|
|
89
|
+
ctx.near(w.view(r.id) ?? r.position, { id: r.id, name: r.name ?? r.id, kind: r.kind }, true);
|
|
90
|
+
}
|
|
80
91
|
const orphans = w.orphans();
|
|
81
|
-
return { total: w.records.size, byKind, presented: w._v.map.size, zone: w.zone, ...(orphans.length && { orphans: orphans.slice(0, 20) }) };
|
|
92
|
+
return { total: w.records.size, byKind, presented: w._v.map.size, zone: w.zone, ...worldChanges(w), ...(orphans.length && { orphans: orphans.slice(0, 20) }) };
|
|
82
93
|
},
|
|
83
94
|
dispose() { w.dispose(); },
|
|
84
95
|
};
|
|
85
96
|
}
|
|
97
|
+
|
|
98
|
+
export const handRolled = 'none: far records by hand are ordinary objects in ordinary lists';
|