threedog 0.7.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +411 -1
- package/README.md +8 -11
- package/core/{Animator.js → assets/Animator.js} +30 -18
- package/core/{Assets.js → assets/Assets.js} +131 -56
- package/core/{Baked.js → assets/Baked.js} +4 -4
- package/core/assets/assetEntry.js +302 -0
- package/core/{assetHot.js → assets/assetHot.js} +9 -7
- package/core/{assetLoad.js → assets/assetLoad.js} +55 -16
- package/core/assets/assetLod.js +113 -0
- package/core/{assetManifest.js → assets/assetManifest.js} +19 -11
- package/core/{assetReport.js → assets/assetReport.js} +7 -14
- package/core/{namedModel.js → assets/namedModel.js} +17 -13
- package/core/{Audio.js → audio/Audio.js} +47 -25
- package/core/{audioRules.js → audio/audioRules.js} +8 -5
- package/core/{audioVoice.js → audio/audioVoice.js} +17 -30
- package/core/{Events.js → base/Events.js} +3 -3
- package/core/{I18n.js → base/I18n.js} +15 -12
- package/core/{Random.js → base/Random.js} +7 -4
- package/core/{Vars.js → base/Vars.js} +14 -4
- package/core/{easing.js → base/easing.js} +1 -1
- package/core/{errorCodes.js → base/errorCodes.js} +151 -125
- package/core/{errorHints.js → base/errorHints.js} +17 -10
- package/core/{errors.js → base/errors.js} +12 -10
- package/core/{events.generated.js → base/events.generated.js} +11 -0
- package/core/base/follows.js +26 -0
- package/core/base/math.js +66 -0
- package/core/{params.js → base/params.js} +5 -6
- package/core/base/saveValues.js +81 -0
- package/core/base/sections.js +97 -0
- package/core/base/spelling.js +32 -0
- package/core/base/util.js +32 -0
- package/core/{validate.js → base/validate.js} +34 -34
- package/core/{Engine.js → engine/Engine.js} +137 -91
- package/core/{Loading.js → engine/Loading.js} +34 -5
- package/core/{copies.js → engine/copies.js} +4 -4
- package/core/{headlessLoad.js → engine/headlessLoad.js} +32 -15
- package/core/{lifecycle.js → engine/lifecycle.js} +41 -34
- package/core/{loop.js → engine/loop.js} +88 -49
- package/core/engine/moduleSlots.js +176 -0
- package/core/{moduleTypes.js → engine/moduleTypes.js} +26 -14
- package/core/engine/modules.js +503 -0
- package/core/{page.js → engine/page.js} +59 -29
- package/core/{plugins.js → engine/plugins.js} +21 -12
- package/core/{services.js → engine/services.js} +50 -40
- package/core/{startup.js → engine/startup.js} +66 -54
- package/core/{Input.js → input/Input.js} +67 -39
- package/core/{inputContext.js → input/inputContext.js} +14 -5
- package/core/input/inputKeyboard.js +39 -0
- package/core/{inputPad.js → input/inputPad.js} +24 -3
- package/core/{inputPointer.js → input/inputPointer.js} +11 -3
- package/core/input/inputSeat.js +66 -0
- package/core/{inputTouch.js → input/inputTouch.js} +24 -7
- package/core/{Budget.js → inspect/Budget.js} +21 -20
- package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +43 -18
- package/core/{Describe.js → inspect/Describe.js} +34 -26
- package/core/{Inspect.js → inspect/Inspect.js} +39 -10
- package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +7 -8
- package/core/{InspectPerf.js → inspect/InspectPerf.js} +19 -13
- package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
- package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +3 -2
- package/core/{UrlState.js → inspect/UrlState.js} +60 -24
- package/core/{catalog.js → inspect/catalog.js} +15 -8
- package/core/{checks.js → inspect/checks.js} +7 -5
- package/core/{debugView.js → inspect/debugView.js} +4 -4
- package/core/{describeRender.js → inspect/describeRender.js} +24 -22
- package/core/{describeText.js → inspect/describeText.js} +17 -8
- package/core/inspect/geometryWatch.js +38 -0
- package/core/{lightWatch.js → inspect/lightWatch.js} +8 -8
- package/core/inspect/metadata.generated.js +4140 -0
- package/core/{pictureWriters.js → inspect/pictureWriters.js} +130 -47
- package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
- package/core/inspect/toolDoor.js +21 -0
- package/core/inspect/valueHistory.js +35 -0
- package/core/{Ops.js → ops/Ops.js} +44 -14
- package/core/{control.js → ops/control.js} +57 -31
- package/core/ops/holds.js +140 -0
- package/core/{opsAtomic.js → ops/opsAtomic.js} +18 -5
- package/core/{opsCheck.js → ops/opsCheck.js} +11 -10
- package/core/{opsFail.js → ops/opsFail.js} +5 -7
- package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
- package/core/{opsRun.js → ops/opsRun.js} +9 -6
- package/core/{owned.js → ops/owned.js} +33 -19
- package/core/{sharedPoint.js → ops/sharedPoint.js} +13 -16
- package/core/{stackFrames.js → ops/stackFrames.js} +2 -2
- package/core/{stacks.js → ops/stacks.js} +34 -15
- package/core/{wrap.js → ops/wrap.js} +8 -6
- package/core/{SaveStore.js → saves/SaveStore.js} +53 -27
- package/core/{Saves.js → saves/Saves.js} +171 -54
- package/core/saves/saveApply.js +312 -0
- package/core/{saveFiles.js → saves/saveFiles.js} +45 -38
- package/core/{saveVersions.js → saves/saveVersions.js} +24 -23
- package/core/saves/session.js +231 -0
- package/core/saves/stateReplace.js +184 -0
- package/core/{Rays.js → scene/Rays.js} +44 -30
- package/core/{Views.js → scene/Views.js} +16 -8
- package/core/{adaptive.js → scene/adaptive.js} +19 -9
- package/core/{canvasBox.js → scene/canvasBox.js} +4 -3
- package/core/scene/compositeGround.js +72 -0
- package/core/scene/floor.js +17 -0
- package/core/{gameLights.js → scene/gameLights.js} +17 -7
- package/core/{grayMap.js → scene/grayMap.js} +8 -2
- package/core/{grid.js → scene/grid.js} +6 -4
- package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
- package/core/scene/ground.contract.js +14 -0
- package/core/scene/ground.js +139 -0
- package/core/{movement.js → scene/movement.js} +3 -3
- package/core/{pictureSlots.js → scene/pictureSlots.js} +2 -2
- package/core/scene/pixel.js +154 -0
- package/core/scene/pixelRatio.js +167 -0
- package/core/{sceneDelta.js → scene/sceneDelta.js} +5 -5
- package/core/{sceneMethods.js → scene/sceneMethods.js} +43 -15
- package/core/scene/stepPoses.js +60 -0
- package/core/{targeting.js → scene/targeting.js} +4 -5
- package/core/{thingExplain.js → scene/thingExplain.js} +7 -6
- package/core/{thingOps.js → scene/thingOps.js} +25 -16
- package/core/{things.js → scene/things.js} +18 -5
- package/core/{threePatches.js → scene/threePatches.js} +1 -1
- package/core/{tier.js → scene/tier.js} +10 -0
- package/core/scene/view.js +161 -0
- package/core/{Batching.js → stream/Batching.js} +85 -28
- package/core/{Stream.js → stream/Stream.js} +80 -38
- package/core/{batchGroups.js → stream/batchGroups.js} +11 -9
- package/core/{chunkStream.js → stream/chunkStream.js} +40 -0
- package/core/{scatter.js → stream/scatter.js} +7 -4
- package/core/{streamSources.js → stream/streamSources.js} +14 -8
- package/core/{Commits.js → threads/Commits.js} +17 -11
- package/core/{Jobs.js → threads/Jobs.js} +25 -13
- package/core/{Threads.js → threads/Threads.js} +21 -18
- package/core/{threadPure.js → threads/threadPure.js} +7 -5
- package/core/{threadServe.js → threads/threadServe.js} +3 -3
- package/core/{Clock.js → time/Clock.js} +20 -11
- package/core/{dayTime.js → time/dayTime.js} +5 -1
- package/core/{skip.js → time/skip.js} +28 -21
- package/core/{time.js → time/time.js} +32 -20
- package/core/{uiClock.js → time/uiClock.js} +4 -4
- package/docs/AI.md +92 -72
- package/docs/API.md +33 -28
- package/docs/CODEMAP.md +121 -200
- package/docs/COMMANDS.md +77 -70
- package/docs/CONVENTIONS.md +167 -24
- package/docs/MIGRATING-0.8.md +171 -0
- package/docs/MIGRATING-1.0.md +101 -0
- package/docs/THREE.md +140 -38
- package/docs/api/assets.md +12 -13
- package/docs/api/audio.md +6 -5
- package/docs/api/budget.md +4 -4
- package/docs/api/calendar.md +10 -11
- package/docs/api/cameraRig.md +32 -29
- package/docs/api/characters.md +35 -24
- package/docs/api/clock.md +1 -1
- package/docs/api/collider3d.md +9 -0
- package/docs/api/collision.md +12 -9
- package/docs/api/content.md +18 -17
- package/docs/api/dialogue.md +5 -4
- package/docs/api/engine.md +58 -54
- package/docs/api/events.md +17 -6
- package/docs/api/flow.md +1 -1
- package/docs/api/grids.md +1 -1
- package/docs/api/ground.md +6 -7
- package/docs/api/hud.md +2 -2
- package/docs/api/i18n.md +6 -6
- package/docs/api/input.md +9 -8
- package/docs/api/interactions.md +5 -5
- package/docs/api/inventory.md +10 -10
- package/docs/api/jobs.md +5 -5
- package/docs/api/level.md +10 -9
- package/docs/api/lightPool.md +1 -6
- package/docs/api/music.md +3 -3
- package/docs/api/nav.md +14 -12
- package/docs/api/openWorld.md +1 -1
- package/docs/api/particles.md +10 -7
- package/docs/api/photo.md +4 -2
- package/docs/api/pickups.md +3 -3
- package/docs/api/post.md +21 -5
- package/docs/api/quests.md +7 -5
- package/docs/api/rays.md +7 -7
- package/docs/api/rigid.md +29 -19
- package/docs/api/saves.md +13 -11
- package/docs/api/settings.md +9 -8
- package/docs/api/sky.md +8 -7
- package/docs/api/stream.md +8 -9
- package/docs/api/swarm.md +34 -0
- package/docs/api/terrain.md +6 -8
- package/docs/api/terrainDraw.md +2 -2
- package/docs/api/timeline.md +4 -4
- package/docs/api/tools.md +27 -22
- package/docs/api/triggers.md +2 -0
- package/docs/api/vars.md +1 -1
- package/docs/api/vegetation.md +4 -3
- package/docs/api/vegetationDraw.md +2 -2
- package/docs/api/water.md +7 -3
- package/docs/api/weather.md +27 -12
- package/docs/api/weatherDraw.md +4 -4
- package/docs/api/world.md +6 -6
- package/docs/recipes/01-new-game.md +28 -43
- package/docs/recipes/02-npc.md +21 -23
- package/docs/recipes/03-items-pickups.md +37 -53
- package/docs/recipes/04-quests.md +5 -4
- package/docs/recipes/05-props-bake.md +34 -44
- package/docs/recipes/06-clock-events.md +31 -22
- package/docs/recipes/07-flow-scenes-pause.md +30 -32
- package/docs/recipes/08-weather-sky.md +91 -37
- package/docs/recipes/09-materials-lights-models.md +25 -39
- package/docs/recipes/10-blender-level.md +22 -11
- package/docs/recipes/11-vehicles.md +44 -24
- package/docs/recipes/12-navmesh.md +60 -15
- package/docs/recipes/13-animation.md +70 -22
- package/docs/recipes/14-custom-module.md +33 -20
- package/docs/recipes/15-perf.md +51 -28
- package/docs/recipes/16-dev-bridge.md +39 -58
- package/docs/recipes/18-world.md +49 -28
- package/docs/recipes/19-shooting-picking.md +7 -4
- package/docs/recipes/20-content-actions-save.md +55 -40
- package/docs/recipes/21-camera.md +47 -25
- package/docs/recipes/22-shop-gold.md +21 -16
- package/docs/recipes/23-ops.md +28 -24
- package/docs/recipes/26-ui-parts.md +25 -14
- package/docs/recipes/27-net.md +3 -5
- package/docs/recipes/28-terrain.md +119 -23
- package/docs/recipes/29-grid.md +3 -3
- package/docs/recipes/30-templates.md +63 -30
- package/docs/recipes/31-audio.md +7 -7
- package/docs/recipes/32-action-game.md +21 -11
- package/docs/recipes/33-stream-sources.md +6 -3
- package/docs/recipes/34-environment-lighting.md +72 -25
- package/docs/recipes/35-picture-from-reference.md +20 -23
- package/docs/recipes/36-ground-plants.md +106 -0
- package/docs/recipes/40-scene.md +18 -21
- package/docs/recipes/43-shader-patches-surfaces.md +27 -48
- package/docs/recipes/44-water-weather-hooks.md +56 -50
- package/docs/recipes/45-cascaded-shadows.md +41 -20
- package/docs/recipes/46-blender-art-route.md +9 -10
- package/docs/recipes/49-game-module-contract.md +7 -6
- package/docs/recipes/50-own-renderer.md +3 -2
- package/docs/recipes/51-capability-catalog.md +14 -8
- package/docs/recipes/52-around-the-picture.md +56 -100
- package/docs/recipes/53-ground-up-close.md +61 -24
- package/docs/recipes/55-mods-time-wrap.md +17 -20
- package/docs/recipes/56-webgpu-tsl.md +28 -15
- package/docs/recipes/57-control.md +39 -12
- package/docs/recipes/58-input.md +15 -2
- package/docs/recipes/59-depth-post-effects.md +1 -1
- package/docs/recipes/60-judge-the-picture.md +30 -25
- package/docs/recipes/62-picture-code.md +129 -39
- package/docs/recipes/63-third-person-start.md +19 -5
- package/docs/recipes/64-particles.md +54 -5
- package/docs/recipes/65-swarm.md +140 -0
- package/docs/recipes/66-common-tasks.md +313 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +5 -5
- package/examples/perf-island/.threedog/content-index.json +1 -0
- package/examples/{sheepisland → perf-island}/GAMEMAP.md +15 -14
- package/examples/{sheepisland → perf-island}/assets.js +1 -1
- package/examples/{sheepisland → perf-island}/main.js +8 -8
- package/examples/{sheepisland → perf-island}/models.js +1 -1
- package/examples/{sheepisland → perf-island}/params.js +1 -1
- package/examples/{sheepisland → perf-island}/picture/index.js +1 -1
- package/examples/{sheepisland → perf-island}/picture/palette.js +2 -2
- package/examples/{sheepisland → perf-island}/views.js +1 -1
- package/examples/plain-picture/GAMEMAP.md +4 -1
- package/examples/rc2d/GAMEMAP.md +4 -3
- package/examples/rc2d/main.js +1 -3
- package/examples/rc2d/rc2d.js +1 -1
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +6 -5
- package/examples/techniques/contact-shadows/contactShadows.js +1 -1
- package/examples/techniques/contact-shadows/main.js +1 -1
- package/examples/techniques/interior-light/main.js +1 -1
- package/examples/techniques/modular-building/README.md +7 -6
- package/examples/techniques/outlines-and-rim/picture/post.js +1 -1
- package/examples/techniques/procedural-animation/README.md +1 -1
- package/examples/webgpu-tsl/GAMEMAP.md +2 -1
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +9 -7
- package/examples/world/main.js +3 -3
- package/examples/world/picture/sky.js +1 -1
- package/index.d.ts +16 -12
- package/index.js +53 -32
- package/llms.txt +11 -14
- package/modules/ambience/Ambience.js +16 -11
- package/modules/calendar/Calendar.js +19 -19
- package/modules/calendar/index.js +18 -16
- package/modules/calendar/schedule.js +11 -6
- package/modules/calendar/seasons.js +7 -7
- package/modules/camera/FirstPersonCamera.js +5 -5
- package/modules/camera/FixedCamera.js +43 -30
- package/modules/camera/FollowCamera.js +24 -15
- package/modules/camera/RtsCamera.js +12 -11
- package/modules/camera/common.js +72 -37
- package/modules/camera/contract.js +1 -0
- package/modules/camera/pixelSnap.js +62 -0
- package/modules/characters/Character.js +166 -70
- package/modules/characters/NPC.js +84 -44
- package/modules/characters/assetModel.js +16 -12
- package/modules/characters/astar.js +48 -27
- package/modules/characters/behaviors.js +4 -5
- package/modules/characters/character.contract.js +21 -0
- package/modules/characters/contract.js +17 -3
- package/modules/characters/index.js +240 -226
- package/modules/characters/moveHelpers.js +88 -12
- package/modules/characters/mover.contract.js +14 -0
- package/modules/characters/movers/common.js +22 -18
- package/modules/characters/movers/manual.js +1 -1
- package/modules/characters/movers/rapier.js +18 -10
- package/modules/characters/movers/simple.js +26 -13
- package/modules/characters/movers/support.js +24 -13
- package/modules/characters/npcAvoid.js +19 -16
- package/modules/characters/npcSim.js +88 -32
- package/modules/characters/npcView.js +19 -11
- package/modules/characters/pathAsync.js +81 -29
- package/modules/characters/pathJob.js +38 -21
- package/modules/characters/pathWorker.js +1 -1
- package/modules/characters/player.js +120 -0
- package/modules/characters/playerStrings.js +2 -2
- package/modules/characters/proceduralRig.js +2 -2
- package/modules/characters/seat.js +56 -0
- package/modules/characters/useModel.js +3 -3
- package/modules/characters/vehicle.contract.js +8 -5
- package/modules/characters/walkTo.js +40 -33
- package/modules/collision/Collision.js +69 -45
- package/modules/collision/contract.js +15 -0
- package/modules/collision/grid.js +6 -1
- package/modules/content/explain.js +2 -3
- package/modules/content/fields.js +24 -3
- package/modules/content/ids.js +5 -3
- package/modules/content/index.js +132 -114
- package/modules/content/loader.js +117 -140
- package/modules/content/markers.js +25 -0
- package/modules/content/models.js +54 -17
- package/modules/content/packs.js +5 -4
- package/modules/content/parts.js +2 -2
- package/modules/content/places.js +36 -0
- package/modules/content/props.js +22 -17
- package/modules/content/rules.js +47 -61
- package/modules/content/stages.js +7 -7
- package/modules/content/templates.js +80 -49
- package/modules/content/words.js +47 -0
- package/modules/debug/DebugPanel.js +14 -45
- package/modules/flow/contract.js +2 -1
- package/modules/flow/index.js +30 -16
- package/modules/gameplay/Container.js +17 -13
- package/modules/gameplay/Containers.js +23 -6
- package/modules/gameplay/Dialogue.js +93 -34
- package/modules/gameplay/Interactions.js +93 -51
- package/modules/gameplay/Inventory.js +64 -22
- package/modules/gameplay/Quests.js +146 -30
- package/modules/gameplay/boxOps.js +8 -1
- package/modules/gameplay/dialogueBubbles.js +16 -12
- package/modules/gameplay/inventoryOps.js +11 -8
- package/modules/gameplay/pickups.js +63 -37
- package/modules/gameplay/questLog.js +4 -2
- package/modules/gameplay/questSave.js +9 -4
- package/modules/gameplay/quests.contract.js +1 -1
- package/modules/grid/Grid.js +2 -2
- package/modules/grid/Layer.js +12 -8
- package/modules/grid/index.js +28 -23
- package/modules/grid/ops.js +43 -46
- package/modules/grid/preview.js +7 -7
- package/modules/grid/tiles.js +6 -6
- package/modules/hlod/index.js +42 -57
- package/modules/hud/index.js +22 -14
- package/modules/hud/parts.js +8 -8
- package/modules/level/contract.js +16 -0
- package/modules/level/heightfield.js +29 -31
- package/modules/level/index.js +113 -161
- package/modules/level/load.js +196 -0
- package/modules/level/meshes.js +65 -0
- package/modules/level/nodes.js +40 -23
- package/modules/lights/index.js +33 -183
- package/modules/lights/slots.js +93 -0
- package/modules/lights/sources.js +90 -0
- package/modules/music/Music.js +34 -28
- package/modules/music/rules.js +1 -1
- package/modules/nav/contract.js +16 -0
- package/modules/nav/index.js +180 -49
- package/modules/nav/navPath.js +45 -10
- package/modules/net/Client.js +7 -7
- package/modules/net/Host.js +7 -7
- package/modules/net/Net.js +1 -1
- package/modules/net/index.js +6 -5
- package/modules/net/sync.js +2 -2
- package/modules/net/transports.js +2 -2
- package/modules/particles/Particles.js +95 -29
- package/modules/particles/effect.js +86 -32
- package/modules/particles/shaders.js +19 -1
- package/modules/photo/Photo.js +23 -23
- package/modules/rigid/RigidBodies.js +255 -89
- package/modules/rigid/Vehicles.js +17 -8
- package/modules/rigid/collider3d.contract.js +26 -0
- package/modules/rigid/ragdoll.js +298 -0
- package/modules/rigid/ragdollBones.js +209 -0
- package/modules/rigid/refresh.js +10 -0
- package/modules/rigid/sync.js +51 -20
- package/modules/settings/Settings.js +177 -61
- package/modules/settings/apply.js +20 -13
- package/modules/settings/sections.js +19 -14
- package/modules/settings/strings.js +2 -2
- package/modules/settings/view.js +3 -3
- package/modules/sky/Sky.js +29 -22
- package/modules/sky/clouds.js +7 -7
- package/modules/sky/dome.js +33 -20
- package/modules/sky/domeLayers.js +9 -9
- package/modules/sky/environment.js +6 -6
- package/modules/sky/frame.js +19 -10
- package/modules/sky/season.js +7 -1
- package/modules/sky/shader.js +24 -25
- package/modules/sky/skyModule.js +17 -28
- package/modules/sky/tint.js +1 -1
- package/modules/swarm/Swarm.js +356 -0
- package/modules/swarm/draw.js +68 -0
- package/modules/swarm/grid.js +63 -0
- package/modules/terrain/ChunkManager.js +71 -59
- package/modules/terrain/chunkQueries.js +7 -24
- package/modules/terrain/chunkWorker.js +1 -1
- package/modules/terrain/draw.js +14 -11
- package/modules/terrain/index.js +42 -42
- package/modules/terrain/terrainColorMap.js +6 -3
- package/modules/terrain/terrainDefaults.js +2 -1
- package/modules/terrain/terrainEdit.js +45 -29
- package/modules/terrain/terrainGen.js +19 -12
- package/modules/terrain/terrainIsland.js +2 -2
- package/modules/terrain/terrainMesh.js +7 -6
- package/modules/terrain/terrainShape.js +8 -10
- package/modules/terrain/terrainShapeMain.js +3 -3
- package/modules/timeline/Timeline.js +83 -43
- package/modules/timeline/Tween.js +25 -19
- package/modules/timeline/shots.js +24 -17
- package/modules/triggers/index.js +95 -28
- package/modules/vegetation/Vegetation.js +34 -26
- package/modules/vegetation/densityMap.js +4 -7
- package/modules/vegetation/draw.js +39 -18
- package/modules/vegetation/groundChunks.js +21 -38
- package/modules/vegetation/index.js +37 -12
- package/modules/vegetation/modelGeometry.js +3 -6
- package/modules/vegetation/nearFade.js +1 -1
- package/modules/water/Water.js +20 -16
- package/modules/water/surface.js +3 -3
- package/modules/weather/Weather.js +52 -40
- package/modules/weather/particles.js +8 -8
- package/modules/weather/weatherDraw.js +28 -23
- package/modules/world/World.js +28 -15
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +30 -17
- package/modules/world/persist.js +90 -27
- package/modules/world/pos.js +5 -5
- package/modules/world/records.js +37 -11
- package/modules/world/sim.js +78 -27
- package/modules/world/simFar.js +2 -2
- package/modules/world/state.js +43 -11
- package/modules/world/thingSource.js +20 -5
- package/modules/world/views.js +27 -14
- package/package.json +48 -7
- package/presets.js +1 -3
- package/render/PostFX.js +83 -53
- package/render/backend.js +31 -33
- package/render/cascades.js +17 -12
- package/render/cascades.tsl.js +5 -8
- package/render/daylight.js +20 -3
- package/render/detail.js +8 -7
- package/render/effects.js +28 -25
- package/render/fuse.js +3 -3
- package/render/fx/cloudShadow.tsl.js +3 -3
- package/render/fx/detail.tsl.js +1 -1
- package/render/fx/index.js +5 -10
- package/render/fx/library.tsl.js +11 -0
- package/render/fx/lighting.tsl.js +2 -1
- package/render/fx/nodeErrors.tsl.js +2 -2
- package/render/fx/objectOrigin.tsl.js +1 -2
- package/render/fx/particles.tsl.js +8 -6
- package/render/fx/patchNodes.tsl.js +5 -15
- package/render/fx/postWebGPU.tsl.js +30 -26
- package/render/fx/sky.tsl.js +15 -17
- package/render/fx/uniforms.tsl.js +4 -4
- package/render/fx/wind.tsl.js +1 -1
- package/render/fxNumbers.js +3 -0
- package/render/layers.js +2 -2
- package/render/lighting.js +5 -3
- package/render/lightmap.js +41 -21
- package/render/lights.js +6 -6
- package/render/lit.js +24 -0
- package/render/materials.js +8 -7
- package/render/mergeCommon.js +22 -0
- package/render/modeling.js +2 -2
- package/render/occlusion.js +62 -15
- package/render/ownFrame.js +4 -4
- package/render/patches.js +15 -15
- package/render/postWebGL.js +15 -12
- package/render/probes.js +41 -19
- package/render/recordSweep.js +117 -0
- package/render/shaderErrors.js +10 -9
- package/render/shadowCache.tsl.js +107 -0
- package/render/shadowTypes.js +9 -0
- package/{core → render}/shadows.js +59 -13
- package/render/slots.js +7 -7
- package/render/terms.js +22 -24
- package/render/uniformDecl.js +1 -1
- package/types/core.d.ts +336 -202
- package/types/gameplay.d.ts +254 -130
- package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +22 -7
- package/types/generated/core/{audioVoice.d.ts → audio/audioVoice.d.ts} +2 -2
- package/types/generated/core/{Events.d.ts → base/Events.d.ts} +4 -4
- package/types/generated/core/{I18n.d.ts → base/I18n.d.ts} +8 -16
- package/types/generated/core/{Random.d.ts → base/Random.d.ts} +4 -3
- package/types/generated/core/{page.d.ts → engine/page.d.ts} +8 -9
- package/types/generated/core/{Input.d.ts → input/Input.d.ts} +28 -10
- package/types/generated/core/input/inputSeat.d.ts +26 -0
- package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
- package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +17 -3
- package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +6 -4
- package/types/generated/core/{control.d.ts → ops/control.d.ts} +14 -10
- package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +62 -18
- package/types/generated/core/{session.d.ts → saves/session.d.ts} +3 -2
- package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
- package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +2 -2
- package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
- package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +22 -18
- package/types/generated/core/{Commits.d.ts → threads/Commits.d.ts} +1 -1
- package/types/generated/core/{Jobs.d.ts → threads/Jobs.d.ts} +6 -6
- package/types/generated/core/{Threads.d.ts → threads/Threads.d.ts} +4 -4
- package/types/generated/modules/calendar/Calendar.d.ts +10 -11
- package/types/generated/modules/debug/DebugPanel.d.ts +1 -9
- package/types/generated/modules/grid/Grid.d.ts +1 -0
- package/types/generated/modules/grid/Layer.d.ts +1 -1
- package/types/generated/modules/grid/index.d.ts +3 -3
- package/types/generated/modules/music/Music.d.ts +7 -5
- package/types/generated/modules/particles/Particles.d.ts +5 -4
- package/types/generated/modules/sky/Sky.d.ts +21 -10
- package/types/generated/modules/swarm/Swarm.d.ts +80 -0
- package/types/generated/modules/timeline/Timeline.d.ts +7 -5
- package/types/generated/modules/water/Water.d.ts +1 -0
- package/types/generated/modules/weather/Weather.d.ts +14 -16
- package/types/generated/modules/weather/weatherDraw.d.ts +3 -3
- package/types/generated/modules/world/World.d.ts +11 -7
- package/types/generated/render/PostFX.d.ts +21 -23
- package/types/generated/render/materials.d.ts +1 -0
- package/types/generated/render/occlusion.d.ts +9 -0
- package/types/generated/render/patches.d.ts +1 -0
- package/types/generated/ui/Focus.d.ts +1 -0
- package/types/generated/ui/UI.d.ts +1 -0
- package/types/nav.d.ts +47 -15
- package/types/physics.d.ts +150 -73
- package/types/pixel.d.ts +75 -0
- package/types/tsl.d.ts +37 -4
- package/types/world.d.ts +48 -75
- package/ui/Focus.js +10 -9
- package/ui/Parts.js +13 -5
- package/ui/UI.js +7 -7
- package/ui/defaults.js +3 -2
- package/ui/theme.js +7 -5
- package/core/assetEntry.js +0 -109
- package/core/engineCamera.js +0 -32
- package/core/ground.js +0 -104
- package/core/holds.js +0 -134
- package/core/math.js +0 -48
- package/core/moduleSlots.js +0 -100
- package/core/modules.js +0 -314
- package/core/saveApply.js +0 -210
- package/core/saveValues.js +0 -46
- package/core/session.js +0 -174
- package/core/shadowTypes.js +0 -16
- package/core/util.js +0 -17
- package/core/view.js +0 -43
- package/docs/MIGRATING-0.3.md +0 -248
- package/docs/MIGRATING-0.4.md +0 -320
- package/docs/MIGRATING-0.5.md +0 -68
- package/docs/MIGRATING-0.6.md +0 -126
- package/docs/PERF.md +0 -245
- package/docs/recipes/36-sky-ground-plants.md +0 -158
- package/docs/recipes/37-terrain-hooks.md +0 -115
- package/docs/recipes/38-environment-hooks.md +0 -67
- package/docs/recipes/42-terrain-shape.md +0 -64
- package/docs/recipes/47-island-snow-backdrop.md +0 -43
- package/docs/recipes/54-three-idioms.md +0 -88
- package/examples/plain-picture/FINDINGS.md +0 -53
- package/examples/sheepisland/.threedog/content-index.json +0 -1
- package/modules/camera/projection.js +0 -21
- /package/core/{mulberry32.js → base/mulberry32.js} +0 -0
- /package/core/{inputDefaults.js → input/inputDefaults.js} +0 -0
- /package/core/{textureBytes.js → inspect/textureBytes.js} +0 -0
- /package/core/{actor.js → ops/actor.js} +0 -0
- /package/core/{opsHistory.js → ops/opsHistory.js} +0 -0
- /package/core/{saveIds.js → saves/saveIds.js} +0 -0
- /package/core/{screenToGround.js → scene/screenToGround.js} +0 -0
- /package/core/{cells.js → stream/cells.js} +0 -0
- /package/core/{streamCells.js → stream/streamCells.js} +0 -0
- /package/core/{pureWorker.js → threads/pureWorker.js} +0 -0
- /package/examples/{sheepisland → perf-island}/content/index.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/props.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/templates.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/vegetation.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/lights.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/materials.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/sky.js +0 -0
|
@@ -1,26 +1,102 @@
|
|
|
1
1
|
// Spawn search and the camera-relative move input (split out of index.js; the characters API calls these with its engine)
|
|
2
2
|
import * as THREE from 'three';
|
|
3
|
-
import { xzOf } from '../../core/math.js';
|
|
4
|
-
import { readParams, keysSchema } from '../../core/params.js';
|
|
3
|
+
import { xzOf, yOf } from '../../core/base/math.js';
|
|
4
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
5
|
+
import { sameFloor } from '../../core/scene/floor.js';
|
|
5
6
|
|
|
6
|
-
const REQ = { x: 0, z: 0, run: false }; // moveInput() result, reused every step (no allocation)
|
|
7
|
+
const REQ = { x: 0, y: 0, z: 0, run: false }; // moveInput() result, reused every step (no allocation)
|
|
7
8
|
|
|
8
9
|
/** Spiral outward from position for walkable dry ground (characters.findSpawn) */
|
|
9
10
|
export function findSpawn(e, position, opts) {
|
|
10
|
-
const [x, z] = xzOf(position);
|
|
11
|
+
const [x, z] = xzOf(position), y = yOf(position); // a height picks the floor, as everywhere; none: the top ground
|
|
11
12
|
readParams('characters.findSpawn()', keysSchema(['minH', 'maxH', 'maxSlope', 'waterMargin']), opts);
|
|
12
|
-
const { minH = -Infinity, maxH = Infinity, maxSlope = 0.3, waterMargin = 0.5 } = opts;
|
|
13
|
+
const { minH = -Infinity, maxH = Infinity, maxSlope = 0.3, waterMargin = 0.5 } = opts; // 0.3: a spawn wants gentler ground than walkableAt, which still applies
|
|
13
14
|
for (let r = 0; r < 4000; r += 6) {
|
|
14
|
-
const a = r * 0.37, px = x + Math.cos(a) * r, pz = z + Math.sin(a) * r, h = e.surface(px, pz);
|
|
15
|
-
const dry = h > e.waterAt(px, pz) + waterMargin, walk = !e.collision || e.collision.walkableAt(px, pz);
|
|
16
|
-
if (dry && h > minH && h < maxH && e.slope(px, pz) < maxSlope && walk) return new THREE.Vector3(px, h, pz);
|
|
15
|
+
const a = r * 0.37, px = x + Math.cos(a) * r, pz = z + Math.sin(a) * r, h = e.surface(px, pz, y);
|
|
16
|
+
const dry = h > e.waterAt(px, pz, h) + waterMargin, walk = !e.collision || e.collision.walkableAt(px, pz, undefined, y);
|
|
17
|
+
if (dry && h > minH && h < maxH && e.slope(px, pz, y) < maxSlope && walk) return new THREE.Vector3(px, h, pz);
|
|
17
18
|
}
|
|
18
|
-
return new THREE.Vector3(x, e.surface(x, z), z);
|
|
19
|
+
return new THREE.Vector3(x, e.surface(x, z, y), z);
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
/**
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Index of the path point to head for from (x, y, z), starting at i: skips points within reach and points already passed (a later point is closer), so the walker
|
|
24
|
+
* never turns back. A point more than `level` above or below is not passed, however close in x, z: on a spiral stair the next turn lies right overhead. Never skips the last point (arriving is the caller's) or a link's start (a link is crossed, not cut past). One rule for walkTo and NPCs; their stuck tests stay apart (walkTo's window has a public
|
|
25
|
+
* option, an NPC's would have to go in its save)
|
|
26
|
+
*/
|
|
27
|
+
export function nextPoint(path, i, x, y, z, reach, level) {
|
|
28
|
+
const dist = p => !sameFloor(p.y ?? y, y, level) ? Infinity : Math.hypot(p.x - x, p.z - z); // p.y: a path saved before paths kept height has none
|
|
29
|
+
while (i < path.length - 1 && !path[i].link && dist(path[i]) < Infinity && (dist(path[i]) < reach || dist(path[i + 1]) < dist(path[i]))) i++;
|
|
30
|
+
return i;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The up part of the unit direction from p to q, what a walk hands a mover as y: built-in movers leave height to the ground, a flying one follows it */
|
|
34
|
+
export const climbTo = (p, q) => { const dy = (q.y ?? p.y) - p.y, d = Math.hypot(q.x - p.x, dy, q.z - p.z); return d > 1e-6 ? dy / d : 0; };
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Whether p stands at the height a goal asks for: within a body height of it, or of the floor that height picks. The second half is why a stop written [x, 0, z] on raised
|
|
38
|
+
* terrain still counts: the height field has one layer, so y only ever picks that. No y on the goal: any height. One rule for walkTo and NPC stops
|
|
39
|
+
*/
|
|
40
|
+
export function sameLevel(e, p, at) {
|
|
41
|
+
const y = yOf(at), h = e.movement.height;
|
|
42
|
+
if (y === undefined || sameFloor(p.y, y, h)) return true;
|
|
43
|
+
const [x, z] = xzOf(at);
|
|
44
|
+
return sameFloor(p.y, e.surface(x, z, y), h);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Give the points of a path that came without height (A*, a game's path source) theirs, in place: each from the ground under it, the height before it choosing the layer;
|
|
49
|
+
* the last takes the goal's given height. Here and not in the search: the worker that runs A* has no ground
|
|
50
|
+
*/
|
|
51
|
+
export function withHeights(e, path, from, to) {
|
|
52
|
+
let ref = yOf(from);
|
|
53
|
+
const gy = yOf(to);
|
|
54
|
+
path.forEach((q, i) => {
|
|
55
|
+
if (!Number.isFinite(q.y)) { const y = i === path.length - 1 && gy !== undefined ? gy : e.surface(q.x, q.z, ref); q.y = Number.isFinite(y) ? y : ref ?? 0; } // the void of terrain({ shape }) is -Infinity
|
|
56
|
+
ref = q.y;
|
|
57
|
+
});
|
|
58
|
+
return path;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Crossing a link (nav({ links })), one rule for NPCs and walkTo. The walker leaves its mover for the crossing: no gravity, no ground, its place comes from the
|
|
62
|
+
// crossing alone, so the plain data { link, from, to, seconds, time } is the whole state and a save taken halfway goes on from the same spot.
|
|
63
|
+
// The look is the game's: link:enter is the moment to play a clip and set crossing.seconds, characters.linkPose bends the line. A game doing neither gets a straight
|
|
64
|
+
// line at walking speed.
|
|
65
|
+
|
|
66
|
+
/** How near a link's start a walker must come before it crosses (m): a crossing runs from where the walker stands, so a far one starts a climb off the ladder's foot */
|
|
67
|
+
export const LINK_REACH = 0.3;
|
|
68
|
+
/** Begin crossing a path point's link from where the character stands; returns the crossing for the caller to keep */
|
|
69
|
+
export function startLink(ch, { id, to }) {
|
|
70
|
+
ch._place(ch.root.position); // off any platform: nothing may carry it during the crossing
|
|
71
|
+
const p = ch.root.position, crossing = { link: id, from: { x: p.x, y: p.y, z: p.z }, to, seconds: Math.hypot(to.x - p.x, to.y - p.y, to.z - p.z) / ch.stat('speed'), time: 0 };
|
|
72
|
+
ch.face(to); ch.velocity.set(0, 0); ch.vy = 0; ch.grounded = false;
|
|
73
|
+
ch.engine.events.emit('link:enter', { id: ch.id, character: ch, crossing });
|
|
74
|
+
if (!(crossing.seconds > 0 && crossing.seconds < Infinity)) crossing.seconds = 0; // speed 0 (a move.speed mod that roots it) or a game's bad value: a crossing always ends, and Infinity would not survive a save
|
|
75
|
+
return crossing;
|
|
76
|
+
}
|
|
77
|
+
/** One step of a crossing: true once it has landed */
|
|
78
|
+
export function stepLink(ch, c, dt) {
|
|
79
|
+
c.time += dt;
|
|
80
|
+
const t = c.seconds > 0 ? c.time / c.seconds : 1, p = ch.root.position, { from: a, to: b } = c;
|
|
81
|
+
if (t >= 1) return landLink(ch, c);
|
|
82
|
+
p.set(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t, a.z + (b.z - a.z) * t);
|
|
83
|
+
ch.engine.characters.linkPose?.(t, p, c, ch);
|
|
84
|
+
ch.syncRecord();
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Put the character at the far end now: the crossing ran out, its walk was cancelled, or a control holder above took the body. A holder pauses what is below it, but a
|
|
89
|
+
* crossing cannot wait paused: the body would hang over the gap, and picking the crossing up later would snap it back to the line. Returns true, as stepLink does on landing
|
|
90
|
+
*/
|
|
91
|
+
export function landLink(ch, c) { ch._place(c.to); ch.grounded = true; leaveLink(ch.engine, ch.id, ch, c); return true; }
|
|
92
|
+
/** Whether a link is still to cross on the path from point i on. Arriving is judged in x, z, which says nothing about a ladder's height: the walker is not there yet */
|
|
93
|
+
export const linkAhead = (path, i = 0) => !!path?.some((p, k) => k >= i && p.link);
|
|
94
|
+
/** A crossing is over, landed or cut short. character: null for an NPC that finished it without a model */
|
|
95
|
+
export function leaveLink(e, id, character, crossing) { e.events.emit('link:exit', { id, character, crossing }); }
|
|
96
|
+
|
|
97
|
+
/** The 'camera' player control as a value (characters.moveInput), read from a seat or engine.input; returns the reused REQ */
|
|
98
|
+
export function moveInput(e, inp = e.input) {
|
|
99
|
+
const a = inp.autopilot || inp.axis; // autopilot (stress tests, recordings): input.autopilot = { x, y, speed? } (speed: the player hook mods move.speed)
|
|
24
100
|
const f = e.cameraRig ? e.cameraRig.forward() : { x: 0, z: -1 }, rt = e.cameraRig ? e.cameraRig.right() : { x: 1, z: 0 };
|
|
25
101
|
// run is the game's key, not a core default
|
|
26
102
|
REQ.x = f.x * a.y + rt.x * a.x; REQ.z = f.z * a.y + rt.z * a.x; REQ.run = inp.actions.has('run') && inp.down('run');
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// What a game's mover must be (fields: see gameplay/inventory.contract.js; shared check: @threedog/tools/contract). Built by (character, engine) => mover, once per character.
|
|
2
|
+
// move(x, z, run, dt, y) every step the character moves: x, z the direction (length 0-1 scales the speed), y up or down, default 0. It writes character.root.position
|
|
3
|
+
// name what describe().player.mover shows
|
|
4
|
+
// dispose() optional: the character is gone, release what the mover built
|
|
5
|
+
// leave() optional: another mover took over; take out of the world what this one keeps there. Its move() runs again when it is back
|
|
6
|
+
// Contact is the mover's to take or leave: engine.characters.kit (beginMove, groundAt, endMove, ownState). Calling none of it means the mover owns grounded, platforms and the fall check.
|
|
7
|
+
export default {
|
|
8
|
+
name: 'mover',
|
|
9
|
+
kind: 'object',
|
|
10
|
+
api: ['move'],
|
|
11
|
+
fields: ['name'],
|
|
12
|
+
position: { authority: 'solver', writers: { mover: 'move() writes character.root.position while the holder of the control slot drives it; it writes no record' } },
|
|
13
|
+
optional: { dispose: v => typeof v === 'function', leave: v => typeof v === 'function' },
|
|
14
|
+
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// Shared by all movers: horizontal velocity smoothing, swim check, jumps (buffer, coyote time, air jumps), landing, facing and action state.
|
|
2
2
|
// Used by simple.js (built-in) and rapier.js (Rapier character controller), so feel parameters (acceleration, air control, jump) match.
|
|
3
|
-
// Movement stats go through the one entry for shared quantities, engine.mod (core/stacks.js), never by writing the character's fields from a module:
|
|
3
|
+
// Movement stats go through the one entry for shared quantities, engine.mod (core/ops/stacks.js), never by writing the character's fields from a module:
|
|
4
4
|
// engine.mod('move.speed', { owner: 'haste', id: 'player', mul: 1.2, for: 5 }); // haste on the player; without id: every character (mud, wind)
|
|
5
5
|
// The character's own field is the base and belongs to the game (player.speed = 6 is always fine); stacks hold only the modifiers, so stamina's
|
|
6
6
|
// "run speed = walk speed", haste x1.2 and mud x0.6 combine and end in any order (stacks.js rules).
|
|
7
|
-
import { xzOf } from '../../../core/math.js';
|
|
7
|
+
import { xzOf, wrapAngle } from '../../../core/base/math.js';
|
|
8
8
|
import { groundAt, stateOf } from './support.js';
|
|
9
|
-
import { warnOnce } from '../../../core/validate.js';
|
|
9
|
+
import { warnOnce } from '../../../core/base/validate.js';
|
|
10
10
|
|
|
11
11
|
const STATE_WRITTEN = "character.state was written directly, but the engine mover recomputes it every step (idle / walk / run / jump / fall / swim), " +
|
|
12
12
|
"so your value was replaced at once. Own states on top (crouch, climb, glide): the states option, (character, facts) => name | null. " +
|
|
@@ -17,12 +17,17 @@ const MOVE_STATS = ['speed', 'runSpeed', 'gravity', 'jumpSpeed', 'canJump'];
|
|
|
17
17
|
/** 'speed' -> 'move.speed', built once: stat runs several times per character per step, so no string is joined there */
|
|
18
18
|
const STACK_OF = Object.fromEntries(MOVE_STATS.map(k => [k, 'move.' + k]));
|
|
19
19
|
|
|
20
|
-
/** @internal define the move.* stacks once per engine: the characters module install does it (so engine.mod works in setup); the Character constructor calls it too for a character made without the module */
|
|
20
|
+
/** @internal define the move.* stacks and the rule 'fall' once per engine: the characters module install does it (so engine.mod works in setup); the Character constructor calls it too for a character made without the module */
|
|
21
21
|
export function moveStacks(e) {
|
|
22
|
-
if (
|
|
22
|
+
if (e.stacks.has('move.speed')) return;
|
|
23
|
+
e.stacks.rule('character.mover', null); // defined here for the same reason: engine.mod('character.mover', ...) in setup, before any character
|
|
23
24
|
for (const k of MOVE_STATS) e.stacks.define(STACK_OF[k], { per: 'optional', ...(k === 'gravity' ? {} : { min: 0 }) });
|
|
25
|
+
e.stacks.rule('fall', false, ['rescue']);
|
|
24
26
|
}
|
|
25
27
|
|
|
28
|
+
/** The steepest ground a walker climbs (rise over run): the collision module's, else the engine's own */
|
|
29
|
+
export const climbLimit = e => e.collision?.maxClimb ?? e.movement.slopeRatio;
|
|
30
|
+
|
|
26
31
|
/**
|
|
27
32
|
* The value a mover uses now: the character's own field (the base) with every engine.mod entry on 'move.<name>' applied. canJump reads 1 / 0.
|
|
28
33
|
* @param {any} c @param {string} name @param {number} [base] a different base on the same stack (airJumpSpeed rides on move.jumpSpeed)
|
|
@@ -30,8 +35,8 @@ export function moveStacks(e) {
|
|
|
30
35
|
export function stat(c, name, base) {
|
|
31
36
|
const b = base ?? (name === 'canJump' ? (c.canJump ? 1 : 0) : c[name]);
|
|
32
37
|
const s = c.engine.stacks, key = STACK_OF[name] ?? 'move.' + name;
|
|
33
|
-
if (!s
|
|
34
|
-
return s.get(key).value(c.
|
|
38
|
+
if (!s.has(key)) return b;
|
|
39
|
+
return s.get(key).value(c.id, b);
|
|
35
40
|
}
|
|
36
41
|
|
|
37
42
|
/** Smooth horizontal velocity toward the target velocity (c.velocity x/y map to world x/z). The direction's length (0-1) scales the speed */
|
|
@@ -57,7 +62,7 @@ const WATER_KEY = new WeakMap(); // the water mode the character is in now (nu
|
|
|
57
62
|
export function water(c, ox, oz) {
|
|
58
63
|
const e = c.engine, p = c.root.position;
|
|
59
64
|
let ground = groundAt(c, p.x, p.z, p.y); // pass the current height: walk the ground under a bridge, the deck on top
|
|
60
|
-
const surface = e.waterAt(p.x, p.z), swimY = surface - c.swimDepth;
|
|
65
|
+
const surface = e.waterAt(p.x, p.z, p.y), swimY = surface - c.swimDepth;
|
|
61
66
|
const mode = ground < swimY ? waterMode(c, surface - ground, p) : null;
|
|
62
67
|
if (mode === 'block') { p.x = ox; p.z = oz; c.velocity.set(0, 0); ground = groundAt(c, ox, oz, p.y); }
|
|
63
68
|
c.swimming = mode === 'swim' && p.y <= swimY + 0.3;
|
|
@@ -81,18 +86,18 @@ export function float(c, swimY) { c.vy = 0; c.grounded = false; c.root.position.
|
|
|
81
86
|
// Jump state lives here, out of reach (a WeakMap, not fields on the character): games read character.jumpState() and change it through
|
|
82
87
|
// jump() / addJumps() / resetJumps() / launch(), so no game depends on how the buffer or coyote time is kept (the old _coyote / _jumpBuffer).
|
|
83
88
|
const JUMP = new WeakMap();
|
|
84
|
-
/** @internal { buffer, coyote, used, air } of a character */
|
|
85
|
-
export function jumpOf(c) { let j = JUMP.get(c); if (!j) JUMP.set(c, j = { buffer: 0, coyote: 0, used: 0, air: true }); return j; }
|
|
89
|
+
/** @internal { buffer, fresh, coyote, used, air } of a character; fresh: jump() asked since the last step, so that step's try comes before the buffer runs down (jumpBuffer: 0 means "this step only") */
|
|
90
|
+
export function jumpOf(c) { let j = JUMP.get(c); if (!j) JUMP.set(c, j = { buffer: 0, fresh: false, coyote: 0, used: 0, air: true }); return j; }
|
|
86
91
|
|
|
87
92
|
/** Count the buffer and coyote time down. Once coyote time runs out in the air the ground jump is spent (only air jumps are left) */
|
|
88
93
|
export function tickJump(c, dt) {
|
|
89
94
|
const j = jumpOf(c);
|
|
90
|
-
j.buffer -= dt;
|
|
95
|
+
if (j.fresh) j.fresh = false; else j.buffer -= dt;
|
|
91
96
|
if (j.coyote > 0 && (j.coyote -= dt) <= 0 && !c.grounded && j.used === 0) j.used = 1;
|
|
92
97
|
}
|
|
93
98
|
|
|
94
|
-
/** Walked off an edge: coyote time starts */
|
|
95
|
-
export function leaveGround(c) { c.grounded = false;
|
|
99
|
+
/** Walked off an edge: coyote time starts. With none the ground jump is spent here (tickJump only spends it when coyote time runs out) */
|
|
100
|
+
export function leaveGround(c) { const j = jumpOf(c); c.grounded = false; j.coyote = c.coyoteTime; if (!(c.coyoteTime > 0) && j.used === 0) j.used = 1; }
|
|
96
101
|
|
|
97
102
|
/** A buffered jump: on the ground or in coyote time the ground jump, else an air jump while jumps are left (and the request allowed air) */
|
|
98
103
|
export function tryJump(c) {
|
|
@@ -109,7 +114,7 @@ export function tryJump(c) {
|
|
|
109
114
|
/** Landing: impact is the landing speed; jumps refill */
|
|
110
115
|
export function land(c, impact) {
|
|
111
116
|
c.vy = 0; c.grounded = true; jumpOf(c).used = 0;
|
|
112
|
-
c.
|
|
117
|
+
c.engine.events.emit('character:land', { character: c, impact });
|
|
113
118
|
}
|
|
114
119
|
|
|
115
120
|
/** Extra horizontal speed carried from a platform the character left, as a Vector2 (x, z), until it lands */
|
|
@@ -127,13 +132,12 @@ function faceAngle(c, sp) {
|
|
|
127
132
|
export function finish(c, dt) {
|
|
128
133
|
const sp = c.velocity.length(), want = faceAngle(c, sp);
|
|
129
134
|
if (want != null) {
|
|
130
|
-
|
|
131
|
-
c.facing += d * Math.min(1, dt * c.turnSpeed);
|
|
135
|
+
c.facing += wrapAngle(want - c.facing) * Math.min(1, dt * c.turnSpeed);
|
|
132
136
|
c.root.rotation.y = c.facing;
|
|
133
137
|
}
|
|
134
138
|
c.moveAmount = sp;
|
|
135
139
|
// a game write since the last step would vanish here without a word (no-conflict rule): say so once, with the calls that do work
|
|
136
|
-
if (c.state !== c.
|
|
140
|
+
if (c.state !== c.stateMark) warnOnce(STATE_WRITTEN);
|
|
137
141
|
const base = c.swimming ? 'swim' : !c.grounded ? (c.vy > 0 ? 'jump' : 'fall') : sp > stat(c, 'speed') * 1.3 ? 'run' : sp > 0.4 ? 'walk' : 'idle';
|
|
138
142
|
// the game's states hook adds its own (crouch, climb, glide, dash...) on top of the built-in ones without taking the mover over; null keeps base
|
|
139
143
|
ownState(c, base, sp);
|
|
@@ -141,5 +145,5 @@ export function finish(c, dt) {
|
|
|
141
145
|
|
|
142
146
|
/** @internal the state after a mover's step: the game's states hook, or base when it returns null */
|
|
143
147
|
export function ownState(c, base, speed) {
|
|
144
|
-
c.state = c.
|
|
148
|
+
c.state = c.stateMark = (c.states && c.states(c, { base, speed, grounded: c.grounded, swimming: c.swimming, vy: c.vy, water: WATER_KEY.get(c) ?? null })) || base;
|
|
145
149
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// mover: 'manual': the game owns the position. The engine integrates no velocity and applies no gravity; it only keeps what other systems read
|
|
2
2
|
// in step with where the game put the character: grounded, what it stands on (a support still carries it), safeGround and the fall check.
|
|
3
3
|
// const p = createPlayer({ control: (p, input, dt) => { p.position.x += 3 * dt; return null; }, faceMode: 'manual', mover: 'manual' });
|
|
4
|
-
// Why a mover and not "a control that never moves": control decides where to go (core/control.js), the mover is still the one that writes the
|
|
4
|
+
// Why a mover and not "a control that never moves": control decides where to go (core/ops/control.js), the mover is still the one that writes the
|
|
5
5
|
// position. 'manual' is the takeover level for the position itself, so a hand-written controller (a platformer's own physics) keeps the
|
|
6
6
|
// platform, safe-ground and fall behaviour without fighting the built-in integration.
|
|
7
7
|
import { groundAt, beginMove, endMove, stateOf } from './support.js';
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Feel parameters (speed, acceleration, jump, air control, swimming) match simple; while physics is not ready or the collision under the feet is not built, simple is used temporarily.
|
|
3
3
|
// Native objects: mover.controller (KinematicCharacterController), mover.body, mover.collider.
|
|
4
4
|
// The player uses rigid.playerBody / playerCollider (rigid syncs it to the player position each step); each NPC builds its own kinematic capsule.
|
|
5
|
-
import { steer, water, float, tryJump, tickJump, leaveGround, land, finish, stat, inherited } from './common.js';
|
|
5
|
+
import { steer, water, float, tryJump, tickJump, leaveGround, land, finish, stat, inherited, climbLimit } from './common.js';
|
|
6
6
|
import { beginMove, endMove } from './support.js';
|
|
7
7
|
|
|
8
8
|
/** Create the 'rapier' mover (c is the character, fallback is the simple mover used when not ready) */
|
|
@@ -11,26 +11,28 @@ export function rapierMover(c, fallback) {
|
|
|
11
11
|
name: 'rapier', controller: null, body: null, collider: null,
|
|
12
12
|
move(dirX, dirZ, run, dt) {
|
|
13
13
|
const e = c.engine, r = e.rigid, p = c.root.position;
|
|
14
|
-
if (!r?.ready || !r.
|
|
15
|
-
const fresh = !m.controller || m.
|
|
14
|
+
if (!r?.ready || !r.readyAt(p)) return fallback.move(dirX, dirZ, run, dt);
|
|
15
|
+
const fresh = !m.controller || m.world !== r.world; // another world (newGame / load rebuilt it, a replaced rigid brought its own): the old controller went with the old one
|
|
16
16
|
if (fresh) setup(e, r);
|
|
17
17
|
const col = m.collider;
|
|
18
18
|
// moved outside the mover (placeAt, load, leaving a vehicle, a platform carrying it; support.js tells exactly): the collider goes there first
|
|
19
|
-
if (beginMove(c) || fresh) { m.body.setTranslation({ x: p.x, y: p.y, z: p.z }, true); r.world.propagateModifiedBodyPositionsToColliders(); }
|
|
19
|
+
if (beginMove(c) || fresh || m.away) { m.away = false; col.setEnabled(true); m.body.setTranslation({ x: p.x, y: p.y, z: p.z }, true); r.world.propagateModifiedBodyPositionsToColliders(); }
|
|
20
20
|
steer(c, dirX, dirZ, run, dt);
|
|
21
21
|
const ox = p.x, oz = p.z, inh = c.grounded ? null : inherited(c);
|
|
22
22
|
|
|
23
23
|
// vertical intent: float to the surface when swimming, otherwise gravity + jump
|
|
24
24
|
tickJump(c, dt);
|
|
25
|
+
// -Infinity: no water here any more (placed in a dry cellar under the lake, the water removed); water() below ends the swim, this step already falls
|
|
26
|
+
const floatY = c.swimming ? e.waterAt(p.x, p.z, p.y) - c.swimDepth : -Infinity;
|
|
25
27
|
let dy;
|
|
26
|
-
if (
|
|
28
|
+
if (floatY > -Infinity) dy = floatY - p.y;
|
|
27
29
|
else {
|
|
28
30
|
tryJump(c);
|
|
29
31
|
if (c.grounded && c.vy <= 0) { c.vy = 0; dy = 0; } // do not press down while standing (it would break auto step-up); downhill relies on ground snapping
|
|
30
32
|
else { c.vy += stat(c, 'gravity') * dt; dy = c.vy * dt; }
|
|
31
33
|
}
|
|
32
34
|
const wasGrounded = c.grounded;
|
|
33
|
-
m.controller.computeColliderMovement(col, { x: (c.velocity.x + (inh?.x ?? 0)) * dt, y: dy, z: (c.velocity.y + (inh?.y ?? 0)) * dt }, r.
|
|
35
|
+
m.controller.computeColliderMovement(col, { x: (c.velocity.x + (inh?.x ?? 0)) * dt, y: dy, z: (c.velocity.y + (inh?.y ?? 0)) * dt }, r.rapier.QueryFilterFlags.EXCLUDE_DYNAMIC | r.rapier.QueryFilterFlags.EXCLUDE_SENSORS);
|
|
34
36
|
const mv = m.controller.computedMovement();
|
|
35
37
|
p.x += mv.x; p.y += mv.y; p.z += mv.z;
|
|
36
38
|
// hit a wall (not stepping up): velocity becomes the wall-sliding velocity, so standing at a wall does not keep walking
|
|
@@ -48,11 +50,17 @@ export function rapierMover(c, fallback) {
|
|
|
48
50
|
finish(c, dt);
|
|
49
51
|
endMove(c, dt, hit && Math.abs(ground - p.y) < 0.1 ? hit : null, 'collider'); // a support counts when the capsule stands on its top
|
|
50
52
|
},
|
|
53
|
+
/** Another mover took over: an NPC's capsule stays out of the world until this mover runs again, or it is an invisible wall where the character left and blocks that mover's own sweeps. The player's belongs to rigid, which keeps it on the character */
|
|
54
|
+
leave() {
|
|
55
|
+
const r = c.engine.rigid;
|
|
56
|
+
if (m.controller && m.body !== r?.playerBody && m.world === r?.world) { m.collider.setEnabled(false); m.away = true; }
|
|
57
|
+
},
|
|
51
58
|
/** Called when the character is deleted: release the NPC's own capsule and controller */
|
|
52
59
|
dispose() {
|
|
53
60
|
const r = c.engine.rigid;
|
|
54
61
|
if (!m.controller) return;
|
|
55
|
-
|
|
62
|
+
// built for a world that was rebuilt or disposed since (engine.dispose runs rigid's before world's, which tears down the NPC models): freed with it
|
|
63
|
+
if (m.world !== r?.world) { m.controller = m.body = m.collider = null; return; }
|
|
56
64
|
r.world.removeCharacterController(m.controller);
|
|
57
65
|
if (m.body !== r.playerBody) r.world.removeRigidBody(m.body);
|
|
58
66
|
m.controller = m.body = m.collider = null;
|
|
@@ -60,8 +68,8 @@ export function rapierMover(c, fallback) {
|
|
|
60
68
|
};
|
|
61
69
|
|
|
62
70
|
function setup(e, r) {
|
|
63
|
-
const R = r.
|
|
64
|
-
m.
|
|
71
|
+
const R = r.rapier, w = r.world, p = c.root.position;
|
|
72
|
+
m.world = w; // what the handles below belong to: the world object itself, since a count would match across two rigid modules
|
|
65
73
|
if (c === e.player) { m.body = r.playerBody; m.collider = r.playerCollider; }
|
|
66
74
|
else {
|
|
67
75
|
const hh = r.playerCapsule.halfHeight;
|
|
@@ -70,7 +78,7 @@ export function rapierMover(c, fallback) {
|
|
|
70
78
|
}
|
|
71
79
|
const k = m.controller = w.createCharacterController(0.02);
|
|
72
80
|
k.enableAutostep(c.stepHeight, 0.15, false);
|
|
73
|
-
k.setMaxSlopeClimbAngle(Math.atan(e
|
|
81
|
+
k.setMaxSlopeClimbAngle(Math.atan(climbLimit(e)));
|
|
74
82
|
k.enableSnapToGround(c.stepHeight);
|
|
75
83
|
}
|
|
76
84
|
return m;
|
|
@@ -1,8 +1,28 @@
|
|
|
1
1
|
// Built-in mover (default): snap to ground height, step up within step height, back off slopes that are too steep, light collision push-out, swimming, jumping.
|
|
2
2
|
// Needs no physics engine, cheap on large maps. Registered supports (characters.support) are ground too, and carry the character (support.js).
|
|
3
|
-
import { steer, water, float, tryJump, tickJump, leaveGround, land, finish, stat, inherited } from './common.js';
|
|
3
|
+
import { steer, water, float, tryJump, tickJump, leaveGround, land, finish, stat, inherited, climbLimit } from './common.js';
|
|
4
4
|
import { groundAt, beginMove, endMove } from './support.js';
|
|
5
5
|
|
|
6
|
+
const MIN_PIECE = 0.05; // a body of no radius still walks in pieces of this length (m), not in endless ones
|
|
7
|
+
|
|
8
|
+
/** Move by (dx, dz) where the ground and colliders let it. False once it stopped dead: the rest of the step goes nowhere */
|
|
9
|
+
function walkPiece(c, dx, dz) {
|
|
10
|
+
const e = c.engine, p = c.root.position, ox = p.x, oz = p.z, oh = groundAt(c, ox, oz, p.y);
|
|
11
|
+
p.x += dx; p.z += dz;
|
|
12
|
+
// back to the old position where it cannot climb: step up directly within step height; above that check the slope; hitting ground higher than itself in the air counts as a wall
|
|
13
|
+
const nh = groundAt(c, p.x, p.z, p.y), step = Math.hypot(p.x - ox, p.z - oz), maxClimb = climbLimit(e), rise = nh - Math.max(oh, c.grounded ? oh : p.y);
|
|
14
|
+
const blocked = c.grounded ? (rise > c.stepHeight && step > 1e-4 && (nh - oh) / step > maxClimb) : nh > p.y + c.stepHeight;
|
|
15
|
+
let moving = true;
|
|
16
|
+
if (blocked) { p.x = ox; p.z = oz; c.velocity.set(0, 0); moving = false; }
|
|
17
|
+
const col = e.collision;
|
|
18
|
+
if (col?.blockedAt(p.x, p.z, c.radius)) { // addBlocked ground (river): slide along it, else stay put
|
|
19
|
+
const nx = p.x, nz = p.z;
|
|
20
|
+
if (!col.blockedAt(nx, oz, c.radius)) p.z = oz; else if (!col.blockedAt(ox, nz, c.radius)) p.x = ox; else { p.x = ox; p.z = oz; c.velocity.set(0, 0); moving = false; }
|
|
21
|
+
}
|
|
22
|
+
col?.resolve(p, c.radius);
|
|
23
|
+
return moving;
|
|
24
|
+
}
|
|
25
|
+
|
|
6
26
|
/** Create the 'simple' mover (c is the character) */
|
|
7
27
|
export function simpleMover(c) {
|
|
8
28
|
return {
|
|
@@ -12,18 +32,11 @@ export function simpleMover(c) {
|
|
|
12
32
|
beginMove(c); // a platform under the feet moved since last step: move with it first
|
|
13
33
|
steer(c, dirX, dirZ, run, dt);
|
|
14
34
|
|
|
15
|
-
const ox = p.x, oz = p.z,
|
|
16
|
-
|
|
17
|
-
//
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
if (blocked) { p.x = ox; p.z = oz; c.velocity.set(0, 0); }
|
|
21
|
-
const col = e.collision;
|
|
22
|
-
if (col?._blocked.length && col.blockedAt(p.x, p.z, c.radius)) { // addBlocked ground (river): slide along it, else stay put
|
|
23
|
-
const nx = p.x, nz = p.z;
|
|
24
|
-
if (!col.blockedAt(nx, oz, c.radius)) p.z = oz; else if (!col.blockedAt(ox, nz, c.radius)) p.x = ox; else { p.x = ox; p.z = oz; c.velocity.set(0, 0); }
|
|
25
|
-
}
|
|
26
|
-
col?.resolve(p, c.radius);
|
|
35
|
+
const ox = p.x, oz = p.z, inh = c.grounded ? null : inherited(c);
|
|
36
|
+
const dx = (c.velocity.x + (inh?.x ?? 0)) * dt, dz = (c.velocity.y + (inh?.y ?? 0)) * dt;
|
|
37
|
+
// a step longer than half the body is walked in pieces: colliders only push out of what the body overlaps, so one long step would land past a thin wall, on its far side
|
|
38
|
+
const pieces = Math.max(1, Math.ceil(Math.hypot(dx, dz) / Math.max(c.radius / 2, MIN_PIECE)));
|
|
39
|
+
for (let i = 0; i < pieces && walkPiece(c, dx / pieces, dz / pieces); i++);
|
|
27
40
|
|
|
28
41
|
const { ground, swimY, hit } = water(c, ox, oz);
|
|
29
42
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// What a character stands on (character.support), moving platforms that carry it, the last safe spot (character.safeGround) and falling out of the
|
|
2
|
-
// level (fall: { belowY }). Shared by
|
|
2
|
+
// level (fall: { belowY }). Shared by the movers (simple.js, rapier.js, manual), so a platform feels the same with or without physics.
|
|
3
3
|
// const lift = engine.characters.support(liftMesh); // a box / mesh the player can stand on and ride; move liftMesh any way you like
|
|
4
4
|
// Why "record -> compare" and not "the platform tells the riders it moved": the rider remembers the platform's matrixWorld when it lands and, before
|
|
5
5
|
// its own move, after every fixed step and once a frame, applies "recorded matrix -> current matrix" to itself and records again. Every bit of platform
|
|
@@ -8,8 +8,9 @@
|
|
|
8
8
|
// Why one "moved outside the mover" check here: a teleport guess from distance ("collider more than 0.3 m from the position") is inexact; a
|
|
9
9
|
// platform carry, placeAt and a load all move the position outside the mover, so the mover compares with where it left the character (exact).
|
|
10
10
|
import * as THREE from 'three';
|
|
11
|
-
import { codedError } from '../../../core/errorHints.js';
|
|
12
|
-
import {
|
|
11
|
+
import { codedError, coded } from '../../../core/base/errorHints.js';
|
|
12
|
+
import { DEV, warnOnce } from '../../../core/base/validate.js';
|
|
13
|
+
import { placeY, FALL_Y } from '../../../core/scene/ground.js';
|
|
13
14
|
|
|
14
15
|
const REG = new WeakMap(); // engine -> { list: Map<id, entry>, riders: Set<character> }
|
|
15
16
|
const STATE = new WeakMap(); // character -> per-character support state (private: games read character.support / safeGround)
|
|
@@ -35,11 +36,11 @@ export function stateOf(c) {
|
|
|
35
36
|
* @returns {{ id: string, remove(): void }}
|
|
36
37
|
*/
|
|
37
38
|
export function addSupport(e, object, { id, safe = true, carry = 'position', inherit = true } = {}) {
|
|
38
|
-
if (!object?.isObject3D) throw codedError('
|
|
39
|
-
if (!CARRY.includes(carry)) throw codedError('
|
|
39
|
+
if (!object?.isObject3D) throw codedError('character-option', `characters.support(object): object is a three.js Object3D (a mesh or group) to stand on, got ${object?.constructor?.name ?? typeof object}`);
|
|
40
|
+
if (!CARRY.includes(carry)) throw codedError('character-option', `characters.support(object, { carry }): carry is ${CARRY.map(c => `'${c}'`).join(' or ')}, got ${JSON.stringify(carry)}`);
|
|
40
41
|
const R = registry(e);
|
|
41
42
|
id ??= object.name || `support#${++R.n}`;
|
|
42
|
-
if (R.list.has(id)) throw codedError('
|
|
43
|
+
if (R.list.has(id)) throw codedError('character-option', `characters.support(object, { id: '${id}' }): id already used by another support; give each a unique id (saves find the platform by it)`);
|
|
43
44
|
object.updateWorldMatrix(true, true);
|
|
44
45
|
const box = new THREE.Box3(), inv = _inv.copy(object.matrixWorld).invert();
|
|
45
46
|
object.traverse(o => {
|
|
@@ -47,7 +48,7 @@ export function addSupport(e, object, { id, safe = true, carry = 'position', inh
|
|
|
47
48
|
if (!g.boundingBox) g.computeBoundingBox();
|
|
48
49
|
box.union(_b.copy(g.boundingBox).applyMatrix4(_m.multiplyMatrices(inv, o.matrixWorld)));
|
|
49
50
|
});
|
|
50
|
-
if (box.isEmpty()) throw codedError('
|
|
51
|
+
if (box.isEmpty()) throw codedError('character-option', `characters.support(object '${id}'): it has no mesh to measure; pass a mesh or a group with meshes`);
|
|
51
52
|
const entry = { id, object, safe, carry, inherit, box };
|
|
52
53
|
R.list.set(id, entry);
|
|
53
54
|
return { id, remove: () => {
|
|
@@ -154,17 +155,27 @@ export function endMove(c, dt, hit, ground = 'ground') {
|
|
|
154
155
|
(s.last ??= new THREE.Vector3()).copy(p);
|
|
155
156
|
}
|
|
156
157
|
|
|
157
|
-
/**
|
|
158
|
+
/** Dev, once: a player gone past the void with nobody deciding stays gone, which reads as a bug in the game unless something names the choice */
|
|
159
|
+
function tellNoFallRule(c) {
|
|
160
|
+
const e = c.engine;
|
|
161
|
+
if (c !== e.player || c.root.position.y >= Math.max(e.ground.voidY?.() ?? -Infinity, FALL_Y)) return;
|
|
162
|
+
const point = e.stacks.get('fall');
|
|
163
|
+
if (point.holders().length + point.holders(c.id).length) return;
|
|
164
|
+
warnOnce(coded('character-option', `the player fell past the void and no rule 'fall' is set, so nothing brings it back. Decide what a fall is: engine.mod('fall', { owner: 'game', set: 'rescue' }) with createPlayer({ fall: { belowY } }) returns it to safeGround, a function is your own rule, and set: false says the game handles it`), 'fall-no-rule');
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** belowY: a height or (character) => boolean. character:fall once per fall, then the rule 'fall' decides: 'rescue' goes back to safeGround, nothing or false leaves it to the game */
|
|
158
168
|
function fallCheck(c, s) {
|
|
169
|
+
if (DEV) tellNoFallRule(c);
|
|
159
170
|
const f = c.fall;
|
|
160
171
|
if (!f) return;
|
|
161
172
|
const out = typeof f.belowY === 'function' ? !!f.belowY(c) : c.root.position.y < f.belowY;
|
|
162
173
|
if (!out) { s.fell = false; return; }
|
|
163
|
-
if (s.fell) return; //
|
|
174
|
+
if (s.fell) return; // the rule kept it out there: say it once, not every step
|
|
164
175
|
s.fell = true;
|
|
165
|
-
const
|
|
166
|
-
c.engine.events.emit('character:fall',
|
|
167
|
-
if (
|
|
176
|
+
const safe = c.safeGround ? c.safeGround.clone() : null;
|
|
177
|
+
c.engine.events.emit('character:fall', { character: c, safe });
|
|
178
|
+
if (c.engine.stacks.rule('fall', false, ['rescue']).decide(c.id, { kind: 'character', who: c, position: c.root.position.clone(), safe }) !== 'rescue') return;
|
|
168
179
|
// the exact spot, not placeAt: a platform that was under this spot may have moved away, and placeAt would land on the ground below it
|
|
169
180
|
if (c.safeGround) c.root.position.copy(c.safeGround);
|
|
170
181
|
detach(c); c.velocity.set(0, 0); c.vy = 0; c._push = 0; c.grounded = true;
|
|
@@ -181,6 +192,6 @@ export function carryRiders(e, between) {
|
|
|
181
192
|
if (!R?.riders.size) return;
|
|
182
193
|
for (const c of [...R.riders]) {
|
|
183
194
|
if (!carry(c)) continue;
|
|
184
|
-
if (between
|
|
195
|
+
if (between) e.ops.allow(() => c._store()); else c._store();
|
|
185
196
|
}
|
|
186
197
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// NPC-vs-NPC avoidance (near NPCs, every fixed step, called from goTo): nearby NPCs push each other apart to at least the sum of their radii;
|
|
2
|
-
// obstacle (NPCs yield,
|
|
1
|
+
// NPC-vs-NPC avoidance (near NPCs, every fixed step, called from goTo): nearby NPCs push each other apart to at least the sum of their radii; every player is an
|
|
2
|
+
// obstacle (NPCs yield, a player is never pushed).
|
|
3
3
|
// Why it is written this way: a continuous run and a save-then-load of the same scenario must give bit-identical positions:
|
|
4
4
|
// 1. Each NPC pushes only itself and reads neighbours' positions as of the start of this step (stamped), so a neighbour that already moved this step does not
|
|
5
5
|
// matter and order is irrelevant;
|
|
@@ -9,8 +9,9 @@
|
|
|
9
9
|
// Push is capped (strength m/s * dt), stronger with more overlap, then constrained by engine.collision (if installed) so NPCs are not pushed into walls.
|
|
10
10
|
// With nav({ crowd: true }) the Recast agents decide and this adds nothing. Only near NPCs with a model; far NPCs are simulated from data without per-NPC
|
|
11
11
|
// avoidance (too costly).
|
|
12
|
-
import { readParams, keysSchema } from '../../core/params.js';
|
|
13
|
-
import { Cells } from '../../core/cells.js';
|
|
12
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
13
|
+
import { Cells } from '../../core/stream/cells.js';
|
|
14
|
+
import { sameFloor } from '../../core/scene/floor.js';
|
|
14
15
|
|
|
15
16
|
const KEYS = ['on', 'radius', 'strength'];
|
|
16
17
|
// push direction is rotated ~25° to the right: two NPCs meeting head-on each swerve to their own right instead of deadlocking in a line
|
|
@@ -27,27 +28,28 @@ function shove(acc, dx, dz, d, min, tie) {
|
|
|
27
28
|
acc.x += Math.round((ux * COS - uz * SIN) * w * Q); acc.z += Math.round((ux * SIN + uz * COS) * w * Q);
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
/**
|
|
31
|
+
/** Mounted on engine.npcs: engine.npcs.avoid.set(false | { radius, strength }) */
|
|
31
32
|
export class NpcAvoid {
|
|
32
|
-
/** @param {(h: any) => any} track the characters module's ctx.track: its listeners leave with the module */
|
|
33
|
-
constructor(engine, track) {
|
|
33
|
+
/** @param {any} engine @param {(h: any) => any} track the characters module's ctx.track: its listeners leave with the module @param {Map<string, { character: any }>} players */
|
|
34
|
+
constructor(engine, track, players) {
|
|
34
35
|
this.engine = engine;
|
|
36
|
+
/** @internal */ this._players = players;
|
|
35
37
|
this.on = true; // switch (default on)
|
|
36
38
|
this.radius = null; // avoid radius per NPC (m); null = engine.movement.radius
|
|
37
39
|
this.strength = 3; // max push speed (m/s)
|
|
38
40
|
this._acc = { x: 0, z: 0 };
|
|
39
41
|
/** @internal ids of NPCs that have a model now (NPCManager keeps it): only they take part, so far NPCs cost nothing per step */ this.built = new Set();
|
|
40
|
-
// id → { id, rec, k, x, z, position, n }: x, z = where its own step started (stamped on step k); position = where it was filed for step n (the stamp, or
|
|
42
|
+
// id → { id, rec, k, x, y, z, position, n }: x, y, z = where its own step started (stamped on step k); position = where it was filed for step n (the stamp, or
|
|
41
43
|
// where it stood before moving), what neighbours read
|
|
42
44
|
this._start = new Map();
|
|
43
|
-
// the shared xz index (core/cells.js) with cells the size of the minimum distance of two NPCs, so a query looks at 3x3 cells. Not world's record index:
|
|
45
|
+
// the shared xz index (core/stream/cells.js) with cells the size of the minimum distance of two NPCs, so a query looks at 3x3 cells. Not world's record index:
|
|
44
46
|
// that one is 32 m per cell (hundreds of NPCs in one or two cells would make per-pair checks too costly) and holds positions as they move during the step,
|
|
45
47
|
// while every push must read the step-start ones
|
|
46
48
|
this._grid = null; this._gridN = -1; this._filed = new Set();
|
|
47
49
|
this._q = null; this._qRec = null; // the NPC being pushed, for the query callback (built once, no closure per push)
|
|
48
50
|
this._onNear = (o, d2) => {
|
|
49
51
|
const own = this._q, rec = this._qRec;
|
|
50
|
-
if (o.rec === rec || d2 >= this._min2 || (o.rec.zone != null && rec.zone != null && o.rec.zone !== rec.zone)) return;
|
|
52
|
+
if (o.rec === rec || d2 >= this._min2 || (o.rec.zone != null && rec.zone != null && o.rec.zone !== rec.zone) || !sameFloor(own.y, o.position.y, this.engine.movement.height)) return;
|
|
51
53
|
shove(this._acc, own.x - o.position.x, own.z - o.position.z, Math.sqrt(d2), this._min, rec.id < o.id ? 1 : -1);
|
|
52
54
|
};
|
|
53
55
|
track(engine.events.on('world:remove', ({ id }) => { const s = this._start.get(id); if (s) { this._grid?.delete(s); this._filed.delete(s); this._start.delete(id); } }));
|
|
@@ -77,11 +79,11 @@ export class NpcAvoid {
|
|
|
77
79
|
stamp(rec) {
|
|
78
80
|
if (!this.on) return;
|
|
79
81
|
const s = this._entry(rec);
|
|
80
|
-
s.k = this.engine.world.steps; s.x = rec.position.x; s.z = rec.position.z;
|
|
82
|
+
s.k = this.engine.world.steps; s.x = rec.position.x; s.y = rec.position.y; s.z = rec.position.z;
|
|
81
83
|
}
|
|
82
84
|
_entry(rec) {
|
|
83
85
|
let s = this._start.get(rec.id);
|
|
84
|
-
if (!s) this._start.set(rec.id, s = { id: rec.id, rec, k: -1, x: 0, z: 0, position: { x: 0, z: 0 }, n: -1 });
|
|
86
|
+
if (!s) this._start.set(rec.id, s = { id: rec.id, rec, k: -1, x: 0, y: 0, z: 0, position: { x: 0, y: 0, z: 0 }, n: -1 });
|
|
85
87
|
s.rec = rec; // a load replaces record objects
|
|
86
88
|
return s;
|
|
87
89
|
}
|
|
@@ -99,13 +101,13 @@ export class NpcAvoid {
|
|
|
99
101
|
const o = W.get(id); if (!o || !W.view(id)) continue;
|
|
100
102
|
const s = this._entry(o);
|
|
101
103
|
const q = s.k === n ? s : o.position;
|
|
102
|
-
s.position.x = q.x; s.position.z = q.z;
|
|
104
|
+
s.position.x = q.x; s.position.y = q.y; s.position.z = q.z;
|
|
103
105
|
s.n = n; G.put(s); filed.add(s);
|
|
104
106
|
}
|
|
105
107
|
for (const s of filed) if (s.n !== n) { G.delete(s); filed.delete(s); } // model gone since last step
|
|
106
108
|
}
|
|
107
109
|
|
|
108
|
-
/** Push ch (the rec's model) apart
|
|
110
|
+
/** Push ch (the rec's model) apart in x, z, from walkers on its own floor only (nav({ crowd: true }) separates by the mesh). Call after ch.move, edits ch.root.position x, z directly */
|
|
109
111
|
push(rec, ch, dt) {
|
|
110
112
|
const e = this.engine, W = e.world;
|
|
111
113
|
if (!this.on || e.nav?.crowd) return;
|
|
@@ -116,8 +118,9 @@ export class NpcAvoid {
|
|
|
116
118
|
const acc = this._acc; acc.x = acc.z = 0;
|
|
117
119
|
this._q = own; this._qRec = rec; this._min = min; this._min2 = min * min;
|
|
118
120
|
this._grid.forEach(own, min, this._onNear);
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
+
const ox = own.x, oz = own.z;
|
|
122
|
+
for (const { character: pl } of this._players.values()) { // a player is an obstacle: only the NPC yields, a player's position belongs to its mover
|
|
123
|
+
if (!sameFloor(own.y, pl.root.position.y, e.movement.height)) continue;
|
|
121
124
|
const q = pl.root.position, m = r + (pl.radius ?? r), dx = ox - q.x, dz = oz - q.z, d = Math.hypot(dx, dz);
|
|
122
125
|
if (d < m) shove(acc, dx, dz, d, m, 1);
|
|
123
126
|
}
|