threedog 0.7.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (593) hide show
  1. package/CHANGELOG.md +411 -1
  2. package/README.md +8 -11
  3. package/core/{Animator.js → assets/Animator.js} +30 -18
  4. package/core/{Assets.js → assets/Assets.js} +131 -56
  5. package/core/{Baked.js → assets/Baked.js} +4 -4
  6. package/core/assets/assetEntry.js +302 -0
  7. package/core/{assetHot.js → assets/assetHot.js} +9 -7
  8. package/core/{assetLoad.js → assets/assetLoad.js} +55 -16
  9. package/core/assets/assetLod.js +113 -0
  10. package/core/{assetManifest.js → assets/assetManifest.js} +19 -11
  11. package/core/{assetReport.js → assets/assetReport.js} +7 -14
  12. package/core/{namedModel.js → assets/namedModel.js} +17 -13
  13. package/core/{Audio.js → audio/Audio.js} +47 -25
  14. package/core/{audioRules.js → audio/audioRules.js} +8 -5
  15. package/core/{audioVoice.js → audio/audioVoice.js} +17 -30
  16. package/core/{Events.js → base/Events.js} +3 -3
  17. package/core/{I18n.js → base/I18n.js} +15 -12
  18. package/core/{Random.js → base/Random.js} +7 -4
  19. package/core/{Vars.js → base/Vars.js} +14 -4
  20. package/core/{easing.js → base/easing.js} +1 -1
  21. package/core/{errorCodes.js → base/errorCodes.js} +151 -125
  22. package/core/{errorHints.js → base/errorHints.js} +17 -10
  23. package/core/{errors.js → base/errors.js} +12 -10
  24. package/core/{events.generated.js → base/events.generated.js} +11 -0
  25. package/core/base/follows.js +26 -0
  26. package/core/base/math.js +66 -0
  27. package/core/{params.js → base/params.js} +5 -6
  28. package/core/base/saveValues.js +81 -0
  29. package/core/base/sections.js +97 -0
  30. package/core/base/spelling.js +32 -0
  31. package/core/base/util.js +32 -0
  32. package/core/{validate.js → base/validate.js} +34 -34
  33. package/core/{Engine.js → engine/Engine.js} +137 -91
  34. package/core/{Loading.js → engine/Loading.js} +34 -5
  35. package/core/{copies.js → engine/copies.js} +4 -4
  36. package/core/{headlessLoad.js → engine/headlessLoad.js} +32 -15
  37. package/core/{lifecycle.js → engine/lifecycle.js} +41 -34
  38. package/core/{loop.js → engine/loop.js} +88 -49
  39. package/core/engine/moduleSlots.js +176 -0
  40. package/core/{moduleTypes.js → engine/moduleTypes.js} +26 -14
  41. package/core/engine/modules.js +503 -0
  42. package/core/{page.js → engine/page.js} +59 -29
  43. package/core/{plugins.js → engine/plugins.js} +21 -12
  44. package/core/{services.js → engine/services.js} +50 -40
  45. package/core/{startup.js → engine/startup.js} +66 -54
  46. package/core/{Input.js → input/Input.js} +67 -39
  47. package/core/{inputContext.js → input/inputContext.js} +14 -5
  48. package/core/input/inputKeyboard.js +39 -0
  49. package/core/{inputPad.js → input/inputPad.js} +24 -3
  50. package/core/{inputPointer.js → input/inputPointer.js} +11 -3
  51. package/core/input/inputSeat.js +66 -0
  52. package/core/{inputTouch.js → input/inputTouch.js} +24 -7
  53. package/core/{Budget.js → inspect/Budget.js} +21 -20
  54. package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +43 -18
  55. package/core/{Describe.js → inspect/Describe.js} +34 -26
  56. package/core/{Inspect.js → inspect/Inspect.js} +39 -10
  57. package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +7 -8
  58. package/core/{InspectPerf.js → inspect/InspectPerf.js} +19 -13
  59. package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
  60. package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +3 -2
  61. package/core/{UrlState.js → inspect/UrlState.js} +60 -24
  62. package/core/{catalog.js → inspect/catalog.js} +15 -8
  63. package/core/{checks.js → inspect/checks.js} +7 -5
  64. package/core/{debugView.js → inspect/debugView.js} +4 -4
  65. package/core/{describeRender.js → inspect/describeRender.js} +24 -22
  66. package/core/{describeText.js → inspect/describeText.js} +17 -8
  67. package/core/inspect/geometryWatch.js +38 -0
  68. package/core/{lightWatch.js → inspect/lightWatch.js} +8 -8
  69. package/core/inspect/metadata.generated.js +4140 -0
  70. package/core/{pictureWriters.js → inspect/pictureWriters.js} +130 -47
  71. package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
  72. package/core/inspect/toolDoor.js +21 -0
  73. package/core/inspect/valueHistory.js +35 -0
  74. package/core/{Ops.js → ops/Ops.js} +44 -14
  75. package/core/{control.js → ops/control.js} +57 -31
  76. package/core/ops/holds.js +140 -0
  77. package/core/{opsAtomic.js → ops/opsAtomic.js} +18 -5
  78. package/core/{opsCheck.js → ops/opsCheck.js} +11 -10
  79. package/core/{opsFail.js → ops/opsFail.js} +5 -7
  80. package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
  81. package/core/{opsRun.js → ops/opsRun.js} +9 -6
  82. package/core/{owned.js → ops/owned.js} +33 -19
  83. package/core/{sharedPoint.js → ops/sharedPoint.js} +13 -16
  84. package/core/{stackFrames.js → ops/stackFrames.js} +2 -2
  85. package/core/{stacks.js → ops/stacks.js} +34 -15
  86. package/core/{wrap.js → ops/wrap.js} +8 -6
  87. package/core/{SaveStore.js → saves/SaveStore.js} +53 -27
  88. package/core/{Saves.js → saves/Saves.js} +171 -54
  89. package/core/saves/saveApply.js +312 -0
  90. package/core/{saveFiles.js → saves/saveFiles.js} +45 -38
  91. package/core/{saveVersions.js → saves/saveVersions.js} +24 -23
  92. package/core/saves/session.js +231 -0
  93. package/core/saves/stateReplace.js +184 -0
  94. package/core/{Rays.js → scene/Rays.js} +44 -30
  95. package/core/{Views.js → scene/Views.js} +16 -8
  96. package/core/{adaptive.js → scene/adaptive.js} +19 -9
  97. package/core/{canvasBox.js → scene/canvasBox.js} +4 -3
  98. package/core/scene/compositeGround.js +72 -0
  99. package/core/scene/floor.js +17 -0
  100. package/core/{gameLights.js → scene/gameLights.js} +17 -7
  101. package/core/{grayMap.js → scene/grayMap.js} +8 -2
  102. package/core/{grid.js → scene/grid.js} +6 -4
  103. package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
  104. package/core/scene/ground.contract.js +14 -0
  105. package/core/scene/ground.js +139 -0
  106. package/core/{movement.js → scene/movement.js} +3 -3
  107. package/core/{pictureSlots.js → scene/pictureSlots.js} +2 -2
  108. package/core/scene/pixel.js +154 -0
  109. package/core/scene/pixelRatio.js +167 -0
  110. package/core/{sceneDelta.js → scene/sceneDelta.js} +5 -5
  111. package/core/{sceneMethods.js → scene/sceneMethods.js} +43 -15
  112. package/core/scene/stepPoses.js +60 -0
  113. package/core/{targeting.js → scene/targeting.js} +4 -5
  114. package/core/{thingExplain.js → scene/thingExplain.js} +7 -6
  115. package/core/{thingOps.js → scene/thingOps.js} +25 -16
  116. package/core/{things.js → scene/things.js} +18 -5
  117. package/core/{threePatches.js → scene/threePatches.js} +1 -1
  118. package/core/{tier.js → scene/tier.js} +10 -0
  119. package/core/scene/view.js +161 -0
  120. package/core/{Batching.js → stream/Batching.js} +85 -28
  121. package/core/{Stream.js → stream/Stream.js} +80 -38
  122. package/core/{batchGroups.js → stream/batchGroups.js} +11 -9
  123. package/core/{chunkStream.js → stream/chunkStream.js} +40 -0
  124. package/core/{scatter.js → stream/scatter.js} +7 -4
  125. package/core/{streamSources.js → stream/streamSources.js} +14 -8
  126. package/core/{Commits.js → threads/Commits.js} +17 -11
  127. package/core/{Jobs.js → threads/Jobs.js} +25 -13
  128. package/core/{Threads.js → threads/Threads.js} +21 -18
  129. package/core/{threadPure.js → threads/threadPure.js} +7 -5
  130. package/core/{threadServe.js → threads/threadServe.js} +3 -3
  131. package/core/{Clock.js → time/Clock.js} +20 -11
  132. package/core/{dayTime.js → time/dayTime.js} +5 -1
  133. package/core/{skip.js → time/skip.js} +28 -21
  134. package/core/{time.js → time/time.js} +32 -20
  135. package/core/{uiClock.js → time/uiClock.js} +4 -4
  136. package/docs/AI.md +92 -72
  137. package/docs/API.md +33 -28
  138. package/docs/CODEMAP.md +121 -200
  139. package/docs/COMMANDS.md +77 -70
  140. package/docs/CONVENTIONS.md +167 -24
  141. package/docs/MIGRATING-0.8.md +171 -0
  142. package/docs/MIGRATING-1.0.md +101 -0
  143. package/docs/THREE.md +140 -38
  144. package/docs/api/assets.md +12 -13
  145. package/docs/api/audio.md +6 -5
  146. package/docs/api/budget.md +4 -4
  147. package/docs/api/calendar.md +10 -11
  148. package/docs/api/cameraRig.md +32 -29
  149. package/docs/api/characters.md +35 -24
  150. package/docs/api/clock.md +1 -1
  151. package/docs/api/collider3d.md +9 -0
  152. package/docs/api/collision.md +12 -9
  153. package/docs/api/content.md +18 -17
  154. package/docs/api/dialogue.md +5 -4
  155. package/docs/api/engine.md +58 -54
  156. package/docs/api/events.md +17 -6
  157. package/docs/api/flow.md +1 -1
  158. package/docs/api/grids.md +1 -1
  159. package/docs/api/ground.md +6 -7
  160. package/docs/api/hud.md +2 -2
  161. package/docs/api/i18n.md +6 -6
  162. package/docs/api/input.md +9 -8
  163. package/docs/api/interactions.md +5 -5
  164. package/docs/api/inventory.md +10 -10
  165. package/docs/api/jobs.md +5 -5
  166. package/docs/api/level.md +10 -9
  167. package/docs/api/lightPool.md +1 -6
  168. package/docs/api/music.md +3 -3
  169. package/docs/api/nav.md +14 -12
  170. package/docs/api/openWorld.md +1 -1
  171. package/docs/api/particles.md +10 -7
  172. package/docs/api/photo.md +4 -2
  173. package/docs/api/pickups.md +3 -3
  174. package/docs/api/post.md +21 -5
  175. package/docs/api/quests.md +7 -5
  176. package/docs/api/rays.md +7 -7
  177. package/docs/api/rigid.md +29 -19
  178. package/docs/api/saves.md +13 -11
  179. package/docs/api/settings.md +9 -8
  180. package/docs/api/sky.md +8 -7
  181. package/docs/api/stream.md +8 -9
  182. package/docs/api/swarm.md +34 -0
  183. package/docs/api/terrain.md +6 -8
  184. package/docs/api/terrainDraw.md +2 -2
  185. package/docs/api/timeline.md +4 -4
  186. package/docs/api/tools.md +27 -22
  187. package/docs/api/triggers.md +2 -0
  188. package/docs/api/vars.md +1 -1
  189. package/docs/api/vegetation.md +4 -3
  190. package/docs/api/vegetationDraw.md +2 -2
  191. package/docs/api/water.md +7 -3
  192. package/docs/api/weather.md +27 -12
  193. package/docs/api/weatherDraw.md +4 -4
  194. package/docs/api/world.md +6 -6
  195. package/docs/recipes/01-new-game.md +28 -43
  196. package/docs/recipes/02-npc.md +21 -23
  197. package/docs/recipes/03-items-pickups.md +37 -53
  198. package/docs/recipes/04-quests.md +5 -4
  199. package/docs/recipes/05-props-bake.md +34 -44
  200. package/docs/recipes/06-clock-events.md +31 -22
  201. package/docs/recipes/07-flow-scenes-pause.md +30 -32
  202. package/docs/recipes/08-weather-sky.md +91 -37
  203. package/docs/recipes/09-materials-lights-models.md +25 -39
  204. package/docs/recipes/10-blender-level.md +22 -11
  205. package/docs/recipes/11-vehicles.md +44 -24
  206. package/docs/recipes/12-navmesh.md +60 -15
  207. package/docs/recipes/13-animation.md +70 -22
  208. package/docs/recipes/14-custom-module.md +33 -20
  209. package/docs/recipes/15-perf.md +51 -28
  210. package/docs/recipes/16-dev-bridge.md +39 -58
  211. package/docs/recipes/18-world.md +49 -28
  212. package/docs/recipes/19-shooting-picking.md +7 -4
  213. package/docs/recipes/20-content-actions-save.md +55 -40
  214. package/docs/recipes/21-camera.md +47 -25
  215. package/docs/recipes/22-shop-gold.md +21 -16
  216. package/docs/recipes/23-ops.md +28 -24
  217. package/docs/recipes/26-ui-parts.md +25 -14
  218. package/docs/recipes/27-net.md +3 -5
  219. package/docs/recipes/28-terrain.md +119 -23
  220. package/docs/recipes/29-grid.md +3 -3
  221. package/docs/recipes/30-templates.md +63 -30
  222. package/docs/recipes/31-audio.md +7 -7
  223. package/docs/recipes/32-action-game.md +21 -11
  224. package/docs/recipes/33-stream-sources.md +6 -3
  225. package/docs/recipes/34-environment-lighting.md +72 -25
  226. package/docs/recipes/35-picture-from-reference.md +20 -23
  227. package/docs/recipes/36-ground-plants.md +106 -0
  228. package/docs/recipes/40-scene.md +18 -21
  229. package/docs/recipes/43-shader-patches-surfaces.md +27 -48
  230. package/docs/recipes/44-water-weather-hooks.md +56 -50
  231. package/docs/recipes/45-cascaded-shadows.md +41 -20
  232. package/docs/recipes/46-blender-art-route.md +9 -10
  233. package/docs/recipes/49-game-module-contract.md +7 -6
  234. package/docs/recipes/50-own-renderer.md +3 -2
  235. package/docs/recipes/51-capability-catalog.md +14 -8
  236. package/docs/recipes/52-around-the-picture.md +56 -100
  237. package/docs/recipes/53-ground-up-close.md +61 -24
  238. package/docs/recipes/55-mods-time-wrap.md +17 -20
  239. package/docs/recipes/56-webgpu-tsl.md +28 -15
  240. package/docs/recipes/57-control.md +39 -12
  241. package/docs/recipes/58-input.md +15 -2
  242. package/docs/recipes/59-depth-post-effects.md +1 -1
  243. package/docs/recipes/60-judge-the-picture.md +30 -25
  244. package/docs/recipes/62-picture-code.md +129 -39
  245. package/docs/recipes/63-third-person-start.md +19 -5
  246. package/docs/recipes/64-particles.md +54 -5
  247. package/docs/recipes/65-swarm.md +140 -0
  248. package/docs/recipes/66-common-tasks.md +313 -0
  249. package/examples/action/.threedog/content-index.json +1 -1
  250. package/examples/action/GAMEMAP.md +5 -5
  251. package/examples/perf-island/.threedog/content-index.json +1 -0
  252. package/examples/{sheepisland → perf-island}/GAMEMAP.md +15 -14
  253. package/examples/{sheepisland → perf-island}/assets.js +1 -1
  254. package/examples/{sheepisland → perf-island}/main.js +8 -8
  255. package/examples/{sheepisland → perf-island}/models.js +1 -1
  256. package/examples/{sheepisland → perf-island}/params.js +1 -1
  257. package/examples/{sheepisland → perf-island}/picture/index.js +1 -1
  258. package/examples/{sheepisland → perf-island}/picture/palette.js +2 -2
  259. package/examples/{sheepisland → perf-island}/views.js +1 -1
  260. package/examples/plain-picture/GAMEMAP.md +4 -1
  261. package/examples/rc2d/GAMEMAP.md +4 -3
  262. package/examples/rc2d/main.js +1 -3
  263. package/examples/rc2d/rc2d.js +1 -1
  264. package/examples/styletest/.threedog/content-index.json +1 -1
  265. package/examples/styletest/GAMEMAP.md +6 -5
  266. package/examples/techniques/contact-shadows/contactShadows.js +1 -1
  267. package/examples/techniques/contact-shadows/main.js +1 -1
  268. package/examples/techniques/interior-light/main.js +1 -1
  269. package/examples/techniques/modular-building/README.md +7 -6
  270. package/examples/techniques/outlines-and-rim/picture/post.js +1 -1
  271. package/examples/techniques/procedural-animation/README.md +1 -1
  272. package/examples/webgpu-tsl/GAMEMAP.md +2 -1
  273. package/examples/world/.threedog/content-index.json +1 -1
  274. package/examples/world/GAMEMAP.md +9 -7
  275. package/examples/world/main.js +3 -3
  276. package/examples/world/picture/sky.js +1 -1
  277. package/index.d.ts +16 -12
  278. package/index.js +53 -32
  279. package/llms.txt +11 -14
  280. package/modules/ambience/Ambience.js +16 -11
  281. package/modules/calendar/Calendar.js +19 -19
  282. package/modules/calendar/index.js +18 -16
  283. package/modules/calendar/schedule.js +11 -6
  284. package/modules/calendar/seasons.js +7 -7
  285. package/modules/camera/FirstPersonCamera.js +5 -5
  286. package/modules/camera/FixedCamera.js +43 -30
  287. package/modules/camera/FollowCamera.js +24 -15
  288. package/modules/camera/RtsCamera.js +12 -11
  289. package/modules/camera/common.js +72 -37
  290. package/modules/camera/contract.js +1 -0
  291. package/modules/camera/pixelSnap.js +62 -0
  292. package/modules/characters/Character.js +166 -70
  293. package/modules/characters/NPC.js +84 -44
  294. package/modules/characters/assetModel.js +16 -12
  295. package/modules/characters/astar.js +48 -27
  296. package/modules/characters/behaviors.js +4 -5
  297. package/modules/characters/character.contract.js +21 -0
  298. package/modules/characters/contract.js +17 -3
  299. package/modules/characters/index.js +240 -226
  300. package/modules/characters/moveHelpers.js +88 -12
  301. package/modules/characters/mover.contract.js +14 -0
  302. package/modules/characters/movers/common.js +22 -18
  303. package/modules/characters/movers/manual.js +1 -1
  304. package/modules/characters/movers/rapier.js +18 -10
  305. package/modules/characters/movers/simple.js +26 -13
  306. package/modules/characters/movers/support.js +24 -13
  307. package/modules/characters/npcAvoid.js +19 -16
  308. package/modules/characters/npcSim.js +88 -32
  309. package/modules/characters/npcView.js +19 -11
  310. package/modules/characters/pathAsync.js +81 -29
  311. package/modules/characters/pathJob.js +38 -21
  312. package/modules/characters/pathWorker.js +1 -1
  313. package/modules/characters/player.js +120 -0
  314. package/modules/characters/playerStrings.js +2 -2
  315. package/modules/characters/proceduralRig.js +2 -2
  316. package/modules/characters/seat.js +56 -0
  317. package/modules/characters/useModel.js +3 -3
  318. package/modules/characters/vehicle.contract.js +8 -5
  319. package/modules/characters/walkTo.js +40 -33
  320. package/modules/collision/Collision.js +69 -45
  321. package/modules/collision/contract.js +15 -0
  322. package/modules/collision/grid.js +6 -1
  323. package/modules/content/explain.js +2 -3
  324. package/modules/content/fields.js +24 -3
  325. package/modules/content/ids.js +5 -3
  326. package/modules/content/index.js +132 -114
  327. package/modules/content/loader.js +117 -140
  328. package/modules/content/markers.js +25 -0
  329. package/modules/content/models.js +54 -17
  330. package/modules/content/packs.js +5 -4
  331. package/modules/content/parts.js +2 -2
  332. package/modules/content/places.js +36 -0
  333. package/modules/content/props.js +22 -17
  334. package/modules/content/rules.js +47 -61
  335. package/modules/content/stages.js +7 -7
  336. package/modules/content/templates.js +80 -49
  337. package/modules/content/words.js +47 -0
  338. package/modules/debug/DebugPanel.js +14 -45
  339. package/modules/flow/contract.js +2 -1
  340. package/modules/flow/index.js +30 -16
  341. package/modules/gameplay/Container.js +17 -13
  342. package/modules/gameplay/Containers.js +23 -6
  343. package/modules/gameplay/Dialogue.js +93 -34
  344. package/modules/gameplay/Interactions.js +93 -51
  345. package/modules/gameplay/Inventory.js +64 -22
  346. package/modules/gameplay/Quests.js +146 -30
  347. package/modules/gameplay/boxOps.js +8 -1
  348. package/modules/gameplay/dialogueBubbles.js +16 -12
  349. package/modules/gameplay/inventoryOps.js +11 -8
  350. package/modules/gameplay/pickups.js +63 -37
  351. package/modules/gameplay/questLog.js +4 -2
  352. package/modules/gameplay/questSave.js +9 -4
  353. package/modules/gameplay/quests.contract.js +1 -1
  354. package/modules/grid/Grid.js +2 -2
  355. package/modules/grid/Layer.js +12 -8
  356. package/modules/grid/index.js +28 -23
  357. package/modules/grid/ops.js +43 -46
  358. package/modules/grid/preview.js +7 -7
  359. package/modules/grid/tiles.js +6 -6
  360. package/modules/hlod/index.js +42 -57
  361. package/modules/hud/index.js +22 -14
  362. package/modules/hud/parts.js +8 -8
  363. package/modules/level/contract.js +16 -0
  364. package/modules/level/heightfield.js +29 -31
  365. package/modules/level/index.js +113 -161
  366. package/modules/level/load.js +196 -0
  367. package/modules/level/meshes.js +65 -0
  368. package/modules/level/nodes.js +40 -23
  369. package/modules/lights/index.js +33 -183
  370. package/modules/lights/slots.js +93 -0
  371. package/modules/lights/sources.js +90 -0
  372. package/modules/music/Music.js +34 -28
  373. package/modules/music/rules.js +1 -1
  374. package/modules/nav/contract.js +16 -0
  375. package/modules/nav/index.js +180 -49
  376. package/modules/nav/navPath.js +45 -10
  377. package/modules/net/Client.js +7 -7
  378. package/modules/net/Host.js +7 -7
  379. package/modules/net/Net.js +1 -1
  380. package/modules/net/index.js +6 -5
  381. package/modules/net/sync.js +2 -2
  382. package/modules/net/transports.js +2 -2
  383. package/modules/particles/Particles.js +95 -29
  384. package/modules/particles/effect.js +86 -32
  385. package/modules/particles/shaders.js +19 -1
  386. package/modules/photo/Photo.js +23 -23
  387. package/modules/rigid/RigidBodies.js +255 -89
  388. package/modules/rigid/Vehicles.js +17 -8
  389. package/modules/rigid/collider3d.contract.js +26 -0
  390. package/modules/rigid/ragdoll.js +298 -0
  391. package/modules/rigid/ragdollBones.js +209 -0
  392. package/modules/rigid/refresh.js +10 -0
  393. package/modules/rigid/sync.js +51 -20
  394. package/modules/settings/Settings.js +177 -61
  395. package/modules/settings/apply.js +20 -13
  396. package/modules/settings/sections.js +19 -14
  397. package/modules/settings/strings.js +2 -2
  398. package/modules/settings/view.js +3 -3
  399. package/modules/sky/Sky.js +29 -22
  400. package/modules/sky/clouds.js +7 -7
  401. package/modules/sky/dome.js +33 -20
  402. package/modules/sky/domeLayers.js +9 -9
  403. package/modules/sky/environment.js +6 -6
  404. package/modules/sky/frame.js +19 -10
  405. package/modules/sky/season.js +7 -1
  406. package/modules/sky/shader.js +24 -25
  407. package/modules/sky/skyModule.js +17 -28
  408. package/modules/sky/tint.js +1 -1
  409. package/modules/swarm/Swarm.js +356 -0
  410. package/modules/swarm/draw.js +68 -0
  411. package/modules/swarm/grid.js +63 -0
  412. package/modules/terrain/ChunkManager.js +71 -59
  413. package/modules/terrain/chunkQueries.js +7 -24
  414. package/modules/terrain/chunkWorker.js +1 -1
  415. package/modules/terrain/draw.js +14 -11
  416. package/modules/terrain/index.js +42 -42
  417. package/modules/terrain/terrainColorMap.js +6 -3
  418. package/modules/terrain/terrainDefaults.js +2 -1
  419. package/modules/terrain/terrainEdit.js +45 -29
  420. package/modules/terrain/terrainGen.js +19 -12
  421. package/modules/terrain/terrainIsland.js +2 -2
  422. package/modules/terrain/terrainMesh.js +7 -6
  423. package/modules/terrain/terrainShape.js +8 -10
  424. package/modules/terrain/terrainShapeMain.js +3 -3
  425. package/modules/timeline/Timeline.js +83 -43
  426. package/modules/timeline/Tween.js +25 -19
  427. package/modules/timeline/shots.js +24 -17
  428. package/modules/triggers/index.js +95 -28
  429. package/modules/vegetation/Vegetation.js +34 -26
  430. package/modules/vegetation/densityMap.js +4 -7
  431. package/modules/vegetation/draw.js +39 -18
  432. package/modules/vegetation/groundChunks.js +21 -38
  433. package/modules/vegetation/index.js +37 -12
  434. package/modules/vegetation/modelGeometry.js +3 -6
  435. package/modules/vegetation/nearFade.js +1 -1
  436. package/modules/water/Water.js +20 -16
  437. package/modules/water/surface.js +3 -3
  438. package/modules/weather/Weather.js +52 -40
  439. package/modules/weather/particles.js +8 -8
  440. package/modules/weather/weatherDraw.js +28 -23
  441. package/modules/world/World.js +28 -15
  442. package/modules/world/explain.js +1 -1
  443. package/modules/world/index.js +30 -17
  444. package/modules/world/persist.js +90 -27
  445. package/modules/world/pos.js +5 -5
  446. package/modules/world/records.js +37 -11
  447. package/modules/world/sim.js +78 -27
  448. package/modules/world/simFar.js +2 -2
  449. package/modules/world/state.js +43 -11
  450. package/modules/world/thingSource.js +20 -5
  451. package/modules/world/views.js +27 -14
  452. package/package.json +48 -7
  453. package/presets.js +1 -3
  454. package/render/PostFX.js +83 -53
  455. package/render/backend.js +31 -33
  456. package/render/cascades.js +17 -12
  457. package/render/cascades.tsl.js +5 -8
  458. package/render/daylight.js +20 -3
  459. package/render/detail.js +8 -7
  460. package/render/effects.js +28 -25
  461. package/render/fuse.js +3 -3
  462. package/render/fx/cloudShadow.tsl.js +3 -3
  463. package/render/fx/detail.tsl.js +1 -1
  464. package/render/fx/index.js +5 -10
  465. package/render/fx/library.tsl.js +11 -0
  466. package/render/fx/lighting.tsl.js +2 -1
  467. package/render/fx/nodeErrors.tsl.js +2 -2
  468. package/render/fx/objectOrigin.tsl.js +1 -2
  469. package/render/fx/particles.tsl.js +8 -6
  470. package/render/fx/patchNodes.tsl.js +5 -15
  471. package/render/fx/postWebGPU.tsl.js +30 -26
  472. package/render/fx/sky.tsl.js +15 -17
  473. package/render/fx/uniforms.tsl.js +4 -4
  474. package/render/fx/wind.tsl.js +1 -1
  475. package/render/fxNumbers.js +3 -0
  476. package/render/layers.js +2 -2
  477. package/render/lighting.js +5 -3
  478. package/render/lightmap.js +41 -21
  479. package/render/lights.js +6 -6
  480. package/render/lit.js +24 -0
  481. package/render/materials.js +8 -7
  482. package/render/mergeCommon.js +22 -0
  483. package/render/modeling.js +2 -2
  484. package/render/occlusion.js +62 -15
  485. package/render/ownFrame.js +4 -4
  486. package/render/patches.js +15 -15
  487. package/render/postWebGL.js +15 -12
  488. package/render/probes.js +41 -19
  489. package/render/recordSweep.js +117 -0
  490. package/render/shaderErrors.js +10 -9
  491. package/render/shadowCache.tsl.js +107 -0
  492. package/render/shadowTypes.js +9 -0
  493. package/{core → render}/shadows.js +59 -13
  494. package/render/slots.js +7 -7
  495. package/render/terms.js +22 -24
  496. package/render/uniformDecl.js +1 -1
  497. package/types/core.d.ts +336 -202
  498. package/types/gameplay.d.ts +254 -130
  499. package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +22 -7
  500. package/types/generated/core/{audioVoice.d.ts → audio/audioVoice.d.ts} +2 -2
  501. package/types/generated/core/{Events.d.ts → base/Events.d.ts} +4 -4
  502. package/types/generated/core/{I18n.d.ts → base/I18n.d.ts} +8 -16
  503. package/types/generated/core/{Random.d.ts → base/Random.d.ts} +4 -3
  504. package/types/generated/core/{page.d.ts → engine/page.d.ts} +8 -9
  505. package/types/generated/core/{Input.d.ts → input/Input.d.ts} +28 -10
  506. package/types/generated/core/input/inputSeat.d.ts +26 -0
  507. package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
  508. package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +17 -3
  509. package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +6 -4
  510. package/types/generated/core/{control.d.ts → ops/control.d.ts} +14 -10
  511. package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +62 -18
  512. package/types/generated/core/{session.d.ts → saves/session.d.ts} +3 -2
  513. package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
  514. package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +2 -2
  515. package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
  516. package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +22 -18
  517. package/types/generated/core/{Commits.d.ts → threads/Commits.d.ts} +1 -1
  518. package/types/generated/core/{Jobs.d.ts → threads/Jobs.d.ts} +6 -6
  519. package/types/generated/core/{Threads.d.ts → threads/Threads.d.ts} +4 -4
  520. package/types/generated/modules/calendar/Calendar.d.ts +10 -11
  521. package/types/generated/modules/debug/DebugPanel.d.ts +1 -9
  522. package/types/generated/modules/grid/Grid.d.ts +1 -0
  523. package/types/generated/modules/grid/Layer.d.ts +1 -1
  524. package/types/generated/modules/grid/index.d.ts +3 -3
  525. package/types/generated/modules/music/Music.d.ts +7 -5
  526. package/types/generated/modules/particles/Particles.d.ts +5 -4
  527. package/types/generated/modules/sky/Sky.d.ts +21 -10
  528. package/types/generated/modules/swarm/Swarm.d.ts +80 -0
  529. package/types/generated/modules/timeline/Timeline.d.ts +7 -5
  530. package/types/generated/modules/water/Water.d.ts +1 -0
  531. package/types/generated/modules/weather/Weather.d.ts +14 -16
  532. package/types/generated/modules/weather/weatherDraw.d.ts +3 -3
  533. package/types/generated/modules/world/World.d.ts +11 -7
  534. package/types/generated/render/PostFX.d.ts +21 -23
  535. package/types/generated/render/materials.d.ts +1 -0
  536. package/types/generated/render/occlusion.d.ts +9 -0
  537. package/types/generated/render/patches.d.ts +1 -0
  538. package/types/generated/ui/Focus.d.ts +1 -0
  539. package/types/generated/ui/UI.d.ts +1 -0
  540. package/types/nav.d.ts +47 -15
  541. package/types/physics.d.ts +150 -73
  542. package/types/pixel.d.ts +75 -0
  543. package/types/tsl.d.ts +37 -4
  544. package/types/world.d.ts +48 -75
  545. package/ui/Focus.js +10 -9
  546. package/ui/Parts.js +13 -5
  547. package/ui/UI.js +7 -7
  548. package/ui/defaults.js +3 -2
  549. package/ui/theme.js +7 -5
  550. package/core/assetEntry.js +0 -109
  551. package/core/engineCamera.js +0 -32
  552. package/core/ground.js +0 -104
  553. package/core/holds.js +0 -134
  554. package/core/math.js +0 -48
  555. package/core/moduleSlots.js +0 -100
  556. package/core/modules.js +0 -314
  557. package/core/saveApply.js +0 -210
  558. package/core/saveValues.js +0 -46
  559. package/core/session.js +0 -174
  560. package/core/shadowTypes.js +0 -16
  561. package/core/util.js +0 -17
  562. package/core/view.js +0 -43
  563. package/docs/MIGRATING-0.3.md +0 -248
  564. package/docs/MIGRATING-0.4.md +0 -320
  565. package/docs/MIGRATING-0.5.md +0 -68
  566. package/docs/MIGRATING-0.6.md +0 -126
  567. package/docs/PERF.md +0 -245
  568. package/docs/recipes/36-sky-ground-plants.md +0 -158
  569. package/docs/recipes/37-terrain-hooks.md +0 -115
  570. package/docs/recipes/38-environment-hooks.md +0 -67
  571. package/docs/recipes/42-terrain-shape.md +0 -64
  572. package/docs/recipes/47-island-snow-backdrop.md +0 -43
  573. package/docs/recipes/54-three-idioms.md +0 -88
  574. package/examples/plain-picture/FINDINGS.md +0 -53
  575. package/examples/sheepisland/.threedog/content-index.json +0 -1
  576. package/modules/camera/projection.js +0 -21
  577. /package/core/{mulberry32.js → base/mulberry32.js} +0 -0
  578. /package/core/{inputDefaults.js → input/inputDefaults.js} +0 -0
  579. /package/core/{textureBytes.js → inspect/textureBytes.js} +0 -0
  580. /package/core/{actor.js → ops/actor.js} +0 -0
  581. /package/core/{opsHistory.js → ops/opsHistory.js} +0 -0
  582. /package/core/{saveIds.js → saves/saveIds.js} +0 -0
  583. /package/core/{screenToGround.js → scene/screenToGround.js} +0 -0
  584. /package/core/{cells.js → stream/cells.js} +0 -0
  585. /package/core/{streamCells.js → stream/streamCells.js} +0 -0
  586. /package/core/{pureWorker.js → threads/pureWorker.js} +0 -0
  587. /package/examples/{sheepisland → perf-island}/content/index.js +0 -0
  588. /package/examples/{sheepisland → perf-island}/content/props.js +0 -0
  589. /package/examples/{sheepisland → perf-island}/content/templates.js +0 -0
  590. /package/examples/{sheepisland → perf-island}/content/vegetation.js +0 -0
  591. /package/examples/{sheepisland → perf-island}/picture/lights.js +0 -0
  592. /package/examples/{sheepisland → perf-island}/picture/materials.js +0 -0
  593. /package/examples/{sheepisland → perf-island}/picture/sky.js +0 -0
@@ -1,20 +1,20 @@
1
1
  // Weather particle systems (recipes/44). Built-in rain and snow are two specs of one falling-particle system; a game draws a field of its
2
- // own table (ash, petals, sparks) with engine.weather.define(field, spec), and the same call replaces rain or snow. The amount each frame is
2
+ // own table (ash, petals, sparks) with engine.weather.defineField(field, spec), and the same call replaces rain or snow. The amount each frame is
3
3
  // weather.current[field], so the table's smooth blending drives particles too.
4
4
  //
5
- // spec (weather({ rain, snow }), or define): shape 'line' (streaks that slant with the wind) | 'round' | 'soft' | 'square' (point sprites
5
+ // spec (weather({ rain, snow }), or defineField): shape 'line' (streaks that slant with the wind) | 'round' | 'soft' | 'square' (point sprites
6
6
  // that drift), texture (asset name, sprites only), color, opacity, size / maxSize (sprite size and pixel cap), length (line meters),
7
7
  // speed (fall m/s), slant (line lean per unit of wind), sway (sprite drift meters), count, density (amount 0..1 -> share of particles drawn),
8
8
  // glsl: { vertex, fragment } (whole shader text; copy from shaders.js), uniforms (for your glsl);
9
9
  // or create(engine, { area, count }) => { object, update?(amount, ctx) } for a system of your own (the engine adds it, shows it while the
10
10
  // amount is above 0.02 and calls update every frame with ctx = { camera, time, wind }).
11
- import { engineOwned } from '../../core/things.js';
11
+ import { engineOwned } from '../../core/scene/things.js';
12
12
  import * as THREE from 'three';
13
- import { closest } from '../../core/validate.js';
14
- import { readParams, keysSchema } from '../../core/params.js';
13
+ import { closest, needMaterial } from '../../core/base/validate.js';
14
+ import { readParams, keysSchema } from '../../core/base/params.js';
15
15
  import { declareUniforms } from '../../render/uniformDecl.js';
16
16
  import { lineVert, lineFrag, pointVert, pointFrag, SHAPES, shaderMat, scatter } from './shaders.js';
17
- import { codedError } from '../../core/errorHints.js';
17
+ import { codedError } from '../../core/base/errorHints.js';
18
18
  import { isWebGPU, webgpuPart } from '../../render/backend.js';
19
19
 
20
20
  const SPEC_KEYS = ['shape', 'texture', 'color', 'opacity', 'size', 'maxSize', 'length', 'speed', 'slant', 'sway', 'count', 'density', 'glsl', 'uniforms', 'create'];
@@ -36,7 +36,7 @@ export function makeSystem(engine, field, spec, { area, count, base = DRIFT }) {
36
36
  const where = `weather particles '${field}'`;
37
37
  readParams(where, keysSchema(SPEC_KEYS), spec);
38
38
  const s = { ...base, ...spec, shape: spec.shape ?? (spec.texture ? 'round' : base.shape) };
39
- const n = Math.max(1, Math.round(spec.count ? (engine.tier === 'low' ? spec.count / 2 : spec.count) : count));
39
+ const n = Math.max(1, Math.round(spec.count || count));
40
40
  if (s.create) {
41
41
  const own = s.create(engine, { area, count: n });
42
42
  if (!own?.object?.isObject3D) throw codedError('weather-option', `${where}: create must return { object: THREE.Object3D, update?(amount, { camera, time, wind }) }`);
@@ -83,7 +83,7 @@ function finish(engine, field, sys) {
83
83
  sys.engineMaterial = mine;
84
84
  Object.defineProperty(sys, 'material', { enumerable: true, get: () => o.material ?? null, set(m) {
85
85
  if (sys.own) throw codedError('weather-option', `weather particles '${field}': this object came from create(), so its material is yours: write it on the object`);
86
- if (m != null && !m.isMaterial) throw codedError('weather-option', `weather particles '${field}': material is a three.js material (or null for the engine's); got ${m}`);
86
+ if (m != null) needMaterial('weather-option', `weather particles '${field}': material`, m, " (null gives the engine's back)");
87
87
  sys.given = m || null;
88
88
  o.material = m ?? mine;
89
89
  } });
@@ -3,39 +3,39 @@
3
3
  // weather table, its save and its events.
4
4
  // shared points: sky tint, lightning flash, snow cover
5
5
  // rain / snow particles that follow the camera (particles.js), thunder, audio rule conditions
6
- import { builtInSounds } from '../../core/assetManifest.js';
7
- import { readParams, keysSchema, isOptions } from '../../core/params.js';
8
- import { codedError } from '../../core/errorHints.js';
6
+ import { builtInSounds } from '../../core/assets/assetManifest.js';
7
+ import { readParams, keysSchema } from '../../core/base/params.js';
8
+ import { isOptions } from '../../core/base/util.js';
9
+ import { codedError } from '../../core/base/errorHints.js';
9
10
  import { onRendererSwap } from '../../render/backend.js';
10
11
  import { makeSystem, updateSystem, dropSystem, RAIN, SNOW } from './particles.js';
11
12
 
12
13
  const DRAW_PARAMS = keysSchema(['particles', 'area', 'rain', 'snow']); // the picture options of weather(): the rest are the state's
13
14
  const BASE = { rain: RAIN, snow: SNOW };
14
15
 
15
- /** engine.weatherDraw: particles and picture effects of the current weather */
16
+ /** engine.weatherDraw: particles and picture effects of the current weather @experimental */
16
17
  export class WeatherDraw {
17
18
  /**
18
19
  * @internal
19
20
  * @param {any} engine
20
21
  * @param {{ particles?: number, area?: number, rain?: any, snow?: any }} [opts]
21
22
  */
22
- constructor(engine, { particles = 6000, area = 40, rain = {}, snow = {} } = {}) {
23
+ constructor(engine, { particles, area = 40, rain = {}, snow = {} } = {}) {
23
24
  /** @internal */ this.engine = engine;
24
- /** @internal the state half: read only */ this.state = engine.weather;
25
25
  /** Sky flash now, 1 at a strike (the weather:lightning event) fading to 0 @type {number} */
26
26
  this.flash = 0;
27
27
  // the weather's entries on the shared sky points: taken once through ctx.mod (owned by this module, gone with it) and rewritten every frame with
28
- // handle.change (core/sharedPoint.js), so a frame adds no entry and no cleanup handle. ctx is set by the module's install
28
+ // handle.change (core/ops/sharedPoint.js), so a frame adds no entry and no cleanup handle. ctx is set by the module's install
29
29
  /** @internal */ this._ctx = null; /** @internal */ this._h = {};
30
- /** @internal */ this._tint = { color: this.state.overcastColor, amount: 0, horizon: 0 };
31
- /** Default particle count per system (halved on low-tier devices) @type {number} */
32
- this.particles = engine.tier === 'low' ? Math.round(particles / 2) : particles;
30
+ /** @internal */ this._tint = { color: null, amount: 0, horizon: 0 };
31
+ /** Default particle count per system: weather({ particles }), else 6000 (3000 on low-tier devices) @type {number} */
32
+ this.particles = particles ?? (engine.tier === 'low' ? 3000 : 6000);
33
33
  /** @internal */ this.area = area;
34
- /** Particle systems drawn now: field -> { field, object, material, uniforms, spec } (rain / snow when the table has them, plus fields engine.weather.define adds) @type {Map<string, any>} */
34
+ /** Particle systems drawn now: field -> { field, object, material, uniforms, spec } (rain / snow when the table has them, plus fields engine.weather.defineField adds) @type {Map<string, any>} */
35
35
  this.systems = new Map();
36
36
  // zero cost when unused: a table where nothing ever rains or snows builds no particle meshes
37
37
  const { cover, ...snowGiven } = snow;
38
- /** @internal what weather({ rain, snow }) gave: define(field, null) goes back to it */ this._given = { rain, snow: snowGiven };
38
+ /** @internal what weather({ rain, snow }) gave: defineField(field, null) goes back to it */ this._given = { rain, snow: snowGiven };
39
39
  for (const k of Object.keys(BASE)) if (this._used(k)) this._build(k, this._given[k], BASE[k]);
40
40
  // snow cover: foliage / ground season tint moves toward the snow colors as current.snow rises (ground.cover)
41
41
  if (cover !== undefined) {
@@ -48,14 +48,16 @@ export class WeatherDraw {
48
48
 
49
49
  /** @internal the weather table (state half) */
50
50
  get types() { return this.state.types; }
51
+ /** @internal the state half, read only and read live: a replaced weather module must not leave the picture on the old one */
52
+ get state() { return this.engine.weather; }
51
53
  /** @internal does any type have this field above 0 */
52
54
  _used(field) { return Object.values(this.types).some(v => v[field] > 0); }
53
55
 
54
- /** @internal engine.weather.define */
55
- define(field, spec) {
56
+ /** @internal engine.weather.defineField */
57
+ defineField(field, spec) {
56
58
  const fields = [...new Set(Object.values(this.types).flatMap(t => Object.keys(t)))];
57
- if (!fields.includes(field)) throw codedError('weather-option', `weather.define('${field}'): no weather type has this field; add it to a type in weather({ types }) (e.g. ashfall: { ${field}: 1 }), or use one of ${fields.join(', ')}`);
58
- if (spec !== null && (typeof spec !== 'object' || Array.isArray(spec))) throw codedError('weather-option', `weather.define('${field}', spec): spec is an object, e.g. { shape: 'soft', color: 0x555555 } or { create }, or null to give the field back; see recipes/44-water-weather-hooks.md`);
59
+ if (!fields.includes(field)) throw codedError('weather-option', `weather.defineField('${field}'): no weather type has this field; add it to a type in weather({ types }) (e.g. ashfall: { ${field}: 1 }), or use one of ${fields.join(', ')}`);
60
+ if (spec !== null && (typeof spec !== 'object' || Array.isArray(spec))) throw codedError('weather-option', `weather.defineField('${field}', spec): spec is an object, e.g. { shape: 'soft', color: 0x555555 } or { create }, or null to give the field back; see recipes/44-water-weather-hooks.md`);
59
61
  if (spec) return this._build(field, spec, BASE[field]);
60
62
  if (BASE[field] && this._used(field)) return this._build(field, this._given[field], BASE[field]);
61
63
  const s = this.systems.get(field);
@@ -65,9 +67,9 @@ export class WeatherDraw {
65
67
 
66
68
  /** @internal */
67
69
  _build(field, spec, base) {
70
+ const sys = makeSystem(this.engine, field, spec, { area: this.area, count: this.particles, base }); // first: a bad spec throws with the old system still drawn
68
71
  const old = this.systems.get(field);
69
72
  if (old) dropSystem(this.engine, old);
70
- const sys = makeSystem(this.engine, field, spec, { area: this.area, count: this.particles, base });
71
73
  sys.base = base; // the renderer swap builds it again over the same defaults
72
74
  this.systems.set(field, sys);
73
75
  return sys;
@@ -75,7 +77,7 @@ export class WeatherDraw {
75
77
 
76
78
  /**
77
79
  * @internal fallback 'webgl': systems built before start() carry WebGPURenderer node materials; rebuild them for the renderer in use, keeping what
78
- * the game wrote since (spec numbers, uniforms, its material). A define() create(engine) object is the game's own and stays (the scene check names it
80
+ * the game wrote since (spec numbers, uniforms, its material). A defineField() create(engine) object is the game's own and stays (the scene check names it
79
81
  * if WebGL cannot draw it).
80
82
  */
81
83
  _rendererSwapped() {
@@ -97,17 +99,20 @@ export class WeatherDraw {
97
99
  */
98
100
  apply(camera, dt = 0) {
99
101
  const c = this.state.current, e = this.engine, T = this._tint;
102
+ T.color = this.state.overcastColor;
100
103
  const t = e.time.now('real');
101
104
  this.flash = Math.max(0, this.flash - dt * 3);
102
105
  T.amount = c.grey; T.horizon = c.grey * 0.8; this._put('sky.tint', 'value', T);
103
106
  this._put('sky.flash', 'add', this.flash > 0 ? this.state.lightning(this.flash, e) * this.state.lightningBrightness : 0);
104
- if (this._cover) { this._coverMod.amount = (c.snow ?? 0) * this._cover.strength; this._put('ground.cover', 'value', this._coverMod); } // requires sky: the picture points exist
107
+ if (this._cover) { this._coverMod.amount = (c.snow ?? 0) * this._cover.strength; this._put('ground.cover', 'value', this._coverMod); }
105
108
  for (const sys of this.systems.values()) updateSystem(sys, c[sys.field] ?? 0, camera, t, c.wind);
106
109
  }
107
110
  /** @internal one contribution to a shared point: taken on first use, then changed in place */
108
111
  _put(point, op, v) {
109
112
  // change() is false when the entry is gone (a point cleared on a new session): take it again, as the old per-frame take did anyway
110
113
  if (this._h[point]?.change(v)) return;
114
+ // no sky module: the point does not exist and nothing reads it; a game's own sky reads weather.current.grey and weatherDraw.flash, or defines the point itself
115
+ if (!this.engine.stacks.has(point)) return;
111
116
  const o = op === 'value' ? { value: v } : { [op]: v, layer: 'effect' }; // tint / cover are data points (value), the flash an effect-layer number
112
117
  this._h[point] = this._ctx ? this._ctx.mod(point, o) : this.engine.mod(point, { ...o, owner: 'weatherDraw' });
113
118
  }
@@ -121,14 +126,13 @@ export function weatherDrawModule(opts) {
121
126
  readParams('weather (drawing half)', DRAW_PARAMS, opts);
122
127
  let L = null;
123
128
  return {
124
- name: 'weatherDraw', type: 'picture', provides: ['weatherDraw'], label: 'Weather drawing', params: DRAW_PARAMS, options: opts, requires: ['weather', 'sky'], stage: 'environment', before: ['sky'], after: ['weather'],
129
+ name: 'weatherDraw', skipKind: 'none', type: 'picture', provides: ['weatherDraw'], label: 'Weather drawing', params: DRAW_PARAMS, options: opts, requires: ['weather'], optional: ['sky'], stage: 'environment', before: ['sky'], after: ['weather'],
125
130
  install(e, ctx) { e.i18n.add({ 'zh-CN': { 'module.weatherDraw': '天气外观' }, en: { 'module.weatherDraw': 'weather drawing' } });
126
131
  L = new WeatherDraw(e, opts);
127
132
  L._ctx = ctx; // the weather's entries on the shared points go with this module (ctx.mod)
128
133
  ctx.track(onRendererSwap(e, () => L._rendererSwapped()));
129
- const w = e.weather;
130
- ctx.track(e.audio.condition('weather', v => [].concat(v).includes(w.name))); // audio rule condition { weather: 'rain' | ['rain', 'storm'] }
131
- for (const k of ['rain', 'snow', 'wind']) ctx.track(e.audio.measure(k, () => w.current[k])); // data rules: { rain: { lt: 0.2 } }, volume add: { rain: 0.22 }
134
+ ctx.track(e.audio.condition('weather', v => [].concat(v).includes(e.weather.name))); // audio rule condition { weather: 'rain' | ['rain', 'storm'] }
135
+ for (const k of ['rain', 'snow', 'wind']) ctx.track(e.audio.measure(k, () => e.weather.current[k])); // data rules: { rain: { lt: 0.2 } }, volume add: { rain: 0.22 }
132
136
  builtInSounds(e.assets, { thunder: (audio, p, out) => { const dur = p.duration ?? 3.5, delay = 0.4 + Math.random() * 1.5; // presentation: thunder delay
133
137
  audio.noiseBurst({ type: 'lowpass', freq: p.freq ?? 140, vol: p.volume ?? 0.9, dur, rate: 0.4 * p.pitch, delay, out }); return delay + dur; } },
134
138
  { bus: 'ambience' }); // sound asset 'thunder', silent until audio.sounds names it
@@ -136,6 +140,7 @@ export function weatherDrawModule(opts) {
136
140
  return L;
137
141
  },
138
142
  frame(dt, e) { L.apply(e.camera, dt); },
143
+ dispose(e) { for (const s of L.systems.values()) dropSystem(e, s); L.systems.clear(); },
139
144
  describe: () => ({ rainVisible: !!L.systems.get('rain')?.object.visible, snowVisible: !!L.systems.get('snow')?.object.visible, flash: Math.round(L.flash * 100) / 100 }),
140
145
  };
141
146
  }
@@ -6,14 +6,14 @@
6
6
  // of persist.js.
7
7
  // Data must be plain values (putting a three.js object or a function in it throws in dev); position is a plain { x, y, z }. Don't hold on to rec: loading a
8
8
  // save swaps in new objects, so keep the id and use world.get(id).
9
- import { DEV, fmt } from '../../core/validate.js';
10
- import { checkTypeRule } from '../../core/moduleTypes.js';
9
+ import { DEV, fmt } from '../../core/base/validate.js';
10
+ import { checkTypeRule } from '../../core/engine/moduleTypes.js';
11
11
  import { addRecord, setRecord, removeRecord, queryRecords } from './records.js';
12
12
  import { Views } from './views.js';
13
13
  import { Sim } from './sim.js';
14
14
  import { initState, mixInternals } from './state.js';
15
15
  import { putPos, centerOf } from './pos.js';
16
- import { codedError } from '../../core/errorHints.js';
16
+ import { codedError } from '../../core/base/errorHints.js';
17
17
 
18
18
  const STRINGS = {
19
19
  anchor: 'world.anchor must be null, an Object3D, a Vector3 / { x, z } or [x, y, z]; got {got}',
@@ -29,7 +29,7 @@ export class World {
29
29
  const { cellSize = 32, radius = 60, farEvery = 1, farMaxPerTick = 500, buildPerFrame = 8 } = opts;
30
30
  /** @internal */ this.engine = engine;
31
31
  initState(this, cellSize);
32
- /** All records: id → record (read-only; use set to change fields, move to change position) @type {Map<string, WorldRecord>} */
32
+ /** All records: id → record (read-only; use set to change fields, move to change position) @type {Map<string, WorldRecord>} @experimental */
33
33
  this.records = new Map();
34
34
  /**
35
35
  * Default distance (meters) for building models and counting as near; present / simulate can override it. Changing it at runtime affects those without
@@ -61,7 +61,10 @@ export class World {
61
61
  set anchor(a) {
62
62
  const ok = a == null || a.isObject3D || (Array.isArray(a) ? a.length === 3 && a.every(Number.isFinite) : Number.isFinite(a.x) && Number.isFinite(a.z));
63
63
  if (!ok) throw codedError('world-option', fmt(STRINGS.anchor, { got: JSON.stringify(a) }));
64
+ const boot = this._anchor, S = this.engine.session;
64
65
  this._anchor = a ?? null;
66
+ // not saved (it may be an Object3D): set during play, it ends with the playthrough and what boot left comes back. Tracked, so a failed load keeps it
67
+ if (S.captured && !this._anchorEnd) this._anchorEnd = S.track({ remove: () => { this._anchor = boot; this._anchorEnd = null; } });
65
68
  }
66
69
 
67
70
  /**
@@ -76,7 +79,7 @@ export class World {
76
79
  * Add a record and return it (a plain object). kind is required; without id one is numbered automatically (kind#1, kind#2…, saved; `#` never appears in an
77
80
  * authored id, so the two can never collide).
78
81
  * opts.initial: initial record written in content (needs an id); saves only keep its changes and removal; if the id already exists the existing one is
79
- * returned (content may load twice);
82
+ * returned (content may load twice), after taking a new position / rot from the content unless play moved it;
80
83
  * returns null if the save removed it (it is not added back). opts.save: false: not saved (temporary things).
81
84
  * @example engine.world.add({ id: 'shop_owner', kind: 'npc', position: [12, 0, -30], name: '店主', mood: 'calm' }, { initial: true })
82
85
  * @param {{ kind: string, id?: string, position?: any, [field: string]: any }} def
@@ -99,6 +102,7 @@ export class World {
99
102
  * @example const h = engine.pick(0, 0); const id = h && engine.world.idOf(h.object);
100
103
  * @param {any} obj a THREE.Object3D (a mesh of the model is fine)
101
104
  * @returns {string | null}
105
+ * @experimental
102
106
  */
103
107
  idOf(obj) {
104
108
  for (let o = obj; o; o = o.parent) { const id = this._v.byObj.get(o); if (id !== undefined) return id; }
@@ -121,7 +125,9 @@ export class World {
121
125
  set(id, patch) { checkTypeRule(this.engine, 'world.write', `set world record ${id}`); return setRecord(this, id, patch); }
122
126
  /**
123
127
  * Move a record (no event; use it in simulate for things that move every step); still saved (saves diff against content).
124
- * The model of a positionFrom 'record' (default) record follows this frame; to do something else with the position in presentation, compare in update
128
+ * The model of a positionFrom 'record' (default) record follows this frame; to do something else with the position in presentation, compare in update.
129
+ * On a live character (the player, an NPC with a model) this is its placeAt: the character owns its position, so it goes there and the record says where it stands.
130
+ * A seated rider gets out to go there (placeAt ends a ride); a write equal to where it sits only follows the seat
125
131
  * @example engine.world.move(rec.id, { x: rec.position.x + 1, z: rec.position.z })
126
132
  * @param {string} id
127
133
  * @param {any} position Vector3 / object / [x, y, z] / { x, z } (y stays unchanged if omitted)
@@ -129,10 +135,18 @@ export class World {
129
135
  */
130
136
  move(id, position) {
131
137
  DEV && this.engine.ops.guard('world.move');
132
- const rec = this._need(id, 'move');
133
- putPos(`world.move("${id}")`, position, rec.position);
138
+ const rec = this._need(id, 'move'), live = this._character(rec), to = live ? { ...live.root.position } : rec.position;
139
+ putPos(`world.move("${id}")`, position, to);
140
+ if (live) { // design.md section 9: the character is the authority. A write that agrees with it is the record following (Character._store, npcSim); any other is a placement
141
+ const p = live.root.position;
142
+ if (p.x !== to.x || p.y !== to.y || p.z !== to.z) live.placeRecord(to);
143
+ rec.position.x = p.x; rec.position.y = p.y; rec.position.z = p.z;
144
+ }
145
+ this._v.placed(rec);
134
146
  this._index(rec);
135
147
  }
148
+ /** @internal The character that owns this record's pose, or null. A far record rules its own model, except a rider's: the seat would take the write back as it comes near */
149
+ _character(rec) { const ch = this.engine.control?.characterOf(rec.id); return ch && (ch.vehicle || !this._s.recordRules(rec)) ? ch : null; }
136
150
  /**
137
151
  * Remove a record (its model is torn down too) and emit the world:remove event. Does nothing if the id does not exist. Removing an initial record is saved,
138
152
  * so it stays gone after loading
@@ -171,7 +185,7 @@ export class World {
171
185
  * radius: meters, or a function (for distances that change, like terrain view distance); defaults to world.radius. Registering the same kind again: old
172
186
  * models are torn down with the old dispose and rebuilt with the new one.
173
187
  * positionFrom: 'record' (default, the model follows the record every frame) or 'view' (the model moves itself, e.g. driven by a character mover; model
174
- * position is copied back to the record at the end of each fixed step).
188
+ * position is copied back to the record at the end of each fixed step, and a write to the record moves the model and a rigid body on it).
175
189
  * @example engine.world.present('chest', { build: rec => new THREE.Mesh(boxGeo, new THREE.MeshStandardMaterial()), dispose: (rec, obj) => engine.remove(obj), show: rec
176
190
  * => !rec.looted })
177
191
  * @param {string} kind
@@ -213,8 +227,8 @@ export class World {
213
227
  * far → near step, far runs first to pay back the owed time.
214
228
  * With only far (crops), near also advances via far; with only near, far records are not simulated and owed time is not made up.
215
229
  * Both dt are accumulated real (fixed-step) seconds (not multiplied by clock.rate). For things measured in game clock (grows over days) store engine.clock.now
216
- * and compare. channel: a time channel name (or rec => name) the kind lives on; then both dt are multiplied by that channel's speed (and the record's
217
- * engine.time.local stack), so bullet time on 'enemies' slows near and far records alike (NPCs use it with their own channel).
230
+ * and compare. channel: a time channel name (or rec => name) the kind lives on; then both dt are the channel time the record lived through (its
231
+ * engine.time.local stack too), whatever the speed when far settles, so bullet time on 'enemies' slows near and far records alike (NPCs use it with their own channel).
218
232
  * radius defaults to the present radius ('view' widened by 1.25), or world.radius without present; may also be a function.
219
233
  * fullRadius + nearEvery (tiers, for crowds): records within fullRadius m (number or function) run near every step; the rest of the near zone runs near
220
234
  * once every nearEvery seconds, dt being the seconds since its last turn (deterministic: turns go by hashed id and step count, saved).
@@ -234,11 +248,10 @@ export class World {
234
248
  * Stop running simulate() handlers on this machine until remove(): a multiplayer client lets the host simulate and only receives the records.
235
249
  * Public so net() needs no world internals.
236
250
  * @returns {{ remove(): void }}
251
+ * @experimental
237
252
  */
238
- pauseSimulation() { const s = this._s; s.fixed = () => {}; return { remove: () => { delete s.fixed; } }; }
239
- /** Number of fixed steps simulated */ get steps() { return this._s.n; }
240
-
241
-
253
+ pauseSimulation() { const s = this._s; s.fixed = () => {}; return { remove: () => { delete s.fixed; for (const e of s.ents.values()) e.ch = e.mark = undefined; } }; } // channels kept moving: no stretch of the pause is owed
254
+ /** Number of fixed steps simulated @experimental */ get steps() { return this._s.n; }
242
255
  }
243
256
 
244
257
  /**
@@ -1,4 +1,4 @@
1
- // World's contribution to thing.explain() (core/thingExplain.js): the record's fields as `state`, and the record's own collision / picking rules.
1
+ // World's contribution to engine.explain({ thing }) (core/scene/thingExplain.js): the record's fields as `state`, and the record's own collision / picking rules.
2
2
  // Template rules come from the content module's explainer (content/explain.js), which runs after this and overrides these.
3
3
 
4
4
  /** @internal Fill state and rules for a thing that has a world record */
@@ -1,13 +1,13 @@
1
1
  // world() module: installed as engine.world (world data, see World.js). Models load around engine.stream sources; records stay when models unload. Independent of game type: slow-life NPCs, shooter enemies, survival zombies and containers all use it.
2
2
  // engine.use(world()) // the openWorld() preset installs it by default
3
3
  // engine.use(world({ radius: 80 })) // distance (meters) for building models and counting as near, default 60
4
- // Save key world (runtime records whole, initial records only changes and removals, see the top of World.js); emits world:load after loading. The loading screen waits for world.ready (nearby models all built). describe() reports world.total / byKind / presented, and nearby records with a name go into nearby.
4
+ // Save key world (runtime records whole, initial records only changes and removals, see the top of persist.js); emits world:load after loading. The loading screen waits for world.ready (nearby models all built). describe() reports world.total / byKind / presented, and nearby records with a name go into nearby.
5
5
  import { recordSource } from './thingSource.js';
6
6
  import { World } from './World.js';
7
- import { WORLD_MIGRATE } from './persist.js';
7
+ import { WORLD_MIGRATE, worldChanges } from './persist.js';
8
8
  import { worldExplain } from './explain.js';
9
- import { closest, warnOnce, DEV } from '../../core/validate.js';
10
- import { readParams, keysSchema } from '../../core/params.js';
9
+ import { closest, warnOnce, DEV, fmt } from '../../core/base/validate.js';
10
+ import { readParams, keysSchema } from '../../core/base/params.js';
11
11
 
12
12
  const PLACED = '[session] {n} world record(s) were created or removed by code before the game started ({ids}): a new game should equal the content. '
13
13
  + 'Move them to content (content/props.js with an id and a template from content/templates.js), or create them during play inside an op';
@@ -15,12 +15,12 @@ const PLACED = '[session] {n} world record(s) were created or removed by code be
15
15
  /**
16
16
  * Dev check on the new-game state (saves.register checkNewGame, run once start() finished): authored things come from content, so a new game has
17
17
  * no runtime records but the player and removes nothing. Changed fields are not checked: simulation may already move authored records (an NPC
18
- * walking its schedule) while loading runs in real time. Lives here, not in core/session.js: only the world knows its own save format.
18
+ * walking its schedule) while loading runs in real time. Lives here, not in core/saves/session.js: only the world knows its own save format.
19
19
  * @param {any} d the world part of the new-game state
20
20
  */
21
21
  function codePlaced(d) {
22
22
  const ids = [...Object.entries(d?.records || {}).filter(([, r]) => r.kind !== 'player').map(([id]) => id), ...(d?.removed || [])];
23
- if (ids.length) warnOnce(PLACED.replace('{n}', String(ids.length)).replace('{ids}', ids.slice(0, 8).join(', ') + (ids.length > 8 ? ', …' : '')));
23
+ if (ids.length) warnOnce(fmt(PLACED, { n: ids.length, ids: ids.slice(0, 8).join(', ') + (ids.length > 8 ? ', …' : '') }));
24
24
  }
25
25
 
26
26
  const ORPHAN = '[world] the save has changes for {n} id(s) that the content no longer defines: {list}. They are kept in the save (restoring the entry brings them back); '
@@ -39,15 +39,20 @@ export function world(opts = {}) {
39
39
  readParams('world', WORLD_PARAMS, opts);
40
40
  let w = null;
41
41
  return {
42
- name: 'world', type: 'world', provides: ['world'], label: 'World data', params: WORLD_PARAMS, options: opts, stage: 'ground',
42
+ name: 'world', skipKind: 'approx', type: 'world', provides: ['world'], label: 'World data', params: WORLD_PARAMS, options: opts, stage: 'ground',
43
43
  install(e, ctx) { e.i18n.add({ 'zh-CN': { 'module.world': '世界数据' }, en: { 'module.world': 'world data' } });
44
44
  w = new World(e, opts);
45
+ const followed = e.stream.player.pos;
45
46
  e.stream.player.at(() => w.center); // the default stream source sits where gameplay is simulated (world.anchor, else the player)
46
- e.stream.readyCheck('world', s => s.detail !== 'full' || w.ready);
47
- e.saves.register('world', { atomic: true, version: 5, migrate: WORLD_MIGRATE, save: () => w.toJSON(), load: d => w.fromJSON(d), checkNewGame: codePlaced });
48
- e._things.addSource(recordSource(w)); // engine.thing / thing.set / the shared id space reach the records through this
49
- e.explainWith(worldExplain);
50
- e.budget.metric('worldRecords', () => w.records.size);
47
+ ctx.track({ remove: () => e.stream.player.at(followed) }); // no closure over this world stays behind
48
+ ctx.stream.addReadyCheck('world', s => s.detail !== 'full' || w.ready);
49
+ // after the modules, not in world's own step: physics writes the models at stage late, and a record must end the step on the solver's result, a save included
50
+ ctx.track(e.onFixed(() => w._v.pull(), { phase: 'late' }));
51
+ ctx.track(e.time.onMove(() => w._s.moved()));
52
+ ctx.saves.register('world', { atomic: true, version: 5, migrate: WORLD_MIGRATE, save: () => w.toJSON(), load: d => w.fromJSON(d), checkNewGame: codePlaced });
53
+ ctx.things.addSource(recordSource(w)); // engine.thing / thing.set / the shared id space reach the records through this
54
+ ctx.things.explainWith(worldExplain);
55
+ ctx.budget.metric('worldRecords', () => w.records.size);
51
56
  if (DEV) { // orphans are known once content loaded (engine:ready), after a load, and per level for `<level>/<node>` ids
52
57
  const warn = () => {
53
58
  targets();
@@ -55,19 +60,19 @@ export function world(opts = {}) {
55
60
  const ids = [...w._base.keys()];
56
61
  // a near id the save has no data for is the likely new name: suggest the exact renames.js pair
57
62
  const list = o.slice(0, 8).map(id => { const c = closest(id, ids); return c ? `${id} (did you mean ${c}? renames: { '${id}': '${c}' })` : id; });
58
- warnOnce(ORPHAN.replace('{n}', String(o.length)).replace('{list}', list.join(', ') + (o.length > 8 ? ', …' : '')));
63
+ warnOnce(fmt(ORPHAN, { n: o.length, list: list.join(', ') + (o.length > 8 ? ', …' : '') }));
59
64
  };
60
65
  const targets = () => { // a rename target nothing defines moves the player's state into a void: name it (level-node targets once that level loaded)
61
66
  const due = id => { const i = id.indexOf('/'); return i < 0 || w._levels.has(id.slice(0, i)); };
62
67
  const bad = [...w._renames].filter(([, b]) => b != null && !w._base.has(b) && due(b));
63
- if (bad.length) warnOnce(RENAME_TARGET.replace('{list}', bad.map(([a, b]) => `${b} (from ${a})`).join(', ')).replace('{near}', closest(bad[0][1], [...w._base.keys()]) ?? '-'));
68
+ if (bad.length) warnOnce(fmt(RENAME_TARGET, { list: bad.map(([a, b]) => `${b} (from ${a})`).join(', '), near: closest(bad[0][1], [...w._base.keys()]) ?? '-' }));
64
69
  };
65
70
  for (const ev of ['engine:ready', 'save:loaded', 'level:loaded']) ctx.track(e.events.on(ev, () => { if (e.ready) warn(); }));
66
71
  }
67
72
  return w;
68
73
  },
69
74
  isReady() { return w.ready; },
70
- afterLoad(e) { if (e.paused) w.refresh(); return w.whenReady; }, // a paused engine has no frames to build in: build now
75
+ afterLoad(e) { if (e.halted) w.refresh(); return w.whenReady; }, // a paused engine has no frames to build in: build now
71
76
  counts() { let views = 0; for (const id of w.records.keys()) if (w.view(id)) views++; return { records: w.records.size, views }; }, // engine.counts().world
72
77
  fixed(dt) { w.fixed(dt); },
73
78
  skip(dt, e, done) { w._s.skip(dt, done); },
@@ -76,10 +81,18 @@ export function world(opts = {}) {
76
81
  const byKind = {};
77
82
  for (const r of w.records.values()) byKind[r.kind] = (byKind[r.kind] || 0) + 1;
78
83
  // with a model, report by the model (merged with the interaction and other modules' reports on the same object into one entry); skip records of another zone (level)
79
- for (const r of w.query({ near: ctx.center, radius: ctx.radius })) if (r.name != null && w._inZone(r)) ctx.near(w.view(r.id) ?? r.position, { id: r.id, name: r.name, kind: r.kind }, true);
84
+ // a record without a name (props, template instances) is listed by its id, nearest 8 only: 'kind' shows what it is, and the list is capped so a thick prop field cannot push NPCs out of nearby
85
+ let unnamed = 0;
86
+ for (const r of w.query({ near: ctx.center, radius: ctx.radius })) { // nearest first
87
+ if (!w.inZone(r) || (r.name == null && unnamed >= 8)) continue;
88
+ if (r.name == null) unnamed++;
89
+ ctx.near(w.view(r.id) ?? r.position, { id: r.id, name: r.name ?? r.id, kind: r.kind }, true);
90
+ }
80
91
  const orphans = w.orphans();
81
- return { total: w.records.size, byKind, presented: w._v.map.size, zone: w.zone, ...(orphans.length && { orphans: orphans.slice(0, 20) }) };
92
+ return { total: w.records.size, byKind, presented: w._v.map.size, zone: w.zone, ...worldChanges(w), ...(orphans.length && { orphans: orphans.slice(0, 20) }) };
82
93
  },
83
94
  dispose() { w.dispose(); },
84
95
  };
85
96
  }
97
+
98
+ export const handRolled = 'none: far records by hand are ordinary objects in ordinary lists';