threedog 0.7.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +411 -1
- package/README.md +8 -11
- package/core/{Animator.js → assets/Animator.js} +30 -18
- package/core/{Assets.js → assets/Assets.js} +131 -56
- package/core/{Baked.js → assets/Baked.js} +4 -4
- package/core/assets/assetEntry.js +302 -0
- package/core/{assetHot.js → assets/assetHot.js} +9 -7
- package/core/{assetLoad.js → assets/assetLoad.js} +55 -16
- package/core/assets/assetLod.js +113 -0
- package/core/{assetManifest.js → assets/assetManifest.js} +19 -11
- package/core/{assetReport.js → assets/assetReport.js} +7 -14
- package/core/{namedModel.js → assets/namedModel.js} +17 -13
- package/core/{Audio.js → audio/Audio.js} +47 -25
- package/core/{audioRules.js → audio/audioRules.js} +8 -5
- package/core/{audioVoice.js → audio/audioVoice.js} +17 -30
- package/core/{Events.js → base/Events.js} +3 -3
- package/core/{I18n.js → base/I18n.js} +15 -12
- package/core/{Random.js → base/Random.js} +7 -4
- package/core/{Vars.js → base/Vars.js} +14 -4
- package/core/{easing.js → base/easing.js} +1 -1
- package/core/{errorCodes.js → base/errorCodes.js} +151 -125
- package/core/{errorHints.js → base/errorHints.js} +17 -10
- package/core/{errors.js → base/errors.js} +12 -10
- package/core/{events.generated.js → base/events.generated.js} +11 -0
- package/core/base/follows.js +26 -0
- package/core/base/math.js +66 -0
- package/core/{params.js → base/params.js} +5 -6
- package/core/base/saveValues.js +81 -0
- package/core/base/sections.js +97 -0
- package/core/base/spelling.js +32 -0
- package/core/base/util.js +32 -0
- package/core/{validate.js → base/validate.js} +34 -34
- package/core/{Engine.js → engine/Engine.js} +137 -91
- package/core/{Loading.js → engine/Loading.js} +34 -5
- package/core/{copies.js → engine/copies.js} +4 -4
- package/core/{headlessLoad.js → engine/headlessLoad.js} +32 -15
- package/core/{lifecycle.js → engine/lifecycle.js} +41 -34
- package/core/{loop.js → engine/loop.js} +88 -49
- package/core/engine/moduleSlots.js +176 -0
- package/core/{moduleTypes.js → engine/moduleTypes.js} +26 -14
- package/core/engine/modules.js +503 -0
- package/core/{page.js → engine/page.js} +59 -29
- package/core/{plugins.js → engine/plugins.js} +21 -12
- package/core/{services.js → engine/services.js} +50 -40
- package/core/{startup.js → engine/startup.js} +66 -54
- package/core/{Input.js → input/Input.js} +67 -39
- package/core/{inputContext.js → input/inputContext.js} +14 -5
- package/core/input/inputKeyboard.js +39 -0
- package/core/{inputPad.js → input/inputPad.js} +24 -3
- package/core/{inputPointer.js → input/inputPointer.js} +11 -3
- package/core/input/inputSeat.js +66 -0
- package/core/{inputTouch.js → input/inputTouch.js} +24 -7
- package/core/{Budget.js → inspect/Budget.js} +21 -20
- package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +43 -18
- package/core/{Describe.js → inspect/Describe.js} +34 -26
- package/core/{Inspect.js → inspect/Inspect.js} +39 -10
- package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +7 -8
- package/core/{InspectPerf.js → inspect/InspectPerf.js} +19 -13
- package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
- package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +3 -2
- package/core/{UrlState.js → inspect/UrlState.js} +60 -24
- package/core/{catalog.js → inspect/catalog.js} +15 -8
- package/core/{checks.js → inspect/checks.js} +7 -5
- package/core/{debugView.js → inspect/debugView.js} +4 -4
- package/core/{describeRender.js → inspect/describeRender.js} +24 -22
- package/core/{describeText.js → inspect/describeText.js} +17 -8
- package/core/inspect/geometryWatch.js +38 -0
- package/core/{lightWatch.js → inspect/lightWatch.js} +8 -8
- package/core/inspect/metadata.generated.js +4140 -0
- package/core/{pictureWriters.js → inspect/pictureWriters.js} +130 -47
- package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
- package/core/inspect/toolDoor.js +21 -0
- package/core/inspect/valueHistory.js +35 -0
- package/core/{Ops.js → ops/Ops.js} +44 -14
- package/core/{control.js → ops/control.js} +57 -31
- package/core/ops/holds.js +140 -0
- package/core/{opsAtomic.js → ops/opsAtomic.js} +18 -5
- package/core/{opsCheck.js → ops/opsCheck.js} +11 -10
- package/core/{opsFail.js → ops/opsFail.js} +5 -7
- package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
- package/core/{opsRun.js → ops/opsRun.js} +9 -6
- package/core/{owned.js → ops/owned.js} +33 -19
- package/core/{sharedPoint.js → ops/sharedPoint.js} +13 -16
- package/core/{stackFrames.js → ops/stackFrames.js} +2 -2
- package/core/{stacks.js → ops/stacks.js} +34 -15
- package/core/{wrap.js → ops/wrap.js} +8 -6
- package/core/{SaveStore.js → saves/SaveStore.js} +53 -27
- package/core/{Saves.js → saves/Saves.js} +171 -54
- package/core/saves/saveApply.js +312 -0
- package/core/{saveFiles.js → saves/saveFiles.js} +45 -38
- package/core/{saveVersions.js → saves/saveVersions.js} +24 -23
- package/core/saves/session.js +231 -0
- package/core/saves/stateReplace.js +184 -0
- package/core/{Rays.js → scene/Rays.js} +44 -30
- package/core/{Views.js → scene/Views.js} +16 -8
- package/core/{adaptive.js → scene/adaptive.js} +19 -9
- package/core/{canvasBox.js → scene/canvasBox.js} +4 -3
- package/core/scene/compositeGround.js +72 -0
- package/core/scene/floor.js +17 -0
- package/core/{gameLights.js → scene/gameLights.js} +17 -7
- package/core/{grayMap.js → scene/grayMap.js} +8 -2
- package/core/{grid.js → scene/grid.js} +6 -4
- package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
- package/core/scene/ground.contract.js +14 -0
- package/core/scene/ground.js +139 -0
- package/core/{movement.js → scene/movement.js} +3 -3
- package/core/{pictureSlots.js → scene/pictureSlots.js} +2 -2
- package/core/scene/pixel.js +154 -0
- package/core/scene/pixelRatio.js +167 -0
- package/core/{sceneDelta.js → scene/sceneDelta.js} +5 -5
- package/core/{sceneMethods.js → scene/sceneMethods.js} +43 -15
- package/core/scene/stepPoses.js +60 -0
- package/core/{targeting.js → scene/targeting.js} +4 -5
- package/core/{thingExplain.js → scene/thingExplain.js} +7 -6
- package/core/{thingOps.js → scene/thingOps.js} +25 -16
- package/core/{things.js → scene/things.js} +18 -5
- package/core/{threePatches.js → scene/threePatches.js} +1 -1
- package/core/{tier.js → scene/tier.js} +10 -0
- package/core/scene/view.js +161 -0
- package/core/{Batching.js → stream/Batching.js} +85 -28
- package/core/{Stream.js → stream/Stream.js} +80 -38
- package/core/{batchGroups.js → stream/batchGroups.js} +11 -9
- package/core/{chunkStream.js → stream/chunkStream.js} +40 -0
- package/core/{scatter.js → stream/scatter.js} +7 -4
- package/core/{streamSources.js → stream/streamSources.js} +14 -8
- package/core/{Commits.js → threads/Commits.js} +17 -11
- package/core/{Jobs.js → threads/Jobs.js} +25 -13
- package/core/{Threads.js → threads/Threads.js} +21 -18
- package/core/{threadPure.js → threads/threadPure.js} +7 -5
- package/core/{threadServe.js → threads/threadServe.js} +3 -3
- package/core/{Clock.js → time/Clock.js} +20 -11
- package/core/{dayTime.js → time/dayTime.js} +5 -1
- package/core/{skip.js → time/skip.js} +28 -21
- package/core/{time.js → time/time.js} +32 -20
- package/core/{uiClock.js → time/uiClock.js} +4 -4
- package/docs/AI.md +92 -72
- package/docs/API.md +33 -28
- package/docs/CODEMAP.md +121 -200
- package/docs/COMMANDS.md +77 -70
- package/docs/CONVENTIONS.md +167 -24
- package/docs/MIGRATING-0.8.md +171 -0
- package/docs/MIGRATING-1.0.md +101 -0
- package/docs/THREE.md +140 -38
- package/docs/api/assets.md +12 -13
- package/docs/api/audio.md +6 -5
- package/docs/api/budget.md +4 -4
- package/docs/api/calendar.md +10 -11
- package/docs/api/cameraRig.md +32 -29
- package/docs/api/characters.md +35 -24
- package/docs/api/clock.md +1 -1
- package/docs/api/collider3d.md +9 -0
- package/docs/api/collision.md +12 -9
- package/docs/api/content.md +18 -17
- package/docs/api/dialogue.md +5 -4
- package/docs/api/engine.md +58 -54
- package/docs/api/events.md +17 -6
- package/docs/api/flow.md +1 -1
- package/docs/api/grids.md +1 -1
- package/docs/api/ground.md +6 -7
- package/docs/api/hud.md +2 -2
- package/docs/api/i18n.md +6 -6
- package/docs/api/input.md +9 -8
- package/docs/api/interactions.md +5 -5
- package/docs/api/inventory.md +10 -10
- package/docs/api/jobs.md +5 -5
- package/docs/api/level.md +10 -9
- package/docs/api/lightPool.md +1 -6
- package/docs/api/music.md +3 -3
- package/docs/api/nav.md +14 -12
- package/docs/api/openWorld.md +1 -1
- package/docs/api/particles.md +10 -7
- package/docs/api/photo.md +4 -2
- package/docs/api/pickups.md +3 -3
- package/docs/api/post.md +21 -5
- package/docs/api/quests.md +7 -5
- package/docs/api/rays.md +7 -7
- package/docs/api/rigid.md +29 -19
- package/docs/api/saves.md +13 -11
- package/docs/api/settings.md +9 -8
- package/docs/api/sky.md +8 -7
- package/docs/api/stream.md +8 -9
- package/docs/api/swarm.md +34 -0
- package/docs/api/terrain.md +6 -8
- package/docs/api/terrainDraw.md +2 -2
- package/docs/api/timeline.md +4 -4
- package/docs/api/tools.md +27 -22
- package/docs/api/triggers.md +2 -0
- package/docs/api/vars.md +1 -1
- package/docs/api/vegetation.md +4 -3
- package/docs/api/vegetationDraw.md +2 -2
- package/docs/api/water.md +7 -3
- package/docs/api/weather.md +27 -12
- package/docs/api/weatherDraw.md +4 -4
- package/docs/api/world.md +6 -6
- package/docs/recipes/01-new-game.md +28 -43
- package/docs/recipes/02-npc.md +21 -23
- package/docs/recipes/03-items-pickups.md +37 -53
- package/docs/recipes/04-quests.md +5 -4
- package/docs/recipes/05-props-bake.md +34 -44
- package/docs/recipes/06-clock-events.md +31 -22
- package/docs/recipes/07-flow-scenes-pause.md +30 -32
- package/docs/recipes/08-weather-sky.md +91 -37
- package/docs/recipes/09-materials-lights-models.md +25 -39
- package/docs/recipes/10-blender-level.md +22 -11
- package/docs/recipes/11-vehicles.md +44 -24
- package/docs/recipes/12-navmesh.md +60 -15
- package/docs/recipes/13-animation.md +70 -22
- package/docs/recipes/14-custom-module.md +33 -20
- package/docs/recipes/15-perf.md +51 -28
- package/docs/recipes/16-dev-bridge.md +39 -58
- package/docs/recipes/18-world.md +49 -28
- package/docs/recipes/19-shooting-picking.md +7 -4
- package/docs/recipes/20-content-actions-save.md +55 -40
- package/docs/recipes/21-camera.md +47 -25
- package/docs/recipes/22-shop-gold.md +21 -16
- package/docs/recipes/23-ops.md +28 -24
- package/docs/recipes/26-ui-parts.md +25 -14
- package/docs/recipes/27-net.md +3 -5
- package/docs/recipes/28-terrain.md +119 -23
- package/docs/recipes/29-grid.md +3 -3
- package/docs/recipes/30-templates.md +63 -30
- package/docs/recipes/31-audio.md +7 -7
- package/docs/recipes/32-action-game.md +21 -11
- package/docs/recipes/33-stream-sources.md +6 -3
- package/docs/recipes/34-environment-lighting.md +72 -25
- package/docs/recipes/35-picture-from-reference.md +20 -23
- package/docs/recipes/36-ground-plants.md +106 -0
- package/docs/recipes/40-scene.md +18 -21
- package/docs/recipes/43-shader-patches-surfaces.md +27 -48
- package/docs/recipes/44-water-weather-hooks.md +56 -50
- package/docs/recipes/45-cascaded-shadows.md +41 -20
- package/docs/recipes/46-blender-art-route.md +9 -10
- package/docs/recipes/49-game-module-contract.md +7 -6
- package/docs/recipes/50-own-renderer.md +3 -2
- package/docs/recipes/51-capability-catalog.md +14 -8
- package/docs/recipes/52-around-the-picture.md +56 -100
- package/docs/recipes/53-ground-up-close.md +61 -24
- package/docs/recipes/55-mods-time-wrap.md +17 -20
- package/docs/recipes/56-webgpu-tsl.md +28 -15
- package/docs/recipes/57-control.md +39 -12
- package/docs/recipes/58-input.md +15 -2
- package/docs/recipes/59-depth-post-effects.md +1 -1
- package/docs/recipes/60-judge-the-picture.md +30 -25
- package/docs/recipes/62-picture-code.md +129 -39
- package/docs/recipes/63-third-person-start.md +19 -5
- package/docs/recipes/64-particles.md +54 -5
- package/docs/recipes/65-swarm.md +140 -0
- package/docs/recipes/66-common-tasks.md +313 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +5 -5
- package/examples/perf-island/.threedog/content-index.json +1 -0
- package/examples/{sheepisland → perf-island}/GAMEMAP.md +15 -14
- package/examples/{sheepisland → perf-island}/assets.js +1 -1
- package/examples/{sheepisland → perf-island}/main.js +8 -8
- package/examples/{sheepisland → perf-island}/models.js +1 -1
- package/examples/{sheepisland → perf-island}/params.js +1 -1
- package/examples/{sheepisland → perf-island}/picture/index.js +1 -1
- package/examples/{sheepisland → perf-island}/picture/palette.js +2 -2
- package/examples/{sheepisland → perf-island}/views.js +1 -1
- package/examples/plain-picture/GAMEMAP.md +4 -1
- package/examples/rc2d/GAMEMAP.md +4 -3
- package/examples/rc2d/main.js +1 -3
- package/examples/rc2d/rc2d.js +1 -1
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +6 -5
- package/examples/techniques/contact-shadows/contactShadows.js +1 -1
- package/examples/techniques/contact-shadows/main.js +1 -1
- package/examples/techniques/interior-light/main.js +1 -1
- package/examples/techniques/modular-building/README.md +7 -6
- package/examples/techniques/outlines-and-rim/picture/post.js +1 -1
- package/examples/techniques/procedural-animation/README.md +1 -1
- package/examples/webgpu-tsl/GAMEMAP.md +2 -1
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +9 -7
- package/examples/world/main.js +3 -3
- package/examples/world/picture/sky.js +1 -1
- package/index.d.ts +16 -12
- package/index.js +53 -32
- package/llms.txt +11 -14
- package/modules/ambience/Ambience.js +16 -11
- package/modules/calendar/Calendar.js +19 -19
- package/modules/calendar/index.js +18 -16
- package/modules/calendar/schedule.js +11 -6
- package/modules/calendar/seasons.js +7 -7
- package/modules/camera/FirstPersonCamera.js +5 -5
- package/modules/camera/FixedCamera.js +43 -30
- package/modules/camera/FollowCamera.js +24 -15
- package/modules/camera/RtsCamera.js +12 -11
- package/modules/camera/common.js +72 -37
- package/modules/camera/contract.js +1 -0
- package/modules/camera/pixelSnap.js +62 -0
- package/modules/characters/Character.js +166 -70
- package/modules/characters/NPC.js +84 -44
- package/modules/characters/assetModel.js +16 -12
- package/modules/characters/astar.js +48 -27
- package/modules/characters/behaviors.js +4 -5
- package/modules/characters/character.contract.js +21 -0
- package/modules/characters/contract.js +17 -3
- package/modules/characters/index.js +240 -226
- package/modules/characters/moveHelpers.js +88 -12
- package/modules/characters/mover.contract.js +14 -0
- package/modules/characters/movers/common.js +22 -18
- package/modules/characters/movers/manual.js +1 -1
- package/modules/characters/movers/rapier.js +18 -10
- package/modules/characters/movers/simple.js +26 -13
- package/modules/characters/movers/support.js +24 -13
- package/modules/characters/npcAvoid.js +19 -16
- package/modules/characters/npcSim.js +88 -32
- package/modules/characters/npcView.js +19 -11
- package/modules/characters/pathAsync.js +81 -29
- package/modules/characters/pathJob.js +38 -21
- package/modules/characters/pathWorker.js +1 -1
- package/modules/characters/player.js +120 -0
- package/modules/characters/playerStrings.js +2 -2
- package/modules/characters/proceduralRig.js +2 -2
- package/modules/characters/seat.js +56 -0
- package/modules/characters/useModel.js +3 -3
- package/modules/characters/vehicle.contract.js +8 -5
- package/modules/characters/walkTo.js +40 -33
- package/modules/collision/Collision.js +69 -45
- package/modules/collision/contract.js +15 -0
- package/modules/collision/grid.js +6 -1
- package/modules/content/explain.js +2 -3
- package/modules/content/fields.js +24 -3
- package/modules/content/ids.js +5 -3
- package/modules/content/index.js +132 -114
- package/modules/content/loader.js +117 -140
- package/modules/content/markers.js +25 -0
- package/modules/content/models.js +54 -17
- package/modules/content/packs.js +5 -4
- package/modules/content/parts.js +2 -2
- package/modules/content/places.js +36 -0
- package/modules/content/props.js +22 -17
- package/modules/content/rules.js +47 -61
- package/modules/content/stages.js +7 -7
- package/modules/content/templates.js +80 -49
- package/modules/content/words.js +47 -0
- package/modules/debug/DebugPanel.js +14 -45
- package/modules/flow/contract.js +2 -1
- package/modules/flow/index.js +30 -16
- package/modules/gameplay/Container.js +17 -13
- package/modules/gameplay/Containers.js +23 -6
- package/modules/gameplay/Dialogue.js +93 -34
- package/modules/gameplay/Interactions.js +93 -51
- package/modules/gameplay/Inventory.js +64 -22
- package/modules/gameplay/Quests.js +146 -30
- package/modules/gameplay/boxOps.js +8 -1
- package/modules/gameplay/dialogueBubbles.js +16 -12
- package/modules/gameplay/inventoryOps.js +11 -8
- package/modules/gameplay/pickups.js +63 -37
- package/modules/gameplay/questLog.js +4 -2
- package/modules/gameplay/questSave.js +9 -4
- package/modules/gameplay/quests.contract.js +1 -1
- package/modules/grid/Grid.js +2 -2
- package/modules/grid/Layer.js +12 -8
- package/modules/grid/index.js +28 -23
- package/modules/grid/ops.js +43 -46
- package/modules/grid/preview.js +7 -7
- package/modules/grid/tiles.js +6 -6
- package/modules/hlod/index.js +42 -57
- package/modules/hud/index.js +22 -14
- package/modules/hud/parts.js +8 -8
- package/modules/level/contract.js +16 -0
- package/modules/level/heightfield.js +29 -31
- package/modules/level/index.js +113 -161
- package/modules/level/load.js +196 -0
- package/modules/level/meshes.js +65 -0
- package/modules/level/nodes.js +40 -23
- package/modules/lights/index.js +33 -183
- package/modules/lights/slots.js +93 -0
- package/modules/lights/sources.js +90 -0
- package/modules/music/Music.js +34 -28
- package/modules/music/rules.js +1 -1
- package/modules/nav/contract.js +16 -0
- package/modules/nav/index.js +180 -49
- package/modules/nav/navPath.js +45 -10
- package/modules/net/Client.js +7 -7
- package/modules/net/Host.js +7 -7
- package/modules/net/Net.js +1 -1
- package/modules/net/index.js +6 -5
- package/modules/net/sync.js +2 -2
- package/modules/net/transports.js +2 -2
- package/modules/particles/Particles.js +95 -29
- package/modules/particles/effect.js +86 -32
- package/modules/particles/shaders.js +19 -1
- package/modules/photo/Photo.js +23 -23
- package/modules/rigid/RigidBodies.js +255 -89
- package/modules/rigid/Vehicles.js +17 -8
- package/modules/rigid/collider3d.contract.js +26 -0
- package/modules/rigid/ragdoll.js +298 -0
- package/modules/rigid/ragdollBones.js +209 -0
- package/modules/rigid/refresh.js +10 -0
- package/modules/rigid/sync.js +51 -20
- package/modules/settings/Settings.js +177 -61
- package/modules/settings/apply.js +20 -13
- package/modules/settings/sections.js +19 -14
- package/modules/settings/strings.js +2 -2
- package/modules/settings/view.js +3 -3
- package/modules/sky/Sky.js +29 -22
- package/modules/sky/clouds.js +7 -7
- package/modules/sky/dome.js +33 -20
- package/modules/sky/domeLayers.js +9 -9
- package/modules/sky/environment.js +6 -6
- package/modules/sky/frame.js +19 -10
- package/modules/sky/season.js +7 -1
- package/modules/sky/shader.js +24 -25
- package/modules/sky/skyModule.js +17 -28
- package/modules/sky/tint.js +1 -1
- package/modules/swarm/Swarm.js +356 -0
- package/modules/swarm/draw.js +68 -0
- package/modules/swarm/grid.js +63 -0
- package/modules/terrain/ChunkManager.js +71 -59
- package/modules/terrain/chunkQueries.js +7 -24
- package/modules/terrain/chunkWorker.js +1 -1
- package/modules/terrain/draw.js +14 -11
- package/modules/terrain/index.js +42 -42
- package/modules/terrain/terrainColorMap.js +6 -3
- package/modules/terrain/terrainDefaults.js +2 -1
- package/modules/terrain/terrainEdit.js +45 -29
- package/modules/terrain/terrainGen.js +19 -12
- package/modules/terrain/terrainIsland.js +2 -2
- package/modules/terrain/terrainMesh.js +7 -6
- package/modules/terrain/terrainShape.js +8 -10
- package/modules/terrain/terrainShapeMain.js +3 -3
- package/modules/timeline/Timeline.js +83 -43
- package/modules/timeline/Tween.js +25 -19
- package/modules/timeline/shots.js +24 -17
- package/modules/triggers/index.js +95 -28
- package/modules/vegetation/Vegetation.js +34 -26
- package/modules/vegetation/densityMap.js +4 -7
- package/modules/vegetation/draw.js +39 -18
- package/modules/vegetation/groundChunks.js +21 -38
- package/modules/vegetation/index.js +37 -12
- package/modules/vegetation/modelGeometry.js +3 -6
- package/modules/vegetation/nearFade.js +1 -1
- package/modules/water/Water.js +20 -16
- package/modules/water/surface.js +3 -3
- package/modules/weather/Weather.js +52 -40
- package/modules/weather/particles.js +8 -8
- package/modules/weather/weatherDraw.js +28 -23
- package/modules/world/World.js +28 -15
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +30 -17
- package/modules/world/persist.js +90 -27
- package/modules/world/pos.js +5 -5
- package/modules/world/records.js +37 -11
- package/modules/world/sim.js +78 -27
- package/modules/world/simFar.js +2 -2
- package/modules/world/state.js +43 -11
- package/modules/world/thingSource.js +20 -5
- package/modules/world/views.js +27 -14
- package/package.json +48 -7
- package/presets.js +1 -3
- package/render/PostFX.js +83 -53
- package/render/backend.js +31 -33
- package/render/cascades.js +17 -12
- package/render/cascades.tsl.js +5 -8
- package/render/daylight.js +20 -3
- package/render/detail.js +8 -7
- package/render/effects.js +28 -25
- package/render/fuse.js +3 -3
- package/render/fx/cloudShadow.tsl.js +3 -3
- package/render/fx/detail.tsl.js +1 -1
- package/render/fx/index.js +5 -10
- package/render/fx/library.tsl.js +11 -0
- package/render/fx/lighting.tsl.js +2 -1
- package/render/fx/nodeErrors.tsl.js +2 -2
- package/render/fx/objectOrigin.tsl.js +1 -2
- package/render/fx/particles.tsl.js +8 -6
- package/render/fx/patchNodes.tsl.js +5 -15
- package/render/fx/postWebGPU.tsl.js +30 -26
- package/render/fx/sky.tsl.js +15 -17
- package/render/fx/uniforms.tsl.js +4 -4
- package/render/fx/wind.tsl.js +1 -1
- package/render/fxNumbers.js +3 -0
- package/render/layers.js +2 -2
- package/render/lighting.js +5 -3
- package/render/lightmap.js +41 -21
- package/render/lights.js +6 -6
- package/render/lit.js +24 -0
- package/render/materials.js +8 -7
- package/render/mergeCommon.js +22 -0
- package/render/modeling.js +2 -2
- package/render/occlusion.js +62 -15
- package/render/ownFrame.js +4 -4
- package/render/patches.js +15 -15
- package/render/postWebGL.js +15 -12
- package/render/probes.js +41 -19
- package/render/recordSweep.js +117 -0
- package/render/shaderErrors.js +10 -9
- package/render/shadowCache.tsl.js +107 -0
- package/render/shadowTypes.js +9 -0
- package/{core → render}/shadows.js +59 -13
- package/render/slots.js +7 -7
- package/render/terms.js +22 -24
- package/render/uniformDecl.js +1 -1
- package/types/core.d.ts +336 -202
- package/types/gameplay.d.ts +254 -130
- package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +22 -7
- package/types/generated/core/{audioVoice.d.ts → audio/audioVoice.d.ts} +2 -2
- package/types/generated/core/{Events.d.ts → base/Events.d.ts} +4 -4
- package/types/generated/core/{I18n.d.ts → base/I18n.d.ts} +8 -16
- package/types/generated/core/{Random.d.ts → base/Random.d.ts} +4 -3
- package/types/generated/core/{page.d.ts → engine/page.d.ts} +8 -9
- package/types/generated/core/{Input.d.ts → input/Input.d.ts} +28 -10
- package/types/generated/core/input/inputSeat.d.ts +26 -0
- package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
- package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +17 -3
- package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +6 -4
- package/types/generated/core/{control.d.ts → ops/control.d.ts} +14 -10
- package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +62 -18
- package/types/generated/core/{session.d.ts → saves/session.d.ts} +3 -2
- package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
- package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +2 -2
- package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
- package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +22 -18
- package/types/generated/core/{Commits.d.ts → threads/Commits.d.ts} +1 -1
- package/types/generated/core/{Jobs.d.ts → threads/Jobs.d.ts} +6 -6
- package/types/generated/core/{Threads.d.ts → threads/Threads.d.ts} +4 -4
- package/types/generated/modules/calendar/Calendar.d.ts +10 -11
- package/types/generated/modules/debug/DebugPanel.d.ts +1 -9
- package/types/generated/modules/grid/Grid.d.ts +1 -0
- package/types/generated/modules/grid/Layer.d.ts +1 -1
- package/types/generated/modules/grid/index.d.ts +3 -3
- package/types/generated/modules/music/Music.d.ts +7 -5
- package/types/generated/modules/particles/Particles.d.ts +5 -4
- package/types/generated/modules/sky/Sky.d.ts +21 -10
- package/types/generated/modules/swarm/Swarm.d.ts +80 -0
- package/types/generated/modules/timeline/Timeline.d.ts +7 -5
- package/types/generated/modules/water/Water.d.ts +1 -0
- package/types/generated/modules/weather/Weather.d.ts +14 -16
- package/types/generated/modules/weather/weatherDraw.d.ts +3 -3
- package/types/generated/modules/world/World.d.ts +11 -7
- package/types/generated/render/PostFX.d.ts +21 -23
- package/types/generated/render/materials.d.ts +1 -0
- package/types/generated/render/occlusion.d.ts +9 -0
- package/types/generated/render/patches.d.ts +1 -0
- package/types/generated/ui/Focus.d.ts +1 -0
- package/types/generated/ui/UI.d.ts +1 -0
- package/types/nav.d.ts +47 -15
- package/types/physics.d.ts +150 -73
- package/types/pixel.d.ts +75 -0
- package/types/tsl.d.ts +37 -4
- package/types/world.d.ts +48 -75
- package/ui/Focus.js +10 -9
- package/ui/Parts.js +13 -5
- package/ui/UI.js +7 -7
- package/ui/defaults.js +3 -2
- package/ui/theme.js +7 -5
- package/core/assetEntry.js +0 -109
- package/core/engineCamera.js +0 -32
- package/core/ground.js +0 -104
- package/core/holds.js +0 -134
- package/core/math.js +0 -48
- package/core/moduleSlots.js +0 -100
- package/core/modules.js +0 -314
- package/core/saveApply.js +0 -210
- package/core/saveValues.js +0 -46
- package/core/session.js +0 -174
- package/core/shadowTypes.js +0 -16
- package/core/util.js +0 -17
- package/core/view.js +0 -43
- package/docs/MIGRATING-0.3.md +0 -248
- package/docs/MIGRATING-0.4.md +0 -320
- package/docs/MIGRATING-0.5.md +0 -68
- package/docs/MIGRATING-0.6.md +0 -126
- package/docs/PERF.md +0 -245
- package/docs/recipes/36-sky-ground-plants.md +0 -158
- package/docs/recipes/37-terrain-hooks.md +0 -115
- package/docs/recipes/38-environment-hooks.md +0 -67
- package/docs/recipes/42-terrain-shape.md +0 -64
- package/docs/recipes/47-island-snow-backdrop.md +0 -43
- package/docs/recipes/54-three-idioms.md +0 -88
- package/examples/plain-picture/FINDINGS.md +0 -53
- package/examples/sheepisland/.threedog/content-index.json +0 -1
- package/modules/camera/projection.js +0 -21
- /package/core/{mulberry32.js → base/mulberry32.js} +0 -0
- /package/core/{inputDefaults.js → input/inputDefaults.js} +0 -0
- /package/core/{textureBytes.js → inspect/textureBytes.js} +0 -0
- /package/core/{actor.js → ops/actor.js} +0 -0
- /package/core/{opsHistory.js → ops/opsHistory.js} +0 -0
- /package/core/{saveIds.js → saves/saveIds.js} +0 -0
- /package/core/{screenToGround.js → scene/screenToGround.js} +0 -0
- /package/core/{cells.js → stream/cells.js} +0 -0
- /package/core/{streamCells.js → stream/streamCells.js} +0 -0
- /package/core/{pureWorker.js → threads/pureWorker.js} +0 -0
- /package/examples/{sheepisland → perf-island}/content/index.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/props.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/templates.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/vegetation.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/lights.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/materials.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/sky.js +0 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
// Two copies of the engine on one page (e.g. a game imports `threedog` while a
|
|
1
|
+
// Two copies of the engine on one page (e.g. a game imports `threedog` while a pack or tool bundles its own copy, or a
|
|
2
2
|
// workspace link plus an npm copy). Each copy installs the shadow accessors on THREE.Mesh.prototype (render/patches.js) and keeps
|
|
3
3
|
// its own patch lists, so the second install makes the first copy's wind / CSM materials cast no matching shadow: nothing throws,
|
|
4
4
|
// shadows just go wrong. So each copy writes itself under one global symbol at load and the second one says so, once, naming both.
|
|
5
5
|
// console: [threedog] two copies of the engine on this page (0.2.1 at .../node_modules/threedog/, 0.2.1 at .../packages/engine/): load one, ...
|
|
6
6
|
// A hot reload re-runs the same file (same path, a ?t= query): that is one copy, not two, so the path without the query decides.
|
|
7
|
-
import { coded } from '
|
|
7
|
+
import { coded } from '../base/errorHints.js';
|
|
8
8
|
|
|
9
|
-
export const VERSION = '0.
|
|
9
|
+
export const VERSION = '0.9.0'; // kept equal to package.json by the "[guard] engine copies" spec
|
|
10
10
|
|
|
11
11
|
const KEY = Symbol.for('threedog.engine.copies');
|
|
12
12
|
|
|
@@ -27,6 +27,6 @@ export function noteCopy(me, registry = globalThis) {
|
|
|
27
27
|
if (!other) return '';
|
|
28
28
|
return coded('engine-two-copies', `[threedog] two copies of the engine on this page (${other.version} at ${other.root}, ${me.version} at ${root}): ` +
|
|
29
29
|
"load one, e.g. vite.config.js: resolve: { dedupe: ['threedog', 'three'] }. Each copy hooks THREE.Mesh.prototype for shadows, so " +
|
|
30
|
-
'wind / cascaded-shadow materials of one copy cast wrong shadows. `npm ls threedog` shows who pulls the second; a
|
|
30
|
+
'wind / cascaded-shadow materials of one copy cast wrong shadows. `npm ls threedog` shows who pulls the second; a pack or ' +
|
|
31
31
|
'tool lists threedog under peerDependencies, not dependencies');
|
|
32
32
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Headless loading after start: a headless engine (?threedog-headless, createEngine({ headless: true })) has no real-time loop, so after start()
|
|
2
2
|
// nothing runs frames unless someone calls step(). Anything that makes the world load again after start (a species added with
|
|
3
|
-
// vegetation.define, terrain.
|
|
3
|
+
// vegetation.define, terrain.density, a teleport, a level swap) queued its work and waited for frames that never came: the page sat on
|
|
4
4
|
// "waiting for module terrain" forever, while the same page in a live browser loaded within a second.
|
|
5
5
|
//
|
|
6
6
|
// Why a load pump and not "step more" in the tools: step() is synchronous, and chunk results come back from workers between tasks, so no
|
|
@@ -9,10 +9,9 @@
|
|
|
9
9
|
// dt 0, jobs drain deterministically), on a timer. A settled world runs nothing, so step()-driven tests keep their exact frame count.
|
|
10
10
|
//
|
|
11
11
|
// stateApplied waits for it too (Engine.js): screenshots, npm test and the dev bridge wait on stateApplied, so a load that began after
|
|
12
|
-
// start is finished before they capture. A load that never settles stops holding stateApplied
|
|
13
|
-
|
|
14
|
-
import {
|
|
15
|
-
import { coded } from './errorHints.js';
|
|
12
|
+
// start is finished before they capture. A load that never settles stops holding stateApplied at whenSettled's limit with one warning naming who is still waiting, so a stuck module cannot hang a tool.
|
|
13
|
+
import { DEV, warnOnce } from '../base/validate.js';
|
|
14
|
+
import { coded, codedError } from '../base/errorHints.js';
|
|
16
15
|
|
|
17
16
|
const TICK_MS = 16; // one loading frame per ~60 Hz tick: the same pace a live loop gives the workers
|
|
18
17
|
|
|
@@ -24,26 +23,44 @@ export function unsettled(e) {
|
|
|
24
23
|
return who;
|
|
25
24
|
}
|
|
26
25
|
|
|
26
|
+
/** The error of a settle that did not come, in the words unsettled() gives */
|
|
27
|
+
const stalled = e => codedError('module-not-ready', `Still waiting after ${Math.round(e.loading.timeoutMs / 1000)} s for: ${unsettled(e).join(', ')}. A module's isReady(e) keeps returning false (or the world never finished its nearby builds); fix that, or raise engine.loading.timeoutMs if the load is only slow`);
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @internal The one wait for "ready to play": true once nothing is unsettled, checked per engine frame so step() advances it too; false as soon as valid() stops holding. It rejects (module-not-ready,
|
|
31
|
+
* naming who still waits) after engine.loading.timeoutMs. start(), flow's transition, level:playable and the headless pump all read this, so the question has one answer and one limit.
|
|
32
|
+
*/
|
|
33
|
+
export function whenSettled(e, valid = () => true) {
|
|
34
|
+
const now = () => !valid() ? false : unsettled(e).length ? null : true;
|
|
35
|
+
const first = now();
|
|
36
|
+
if (first !== null) return Promise.resolve(first);
|
|
37
|
+
const since = performance.now(); // measure: wall clock, so a wait with no frames to run on still ends
|
|
38
|
+
let h;
|
|
39
|
+
const settled = new Promise((res, rej) => {
|
|
40
|
+
h = e.onFrame(() => {
|
|
41
|
+
try { const r = now(); if (r !== null) { h.remove(); res(r); } } catch (err) { h.remove(); rej(err); } // a throwing isReady ends the wait: this hook's error would reach no waiter
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
return e.loading._limit(settled, () => now() === null ? since : null, () => { h.remove(); return stalled(e); });
|
|
45
|
+
}
|
|
46
|
+
|
|
27
47
|
/** @internal start(): begin pumping loading frames for a headless engine (no-op for a live one, its loop already runs frames) */
|
|
28
48
|
export function startHeadlessLoad(e) {
|
|
29
49
|
if (!e.headless || e._headlessLoad) return;
|
|
30
|
-
const s = e._headlessLoad = {
|
|
50
|
+
const s = e._headlessLoad = { watching: false, stalled: false };
|
|
31
51
|
const tick = () => {
|
|
32
52
|
if (e.disposed) return;
|
|
33
|
-
if (!unsettled(e).length)
|
|
53
|
+
if (!unsettled(e).length) s.stalled = false;
|
|
34
54
|
else {
|
|
35
|
-
|
|
36
|
-
|
|
55
|
+
if (!s.watching && !s.stalled) {
|
|
56
|
+
s.watching = true;
|
|
57
|
+
whenSettled(e).catch(err => { s.stalled = true; if (DEV) warnOnce(coded('module-not-ready', `headless load after start: ${err.message}; stateApplied no longer waits for it`)); }).finally(() => { s.watching = false; });
|
|
58
|
+
}
|
|
37
59
|
// the same loading frame start() runs while it waits (startup.js _waitReady): frame hooks, stream, jobs; game time stays put
|
|
38
60
|
// (no input.endFrame: a key a test pressed before its next step() must still read as just pressed there)
|
|
39
61
|
e._frameHooks(0, true);
|
|
40
|
-
if (!s.stalled && now - s.since > e.loading.timeoutMs) {
|
|
41
|
-
s.stalled = true;
|
|
42
|
-
const who = unsettled(e);
|
|
43
|
-
if (DEV && who.length) warnOnce(coded('module-not-ready', `headless load after start stalled: still waiting after ${Math.round(e.loading.timeoutMs / 1000)} s for: ${who.join(', ')}; stateApplied no longer waits for it. A module's isReady(e) keeps returning false; fix that module, or raise engine.loading.timeoutMs if the load is just slow`));
|
|
44
|
-
}
|
|
45
62
|
}
|
|
46
|
-
|
|
63
|
+
setTimeout(tick, TICK_MS); // main-loop: a headless engine's stand-in for the live frame loop while something is loading
|
|
47
64
|
};
|
|
48
65
|
tick();
|
|
49
66
|
}
|
|
@@ -10,19 +10,23 @@
|
|
|
10
10
|
// ctx.track (modules.js), so they also leave when its install rolls back or its init fails, and go before its dispose hook runs.
|
|
11
11
|
// - Things core does not know about (Worker, physics world, Audio nodes, real-time timers): clean up in the module's dispose(e) hook, called in reverse install order.
|
|
12
12
|
// - GPU memory: every geometry, material and texture in the scene, the assets cache, the post composer, then renderer.dispose().
|
|
13
|
+
// Waits across dispose, one rule: a wait in game code (model(), jobs.add, nextFixed, a cutscene, an await of what those feed) stays pending for good, because the code after it
|
|
14
|
+
// belongs to a dead engine (assetEntry.js says why not reject). Two waits have to answer instead: start(), for whoever booted the engine (startup.js), and a stream source's whenReady,
|
|
15
|
+
// which rejects stream-removed: dispose removes every source, and a source made afterwards is born removed.
|
|
13
16
|
// Level changes do not come through here: things inside a level register with level.track(handle), and the level removes them itself on change.
|
|
14
17
|
|
|
15
|
-
import { coded, codedError } from '
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
18
|
+
import { coded, codedError } from '../base/errorHints.js';
|
|
19
|
+
import { fmt } from '../base/validate.js';
|
|
20
|
+
import { dropOwned } from '../ops/owned.js';
|
|
21
|
+
import { reportError } from '../base/errors.js';
|
|
22
|
+
import { releaseContext, memory } from '../../render/backend.js';
|
|
19
23
|
|
|
20
|
-
/** The per-step / per-frame callback lists (onFixed, onFrame, onRender, module hooks), empty: the constructor's starting state and what dispose leaves */
|
|
24
|
+
/** The per-step / per-frame callback lists (onFixed, onFrame, animators, onRender, module hooks), empty: the constructor's starting state and what dispose leaves */
|
|
21
25
|
export function clearHooks(e) {
|
|
22
|
-
e._fixed = []; e._fixedLate = []; e._frame = []; e._onRender = { before: [], after: [] }; e._hooks = { fixed: [], frame: [], afterRender: [], skip: [] };
|
|
26
|
+
e._fixed = []; e._fixedLate = []; e._frame = []; e._animate = []; e._onRender = { before: [], after: [] }; e._hooks = { fixed: [], frame: [], afterRender: [], skip: [] };
|
|
23
27
|
}
|
|
24
28
|
|
|
25
|
-
const STRINGS = { failed: '[engine] dispose hook of module {name} threw (the rest are still cleaned up)',
|
|
29
|
+
const STRINGS = { failed: '[engine] dispose hook of module {name} threw (the rest are still cleaned up)', part: '[engine] a cleanup step of engine.dispose() threw, {why} (the rest are still cleaned up)',
|
|
26
30
|
released: 'createEngine(): this canvas lost its WebGL context in an earlier engine.dispose(), so a new engine cannot draw on it; use a new canvas, or dispose the old engine with dispose({ keepContext: true })',
|
|
27
31
|
opts: 'engine.dispose(opts): opts is { keepContext?: boolean }; got {v}' };
|
|
28
32
|
|
|
@@ -31,57 +35,60 @@ const released = new WeakSet();
|
|
|
31
35
|
/** createEngine calls it before building its renderer on a canvas */
|
|
32
36
|
export function checkCanvasUsable(canvas) { if (canvas && released.has(canvas)) throw codedError('canvas-released', STRINGS.released); }
|
|
33
37
|
|
|
34
|
-
/** Dispose the geometry, materials and
|
|
35
|
-
function disposeObject(o) {
|
|
36
|
-
o.geometry?.dispose();
|
|
38
|
+
/** Dispose the GPU data of one scene object: geometry, materials and their textures, instance buffers, shadow map, bone texture */
|
|
39
|
+
function disposeObject(o, tidy) {
|
|
40
|
+
tidy(() => o.geometry?.dispose());
|
|
41
|
+
tidy(() => { if (o.isInstancedMesh || o.isBatchedMesh || o.isLight) o.dispose(); }); // instance buffers, batch textures, a light's shadow map
|
|
42
|
+
tidy(() => o.skeleton?.dispose()); // the bone texture
|
|
37
43
|
for (const m of [].concat(o.material || [])) {
|
|
38
|
-
for (const k in m) if (m[k]?.isTexture) m[k].dispose();
|
|
39
|
-
m.dispose();
|
|
44
|
+
for (const k in m) if (m[k]?.isTexture) tidy(() => m[k].dispose());
|
|
45
|
+
tidy(() => m.dispose());
|
|
40
46
|
}
|
|
41
47
|
}
|
|
42
48
|
|
|
43
49
|
export const lifecycleMethods = {
|
|
44
50
|
/**
|
|
45
51
|
* Destroy the engine: stop the main loop, call each module's dispose(e) in reverse install order, then clean up core (listeners, timers, sound, UI, GPU memory).
|
|
46
|
-
* No callbacks fire afterwards and engine.disposed becomes true. Safe to call repeatedly.
|
|
52
|
+
* No callbacks fire afterwards and engine.disposed becomes true. Safe to call repeatedly. start() rejects with engine-disposed; awaits in game code (a model, a job, nextFixed) stay pending for good.
|
|
47
53
|
* The engine's own renderer also gives its WebGL context back (renderer.forceContextLoss): browsers keep only about 16 live contexts, so a page that
|
|
48
54
|
* creates and disposes engines (level editor, tests, restart) would otherwise lose the oldest one. That canvas cannot host a new engine afterwards;
|
|
49
55
|
* keepContext: true keeps the context for a new engine on the same canvas. A renderer the game passed in (createEngine({ renderer })) is never released.
|
|
50
56
|
* @param {{ keepContext?: boolean }} [opts]
|
|
51
57
|
*/
|
|
52
58
|
dispose(opts = {}) {
|
|
53
|
-
if (opts === null || typeof opts !== 'object' || Object.keys(opts).some(k => k !== 'keepContext')) throw codedError('dispose-options', STRINGS.opts
|
|
59
|
+
if (opts === null || typeof opts !== 'object' || Object.keys(opts).some(k => k !== 'keepContext')) throw codedError('dispose-options', fmt(STRINGS.opts, { v: String(JSON.stringify(opts)) }));
|
|
54
60
|
if (this.disposed) return;
|
|
55
|
-
this.phase = 'disposed'; this.
|
|
61
|
+
this.phase = 'disposed'; this.halted = true; this._starting = null; // a finished start() must not answer a later call as if the engine were alive
|
|
56
62
|
cancelAnimationFrame(this._raf);
|
|
57
|
-
|
|
63
|
+
// one step that throws must not leave the renderer, the UI and the listeners alive: a game's 'dispose' listener on a material reaches here, and three calls it inside m.dispose()
|
|
64
|
+
const tidy = fn => { try { fn(); } catch (err) { reportError(this, err, coded('module-dispose', fmt(STRINGS.part, { why: String(err?.message ?? err) })), { soft: true }); } };
|
|
65
|
+
tidy(() => dropOwned(this, [...(this._owned?.values() ?? [])])); // owned.js keeps a page-wide list for allowOwned
|
|
58
66
|
for (const m of [...this.modules.values()].reverse()) {
|
|
59
67
|
this._modState.set(m.name, 'disposed');
|
|
60
68
|
this._dropTracked(m.name); // its listeners / timers go first, so nothing calls into the module while its dispose tears it down
|
|
61
69
|
if (!m.dispose) continue;
|
|
62
|
-
try { m.dispose(this); } catch (err) { reportError(this, err, coded('module-dispose', STRINGS.failed
|
|
70
|
+
try { m.dispose(this); } catch (err) { reportError(this, err, coded('module-dispose', fmt(STRINGS.failed, { name: m.name })), { soft: true }); }
|
|
63
71
|
}
|
|
64
72
|
this._abort.abort();
|
|
65
|
-
this._untrackValidate();
|
|
66
|
-
this._wraps?.dispose(); // engine.wrap: every wrapped method back on its object (a game object or api may outlive the engine)
|
|
67
|
-
this.
|
|
68
|
-
|
|
73
|
+
tidy(() => this._untrackValidate());
|
|
74
|
+
tidy(() => this._wraps?.dispose()); // engine.wrap: every wrapped method back on its object (a game object or api may outlive the engine)
|
|
75
|
+
tidy(() => this._picture?.dispose()); // dev tool: its scene watchers go with the engine
|
|
76
|
+
tidy(() => this.debug.dispose()); // before the scene is disposed: undoes every diagnostic override and view (puts swapped materials back)
|
|
77
|
+
for (const part of [this.saves, this.audio, this.time, this.commits, this.jobs, this.threads, this.stream, this.batching, this.rays, this.events]) tidy(() => part.dispose());
|
|
69
78
|
clearHooks(this); this._afterTick = null;
|
|
70
|
-
this.scene.traverse(disposeObject);
|
|
79
|
+
this.scene.traverse(o => disposeObject(o, tidy));
|
|
71
80
|
// scene.environment is never disposed here: the engine's own maps (sky PMREM targets, the baseline room map) were freed above by their
|
|
72
81
|
// owners, and anything else is the game's texture (a direct scene.environment write), which stays the game's to free
|
|
73
82
|
this.scene.environment = null;
|
|
74
|
-
if (this.scene.background?.isTexture) this.scene.background.dispose();
|
|
75
|
-
this.assets.dispose();
|
|
76
|
-
this.
|
|
77
|
-
this.
|
|
78
|
-
|
|
79
|
-
this.
|
|
80
|
-
this.
|
|
81
|
-
|
|
82
|
-
this.
|
|
83
|
-
this._materials.remove();
|
|
84
|
-
this._uiStyle.remove();
|
|
83
|
+
tidy(() => { if (this.scene.background?.isTexture) this.scene.background.dispose(); });
|
|
84
|
+
for (const part of [this.assets, this.occlusion, this.post]) tidy(() => part.dispose());
|
|
85
|
+
tidy(() => this._webglOnlyView?.remove()); this._webglOnlyView = null;
|
|
86
|
+
tidy(() => this._gpu?.dispose());
|
|
87
|
+
tidy(() => this.renderer.dispose());
|
|
88
|
+
tidy(() => { if (this._ownsRenderer && !opts.keepContext) { releaseContext(this.renderer); released.add(this.renderer.domElement); } });
|
|
89
|
+
tidy(() => this.ui._dispose());
|
|
90
|
+
tidy(() => this._materials.remove());
|
|
91
|
+
tidy(() => this._uiStyle.remove());
|
|
85
92
|
this.uiRoot.remove();
|
|
86
93
|
},
|
|
87
94
|
|
|
@@ -93,7 +100,7 @@ export const lifecycleMethods = {
|
|
|
93
100
|
counts() {
|
|
94
101
|
const mem = memory(this.renderer);
|
|
95
102
|
const c = {
|
|
96
|
-
listeners: this.events.size, fixed: this._fixed.length + this._fixedLate.length, frame: this._frame.length, timers: this.time.size,
|
|
103
|
+
listeners: this.events.size, fixed: this._fixed.length + this._fixedLate.length, frame: this._frame.length + this._animate.length, timers: this.time.size,
|
|
97
104
|
statics: this.rays.statics.size, streamEntries: this.stream.entries.size, jobs: this.jobs.pending, commits: this.commits.pending,
|
|
98
105
|
geometries: mem.geometries, textures: mem.textures,
|
|
99
106
|
};
|
|
@@ -12,17 +12,19 @@
|
|
|
12
12
|
//
|
|
13
13
|
// Determinism: in engine.step() and headless loading frames, jobs ignore the real-time budget and drain the queue (see Jobs.js),
|
|
14
14
|
// and stream's synchronous builds are attached to the scene before step returns: same input and same seed (engine.random) give the same result.
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
15
|
+
import { Vector4 } from 'three';
|
|
16
|
+
import { reportError } from '../base/errors.js';
|
|
17
|
+
import { DEV, warnOnce, fmt } from '../base/validate.js';
|
|
18
|
+
import { coded, codedError } from '../base/errorHints.js';
|
|
19
|
+
import { watchLights } from '../inspect/lightWatch.js';
|
|
20
|
+
import { watchGeometries } from '../inspect/geometryWatch.js';
|
|
21
|
+
import { followFocus } from '../../render/lights.js';
|
|
22
|
+
import { STEP } from '../time/time.js'; // fixed step length: 60 per second
|
|
23
|
+
import { adapt } from '../scene/adaptive.js';
|
|
24
|
+
import { advanceUiClock } from '../time/uiClock.js';
|
|
25
|
+
import { resetStats, programCount, freshFrame } from '../../render/backend.js';
|
|
26
|
+
import { engineDraws } from '../../render/ownFrame.js';
|
|
27
|
+
import { writeDaylight } from '../../render/daylight.js';
|
|
26
28
|
// Most real time one frame may turn into fixed steps (6 steps). A longer hitch slows the game for that frame
|
|
27
29
|
// instead of replaying it in a burst (no spiral of death, no jump after a stall).
|
|
28
30
|
const MAX_CATCHUP = 0.1;
|
|
@@ -32,58 +34,81 @@ const MAX_CATCHUP = 0.1;
|
|
|
32
34
|
const CATCHUP_MS = STEP * 2000;
|
|
33
35
|
// Dev message (console): which hook failed
|
|
34
36
|
const STRINGS = {
|
|
35
|
-
onFixed: 'onFixed callback',
|
|
37
|
+
onFixed: 'onFixed callback', onFrame: 'onFrame callback', animate: 'animator update', onRender: 'onRender callback', clock: 'clock timer', render: 'render',
|
|
36
38
|
hook: '{kind} hook of module {name}',
|
|
39
|
+
stepStart: 'engine.step() ran while start() is still loading: no game time passes, only frame hooks run. Wait for it first: await engine.start(); engine.step(1)',
|
|
40
|
+
stepSession: 'engine.step() ran while a new game, load or quit is still replacing the state: the step plays on a half-replaced world. Wait for it first: await engine.session.load(slot); engine.step(1)',
|
|
37
41
|
};
|
|
38
42
|
|
|
39
43
|
const SOFT = { soft: true }; // core steps (render, stream): report once only
|
|
44
|
+
const _viewport = new Vector4(), _scissor = new Vector4();
|
|
40
45
|
/** Call a hook fn.call(self, a, b); errors go to reportError for tiering.
|
|
41
46
|
* opts: { module } the failing module / SOFT / null (game callback, counts as gameplay).
|
|
42
47
|
* Takes no ...args and needs no caller closure: the main loop calls this many times a frame, so it must not allocate each time. */
|
|
43
48
|
function safe(engine, key, fn, opts, self, a, b) {
|
|
44
49
|
try { fn.call(self, a, b); } catch (err) { reportError(engine, err, key, opts ?? undefined); }
|
|
45
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* One engine.onRender hook. What a hook borrows to draw (the target, viewport, scissor, autoClear, scene.overrideMaterial, camera.layers) it gives back on its last lines, which a
|
|
53
|
+
* throw skips, and the engine's frame then draws into an 8-pixel corner or in one flat material from there on. So a hook that throws has them put back. One that returns
|
|
54
|
+
* is taken at its word: what it left is the game's choice.
|
|
55
|
+
*/
|
|
56
|
+
function drawHook(f, ctx) {
|
|
57
|
+
const { renderer: r, scene, camera } = ctx, target = r.getRenderTarget(), viewport = r.getViewport(_viewport), scissor = r.getScissor(_scissor), scissorTest = r.getScissorTest();
|
|
58
|
+
const { autoClear } = r, { overrideMaterial } = scene, { mask } = camera.layers;
|
|
59
|
+
try { f(ctx); } catch (err) {
|
|
60
|
+
r.setRenderTarget(target); r.setViewport(viewport); r.setScissor(scissor); r.setScissorTest(scissorTest);
|
|
61
|
+
r.autoClear = autoClear; scene.overrideMaterial = overrideMaterial; camera.layers.mask = mask;
|
|
62
|
+
throw err;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** Run one game callback list. remove() replaces the list, so a hook an earlier one removed in this pass (or a dispose) is skipped: it may sit on what its remover just tore down */
|
|
66
|
+
function runList(e, name, key, a) {
|
|
67
|
+
const list = e[name];
|
|
68
|
+
for (const f of list) if (e[name] === list || e[name].includes(f)) safe(e, key, f, null, undefined, a);
|
|
69
|
+
}
|
|
46
70
|
|
|
47
|
-
/** A freeze holder asked to stop ambient animation too (freeze(owner, { ambient: true })); only read while frozen */
|
|
48
71
|
// The first frame drawn after ready ends the first-frame measure (engine.startup.firstFrameMs, startup.js); one compare per frame after that
|
|
49
72
|
function firstFrame(e, at) {
|
|
50
73
|
const s = e.startup;
|
|
51
74
|
e._readyAt = null;
|
|
52
75
|
if (s) { s.phases.draw = Math.round(at - (s.phases.script + s.phases.construct + s.phases.setup + s.phases.init + s.phases.preload + s.phases.world + s.phases.compile)); s.firstFrameMs = Math.round(at); }
|
|
53
76
|
}
|
|
54
|
-
function ambientHeld(e) { for (const h of e.stacks.get('freeze').entries()) if (h.value?.ambient) return true; return false; }
|
|
55
77
|
|
|
56
78
|
export const loopMethods = {
|
|
57
79
|
_fixedStep() {
|
|
58
80
|
// No game time while start() loads (engine.phase): loading takes as long as the machine needs, so a step during it would make the opening
|
|
59
|
-
// tick
|
|
81
|
+
// tick and clock depend on machine speed (review 0.4 core B1). step() during loading (headless scenario settling) still runs frame
|
|
60
82
|
// hooks. An engine never started ('constructed': no loop, nothing loading) steps by hand only, for tests and tools that need no world
|
|
61
|
-
if (this.
|
|
83
|
+
if (this._inStart) return;
|
|
62
84
|
// input snapshot for this step: keys read in fixed depend only on the step count, not on how many steps a frame ran
|
|
63
85
|
this.input.beginFixed();
|
|
64
86
|
try {
|
|
65
87
|
// gameplay frozen: no clock moves, no channel, no mod({ for }) timer (frame hooks and render continue). uTime is the ambient clock (wind, water,
|
|
66
88
|
// clouds): it keeps moving behind a pause menu, the common expectation, unless a freezer asked freeze(owner, { ambient: true })
|
|
67
|
-
if (this.frozen) { this.time._frozenStep(!
|
|
68
|
-
this.time._beginStep(); // the one counter (core/time.js): this step's commits, ops and input records carry the new tick
|
|
89
|
+
if (this.frozen) { this.time._frozenStep(!this.still); return; }
|
|
90
|
+
this.time._beginStep(); // the one counter (core/time/time.js): this step's commits, ops and input records carry the new tick
|
|
69
91
|
this._inFixed = true; // ops log phase 'fixed' and the dev guard lets gameplay writes through
|
|
70
92
|
// due background results first, so this step's gameplay sees them; an engine stepped by hand before start() applies none (start() rebases them)
|
|
71
|
-
if (this.ready)
|
|
72
|
-
|
|
93
|
+
if (this.ready) this.commits.tick(this.time.tick);
|
|
94
|
+
runList(this, '_fixed', STRINGS.onFixed, STEP);
|
|
73
95
|
this._runHooks('fixed', STEP);
|
|
74
|
-
|
|
96
|
+
runList(this, '_fixedLate', STRINGS.onFixed, STEP); // onFixed({ phase: 'late' }): reads this step's result
|
|
75
97
|
safe(this, STRINGS.clock, this.time._endStep, null, this.time); // ambient, channel and calendar seconds; timed mods end; timers fire
|
|
76
98
|
} finally { this._inFixed = false; this.input.endFixed(); }
|
|
77
99
|
},
|
|
78
|
-
/** Per frame: onFrame callbacks, module frame, stream, jobs. With deterministic true (step, headless loading) jobs ignore real time. */
|
|
100
|
+
/** @internal The loop and the dev tools. Per frame: onFrame callbacks, module frame, stream, jobs. With deterministic true (step, headless loading) jobs ignore real time. */
|
|
79
101
|
_frameHooks(dt, deterministic = false) {
|
|
102
|
+
if (this.disposed) return; // a fixed step of this frame disposed the engine (step() checks the same)
|
|
80
103
|
// one profile frame = one frame-hook cycle (the real loop: one per rendered frame; step(): one per frameEvery fixed steps). Counting rendered frames
|
|
81
104
|
// instead made step(render: false) divide by zero frames and report the whole run's milliseconds as one frame's
|
|
82
105
|
if (this._prof) this._prof.frames++;
|
|
83
106
|
this._picture?.frameStart();
|
|
84
|
-
advanceUiClock(this, dt); // headless pages: UI display timers run on the stepped time (core/uiClock.js)
|
|
107
|
+
advanceUiClock(this, dt); // headless pages: UI display timers run on the stepped time (core/time/uiClock.js)
|
|
85
108
|
writeDaylight(this); // before the hooks: an onFrame reads this frame's signal
|
|
86
|
-
|
|
109
|
+
runList(this, '_frame', STRINGS.onFrame, dt);
|
|
110
|
+
// after every onFrame, whoever registered first: an anim.sync / go / set made this frame shows this frame. Before the module frame hooks, which read the pose
|
|
111
|
+
runList(this, '_animate', STRINGS.animate, dt);
|
|
87
112
|
this._runHooks('frame', dt);
|
|
88
113
|
safe(this, 'stream.update', this.stream._update, SOFT, this.stream);
|
|
89
114
|
this.jobs.run({ deterministic });
|
|
@@ -91,7 +116,8 @@ export const loopMethods = {
|
|
|
91
116
|
safe(this, 'batching.update', this.batching.update, SOFT, this.batching); // last before rendering: picks up everything built this frame
|
|
92
117
|
safe(this, 'audio.tick', this.audio._tick, SOFT, this.audio); // positional sounds follow their objects (returns at once when there are none)
|
|
93
118
|
},
|
|
94
|
-
/** @
|
|
119
|
+
/** @internal The loop and the dev tools: one whole engine frame (onRender hooks, own-frame yielding, per-frame bookkeeping). engine.renderOnce stays the public draw: photo mode needs its picture even from a game that owns the frame, and a game may call it inside a hook.
|
|
120
|
+
* @param {number} dt @param {boolean} [hooks] false: draw without the game's onRender hooks (the picture check's probe renders: picture code
|
|
95
121
|
* run there wrote back the light it had just turned off) */
|
|
96
122
|
_render(dt, hooks = true) {
|
|
97
123
|
const r = this.renderer;
|
|
@@ -108,26 +134,32 @@ export const loopMethods = {
|
|
|
108
134
|
// the game drew the canvas itself since the last engine frame (own composer / render loop): it holds the frame, the engine yields (render/ownFrame.js)
|
|
109
135
|
const draws = engineDraws(this), own = this._ownFrame;
|
|
110
136
|
if (own) own.inside++;
|
|
137
|
+
this._poses.draw(); // moving things draw between the last two fixed steps (stepPoses.js); undone below, gameplay never sees it
|
|
111
138
|
try {
|
|
112
|
-
for (const f of before) { safe(this, STRINGS.onRender,
|
|
113
|
-
this.shadows._frame(); // a game light's cascades, after 'before': picture code aims its light there, and the placement must be what is drawn (
|
|
139
|
+
for (const f of before) { safe(this, STRINGS.onRender, drawHook, null, undefined, f, ctx); r.setRenderTarget(null); }
|
|
140
|
+
this.shadows._frame(); // a game light's cascades, after 'before': picture code aims its light there, and the placement must be what is drawn (render/shadows.js)
|
|
114
141
|
this._checkBackendAdds(); // WebGPU route: a WebGL-only material added since the last frame is named, not drawn blank (startup.js)
|
|
115
142
|
freshFrame(r); // WebGPU: step() several times in one task, or a renderOnce() earlier in this tick, must not reuse that scene pass
|
|
116
143
|
if (this._picture) this._picture.drawing = true;
|
|
117
|
-
if (draws) this.post.render(dt);
|
|
144
|
+
if (draws) { this.batching.skip(); try { this.post.render(dt); } finally { this.batching.unskip(); } }
|
|
118
145
|
if (this._picture) this._picture.drawing = false;
|
|
119
|
-
for (const f of after) safe(this, STRINGS.onRender,
|
|
120
|
-
} finally { if (own) own.inside--; this._picture?.frameEnd(); }
|
|
146
|
+
for (const f of after) safe(this, STRINGS.onRender, drawHook, null, undefined, f, ctx);
|
|
147
|
+
} finally { this._poses.undraw(); if (own) own.inside--; this._picture?.frameEnd(); }
|
|
121
148
|
gpu?.end();
|
|
122
149
|
// frames that first draw new objects pay their GPU upload here (Budget.js ApplyCost); a frame that compiled shaders is not judged by adaptive resolution
|
|
123
150
|
this._compiled = this.budget.cost.rendered(performance.now() - t0, programCount(r) ?? -1, t0 / 1000); // measure
|
|
124
|
-
if (DEV && this.ready && !this._probing)
|
|
151
|
+
if (DEV && this.ready && !this._probing) {
|
|
152
|
+
watchLights(this); // dev: a light added / removed mid-play compiled new shaders (one long frame): say so (lightWatch.js)
|
|
153
|
+
watchGeometries(this, dt); // dev: geometries piling up that nothing in the scene uses (geometryWatch.js)
|
|
154
|
+
}
|
|
155
|
+
this._records?.step(dt); // WebGPU: free the records of meshes that left the scene, a slice per frame (render/recordSweep.js)
|
|
125
156
|
},
|
|
126
157
|
_runHooks(kind, dt) {
|
|
127
158
|
const p = this._prof;
|
|
128
|
-
const was = this._curModule;
|
|
129
|
-
for (const h of
|
|
130
|
-
|
|
159
|
+
const was = this._curModule, list = this._hooks[kind];
|
|
160
|
+
for (const h of list) {
|
|
161
|
+
if (this._hooks[kind] !== list && !this._hooks[kind].includes(h)) continue; // its module went earlier in this pass (unuse, disabled): no hook after its dispose
|
|
162
|
+
const key = h.key ??= fmt(STRINGS.hook, { name: h.name, kind }); // build the key once
|
|
131
163
|
const opts = h.opts ??= { module: h.mod };
|
|
132
164
|
this._curModule = h.mod; // the module type checks (moduleTypes.js) know whose hook is writing
|
|
133
165
|
if (!p) { safe(this, key, h.fn, opts, undefined, dt, this); continue; }
|
|
@@ -148,7 +180,7 @@ export const loopMethods = {
|
|
|
148
180
|
return r;
|
|
149
181
|
},
|
|
150
182
|
|
|
151
|
-
// ---------- nextFixed (
|
|
183
|
+
// ---------- nextFixed (halt / freeze / runState live in holds.js; step() below is the deterministic way to advance) ----------
|
|
152
184
|
/**
|
|
153
185
|
* Run fn at the start of the next fixed step (before that step's fixed hooks), from any callback (UI click, promise, worker result): gameplay state is safe to write there.
|
|
154
186
|
* Returns a Promise of fn's value (rejects if fn throws). Waits while frozen or loading. Built on engine.commits: applies in request order and survives save loads.
|
|
@@ -173,13 +205,15 @@ export const loopMethods = {
|
|
|
173
205
|
let acc = Math.min((this._acc || 0) + dt, MAX_CATCHUP), n = 0;
|
|
174
206
|
const f0 = performance.now(); // measure
|
|
175
207
|
let s0 = f0;
|
|
176
|
-
while (acc >= STEP) {
|
|
208
|
+
while (acc >= STEP && !this.disposed) { // a hook may dispose the engine
|
|
177
209
|
this._fixedStep(); acc -= STEP; n++;
|
|
178
210
|
const t = performance.now(); // measure
|
|
179
211
|
if (acc >= STEP && t - f0 + (t - s0) > CATCHUP_MS) { acc %= STEP; break; } // the next one would go over: drop the rest
|
|
180
212
|
s0 = t;
|
|
181
213
|
}
|
|
182
214
|
this._acc = acc;
|
|
215
|
+
// held while frozen: with no fixed steps positions stand still, and a moving ratio would make interpolated things shake in place
|
|
216
|
+
if (!this.frozen) this.stepBlend = acc / STEP;
|
|
183
217
|
return n;
|
|
184
218
|
},
|
|
185
219
|
|
|
@@ -191,14 +225,14 @@ export const loopMethods = {
|
|
|
191
225
|
const tick = now => {
|
|
192
226
|
if (this.disposed) return;
|
|
193
227
|
this._raf = requestAnimationFrame(tick);
|
|
194
|
-
const dt = Math.min(0.25, (now - last) / 1000); last = now;
|
|
195
|
-
if (this.
|
|
228
|
+
const dt = Math.min(0.25, Math.max(0, now - last) / 1000); last = now; // max: the first frame's timestamp can be older than the performance.now() above
|
|
229
|
+
if (this.halted) { this._acc = 0; return; } // halted: no advance, no render
|
|
196
230
|
// Adaptive resolution judges the frames up to the last one (cpuMs, GPU time and _compiled still describe it) and changes the
|
|
197
231
|
// render scale here, before this frame draws. Why not after the render: a canvas resize clears its drawing buffer, so a change made
|
|
198
232
|
// after the draw handed the compositor a blank frame (R2: a screenshot caught the 1 -> 0.9 frame black). Not counted in cpuMs
|
|
199
233
|
this._adapt(dt);
|
|
200
234
|
this._compiled = false;
|
|
201
|
-
// CPU time of one frame = main-thread work from here to the end of the afterRender hooks, in four phases (engine.
|
|
235
|
+
// CPU time of one frame = main-thread work from here to the end of the afterRender hooks, in four phases (engine._cpuPhases):
|
|
202
236
|
// fixed (input poll + fixed steps), frame (onFrame + module frame hooks + stream / jobs / batching), render (submitting the draw
|
|
203
237
|
// calls: three.js CPU work, upload of new objects, shader compiles; not GPU time), afterRender (module hooks). Adaptive resolution
|
|
204
238
|
// (before, above) and the startup readiness check (after) are not counted. Budget is sampled last so it sees this frame, not the previous one.
|
|
@@ -206,8 +240,8 @@ export const loopMethods = {
|
|
|
206
240
|
let c1, c2, c3;
|
|
207
241
|
try {
|
|
208
242
|
this.input.poll(dt);
|
|
209
|
-
//
|
|
210
|
-
if (this.page.
|
|
243
|
+
// coming back from a hidden tab drops the time spent away, so play resumes without a burst of steps (page.js)
|
|
244
|
+
if (this.page.consumeResync()) this._acc = 0;
|
|
211
245
|
else this._catchUp(dt);
|
|
212
246
|
c1 = performance.now(); // measure
|
|
213
247
|
this._frameHooks(dt);
|
|
@@ -219,9 +253,9 @@ export const loopMethods = {
|
|
|
219
253
|
if (this._readyAt != null && this.ready) firstFrame(this, c3);
|
|
220
254
|
} finally { this.input.endFrame(); }
|
|
221
255
|
this._runHooks('afterRender', dt);
|
|
222
|
-
const c4 = performance.now(), P = this.
|
|
256
|
+
const c4 = performance.now(), P = this._cpuPhases; // measure
|
|
223
257
|
P.fixed = c1 - c0; P.frame = c2 - c1; P.render = c3 - c2; P.afterRender = c4 - c3;
|
|
224
|
-
this.
|
|
258
|
+
this._cpuMs = c4 - c0;
|
|
225
259
|
this.budget.sample(dt);
|
|
226
260
|
this.fps += (1 / Math.max(dt, 1e-3) - this.fps) * 0.05;
|
|
227
261
|
this._afterTick?.();
|
|
@@ -230,7 +264,7 @@ export const loopMethods = {
|
|
|
230
264
|
},
|
|
231
265
|
|
|
232
266
|
/**
|
|
233
|
-
* Advance synchronously by seconds of real (fixed-step) time; channels and the calendar advance by their own scales (core/time.js): fixed hooks run at 60 Hz;
|
|
267
|
+
* Advance synchronously by seconds of real (fixed-step) time; channels and the calendar advance by their own scales (core/time/time.js): fixed hooks run at 60 Hz;
|
|
234
268
|
* frame hooks run once per frameEvery fixed steps (default 2, i.e. 30 Hz, dt = 1/30),
|
|
235
269
|
* so fast-forwarding 600 seconds runs only 18000 frame-hook calls with no rendering and finishes in seconds. Renders one frame at the end when
|
|
236
270
|
* render is true.
|
|
@@ -241,24 +275,27 @@ export const loopMethods = {
|
|
|
241
275
|
* cutscene across several step calls.
|
|
242
276
|
* seconds must be a finite number >= 0: step(0) advances nothing (no fixed step, no render), a negative or non-finite value throws; any positive
|
|
243
277
|
* value runs at least one fixed step. While start() is still loading it runs frame hooks only (no game time passes until engine.phase is
|
|
244
|
-
* 'ready').
|
|
278
|
+
* 'ready'); in dev that, and a step during a session change nobody awaited, warns once.
|
|
245
279
|
* Returns the result of describe() (null with { describe: false }, which callers that ignore it pass to skip the work).
|
|
246
280
|
*/
|
|
247
281
|
step(seconds, { render = true, frameEvery = 2, describe = true } = {}) {
|
|
248
282
|
if (this.disposed) return null; // nothing advances after dispose
|
|
249
283
|
if (typeof seconds !== 'number' || !Number.isFinite(seconds) || seconds < 0)
|
|
250
284
|
throw codedError('step-seconds',
|
|
251
|
-
`engine.step(${String(seconds)}): seconds must be a finite number >= 0, e.g. engine.step(0.5) (
|
|
285
|
+
`engine.step(${String(seconds)}): seconds must be a finite number >= 0, e.g. engine.step(0.5) (real seconds; 1 / 60 is one fixed step)`);
|
|
252
286
|
if (seconds === 0) return describe ? this.describe() : null; // 0 advances nothing (a tiny positive value still runs one fixed step)
|
|
287
|
+
if (DEV && (this._inStart || this.session._busy)) warnOnce(coded('step-during-load', this._inStart ? STRINGS.stepStart : STRINGS.stepSession), 'step-during-load');
|
|
253
288
|
const n = Math.max(1, Math.round(seconds / STEP));
|
|
289
|
+
this.stepBlend = 1; // step() takes the state to the end of each step, so the latest state is what cameras read and what gets drawn
|
|
254
290
|
let since = 0;
|
|
255
|
-
for (let i = 0; i < n; i++) {
|
|
291
|
+
for (let i = 0; i < n && !this.disposed; i++) { // a hook may dispose the engine
|
|
256
292
|
this._fixedStep();
|
|
257
293
|
if (++since >= frameEvery || i === n - 1) {
|
|
258
294
|
try { this._frameHooks(since * STEP, true); } finally { this.input.endFrame(); }
|
|
259
295
|
since = 0;
|
|
260
296
|
}
|
|
261
297
|
}
|
|
298
|
+
if (this.disposed) return null;
|
|
262
299
|
if (render) {
|
|
263
300
|
safe(this, STRINGS.render, this._render, SOFT, this, STEP);
|
|
264
301
|
this._runHooks('afterRender', STEP);
|
|
@@ -266,6 +303,8 @@ export const loopMethods = {
|
|
|
266
303
|
return describe ? this.describe() : null; // describe: false for internal loops that ignore the result (describe() walks every module)
|
|
267
304
|
},
|
|
268
305
|
|
|
269
|
-
// Adaptive resolution (core/adaptive.js): judged on frame cost; tests drive it with explicit cost / compiled values
|
|
270
|
-
_adapt(dt, cost = Math.max(this.
|
|
306
|
+
// Adaptive resolution (core/scene/adaptive.js): judged on frame cost; tests drive it with explicit cost / compiled values
|
|
307
|
+
_adapt(dt, cost = Math.max(this._cpuMs, this._gpu?.ms ?? 0), compiled = !!this._compiled, gpuKnown = this._gpu?.ms != null) { adapt(this, dt, cost, compiled, gpuKnown); },
|
|
271
308
|
};
|
|
309
|
+
|
|
310
|
+
export const handRolled = [{ kind: 'loop', seen: 'a requestAnimationFrame game loop of its own', use: 'engine.onFrame(dt => ...) for what is seen, engine.onFixed(dt => ...) for rules: pause, step, tests and saves follow them', code: /\brequestAnimationFrame\s*\(\s*[\w.]+\s*\)|\.setAnimationLoop\s*\(/ }];
|