threedog 0.7.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 +196 -1
- package/README.md +6 -9
- package/core/{Animator.js → assets/Animator.js} +28 -18
- package/core/{Assets.js → assets/Assets.js} +98 -54
- package/core/{Baked.js → assets/Baked.js} +4 -4
- package/core/assets/assetEntry.js +237 -0
- package/core/{assetHot.js → assets/assetHot.js} +7 -6
- 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} +6 -12
- package/core/{namedModel.js → assets/namedModel.js} +17 -13
- package/core/{Audio.js → audio/Audio.js} +26 -23
- 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} +98 -110
- package/core/{errorHints.js → base/errorHints.js} +5 -9
- package/core/{errors.js → base/errors.js} +6 -6
- package/core/{events.generated.js → base/events.generated.js} +1 -0
- package/core/{math.js → base/math.js} +15 -4
- package/core/{params.js → base/params.js} +3 -4
- package/core/base/util.js +32 -0
- package/core/{validate.js → base/validate.js} +28 -7
- package/core/{Engine.js → engine/Engine.js} +80 -77
- 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} +14 -12
- package/core/{loop.js → engine/loop.js} +68 -47
- package/core/{moduleSlots.js → engine/moduleSlots.js} +6 -6
- package/core/{moduleTypes.js → engine/moduleTypes.js} +13 -14
- package/core/{modules.js → engine/modules.js} +14 -11
- package/core/{page.js → engine/page.js} +36 -23
- package/core/{plugins.js → engine/plugins.js} +6 -9
- package/core/{services.js → engine/services.js} +47 -40
- package/core/{startup.js → engine/startup.js} +26 -24
- package/core/{Input.js → input/Input.js} +30 -22
- 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} +21 -20
- package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +30 -16
- package/core/{Describe.js → inspect/Describe.js} +26 -22
- package/core/{Inspect.js → inspect/Inspect.js} +9 -7
- 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} +52 -20
- package/core/{catalog.js → inspect/catalog.js} +3 -3
- 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} +21 -20
- package/core/{describeText.js → inspect/describeText.js} +11 -6
- package/core/inspect/geometryWatch.js +38 -0
- package/core/{lightWatch.js → inspect/lightWatch.js} +8 -8
- package/core/{pictureWriters.js → inspect/pictureWriters.js} +15 -16
- 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} +14 -17
- package/core/{sharedPoint.js → ops/sharedPoint.js} +8 -8
- package/core/{stackFrames.js → ops/stackFrames.js} +2 -2
- package/core/{stacks.js → ops/stacks.js} +12 -14
- 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} +23 -25
- package/core/{Views.js → scene/Views.js} +14 -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} +17 -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/{pictureSlots.js → scene/pictureSlots.js} +2 -2
- package/core/{sceneDelta.js → scene/sceneDelta.js} +2 -2
- package/core/{sceneMethods.js → scene/sceneMethods.js} +36 -13
- package/core/scene/stepPoses.js +55 -0
- package/core/{targeting.js → scene/targeting.js} +4 -5
- package/core/{thingExplain.js → scene/thingExplain.js} +6 -5
- package/core/{thingOps.js → scene/thingOps.js} +4 -3
- package/core/{things.js → scene/things.js} +18 -5
- package/core/{threePatches.js → scene/threePatches.js} +1 -1
- package/core/{view.js → scene/view.js} +17 -16
- package/core/{Batching.js → stream/Batching.js} +85 -27
- package/core/{Stream.js → stream/Stream.js} +60 -30
- package/core/{batchGroups.js → stream/batchGroups.js} +10 -9
- package/core/{chunkStream.js → stream/chunkStream.js} +40 -0
- 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 +22 -19
- package/docs/API.md +24 -23
- package/docs/CODEMAP.md +76 -183
- package/docs/COMMANDS.md +66 -58
- package/docs/CONVENTIONS.md +54 -14
- package/docs/MIGRATING-0.8.md +169 -0
- package/docs/THREE.md +78 -29
- 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 +29 -29
- package/docs/api/characters.md +23 -18
- package/docs/api/clock.md +1 -1
- package/docs/api/collision.md +12 -9
- package/docs/api/content.md +6 -6
- package/docs/api/dialogue.md +3 -3
- package/docs/api/engine.md +45 -43
- package/docs/api/events.md +3 -2
- package/docs/api/flow.md +1 -1
- package/docs/api/grids.md +1 -1
- package/docs/api/ground.md +4 -5
- package/docs/api/hud.md +2 -2
- package/docs/api/i18n.md +6 -6
- package/docs/api/input.md +7 -7
- package/docs/api/interactions.md +4 -4
- package/docs/api/inventory.md +9 -9
- package/docs/api/jobs.md +5 -5
- package/docs/api/level.md +7 -7
- package/docs/api/lightPool.md +1 -6
- package/docs/api/music.md +3 -3
- package/docs/api/nav.md +10 -10
- package/docs/api/openWorld.md +1 -1
- package/docs/api/particles.md +2 -2
- package/docs/api/photo.md +4 -2
- package/docs/api/pickups.md +2 -2
- package/docs/api/post.md +20 -3
- 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 +8 -7
- package/docs/api/stream.md +7 -7
- package/docs/api/swarm.md +34 -0
- package/docs/api/terrain.md +7 -8
- package/docs/api/terrainDraw.md +1 -1
- package/docs/api/timeline.md +2 -2
- package/docs/api/tools.md +25 -22
- package/docs/api/vars.md +1 -1
- package/docs/api/vegetation.md +4 -3
- package/docs/api/vegetationDraw.md +1 -1
- package/docs/api/water.md +1 -1
- package/docs/api/weather.md +9 -9
- package/docs/api/weatherDraw.md +3 -3
- package/docs/api/world.md +5 -5
- package/docs/recipes/01-new-game.md +25 -40
- package/docs/recipes/02-npc.md +19 -20
- package/docs/recipes/03-items-pickups.md +27 -43
- package/docs/recipes/04-quests.md +3 -4
- package/docs/recipes/05-props-bake.md +29 -39
- package/docs/recipes/06-clock-events.md +27 -18
- package/docs/recipes/07-flow-scenes-pause.md +12 -17
- package/docs/recipes/08-weather-sky.md +88 -34
- package/docs/recipes/09-materials-lights-models.md +22 -36
- package/docs/recipes/10-blender-level.md +6 -7
- package/docs/recipes/11-vehicles.md +30 -22
- package/docs/recipes/12-navmesh.md +9 -8
- package/docs/recipes/13-animation.md +39 -17
- package/docs/recipes/14-custom-module.md +14 -13
- package/docs/recipes/15-perf.md +49 -26
- package/docs/recipes/16-dev-bridge.md +32 -52
- package/docs/recipes/18-world.md +36 -23
- package/docs/recipes/19-shooting-picking.md +4 -2
- package/docs/recipes/20-content-actions-save.md +30 -35
- package/docs/recipes/21-camera.md +33 -5
- package/docs/recipes/22-shop-gold.md +0 -4
- package/docs/recipes/23-ops.md +10 -10
- package/docs/recipes/26-ui-parts.md +22 -12
- package/docs/recipes/27-net.md +0 -2
- package/docs/recipes/28-terrain.md +117 -21
- package/docs/recipes/29-grid.md +2 -2
- package/docs/recipes/30-templates.md +55 -19
- package/docs/recipes/31-audio.md +5 -5
- package/docs/recipes/32-action-game.md +15 -6
- package/docs/recipes/33-stream-sources.md +2 -2
- package/docs/recipes/34-environment-lighting.md +67 -19
- package/docs/recipes/35-picture-from-reference.md +10 -17
- package/docs/recipes/36-ground-plants.md +105 -0
- package/docs/recipes/40-scene.md +7 -11
- package/docs/recipes/43-shader-patches-surfaces.md +20 -41
- package/docs/recipes/44-water-weather-hooks.md +48 -43
- package/docs/recipes/45-cascaded-shadows.md +39 -17
- package/docs/recipes/46-blender-art-route.md +7 -8
- package/docs/recipes/49-game-module-contract.md +5 -5
- package/docs/recipes/50-own-renderer.md +2 -2
- package/docs/recipes/52-around-the-picture.md +54 -98
- package/docs/recipes/53-ground-up-close.md +61 -24
- package/docs/recipes/55-mods-time-wrap.md +12 -16
- package/docs/recipes/56-webgpu-tsl.md +16 -14
- package/docs/recipes/57-control.md +9 -2
- package/docs/recipes/58-input.md +2 -2
- package/docs/recipes/59-depth-post-effects.md +1 -1
- package/docs/recipes/60-judge-the-picture.md +29 -24
- package/docs/recipes/62-picture-code.md +49 -17
- package/docs/recipes/63-third-person-start.md +17 -4
- package/docs/recipes/64-particles.md +1 -1
- package/docs/recipes/65-swarm.md +140 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +2 -2
- package/examples/{sheepisland → perf-island}/.threedog/content-index.json +1 -1
- package/examples/{sheepisland → perf-island}/GAMEMAP.md +12 -11
- 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 +1 -0
- package/examples/rc2d/GAMEMAP.md +3 -2
- package/examples/rc2d/main.js +1 -3
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +3 -2
- 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 +1 -0
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +4 -3
- package/examples/world/picture/sky.js +1 -1
- package/index.d.ts +8 -7
- package/index.js +31 -31
- package/llms.txt +9 -13
- package/modules/ambience/Ambience.js +11 -8
- package/modules/calendar/Calendar.js +19 -19
- package/modules/calendar/index.js +13 -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 +48 -24
- package/modules/camera/contract.js +1 -0
- package/modules/camera/projection.js +2 -2
- package/modules/characters/Character.js +33 -30
- package/modules/characters/NPC.js +27 -19
- package/modules/characters/assetModel.js +14 -10
- 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 +168 -214
- package/modules/characters/moveHelpers.js +14 -3
- package/modules/characters/movers/common.js +16 -14
- package/modules/characters/movers/manual.js +1 -1
- package/modules/characters/movers/rapier.js +7 -6
- package/modules/characters/movers/simple.js +3 -3
- package/modules/characters/movers/support.js +8 -8
- package/modules/characters/npcAvoid.js +4 -4
- package/modules/characters/npcSim.js +23 -17
- 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 +2 -2
- package/modules/characters/useModel.js +3 -3
- package/modules/characters/walkTo.js +11 -17
- package/modules/collision/Collision.js +26 -20
- 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 +61 -99
- package/modules/content/loader.js +14 -17
- package/modules/content/markers.js +25 -0
- package/modules/content/models.js +10 -7
- 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 +17 -14
- package/modules/content/rules.js +25 -21
- package/modules/content/stages.js +7 -7
- package/modules/content/templates.js +20 -20
- 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 +37 -24
- package/modules/gameplay/Inventory.js +8 -9
- package/modules/gameplay/Quests.js +16 -9
- package/modules/gameplay/boxOps.js +1 -1
- package/modules/gameplay/dialogueBubbles.js +3 -4
- package/modules/gameplay/inventoryOps.js +0 -1
- package/modules/gameplay/pickups.js +22 -23
- package/modules/gameplay/questSave.js +3 -3
- package/modules/grid/Grid.js +1 -1
- package/modules/grid/Layer.js +4 -4
- package/modules/grid/index.js +7 -8
- package/modules/grid/preview.js +7 -7
- package/modules/grid/tiles.js +6 -6
- package/modules/hlod/index.js +37 -55
- package/modules/hud/index.js +17 -11
- package/modules/hud/parts.js +4 -4
- package/modules/level/contract.js +16 -0
- package/modules/level/heightfield.js +12 -10
- package/modules/level/index.js +47 -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 +28 -181
- package/modules/lights/slots.js +93 -0
- package/modules/lights/sources.js +88 -0
- package/modules/music/Music.js +30 -26
- 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 +11 -8
- package/modules/particles/effect.js +7 -5
- package/modules/particles/shaders.js +2 -1
- package/modules/photo/Photo.js +15 -17
- 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 +108 -39
- package/modules/settings/apply.js +6 -6
- package/modules/settings/sections.js +16 -14
- 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 +14 -27
- package/modules/sky/tint.js +1 -1
- 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 +70 -52
- 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 +28 -34
- package/modules/terrain/terrainColorMap.js +6 -3
- package/modules/terrain/terrainDefaults.js +2 -1
- package/modules/terrain/terrainEdit.js +32 -27
- package/modules/terrain/terrainGen.js +17 -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 +27 -19
- package/modules/timeline/Tween.js +6 -6
- package/modules/timeline/shots.js +5 -7
- package/modules/triggers/index.js +9 -9
- package/modules/vegetation/Vegetation.js +30 -23
- package/modules/vegetation/densityMap.js +4 -7
- package/modules/vegetation/draw.js +23 -18
- package/modules/vegetation/groundChunks.js +11 -31
- package/modules/vegetation/index.js +8 -6
- package/modules/vegetation/modelGeometry.js +3 -6
- package/modules/vegetation/nearFade.js +1 -1
- package/modules/water/Water.js +16 -16
- package/modules/water/surface.js +3 -3
- package/modules/weather/Weather.js +41 -30
- package/modules/weather/particles.js +8 -8
- package/modules/weather/weatherDraw.js +22 -18
- package/modules/world/World.js +8 -8
- 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 +11 -9
- package/package.json +42 -7
- package/presets.js +1 -3
- package/render/PostFX.js +39 -27
- package/render/backend.js +26 -32
- 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/patchNodes.tsl.js +5 -15
- package/render/fx/postWebGPU.tsl.js +27 -23
- 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 +1 -1
- package/render/lighting.js +5 -3
- package/render/lightmap.js +20 -20
- 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 +20 -4
- package/render/ownFrame.js +4 -4
- package/render/patches.js +13 -13
- package/render/postWebGL.js +12 -10
- package/render/probes.js +16 -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 +57 -11
- package/render/slots.js +7 -7
- package/render/terms.js +22 -24
- package/render/uniformDecl.js +1 -1
- package/types/core.d.ts +200 -153
- package/types/gameplay.d.ts +163 -91
- 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} +7 -15
- 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} +12 -8
- package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
- package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +2 -2
- 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 +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 +1 -1
- 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 +2 -1
- package/types/generated/modules/water/Water.d.ts +1 -0
- package/types/generated/modules/weather/Weather.d.ts +16 -12
- package/types/generated/modules/weather/weatherDraw.d.ts +3 -3
- package/types/generated/modules/world/World.d.ts +5 -3
- package/types/generated/render/PostFX.d.ts +17 -11
- 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 +11 -11
- package/types/physics.d.ts +99 -70
- package/types/tsl.d.ts +37 -4
- package/types/world.d.ts +38 -71
- package/ui/Focus.js +10 -9
- package/ui/Parts.js +4 -3
- package/ui/UI.js +7 -7
- package/ui/defaults.js +3 -2
- package/ui/theme.js +5 -3
- package/core/assetEntry.js +0 -109
- package/core/holds.js +0 -134
- package/core/shadowTypes.js +0 -16
- package/core/util.js +0 -17
- 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/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/{tier.js → scene/tier.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
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Seven temperate ones are an opt-in preset: weather(presets.weather.temperate), extend with types: { ...presets.weather.temperate.types, dust: {...} }.
|
|
3
3
|
// All fields blend smoothly on change.
|
|
4
4
|
// Affects: cloud shadows, sky color, wind (plants sway), rain/snow particles, lightning, ambience; light and fog are the game's, which reads uWeatherLight / uWeatherFog.
|
|
5
|
-
// Particle and lightning pictures: weather({ rain, snow, lightning }), engine.weather.
|
|
5
|
+
// Particle and lightning pictures: weather({ rain, snow, lightning }), engine.weather.defineField(field, spec), engine.weather.particles (particles.js, recipes/44).
|
|
6
6
|
// weather() installs two modules: this state (current / target / progress, auto weather, lightning timing, events, save) and the drawing half
|
|
7
7
|
// (weatherDraw.js: particles, sky effects, thunder). Why split: the state is game data that saves and skips; the picture only reads it,
|
|
8
8
|
// so a game can swap the picture without touching the weather a save restores.
|
|
@@ -12,10 +12,11 @@
|
|
|
12
12
|
// Weather display names live in the string table as weather.<name> (describe and the debug panel use them); a game that adds a new weather adds its name with
|
|
13
13
|
// i18n.add.
|
|
14
14
|
import * as THREE from 'three';
|
|
15
|
-
import { warnMissing } from '../../core/validate.js';
|
|
16
|
-
import { readParams, keysSchema } from '../../core/params.js';
|
|
15
|
+
import { warnMissing, fmt } from '../../core/base/validate.js';
|
|
16
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
17
17
|
import { STRINGS, ERR } from './strings.js';
|
|
18
|
-
import { codedError } from '../../core/errorHints.js';
|
|
18
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
19
|
+
import { STEP } from '../../core/time/time.js';
|
|
19
20
|
import { weatherDrawModule } from './weatherDraw.js';
|
|
20
21
|
/** @import { ModuleDef } from '../../types/core' */
|
|
21
22
|
/** @import { WeatherName, WeatherPreset, WeatherOptions, WeatherParticles, WeatherParticleSystem } from '../../types/world' */
|
|
@@ -42,7 +43,7 @@ export class Weather {
|
|
|
42
43
|
/** @internal */ this.engine = engine;
|
|
43
44
|
if (typeof lightning !== 'function') throw codedError('weather-option', 'weather({ lightning }) must be a function (flash 0..1, engine) => sky flash amount, e.g. lightning: f => f * 0.6; return 0 and draw your own bolt on the weather:lightning event');
|
|
44
45
|
// The game's table is the whole list (a desert game has no snow, a space station no rain); without one only a calm 'clear'.
|
|
45
|
-
if (types !== undefined && (!types || typeof types !== 'object' || !Object.keys(types).length)) throw codedError('weather-option', ERR.types
|
|
46
|
+
if (types !== undefined && (!types || typeof types !== 'object' || !Object.keys(types).length)) throw codedError('weather-option', fmt(ERR.types, { got: String(JSON.stringify(types)) }));
|
|
46
47
|
const table = types ?? ONLY_CLEAR;
|
|
47
48
|
/**
|
|
48
49
|
* The weather types this game has: name -> numbers (the standard fields plus any of the game's own, all blended on change) @type {Record<string,
|
|
@@ -51,13 +52,13 @@ export class Weather {
|
|
|
51
52
|
this.types = {};
|
|
52
53
|
for (const k of Object.keys(table)) {
|
|
53
54
|
const v = { ...CALM, ...table[k] };
|
|
54
|
-
for (const f in v) if (typeof v[f] !== 'number') throw codedError('weather-option', ERR.field
|
|
55
|
+
for (const f in v) if (typeof v[f] !== 'number') throw codedError('weather-option', fmt(ERR.field, { k, f, got: String(JSON.stringify(v[f])) }));
|
|
55
56
|
this.types[k] = v;
|
|
56
57
|
}
|
|
57
58
|
// a game field one type has ('heat' on 'heatwave') is 0 on the others, so a change always blends between two numbers
|
|
58
59
|
for (const v of Object.values(this.types)) for (const o of Object.values(this.types)) for (const f in o) v[f] ??= 0;
|
|
59
60
|
start ??= this.types.clear ? 'clear' : Object.keys(this.types)[0];
|
|
60
|
-
if (!this.types[start]) throw codedError('weather-option', ERR.start
|
|
61
|
+
if (!this.types[start]) throw codedError('weather-option', fmt(ERR.start, { got: String(start), list: Object.keys(this.types).join(', ') }));
|
|
61
62
|
/** Current (mid-transition) weather parameters @type {WeatherPreset} */
|
|
62
63
|
this.current = { ...this.types[start] };
|
|
63
64
|
/** @internal */ this.from = { ...this.current };
|
|
@@ -66,22 +67,21 @@ export class Weather {
|
|
|
66
67
|
/** @internal */ this.dur = 1;
|
|
67
68
|
/** Current weather name @type {string} */
|
|
68
69
|
this.name = start;
|
|
69
|
-
/**
|
|
70
|
-
this.auto = false;
|
|
70
|
+
/** @internal */ this._auto = false;
|
|
71
71
|
/** @internal */ this.autoTimer = 0;
|
|
72
|
-
/** Candidates for automatic weather (repeat a name to make it likelier) @type {string[]} */
|
|
72
|
+
/** Candidates for automatic weather (repeat a name to make it likelier) @type {string[]} @experimental */
|
|
73
73
|
this.autoPool = [...(autoPool || Object.keys(this.types))];
|
|
74
|
-
for (const k of this.autoPool) if (!this.types[k]) throw codedError('weather-option', ERR.pool
|
|
75
|
-
/** Automatic weather interval [min, max] seconds @type {number[]} */
|
|
74
|
+
for (const k of this.autoPool) if (!this.types[k]) throw codedError('weather-option', fmt(ERR.pool, { got: String(k), list: Object.keys(this.types).join(', ') }));
|
|
75
|
+
/** Automatic weather interval [min, max] seconds @type {number[]} @experimental */
|
|
76
76
|
this.autoInterval = autoInterval;
|
|
77
|
-
/** Transition seconds for automatic weather @type {number} */
|
|
77
|
+
/** Transition seconds for automatic weather @type {number} @experimental */
|
|
78
78
|
this.autoTransition = transition;
|
|
79
|
-
/** Seconds to the first bolt (also after a load without a saved timer) @type {number} */
|
|
79
|
+
/** Seconds to the first bolt (also after a load without a saved timer) @type {number} @experimental */
|
|
80
80
|
this.lightningFirst = lightningFirst;
|
|
81
|
-
/** [min, max] seconds between bolts while a type with lightning > 0.5 holds @type {number[]} */
|
|
81
|
+
/** [min, max] seconds between bolts while a type with lightning > 0.5 holds @type {number[]} @experimental */
|
|
82
82
|
this.lightningInterval = lightningInterval;
|
|
83
83
|
/** @internal seconds to the next lightning strike while a type with lightning > 0.5 holds */ this.nextBolt = lightningFirst;
|
|
84
|
-
/** Strike picture: flash (1 at the strike, fading in a third of a second) -> sky flash amount. Write it at any time @type {(flash: number, engine: any) => number} */
|
|
84
|
+
/** Strike picture: flash (1 at the strike, fading in a third of a second) -> sky flash amount. Write it at any time @type {(flash: number, engine: any) => number} @experimental */
|
|
85
85
|
this.lightning = lightning;
|
|
86
86
|
/** Multiplies the sky flash of every strike; write it at any time @type {number} */
|
|
87
87
|
this.lightningBrightness = lightningBrightness;
|
|
@@ -90,7 +90,7 @@ export class Weather {
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
/**
|
|
93
|
-
* The particle systems drawn now, by field: rain and snow when the table has them, plus what
|
|
93
|
+
* The particle systems drawn now, by field: rain and snow when the table has them, plus what defineField() added. Each has material (the plain three.js
|
|
94
94
|
* material: read it, or set your own, drawn as given; null gives the engine's back), uniforms ({ value } objects the engine writes each frame, a
|
|
95
95
|
* ShaderMaterial of yours shares them; uColor, uLen, uPx, uMaxPx, uSwayAmp are yours to write), spec (opacity, speed, slant, density are read each
|
|
96
96
|
* frame, plain writes), object (the three.js object). Empty when a game replaced the weather drawing
|
|
@@ -105,23 +105,29 @@ export class Weather {
|
|
|
105
105
|
* frame is weather.current[field], so they fade with the weather. spec takes the keys of weather({ rain }), or
|
|
106
106
|
* { create(engine, { area, count }) => { object, update?(amount, { camera, time, wind }) } } for a system of your own; null gives rain / snow back
|
|
107
107
|
* to weather({ rain, snow }) and removes any other field. Defining a field again replaces it. A field no type has throws with the table's fields
|
|
108
|
-
* @example engine.weather.
|
|
108
|
+
* @example engine.weather.defineField('ash', { shape: 'soft', color: 0x555555, size: 14, speed: 0.8, sway: 3 });
|
|
109
109
|
* @param {string} field
|
|
110
110
|
* @param {WeatherParticles | null} spec
|
|
111
111
|
* @returns {WeatherParticleSystem | null}
|
|
112
112
|
*/
|
|
113
|
-
|
|
113
|
+
defineField(field, spec) {
|
|
114
114
|
const drawPart = this.engine.weatherDraw;
|
|
115
|
-
if (!drawPart) throw codedError('weather-option', "weather.
|
|
116
|
-
return drawPart.
|
|
115
|
+
if (!drawPart) throw codedError('weather-option', "weather.defineField(): the weather is drawn by a game module (replaces: 'weatherDraw'); draw this field there, reading engine.weather.current");
|
|
116
|
+
return drawPart.defineField(field, spec);
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
/**
|
|
120
|
+
* Automatic weather on/off. Writing it takes effect like setAuto.
|
|
121
|
+
* @type {boolean}
|
|
122
|
+
*/
|
|
123
|
+
get auto() { return this._auto; }
|
|
124
|
+
set auto(on) { this._auto = on; if (on) this.autoTimer = 0; }
|
|
119
125
|
/**
|
|
120
126
|
* Automatic weather on/off
|
|
121
127
|
* @param {boolean} on
|
|
122
128
|
* @returns {void}
|
|
123
129
|
*/
|
|
124
|
-
setAuto(on) { this.auto = on;
|
|
130
|
+
setAuto(on) { this.auto = on; }
|
|
125
131
|
|
|
126
132
|
/**
|
|
127
133
|
* Switch weather. seconds: transition seconds, default 15; 0 switches at once (current is the new weather before the next step, so a
|
|
@@ -138,7 +144,7 @@ export class Weather {
|
|
|
138
144
|
const p = this.types[name];
|
|
139
145
|
if (!p) { warnMissing('weather', name, Object.keys(this.types)); return; }
|
|
140
146
|
const from = this.name;
|
|
141
|
-
if (!(seconds >= 0 && Number.isFinite(seconds))) throw codedError('
|
|
147
|
+
if (!(seconds >= 0 && Number.isFinite(seconds))) throw codedError('weather-option', `weather.set('${name}', { seconds }) takes seconds >= 0 (0 = at once); got ${seconds}`);
|
|
142
148
|
this.name = name; this.from = { ...this.current }; this.to = { ...p }; this.t = 0; this.dur = seconds;
|
|
143
149
|
// seconds 0: land now, not on the next fixed step (a shot or test right after the call saw the old weather, or 1/3 of a short blend)
|
|
144
150
|
if (seconds === 0) { this.t = 1; for (const key in this.to) this.current[key] = this.to[key]; }
|
|
@@ -166,7 +172,7 @@ export class Weather {
|
|
|
166
172
|
this.t = Math.min(1, this.t + dt / this.dur);
|
|
167
173
|
const k = this.t * this.t * (3 - 2 * this.t);
|
|
168
174
|
// a finished blend lands on `to` exactly: from + (to - from) * 1 is off by a rounding error that depends on where the blend started, so a load
|
|
169
|
-
// or session.newGame (set(name, 0.01) from whatever the last playthrough left) would not give the same weather twice
|
|
175
|
+
// or session.newGame (set(name, { seconds: 0.01 }) from whatever the last playthrough left) would not give the same weather twice
|
|
170
176
|
for (const key in this.to) this.current[key] = this.t >= 1 ? this.to[key] : this.from[key] + (this.to[key] - this.from[key]) * k;
|
|
171
177
|
}
|
|
172
178
|
if (this.auto) {
|
|
@@ -185,7 +191,7 @@ export class Weather {
|
|
|
185
191
|
}
|
|
186
192
|
|
|
187
193
|
/**
|
|
188
|
-
* Weather: two modules for one engine.use: the state (engine.weather, type 'world') and its picture (engine.weatherDraw, type 'picture';
|
|
194
|
+
* Weather: two modules for one engine.use: the state (engine.weather, type 'world') and its picture (engine.weatherDraw, type 'picture'; sky optional)
|
|
189
195
|
* @param {WeatherOptions} [opts]
|
|
190
196
|
* @returns {[ModuleDef<Weather>, ModuleDef<import('./weatherDraw.js').WeatherDraw>]}
|
|
191
197
|
* @example engine.use(sky(), weather({ types: presets.weather.temperate.types, start: 'clear' }))
|
|
@@ -200,13 +206,15 @@ export function weather(opts = {}) {
|
|
|
200
206
|
w = new Weather(e, opts);
|
|
201
207
|
if (opts.auto) w.auto = true;
|
|
202
208
|
// the transition is saved too (current / from / to / t / dur): a save made 30% into sun -> rain loads 30% in, not as full rain, and fires no
|
|
203
|
-
// weather:change (nothing changed for the player).
|
|
209
|
+
// weather:change (nothing changed for the player). A damaged part, or a weather the game no longer has, loads as a finished switch to that name
|
|
204
210
|
e.saves.register('weather', {
|
|
205
211
|
save: () => ({ name: w.name, auto: w.auto, autoTimer: w.autoTimer, nextBolt: w.nextBolt, current: { ...w.current }, from: { ...w.from }, to: { ...w.to }, t: w.t, dur: w.dur }),
|
|
206
212
|
load: d => {
|
|
207
213
|
if (!d) return;
|
|
208
214
|
if (Number.isFinite(d.t) && d.current && d.from && d.to && w.types[d.name]) {
|
|
209
|
-
|
|
215
|
+
// over the type's own fields: a save older than a field the table has now would blend it from undefined (NaN)
|
|
216
|
+
const full = v => ({ ...w.types[d.name], ...v });
|
|
217
|
+
w.name = d.name; w.current = full(d.current); w.from = full(d.from); w.to = full(d.to); w.t = d.t; w.dur = Math.max(0.01, d.dur ?? 1);
|
|
210
218
|
} else w.set(d.name, { seconds: 0 });
|
|
211
219
|
w.auto = d.auto; w.autoTimer = d.autoTimer ?? 0; w.nextBolt = d.nextBolt ?? w.lightningFirst;
|
|
212
220
|
} });
|
|
@@ -214,16 +222,19 @@ export function weather(opts = {}) {
|
|
|
214
222
|
},
|
|
215
223
|
fixed(dt) { w.tick(dt); },
|
|
216
224
|
// the weather as signals (engine.uniforms) every frame, from the state and not its picture: a game that draws its own rain still reads them
|
|
217
|
-
frame(_dt, e) { const U = e.uniforms, c = w.current; U.
|
|
225
|
+
frame(_dt, e) { const U = e.uniforms, c = w.current; U.uWeatherCloud.value = c.cloud; U.uWind.value = c.wind; U.uRain.value = c.rain; U.uSnow.value = c.snow; U.uWeatherLight.value = c.sun; U.uWeatherFog.value = c.fog; },
|
|
218
226
|
// engine.skip: fixed hooks do not run, so the skipped fixed steps are replayed here without events (a bolt nobody saw)
|
|
219
227
|
skip(dt) { // replay the fixed steps (same random draws, same order as stepping, so checkSkip matches); nothing pending = nothing to replay
|
|
220
228
|
if (w.t >= 1 && !w.auto && !(w.current.lightning > 0.5)) return;
|
|
221
|
-
for (let n = Math.round(dt
|
|
229
|
+
for (let n = Math.round(dt / STEP); n > 0; n--) w.tick(STEP, true);
|
|
222
230
|
},
|
|
223
231
|
// scenario param weather: switch to this weather at once (no transition) and turn off automatic weather, so the scene is reproducible
|
|
232
|
+
stateKeys: ['weather'],
|
|
224
233
|
applyState(e, { weather: name }) {
|
|
225
234
|
if (!name) return;
|
|
226
|
-
w.set(name, { seconds: 0 });
|
|
235
|
+
w.set(name, { seconds: 0 }); // an unknown name warns and changes nothing, so the name is read back
|
|
236
|
+
if (w.name !== name) return { refused: { weather: `no weather named "${name}"; this game has ${Object.keys(w.types).join(', ')} (types in weather({ types }), e.g. presets.weather.temperate)` } };
|
|
237
|
+
w.auto = false;
|
|
227
238
|
},
|
|
228
239
|
describe() {
|
|
229
240
|
const c = w.current, r = v => Math.round(v * 100) / 100;
|
|
@@ -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,40 @@
|
|
|
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
25
|
/** @internal the state half: read only */ this.state = engine.weather;
|
|
25
26
|
/** Sky flash now, 1 at a strike (the weather:lightning event) fading to 0 @type {number} */
|
|
26
27
|
this.flash = 0;
|
|
27
28
|
// 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
|
|
29
|
+
// 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
30
|
/** @internal */ this._ctx = null; /** @internal */ this._h = {};
|
|
30
31
|
/** @internal */ this._tint = { color: this.state.overcastColor, amount: 0, horizon: 0 };
|
|
31
|
-
/** Default particle count per system (
|
|
32
|
-
this.particles = engine.tier === 'low' ?
|
|
32
|
+
/** Default particle count per system: weather({ particles }), else 6000 (3000 on low-tier devices) @type {number} */
|
|
33
|
+
this.particles = particles ?? (engine.tier === 'low' ? 3000 : 6000);
|
|
33
34
|
/** @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.
|
|
35
|
+
/** 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
36
|
this.systems = new Map();
|
|
36
37
|
// zero cost when unused: a table where nothing ever rains or snows builds no particle meshes
|
|
37
38
|
const { cover, ...snowGiven } = snow;
|
|
38
|
-
/** @internal what weather({ rain, snow }) gave:
|
|
39
|
+
/** @internal what weather({ rain, snow }) gave: defineField(field, null) goes back to it */ this._given = { rain, snow: snowGiven };
|
|
39
40
|
for (const k of Object.keys(BASE)) if (this._used(k)) this._build(k, this._given[k], BASE[k]);
|
|
40
41
|
// snow cover: foliage / ground season tint moves toward the snow colors as current.snow rises (ground.cover)
|
|
41
42
|
if (cover !== undefined) {
|
|
@@ -51,11 +52,11 @@ export class WeatherDraw {
|
|
|
51
52
|
/** @internal does any type have this field above 0 */
|
|
52
53
|
_used(field) { return Object.values(this.types).some(v => v[field] > 0); }
|
|
53
54
|
|
|
54
|
-
/** @internal engine.weather.
|
|
55
|
-
|
|
55
|
+
/** @internal engine.weather.defineField */
|
|
56
|
+
defineField(field, spec) {
|
|
56
57
|
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.
|
|
58
|
+
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(', ')}`);
|
|
59
|
+
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
60
|
if (spec) return this._build(field, spec, BASE[field]);
|
|
60
61
|
if (BASE[field] && this._used(field)) return this._build(field, this._given[field], BASE[field]);
|
|
61
62
|
const s = this.systems.get(field);
|
|
@@ -65,9 +66,9 @@ export class WeatherDraw {
|
|
|
65
66
|
|
|
66
67
|
/** @internal */
|
|
67
68
|
_build(field, spec, base) {
|
|
69
|
+
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
70
|
const old = this.systems.get(field);
|
|
69
71
|
if (old) dropSystem(this.engine, old);
|
|
70
|
-
const sys = makeSystem(this.engine, field, spec, { area: this.area, count: this.particles, base });
|
|
71
72
|
sys.base = base; // the renderer swap builds it again over the same defaults
|
|
72
73
|
this.systems.set(field, sys);
|
|
73
74
|
return sys;
|
|
@@ -75,7 +76,7 @@ export class WeatherDraw {
|
|
|
75
76
|
|
|
76
77
|
/**
|
|
77
78
|
* @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
|
|
79
|
+
* 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
80
|
* if WebGL cannot draw it).
|
|
80
81
|
*/
|
|
81
82
|
_rendererSwapped() {
|
|
@@ -101,13 +102,15 @@ export class WeatherDraw {
|
|
|
101
102
|
this.flash = Math.max(0, this.flash - dt * 3);
|
|
102
103
|
T.amount = c.grey; T.horizon = c.grey * 0.8; this._put('sky.tint', 'value', T);
|
|
103
104
|
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); }
|
|
105
|
+
if (this._cover) { this._coverMod.amount = (c.snow ?? 0) * this._cover.strength; this._put('ground.cover', 'value', this._coverMod); }
|
|
105
106
|
for (const sys of this.systems.values()) updateSystem(sys, c[sys.field] ?? 0, camera, t, c.wind);
|
|
106
107
|
}
|
|
107
108
|
/** @internal one contribution to a shared point: taken on first use, then changed in place */
|
|
108
109
|
_put(point, op, v) {
|
|
109
110
|
// 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
111
|
if (this._h[point]?.change(v)) return;
|
|
112
|
+
// 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
|
|
113
|
+
if (!this.engine.stacks.has(point)) return;
|
|
111
114
|
const o = op === 'value' ? { value: v } : { [op]: v, layer: 'effect' }; // tint / cover are data points (value), the flash an effect-layer number
|
|
112
115
|
this._h[point] = this._ctx ? this._ctx.mod(point, o) : this.engine.mod(point, { ...o, owner: 'weatherDraw' });
|
|
113
116
|
}
|
|
@@ -121,7 +124,7 @@ export function weatherDrawModule(opts) {
|
|
|
121
124
|
readParams('weather (drawing half)', DRAW_PARAMS, opts);
|
|
122
125
|
let L = null;
|
|
123
126
|
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'],
|
|
127
|
+
name: 'weatherDraw', type: 'picture', provides: ['weatherDraw'], label: 'Weather drawing', params: DRAW_PARAMS, options: opts, requires: ['weather'], optional: ['sky'], stage: 'environment', before: ['sky'], after: ['weather'],
|
|
125
128
|
install(e, ctx) { e.i18n.add({ 'zh-CN': { 'module.weatherDraw': '天气外观' }, en: { 'module.weatherDraw': 'weather drawing' } });
|
|
126
129
|
L = new WeatherDraw(e, opts);
|
|
127
130
|
L._ctx = ctx; // the weather's entries on the shared points go with this module (ctx.mod)
|
|
@@ -136,6 +139,7 @@ export function weatherDrawModule(opts) {
|
|
|
136
139
|
return L;
|
|
137
140
|
},
|
|
138
141
|
frame(dt, e) { L.apply(e.camera, dt); },
|
|
142
|
+
dispose(e) { for (const s of L.systems.values()) dropSystem(e, s); L.systems.clear(); },
|
|
139
143
|
describe: () => ({ rainVisible: !!L.systems.get('rain')?.object.visible, snowVisible: !!L.systems.get('snow')?.object.visible, flash: Math.round(L.flash * 100) / 100 }),
|
|
140
144
|
};
|
|
141
145
|
}
|
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
|
|
@@ -76,7 +76,7 @@ export class World {
|
|
|
76
76
|
* 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
77
|
* authored id, so the two can never collide).
|
|
78
78
|
* 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);
|
|
79
|
+
* returned (content may load twice), after taking a new position / rot from the content unless play moved it;
|
|
80
80
|
* returns null if the save removed it (it is not added back). opts.save: false: not saved (temporary things).
|
|
81
81
|
* @example engine.world.add({ id: 'shop_owner', kind: 'npc', position: [12, 0, -30], name: '店主', mood: 'calm' }, { initial: true })
|
|
82
82
|
* @param {{ kind: string, id?: string, position?: any, [field: string]: any }} def
|
|
@@ -99,6 +99,7 @@ export class World {
|
|
|
99
99
|
* @example const h = engine.pick(0, 0); const id = h && engine.world.idOf(h.object);
|
|
100
100
|
* @param {any} obj a THREE.Object3D (a mesh of the model is fine)
|
|
101
101
|
* @returns {string | null}
|
|
102
|
+
* @experimental
|
|
102
103
|
*/
|
|
103
104
|
idOf(obj) {
|
|
104
105
|
for (let o = obj; o; o = o.parent) { const id = this._v.byObj.get(o); if (id !== undefined) return id; }
|
|
@@ -234,11 +235,10 @@ export class World {
|
|
|
234
235
|
* Stop running simulate() handlers on this machine until remove(): a multiplayer client lets the host simulate and only receives the records.
|
|
235
236
|
* Public so net() needs no world internals.
|
|
236
237
|
* @returns {{ remove(): void }}
|
|
238
|
+
* @experimental
|
|
237
239
|
*/
|
|
238
240
|
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
|
-
|
|
241
|
+
/** Number of fixed steps simulated @experimental */ get steps() { return this._s.n; }
|
|
242
242
|
}
|
|
243
243
|
|
|
244
244
|
/**
|
package/modules/world/explain.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// World's contribution to thing.explain() (core/thingExplain.js): the record's fields as `state`, and the record's own collision / picking rules.
|
|
1
|
+
// World's contribution to thing.explain() (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); '
|
|
@@ -43,7 +43,7 @@ export function world(opts = {}) {
|
|
|
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
45
|
e.stream.player.at(() => w.center); // the default stream source sits where gameplay is simulated (world.anchor, else the player)
|
|
46
|
-
e.stream.
|
|
46
|
+
e.stream.addReadyCheck('world', s => s.detail !== 'full' || w.ready);
|
|
47
47
|
e.saves.register('world', { atomic: true, version: 5, migrate: WORLD_MIGRATE, save: () => w.toJSON(), load: d => w.fromJSON(d), checkNewGame: codePlaced });
|
|
48
48
|
e._things.addSource(recordSource(w)); // engine.thing / thing.set / the shared id space reach the records through this
|
|
49
49
|
e.explainWith(worldExplain);
|
|
@@ -55,19 +55,19 @@ export function world(opts = {}) {
|
|
|
55
55
|
const ids = [...w._base.keys()];
|
|
56
56
|
// a near id the save has no data for is the likely new name: suggest the exact renames.js pair
|
|
57
57
|
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
|
|
58
|
+
warnOnce(fmt(ORPHAN, { n: o.length, list: list.join(', ') + (o.length > 8 ? ', …' : '') }));
|
|
59
59
|
};
|
|
60
60
|
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
61
|
const due = id => { const i = id.indexOf('/'); return i < 0 || w._levels.has(id.slice(0, i)); };
|
|
62
62
|
const bad = [...w._renames].filter(([, b]) => b != null && !w._base.has(b) && due(b));
|
|
63
|
-
if (bad.length) warnOnce(RENAME_TARGET
|
|
63
|
+
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
64
|
};
|
|
65
65
|
for (const ev of ['engine:ready', 'save:loaded', 'level:loaded']) ctx.track(e.events.on(ev, () => { if (e.ready) warn(); }));
|
|
66
66
|
}
|
|
67
67
|
return w;
|
|
68
68
|
},
|
|
69
69
|
isReady() { return w.ready; },
|
|
70
|
-
afterLoad(e) { if (e.
|
|
70
|
+
afterLoad(e) { if (e.halted) w.refresh(); return w.whenReady; }, // a paused engine has no frames to build in: build now
|
|
71
71
|
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
72
|
fixed(dt) { w.fixed(dt); },
|
|
73
73
|
skip(dt, e, done) { w._s.skip(dt, done); },
|
|
@@ -76,9 +76,15 @@ export function world(opts = {}) {
|
|
|
76
76
|
const byKind = {};
|
|
77
77
|
for (const r of w.records.values()) byKind[r.kind] = (byKind[r.kind] || 0) + 1;
|
|
78
78
|
// 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
|
-
|
|
79
|
+
// 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
|
|
80
|
+
let unnamed = 0;
|
|
81
|
+
for (const r of w.query({ near: ctx.center, radius: ctx.radius })) { // nearest first
|
|
82
|
+
if (!w.inZone(r) || (r.name == null && unnamed >= 8)) continue;
|
|
83
|
+
if (r.name == null) unnamed++;
|
|
84
|
+
ctx.near(w.view(r.id) ?? r.position, { id: r.id, name: r.name ?? r.id, kind: r.kind }, true);
|
|
85
|
+
}
|
|
80
86
|
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) }) };
|
|
87
|
+
return { total: w.records.size, byKind, presented: w._v.map.size, zone: w.zone, ...worldChanges(w), ...(orphans.length && { orphans: orphans.slice(0, 20) }) };
|
|
82
88
|
},
|
|
83
89
|
dispose() { w.dispose(); },
|
|
84
90
|
};
|