threedog 0.2.0 → 0.5.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 +290 -0
- package/README.md +9 -8
- package/core/Animator.js +15 -12
- package/core/Assets.js +83 -16
- package/core/Audio.js +45 -38
- package/core/Baked.js +32 -8
- package/core/Batching.js +102 -15
- package/core/Budget.js +39 -18
- package/core/Clock.js +40 -80
- package/core/DebugOverrides.js +45 -10
- package/core/Describe.js +104 -43
- package/core/Engine.js +190 -57
- package/core/Events.js +4 -1
- package/core/I18n.js +25 -13
- package/core/Input.js +168 -79
- package/core/Inspect.js +2 -2
- package/core/InspectMaterials.js +85 -0
- package/core/InspectPerf.js +61 -0
- package/core/InspectScene.js +13 -2
- package/core/Loading.js +2 -1
- package/core/Ops.js +50 -9
- package/core/Random.js +9 -2
- package/core/Rays.js +5 -5
- package/core/SaveStore.js +41 -9
- package/core/Saves.js +71 -15
- package/core/Stream.js +14 -10
- package/core/Threads.js +26 -7
- package/core/UrlState.js +25 -9
- package/core/Views.js +9 -6
- package/core/actor.js +1 -1
- package/core/adaptive.js +93 -0
- package/core/assetEntry.js +22 -5
- package/core/assetHot.js +176 -0
- package/core/assetLoad.js +38 -11
- package/core/assetManifest.js +48 -9
- package/core/assetReport.js +1 -1
- package/core/audioRules.js +13 -11
- package/core/audioVoice.js +69 -42
- package/core/canvasBox.js +1 -2
- package/core/catalog.js +5 -2
- package/core/cells.js +62 -0
- package/core/checks.js +10 -8
- package/core/chunkStream.js +87 -0
- package/core/control.js +149 -0
- package/core/copies.js +32 -0
- package/core/dayTime.js +12 -6
- package/core/debugView.js +82 -15
- package/core/describeRender.js +43 -17
- package/core/describeText.js +41 -21
- package/core/engineCamera.js +32 -0
- package/core/errorCodes.js +438 -19
- package/core/errorHints.js +37 -141
- package/core/errors.js +31 -8
- package/core/events.generated.js +12 -7
- package/core/gameLights.js +62 -0
- package/core/grayMap.js +20 -0
- package/core/grid.js +128 -0
- package/core/gridLoad.js +20 -0
- package/core/ground.js +6 -4
- package/core/headlessLoad.js +55 -0
- package/core/holds.js +78 -50
- package/core/inputContext.js +11 -7
- package/core/inputDefaults.js +24 -21
- package/core/inputPad.js +1 -1
- package/core/inputPointer.js +1 -1
- package/core/inputTouch.js +2 -2
- package/core/lifecycle.js +48 -12
- package/core/lightWatch.js +6 -4
- package/core/look/coreParts.js +137 -30
- package/core/look/part.js +175 -95
- package/core/look/points.js +255 -0
- package/core/look/report.js +34 -17
- package/core/look/shadowPart.js +63 -0
- package/core/look/state.js +45 -0
- package/core/look/write.js +12 -28
- package/core/loop.js +101 -37
- package/core/math.js +11 -3
- package/core/moduleSlots.js +75 -0
- package/core/moduleTypes.js +73 -0
- package/core/modules.js +145 -27
- package/core/movement.js +2 -2
- package/core/namedModel.js +70 -0
- package/core/opsCheck.js +3 -3
- package/core/opsFail.js +15 -6
- package/core/opsGuard.js +4 -4
- package/core/opsRun.js +4 -3
- package/core/owned.js +168 -0
- package/core/page.js +2 -1
- package/core/params.js +30 -8
- package/core/plugins.js +277 -0
- package/core/saveApply.js +99 -17
- package/core/saveFiles.js +8 -6
- package/core/saveValues.js +46 -0
- package/core/saveVersions.js +20 -3
- package/core/scatter.js +48 -19
- package/core/sceneDelta.js +203 -0
- package/core/sceneMethods.js +35 -30
- package/core/screenToGround.js +1 -1
- package/core/services.js +27 -11
- package/core/session.js +28 -25
- package/core/shaderCost.js +78 -0
- package/core/shadowTypes.js +2 -1
- package/core/sharedPoint.js +317 -0
- package/core/skip.js +36 -28
- package/core/stackFrames.js +34 -0
- package/core/stacks.js +166 -0
- package/core/startup.js +153 -11
- package/core/streamSources.js +0 -11
- package/core/styleParts.js +65 -47
- package/core/targeting.js +1 -1
- package/core/textureBytes.js +20 -0
- package/core/thingExplain.js +2 -2
- package/core/thingOps.js +29 -6
- package/core/things.js +21 -11
- package/core/threadPure.js +7 -3
- package/core/threePatches.js +47 -0
- package/core/tier.js +21 -10
- package/core/time.js +236 -0
- package/core/uiClock.js +25 -0
- package/core/util.js +7 -1
- package/core/validate.js +65 -86
- package/core/wrap.js +106 -0
- package/docs/AI.md +89 -97
- package/docs/API.md +32 -28
- package/docs/CODEMAP.md +224 -149
- package/docs/COMMANDS.md +57 -34
- package/docs/CONVENTIONS.md +92 -30
- package/docs/MIGRATING-0.3.md +248 -0
- package/docs/MIGRATING-0.4.md +228 -0
- package/docs/MIGRATING-0.5.md +68 -0
- package/docs/PERF.md +35 -7
- package/docs/THREE.md +79 -27
- package/docs/api/ambience.md +0 -1
- package/docs/api/assets.md +12 -9
- package/docs/api/audio.md +10 -14
- package/docs/api/calendar.md +41 -0
- package/docs/api/cameraRig.md +16 -5
- package/docs/api/characters.md +41 -25
- package/docs/api/clock.md +6 -5
- package/docs/api/collision.md +9 -6
- package/docs/api/content.md +6 -4
- package/docs/api/dialogue.md +9 -9
- package/docs/api/engine.md +65 -62
- package/docs/api/events.md +19 -14
- package/docs/api/grids.md +3 -3
- package/docs/api/ground.md +1 -1
- package/docs/api/hud.md +2 -2
- package/docs/api/i18n.md +1 -1
- package/docs/api/input.md +11 -6
- package/docs/api/interactions.md +7 -5
- package/docs/api/inventory.md +17 -16
- package/docs/api/level.md +0 -1
- package/docs/api/lightPool.md +3 -1
- package/docs/api/music.md +1 -1
- package/docs/api/nav.md +3 -0
- package/docs/api/openWorld.md +2 -1
- package/docs/api/particles.md +2 -2
- package/docs/api/photo.md +0 -2
- package/docs/api/pickups.md +15 -0
- package/docs/api/post.md +5 -4
- package/docs/api/quests.md +2 -3
- package/docs/api/rigid.md +16 -14
- package/docs/api/saves.md +6 -4
- package/docs/api/settings.md +2 -3
- package/docs/api/sky.md +11 -44
- package/docs/api/stream.md +1 -1
- package/docs/api/style.md +31 -29
- package/docs/api/terrain.md +9 -6
- package/docs/api/terrainLook.md +10 -0
- package/docs/api/timeline.md +3 -4
- package/docs/api/tools.md +30 -13
- package/docs/api/triggers.md +5 -10
- package/docs/api/vegetation.md +12 -8
- package/docs/api/vegetationLook.md +10 -0
- package/docs/api/water.md +4 -20
- package/docs/api/weather.md +5 -15
- package/docs/api/weatherLook.md +10 -0
- package/docs/api/world.md +2 -1
- package/docs/recipes/01-new-game.md +71 -59
- package/docs/recipes/02-npc.md +46 -29
- package/docs/recipes/03-items-pickups.md +38 -24
- package/docs/recipes/04-quests.md +34 -27
- package/docs/recipes/05-props-bake.md +154 -18
- package/docs/recipes/06-clock-events.md +100 -52
- package/docs/recipes/07-flow-scenes-pause.md +41 -10
- package/docs/recipes/08-weather-sky.md +146 -37
- package/docs/recipes/09-style.md +218 -0
- package/docs/recipes/10-blender-level.md +14 -2
- package/docs/recipes/11-vehicles.md +64 -7
- package/docs/recipes/13-animation.md +34 -10
- package/docs/recipes/14-custom-module.md +65 -34
- package/docs/recipes/15-perf.md +35 -6
- package/docs/recipes/16-dev-bridge.md +65 -41
- package/docs/recipes/18-world.md +21 -8
- package/docs/recipes/19-shooting-picking.md +12 -11
- package/docs/recipes/20-content-actions-save.md +63 -25
- package/docs/recipes/21-camera.md +49 -16
- package/docs/recipes/22-shop-gold.md +18 -18
- package/docs/recipes/23-ops.md +17 -11
- package/docs/recipes/26-ui-parts.md +61 -12
- package/docs/recipes/27-net.md +12 -6
- package/docs/recipes/28-terrain.md +35 -2
- package/docs/recipes/29-grid.md +71 -33
- package/docs/recipes/30-templates.md +64 -12
- package/docs/recipes/31-audio.md +20 -12
- package/docs/recipes/32-action-game.md +35 -2
- package/docs/recipes/34-environment-lighting.md +27 -4
- package/docs/recipes/35-style-from-reference.md +115 -51
- package/docs/recipes/36-sky-ground-plant-looks.md +37 -35
- package/docs/recipes/37-terrain-look-hooks.md +37 -15
- package/docs/recipes/38-environment-look-hooks.md +64 -48
- package/docs/recipes/40-scene.md +16 -13
- package/docs/recipes/41-thing-registry.md +11 -7
- package/docs/recipes/42-terrain-shape.md +3 -3
- package/docs/recipes/43-shader-patches-surface-looks.md +171 -74
- package/docs/recipes/44-water-weather-look-hooks.md +30 -21
- package/docs/recipes/45-cascaded-shadows.md +17 -8
- package/docs/recipes/46-blender-art-route.md +4 -4
- package/docs/recipes/47-island-snow-backdrop.md +11 -10
- package/docs/recipes/48-make-material.md +11 -6
- package/docs/recipes/49-game-module-contract.md +46 -33
- package/docs/recipes/50-own-renderer.md +2 -2
- package/docs/recipes/51-capability-catalog.md +4 -4
- package/docs/recipes/52-look.md +228 -54
- package/docs/recipes/53-ground-up-close.md +58 -0
- package/docs/recipes/54-three-idioms.md +88 -0
- package/docs/recipes/55-mods-time-wrap.md +112 -0
- package/docs/recipes/56-webgpu-tsl.md +260 -0
- package/docs/recipes/57-control.md +65 -0
- package/docs/recipes/58-input.md +57 -0
- package/docs/recipes/59-depth-post-effects.md +83 -0
- package/docs/recipes/60-judge-the-picture.md +55 -0
- package/examples/action/.threedog/content-index.json +1 -0
- package/examples/action/GAMEMAP.md +17 -13
- package/examples/action/assets.js +8 -0
- package/examples/action/content/actions.js +1 -1
- package/examples/action/content/audio.js +5 -5
- package/examples/action/look.js +1 -1
- package/examples/action/main.js +10 -13
- package/examples/action/models.js +24 -23
- package/examples/pullable.json +111 -0
- package/examples/rc2d/.threedog/content-index.json +1 -0
- package/examples/rc2d/GAMEMAP.md +83 -0
- package/examples/rc2d/README.md +52 -0
- package/examples/rc2d/main.js +63 -0
- package/examples/rc2d/rc2d.js +197 -0
- package/examples/rc2d/shaders.js +144 -0
- package/examples/sheepisland/.threedog/content-index.json +1 -0
- package/examples/sheepisland/GAMEMAP.md +13 -11
- package/examples/sheepisland/assets.js +5 -0
- package/examples/sheepisland/main.js +17 -12
- package/examples/sheepisland/style/index.js +6 -6
- package/examples/styletest/.threedog/content-index.json +1 -0
- package/examples/styletest/GAMEMAP.md +15 -16
- package/examples/styletest/assets.js +6 -0
- package/examples/styletest/content/npcs.js +1 -1
- package/examples/styletest/content/templates.js +1 -1
- package/examples/styletest/content/vegetation.js +1 -1
- package/examples/styletest/look.js +1 -1
- package/examples/styletest/main.js +18 -17
- package/examples/styletest/models.js +1 -1
- package/examples/styletest/params.js +3 -3
- package/examples/techniques/contact-shadows/README.md +92 -0
- package/examples/techniques/contact-shadows/contactShadows.js +51 -0
- package/examples/techniques/contact-shadows/main.js +53 -0
- package/examples/techniques/day-night-grade/README.md +86 -0
- package/examples/techniques/day-night-grade/dayNightGrade.js +76 -0
- package/examples/techniques/day-night-grade/main.js +51 -0
- package/examples/techniques/interior-light/README.md +103 -0
- package/examples/techniques/interior-light/interiorLight.js +45 -0
- package/examples/techniques/interior-light/main.js +124 -0
- package/examples/techniques/modular-building/README.md +125 -0
- package/examples/techniques/modular-building/kit.js +426 -0
- package/examples/techniques/modular-building/main.js +47 -0
- package/examples/techniques/night-lights/README.md +94 -0
- package/examples/techniques/night-lights/main.js +70 -0
- package/examples/techniques/night-lights/nightLights.js +91 -0
- package/examples/techniques/outlines-and-rim/README.md +59 -0
- package/examples/techniques/outlines-and-rim/main.js +84 -0
- package/examples/techniques/outlines-and-rim/outlines.js +64 -0
- package/examples/techniques/procedural-animation/README.md +77 -0
- package/examples/techniques/procedural-animation/creature.js +44 -0
- package/examples/techniques/procedural-animation/main.js +45 -0
- package/examples/techniques/procedural-animation/proceduralAnim.js +118 -0
- package/examples/techniques/procedural-surface/README.md +67 -0
- package/examples/techniques/procedural-surface/main.js +103 -0
- package/examples/techniques/procedural-surface/surface.js +120 -0
- package/examples/techniques/stylized-shading/README.md +75 -0
- package/examples/techniques/stylized-shading/main.js +93 -0
- package/examples/techniques/stylized-shading/shading.js +131 -0
- package/examples/techniques/sun-and-key-light/README.md +135 -0
- package/examples/techniques/sun-and-key-light/keyLight.js +53 -0
- package/examples/techniques/sun-and-key-light/main.js +95 -0
- package/examples/techniques/wet-road/README.md +99 -0
- package/examples/techniques/wet-road/main.js +68 -0
- package/examples/techniques/wet-road/wetRoad.js +209 -0
- package/examples/webgpu-tsl/.threedog/content-index.json +1 -0
- package/examples/webgpu-tsl/GAMEMAP.md +84 -0
- package/examples/webgpu-tsl/README.md +42 -0
- package/examples/webgpu-tsl/main.js +21 -0
- package/examples/webgpu-tsl/tslScene.js +75 -0
- package/examples/world/.threedog/content-index.json +1 -0
- package/examples/world/GAMEMAP.md +22 -15
- package/examples/world/art/humanoid.js +42 -0
- package/examples/world/art/index.js +11 -0
- package/examples/world/art/models.js +58 -0
- package/examples/world/art/shapes.js +9 -0
- package/examples/world/assets.js +6 -0
- package/examples/world/content/audio.js +5 -5
- package/examples/world/content/npcs.js +2 -2
- package/examples/world/content/props.js +1 -1
- package/examples/world/content/rules.js +1 -1
- package/examples/world/content/templates.js +1 -1
- package/examples/world/content/vegetation.js +1 -1
- package/examples/world/main.js +17 -13
- package/examples/world/style/index.js +61 -0
- package/examples/world/style/plugins/10-bloom.js +5 -0
- package/index.d.ts +50 -45
- package/index.js +27 -22
- package/llms.txt +20 -12
- package/modules/ambience/Ambience.js +34 -23
- package/modules/calendar/Calendar.js +163 -0
- package/modules/calendar/contract.js +21 -0
- package/modules/calendar/index.js +81 -0
- package/modules/{sky → calendar}/schedule.js +17 -16
- package/modules/calendar/seasons.js +55 -0
- package/modules/camera/FirstPersonCamera.js +6 -15
- package/modules/camera/FixedCamera.js +33 -15
- package/modules/camera/FollowCamera.js +90 -16
- package/modules/camera/RtsCamera.js +18 -17
- package/modules/camera/common.js +70 -19
- package/modules/camera/contract.js +17 -0
- package/modules/camera/projection.js +11 -24
- package/modules/characters/Character.js +196 -59
- package/modules/characters/NPC.js +87 -36
- package/modules/characters/assetModel.js +27 -8
- package/modules/characters/behaviors.js +2 -1
- package/modules/characters/contract.js +13 -0
- package/modules/characters/footsteps.js +1 -1
- package/modules/characters/index.js +87 -49
- package/modules/characters/moveHelpers.js +4 -5
- package/modules/characters/movers/common.js +97 -19
- package/modules/characters/movers/manual.js +20 -0
- package/modules/characters/movers/rapier.js +19 -16
- package/modules/characters/movers/simple.js +14 -11
- package/modules/characters/movers/support.js +172 -0
- package/modules/characters/npcAvoid.js +47 -42
- package/modules/characters/npcSim.js +12 -8
- package/modules/characters/npcView.js +44 -16
- package/modules/characters/pathAsync.js +7 -3
- package/modules/characters/playerStrings.js +4 -3
- package/modules/characters/proceduralRig.js +46 -10
- package/modules/characters/useModel.js +1 -1
- package/modules/characters/vehicle.contract.js +21 -0
- package/modules/characters/walkTo.js +21 -7
- package/modules/collision/Collision.js +65 -25
- package/modules/collision/grid.js +8 -6
- package/modules/content/explain.js +2 -2
- package/modules/content/fields.js +102 -0
- package/modules/content/ids.js +8 -6
- package/modules/content/index.js +97 -28
- package/modules/content/loader.js +45 -33
- package/modules/content/models.js +11 -40
- package/modules/content/packs.js +6 -5
- package/modules/content/parts.js +41 -0
- package/modules/content/props.js +16 -9
- package/modules/content/rules.js +58 -0
- package/modules/content/stages.js +80 -0
- package/modules/content/templates.js +121 -30
- package/modules/debug/DebugPanel.js +24 -17
- package/modules/flow/contract.js +16 -0
- package/modules/flow/index.js +21 -15
- package/modules/gameplay/Container.js +41 -32
- package/modules/gameplay/Containers.js +30 -15
- package/modules/gameplay/Dialogue.js +113 -55
- package/modules/gameplay/Interactions.js +193 -67
- package/modules/gameplay/Inventory.js +69 -73
- package/modules/gameplay/Quests.js +75 -39
- package/modules/gameplay/boxOps.js +3 -3
- package/modules/gameplay/dialogue.contract.js +21 -0
- package/modules/gameplay/dialogueBox.js +4 -2
- package/modules/gameplay/dialogueBubbles.js +116 -0
- package/modules/gameplay/interactionPrompt.js +4 -1
- package/modules/gameplay/interactions.contract.js +16 -0
- package/modules/gameplay/inventory.contract.js +23 -0
- package/modules/gameplay/inventoryOps.js +18 -16
- package/modules/gameplay/pickups.js +268 -85
- package/modules/gameplay/questLog.js +4 -4
- package/modules/gameplay/quests.contract.js +17 -0
- package/modules/grid/Grid.js +92 -50
- package/modules/grid/Layer.js +14 -13
- package/modules/grid/index.js +60 -36
- package/modules/grid/ops.js +20 -18
- package/modules/grid/preview.js +15 -16
- package/modules/grid/strings.js +12 -0
- package/modules/grid/tiles.js +6 -5
- package/modules/hlod/index.js +51 -19
- package/modules/hud/index.js +35 -20
- package/modules/hud/parts.js +20 -7
- package/modules/level/heightfield.js +3 -1
- package/modules/level/index.js +45 -20
- package/modules/level/nodes.js +4 -3
- package/modules/lights/index.js +42 -18
- package/modules/music/Music.js +38 -21
- package/modules/music/rules.js +1 -1
- package/modules/nav/index.js +48 -42
- package/modules/net/Client.js +13 -6
- package/modules/net/Host.js +19 -5
- package/modules/net/Net.js +2 -1
- package/modules/net/index.js +13 -8
- package/modules/net/sync.js +9 -8
- package/modules/net/transports.js +77 -27
- package/modules/particles/Particles.js +23 -14
- package/modules/particles/contract.js +17 -0
- package/modules/particles/effect.js +39 -11
- package/modules/photo/Photo.js +53 -36
- package/modules/rigid/RigidBodies.js +194 -32
- package/modules/rigid/Vehicles.js +18 -15
- package/modules/rigid/sync.js +62 -17
- package/modules/settings/Settings.js +57 -52
- package/modules/settings/apply.js +38 -3
- package/modules/settings/sections.js +5 -3
- package/modules/settings/strings.js +3 -2
- package/modules/settings/view.js +5 -3
- package/modules/sky/Sky.js +88 -176
- package/modules/sky/cascades.js +86 -25
- package/modules/sky/cascades.tsl.js +82 -0
- package/modules/sky/clouds.js +34 -19
- package/modules/sky/domeLayers.js +30 -15
- package/modules/sky/environment.js +83 -13
- package/modules/sky/fog.js +140 -95
- package/modules/sky/frame.js +112 -44
- package/modules/sky/look.js +22 -19
- package/modules/sky/lookFog.js +48 -52
- package/modules/sky/lookShadow.js +53 -41
- package/modules/sky/lookSky.js +82 -21
- package/modules/sky/season.js +21 -0
- package/modules/sky/shader.js +41 -19
- package/modules/sky/shadow.js +44 -20
- package/modules/sky/skyModule.js +45 -33
- package/modules/sky/tint.js +61 -0
- package/modules/terrain/ChunkManager.js +175 -108
- package/modules/terrain/chunkJob.js +1 -1
- package/modules/terrain/chunkQueries.js +6 -4
- package/modules/terrain/index.js +105 -50
- package/modules/terrain/look.js +83 -0
- package/modules/terrain/lookGround.js +21 -16
- package/modules/terrain/terrainDefaults.js +1 -1
- package/modules/terrain/terrainEdit.js +18 -20
- package/modules/terrain/terrainGen.js +5 -3
- package/modules/terrain/terrainIsland.js +5 -4
- package/modules/terrain/terrainShape.js +12 -12
- package/modules/terrain/terrainShapeMain.js +8 -7
- package/modules/terrain/terrainTexture.js +21 -19
- package/modules/timeline/Timeline.js +95 -43
- package/modules/timeline/Tween.js +18 -10
- package/modules/timeline/letterbox.js +2 -2
- package/modules/timeline/shots.js +5 -1
- package/modules/triggers/index.js +107 -76
- package/modules/vegetation/Vegetation.js +190 -102
- package/modules/vegetation/densityMap.js +62 -0
- package/modules/vegetation/groundChunks.js +52 -58
- package/modules/vegetation/index.js +31 -10
- package/modules/vegetation/look.js +119 -0
- package/modules/vegetation/lookWind.js +71 -10
- package/modules/vegetation/modelGeometry.js +3 -2
- package/modules/vegetation/nearFade.js +45 -0
- package/modules/water/Water.js +65 -27
- package/modules/water/look.js +29 -18
- package/modules/water/surface.js +64 -25
- package/modules/water/surfaceDefaults.js +3 -0
- package/modules/weather/Weather.js +62 -104
- package/modules/weather/look.js +1 -2
- package/modules/weather/particles.js +24 -9
- package/modules/weather/strings.js +2 -2
- package/modules/weather/weatherLook.js +135 -0
- package/modules/world/World.js +24 -7
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +18 -4
- package/modules/world/persist.js +62 -2
- package/modules/world/pos.js +3 -2
- package/modules/world/records.js +8 -6
- package/modules/world/sim.js +60 -20
- package/modules/world/simFar.js +4 -3
- package/modules/world/state.js +3 -2
- package/modules/world/thingSource.js +1 -1
- package/modules/world/views.js +7 -5
- package/package.json +8 -3
- package/presets.js +41 -27
- package/render/PostFX.js +145 -120
- package/render/backend.js +440 -0
- package/render/detail.js +150 -45
- package/render/effects.js +130 -38
- package/render/engineUniforms.js +10 -1
- package/render/fuse.js +5 -4
- package/render/fx/cloudShadow.tsl.js +16 -0
- package/render/fx/detail.tsl.js +66 -0
- package/render/fx/index.js +26 -0
- package/render/fx/lighting.tsl.js +28 -0
- package/render/fx/nodeErrors.tsl.js +68 -0
- package/render/fx/noise.tsl.js +12 -0
- package/render/fx/objectOrigin.tsl.js +42 -0
- package/render/fx/particles.tsl.js +139 -0
- package/render/fx/patchNodes.tsl.js +403 -0
- package/render/fx/postWebGPU.tsl.js +158 -0
- package/render/fx/season.tsl.js +13 -0
- package/render/fx/sky.tsl.js +260 -0
- package/render/fx/uniforms.tsl.js +67 -0
- package/render/fx/water.tsl.js +53 -0
- package/render/fx/wind.tsl.js +22 -0
- package/render/fxNumbers.js +36 -0
- package/render/hotGlsl.js +24 -0
- package/render/lighting.js +66 -14
- package/render/lights.js +223 -4
- package/render/lookGlow.js +139 -0
- package/render/lookSurface.js +99 -36
- package/render/materials.js +71 -52
- package/render/modeling.js +73 -0
- package/render/ownFrame.js +76 -0
- package/render/patches.js +311 -34
- package/render/postLook.js +124 -46
- package/render/postWebGL.js +197 -0
- package/render/probes.js +231 -0
- package/render/shaderErrors.js +154 -0
- package/render/slots.js +165 -0
- package/render/surface.js +53 -17
- package/render/terms.js +211 -0
- package/render/uniformDecl.js +3 -2
- package/types/common.d.ts +2 -2
- package/types/core.d.ts +620 -244
- package/types/gameplay.d.ts +494 -318
- package/types/generated/core/Audio.d.ts +26 -42
- package/types/generated/core/Batching.d.ts +6 -2
- package/types/generated/core/Budget.d.ts +2 -8
- package/types/generated/core/DebugOverrides.d.ts +44 -3
- package/types/generated/core/I18n.d.ts +2 -2
- package/types/generated/core/Input.d.ts +102 -31
- package/types/generated/core/Ops.d.ts +31 -0
- package/types/generated/core/Random.d.ts +2 -2
- package/types/generated/core/Saves.d.ts +10 -2
- package/types/generated/core/Stream.d.ts +1 -1
- package/types/generated/core/Threads.d.ts +4 -1
- package/types/generated/core/Views.d.ts +0 -1
- package/types/generated/core/audioVoice.d.ts +17 -9
- package/types/generated/core/control.d.ts +55 -0
- package/types/generated/core/session.d.ts +2 -1
- package/types/generated/modules/ambience/Ambience.d.ts +0 -9
- package/types/generated/modules/calendar/Calendar.d.ts +84 -0
- package/types/generated/modules/calendar/index.d.ts +10 -0
- package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
- package/types/generated/modules/grid/Grid.d.ts +61 -25
- package/types/generated/modules/grid/Layer.d.ts +5 -5
- package/types/generated/modules/grid/index.d.ts +29 -17
- package/types/generated/modules/music/Music.d.ts +5 -3
- package/types/generated/modules/net/index.d.ts +3 -3
- package/types/generated/modules/net/transports.d.ts +12 -3
- package/types/generated/modules/particles/Particles.d.ts +1 -1
- package/types/generated/modules/sky/Sky.d.ts +12 -104
- package/types/generated/modules/sky/skyModule.d.ts +1 -1
- package/types/generated/modules/timeline/Timeline.d.ts +8 -6
- package/types/generated/modules/weather/Weather.d.ts +17 -18
- package/types/generated/modules/weather/weatherLook.d.ts +12 -0
- package/types/generated/modules/world/World.d.ts +18 -3
- package/types/generated/render/PostFX.d.ts +67 -30
- package/types/generated/render/materials.d.ts +26 -20
- package/types/generated/render/modeling.d.ts +30 -0
- package/types/generated/render/patches.d.ts +16 -2
- package/types/generated/ui/UI.d.ts +6 -3
- package/types/nav.d.ts +6 -0
- package/types/physics.d.ts +137 -44
- package/types/style.d.ts +125 -92
- package/types/tsl.d.ts +86 -0
- package/types/world.d.ts +164 -110
- package/ui/Focus.js +25 -14
- package/ui/LoadingScreen.js +1 -1
- package/ui/Parts.js +27 -11
- package/ui/UI.js +20 -10
- package/ui/cursor.js +115 -0
- package/ui/defaults.js +15 -11
- package/ui/theme.js +9 -6
- package/ui/touchPart.js +1 -1
- package/core/claims.js +0 -51
- package/core/look/layers.js +0 -136
- package/core/renamed.js +0 -21
- package/docs/api/entities.md +0 -61
- package/docs/recipes/09-style-pack.md +0 -234
- package/examples/styletest/overrides.js +0 -33
- package/examples/styletest/panel.js +0 -135
- package/modules/entities/Entities.js +0 -243
- package/modules/entities/build.js +0 -25
- package/modules/entities/index.js +0 -4
- package/modules/sky/calendar.js +0 -80
- package/modules/sky/layers.js +0 -69
- package/modules/terrain/chunkLevels.js +0 -40
- package/modules/terrain/mountTerrain.js +0 -32
- package/modules/world/cells.js +0 -42
package/core/thingOps.js
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
// engine.add. Why both go through ops: a change then has undo, lands in the op log and is checked by can(), whichever system owns the object.
|
|
4
4
|
// For a record the ops turn into world.set / world.move / world.remove (the model follows the record); for a plain object they write the transform and,
|
|
5
5
|
// when the object has a stable id and is rebuilt by code at setup, record it as an override in the 'scene' save part (things.js).
|
|
6
|
-
import { Things, snap, write } from './things.js';
|
|
7
|
-
import { closest } from './validate.js';
|
|
6
|
+
import { Things, snap, write, moduleOwnerOf } from './things.js';
|
|
7
|
+
import { closest, DEV } from './validate.js';
|
|
8
|
+
import { onSceneRoot } from './sceneDelta.js';
|
|
8
9
|
import { codedError } from './errorHints.js';
|
|
9
10
|
import { explainThing } from './thingExplain.js';
|
|
10
11
|
|
|
@@ -23,7 +24,7 @@ function editText(en, tier, rec) {
|
|
|
23
24
|
if (tier === 'engine') return `managed by ${en.owner}: change it through that module, not directly`;
|
|
24
25
|
if (tier === 'code') return `added by code${at} (id '${en.id}'): to change it for good edit that line; thing.set changes are saved as overrides`;
|
|
25
26
|
if (!en.stable) return `added by code${at} without an id: give it one at setup (engine.add(obj, { id: 'name' })) to save thing.set changes; now they last this session only`;
|
|
26
|
-
return `made during play${en.op ? ` by op ${en.op}` : ''}${at}: to keep it, make it a template and create it inside the op with engine.spawn(name, at)`;
|
|
27
|
+
return `made during play${en.op ? ` by op ${en.op}` : ''}${at}: to keep it, make it a template and create it inside the op with engine.content.spawn(name, at)`;
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
/** thing.explain(): the whole story of the id in one object (thingExplain.js); a method, not a field, so the thing stays small */
|
|
@@ -81,6 +82,30 @@ const uni = s => typeof s === 'number' ? s : s[0];
|
|
|
81
82
|
/** Register the registry, engine.thing's ops, the 'scene' save part and the session:start setup window (called once by the Engine constructor) */
|
|
82
83
|
export function installThings(e) {
|
|
83
84
|
const T = e._things = new Things(e);
|
|
85
|
+
// Adopt-on-add: plain three.js scene.add(obj) registers obj exactly as engine.add(obj) does (engine.thing, describe().scene, thing.set /
|
|
86
|
+
// remove, the save tier), because the owner's rule is that what the engine can see it plugs in without an extra call. Only roots right
|
|
87
|
+
// under the scene: a child added to a root belongs to that root's entry (entryOf walks up). engine.add registers before it attaches,
|
|
88
|
+
// so its options win; a module's own objects carry their module owner (engineOwned) and never count as the game's.
|
|
89
|
+
e._adoptAdds = onSceneRoot(e.scene, o => {
|
|
90
|
+
if (T.byObj.has(o)) return;
|
|
91
|
+
const owner = moduleOwnerOf(o);
|
|
92
|
+
let stack = null;
|
|
93
|
+
if (DEV && !owner && T.wantStack()) { // frame 0 here, 1 the Object3D.add hook, 2 the game line that called scene.add
|
|
94
|
+
const lim = Error.stackTraceLimit; Error.stackTraceLimit = 4;
|
|
95
|
+
try { stack = new Error(); } finally { Error.stackTraceLimit = lim; }
|
|
96
|
+
}
|
|
97
|
+
T.add(o, owner ? { owner } : null, stack);
|
|
98
|
+
}, o => {
|
|
99
|
+
// Release-on-remove: a root with no stable id taken off the scene (scene.remove of a bullet) is forgotten, else a game adding and
|
|
100
|
+
// removing ten bullets a second grew byId by 36 000 entries an hour, all walked by describe(). Checked after the current code finishes
|
|
101
|
+
// (a microtask), so a remove and re-add on the same line (three's add detaches first, a move between parents) keeps its id;
|
|
102
|
+
// thing.remove's held objects and objects with an id stay (they may come back, the save names them).
|
|
103
|
+
const en = T.byObj.get(o);
|
|
104
|
+
if (!en || en.stable || T.gone.has(en.id) || !(en.owner === 'game' || en.owner.startsWith('engine:'))) return;
|
|
105
|
+
queueMicrotask(() => { let r = o; while (r.parent) r = r.parent; if (r !== e.scene && T.byObj.get(o) === en) T.forget(o); });
|
|
106
|
+
});
|
|
107
|
+
// what a module put in the scene before the registry existed (the default sun and hemisphere are made first) gets its module owner too
|
|
108
|
+
for (const o of e.scene.children) { const owner = moduleOwnerOf(o); if (owner && !T.byObj.has(o)) T.add(o, { owner }, null); }
|
|
84
109
|
T.explainers = []; // explain contributions from modules (see thingExplain.js)
|
|
85
110
|
/**
|
|
86
111
|
* Add a contribution to engine.thing(id).explain(): fn(engine, thing, out) may fill out.state / out.rules (or add keys) for the things its module owns.
|
|
@@ -89,8 +114,6 @@ export function installThings(e) {
|
|
|
89
114
|
* @example engine.explainWith((e, t, out) => { const r = e.myRecords.get(t.id); if (r) out.state = { ...r }; });
|
|
90
115
|
*/
|
|
91
116
|
e.explainWith = fn => { T.explainers.push(fn); };
|
|
92
|
-
// content() replaces this; without it a bare "spawn is not a function" would not say which module to install
|
|
93
|
-
e.spawn = () => { throw new Error("engine.spawn needs the content module: add content() to engine.use(...) (import { content } from 'threedog')"); };
|
|
94
117
|
e.saves.register('scene', { atomic: true, save: () => T.save(), load: d => T.load(d) });
|
|
95
118
|
const kindOf = id => T.source(id) ? 'record' : T.live(id) ? T.tier(T.byObj.get(T.live(id))) : null;
|
|
96
119
|
const reasons = {
|
|
@@ -164,5 +187,5 @@ export function thing(e, q) {
|
|
|
164
187
|
const t = findThing(e, q);
|
|
165
188
|
if (t) return t;
|
|
166
189
|
const what = typeof q === 'string' ? `'${q}'` : q?.isObject3D ? `an unregistered ${q.type}` : JSON.stringify(q);
|
|
167
|
-
throw codedError('thing-id', `engine.thing(${what}): nothing has this id or name${typeof q === 'string' ? hintThing(e, q) : ''}. Pass a world record id, the id given to engine.add(obj, { id }), an object name or any Object3D
|
|
190
|
+
throw codedError('thing-id', `engine.thing(${what}): nothing has this id or name${typeof q === 'string' ? hintThing(e, q) : ''}. Pass a world record id, the id given to engine.add(obj, { id }), an object name or any Object3D in engine.scene (scene.add and engine.add both register; an object not in the scene is not)`);
|
|
168
191
|
}
|
package/core/things.js
CHANGED
|
@@ -6,18 +6,28 @@
|
|
|
6
6
|
// { set: { id: { position?, rotation?, scale?, visible? } }, removed: [id] }; ids a save names before the object exists wait in pending.
|
|
7
7
|
import { DEV, warnOnce } from './validate.js';
|
|
8
8
|
import { codedError, coded } from './errorHints.js';
|
|
9
|
+
import { stackFrames, frameText } from './stackFrames.js';
|
|
9
10
|
|
|
10
11
|
/** Stacks taken per session in dev: bullets or debris added every frame must not slow dev builds down for a file:line nobody reads */
|
|
11
12
|
const STACK_CAP = 2000;
|
|
12
13
|
const KEYS = ['position', 'rotation', 'scale', 'visible'];
|
|
13
|
-
|
|
14
|
+
/** 'main.js:50' from a captured Error: frame 0 is captureStack, 1 engine.add (or the scene.add hook), 2 its caller; the host part of a URL is dropped */
|
|
15
|
+
function stackAt(err) { const f = stackFrames(err?.stack)[2]; return f ? frameText(f) : null; }
|
|
14
16
|
|
|
15
|
-
/**
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Objects an engine module puts in the scene itself (sky dome, terrain chunks, default lights): owner name per object. A plain scene.add is
|
|
19
|
+
* adopted as a game object, so a module that adds with scene.add (often before engine.add exists, at construction) marks its objects here
|
|
20
|
+
* and they are registered under their module instead of showing up as the game's. A WeakMap: nothing is held after the object is dropped.
|
|
21
|
+
*/
|
|
22
|
+
const MODULE_OWNER = new WeakMap();
|
|
23
|
+
/**
|
|
24
|
+
* Mark objects as an engine module's before scene.add (returns the first, so it fits in the call). For module code; a game never needs it.
|
|
25
|
+
* @example scene.add(engineOwned('sky', this.dome));
|
|
26
|
+
* @template {import('three').Object3D} T @param {string} module @param {[T, ...import('three').Object3D[]]} objs @returns {T}
|
|
27
|
+
*/
|
|
28
|
+
export function engineOwned(module, ...objs) { for (const o of objs) MODULE_OWNER.set(o, `engine:${module}`); return objs[0]; }
|
|
29
|
+
/** The module owner engineOwned gave obj, else undefined @param {any} obj */
|
|
30
|
+
export const moduleOwnerOf = obj => MODULE_OWNER.get(obj);
|
|
21
31
|
|
|
22
32
|
/** One registered root. `at` parses the stack the first time it is read (V8 formats a stack only when .stack is read) */
|
|
23
33
|
class Entry {
|
|
@@ -103,7 +113,7 @@ export class Things {
|
|
|
103
113
|
tier(en) { return en.owner === 'world' ? 'record' : en.owner !== 'game' ? 'engine' : en.stable && en.phase === 'setup' ? 'code' : 'session'; }
|
|
104
114
|
|
|
105
115
|
/**
|
|
106
|
-
* Register one root (engine.add). owner: 'game' (default) | 'world' | 'level' | 'stream' | 'engine:<module>'. Re-adding a detached object keeps its entry.
|
|
116
|
+
* Register one root (engine.add). owner: 'game' (default) | 'world' | 'level' | 'stream' | 'engine:<module>'. Re-adding a detached object keeps its entry (one with a stable id; one without is forgotten once it leaves the scene, thingOps.js).
|
|
107
117
|
* @param {any} obj @param {{ id?: string, owner?: string, save?: boolean } | null} opts @param {Error | null} stack
|
|
108
118
|
*/
|
|
109
119
|
add(obj, opts, stack) {
|
|
@@ -118,7 +128,7 @@ export class Things {
|
|
|
118
128
|
if (owner === 'game') this.adopt(obj, en);
|
|
119
129
|
return en;
|
|
120
130
|
}
|
|
121
|
-
/** engine.remove
|
|
131
|
+
/** engine.remove, or a root without a stable id that left the scene (thingOps.js): forget the entry */
|
|
122
132
|
forget(obj) {
|
|
123
133
|
const en = this.byObj.get(obj); if (!en) return;
|
|
124
134
|
this.byObj.delete(obj);
|
|
@@ -130,7 +140,7 @@ export class Things {
|
|
|
130
140
|
const tier = this.tier(en);
|
|
131
141
|
if (tier === 'session' && (en.save === true || en.op)) {
|
|
132
142
|
this.unsaved.add(new WeakRef(obj));
|
|
133
|
-
if (DEV && en.save === true) warnOnce(coded('thing-unsaved', `engine.add(obj, { save: true })${en.at ? ` at ${en.at}` : ''}: this object cannot be saved (${en.stable ? 'it was made during play' : 'it has no stable id'}), so it will not come back after a load. Give it an id and add it at setup (engine.add(obj, { id: 'name' })), or make it a template and create it inside an op with engine.spawn(name, at)`));
|
|
143
|
+
if (DEV && en.save === true) warnOnce(coded('thing-unsaved', `engine.add(obj, { save: true })${en.at ? ` at ${en.at}` : ''}: this object cannot be saved (${en.stable ? 'it was made during play' : 'it has no stable id'}), so it will not come back after a load. Give it an id and add it at setup (engine.add(obj, { id: 'name' })), or make it a template and create it inside an op with engine.content.spawn(name, at)`));
|
|
134
144
|
}
|
|
135
145
|
if (tier === 'code') this.applySaved(obj, en.id);
|
|
136
146
|
}
|
|
@@ -202,7 +212,7 @@ export class Things {
|
|
|
202
212
|
}
|
|
203
213
|
warnLost(where) {
|
|
204
214
|
const l = this.lost(); if (!l.length) return;
|
|
205
|
-
warnOnce(coded('thing-unsaved', `${where}: ${l.length} object(s) added with engine.add during play will not come back after a load (${l.slice(0, 5).map(en => `${en.id}${en.at ? ` at ${en.at}` : ''}${en.op ? ` in op ${en.op}` : ''}`).join(', ')}). To keep such things, make them a template and create them inside the op with engine.spawn(name, at)`));
|
|
215
|
+
warnOnce(coded('thing-unsaved', `${where}: ${l.length} object(s) added with engine.add during play will not come back after a load (${l.slice(0, 5).map(en => `${en.id}${en.at ? ` at ${en.at}` : ''}${en.op ? ` in op ${en.op}` : ''}`).join(', ')}). To keep such things, make them a template and create them inside the op with engine.content.spawn(name, at)`));
|
|
206
216
|
}
|
|
207
217
|
/** Dev finding: two systems manage one object (kept for describe().scene.conflicts, warned once per text) */
|
|
208
218
|
conflict(text) {
|
package/core/threadPure.js
CHANGED
|
@@ -5,11 +5,15 @@ const PURE_STRINGS = {
|
|
|
5
5
|
native: '{label}: must be a written-out function (not a built-in, bound or class method); it is sent to a worker as source text',
|
|
6
6
|
async: '{label}: cannot be async or a generator; a worker batch needs the result immediately',
|
|
7
7
|
parse: '{label}: could not be recompiled from its source text ({msg}); write it as (rec, dt) => { ... } or function (rec, dt) { ... }',
|
|
8
|
-
closure: '{label} runs in a worker
|
|
8
|
+
closure: '{label} runs in a worker, so closures are not supported (outer variables are not sent with the source text); it only sees its own parameters and globals like Math: {msg}. {fix}',
|
|
9
|
+
fixRecord: 'Put constants inside the function, or store the value on the record',
|
|
10
|
+
// terrain functions get settings as data: terrain({ params }) arrives as n.params in every worker (modules/terrain)
|
|
11
|
+
fixTerrain: 'Pass the values as data instead: terrain({ params: { hill: 30 }, height: (x, z, n) => n.params.hill * n.fbm(x * 0.004, z * 0.004) }), or put constants inside the function',
|
|
9
12
|
unknown: '[threads] pure function {key} was not defined in this worker',
|
|
10
13
|
};
|
|
11
14
|
const fmt = (s, o) => s.replace(/\{(\w+)\}/g, (m, k) => o[k] ?? m); // own copy: this file stays import-free for workers
|
|
12
15
|
/** Errors carry the stable code 'pure-function' (errorHints.js) as err.code and a [pure-function] tag */
|
|
16
|
+
const fixFor = label => /^terrain/.test(label) ? PURE_STRINGS.fixTerrain : PURE_STRINGS.fixRecord;
|
|
13
17
|
const pureError = msg => Object.assign(new Error(msg + ' [pure-function]'), { code: 'pure-function' });
|
|
14
18
|
|
|
15
19
|
/**
|
|
@@ -30,10 +34,10 @@ export function compilePure(fnOrSrc, label) {
|
|
|
30
34
|
}
|
|
31
35
|
const free = freeNames(used);
|
|
32
36
|
// caught here, not on the first call: in a worker that call happens steps later and far from the line that registered the function
|
|
33
|
-
if (free.length) throw pureError(fmt(PURE_STRINGS.closure, { label, msg: `it reads ${free.map(n => `'${n}'`).join(', ')}, which is neither its parameter nor a global` }));
|
|
37
|
+
if (free.length) throw pureError(fmt(PURE_STRINGS.closure, { label, fix: fixFor(label), msg: `it reads ${free.map(n => `'${n}'`).join(', ')}, which is neither its parameter nor a global` }));
|
|
34
38
|
const call = (...args) => {
|
|
35
39
|
try { return fn(...args); } catch (err) {
|
|
36
|
-
if (err instanceof ReferenceError) throw pureError(fmt(PURE_STRINGS.closure, { label, msg: err.message }));
|
|
40
|
+
if (err instanceof ReferenceError) throw pureError(fmt(PURE_STRINGS.closure, { label, fix: fixFor(label), msg: err.message }));
|
|
37
41
|
throw err;
|
|
38
42
|
}
|
|
39
43
|
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Every change the engine makes to three.js itself or to the game's own three.js objects, in one list: describe().threePatches shows them,
|
|
2
|
+
// threePatches.off(id) undoes one (when it can be undone).
|
|
3
|
+
// Why a list: "three.js stays fully writable" means a game can see every place the engine reaches into three's own classes, objects or
|
|
4
|
+
// renderer and turn it off, instead of finding it by surprise (an accessor in devtools, another library's Object3D.add wrapper stacking on
|
|
5
|
+
// the engine's). THREE.md "Global changes" says what each one does to the game's own code. Every change made anywhere is noted here where
|
|
6
|
+
// it is made; a change that cannot be undone is still listed, with why (off(id) then throws and says what it would cost).
|
|
7
|
+
// threePatches.list() // [{ id, what, scope, on, offable, lost }]
|
|
8
|
+
// threePatches.off('shadow-accessors') // three's own behavior again (moving patches then cast still shadows)
|
|
9
|
+
// Page-wide on purpose: a prototype is shared by every engine on the page, so the switch is too.
|
|
10
|
+
import { codedError } from './errorHints.js';
|
|
11
|
+
|
|
12
|
+
const KEY = Symbol.for('threedog.threePatches'); // global: a second copy of a file (hot reload) re-registers the same id instead of a second entry
|
|
13
|
+
/** @typedef {{ id: string, what: string, scope: string, on: boolean, offable: boolean, lost: string, off: (() => void) | null }} PatchEntry */
|
|
14
|
+
/** @type {Map<string, PatchEntry>} */
|
|
15
|
+
const reg = globalThis[KEY] ??= new Map();
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Record one change to three.js (engine code calls this where it makes the change).
|
|
19
|
+
* @param {string} id short stable name ('shadow-accessors')
|
|
20
|
+
* @param {string} what one line: which member of what, and why
|
|
21
|
+
* @param {(() => void) | null} off puts three's original back; null when it cannot be undone (say why in opts.lost)
|
|
22
|
+
* @param {{ scope?: string, lost?: string }} [opts] scope: what it reaches ('page' default: a three.js class or shared table;
|
|
23
|
+
* 'objects in the scene', 'engine renderer'); lost: what stops working when it is off (or, with off null, why it stays)
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
export function notePatch(id, what, off, { scope = 'page', lost = '' } = {}) { reg.set(id, { id, what, scope, on: true, offable: !!off, lost, off }); }
|
|
27
|
+
/**
|
|
28
|
+
* Whether a change is still on: the switch of a change that is applied object by object as they appear (its off() then only flips this,
|
|
29
|
+
* and the code that applies it asks here). Page-wide like the list. @param {string} id @returns {boolean} @internal
|
|
30
|
+
*/
|
|
31
|
+
export const patchOn = id => reg.get(id)?.on !== false;
|
|
32
|
+
|
|
33
|
+
export const threePatches = {
|
|
34
|
+
/** Every change the engine made to three.js: [{ id, what, scope, on, offable, lost }] @returns {{ id: string, what: string, scope: string, on: boolean, offable: boolean, lost: string }[]} */
|
|
35
|
+
list: () => [...reg.values()].map(({ id, what, scope, on, offable, lost }) => ({ id, what, scope, on, offable, lost })),
|
|
36
|
+
/**
|
|
37
|
+
* Undo one change page-wide (three's original member again). Call it before creating the objects that should not see it.
|
|
38
|
+
* @param {string} id
|
|
39
|
+
* @returns {void}
|
|
40
|
+
*/
|
|
41
|
+
off(id) {
|
|
42
|
+
const p = reg.get(id);
|
|
43
|
+
if (!p) throw codedError('unknown-name', `threePatches.off('${id}'): no such change; the changes are ${[...reg.keys()].join(', ') || 'none'}`);
|
|
44
|
+
if (!p.off) throw codedError('engine-misuse', `threePatches.off('${id}'): this change cannot be undone (${p.lost}); it is listed so it can be seen`);
|
|
45
|
+
if (p.on) { p.off(); p.on = false; }
|
|
46
|
+
},
|
|
47
|
+
};
|
package/core/tier.js
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
|
-
// Device tier:
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
// Device tier: tool pages' forced tier, render scale per tier. Detection is render/backend.js tier() (the GPU name is read per renderer).
|
|
2
|
+
//
|
|
3
|
+
// Headless tool pages (shot, gallery, capture) pass ?threedog-tier=high|low. Why: the headless browser reports SwiftShader or the machine's
|
|
4
|
+
// integrated GPU, so detection called every tool page "low" and costly post (ao, bloom) silently dropped out of the picture, which then did not
|
|
5
|
+
// show the game's look. The tool says which tier it rendered at; tests pass nothing and keep their detected (deterministic) tier.
|
|
6
|
+
const TIERS = ['low', 'high'];
|
|
7
|
+
|
|
8
|
+
/** The tier a headless tool page asks for (?threedog-tier=low|high), or null (the tools check the value: shot --tier fails on anything else). */
|
|
9
|
+
export function forcedTier(search = typeof location === 'undefined' ? '' : location.search) {
|
|
10
|
+
const t = new URLSearchParams(search).get('threedog-tier');
|
|
11
|
+
return TIERS.includes(t) ? t : null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Default render scale. High tier: the display scale up to 1.5. Low tier: at least 0.75 x display scale (1.5 on a 2x screen; a fixed 1 there
|
|
16
|
+
* would be an upscaled blurry picture), never above 1.5 or the display scale.
|
|
17
|
+
* @param {number} dpr @param {string} tier
|
|
18
|
+
*/
|
|
19
|
+
export function defaultPixelRatio(dpr, tier) {
|
|
20
|
+
const cap = Math.min(dpr, 1.5);
|
|
21
|
+
return tier === 'low' ? Math.min(cap, Math.max(1, +(0.75 * dpr).toFixed(2))) : cap;
|
|
11
22
|
}
|
package/core/time.js
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
// engine.time: the one time source. Every other time in the engine is a read-only view of what this module counts.
|
|
2
|
+
// engine.time.tick fixed steps run (the gameplay timeline: commits, op history, input records); stops while frozen
|
|
3
|
+
// engine.time.now('real') tick / 60 (+ the part of a skip shorter than one step): no scale, stops while frozen. Cooldowns that ignore bullet time
|
|
4
|
+
// engine.time.now('ambient') wind, water, clouds (= uniforms.uTime): moves while frozen too, unless a freezer asked freeze(owner, { ambient: true })
|
|
5
|
+
// engine.time.now('world' | 'player' | 'enemies' ...) channel seconds: each step adds 1/60 x the channel's speed. Movement, AI, status effects
|
|
6
|
+
// engine.time.now('calendar') calendar seconds = world seconds x the calendar rate (stack 'clock.rate'); engine.clock.now is the same number
|
|
7
|
+
// Channel speeds change only through engine.mod (core/stacks.js):
|
|
8
|
+
// engine.mod('time.enemies', { owner: 'bullet-time', mul: 0.35, for: 2 }); // bullet time: enemies at 35% for 2 real seconds
|
|
9
|
+
// engine.mod('time.local', { owner: 'stopwatch', id: 'e1', set: 0, layer: 'effect' }); // stop one record only
|
|
10
|
+
// engine.onFixed(dt => moveEnemies(dt), { channel: 'enemies' }); // this dt is already scaled
|
|
11
|
+
// Timers: one queue for every channel, written as engine.clock.after(s, fnOrEvent, data, { channel }) / clock.every (default channel 'calendar').
|
|
12
|
+
//
|
|
13
|
+
// Why one source: separate counters for real seconds, shader time, channels and the calendar, each added to and zeroed in its own place, drift
|
|
14
|
+
// apart (a skip that moves some, a new game that zeroes some; review 0.4, B). So only this file adds to any of them, and three entry points move them together: a fixed step (_beginStep / _endStep), engine.skip
|
|
15
|
+
// (_skip), and a new playthrough (_restart). A spec greps core/ and modules/ so no second counter comes back.
|
|
16
|
+
// Freeze is not "scale 0": a frozen engine runs no fixed step at all (loop.js), so tick, real, channels and timers stay put; only ambient moves.
|
|
17
|
+
// A plain onFixed without { channel } gets real seconds (always 1 / 60), so cooldowns and UI are never slowed by accident.
|
|
18
|
+
// Built in: world (the root), player (parent world), calendar (parent world, speed 'clock.rate'). Physics (rapier) has one world step and follows nothing here.
|
|
19
|
+
import { codedError } from './errorHints.js';
|
|
20
|
+
import { reportError } from './errors.js';
|
|
21
|
+
import { saveValues } from './saveValues.js';
|
|
22
|
+
|
|
23
|
+
export const STEP = 1 / 60;
|
|
24
|
+
const STRINGS = { where: 'clock timer', onMove: 'time.onMove listener' };
|
|
25
|
+
const EPS = 1e-9; // float sums of STEP x scale land a hair short of a whole second: due within 1e-9 counts as due
|
|
26
|
+
|
|
27
|
+
export class Time {
|
|
28
|
+
constructor(engine) {
|
|
29
|
+
this.engine = engine;
|
|
30
|
+
/** @internal whole fixed steps (public: tick) */ this._tick = 0;
|
|
31
|
+
/** @internal real seconds a skip moved past the last whole step (< STEP): kept so real stays exact after a skip */ this._carry = 0;
|
|
32
|
+
/** @internal ambient seconds (public: now('ambient'), uniforms.uTime) */ this._amb = 0;
|
|
33
|
+
/** @type {Map<string, { name: string, parent: string | null, now: number, stack: string }>} */
|
|
34
|
+
this._ch = new Map();
|
|
35
|
+
/** @internal listeners of onMove */ this._onMove = [];
|
|
36
|
+
/** @internal the one timer queue: { ch, due, fn?, event?, data?, every?, dead? } (due is in that channel's seconds) */ this._timers = [];
|
|
37
|
+
/** @internal saved now of channels the game has not defined yet (a load before channel()): applied when it does */ this._pending = {};
|
|
38
|
+
this._local = engine.stacks.define('time.local', { per: true, min: 0 });
|
|
39
|
+
engine.stacks._nowOf = name => this.now(name);
|
|
40
|
+
this.channel('world', { parent: null });
|
|
41
|
+
this.channel('player');
|
|
42
|
+
this.channel('calendar', { stack: 'clock.rate' });
|
|
43
|
+
engine.saves.register('time', {
|
|
44
|
+
version: 2,
|
|
45
|
+
// v1 kept the calendar in its own 'clock' part ({ now, timers }); v2 has it as the 'calendar' channel of this part
|
|
46
|
+
migrate: { 1: (d, save) => {
|
|
47
|
+
const c = save?.parts?.clock ?? {};
|
|
48
|
+
return { channels: { ...(d?.channels ?? {}), calendar: c.now ?? 0 },
|
|
49
|
+
timers: [...(d?.timers ?? []), ...(Array.isArray(c.timers) ? c.timers : []).map(t => ({ ...t, channel: 'calendar' }))] };
|
|
50
|
+
} },
|
|
51
|
+
save: () => ({ channels: Object.fromEntries([...this._ch.values()].map(c => [c.name, c.now])),
|
|
52
|
+
timers: this._timers.filter(t => t.event && !t.dead).map(({ ch, due, event, data }) => ({ channel: ch, due, event, data })) }),
|
|
53
|
+
load: d => this._load(d),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/** @internal the save part: channel seconds and event timers come from the save; function timers (not saveable) keep their time left */
|
|
57
|
+
_load(d) {
|
|
58
|
+
// saved seconds pass saveValues first: a negative / non-finite channel time ran its timers backwards (durability audit); clamped to >= 0, one warning
|
|
59
|
+
const v = saveValues('time'), chans = {};
|
|
60
|
+
for (const [name, now] of Object.entries(d?.channels ?? {})) chans[name] = v.num(now, `channels.${name}`, { min: 0, fallback: 0 });
|
|
61
|
+
const timers = (Array.isArray(d?.timers) ? d.timers : []).filter(t => {
|
|
62
|
+
if (Number.isFinite(t?.due) && typeof t.event === 'string' && typeof t.channel === 'string') return true;
|
|
63
|
+
v.drop('timers[]', t); return false;
|
|
64
|
+
});
|
|
65
|
+
v.done();
|
|
66
|
+
// in the save but not yet defined by the game (channel('enemies') only after load): note it down, fill in when channel() defines it
|
|
67
|
+
this._pending = {};
|
|
68
|
+
for (const [name, now] of Object.entries(chans)) if (!this._ch.has(name)) this._pending[name] = now;
|
|
69
|
+
const delta = {};
|
|
70
|
+
for (const c of this._ch.values()) { const now = chans[c.name] ?? 0; delta[c.name] = now - c.now; c.now = now; this.engine.stacks._rebase(c.name, delta[c.name]); }
|
|
71
|
+
const fn = this._timers.filter(t => !t.event && !t.dead);
|
|
72
|
+
for (const t of fn) t.due += delta[t.ch] ?? 0;
|
|
73
|
+
this._timers = fn.concat(timers.map(({ channel, due, event, data }) => ({ ch: channel, due, event, data })));
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Define a channel (its speed stack is 'time.<name>'). parent: the channel whose speed it multiplies (default 'world').
|
|
77
|
+
* @param {string} name @param {{ parent?: string | null, stack?: string }} [o]
|
|
78
|
+
* @example engine.time.channel('enemies'); engine.mod('time.enemies', { owner: 'bullet-time', mul: 0.35, for: 2 });
|
|
79
|
+
*/
|
|
80
|
+
channel(name, { parent = 'world', stack = 'time.' + name } = {}) {
|
|
81
|
+
if (this._ch.has(name)) return this;
|
|
82
|
+
if (name === 'real' || name === 'ambient') throw codedError('unknown-name', `engine.time.channel('${name}'): '${name}' is a built-in view of the time source, pick another name`);
|
|
83
|
+
if (parent != null && !this._ch.has(parent)) throw codedError('unknown-name', `engine.time.channel('${name}', { parent: '${parent}' }): no channel '${parent}'. Channels: ${this.channels().join(', ')}`);
|
|
84
|
+
const saved = this._pending[name]; delete this._pending[name];
|
|
85
|
+
// put now in place before defining the speed stack: entries in the stack saved against this channel's clock restore the remaining time from its now
|
|
86
|
+
this._ch.set(name, { name, parent, now: saved ?? 0, stack });
|
|
87
|
+
this.engine.stacks.define(stack, { min: 0 });
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Call fn() right after the channels moved (each fixed step, each engine.skip segment; not while frozen), before timed mods end and timers fire.
|
|
92
|
+
* For views derived from a channel: the calendar's day and time of day are read from the 'calendar' channel, and its day:start fires here.
|
|
93
|
+
* @param {() => void} fn
|
|
94
|
+
* @returns {{ remove(): void }}
|
|
95
|
+
* @example ctx.track(engine.time.onMove(() => { if (engine.clock.now > nextTide) tide.turn(); }))
|
|
96
|
+
*/
|
|
97
|
+
onMove(fn) {
|
|
98
|
+
this._onMove.push(fn);
|
|
99
|
+
return { remove: () => { const i = this._onMove.indexOf(fn); if (i >= 0) this._onMove.splice(i, 1); } };
|
|
100
|
+
}
|
|
101
|
+
/** Channel names */
|
|
102
|
+
channels() { return [...this._ch.keys()]; }
|
|
103
|
+
/** @internal */
|
|
104
|
+
_get(name) {
|
|
105
|
+
const c = this._ch.get(name);
|
|
106
|
+
if (!c) throw codedError('unknown-name', `engine.time: no channel '${name}'. Channels: real, ambient, ${this.channels().join(', ')}; add one with engine.time.channel('${name}')`);
|
|
107
|
+
return c;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* The effective speed of a channel (parent x its own stack), times the record's own stack when id is given. Read-only: change it with engine.mod.
|
|
111
|
+
* @param {string} name @param {string} [id]
|
|
112
|
+
*/
|
|
113
|
+
scale(name, id) {
|
|
114
|
+
if (name === 'real' || name === 'ambient') return 1;
|
|
115
|
+
const c = this._get(name);
|
|
116
|
+
let s = (c.parent ? this.scale(c.parent) : 1) * this.engine.stacks.get(c.stack).value();
|
|
117
|
+
if (id != null) s *= this._local.value(id);
|
|
118
|
+
return s;
|
|
119
|
+
}
|
|
120
|
+
/** Fixed steps run since the start of this playthrough (the one counter; read-only) */
|
|
121
|
+
get tick() { return this._tick; }
|
|
122
|
+
/** Seconds on a view: 'real', 'ambient', 'calendar' or a channel @param {string} name */
|
|
123
|
+
now(name) {
|
|
124
|
+
if (name === 'real') return this._tick * STEP + this._carry;
|
|
125
|
+
if (name === 'ambient') return this._amb;
|
|
126
|
+
return this._get(name).now;
|
|
127
|
+
}
|
|
128
|
+
/** This fixed step's dt on a channel (STEP x scale), for a record when id is given @param {string} name @param {string} [id] */
|
|
129
|
+
dt(name, id) { return STEP * this.scale(name, id); }
|
|
130
|
+
|
|
131
|
+
// ---------- the one timer queue (public form: engine.clock.after / every) ----------
|
|
132
|
+
/**
|
|
133
|
+
* @internal Add a timer on a view ('real', a channel, 'calendar'). Returns { remove() }.
|
|
134
|
+
* Why remove() marks the timer dead as well as dropping it: the step that fires timers takes its due list first, so a timer removed by an
|
|
135
|
+
* earlier callback in that same list used to fire anyway (review 0.4, B). A dead timer never fires, whatever list it is in.
|
|
136
|
+
*/
|
|
137
|
+
_add(ch, seconds, fnOrEvent, data, every = 0) {
|
|
138
|
+
if (ch !== 'real') this._get(ch);
|
|
139
|
+
const t = typeof fnOrEvent === 'string' ? { ch, due: this.now(ch) + seconds, event: fnOrEvent, data, every, dead: false }
|
|
140
|
+
: { ch, due: this.now(ch) + seconds, fn: fnOrEvent, every, dead: false };
|
|
141
|
+
this._timers.push(t);
|
|
142
|
+
return { remove: () => { t.dead = true; this._timers = this._timers.filter(x => x !== t); } };
|
|
143
|
+
}
|
|
144
|
+
/** Timers in the queue (engine.counts) */
|
|
145
|
+
get size() { return this._timers.length; }
|
|
146
|
+
/** @internal timers fire per view in this order: real, the channels as defined, the calendar last (calendar timers see this step's channel results) */
|
|
147
|
+
_fireOrder() { const names = this.channels().filter(n => n !== 'calendar'); return ['real', ...names, 'calendar']; }
|
|
148
|
+
/** @internal */
|
|
149
|
+
_runTimers() {
|
|
150
|
+
if (!this._timers.length) return;
|
|
151
|
+
for (const ch of this._fireOrder()) {
|
|
152
|
+
const at = this.now(ch) + EPS;
|
|
153
|
+
const due = this._timers.filter(t => t.ch === ch && t.due <= at).sort((a, b) => a.due - b.due);
|
|
154
|
+
if (!due.length) continue;
|
|
155
|
+
this._timers = this._timers.filter(t => !(t.ch === ch && t.due <= at) || t.every);
|
|
156
|
+
for (const t of due) {
|
|
157
|
+
if (t.every) { while (!t.dead && t.due <= at) { t.due += t.every; this._call(t); } continue; }
|
|
158
|
+
if (!t.dead) { t.dead = true; this._call(t); }
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/** @internal a callback that throws is a gameplay error; the other timers still run */
|
|
163
|
+
_call(t) {
|
|
164
|
+
if (t.event) { this.engine.events.emit(t.event, t.data); return; }
|
|
165
|
+
try { t.fn(); } catch (err) { reportError(this.engine, err, STRINGS.where); }
|
|
166
|
+
}
|
|
167
|
+
/** @internal engine.session: the function timers now, each with its time left (what a new playthrough starts with) @returns {{ t: any, rem: number }[]} */
|
|
168
|
+
_snapshotFn() { return this._timers.filter(t => !t.event && !t.dead).map(t => ({ t, rem: t.due - this.now(t.ch) })); }
|
|
169
|
+
/** @internal engine.session: keep the event timers (they came with the save), put back exactly the snapshotted function timers with their original delay */
|
|
170
|
+
_restoreFn(list) { this._timers = this._timers.filter(t => t.event).concat(list.map(({ t, rem }) => Object.assign(t, { due: this.now(t.ch) + rem, dead: false }))); }
|
|
171
|
+
|
|
172
|
+
// ---------- the three ways time moves ----------
|
|
173
|
+
/** @internal loop.js, at the start of a fixed step: count it, so this step's commits, ops and input records carry the new tick */
|
|
174
|
+
_beginStep() { this._tick++; }
|
|
175
|
+
/** @internal loop.js, after the step's gameplay: everything else moves by one step (real already moved with the tick) */
|
|
176
|
+
_endStep() { this._move(STEP, null); }
|
|
177
|
+
/** @internal loop.js, a frozen step: only ambient moves (and not even that while a freezer holds ambient) */
|
|
178
|
+
_frozenStep(ambient) { if (ambient) this._setAmbient(this._amb + STEP); }
|
|
179
|
+
/**
|
|
180
|
+
* @internal engine.skip, one segment: `fixed` fixed seconds as if stepped (tick and real too, so skip and stepping agree on every view);
|
|
181
|
+
* calendar = the calendar seconds of the segment when skip measured it itself (exact segment ends; a stopped calendar skips as if at 1x).
|
|
182
|
+
*/
|
|
183
|
+
_skip(fixed, calendar) {
|
|
184
|
+
const c = this._carry + fixed, n = Math.floor(c / STEP + EPS);
|
|
185
|
+
this._tick += n; this._carry = Math.max(0, c - n * STEP);
|
|
186
|
+
this._move(fixed, calendar);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* @internal engine.session (new game / load / quit): tick, real and ambient start from 0 like a fresh page (channels and the calendar come
|
|
190
|
+
* from the save part). Returns undo(): a refused or rolled-back load puts them back, else 'real' mods and shader time restart mid-play.
|
|
191
|
+
*/
|
|
192
|
+
_restart() {
|
|
193
|
+
const was = [this._tick, this._carry, this._amb];
|
|
194
|
+
this._tick = 0; this._carry = 0; this._setAmbient(0);
|
|
195
|
+
return () => { [this._tick, this._carry] = was; this._setAmbient(was[2]); };
|
|
196
|
+
}
|
|
197
|
+
/** @internal */
|
|
198
|
+
_setAmbient(v) { this._amb = v; const u = this.engine.uniforms?.uTime; if (u) u.value = v; } // uTime is this view, written only here
|
|
199
|
+
/**
|
|
200
|
+
* @internal Move ambient, channels and the calendar by `fixed` fixed seconds, end timed mods, fire timers.
|
|
201
|
+
* Speeds are read once before anything moves, so every channel advances with the scales this step's gameplay saw; then timed mods end
|
|
202
|
+
* (earliest first, mod:end each), then timers fire.
|
|
203
|
+
*/
|
|
204
|
+
_move(fixed, calendar) {
|
|
205
|
+
const scales = [...this._ch.values()].map(c => [c, this.scale(c.name)]);
|
|
206
|
+
this._setAmbient(this._amb + fixed);
|
|
207
|
+
for (const [c, s] of scales) c.now += c.name === 'calendar' && calendar != null ? calendar : fixed * s;
|
|
208
|
+
for (const fn of [...this._onMove]) { try { fn(); } catch (err) { reportError(this.engine, err, STRINGS.onMove); } }
|
|
209
|
+
this.engine.stacks._expire();
|
|
210
|
+
this._runTimers();
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* @internal engine.skip: calendar seconds until the next timer or timed mod is due, at the current speeds (a segment ends there so they fire in
|
|
214
|
+
* the same order as when stepping). gamePerFixed = calendar seconds per fixed second of the skip.
|
|
215
|
+
*/
|
|
216
|
+
_untilNext(gamePerFixed) {
|
|
217
|
+
const toGame = (ch, left) => {
|
|
218
|
+
if (ch === 'calendar') return left;
|
|
219
|
+
const s = this.scale(ch); return s > 0 ? left / s * gamePerFixed : Infinity;
|
|
220
|
+
};
|
|
221
|
+
let best = Infinity;
|
|
222
|
+
for (const t of this._timers) best = Math.min(best, toGame(t.ch, Math.max(0, t.due - this.now(t.ch))));
|
|
223
|
+
return Math.min(best, this.engine.stacks._untilNext(toGame));
|
|
224
|
+
}
|
|
225
|
+
/** describe().time.channels: { name: { scale, now, holders? } } */
|
|
226
|
+
describe() {
|
|
227
|
+
const out = {};
|
|
228
|
+
for (const c of this._ch.values()) {
|
|
229
|
+
const h = this.engine.stacks.get(c.stack).holders();
|
|
230
|
+
out[c.name] = { scale: Math.round(this.scale(c.name) * 1000) / 1000, now: Math.round(c.now * 100) / 100, ...(h.length ? { holders: h } : {}) };
|
|
231
|
+
}
|
|
232
|
+
return out;
|
|
233
|
+
}
|
|
234
|
+
/** Clear all timers (engine.dispose) */
|
|
235
|
+
dispose() { for (const t of this._timers) t.dead = true; this._timers = []; }
|
|
236
|
+
}
|
package/core/uiClock.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// UI timers on the page clock.
|
|
2
|
+
// How long a toast stays: one rule, it runs on whatever drives the page. A page the browser runs (the game) counts wall-clock
|
|
3
|
+
// time, so a message still goes away while gameplay is paused (a pause menu stops the frame loop, not the clock). A headless tool page
|
|
4
|
+
// (?threedog-headless) is driven by engine.step: its "now" is the stepped time, so `threedog step 60` then `snap` shows the messages of the last
|
|
5
|
+
// seconds only. Before, a headless page kept wall-clock timers too and a step of 60 game seconds took a few real seconds, so eight toasts from
|
|
6
|
+
// the step covered the shot (farm R4). CSS fades are not timers: they always run on the browser's clock.
|
|
7
|
+
// How: the headless timers advance in _frameHooks (core/loop.js), which runs for every frame step() makes and for a resumed headless loop.
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Call fn after ms of the page's own time (wall clock in the game, stepped time on a headless page)
|
|
11
|
+
* @param {any} e the engine @param {number} ms @param {() => void} fn
|
|
12
|
+
*/
|
|
13
|
+
export function uiAfter(e, ms, fn) {
|
|
14
|
+
if (!e.headless) { setTimeout(fn, ms); return; } // wall-clock: the browser drives this page
|
|
15
|
+
(e._uiTimers ??= []).push({ left: ms / 1000, fn });
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Advance the headless UI timers by dt seconds (core/loop.js _frameHooks) @param {any} e @param {number} dt */
|
|
19
|
+
export function advanceUiClock(e, dt) {
|
|
20
|
+
const T = e._uiTimers;
|
|
21
|
+
if (!T?.length || !(dt > 0)) return;
|
|
22
|
+
const due = [];
|
|
23
|
+
for (let i = T.length - 1; i >= 0; i--) if ((T[i].left -= dt) <= 0) due.push(T.splice(i, 1)[0]);
|
|
24
|
+
for (let i = due.length - 1; i >= 0; i--) due[i].fn(); // in the order they were set
|
|
25
|
+
}
|
package/core/util.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
// Small
|
|
1
|
+
// Small shared core helpers. One definition each, so "what counts as a plain object" and "how a dotted path is read" cannot drift apart.
|
|
2
2
|
|
|
3
3
|
/** A plain data object: { } or Object.create(null); not an array, class instance, three.js object or function */
|
|
4
4
|
export const isPlainObject = v => v !== null && typeof v === 'object' && !Array.isArray(v) && [Object.prototype, null].includes(Object.getPrototypeOf(v));
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* f() or null when it throws. For read-only reports (thing.explain and its module parts) that join several sources: one source that cannot
|
|
8
|
+
* answer (an unknown template, a disposed part) leaves its field null instead of failing the whole report. Never for gameplay paths.
|
|
9
|
+
*/
|
|
10
|
+
export const orNull = f => { try { return f(); } catch { return null; } };
|
|
11
|
+
|
|
6
12
|
/** Read a dotted path ('look.fog.color'); undefined as soon as a step is missing @param {any} obj @param {string} path */
|
|
7
13
|
export function getPath(obj, path) {
|
|
8
14
|
let v = obj;
|