threedog 0.2.1 → 0.7.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 +371 -1
- package/README.md +21 -12
- package/core/Animator.js +15 -12
- package/core/Assets.js +92 -26
- package/core/Audio.js +45 -38
- package/core/Baked.js +30 -15
- package/core/Batching.js +102 -15
- package/core/Budget.js +40 -19
- package/core/Clock.js +40 -80
- package/core/DebugOverrides.js +75 -25
- package/core/Describe.js +105 -45
- package/core/Engine.js +203 -75
- package/core/Events.js +4 -1
- package/core/I18n.js +25 -13
- package/core/Input.js +175 -80
- package/core/Inspect.js +8 -5
- package/core/InspectMaterials.js +84 -0
- package/core/InspectPerf.js +68 -0
- package/core/InspectScene.js +13 -2
- package/core/Loading.js +2 -1
- package/core/MaterialInfo.js +7 -5
- package/core/Ops.js +50 -9
- package/core/Random.js +9 -2
- package/core/Rays.js +12 -7
- package/core/SaveStore.js +41 -9
- package/core/Saves.js +71 -15
- package/core/Stream.js +13 -10
- package/core/Threads.js +26 -7
- package/core/UrlState.js +69 -13
- package/core/Views.js +10 -6
- package/core/actor.js +1 -1
- package/core/adaptive.js +93 -0
- package/core/assetEntry.js +27 -7
- package/core/assetHot.js +176 -0
- package/core/assetLoad.js +44 -19
- package/core/assetManifest.js +53 -11
- package/core/assetReport.js +5 -5
- package/core/audioRules.js +13 -11
- package/core/audioVoice.js +69 -42
- package/core/batchGroups.js +9 -1
- package/core/canvasBox.js +1 -2
- package/core/catalog.js +21 -5
- 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 +85 -18
- package/core/describeRender.js +117 -21
- package/core/describeText.js +41 -21
- package/core/engineCamera.js +32 -0
- package/core/errorCodes.js +478 -32
- package/core/errorHints.js +41 -142
- package/core/errors.js +31 -8
- package/core/events.generated.js +13 -7
- package/core/gameLights.js +69 -0
- package/core/grayMap.js +20 -0
- package/core/grid.js +14 -13
- package/core/gridLoad.js +2 -1
- 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 +46 -12
- package/core/lightWatch.js +9 -5
- package/core/loop.js +109 -43
- package/core/math.js +18 -3
- package/core/moduleSlots.js +100 -0
- package/core/moduleTypes.js +86 -0
- package/core/modules.js +147 -29
- package/core/movement.js +2 -2
- package/core/namedModel.js +74 -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 +171 -0
- package/core/page.js +44 -10
- package/core/params.js +30 -8
- package/core/pictureSlots.js +33 -0
- package/core/pictureWriters.js +343 -0
- package/core/plugins.js +245 -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 +211 -0
- package/core/sceneMethods.js +31 -33
- 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 +3 -2
- package/core/shadows.js +405 -0
- package/core/sharedPoint.js +303 -0
- package/core/skip.js +36 -28
- package/core/stackFrames.js +45 -0
- package/core/stacks.js +166 -0
- package/core/startup.js +153 -13
- package/core/streamSources.js +0 -11
- package/core/targeting.js +1 -1
- package/core/textureBytes.js +20 -0
- package/core/thingExplain.js +3 -3
- package/core/thingOps.js +29 -6
- package/core/things.js +22 -12
- 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 +8 -2
- package/core/validate.js +66 -87
- package/core/view.js +43 -0
- package/core/wrap.js +106 -0
- package/docs/AI.md +95 -104
- package/docs/API.md +35 -31
- package/docs/CODEMAP.md +231 -176
- package/docs/COMMANDS.md +63 -39
- package/docs/CONVENTIONS.md +99 -31
- package/docs/MIGRATING-0.3.md +248 -0
- package/docs/MIGRATING-0.4.md +320 -0
- package/docs/MIGRATING-0.5.md +68 -0
- package/docs/MIGRATING-0.6.md +126 -0
- package/docs/MIGRATING-0.7.md +39 -0
- package/docs/PERF.md +35 -7
- package/docs/THREE.md +82 -28
- package/docs/api/ambience.md +0 -1
- package/docs/api/assets.md +15 -11
- package/docs/api/audio.md +10 -14
- package/docs/api/budget.md +4 -0
- package/docs/api/calendar.md +41 -0
- package/docs/api/cameraRig.md +16 -5
- package/docs/api/characters.md +41 -24
- package/docs/api/clock.md +6 -5
- package/docs/api/collision.md +10 -7
- package/docs/api/content.md +6 -4
- package/docs/api/dialogue.md +9 -9
- package/docs/api/engine.md +95 -65
- package/docs/api/events.md +20 -14
- package/docs/api/grids.md +10 -3
- package/docs/api/ground.md +1 -1
- package/docs/api/hud.md +5 -2
- package/docs/api/i18n.md +1 -1
- package/docs/api/input.md +13 -7
- package/docs/api/interactions.md +10 -6
- package/docs/api/inventory.md +17 -17
- package/docs/api/level.md +0 -2
- package/docs/api/lightPool.md +3 -1
- package/docs/api/music.md +1 -1
- package/docs/api/nav.md +3 -0
- package/docs/api/occlusion.md +5 -0
- package/docs/api/openWorld.md +2 -1
- package/docs/api/particles.md +6 -3
- package/docs/api/photo.md +0 -2
- package/docs/api/pickups.md +21 -0
- package/docs/api/post.md +8 -5
- 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 +18 -49
- package/docs/api/stream.md +1 -1
- package/docs/api/terrain.md +16 -7
- package/docs/api/terrainDraw.md +12 -0
- package/docs/api/timeline.md +3 -4
- package/docs/api/tools.md +32 -15
- package/docs/api/triggers.md +7 -10
- package/docs/api/vegetation.md +17 -9
- package/docs/api/vegetationDraw.md +10 -0
- package/docs/api/water.md +9 -21
- package/docs/api/weather.md +10 -15
- package/docs/api/weatherDraw.md +10 -0
- package/docs/api/world.md +3 -2
- package/docs/recipes/01-new-game.md +52 -42
- package/docs/recipes/02-npc.md +24 -7
- package/docs/recipes/03-items-pickups.md +57 -22
- package/docs/recipes/04-quests.md +12 -5
- package/docs/recipes/05-props-bake.md +174 -22
- package/docs/recipes/06-clock-events.md +100 -52
- package/docs/recipes/07-flow-scenes-pause.md +50 -10
- package/docs/recipes/08-weather-sky.md +134 -37
- package/docs/recipes/09-materials-lights-models.md +185 -0
- package/docs/recipes/10-blender-level.md +16 -4
- package/docs/recipes/11-vehicles.md +67 -10
- package/docs/recipes/13-animation.md +23 -9
- package/docs/recipes/14-custom-module.md +63 -29
- package/docs/recipes/15-perf.md +31 -10
- package/docs/recipes/16-dev-bridge.md +74 -40
- package/docs/recipes/18-world.md +26 -14
- package/docs/recipes/19-shooting-picking.md +12 -10
- package/docs/recipes/20-content-actions-save.md +60 -18
- package/docs/recipes/21-camera.md +55 -17
- package/docs/recipes/22-shop-gold.md +3 -3
- package/docs/recipes/23-ops.md +17 -11
- package/docs/recipes/26-ui-parts.md +86 -13
- package/docs/recipes/27-net.md +11 -5
- package/docs/recipes/28-terrain.md +36 -3
- package/docs/recipes/29-grid.md +46 -19
- package/docs/recipes/30-templates.md +72 -15
- package/docs/recipes/31-audio.md +20 -12
- package/docs/recipes/32-action-game.md +51 -4
- package/docs/recipes/34-environment-lighting.md +108 -21
- package/docs/recipes/35-picture-from-reference.md +147 -0
- package/docs/recipes/36-sky-ground-plants.md +158 -0
- package/docs/recipes/{37-terrain-look-hooks.md → 37-terrain-hooks.md} +9 -12
- package/docs/recipes/38-environment-hooks.md +67 -0
- package/docs/recipes/40-scene.md +114 -32
- package/docs/recipes/42-terrain-shape.md +2 -2
- package/docs/recipes/43-shader-patches-surfaces.md +206 -0
- package/docs/recipes/44-water-weather-hooks.md +191 -0
- package/docs/recipes/45-cascaded-shadows.md +130 -23
- package/docs/recipes/46-blender-art-route.md +17 -20
- package/docs/recipes/47-island-snow-backdrop.md +13 -15
- package/docs/recipes/49-game-module-contract.md +30 -17
- package/docs/recipes/50-own-renderer.md +4 -4
- package/docs/recipes/51-capability-catalog.md +3 -3
- package/docs/recipes/52-around-the-picture.md +181 -0
- package/docs/recipes/53-ground-up-close.md +12 -12
- package/docs/recipes/54-three-idioms.md +88 -0
- package/docs/recipes/55-mods-time-wrap.md +124 -0
- package/docs/recipes/56-webgpu-tsl.md +303 -0
- package/docs/recipes/57-control.md +104 -0
- package/docs/recipes/58-input.md +60 -0
- package/docs/recipes/59-depth-post-effects.md +83 -0
- package/docs/recipes/60-judge-the-picture.md +70 -0
- package/docs/recipes/61-deploy.md +27 -0
- package/docs/recipes/62-picture-code.md +244 -0
- package/docs/recipes/63-third-person-start.md +77 -0
- package/docs/recipes/64-particles.md +35 -0
- package/examples/action/.threedog/content-index.json +1 -0
- package/examples/action/GAMEMAP.md +20 -14
- 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/main.js +12 -15
- package/examples/action/models.js +23 -24
- package/examples/action/picture/index.js +13 -0
- package/examples/action/picture/lights.js +35 -0
- package/examples/action/picture/materials.js +8 -0
- package/examples/action/picture/palette.js +33 -0
- package/examples/plain-picture/.threedog/content-index.json +1 -0
- package/examples/plain-picture/FINDINGS.md +53 -0
- package/examples/plain-picture/GAMEMAP.md +90 -0
- package/examples/plain-picture/main.js +48 -0
- package/examples/plain-picture/picture/index.js +21 -0
- package/examples/plain-picture/picture/lights.js +54 -0
- package/examples/plain-picture/picture/materials.js +24 -0
- package/examples/plain-picture/picture/palette.js +16 -0
- package/examples/plain-picture/picture/sky.js +37 -0
- package/examples/pullable.json +133 -0
- package/examples/rc2d/.threedog/content-index.json +1 -0
- package/examples/rc2d/GAMEMAP.md +88 -0
- package/examples/rc2d/README.md +57 -0
- package/examples/rc2d/main.js +55 -0
- package/examples/rc2d/picture/index.js +18 -0
- package/examples/rc2d/picture/lights.js +11 -0
- package/examples/rc2d/picture/materials.js +18 -0
- package/examples/rc2d/picture/palette.js +15 -0
- package/examples/rc2d/picture/post.js +11 -0
- package/examples/rc2d/rc2d.js +187 -0
- package/examples/rc2d/shaders.js +144 -0
- package/examples/sheepisland/.threedog/content-index.json +1 -0
- package/examples/sheepisland/GAMEMAP.md +22 -17
- package/examples/sheepisland/assets.js +5 -0
- package/examples/sheepisland/content/templates.js +1 -1
- package/examples/sheepisland/content/vegetation.js +3 -1
- package/examples/sheepisland/main.js +29 -18
- package/examples/sheepisland/{style/models.js → models.js} +13 -24
- package/examples/sheepisland/picture/index.js +20 -0
- package/examples/sheepisland/picture/lights.js +34 -0
- package/examples/sheepisland/picture/materials.js +61 -0
- package/examples/sheepisland/picture/palette.js +60 -0
- package/examples/sheepisland/picture/sky.js +20 -0
- package/examples/sheepisland/views.js +1 -1
- package/examples/styletest/.threedog/content-index.json +1 -0
- package/examples/styletest/GAMEMAP.md +25 -22
- package/examples/styletest/assets.js +6 -0
- package/examples/styletest/content/templates.js +1 -1
- package/examples/styletest/content/vegetation.js +1 -1
- package/examples/styletest/main.js +25 -34
- package/examples/styletest/models.js +30 -30
- package/examples/styletest/params.js +2 -5
- package/examples/styletest/picture/env.js +38 -0
- package/examples/styletest/picture/index.js +16 -0
- package/examples/styletest/picture/lights.js +9 -0
- package/examples/styletest/picture/materials.js +28 -0
- package/examples/styletest/picture/palette.js +22 -0
- package/examples/techniques/contact-shadows/README.md +91 -0
- package/examples/techniques/contact-shadows/contactShadows.js +67 -0
- package/examples/techniques/contact-shadows/main.js +55 -0
- package/examples/techniques/contact-shadows/picture/index.js +14 -0
- package/examples/techniques/contact-shadows/picture/lights.js +34 -0
- package/examples/techniques/contact-shadows/picture/materials.js +12 -0
- package/examples/techniques/contact-shadows/picture/palette.js +17 -0
- package/examples/techniques/day-night-grade/README.md +83 -0
- package/examples/techniques/day-night-grade/main.js +41 -0
- package/examples/techniques/day-night-grade/picture/index.js +20 -0
- package/examples/techniques/day-night-grade/picture/lights.js +45 -0
- package/examples/techniques/day-night-grade/picture/materials.js +15 -0
- package/examples/techniques/day-night-grade/picture/palette.js +59 -0
- package/examples/techniques/day-night-grade/picture/post.js +25 -0
- package/examples/techniques/day-night-grade/picture/sky.js +33 -0
- package/examples/techniques/interior-light/README.md +106 -0
- package/examples/techniques/interior-light/interiorLight.js +47 -0
- package/examples/techniques/interior-light/main.js +87 -0
- package/examples/techniques/interior-light/picture/index.js +24 -0
- package/examples/techniques/interior-light/picture/lights.js +52 -0
- package/examples/techniques/interior-light/picture/materials.js +13 -0
- package/examples/techniques/interior-light/picture/palette.js +32 -0
- package/examples/techniques/interior-light/picture/sky.js +40 -0
- package/examples/techniques/modular-building/README.md +126 -0
- package/examples/techniques/modular-building/kit.js +426 -0
- package/examples/techniques/modular-building/main.js +39 -0
- package/examples/techniques/modular-building/picture/index.js +17 -0
- package/examples/techniques/modular-building/picture/lights.js +26 -0
- package/examples/techniques/modular-building/picture/materials.js +13 -0
- package/examples/techniques/modular-building/picture/palette.js +23 -0
- package/examples/techniques/night-lights/README.md +95 -0
- package/examples/techniques/night-lights/main.js +47 -0
- package/examples/techniques/night-lights/nightLights.js +95 -0
- package/examples/techniques/night-lights/picture/index.js +18 -0
- package/examples/techniques/night-lights/picture/lights.js +44 -0
- package/examples/techniques/night-lights/picture/materials.js +15 -0
- package/examples/techniques/night-lights/picture/palette.js +34 -0
- package/examples/techniques/night-lights/picture/post.js +9 -0
- package/examples/techniques/night-lights/picture/sky.js +36 -0
- package/examples/techniques/outlines-and-rim/README.md +59 -0
- package/examples/techniques/outlines-and-rim/main.js +61 -0
- package/examples/techniques/outlines-and-rim/outlines.js +64 -0
- package/examples/techniques/outlines-and-rim/picture/index.js +16 -0
- package/examples/techniques/outlines-and-rim/picture/lights.js +18 -0
- package/examples/techniques/outlines-and-rim/picture/materials.js +11 -0
- package/examples/techniques/outlines-and-rim/picture/palette.js +16 -0
- package/examples/techniques/outlines-and-rim/picture/post.js +10 -0
- package/examples/techniques/procedural-animation/README.md +79 -0
- package/examples/techniques/procedural-animation/creature.js +44 -0
- package/examples/techniques/procedural-animation/main.js +47 -0
- package/examples/techniques/procedural-animation/picture/index.js +15 -0
- package/examples/techniques/procedural-animation/picture/lights.js +35 -0
- package/examples/techniques/procedural-animation/picture/materials.js +10 -0
- package/examples/techniques/procedural-animation/picture/palette.js +16 -0
- package/examples/techniques/procedural-animation/picture/sky.js +31 -0
- package/examples/techniques/procedural-animation/proceduralAnim.js +118 -0
- package/examples/techniques/procedural-surface/README.md +69 -0
- package/examples/techniques/procedural-surface/main.js +65 -0
- package/examples/techniques/procedural-surface/picture/index.js +14 -0
- package/examples/techniques/procedural-surface/picture/lights.js +18 -0
- package/examples/techniques/procedural-surface/picture/materials.js +34 -0
- package/examples/techniques/procedural-surface/picture/palette.js +15 -0
- package/examples/techniques/procedural-surface/surface.js +120 -0
- package/examples/techniques/stylized-shading/README.md +74 -0
- package/examples/techniques/stylized-shading/main.js +62 -0
- package/examples/techniques/stylized-shading/picture/index.js +14 -0
- package/examples/techniques/stylized-shading/picture/lights.js +23 -0
- package/examples/techniques/stylized-shading/picture/materials.js +18 -0
- package/examples/techniques/stylized-shading/picture/palette.js +19 -0
- package/examples/techniques/stylized-shading/shading.js +131 -0
- package/examples/techniques/sun-and-key-light/README.md +133 -0
- package/examples/techniques/sun-and-key-light/keyLight.js +71 -0
- package/examples/techniques/sun-and-key-light/main.js +51 -0
- package/examples/techniques/sun-and-key-light/picture/index.js +13 -0
- package/examples/techniques/sun-and-key-light/picture/lights.js +33 -0
- package/examples/techniques/sun-and-key-light/picture/materials.js +9 -0
- package/examples/techniques/sun-and-key-light/picture/palette.js +29 -0
- package/examples/techniques/sun-and-key-light/picture/sky.js +16 -0
- package/examples/techniques/three-looks/README.md +21 -0
- package/examples/techniques/three-looks/main.js +58 -0
- package/examples/techniques/three-looks/picture/cartoon.js +23 -0
- package/examples/techniques/three-looks/picture/cinematic.js +27 -0
- package/examples/techniques/three-looks/picture/comic.js +27 -0
- package/examples/techniques/three-looks/picture/index.js +14 -0
- package/examples/techniques/three-looks/picture/sun.js +23 -0
- package/examples/techniques/wet-road/README.md +102 -0
- package/examples/techniques/wet-road/main.js +48 -0
- package/examples/techniques/wet-road/picture/index.js +17 -0
- package/examples/techniques/wet-road/picture/lights.js +57 -0
- package/examples/techniques/wet-road/picture/materials.js +16 -0
- package/examples/techniques/wet-road/picture/palette.js +24 -0
- package/examples/techniques/wet-road/picture/sky.js +46 -0
- package/examples/techniques/wet-road/wetRoad.js +209 -0
- package/examples/webgpu-tsl/.threedog/content-index.json +1 -0
- package/examples/webgpu-tsl/GAMEMAP.md +89 -0
- package/examples/webgpu-tsl/README.md +45 -0
- package/examples/webgpu-tsl/main.js +44 -0
- package/examples/webgpu-tsl/picture/index.js +18 -0
- package/examples/webgpu-tsl/picture/lights.js +25 -0
- package/examples/webgpu-tsl/picture/materials.js +36 -0
- package/examples/webgpu-tsl/picture/palette.js +23 -0
- package/examples/webgpu-tsl/picture/post.js +16 -0
- package/examples/webgpu-tsl/picture/sky.js +30 -0
- package/examples/world/.threedog/content-index.json +1 -0
- package/examples/world/GAMEMAP.md +31 -21
- package/examples/world/art/humanoid.js +38 -0
- package/examples/world/art/index.js +11 -0
- package/examples/world/art/models.js +57 -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/items.js +1 -1
- package/examples/world/content/npcs.js +1 -1
- 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 +22 -18
- package/examples/world/models.js +17 -7
- package/examples/world/picture/index.js +20 -0
- package/examples/world/picture/lights.js +41 -0
- package/examples/world/picture/materials.js +34 -0
- package/examples/world/picture/palette.js +74 -0
- package/examples/world/picture/post.js +9 -0
- package/examples/world/picture/sky.js +39 -0
- package/index.d.ts +44 -54
- package/index.js +29 -25
- package/llms.txt +24 -15
- 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 +82 -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 +73 -20
- package/modules/camera/contract.js +17 -0
- package/modules/camera/projection.js +11 -24
- package/modules/characters/Character.js +188 -48
- package/modules/characters/NPC.js +92 -41
- package/modules/characters/assetModel.js +8 -16
- 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 +112 -49
- package/modules/characters/moveHelpers.js +4 -5
- package/modules/characters/movers/common.js +102 -19
- package/modules/characters/movers/manual.js +23 -0
- package/modules/characters/movers/rapier.js +19 -16
- package/modules/characters/movers/simple.js +14 -11
- package/modules/characters/movers/support.js +186 -0
- package/modules/characters/npcAvoid.js +47 -42
- package/modules/characters/npcSim.js +17 -9
- 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 +19 -4
- package/modules/characters/useModel.js +2 -2
- package/modules/characters/vehicle.contract.js +21 -0
- package/modules/characters/walkTo.js +21 -7
- package/modules/collision/Collision.js +69 -27
- 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 +104 -27
- package/modules/content/loader.js +45 -33
- package/modules/content/models.js +58 -42
- package/modules/content/packs.js +6 -5
- package/modules/content/parts.js +41 -0
- package/modules/content/props.js +20 -11
- package/modules/content/rules.js +66 -0
- package/modules/content/stages.js +80 -0
- package/modules/content/templates.js +123 -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 +273 -72
- package/modules/gameplay/Inventory.js +72 -76
- 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 +19 -17
- package/modules/gameplay/pickups.js +306 -85
- package/modules/gameplay/questLog.js +6 -6
- package/modules/gameplay/quests.contract.js +17 -0
- package/modules/grid/Grid.js +92 -50
- package/modules/grid/Layer.js +27 -13
- package/modules/grid/index.js +96 -43
- package/modules/grid/ops.js +20 -18
- package/modules/grid/preview.js +37 -29
- package/modules/grid/strings.js +12 -0
- package/modules/grid/tiles.js +19 -22
- package/modules/hlod/index.js +52 -19
- package/modules/hud/index.js +48 -20
- package/modules/hud/parts.js +28 -13
- package/modules/level/heightfield.js +3 -1
- package/modules/level/index.js +49 -23
- package/modules/level/nodes.js +4 -3
- package/modules/lights/index.js +47 -19
- 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 +58 -28
- package/modules/particles/contract.js +17 -0
- package/modules/particles/effect.js +54 -11
- package/modules/photo/Photo.js +56 -38
- 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 +60 -55
- 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 +132 -205
- package/modules/sky/clouds.js +37 -23
- package/modules/sky/dome.js +100 -0
- package/modules/sky/domeLayers.js +30 -15
- package/modules/sky/environment.js +45 -99
- package/modules/sky/fog.js +9 -139
- package/modules/sky/frame.js +60 -56
- package/modules/sky/season.js +21 -0
- package/modules/sky/shader.js +63 -35
- package/modules/sky/skyModule.js +52 -37
- package/modules/sky/tint.js +59 -0
- package/modules/terrain/ChunkManager.js +194 -110
- package/modules/terrain/chunkJob.js +1 -1
- package/modules/terrain/chunkQueries.js +6 -4
- package/modules/terrain/draw.js +154 -0
- package/modules/terrain/index.js +87 -54
- package/modules/terrain/terrainDefaults.js +2 -2
- package/modules/terrain/terrainEdit.js +18 -20
- package/modules/terrain/terrainGen.js +6 -4
- 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 +111 -76
- package/modules/vegetation/Vegetation.js +229 -112
- package/modules/vegetation/densityMap.js +62 -0
- package/modules/vegetation/draw.js +191 -0
- package/modules/vegetation/groundChunks.js +52 -58
- package/modules/vegetation/index.js +32 -11
- package/modules/vegetation/modelGeometry.js +3 -2
- package/modules/vegetation/nearFade.js +8 -2
- package/modules/water/Water.js +157 -72
- package/modules/water/surface.js +86 -47
- package/modules/weather/Weather.js +96 -103
- package/modules/weather/particles.js +37 -14
- package/modules/weather/shaders.js +1 -1
- package/modules/weather/strings.js +2 -2
- package/modules/weather/weatherDraw.js +141 -0
- package/modules/world/World.js +26 -9
- 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 +8 -6
- package/package.json +8 -3
- package/presets.js +43 -29
- package/render/PostFX.js +318 -135
- package/render/backend.js +486 -0
- package/render/cascades.js +195 -0
- package/render/cascades.tsl.js +96 -0
- package/render/daylight.js +39 -0
- package/render/detail.js +122 -41
- package/render/effects.js +155 -48
- package/render/engineUniforms.js +10 -1
- package/render/fuse.js +5 -4
- package/render/fx/cel.tsl.js +42 -0
- package/render/fx/cloudShadow.tsl.js +16 -0
- package/render/fx/detail.tsl.js +66 -0
- package/render/fx/index.js +28 -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 +181 -0
- package/render/fx/season.tsl.js +13 -0
- package/render/fx/sky.tsl.js +187 -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/layers.js +14 -0
- package/render/lighting.js +71 -18
- package/render/lightmap.js +142 -0
- package/render/lights.js +47 -6
- package/render/materials.js +55 -152
- package/render/modeling.js +73 -0
- package/render/neutral.js +23 -0
- package/render/occlusion.js +184 -0
- package/render/ownFrame.js +76 -0
- package/render/patches.js +317 -35
- package/render/postWebGL.js +205 -0
- package/render/probes.js +288 -0
- package/render/shaderErrors.js +154 -0
- package/render/slots.js +165 -0
- package/render/terms.js +163 -0
- package/render/uniformDecl.js +4 -3
- package/types/common.d.ts +2 -2
- package/types/core.d.ts +757 -346
- package/types/gameplay.d.ts +539 -330
- 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 +58 -9
- package/types/generated/core/I18n.d.ts +2 -2
- package/types/generated/core/Input.d.ts +110 -32
- 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/page.d.ts +9 -2
- 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 +13 -5
- package/types/generated/modules/grid/index.d.ts +56 -20
- 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 +13 -6
- package/types/generated/modules/sky/Sky.d.ts +85 -110
- package/types/generated/modules/sky/skyModule.d.ts +1 -1
- package/types/generated/modules/timeline/Timeline.d.ts +8 -6
- package/types/generated/modules/water/Water.d.ts +50 -3
- package/types/generated/modules/weather/Weather.d.ts +44 -15
- package/types/generated/modules/weather/weatherDraw.d.ts +11 -0
- package/types/generated/modules/world/World.d.ts +20 -5
- package/types/generated/render/PostFX.d.ts +109 -29
- package/types/generated/render/lighting.d.ts +29 -0
- package/types/generated/render/materials.d.ts +31 -50
- package/types/generated/render/modeling.d.ts +30 -0
- package/types/generated/render/occlusion.d.ts +13 -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 +140 -45
- package/types/tsl.d.ts +94 -0
- package/types/world.d.ts +489 -122
- package/ui/Focus.js +35 -14
- package/ui/LoadingScreen.js +3 -3
- package/ui/Parts.js +35 -15
- package/ui/UI.js +27 -17
- package/ui/cursor.js +115 -0
- package/ui/defaults.js +15 -11
- package/ui/theme.js +36 -27
- package/ui/touchPart.js +2 -2
- package/core/claims.js +0 -51
- package/core/look/coreParts.js +0 -112
- package/core/look/layers.js +0 -136
- package/core/look/part.js +0 -173
- package/core/look/report.js +0 -79
- package/core/look/write.js +0 -86
- package/core/renamed.js +0 -22
- package/core/styleParts.js +0 -98
- package/docs/api/entities.md +0 -61
- package/docs/api/style.md +0 -134
- package/docs/recipes/09-style-pack.md +0 -169
- package/docs/recipes/35-style-from-reference.md +0 -84
- package/docs/recipes/36-sky-ground-plant-looks.md +0 -118
- package/docs/recipes/38-environment-look-hooks.md +0 -88
- package/docs/recipes/41-thing-registry.md +0 -93
- package/docs/recipes/43-shader-patches-surface-looks.md +0 -135
- package/docs/recipes/44-water-weather-look-hooks.md +0 -135
- package/docs/recipes/48-make-material.md +0 -70
- package/docs/recipes/52-look.md +0 -146
- package/examples/action/look.js +0 -5
- package/examples/sheepisland/style/index.js +0 -79
- package/examples/styletest/look.js +0 -11
- 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/cascades.js +0 -125
- package/modules/sky/layers.js +0 -69
- package/modules/sky/look.js +0 -51
- package/modules/sky/lookFog.js +0 -80
- package/modules/sky/lookShadow.js +0 -50
- package/modules/sky/lookSky.js +0 -108
- package/modules/sky/shadow.js +0 -74
- package/modules/terrain/chunkLevels.js +0 -40
- package/modules/terrain/lookGround.js +0 -61
- package/modules/terrain/mountTerrain.js +0 -32
- package/modules/vegetation/lookWind.js +0 -37
- package/modules/water/look.js +0 -80
- package/modules/weather/look.js +0 -75
- package/modules/world/cells.js +0 -42
- package/render/lookSurface.js +0 -161
- package/render/postLook.js +0 -86
- package/render/surface.js +0 -69
- package/types/style.d.ts +0 -643
package/core/stacks.js
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// engine.stacks: the registry of every shared point (the point itself and its rules are core/sharedPoint.js). Here: define / get / mod, the timers
|
|
2
|
+
// behind `for`, saving entries, and describe().shared. Kept apart from sharedPoint.js only for size: the rules read without the bookkeeping between.
|
|
3
|
+
import { codedError } from './errorHints.js';
|
|
4
|
+
import { DEV, warnOnce } from './validate.js';
|
|
5
|
+
import { Stack } from './sharedPoint.js';
|
|
6
|
+
|
|
7
|
+
const KEYS = ['owner', 'set', 'add', 'mul', 'clamp', 'value', 'for', 'clock', 'id', 'layer'];
|
|
8
|
+
// Saved: engine / game / effect entries (what the playthrough did). Not saved: system / debug (menus, cutscenes, debug: "what the
|
|
9
|
+
// screen is doing now", retaken after a load), settings (the settings module re-applies the player's choices from its own prefs)
|
|
10
|
+
const SAVED = new Set(['engine', 'game', 'effect']);
|
|
11
|
+
const saved = e => SAVED.has(e.layer);
|
|
12
|
+
|
|
13
|
+
/** engine.stacks: every shared point by name; engine.mod(name, o) is the one way to change one */
|
|
14
|
+
export class Stacks {
|
|
15
|
+
constructor(engine) {
|
|
16
|
+
this.engine = engine;
|
|
17
|
+
/** @type {Map<string, Stack>} */ this._all = new Map();
|
|
18
|
+
/** @internal saved entries of a point the game has not defined yet: applied when it does */ this._pending = {};
|
|
19
|
+
this._version = 0; this._timedDirty = false;
|
|
20
|
+
/** @internal now on a clock ('real' or a channel); core/time.js replaces it */ this._nowOf = () => 0;
|
|
21
|
+
// since = game clock time of the take (engine.clock.now), not engine.time.now('real'): session.newGame resets the clock, so an entry a fresh
|
|
22
|
+
// playthrough makes reads the same in every new game
|
|
23
|
+
this._at = () => engine.clock?.now ?? 0;
|
|
24
|
+
this._hooked = false; this._hook();
|
|
25
|
+
}
|
|
26
|
+
/** @internal saves and world:remove. The registry is made before them (Engine.js: the drawing parts' points exist from the first drawing part on);
|
|
27
|
+
* createServices calls this again once saves and events exist */
|
|
28
|
+
_hook() {
|
|
29
|
+
const e = this.engine;
|
|
30
|
+
if (this._hooked || !e.saves || !e.events) return;
|
|
31
|
+
this._hooked = true;
|
|
32
|
+
e.saves.register('stacks', { save: () => this._save(), load: d => this._load(d) });
|
|
33
|
+
e.events.on('world:remove', ({ id }) => { for (const s of this._all.values()) if (s.per) s.dropId(id); });
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Define a shared point (engine modules and games use the same call). kind: 'number' (default; base 1), 'value' (any data, set only), 'any'
|
|
37
|
+
* (true while held), 'top' (latest holder wins), 'one' (an exclusive slot; modules take theirs with `provides`).
|
|
38
|
+
* per: true = one value per record id (mod with { id }); per: 'optional' = an entry with { id } is that record's, one without is every record's
|
|
39
|
+
* (move.speed: haste on the player, mud on everyone). save: false keeps it out of saves (screen state like the camera holder).
|
|
40
|
+
* manual: the copyable takeover call the conflict error offers (a drawing part's manual()).
|
|
41
|
+
* @param {string} name @param {{ kind?: 'number' | 'value' | 'any' | 'top' | 'one', base?: any, min?: number, max?: number, per?: boolean | 'optional', save?: boolean, manual?: string, settingsSet?: boolean, onChange?: (id: string | null) => void }} [o]
|
|
42
|
+
* @returns {Stack}
|
|
43
|
+
* @example engine.stacks.define('damageTaken', { per: true, min: 0 }); engine.mod('damageTaken', { owner: 'shield', id: 'player', mul: 0.5, for: 3 });
|
|
44
|
+
*/
|
|
45
|
+
define(name, o = {}) {
|
|
46
|
+
if (this._all.has(name)) throw codedError('mod-owner', `engine.stacks.define('${name}'): already defined; read it with engine.stacks.get('${name}')`);
|
|
47
|
+
const s = new Stack(this, name, o);
|
|
48
|
+
this._all.set(name, s);
|
|
49
|
+
if (this._pending[name]) { this._loadOne(s, this._pending[name]); delete this._pending[name]; }
|
|
50
|
+
return s;
|
|
51
|
+
}
|
|
52
|
+
/** @param {string} name @returns {Stack} */
|
|
53
|
+
get(name) {
|
|
54
|
+
const s = this._all.get(name);
|
|
55
|
+
if (!s) throw codedError('unknown-name', `engine.stacks: no shared point '${name}'. Known: ${[...this._all.keys()].join(', ')}. Define your own with engine.stacks.define('${name}', { base })`);
|
|
56
|
+
return s;
|
|
57
|
+
}
|
|
58
|
+
/** @param {string} name */
|
|
59
|
+
has(name) { return this._all.has(name); }
|
|
60
|
+
/** Names of every point */
|
|
61
|
+
list() { return [...this._all.keys()]; }
|
|
62
|
+
/**
|
|
63
|
+
* The one entry: change a shared point; returns a handle whose remove() ends only this owner's entry.
|
|
64
|
+
* @param {string} name @param {{ owner: string, set?: any, add?: number, mul?: number, clamp?: { min?: number, max?: number }, value?: any, for?: number, clock?: string, id?: string, layer?: 'engine' | 'game' | 'effect' | 'system' | 'settings' | 'debug' }} o
|
|
65
|
+
* @returns {{ owner: string, remove(): void, change(value: any): boolean }} remove() ends it; change(v) rewrites its value in place (same op, layer)
|
|
66
|
+
*/
|
|
67
|
+
mod(name, o) {
|
|
68
|
+
if (DEV) { const bad = Object.keys(o ?? {}).filter(k => !KEYS.includes(k)); if (bad.length) warnOnce(`engine.mod('${name}'): unknown option ${bad.join(', ')}; known: ${KEYS.join(', ')}`); }
|
|
69
|
+
return this.get(name).take(o ?? {});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* describe().shared: one row per point that has entries (or that the engine yielded to a three.js write):
|
|
73
|
+
* { 'time.enemies': { value, writer, layer?, at?, how?, also: [{ owner, layer, op, value, left?, at?, hidden? }] } }.
|
|
74
|
+
* Per-record points show as 'move.speed[player]'; a per: 'optional' point's every-record entries as 'move.speed[*]'.
|
|
75
|
+
*/
|
|
76
|
+
describe() {
|
|
77
|
+
const out = {};
|
|
78
|
+
for (const s of this._all.values()) {
|
|
79
|
+
if (s.per) {
|
|
80
|
+
for (const id of s.ids()) out[`${s.name}[${id}]`] = s.row(id);
|
|
81
|
+
if (s.size()) out[`${s.name}[*]`] = s.row();
|
|
82
|
+
} else if (s.size()) out[s.name] = s.row();
|
|
83
|
+
}
|
|
84
|
+
return out;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Everything one owner changes now, grouped the other way round from describe().shared: "what did rainyNight change?"
|
|
88
|
+
* @param {string} owner a module name, a game owner ('bullet-time'), 'settings', ...
|
|
89
|
+
* @returns {string[]} e.g. ['time.world (mul 0.8, effect)', 'inventory (holds)']
|
|
90
|
+
* @example engine.stacks.of('weather')
|
|
91
|
+
*/
|
|
92
|
+
of(owner) {
|
|
93
|
+
const out = [];
|
|
94
|
+
for (const s of this._all.values()) for (const [id, m] of s._by) {
|
|
95
|
+
const e = m.get(owner);
|
|
96
|
+
if (e) out.push(`${id ? `${s.name}[${id}]` : s.name} (${e.op ? `${e.op} ${JSON.stringify(e.value)}, ${e.layer}` : 'holds'})`);
|
|
97
|
+
}
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
100
|
+
/** @internal entries with a `for`, as [point, entry] */
|
|
101
|
+
_timed() {
|
|
102
|
+
const out = [];
|
|
103
|
+
for (const s of this._all.values()) for (const m of s._by.values()) for (const e of m.values()) if (e.until != null) out.push([s, e]);
|
|
104
|
+
return out;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* @internal End every entry whose time is up (core/time.js calls it after advancing the clocks), earliest first; emits mod:end for each.
|
|
108
|
+
* @returns {number} how many ended
|
|
109
|
+
*/
|
|
110
|
+
_expire() {
|
|
111
|
+
if (!this._timedDirty) return 0;
|
|
112
|
+
const timed = this._timed();
|
|
113
|
+
if (!timed.length) { this._timedDirty = false; return 0; } // nothing timed: later steps return at once until the next timed mod
|
|
114
|
+
const due = timed.map(([s, e]) => ({ s, e, over: this._nowOf(e.clock) - e.until })).filter(d => d.over >= -1e-9);
|
|
115
|
+
due.sort((a, b) => b.over - a.over); // the most overdue ended first in time
|
|
116
|
+
for (const { s, e } of due) {
|
|
117
|
+
if (!s._drop(e.owner, e.id, e)) continue;
|
|
118
|
+
this.engine.events?.emit('mod:end', { target: s.name, owner: e.owner, id: e.id });
|
|
119
|
+
}
|
|
120
|
+
return due.length;
|
|
121
|
+
}
|
|
122
|
+
/** @internal smallest time left on any timed entry, converted to game seconds by toGame(clock, left) (engine.skip ends a segment there) */
|
|
123
|
+
_untilNext(toGame) {
|
|
124
|
+
let best = Infinity;
|
|
125
|
+
for (const [, e] of this._timed()) best = Math.min(best, toGame(e.clock, Math.max(0, e.until - this._nowOf(e.clock))));
|
|
126
|
+
return best;
|
|
127
|
+
}
|
|
128
|
+
/** @internal a channel's clock jumped by delta (a load set its now): entries timed on it keep their time left, whichever save part loaded first */
|
|
129
|
+
_rebase(clock, delta) { for (const [, e] of this._timed()) if (e.clock === clock) e.until += delta; }
|
|
130
|
+
/** @internal number and value points; entries below the settings layer */
|
|
131
|
+
_save() {
|
|
132
|
+
const out = {};
|
|
133
|
+
for (const s of this._all.values()) {
|
|
134
|
+
if (s.save === false || (s.kind !== 'number' && s.kind !== 'value')) continue;
|
|
135
|
+
const list = [];
|
|
136
|
+
for (const m of s._by.values()) for (const e of m.values()) {
|
|
137
|
+
if (!saved(e)) continue;
|
|
138
|
+
list.push({ owner: e.owner, id: e.id, op: e.op, value: e.value, layer: e.layer, clock: e.clock, left: e.until == null ? null : e.until - this._nowOf(e.clock) });
|
|
139
|
+
}
|
|
140
|
+
if (list.length) out[s.name] = list;
|
|
141
|
+
}
|
|
142
|
+
return out;
|
|
143
|
+
}
|
|
144
|
+
/** @internal a load replaces every saved (engine..effect) entry; system / settings / debug entries stay (the menu that holds them is still up) */
|
|
145
|
+
_load(d) {
|
|
146
|
+
this._pending = {};
|
|
147
|
+
for (const s of this._all.values()) if (s.save !== false && (s.kind === 'number' || s.kind === 'value')) this._loadOne(s, d?.[s.name] ?? []);
|
|
148
|
+
for (const [k, v] of Object.entries(d ?? {})) if (!this._all.has(k)) this._pending[k] = v;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* @internal Replace s's saved entries with list. An owner that holds an entry now and also in the save keeps the SAME entry object, rewritten
|
|
152
|
+
* with the saved values: handles taken before the load (engine.mod, ctx.mod) still remove() / change() it. A new object here made every such
|
|
153
|
+
* handle stale in silence (a slow zone's time.world mul 0.5 stayed after leaving the zone).
|
|
154
|
+
*/
|
|
155
|
+
_loadOne(s, list) {
|
|
156
|
+
const had = new Map();
|
|
157
|
+
for (const m of [...s._by.values()]) for (const e of [...m.values()]) if (saved(e)) { had.set(`${e.id ?? ''}\0${e.owner}`, e); s._drop(e.owner, e.id, e); }
|
|
158
|
+
for (const e of list) {
|
|
159
|
+
const m = s._map(e.id, true), clock = e.clock ?? 'real', old = had.get(`${e.id ?? ''}\0${e.owner}`);
|
|
160
|
+
const fields = { since: this._at(), op: e.op, value: e.value, layer: SAVED.has(e.layer) ? e.layer : 'game', clock, until: e.left == null ? null : this._nowOf(clock) + e.left };
|
|
161
|
+
m.set(e.owner, old ? Object.assign(old, fields) : { owner: e.owner, id: e.id ?? null, where: null, ...fields });
|
|
162
|
+
this._timedDirty = true;
|
|
163
|
+
s._changed(e.id);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
package/core/startup.js
CHANGED
|
@@ -3,10 +3,21 @@
|
|
|
3
3
|
// A critical asset (manifest critical: true) that fails stops start() with the reason instead of starting a broken game.
|
|
4
4
|
|
|
5
5
|
import { reportError } from './errors.js';
|
|
6
|
+
import { asModule } from './moduleTypes.js';
|
|
6
7
|
import { catalogSnap, catalogClaim } from './catalog.js';
|
|
7
|
-
import { codedError } from './errorHints.js';
|
|
8
|
+
import { codedError, coded } from './errorHints.js';
|
|
9
|
+
import { warnOnce, DEV_SERVER } from './validate.js';
|
|
8
10
|
import { touchStart } from './inputTouch.js';
|
|
9
11
|
import { Loading, failureText } from './Loading.js';
|
|
12
|
+
import { startHeadlessLoad } from './headlessLoad.js';
|
|
13
|
+
import * as THREE from 'three';
|
|
14
|
+
import { isWebGPU, backendName, whyNoWebGPU, firstNodeMaterial, webglOnlyOn, tier as detectTier, timerContext, rendererSwapped, compileThrough } from '../render/backend.js';
|
|
15
|
+
import { bindUniforms } from '../render/engineUniforms.js';
|
|
16
|
+
import { nameShaderErrors } from '../render/shaderErrors.js';
|
|
17
|
+
import { forcedTier, defaultPixelRatio } from './tier.js';
|
|
18
|
+
import { GpuTimer } from './adaptive.js';
|
|
19
|
+
import { sceneVisitor } from './sceneDelta.js';
|
|
20
|
+
import { plugAtStart } from './plugins.js';
|
|
10
21
|
|
|
11
22
|
const DEV_STRINGS = {
|
|
12
23
|
initFailed: 'init of module {name}',
|
|
@@ -24,7 +35,7 @@ export const startupMethods = {
|
|
|
24
35
|
get loading() { return this._loading ||= new Loading(this); },
|
|
25
36
|
|
|
26
37
|
/** Start the game: init modules, preload, apply scenario parameters, wait until the world is ready. A second call returns the first call's Promise. */
|
|
27
|
-
start() { return (this._starting ??= this._start()); },
|
|
38
|
+
start() { this._born.start ||= performance.now(); return (this._starting ??= this._start()); }, // measure
|
|
28
39
|
|
|
29
40
|
/** @internal stop when dispose() ran during an await of start() */
|
|
30
41
|
_alive(at) { if (this.disposed) throw codedError('engine-disposed', DEV_STRINGS.disposed.replace('{at}', at)); },
|
|
@@ -32,10 +43,15 @@ export const startupMethods = {
|
|
|
32
43
|
/** @internal */
|
|
33
44
|
async _start() {
|
|
34
45
|
// Dev server only (npm run dev): if main.js forgot window.engine = engine, set it so the dev bridge and console can find the engine; leave an existing one alone (including tests with several engines)
|
|
35
|
-
if (
|
|
46
|
+
if (DEV_SERVER && typeof window !== 'undefined' && !window.engine) window.engine = this;
|
|
47
|
+
this._alive('starting');
|
|
48
|
+
this.phase = 'loading'; // from here until the world is built: frame hooks only, no fixed step (loop.js)
|
|
36
49
|
await this.saves.whenReady; // read the save index into memory (IndexedDB is async) so saves.list / check are synchronous afterwards
|
|
37
50
|
this._alive('reading saves');
|
|
38
|
-
this.
|
|
51
|
+
await this._startRenderer(); // WebGPURenderer: init (or fall back) before anything draws or compiles; WebGL: nothing to do
|
|
52
|
+
plugAtStart(this); // the plugins folder: before module init, so a module from a plugin inits with the others (plugins.js)
|
|
53
|
+
this._alive('plugging plugins');
|
|
54
|
+
this._checkOptional(); // optional dependencies that affect gameplay are missing: warn once in dev (modules.js)
|
|
39
55
|
if (!this.headless) this._loop();
|
|
40
56
|
this.ui._check(); // a UI part name the game set but no module declared is a typo: fail now, not silently
|
|
41
57
|
touchStart(this.input); // on-screen stick / buttons are a UI part too, so they are drawn only once the parts are settled
|
|
@@ -49,9 +65,11 @@ export const startupMethods = {
|
|
|
49
65
|
const t = performance.now(); // measure
|
|
50
66
|
this._setModState(m, 'initializing'); // no hooks until init succeeded (modules.js)
|
|
51
67
|
const snap = catalogSnap(this); // what init registers belongs to this module in engine.catalog()
|
|
52
|
-
|
|
68
|
+
const inst = this._modInst.get(m.name); // a plugin removed while init awaits: its completion must not touch a same-named newcomer (modules.js)
|
|
69
|
+
try { await asModule(this, m, () => m.init(this, this._modCtx(m, inst))); if (this._isLive(m.name, inst)) { catalogClaim(this, m.name, snap); this._setModState(m, 'running'); } L._done(task); }
|
|
53
70
|
catch (e) {
|
|
54
|
-
L._fail(task, e);
|
|
71
|
+
L._fail(task, e);
|
|
72
|
+
if (this._isLive(m.name, inst)) { this._setModState(m, 'failed'); this._dropTracked(m.name); } // a failed module keeps no listener on half-built state
|
|
55
73
|
// a critical module stops start() with the reason (below); any other failure is reported by severity and start() goes on
|
|
56
74
|
if (!m.critical) reportError(this, e, DEV_STRINGS.initFailed.replace('{name}', m.name), { module: m });
|
|
57
75
|
}
|
|
@@ -62,9 +80,9 @@ export const startupMethods = {
|
|
|
62
80
|
this._started = true; // a module installed from now on runs its init at once (modules.js)
|
|
63
81
|
const tp = performance.now(); // measure
|
|
64
82
|
const progress = p => ls?.update({ progress: 0.2 + p * 0.3, text: L.text() ?? this.t('common.loadingAssets') });
|
|
65
|
-
// fonts the UI
|
|
83
|
+
// fonts the UI picture names (ui.fonts: asset names) load with the preload, so the first menu never flashes the fallback font;
|
|
66
84
|
// an unknown name rejects here with the manifest line to add
|
|
67
|
-
await Promise.all([this.assets.preload(progress), ...
|
|
85
|
+
await Promise.all([this.assets.preload(progress), ...this.ui.fonts.map(n => this.assets.font(n))]);
|
|
68
86
|
const preloadMs = ms(tp), tr = performance.now(); // measure
|
|
69
87
|
this._alive('preloading assets');
|
|
70
88
|
if (this._fatal().length) return this._blocked(this._fatal());
|
|
@@ -75,23 +93,145 @@ export const startupMethods = {
|
|
|
75
93
|
await this._waitReady(timing, tr, ms, v => { streamMs = v; }, () => streamMs).catch(why => Array.isArray(why) ? this._blocked(why) : Promise.reject(why));
|
|
76
94
|
// Compile every visible material for the current lights now, behind the loading screen, instead of stalling the first frame that shows it
|
|
77
95
|
// (async where the browser has KHR_parallel_shader_compile). A later change in the number of lights compiles again: see recipes/09 "Lights and stalls"
|
|
96
|
+
this._checkBackendScene(); // the scene is built now: materials the chosen backend cannot draw fail by name, not as a blank picture
|
|
78
97
|
const tc = performance.now(); // measure
|
|
79
|
-
|
|
80
|
-
|
|
98
|
+
// Everything below is handed to the parallel compile together, then awaited once: the scene, and on WebGL the post chain's fullscreen passes
|
|
99
|
+
// compile for the target the scene really draws into (the composer's when post is on): see PostFX._sceneTarget.
|
|
100
|
+
// compile() runs synchronously inside compileAsync, so the target only needs to be set around the call, not across the await
|
|
101
|
+
const r = this.renderer, target = this.post._sceneTarget();
|
|
102
|
+
r.setRenderTarget(target);
|
|
103
|
+
let compiling;
|
|
104
|
+
try { compiling = r.compileAsync(this.scene, this.camera); } finally { r.setRenderTarget(null); }
|
|
105
|
+
// the chain's passes draw through three themselves, so compileAsync of the scene never sees their materials: a dry run of the chain
|
|
106
|
+
// (render/backend.js compileThrough) starts them now instead of one by one in the warm-up frame (~130 ms measured, nine passes).
|
|
107
|
+
// Not on WebGPU: its passes are nodes of one pipeline whose inner renders run only inside a real frame
|
|
108
|
+
const post = !this.headless && this.post.active && !isWebGPU(r) ? compileThrough(r, () => this.post.render(0)) : null;
|
|
109
|
+
// the page's thread is idle until the GPU is done: the one-time warm-ups modules queued run now instead of in the first frame (rigid)
|
|
110
|
+
for (const f of this._whileCompiling.splice(0)) { try { f(); } catch (err) { reportError(this, err, 'warm-up while compiling', { soft: true }); } }
|
|
111
|
+
await Promise.all([compiling, post]);
|
|
81
112
|
this._alive('compiling shaders');
|
|
82
|
-
|
|
113
|
+
// One hidden frame behind the loading screen: shadow depth materials, the post passes and the background quad are programs compileAsync
|
|
114
|
+
// never sees, and without this frame they compiled in the first frame the player saw (a 300 ms hitch measured)
|
|
115
|
+
if (!this.headless) { try { this._render(0); } catch (err) { reportError(this, err, 'render (warm-up frame)', { soft: true }); } }
|
|
116
|
+
const compileMs = ms(tc), tReady = performance.now(); // measure
|
|
117
|
+
this.phase = 'ready'; // fixed steps run from the next one on: game time starts here on every machine (loop.js)
|
|
83
118
|
this.commits.rebase(); // background results registered during loading restart timing from now (see Commits.js)
|
|
84
119
|
// Startup timing: totalMs from page open to playable, startMs from start() to playable
|
|
85
|
-
|
|
120
|
+
// firstFrameMs (page open to the end of the first frame drawn after the loading screen) and its phases, which add up to it: script (page
|
|
121
|
+
// open until createEngine), construct (createEngine), setup (game code until start(), installs included), init (saves, renderer, module
|
|
122
|
+
// init), preload, world (scenario parameters, nearby builds), compile (shaders + hidden warm-up frame), draw (ready until that frame's
|
|
123
|
+
// draw calls were submitted; loop.js). draw and firstFrameMs stay null until the frame, and with no real-time loop (headless)
|
|
124
|
+
const b = this._born, d = (a, z) => Math.round(z - a); // measure
|
|
125
|
+
const phases = { script: Math.round(b.at), construct: d(b.at, b.built), setup: d(b.built, b.start), init: d(b.start, tp), preload: d(tp, tr), world: d(tr, tc), compile: d(tc, tReady), draw: null };
|
|
126
|
+
this.startup = { totalMs: Math.round(performance.now()), startMs: ms(t0), preloadMs, streamMs, compileMs, firstFrameMs: null, phases, modules: timing }; // measure
|
|
127
|
+
this._readyAt = tReady;
|
|
86
128
|
this.budget.checkStartup(this.startup);
|
|
87
129
|
ls?.update({ progress: 1, text: '' }); ls?.hide();
|
|
88
130
|
this.ops.allow(() => this.events.emit('engine:ready')); // engine:ready listeners finish setting up the game; still loading for the ops guard
|
|
89
131
|
this.session._capture(); // the state engine.session.newGame() returns to: set up, nothing played yet
|
|
90
132
|
this.ui.open('title'); // the title screen, only when the game turned it on (createEngine({ ui: { title: {...} } }))
|
|
91
133
|
await this._urlState.late(); // scenario parameters: skip the cutscene, wait, align the time, then emit state:applied
|
|
134
|
+
startHeadlessLoad(this); // headless: what the game sets up after start (a species, a teleport) still loads with no step() (headlessLoad.js)
|
|
135
|
+
this._alive('applying scenario parameters');
|
|
136
|
+
this.phase = 'running';
|
|
92
137
|
return this;
|
|
93
138
|
},
|
|
94
139
|
|
|
140
|
+
/**
|
|
141
|
+
* @internal The WebGPU route (docs/plans/2026-11-03-webgpu-phase2.md section 1.2; Engine already checked threedog/tsl is loaded): find out
|
|
142
|
+
* whether WebGPU is there, then init or fall back by createEngine({ fallback }). Whatever it falls back to is said loudly and kept in
|
|
143
|
+
* describe().renderer. Why probe before init(): three falls back to WebGL2 silently and loses the reason, and once its WebGL2 backend took
|
|
144
|
+
* the canvas, fallback 'webgl' could not hand a clean canvas to WebGLRenderer.
|
|
145
|
+
*/
|
|
146
|
+
async _startRenderer() {
|
|
147
|
+
const r = this.renderer, want = this._backendWant;
|
|
148
|
+
if (!isWebGPU(r)) { this._backend = { requested: 'webgl', backend: 'webgl', reason: null }; return; }
|
|
149
|
+
const forced = !!r.backend?.parameters?.forceWebGL; // the game asked for the WebGL2 backend itself: not a fallback
|
|
150
|
+
let reason = forced || (r.initialized && r.backend.isWebGPUBackend) ? null : await whyNoWebGPU();
|
|
151
|
+
this._alive('looking for WebGPU');
|
|
152
|
+
if (reason && want.fallback === 'error') {
|
|
153
|
+
throw codedError('renderer-backend', `[threedog] WebGPU unavailable (${reason}) and createEngine({ fallback: 'error' }) asked not to fall back; `
|
|
154
|
+
+ "fallback: 'webgl2' runs the same renderer on WebGL2 (your TSL keeps working), 'webgl' runs WebGLRenderer (GLSL only)");
|
|
155
|
+
}
|
|
156
|
+
if (reason && want.fallback === 'webgl') this._swapToWebGL(r);
|
|
157
|
+
else if (!r.initialized) { await r.init(); this._alive('initializing WebGPU'); }
|
|
158
|
+
const backend = backendName(this.renderer);
|
|
159
|
+
// the probe said yes but three still fell back (a device lost in between): say so all the same
|
|
160
|
+
if (!forced && backend === 'webgl2') reason ??= 'three fell back to its WebGL2 backend during init()';
|
|
161
|
+
if (reason && want.fallback === 'error') throw codedError('renderer-backend', `[threedog] WebGPU unavailable (${reason}) and createEngine({ fallback: 'error' }) asked not to fall back`);
|
|
162
|
+
this._backend = { requested: 'webgpu', backend, reason: forced ? 'forceWebGL: true (asked for by the game)' : reason };
|
|
163
|
+
// loud on purpose: a game that chose WebGPU runs 1.5-1.9x slower on the WebGL2 backend, or without its TSL on WebGLRenderer
|
|
164
|
+
if (reason && !forced) warnOnce(coded('renderer-backend', `[threedog] WebGPU unavailable (${reason}), running ${backend}; createEngine({ renderer: 'webgpu', fallback: 'webgl2' | 'webgl' | 'error' })`));
|
|
165
|
+
// the GPU is known only now (adapterInfo after init): the default quality follows the real device
|
|
166
|
+
if (!(this.headless && forcedTier())) {
|
|
167
|
+
const t = detectTier(this.renderer);
|
|
168
|
+
if (t !== this.tier && this._ownsRenderer && this._createParams.pixelRatio == null) this.renderer.setPixelRatio(defaultPixelRatio(devicePixelRatio || 1, t));
|
|
169
|
+
// MSAA defaults from the tier too (Engine.js: antialias ?? tier !== 'low'); decided from a WebGL probe before the WebGPU
|
|
170
|
+
// adapter was known, so a low-tier device could keep MSAA on the WebGPU route (found by the WebGPU parity test). Untouched when the game
|
|
171
|
+
// chose, or changed it since. The renderer's own samples stay as made: the new value then runs through the post chain (PostFX active)
|
|
172
|
+
const aaDefault = this._createParams.antialias == null && this.post.antialias === (this.tier !== 'low');
|
|
173
|
+
if (t !== this.tier && aaDefault) this.post.setAntialias(t !== 'low');
|
|
174
|
+
this.tier = t;
|
|
175
|
+
}
|
|
176
|
+
this.post?._sync(); // effects held by tier or backend (PostFX _held) are only known now
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* @internal fallback 'webgl': drop the WebGPURenderer (never initialized, so the canvas has no context yet) for a WebGLRenderer on the
|
|
181
|
+
* same canvas, carrying over what was already set on it (size, scale, tone, shadows, clear color) and what the engine hooked onto it.
|
|
182
|
+
* @param {any} old
|
|
183
|
+
*/
|
|
184
|
+
_swapToWebGL(old) {
|
|
185
|
+
// the canvas's own MSAA as the post chain wants it, so an effect-free frame still draws straight to the canvas (PostFX active)
|
|
186
|
+
const r = new THREE.WebGLRenderer({ canvas: old.domElement, antialias: this.post.antialias, powerPreference: 'high-performance' });
|
|
187
|
+
const size = old.getSize(new THREE.Vector2());
|
|
188
|
+
r.setPixelRatio(old.getPixelRatio()); r.setSize(size.x, size.y, false);
|
|
189
|
+
r.shadowMap.enabled = old.shadowMap.enabled; r.shadowMap.type = old.shadowMap.type;
|
|
190
|
+
r.toneMapping = old.toneMapping; r.toneMappingExposure = old.toneMappingExposure; r.outputColorSpace = old.outputColorSpace;
|
|
191
|
+
r.setClearColor(old.getClearColor(new THREE.Color()), old.getClearAlpha());
|
|
192
|
+
r.info.autoReset = false;
|
|
193
|
+
nameShaderErrors(r); bindUniforms(r, this.uniforms);
|
|
194
|
+
try { old.dispose(); } catch { /* never initialized: nothing of it reached the GPU */ }
|
|
195
|
+
// owned rows name the renderer object they live on (tween exemptions, core/owned.js)
|
|
196
|
+
for (const row of [this._oTone, this._oPixelRatio]) if (row) row.objects = row.objects.map(o => (o === old ? r : o));
|
|
197
|
+
this.renderer = r;
|
|
198
|
+
// parts built for the old renderer before start(): the post chain (its backend and every effect's part), then whatever registered a rebuild
|
|
199
|
+
this.post._setBackend();
|
|
200
|
+
rendererSwapped(this);
|
|
201
|
+
if (this._gpu) this._gpu = new GpuTimer(timerContext(r));
|
|
202
|
+
},
|
|
203
|
+
|
|
204
|
+
/** @internal After the world is built, before compiling: what the backend in use cannot draw is an error naming it (plan section 1.3) */
|
|
205
|
+
_checkBackendScene() {
|
|
206
|
+
const b = this._backend;
|
|
207
|
+
if (b?.requested !== 'webgpu') return;
|
|
208
|
+
if (b.backend === 'webgl') {
|
|
209
|
+
const hit = firstNodeMaterial(this.scene);
|
|
210
|
+
if (hit) throw codedError('renderer-backend', `[threedog] ${hit.material.type} on ${hit.object.type} '${hit.object.name || '(unnamed)'}' is a NodeMaterial (TSL), and `
|
|
211
|
+
+ `createEngine({ fallback: 'webgl' }) is running WebGLRenderer, which cannot draw it (WebGPU unavailable: ${b.reason}). Use fallback: 'webgl2' `
|
|
212
|
+
+ '(the same WebGPURenderer on WebGL2: TSL keeps working), or give these objects a GLSL material too');
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
// one visitor on the engine's "entered the scene" mechanism (core/sceneDelta.js): the whole scene now, then only what is added later,
|
|
216
|
+
// checked each frame by _checkBackendAdds; a material swapped in (mesh.material = m) counts as an add.
|
|
217
|
+
// shortcut: an onBeforeCompile assigned to a material already in the scene is not seen; an add after it is. Upgrade if games do that.
|
|
218
|
+
const found = [];
|
|
219
|
+
this._webglOnlyView = sceneVisitor(this.scene, { enter: o => { if (o.material) { const msg = webglOnlyOn(o); if (msg) found.push(msg); } } });
|
|
220
|
+
this._webglOnlyFound = found;
|
|
221
|
+
this._webglOnlyView.sync();
|
|
222
|
+
if (found.length) { const msg = found[0]; found.length = 0; throw codedError('renderer-backend', `[threedog] ${msg}`); }
|
|
223
|
+
},
|
|
224
|
+
/** @internal Per frame on the WebGPU route: what entered the scene since the last frame and will not draw there is an error naming it (reportError) */
|
|
225
|
+
_checkBackendAdds() {
|
|
226
|
+
const v = this._webglOnlyView;
|
|
227
|
+
if (!v) return;
|
|
228
|
+
v.sync();
|
|
229
|
+
const found = this._webglOnlyFound;
|
|
230
|
+
if (!found.length) return;
|
|
231
|
+
const msgs = found.splice(0);
|
|
232
|
+
for (const msg of msgs) reportError(this, codedError('renderer-backend', `[threedog] ${msg} (added after start())`), msg);
|
|
233
|
+
},
|
|
234
|
+
|
|
95
235
|
/** Critical items that failed: assets, track() steps and modules declared critical: true (a non-critical module's init error goes through reportError instead) */
|
|
96
236
|
_fatal() { return this.loading.list({ phase: 'failed' }).filter(t => t.critical); },
|
|
97
237
|
|
|
@@ -99,7 +239,7 @@ export const startupMethods = {
|
|
|
99
239
|
_blocked(fatal) {
|
|
100
240
|
const err = codedError(fatal.some(t => t.kind === 'module') ? 'module-critical' : 'asset-critical', DEV_STRINGS.blocked.replace('{n}', String(fatal.length)).replace('{list}', fatal.map(failureText).join('\n ')));
|
|
101
241
|
this.ui.get('loading')?.update({ progress: 1, text: this.t('loading.failed', { name: fatal.map(t => t.name).join(', ') }), failed: fatal });
|
|
102
|
-
|
|
242
|
+
reportError(this, err, 'engine.start()', { soft: true }); // logged once (errors.log in dev), then start() rejects with it
|
|
103
243
|
throw err;
|
|
104
244
|
},
|
|
105
245
|
|
package/core/streamSources.js
CHANGED
|
@@ -60,14 +60,3 @@ export class Source {
|
|
|
60
60
|
this._settle(codedError('stream-removed', SOURCE_STRINGS.removed.replace('{name}', this.name))); // an await on whenReady never hangs
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Ring of a chunk (cx, cz) from the nearest stream source, in chunk units. `centers` are the sources in chunk units ({ cx, cz, simple }); a simple
|
|
66
|
-
* source counts as the outer ring (far look, no near detail). Shared by the terrain and vegetation chunk tables so both rings mean the same.
|
|
67
|
-
* @internal
|
|
68
|
-
*/
|
|
69
|
-
export function chunkRing(cx, cz, centers, viewChunks) {
|
|
70
|
-
let r = Infinity;
|
|
71
|
-
for (const s of centers) r = Math.min(r, Math.max(Math.abs(cx - s.cx), Math.abs(cz - s.cz), s.simple ? viewChunks : 0));
|
|
72
|
-
return r;
|
|
73
|
-
}
|
package/core/targeting.js
CHANGED
|
@@ -10,7 +10,7 @@ const yawOf = view => typeof view === 'number' ? view : Math.atan2(view.x, view.
|
|
|
10
10
|
/** Candidate position: an Object3D / NPC / Character / world record has .position; a Vector3 / { x, z } / [x, y, z] is the position itself */
|
|
11
11
|
const posOf = c => c.position ?? c;
|
|
12
12
|
function check(fn, opts) {
|
|
13
|
-
if ('range' in opts) throw codedError('unknown-option', `${fn}(): the distance option is radius (meters), as in
|
|
13
|
+
if ('range' in opts) throw codedError('unknown-option', `${fn}(): the distance option is radius (meters), as in world.query: write { radius: ${opts.range} }`);
|
|
14
14
|
for (const k of Object.keys(opts)) if (!KEYS.includes(k)) throw codedError('unknown-option', `${fn}(): unknown option '${k}'; available: ${KEYS.join(', ')}`);
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Estimated GPU bytes of a three.js texture (engine.inspect.materials / engine.inspect.perf). An estimate: three.js does not report VRAM.
|
|
2
|
+
// Compressed / data textures: their data size; images: width x height x bytes per texel, x 4/3 with mipmaps, x 6 for a cube.
|
|
3
|
+
const PER_CHANNEL = { 1009: 1, 1010: 1, 1011: 2, 1012: 2, 1013: 4, 1014: 4, 1015: 4, 1016: 2 }; // three's type constants UnsignedByte ... HalfFloat
|
|
4
|
+
const CHANNELS = { 1021: 1, 1022: 3, 1023: 4, 1024: 1, 1025: 2, 1028: 1, 1030: 2, 1033: 4 }; // Alpha, RGB, RGBA, Luminance, LuminanceAlpha, Red, RG, RGBAInteger
|
|
5
|
+
|
|
6
|
+
/** @param {any} t a THREE.Texture @returns {number} estimated bytes on the GPU (0 when unknown) */
|
|
7
|
+
export function textureBytes(t) {
|
|
8
|
+
if (!t) return 0;
|
|
9
|
+
if (t.isCompressedTexture) return (t.mipmaps || []).reduce((s, m) => s + (m?.data?.byteLength ?? 0), 0) * (t.isCubeTexture ? 6 : 1);
|
|
10
|
+
const faces = Array.isArray(t.image) ? t.image : [t.image];
|
|
11
|
+
const i = faces[0];
|
|
12
|
+
if (!i) return 0;
|
|
13
|
+
const w = i.width ?? i.videoWidth ?? 0, h = i.height ?? i.videoHeight ?? 0, d = i.depth ?? 1;
|
|
14
|
+
const texel = (PER_CHANNEL[t.type] ?? 1) * (CHANNELS[t.format] ?? 4);
|
|
15
|
+
const mips = t.generateMipmaps !== false && t.minFilter !== 1006 && t.minFilter !== 1003 ? 4 / 3 : 1; // Linear / Nearest min filter: no mip chain
|
|
16
|
+
return Math.round(w * h * d * texel * mips * faces.length);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Bytes as a short MB / KB string @param {number} b */
|
|
20
|
+
export const mb = b => b >= 1048576 ? `${(b / 1048576).toFixed(1)} MB` : `${Math.round(b / 1024)} KB`;
|
package/core/thingExplain.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// Why one object: an AI asked "why is this crate here, blocking me, and how do I change it?" otherwise joins thing(), world.origin, material info, the
|
|
3
3
|
// template, collision settings and the op list by hand. Each part reads an existing source; nothing here is stored or changes any state.
|
|
4
4
|
import { materialInfo } from './MaterialInfo.js';
|
|
5
|
+
import { orNull } from './util.js';
|
|
5
6
|
|
|
6
7
|
const MAT_MAX = 8;
|
|
7
|
-
const safe = f => { try { return f(); } catch { return null; } };
|
|
8
8
|
|
|
9
9
|
/** Unique materials under obj with role / name / where the spec came from */
|
|
10
10
|
function materialsOf(obj) {
|
|
@@ -13,7 +13,7 @@ function materialsOf(obj) {
|
|
|
13
13
|
for (const m of [o.material].flat()) {
|
|
14
14
|
if (!m || seen.has(m)) continue;
|
|
15
15
|
seen.add(m);
|
|
16
|
-
if (out.length < MAT_MAX) { const i = materialInfo(m, o); out.push({ role: i.role, name: m.name || null, from: i.from,
|
|
16
|
+
if (out.length < MAT_MAX) { const i = materialInfo(m, o); out.push({ role: i.role, name: m.name || null, from: i.from, type: i.type, color: i.color, mesh: o.name || null }); }
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
19
|
if (seen.size > MAT_MAX) out.push({ more: seen.size - MAT_MAX });
|
|
@@ -63,6 +63,6 @@ export function explainThing(e, t) {
|
|
|
63
63
|
};
|
|
64
64
|
// Explain contributions (arch #6): a module that owns records or templates adds to the object with e._things.explainers.push((e, t, out) => { ... }),
|
|
65
65
|
// so core never reads their shapes. A throwing explainer is skipped: explain is a diagnostic and must not fail because of one part.
|
|
66
|
-
for (const f of T.explainers)
|
|
66
|
+
for (const f of T.explainers) orNull(() => f(e, t, out));
|
|
67
67
|
return out;
|
|
68
68
|
}
|
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
|
}
|