threedog 0.0.0-stage → 0.2.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 +5 -0
- package/LICENSE +21 -0
- package/README.md +39 -2
- package/core/Animator.js +268 -0
- package/core/Assets.js +256 -0
- package/core/Audio.js +267 -0
- package/core/Baked.js +72 -0
- package/core/Batching.js +247 -0
- package/core/Budget.js +221 -0
- package/core/Clock.js +94 -0
- package/core/Commits.js +77 -0
- package/core/DebugOverrides.js +143 -0
- package/core/Describe.js +145 -0
- package/core/Engine.js +184 -0
- package/core/Events.js +153 -0
- package/core/I18n.js +94 -0
- package/core/Input.js +245 -0
- package/core/Inspect.js +77 -0
- package/core/InspectScene.js +191 -0
- package/core/Jobs.js +146 -0
- package/core/Loading.js +149 -0
- package/core/MaterialInfo.js +32 -0
- package/core/Ops.js +256 -0
- package/core/Random.js +52 -0
- package/core/Rays.js +160 -0
- package/core/SaveStore.js +85 -0
- package/core/Saves.js +254 -0
- package/core/Stream.js +279 -0
- package/core/Threads.js +158 -0
- package/core/UrlState.js +94 -0
- package/core/Vars.js +35 -0
- package/core/Views.js +49 -0
- package/core/actor.js +23 -0
- package/core/assetEntry.js +89 -0
- package/core/assetLoad.js +190 -0
- package/core/assetManifest.js +35 -0
- package/core/assetReport.js +83 -0
- package/core/audioRules.js +121 -0
- package/core/audioVoice.js +225 -0
- package/core/batchGroups.js +116 -0
- package/core/canvasBox.js +63 -0
- package/core/catalog.js +169 -0
- package/core/checks.js +67 -0
- package/core/claims.js +51 -0
- package/core/dayTime.js +15 -0
- package/core/debugView.js +76 -0
- package/core/describeRender.js +45 -0
- package/core/describeText.js +143 -0
- package/core/easing.js +34 -0
- package/core/errorCodes.js +205 -0
- package/core/errorHints.js +208 -0
- package/core/errors.js +40 -0
- package/core/events.generated.js +84 -0
- package/core/ground.js +102 -0
- package/core/holds.js +106 -0
- package/core/inputContext.js +69 -0
- package/core/inputDefaults.js +22 -0
- package/core/inputPad.js +35 -0
- package/core/inputPointer.js +48 -0
- package/core/inputTouch.js +48 -0
- package/core/lifecycle.js +69 -0
- package/core/lightWatch.js +56 -0
- package/core/look/coreParts.js +112 -0
- package/core/look/layers.js +136 -0
- package/core/look/part.js +173 -0
- package/core/look/report.js +79 -0
- package/core/look/write.js +86 -0
- package/core/loop.js +200 -0
- package/core/math.js +33 -0
- package/core/modules.js +196 -0
- package/core/movement.js +19 -0
- package/core/mulberry32.js +14 -0
- package/core/opsAtomic.js +31 -0
- package/core/opsCheck.js +97 -0
- package/core/opsFail.js +20 -0
- package/core/opsGuard.js +26 -0
- package/core/opsHistory.js +27 -0
- package/core/opsRun.js +77 -0
- package/core/page.js +78 -0
- package/core/params.js +132 -0
- package/core/pureWorker.js +5 -0
- package/core/renamed.js +21 -0
- package/core/saveApply.js +128 -0
- package/core/saveFiles.js +139 -0
- package/core/saveIds.js +53 -0
- package/core/saveVersions.js +97 -0
- package/core/scatter.js +92 -0
- package/core/sceneMethods.js +100 -0
- package/core/screenToGround.js +39 -0
- package/core/services.js +73 -0
- package/core/session.js +171 -0
- package/core/shadowTypes.js +15 -0
- package/core/skip.js +104 -0
- package/core/startup.js +135 -0
- package/core/streamCells.js +24 -0
- package/core/streamSources.js +73 -0
- package/core/styleParts.js +96 -0
- package/core/targeting.js +64 -0
- package/core/thingExplain.js +68 -0
- package/core/thingOps.js +168 -0
- package/core/things.js +212 -0
- package/core/threadPure.js +120 -0
- package/core/threadServe.js +25 -0
- package/core/tier.js +11 -0
- package/core/util.js +11 -0
- package/core/validate.js +204 -0
- package/docs/AI.md +123 -0
- package/docs/API.md +83 -0
- package/docs/CODEMAP.md +347 -0
- package/docs/COMMANDS.md +108 -0
- package/docs/CONVENTIONS.md +145 -0
- package/docs/PERF.md +217 -0
- package/docs/THREE.md +86 -0
- package/docs/api/ambience.md +15 -0
- package/docs/api/assets.md +62 -0
- package/docs/api/audio.md +53 -0
- package/docs/api/budget.md +40 -0
- package/docs/api/cameraRig.md +120 -0
- package/docs/api/characters.md +144 -0
- package/docs/api/clock.md +7 -0
- package/docs/api/collision.md +39 -0
- package/docs/api/content.md +64 -0
- package/docs/api/dialogue.md +39 -0
- package/docs/api/engine.md +199 -0
- package/docs/api/entities.md +61 -0
- package/docs/api/events.md +95 -0
- package/docs/api/flow.md +27 -0
- package/docs/api/grids.md +11 -0
- package/docs/api/ground.md +16 -0
- package/docs/api/hlod.md +34 -0
- package/docs/api/hud.md +31 -0
- package/docs/api/i18n.md +10 -0
- package/docs/api/input.md +24 -0
- package/docs/api/interactions.md +31 -0
- package/docs/api/inventory.md +66 -0
- package/docs/api/jobs.md +10 -0
- package/docs/api/level.md +41 -0
- package/docs/api/lightPool.md +56 -0
- package/docs/api/music.md +34 -0
- package/docs/api/nav.md +26 -0
- package/docs/api/net.md +14 -0
- package/docs/api/openWorld.md +24 -0
- package/docs/api/particles.md +41 -0
- package/docs/api/photo.md +15 -0
- package/docs/api/post.md +10 -0
- package/docs/api/quests.md +36 -0
- package/docs/api/rays.md +26 -0
- package/docs/api/rigid.md +84 -0
- package/docs/api/saves.md +32 -0
- package/docs/api/settings.md +36 -0
- package/docs/api/sky.md +58 -0
- package/docs/api/stream.md +31 -0
- package/docs/api/style.md +134 -0
- package/docs/api/terrain.md +34 -0
- package/docs/api/timeline.md +39 -0
- package/docs/api/tools.md +57 -0
- package/docs/api/triggers.md +56 -0
- package/docs/api/vars.md +9 -0
- package/docs/api/vegetation.md +52 -0
- package/docs/api/water.md +48 -0
- package/docs/api/weather.md +29 -0
- package/docs/api/world.md +30 -0
- package/docs/recipes/01-new-game.md +148 -0
- package/docs/recipes/02-npc.md +167 -0
- package/docs/recipes/03-items-pickups.md +158 -0
- package/docs/recipes/04-quests.md +83 -0
- package/docs/recipes/05-props-bake.md +159 -0
- package/docs/recipes/06-clock-events.md +117 -0
- package/docs/recipes/07-flow-scenes-pause.md +132 -0
- package/docs/recipes/08-weather-sky.md +74 -0
- package/docs/recipes/09-style-pack.md +234 -0
- package/docs/recipes/10-blender-level.md +67 -0
- package/docs/recipes/11-vehicles.md +55 -0
- package/docs/recipes/12-navmesh.md +79 -0
- package/docs/recipes/13-animation.md +149 -0
- package/docs/recipes/14-custom-module.md +91 -0
- package/docs/recipes/15-perf.md +78 -0
- package/docs/recipes/16-dev-bridge.md +180 -0
- package/docs/recipes/18-world.md +185 -0
- package/docs/recipes/19-shooting-picking.md +76 -0
- package/docs/recipes/20-content-actions-save.md +176 -0
- package/docs/recipes/21-camera.md +153 -0
- package/docs/recipes/22-shop-gold.md +107 -0
- package/docs/recipes/23-ops.md +175 -0
- package/docs/recipes/26-ui-parts.md +138 -0
- package/docs/recipes/27-net.md +96 -0
- package/docs/recipes/28-terrain.md +80 -0
- package/docs/recipes/29-grid.md +87 -0
- package/docs/recipes/30-templates.md +131 -0
- package/docs/recipes/31-audio.md +126 -0
- package/docs/recipes/32-action-game.md +33 -0
- package/docs/recipes/33-stream-sources.md +37 -0
- package/docs/recipes/34-environment-lighting.md +36 -0
- package/docs/recipes/35-style-from-reference.md +89 -0
- package/docs/recipes/36-sky-ground-plant-looks.md +116 -0
- package/docs/recipes/37-terrain-look-hooks.md +97 -0
- package/docs/recipes/38-environment-look-hooks.md +83 -0
- package/docs/recipes/40-scene.md +108 -0
- package/docs/recipes/41-thing-registry.md +93 -0
- package/docs/recipes/42-terrain-shape.md +64 -0
- package/docs/recipes/43-shader-patches-surface-looks.md +120 -0
- package/docs/recipes/44-water-weather-look-hooks.md +135 -0
- package/docs/recipes/45-cascaded-shadows.md +51 -0
- package/docs/recipes/46-blender-art-route.md +114 -0
- package/docs/recipes/47-island-snow-backdrop.md +44 -0
- package/docs/recipes/48-make-material.md +70 -0
- package/docs/recipes/49-game-module-contract.md +71 -0
- package/docs/recipes/50-own-renderer.md +12 -0
- package/docs/recipes/51-capability-catalog.md +63 -0
- package/docs/recipes/52-look.md +108 -0
- package/examples/action/DESIGN.md +3 -0
- package/examples/action/GAMEMAP.md +127 -0
- package/examples/action/content/actions.js +8 -0
- package/examples/action/content/audio.js +9 -0
- package/examples/action/content/index.js +10 -0
- package/examples/action/content/items.js +4 -0
- package/examples/action/content/places.js +4 -0
- package/examples/action/content/props.js +11 -0
- package/examples/action/content/templates.js +10 -0
- package/examples/action/content/views.js +6 -0
- package/examples/action/look.js +5 -0
- package/examples/action/main.js +137 -0
- package/examples/action/models.js +25 -0
- package/examples/sheepisland/GAMEMAP.md +107 -0
- package/examples/sheepisland/content/index.js +6 -0
- package/examples/sheepisland/content/props.js +19 -0
- package/examples/sheepisland/content/templates.js +5 -0
- package/examples/sheepisland/content/vegetation.js +8 -0
- package/examples/sheepisland/main.js +71 -0
- package/examples/sheepisland/params.js +25 -0
- package/examples/sheepisland/style/index.js +79 -0
- package/examples/sheepisland/style/models.js +59 -0
- package/examples/sheepisland/views.js +9 -0
- package/examples/styletest/GAMEMAP.md +135 -0
- package/examples/styletest/content/index.js +9 -0
- package/examples/styletest/content/items.js +8 -0
- package/examples/styletest/content/npcs.js +8 -0
- package/examples/styletest/content/places.js +5 -0
- package/examples/styletest/content/props.js +16 -0
- package/examples/styletest/content/templates.js +9 -0
- package/examples/styletest/content/vegetation.js +31 -0
- package/examples/styletest/look.js +11 -0
- package/examples/styletest/main.js +95 -0
- package/examples/styletest/models.js +87 -0
- package/examples/styletest/overrides.js +33 -0
- package/examples/styletest/panel.js +135 -0
- package/examples/styletest/params.js +32 -0
- package/examples/styletest/views.js +31 -0
- package/examples/world/DESIGN.md +5 -0
- package/examples/world/GAMEMAP.md +171 -0
- package/examples/world/content/actions.js +8 -0
- package/examples/world/content/audio.js +25 -0
- package/examples/world/content/bodies.js +12 -0
- package/examples/world/content/containers.js +4 -0
- package/examples/world/content/dialogues.js +33 -0
- package/examples/world/content/index.js +17 -0
- package/examples/world/content/items.js +10 -0
- package/examples/world/content/npcs.js +14 -0
- package/examples/world/content/pickups.js +11 -0
- package/examples/world/content/places.js +6 -0
- package/examples/world/content/props.js +12 -0
- package/examples/world/content/quests.js +15 -0
- package/examples/world/content/rules.js +23 -0
- package/examples/world/content/templates.js +5 -0
- package/examples/world/content/vegetation.js +32 -0
- package/examples/world/main.js +168 -0
- package/examples/world/models.js +28 -0
- package/index.d.ts +306 -0
- package/index.js +122 -0
- package/llms.txt +61 -0
- package/modules/ambience/Ambience.js +186 -0
- package/modules/camera/FirstPersonCamera.js +131 -0
- package/modules/camera/FixedCamera.js +162 -0
- package/modules/camera/FollowCamera.js +91 -0
- package/modules/camera/RtsCamera.js +132 -0
- package/modules/camera/common.js +182 -0
- package/modules/camera/index.js +11 -0
- package/modules/camera/projection.js +34 -0
- package/modules/characters/Character.js +235 -0
- package/modules/characters/NPC.js +242 -0
- package/modules/characters/assetModel.js +42 -0
- package/modules/characters/astar.js +66 -0
- package/modules/characters/behaviors.js +72 -0
- package/modules/characters/footsteps.js +13 -0
- package/modules/characters/index.js +215 -0
- package/modules/characters/moveHelpers.js +29 -0
- package/modules/characters/movers/common.js +62 -0
- package/modules/characters/movers/rapier.js +74 -0
- package/modules/characters/movers/simple.js +43 -0
- package/modules/characters/npcAvoid.js +129 -0
- package/modules/characters/npcSim.js +150 -0
- package/modules/characters/npcView.js +42 -0
- package/modules/characters/pathAsync.js +113 -0
- package/modules/characters/pathJob.js +62 -0
- package/modules/characters/pathWorker.js +7 -0
- package/modules/characters/playerStrings.js +12 -0
- package/modules/characters/proceduralRig.js +58 -0
- package/modules/characters/useModel.js +22 -0
- package/modules/characters/walkTo.js +58 -0
- package/modules/collision/Collision.js +274 -0
- package/modules/collision/grid.js +63 -0
- package/modules/content/explain.js +13 -0
- package/modules/content/ids.js +95 -0
- package/modules/content/index.js +154 -0
- package/modules/content/loader.js +190 -0
- package/modules/content/models.js +69 -0
- package/modules/content/packs.js +69 -0
- package/modules/content/props.js +89 -0
- package/modules/content/rules.js +134 -0
- package/modules/content/templates.js +189 -0
- package/modules/debug/DebugPanel.js +174 -0
- package/modules/entities/Entities.js +243 -0
- package/modules/entities/build.js +25 -0
- package/modules/entities/index.js +4 -0
- package/modules/flow/index.js +101 -0
- package/modules/gameplay/Container.js +227 -0
- package/modules/gameplay/Containers.js +89 -0
- package/modules/gameplay/Dialogue.js +219 -0
- package/modules/gameplay/Interactions.js +253 -0
- package/modules/gameplay/Inventory.js +224 -0
- package/modules/gameplay/Quests.js +205 -0
- package/modules/gameplay/boxOps.js +60 -0
- package/modules/gameplay/dialogueBox.js +48 -0
- package/modules/gameplay/interactionPrompt.js +28 -0
- package/modules/gameplay/inventoryOps.js +137 -0
- package/modules/gameplay/pickups.js +115 -0
- package/modules/gameplay/questLog.js +54 -0
- package/modules/gameplay/questSave.js +71 -0
- package/modules/grid/Grid.js +184 -0
- package/modules/grid/Layer.js +142 -0
- package/modules/grid/index.js +236 -0
- package/modules/grid/ops.js +73 -0
- package/modules/grid/preview.js +85 -0
- package/modules/grid/tiles.js +79 -0
- package/modules/hlod/index.js +167 -0
- package/modules/hud/index.js +167 -0
- package/modules/hud/parts.js +80 -0
- package/modules/level/geometry.js +46 -0
- package/modules/level/heightfield.js +160 -0
- package/modules/level/index.js +233 -0
- package/modules/level/nodes.js +84 -0
- package/modules/lights/index.js +227 -0
- package/modules/music/Music.js +294 -0
- package/modules/music/index.js +2 -0
- package/modules/music/rules.js +28 -0
- package/modules/nav/index.js +156 -0
- package/modules/nav/navPath.js +17 -0
- package/modules/net/Client.js +137 -0
- package/modules/net/Host.js +117 -0
- package/modules/net/Net.js +49 -0
- package/modules/net/index.js +77 -0
- package/modules/net/sync.js +114 -0
- package/modules/net/transports.js +118 -0
- package/modules/particles/Particles.js +179 -0
- package/modules/particles/effect.js +112 -0
- package/modules/particles/shaders.js +28 -0
- package/modules/photo/Photo.js +146 -0
- package/modules/rigid/RigidBodies.js +265 -0
- package/modules/rigid/Vehicles.js +97 -0
- package/modules/rigid/sync.js +158 -0
- package/modules/settings/Settings.js +297 -0
- package/modules/settings/apply.js +21 -0
- package/modules/settings/index.js +3 -0
- package/modules/settings/sections.js +156 -0
- package/modules/settings/strings.js +53 -0
- package/modules/settings/view.js +65 -0
- package/modules/sky/Sky.js +259 -0
- package/modules/sky/calendar.js +80 -0
- package/modules/sky/cascades.js +125 -0
- package/modules/sky/clouds.js +79 -0
- package/modules/sky/domeLayers.js +33 -0
- package/modules/sky/environment.js +141 -0
- package/modules/sky/fog.js +139 -0
- package/modules/sky/frame.js +77 -0
- package/modules/sky/layers.js +69 -0
- package/modules/sky/look.js +51 -0
- package/modules/sky/lookFog.js +80 -0
- package/modules/sky/lookShadow.js +50 -0
- package/modules/sky/lookSky.js +108 -0
- package/modules/sky/schedule.js +80 -0
- package/modules/sky/shader.js +96 -0
- package/modules/sky/shadow.js +74 -0
- package/modules/sky/skyModule.js +60 -0
- package/modules/terrain/ChunkManager.js +260 -0
- package/modules/terrain/chunkJob.js +19 -0
- package/modules/terrain/chunkLevels.js +40 -0
- package/modules/terrain/chunkQueries.js +42 -0
- package/modules/terrain/chunkWorker.js +5 -0
- package/modules/terrain/index.js +118 -0
- package/modules/terrain/lookGround.js +61 -0
- package/modules/terrain/mountTerrain.js +32 -0
- package/modules/terrain/terrainColorMap.js +41 -0
- package/modules/terrain/terrainDefaults.js +39 -0
- package/modules/terrain/terrainEdit.js +139 -0
- package/modules/terrain/terrainGen.js +155 -0
- package/modules/terrain/terrainIsland.js +131 -0
- package/modules/terrain/terrainMesh.js +92 -0
- package/modules/terrain/terrainShape.js +108 -0
- package/modules/terrain/terrainShapeMain.js +41 -0
- package/modules/terrain/terrainTexture.js +44 -0
- package/modules/timeline/Timeline.js +253 -0
- package/modules/timeline/Tween.js +114 -0
- package/modules/timeline/letterbox.js +24 -0
- package/modules/timeline/shots.js +90 -0
- package/modules/triggers/index.js +268 -0
- package/modules/vegetation/Vegetation.js +256 -0
- package/modules/vegetation/groundChunks.js +177 -0
- package/modules/vegetation/index.js +43 -0
- package/modules/vegetation/lookWind.js +37 -0
- package/modules/vegetation/modelGeometry.js +21 -0
- package/modules/water/Water.js +160 -0
- package/modules/water/look.js +80 -0
- package/modules/water/surface.js +88 -0
- package/modules/weather/Weather.js +242 -0
- package/modules/weather/look.js +75 -0
- package/modules/weather/particles.js +92 -0
- package/modules/weather/shaders.js +49 -0
- package/modules/weather/strings.js +15 -0
- package/modules/world/World.js +231 -0
- package/modules/world/cells.js +42 -0
- package/modules/world/explain.js +11 -0
- package/modules/world/index.js +71 -0
- package/modules/world/persist.js +107 -0
- package/modules/world/pos.js +20 -0
- package/modules/world/records.js +89 -0
- package/modules/world/sim.js +175 -0
- package/modules/world/simFar.js +82 -0
- package/modules/world/state.js +115 -0
- package/modules/world/thingSource.js +44 -0
- package/modules/world/views.js +182 -0
- package/package.json +66 -4
- package/presets.js +96 -0
- package/render/PostFX.js +240 -0
- package/render/detail.js +105 -0
- package/render/effects.js +144 -0
- package/render/engineUniforms.js +23 -0
- package/render/fuse.js +84 -0
- package/render/lighting.js +100 -0
- package/render/lights.js +18 -0
- package/render/lookSurface.js +161 -0
- package/render/materials.js +220 -0
- package/render/patches.js +252 -0
- package/render/postLook.js +86 -0
- package/render/surface.js +69 -0
- package/render/uniformDecl.js +29 -0
- package/types/common.d.ts +34 -0
- package/types/core.d.ts +1965 -0
- package/types/gameplay.d.ts +1822 -0
- package/types/generated/core/Audio.d.ts +200 -0
- package/types/generated/core/Batching.d.ts +47 -0
- package/types/generated/core/Budget.d.ts +90 -0
- package/types/generated/core/Commits.d.ts +31 -0
- package/types/generated/core/DebugOverrides.d.ts +52 -0
- package/types/generated/core/Events.d.ts +89 -0
- package/types/generated/core/I18n.d.ts +30 -0
- package/types/generated/core/Input.d.ts +118 -0
- package/types/generated/core/Jobs.d.ts +41 -0
- package/types/generated/core/Ops.d.ts +203 -0
- package/types/generated/core/Random.d.ts +49 -0
- package/types/generated/core/Rays.d.ts +49 -0
- package/types/generated/core/Saves.d.ts +162 -0
- package/types/generated/core/Stream.d.ts +93 -0
- package/types/generated/core/Threads.d.ts +82 -0
- package/types/generated/core/Views.d.ts +33 -0
- package/types/generated/core/audioVoice.d.ts +47 -0
- package/types/generated/core/page.d.ts +18 -0
- package/types/generated/core/session.d.ts +48 -0
- package/types/generated/modules/ambience/Ambience.d.ts +48 -0
- package/types/generated/modules/debug/DebugPanel.d.ts +24 -0
- package/types/generated/modules/flow/index.d.ts +10 -0
- package/types/generated/modules/grid/Grid.d.ts +151 -0
- package/types/generated/modules/grid/Layer.d.ts +65 -0
- package/types/generated/modules/grid/index.d.ts +86 -0
- package/types/generated/modules/hlod/index.d.ts +11 -0
- package/types/generated/modules/hud/index.d.ts +10 -0
- package/types/generated/modules/lights/index.d.ts +13 -0
- package/types/generated/modules/music/Music.d.ts +111 -0
- package/types/generated/modules/net/Net.d.ts +34 -0
- package/types/generated/modules/net/index.d.ts +53 -0
- package/types/generated/modules/net/transports.d.ts +58 -0
- package/types/generated/modules/particles/Particles.d.ts +69 -0
- package/types/generated/modules/sky/Sky.d.ts +145 -0
- package/types/generated/modules/sky/skyModule.d.ts +10 -0
- package/types/generated/modules/timeline/Timeline.d.ts +51 -0
- package/types/generated/modules/water/Water.d.ts +29 -0
- package/types/generated/modules/weather/Weather.d.ts +62 -0
- package/types/generated/modules/world/World.d.ts +242 -0
- package/types/generated/modules/world/index.d.ts +15 -0
- package/types/generated/render/PostFX.d.ts +125 -0
- package/types/generated/render/materials.d.ts +100 -0
- package/types/generated/render/patches.d.ts +41 -0
- package/types/generated/ui/Focus.d.ts +11 -0
- package/types/generated/ui/LoadingScreen.d.ts +2 -0
- package/types/generated/ui/UI.d.ts +57 -0
- package/types/nav.d.ts +52 -0
- package/types/physics.d.ts +592 -0
- package/types/style.d.ts +638 -0
- package/types/worker.d.ts +11 -0
- package/types/world.d.ts +772 -0
- package/ui/Focus.js +51 -0
- package/ui/LoadingScreen.js +42 -0
- package/ui/Parts.js +199 -0
- package/ui/UI.js +167 -0
- package/ui/defaults.js +85 -0
- package/ui/theme.js +124 -0
- package/ui/touchPart.js +49 -0
package/core/scatter.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// Scatter by rule: where instances go in one ground chunk (plants, rocks), pure computation over a ground's height, slope and type
|
|
2
|
+
// functions, no three.js dependency. In core because more than one module places with it -- the generated-ground chunk worker and the
|
|
3
|
+
// chunks laid over any other ground provider (a level model, a code-built ground) -- and a rule must mean the same on every kind of ground.
|
|
4
|
+
|
|
5
|
+
// mulberry32 whose state can be reset: each placement attempt gets its own stream, so skipping an attempt (edited ground, failed rule)
|
|
6
|
+
// never shifts the random numbers of later attempts -- the other trees stay put and felled-tree ids stay valid
|
|
7
|
+
import { mulberry32 } from './mulberry32.js';
|
|
8
|
+
|
|
9
|
+
function stream() {
|
|
10
|
+
const st = { state: 0 };
|
|
11
|
+
const rnd = () => mulberry32(st);
|
|
12
|
+
rnd.seed = s => { st.state = s | 0; };
|
|
13
|
+
return rnd;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Seeded value noise: hash(x, z, salt) 0..1, noise(x, z) smooth 0..1, fbm(x, z, octaves). The terrain generator and cluster rules use the same one */
|
|
17
|
+
export function makeNoise(seed) {
|
|
18
|
+
const SEED = seed | 0;
|
|
19
|
+
function hash(x, z, salt = 0) {
|
|
20
|
+
let h = (Math.imul(x | 0, 374761393) + Math.imul(z | 0, 668265263) + SEED + Math.imul(salt, 1442695041)) | 0;
|
|
21
|
+
h = Math.imul(h ^ (h >>> 13), 1274126177); h ^= h >>> 16;
|
|
22
|
+
return (h >>> 0) / 4294967296;
|
|
23
|
+
}
|
|
24
|
+
function noise(x, z) {
|
|
25
|
+
const xi = Math.floor(x), zi = Math.floor(z), fx = x - xi, fz = z - zi;
|
|
26
|
+
const u = fx * fx * (3 - 2 * fx), v = fz * fz * (3 - 2 * fz);
|
|
27
|
+
const a = hash(xi, zi), b = hash(xi + 1, zi), c = hash(xi, zi + 1), d = hash(xi + 1, zi + 1);
|
|
28
|
+
return a + (b - a) * u + (c - a) * v + (a - b - c + d) * u * v;
|
|
29
|
+
}
|
|
30
|
+
function fbm(x, z, oct = 4) {
|
|
31
|
+
let s = 0, a = 0.5, f = 1, n = 0;
|
|
32
|
+
for (let i = 0; i < oct; i++) { s += a * noise(x * f, z * f); n += a; a *= 0.5; f *= 2.03; }
|
|
33
|
+
return s / n;
|
|
34
|
+
}
|
|
35
|
+
return { hash, noise, fbm };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Rule defaults. Heights are unlimited unless the rule says so: a level floor at y = 12 or a cave at y = -30 grows plants too
|
|
39
|
+
// (a terrain game names its own band above the water, e.g. minHeight: 1.5)
|
|
40
|
+
const RULE = { perChunk: 100, minHeight: -Infinity, maxHeight: Infinity, maxSlope: 0.6, cluster: 'none', scale: [0.8, 1.2], stretch: [1, 1], sink: 0.1,
|
|
41
|
+
tintJitter: 0.1, tints: [], salt: 0, biomes: null, collider: 0, avoidFlat: true };
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Placement over one ground. chunk: edge length (m); seed: placement seed; surface / slope / typeAt (x, z): the ground;
|
|
45
|
+
* skip(x, z): true where nothing may grow (edited terrain cells, flattened plots when the rule says avoidFlat), optional.
|
|
46
|
+
* place(cx, cz, rule, density) returns instance matrices (column-major, chunk-local x / z), instance colors, collision circles (world x, z, radius)
|
|
47
|
+
* and stable ids (the attempt index, independent of density).
|
|
48
|
+
*/
|
|
49
|
+
export function makePlacer({ chunk: CHUNK, seed, surface, slope, typeAt, fbm, skip = null, flat = null }) {
|
|
50
|
+
const SEED = seed | 0;
|
|
51
|
+
return function place(cx, cz, rule, density = 1) {
|
|
52
|
+
const r = { ...RULE, ...rule };
|
|
53
|
+
const base = Math.imul(cx, 92821) ^ Math.imul(cz, 68917) ^ SEED ^ Math.imul(r.salt + 1, 40503), rnd = stream();
|
|
54
|
+
const ox = cx * CHUNK, oz = cz * CHUNK;
|
|
55
|
+
const attempts = Math.round(r.perChunk * density);
|
|
56
|
+
const m = new Float32Array(attempts * 16), c = new Float32Array(attempts * 3), k = new Float32Array(r.collider ? attempts * 3 : 0), ids = new Uint32Array(attempts);
|
|
57
|
+
let n = 0;
|
|
58
|
+
for (let a = 0; a < attempts; a++) {
|
|
59
|
+
rnd.seed(base ^ Math.imul(a + 1, 0x9E3779B1));
|
|
60
|
+
const lx = rnd() * CHUNK, lz = rnd() * CHUNK, wx = ox + lx, wz = oz + lz;
|
|
61
|
+
if (skip?.(wx, wz)) continue; // dug, raised or painted ground: what grew there is gone
|
|
62
|
+
const roll = rnd();
|
|
63
|
+
if (r.cluster !== 'none') {
|
|
64
|
+
const f = fbm(wx * 0.008 + 9, wz * 0.008 - 4, 3);
|
|
65
|
+
let t = Math.min(1, Math.max(0, (f - 0.38) / 0.24));
|
|
66
|
+
if (r.cluster === 'meadow') t = 1 - t;
|
|
67
|
+
if (roll > t * t * 0.9 + 0.03) continue;
|
|
68
|
+
} else if (roll > (r.chance ?? 1)) continue;
|
|
69
|
+
const h = surface(wx, wz), sl = slope(wx, wz);
|
|
70
|
+
if (h < r.minHeight || h > r.maxHeight || sl > r.maxSlope) continue;
|
|
71
|
+
if (r.biomes) { const b = typeAt(wx, wz, h, sl); const w = r.biomes[b]; if (!w || rnd() > w) continue; }
|
|
72
|
+
if (r.avoidFlat && flat?.(wx, wz)) continue;
|
|
73
|
+
const s = r.scale[0] + rnd() * (r.scale[1] - r.scale[0]);
|
|
74
|
+
const sy = s * (r.stretch[0] + rnd() * (r.stretch[1] - r.stretch[0]));
|
|
75
|
+
const yaw = rnd() * Math.PI * 2, co = Math.cos(yaw), si = Math.sin(yaw);
|
|
76
|
+
const o = n * 16;
|
|
77
|
+
m[o] = co * s; m[o + 1] = 0; m[o + 2] = -si * s; m[o + 3] = 0;
|
|
78
|
+
m[o + 4] = 0; m[o + 5] = sy; m[o + 6] = 0; m[o + 7] = 0;
|
|
79
|
+
m[o + 8] = si * s; m[o + 9] = 0; m[o + 10] = co * s; m[o + 11] = 0;
|
|
80
|
+
m[o + 12] = lx; m[o + 13] = h - r.sink * s; m[o + 14] = lz; m[o + 15] = 1;
|
|
81
|
+
const jt = r.tintJitter;
|
|
82
|
+
let tr = 1 - jt / 2 + rnd() * jt, tg = 1 - jt / 2 + rnd() * jt, tb = 1 - jt / 2 + rnd() * jt;
|
|
83
|
+
const pick = rnd(); let acc = 0;
|
|
84
|
+
for (const t of r.tints) { acc += t.chance; if (pick < acc) { tr = t.color[0]; tg = t.color[1]; tb = t.color[2]; break; } }
|
|
85
|
+
c[n * 3] = tr; c[n * 3 + 1] = tg; c[n * 3 + 2] = tb;
|
|
86
|
+
if (r.collider) { k[n * 3] = wx; k[n * 3 + 1] = wz; k[n * 3 + 2] = r.collider * s; }
|
|
87
|
+
ids[n] = a; // stable id: attempt index. Independent of density under one seed (density only sets how many attempts), felled-tree records rely on it
|
|
88
|
+
n++;
|
|
89
|
+
}
|
|
90
|
+
return { m: m.slice(0, n * 16), c: c.slice(0, n * 3), k: k.slice(0, r.collider ? n * 3 : 0), ids: ids.slice(0, n), n };
|
|
91
|
+
};
|
|
92
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// Scene and render settings on the engine (split out of Engine.js): add / detach / remove objects, pixel ratio, shadows, fog distance,
|
|
2
|
+
// tone mapping and exposure.
|
|
3
|
+
// add registers each root in the thing registry (things.js) so engine.thing / hit.thing can say what it is and what a save keeps; engine.scene.add
|
|
4
|
+
// stays the plain three.js way in, with no registration.
|
|
5
|
+
import { DEV } from './validate.js';
|
|
6
|
+
import { codedError, renamed } from './errorHints.js';
|
|
7
|
+
import { thing } from './thingOps.js';
|
|
8
|
+
import { TONE, exposureDriver } from './look/coreParts.js';
|
|
9
|
+
|
|
10
|
+
export { TONE } from './look/coreParts.js'; // style.toneMapping names -> three constants (kept here for older imports)
|
|
11
|
+
|
|
12
|
+
/** A short stack for "added at main.js:50" (dev): 4 frames are enough (this, add, its caller) and keep the cost low; it is formatted only when read */
|
|
13
|
+
function captureStack() {
|
|
14
|
+
const lim = Error.stackTraceLimit; Error.stackTraceLimit = 4;
|
|
15
|
+
try { return new Error(); } finally { Error.stackTraceLimit = lim; }
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const sceneMethods = {
|
|
19
|
+
/**
|
|
20
|
+
* Add objects to the scene and register them (engine.thing). The last argument may be an options object: id makes the object's thing.set /
|
|
21
|
+
* thing.remove changes saved (unique, no '#'; with several objects pass id for one object only); without it a unique obj.name is used, else a
|
|
22
|
+
* session id obj#n. save: true says you expect it to be saved: dev warns when it cannot be (no id, or added during play). Returns the first object.
|
|
23
|
+
* @example engine.add(windmill, { id: 'windmill' }); // at setup: thing.set changes to it are saved
|
|
24
|
+
* @example engine.add(spark); // fine for effects: lives this session only
|
|
25
|
+
* @template {import('three').Object3D} T
|
|
26
|
+
* @param {[T, ...any[]]} objs Object3D roots, optionally followed by { id?, save? }
|
|
27
|
+
* @returns {T}
|
|
28
|
+
*/
|
|
29
|
+
add(...objs) {
|
|
30
|
+
const last = objs.at(-1), opts = last && !last.isObject3D ? objs.pop() : null;
|
|
31
|
+
if (opts?.id != null && objs.length > 1) throw codedError('thing-id', `engine.add(a, b, …, { id: '${opts.id}' }): an id names one object; add the others in their own call`);
|
|
32
|
+
const T = this._things, stack = DEV && !opts?.owner && T.wantStack() ? captureStack() : null;
|
|
33
|
+
if (DEV && opts?.owner !== 'world') for (const o of objs) {
|
|
34
|
+
const rid = this._things.idOf(o);
|
|
35
|
+
if (rid) throw codedError('thing-owned', `engine.add(): this object is the model of world record '${rid}' (world builds, places and tears it down). Change the record instead: ops.run('thing.set', { id: '${rid}', position }) or world.set / world.move`);
|
|
36
|
+
}
|
|
37
|
+
this.scene.add(...objs);
|
|
38
|
+
for (const o of objs) T.add(o, opts, stack);
|
|
39
|
+
return objs[0];
|
|
40
|
+
},
|
|
41
|
+
/**
|
|
42
|
+
* What a thing is and what a save keeps: a world record id, an id / name given to engine.add, or any Object3D (its registered ancestor).
|
|
43
|
+
* Returns { id, kind, owner, at, phase, saved: 'record' | 'code' | 'session' | 'engine', keeps, loses, edit, object } (object is the live
|
|
44
|
+
* Object3D); throws with the closest id when nothing matches. Change it with ops.run('thing.set', { id, position }) or 'thing.remove'.
|
|
45
|
+
* @example engine.thing('windmill').saved // 'code': rebuilt by code each start, thing.set changes saved
|
|
46
|
+
* @example engine.thing(engine.pick(0, 0).object).edit
|
|
47
|
+
* @param {string | import('three').Object3D} idOrObj
|
|
48
|
+
* @returns {import('../types/core').Thing}
|
|
49
|
+
*/
|
|
50
|
+
thing(idOrObj) { return thing(this, idOrObj); },
|
|
51
|
+
/** @internal Dev: a module found two systems managing one object; listed in describe().scene.conflicts and warned once (code thing-owned) */
|
|
52
|
+
thingConflict(text) { this._things.conflict(text); },
|
|
53
|
+
/** Detach from the parent only (no GPU release; use when you will add it back). Use remove for objects you are done with */
|
|
54
|
+
detach(...objs) { for (const o of objs) o.removeFromParent(); },
|
|
55
|
+
/**
|
|
56
|
+
* Delete an object for good: detach it, unregister its rays and dispose geometries and materials (textures are kept). Geometry and materials shared by assets
|
|
57
|
+
* model clones are only decremented in use count (see Assets.js)
|
|
58
|
+
*/
|
|
59
|
+
remove(...objs) {
|
|
60
|
+
for (const o of objs) {
|
|
61
|
+
o.removeFromParent();
|
|
62
|
+
this._things.forget(o);
|
|
63
|
+
this.rays.forget(o);
|
|
64
|
+
this.assets.forget(o);
|
|
65
|
+
const shared = this.assets.shared, held = this.batching.held; // a batch still drawing the same geometry / material keeps it alive
|
|
66
|
+
o.traverse(c => {
|
|
67
|
+
if (c.geometry && !shared.has(c.geometry) && !held.has(c.geometry)) c.geometry.dispose();
|
|
68
|
+
for (const m of [].concat(c.material || [])) if (!shared.has(m) && !held.has(m)) m.dispose();
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
setPixelRatio(p) { this.renderer.setPixelRatio(p); this.post.setPixelRatio(p); },
|
|
73
|
+
/**
|
|
74
|
+
* Master shadow switch. Off: remember each light's castShadow (the game's choice) then turn it off; on: restore only the lights that cast before (lights the
|
|
75
|
+
* game turned off stay off).
|
|
76
|
+
* Lights added while off are left alone (the renderer has shadows off, so it makes no difference).
|
|
77
|
+
*/
|
|
78
|
+
setShadows(on) {
|
|
79
|
+
this.shadows = on;
|
|
80
|
+
this.renderer.shadowMap.enabled = on;
|
|
81
|
+
this.scene.traverse(o => {
|
|
82
|
+
if (o.isLight && o.shadow) {
|
|
83
|
+
const u = o.userData;
|
|
84
|
+
if (!on) { if (!('threedogCastShadow' in u)) u.threedogCastShadow = o.castShadow; o.castShadow = false; }
|
|
85
|
+
else if ('threedogCastShadow' in u) { o.castShadow = u.threedogCastShadow; delete u.threedogCastShadow; }
|
|
86
|
+
}
|
|
87
|
+
if (o.material) [].concat(o.material).forEach(m => m.needsUpdate = true);
|
|
88
|
+
});
|
|
89
|
+
this.events.emit('settings:shadows', on);
|
|
90
|
+
},
|
|
91
|
+
setFogFar(d) {
|
|
92
|
+
this.fogFar = d;
|
|
93
|
+
if (this.scene.fog) { this.scene.fog.far = d; this.scene.fog.near = d * 0.3; }
|
|
94
|
+
this.camera.far = d + 150; this.camera.updateProjectionMatrix();
|
|
95
|
+
},
|
|
96
|
+
/** Renamed in 0.2: throws and names the new call, engine.look.tone.set({ mapping }). @param {string} _kind @returns {never} */
|
|
97
|
+
setToneMapping(_kind) { return renamed('setToneMapping'); },
|
|
98
|
+
/** Renamed in 0.2: throws and names the new call, engine.look.tone.set({ exposure }). @param {any} _v @returns {never} */
|
|
99
|
+
setExposure(_v) { return renamed('setExposure'); }
|
|
100
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Screen point -> ground point: what clicking the ground means for click-to-move, the rts camera and grid placement. In core because several modules use it.
|
|
2
|
+
import * as THREE from 'three';
|
|
3
|
+
|
|
4
|
+
const _ray = new THREE.Raycaster(), _ndc = new THREE.Vector2();
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Screen coordinates -> point on the ground (for click-to-move). Samples engine.surface along the ray, then bisects once it crosses the ground.
|
|
8
|
+
* ndcX/ndcY are screen coordinates in -1..1 (input.pointer.ndcX/ndcY). Returns null if the ray points up or the ground is too far.
|
|
9
|
+
* @param {any} e engine
|
|
10
|
+
* @param {number} ndcX
|
|
11
|
+
* @param {number} ndcY
|
|
12
|
+
* @param {{ maxDistance?: number }} [opts]
|
|
13
|
+
* @returns {THREE.Vector3 | null}
|
|
14
|
+
*/
|
|
15
|
+
export function screenToGround(e, ndcX, ndcY, { maxDistance = 1500 } = {}) {
|
|
16
|
+
const cam = e.camera;
|
|
17
|
+
cam.updateMatrixWorld();
|
|
18
|
+
_ray.setFromCamera(_ndc.set(ndcX, ndcY), cam);
|
|
19
|
+
const o = _ray.ray.origin, d = _ray.ray.direction;
|
|
20
|
+
const above = t => o.y + d.y * t - e.surface(o.x + d.x * t, o.z + d.z * t);
|
|
21
|
+
let t0 = 0, h0 = above(0);
|
|
22
|
+
if (h0 < 0) return new THREE.Vector3(o.x, e.surface(o.x, o.z), o.z); // camera is underground
|
|
23
|
+
let t = 0;
|
|
24
|
+
while (t < maxDistance) {
|
|
25
|
+
// Step size: faster the higher above ground (estimated from descent rate), but at most 8 m and at least 0.25 m
|
|
26
|
+
const step = d.y < -1e-3 ? Math.min(8, Math.max(0.25, h0 / -d.y * 0.5)) : 8;
|
|
27
|
+
t = t0 + step;
|
|
28
|
+
const h = above(t);
|
|
29
|
+
if (h <= 0) {
|
|
30
|
+
let a = t0, b = t;
|
|
31
|
+
for (let i = 0; i < 14; i++) { const m = (a + b) / 2; if (above(m) > 0) a = m; else b = m; }
|
|
32
|
+
const x = o.x + d.x * b, z = o.z + d.z * b;
|
|
33
|
+
return new THREE.Vector3(x, e.surface(x, z), z);
|
|
34
|
+
}
|
|
35
|
+
t0 = t; h0 = h;
|
|
36
|
+
if (d.y >= 0 && h0 > 2000) break;
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
package/core/services.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Engine services: the objects every engine owns besides rendering (events, i18n, saves, input, audio, assets, clock, ops, jobs, streaming...).
|
|
2
|
+
// Split out of the Engine constructor so it stays readable; the order below matters (later services read earlier ones), do not reorder.
|
|
3
|
+
import { Events } from './Events.js';
|
|
4
|
+
import { I18n } from './I18n.js';
|
|
5
|
+
import { Saves } from './Saves.js';
|
|
6
|
+
import { Session } from './session.js';
|
|
7
|
+
import { Input } from './Input.js';
|
|
8
|
+
import { Audio } from './Audio.js';
|
|
9
|
+
import { Assets } from './Assets.js';
|
|
10
|
+
import { Clock } from './Clock.js';
|
|
11
|
+
import { Vars } from './Vars.js';
|
|
12
|
+
import { Budget } from './Budget.js';
|
|
13
|
+
import { Rays } from './Rays.js';
|
|
14
|
+
import { Random } from './Random.js';
|
|
15
|
+
import { UrlState } from './UrlState.js';
|
|
16
|
+
import { Jobs } from './Jobs.js';
|
|
17
|
+
import { Threads } from './Threads.js';
|
|
18
|
+
import { Commits } from './Commits.js';
|
|
19
|
+
import { Ops } from './Ops.js';
|
|
20
|
+
import { Views } from './Views.js';
|
|
21
|
+
import { Stream } from './Stream.js';
|
|
22
|
+
import { Batching } from './Batching.js';
|
|
23
|
+
import { claims } from './claims.js';
|
|
24
|
+
import { DebugOverrides } from './DebugOverrides.js';
|
|
25
|
+
import { describeApi } from './Describe.js';
|
|
26
|
+
import { reportListenerError } from './errors.js';
|
|
27
|
+
import { defineSkipOp } from './skip.js';
|
|
28
|
+
import { installThings } from './thingOps.js';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Create the engine services on `engine` (called once from the Engine constructor, after the renderer, scene and uniforms exist).
|
|
32
|
+
* @param engine the engine under construction
|
|
33
|
+
* @param o the createEngine options these services read, already defaulted by the constructor
|
|
34
|
+
*/
|
|
35
|
+
export function createServices(engine, { canvas, validate, locale, strings, saveKey, joystick, bindings, padBindings, audio, decoders, budget, seed, headless, urlState, threads, batching }) {
|
|
36
|
+
engine.events = new Events({ check: import.meta.env?.DEV && validate !== false, // event-name spelling check runs in development only
|
|
37
|
+
onError: (name, err) => reportListenerError(engine, name, err), now: () => engine.tick }); // listener errors are handled by severity (errors.js)
|
|
38
|
+
engine.i18n = new I18n(engine, { locale, strings });
|
|
39
|
+
engine.saves = new Saves(engine, { prefix: saveKey + '-' });
|
|
40
|
+
engine.session = new Session(engine); // new game / continue / back to title from a clean slate (session.js)
|
|
41
|
+
engine.input = new Input(engine, canvas, { joystick, bindings, padBindings });
|
|
42
|
+
engine.events.on('ui:open', id => engine.openWindows.add(id));
|
|
43
|
+
engine.events.on('ui:close', id => engine.openWindows.delete(id));
|
|
44
|
+
engine.audio = new Audio(engine, audio);
|
|
45
|
+
engine.decoders = decoders;
|
|
46
|
+
engine.assets = new Assets(engine);
|
|
47
|
+
engine.clock = new Clock(engine); // game clock (game seconds, timers)
|
|
48
|
+
engine.vars = new Vars(engine); // story flags and counters
|
|
49
|
+
engine.budget = new Budget(engine); // performance budget (default off)
|
|
50
|
+
if (budget) engine.budget.enable(budget);
|
|
51
|
+
engine.rays = new Rays(engine); // ray registry: engine.raycast / pick
|
|
52
|
+
Object.assign(engine, describeApi(engine)); // describe / describeText / inspect / explain, see Describe.js
|
|
53
|
+
engine.random = new Random(seed ?? (headless ? 1 : Date.now())); // wall-clock: differs per run when no seed is given
|
|
54
|
+
engine.saves.register('random', { atomic: true, save: () => engine.random.toJSON(), load: d => engine.random.fromJSON(d) });
|
|
55
|
+
engine._urlState = new UrlState(engine, { fromUrl: urlState });
|
|
56
|
+
// who holds the engine still, one claims() each (claims.js: same owner rules for all, owners() in describe); pause / freeze / takeCamera in holds.js
|
|
57
|
+
const now = () => engine.elapsed ?? 0;
|
|
58
|
+
engine._freezers = claims({ what: 'engine.freeze', now }); // who froze gameplay
|
|
59
|
+
engine._pausers = claims({ what: 'engine.pause', now }); // who paused the loop; it resumes only when empty
|
|
60
|
+
engine._cameraClaims = claims({ what: 'engine.takeCamera', now }); // who holds the camera; the latest is in charge (cameraOverride)
|
|
61
|
+
engine.tick = 0; // fixed-step count (the gameplay timeline: commits, event history and input records use it; stops while frozen)
|
|
62
|
+
engine.commits = new Commits(engine); // background results that affect gameplay take effect on a fixed tick (see Commits.js)
|
|
63
|
+
engine.ops = new Ops(engine); // one entry point for actions (define / run / can / list / recent), see Ops.js
|
|
64
|
+
engine.views = new Views(engine); // named fixed camera views for repeatable screenshots (Views.js)
|
|
65
|
+
defineSkipOp(engine); // 'time.skip', behind engine.skip (skip.js)
|
|
66
|
+
installThings(engine); // engine.add registry, thing.set / remove, 'scene' save part
|
|
67
|
+
engine.debug = new DebugOverrides(engine); // diagnostic overrides and view modes, all core; the debug() panel module adds engine.debug.panel (DebugOverrides.js)
|
|
68
|
+
engine.jobs = new Jobs(engine); // frame-spread job scheduler
|
|
69
|
+
engine.threads = new Threads(threads); // worker pool (see Threads.js); workers start only when a lane is used
|
|
70
|
+
// spatial stream-in and the stream sources (where the world is loaded: stream, models, terrain, colliders read them)
|
|
71
|
+
engine.stream = new Stream(engine);
|
|
72
|
+
engine.batching = new Batching(engine, batching); // repeated static models drawn as InstancedMesh batches (Batching.js)
|
|
73
|
+
}
|
package/core/session.js
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// engine.session: one playthrough, from "new game" or "load" until the next one. Starting a playthrough leaves nothing of the previous one behind.
|
|
2
|
+
// engine.session.newGame() // the state right after start() (world, containers, vars, quests, clock, sky, weather, random...), as if the page had just opened
|
|
3
|
+
// await engine.session.load('slot1') // continue, or retry from a checkpoint: the new-game state with the save on top (a part the save lacks gets its new-game state)
|
|
4
|
+
// engine.session.quit() // back to the title screen with a clean slate (the title's Start calls newGame)
|
|
5
|
+
// engine.session.track(handle) // a listener / timer / hook the game adds during play: removed when the playthrough ends
|
|
6
|
+
// Versus engine.saves.load(slot): that applies a save onto the running playthrough (quick load) and keeps what the game added during play.
|
|
7
|
+
// Deleting a save is engine.saves.remove(slot); none of these touch stored saves.
|
|
8
|
+
//
|
|
9
|
+
// What ending a playthrough clears: handles passed to track(), clock function timers added after start() (boot-time ones come back with their original delay),
|
|
10
|
+
// a running engine.skip (cancelled), background results not yet applied (commits: worker / job results requested in the old playthrough never land), and every
|
|
11
|
+
// save part (the state captured when start() finished is applied). Modules end their own part on 'session:end' (a cutscene is skipped, the music stops),
|
|
12
|
+
// and the camera starts over on 'session:start'. Listeners and hooks the game registered at boot stay: they belong to the game, not the playthrough.
|
|
13
|
+
// Events: 'session:end' (before the reset; flow returns to its start state), 'session:start' { kind: 'new' | 'load', slot? } (after; flow goes to 'playing').
|
|
14
|
+
import { codedError } from './errorHints.js';
|
|
15
|
+
import { DEV as IS_DEV, warnOnce } from './validate.js';
|
|
16
|
+
|
|
17
|
+
const DEV = {
|
|
18
|
+
early: 'engine.session.{fn}() was called before engine.start() finished: the new-game state is captured when loading completes. Call it from a button or after `await engine.start()`.',
|
|
19
|
+
badHandle: 'engine.session.track(handle): handle must have remove(), like the result of engine.events.on / onFixed / clock.after. Got {got}.',
|
|
20
|
+
placed: '[session] {n} world record(s) were created or removed by code before the game started ({ids}): a new game should equal the content. '
|
|
21
|
+
+ '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',
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Dev check on the new-game state: authored things come from content, so a new game has no runtime records but the player and removes nothing.
|
|
26
|
+
* Changed fields are not checked: simulation may already move authored records (an NPC walking its schedule) while loading runs in real time. @internal
|
|
27
|
+
*/
|
|
28
|
+
function codePlaced(parts) {
|
|
29
|
+
const w = parts?.world; if (!w) return;
|
|
30
|
+
const ids = [...Object.entries(w.records || {}).filter(([, r]) => r.kind !== 'player').map(([id]) => id), ...(w.removed || [])];
|
|
31
|
+
if (ids.length) warnOnce(DEV.placed.replace('{n}', String(ids.length)).replace('{ids}', ids.slice(0, 8).join(', ') + (ids.length > 8 ? ', …' : '')));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The fixed-step hook behind saves.autosave: saves 'auto' every `every` fixed seconds of play; outside play (session.playing false, or a gameplay error) it counts from zero again.
|
|
36
|
+
* @param {any} saves
|
|
37
|
+
* @param {number} every fixed seconds
|
|
38
|
+
* @param {() => void} onRemove
|
|
39
|
+
* @returns {{ remove(): void }}
|
|
40
|
+
* @internal
|
|
41
|
+
*/
|
|
42
|
+
export function autosaveHook(saves, every, onRemove) {
|
|
43
|
+
const e = saves.engine;
|
|
44
|
+
let t = 0;
|
|
45
|
+
const tick = e.onFixed(dt => {
|
|
46
|
+
if (!e.session.playing || e.error) { t = 0; return; } // nothing of a playthrough to keep: start counting again once one runs
|
|
47
|
+
if ((t += dt) < every) return;
|
|
48
|
+
t = 0; saves.save('auto');
|
|
49
|
+
});
|
|
50
|
+
return { remove: () => { tick.remove(); onRemove(); } };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** engine.session: new game / continue / back to title, each from a clean slate. */
|
|
54
|
+
export class Session {
|
|
55
|
+
/** @internal */
|
|
56
|
+
constructor(engine) {
|
|
57
|
+
/** @internal */ this.engine = engine;
|
|
58
|
+
/** @internal JSON of the state when start() finished */ this._base = null;
|
|
59
|
+
/** @internal clock function timers at that moment, with their remaining delay */ this._timers = [];
|
|
60
|
+
/** @internal */ this._tracked = new Set();
|
|
61
|
+
/** @internal true while newGame / load / quit replace the state */ this._busy = false;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* True while a playthrough runs: start() has finished, no newGame / load / quit is replacing the state, and the title screen is not up.
|
|
66
|
+
* Autosave and other "only during play" work check it.
|
|
67
|
+
* @type {boolean}
|
|
68
|
+
*/
|
|
69
|
+
get playing() { return !!this._base && !this._busy && !this.engine.ui.isOpen('title'); }
|
|
70
|
+
|
|
71
|
+
/** @internal Called by start() once the world is ready: what newGame returns to */
|
|
72
|
+
_capture() {
|
|
73
|
+
const base = this.engine.saves.collect();
|
|
74
|
+
if (IS_DEV) codePlaced(base.parts);
|
|
75
|
+
this._base = JSON.stringify(base);
|
|
76
|
+
this._timers = this.engine.clock.snapshotFnTimers();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** @internal A save part registered after start() (engine.use later): its state now is its new-game state, so newGame resets it too */
|
|
80
|
+
_late(key) {
|
|
81
|
+
if (!this._base) return;
|
|
82
|
+
const base = JSON.parse(this._base), p = this.engine.saves.providers.get(key);
|
|
83
|
+
if (key in base.parts) return;
|
|
84
|
+
try { base.parts[key] = p.save(); base.versions[key] = p.version; } catch { return; } // its save() cannot run yet: newGame leaves this part as it is
|
|
85
|
+
this._base = JSON.stringify(base);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Keep a handle only for this playthrough: newGame / load / quit call handle.remove(). Returns the handle.
|
|
90
|
+
* @template {{ remove(): void }} H
|
|
91
|
+
* @param {H} handle
|
|
92
|
+
* @returns {H}
|
|
93
|
+
* @example
|
|
94
|
+
* // a quest's helper listener lives only as long as this playthrough
|
|
95
|
+
* engine.session.track(engine.events.on('npc:talk', ({ id }) => { if (id === 'baker') engine.vars.setFlag('metBaker'); }));
|
|
96
|
+
*/
|
|
97
|
+
track(handle) {
|
|
98
|
+
if (typeof handle?.remove !== 'function') throw codedError('session-handle', DEV.badHandle.replace('{got}', String(handle)));
|
|
99
|
+
this._tracked.add(handle);
|
|
100
|
+
return handle;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Start a new playthrough from the state the game had right after start(). Returns Promise<boolean> (false only if a save part failed to load; the game is then rolled back).
|
|
105
|
+
* @returns {Promise<boolean>}
|
|
106
|
+
* @example
|
|
107
|
+
* // a "Restart" button in a game-over screen
|
|
108
|
+
* restartBtn.onclick = () => engine.session.newGame();
|
|
109
|
+
*/
|
|
110
|
+
newGame() { return this._begin('newGame', () => this.engine.saves.apply(this._baseData(), '(new game)'), { kind: 'new' }); }
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Continue from a save (or retry from a checkpoint) with nothing of the current playthrough left over: the new-game state with the save on top,
|
|
114
|
+
* so a part the save does not have (a module added in a later version of the game) starts from its new-game state.
|
|
115
|
+
* A save that cannot be read (missing, corrupt, from a newer build) is refused before anything changes: returns false, the current game and the save stay as they were.
|
|
116
|
+
* @param {string} [slot]
|
|
117
|
+
* @returns {Promise<boolean>}
|
|
118
|
+
* @example
|
|
119
|
+
* engine.events.on('player:dead', () => engine.session.load('checkpoint')); // retry; the checkpoint was saved with engine.saves.save('checkpoint')
|
|
120
|
+
*/
|
|
121
|
+
async load(slot = 'auto') {
|
|
122
|
+
const S = this.engine.saves, bad = S.check(slot);
|
|
123
|
+
if (bad) return bad === 'missing' ? false : S.load(slot); // load shows the message and changes nothing
|
|
124
|
+
return this._begin('load', () => S._load(slot, this._baseData()), { kind: 'load', slot });
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* End the playthrough and show the title screen (the title part when the game turned it on; flow returns to its start state).
|
|
129
|
+
* The state behind the title is the new-game state, so nothing from the old playthrough runs while the title is up.
|
|
130
|
+
* @returns {Promise<boolean>}
|
|
131
|
+
* @example settingsBackToTitle.onclick = () => engine.session.quit();
|
|
132
|
+
*/
|
|
133
|
+
async quit() {
|
|
134
|
+
const ok = await this._reset('quit', () => this.engine.saves.apply(this._baseData(), '(new game)'));
|
|
135
|
+
this.engine.ui.open('title');
|
|
136
|
+
return ok;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** @internal the new-game state as save data */
|
|
140
|
+
_baseData() {
|
|
141
|
+
if (!this._base) throw codedError('session-early', DEV.early.replace('{fn}', 'newGame / load'));
|
|
142
|
+
return JSON.parse(this._base);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** @internal end the playthrough, apply, then announce the new one */
|
|
146
|
+
async _begin(fn, apply, info) {
|
|
147
|
+
const ok = await this._reset(fn, apply);
|
|
148
|
+
this.engine.events.emit('session:start', info);
|
|
149
|
+
return ok;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** @internal */
|
|
153
|
+
async _reset(fn, apply) {
|
|
154
|
+
const e = this.engine;
|
|
155
|
+
if (!this._base) throw codedError('session-early', DEV.early.replace('{fn}', fn));
|
|
156
|
+
this._busy = true;
|
|
157
|
+
try {
|
|
158
|
+
e.events.emit('session:end'); // modules end their part: a running engine.skip is cancelled, a cutscene skipped, the music stopped
|
|
159
|
+
for (const h of this._tracked) h.remove();
|
|
160
|
+
this._tracked.clear();
|
|
161
|
+
await new Promise(r => setTimeout(r, 0)); // main-loop: one macrotask, so what session:end listeners started (a skipped cutscene's last steps) settles first
|
|
162
|
+
e.commits.invalidate(); // apply invalidates too, but a refused apply must not let old results land either
|
|
163
|
+
const ok = await apply();
|
|
164
|
+
e.clock.restoreFnTimers(this._timers); // event timers came back with the save; function timers are exactly the boot-time ones, each with its original delay
|
|
165
|
+
return ok;
|
|
166
|
+
} finally { this._busy = false; }
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** @internal for describe */
|
|
170
|
+
describe() { return { tracked: this._tracked.size, playing: this.playing }; }
|
|
171
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
|
|
3
|
+
// three 0.187 shadow filters. cost = rough relative shadow-pass cost vs pcf (an estimate, not measured: vsm adds a blur pass and
|
|
4
|
+
// float targets, basic is a single hard-edged tap).
|
|
5
|
+
export const SHADOW_TYPES = {
|
|
6
|
+
basic: { three: THREE.BasicShadowMap, cost: 0.8 },
|
|
7
|
+
pcf: { three: THREE.PCFShadowMap, cost: 1 },
|
|
8
|
+
vsm: { three: THREE.VSMShadowMap, cost: 1.6 },
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/** Validate a shadow type name; throws with the allowed values (a wrong name would otherwise silently fall back to the default look). */
|
|
12
|
+
export function shadowTypeOf(name, where) {
|
|
13
|
+
if (Object.hasOwn(SHADOW_TYPES, name)) return SHADOW_TYPES[name].three;
|
|
14
|
+
throw new Error(`${where}: unknown shadow type ${JSON.stringify(name)}. Use one of: ${Object.keys(SHADOW_TYPES).map(k => `'${k}'`).join(', ')}.`);
|
|
15
|
+
}
|
package/core/skip.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// Skipping time (part of Engine, mixed into Engine.prototype): engine.skip({ to: '06:00' }) for "sleep until morning", { seconds } for "wait a while".
|
|
2
|
+
// Why not step(): a long skip can be hours of fixed steps. skip moves game seconds in segments that end at each timed thing
|
|
3
|
+
// (a clock timer due, a sky clock mark: midnight, an at time, a between edge), so after / every / at / daily / between / day:start / season:change
|
|
4
|
+
// fire in the same order and the same number of times as when stepping. The world catches up once at the end: every record with far
|
|
5
|
+
// gets the whole span as one far(rec, dt) (records added by a timer mid-skip owe only from when they were added).
|
|
6
|
+
// What does not run while skipping: onFixed callbacks, module fixed hooks, physics and near simulation; fixed seconds (engine.elapsed, engine.tick) stay put.
|
|
7
|
+
// Modules that keep their own time implement the hook skip(dt, e, done): dt is the segment in fixed seconds, done is true on the last segment (do expensive catch-up once there).
|
|
8
|
+
// The jump itself is the op 'time.skip' (logged, replayable, allowed to write saved state); skip() adds the 'skip' input context, optional fade and autosave around it.
|
|
9
|
+
import { parseClock } from './dayTime.js';
|
|
10
|
+
import { checkOptions } from './validate.js';
|
|
11
|
+
import { reportError } from './errors.js';
|
|
12
|
+
import { codedError } from './errorHints.js';
|
|
13
|
+
import { fadeScreen } from '../ui/UI.js';
|
|
14
|
+
|
|
15
|
+
const NUDGE = 1e-6; // game seconds past each mark: land just after it, so float error never leaves a mark uncrossed
|
|
16
|
+
const STRINGS = {
|
|
17
|
+
amount: 'engine.skip(): pass { to: "06:00" } (until the sky clock next reads 06:00) or { seconds: 600 } (game seconds, > 0); got {got}',
|
|
18
|
+
noSky: 'engine.skip({ to }) needs the sky module (it reads the sky clock); without sky pass { seconds } (game seconds)',
|
|
19
|
+
fixedDay: 'engine.skip({ to }): the sky time of day never moves (sky({ dayLength: Infinity })), so the clock never reads that time; pass { seconds } (game seconds)',
|
|
20
|
+
hook: 'skip hook of module {name}',
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/** Game seconds to skip for opts ({ seconds } or { to } = the next time the sky clock reads that time; the current time itself means a full day) */
|
|
24
|
+
function amount(e, o) {
|
|
25
|
+
const bad = () => codedError('skip-amount', STRINGS.amount.replace('{got}', JSON.stringify(o)));
|
|
26
|
+
if (o.seconds != null) { if (!(o.seconds > 0) || !Number.isFinite(o.seconds)) throw bad(); return o.seconds; }
|
|
27
|
+
if (o.to == null) throw bad();
|
|
28
|
+
const sky = e.sky; if (!sky) throw codedError('skip-amount', STRINGS.noSky);
|
|
29
|
+
if (!Number.isFinite(sky.dayLength)) throw codedError('skip-amount', STRINGS.fixedDay); // the clock never reaches that time: an endless skip otherwise
|
|
30
|
+
const f = parseClock(o.to, sky.hoursPerDay) % 1;
|
|
31
|
+
if (!Number.isFinite(f)) throw bad();
|
|
32
|
+
return ((((f - sky.timeOfDay) % 1) + 1) % 1 || 1) * sky.dayLength;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Advance game seconds in segments (see the top of the file). Called by the op 'time.skip' */
|
|
36
|
+
function jump(e, seconds) {
|
|
37
|
+
const clock = e.clock, sky = e.sky, ts0 = clock.timeScale, ts = ts0 > 0 ? ts0 : 1;
|
|
38
|
+
clock.timeScale = ts; // a stopped clock (0) would need infinite fixed seconds: skip as if at 1x
|
|
39
|
+
let left = seconds, ended = false;
|
|
40
|
+
const off = e.events.on('session:end', () => { ended = true; }); // a timer callback ended the playthrough mid-skip: the new one must not be skipped
|
|
41
|
+
try {
|
|
42
|
+
while (left > 0 && !ended) {
|
|
43
|
+
let seg = Math.min(left, clock.untilNext() + NUDGE, sky ? sky.untilMark() + NUDGE : Infinity);
|
|
44
|
+
left -= seg;
|
|
45
|
+
if (left < NUDGE) { seg += left; left = 0; } // no sliver segment at the end
|
|
46
|
+
const dt = seg / ts, done = left === 0;
|
|
47
|
+
for (const h of e._hooks.skip) {
|
|
48
|
+
try { h.fn(dt, e, done); } catch (err) { reportError(e, err, STRINGS.hook.replace('{name}', h.name), { module: h.mod }); }
|
|
49
|
+
}
|
|
50
|
+
clock.tick(dt);
|
|
51
|
+
}
|
|
52
|
+
} finally { clock.timeScale = ts0; off.remove(); }
|
|
53
|
+
if (ended) return null;
|
|
54
|
+
e.events.emit('time:skip', { seconds });
|
|
55
|
+
return { seconds, clock: sky?.clock ?? null, day: sky?.day ?? null };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Register the op behind engine.skip (called once by the Engine constructor) */
|
|
59
|
+
export function defineSkipOp(e) {
|
|
60
|
+
e.ops.define('time.skip', {
|
|
61
|
+
desc: 'Skip game time forward by seconds game seconds (timers, sky clock events and world far simulation catch up in order)',
|
|
62
|
+
args: { seconds: 'number' },
|
|
63
|
+
can: (_, a) => a.seconds > 0 ? true : 'notForward',
|
|
64
|
+
run: (eng, a) => jump(eng, a.seconds),
|
|
65
|
+
reasons: { notForward: 'seconds must be > 0 (time only skips forward)' },
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export const skipMethods = {
|
|
70
|
+
/**
|
|
71
|
+
* Skip game time forward (sleep until morning, wait an hour) without stepping every fixed step.
|
|
72
|
+
* Timers fire in time order as if stepped: clock.after / every, sky.at / daily / between, day:start, season:change (each crossing once; catchUp does not apply).
|
|
73
|
+
* World records with far catch up the whole span in one far(rec, dt) (dt in fixed seconds = game seconds / timeScale); growth and respawns measured with clock.now are exact.
|
|
74
|
+
* Not run while skipping: onFixed, module fixed hooks, physics, near simulation. Input is blocked (an opaque 'skip' input context) and gameplay frozen for the whole skip; emits time:skip { seconds } after the jump.
|
|
75
|
+
* With fade 0 (default) the time has already moved when skip returns; with fade > 0 it fades out, jumps, (saves), fades in (through flow.transition when flow is installed),
|
|
76
|
+
* and the Promise resolves after the fade in, which needs frames: in a paused test keep calling engine.step while waiting.
|
|
77
|
+
* @example await engine.skip({ to: '06:00' }); // sleep: until the sky clock next reads 06:00
|
|
78
|
+
* @example engine.skip({ seconds: 600 }); // wait 600 game seconds
|
|
79
|
+
* @example await engine.skip({ to: '06:00', fade: 0.6, save: 'auto' }); // fade to black, jump, autosave, fade in
|
|
80
|
+
* @param {{ to?: string | number, seconds?: number, fade?: number, save?: string | boolean }} opts
|
|
81
|
+
* Cancelled cleanly by session.newGame / load / quit (the skip resolves null and time stays where the new playthrough put it).
|
|
82
|
+
* @returns {Promise<{ seconds: number, clock: string | null, day: number | null } | null>}
|
|
83
|
+
*/
|
|
84
|
+
skip(opts = {}) {
|
|
85
|
+
checkOptions('engine.skip()', opts, ['to', 'seconds', 'fade', 'save']);
|
|
86
|
+
const { fade = 0, save = null } = opts;
|
|
87
|
+
amount(this, opts); // throw on bad arguments now, not after the fade
|
|
88
|
+
let out = null, ended = false;
|
|
89
|
+
const go = () => {
|
|
90
|
+
if (ended) return; // the playthrough ended during the fade out: nothing to skip in the new one
|
|
91
|
+
const r = this.ops.run('time.skip', { seconds: amount(this, opts) }); // measured at jump time: a queued transition may have moved the clock
|
|
92
|
+
if (!r.ok) throw codedError('skip-amount', `engine.skip(): ${r.reason}`);
|
|
93
|
+
out = r.value;
|
|
94
|
+
if (save && out) this.saves.save(save === true ? 'auto' : save);
|
|
95
|
+
};
|
|
96
|
+
const ctx = this.input.push('skip'); this.freeze('skip'); // opaque 'skip' context: gameplay input blocked until the skip ends
|
|
97
|
+
const off = this.events.on('session:end', () => { ended = true; }); // newGame / load / quit cancel the skip cleanly (it resolves null)
|
|
98
|
+
const end = () => { ctx.remove(); this.unfreeze('skip'); off.remove(); };
|
|
99
|
+
if (!(fade > 0)) { try { go(); } finally { end(); } return Promise.resolve(out); }
|
|
100
|
+
const run = this.flow ? this.flow.transition(go, { fade, autosave: false, music: false })
|
|
101
|
+
: (async () => { try { await fadeScreen(this, 1, fade); go(); } finally { await fadeScreen(this, 0, fade); } })();
|
|
102
|
+
return run.finally(end).then(() => out);
|
|
103
|
+
},
|
|
104
|
+
};
|