threedog 0.2.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +371 -1
- package/README.md +21 -12
- package/core/Animator.js +15 -12
- package/core/Assets.js +92 -26
- package/core/Audio.js +45 -38
- package/core/Baked.js +30 -15
- package/core/Batching.js +102 -15
- package/core/Budget.js +40 -19
- package/core/Clock.js +40 -80
- package/core/DebugOverrides.js +75 -25
- package/core/Describe.js +105 -45
- package/core/Engine.js +203 -75
- package/core/Events.js +4 -1
- package/core/I18n.js +25 -13
- package/core/Input.js +175 -80
- package/core/Inspect.js +8 -5
- package/core/InspectMaterials.js +84 -0
- package/core/InspectPerf.js +68 -0
- package/core/InspectScene.js +13 -2
- package/core/Loading.js +2 -1
- package/core/MaterialInfo.js +7 -5
- package/core/Ops.js +50 -9
- package/core/Random.js +9 -2
- package/core/Rays.js +12 -7
- package/core/SaveStore.js +41 -9
- package/core/Saves.js +71 -15
- package/core/Stream.js +13 -10
- package/core/Threads.js +26 -7
- package/core/UrlState.js +69 -13
- package/core/Views.js +10 -6
- package/core/actor.js +1 -1
- package/core/adaptive.js +93 -0
- package/core/assetEntry.js +27 -7
- package/core/assetHot.js +176 -0
- package/core/assetLoad.js +44 -19
- package/core/assetManifest.js +53 -11
- package/core/assetReport.js +5 -5
- package/core/audioRules.js +13 -11
- package/core/audioVoice.js +69 -42
- package/core/batchGroups.js +9 -1
- package/core/canvasBox.js +1 -2
- package/core/catalog.js +21 -5
- package/core/cells.js +62 -0
- package/core/checks.js +10 -8
- package/core/chunkStream.js +87 -0
- package/core/control.js +149 -0
- package/core/copies.js +32 -0
- package/core/dayTime.js +12 -6
- package/core/debugView.js +85 -18
- package/core/describeRender.js +117 -21
- package/core/describeText.js +41 -21
- package/core/engineCamera.js +32 -0
- package/core/errorCodes.js +478 -32
- package/core/errorHints.js +41 -142
- package/core/errors.js +31 -8
- package/core/events.generated.js +13 -7
- package/core/gameLights.js +69 -0
- package/core/grayMap.js +20 -0
- package/core/grid.js +14 -13
- package/core/gridLoad.js +2 -1
- package/core/ground.js +6 -4
- package/core/headlessLoad.js +55 -0
- package/core/holds.js +78 -50
- package/core/inputContext.js +11 -7
- package/core/inputDefaults.js +24 -21
- package/core/inputPad.js +1 -1
- package/core/inputPointer.js +1 -1
- package/core/inputTouch.js +2 -2
- package/core/lifecycle.js +46 -12
- package/core/lightWatch.js +9 -5
- package/core/loop.js +109 -43
- package/core/math.js +18 -3
- package/core/moduleSlots.js +100 -0
- package/core/moduleTypes.js +86 -0
- package/core/modules.js +147 -29
- package/core/movement.js +2 -2
- package/core/namedModel.js +74 -0
- package/core/opsCheck.js +3 -3
- package/core/opsFail.js +15 -6
- package/core/opsGuard.js +4 -4
- package/core/opsRun.js +4 -3
- package/core/owned.js +171 -0
- package/core/page.js +44 -10
- package/core/params.js +30 -8
- package/core/pictureSlots.js +33 -0
- package/core/pictureWriters.js +343 -0
- package/core/plugins.js +245 -0
- package/core/saveApply.js +99 -17
- package/core/saveFiles.js +8 -6
- package/core/saveValues.js +46 -0
- package/core/saveVersions.js +20 -3
- package/core/scatter.js +48 -19
- package/core/sceneDelta.js +211 -0
- package/core/sceneMethods.js +31 -33
- package/core/screenToGround.js +1 -1
- package/core/services.js +27 -11
- package/core/session.js +28 -25
- package/core/shaderCost.js +78 -0
- package/core/shadowTypes.js +3 -2
- package/core/shadows.js +405 -0
- package/core/sharedPoint.js +303 -0
- package/core/skip.js +36 -28
- package/core/stackFrames.js +45 -0
- package/core/stacks.js +166 -0
- package/core/startup.js +153 -13
- package/core/streamSources.js +0 -11
- package/core/targeting.js +1 -1
- package/core/textureBytes.js +20 -0
- package/core/thingExplain.js +3 -3
- package/core/thingOps.js +29 -6
- package/core/things.js +22 -12
- package/core/threadPure.js +7 -3
- package/core/threePatches.js +47 -0
- package/core/tier.js +21 -10
- package/core/time.js +236 -0
- package/core/uiClock.js +25 -0
- package/core/util.js +8 -2
- package/core/validate.js +66 -87
- package/core/view.js +43 -0
- package/core/wrap.js +106 -0
- package/docs/AI.md +95 -104
- package/docs/API.md +35 -31
- package/docs/CODEMAP.md +231 -176
- package/docs/COMMANDS.md +63 -39
- package/docs/CONVENTIONS.md +99 -31
- package/docs/MIGRATING-0.3.md +248 -0
- package/docs/MIGRATING-0.4.md +320 -0
- package/docs/MIGRATING-0.5.md +68 -0
- package/docs/MIGRATING-0.6.md +126 -0
- package/docs/MIGRATING-0.7.md +39 -0
- package/docs/PERF.md +35 -7
- package/docs/THREE.md +82 -28
- package/docs/api/ambience.md +0 -1
- package/docs/api/assets.md +15 -11
- package/docs/api/audio.md +10 -14
- package/docs/api/budget.md +4 -0
- package/docs/api/calendar.md +41 -0
- package/docs/api/cameraRig.md +16 -5
- package/docs/api/characters.md +41 -24
- package/docs/api/clock.md +6 -5
- package/docs/api/collision.md +10 -7
- package/docs/api/content.md +6 -4
- package/docs/api/dialogue.md +9 -9
- package/docs/api/engine.md +95 -65
- package/docs/api/events.md +20 -14
- package/docs/api/grids.md +10 -3
- package/docs/api/ground.md +1 -1
- package/docs/api/hud.md +5 -2
- package/docs/api/i18n.md +1 -1
- package/docs/api/input.md +13 -7
- package/docs/api/interactions.md +10 -6
- package/docs/api/inventory.md +17 -17
- package/docs/api/level.md +0 -2
- package/docs/api/lightPool.md +3 -1
- package/docs/api/music.md +1 -1
- package/docs/api/nav.md +3 -0
- package/docs/api/occlusion.md +5 -0
- package/docs/api/openWorld.md +2 -1
- package/docs/api/particles.md +6 -3
- package/docs/api/photo.md +0 -2
- package/docs/api/pickups.md +21 -0
- package/docs/api/post.md +8 -5
- package/docs/api/quests.md +2 -3
- package/docs/api/rigid.md +16 -14
- package/docs/api/saves.md +6 -4
- package/docs/api/settings.md +2 -3
- package/docs/api/sky.md +18 -49
- package/docs/api/stream.md +1 -1
- package/docs/api/terrain.md +16 -7
- package/docs/api/terrainDraw.md +12 -0
- package/docs/api/timeline.md +3 -4
- package/docs/api/tools.md +32 -15
- package/docs/api/triggers.md +7 -10
- package/docs/api/vegetation.md +17 -9
- package/docs/api/vegetationDraw.md +10 -0
- package/docs/api/water.md +9 -21
- package/docs/api/weather.md +10 -15
- package/docs/api/weatherDraw.md +10 -0
- package/docs/api/world.md +3 -2
- package/docs/recipes/01-new-game.md +52 -42
- package/docs/recipes/02-npc.md +24 -7
- package/docs/recipes/03-items-pickups.md +57 -22
- package/docs/recipes/04-quests.md +12 -5
- package/docs/recipes/05-props-bake.md +174 -22
- package/docs/recipes/06-clock-events.md +100 -52
- package/docs/recipes/07-flow-scenes-pause.md +50 -10
- package/docs/recipes/08-weather-sky.md +134 -37
- package/docs/recipes/09-materials-lights-models.md +185 -0
- package/docs/recipes/10-blender-level.md +16 -4
- package/docs/recipes/11-vehicles.md +67 -10
- package/docs/recipes/13-animation.md +23 -9
- package/docs/recipes/14-custom-module.md +63 -29
- package/docs/recipes/15-perf.md +31 -10
- package/docs/recipes/16-dev-bridge.md +74 -40
- package/docs/recipes/18-world.md +26 -14
- package/docs/recipes/19-shooting-picking.md +12 -10
- package/docs/recipes/20-content-actions-save.md +60 -18
- package/docs/recipes/21-camera.md +55 -17
- package/docs/recipes/22-shop-gold.md +3 -3
- package/docs/recipes/23-ops.md +17 -11
- package/docs/recipes/26-ui-parts.md +86 -13
- package/docs/recipes/27-net.md +11 -5
- package/docs/recipes/28-terrain.md +36 -3
- package/docs/recipes/29-grid.md +46 -19
- package/docs/recipes/30-templates.md +72 -15
- package/docs/recipes/31-audio.md +20 -12
- package/docs/recipes/32-action-game.md +51 -4
- package/docs/recipes/34-environment-lighting.md +108 -21
- package/docs/recipes/35-picture-from-reference.md +147 -0
- package/docs/recipes/36-sky-ground-plants.md +158 -0
- package/docs/recipes/{37-terrain-look-hooks.md → 37-terrain-hooks.md} +9 -12
- package/docs/recipes/38-environment-hooks.md +67 -0
- package/docs/recipes/40-scene.md +114 -32
- package/docs/recipes/42-terrain-shape.md +2 -2
- package/docs/recipes/43-shader-patches-surfaces.md +206 -0
- package/docs/recipes/44-water-weather-hooks.md +191 -0
- package/docs/recipes/45-cascaded-shadows.md +130 -23
- package/docs/recipes/46-blender-art-route.md +17 -20
- package/docs/recipes/47-island-snow-backdrop.md +13 -15
- package/docs/recipes/49-game-module-contract.md +30 -17
- package/docs/recipes/50-own-renderer.md +4 -4
- package/docs/recipes/51-capability-catalog.md +3 -3
- package/docs/recipes/52-around-the-picture.md +181 -0
- package/docs/recipes/53-ground-up-close.md +12 -12
- package/docs/recipes/54-three-idioms.md +88 -0
- package/docs/recipes/55-mods-time-wrap.md +124 -0
- package/docs/recipes/56-webgpu-tsl.md +303 -0
- package/docs/recipes/57-control.md +104 -0
- package/docs/recipes/58-input.md +60 -0
- package/docs/recipes/59-depth-post-effects.md +83 -0
- package/docs/recipes/60-judge-the-picture.md +70 -0
- package/docs/recipes/61-deploy.md +27 -0
- package/docs/recipes/62-picture-code.md +244 -0
- package/docs/recipes/63-third-person-start.md +77 -0
- package/docs/recipes/64-particles.md +35 -0
- package/examples/action/.threedog/content-index.json +1 -0
- package/examples/action/GAMEMAP.md +20 -14
- package/examples/action/assets.js +8 -0
- package/examples/action/content/actions.js +1 -1
- package/examples/action/content/audio.js +5 -5
- package/examples/action/main.js +12 -15
- package/examples/action/models.js +23 -24
- package/examples/action/picture/index.js +13 -0
- package/examples/action/picture/lights.js +35 -0
- package/examples/action/picture/materials.js +8 -0
- package/examples/action/picture/palette.js +33 -0
- package/examples/plain-picture/.threedog/content-index.json +1 -0
- package/examples/plain-picture/FINDINGS.md +53 -0
- package/examples/plain-picture/GAMEMAP.md +90 -0
- package/examples/plain-picture/main.js +48 -0
- package/examples/plain-picture/picture/index.js +21 -0
- package/examples/plain-picture/picture/lights.js +54 -0
- package/examples/plain-picture/picture/materials.js +24 -0
- package/examples/plain-picture/picture/palette.js +16 -0
- package/examples/plain-picture/picture/sky.js +37 -0
- package/examples/pullable.json +133 -0
- package/examples/rc2d/.threedog/content-index.json +1 -0
- package/examples/rc2d/GAMEMAP.md +88 -0
- package/examples/rc2d/README.md +57 -0
- package/examples/rc2d/main.js +55 -0
- package/examples/rc2d/picture/index.js +18 -0
- package/examples/rc2d/picture/lights.js +11 -0
- package/examples/rc2d/picture/materials.js +18 -0
- package/examples/rc2d/picture/palette.js +15 -0
- package/examples/rc2d/picture/post.js +11 -0
- package/examples/rc2d/rc2d.js +187 -0
- package/examples/rc2d/shaders.js +144 -0
- package/examples/sheepisland/.threedog/content-index.json +1 -0
- package/examples/sheepisland/GAMEMAP.md +22 -17
- package/examples/sheepisland/assets.js +5 -0
- package/examples/sheepisland/content/templates.js +1 -1
- package/examples/sheepisland/content/vegetation.js +3 -1
- package/examples/sheepisland/main.js +29 -18
- package/examples/sheepisland/{style/models.js → models.js} +13 -24
- package/examples/sheepisland/picture/index.js +20 -0
- package/examples/sheepisland/picture/lights.js +34 -0
- package/examples/sheepisland/picture/materials.js +61 -0
- package/examples/sheepisland/picture/palette.js +60 -0
- package/examples/sheepisland/picture/sky.js +20 -0
- package/examples/sheepisland/views.js +1 -1
- package/examples/styletest/.threedog/content-index.json +1 -0
- package/examples/styletest/GAMEMAP.md +25 -22
- package/examples/styletest/assets.js +6 -0
- package/examples/styletest/content/templates.js +1 -1
- package/examples/styletest/content/vegetation.js +1 -1
- package/examples/styletest/main.js +25 -34
- package/examples/styletest/models.js +30 -30
- package/examples/styletest/params.js +2 -5
- package/examples/styletest/picture/env.js +38 -0
- package/examples/styletest/picture/index.js +16 -0
- package/examples/styletest/picture/lights.js +9 -0
- package/examples/styletest/picture/materials.js +28 -0
- package/examples/styletest/picture/palette.js +22 -0
- package/examples/techniques/contact-shadows/README.md +91 -0
- package/examples/techniques/contact-shadows/contactShadows.js +67 -0
- package/examples/techniques/contact-shadows/main.js +55 -0
- package/examples/techniques/contact-shadows/picture/index.js +14 -0
- package/examples/techniques/contact-shadows/picture/lights.js +34 -0
- package/examples/techniques/contact-shadows/picture/materials.js +12 -0
- package/examples/techniques/contact-shadows/picture/palette.js +17 -0
- package/examples/techniques/day-night-grade/README.md +83 -0
- package/examples/techniques/day-night-grade/main.js +41 -0
- package/examples/techniques/day-night-grade/picture/index.js +20 -0
- package/examples/techniques/day-night-grade/picture/lights.js +45 -0
- package/examples/techniques/day-night-grade/picture/materials.js +15 -0
- package/examples/techniques/day-night-grade/picture/palette.js +59 -0
- package/examples/techniques/day-night-grade/picture/post.js +25 -0
- package/examples/techniques/day-night-grade/picture/sky.js +33 -0
- package/examples/techniques/interior-light/README.md +106 -0
- package/examples/techniques/interior-light/interiorLight.js +47 -0
- package/examples/techniques/interior-light/main.js +87 -0
- package/examples/techniques/interior-light/picture/index.js +24 -0
- package/examples/techniques/interior-light/picture/lights.js +52 -0
- package/examples/techniques/interior-light/picture/materials.js +13 -0
- package/examples/techniques/interior-light/picture/palette.js +32 -0
- package/examples/techniques/interior-light/picture/sky.js +40 -0
- package/examples/techniques/modular-building/README.md +126 -0
- package/examples/techniques/modular-building/kit.js +426 -0
- package/examples/techniques/modular-building/main.js +39 -0
- package/examples/techniques/modular-building/picture/index.js +17 -0
- package/examples/techniques/modular-building/picture/lights.js +26 -0
- package/examples/techniques/modular-building/picture/materials.js +13 -0
- package/examples/techniques/modular-building/picture/palette.js +23 -0
- package/examples/techniques/night-lights/README.md +95 -0
- package/examples/techniques/night-lights/main.js +47 -0
- package/examples/techniques/night-lights/nightLights.js +95 -0
- package/examples/techniques/night-lights/picture/index.js +18 -0
- package/examples/techniques/night-lights/picture/lights.js +44 -0
- package/examples/techniques/night-lights/picture/materials.js +15 -0
- package/examples/techniques/night-lights/picture/palette.js +34 -0
- package/examples/techniques/night-lights/picture/post.js +9 -0
- package/examples/techniques/night-lights/picture/sky.js +36 -0
- package/examples/techniques/outlines-and-rim/README.md +59 -0
- package/examples/techniques/outlines-and-rim/main.js +61 -0
- package/examples/techniques/outlines-and-rim/outlines.js +64 -0
- package/examples/techniques/outlines-and-rim/picture/index.js +16 -0
- package/examples/techniques/outlines-and-rim/picture/lights.js +18 -0
- package/examples/techniques/outlines-and-rim/picture/materials.js +11 -0
- package/examples/techniques/outlines-and-rim/picture/palette.js +16 -0
- package/examples/techniques/outlines-and-rim/picture/post.js +10 -0
- package/examples/techniques/procedural-animation/README.md +79 -0
- package/examples/techniques/procedural-animation/creature.js +44 -0
- package/examples/techniques/procedural-animation/main.js +47 -0
- package/examples/techniques/procedural-animation/picture/index.js +15 -0
- package/examples/techniques/procedural-animation/picture/lights.js +35 -0
- package/examples/techniques/procedural-animation/picture/materials.js +10 -0
- package/examples/techniques/procedural-animation/picture/palette.js +16 -0
- package/examples/techniques/procedural-animation/picture/sky.js +31 -0
- package/examples/techniques/procedural-animation/proceduralAnim.js +118 -0
- package/examples/techniques/procedural-surface/README.md +69 -0
- package/examples/techniques/procedural-surface/main.js +65 -0
- package/examples/techniques/procedural-surface/picture/index.js +14 -0
- package/examples/techniques/procedural-surface/picture/lights.js +18 -0
- package/examples/techniques/procedural-surface/picture/materials.js +34 -0
- package/examples/techniques/procedural-surface/picture/palette.js +15 -0
- package/examples/techniques/procedural-surface/surface.js +120 -0
- package/examples/techniques/stylized-shading/README.md +74 -0
- package/examples/techniques/stylized-shading/main.js +62 -0
- package/examples/techniques/stylized-shading/picture/index.js +14 -0
- package/examples/techniques/stylized-shading/picture/lights.js +23 -0
- package/examples/techniques/stylized-shading/picture/materials.js +18 -0
- package/examples/techniques/stylized-shading/picture/palette.js +19 -0
- package/examples/techniques/stylized-shading/shading.js +131 -0
- package/examples/techniques/sun-and-key-light/README.md +133 -0
- package/examples/techniques/sun-and-key-light/keyLight.js +71 -0
- package/examples/techniques/sun-and-key-light/main.js +51 -0
- package/examples/techniques/sun-and-key-light/picture/index.js +13 -0
- package/examples/techniques/sun-and-key-light/picture/lights.js +33 -0
- package/examples/techniques/sun-and-key-light/picture/materials.js +9 -0
- package/examples/techniques/sun-and-key-light/picture/palette.js +29 -0
- package/examples/techniques/sun-and-key-light/picture/sky.js +16 -0
- package/examples/techniques/three-looks/README.md +21 -0
- package/examples/techniques/three-looks/main.js +58 -0
- package/examples/techniques/three-looks/picture/cartoon.js +23 -0
- package/examples/techniques/three-looks/picture/cinematic.js +27 -0
- package/examples/techniques/three-looks/picture/comic.js +27 -0
- package/examples/techniques/three-looks/picture/index.js +14 -0
- package/examples/techniques/three-looks/picture/sun.js +23 -0
- package/examples/techniques/wet-road/README.md +102 -0
- package/examples/techniques/wet-road/main.js +48 -0
- package/examples/techniques/wet-road/picture/index.js +17 -0
- package/examples/techniques/wet-road/picture/lights.js +57 -0
- package/examples/techniques/wet-road/picture/materials.js +16 -0
- package/examples/techniques/wet-road/picture/palette.js +24 -0
- package/examples/techniques/wet-road/picture/sky.js +46 -0
- package/examples/techniques/wet-road/wetRoad.js +209 -0
- package/examples/webgpu-tsl/.threedog/content-index.json +1 -0
- package/examples/webgpu-tsl/GAMEMAP.md +89 -0
- package/examples/webgpu-tsl/README.md +45 -0
- package/examples/webgpu-tsl/main.js +44 -0
- package/examples/webgpu-tsl/picture/index.js +18 -0
- package/examples/webgpu-tsl/picture/lights.js +25 -0
- package/examples/webgpu-tsl/picture/materials.js +36 -0
- package/examples/webgpu-tsl/picture/palette.js +23 -0
- package/examples/webgpu-tsl/picture/post.js +16 -0
- package/examples/webgpu-tsl/picture/sky.js +30 -0
- package/examples/world/.threedog/content-index.json +1 -0
- package/examples/world/GAMEMAP.md +31 -21
- package/examples/world/art/humanoid.js +38 -0
- package/examples/world/art/index.js +11 -0
- package/examples/world/art/models.js +57 -0
- package/examples/world/art/shapes.js +9 -0
- package/examples/world/assets.js +6 -0
- package/examples/world/content/audio.js +5 -5
- package/examples/world/content/items.js +1 -1
- package/examples/world/content/npcs.js +1 -1
- package/examples/world/content/props.js +1 -1
- package/examples/world/content/rules.js +1 -1
- package/examples/world/content/templates.js +1 -1
- package/examples/world/content/vegetation.js +1 -1
- package/examples/world/main.js +22 -18
- package/examples/world/models.js +17 -7
- package/examples/world/picture/index.js +20 -0
- package/examples/world/picture/lights.js +41 -0
- package/examples/world/picture/materials.js +34 -0
- package/examples/world/picture/palette.js +74 -0
- package/examples/world/picture/post.js +9 -0
- package/examples/world/picture/sky.js +39 -0
- package/index.d.ts +44 -54
- package/index.js +29 -25
- package/llms.txt +24 -15
- package/modules/ambience/Ambience.js +34 -23
- package/modules/calendar/Calendar.js +163 -0
- package/modules/calendar/contract.js +21 -0
- package/modules/calendar/index.js +82 -0
- package/modules/{sky → calendar}/schedule.js +17 -16
- package/modules/calendar/seasons.js +55 -0
- package/modules/camera/FirstPersonCamera.js +6 -15
- package/modules/camera/FixedCamera.js +33 -15
- package/modules/camera/FollowCamera.js +90 -16
- package/modules/camera/RtsCamera.js +18 -17
- package/modules/camera/common.js +73 -20
- package/modules/camera/contract.js +17 -0
- package/modules/camera/projection.js +11 -24
- package/modules/characters/Character.js +188 -48
- package/modules/characters/NPC.js +92 -41
- package/modules/characters/assetModel.js +8 -16
- package/modules/characters/behaviors.js +2 -1
- package/modules/characters/contract.js +13 -0
- package/modules/characters/footsteps.js +1 -1
- package/modules/characters/index.js +112 -49
- package/modules/characters/moveHelpers.js +4 -5
- package/modules/characters/movers/common.js +102 -19
- package/modules/characters/movers/manual.js +23 -0
- package/modules/characters/movers/rapier.js +19 -16
- package/modules/characters/movers/simple.js +14 -11
- package/modules/characters/movers/support.js +186 -0
- package/modules/characters/npcAvoid.js +47 -42
- package/modules/characters/npcSim.js +17 -9
- package/modules/characters/npcView.js +44 -16
- package/modules/characters/pathAsync.js +7 -3
- package/modules/characters/playerStrings.js +4 -3
- package/modules/characters/proceduralRig.js +19 -4
- package/modules/characters/useModel.js +2 -2
- package/modules/characters/vehicle.contract.js +21 -0
- package/modules/characters/walkTo.js +21 -7
- package/modules/collision/Collision.js +69 -27
- package/modules/collision/grid.js +8 -6
- package/modules/content/explain.js +2 -2
- package/modules/content/fields.js +102 -0
- package/modules/content/ids.js +8 -6
- package/modules/content/index.js +104 -27
- package/modules/content/loader.js +45 -33
- package/modules/content/models.js +58 -42
- package/modules/content/packs.js +6 -5
- package/modules/content/parts.js +41 -0
- package/modules/content/props.js +20 -11
- package/modules/content/rules.js +66 -0
- package/modules/content/stages.js +80 -0
- package/modules/content/templates.js +123 -30
- package/modules/debug/DebugPanel.js +24 -17
- package/modules/flow/contract.js +16 -0
- package/modules/flow/index.js +21 -15
- package/modules/gameplay/Container.js +41 -32
- package/modules/gameplay/Containers.js +30 -15
- package/modules/gameplay/Dialogue.js +113 -55
- package/modules/gameplay/Interactions.js +273 -72
- package/modules/gameplay/Inventory.js +72 -76
- package/modules/gameplay/Quests.js +75 -39
- package/modules/gameplay/boxOps.js +3 -3
- package/modules/gameplay/dialogue.contract.js +21 -0
- package/modules/gameplay/dialogueBox.js +4 -2
- package/modules/gameplay/dialogueBubbles.js +116 -0
- package/modules/gameplay/interactionPrompt.js +4 -1
- package/modules/gameplay/interactions.contract.js +16 -0
- package/modules/gameplay/inventory.contract.js +23 -0
- package/modules/gameplay/inventoryOps.js +19 -17
- package/modules/gameplay/pickups.js +306 -85
- package/modules/gameplay/questLog.js +6 -6
- package/modules/gameplay/quests.contract.js +17 -0
- package/modules/grid/Grid.js +92 -50
- package/modules/grid/Layer.js +27 -13
- package/modules/grid/index.js +96 -43
- package/modules/grid/ops.js +20 -18
- package/modules/grid/preview.js +37 -29
- package/modules/grid/strings.js +12 -0
- package/modules/grid/tiles.js +19 -22
- package/modules/hlod/index.js +52 -19
- package/modules/hud/index.js +48 -20
- package/modules/hud/parts.js +28 -13
- package/modules/level/heightfield.js +3 -1
- package/modules/level/index.js +49 -23
- package/modules/level/nodes.js +4 -3
- package/modules/lights/index.js +47 -19
- package/modules/music/Music.js +38 -21
- package/modules/music/rules.js +1 -1
- package/modules/nav/index.js +48 -42
- package/modules/net/Client.js +13 -6
- package/modules/net/Host.js +19 -5
- package/modules/net/Net.js +2 -1
- package/modules/net/index.js +13 -8
- package/modules/net/sync.js +9 -8
- package/modules/net/transports.js +77 -27
- package/modules/particles/Particles.js +58 -28
- package/modules/particles/contract.js +17 -0
- package/modules/particles/effect.js +54 -11
- package/modules/photo/Photo.js +56 -38
- package/modules/rigid/RigidBodies.js +194 -32
- package/modules/rigid/Vehicles.js +18 -15
- package/modules/rigid/sync.js +62 -17
- package/modules/settings/Settings.js +60 -55
- package/modules/settings/apply.js +38 -3
- package/modules/settings/sections.js +5 -3
- package/modules/settings/strings.js +3 -2
- package/modules/settings/view.js +5 -3
- package/modules/sky/Sky.js +132 -205
- package/modules/sky/clouds.js +37 -23
- package/modules/sky/dome.js +100 -0
- package/modules/sky/domeLayers.js +30 -15
- package/modules/sky/environment.js +45 -99
- package/modules/sky/fog.js +9 -139
- package/modules/sky/frame.js +60 -56
- package/modules/sky/season.js +21 -0
- package/modules/sky/shader.js +63 -35
- package/modules/sky/skyModule.js +52 -37
- package/modules/sky/tint.js +59 -0
- package/modules/terrain/ChunkManager.js +194 -110
- package/modules/terrain/chunkJob.js +1 -1
- package/modules/terrain/chunkQueries.js +6 -4
- package/modules/terrain/draw.js +154 -0
- package/modules/terrain/index.js +87 -54
- package/modules/terrain/terrainDefaults.js +2 -2
- package/modules/terrain/terrainEdit.js +18 -20
- package/modules/terrain/terrainGen.js +6 -4
- package/modules/terrain/terrainIsland.js +5 -4
- package/modules/terrain/terrainShape.js +12 -12
- package/modules/terrain/terrainShapeMain.js +8 -7
- package/modules/terrain/terrainTexture.js +21 -19
- package/modules/timeline/Timeline.js +95 -43
- package/modules/timeline/Tween.js +18 -10
- package/modules/timeline/letterbox.js +2 -2
- package/modules/timeline/shots.js +5 -1
- package/modules/triggers/index.js +111 -76
- package/modules/vegetation/Vegetation.js +229 -112
- package/modules/vegetation/densityMap.js +62 -0
- package/modules/vegetation/draw.js +191 -0
- package/modules/vegetation/groundChunks.js +52 -58
- package/modules/vegetation/index.js +32 -11
- package/modules/vegetation/modelGeometry.js +3 -2
- package/modules/vegetation/nearFade.js +8 -2
- package/modules/water/Water.js +157 -72
- package/modules/water/surface.js +86 -47
- package/modules/weather/Weather.js +96 -103
- package/modules/weather/particles.js +37 -14
- package/modules/weather/shaders.js +1 -1
- package/modules/weather/strings.js +2 -2
- package/modules/weather/weatherDraw.js +141 -0
- package/modules/world/World.js +26 -9
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +18 -4
- package/modules/world/persist.js +62 -2
- package/modules/world/pos.js +3 -2
- package/modules/world/records.js +8 -6
- package/modules/world/sim.js +60 -20
- package/modules/world/simFar.js +4 -3
- package/modules/world/state.js +3 -2
- package/modules/world/thingSource.js +1 -1
- package/modules/world/views.js +8 -6
- package/package.json +8 -3
- package/presets.js +43 -29
- package/render/PostFX.js +318 -135
- package/render/backend.js +486 -0
- package/render/cascades.js +195 -0
- package/render/cascades.tsl.js +96 -0
- package/render/daylight.js +39 -0
- package/render/detail.js +122 -41
- package/render/effects.js +155 -48
- package/render/engineUniforms.js +10 -1
- package/render/fuse.js +5 -4
- package/render/fx/cel.tsl.js +42 -0
- package/render/fx/cloudShadow.tsl.js +16 -0
- package/render/fx/detail.tsl.js +66 -0
- package/render/fx/index.js +28 -0
- package/render/fx/lighting.tsl.js +28 -0
- package/render/fx/nodeErrors.tsl.js +68 -0
- package/render/fx/noise.tsl.js +12 -0
- package/render/fx/objectOrigin.tsl.js +42 -0
- package/render/fx/particles.tsl.js +139 -0
- package/render/fx/patchNodes.tsl.js +403 -0
- package/render/fx/postWebGPU.tsl.js +181 -0
- package/render/fx/season.tsl.js +13 -0
- package/render/fx/sky.tsl.js +187 -0
- package/render/fx/uniforms.tsl.js +67 -0
- package/render/fx/water.tsl.js +53 -0
- package/render/fx/wind.tsl.js +22 -0
- package/render/fxNumbers.js +36 -0
- package/render/hotGlsl.js +24 -0
- package/render/layers.js +14 -0
- package/render/lighting.js +71 -18
- package/render/lightmap.js +142 -0
- package/render/lights.js +47 -6
- package/render/materials.js +55 -152
- package/render/modeling.js +73 -0
- package/render/neutral.js +23 -0
- package/render/occlusion.js +184 -0
- package/render/ownFrame.js +76 -0
- package/render/patches.js +317 -35
- package/render/postWebGL.js +205 -0
- package/render/probes.js +288 -0
- package/render/shaderErrors.js +154 -0
- package/render/slots.js +165 -0
- package/render/terms.js +163 -0
- package/render/uniformDecl.js +4 -3
- package/types/common.d.ts +2 -2
- package/types/core.d.ts +757 -346
- package/types/gameplay.d.ts +539 -330
- package/types/generated/core/Audio.d.ts +26 -42
- package/types/generated/core/Batching.d.ts +6 -2
- package/types/generated/core/Budget.d.ts +2 -8
- package/types/generated/core/DebugOverrides.d.ts +58 -9
- package/types/generated/core/I18n.d.ts +2 -2
- package/types/generated/core/Input.d.ts +110 -32
- package/types/generated/core/Ops.d.ts +31 -0
- package/types/generated/core/Random.d.ts +2 -2
- package/types/generated/core/Saves.d.ts +10 -2
- package/types/generated/core/Stream.d.ts +1 -1
- package/types/generated/core/Threads.d.ts +4 -1
- package/types/generated/core/Views.d.ts +0 -1
- package/types/generated/core/audioVoice.d.ts +17 -9
- package/types/generated/core/control.d.ts +55 -0
- package/types/generated/core/page.d.ts +9 -2
- package/types/generated/core/session.d.ts +2 -1
- package/types/generated/modules/ambience/Ambience.d.ts +0 -9
- package/types/generated/modules/calendar/Calendar.d.ts +84 -0
- package/types/generated/modules/calendar/index.d.ts +10 -0
- package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
- package/types/generated/modules/grid/Grid.d.ts +61 -25
- package/types/generated/modules/grid/Layer.d.ts +13 -5
- package/types/generated/modules/grid/index.d.ts +56 -20
- package/types/generated/modules/music/Music.d.ts +5 -3
- package/types/generated/modules/net/index.d.ts +3 -3
- package/types/generated/modules/net/transports.d.ts +12 -3
- package/types/generated/modules/particles/Particles.d.ts +13 -6
- package/types/generated/modules/sky/Sky.d.ts +85 -110
- package/types/generated/modules/sky/skyModule.d.ts +1 -1
- package/types/generated/modules/timeline/Timeline.d.ts +8 -6
- package/types/generated/modules/water/Water.d.ts +50 -3
- package/types/generated/modules/weather/Weather.d.ts +44 -15
- package/types/generated/modules/weather/weatherDraw.d.ts +11 -0
- package/types/generated/modules/world/World.d.ts +20 -5
- package/types/generated/render/PostFX.d.ts +109 -29
- package/types/generated/render/lighting.d.ts +29 -0
- package/types/generated/render/materials.d.ts +31 -50
- package/types/generated/render/modeling.d.ts +30 -0
- package/types/generated/render/occlusion.d.ts +13 -0
- package/types/generated/render/patches.d.ts +16 -2
- package/types/generated/ui/UI.d.ts +6 -3
- package/types/nav.d.ts +6 -0
- package/types/physics.d.ts +140 -45
- package/types/tsl.d.ts +94 -0
- package/types/world.d.ts +489 -122
- package/ui/Focus.js +35 -14
- package/ui/LoadingScreen.js +3 -3
- package/ui/Parts.js +35 -15
- package/ui/UI.js +27 -17
- package/ui/cursor.js +115 -0
- package/ui/defaults.js +15 -11
- package/ui/theme.js +36 -27
- package/ui/touchPart.js +2 -2
- package/core/claims.js +0 -51
- package/core/look/coreParts.js +0 -112
- package/core/look/layers.js +0 -136
- package/core/look/part.js +0 -173
- package/core/look/report.js +0 -79
- package/core/look/write.js +0 -86
- package/core/renamed.js +0 -22
- package/core/styleParts.js +0 -98
- package/docs/api/entities.md +0 -61
- package/docs/api/style.md +0 -134
- package/docs/recipes/09-style-pack.md +0 -169
- package/docs/recipes/35-style-from-reference.md +0 -84
- package/docs/recipes/36-sky-ground-plant-looks.md +0 -118
- package/docs/recipes/38-environment-look-hooks.md +0 -88
- package/docs/recipes/41-thing-registry.md +0 -93
- package/docs/recipes/43-shader-patches-surface-looks.md +0 -135
- package/docs/recipes/44-water-weather-look-hooks.md +0 -135
- package/docs/recipes/48-make-material.md +0 -70
- package/docs/recipes/52-look.md +0 -146
- package/examples/action/look.js +0 -5
- package/examples/sheepisland/style/index.js +0 -79
- package/examples/styletest/look.js +0 -11
- package/examples/styletest/overrides.js +0 -33
- package/examples/styletest/panel.js +0 -135
- package/modules/entities/Entities.js +0 -243
- package/modules/entities/build.js +0 -25
- package/modules/entities/index.js +0 -4
- package/modules/sky/calendar.js +0 -80
- package/modules/sky/cascades.js +0 -125
- package/modules/sky/layers.js +0 -69
- package/modules/sky/look.js +0 -51
- package/modules/sky/lookFog.js +0 -80
- package/modules/sky/lookShadow.js +0 -50
- package/modules/sky/lookSky.js +0 -108
- package/modules/sky/shadow.js +0 -74
- package/modules/terrain/chunkLevels.js +0 -40
- package/modules/terrain/lookGround.js +0 -61
- package/modules/terrain/mountTerrain.js +0 -32
- package/modules/vegetation/lookWind.js +0 -37
- package/modules/water/look.js +0 -80
- package/modules/weather/look.js +0 -75
- package/modules/world/cells.js +0 -42
- package/render/lookSurface.js +0 -161
- package/render/postLook.js +0 -86
- package/render/surface.js +0 -69
- package/types/style.d.ts +0 -643
package/core/catalog.js
CHANGED
|
@@ -5,11 +5,12 @@
|
|
|
5
5
|
// engine.catalog('shop') -> one module expanded: dependencies, ops with args / defaults / failure codes, saved parts, time model
|
|
6
6
|
// engine.catalog('shop.buy') -> one op expanded (args schema, reasons, its last attempt)
|
|
7
7
|
// engine.catalog({ find: 'buy' }) -> the short list filtered by id, label, op or save name
|
|
8
|
+
// engine.catalog('post') -> a capability that is no module (post chain, shadows): its entry names and what it holds now
|
|
8
9
|
// Ownership: engine.use / module init take a snapshot of the op, save and describe names before and after (catalogSnap / catalogClaim);
|
|
9
10
|
// what existed before the first engine.use is 'core', what appeared outside any module is 'game'. An op named '<module>.verb' or a save
|
|
10
11
|
// part keyed by the module name belongs to that module even when registered later (from game code calling into the module).
|
|
11
12
|
import { parseSchema, schemaInfo } from './params.js';
|
|
12
|
-
import {
|
|
13
|
+
import { ENGINE_PARAMS } from './Engine.js';
|
|
13
14
|
|
|
14
15
|
const TIME_HOOKS = ['fixed', 'frame', 'afterRender', 'skip', 'afterLoad'];
|
|
15
16
|
const MAX_API = 200; // the dev bridge narrows this to what the api page lists (tools/threedog/catalog.mjs)
|
|
@@ -121,7 +122,20 @@ function moduleEntry(e, m) {
|
|
|
121
122
|
function looseEntry(e, id) {
|
|
122
123
|
const own = owned(e, id);
|
|
123
124
|
return { id, kind: id, ops: own.op.map(n => opInfo(e, n, false)), saves: own.save.map(k => saveInfo(e, k)),
|
|
124
|
-
queries: { describe: null, extra: own.describe.map(n => `describe().${n}`), api: [] }, problems: []
|
|
125
|
+
queries: { describe: null, extra: own.describe.map(n => `describe().${n}`), api: [] }, problems: [],
|
|
126
|
+
// core params are createEngine() options: same schema, values read from engine._createParams (same shape as module params)
|
|
127
|
+
...(id === 'core' ? { params: paramsOf({ name: 'core', params: ENGINE_PARAMS, options: e._createParams }) } : {}) };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Not modules, but a reader asks for them the same way. Read live from the object, so nothing here can drift
|
|
131
|
+
const CAPABILITIES = {
|
|
132
|
+
post: e => ({ describe: 'describe().render', facts: { antialias: e.post.antialias, ownedByGame: !e.post._own.on,
|
|
133
|
+
effects: e.post._list.map(h => ({ name: h.name, slot: h.slot, order: h.order, enabled: h.enabled, params: Object.fromEntries(Object.entries(h.params).map(([k, v]) => [k, toData(v)])) })) } }),
|
|
134
|
+
shadows: e => ({ describe: 'describe().picture', facts: { enabled: e.shadows.enabled, cascades: !!e.shadows.csm } }),
|
|
135
|
+
};
|
|
136
|
+
function capabilityEntry(e, id) {
|
|
137
|
+
const { describe, facts } = CAPABILITIES[id](e);
|
|
138
|
+
return { id, kind: 'capability', ops: [], saves: [], queries: { describe, extra: [], api: apiNames(e[id]) }, facts, problems: [] };
|
|
125
139
|
}
|
|
126
140
|
|
|
127
141
|
function summary(x) {
|
|
@@ -139,6 +153,7 @@ function summary(x) {
|
|
|
139
153
|
function entries(e) {
|
|
140
154
|
const out = [...e.modules.values()].map(m => moduleEntry(e, m));
|
|
141
155
|
for (const id of ['core', 'game']) { const x = looseEntry(e, id); if (x.ops.length || x.saves.length || x.queries.extra.length) out.push(x); }
|
|
156
|
+
for (const id of Object.keys(CAPABILITIES)) if (e[id] && !e.modules.has(id)) out.push(capabilityEntry(e, id));
|
|
142
157
|
return out;
|
|
143
158
|
}
|
|
144
159
|
|
|
@@ -147,10 +162,11 @@ function entries(e) {
|
|
|
147
162
|
* No argument: a short list (id, state, stage, op and save names, time model, problem count). A module id: that module expanded
|
|
148
163
|
* (requires / optional, params with defaults and the values in use, ops with args schema and failure codes, saved parts and versions,
|
|
149
164
|
* time hooks, describe fields and api names, problems such as "fixed hook but no skip hook"). An op name: that op expanded, with its last attempt.
|
|
165
|
+
* 'post' or 'shadows': that capability's entry names and what it holds now (effects in the chain, cascades on or off).
|
|
150
166
|
* The dev bridge `threedog catalog [id]` prints the same data and adds the doc, recipe and source files.
|
|
151
167
|
* @param {string | { find?: string }} [id]
|
|
152
168
|
* @returns {any}
|
|
153
|
-
* @example engine.catalog(); // [{ id: '
|
|
169
|
+
* @example engine.catalog(); // [{ id: 'calendar', kind: 'module', state: 'running', stage: 'environment', ops: [], saves: ['calendar'], time: 'fixed+skip' }, ...]
|
|
154
170
|
* engine.catalog('shop').ops[0]; // { name: 'shop.buy', args: { n: { type: 'int', optional: true, default: 1 } }, failures: ['soldOut', 'noMoney'] }
|
|
155
171
|
* engine.catalog('shop.buy').last; // { tick: 812, ok: false, code: 'noMoney', ... }
|
|
156
172
|
* engine.catalog({ find: 'throw' }); // only entries whose id, label, op or save mentions "throw"
|
|
@@ -160,10 +176,10 @@ export function catalog(e, id) {
|
|
|
160
176
|
if (e.modules.has(id)) return moduleEntry(e, e.modules.get(id));
|
|
161
177
|
if (e.ops.defs.has(id)) return opInfo(e, id, true);
|
|
162
178
|
if (id === 'core' || id === 'game') return looseEntry(e, id);
|
|
163
|
-
if (id
|
|
179
|
+
if (id in CAPABILITIES && e[id]) return capabilityEntry(e, id);
|
|
164
180
|
return null;
|
|
165
181
|
}
|
|
166
|
-
const list =
|
|
182
|
+
const list = entries(e).map(summary);
|
|
167
183
|
const q = id?.find?.toLowerCase();
|
|
168
184
|
return q ? list.filter(s => [s.id, s.label, ...s.ops, ...s.saves].some(x => x?.toLowerCase().includes(q))) : list;
|
|
169
185
|
}
|
package/core/cells.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// Shared xz grid index.
|
|
2
|
+
// The plane is cut into fixed-size cells and each entry is filed under its cell. World records (32 m cells), fixed-position interactions, NPC avoidance
|
|
3
|
+
// (cells the size of two NPC radii) and trigger zones all use it, so "what is near this point" has one implementation.
|
|
4
|
+
// Cell keys are numbers and cells hold the entries directly: there are hundreds to thousands of moves and neighbor queries per step, and string keys plus id
|
|
5
|
+
// lookups would only add garbage and cost.
|
|
6
|
+
// Two kinds of entry, one kind per index: points ({ id, position: { x, z } }, put / delete / forEach) and boxes covering every cell they touch
|
|
7
|
+
// (cover / uncover / at, for zones larger than a point).
|
|
8
|
+
|
|
9
|
+
const OFF = 2 ** 20, SPAN = 2 ** 21; // ±1 million cells in each direction (±30,000 km at 32 m per cell); keys stay safe integers
|
|
10
|
+
|
|
11
|
+
/** @internal */
|
|
12
|
+
export class Cells {
|
|
13
|
+
/** @param {number} size cell edge length (meters) */
|
|
14
|
+
constructor(size) {
|
|
15
|
+
this.size = size;
|
|
16
|
+
this.map = new Map(); // cell key → Set<entry> (deleted when empty, so walked-through areas leave no empty cells)
|
|
17
|
+
this.of = new Map(); // point: id → cell key; box: entry → [x0, x1, z0, z1] cell span
|
|
18
|
+
}
|
|
19
|
+
key(x, z) { return (Math.floor(x / this.size) + OFF) * SPAN + Math.floor(z / this.size) + OFF; }
|
|
20
|
+
/** Put a point entry into / move it to the cell containing its position; returns true if the cell changed */
|
|
21
|
+
put(rec) {
|
|
22
|
+
const k = this.key(rec.position.x, rec.position.z), old = this.of.get(rec.id);
|
|
23
|
+
if (old === k) return false;
|
|
24
|
+
if (old !== undefined) this.out(old, rec);
|
|
25
|
+
this.in(k, rec); this.of.set(rec.id, k);
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
delete(rec) { const k = this.of.get(rec.id); if (k !== undefined) this.out(k, rec); this.of.delete(rec.id); }
|
|
29
|
+
in(k, rec) { let set = this.map.get(k); if (!set) this.map.set(k, set = new Set()); set.add(rec); }
|
|
30
|
+
out(k, rec) { const set = this.map.get(k); set.delete(rec); if (!set.size) this.map.delete(k); }
|
|
31
|
+
clear() { this.map.clear(); this.of.clear(); }
|
|
32
|
+
/** Call fn(entry, squared distance) for each point entry within radius of c. No allocation, no sorting.
|
|
33
|
+
* When the circle covers more cells than exist (huge radius, even Infinity) scan all cells instead, so it cannot hang */
|
|
34
|
+
forEach(c, radius, fn) {
|
|
35
|
+
const s = this.size, r2 = radius * radius, cx = c.x, cz = c.z;
|
|
36
|
+
const x0 = Math.floor((cx - radius) / s), x1 = Math.floor((cx + radius) / s), z0 = Math.floor((cz - radius) / s), z1 = Math.floor((cz + radius) / s);
|
|
37
|
+
if ((x1 - x0 + 1) * (z1 - z0 + 1) > this.map.size) { for (const set of this.map.values()) visit(set, cx, cz, r2, fn); return; }
|
|
38
|
+
for (let x = x0; x <= x1; x++) for (let z = z0; z <= z1; z++) {
|
|
39
|
+
const set = this.map.get((x + OFF) * SPAN + z + OFF);
|
|
40
|
+
if (set) visit(set, cx, cz, r2, fn);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** File a box entry under every cell its xz bounds touch; false (nothing filed) when that is more than maxCells cells: the caller checks it some other way */
|
|
44
|
+
cover(item, minX, minZ, maxX, maxZ, maxCells = Infinity) {
|
|
45
|
+
const s = this.size, x0 = Math.floor(minX / s), x1 = Math.floor(maxX / s), z0 = Math.floor(minZ / s), z1 = Math.floor(maxZ / s);
|
|
46
|
+
if ((x1 - x0 + 1) * (z1 - z0 + 1) > maxCells) return false;
|
|
47
|
+
this.of.set(item, [x0, x1, z0, z1]);
|
|
48
|
+
for (let x = x0; x <= x1; x++) for (let z = z0; z <= z1; z++) this.in((x + OFF) * SPAN + z + OFF, item);
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
uncover(item) {
|
|
52
|
+
const sp = this.of.get(item); if (!sp) return;
|
|
53
|
+
this.of.delete(item);
|
|
54
|
+
for (let x = sp[0]; x <= sp[1]; x++) for (let z = sp[2]; z <= sp[3]; z++) this.out((x + OFF) * SPAN + z + OFF, item);
|
|
55
|
+
}
|
|
56
|
+
/** Box entries filed under the cell containing (x, z), in the order they were filed; undefined when none */
|
|
57
|
+
at(x, z) { return this.map.get(this.key(x, z)); }
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function visit(set, cx, cz, r2, fn) {
|
|
61
|
+
for (const rec of set) { const dx = rec.position.x - cx, dz = rec.position.z - cz, d2 = dx * dx + dz * dz; if (d2 <= r2) fn(rec, d2); }
|
|
62
|
+
}
|
package/core/checks.js
CHANGED
|
@@ -4,11 +4,12 @@
|
|
|
4
4
|
// await engine.checkSave() // save -> load: same saved state?
|
|
5
5
|
// "State" is what engine.saves.collect() returns (every save part), so a module that keeps state outside its save part is invisible here: that is the point
|
|
6
6
|
// of the check, a skip or a load that loses it shows up as a diff of the part's data.
|
|
7
|
+
import { failure } from './opsFail.js';
|
|
7
8
|
|
|
8
9
|
const MAX_DIFFS = 20;
|
|
9
10
|
|
|
10
11
|
/** Flatten two JSON values into the paths where they differ: [{ path, a, b }] (at most MAX_DIFFS; numbers within 1e-6 are equal) */
|
|
11
|
-
|
|
12
|
+
function diffState(a, b, ignore = []) {
|
|
12
13
|
const out = [];
|
|
13
14
|
const walk = (x, y, path) => {
|
|
14
15
|
if (out.length >= MAX_DIFFS || ignore.some(p => path === p || path.startsWith(p + '.'))) return;
|
|
@@ -33,21 +34,22 @@ export const checkMethods = {
|
|
|
33
34
|
* or a test, not in the middle of a real one. A diff usually means a module that keeps its own time lacks (or has a wrong) skip hook.
|
|
34
35
|
* @param {number} seconds game seconds, > 0
|
|
35
36
|
* @param {{ ignore?: string[] }} [opts] ignore: state paths (or their prefix, e.g. 'random') not to compare
|
|
36
|
-
* Refuses ({ ok: false,
|
|
37
|
-
* @returns {Promise<{ ok: boolean,
|
|
37
|
+
* Refuses (failure: { ok: false, code: 'frozen' | 'rate0', facts, nextActions, diffs }) while gameplay is frozen or paused, or the calendar is stopped.
|
|
38
|
+
* @returns {Promise<{ ok: boolean, code?: string, diffs: { path: string, a: any, b: any }[] }>} a = after skip, b = after stepping
|
|
38
39
|
* @example const r = await engine.checkSkip(600); if (!r.ok) console.log(r.diffs);
|
|
39
40
|
*/
|
|
40
41
|
async checkSkip(seconds, { ignore = [] } = {}) {
|
|
41
|
-
// Refuse where the two paths cannot be the same thing: frozen gameplay does not step, and a stopped
|
|
42
|
-
const refuse = (why, b) => ({
|
|
43
|
-
if (this.frozen) return refuse('frozen', 'unfreeze first (stepping obeys freezes): ' +
|
|
44
|
-
|
|
42
|
+
// Refuse where the two paths cannot be the same thing: frozen gameplay does not step, and a stopped calendar (rate or world speed 0) makes "seconds" mean nothing
|
|
43
|
+
const refuse = (why, b) => Object.assign(failure({ code: why, facts: { fix: b } }), { diffs: [{ path: '(precondition)', a: why, b }] });
|
|
44
|
+
if (this.frozen) return refuse('frozen', 'unfreeze first (stepping obeys freezes): ' + this.stacks.get('freeze').names().join(', '));
|
|
45
|
+
const perFixed = this.clock.speed; // calendar seconds per real second
|
|
46
|
+
if (!(perFixed > 0)) return refuse('rate0', `calendar stopped (engine.clock.rate ${this.clock.rate}, world speed ${this.time.scale('world')}); end the mod that sets it to 0, e.g. engine.mod('clock.rate', { owner: 'game', set: 1 })`);
|
|
45
47
|
this.commits.tick(Infinity); // pending background results land first, so they cannot sit in one path's state and not the other's
|
|
46
48
|
const before = JSON.parse(JSON.stringify(this.saves.collect()));
|
|
47
49
|
await this.skip({ seconds });
|
|
48
50
|
const skipped = snapshot(this);
|
|
49
51
|
if (!(await this.saves.apply(before, 'checkSkip'))) return { ok: false, diffs: [{ path: '(rewind)', a: 'applied', b: 'refused' }] };
|
|
50
|
-
this.step(seconds /
|
|
52
|
+
this.step(seconds / perFixed, { render: false });
|
|
51
53
|
const diffs = diffState(skipped, snapshot(this), ignore);
|
|
52
54
|
return { ok: diffs.length === 0, diffs };
|
|
53
55
|
},
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// Chunk streaming shared by every chunk table (terrain chunks, vegetation on its own ground): which chunks the engine.stream sources need, which
|
|
2
|
+
// are far from all of them, the ring of a chunk and frustum culling. The tables keep only what differs: how a chunk is made (a worker job or
|
|
3
|
+
// main-thread placement), what it holds and who is told.
|
|
4
|
+
//
|
|
5
|
+
// Why one helper: the two tables were near copies, and the copy had drifted (it rebuilt its source list and a key string every frame). Ring,
|
|
6
|
+
// keep distance and queue order must mean the same in both, or trees load a ring later than the ground under them.
|
|
7
|
+
//
|
|
8
|
+
// A table gives: chunks (Map key -> chunk { cx, cz, key, state, sphere, inView }), _want (queued chunks, nearest first), _queue(cx, cz, key)
|
|
9
|
+
// (make + register a queued chunk), _dispose(c) (release a chunk's content). Hooks passed here: show(c, visible), level(c, ring) (near-only
|
|
10
|
+
// detail per ring), count(c, ring) (instances drawn, for stats).
|
|
11
|
+
import * as THREE from 'three';
|
|
12
|
+
|
|
13
|
+
export class ChunkStream {
|
|
14
|
+
/** @param {any} table @param {{ show: Function, level: Function, count: Function, inArea?: Function }} hooks */
|
|
15
|
+
constructor(table, hooks) {
|
|
16
|
+
this.table = table; this.hooks = hooks;
|
|
17
|
+
/** stream sources in chunk units: { cx, cz, R, simple }, reused objects (set by follow) */ this.centers = [];
|
|
18
|
+
this._for = [NaN, NaN]; // view distance and table version the wanted list was last built for
|
|
19
|
+
this.ver = 0; // +1 whenever the table is cleared: the next follow() plans again
|
|
20
|
+
this._frustum = new THREE.Frustum(); this._m = new THREE.Matrix4();
|
|
21
|
+
this._d2 = c => { let m = Infinity; for (const s of this.centers) m = Math.min(m, (c.cx - s.cx) ** 2 + (c.cz - s.cz) ** 2); return m; };
|
|
22
|
+
this._byDist = (a, b) => this._d2(a) - this._d2(b);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Ring of a chunk from the nearest source; a 'simple' source counts as the outer ring (far picture, no near detail) */
|
|
26
|
+
ring(c) {
|
|
27
|
+
let r = Infinity;
|
|
28
|
+
for (const s of this.centers) r = Math.min(r, Math.max(Math.abs(c.cx - s.cx), Math.abs(c.cz - s.cz), s.simple ? this.table.viewChunks : 0));
|
|
29
|
+
return r;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Follow the sources: centers are reused and compared field by field, so a quiet frame allocates nothing. When a source changed chunk (or
|
|
34
|
+
* the view distance / table changed) queue the chunks any source needs and release those far from all. Returns whether it planned.
|
|
35
|
+
*/
|
|
36
|
+
follow(sources, chunkSize, viewChunks) {
|
|
37
|
+
const C = this.centers, V = viewChunks, T = this.table;
|
|
38
|
+
let changed = C.length !== sources.length || this._for[0] !== V || this._for[1] !== this.ver;
|
|
39
|
+
C.length = sources.length;
|
|
40
|
+
for (let i = 0; i < sources.length; i++) {
|
|
41
|
+
const s = sources[i], cx = Math.floor(s.x / chunkSize), cz = Math.floor(s.z / chunkSize), simple = s.detail === 'simple';
|
|
42
|
+
const R = s.radius == null ? V : Math.min(V, Math.max(1, Math.ceil(s.radius / chunkSize))), c = C[i] ??= { cx: NaN, cz: 0, R: 0, simple: false };
|
|
43
|
+
if (c.cx !== cx || c.cz !== cz || c.R !== R || c.simple !== simple) { c.cx = cx; c.cz = cz; c.R = R; c.simple = simple; changed = true; }
|
|
44
|
+
}
|
|
45
|
+
if (!changed) return false;
|
|
46
|
+
this._for[0] = V; this._for[1] = this.ver;
|
|
47
|
+
const fresh = [], inArea = this.hooks.inArea;
|
|
48
|
+
for (const s of C) {
|
|
49
|
+
const R = s.R, lim = R * R + R;
|
|
50
|
+
for (let dz = -R; dz <= R; dz++) for (let dx = -R; dx <= R; dx++) {
|
|
51
|
+
const cx = s.cx + dx, cz = s.cz + dz, key = cx + ',' + cz;
|
|
52
|
+
if (dx * dx + dz * dz <= lim && !T.chunks.has(key) && (!inArea || inArea(cx, cz))) fresh.push(T._queue(cx, cz, key));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// keep one ring past the load radius so a source pacing on a chunk border does not load / release the same chunks every step
|
|
56
|
+
const kept = c => C.some(s => (c.cx - s.cx) ** 2 + (c.cz - s.cz) ** 2 <= (s.R + 1) * (s.R + 1) + s.R + 1);
|
|
57
|
+
for (const [key, c] of T.chunks) if (!kept(c)) { c.ticket?.remove(); T._dispose(c); T.chunks.delete(key); }
|
|
58
|
+
// queued chunks still wanted plus the new ones, nearest source first
|
|
59
|
+
T._want = T._want.filter(c => c.state === 'queued' && T.chunks.get(c.key) === c).concat(fresh).sort(this._byDist);
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Drop every chunk (before(c) first for a table's own cleanup); the next follow() places them again around the sources */
|
|
64
|
+
drop(before) {
|
|
65
|
+
const T = this.table;
|
|
66
|
+
for (const c of T.chunks.values()) { c.ticket?.remove(); before?.(c); T._dispose(c); } // a pending commit ticket is withdrawn with its chunk
|
|
67
|
+
T.chunks.clear(); T._want = []; this.ver++;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** LOD + frustum over ready chunks: level(c, ring) each, show(c, visible) when it changes. Returns { visible, instances } (reused object) */
|
|
71
|
+
cull(camera) {
|
|
72
|
+
camera.updateMatrixWorld();
|
|
73
|
+
this._m.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
|
|
74
|
+
this._frustum.setFromProjectionMatrix(this._m);
|
|
75
|
+
const H = this.hooks, out = this._out ??= { visible: 0, instances: 0 };
|
|
76
|
+
out.visible = 0; out.instances = 0;
|
|
77
|
+
for (const c of this.table.chunks.values()) {
|
|
78
|
+
if (c.state !== 'ready') continue;
|
|
79
|
+
const ring = this.ring(c);
|
|
80
|
+
H.level(c, ring);
|
|
81
|
+
const v = ring <= 1 || this._frustum.intersectsSphere(c.sphere);
|
|
82
|
+
if (v !== c.inView) { c.inView = v; H.show(c, v); }
|
|
83
|
+
if (v) { out.visible++; out.instances += H.count(c, ring); }
|
|
84
|
+
}
|
|
85
|
+
return out;
|
|
86
|
+
}
|
|
87
|
+
}
|
package/core/control.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
// engine.control: who decides where a character goes. Every character has one control slot (by its id); one owner is in charge at a time.
|
|
2
|
+
// const h = engine.control.take(npc, { owner: 'escort', layer: 'script', step: (dt, ch) => ({ x: 1, z: 0 }) }); // the engine calls step
|
|
3
|
+
// const m = engine.control.take(player, { owner: 'roll', layer: 'script' }); engine.onFixed(dt => m.move(1, 0, false, dt)); // or you move
|
|
4
|
+
// h.remove(); // give it back: the owner below carries on where it paused
|
|
5
|
+
// ctx.control.take(ch, { ... }) // inside a module: owner defaults to the module, and the hold goes when the module goes
|
|
6
|
+
// Why one slot and not "everyone calls character.move": keys, walkTo, an NPC behaviour, a cutscene and the network all used to push the same
|
|
7
|
+
// character in the same step; the last move() won and nobody could tell why the player slid. Now exactly one owner moves it per step.
|
|
8
|
+
// Rules (one table, so a tool can predict them):
|
|
9
|
+
// - layers, lowest first: base (the character's own driver: the player's keys, an NPC's behaviour) < script (walkTo, a quest escort, an AI
|
|
10
|
+
// order) < cutscene (timeline) < net (a character another machine drives: held for good, nobody else may take it)
|
|
11
|
+
// - the highest layer is in charge; the ones below are paused, not cancelled: when it ends they carry on (a walk resumes after a cutscene)
|
|
12
|
+
// - one owner per layer: a second, different owner on the same layer throws control-conflict in dev naming both (release: the later wins, the
|
|
13
|
+
// earlier is dropped, warned once). The same owner taking again replaces its own hold.
|
|
14
|
+
// - a character with any holder moves only through its holder: the step function, or the handle's move(). A direct character.move() from
|
|
15
|
+
// anyone else throws control-bypass in dev. A character nobody holds (a hand-built Character in a test) moves freely.
|
|
16
|
+
// - "who decides where to go" (this) is not "how the body moves" (character.mover: simple / rapier / manual); the two never mix.
|
|
17
|
+
// Kept by id, not by model: an NPC's model is torn down and rebuilt as it goes far and near; the hold stays with the NPC. The slot is dropped when
|
|
18
|
+
// the world record goes (world:remove) or a record-less character is disposed. Not saved: holders are code (a running walk, a cutscene), retaken
|
|
19
|
+
// by that code after a load.
|
|
20
|
+
import { codedError, coded } from './errorHints.js';
|
|
21
|
+
import { DEV, warnOnce } from './validate.js';
|
|
22
|
+
import { callerAt } from './stackFrames.js';
|
|
23
|
+
import { STEP } from './time.js'; // the fixed step: handle.move()'s dt when none is given
|
|
24
|
+
|
|
25
|
+
/** Control layers, lowest first (see the header) */
|
|
26
|
+
export const CONTROL_LAYERS = { base: 0, script: 1, cutscene: 2, net: 3 };
|
|
27
|
+
const LAYER_NAMES = Object.keys(CONTROL_LAYERS);
|
|
28
|
+
|
|
29
|
+
const idOf = who => (typeof who === 'string' ? who : who?.id);
|
|
30
|
+
|
|
31
|
+
/** engine.control (made for every engine in services.js; the characters module tells it how to find a character by id) */
|
|
32
|
+
export class Control {
|
|
33
|
+
constructor(engine) {
|
|
34
|
+
/** @internal */ this.engine = engine;
|
|
35
|
+
/** @type {Map<string, Map<string, any>>} id -> owner -> entry (take order) */ this._by = new Map();
|
|
36
|
+
/** @internal the entry whose move is running now (handle.move / a behaviour run): the one caller character.move() lets through */ this._cur = null;
|
|
37
|
+
/** @internal id -> Character; set by the characters module through resolveWith (core names no module) */ this._resolve = () => null;
|
|
38
|
+
engine.events?.on('world:remove', ({ id }) => this.forget(id));
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Take a character's control. step (optional): (dt, character) => ({ x, z, run? }) | null | false, called each fixed step while this owner is in
|
|
42
|
+
* charge (dt on the character's time channel): a direction moves it, null stands still (gravity and the idle pose go on), false skips the
|
|
43
|
+
* move this step (you placed it yourself). Without step, move it with handle.move(x, z, run, dt), which does nothing while paused.
|
|
44
|
+
* @param {any} who a Character, an NPC handle or a character id ('player', an NPC id)
|
|
45
|
+
* @param {{ owner: string, layer?: 'base' | 'script' | 'cutscene' | 'net', step?: (dt: number, ch: any) => ({ x: number, z: number, run?: boolean } | null | false | void) }} o
|
|
46
|
+
* @returns {{ owner: string, layer: string, id: string, readonly active: boolean, move(x: number, z: number, run?: boolean, dt?: number): boolean, remove(): void }}
|
|
47
|
+
* @example const h = engine.control.take(player, { owner: 'tutorial', layer: 'script', step: () => ({ x: 0, z: 1 }) }); ... h.remove();
|
|
48
|
+
*/
|
|
49
|
+
take(who, o = {}) {
|
|
50
|
+
const id = idOf(who), { owner, layer = 'script', step = null } = o;
|
|
51
|
+
if (!id || typeof id !== 'string') throw codedError('control-layer', `engine.control.take(character, { owner }): pass a character, an NPC handle or an id like 'player', got ${String(who)}`);
|
|
52
|
+
if (!owner || typeof owner !== 'string') throw codedError('control-layer', `engine.control.take('${id}', { owner }): owner is a non-empty string naming who drives it, e.g. 'escort-quest', got ${JSON.stringify(owner)}`);
|
|
53
|
+
if (!(layer in CONTROL_LAYERS)) throw codedError('control-layer', `engine.control.take('${id}', { layer }): layer is one of ${LAYER_NAMES.join(' < ')}, got ${JSON.stringify(layer)}`);
|
|
54
|
+
if (step != null && typeof step !== 'function') throw codedError('control-layer', `engine.control.take('${id}', { step }): step is (dt, character) => ({ x, z, run }) or left out (then move with handle.move()), got ${typeof step}`);
|
|
55
|
+
let m = this._by.get(id);
|
|
56
|
+
if (!m) this._by.set(id, m = new Map());
|
|
57
|
+
const at = DEV ? callerAt() : null;
|
|
58
|
+
for (const e of m.values()) {
|
|
59
|
+
if (e.owner === owner) continue;
|
|
60
|
+
// the network holds a remote character for good: always an error, release builds too (moving it here would be undone by the next update)
|
|
61
|
+
if (e.layer === 'net') throw codedError('control-net', `character '${id}' is driven by another machine (held by '${e.owner}'), so '${owner}' cannot take it. `
|
|
62
|
+
+ `Fix: change it where it is driven: run an op the host runs (engine.ops.run(...)), or take the character that is yours (engine.player)`);
|
|
63
|
+
if (e.layer !== layer) continue;
|
|
64
|
+
const msg = `character '${id}': two owners want layer '${layer}': '${e.owner}'${e.at ? ` (${e.at})` : ''} and '${owner}'${at ? ` (${at})` : ''}. `
|
|
65
|
+
+ `Rule: one owner per layer, so nothing silently decides which one steers. Fix, one of: (1) end the old one first (its handle.remove()); `
|
|
66
|
+
+ `(2) take another layer: engine.control.take(ch, { owner: '${owner}', layer: '${layer === 'cutscene' ? 'script' : 'cutscene'}' }) (higher pauses lower)`;
|
|
67
|
+
if (DEV) throw codedError('control-conflict', msg);
|
|
68
|
+
warnOnce(coded('control-conflict', `${msg}. In this build the later one takes it`), `control-conflict:${id}:${e.owner}:${owner}`);
|
|
69
|
+
m.delete(e.owner);
|
|
70
|
+
}
|
|
71
|
+
const old = m.get(owner);
|
|
72
|
+
m.delete(owner); // a new object: the old handle goes stale, so its remove() cannot end the new hold
|
|
73
|
+
const ent = { id, owner, layer, step, at: old ? old.at : at, ch: typeof who === 'object' && who?.move ? who : null };
|
|
74
|
+
m.set(owner, ent);
|
|
75
|
+
const self = this;
|
|
76
|
+
return {
|
|
77
|
+
owner, layer, id,
|
|
78
|
+
/** true while this owner is in charge (highest layer); false while paused below a higher one, or after remove() */
|
|
79
|
+
get active() { return self._top(id) === ent; },
|
|
80
|
+
/** Move the character for this step (x, z: world direction, length 0-1 scales the speed). Does nothing and returns false while paused */
|
|
81
|
+
move(x, z, run = false, dt = STEP) {
|
|
82
|
+
if (self._top(id) !== ent) return false;
|
|
83
|
+
const ch = self._char(ent);
|
|
84
|
+
if (!ch) return false;
|
|
85
|
+
self._drive(ent, () => ch.move(x, z, run, dt));
|
|
86
|
+
return true;
|
|
87
|
+
},
|
|
88
|
+
remove() { const mm = self._by.get(id); if (mm?.get(owner) === ent) { mm.delete(owner); if (!mm.size) self._by.delete(id); } },
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Who controls a character now: { owner, layer, at?, waiting: [{ owner, layer }] } (waiting = paused below, highest first), or null.
|
|
93
|
+
* @param {any} who a Character, an NPC handle or an id
|
|
94
|
+
*/
|
|
95
|
+
of(who) {
|
|
96
|
+
const id = idOf(who), top = this._top(id);
|
|
97
|
+
if (!top) return null;
|
|
98
|
+
const waiting = [...this._by.get(id).values()].filter(e => e !== top).sort((a, b) => CONTROL_LAYERS[b.layer] - CONTROL_LAYERS[a.layer]).map(e => ({ owner: e.owner, layer: e.layer }));
|
|
99
|
+
return { owner: top.owner, layer: top.layer, ...(top.at && { at: top.at }), waiting };
|
|
100
|
+
}
|
|
101
|
+
/** @internal the characters module tells control how to find a live Character by id (the player, an NPC's model) @param {(id: string) => any} fn */
|
|
102
|
+
resolveWith(fn) { this._resolve = fn; }
|
|
103
|
+
/** True while owner holds the character (in charge or paused) @param {any} who @param {string} owner */
|
|
104
|
+
has(who, owner) { return !!this._by.get(idOf(who))?.has(owner); }
|
|
105
|
+
/** describe().control: every held character by id, as of() */
|
|
106
|
+
describe() { const out = {}; for (const id of this._by.keys()) out[id] = this.of(id); return out; }
|
|
107
|
+
/** Drop every hold on a character (its record left the world, or a record-less character was disposed) @param {string} id */
|
|
108
|
+
forget(id) { this._by.delete(id); }
|
|
109
|
+
/** @internal the entry in charge: highest layer, latest taker inside it (only one per layer in dev) */
|
|
110
|
+
_top(id) {
|
|
111
|
+
const m = this._by.get(id); if (!m) return null;
|
|
112
|
+
let t = null;
|
|
113
|
+
for (const e of m.values()) if (!t || CONTROL_LAYERS[e.layer] >= CONTROL_LAYERS[t.layer]) t = e;
|
|
114
|
+
return t;
|
|
115
|
+
}
|
|
116
|
+
/** @internal the Character an entry moves: the one passed in, if it is still the live one, else found by id (an NPC model rebuilt) */
|
|
117
|
+
_char(ent) { const ch = ent.ch && !ent.ch._disposed ? ent.ch : this._resolve(ent.id); return ch ?? null; }
|
|
118
|
+
/** @internal run fn as the entry's own move (checkMove reads _cur) */
|
|
119
|
+
_drive(ent, fn) { const prev = this._cur; this._cur = ent; try { return fn(); } finally { this._cur = prev; } }
|
|
120
|
+
/** @internal for drivers that call character.move inside their own code (an NPC behaviour): run fn as owner's move when it is in charge; false when paused */
|
|
121
|
+
runAs(id, owner, fn) {
|
|
122
|
+
const top = this._top(id);
|
|
123
|
+
if (!top || top.owner !== owner) return false;
|
|
124
|
+
this._drive(top, fn);
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
/** @internal each fixed step (the characters module calls it): every in-charge holder with a step moves its character once */
|
|
128
|
+
stepAll() {
|
|
129
|
+
const T = this.engine.time;
|
|
130
|
+
for (const id of [...this._by.keys()]) {
|
|
131
|
+
const top = this._top(id);
|
|
132
|
+
if (!top?.step) continue;
|
|
133
|
+
const ch = this._char(top);
|
|
134
|
+
if (!ch) continue;
|
|
135
|
+
const dt = T ? T.dt(ch.channel, ch.modId) : STEP;
|
|
136
|
+
const m = top.step(dt, ch);
|
|
137
|
+
if (m === false || this._top(id) !== top) continue; // placed by hand this step, or the step handed control on (ended itself, something took it)
|
|
138
|
+
this._drive(top, () => ch.move(m?.x ?? 0, m?.z ?? 0, !!m?.run, dt));
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/** @internal dev check from character.move(): a held character moves only through its holder (the header's bypass rule) */
|
|
142
|
+
checkMove(ch) {
|
|
143
|
+
const top = this._top(ch.id);
|
|
144
|
+
if (!top || this._cur === top) return;
|
|
145
|
+
throw codedError('control-bypass', `character '${ch.id}' is controlled by '${top.owner}' (layer ${top.layer}), but its move() was called from outside that owner. `
|
|
146
|
+
+ `Rule: one owner moves a character per step. Fix: take control and move through it: const h = engine.control.take(ch, { owner: 'mine', layer: 'script' }); h.move(x, z, run, dt) `
|
|
147
|
+
+ `(or give step); it pauses '${top.owner}' until h.remove()`);
|
|
148
|
+
}
|
|
149
|
+
}
|
package/core/copies.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Two copies of the engine on one page (e.g. a game imports `threedog` while a style or tool bundles its own copy, or a
|
|
2
|
+
// workspace link plus an npm copy). Each copy installs the shadow accessors on THREE.Mesh.prototype (render/patches.js) and keeps
|
|
3
|
+
// its own patch lists, so the second install makes the first copy's wind / CSM materials cast no matching shadow: nothing throws,
|
|
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
|
+
// 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
|
+
// 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 './errorHints.js';
|
|
8
|
+
|
|
9
|
+
export const VERSION = '0.7.0'; // kept equal to package.json by the "[guard] engine copies" spec
|
|
10
|
+
|
|
11
|
+
const KEY = Symbol.for('threedog.engine.copies');
|
|
12
|
+
|
|
13
|
+
/** Path of an engine file without the query / hash (?t=... from a hot reload) and without the file itself: the copy's root. @param {string} url */
|
|
14
|
+
function copyRoot(url) { return String(url).replace(/[?#].*$/, '').replace(/[^/]*$/, '').replace(/render\/$/, ''); }
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Record this copy; returns the warning text when another copy (different root) is already on the page, else ''.
|
|
18
|
+
* Pure on the passed registry so the spec can feed it fake copies; the engine calls it with the global one.
|
|
19
|
+
* @param {{ version: string, url: string }} me
|
|
20
|
+
* @param {any} [registry]
|
|
21
|
+
*/
|
|
22
|
+
export function noteCopy(me, registry = globalThis) {
|
|
23
|
+
const list = (registry[KEY] ??= []);
|
|
24
|
+
const root = copyRoot(me.url);
|
|
25
|
+
const other = list.find((/** @type {{ root: string }} */ c) => c.root !== root);
|
|
26
|
+
if (!list.some((/** @type {{ root: string }} */ c) => c.root === root)) list.push({ version: me.version, root });
|
|
27
|
+
if (!other) return '';
|
|
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
|
+
"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 style or ' +
|
|
31
|
+
'tool lists threedog under peerDependencies, not dependencies');
|
|
32
|
+
}
|
package/core/dayTime.js
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
//
|
|
1
|
+
// 'HH:MM' <-> day fraction. Pure functions.
|
|
2
|
+
// Clock-time conversion (pure functions): the calendar's time of day `timeOfDay` is the fraction of a day, 0-1, and 'HH:MM' is just another way to write it. engine.calendar timers, npc schedules and music conditions all use it.
|
|
3
|
+
import { codedError } from './errorHints.js';
|
|
2
4
|
/** 'HH:MM' or 0-1 (a number, or text such as '0.25' from a URL) -> fraction of a day, 0-1 (hoursPerDay = hours in a day, default 24) */
|
|
3
5
|
export function parseClock(v, hoursPerDay = 24) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
let t;
|
|
7
|
+
if (typeof v === 'number' || !String(v).includes(':')) t = typeof v === 'string' && !v.trim() ? NaN : +v;
|
|
8
|
+
else { const [h, m = 0] = String(v).split(':').map(Number); t = (h + m / 60) / hoursPerDay; }
|
|
9
|
+
// every clock time passes here (URL ?time=, calendar / sky options, schedules, timers): a NaN let through blacked out the sun and the frame
|
|
10
|
+
if (!Number.isFinite(t) || t < 0) throw codedError('clock-time', `clock time ${JSON.stringify(v)} is not a time of day: write 'HH:MM' ('18:30') or a fraction of the day 0-1 (0.75)`);
|
|
11
|
+
return t;
|
|
7
12
|
}
|
|
8
|
-
/** Is time t (0-1) inside the window [from, to)? (from and to are 'HH:MM' or 0-1; from > to wraps past midnight).
|
|
13
|
+
/** Is time t (0-1) inside the window [from, to)? (from and to are 'HH:MM' or 0-1; from > to wraps past midnight). calendar.between and the audio rule condition { time: [from, to] } both use it */
|
|
9
14
|
export function inRange(t, from, to, hoursPerDay = 24) { return inFrac(t, parseClock(from, hoursPerDay), parseClock(to, hoursPerDay)); }
|
|
10
15
|
export const inFrac = (t, a, b) => (a <= b ? t >= a && t < b : t >= a || t < b);
|
|
11
16
|
/** Fraction of a day 0-1 -> 'HH:MM' */
|
|
12
17
|
export function formatClock(t, hoursPerDay = 24) {
|
|
13
|
-
|
|
18
|
+
// whole minutes with a hair of slack: 0.3 * 24 * 60 is 431.99999999999994 in floats, and flooring that showed 07:11 for 07:12
|
|
19
|
+
const all = Math.floor(t * hoursPerDay * 60 + 1e-6), h = Math.floor(all / 60), m = all % 60;
|
|
14
20
|
return String(h).padStart(2, '0') + ':' + String(m).padStart(2, '0');
|
|
15
21
|
}
|