threedog 0.2.1 → 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 +71 -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 +183 -59
- 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 +37 -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 +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 +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 +100 -41
- 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 +63 -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 +87 -100
- package/docs/API.md +32 -28
- package/docs/CODEMAP.md +220 -147
- package/docs/COMMANDS.md +56 -35
- package/docs/CONVENTIONS.md +90 -28
- 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 +11 -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 +38 -23
- 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 +63 -60
- 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 +28 -26
- 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 +29 -13
- package/docs/api/triggers.md +5 -10
- package/docs/api/vegetation.md +11 -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 +48 -34
- package/docs/recipes/02-npc.md +24 -7
- package/docs/recipes/03-items-pickups.md +35 -21
- package/docs/recipes/04-quests.md +12 -5
- package/docs/recipes/05-props-bake.md +151 -15
- package/docs/recipes/06-clock-events.md +100 -52
- package/docs/recipes/07-flow-scenes-pause.md +40 -9
- package/docs/recipes/08-weather-sky.md +145 -36
- package/docs/recipes/{09-style-pack.md → 09-style.md} +101 -52
- package/docs/recipes/10-blender-level.md +14 -2
- package/docs/recipes/11-vehicles.md +64 -7
- package/docs/recipes/13-animation.md +14 -6
- package/docs/recipes/14-custom-module.md +61 -29
- package/docs/recipes/15-perf.md +30 -9
- package/docs/recipes/16-dev-bridge.md +61 -37
- package/docs/recipes/18-world.md +16 -6
- package/docs/recipes/19-shooting-picking.md +6 -6
- package/docs/recipes/20-content-actions-save.md +55 -17
- package/docs/recipes/21-camera.md +49 -16
- package/docs/recipes/22-shop-gold.md +3 -3
- package/docs/recipes/23-ops.md +16 -10
- package/docs/recipes/26-ui-parts.md +61 -12
- package/docs/recipes/27-net.md +11 -5
- package/docs/recipes/28-terrain.md +34 -1
- package/docs/recipes/29-grid.md +34 -16
- 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 +26 -3
- package/docs/recipes/35-style-from-reference.md +88 -19
- package/docs/recipes/36-sky-ground-plant-looks.md +18 -18
- package/docs/recipes/37-terrain-look-hooks.md +3 -2
- package/docs/recipes/38-environment-look-hooks.md +37 -26
- package/docs/recipes/40-scene.md +16 -13
- package/docs/recipes/41-thing-registry.md +11 -7
- package/docs/recipes/42-terrain-shape.md +2 -2
- package/docs/recipes/43-shader-patches-surface-looks.md +158 -76
- package/docs/recipes/44-water-weather-look-hooks.md +26 -17
- package/docs/recipes/45-cascaded-shadows.md +16 -7
- package/docs/recipes/47-island-snow-backdrop.md +7 -7
- package/docs/recipes/48-make-material.md +11 -6
- package/docs/recipes/49-game-module-contract.md +30 -17
- package/docs/recipes/50-own-renderer.md +2 -2
- package/docs/recipes/51-capability-catalog.md +3 -3
- package/docs/recipes/52-look.md +197 -61
- package/docs/recipes/53-ground-up-close.md +1 -1
- 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 -14
- 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/templates.js +1 -1
- package/examples/styletest/content/vegetation.js +1 -1
- package/examples/styletest/look.js +1 -1
- package/examples/styletest/main.js +17 -16
- 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 +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 +17 -13
- package/examples/world/style/index.js +61 -0
- package/examples/world/style/plugins/10-bloom.js +5 -0
- package/index.d.ts +44 -45
- package/index.js +26 -22
- package/llms.txt +11 -4
- 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 +177 -42
- package/modules/characters/NPC.js +87 -36
- package/modules/characters/assetModel.js +4 -13
- 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 +2 -1
- 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 +96 -27
- 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 +186 -110
- package/modules/vegetation/densityMap.js +62 -0
- package/modules/vegetation/groundChunks.js +52 -58
- package/modules/vegetation/index.js +32 -11
- 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 +8 -2
- 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 +7 -3
- package/presets.js +41 -27
- package/render/PostFX.js +145 -120
- package/render/backend.js +440 -0
- package/render/detail.js +120 -39
- 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 +614 -240
- package/types/gameplay.d.ts +482 -312
- 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 +109 -81
- package/types/tsl.d.ts +86 -0
- package/types/world.d.ts +158 -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 -22
- package/docs/api/entities.md +0 -61
- 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/Describe.js
CHANGED
|
@@ -15,18 +15,29 @@
|
|
|
15
15
|
// Display names (ground type, weather name) are not hard-coded here: they come from the string table, ground.<type> and weather.<name> (registered by the terrain and weather modules), and go into groundName / label.
|
|
16
16
|
// describeText, which turns this into text, lives in describeText.js.
|
|
17
17
|
import { describeText } from './describeText.js';
|
|
18
|
+
import { moduleRow } from './moduleTypes.js';
|
|
18
19
|
import { inspect, explain } from './Inspect.js';
|
|
19
20
|
import { inspectScene } from './InspectScene.js';
|
|
20
|
-
import {
|
|
21
|
+
import { inspectMaterials } from './InspectMaterials.js';
|
|
22
|
+
import { inspectPerf } from './InspectPerf.js';
|
|
23
|
+
import { codedError, coded } from './errorHints.js';
|
|
21
24
|
import { r1 } from './math.js';
|
|
22
25
|
import { describeRender } from './describeRender.js';
|
|
23
26
|
import { describeLook } from './look/report.js';
|
|
27
|
+
import { describeOwned } from './owned.js';
|
|
24
28
|
import { describeScene } from './thingOps.js';
|
|
29
|
+
import { describeHolds } from './holds.js';
|
|
30
|
+
import { warnOnce } from './validate.js';
|
|
31
|
+
import { stats } from '../render/backend.js';
|
|
32
|
+
import { threePatches } from './threePatches.js';
|
|
33
|
+
import { describeSlots } from './plugins.js';
|
|
34
|
+
/** describe().perf's draw counters (render/backend.js reads them per renderer) @param {any} r */
|
|
35
|
+
const drawStats = r => { const s = stats(r); return { drawCalls: s.drawCalls, triangles: s.triangles }; };
|
|
25
36
|
|
|
26
37
|
const NEAR_RADIUS = 30, NEAR_MAX = 15;
|
|
27
38
|
const COMPASS = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW']; // north = -Z, east = +X
|
|
28
39
|
const RELATIVE = ['front', 'front-right', 'right', 'back-right', 'back', 'back-left', 'left', 'front-left']; // relative to the camera heading
|
|
29
|
-
const STANDARD = new Set(['ready', 'error', 'disabledModules', 'moduleStates', 'loading', 'time', 'player', 'camera', 'nearbyRadius', 'nearby', 'actions', 'ui', 'cutscene', 'modules', 'perf', 'scene', 'render', 'look']);
|
|
40
|
+
const STANDARD = new Set(['ready', 'error', 'disabledModules', 'moduleStates', 'loading', 'time', 'player', 'camera', 'nearbyRadius', 'nearby', 'actions', 'ui', 'cutscene', 'modules', 'perf', 'scene', 'render', 'look', 'owned', 'shared', 'control']);
|
|
30
41
|
const ACTIONS_MAX = 8; // what the player can do now, with why not: saves the AI a guess for a few dozen characters // the core's own fields
|
|
31
42
|
const sector = a => Math.round(((a % (Math.PI * 2)) + Math.PI * 2) / (Math.PI / 4)) % 8;
|
|
32
43
|
|
|
@@ -42,9 +53,21 @@ export function describeApi(e) {
|
|
|
42
53
|
const extras = new Map();
|
|
43
54
|
/**
|
|
44
55
|
* Current game state (plain object, JSON.stringify-able). radius: how far counts as "nearby" (meters), default 30
|
|
45
|
-
* @param {{ radius?: number, center?: { x: number, z: number } }} [opts] center: measure "nearby" from here instead
|
|
56
|
+
* @param {string | string[] | { radius?: number, center?: { x: number, z: number }, only?: string[] }} [opts] center: measure "nearby" from here instead
|
|
57
|
+
* of the player (inspect uses it); only: just these top-level sections (a name or an array is short for { only }), e.g. describe('look')
|
|
58
|
+
* or describe({ only: ['look', 'shared'] }). Why: the whole object is ~40 KB on a mid-size world, most of it engine tables (shared, look, slots)
|
|
59
|
+
* that a question about one part does not need, and only the asked sections are built. An unknown section name is reported in the result as unknownSections, never a silent {}
|
|
60
|
+
* @example engine.describe('player').player.x
|
|
46
61
|
*/
|
|
47
|
-
const api = opts =>
|
|
62
|
+
const api = opts => {
|
|
63
|
+
const o = typeof opts === 'string' || Array.isArray(opts) ? { only: [opts].flat() } : opts ?? {};
|
|
64
|
+
const part = describe(e, o, extras);
|
|
65
|
+
if (part) return part;
|
|
66
|
+
// a name that is not a section this time: build everything once to say which sections exist
|
|
67
|
+
const all = describe(e, { ...o, only: undefined }, extras);
|
|
68
|
+
const out = Object.fromEntries(o.only.filter(k => k in all).map(k => [k, all[k]])), unknown = o.only.filter(k => !(k in all));
|
|
69
|
+
return { ...out, unknownSections: unknown, sections: Object.keys(all) };
|
|
70
|
+
};
|
|
48
71
|
/** @internal engine.catalog() reads which names were added (and by which module) */ api._extras = extras;
|
|
49
72
|
/**
|
|
50
73
|
* Register the game's own state: the return value of fn(engine, ctx) (must be JSON-able) goes into describe().<name>; undefined is omitted
|
|
@@ -59,62 +82,95 @@ export function describeApi(e) {
|
|
|
59
82
|
return { remove: () => { extras.delete(name); } };
|
|
60
83
|
};
|
|
61
84
|
/** Text of describe(): a summary by default; { path: 'world' } one part as JSON; { full: true } everything (see describeText.js) */
|
|
62
|
-
|
|
63
|
-
const
|
|
85
|
+
// game: the describe.add names, so the summary lists the game's own state before engine tables (it is what the game author asked to see)
|
|
86
|
+
const text = ({ full, path, ...opts } = {}) => describeText(api(opts), { full, path, game: [...extras.keys()] });
|
|
87
|
+
const inspectApi = Object.assign((at, opts) => inspect(e, at, opts), { scene: opts => inspectScene(e, opts),
|
|
88
|
+
materials: opts => inspectMaterials(e, opts), perf: opts => inspectPerf(e, opts) });
|
|
64
89
|
return { describe: api, describeText: text, inspect: inspectApi, explain: q => explain(e, q) };
|
|
65
90
|
}
|
|
66
91
|
|
|
67
|
-
/** Only the modules that are not running normally (initializing / failed) appear in describe, so the common case adds nothing; engine.moduleStates has all of them */
|
|
92
|
+
/** Only the modules that are not running normally (initializing / failed) appear in describe, so the common case adds nothing (null); engine.moduleStates has all of them */
|
|
68
93
|
function pendingModules(e) {
|
|
69
94
|
const out = {};
|
|
70
95
|
for (const [name, st] of e._modState) if (st === 'initializing' || st === 'failed') out[name] = st;
|
|
71
|
-
return Object.keys(out).length ?
|
|
96
|
+
return Object.keys(out).length ? out : null;
|
|
72
97
|
}
|
|
73
98
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
99
|
+
// Engine tables no module hook writes into (hooks add to time / player / camera / ui / perf / cutscene / nearby): a describe({ only }) that asks
|
|
100
|
+
// for nothing else skips the hooks, describe.add and the action list
|
|
101
|
+
const TABLES = new Set(['ready', 'error', 'disabledModules', 'loading', 'holds', 'input', 'control', 'shared', 'modules', 'slots', 'scene', 'threePatches', 'owned', 'look', 'render', 'renderer']);
|
|
102
|
+
const NONE = Symbol('none'); // a conditional section that is absent this time
|
|
79
103
|
|
|
80
|
-
/**
|
|
81
|
-
|
|
104
|
+
/**
|
|
105
|
+
* Build the state object. radius: how far counts as "nearby"; extras: those registered by describe.add; only: build just these top-level
|
|
106
|
+
* sections (the other core sections are built on first touch, so a hook that writes ctx.out.time still works). Returns null when a requested
|
|
107
|
+
* name is not a section this time: api() then builds everything to name the sections that exist
|
|
108
|
+
*/
|
|
109
|
+
function describe(e, { radius = NEAR_RADIUS, center: at, only } = {}, extras) {
|
|
82
110
|
const p = e.player?.position, center = at || p || e.focus, cam = e.camera;
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
ready: e.ready,
|
|
86
|
-
error: e.error, // gameplay error in dev / tests (gameplay is frozen)
|
|
87
|
-
|
|
88
|
-
...
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
111
|
+
/** @type {Record<string, () => any>} the core's sections in output order; NONE = left out */
|
|
112
|
+
const core = {
|
|
113
|
+
ready: () => e.ready,
|
|
114
|
+
error: () => e.error, // gameplay error in dev / tests (gameplay is frozen)
|
|
115
|
+
unhandled: () => e._unhandled || NONE, // dev: first promise rejection nobody caught, and how many followed (errors.js)
|
|
116
|
+
disabledModules: () => [...e.disabledModules], // look / ui modules disabled after an error
|
|
117
|
+
moduleStates: () => pendingModules(e) ?? NONE, // while a module is initializing or failed
|
|
118
|
+
loading: () => e.loading.view(), // what is pending / failed and whether it blocks the start (Loading.js)
|
|
119
|
+
time: () => ({ tick: e.tick, real: r1(e.time.now('real')), ambient: r1(e.time.now('ambient')), calendar: r1(e.clock.now), paused: e.paused, frozen: e.frozen, ...(e.frozen ? { frozenBy: e.stacks.get('freeze').names() } : {}), headless: e.headless, run: e.runState,
|
|
120
|
+
channels: e.time.describe(), rate: e.clock.rate }),
|
|
121
|
+
holds: () => describeHolds(e), // who holds pause / freeze / camera / input (holds.js)
|
|
122
|
+
input: () => e.input.describe(), // context stack, declared actions nobody bound, the player's rebindings (Input.js)
|
|
123
|
+
control: () => e.control.describe(), // who decides where each held character goes: { id: { owner, layer, waiting } } (control.js)
|
|
124
|
+
shared: () => e.stacks.describe(), // every shared value / slot with entries: value, writer, how it combined, who else wants it (stacks.js)
|
|
125
|
+
wraps: () => { const w = e._wraps?.describe(); return w && Object.keys(w).length ? w : NONE; }, // engine.wrap: { 'inventory.add': [owners, outermost first] }
|
|
126
|
+
player: () => p ? {
|
|
92
127
|
x: r1(p.x), y: r1(p.y), z: r1(p.z),
|
|
93
128
|
ground: e.groundType(p.x, p.z),
|
|
94
129
|
groundName: nameOf(e, 'ground.', e.groundType(p.x, p.z)),
|
|
95
130
|
inWater: e.waterAt(p.x, p.z) > p.y,
|
|
96
|
-
state: e.player.state ?? null,
|
|
97
|
-
running: e.player.state === 'run',
|
|
98
|
-
jumping: e.player.state === 'jump' || e.player.state === 'fall',
|
|
131
|
+
state: e.player.state ?? null, // the character module's own state name ('walk', 'jump'...): core passes it on and never interprets it
|
|
99
132
|
} : null,
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
133
|
+
// projection: engine.camera is an EngineCamera (core/engineCamera.js) that a rig may switch to orthographic; said here so the switch is never hidden
|
|
134
|
+
camera: () => ({ type: null, projection: cam.orthoSize ? 'orthographic' : 'perspective', ...(cam.orthoSize ? { orthoSize: r1(cam.orthoSize) } : {}), x: r1(cam.position.x), y: r1(cam.position.y), z: r1(cam.position.z),
|
|
135
|
+
focus: { x: r1(e.focus.x), z: r1(e.focus.z) }, override: e.cameraOverride?.owner ?? null }),
|
|
136
|
+
nearbyRadius: () => radius,
|
|
137
|
+
nearby: () => [],
|
|
138
|
+
ui: () => ({ windows: [...e.openWindows], inputLocked: !e.input.enabled, dialogue: null, parts: e.ui.describe() }), // windows include full-screen UI parts (title); parts: default / custom / off
|
|
139
|
+
cutscene: () => null,
|
|
140
|
+
modules: () => [...e.modules.values()].map(moduleRow), // { name, type, provides?, requires? } in install order (moduleTypes.js)
|
|
141
|
+
slots: () => describeSlots(e), // what is plugged in where, from which file, what it affects (plugins.js)
|
|
142
|
+
scene: () => describeScene(e), // engine.add / world things: counts by save tier and what will not survive a load (thingOps.js)
|
|
143
|
+
threePatches: () => threePatches.list(), // page-wide changes to three.js classes still on (core/threePatches.js)
|
|
144
|
+
owned: () => describeOwned(e), // every property the engine writes on its own and who writes it now (owned.js)
|
|
145
|
+
look: () => describeLook(e), // every look part key, its value and who set it (look/report.js)
|
|
146
|
+
render: () => describeRender(e), // renderer / post / lights and who set each (describeRender.js)
|
|
147
|
+
// which renderer was asked for and which backend draws; reason = why not WebGPU (core/startup.js _startRenderer). backend null before start()
|
|
148
|
+
renderer: () => e._backend ?? { requested: e._backendWant.requested, backend: null, reason: null },
|
|
149
|
+
perf: () => ({
|
|
111
150
|
fps: e.paused ? null : Math.round(e.fps), cpuMs: e.paused ? null : r1(e.cpuMs),
|
|
112
151
|
cpu: e.paused ? null : Object.fromEntries(Object.entries(e.cpuPhases).map(([k, v]) => [k, r1(v)])),
|
|
113
152
|
apply: e.budget.cost.report(),
|
|
114
|
-
|
|
153
|
+
...drawStats(e.renderer), pixelRatio: e.renderer.getPixelRatio(),
|
|
115
154
|
budget: e.budget.report(), startup: e.startup, stream: e.stream.stats, batching: e.batching.stats, jobs: e.jobs.pending, commits: { pending: e.commits.pending, ...e.commits.stats },
|
|
116
|
-
},
|
|
155
|
+
}),
|
|
117
156
|
};
|
|
157
|
+
const out = {};
|
|
158
|
+
if (!only) for (const k in core) { const v = core[k](); if (v !== NONE) out[k] = v; }
|
|
159
|
+
else for (const k in core) {
|
|
160
|
+
// built on first read; a hook's plain write (ctx.out.cutscene = ...) replaces it the same way
|
|
161
|
+
const put = v => { if (v === NONE) delete out[k]; else Object.defineProperty(out, k, { value: v, writable: true, enumerable: true, configurable: true }); };
|
|
162
|
+
Object.defineProperty(out, k, { get: () => (put(core[k]()), out[k]), set: put, enumerable: true, configurable: true });
|
|
163
|
+
}
|
|
164
|
+
if (!only || !only.every(k => TABLES.has(k) && !e.modules.has(k) && !extras.has(k))) hooks(e, out, radius, center, extras);
|
|
165
|
+
if (!only) return out;
|
|
166
|
+
const picked = {};
|
|
167
|
+
for (const k of only) { const v = out[k]; if (!(k in out)) return null; picked[k] = v; }
|
|
168
|
+
return picked;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** Module describe hooks and describe.add, then the nearby list and the player's actions, into out */
|
|
172
|
+
function hooks(e, out, radius, center, extras) {
|
|
173
|
+
const dir = e.camera.getWorldDirection(new e.THREE.Vector3()), camYaw = Math.atan2(dir.x, -dir.z);
|
|
118
174
|
// Nearby things: collect first, then sort and truncate once at the end
|
|
119
175
|
const found = new Map(), v = new e.THREE.Vector3();
|
|
120
176
|
const ctx = {
|
|
@@ -129,10 +185,16 @@ function describe(e, { radius = NEAR_RADIUS, center: at } = {}, extras) {
|
|
|
129
185
|
found.set(at, { ...info, dist: r1(dist), dir: COMPASS[sector(bearing)], rel: RELATIVE[sector(bearing - camYaw)], x: r1(pos.x), z: r1(pos.z) });
|
|
130
186
|
},
|
|
131
187
|
};
|
|
188
|
+
// A module's hook that throws fills only its own entry: describe() runs at the end of every engine.step(), so letting one broken hook throw
|
|
189
|
+
// would make step() throw after time has already advanced and lose every other module's state with it.
|
|
132
190
|
for (const m of e.modules.values()) {
|
|
133
191
|
if (!m.describe) continue;
|
|
134
|
-
const part = m.describe(e, ctx);
|
|
135
|
-
|
|
192
|
+
try { const part = m.describe(e, ctx); if (part !== undefined) out[m.name] = part; }
|
|
193
|
+
catch (err) {
|
|
194
|
+
const msg = String(err?.message || err);
|
|
195
|
+
out[m.name] = { error: msg, code: 'describe-threw' };
|
|
196
|
+
warnOnce(coded('describe-threw', `describe(): module '${m.name}' describe hook threw: ${msg}`), 'describe-threw:' + m.name);
|
|
197
|
+
}
|
|
136
198
|
}
|
|
137
199
|
for (const [name, fn] of extras) {
|
|
138
200
|
try { const part = fn(e, ctx); if (part !== undefined) out[name] = part; } catch (err) { out[name] = { error: String(err.message || err) }; } // an error in the game's own description must not take down the whole describe
|
|
@@ -141,5 +203,4 @@ function describe(e, { radius = NEAR_RADIUS, center: at } = {}, extras) {
|
|
|
141
203
|
// ops on offer for the player (engine.ops.list({ available: true })): possible ones first; omitted when the game has none
|
|
142
204
|
const acts = e.ops.list({ available: true }).sort((a, b) => b.ok - a.ok).slice(0, ACTIONS_MAX);
|
|
143
205
|
if (acts.length) out.actions = acts.map(a => ({ op: a.name, args: a.args, ok: a.ok, ...(a.ok ? {} : { code: a.code, facts: a.facts, nextActions: a.nextActions }) }));
|
|
144
|
-
return out;
|
|
145
206
|
}
|
package/core/Engine.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import * as THREE from 'three';
|
|
6
6
|
import { Page } from './page.js';
|
|
7
7
|
import { createServices } from './services.js';
|
|
8
|
+
import { Stacks } from './stacks.js';
|
|
8
9
|
import { PostFX } from '../render/PostFX.js';
|
|
9
10
|
import { createDefaultLights } from '../render/lights.js';
|
|
10
11
|
import { registerEngine, makeMaterial, MATERIAL_PURPOSES } from '../render/materials.js';
|
|
@@ -14,14 +15,19 @@ import { bindUniforms } from '../render/engineUniforms.js';
|
|
|
14
15
|
import { UIParts } from '../ui/Parts.js';
|
|
15
16
|
import { defineCoreParts } from '../ui/defaults.js';
|
|
16
17
|
import { applyUIStyle } from '../ui/theme.js';
|
|
17
|
-
import {
|
|
18
|
+
import { trackValidate, warnOnce, DEV } from './validate.js';
|
|
19
|
+
import { readParams } from './params.js';
|
|
18
20
|
import { loopMethods } from './loop.js';
|
|
19
21
|
import { holdMethods } from './holds.js';
|
|
20
22
|
import { startupMethods } from './startup.js';
|
|
21
23
|
import { groundMethods, flatGround } from './ground.js';
|
|
22
24
|
import { actorMethods } from './actor.js';
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
+
import { forcedTier, defaultPixelRatio } from './tier.js';
|
|
26
|
+
import { tier as detectTier, tierBeforeRenderer, ownMsaa, timerContext, isWebGPU, webgpuPart, watchNodePrograms } from '../render/backend.js';
|
|
27
|
+
import { dressNodeTwins } from '../render/patches.js';
|
|
28
|
+
import { lifecycleMethods, clearHooks, checkCanvasUsable } from './lifecycle.js';
|
|
29
|
+
import { createAdaptive, GpuTimer } from './adaptive.js';
|
|
30
|
+
import { watchRejections } from './errors.js';
|
|
25
31
|
import { createMovement } from './movement.js';
|
|
26
32
|
import { moduleMethods } from './modules.js';
|
|
27
33
|
import { skipMethods } from './skip.js';
|
|
@@ -29,52 +35,104 @@ import { checkMethods } from './checks.js';
|
|
|
29
35
|
import { styleFrom, NO_STYLE, styleIsEmpty } from './styleParts.js';
|
|
30
36
|
import { canvasBox, placeUI, resizeMethods } from './canvasBox.js';
|
|
31
37
|
import { sceneMethods } from './sceneMethods.js';
|
|
38
|
+
import { EngineCamera } from './engineCamera.js';
|
|
32
39
|
import { recordRender } from './describeRender.js';
|
|
33
|
-
import { defineCoreLook, defineCloudShadowLook } from './look/coreParts.js';
|
|
34
|
-
import {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
40
|
+
import { defineCoreLook, defineCloudShadowLook, defineSeasonLook, defineViewLook } from './look/coreParts.js';
|
|
41
|
+
import { defineShadowLook } from './look/shadowPart.js';
|
|
42
|
+
import { nameShaderErrors } from '../render/shaderErrors.js';
|
|
43
|
+
import { probeMethods } from '../render/probes.js';
|
|
44
|
+
import { headlessSettled } from './headlessLoad.js';
|
|
45
|
+
import { codedError } from './errorHints.js';
|
|
46
|
+
const FALLBACKS = ['webgl2', 'webgl', 'error'];
|
|
47
|
+
// createEngine() options: the one table for the unknown-key and type check (dev throws with did-you-mean, release warns once), the plain
|
|
48
|
+
// defaults and engine.catalog('core').params; R6 checks EngineOptions (types/core.d.ts) has exactly these keys. A key with several shapes
|
|
49
|
+
// names them all ('bool|object'). Object / array defaults stay in the destructuring below (in the schema all engines would share one object).
|
|
50
|
+
/** @internal */
|
|
51
|
+
export const ENGINE_PARAMS = {
|
|
52
|
+
canvas: 'object?', renderer: { type: 'string|object', optional: true, desc: "'webgl' (default), 'webgpu', or a renderer the game built" },
|
|
53
|
+
fallback: { type: 'string', optional: true, values: FALLBACKS }, style: 'object|array?', antialias: 'bool?',
|
|
54
|
+
pixelRatio: 'number?', adaptiveResolution: { type: 'bool', default: true }, targetFps: { type: 'number', default: 55, min: 1 },
|
|
55
|
+
ui: 'object?', audio: 'object?', fov: { type: 'number', default: 55, min: 1, max: 179 }, near: { type: 'number', default: 0.3, min: 0 },
|
|
56
|
+
locale: { type: 'string', default: 'auto' }, strings: 'object?', bindings: 'object?', saveKey: { type: 'string', default: 'game' },
|
|
57
|
+
joystick: { type: 'string|bool', default: 'auto' }, headless: 'bool?', validate: { type: 'bool', default: true }, decoders: 'string?',
|
|
58
|
+
budget: 'object?', urlState: 'bool?', seed: 'number?', movement: 'object?', threads: { type: 'string|number|bool', default: 'auto' },
|
|
59
|
+
pauseOnBlur: { type: 'bool', default: true }, batching: 'bool|object?', lights: { type: 'bool', default: true },
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/** createEngine({ renderer: 'webgpu' }): three's WebGPURenderer from the classes threedog/tsl registered (render/backend.js) @param {any} canvas */
|
|
63
|
+
function newWebGPURenderer(canvas, antialias) {
|
|
64
|
+
return new (needTsl("'webgpu'").WebGPURenderer)({ canvas, antialias, powerPreference: 'high-performance' });
|
|
65
|
+
}
|
|
39
66
|
|
|
40
67
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
68
|
+
* The three/webgpu classes threedog/tsl registered. Both WebGPU roads need it before createEngine: it brings three/webgpu for 'webgpu', and
|
|
69
|
+
* the tsl side of patches and the WebGPU parts for any WebGPURenderer. Why not a dynamic import in start(): the engine core never imports it,
|
|
70
|
+
* so WebGL games stay small.
|
|
71
|
+
* @param {string} how
|
|
43
72
|
*/
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
73
|
+
const needTsl = how => webgpuPart('classes', `createEngine({ renderer: ${how} })`);
|
|
74
|
+
|
|
75
|
+
/** Check renderer / fallback and say what start() does: { requested, fallback } @param {any} r @param {any} rendererIn @param {any} fallback */
|
|
76
|
+
function rendererWant(r, rendererIn, fallback) {
|
|
77
|
+
if (typeof rendererIn === 'string' && rendererIn !== 'webgpu') throw codedError('engine-misuse', `createEngine({ renderer }): a name is 'webgl' (the default) or 'webgpu', or pass a three.js renderer object, got ${JSON.stringify(rendererIn)}`);
|
|
78
|
+
const gpu = isWebGPU(r);
|
|
79
|
+
if (gpu) needTsl('yourWebGPURenderer');
|
|
80
|
+
if (fallback !== undefined && !gpu) throw codedError('engine-misuse', "createEngine({ fallback }) only applies with renderer: 'webgpu' or your own WebGPURenderer (WebGLRenderer has nothing to fall back from)");
|
|
81
|
+
return { requested: gpu ? 'webgpu' : 'webgl', fallback: fallback ?? 'webgl2' };
|
|
47
82
|
}
|
|
48
83
|
|
|
84
|
+
|
|
49
85
|
export class Engine {
|
|
50
86
|
/**
|
|
51
87
|
* @param o createEngine options: each option, its default and meaning is documented once on EngineOptions (types/core.d.ts).
|
|
52
|
-
* style can also be a list of parts deep-merged left to right (rules in core/styleParts.js).
|
|
88
|
+
* style can also be a list of parts deep-merged left to right (rules in core/styleParts.js). ENGINE_PARAMS and the destructuring below must match it.
|
|
53
89
|
*/
|
|
54
90
|
constructor(opts = {}) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
91
|
+
/** @internal first-frame phases (startup.js): when the page's scripts had run and the engine began / finished building */
|
|
92
|
+
this._born = { at: performance.now(), built: 0, start: 0 }; // measure
|
|
93
|
+
/** This engine's dev checks (createEngine({ validate })); another engine on the page does not change it @type {boolean} */
|
|
94
|
+
this.validate = opts.validate !== false;
|
|
95
|
+
/** @internal */ this._untrackValidate = trackValidate(opts.validate);
|
|
96
|
+
// createEngine({ post }) was a third switch next to look.post.set, and read as "turn bloom on" when nothing had added a bloom. Said here,
|
|
97
|
+
// before the unknown-option check, so the message names the one way instead of only "unknown option"
|
|
98
|
+
if (opts.post !== undefined) throw codedError('post-effect', 'createEngine({ post }) is gone. The engine ships no effects: add one with engine.look.post.add(bloom()) ' +
|
|
99
|
+
"(import { bloom } from '@threedog/post-effects'), or a plugins/10-bloom.js file (export default bloom()); switch an added one with " +
|
|
100
|
+
`engine.look.post.set(${JSON.stringify(opts.post)}) after it is added (a style's costly effects start off on low-tier devices: set turns them on)`);
|
|
101
|
+
const o = readParams('createEngine()', ENGINE_PARAMS, opts);
|
|
102
|
+
/** @internal createEngine options as read (engine.catalog('core').params shows them with the schema) */ this._createParams = o;
|
|
103
|
+
const { canvas: canvasIn, renderer: rendererName, style: styleIn, antialias, pixelRatio, adaptiveResolution, targetFps, ui = {}, audio = {},
|
|
104
|
+
fov, near, locale, strings = {}, bindings = {}, saveKey, joystick,
|
|
105
|
+
headless = new URLSearchParams(location.search).has('threedog-headless'), validate,
|
|
106
|
+
decoders = null, budget = null, urlState = DEV, seed, movement, threads, pauseOnBlur, batching = {}, lights, fallback } = o;
|
|
61
107
|
this.THREE = THREE;
|
|
62
|
-
|
|
108
|
+
// 'webgl' names the default (a WebGLRenderer the engine builds), so it reads like leaving the option out
|
|
109
|
+
const rendererIn = rendererName === 'webgl' ? undefined : rendererName;
|
|
110
|
+
// 'webgpu' is the same road as a game's own WebGPURenderer: built here, then handed on like one (start() inits it, core/startup.js)
|
|
111
|
+
const gpuWanted = rendererIn === 'webgpu';
|
|
112
|
+
const canvas = canvasIn ?? (gpuWanted ? undefined : rendererIn?.domElement);
|
|
63
113
|
this.movement = createMovement(movement); // character radius / height / slope / step height: the single copy shared by collision, physics and nav
|
|
64
114
|
const style = this.style = styleFrom(styleIn); // a list of parts is deep-merged (styleParts.js); one object is used as is
|
|
65
115
|
if (styleIsEmpty(opts.style)) warnOnce(NO_STYLE);
|
|
66
116
|
// a game-supplied renderer is used as is: the engine configures (pixel ratio, size, tone mapping, shadows) only a renderer it created itself
|
|
67
|
-
const owned = !rendererIn;
|
|
68
|
-
|
|
69
|
-
|
|
117
|
+
const owned = !rendererIn || gpuWanted;
|
|
118
|
+
this._ownsRenderer = owned; // dispose() releases the WebGL context only of a renderer the engine built
|
|
119
|
+
if (owned) checkCanvasUsable(canvas);
|
|
120
|
+
// 'low' | 'high': device tier, decides default quality. A headless tool page names its tier (?threedog-tier, core/tier.js): detection would call
|
|
121
|
+
// every headless browser low tier and drop the game's costly post from shots. An engine-built renderer needs it before it exists: MSAA defaults
|
|
122
|
+
// from the tier and is the canvas's own (antialias, fixed when the context is made), so an effect-free frame skips the post chain
|
|
123
|
+
const tierFirst = (headless && forcedTier()) || (owned ? tierBeforeRenderer() : null);
|
|
124
|
+
const aa = antialias ?? style.antialias ?? (owned ? tierFirst !== 'low' : null);
|
|
125
|
+
const r = this.renderer = gpuWanted ? newWebGPURenderer(canvas, aa) : rendererIn ?? new THREE.WebGLRenderer({ canvas, antialias: aa, powerPreference: 'high-performance' });
|
|
126
|
+
/** @internal what the game asked for and what to do without WebGPU; start() fills describe().renderer from it */
|
|
127
|
+
this._backendWant = rendererWant(r, rendererIn, fallback);
|
|
128
|
+
watchNodePrograms(r); // WebGPU: generated code per material, for debug.view('shaderCost') (render/backend.js)
|
|
129
|
+
if (isWebGPU(r)) dressNodeTwins(r); // WebGPU: classic materials get their patches as nodes (render/patches.js)
|
|
130
|
+
nameShaderErrors(r); // compile errors name the patch and slot (render/shaderErrors.js); a game's own handler stays
|
|
131
|
+
this.tier = tierFirst || detectTier(r);
|
|
70
132
|
if (owned || pixelRatio != null) r.setPixelRatio(pixelRatio ?? defaultPixelRatio(devicePixelRatio || 1, this.tier));
|
|
71
133
|
this._autoSize = undefined; // decided once the canvas is in the page (sizeMode): true = no CSS size, the engine sizes it to the window
|
|
72
134
|
const box = canvasBox(this);
|
|
73
135
|
if (owned) r.setSize(box.w, box.h, !!this._autoSize);
|
|
74
|
-
if (owned) {
|
|
75
|
-
r.shadowMap.enabled = shadows;
|
|
76
|
-
r.shadowMap.type = shadowTypeOf(shadowType, 'createEngine({ shadowType })');
|
|
77
|
-
}
|
|
78
136
|
r.info.autoReset = false;
|
|
79
137
|
|
|
80
138
|
this.scene = new THREE.Scene();
|
|
@@ -83,14 +141,15 @@ export class Engine {
|
|
|
83
141
|
/** Look parts by name, each with set / patch / replace (recipes/52-look.md): tone, lights, cloudShadow from core, the rest from the modules that provide them @type {Record<string, import('../index').LookPart>} */
|
|
84
142
|
this.look = {};
|
|
85
143
|
this.lights = createDefaultLights(this, { add: lights !== false });
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
this.
|
|
144
|
+
// the engine's own renderer: render defaults are a technical baseline under every style (AgX, soft shadows, neutral environment; coreParts.js);
|
|
145
|
+
// a pack that wants none sets it (toneMapping: 'none', look.shadow enabled false, look.lights env.intensity 0)
|
|
146
|
+
this.stacks = new Stacks(this); // look values are shared points (core/look/points.js): the registry exists before the first look part
|
|
147
|
+
defineCoreLook(this, { owned, baseline: owned }); // writes renderer.toneMapping once (style.toneMapping, else AgX); look.tone (exposure) and look.lights (coreParts.js)
|
|
148
|
+
defineShadowLook(this, { owned, baseline: owned }); // look.shadow: the master switch and filter (a sky adds its shadow-box keys)
|
|
149
|
+
recordRender(this, { owned }); // baseline for describe().render (after the curve is written): which values the engine / style set
|
|
150
|
+
this.camera = new EngineCamera(fov, box.w / box.h, near, 1500); // a PerspectiveCamera that camera rigs can switch to orthographic (core/engineCamera.js)
|
|
89
151
|
this.camera.position.set(0, 10, 20);
|
|
90
152
|
this.focus = new THREE.Vector3(); // camera focus (updated by the camera module): the view loads around it; simulation follows world.anchor
|
|
91
|
-
this.shadows = shadows;
|
|
92
|
-
/** Shadow filter in use ('basic' | 'pcf' | 'vsm'); change it with look.shadow.set({ type }) @type {string} */
|
|
93
|
-
this.shadowType = shadowType;
|
|
94
153
|
this.ground = flatGround;
|
|
95
154
|
this.player = null;
|
|
96
155
|
/**
|
|
@@ -98,8 +157,15 @@ export class Engine {
|
|
|
98
157
|
* control to a vehicle or squad member @type {string}
|
|
99
158
|
*/
|
|
100
159
|
this.actor = 'player';
|
|
101
|
-
|
|
102
|
-
|
|
160
|
+
/**
|
|
161
|
+
* Where the engine is in its life, the one state every "may this run yet" check reads: 'constructed' (createEngine done, start() not called)
|
|
162
|
+
* -> 'loading' (start() running: modules init, assets, the world builds; frame hooks run, fixed steps do not, so no game time passes)
|
|
163
|
+
* -> 'ready' (the world is built: fixed steps run, engine:ready fires, the new-game state is captured) -> 'running' (start() resolved)
|
|
164
|
+
* -> 'disposed'. @type {'constructed' | 'loading' | 'ready' | 'running' | 'disposed'}
|
|
165
|
+
*/
|
|
166
|
+
this.phase = 'constructed';
|
|
167
|
+
/** @internal module name -> handles its install / init passed to ctx.track (removed with the module: modules.js) */ this._modTracked = new Map();
|
|
168
|
+
/** @internal module name -> the token of its current install: ctx and async init check it (modules.js, a stale init must not act on a newcomer) */ this._modInst = new Map();
|
|
103
169
|
this._abort = new AbortController();
|
|
104
170
|
// attach DOM listeners to it: addEventListener(type, fn, { signal: engine.signal }); dispose cancels them together
|
|
105
171
|
this.signal = this._abort.signal;
|
|
@@ -114,40 +180,46 @@ export class Engine {
|
|
|
114
180
|
this.cpuMs = 0; // main-thread ms of the last real-time frame; cpuPhases splits it (loop.js)
|
|
115
181
|
this.cpuPhases = { fixed: 0, frame: 0, render: 0, afterRender: 0 };
|
|
116
182
|
this.openWindows = new Set(); // ids of open windows (for describe)
|
|
117
|
-
this.fogFar = fogFar; // base fog distance; terrain view range changes it, weather scales it
|
|
118
183
|
this.modules = new Map();
|
|
119
184
|
this._modState = new Map(); // module name -> registered | initializing | running | failed | disposed (modules.js)
|
|
120
185
|
this.waterBodies = [];
|
|
121
|
-
this
|
|
186
|
+
clearHooks(this);
|
|
122
187
|
this._hookErrors = new Set(); // places that already reported an error (once per place, see errors.js)
|
|
123
188
|
this.error = null; // gameplay error in dev/test: { where, message, cause?, docs? }; gameplay is frozen (see errors.js)
|
|
124
|
-
this.disabledModules = new Set(); //
|
|
125
|
-
this._elapsed = 0; // engine.elapsed: fixed seconds, advanced per fixed step and copied into uniforms.uTime
|
|
189
|
+
this.disabledModules = new Set(); // look / ui modules disabled after they threw
|
|
126
190
|
/**
|
|
127
191
|
* This engine's shader uniforms (uTime, uWind, uCloud, season tints...); share these objects in your own ShaderMaterial or patch @type
|
|
128
192
|
* {import('../types/core').EngineUniforms}
|
|
129
193
|
*/
|
|
130
194
|
this.uniforms = createUniforms(style);
|
|
131
195
|
bindUniforms(r, this.uniforms); // built-in shader effects read this engine's uniforms when compiled by this renderer
|
|
196
|
+
defineViewLook(this); // look.view: manual() for camera.far / pixel ratio / camera pose the engine changes on its own (coreParts.js)
|
|
132
197
|
defineCloudShadowLook(this); // look.cloudShadow: the cloud-shadow patch every engine material carries, declared (coreParts.js)
|
|
198
|
+
defineSeasonLook(this); // look.season: the season / cover tint's replace slot (coreParts.js, render/terms.js)
|
|
133
199
|
defineMaterialsLook(this, MATERIAL_PURPOSES); defineSurfaceLook(this); // look.materials / look.surface: what makeMaterial reads (render/lookSurface.js)
|
|
134
|
-
this._materials = registerEngine(this); // makeMaterial without an engine argument uses the first live engine's style
|
|
200
|
+
this._materials = registerEngine(this); // makeMaterial without an engine argument uses the first live engine's style
|
|
135
201
|
|
|
136
|
-
createServices(this, { canvas, validate, locale, strings, saveKey, joystick, bindings,
|
|
202
|
+
createServices(this, { canvas, validate, locale, strings, saveKey, joystick, bindings, audio, decoders, budget, seed, headless, urlState, threads, batching });
|
|
137
203
|
this.startup = null; // startup timing report (set once start() finishes)
|
|
204
|
+
this._readyAt = null; // set at ready until the first frame is drawn (loop.js firstFrame)
|
|
205
|
+
this._whileCompiling = []; // @internal one-time warm-ups a module queues during loading; start() runs them while the GPU compiles
|
|
138
206
|
this._prof = null; // module hook timing (profile(true) turns it on)
|
|
139
207
|
this._afterTick = null; // at startup, checked once at the end of each frame for readiness
|
|
140
|
-
// effects come
|
|
141
|
-
|
|
142
|
-
|
|
208
|
+
// effects come through look.post.add only (a style's plugins, the plugins folder, game code); style.post was the second way in, gone
|
|
209
|
+
if (style.post != null) throw codedError('style-value', 'style.post is gone: a style brings its post effects as plugins (style/plugins/10-bloom.js: export default bloom(); ' +
|
|
210
|
+
"the style object: plugins: import.meta.glob('./plugins/*.js', { eager: true })), the same files a game's plugins/ folder takes. docs/MIGRATING-0.4.md");
|
|
211
|
+
// a game's own renderer keeps its own MSAA choice by default (used as is, like its pixel ratio)
|
|
212
|
+
this.post = new PostFX(this, { antialias: aa ?? ownMsaa(r) });
|
|
213
|
+
this._uiStyle = applyUIStyle(this, style.ui); // theme variables, the style's CSS and fonts; removed on dispose
|
|
143
214
|
this.ui = new UIParts(this, ui); // UI parts: every piece of screen UI is replaceable or off (ui/Parts.js)
|
|
144
215
|
defineCoreParts(this);
|
|
145
216
|
this.ui.get('loading')?.show({});
|
|
146
|
-
this.adaptive = {
|
|
147
|
-
|
|
217
|
+
this.adaptive = createAdaptive({ on: adaptiveResolution && !headless, target: targetFps, max: r.getPixelRatio() });
|
|
218
|
+
this._gpu = this.adaptive.on ? new GpuTimer(timerContext(r)) : null; // GPU frame time for adaptive resolution where the browser offers the timer query
|
|
148
219
|
// follow the canvas's own CSS box, not the window: a canvas in a page section or editor panel renders at its own size.
|
|
149
220
|
// The window event stays for a canvas outside the page (no box, falls back to the window) and for moves that do not resize the canvas
|
|
150
221
|
addEventListener('resize', () => this._resize(), { signal: this.signal });
|
|
222
|
+
this._unhandled = null; watchRejections(this);
|
|
151
223
|
if (typeof ResizeObserver === 'function') {
|
|
152
224
|
const ro = new ResizeObserver(() => this._resize());
|
|
153
225
|
ro.observe(r.domElement);
|
|
@@ -155,19 +227,24 @@ export class Engine {
|
|
|
155
227
|
}
|
|
156
228
|
placeUI(this);
|
|
157
229
|
this.page = new Page(this, { pauseOnBlur }); // window focus, tab visibility, mouse lock, WebGL context: handled only there
|
|
230
|
+
this._born.built = performance.now(); // measure
|
|
158
231
|
}
|
|
159
232
|
|
|
160
233
|
get waterLevel() { return this.ground.waterLevel; }
|
|
234
|
+
/** True once the world is built (phase 'ready' or 'running'): fixed steps, ops and rendering run from here on @type {boolean} */
|
|
235
|
+
get ready() { return this.phase === 'ready' || this.phase === 'running'; }
|
|
236
|
+
/** True after dispose() @type {boolean} */
|
|
237
|
+
get disposed() { return this.phase === 'disposed'; }
|
|
161
238
|
|
|
162
239
|
// ---------- common ----------
|
|
163
240
|
/** Get a UI string (i18n) */
|
|
164
241
|
t(key, params) { return this.i18n.t(key, params); }
|
|
165
242
|
/**
|
|
166
|
-
*
|
|
167
|
-
*
|
|
243
|
+
* Fixed steps run (= engine.time.tick, the one time counter, core/time.js). Read-only; starts again from 0 on session.newGame / load / quit.
|
|
244
|
+
* Seconds are views of it: engine.time.now('real' | 'ambient' | 'calendar' | channel)
|
|
168
245
|
*/
|
|
169
|
-
get
|
|
170
|
-
/** Material by role from this engine's style
|
|
246
|
+
get tick() { return this.time.tick; }
|
|
247
|
+
/** Material by role from this engine's style: engine.makeMaterial('prop', { color: 0x8a5a36 }) */
|
|
171
248
|
makeMaterial(purpose, params) { return makeMaterial(purpose, params, this); }
|
|
172
249
|
/** Ray cast: the nearest hit or null, see Rays.js */
|
|
173
250
|
raycast(origin, dir, opts) { return this.rays.cast(origin, dir, opts); }
|
|
@@ -175,19 +252,66 @@ export class Engine {
|
|
|
175
252
|
pick(ndcX, ndcY, opts) { return this.rays.pick(ndcX, ndcY, opts); }
|
|
176
253
|
/** Set up a scenario: { time, weather, pos, save, wait, cutscene, state }, see UrlState.js */
|
|
177
254
|
applyState(params) { return this._urlState.apply(params); }
|
|
178
|
-
/**
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
255
|
+
/**
|
|
256
|
+
* Scenario ready: start() has finished, the URL parameters / latest applyState are applied, and (headless) a load begun after start has settled
|
|
257
|
+
* (tests and screenshots wait for it; core/headlessLoad.js)
|
|
258
|
+
*/
|
|
259
|
+
get stateApplied() { return this.ready && this._urlState.applied && headlessSettled(this); }
|
|
260
|
+
/**
|
|
261
|
+
* Name a set of scenario parameters, then use applyState({ state: name }) or the URL ?state=name. Returns a handle: remove() forgets the name
|
|
262
|
+
* @param {string} name @param {import('../types/core').StateParams} params @param {{ owner?: string }} [opts]
|
|
263
|
+
* @returns {{ owner?: string, remove(): void }}
|
|
264
|
+
*/
|
|
265
|
+
defineState(name, params, opts) { return this._urlState.define(name, params, opts); }
|
|
266
|
+
/**
|
|
267
|
+
* Fixed-step logic (60 per second): movement, timers, gameplay keys. dt is real seconds (always 1 / 60) unless { channel } names a time channel:
|
|
268
|
+
* then dt is that channel's scaled dt (bullet time slows it). Returns a handle { remove() }
|
|
269
|
+
* phase (order is declared, never "which line registered first"): 'early' (default) runs before every module fixed hook, so the player has not
|
|
270
|
+
* moved yet this step; 'late' runs after all modules (player moved, physics stepped) and before the clock: hit checks, reading this step's result.
|
|
271
|
+
* @example engine.onFixed(dt => moveEnemies(dt), { channel: 'enemies' })
|
|
272
|
+
* @example engine.onFixed(() => checkHits(engine.player.position), { phase: 'late' })
|
|
273
|
+
*/
|
|
274
|
+
onFixed(fn, { channel, phase = 'early' } = {}) {
|
|
275
|
+
if (phase !== 'early' && phase !== 'late') throw codedError('engine-misuse', `engine.onFixed(fn, { phase }): phase is 'early' (default, before modules) or 'late' (after modules), got ${JSON.stringify(phase)}`);
|
|
276
|
+
if (channel) this.time._get(channel); // unknown channel: throw now, not every step
|
|
277
|
+
const f = channel ? () => fn(this.time.dt(channel)) : fn, key = phase === 'late' ? '_fixedLate' : '_fixed';
|
|
278
|
+
this[key].push(f); return { remove: () => { this[key] = this[key].filter(x => x !== f); } };
|
|
279
|
+
}
|
|
184
280
|
/** Once per frame: animation, camera, UI. Returns a handle { remove() } */
|
|
185
281
|
onFrame(fn) { this._frame.push(fn); return { remove: () => { this._frame = this._frame.filter(f => f !== fn); } }; }
|
|
282
|
+
/**
|
|
283
|
+
* Around the main render, after the camera update and batching: fn({ renderer, scene, camera, dt }). when 'before' (default) runs just before the
|
|
284
|
+
* engine's frame render: render to your own target there (mirror, minimap, portal, picking); the render target is reset afterwards. 'after' runs
|
|
285
|
+
* right after it (read pixels, overlays). The main frame render stays the engine's. Returns a handle { remove() }
|
|
286
|
+
* @param {(ctx: { renderer: any, scene: any, camera: any, dt: number }) => void} fn @param {{ when?: 'before' | 'after' }} [opts]
|
|
287
|
+
*/
|
|
288
|
+
onRender(fn, { when = 'before' } = {}) {
|
|
289
|
+
if (typeof fn !== 'function') throw codedError('engine-misuse', `engine.onRender(fn, { when }): fn must be a function, got ${typeof fn}`);
|
|
290
|
+
if (when !== 'before' && when !== 'after') throw codedError('engine-misuse', `engine.onRender(fn, { when }): when must be 'before' or 'after', got ${JSON.stringify(when)}`);
|
|
291
|
+
this._onRender[when].push(fn);
|
|
292
|
+
return { remove: () => { this._onRender[when] = this._onRender[when].filter(f => f !== fn); } };
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* @internal Stands in until a camera module is installed (its install replaces engine.setCamera). Why: core cannot install a module (rule 2), and
|
|
297
|
+
* without this a scene with no openWorld / camera module failed with "setCamera is not a function", which names no fix.
|
|
298
|
+
*/
|
|
299
|
+
setCamera(kind, opts) {
|
|
300
|
+
const o = opts && typeof opts === 'object' ? `{ ${Object.keys(opts).join(', ')} }` : '';
|
|
301
|
+
throw codedError('camera-none', `engine.setCamera('${kind}'${o ? ', ' + o : ''}) needs a camera module, and none is installed (openWorld({ camera }) `
|
|
302
|
+
+ `installs the one you name, camera: false installs none; a bare scene has none): install the kind you want once, engine.use(${kind === 'firstPerson' ? 'firstPersonCamera' : kind === 'rts' ? 'rtsCamera' : kind === 'follow' ? 'followCamera' : 'fixedCamera'}(${o})), `
|
|
303
|
+
+ `then setCamera switches between kinds`);
|
|
304
|
+
}
|
|
186
305
|
|
|
187
306
|
/** @internal Display name of a module (loading screen): module.<name> from the string table, else the module's own label */
|
|
188
307
|
moduleName(m) { return this.i18n.has('module.' + m.name) ? this.t('module.' + m.name) : (m.label || m.name); }
|
|
189
308
|
}
|
|
190
309
|
|
|
191
310
|
// Mix in by property descriptor (Object.assign would evaluate getters on the spot and lose them)
|
|
192
|
-
for (const part of [loopMethods, holdMethods, startupMethods, groundMethods, actorMethods, moduleMethods, lifecycleMethods, skipMethods, checkMethods, resizeMethods, sceneMethods])
|
|
311
|
+
for (const part of [loopMethods, holdMethods, startupMethods, groundMethods, actorMethods, moduleMethods, lifecycleMethods, skipMethods, checkMethods, resizeMethods, sceneMethods, probeMethods])
|
|
193
312
|
Object.defineProperties(Engine.prototype, Object.getOwnPropertyDescriptors(part));
|
|
313
|
+
// engine.elapsed was a second counter beside engine.time (review 0.4, B): removed. In dev a read throws with the new form instead of giving
|
|
314
|
+
// undefined (NaN in every Math.sin(engine.elapsed) animation, silently)
|
|
315
|
+
if (DEV) Object.defineProperty(Engine.prototype, 'elapsed', { configurable: true, get() {
|
|
316
|
+
throw codedError('renamed-field', "engine.elapsed was removed: read engine.time.now('real') (fixed seconds, no scale) or engine.time.now('ambient') (keeps moving while frozen)");
|
|
317
|
+
} });
|