threedog 0.2.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +290 -0
- package/README.md +9 -8
- package/core/Animator.js +15 -12
- package/core/Assets.js +83 -16
- package/core/Audio.js +45 -38
- package/core/Baked.js +32 -8
- package/core/Batching.js +102 -15
- package/core/Budget.js +39 -18
- package/core/Clock.js +40 -80
- package/core/DebugOverrides.js +45 -10
- package/core/Describe.js +104 -43
- package/core/Engine.js +190 -57
- package/core/Events.js +4 -1
- package/core/I18n.js +25 -13
- package/core/Input.js +168 -79
- package/core/Inspect.js +2 -2
- package/core/InspectMaterials.js +85 -0
- package/core/InspectPerf.js +61 -0
- package/core/InspectScene.js +13 -2
- package/core/Loading.js +2 -1
- package/core/Ops.js +50 -9
- package/core/Random.js +9 -2
- package/core/Rays.js +5 -5
- package/core/SaveStore.js +41 -9
- package/core/Saves.js +71 -15
- package/core/Stream.js +14 -10
- package/core/Threads.js +26 -7
- package/core/UrlState.js +25 -9
- package/core/Views.js +9 -6
- package/core/actor.js +1 -1
- package/core/adaptive.js +93 -0
- package/core/assetEntry.js +22 -5
- package/core/assetHot.js +176 -0
- package/core/assetLoad.js +38 -11
- package/core/assetManifest.js +48 -9
- package/core/assetReport.js +1 -1
- package/core/audioRules.js +13 -11
- package/core/audioVoice.js +69 -42
- package/core/canvasBox.js +1 -2
- package/core/catalog.js +5 -2
- package/core/cells.js +62 -0
- package/core/checks.js +10 -8
- package/core/chunkStream.js +87 -0
- package/core/control.js +149 -0
- package/core/copies.js +32 -0
- package/core/dayTime.js +12 -6
- package/core/debugView.js +82 -15
- package/core/describeRender.js +43 -17
- package/core/describeText.js +41 -21
- package/core/engineCamera.js +32 -0
- package/core/errorCodes.js +438 -19
- package/core/errorHints.js +37 -141
- package/core/errors.js +31 -8
- package/core/events.generated.js +12 -7
- package/core/gameLights.js +62 -0
- package/core/grayMap.js +20 -0
- package/core/grid.js +128 -0
- package/core/gridLoad.js +20 -0
- package/core/ground.js +6 -4
- package/core/headlessLoad.js +55 -0
- package/core/holds.js +78 -50
- package/core/inputContext.js +11 -7
- package/core/inputDefaults.js +24 -21
- package/core/inputPad.js +1 -1
- package/core/inputPointer.js +1 -1
- package/core/inputTouch.js +2 -2
- package/core/lifecycle.js +48 -12
- package/core/lightWatch.js +6 -4
- package/core/look/coreParts.js +137 -30
- package/core/look/part.js +175 -95
- package/core/look/points.js +255 -0
- package/core/look/report.js +34 -17
- package/core/look/shadowPart.js +63 -0
- package/core/look/state.js +45 -0
- package/core/look/write.js +12 -28
- package/core/loop.js +101 -37
- package/core/math.js +11 -3
- package/core/moduleSlots.js +75 -0
- package/core/moduleTypes.js +73 -0
- package/core/modules.js +145 -27
- package/core/movement.js +2 -2
- package/core/namedModel.js +70 -0
- package/core/opsCheck.js +3 -3
- package/core/opsFail.js +15 -6
- package/core/opsGuard.js +4 -4
- package/core/opsRun.js +4 -3
- package/core/owned.js +168 -0
- package/core/page.js +2 -1
- package/core/params.js +30 -8
- package/core/plugins.js +277 -0
- package/core/saveApply.js +99 -17
- package/core/saveFiles.js +8 -6
- package/core/saveValues.js +46 -0
- package/core/saveVersions.js +20 -3
- package/core/scatter.js +48 -19
- package/core/sceneDelta.js +203 -0
- package/core/sceneMethods.js +35 -30
- package/core/screenToGround.js +1 -1
- package/core/services.js +27 -11
- package/core/session.js +28 -25
- package/core/shaderCost.js +78 -0
- package/core/shadowTypes.js +2 -1
- package/core/sharedPoint.js +317 -0
- package/core/skip.js +36 -28
- package/core/stackFrames.js +34 -0
- package/core/stacks.js +166 -0
- package/core/startup.js +153 -11
- package/core/streamSources.js +0 -11
- package/core/styleParts.js +65 -47
- package/core/targeting.js +1 -1
- package/core/textureBytes.js +20 -0
- package/core/thingExplain.js +2 -2
- package/core/thingOps.js +29 -6
- package/core/things.js +21 -11
- package/core/threadPure.js +7 -3
- package/core/threePatches.js +47 -0
- package/core/tier.js +21 -10
- package/core/time.js +236 -0
- package/core/uiClock.js +25 -0
- package/core/util.js +7 -1
- package/core/validate.js +65 -86
- package/core/wrap.js +106 -0
- package/docs/AI.md +89 -97
- package/docs/API.md +32 -28
- package/docs/CODEMAP.md +224 -149
- package/docs/COMMANDS.md +57 -34
- package/docs/CONVENTIONS.md +92 -30
- package/docs/MIGRATING-0.3.md +248 -0
- package/docs/MIGRATING-0.4.md +228 -0
- package/docs/MIGRATING-0.5.md +68 -0
- package/docs/PERF.md +35 -7
- package/docs/THREE.md +79 -27
- package/docs/api/ambience.md +0 -1
- package/docs/api/assets.md +12 -9
- package/docs/api/audio.md +10 -14
- package/docs/api/calendar.md +41 -0
- package/docs/api/cameraRig.md +16 -5
- package/docs/api/characters.md +41 -25
- package/docs/api/clock.md +6 -5
- package/docs/api/collision.md +9 -6
- package/docs/api/content.md +6 -4
- package/docs/api/dialogue.md +9 -9
- package/docs/api/engine.md +65 -62
- package/docs/api/events.md +19 -14
- package/docs/api/grids.md +3 -3
- package/docs/api/ground.md +1 -1
- package/docs/api/hud.md +2 -2
- package/docs/api/i18n.md +1 -1
- package/docs/api/input.md +11 -6
- package/docs/api/interactions.md +7 -5
- package/docs/api/inventory.md +17 -16
- package/docs/api/level.md +0 -1
- package/docs/api/lightPool.md +3 -1
- package/docs/api/music.md +1 -1
- package/docs/api/nav.md +3 -0
- package/docs/api/openWorld.md +2 -1
- package/docs/api/particles.md +2 -2
- package/docs/api/photo.md +0 -2
- package/docs/api/pickups.md +15 -0
- package/docs/api/post.md +5 -4
- package/docs/api/quests.md +2 -3
- package/docs/api/rigid.md +16 -14
- package/docs/api/saves.md +6 -4
- package/docs/api/settings.md +2 -3
- package/docs/api/sky.md +11 -44
- package/docs/api/stream.md +1 -1
- package/docs/api/style.md +31 -29
- package/docs/api/terrain.md +9 -6
- package/docs/api/terrainLook.md +10 -0
- package/docs/api/timeline.md +3 -4
- package/docs/api/tools.md +30 -13
- package/docs/api/triggers.md +5 -10
- package/docs/api/vegetation.md +12 -8
- package/docs/api/vegetationLook.md +10 -0
- package/docs/api/water.md +4 -20
- package/docs/api/weather.md +5 -15
- package/docs/api/weatherLook.md +10 -0
- package/docs/api/world.md +2 -1
- package/docs/recipes/01-new-game.md +71 -59
- package/docs/recipes/02-npc.md +46 -29
- package/docs/recipes/03-items-pickups.md +38 -24
- package/docs/recipes/04-quests.md +34 -27
- package/docs/recipes/05-props-bake.md +154 -18
- package/docs/recipes/06-clock-events.md +100 -52
- package/docs/recipes/07-flow-scenes-pause.md +41 -10
- package/docs/recipes/08-weather-sky.md +146 -37
- package/docs/recipes/09-style.md +218 -0
- package/docs/recipes/10-blender-level.md +14 -2
- package/docs/recipes/11-vehicles.md +64 -7
- package/docs/recipes/13-animation.md +34 -10
- package/docs/recipes/14-custom-module.md +65 -34
- package/docs/recipes/15-perf.md +35 -6
- package/docs/recipes/16-dev-bridge.md +65 -41
- package/docs/recipes/18-world.md +21 -8
- package/docs/recipes/19-shooting-picking.md +12 -11
- package/docs/recipes/20-content-actions-save.md +63 -25
- package/docs/recipes/21-camera.md +49 -16
- package/docs/recipes/22-shop-gold.md +18 -18
- package/docs/recipes/23-ops.md +17 -11
- package/docs/recipes/26-ui-parts.md +61 -12
- package/docs/recipes/27-net.md +12 -6
- package/docs/recipes/28-terrain.md +35 -2
- package/docs/recipes/29-grid.md +71 -33
- package/docs/recipes/30-templates.md +64 -12
- package/docs/recipes/31-audio.md +20 -12
- package/docs/recipes/32-action-game.md +35 -2
- package/docs/recipes/34-environment-lighting.md +27 -4
- package/docs/recipes/35-style-from-reference.md +115 -51
- package/docs/recipes/36-sky-ground-plant-looks.md +37 -35
- package/docs/recipes/37-terrain-look-hooks.md +37 -15
- package/docs/recipes/38-environment-look-hooks.md +64 -48
- package/docs/recipes/40-scene.md +16 -13
- package/docs/recipes/41-thing-registry.md +11 -7
- package/docs/recipes/42-terrain-shape.md +3 -3
- package/docs/recipes/43-shader-patches-surface-looks.md +171 -74
- package/docs/recipes/44-water-weather-look-hooks.md +30 -21
- package/docs/recipes/45-cascaded-shadows.md +17 -8
- package/docs/recipes/46-blender-art-route.md +4 -4
- package/docs/recipes/47-island-snow-backdrop.md +11 -10
- package/docs/recipes/48-make-material.md +11 -6
- package/docs/recipes/49-game-module-contract.md +46 -33
- package/docs/recipes/50-own-renderer.md +2 -2
- package/docs/recipes/51-capability-catalog.md +4 -4
- package/docs/recipes/52-look.md +228 -54
- package/docs/recipes/53-ground-up-close.md +58 -0
- package/docs/recipes/54-three-idioms.md +88 -0
- package/docs/recipes/55-mods-time-wrap.md +112 -0
- package/docs/recipes/56-webgpu-tsl.md +260 -0
- package/docs/recipes/57-control.md +65 -0
- package/docs/recipes/58-input.md +57 -0
- package/docs/recipes/59-depth-post-effects.md +83 -0
- package/docs/recipes/60-judge-the-picture.md +55 -0
- package/examples/action/.threedog/content-index.json +1 -0
- package/examples/action/GAMEMAP.md +17 -13
- package/examples/action/assets.js +8 -0
- package/examples/action/content/actions.js +1 -1
- package/examples/action/content/audio.js +5 -5
- package/examples/action/look.js +1 -1
- package/examples/action/main.js +10 -13
- package/examples/action/models.js +24 -23
- package/examples/pullable.json +111 -0
- package/examples/rc2d/.threedog/content-index.json +1 -0
- package/examples/rc2d/GAMEMAP.md +83 -0
- package/examples/rc2d/README.md +52 -0
- package/examples/rc2d/main.js +63 -0
- package/examples/rc2d/rc2d.js +197 -0
- package/examples/rc2d/shaders.js +144 -0
- package/examples/sheepisland/.threedog/content-index.json +1 -0
- package/examples/sheepisland/GAMEMAP.md +13 -11
- package/examples/sheepisland/assets.js +5 -0
- package/examples/sheepisland/main.js +17 -12
- package/examples/sheepisland/style/index.js +6 -6
- package/examples/styletest/.threedog/content-index.json +1 -0
- package/examples/styletest/GAMEMAP.md +15 -16
- package/examples/styletest/assets.js +6 -0
- package/examples/styletest/content/npcs.js +1 -1
- package/examples/styletest/content/templates.js +1 -1
- package/examples/styletest/content/vegetation.js +1 -1
- package/examples/styletest/look.js +1 -1
- package/examples/styletest/main.js +18 -17
- package/examples/styletest/models.js +1 -1
- package/examples/styletest/params.js +3 -3
- package/examples/techniques/contact-shadows/README.md +92 -0
- package/examples/techniques/contact-shadows/contactShadows.js +51 -0
- package/examples/techniques/contact-shadows/main.js +53 -0
- package/examples/techniques/day-night-grade/README.md +86 -0
- package/examples/techniques/day-night-grade/dayNightGrade.js +76 -0
- package/examples/techniques/day-night-grade/main.js +51 -0
- package/examples/techniques/interior-light/README.md +103 -0
- package/examples/techniques/interior-light/interiorLight.js +45 -0
- package/examples/techniques/interior-light/main.js +124 -0
- package/examples/techniques/modular-building/README.md +125 -0
- package/examples/techniques/modular-building/kit.js +426 -0
- package/examples/techniques/modular-building/main.js +47 -0
- package/examples/techniques/night-lights/README.md +94 -0
- package/examples/techniques/night-lights/main.js +70 -0
- package/examples/techniques/night-lights/nightLights.js +91 -0
- package/examples/techniques/outlines-and-rim/README.md +59 -0
- package/examples/techniques/outlines-and-rim/main.js +84 -0
- package/examples/techniques/outlines-and-rim/outlines.js +64 -0
- package/examples/techniques/procedural-animation/README.md +77 -0
- package/examples/techniques/procedural-animation/creature.js +44 -0
- package/examples/techniques/procedural-animation/main.js +45 -0
- package/examples/techniques/procedural-animation/proceduralAnim.js +118 -0
- package/examples/techniques/procedural-surface/README.md +67 -0
- package/examples/techniques/procedural-surface/main.js +103 -0
- package/examples/techniques/procedural-surface/surface.js +120 -0
- package/examples/techniques/stylized-shading/README.md +75 -0
- package/examples/techniques/stylized-shading/main.js +93 -0
- package/examples/techniques/stylized-shading/shading.js +131 -0
- package/examples/techniques/sun-and-key-light/README.md +135 -0
- package/examples/techniques/sun-and-key-light/keyLight.js +53 -0
- package/examples/techniques/sun-and-key-light/main.js +95 -0
- package/examples/techniques/wet-road/README.md +99 -0
- package/examples/techniques/wet-road/main.js +68 -0
- package/examples/techniques/wet-road/wetRoad.js +209 -0
- package/examples/webgpu-tsl/.threedog/content-index.json +1 -0
- package/examples/webgpu-tsl/GAMEMAP.md +84 -0
- package/examples/webgpu-tsl/README.md +42 -0
- package/examples/webgpu-tsl/main.js +21 -0
- package/examples/webgpu-tsl/tslScene.js +75 -0
- package/examples/world/.threedog/content-index.json +1 -0
- package/examples/world/GAMEMAP.md +22 -15
- package/examples/world/art/humanoid.js +42 -0
- package/examples/world/art/index.js +11 -0
- package/examples/world/art/models.js +58 -0
- package/examples/world/art/shapes.js +9 -0
- package/examples/world/assets.js +6 -0
- package/examples/world/content/audio.js +5 -5
- package/examples/world/content/npcs.js +2 -2
- package/examples/world/content/props.js +1 -1
- package/examples/world/content/rules.js +1 -1
- package/examples/world/content/templates.js +1 -1
- package/examples/world/content/vegetation.js +1 -1
- package/examples/world/main.js +17 -13
- package/examples/world/style/index.js +61 -0
- package/examples/world/style/plugins/10-bloom.js +5 -0
- package/index.d.ts +50 -45
- package/index.js +27 -22
- package/llms.txt +20 -12
- package/modules/ambience/Ambience.js +34 -23
- package/modules/calendar/Calendar.js +163 -0
- package/modules/calendar/contract.js +21 -0
- package/modules/calendar/index.js +81 -0
- package/modules/{sky → calendar}/schedule.js +17 -16
- package/modules/calendar/seasons.js +55 -0
- package/modules/camera/FirstPersonCamera.js +6 -15
- package/modules/camera/FixedCamera.js +33 -15
- package/modules/camera/FollowCamera.js +90 -16
- package/modules/camera/RtsCamera.js +18 -17
- package/modules/camera/common.js +70 -19
- package/modules/camera/contract.js +17 -0
- package/modules/camera/projection.js +11 -24
- package/modules/characters/Character.js +196 -59
- package/modules/characters/NPC.js +87 -36
- package/modules/characters/assetModel.js +27 -8
- package/modules/characters/behaviors.js +2 -1
- package/modules/characters/contract.js +13 -0
- package/modules/characters/footsteps.js +1 -1
- package/modules/characters/index.js +87 -49
- package/modules/characters/moveHelpers.js +4 -5
- package/modules/characters/movers/common.js +97 -19
- package/modules/characters/movers/manual.js +20 -0
- package/modules/characters/movers/rapier.js +19 -16
- package/modules/characters/movers/simple.js +14 -11
- package/modules/characters/movers/support.js +172 -0
- package/modules/characters/npcAvoid.js +47 -42
- package/modules/characters/npcSim.js +12 -8
- package/modules/characters/npcView.js +44 -16
- package/modules/characters/pathAsync.js +7 -3
- package/modules/characters/playerStrings.js +4 -3
- package/modules/characters/proceduralRig.js +46 -10
- package/modules/characters/useModel.js +1 -1
- package/modules/characters/vehicle.contract.js +21 -0
- package/modules/characters/walkTo.js +21 -7
- package/modules/collision/Collision.js +65 -25
- package/modules/collision/grid.js +8 -6
- package/modules/content/explain.js +2 -2
- package/modules/content/fields.js +102 -0
- package/modules/content/ids.js +8 -6
- package/modules/content/index.js +97 -28
- package/modules/content/loader.js +45 -33
- package/modules/content/models.js +11 -40
- package/modules/content/packs.js +6 -5
- package/modules/content/parts.js +41 -0
- package/modules/content/props.js +16 -9
- package/modules/content/rules.js +58 -0
- package/modules/content/stages.js +80 -0
- package/modules/content/templates.js +121 -30
- package/modules/debug/DebugPanel.js +24 -17
- package/modules/flow/contract.js +16 -0
- package/modules/flow/index.js +21 -15
- package/modules/gameplay/Container.js +41 -32
- package/modules/gameplay/Containers.js +30 -15
- package/modules/gameplay/Dialogue.js +113 -55
- package/modules/gameplay/Interactions.js +193 -67
- package/modules/gameplay/Inventory.js +69 -73
- package/modules/gameplay/Quests.js +75 -39
- package/modules/gameplay/boxOps.js +3 -3
- package/modules/gameplay/dialogue.contract.js +21 -0
- package/modules/gameplay/dialogueBox.js +4 -2
- package/modules/gameplay/dialogueBubbles.js +116 -0
- package/modules/gameplay/interactionPrompt.js +4 -1
- package/modules/gameplay/interactions.contract.js +16 -0
- package/modules/gameplay/inventory.contract.js +23 -0
- package/modules/gameplay/inventoryOps.js +18 -16
- package/modules/gameplay/pickups.js +268 -85
- package/modules/gameplay/questLog.js +4 -4
- package/modules/gameplay/quests.contract.js +17 -0
- package/modules/grid/Grid.js +92 -50
- package/modules/grid/Layer.js +14 -13
- package/modules/grid/index.js +60 -36
- package/modules/grid/ops.js +20 -18
- package/modules/grid/preview.js +15 -16
- package/modules/grid/strings.js +12 -0
- package/modules/grid/tiles.js +6 -5
- package/modules/hlod/index.js +51 -19
- package/modules/hud/index.js +35 -20
- package/modules/hud/parts.js +20 -7
- package/modules/level/heightfield.js +3 -1
- package/modules/level/index.js +45 -20
- package/modules/level/nodes.js +4 -3
- package/modules/lights/index.js +42 -18
- package/modules/music/Music.js +38 -21
- package/modules/music/rules.js +1 -1
- package/modules/nav/index.js +48 -42
- package/modules/net/Client.js +13 -6
- package/modules/net/Host.js +19 -5
- package/modules/net/Net.js +2 -1
- package/modules/net/index.js +13 -8
- package/modules/net/sync.js +9 -8
- package/modules/net/transports.js +77 -27
- package/modules/particles/Particles.js +23 -14
- package/modules/particles/contract.js +17 -0
- package/modules/particles/effect.js +39 -11
- package/modules/photo/Photo.js +53 -36
- package/modules/rigid/RigidBodies.js +194 -32
- package/modules/rigid/Vehicles.js +18 -15
- package/modules/rigid/sync.js +62 -17
- package/modules/settings/Settings.js +57 -52
- package/modules/settings/apply.js +38 -3
- package/modules/settings/sections.js +5 -3
- package/modules/settings/strings.js +3 -2
- package/modules/settings/view.js +5 -3
- package/modules/sky/Sky.js +88 -176
- package/modules/sky/cascades.js +86 -25
- package/modules/sky/cascades.tsl.js +82 -0
- package/modules/sky/clouds.js +34 -19
- package/modules/sky/domeLayers.js +30 -15
- package/modules/sky/environment.js +83 -13
- package/modules/sky/fog.js +140 -95
- package/modules/sky/frame.js +112 -44
- package/modules/sky/look.js +22 -19
- package/modules/sky/lookFog.js +48 -52
- package/modules/sky/lookShadow.js +53 -41
- package/modules/sky/lookSky.js +82 -21
- package/modules/sky/season.js +21 -0
- package/modules/sky/shader.js +41 -19
- package/modules/sky/shadow.js +44 -20
- package/modules/sky/skyModule.js +45 -33
- package/modules/sky/tint.js +61 -0
- package/modules/terrain/ChunkManager.js +175 -108
- package/modules/terrain/chunkJob.js +1 -1
- package/modules/terrain/chunkQueries.js +6 -4
- package/modules/terrain/index.js +105 -50
- package/modules/terrain/look.js +83 -0
- package/modules/terrain/lookGround.js +21 -16
- package/modules/terrain/terrainDefaults.js +1 -1
- package/modules/terrain/terrainEdit.js +18 -20
- package/modules/terrain/terrainGen.js +5 -3
- package/modules/terrain/terrainIsland.js +5 -4
- package/modules/terrain/terrainShape.js +12 -12
- package/modules/terrain/terrainShapeMain.js +8 -7
- package/modules/terrain/terrainTexture.js +21 -19
- package/modules/timeline/Timeline.js +95 -43
- package/modules/timeline/Tween.js +18 -10
- package/modules/timeline/letterbox.js +2 -2
- package/modules/timeline/shots.js +5 -1
- package/modules/triggers/index.js +107 -76
- package/modules/vegetation/Vegetation.js +190 -102
- package/modules/vegetation/densityMap.js +62 -0
- package/modules/vegetation/groundChunks.js +52 -58
- package/modules/vegetation/index.js +31 -10
- package/modules/vegetation/look.js +119 -0
- package/modules/vegetation/lookWind.js +71 -10
- package/modules/vegetation/modelGeometry.js +3 -2
- package/modules/vegetation/nearFade.js +45 -0
- package/modules/water/Water.js +65 -27
- package/modules/water/look.js +29 -18
- package/modules/water/surface.js +64 -25
- package/modules/water/surfaceDefaults.js +3 -0
- package/modules/weather/Weather.js +62 -104
- package/modules/weather/look.js +1 -2
- package/modules/weather/particles.js +24 -9
- package/modules/weather/strings.js +2 -2
- package/modules/weather/weatherLook.js +135 -0
- package/modules/world/World.js +24 -7
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +18 -4
- package/modules/world/persist.js +62 -2
- package/modules/world/pos.js +3 -2
- package/modules/world/records.js +8 -6
- package/modules/world/sim.js +60 -20
- package/modules/world/simFar.js +4 -3
- package/modules/world/state.js +3 -2
- package/modules/world/thingSource.js +1 -1
- package/modules/world/views.js +7 -5
- package/package.json +8 -3
- package/presets.js +41 -27
- package/render/PostFX.js +145 -120
- package/render/backend.js +440 -0
- package/render/detail.js +150 -45
- package/render/effects.js +130 -38
- package/render/engineUniforms.js +10 -1
- package/render/fuse.js +5 -4
- package/render/fx/cloudShadow.tsl.js +16 -0
- package/render/fx/detail.tsl.js +66 -0
- package/render/fx/index.js +26 -0
- package/render/fx/lighting.tsl.js +28 -0
- package/render/fx/nodeErrors.tsl.js +68 -0
- package/render/fx/noise.tsl.js +12 -0
- package/render/fx/objectOrigin.tsl.js +42 -0
- package/render/fx/particles.tsl.js +139 -0
- package/render/fx/patchNodes.tsl.js +403 -0
- package/render/fx/postWebGPU.tsl.js +158 -0
- package/render/fx/season.tsl.js +13 -0
- package/render/fx/sky.tsl.js +260 -0
- package/render/fx/uniforms.tsl.js +67 -0
- package/render/fx/water.tsl.js +53 -0
- package/render/fx/wind.tsl.js +22 -0
- package/render/fxNumbers.js +36 -0
- package/render/hotGlsl.js +24 -0
- package/render/lighting.js +66 -14
- package/render/lights.js +223 -4
- package/render/lookGlow.js +139 -0
- package/render/lookSurface.js +99 -36
- package/render/materials.js +71 -52
- package/render/modeling.js +73 -0
- package/render/ownFrame.js +76 -0
- package/render/patches.js +311 -34
- package/render/postLook.js +124 -46
- package/render/postWebGL.js +197 -0
- package/render/probes.js +231 -0
- package/render/shaderErrors.js +154 -0
- package/render/slots.js +165 -0
- package/render/surface.js +53 -17
- package/render/terms.js +211 -0
- package/render/uniformDecl.js +3 -2
- package/types/common.d.ts +2 -2
- package/types/core.d.ts +620 -244
- package/types/gameplay.d.ts +494 -318
- package/types/generated/core/Audio.d.ts +26 -42
- package/types/generated/core/Batching.d.ts +6 -2
- package/types/generated/core/Budget.d.ts +2 -8
- package/types/generated/core/DebugOverrides.d.ts +44 -3
- package/types/generated/core/I18n.d.ts +2 -2
- package/types/generated/core/Input.d.ts +102 -31
- package/types/generated/core/Ops.d.ts +31 -0
- package/types/generated/core/Random.d.ts +2 -2
- package/types/generated/core/Saves.d.ts +10 -2
- package/types/generated/core/Stream.d.ts +1 -1
- package/types/generated/core/Threads.d.ts +4 -1
- package/types/generated/core/Views.d.ts +0 -1
- package/types/generated/core/audioVoice.d.ts +17 -9
- package/types/generated/core/control.d.ts +55 -0
- package/types/generated/core/session.d.ts +2 -1
- package/types/generated/modules/ambience/Ambience.d.ts +0 -9
- package/types/generated/modules/calendar/Calendar.d.ts +84 -0
- package/types/generated/modules/calendar/index.d.ts +10 -0
- package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
- package/types/generated/modules/grid/Grid.d.ts +61 -25
- package/types/generated/modules/grid/Layer.d.ts +5 -5
- package/types/generated/modules/grid/index.d.ts +29 -17
- package/types/generated/modules/music/Music.d.ts +5 -3
- package/types/generated/modules/net/index.d.ts +3 -3
- package/types/generated/modules/net/transports.d.ts +12 -3
- package/types/generated/modules/particles/Particles.d.ts +1 -1
- package/types/generated/modules/sky/Sky.d.ts +12 -104
- package/types/generated/modules/sky/skyModule.d.ts +1 -1
- package/types/generated/modules/timeline/Timeline.d.ts +8 -6
- package/types/generated/modules/weather/Weather.d.ts +17 -18
- package/types/generated/modules/weather/weatherLook.d.ts +12 -0
- package/types/generated/modules/world/World.d.ts +18 -3
- package/types/generated/render/PostFX.d.ts +67 -30
- package/types/generated/render/materials.d.ts +26 -20
- package/types/generated/render/modeling.d.ts +30 -0
- package/types/generated/render/patches.d.ts +16 -2
- package/types/generated/ui/UI.d.ts +6 -3
- package/types/nav.d.ts +6 -0
- package/types/physics.d.ts +137 -44
- package/types/style.d.ts +125 -92
- package/types/tsl.d.ts +86 -0
- package/types/world.d.ts +164 -110
- package/ui/Focus.js +25 -14
- package/ui/LoadingScreen.js +1 -1
- package/ui/Parts.js +27 -11
- package/ui/UI.js +20 -10
- package/ui/cursor.js +115 -0
- package/ui/defaults.js +15 -11
- package/ui/theme.js +9 -6
- package/ui/touchPart.js +1 -1
- package/core/claims.js +0 -51
- package/core/look/layers.js +0 -136
- package/core/renamed.js +0 -21
- package/docs/api/entities.md +0 -61
- package/docs/recipes/09-style-pack.md +0 -234
- package/examples/styletest/overrides.js +0 -33
- package/examples/styletest/panel.js +0 -135
- package/modules/entities/Entities.js +0 -243
- package/modules/entities/build.js +0 -25
- package/modules/entities/index.js +0 -4
- package/modules/sky/calendar.js +0 -80
- package/modules/sky/layers.js +0 -69
- package/modules/terrain/chunkLevels.js +0 -40
- package/modules/terrain/mountTerrain.js +0 -32
- package/modules/world/cells.js +0 -42
package/modules/world/World.js
CHANGED
|
@@ -7,11 +7,13 @@
|
|
|
7
7
|
// Data must be plain values (putting a three.js object or a function in it throws in dev); position is a plain { x, y, z }. Don't hold on to rec: loading a
|
|
8
8
|
// save swaps in new objects, so keep the id and use world.get(id).
|
|
9
9
|
import { DEV, fmt } from '../../core/validate.js';
|
|
10
|
+
import { checkTypeRule } from '../../core/moduleTypes.js';
|
|
10
11
|
import { addRecord, setRecord, removeRecord, queryRecords } from './records.js';
|
|
11
12
|
import { Views } from './views.js';
|
|
12
13
|
import { Sim } from './sim.js';
|
|
13
14
|
import { initState, mixInternals } from './state.js';
|
|
14
15
|
import { putPos, centerOf } from './pos.js';
|
|
16
|
+
import { codedError } from '../../core/errorHints.js';
|
|
15
17
|
|
|
16
18
|
const STRINGS = {
|
|
17
19
|
anchor: 'world.anchor must be null, an Object3D, a Vector3 / { x, z } or [x, y, z]; got {got}',
|
|
@@ -58,7 +60,7 @@ export class World {
|
|
|
58
60
|
get anchor() { return this._anchor; }
|
|
59
61
|
set anchor(a) {
|
|
60
62
|
const ok = a == null || a.isObject3D || (Array.isArray(a) ? a.length === 3 && a.every(Number.isFinite) : Number.isFinite(a.x) && Number.isFinite(a.z));
|
|
61
|
-
if (!ok) throw
|
|
63
|
+
if (!ok) throw codedError('world-option', fmt(STRINGS.anchor, { got: JSON.stringify(a) }));
|
|
62
64
|
this._anchor = a ?? null;
|
|
63
65
|
}
|
|
64
66
|
|
|
@@ -81,7 +83,7 @@ export class World {
|
|
|
81
83
|
* @param {{ initial?: boolean, save?: boolean }} [opts]
|
|
82
84
|
* @returns {WorldRecord | null}
|
|
83
85
|
*/
|
|
84
|
-
add(def, opts) { return addRecord(this, def, opts); }
|
|
86
|
+
add(def, opts) { checkTypeRule(this.engine, 'world.write', `added a world record (${def?.kind ?? '?'})`); return addRecord(this, def, opts); }
|
|
85
87
|
/**
|
|
86
88
|
* Where a record comes from (filled in dev and test builds; null in release): { definedAt: 'content/props.js:14' } for a content entry,
|
|
87
89
|
* { level, node } for a level-model node, { template } when it is a template instance, { spawned: { op, tick } } for a record created during play.
|
|
@@ -116,7 +118,7 @@ export class World {
|
|
|
116
118
|
* @param {Record<string, any>} patch
|
|
117
119
|
* @returns {WorldRecord}
|
|
118
120
|
*/
|
|
119
|
-
set(id, patch) { return setRecord(this, id, patch); }
|
|
121
|
+
set(id, patch) { checkTypeRule(this.engine, 'world.write', `set world record ${id}`); return setRecord(this, id, patch); }
|
|
120
122
|
/**
|
|
121
123
|
* Move a record (no event; use it in simulate for things that move every step); still saved (saves diff against content).
|
|
122
124
|
* The model of a positionFrom 'record' (default) record follows this frame; to do something else with the position in presentation, compare in update
|
|
@@ -137,7 +139,7 @@ export class World {
|
|
|
137
139
|
* @param {string} id
|
|
138
140
|
* @returns {void}
|
|
139
141
|
*/
|
|
140
|
-
remove(id) { removeRecord(this, id); }
|
|
142
|
+
remove(id) { checkTypeRule(this.engine, 'world.write', `removed world record ${id}`); removeRecord(this, id); }
|
|
141
143
|
/**
|
|
142
144
|
* Query records; returns an array. With near only nearby cells are scanned and results are sorted nearest first (radius defaults to 30 m); where filters
|
|
143
145
|
* further. For neighbor queries every step use forEachNear
|
|
@@ -184,6 +186,11 @@ export class World {
|
|
|
184
186
|
* @returns {any}
|
|
185
187
|
*/
|
|
186
188
|
view(id) { return this._v.map.get(id)?.obj ?? null; }
|
|
189
|
+
/**
|
|
190
|
+
* @internal Tear down this record's model now and build it again on the next refresh (a content template stage that names another model).
|
|
191
|
+
* The record is untouched; safe to call from a present update (the views loop tolerates the entry going away).
|
|
192
|
+
*/
|
|
193
|
+
rebuild(id) { this._v.unview(id); this._v.dirty = true; }
|
|
187
194
|
/**
|
|
188
195
|
* All models that should exist near the stream sources are built (async ones too; failed builds do not count as pending). The loading screen waits for it; to
|
|
189
196
|
* wait yourself, await world.whenReady @type {boolean}
|
|
@@ -205,20 +212,30 @@ export class World {
|
|
|
205
212
|
* far(rec, dt): farther away, once every farEvery seconds; dt is the seconds accumulated since the last simulation (can catch up a long time at once); on the
|
|
206
213
|
* far → near step, far runs first to pay back the owed time.
|
|
207
214
|
* With only far (crops), near also advances via far; with only near, far records are not simulated and owed time is not made up.
|
|
208
|
-
* Both dt are accumulated fixed-step seconds (not multiplied by clock.
|
|
209
|
-
* and compare.
|
|
215
|
+
* Both dt are accumulated real (fixed-step) seconds (not multiplied by clock.rate). For things measured in game clock (grows over days) store engine.clock.now
|
|
216
|
+
* and compare. channel: a time channel name (or rec => name) the kind lives on; then both dt are multiplied by that channel's speed (and the record's
|
|
217
|
+
* engine.time.local stack), so bullet time on 'enemies' slows near and far records alike (NPCs use it with their own channel).
|
|
210
218
|
* radius defaults to the present radius ('view' widened by 1.25), or world.radius without present; may also be a function.
|
|
219
|
+
* fullRadius + nearEvery (tiers, for crowds): records within fullRadius m (number or function) run near every step; the rest of the near zone runs near
|
|
220
|
+
* once every nearEvery seconds, dt being the seconds since its last turn (deterministic: turns go by hashed id and step count, saved).
|
|
211
221
|
* worker: true (experimental) runs far in engine.threads workers (batched per step, written back 4 steps later, bit-identical with threads off). far must
|
|
212
222
|
* then be self-contained:
|
|
213
223
|
* it is recompiled from source and sees only (rec, dt) and globals like Math; an outside variable throws naming it (threads on or off alike).
|
|
214
224
|
* @example engine.world.simulate('zombie', { near: (rec, dt) => chase(rec, dt), far: (rec, dt) => wander(rec, dt), farEvery: 2 })
|
|
225
|
+
* @example engine.world.simulate('slime', { near: chase, far: wander, channel: 'enemies' }) // engine.mod('time.enemies', { mul: 0.35, for: 2 }) slows them
|
|
215
226
|
* @example engine.world.simulate('crop', { far: (rec, dt) => { rec.growth = Math.min(1, rec.growth + dt / 600); }, worker: true })
|
|
216
227
|
* @param {string} kind
|
|
217
228
|
* @param {{ near?: (rec: WorldRecord, dt: number, obj: any) => void, far?: (rec: WorldRecord, dt: number) => void, farEvery?: number, radius?: number | (()
|
|
218
|
-
* => number), worker?: boolean }} opts
|
|
229
|
+
* => number), fullRadius?: number | (() => number), nearEvery?: number, worker?: boolean, channel?: string | ((rec: WorldRecord) => string) }} opts
|
|
219
230
|
* @returns {{ remove(): void }}
|
|
220
231
|
*/
|
|
221
232
|
simulate(kind, opts) { return this._s.simulate(kind, opts); }
|
|
233
|
+
/**
|
|
234
|
+
* Stop running simulate() handlers on this machine until remove(): a multiplayer client lets the host simulate and only receives the records.
|
|
235
|
+
* Public so net() needs no world internals.
|
|
236
|
+
* @returns {{ remove(): void }}
|
|
237
|
+
*/
|
|
238
|
+
pauseSimulation() { const s = this._s; s.fixed = () => {}; return { remove: () => { delete s.fixed; } }; }
|
|
222
239
|
/** Number of fixed steps simulated */ get steps() { return this._s.n; }
|
|
223
240
|
|
|
224
241
|
|
package/modules/world/explain.js
CHANGED
|
@@ -8,4 +8,4 @@ export function worldExplain(e, t, out) {
|
|
|
8
8
|
out.state = { ...t.fields, position: t.position };
|
|
9
9
|
Object.assign(out.rules, { blocksMovement: rec.collide ?? false, pickable: rec.static !== false, interact: null, note: RULES_NOTE });
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
const RULES_NOTE = 'blocksMovement = the collision shape (box / circle) walkers stop at; blocking sight is not modelled by the engine';
|
package/modules/world/index.js
CHANGED
|
@@ -9,6 +9,20 @@ import { worldExplain } from './explain.js';
|
|
|
9
9
|
import { closest, warnOnce, DEV } from '../../core/validate.js';
|
|
10
10
|
import { readParams, keysSchema } from '../../core/params.js';
|
|
11
11
|
|
|
12
|
+
const PLACED = '[session] {n} world record(s) were created or removed by code before the game started ({ids}): a new game should equal the content. '
|
|
13
|
+
+ 'Move them to content (content/props.js with an id and a template from content/templates.js), or create them during play inside an op';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Dev check on the new-game state (saves.register checkNewGame, run once start() finished): authored things come from content, so a new game has
|
|
17
|
+
* no runtime records but the player and removes nothing. Changed fields are not checked: simulation may already move authored records (an NPC
|
|
18
|
+
* walking its schedule) while loading runs in real time. Lives here, not in core/session.js: only the world knows its own save format.
|
|
19
|
+
* @param {any} d the world part of the new-game state
|
|
20
|
+
*/
|
|
21
|
+
function codePlaced(d) {
|
|
22
|
+
const ids = [...Object.entries(d?.records || {}).filter(([, r]) => r.kind !== 'player').map(([id]) => id), ...(d?.removed || [])];
|
|
23
|
+
if (ids.length) warnOnce(PLACED.replace('{n}', String(ids.length)).replace('{ids}', ids.slice(0, 8).join(', ') + (ids.length > 8 ? ', …' : '')));
|
|
24
|
+
}
|
|
25
|
+
|
|
12
26
|
const ORPHAN = '[world] the save has changes for {n} id(s) that the content no longer defines: {list}. They are kept in the save (restoring the entry brings them back); '
|
|
13
27
|
+ "if an entry was renamed, add the pair to content/renames.js (export default { 'oldId': 'newId' }) and the saved state follows it; 'oldId': null drops it";
|
|
14
28
|
const RENAME_TARGET = '[world] content/renames.js moves saved state to {list}, which no content entry defines: fix the new id (did you mean {near}?)';
|
|
@@ -25,12 +39,12 @@ export function world(opts = {}) {
|
|
|
25
39
|
readParams('world', WORLD_PARAMS, opts);
|
|
26
40
|
let w = null;
|
|
27
41
|
return {
|
|
28
|
-
name: 'world', label: 'World data', params: WORLD_PARAMS, options: opts, stage: '
|
|
29
|
-
install(e) {
|
|
42
|
+
name: 'world', type: 'world', provides: ['world'], label: 'World data', params: WORLD_PARAMS, options: opts, stage: 'ground',
|
|
43
|
+
install(e, ctx) { e.i18n.add({ 'zh-CN': { 'module.world': '世界数据' }, en: { 'module.world': 'world data' } });
|
|
30
44
|
w = new World(e, opts);
|
|
31
45
|
e.stream.player.at(() => w.center); // the default stream source sits where gameplay is simulated (world.anchor, else the player)
|
|
32
46
|
e.stream.readyCheck('world', s => s.detail !== 'full' || w.ready);
|
|
33
|
-
e.saves.register('world', { atomic: true, version:
|
|
47
|
+
e.saves.register('world', { atomic: true, version: 5, migrate: WORLD_MIGRATE, save: () => w.toJSON(), load: d => w.fromJSON(d), checkNewGame: codePlaced });
|
|
34
48
|
e._things.addSource(recordSource(w)); // engine.thing / thing.set / the shared id space reach the records through this
|
|
35
49
|
e.explainWith(worldExplain);
|
|
36
50
|
e.budget.metric('worldRecords', () => w.records.size);
|
|
@@ -48,7 +62,7 @@ export function world(opts = {}) {
|
|
|
48
62
|
const bad = [...w._renames].filter(([, b]) => b != null && !w._base.has(b) && due(b));
|
|
49
63
|
if (bad.length) warnOnce(RENAME_TARGET.replace('{list}', bad.map(([a, b]) => `${b} (from ${a})`).join(', ')).replace('{near}', closest(bad[0][1], [...w._base.keys()]) ?? '-'));
|
|
50
64
|
};
|
|
51
|
-
for (const ev of ['engine:ready', 'save:loaded', 'level:loaded']) e.events.on(ev, () => { if (e.ready) warn(); });
|
|
65
|
+
for (const ev of ['engine:ready', 'save:loaded', 'level:loaded']) ctx.track(e.events.on(ev, () => { if (e.ready) warn(); }));
|
|
52
66
|
}
|
|
53
67
|
return w;
|
|
54
68
|
},
|
package/modules/world/persist.js
CHANGED
|
@@ -7,17 +7,23 @@
|
|
|
7
7
|
// Loading before content is loaded works too: changes and removals are remembered and applied / skipped when content is added. Things newly added to content after a game update still show up with an old save.
|
|
8
8
|
// Temporary things (data for effects, one-off spawns): add(def, { save: false }) — not saved, cleared on load.
|
|
9
9
|
// Changes are found by comparing JSON against the original content, not by events: fields changed directly inside simulate are saved too.
|
|
10
|
-
// Save format (part 'world', version
|
|
10
|
+
// Save format (part 'world', version 4): every record is keyed by its stable id, and only what play changed is stored:
|
|
11
11
|
// { seq, step, time, records: { id: whole runtime record without id }, changed: { id: { set?: changed fields, del?: [removed fields] } },
|
|
12
12
|
// removed: [ids of removed initial records], owed: { id: simulation seconds owed, only for kinds simulated with far } }
|
|
13
13
|
// Version 1 kept records as an array: migrate step 1 (WORLD_MIGRATE) turns it into the id-keyed object.
|
|
14
14
|
// Version 2 numbered runtime records `<kind>-<n>`; version 3 uses `<kind>#<n>`, so a runtime id can never equal an authored one (authored ids may not
|
|
15
15
|
// contain `#`, content/ids.js). Step 2 renames them (legacyRuntimeIds says which), and the containers part follows with the same map (a template
|
|
16
16
|
// instance's container is keyed by the record id).
|
|
17
|
+
// Version 4: a character's motion (Character.saveMotion: on the player record itself, in rec.motion for NPCs) keeps its jump state as
|
|
18
|
+
// jump: { coyote, used } instead of the flat coyote field (the jump API: air jumps count used jumps). Step 3 moves it.
|
|
19
|
+
// Version 5: an NPC's talk / talkLabel / talkRadius became interact { label, op: 'npc.talk', args: { script }, radius } (talking is one interact op
|
|
20
|
+
// among many). Step 4 moves them, on whole records and on changed fields.
|
|
17
21
|
// Removed fields are recorded separately (not saved as null): after loading it is "no such field", same as in a live run; a field that was null stays null.
|
|
18
22
|
// step / time are the simulation step count and accumulated seconds: far simulation takes turns by step-count buckets, so one save advances the same way every time (see sim.js).
|
|
19
23
|
|
|
20
24
|
import { legacyRuntimeIds, renameIdKeys, renameIdValues } from '../../core/saveIds.js';
|
|
25
|
+
import { codedError } from '../../core/errorHints.js';
|
|
26
|
+
import { isPlainObject } from '../../core/util.js';
|
|
21
27
|
|
|
22
28
|
const PLAIN_STRINGS = {
|
|
23
29
|
msg: 'world data must be plain values (number, string, boolean, array, plain object): {path} is {what}. Put models in world.present() and logic in world.simulate()',
|
|
@@ -25,7 +31,7 @@ const PLAIN_STRINGS = {
|
|
|
25
31
|
};
|
|
26
32
|
/** Dev-time check: data must not contain three.js objects, functions or DOM elements (saves can only store plain values) @internal */
|
|
27
33
|
export function checkPlain(v, path, depth = 0) {
|
|
28
|
-
const fail = what => { throw
|
|
34
|
+
const fail = what => { throw codedError('world-plain', PLAIN_STRINGS.msg.replace('{path}', path).replace('{what}', what)); };
|
|
29
35
|
if (v == null || typeof v !== 'object') { if (typeof v === 'function') fail(PLAIN_STRINGS.fn); return; }
|
|
30
36
|
const what = v.isObject3D ? PLAIN_STRINGS.obj : v.isMaterial || v.isBufferGeometry || v.isTexture ? PLAIN_STRINGS.asset : typeof Element !== 'undefined' && v instanceof Element ? PLAIN_STRINGS.dom : null;
|
|
31
37
|
if (what) fail(what);
|
|
@@ -52,6 +58,27 @@ export const WORLD_MIGRATE = {
|
|
|
52
58
|
if (!map.size) return d;
|
|
53
59
|
return { ...d, records: renameIdValues(renameIdKeys(d.records, map), map), changed: renameIdValues(d.changed, map), owed: renameIdKeys(d.owed, map) };
|
|
54
60
|
},
|
|
61
|
+
3: d => { // motion coyote -> jump: { coyote, used: 0 } (whole runtime records and changed fields; the player keeps it on the record, NPCs in motion)
|
|
62
|
+
const fix = m => { if (!m || typeof m !== 'object' || !('coyote' in m)) return m; const { coyote, ...rest } = m; return { ...rest, jump: { coyote: coyote ?? 0, used: 0 } }; };
|
|
63
|
+
const rec = r => { const o = fix(r); return o && typeof o === 'object' && o.motion ? { ...o, motion: fix(o.motion) } : o; };
|
|
64
|
+
const map = (o, f) => o && typeof o === 'object' ? Object.fromEntries(Object.entries(o).map(([k, v]) => [k, f(v)])) : o;
|
|
65
|
+
return { ...d, records: map(d.records, rec), changed: map(d.changed, c => c?.set ? { ...c, set: rec(c.set) } : c) };
|
|
66
|
+
},
|
|
67
|
+
4: d => { // NPC talk / talkLabel / talkRadius -> interact (records of any kind that carry talk: only NPCs had it)
|
|
68
|
+
const fix = r => {
|
|
69
|
+
if (!r || typeof r !== 'object' || !('talk' in r)) return r;
|
|
70
|
+
const { talk, talkLabel, talkRadius, ...rest } = r;
|
|
71
|
+
return { ...rest, interact: talk ? { label: talkLabel ?? null, op: 'npc.talk', args: { script: talk }, radius: talkRadius ?? 3.2 } : null };
|
|
72
|
+
};
|
|
73
|
+
const map = (o, f) => o && typeof o === 'object' ? Object.fromEntries(Object.entries(o).map(([k, v]) => [k, f(v)])) : o;
|
|
74
|
+
// a changed entry of an initial NPC: a removed talk means it no longer talks (interact removed). A label / radius alone (set or removed) has no
|
|
75
|
+
// script to build an interact from, so it is dropped and the content's interact stays; a stray key would sit on the record unread
|
|
76
|
+
const OLD = ['talkLabel', 'talkRadius'];
|
|
77
|
+
const strip = s => s && typeof s === 'object' && !('talk' in s) && OLD.some(k => k in s) ? Object.fromEntries(Object.entries(s).filter(([k]) => !OLD.includes(k))) : s;
|
|
78
|
+
const del = l => Array.isArray(l) ? [...new Set(l.filter(k => !OLD.includes(k)).map(k => k === 'talk' ? 'interact' : k))] : l;
|
|
79
|
+
const change = c => c && typeof c === 'object' ? { ...c, ...(c.set && { set: strip(fix(c.set)) }), ...(c.del && { del: del(c.del) }) } : c;
|
|
80
|
+
return { ...d, records: map(d.records, fix), changed: map(d.changed, change) };
|
|
81
|
+
},
|
|
55
82
|
};
|
|
56
83
|
|
|
57
84
|
|
|
@@ -70,8 +97,41 @@ export function saveWorld(w) {
|
|
|
70
97
|
return { seq: w._seq, ...w._s.toJSON(), records, changed, removed: [...w._removed] };
|
|
71
98
|
}
|
|
72
99
|
|
|
100
|
+
// Shape check of a world save before anything is replaced. Why here and not in add(): putPos only checks in dev, and a save bypasses add() entirely,
|
|
101
|
+
// so a hand-edited or damaged record ({ x: 1e12, y: null, z: 'abc' }) went straight into the records and threw later in a listener / a mover,
|
|
102
|
+
// with the game half-loaded. Refusing throws: saves.apply rolls the whole load back and reports this message (save-bad-record).
|
|
103
|
+
const SHAPE_STRINGS = {
|
|
104
|
+
bad: "world save: {path} {why} (got {got}); the save was refused and the game was rolled back. The save was edited by hand or damaged: fix that field, or load another save",
|
|
105
|
+
obj: 'must be a plain object', kind: 'must have kind (a string)', pos: 'must be { x, y, z } with finite numbers within ±{max}',
|
|
106
|
+
arr: 'must be an array of record ids', count: 'must be a finite number >= 0',
|
|
107
|
+
};
|
|
108
|
+
/** Positions beyond this are damage, not a big world: float32 models are already centimetres off at 1e5 and useless far before 1e7 */
|
|
109
|
+
const POS_MAX = 1e7;
|
|
110
|
+
/** Throw save-bad-record for the first malformed core field of a world save (fields of the game's own are not checked) @internal */
|
|
111
|
+
function checkWorldSave(d) {
|
|
112
|
+
const bad = (path, why, got) => { throw codedError('save-bad-record', SHAPE_STRINGS.bad.replace('{path}', path).replace('{why}', why.replace('{max}', String(POS_MAX))).replace('{got}', String(JSON.stringify(got)).slice(0, 120))); };
|
|
113
|
+
const pos = (path, p) => { if (!isPlainObject(p) || !['x', 'y', 'z'].every(k => Number.isFinite(p[k]) && Math.abs(p[k]) <= POS_MAX)) bad(path, SHAPE_STRINGS.pos, p); };
|
|
114
|
+
const num = (path, v) => { if (v !== undefined && !(Number.isFinite(v) && v >= 0)) bad(path, SHAPE_STRINGS.count, v); };
|
|
115
|
+
if (!isPlainObject(d)) bad('the world part', SHAPE_STRINGS.obj, d);
|
|
116
|
+
num('seq', d.seq); num('step', d.step); num('time', d.time);
|
|
117
|
+
for (const f of ['records', 'changed', 'owed']) if (d[f] !== undefined && !isPlainObject(d[f])) bad(f, SHAPE_STRINGS.obj, d[f]);
|
|
118
|
+
if (d.removed !== undefined && !(Array.isArray(d.removed) && d.removed.every(id => typeof id === 'string'))) bad('removed', SHAPE_STRINGS.arr, d.removed);
|
|
119
|
+
for (const [id, r] of Object.entries(d.records ?? {})) {
|
|
120
|
+
if (!isPlainObject(r)) bad(`records.${id}`, SHAPE_STRINGS.obj, r);
|
|
121
|
+
if (typeof r.kind !== 'string') bad(`records.${id}`, SHAPE_STRINGS.kind, r.kind);
|
|
122
|
+
if ('position' in r) pos(`records.${id}.position`, r.position);
|
|
123
|
+
}
|
|
124
|
+
for (const [id, c] of Object.entries(d.changed ?? {})) {
|
|
125
|
+
if (!isPlainObject(c) || (c.set !== undefined && !isPlainObject(c.set)) || (c.del !== undefined && !Array.isArray(c.del))) bad(`changed.${id}`, SHAPE_STRINGS.obj, c);
|
|
126
|
+
if (c.set && 'position' in c.set) pos(`changed.${id}.set.position`, c.set.position);
|
|
127
|
+
if (c.set && 'kind' in c.set && typeof c.set.kind !== 'string') bad(`changed.${id}.set`, SHAPE_STRINGS.kind, c.set.kind);
|
|
128
|
+
}
|
|
129
|
+
for (const [id, v] of Object.entries(d.owed ?? {})) num(`owed.${id}`, v);
|
|
130
|
+
}
|
|
131
|
+
|
|
73
132
|
/** Load: replace runtime records wholesale; loaded initial records go back to the original then get the save's changes; unloaded content waits for its add. Independent of the order of content.load @internal */
|
|
74
133
|
export function loadWorld(w, d) {
|
|
134
|
+
checkWorldSave(d); // before anything is cleared: a refused save leaves the world as it was (the rollback then has nothing to undo here)
|
|
75
135
|
w._v.clear();
|
|
76
136
|
w.records.clear(); w._cells.clear(); w._unsaved.clear();
|
|
77
137
|
for (const id of [...w._origin.keys()]) if (!w._base.has(id)) w._origin.delete(id); // runtime records come from the save now (no op to name)
|
package/modules/world/pos.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Position read / write for world: shared by add / move / query. A wrong position (a Vector3 used as an array, [x, z] with only two numbers) silently becomes NaN and null in the save,
|
|
2
2
|
// so dev builds throw on the spot and say how to fix it.
|
|
3
3
|
import { DEV } from '../../core/validate.js';
|
|
4
|
+
import { codedError } from '../../core/errorHints.js';
|
|
4
5
|
|
|
5
6
|
const STRINGS = {
|
|
6
7
|
arr: '{fn}: an array position must be [x, y, z] (three numbers); for a horizontal position only, write { x, z }',
|
|
@@ -10,10 +11,10 @@ const STRINGS = {
|
|
|
10
11
|
/** Write position v (Vector3 / object / [x, y, z] / { x, z }) into p; y stays unchanged if omitted @internal */
|
|
11
12
|
export function putPos(fn, v, p) {
|
|
12
13
|
const arr = Array.isArray(v), o = v.isObject3D ? v.position : v;
|
|
13
|
-
if (DEV && arr && v.length !== 3) throw
|
|
14
|
+
if (DEV && arr && v.length !== 3) throw codedError('bad-position', STRINGS.arr.replace('{fn}', fn));
|
|
14
15
|
const x = arr ? v[0] : o.x, y = arr ? v[1] : o.y ?? p.y, z = arr ? v[2] : o.z;
|
|
15
16
|
// check before writing: a bad position leaves no half-written NaN in the data
|
|
16
|
-
if (DEV && !(Number.isFinite(x) && Number.isFinite(y) && Number.isFinite(z))) throw
|
|
17
|
+
if (DEV && !(Number.isFinite(x) && Number.isFinite(y) && Number.isFinite(z))) throw codedError('bad-position', STRINGS.nan.replace('{fn}', fn).replace('{got}', JSON.stringify(v)));
|
|
17
18
|
p.x = x; p.y = y; p.z = z;
|
|
18
19
|
}
|
|
19
20
|
/** Query center: objects use position, arrays are [x, y, z], others (Vector3 / { x, z }) are used as is, no allocation @internal */
|
package/modules/world/records.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
// World record mutations (add / rest / orphans / set / remove): the bodies behind the World methods of the same names. World.js keeps the public
|
|
2
2
|
// JSDoc and signatures; these functions take the world as `w` and reach its internals the same way sim.js / views.js / persist.js do.
|
|
3
|
-
import { DEV,
|
|
3
|
+
import { DEV, fmt } from '../../core/validate.js';
|
|
4
|
+
import { readParams, keysSchema } from '../../core/params.js';
|
|
4
5
|
import { checkPlain } from './persist.js';
|
|
5
6
|
import { putPos, centerOf } from './pos.js';
|
|
6
7
|
import { claimId } from '../../core/things.js';
|
|
8
|
+
import { codedError } from '../../core/errorHints.js';
|
|
7
9
|
|
|
8
10
|
export const STRINGS = {
|
|
9
11
|
noKind: 'world.add() needs a kind (what sort of thing this is), e.g. world.add({ kind: "crate", position: [0, 0, 0] })',
|
|
@@ -15,10 +17,10 @@ export const STRINGS = {
|
|
|
15
17
|
|
|
16
18
|
export function addRecord(w, def, opts) {
|
|
17
19
|
DEV && w.engine.ops.guard('world.add');
|
|
18
|
-
if (!def?.kind) throw
|
|
19
|
-
if (DEV) {
|
|
20
|
+
if (!def?.kind) throw codedError('world-add', STRINGS.noKind);
|
|
21
|
+
if (DEV) { readParams('world.add(def, opts)', keysSchema(['initial', 'save']), opts); checkPlain({ ...def, position: undefined }, def.kind); }
|
|
20
22
|
const { id: given, kind, position, ...rest } = def, initial = !!opts?.initial;
|
|
21
|
-
if (initial && given == null) throw
|
|
23
|
+
if (initial && given == null) throw codedError('world-add', fmt(STRINGS.initialId, { kind }));
|
|
22
24
|
const id = given ?? `${kind}#${++w._seq}`, have = w.records.get(id), p = { x: 0, y: 0, z: 0 };
|
|
23
25
|
if (position) putPos('world.add()', position, p);
|
|
24
26
|
const rec = { id, kind, position: p, ...rest };
|
|
@@ -29,7 +31,7 @@ export function addRecord(w, def, opts) {
|
|
|
29
31
|
if (w._removed.has(id)) return null;
|
|
30
32
|
return w._insert(w._fromBase(id, w._base.get(id)), true);
|
|
31
33
|
}
|
|
32
|
-
if (have) throw
|
|
34
|
+
if (have) throw codedError('world-id', fmt(STRINGS.dupId, { id }));
|
|
33
35
|
claimId(w.engine, id);
|
|
34
36
|
if (opts?.save === false) w._unsaved.add(id);
|
|
35
37
|
if (DEV) w._origin.set(id, { spawned: { op: w.engine.ops.running, tick: w.engine.tick } }); // who made it (inspect / pick)
|
|
@@ -55,7 +57,7 @@ export function orphanIds(w) {
|
|
|
55
57
|
export function setRecord(w, id, patch) {
|
|
56
58
|
DEV && w.engine.ops.guard('world.set');
|
|
57
59
|
const rec = w._need(id, 'set');
|
|
58
|
-
if (DEV) { if ('id' in patch || 'kind' in patch) throw
|
|
60
|
+
if (DEV) { if ('id' in patch || 'kind' in patch) throw codedError('world-add', fmt(STRINGS.setKey, { id })); checkPlain({ ...patch, position: undefined }, id); }
|
|
59
61
|
const { position, ...rest } = patch;
|
|
60
62
|
Object.assign(rec, rest);
|
|
61
63
|
if (position) w.move(id, position);
|
package/modules/world/sim.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
// Simulation layer of world: near records every fixed step, far records in id buckets taking turns under a per-step cap. The public API is in World.js
|
|
2
2
|
// (simulate / anchor); this is the implementation.
|
|
3
|
-
// Time: the dt of both near and far is "accumulated fixed-step seconds" (same ruler as
|
|
3
|
+
// Time: the dt of both near and far is "accumulated fixed-step seconds" (real seconds, the same ruler as a plain onFixed dt; not multiplied by clock.rate).
|
|
4
|
+
// simulate(kind, { channel }) puts the kind on a time channel (engine.time): every dt handed to near / far (the owed payback and engine.skip's catch-up too)
|
|
5
|
+
// is multiplied by that channel's speed now, times the record's own engine.time.local stack, so bullet time on 'enemies' slows near and far alike.
|
|
6
|
+
// channel may be a function of the record (NPCs: each record names its own). The bookkeeping below stays in real seconds; only the handed dt is scaled.
|
|
4
7
|
// For one record going near, far, near again, the dts add up to the elapsed time:
|
|
5
8
|
// far dt = seconds accumulated since the last simulation; on the far → near step, far first pays back the owed time, then near runs.
|
|
6
9
|
// A kind with only far (crops) does not split near / far and always advances at far's pace; a kind with only near is not simulated while far and its owed time
|
|
@@ -14,9 +17,15 @@
|
|
|
14
17
|
// changes after loading;
|
|
15
18
|
// when near records affect each other (avoiding each other, fighting over the same thing), sorting by id keeps "kept running" and "saved then loaded"
|
|
16
19
|
// bit-identical.
|
|
20
|
+
// Near tiers (simulate({ fullRadius, nearEvery })): records inside fullRadius run every step; the rest of the near zone runs in id-hash buckets once every
|
|
21
|
+
// nearEvery seconds with the accumulated dt (the far idea, inside the near zone). Why: a crowd that is visible but not close (hundreds of NPCs) paid the full
|
|
22
|
+
// mover cost every step. Buckets follow the hashed id and the step count (both saved), not distances measured on frame boundaries, so a loaded save runs the
|
|
23
|
+
// same records on the same steps as a live run.
|
|
17
24
|
|
|
18
|
-
import { DEV
|
|
25
|
+
import { DEV } from '../../core/validate.js';
|
|
26
|
+
import { readParams, keysSchema } from '../../core/params.js';
|
|
19
27
|
import { FarFlights } from './simFar.js';
|
|
28
|
+
import { codedError } from '../../core/errorHints.js';
|
|
20
29
|
|
|
21
30
|
/** Near simulation order: by id (independent of insertion order and loading) */
|
|
22
31
|
const byId = (a, b) => a.rec.id < b.rec.id ? -1 : 1;
|
|
@@ -37,19 +46,31 @@ export class Sim {
|
|
|
37
46
|
this.n = 0; // simulation step count (saved: buckets follow it, so after loading the same batch is up as in a live run)
|
|
38
47
|
this.at = { x: 0, z: 0 }; // this step's simulation center (taken from world.anchor at the start of each step)
|
|
39
48
|
this.dt = 0;
|
|
40
|
-
this.list = []; // records
|
|
49
|
+
this.list = []; // records inside a near radius this step (reused, not allocated each step)
|
|
50
|
+
this.order = []; // last step's near list sorted by id: reused when the membership did not change (most steps), so no sort per step
|
|
41
51
|
this.flights = new FarFlights(this); // far with worker: true (simFar.js)
|
|
42
52
|
// created once, no closure per step
|
|
43
|
-
this._pick = (rec, d2) => {
|
|
53
|
+
this._pick = (rec, d2) => {
|
|
54
|
+
const s = this.sims.get(rec.kind);
|
|
55
|
+
if (s && d2 <= s.r2 && this.w._inZone(rec)) { const e = this.ents.get(rec.id); e.d2 = d2; this.list.push(e); }
|
|
56
|
+
};
|
|
44
57
|
}
|
|
45
58
|
|
|
46
59
|
simulate(kind, opts) {
|
|
47
|
-
if (DEV)
|
|
60
|
+
if (DEV) readParams(`world.simulate('${kind}', opts)`, keysSchema(['near', 'far', 'farEvery', 'radius', 'fullRadius', 'nearEvery', 'worker', 'channel']), opts);
|
|
48
61
|
const s = { ...opts };
|
|
62
|
+
if (s.channel != null && typeof s.channel !== 'string' && typeof s.channel !== 'function') {
|
|
63
|
+
throw codedError('world-option', `world.simulate('${kind}', { channel }): a time channel name ('world', 'player' or one from engine.time.channel(name)) or rec => name; got ${JSON.stringify(s.channel)}`);
|
|
64
|
+
}
|
|
49
65
|
if (s.worker && s.far) this.flights.register(kind, s);
|
|
50
66
|
this.sims.set(kind, s);
|
|
51
67
|
return { remove: () => { if (this.sims.get(kind) === s) this.sims.delete(kind); } };
|
|
52
68
|
}
|
|
69
|
+
/** dt as the kind's near / far gets it: on its time channel when simulate set one (real seconds otherwise) */
|
|
70
|
+
scaled(s, rec, dt) {
|
|
71
|
+
const ch = s.channel;
|
|
72
|
+
return ch == null ? dt : dt * this.w.engine.time.scale(typeof ch === 'function' ? ch(rec) : ch, rec.id);
|
|
73
|
+
}
|
|
53
74
|
/** A new record starts counting time from the moment it is added (owed time from a save carries on) */
|
|
54
75
|
added(rec) {
|
|
55
76
|
const id = rec.id, o = this.owed.get(id);
|
|
@@ -82,13 +103,25 @@ export class Sim {
|
|
|
82
103
|
if (!this.sims.size) return;
|
|
83
104
|
let maxR2 = -1;
|
|
84
105
|
// radius may be a function: asked once per kind per step
|
|
85
|
-
for (const [kind, s] of this.sims) {
|
|
106
|
+
for (const [kind, s] of this.sims) {
|
|
107
|
+
s.r2 = s.near ? this.radius(kind, s) ** 2 : -1; if (s.r2 > maxR2) maxR2 = s.r2;
|
|
108
|
+
// tiers: f2 = full-rate radius squared (Infinity = no tiers), P = steps between turns of the outer part
|
|
109
|
+
const f = s.fullRadius == null ? Infinity : typeof s.fullRadius === 'function' ? s.fullRadius() : s.fullRadius;
|
|
110
|
+
s.f2 = f * f; s.P = s.nearEvery ? Math.max(1, Math.round(s.nearEvery / dt)) : 1;
|
|
111
|
+
}
|
|
86
112
|
if (maxR2 >= 0) {
|
|
87
113
|
const L = this.list; L.length = 0;
|
|
88
114
|
W._cells.forEach(this.at, Math.sqrt(maxR2), this._pick);
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
for (const e of L) if (
|
|
115
|
+
// same members as last step (every one was near on step n - 1 and the count matches): last step's sorted order is still the id order
|
|
116
|
+
let same = L.length === this.order.length;
|
|
117
|
+
if (same) for (const e of L) if (e.near !== n - 1) { same = false; break; }
|
|
118
|
+
const O = same ? this.order : (this.order = L.slice().sort(byId));
|
|
119
|
+
for (const e of O) e.near = n; // mark first: isNear in simulate and skipping far both follow what was picked at the start of this step
|
|
120
|
+
for (const e of O) {
|
|
121
|
+
if (e.dead) continue;
|
|
122
|
+
const s = this.sims.get(e.rec.kind);
|
|
123
|
+
if (s && (s.P === 1 || e.d2 <= s.f2 || (n + e.h) % s.P === 0)) this.nearOne(e, s);
|
|
124
|
+
}
|
|
92
125
|
}
|
|
93
126
|
// far: first the ones queued by the previous step, then this step's bucket; at most farMaxPerTick per step, the rest queue (dt accumulates, no time lost)
|
|
94
127
|
const max = W.farMaxPerTick, q = this.backlog;
|
|
@@ -111,24 +144,28 @@ export class Sim {
|
|
|
111
144
|
}
|
|
112
145
|
this.flights.flush();
|
|
113
146
|
}
|
|
114
|
-
nearOne(e) {
|
|
115
|
-
const rec = e.rec,
|
|
116
|
-
if (!s
|
|
147
|
+
nearOne(e, s) {
|
|
148
|
+
const rec = e.rec, now = this.time, dt = this.dt;
|
|
149
|
+
if (!s.near) return; // earlier simulation in this step replaced the registration of this kind
|
|
117
150
|
// For records whose model drives the position (positionFrom 'view'): near simulation needs the model, so build it right now instead of next frame —
|
|
118
151
|
// otherwise the steps before the model is built and the first step after loading would differ from a live run (the result would depend on frame boundaries)
|
|
119
152
|
const V = this.w._v, p = V.presenters.get(rec.kind);
|
|
120
153
|
if (p?.positionFrom === 'view' && !V.map.has(rec.id) && (!p.show || p.show(rec))) V.build(rec, p);
|
|
121
154
|
if (e.flight) this.flights.land(e);
|
|
122
|
-
|
|
155
|
+
// near takes one step, or for a tiered kind everything since its last turn up to one tier period (the outer part waits P steps between turns; a record
|
|
156
|
+
// moving inward catches up its gap the same way); what is older came from far: far pays that stretch back first
|
|
157
|
+
const step = s.P > 1 ? Math.max(dt, Math.min(now - e.last, s.P * dt)) : dt;
|
|
158
|
+
const owed = now - step - e.last;
|
|
123
159
|
e.last = now;
|
|
124
|
-
if (owed > 1e-9 && s.far) s.far(rec, owed);
|
|
125
|
-
s.near(rec,
|
|
160
|
+
if (owed > 1e-9 && s.far) s.far(rec, this.scaled(s, rec, owed));
|
|
161
|
+
s.near(rec, this.scaled(s, rec, step), this.w.view(rec.id));
|
|
126
162
|
}
|
|
127
163
|
farOne(e, s, now) {
|
|
128
164
|
const dt = now - e.last;
|
|
129
165
|
e.last = now;
|
|
130
166
|
if (dt <= 0) return 0; // added during this step
|
|
131
|
-
|
|
167
|
+
const d = this.scaled(s, e.rec, dt);
|
|
168
|
+
if (s.pure) this.flights.add(e, s, dt, d); else s.far(e.rec, d);
|
|
132
169
|
return 1;
|
|
133
170
|
}
|
|
134
171
|
/** engine.skip: move simulation time without stepping; on the last segment (done) every record with far catches up what it owes in one far(rec, dt), in id order.
|
|
@@ -143,7 +180,8 @@ export class Sim {
|
|
|
143
180
|
const owed = now - e.last;
|
|
144
181
|
e.last = now;
|
|
145
182
|
if (owed <= 0) continue;
|
|
146
|
-
|
|
183
|
+
const d = this.scaled(s, e.rec, owed);
|
|
184
|
+
if (s.pure) this.flights.now(e, s, d); else s.far(e.rec, d);
|
|
147
185
|
}
|
|
148
186
|
}
|
|
149
187
|
rebucket(K, P) {
|
|
@@ -156,9 +194,11 @@ export class Sim {
|
|
|
156
194
|
toJSON() {
|
|
157
195
|
const owed = {}, W = this.w, t = this.time;
|
|
158
196
|
// in flight (worker far not landed): the record does not have that stretch yet, so it is still owed
|
|
159
|
-
// only kinds simulated with far owe time: a prop, pickup or near-only kind never makes it up, so it writes nothing (saves stay small)
|
|
197
|
+
// only kinds simulated with far owe time: a prop, pickup or near-only kind never makes it up, so it writes nothing (saves stay small);
|
|
198
|
+
// a tiered near record waiting for its turn does owe its gap (near pays it on the turn), so a loaded save hands it the same dt as a live run
|
|
160
199
|
for (const [id, e] of this.ents) {
|
|
161
|
-
|
|
200
|
+
const s = this.sims.get(e.rec.kind);
|
|
201
|
+
if (!s?.far && !(s?.P > 1 && e.near === this.n)) continue;
|
|
162
202
|
const last = e.flight ? e.flight.from : e.last;
|
|
163
203
|
if (t - last > 1e-6 && !W._unsaved.has(id)) owed[id] = t - last;
|
|
164
204
|
}
|
|
@@ -168,7 +208,7 @@ export class Sim {
|
|
|
168
208
|
/** Load: work back the last simulation time from "seconds owed"; records are re-added later by loadWorld */
|
|
169
209
|
fromJSON(d) {
|
|
170
210
|
for (const e of this.ents.values()) e.dead = true; // results still in flight belong to the old records: dropped
|
|
171
|
-
this.ents.clear(); this.kinds.clear(); this.backlog.length = 0;
|
|
211
|
+
this.ents.clear(); this.kinds.clear(); this.backlog.length = 0; this.order.length = 0;
|
|
172
212
|
this.n = d?.step ?? 0; this.time = d?.time ?? 0;
|
|
173
213
|
this.owed = new Map(Object.entries(d?.owed || {}).map(([id, s]) => [id, this.time - s]));
|
|
174
214
|
}
|
package/modules/world/simFar.js
CHANGED
|
@@ -37,9 +37,10 @@ export class FarFlights {
|
|
|
37
37
|
s.key = kind + '#' + ++this.defs;
|
|
38
38
|
if (T.size) T.pureLane().broadcast({ def: s.key, src: s.pure.src, label }, 'def:' + s.key);
|
|
39
39
|
}
|
|
40
|
-
|
|
40
|
+
/** dt: real seconds this turn covers (bookkeeping); d: the dt far gets (dt on the kind's time channel, sim.scaled) */
|
|
41
|
+
add(e, s, dt, d = dt) {
|
|
41
42
|
let b = this.open.get(s); if (!b) this.open.set(s, b = []);
|
|
42
|
-
b.push([e, dt]);
|
|
43
|
+
b.push([e, dt, d]);
|
|
43
44
|
}
|
|
44
45
|
/** End of the far pass: send each kind's batch */
|
|
45
46
|
flush() {
|
|
@@ -49,7 +50,7 @@ export class FarFlights {
|
|
|
49
50
|
send(s, items) {
|
|
50
51
|
const engine = this.sim.w.engine, T = engine.threads;
|
|
51
52
|
// copies taken now: what far sees is the record as of this step, whatever happens to it during the flight
|
|
52
|
-
const f = { s, items, snaps: items.map(([e,
|
|
53
|
+
const f = { s, items, snaps: items.map(([e, , d]) => [structuredClone(e.rec), d]), results: null };
|
|
53
54
|
for (const [e, dt] of items) e.flight = { f, from: e.last - dt };
|
|
54
55
|
const t = engine.commits.request({ lag: FAR_LAG, apply: r => this.apply(f, r), fallback: () => f.snaps.map((_, i) => this.compute(f, i)) });
|
|
55
56
|
// a failed worker run is ignored: the fallback runs the same code here at the due step and throws the same (clear) error
|
package/modules/world/state.js
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
import { DEV, fmt } from '../../core/validate.js';
|
|
4
4
|
import { STRINGS as RECORD_STRINGS, restRecord, orphanIds } from './records.js';
|
|
5
5
|
import { saveWorld, loadWorld, renamePending } from './persist.js';
|
|
6
|
-
import { Cells } from '
|
|
6
|
+
import { Cells } from '../../core/cells.js';
|
|
7
7
|
import { centerOf } from './pos.js';
|
|
8
|
+
import { codedError } from '../../core/errorHints.js';
|
|
8
9
|
|
|
9
10
|
export function initState(w, cellSize) {
|
|
10
11
|
/** @internal */ w._anchor = null;
|
|
@@ -88,7 +89,7 @@ class Internals {
|
|
|
88
89
|
/** @internal */
|
|
89
90
|
_inZone(rec) { return this.zone == null || rec.zone == null || rec.zone === this.zone; }
|
|
90
91
|
/** @internal */
|
|
91
|
-
_need(id, fn) { const r = this.records.get(id); if (!r) throw
|
|
92
|
+
_need(id, fn) { const r = this.records.get(id); if (!r) throw codedError('world-record', fmt(RECORD_STRINGS.noId, { fn, id })); return r; }
|
|
92
93
|
/** Copy the original initial record and apply the changes from the save @internal */
|
|
93
94
|
_fromBase(id, base) {
|
|
94
95
|
const rec = structuredClone(base), d = this._pending.get(id);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// explain, plus idOf / view / ids / restore for the model link and undo), never the World class, so engine.thing, thing.set and the shared id space
|
|
3
3
|
// work the same whether or not this module is installed.
|
|
4
4
|
const SAY = {
|
|
5
|
-
defined: 'defined in {at}: edit it there to change the level for good (ops change only this session), or:
|
|
5
|
+
defined: 'defined in {at}: edit it there to change the level for good (ops change only this session), or: threedog content set {id} <field> <json>',
|
|
6
6
|
node: 'level {level} node {node}: change it in the level model',
|
|
7
7
|
spawned: 'made during play{op}: not in content, saved whole',
|
|
8
8
|
};
|
package/modules/world/views.js
CHANGED
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
// It only decides "which records have a model" and never affects gameplay: simulation follows the gameplay anchor (sim.js), and how fast models are built, or
|
|
5
5
|
// whether they are built, does not change simulation results.
|
|
6
6
|
import { reportError } from '../../core/errors.js';
|
|
7
|
-
import { DEV,
|
|
7
|
+
import { DEV, warnOnce } from '../../core/validate.js';
|
|
8
|
+
import { readParams, keysSchema } from '../../core/params.js';
|
|
9
|
+
import { codedError } from '../../core/errorHints.js';
|
|
8
10
|
|
|
9
11
|
const STRINGS = {
|
|
10
12
|
noBuild: 'world.present(\'{kind}\', { build }) needs build: rec => three.js object',
|
|
@@ -37,10 +39,10 @@ export class Views {
|
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
present(kind, opts) {
|
|
40
|
-
if (typeof opts?.build !== 'function') throw
|
|
42
|
+
if (typeof opts?.build !== 'function') throw codedError('world-present', say(STRINGS.noBuild, kind));
|
|
41
43
|
if (DEV) {
|
|
42
|
-
|
|
43
|
-
if (opts.positionFrom != null && opts.positionFrom !== 'record' && opts.positionFrom !== 'view') throw
|
|
44
|
+
readParams(`world.present('${kind}', opts)`, keysSchema(OPTS), opts);
|
|
45
|
+
if (opts.positionFrom != null && opts.positionFrom !== 'record' && opts.positionFrom !== 'view') throw codedError('world-present', say(STRINGS.positionFrom, kind));
|
|
44
46
|
if (opts.dispose?.length === 1) warnOnce(say(STRINGS.disposeArgs, kind));
|
|
45
47
|
}
|
|
46
48
|
const old = this.presenters.get(kind);
|
|
@@ -152,7 +154,7 @@ export class Views {
|
|
|
152
154
|
this.map.set(rec.id, v);
|
|
153
155
|
const fail = err => { if (this.map.get(rec.id) === v) v.pending = false; reportError(e, err, say(STRINGS.failed, rec.kind), { soft: true }); };
|
|
154
156
|
const done = obj => {
|
|
155
|
-
if (!obj?.isObject3D) throw
|
|
157
|
+
if (!obj?.isObject3D) throw codedError('world-present', say(STRINGS.nullBuild, rec.kind, rec.id, String(obj)));
|
|
156
158
|
if (this.map.get(rec.id) !== v) { this.drop(rec, p, obj); return; } // no longer wanted by the time it was built
|
|
157
159
|
v.obj = obj; v.pending = false; this.byObj.set(obj, rec.id);
|
|
158
160
|
if (p.positionFrom === 'view') this.moving.add(rec.id);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "threedog",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Web 3D game engine on three.js
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "Web 3D game engine on three.js: core + optional modules, no built-in art (the look comes from your own style), built to be driven by an AI",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"url": "https://github.com/penstic123-code/ThreeDog.js-Game-Engine/issues"
|
|
14
14
|
},
|
|
15
15
|
"engines": {
|
|
16
|
-
"node": "
|
|
16
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
17
17
|
},
|
|
18
18
|
"type": "module",
|
|
19
19
|
"main": "./index.js",
|
|
@@ -24,10 +24,15 @@
|
|
|
24
24
|
"default": "./index.js"
|
|
25
25
|
},
|
|
26
26
|
"./error-hints": "./core/errorHints.js",
|
|
27
|
+
"./grid": "./core/grid.js",
|
|
27
28
|
"./worker": {
|
|
28
29
|
"types": "./types/worker.d.ts",
|
|
29
30
|
"default": "./core/threadServe.js"
|
|
30
31
|
},
|
|
32
|
+
"./tsl": {
|
|
33
|
+
"types": "./types/tsl.d.ts",
|
|
34
|
+
"default": "./render/fx/index.js"
|
|
35
|
+
},
|
|
31
36
|
"./package.json": "./package.json"
|
|
32
37
|
},
|
|
33
38
|
"files": [
|