threedog 1.4.0 → 2.1.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 +48 -0
- package/README.md +13 -7
- package/bin/threedog.mjs +42 -0
- package/core/assets/assetEntry.js +1 -1
- package/core/assets/assetPart.js +1 -1
- package/core/base/Events.js +7 -1
- package/core/base/errorCodes.js +1 -1
- package/core/base/events.generated.js +2 -2
- package/core/engine/Engine.js +11 -7
- package/core/engine/copies.js +1 -1
- package/core/engine/moduleTypes.js +1 -1
- package/core/engine/modules.js +23 -6
- package/core/engine/page.js +1 -0
- package/core/engine/services.js +5 -3
- package/core/engine/startup.js +4 -1
- package/core/inspect/DebugOverrides.js +2 -2
- package/core/inspect/InspectPerf.js +1 -1
- package/core/inspect/describeRender.js +0 -7
- package/core/inspect/metadata.generated.js +139 -50
- package/core/inspect/pictureChecks.js +2 -27
- package/core/ops/control.js +3 -3
- package/core/ops/holds.js +8 -3
- package/core/ops/sharedPoint.js +11 -2
- package/core/saves/saveApply.js +3 -3
- package/core/saves/session.js +20 -4
- package/core/scene/adaptive.js +5 -2
- package/core/scene/pixelRatio.js +39 -17
- package/core/scene/sceneMethods.js +1 -1
- package/core/scene/things.js +3 -2
- package/core/scene/tier.js +2 -16
- package/core/scene/view.js +14 -0
- package/core/time/skip.js +1 -1
- package/docs/AI.md +2 -2
- package/docs/CODEMAP.md +8 -8
- package/docs/COMMANDS.md +2 -2
- package/docs/CONVENTIONS.md +1 -0
- package/docs/THREE.md +1 -1
- package/docs/api/ambience.md +2 -2
- package/docs/api/cameraRig.md +7 -0
- package/docs/api/engine.md +6 -3
- package/docs/api/events.md +3 -3
- package/docs/api/particles.md +1 -1
- package/docs/api/photo.md +5 -0
- package/docs/api/pickups.md +1 -1
- package/docs/api/post.md +1 -1
- package/docs/api/rigid.md +1 -1
- package/docs/api/sky.md +11 -1
- package/docs/api/terrain.md +19 -0
- package/docs/api/tools.md +1 -1
- package/docs/recipes/01-new-game.md +1 -1
- package/docs/recipes/03-items-pickups.md +1 -1
- package/docs/recipes/05-props-bake.md +1 -1
- package/docs/recipes/06-clock-events.md +3 -10
- package/docs/recipes/07-flow-scenes-pause.md +3 -4
- package/docs/recipes/09-materials-lights-models.md +1 -1
- package/docs/recipes/10-blender-level.md +2 -2
- package/docs/recipes/{11-vehicles.md → 11-physics.md} +13 -5
- package/docs/recipes/12-navmesh.md +3 -3
- package/docs/recipes/14-custom-module.md +6 -5
- package/docs/recipes/15-perf.md +1 -1
- package/docs/recipes/16-dev-bridge.md +1 -1
- package/docs/recipes/18-world.md +1 -1
- package/docs/recipes/20-content-actions-save.md +0 -1
- package/docs/recipes/21-camera.md +11 -1
- package/docs/recipes/26-ui-parts.md +2 -2
- package/docs/recipes/27-net.md +1 -1
- package/docs/recipes/29-grid.md +1 -1
- package/docs/recipes/34-environment-lighting.md +5 -3
- package/docs/recipes/40-scene.md +1 -1
- package/docs/recipes/44-water-weather-hooks.md +1 -1
- package/docs/recipes/45-cascaded-shadows.md +6 -3
- package/docs/recipes/51-capability-catalog.md +1 -1
- package/docs/recipes/52-around-the-picture.md +8 -8
- package/docs/recipes/53-ground-up-close.md +2 -2
- package/docs/recipes/55-mods-time-wrap.md +6 -8
- package/docs/recipes/57-control.md +1 -1
- package/docs/recipes/59-depth-post-effects.md +1 -1
- package/docs/recipes/60-judge-the-picture.md +7 -7
- package/docs/recipes/62-picture-code.md +13 -17
- package/examples/action/GAMEMAP.md +4 -2
- package/examples/action/picture/lights.js +3 -2
- package/examples/perf-island/GAMEMAP.md +2 -1
- package/examples/perf-island/picture/lights.js +3 -2
- package/examples/styletest/GAMEMAP.md +2 -2
- package/examples/styletest/picture/env.js +1 -2
- package/examples/techniques/contact-shadows/README.md +1 -1
- package/examples/techniques/day-night-grade/picture/lights.js +3 -1
- package/examples/techniques/interior-light/README.md +1 -1
- package/examples/techniques/interior-light/picture/lights.js +4 -2
- package/examples/techniques/modular-building/picture/lights.js +3 -2
- package/examples/techniques/night-lights/README.md +1 -1
- package/examples/techniques/night-lights/picture/lights.js +3 -1
- package/examples/techniques/night-lights/picture/post.js +2 -2
- package/examples/techniques/outlines-and-rim/README.md +1 -1
- package/examples/techniques/outlines-and-rim/picture/lights.js +3 -2
- package/examples/techniques/procedural-animation/README.md +1 -1
- package/examples/techniques/procedural-animation/picture/lights.js +3 -1
- package/examples/techniques/procedural-surface/README.md +1 -1
- package/examples/techniques/procedural-surface/picture/lights.js +3 -1
- package/examples/techniques/stylized-shading/picture/lights.js +3 -1
- package/examples/techniques/wet-road/README.md +1 -1
- package/examples/techniques/wet-road/picture/lights.js +3 -1
- package/examples/webgpu-tsl/GAMEMAP.md +4 -2
- package/examples/webgpu-tsl/picture/lights.js +3 -1
- package/examples/world/GAMEMAP.md +4 -3
- package/examples/world/picture/lights.js +3 -1
- package/examples/world/picture/post.js +2 -2
- package/llms.txt +33 -7
- package/modules/camera/common.js +22 -20
- package/modules/camera/contract.js +1 -1
- package/modules/characters/Character.js +2 -2
- package/modules/characters/NPC.js +7 -8
- package/modules/characters/index.js +8 -8
- package/modules/characters/mover.contract.js +1 -1
- package/modules/characters/movers/rapier.js +7 -9
- package/modules/characters/npcAvoid.js +2 -2
- package/modules/characters/player.js +11 -15
- package/modules/characters/playerStrings.js +1 -2
- package/modules/characters/seat.js +1 -1
- package/modules/collision/Collision.js +1 -1
- package/modules/collision/grid.js +1 -1
- package/modules/content/index.js +4 -3
- package/modules/content/models.js +1 -1
- package/modules/content/templates.js +3 -2
- package/modules/flow/index.js +8 -8
- package/modules/gameplay/Dialogue.js +1 -1
- package/modules/gameplay/Inventory.js +3 -3
- package/modules/gameplay/Quests.js +1 -0
- package/modules/gameplay/inventory.contract.js +1 -1
- package/modules/gameplay/pickups.js +1 -1
- package/modules/gameplay/questLog.js +0 -1
- package/modules/grid/index.js +1 -1
- package/modules/grid/tiles.js +6 -3
- package/modules/hud/index.js +2 -2
- package/modules/level/contract.js +2 -2
- package/modules/level/index.js +1 -1
- package/modules/music/Music.js +1 -1
- package/modules/nav/index.js +1 -1
- package/modules/net/sync.js +1 -1
- package/modules/particles/Particles.js +12 -5
- package/modules/particles/effect.js +17 -3
- package/modules/photo/pathTrace.js +1 -1
- package/modules/rigid/RigidBodies.js +23 -9
- package/modules/rigid/ragdoll.js +1 -1
- package/modules/rigid/sync.js +14 -0
- package/modules/settings/Settings.js +3 -2
- package/modules/settings/apply.js +4 -3
- package/modules/settings/sections.js +1 -1
- package/modules/sky/Sky.js +9 -4
- package/modules/sky/environment.js +5 -3
- package/modules/terrain/index.js +1 -2
- package/modules/timeline/Timeline.js +9 -6
- package/modules/vegetation/Vegetation.js +1 -1
- package/modules/vegetation/index.js +1 -1
- package/modules/weather/weatherDraw.js +1 -2
- package/modules/world/World.js +1 -0
- package/modules/world/index.js +1 -0
- package/modules/world/persist.js +1 -1
- package/package.json +6 -2
- package/render/PostFX.js +17 -12
- package/render/fx/postWebGPU.tsl.js +2 -1
- package/render/lightmap.js +1 -1
- package/render/lights.js +1 -2
- package/render/neutral.js +1 -1
- package/render/patches.js +3 -3
- package/render/probes.js +27 -2
- package/render/shaderErrors.js +1 -1
- package/render/shadows.js +1 -3
- package/types/core.d.ts +16 -9
- package/types/gameplay.d.ts +8 -3
- package/types/generated/modules/sky/Sky.d.ts +4 -4
- package/types/generated/render/PostFX.d.ts +2 -2
- package/types/generated/ui/UI.d.ts +2 -1
- package/types/physics.d.ts +1 -1
- package/types/world.d.ts +4 -2
- package/ui/UI.js +18 -14
- package/ui/cursor.js +2 -2
- package/examples/action/.threedog/content-index.json +0 -1
- package/examples/perf-island/.threedog/content-index.json +0 -1
- package/examples/plain-picture/.threedog/content-index.json +0 -1
- package/examples/rc2d/.threedog/content-index.json +0 -1
- package/examples/styletest/.threedog/content-index.json +0 -1
- package/examples/webgpu-tsl/.threedog/content-index.json +0 -1
- package/examples/world/.threedog/content-index.json +0 -1
|
@@ -38,7 +38,7 @@ export const sectionHomes = {
|
|
|
38
38
|
"grids": "grids() after world()",
|
|
39
39
|
"items": "inventory()",
|
|
40
40
|
"level": "level()",
|
|
41
|
-
"npcs": "characters()",
|
|
41
|
+
"npcs": "characters() after world()",
|
|
42
42
|
"pickups": "pickups() after world()",
|
|
43
43
|
"places": "content()",
|
|
44
44
|
"props": "content()",
|
|
@@ -71,12 +71,14 @@ export const metadata = {
|
|
|
71
71
|
"rules": {
|
|
72
72
|
"type": "any",
|
|
73
73
|
"optional": true,
|
|
74
|
-
"docType": "import('./core').AmbienceRule[]"
|
|
74
|
+
"docType": "import('./core').AmbienceRule[]",
|
|
75
|
+
"desc": "Rules added after the ones in createEngine({ audio: { ambience } })"
|
|
75
76
|
},
|
|
76
77
|
"interval": {
|
|
77
78
|
"type": "any",
|
|
78
79
|
"optional": true,
|
|
79
|
-
"docType": "number"
|
|
80
|
+
"docType": "number",
|
|
81
|
+
"desc": "Seconds between rule checks, default 0.25"
|
|
80
82
|
}
|
|
81
83
|
},
|
|
82
84
|
"page": true,
|
|
@@ -273,7 +275,8 @@ export const metadata = {
|
|
|
273
275
|
"time": {
|
|
274
276
|
"kind": "none",
|
|
275
277
|
"hooks": [
|
|
276
|
-
"frame"
|
|
278
|
+
"frame",
|
|
279
|
+
"sessionStart"
|
|
277
280
|
]
|
|
278
281
|
}
|
|
279
282
|
},
|
|
@@ -286,7 +289,9 @@ export const metadata = {
|
|
|
286
289
|
"provides": [
|
|
287
290
|
"characters"
|
|
288
291
|
],
|
|
289
|
-
"requires": [
|
|
292
|
+
"requires": [
|
|
293
|
+
"world"
|
|
294
|
+
],
|
|
290
295
|
"handRolled": "none: walking code is game movement, and any code shape would match ordinary maths",
|
|
291
296
|
"stage": "late",
|
|
292
297
|
"before": [
|
|
@@ -300,8 +305,7 @@ export const metadata = {
|
|
|
300
305
|
"dialogue",
|
|
301
306
|
"nav",
|
|
302
307
|
"collision",
|
|
303
|
-
"rigid"
|
|
304
|
-
"world"
|
|
308
|
+
"rigid"
|
|
305
309
|
],
|
|
306
310
|
"params": {
|
|
307
311
|
"npcs": {
|
|
@@ -353,7 +357,8 @@ export const metadata = {
|
|
|
353
357
|
"kind": "none",
|
|
354
358
|
"hooks": [
|
|
355
359
|
"fixed",
|
|
356
|
-
"frame"
|
|
360
|
+
"frame",
|
|
361
|
+
"worldLoad"
|
|
357
362
|
],
|
|
358
363
|
"noSkip": "fixed steps paths, control holders and riders, none of which a time jump moves; schedules read the calendar clock"
|
|
359
364
|
}
|
|
@@ -502,7 +507,9 @@ export const metadata = {
|
|
|
502
507
|
],
|
|
503
508
|
"time": {
|
|
504
509
|
"kind": "none",
|
|
505
|
-
"hooks": [
|
|
510
|
+
"hooks": [
|
|
511
|
+
"worldLoad"
|
|
512
|
+
]
|
|
506
513
|
}
|
|
507
514
|
},
|
|
508
515
|
"debugPanel": {
|
|
@@ -608,6 +615,7 @@ export const metadata = {
|
|
|
608
615
|
"kind": "none",
|
|
609
616
|
"hooks": [
|
|
610
617
|
"frame",
|
|
618
|
+
"sessionEnd",
|
|
611
619
|
"afterLoad"
|
|
612
620
|
]
|
|
613
621
|
}
|
|
@@ -650,7 +658,10 @@ export const metadata = {
|
|
|
650
658
|
"saves": [],
|
|
651
659
|
"time": {
|
|
652
660
|
"kind": "none",
|
|
653
|
-
"hooks": [
|
|
661
|
+
"hooks": [
|
|
662
|
+
"sessionEnd",
|
|
663
|
+
"sessionStart"
|
|
664
|
+
]
|
|
654
665
|
}
|
|
655
666
|
},
|
|
656
667
|
"grids": {
|
|
@@ -733,7 +744,8 @@ export const metadata = {
|
|
|
733
744
|
"time": {
|
|
734
745
|
"kind": "none",
|
|
735
746
|
"hooks": [
|
|
736
|
-
"frame"
|
|
747
|
+
"frame",
|
|
748
|
+
"worldLoad"
|
|
737
749
|
]
|
|
738
750
|
}
|
|
739
751
|
},
|
|
@@ -847,7 +859,8 @@ export const metadata = {
|
|
|
847
859
|
"time": {
|
|
848
860
|
"kind": "none",
|
|
849
861
|
"hooks": [
|
|
850
|
-
"frame"
|
|
862
|
+
"frame",
|
|
863
|
+
"sessionEnd"
|
|
851
864
|
]
|
|
852
865
|
}
|
|
853
866
|
},
|
|
@@ -1009,7 +1022,9 @@ export const metadata = {
|
|
|
1009
1022
|
"time": {
|
|
1010
1023
|
"kind": "none",
|
|
1011
1024
|
"hooks": [
|
|
1012
|
-
"frame"
|
|
1025
|
+
"frame",
|
|
1026
|
+
"sessionEnd",
|
|
1027
|
+
"sessionStart"
|
|
1013
1028
|
],
|
|
1014
1029
|
"noSkip": "no timers or spatial state"
|
|
1015
1030
|
}
|
|
@@ -1294,7 +1309,8 @@ export const metadata = {
|
|
|
1294
1309
|
"time": {
|
|
1295
1310
|
"kind": "none",
|
|
1296
1311
|
"hooks": [
|
|
1297
|
-
"frame"
|
|
1312
|
+
"frame",
|
|
1313
|
+
"sessionEnd"
|
|
1298
1314
|
]
|
|
1299
1315
|
}
|
|
1300
1316
|
},
|
|
@@ -1603,23 +1619,33 @@ export const metadata = {
|
|
|
1603
1619
|
},
|
|
1604
1620
|
"scale": {
|
|
1605
1621
|
"type": "any",
|
|
1606
|
-
"optional": true
|
|
1622
|
+
"optional": true,
|
|
1623
|
+
"docType": "number",
|
|
1624
|
+
"desc": "Resolution multiplier, default 1.6"
|
|
1607
1625
|
},
|
|
1608
1626
|
"shadowMapSize": {
|
|
1609
1627
|
"type": "any",
|
|
1610
|
-
"optional": true
|
|
1628
|
+
"optional": true,
|
|
1629
|
+
"docType": "number",
|
|
1630
|
+
"desc": "Shadow resolution (pixels), default 4096"
|
|
1611
1631
|
},
|
|
1612
1632
|
"bloom": {
|
|
1613
1633
|
"type": "any",
|
|
1614
|
-
"optional": true
|
|
1634
|
+
"optional": true,
|
|
1635
|
+
"docType": "boolean | null",
|
|
1636
|
+
"desc": "Bloom for the shot: null (default) keeps what the game's post has; true / false forces it for that shot only"
|
|
1615
1637
|
},
|
|
1616
1638
|
"quality": {
|
|
1617
1639
|
"type": "any",
|
|
1618
|
-
"optional": true
|
|
1640
|
+
"optional": true,
|
|
1641
|
+
"docType": "number",
|
|
1642
|
+
"desc": "Image quality 0–1"
|
|
1619
1643
|
},
|
|
1620
1644
|
"format": {
|
|
1621
1645
|
"type": "any",
|
|
1622
|
-
"optional": true
|
|
1646
|
+
"optional": true,
|
|
1647
|
+
"docType": "string",
|
|
1648
|
+
"desc": "Image format, e.g. 'image/jpeg'"
|
|
1623
1649
|
}
|
|
1624
1650
|
},
|
|
1625
1651
|
"page": true,
|
|
@@ -1722,7 +1748,8 @@ export const metadata = {
|
|
|
1722
1748
|
"time": {
|
|
1723
1749
|
"kind": "exact",
|
|
1724
1750
|
"hooks": [
|
|
1725
|
-
"fixed"
|
|
1751
|
+
"fixed",
|
|
1752
|
+
"worldLoad"
|
|
1726
1753
|
],
|
|
1727
1754
|
"noSkip": "auto pickups are spatial; respawn follows the game clock"
|
|
1728
1755
|
}
|
|
@@ -1791,7 +1818,8 @@ export const metadata = {
|
|
|
1791
1818
|
"hooks": [
|
|
1792
1819
|
"fixed",
|
|
1793
1820
|
"frame",
|
|
1794
|
-
"skip"
|
|
1821
|
+
"skip",
|
|
1822
|
+
"sessionEnd"
|
|
1795
1823
|
]
|
|
1796
1824
|
}
|
|
1797
1825
|
},
|
|
@@ -1923,6 +1951,8 @@ export const metadata = {
|
|
|
1923
1951
|
"kind": "none",
|
|
1924
1952
|
"hooks": [
|
|
1925
1953
|
"fixed",
|
|
1954
|
+
"sessionEnd",
|
|
1955
|
+
"worldLoad",
|
|
1926
1956
|
"afterLoad"
|
|
1927
1957
|
],
|
|
1928
1958
|
"noSkip": "bodies rest while time jumps (stepping seconds of physics would only scatter them)"
|
|
@@ -2033,43 +2063,63 @@ export const metadata = {
|
|
|
2033
2063
|
},
|
|
2034
2064
|
"clouds": {
|
|
2035
2065
|
"type": "any",
|
|
2036
|
-
"optional": true
|
|
2066
|
+
"optional": true,
|
|
2067
|
+
"docType": "SkyCloudOptions",
|
|
2068
|
+
"desc": "Clouds in the sky (cloud cover follows the weather); see SkyCloudOptions"
|
|
2037
2069
|
},
|
|
2038
2070
|
"backdrop": {
|
|
2039
2071
|
"type": "any",
|
|
2040
|
-
"optional": true
|
|
2072
|
+
"optional": true,
|
|
2073
|
+
"docType": "ColorLike",
|
|
2074
|
+
"desc": "A flat background color in place of the dome (no gradient, horizon line, sun / moon disk, stars or clouds). Drawn as written (no tone mapping); a fog asked for in the default horizon color takes it (a fog.color of your own still wins). Leave out for the dome. recipes/08. Example: `backdrop: 0xefebe4`"
|
|
2041
2075
|
},
|
|
2042
2076
|
"keyframes": {
|
|
2043
2077
|
"type": "any",
|
|
2044
|
-
"optional": true
|
|
2078
|
+
"optional": true,
|
|
2079
|
+
"docType": "SkyKeyframe[]",
|
|
2080
|
+
"desc": "Rows [time, zenith, horizon, sunColor, ambient]. time: share of the day (0 = 00:00, 0.5 = noon), sorted, first row 0, last 1 (midnight again: same values as 0). They color the dome and the signals uSkyTop / uSkyHorizon, and light nothing: sunColor is the sun disk and the signal uSunColor, ambient dims a skybox and the weather's sky tint (recipe 08). Example: `[[0, 0x0b1030, 0x1c2440, 0x8090c0, 0.25], [0.5, 0x5a8fd0, 0xbcd4ea, 0xfff4e0, 1.1], [1, 0x0b1030, 0x1c2440, 0x8090c0, 0.25]]`"
|
|
2045
2081
|
},
|
|
2046
2082
|
"sunSize": {
|
|
2047
2083
|
"type": "any",
|
|
2048
|
-
"optional": true
|
|
2084
|
+
"optional": true,
|
|
2085
|
+
"docType": "number",
|
|
2086
|
+
"desc": "Sharpness exponent of the sun disk, default 900 (about 2 deg); larger = smaller. Not a size in degrees: 10 is ~20 deg, under ~3 the \"disk\" washes most of the sky toward the sun color"
|
|
2049
2087
|
},
|
|
2050
2088
|
"sunGlow": {
|
|
2051
2089
|
"type": "any",
|
|
2052
|
-
"optional": true
|
|
2090
|
+
"optional": true,
|
|
2091
|
+
"docType": "number",
|
|
2092
|
+
"desc": "Sun glow, default 0.18"
|
|
2053
2093
|
},
|
|
2054
2094
|
"sunBrightness": {
|
|
2055
2095
|
"type": "any",
|
|
2056
|
-
"optional": true
|
|
2096
|
+
"optional": true,
|
|
2097
|
+
"docType": "number",
|
|
2098
|
+
"desc": "(experimental) Sun brightness, default 6"
|
|
2057
2099
|
},
|
|
2058
2100
|
"moonColor": {
|
|
2059
2101
|
"type": "any",
|
|
2060
|
-
"optional": true
|
|
2102
|
+
"optional": true,
|
|
2103
|
+
"docType": "ColorLike",
|
|
2104
|
+
"desc": "(experimental) Color of the moon disk drawn at night, default 0xdcdcdc"
|
|
2061
2105
|
},
|
|
2062
2106
|
"moonBrightness": {
|
|
2063
2107
|
"type": "any",
|
|
2064
|
-
"optional": true
|
|
2108
|
+
"optional": true,
|
|
2109
|
+
"docType": "number",
|
|
2110
|
+
"desc": "(experimental) Brightness of the moon disk drawn at night, default 3"
|
|
2065
2111
|
},
|
|
2066
2112
|
"starDensity": {
|
|
2067
2113
|
"type": "any",
|
|
2068
|
-
"optional": true
|
|
2114
|
+
"optional": true,
|
|
2115
|
+
"docType": "number",
|
|
2116
|
+
"desc": "Share of the sky grid cells (0-1) that hold a star at night, default 0.0025 (0 = no stars). A probability, not a brightness: near 1 every cell is lit and the upper sky turns into a white sheet."
|
|
2069
2117
|
},
|
|
2070
2118
|
"dim": {
|
|
2071
2119
|
"type": "any",
|
|
2072
|
-
"optional": true
|
|
2120
|
+
"optional": true,
|
|
2121
|
+
"docType": "{ tint?: boolean; stars?: boolean }",
|
|
2122
|
+
"desc": "What the sky dims for every game unless the style says no (each default true; false turns that one off, the rest stay). The one place these picture decisions are switched: - tint: a sky.tint color (weather grey, a cave tint) dims with the sky's own light, so a grey rain tint stays dark at night. Example: `sky({ dim: { stars: false } }) // live: engine.sky.dim.tint = false`"
|
|
2073
2123
|
}
|
|
2074
2124
|
},
|
|
2075
2125
|
"page": true,
|
|
@@ -2210,77 +2260,107 @@ export const metadata = {
|
|
|
2210
2260
|
"seed": {
|
|
2211
2261
|
"type": "any",
|
|
2212
2262
|
"optional": true,
|
|
2213
|
-
"default": 1337
|
|
2263
|
+
"default": 1337,
|
|
2264
|
+
"docType": "number",
|
|
2265
|
+
"desc": "Random seed; the same seed gives the same terrain"
|
|
2214
2266
|
},
|
|
2215
2267
|
"chunkSize": {
|
|
2216
2268
|
"type": "any",
|
|
2217
2269
|
"optional": true,
|
|
2218
|
-
"default": 64
|
|
2270
|
+
"default": 64,
|
|
2271
|
+
"docType": "number",
|
|
2272
|
+
"desc": "Chunk edge length (meters), default 64"
|
|
2219
2273
|
},
|
|
2220
2274
|
"resolution": {
|
|
2221
2275
|
"type": "any",
|
|
2222
2276
|
"optional": true,
|
|
2223
|
-
"default": 16
|
|
2277
|
+
"default": 16,
|
|
2278
|
+
"docType": "number",
|
|
2279
|
+
"desc": "Cells per chunk; smaller is more \"low poly\", default 16"
|
|
2224
2280
|
},
|
|
2225
2281
|
"waterLevel": {
|
|
2226
2282
|
"type": "any",
|
|
2227
2283
|
"optional": true,
|
|
2228
|
-
"default": null
|
|
2284
|
+
"default": null,
|
|
2285
|
+
"docType": "number",
|
|
2286
|
+
"desc": "Water level (meters), default -Infinity = no water (terrainPreset() from"
|
|
2229
2287
|
},
|
|
2230
2288
|
"flatten": {
|
|
2231
2289
|
"type": "any",
|
|
2232
2290
|
"optional": true,
|
|
2233
|
-
"default": []
|
|
2291
|
+
"default": [],
|
|
2292
|
+
"docType": "FlattenZone[]",
|
|
2293
|
+
"desc": "Flattened plots"
|
|
2234
2294
|
},
|
|
2235
2295
|
"heightmap": {
|
|
2236
2296
|
"type": "any",
|
|
2237
2297
|
"optional": true,
|
|
2238
|
-
"default": null
|
|
2298
|
+
"default": null,
|
|
2299
|
+
"docType": "{ url?, size?, min?, max?, center?, outside?, … } | null",
|
|
2300
|
+
"desc": "Heightmap (used when there is no height function): url grayscale image, size [width m, length m], min/max height (meters), center [x, z]"
|
|
2239
2301
|
},
|
|
2240
2302
|
"height": {
|
|
2241
2303
|
"type": "any",
|
|
2242
2304
|
"optional": true,
|
|
2243
|
-
"default": null
|
|
2305
|
+
"default": null,
|
|
2306
|
+
"docType": "((x, z, n) => number) | string | null",
|
|
2307
|
+
"desc": "Height generator: (x, z, n) => meters. Without one (and without a heightmap) the ground is flat at y = 0, a placeholder (dev warning). Runs in workers, so it must be pure (only its parameters and globals like Math); an outside variable throws at terrain() naming it. n = { fbm(x, z, octaves?), noise(x, z), hash(x, z, salt?), seed, waterLevel, params }. Example: `terrain({ height: (x, z, n) => 4 + 12 * n.fbm(x * 0.01, z * 0.01) })`"
|
|
2244
2308
|
},
|
|
2245
2309
|
"groundType": {
|
|
2246
2310
|
"type": "any",
|
|
2247
2311
|
"optional": true,
|
|
2248
|
-
"default": null
|
|
2312
|
+
"default": null,
|
|
2313
|
+
"docType": "((x, z, h, slope, n) => string | null) | string | null",
|
|
2314
|
+
"desc": "Ground type: (x, z, h, slope, n) => type name (null = 'default'). Pure, like height. Colors come from biomeColors[type]; vegetation rules and footsteps match by name. Example: `terrain({ groundType: (x, z, h, slope) => slope > 0.7 ? 'rock' : h < 2 ? 'beach' : 'grass' })`"
|
|
2249
2315
|
},
|
|
2250
2316
|
"params": {
|
|
2251
2317
|
"type": "any",
|
|
2252
2318
|
"optional": true,
|
|
2253
|
-
"default": null
|
|
2319
|
+
"default": null,
|
|
2320
|
+
"docType": "Record<string, any> | null",
|
|
2321
|
+
"desc": "Plain data handed to height / groundType as n.params (a preset's settings); must be serializable"
|
|
2254
2322
|
},
|
|
2255
2323
|
"shading": {
|
|
2256
2324
|
"type": "any",
|
|
2257
2325
|
"optional": true,
|
|
2258
|
-
"default": "smooth"
|
|
2326
|
+
"default": "smooth",
|
|
2327
|
+
"docType": "'flat' | 'smooth' | 'texture'",
|
|
2328
|
+
"desc": "How the ground gets its color: 'smooth' (default) blended per grid point / 'flat' one color and normal per triangle (low poly) / 'texture' per-chunk color map sampled per pixel, so color borders (a river bank) are not confined to triangle edges and the mesh can stay coarse. See recipes/53-ground-up-close.md."
|
|
2259
2329
|
},
|
|
2260
2330
|
"colorResolution": {
|
|
2261
2331
|
"type": "any",
|
|
2262
2332
|
"optional": true,
|
|
2263
|
-
"default": 128
|
|
2333
|
+
"default": 128,
|
|
2334
|
+
"docType": "number",
|
|
2335
|
+
"desc": "Texture shading: color map pixels per chunk edge (default 128, 64 on low-tier devices; independent of `resolution`)"
|
|
2264
2336
|
},
|
|
2265
2337
|
"normals": {
|
|
2266
2338
|
"type": "any",
|
|
2267
2339
|
"optional": true,
|
|
2268
|
-
"default": null
|
|
2340
|
+
"default": null,
|
|
2341
|
+
"docType": "'smooth' | 'flat' | null",
|
|
2342
|
+
"desc": "Texture shading only: lighting normals 'smooth' (default) / 'flat'"
|
|
2269
2343
|
},
|
|
2270
2344
|
"normalFn": {
|
|
2271
2345
|
"type": "any",
|
|
2272
2346
|
"optional": true,
|
|
2273
|
-
"default": null
|
|
2347
|
+
"default": null,
|
|
2348
|
+
"docType": "((i, j, h, cell) => number[]) | string | null",
|
|
2349
|
+
"desc": "Replace the smooth normal at grid point (i, j): (i, j, h, cell) => [nx, ny, nz] (any length; the engine normalizes). h(i, j) is a grid-point height, cell the grid spacing in meters. Pure, like height (workers get its source). Default: central difference of the neighbors. Example: `terrain({ normalFn: (i, j, h, cell) => [(h(i - 1, j) - h(i + 1, j)) / (2 * cell), 2, (h(i, j - 1) - h(i, j + 1)) / (2 * cell)] }) // flatter lighting`"
|
|
2274
2350
|
},
|
|
2275
2351
|
"diagonal": {
|
|
2276
2352
|
"type": "any",
|
|
2277
2353
|
"optional": true,
|
|
2278
|
-
"default": "fixed"
|
|
2354
|
+
"default": "fixed",
|
|
2355
|
+
"docType": "'fixed' | 'adaptive' | 'alternate'",
|
|
2356
|
+
"desc": "How each cell is cut into two triangles: 'fixed' (default, the same diagonal everywhere) / 'adaptive' (along the diagonal with the smaller height difference, fewer zigzag ridges on slopes) / 'alternate' (flips every other cell). It is shape: engine.surface follows it"
|
|
2279
2357
|
},
|
|
2280
2358
|
"shape": {
|
|
2281
2359
|
"type": "any",
|
|
2282
2360
|
"optional": true,
|
|
2283
|
-
"default": null
|
|
2361
|
+
"default": null,
|
|
2362
|
+
"docType": "TerrainShape | null",
|
|
2363
|
+
"desc": "World outline (default null = ground everywhere): an island, a floating rock, a coastline that ends"
|
|
2284
2364
|
},
|
|
2285
2365
|
"boundsPad": {
|
|
2286
2366
|
"type": "any",
|
|
@@ -2288,22 +2368,30 @@ export const metadata = {
|
|
|
2288
2368
|
"default": {
|
|
2289
2369
|
"up": 3,
|
|
2290
2370
|
"radius": 8
|
|
2291
|
-
}
|
|
2371
|
+
},
|
|
2372
|
+
"docType": "{ up?: number; radius?: number }",
|
|
2373
|
+
"desc": "Chunk bounding sphere margin in meters (default { up: 3, radius: 8 }): center raised by `up`, radius grown by `radius`. Raise it when a shader moves vertices far"
|
|
2292
2374
|
},
|
|
2293
2375
|
"colors": {
|
|
2294
2376
|
"type": "any",
|
|
2295
2377
|
"optional": true,
|
|
2296
|
-
"default": {}
|
|
2378
|
+
"default": {},
|
|
2379
|
+
"docType": "Record<string, ColorLike>",
|
|
2380
|
+
"desc": "Palette: color name → color"
|
|
2297
2381
|
},
|
|
2298
2382
|
"biomeColors": {
|
|
2299
2383
|
"type": "any",
|
|
2300
2384
|
"optional": true,
|
|
2301
|
-
"default": {}
|
|
2385
|
+
"default": {},
|
|
2386
|
+
"docType": "Record<string, string[]>",
|
|
2387
|
+
"desc": "Ground type → palette color names (two are blended by noise); a type left out is neutral gray"
|
|
2302
2388
|
},
|
|
2303
2389
|
"steep": {
|
|
2304
2390
|
"type": "any",
|
|
2305
2391
|
"optional": true,
|
|
2306
|
-
"default": []
|
|
2392
|
+
"default": [],
|
|
2393
|
+
"docType": "SteepRule[]",
|
|
2394
|
+
"desc": "Steep-slope color rule"
|
|
2307
2395
|
}
|
|
2308
2396
|
},
|
|
2309
2397
|
"page": true,
|
|
@@ -2541,6 +2629,7 @@ export const metadata = {
|
|
|
2541
2629
|
"kind": "none",
|
|
2542
2630
|
"hooks": [
|
|
2543
2631
|
"frame",
|
|
2632
|
+
"sessionEnd",
|
|
2544
2633
|
"afterLoad"
|
|
2545
2634
|
]
|
|
2546
2635
|
}
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
// drawn picture could prove it (a top-down view never shows the horizon, a metal can glow on its own): the facts, never "must fix".
|
|
7
7
|
// Never taste ("too dark", "too much bloom"), never a target value. Runs on describe() and at load, never per frame: some walk the scene.
|
|
8
8
|
import * as THREE from 'three';
|
|
9
|
-
import { mats
|
|
9
|
+
import { mats } from '../../render/lit.js';
|
|
10
|
+
import { litTwice, bakeSeenScene } from '../../render/probes.js';
|
|
10
11
|
import { cameraFrustum } from '../base/math.js';
|
|
11
12
|
import { drawnAFrame } from '../../render/backend.js';
|
|
12
13
|
import { fogLook } from '../../render/fogLook.js';
|
|
@@ -30,32 +31,6 @@ function metalNoEnv(e, out) {
|
|
|
30
31
|
note(out, 'metal-no-env', `no environment reflection on ${metal.size} metal mesh(es) (${[...metal][0]}): what metal reflects comes from scene.environment or material.envMap, and neither is set${bg}.`);
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
/**
|
|
34
|
-
* Baked light (a probe set or a lightmap) plus a light the bake already saw: that light counts twice. Exported for the load-time warning of
|
|
35
|
-
* render/probes.js and render/lightmap.js (the same words there). @param {any} e @returns {string | null}
|
|
36
|
-
*/
|
|
37
|
-
export function litTwice(e) {
|
|
38
|
-
const probes = !!e._probeSets?.size, lightmap = !!e._lightmap;
|
|
39
|
-
if (!probes && !lightmap) return null;
|
|
40
|
-
const doubled = [];
|
|
41
|
-
let mapped = 0;
|
|
42
|
-
e.scene.traverseVisible(o => {
|
|
43
|
-
if (noteFillLight(o, doubled)) return;
|
|
44
|
-
if (lightmap && o.isLightProbeGrid) doubled.push(`probe grid ${o.name}`); // the lightmap baked the bounce the grid adds again
|
|
45
|
-
else if (probes && !lightmap && o.isMesh && mats(o).some(m => m?.lightMap)) mapped++; // a game's own lightMap under a probe grid
|
|
46
|
-
});
|
|
47
|
-
noteEnvironment(e.scene, doubled);
|
|
48
|
-
if (mapped) doubled.push(`material.lightMap on ${mapped} mesh(es)`);
|
|
49
|
-
if (!doubled.length) return null;
|
|
50
|
-
const what = [probes && 'probe', lightmap && 'lightmap'].filter(Boolean).join(' and ');
|
|
51
|
-
const list = doubled.slice(0, 2).join(', ') + (doubled.length > 2 ? ` and ${doubled.length - 2} more` : '');
|
|
52
|
-
if (!bakeSeenScene(e)) return `${what} light is added on top of ${list}. If the bake saw it, it counts twice (a loaded file does not say which lights it saw). Fix: lower it where the bake takes over, or bake without it.`;
|
|
53
|
-
return `${what} light is added on top of ${list}, which the bake already saw, so it counts twice. Fix: lower it where the bake takes over, or bake without it.`;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** True only when every baked light came from a bake made in this session (engine.bakeProbes): it saw this scene's lights. A loaded file or a lightmap carries no record of them */
|
|
57
|
-
const bakeSeenScene = e => !e._lightmap && [...(e._probeSets ?? [])].every(s => s.source === 'bake');
|
|
58
|
-
|
|
59
34
|
/**
|
|
60
35
|
* A glow before the exposure that applies after it: its threshold acts on light the screen shows scaled. A note: how much of the picture passes the
|
|
61
36
|
* threshold depends on the light in view, which only the pixels say. Effects are found by what they declare (about.acts, @threedog/post-effects
|
package/core/ops/control.js
CHANGED
|
@@ -50,9 +50,9 @@ export class Control {
|
|
|
50
50
|
/** @internal the entry whose move is running now (handle.move / a behaviour run): the one caller character.move() lets through */ this._cur = null;
|
|
51
51
|
/** @internal id -> Character; set by the characters module through resolveWith (core names no module) */ this.characterOf = () => null;
|
|
52
52
|
engine.events.on('world:remove', ({ id }) => this.forget(id));
|
|
53
|
-
// Two moments, and state:replaced is neither.
|
|
54
|
-
// running playthrough, the only word a direct apply gives. state:replaced comes last, after the save:loaded and session:start listeners that start the new state's walks: it would end them
|
|
55
|
-
|
|
53
|
+
// Two moments, and state:replaced is neither. A playthrough ending: session.js calls endTasks first in its end step, before anything is replaced, so no walk runs on into the swap.
|
|
54
|
+
// save:loaded: a save landed on a running playthrough, the only word a direct apply gives. state:replaced comes last, after the save:loaded and session:start listeners that start the new state's walks: it would end them
|
|
55
|
+
engine.events.on('save:loaded', () => this.endTasks(null, 'replaced'));
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
58
58
|
* Take a character's control. step (optional): (dt, character) => ({ x, y?, z, run? }) | null | false, called each fixed step while this owner is in
|
package/core/ops/holds.js
CHANGED
|
@@ -25,8 +25,11 @@ function handle(owner, remove) { return { owner, remove }; }
|
|
|
25
25
|
export function defineHoldStacks(engine) {
|
|
26
26
|
engine.stacks.define('freeze', { kind: 'any', save: false, onChange: () => engine.input?._kbSync?.() }); // who froze gameplay; a freeze gives the page's key lock back (inputKeyboard.js)
|
|
27
27
|
engine.stacks.define('halt', { kind: 'any', save: false, onChange: () => { // who stopped the loop; it restarts only when empty
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
// the last holder leaving gives back what was there before the first: a headless page (tests, shots) stays stepped by hand, and an engine not
|
|
29
|
+
// started yet gets no loop (start() begins it). Setting false and looping here made a halt taken and removed on such a page run in real time
|
|
30
|
+
const P = engine.stacks.get('halt');
|
|
31
|
+
if (P.size()) { if (!engine.halted) engine._haltBase = false; else engine._haltBase ??= true; engine.halted = true; }
|
|
32
|
+
else if (!engine.disposed) { engine.halted = engine._haltBase ?? false; engine._haltBase = null; if (!engine.halted && engine.phase !== 'constructed') engine._loop(); }
|
|
30
33
|
engine.page._sync(); // a page hold is about the real-time loop: there is none while the loop is stopped (core/engine/page.js)
|
|
31
34
|
} });
|
|
32
35
|
// who holds the camera; the latest is in charge (cameraOverride). A claim that is in charge again after a newer one left gets its opts.onTop() called: it holds the camera
|
|
@@ -66,7 +69,9 @@ export const holdMethods = {
|
|
|
66
69
|
const P = this.stacks.get('halt');
|
|
67
70
|
if (P.size() && !P.has(o)) { warnOnce(coded('halt-owner', `ending the halt of '${o}': halted by ${P.names().map(n => `'${n}'`).join(', ')}, not by '${o}'. End a halt with the handle haltLoop() returned (h.remove()), or the loop stays stopped`)); return this; }
|
|
68
71
|
// with holders the stack's onChange restarts the loop; with none (headless start) this call starts it
|
|
69
|
-
|
|
72
|
+
// an explicit resume (the bridge's threedog resume): live once no one holds a halt, also where releasing the last one gave back a headless page's stepped state
|
|
73
|
+
const had = P.release(o);
|
|
74
|
+
if (!P.size() && !this.disposed && (!had || this.halted)) { this.halted = false; this._loop(); }
|
|
70
75
|
return this;
|
|
71
76
|
},
|
|
72
77
|
// Gameplay freeze (menus, flow 'paused'): no fixed steps (movement, timers, tick and every time view but ambient stop) while frame hooks
|
package/core/ops/sharedPoint.js
CHANGED
|
@@ -80,7 +80,8 @@ export class Stack {
|
|
|
80
80
|
if (kind === 'number' && !Number.isFinite(this.base)) throw codedError('shared-value', `engine.stacks.define('${name}', { base }): base is a finite number, got ${shown(this.base)}. Fix: { base: 1 }`);
|
|
81
81
|
for (const [k, b] of [['min', min], ['max', max]]) if (typeof b !== 'number' || Number.isNaN(b)) throw codedError('shared-value', `engine.stacks.define('${name}', { ${k} }): ${k} is a number (leave it out for no bound), got ${shown(b)}`);
|
|
82
82
|
if (min > max) throw codedError('shared-value', `engine.stacks.define('${name}', { min, max }): min must be <= max, got min ${min} > max ${max}. Fix: { min: ${max}, max: ${min} }`);
|
|
83
|
-
this.min = min; this.max = max; this.save = save; this.per = per;
|
|
83
|
+
this.min = min; this.max = max; this.save = save; this.per = per;
|
|
84
|
+
/** @type {Set<(id: string | null) => void>} define's onChange is the first follower */ this._watchers = new Set(); if (onChange) this._watchers.add(onChange);
|
|
84
85
|
/** the copyable "take it over on purpose" call the conflict error offers (a module's own takeover entry); default: a set on the system layer */
|
|
85
86
|
this.manual = manual;
|
|
86
87
|
/** the settings layer may set here (key bindings: the player's rebinding replaces the game's keys, it is not a restriction) */
|
|
@@ -219,7 +220,15 @@ export class Stack {
|
|
|
219
220
|
return true;
|
|
220
221
|
}
|
|
221
222
|
/** @internal */
|
|
222
|
-
_changed(id) { this._ver++; this.all._version++; this.
|
|
223
|
+
_changed(id) { this._ver++; this.all._version++; for (const fn of [...this._watchers]) fn(id ?? null); }
|
|
224
|
+
/** @internal Follow every change, in registration order: several parts follow one point (the tier: lights, post chain, cascades, terrain, weather) @param {(id: string | null) => void} fn @returns {{ remove(): void }} */
|
|
225
|
+
watch(fn) { this._watchers.add(fn); return { remove: () => { this._watchers.delete(fn); } }; }
|
|
226
|
+
/** @internal The one way to change the base: it tells the followers, which a bare write to .base did not @param {any} v */
|
|
227
|
+
setBase(v) {
|
|
228
|
+
if (Object.is(this.base, v)) return;
|
|
229
|
+
if (this.kind === 'number' && !Number.isFinite(v)) throw codedError('shared-value', `engine.stacks.get('${this.name}').setBase(v): v is a finite number, got ${shown(v)}. Fix: setBase(1)`);
|
|
230
|
+
this.base = v; this._changed();
|
|
231
|
+
}
|
|
223
232
|
/** @internal End owner's entry by name (engine holds: the halt handle); games end theirs with the handle's remove(). false when it held none @param {string} owner @param {{ id?: string }} [o] */
|
|
224
233
|
release(owner, { id } = {}) { return this._drop(owner, id); }
|
|
225
234
|
/** Drop every entry for record id (world.remove does it, so no orphan entries) @param {string} id */
|
package/core/saves/saveApply.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Applying a save (split out of Saves.js): every part is checked and migrated before anything changes (saveVersions.js), then loaded in order;
|
|
2
2
|
// if anything in the load throws, every part reloads the state from just before the load (rollback), so a game is never left half-loaded.
|
|
3
3
|
// "Anything" is the whole load, not only load() itself: a listener of an event a part emits while loading (world:load) and the modules' afterLoad
|
|
4
|
-
// hooks count too. Reported on their own they let the load carry on: a hand-edited player position threw in a world:load listener and left the game
|
|
4
|
+
// hooks count too. Reported on their own they let the load carry on: a hand-edited player position threw in a worldLoad hook (then a world:load listener) and left the game
|
|
5
5
|
// frozen half-loaded (durability audit 2026-11-02).
|
|
6
6
|
// The capture lasts the whole load, past every await: an async part that emits after `await` (async load(d) { apply(d); await res(); emit(...) })
|
|
7
7
|
// is part of the load as much as its first line. The browser has no async context to tell whose code emitted after an await, so each load
|
|
@@ -211,7 +211,7 @@ export const restoreParts = (s, list, where) => { runParts(s, list, where, [], o
|
|
|
211
211
|
export function adoptPart(s, key, part) {
|
|
212
212
|
const f = s._foreign, q = s._replace, where = fmt(DEV_STRINGS.adoptAt, { k: key }), L = s.engine.loading;
|
|
213
213
|
// engine.loading.settled() waits for it: use(mod); await loading.settled() says the module runs with its data back, and gameplay is no longer held for it.
|
|
214
|
-
// Its own set, not the inits': a failed replaces tells module:
|
|
214
|
+
// Its own set, not the inits': a failed replaces tells module:fresh once the inits are done, and its content must land on the line after use() threw
|
|
215
215
|
L._track(q.run(null, () => {
|
|
216
216
|
// the provider this data was kept for: one removed meanwhile, or another under the same key, does not get it (review l2 #4)
|
|
217
217
|
if (s._foreign !== f || s.providers.get(key) !== part || !Object.hasOwn(f.parts, key)) return;
|
|
@@ -291,7 +291,7 @@ export function applyAnnounced(s, data, slot, done) {
|
|
|
291
291
|
* Returns true when no module has a hook (nothing waited), else a Promise. The hooks start a microtask after the parts, and the marker and the
|
|
292
292
|
* freeze with them: the lines right after an unawaited apply can still step, run ops and apply again (stateReplace.js, pause). */
|
|
293
293
|
function afterLoad(s, e, slot, scope) {
|
|
294
|
-
const has =
|
|
294
|
+
const has = e.moduleOrder.map(n => e.modules.get(n)).filter(m => m?.afterLoad), q = s._replace; // in module order, like every reset step (session.js)
|
|
295
295
|
if (!has.length) { takeListenerError(scope, 0); return true; }
|
|
296
296
|
const job = q.pause();
|
|
297
297
|
let hooks = [];
|
package/core/saves/session.js
CHANGED
|
@@ -8,8 +8,18 @@
|
|
|
8
8
|
//
|
|
9
9
|
// What ending a playthrough clears: handles passed to track() and clock function timers added after start() (boot-time ones and a module's install-time ones, ctx.track, follow the module: they come back with their original delay while it stays; what a part's load() or an afterLoad sets up belongs to the new playthrough and stays),
|
|
10
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
|
|
12
|
-
// and the camera starts over
|
|
11
|
+
// save part (the state captured when start() finished is applied). Modules end their own part in their sessionEnd hook (a cutscene is skipped, the music stops),
|
|
12
|
+
// and the camera starts over in its sessionStart hook (the same rig object, as installed, keeping the view the load left on it). Listeners and hooks the game registered at boot stay: they belong to the game, not the playthrough.
|
|
13
|
+
//
|
|
14
|
+
// The reset sequence, one declared order (a module joins with hooks on its definition, never with listeners whose order would be install order):
|
|
15
|
+
// 1. end core first (control ends the old walks), then every module's sessionEnd(e), then the 'session:end' event
|
|
16
|
+
// 2. apply the save parts load (saveApply.js); when the records part (world module) replaced its records it calls ctx.things.recordsLoaded, which runs
|
|
17
|
+
// every module's worldLoad(e, info), then emits 'world:load' (outside a session too: a quick load, a level load; an atomic op's muted rollback runs neither)
|
|
18
|
+
// 3. rebuild every module's afterLoad(e, turn) (saveApply.js; gameplay frozen until they settle)
|
|
19
|
+
// 4. start core first (what is added now is setup, things.js), then every module's sessionStart(e, info), then the 'session:start' event
|
|
20
|
+
// Within a step modules run in engine.moduleOrder (stage, then before / after, then install order: modules.js), so an order that matters is declared there.
|
|
21
|
+
// The events are notifications for the game, after the modules' step: no module relies on them for its reset. A quick load (saves.load / apply)
|
|
22
|
+
// runs steps 2 and 3 only.
|
|
13
23
|
// engine.time.tick and every time view (core/time/time.js) start again from 0 or the save's value, and physics (rigid) rebuilds its world (velocities, sleep, solver caches), as on a fresh page.
|
|
14
24
|
// Events: 'session:end' (before the reset; flow returns to its start state), 'session:start' { kind: 'new' | 'load', slot? } (after; flow goes to 'playing').
|
|
15
25
|
// Around a state replacement, one list for every door (saves.apply, saves.load, session.newGame / load / quit):
|
|
@@ -196,7 +206,11 @@ export class Session {
|
|
|
196
206
|
/** @internal end the playthrough, apply, then announce the new one */
|
|
197
207
|
async _begin(fn, apply, info) {
|
|
198
208
|
const ok = await this._reset(fn, apply);
|
|
199
|
-
if (ok)
|
|
209
|
+
if (ok) {
|
|
210
|
+
this._started();
|
|
211
|
+
this.engine._things.setupTurn(); // step 4, core first: what the hooks and listeners below add is setup, rebuilt by code every playthrough
|
|
212
|
+
this.engine._resetStep('sessionStart', info);
|
|
213
|
+
}
|
|
200
214
|
this.engine.events.emit(ok ? 'session:start' : 'session:failed', info);
|
|
201
215
|
// ?play starts the first run inside engine.start(), so a session:start listener attached after `await engine.start()` misses it silently; hint once.
|
|
202
216
|
// Mark only when fired during start(), and hint only once start() returned (phase 'running') with no tick yet; later listeners are waiting for the next run.
|
|
@@ -210,7 +224,9 @@ export class Session {
|
|
|
210
224
|
if (!this._base) throw codedError('session-early', fmt(DEV.early, { fn }));
|
|
211
225
|
this._busy = true;
|
|
212
226
|
try {
|
|
213
|
-
e.events.
|
|
227
|
+
e.events._call('session:end', () => e.control.endTasks(null, 'replaced'), []); // step 1, core first: no walk runs on into the swap (a throwing task callback is reported, as from the listener it was)
|
|
228
|
+
e._resetStep('sessionEnd'); // modules end their part: a cutscene skipped, the music stopped
|
|
229
|
+
e.events.emit('session:end'); // then the game hears it (a running engine.skip listens here and is cancelled)
|
|
214
230
|
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
|
|
215
231
|
if (e.disposed) return false; // disposed in that macrotask: there is no state left to replace
|
|
216
232
|
// background results die inside apply (saveApply), which gives them back when it fails, before its rollback: a second epoch held here made what the rollback asked for look old
|