threedog 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (506) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/LICENSE +21 -0
  3. package/README.md +39 -2
  4. package/core/Animator.js +268 -0
  5. package/core/Assets.js +256 -0
  6. package/core/Audio.js +267 -0
  7. package/core/Baked.js +72 -0
  8. package/core/Batching.js +247 -0
  9. package/core/Budget.js +221 -0
  10. package/core/Clock.js +94 -0
  11. package/core/Commits.js +77 -0
  12. package/core/DebugOverrides.js +143 -0
  13. package/core/Describe.js +145 -0
  14. package/core/Engine.js +184 -0
  15. package/core/Events.js +153 -0
  16. package/core/I18n.js +94 -0
  17. package/core/Input.js +245 -0
  18. package/core/Inspect.js +77 -0
  19. package/core/InspectScene.js +191 -0
  20. package/core/Jobs.js +146 -0
  21. package/core/Loading.js +149 -0
  22. package/core/MaterialInfo.js +32 -0
  23. package/core/Ops.js +256 -0
  24. package/core/Random.js +52 -0
  25. package/core/Rays.js +160 -0
  26. package/core/SaveStore.js +85 -0
  27. package/core/Saves.js +254 -0
  28. package/core/Stream.js +279 -0
  29. package/core/Threads.js +158 -0
  30. package/core/UrlState.js +94 -0
  31. package/core/Vars.js +35 -0
  32. package/core/Views.js +49 -0
  33. package/core/actor.js +23 -0
  34. package/core/assetEntry.js +89 -0
  35. package/core/assetLoad.js +190 -0
  36. package/core/assetManifest.js +35 -0
  37. package/core/assetReport.js +83 -0
  38. package/core/audioRules.js +121 -0
  39. package/core/audioVoice.js +225 -0
  40. package/core/batchGroups.js +116 -0
  41. package/core/canvasBox.js +63 -0
  42. package/core/catalog.js +169 -0
  43. package/core/checks.js +67 -0
  44. package/core/claims.js +51 -0
  45. package/core/dayTime.js +15 -0
  46. package/core/debugView.js +76 -0
  47. package/core/describeRender.js +45 -0
  48. package/core/describeText.js +143 -0
  49. package/core/easing.js +34 -0
  50. package/core/errorCodes.js +205 -0
  51. package/core/errorHints.js +208 -0
  52. package/core/errors.js +40 -0
  53. package/core/events.generated.js +84 -0
  54. package/core/ground.js +102 -0
  55. package/core/holds.js +106 -0
  56. package/core/inputContext.js +69 -0
  57. package/core/inputDefaults.js +22 -0
  58. package/core/inputPad.js +35 -0
  59. package/core/inputPointer.js +48 -0
  60. package/core/inputTouch.js +48 -0
  61. package/core/lifecycle.js +69 -0
  62. package/core/lightWatch.js +56 -0
  63. package/core/look/coreParts.js +112 -0
  64. package/core/look/layers.js +136 -0
  65. package/core/look/part.js +173 -0
  66. package/core/look/report.js +79 -0
  67. package/core/look/write.js +86 -0
  68. package/core/loop.js +200 -0
  69. package/core/math.js +33 -0
  70. package/core/modules.js +196 -0
  71. package/core/movement.js +19 -0
  72. package/core/mulberry32.js +14 -0
  73. package/core/opsAtomic.js +31 -0
  74. package/core/opsCheck.js +97 -0
  75. package/core/opsFail.js +20 -0
  76. package/core/opsGuard.js +26 -0
  77. package/core/opsHistory.js +27 -0
  78. package/core/opsRun.js +77 -0
  79. package/core/page.js +78 -0
  80. package/core/params.js +132 -0
  81. package/core/pureWorker.js +5 -0
  82. package/core/renamed.js +21 -0
  83. package/core/saveApply.js +128 -0
  84. package/core/saveFiles.js +139 -0
  85. package/core/saveIds.js +53 -0
  86. package/core/saveVersions.js +97 -0
  87. package/core/scatter.js +92 -0
  88. package/core/sceneMethods.js +100 -0
  89. package/core/screenToGround.js +39 -0
  90. package/core/services.js +73 -0
  91. package/core/session.js +171 -0
  92. package/core/shadowTypes.js +15 -0
  93. package/core/skip.js +104 -0
  94. package/core/startup.js +135 -0
  95. package/core/streamCells.js +24 -0
  96. package/core/streamSources.js +73 -0
  97. package/core/styleParts.js +96 -0
  98. package/core/targeting.js +64 -0
  99. package/core/thingExplain.js +68 -0
  100. package/core/thingOps.js +168 -0
  101. package/core/things.js +212 -0
  102. package/core/threadPure.js +120 -0
  103. package/core/threadServe.js +25 -0
  104. package/core/tier.js +11 -0
  105. package/core/util.js +11 -0
  106. package/core/validate.js +204 -0
  107. package/docs/AI.md +123 -0
  108. package/docs/API.md +83 -0
  109. package/docs/CODEMAP.md +347 -0
  110. package/docs/COMMANDS.md +108 -0
  111. package/docs/CONVENTIONS.md +145 -0
  112. package/docs/PERF.md +217 -0
  113. package/docs/THREE.md +86 -0
  114. package/docs/api/ambience.md +15 -0
  115. package/docs/api/assets.md +62 -0
  116. package/docs/api/audio.md +53 -0
  117. package/docs/api/budget.md +40 -0
  118. package/docs/api/cameraRig.md +120 -0
  119. package/docs/api/characters.md +144 -0
  120. package/docs/api/clock.md +7 -0
  121. package/docs/api/collision.md +39 -0
  122. package/docs/api/content.md +64 -0
  123. package/docs/api/dialogue.md +39 -0
  124. package/docs/api/engine.md +199 -0
  125. package/docs/api/entities.md +61 -0
  126. package/docs/api/events.md +95 -0
  127. package/docs/api/flow.md +27 -0
  128. package/docs/api/grids.md +11 -0
  129. package/docs/api/ground.md +16 -0
  130. package/docs/api/hlod.md +34 -0
  131. package/docs/api/hud.md +31 -0
  132. package/docs/api/i18n.md +10 -0
  133. package/docs/api/input.md +24 -0
  134. package/docs/api/interactions.md +31 -0
  135. package/docs/api/inventory.md +66 -0
  136. package/docs/api/jobs.md +10 -0
  137. package/docs/api/level.md +41 -0
  138. package/docs/api/lightPool.md +56 -0
  139. package/docs/api/music.md +34 -0
  140. package/docs/api/nav.md +26 -0
  141. package/docs/api/net.md +14 -0
  142. package/docs/api/openWorld.md +24 -0
  143. package/docs/api/particles.md +41 -0
  144. package/docs/api/photo.md +15 -0
  145. package/docs/api/post.md +10 -0
  146. package/docs/api/quests.md +36 -0
  147. package/docs/api/rays.md +26 -0
  148. package/docs/api/rigid.md +84 -0
  149. package/docs/api/saves.md +32 -0
  150. package/docs/api/settings.md +36 -0
  151. package/docs/api/sky.md +58 -0
  152. package/docs/api/stream.md +31 -0
  153. package/docs/api/style.md +134 -0
  154. package/docs/api/terrain.md +34 -0
  155. package/docs/api/timeline.md +39 -0
  156. package/docs/api/tools.md +57 -0
  157. package/docs/api/triggers.md +56 -0
  158. package/docs/api/vars.md +9 -0
  159. package/docs/api/vegetation.md +52 -0
  160. package/docs/api/water.md +48 -0
  161. package/docs/api/weather.md +29 -0
  162. package/docs/api/world.md +30 -0
  163. package/docs/recipes/01-new-game.md +148 -0
  164. package/docs/recipes/02-npc.md +167 -0
  165. package/docs/recipes/03-items-pickups.md +158 -0
  166. package/docs/recipes/04-quests.md +83 -0
  167. package/docs/recipes/05-props-bake.md +159 -0
  168. package/docs/recipes/06-clock-events.md +117 -0
  169. package/docs/recipes/07-flow-scenes-pause.md +132 -0
  170. package/docs/recipes/08-weather-sky.md +74 -0
  171. package/docs/recipes/09-style-pack.md +234 -0
  172. package/docs/recipes/10-blender-level.md +67 -0
  173. package/docs/recipes/11-vehicles.md +55 -0
  174. package/docs/recipes/12-navmesh.md +79 -0
  175. package/docs/recipes/13-animation.md +149 -0
  176. package/docs/recipes/14-custom-module.md +91 -0
  177. package/docs/recipes/15-perf.md +78 -0
  178. package/docs/recipes/16-dev-bridge.md +180 -0
  179. package/docs/recipes/18-world.md +185 -0
  180. package/docs/recipes/19-shooting-picking.md +76 -0
  181. package/docs/recipes/20-content-actions-save.md +176 -0
  182. package/docs/recipes/21-camera.md +153 -0
  183. package/docs/recipes/22-shop-gold.md +107 -0
  184. package/docs/recipes/23-ops.md +175 -0
  185. package/docs/recipes/26-ui-parts.md +138 -0
  186. package/docs/recipes/27-net.md +96 -0
  187. package/docs/recipes/28-terrain.md +80 -0
  188. package/docs/recipes/29-grid.md +87 -0
  189. package/docs/recipes/30-templates.md +131 -0
  190. package/docs/recipes/31-audio.md +126 -0
  191. package/docs/recipes/32-action-game.md +33 -0
  192. package/docs/recipes/33-stream-sources.md +37 -0
  193. package/docs/recipes/34-environment-lighting.md +36 -0
  194. package/docs/recipes/35-style-from-reference.md +89 -0
  195. package/docs/recipes/36-sky-ground-plant-looks.md +116 -0
  196. package/docs/recipes/37-terrain-look-hooks.md +97 -0
  197. package/docs/recipes/38-environment-look-hooks.md +83 -0
  198. package/docs/recipes/40-scene.md +108 -0
  199. package/docs/recipes/41-thing-registry.md +93 -0
  200. package/docs/recipes/42-terrain-shape.md +64 -0
  201. package/docs/recipes/43-shader-patches-surface-looks.md +120 -0
  202. package/docs/recipes/44-water-weather-look-hooks.md +135 -0
  203. package/docs/recipes/45-cascaded-shadows.md +51 -0
  204. package/docs/recipes/46-blender-art-route.md +114 -0
  205. package/docs/recipes/47-island-snow-backdrop.md +44 -0
  206. package/docs/recipes/48-make-material.md +70 -0
  207. package/docs/recipes/49-game-module-contract.md +71 -0
  208. package/docs/recipes/50-own-renderer.md +12 -0
  209. package/docs/recipes/51-capability-catalog.md +63 -0
  210. package/docs/recipes/52-look.md +108 -0
  211. package/examples/action/DESIGN.md +3 -0
  212. package/examples/action/GAMEMAP.md +127 -0
  213. package/examples/action/content/actions.js +8 -0
  214. package/examples/action/content/audio.js +9 -0
  215. package/examples/action/content/index.js +10 -0
  216. package/examples/action/content/items.js +4 -0
  217. package/examples/action/content/places.js +4 -0
  218. package/examples/action/content/props.js +11 -0
  219. package/examples/action/content/templates.js +10 -0
  220. package/examples/action/content/views.js +6 -0
  221. package/examples/action/look.js +5 -0
  222. package/examples/action/main.js +137 -0
  223. package/examples/action/models.js +25 -0
  224. package/examples/sheepisland/GAMEMAP.md +107 -0
  225. package/examples/sheepisland/content/index.js +6 -0
  226. package/examples/sheepisland/content/props.js +19 -0
  227. package/examples/sheepisland/content/templates.js +5 -0
  228. package/examples/sheepisland/content/vegetation.js +8 -0
  229. package/examples/sheepisland/main.js +71 -0
  230. package/examples/sheepisland/params.js +25 -0
  231. package/examples/sheepisland/style/index.js +79 -0
  232. package/examples/sheepisland/style/models.js +59 -0
  233. package/examples/sheepisland/views.js +9 -0
  234. package/examples/styletest/GAMEMAP.md +135 -0
  235. package/examples/styletest/content/index.js +9 -0
  236. package/examples/styletest/content/items.js +8 -0
  237. package/examples/styletest/content/npcs.js +8 -0
  238. package/examples/styletest/content/places.js +5 -0
  239. package/examples/styletest/content/props.js +16 -0
  240. package/examples/styletest/content/templates.js +9 -0
  241. package/examples/styletest/content/vegetation.js +31 -0
  242. package/examples/styletest/look.js +11 -0
  243. package/examples/styletest/main.js +95 -0
  244. package/examples/styletest/models.js +87 -0
  245. package/examples/styletest/overrides.js +33 -0
  246. package/examples/styletest/panel.js +135 -0
  247. package/examples/styletest/params.js +32 -0
  248. package/examples/styletest/views.js +31 -0
  249. package/examples/world/DESIGN.md +5 -0
  250. package/examples/world/GAMEMAP.md +171 -0
  251. package/examples/world/content/actions.js +8 -0
  252. package/examples/world/content/audio.js +25 -0
  253. package/examples/world/content/bodies.js +12 -0
  254. package/examples/world/content/containers.js +4 -0
  255. package/examples/world/content/dialogues.js +33 -0
  256. package/examples/world/content/index.js +17 -0
  257. package/examples/world/content/items.js +10 -0
  258. package/examples/world/content/npcs.js +14 -0
  259. package/examples/world/content/pickups.js +11 -0
  260. package/examples/world/content/places.js +6 -0
  261. package/examples/world/content/props.js +12 -0
  262. package/examples/world/content/quests.js +15 -0
  263. package/examples/world/content/rules.js +23 -0
  264. package/examples/world/content/templates.js +5 -0
  265. package/examples/world/content/vegetation.js +32 -0
  266. package/examples/world/main.js +168 -0
  267. package/examples/world/models.js +28 -0
  268. package/index.d.ts +306 -0
  269. package/index.js +122 -0
  270. package/llms.txt +61 -0
  271. package/modules/ambience/Ambience.js +186 -0
  272. package/modules/camera/FirstPersonCamera.js +131 -0
  273. package/modules/camera/FixedCamera.js +162 -0
  274. package/modules/camera/FollowCamera.js +91 -0
  275. package/modules/camera/RtsCamera.js +132 -0
  276. package/modules/camera/common.js +182 -0
  277. package/modules/camera/index.js +11 -0
  278. package/modules/camera/projection.js +34 -0
  279. package/modules/characters/Character.js +235 -0
  280. package/modules/characters/NPC.js +242 -0
  281. package/modules/characters/assetModel.js +42 -0
  282. package/modules/characters/astar.js +66 -0
  283. package/modules/characters/behaviors.js +72 -0
  284. package/modules/characters/footsteps.js +13 -0
  285. package/modules/characters/index.js +215 -0
  286. package/modules/characters/moveHelpers.js +29 -0
  287. package/modules/characters/movers/common.js +62 -0
  288. package/modules/characters/movers/rapier.js +74 -0
  289. package/modules/characters/movers/simple.js +43 -0
  290. package/modules/characters/npcAvoid.js +129 -0
  291. package/modules/characters/npcSim.js +150 -0
  292. package/modules/characters/npcView.js +42 -0
  293. package/modules/characters/pathAsync.js +113 -0
  294. package/modules/characters/pathJob.js +62 -0
  295. package/modules/characters/pathWorker.js +7 -0
  296. package/modules/characters/playerStrings.js +12 -0
  297. package/modules/characters/proceduralRig.js +58 -0
  298. package/modules/characters/useModel.js +22 -0
  299. package/modules/characters/walkTo.js +58 -0
  300. package/modules/collision/Collision.js +274 -0
  301. package/modules/collision/grid.js +63 -0
  302. package/modules/content/explain.js +13 -0
  303. package/modules/content/ids.js +95 -0
  304. package/modules/content/index.js +154 -0
  305. package/modules/content/loader.js +190 -0
  306. package/modules/content/models.js +69 -0
  307. package/modules/content/packs.js +69 -0
  308. package/modules/content/props.js +89 -0
  309. package/modules/content/rules.js +134 -0
  310. package/modules/content/templates.js +189 -0
  311. package/modules/debug/DebugPanel.js +174 -0
  312. package/modules/entities/Entities.js +243 -0
  313. package/modules/entities/build.js +25 -0
  314. package/modules/entities/index.js +4 -0
  315. package/modules/flow/index.js +101 -0
  316. package/modules/gameplay/Container.js +227 -0
  317. package/modules/gameplay/Containers.js +89 -0
  318. package/modules/gameplay/Dialogue.js +219 -0
  319. package/modules/gameplay/Interactions.js +253 -0
  320. package/modules/gameplay/Inventory.js +224 -0
  321. package/modules/gameplay/Quests.js +205 -0
  322. package/modules/gameplay/boxOps.js +60 -0
  323. package/modules/gameplay/dialogueBox.js +48 -0
  324. package/modules/gameplay/interactionPrompt.js +28 -0
  325. package/modules/gameplay/inventoryOps.js +137 -0
  326. package/modules/gameplay/pickups.js +115 -0
  327. package/modules/gameplay/questLog.js +54 -0
  328. package/modules/gameplay/questSave.js +71 -0
  329. package/modules/grid/Grid.js +184 -0
  330. package/modules/grid/Layer.js +142 -0
  331. package/modules/grid/index.js +236 -0
  332. package/modules/grid/ops.js +73 -0
  333. package/modules/grid/preview.js +85 -0
  334. package/modules/grid/tiles.js +79 -0
  335. package/modules/hlod/index.js +167 -0
  336. package/modules/hud/index.js +167 -0
  337. package/modules/hud/parts.js +80 -0
  338. package/modules/level/geometry.js +46 -0
  339. package/modules/level/heightfield.js +160 -0
  340. package/modules/level/index.js +233 -0
  341. package/modules/level/nodes.js +84 -0
  342. package/modules/lights/index.js +227 -0
  343. package/modules/music/Music.js +294 -0
  344. package/modules/music/index.js +2 -0
  345. package/modules/music/rules.js +28 -0
  346. package/modules/nav/index.js +156 -0
  347. package/modules/nav/navPath.js +17 -0
  348. package/modules/net/Client.js +137 -0
  349. package/modules/net/Host.js +117 -0
  350. package/modules/net/Net.js +49 -0
  351. package/modules/net/index.js +77 -0
  352. package/modules/net/sync.js +114 -0
  353. package/modules/net/transports.js +118 -0
  354. package/modules/particles/Particles.js +179 -0
  355. package/modules/particles/effect.js +112 -0
  356. package/modules/particles/shaders.js +28 -0
  357. package/modules/photo/Photo.js +146 -0
  358. package/modules/rigid/RigidBodies.js +265 -0
  359. package/modules/rigid/Vehicles.js +97 -0
  360. package/modules/rigid/sync.js +158 -0
  361. package/modules/settings/Settings.js +297 -0
  362. package/modules/settings/apply.js +21 -0
  363. package/modules/settings/index.js +3 -0
  364. package/modules/settings/sections.js +156 -0
  365. package/modules/settings/strings.js +53 -0
  366. package/modules/settings/view.js +65 -0
  367. package/modules/sky/Sky.js +259 -0
  368. package/modules/sky/calendar.js +80 -0
  369. package/modules/sky/cascades.js +125 -0
  370. package/modules/sky/clouds.js +79 -0
  371. package/modules/sky/domeLayers.js +33 -0
  372. package/modules/sky/environment.js +141 -0
  373. package/modules/sky/fog.js +139 -0
  374. package/modules/sky/frame.js +77 -0
  375. package/modules/sky/layers.js +69 -0
  376. package/modules/sky/look.js +51 -0
  377. package/modules/sky/lookFog.js +80 -0
  378. package/modules/sky/lookShadow.js +50 -0
  379. package/modules/sky/lookSky.js +108 -0
  380. package/modules/sky/schedule.js +80 -0
  381. package/modules/sky/shader.js +96 -0
  382. package/modules/sky/shadow.js +74 -0
  383. package/modules/sky/skyModule.js +60 -0
  384. package/modules/terrain/ChunkManager.js +260 -0
  385. package/modules/terrain/chunkJob.js +19 -0
  386. package/modules/terrain/chunkLevels.js +40 -0
  387. package/modules/terrain/chunkQueries.js +42 -0
  388. package/modules/terrain/chunkWorker.js +5 -0
  389. package/modules/terrain/index.js +118 -0
  390. package/modules/terrain/lookGround.js +61 -0
  391. package/modules/terrain/mountTerrain.js +32 -0
  392. package/modules/terrain/terrainColorMap.js +41 -0
  393. package/modules/terrain/terrainDefaults.js +39 -0
  394. package/modules/terrain/terrainEdit.js +139 -0
  395. package/modules/terrain/terrainGen.js +155 -0
  396. package/modules/terrain/terrainIsland.js +131 -0
  397. package/modules/terrain/terrainMesh.js +92 -0
  398. package/modules/terrain/terrainShape.js +108 -0
  399. package/modules/terrain/terrainShapeMain.js +41 -0
  400. package/modules/terrain/terrainTexture.js +44 -0
  401. package/modules/timeline/Timeline.js +253 -0
  402. package/modules/timeline/Tween.js +114 -0
  403. package/modules/timeline/letterbox.js +24 -0
  404. package/modules/timeline/shots.js +90 -0
  405. package/modules/triggers/index.js +268 -0
  406. package/modules/vegetation/Vegetation.js +256 -0
  407. package/modules/vegetation/groundChunks.js +177 -0
  408. package/modules/vegetation/index.js +43 -0
  409. package/modules/vegetation/lookWind.js +37 -0
  410. package/modules/vegetation/modelGeometry.js +21 -0
  411. package/modules/water/Water.js +160 -0
  412. package/modules/water/look.js +80 -0
  413. package/modules/water/surface.js +88 -0
  414. package/modules/weather/Weather.js +242 -0
  415. package/modules/weather/look.js +75 -0
  416. package/modules/weather/particles.js +92 -0
  417. package/modules/weather/shaders.js +49 -0
  418. package/modules/weather/strings.js +15 -0
  419. package/modules/world/World.js +231 -0
  420. package/modules/world/cells.js +42 -0
  421. package/modules/world/explain.js +11 -0
  422. package/modules/world/index.js +71 -0
  423. package/modules/world/persist.js +107 -0
  424. package/modules/world/pos.js +20 -0
  425. package/modules/world/records.js +89 -0
  426. package/modules/world/sim.js +175 -0
  427. package/modules/world/simFar.js +82 -0
  428. package/modules/world/state.js +115 -0
  429. package/modules/world/thingSource.js +44 -0
  430. package/modules/world/views.js +182 -0
  431. package/package.json +66 -4
  432. package/presets.js +96 -0
  433. package/render/PostFX.js +240 -0
  434. package/render/detail.js +105 -0
  435. package/render/effects.js +144 -0
  436. package/render/engineUniforms.js +23 -0
  437. package/render/fuse.js +84 -0
  438. package/render/lighting.js +100 -0
  439. package/render/lights.js +18 -0
  440. package/render/lookSurface.js +161 -0
  441. package/render/materials.js +220 -0
  442. package/render/patches.js +252 -0
  443. package/render/postLook.js +86 -0
  444. package/render/surface.js +69 -0
  445. package/render/uniformDecl.js +29 -0
  446. package/types/common.d.ts +34 -0
  447. package/types/core.d.ts +1965 -0
  448. package/types/gameplay.d.ts +1822 -0
  449. package/types/generated/core/Audio.d.ts +200 -0
  450. package/types/generated/core/Batching.d.ts +47 -0
  451. package/types/generated/core/Budget.d.ts +90 -0
  452. package/types/generated/core/Commits.d.ts +31 -0
  453. package/types/generated/core/DebugOverrides.d.ts +52 -0
  454. package/types/generated/core/Events.d.ts +89 -0
  455. package/types/generated/core/I18n.d.ts +30 -0
  456. package/types/generated/core/Input.d.ts +118 -0
  457. package/types/generated/core/Jobs.d.ts +41 -0
  458. package/types/generated/core/Ops.d.ts +203 -0
  459. package/types/generated/core/Random.d.ts +49 -0
  460. package/types/generated/core/Rays.d.ts +49 -0
  461. package/types/generated/core/Saves.d.ts +162 -0
  462. package/types/generated/core/Stream.d.ts +93 -0
  463. package/types/generated/core/Threads.d.ts +82 -0
  464. package/types/generated/core/Views.d.ts +33 -0
  465. package/types/generated/core/audioVoice.d.ts +47 -0
  466. package/types/generated/core/page.d.ts +18 -0
  467. package/types/generated/core/session.d.ts +48 -0
  468. package/types/generated/modules/ambience/Ambience.d.ts +48 -0
  469. package/types/generated/modules/debug/DebugPanel.d.ts +24 -0
  470. package/types/generated/modules/flow/index.d.ts +10 -0
  471. package/types/generated/modules/grid/Grid.d.ts +151 -0
  472. package/types/generated/modules/grid/Layer.d.ts +65 -0
  473. package/types/generated/modules/grid/index.d.ts +86 -0
  474. package/types/generated/modules/hlod/index.d.ts +11 -0
  475. package/types/generated/modules/hud/index.d.ts +10 -0
  476. package/types/generated/modules/lights/index.d.ts +13 -0
  477. package/types/generated/modules/music/Music.d.ts +111 -0
  478. package/types/generated/modules/net/Net.d.ts +34 -0
  479. package/types/generated/modules/net/index.d.ts +53 -0
  480. package/types/generated/modules/net/transports.d.ts +58 -0
  481. package/types/generated/modules/particles/Particles.d.ts +69 -0
  482. package/types/generated/modules/sky/Sky.d.ts +145 -0
  483. package/types/generated/modules/sky/skyModule.d.ts +10 -0
  484. package/types/generated/modules/timeline/Timeline.d.ts +51 -0
  485. package/types/generated/modules/water/Water.d.ts +29 -0
  486. package/types/generated/modules/weather/Weather.d.ts +62 -0
  487. package/types/generated/modules/world/World.d.ts +242 -0
  488. package/types/generated/modules/world/index.d.ts +15 -0
  489. package/types/generated/render/PostFX.d.ts +125 -0
  490. package/types/generated/render/materials.d.ts +100 -0
  491. package/types/generated/render/patches.d.ts +41 -0
  492. package/types/generated/ui/Focus.d.ts +11 -0
  493. package/types/generated/ui/LoadingScreen.d.ts +2 -0
  494. package/types/generated/ui/UI.d.ts +57 -0
  495. package/types/nav.d.ts +52 -0
  496. package/types/physics.d.ts +592 -0
  497. package/types/style.d.ts +638 -0
  498. package/types/worker.d.ts +11 -0
  499. package/types/world.d.ts +772 -0
  500. package/ui/Focus.js +51 -0
  501. package/ui/LoadingScreen.js +42 -0
  502. package/ui/Parts.js +199 -0
  503. package/ui/UI.js +167 -0
  504. package/ui/defaults.js +85 -0
  505. package/ui/theme.js +124 -0
  506. package/ui/touchPart.js +49 -0
@@ -0,0 +1,225 @@
1
+ // One playing sound (a "voice") of engine.audio.sfx / play: source -> voice gain -> [panner] -> bus.
2
+ // Split out of Audio.js so the bus / config side and the per-sound side each stay small enough to read in one go.
3
+ // Randomness here (variant pick, jitter) only changes what is heard, never gameplay, so it uses Math.random and carries // presentation.
4
+ import * as THREE from 'three';
5
+ import { xzOf } from './math.js';
6
+ import { missingText, warnOnce, checkOptions } from './validate.js';
7
+ import { codedError } from './errorHints.js';
8
+
9
+ const SFX_KEYS = ['volume', 'pitch', 'at', 'bus', 'loop', 'params', 'fadeIn'];
10
+ const jit = (v, j) => v * (1 + (Math.random() * 2 - 1) * (j || 0)); // presentation
11
+ const SOUND_KEYS = ['src', 'synth', 'params', 'bus', 'volume', 'pitch', 'jitter', 'cooldown', 'voices', 'loop', 'distance'];
12
+
13
+ const _v = new THREE.Vector3(), _d = new THREE.Vector3(), _u = new THREE.Vector3(), _q = new THREE.Quaternion();
14
+
15
+ /** Normalize a sounds entry: string / string[] / { src, synth, ... } -> one shape, so playback code has a single path */
16
+ function soundDef(name, v) {
17
+ if (v == null) return null;
18
+ if (v === 'synth') return { synth: name };
19
+ if (typeof v === 'string' || Array.isArray(v)) return { src: v };
20
+ return v.src == null && v.synth == null ? { ...v, synth: name } : v;
21
+ }
22
+
23
+ /** The sounds entry for a name, or a game-registered synth of that name; null = silent (a built-in synth the game did not ask for) */
24
+ function resolveDef(audio, name) {
25
+ const def = soundDef(name, audio.config.sounds[name]), synth = audio.synths.get(def?.synth ?? name);
26
+ if (def) {
27
+ checkOptions(`audio.sounds.${name}`, def, SOUND_KEYS);
28
+ if (def.src == null && !synth) { warnOnce(missingText('synth', def.synth, [...audio.synths.keys()])); return null; }
29
+ return def;
30
+ }
31
+ if (synth && !synth.builtIn) return { synth: name };
32
+ if (!synth) warnOnce(`audio.sfx('${name}'): no sound named ${name}. Add it to a content pack's audio.sounds (${name}: an asset pack sound name, or 'synth') `
33
+ + `or to createEngine({ audio: { sounds: { ${name}: '/sfx/${name}.ogg' } } })`);
34
+ return null;
35
+ }
36
+
37
+ /** Pick a variant at random, never the same one twice in a row (a repeated footstep or gunshot sounds mechanical) */
38
+ function pickVariant(list, last) {
39
+ if (!Array.isArray(list)) return [list, 0];
40
+ if (list.length < 2) return [list[0], 0];
41
+ let i = Math.floor(Math.random() * (list.length - 1)); // presentation
42
+ if (i >= last) i++;
43
+ return [list[i], i];
44
+ }
45
+
46
+ /** Where a voice sits: a world position ({ x, y, z } / [x, y, z] / Vector3) or an Object3D it follows every frame */
47
+ function readPosition(at, out = _v) {
48
+ if (at.isObject3D) return at.getWorldPosition(out);
49
+ if (Array.isArray(at)) return out.set(at[0], at[1] ?? 0, at[2] ?? 0);
50
+ if (at.y === undefined) { const [x, z] = xzOf(at); return out.set(x, 0, z); }
51
+ return out.set(at.x, at.y, at.z);
52
+ }
53
+ function setParam(p, v, t) { p.setValueAtTime(v, t); }
54
+
55
+ /** Point the Web Audio listener where the camera is (only called while positional voices exist: zero cost otherwise) */
56
+ export function placeListener(ctx, camera) {
57
+ const L = ctx.listener, t = ctx.currentTime;
58
+ camera.getWorldPosition(_v); camera.getWorldDirection(_d); _u.set(0, 1, 0).applyQuaternion(camera.getWorldQuaternion(_q)); // world up, like the world forward above (a camera inside a rotated rig)
59
+ if (L.positionX) {
60
+ setParam(L.positionX, _v.x, t); setParam(L.positionY, _v.y, t); setParam(L.positionZ, _v.z, t);
61
+ setParam(L.forwardX, _d.x, t); setParam(L.forwardY, _d.y, t); setParam(L.forwardZ, _d.z, t);
62
+ setParam(L.upX, _u.x, t); setParam(L.upY, _u.y, t); setParam(L.upZ, _u.z, t);
63
+ } else { L.setPosition(_v.x, _v.y, _v.z); L.setOrientation(_d.x, _d.y, _d.z, _u.x, _u.y, _u.z); }
64
+ }
65
+
66
+ /** A playing sound. engine.audio.sfx / play return one; the game keeps it to stop, fade or move the sound */
67
+ export class SoundHandle {
68
+ /** @internal */
69
+ constructor(audio, name, out, at, distance = {}) {
70
+ const ctx = audio.ctx;
71
+ /** @internal */ this.audio = audio;
72
+ /** Sound name (sfx) or file path (play) */
73
+ this.name = name;
74
+ /** The voice's GainNode (volume of this one sound) @type {any} */
75
+ this.gain = ctx.createGain();
76
+ /** The PannerNode of a positional sound, else null @type {any} */
77
+ this.panner = null;
78
+ /** The AudioBufferSourceNode once a file started (null for synths and while loading) @type {any} */
79
+ this.source = null;
80
+ /** @internal */ this.endsAt = Infinity;
81
+ /** @internal */ this.loop = null; // a synth loop's { stop(t) }
82
+ /** @internal */ this.follow = null;
83
+ /** @internal */ this.startedAt = ctx.currentTime;
84
+ if (at) {
85
+ const p = this.panner = ctx.createPanner();
86
+ p.panningModel = 'equalpower'; p.distanceModel = 'inverse';
87
+ p.refDistance = distance.ref ?? 2; p.maxDistance = distance.max ?? 60; p.rolloffFactor = distance.rolloff ?? 1;
88
+ this.gain.connect(p).connect(out);
89
+ this.setPosition(at);
90
+ audio._spatial.add(this);
91
+ } else this.gain.connect(out);
92
+ }
93
+ /** Still sounding (not stopped and not finished)? @returns {boolean} */
94
+ get playing() { return !this._stopped && this.audio.ctx != null && this.audio.ctx.currentTime < this.endsAt; }
95
+ /**
96
+ * Move a positional sound: a position, or an Object3D to follow every frame (no effect on a non-positional sound)
97
+ * @param {any} at
98
+ * @returns {this}
99
+ */
100
+ setPosition(at) {
101
+ if (!this.panner) return this;
102
+ this.follow = at?.isObject3D ? at : null;
103
+ const p = readPosition(at), t = this.audio.ctx.currentTime, n = this.panner;
104
+ if (n.positionX) { setParam(n.positionX, p.x, t); setParam(n.positionY, p.y, t); setParam(n.positionZ, p.z, t); } else n.setPosition(p.x, p.y, p.z);
105
+ return this;
106
+ }
107
+ /**
108
+ * Fade this sound's volume to `to` (0-1) over `seconds`; it keeps playing (use stop to end it)
109
+ * @param {number} to
110
+ * @param {number} [seconds]
111
+ * @returns {this}
112
+ * @example h.fade(0.2, 1.5);
113
+ */
114
+ fade(to, seconds = 0.5) {
115
+ const ctx = this.audio.ctx; if (!ctx || this._stopped) return this;
116
+ const g = this.gain.gain, t = ctx.currentTime;
117
+ g.cancelScheduledValues(t); g.setValueAtTime(g.value, t); g.linearRampToValueAtTime(to, t + Math.max(0.01, seconds));
118
+ return this;
119
+ }
120
+ /**
121
+ * Stop, fading out over `fade` seconds (0 = at once)
122
+ * @param {number} [fade]
123
+ * @returns {void}
124
+ * @example const h = engine.audio.sfx('engine-hum', { loop: true }); h.stop(1);
125
+ */
126
+ stop(fade = 0.05) {
127
+ const ctx = this.audio.ctx; if (!ctx || this._stopped) return;
128
+ this.fade(0, fade); this._stopped = true;
129
+ const end = ctx.currentTime + Math.max(0.01, fade) + 0.05;
130
+ try { this.source?.stop(end); } catch { /* already ended: nothing to stop */ }
131
+ this.loop?.stop?.(end);
132
+ this.endsAt = Math.min(this.endsAt, end);
133
+ this.audio._spatial.delete(this);
134
+ }
135
+ }
136
+
137
+ /** Start a synth or file for a voice. Synths get (audio, params, out) and return their length in seconds, or { stop(t) } when looping */
138
+ function startSource(audio, voice, def, { pitch, loop, url, params }) {
139
+ const ctx = audio.ctx;
140
+ if (url) {
141
+ audio.load(url).then(buf => { // url: a file, or a sound name from an asset pack (audio.load resolves it)
142
+ if (!buf) { voice.endsAt = 0; voice.failed = true; return; } // an asset that failed and fell back to silence (engine.loading has the error)
143
+ if (voice._stopped || !audio.ctx) return;
144
+ const s = ctx.createBufferSource(); s.buffer = buf; s.loop = loop; s.playbackRate.value = pitch;
145
+ s.connect(voice.gain); s.start(); voice.source = s;
146
+ voice.endsAt = loop ? Infinity : ctx.currentTime + buf.duration / pitch;
147
+ }).catch(err => { voice.endsAt = 0; voice.failed = true; audio._warn(err.message); }); // failed: rule loops (ambience) read it and stop retrying
148
+ return;
149
+ }
150
+ const synth = audio.synths.get(def.synth);
151
+ const r = synth.fn(audio, { ...synth.params, ...def.params, ...params, pitch, loop }, voice.gain);
152
+ if (r && typeof r === 'object') voice.loop = r;
153
+ else voice.endsAt = typeof r === 'number' ? ctx.currentTime + r : loop ? Infinity : ctx.currentTime + 1; // a one-shot synth asked to loop still ends
154
+ }
155
+
156
+ /** Synth building block behind audio.noiseBurst: a burst of filtered noise */
157
+ export function synthNoise(audio, opts) {
158
+ const { dur = 0.1, type = 'bandpass', freq = 1000, vol = 0.2, bus = 'sfx', out, rate = 1, delay = 0 } = opts;
159
+ if (!audio.running) return;
160
+ const ctx = audio.ctx, t0 = ctx.currentTime + delay, src = ctx.createBufferSource(), f = ctx.createBiquadFilter(), g = ctx.createGain();
161
+ src.buffer = audio.noise; src.playbackRate.value = rate; f.type = type; f.frequency.value = freq;
162
+ g.gain.setValueAtTime(vol, t0); g.gain.exponentialRampToValueAtTime(0.0005, t0 + dur);
163
+ src.connect(f).connect(g).connect(out ?? audio._bus(bus)); src.start(t0, Math.random()); src.stop(t0 + dur + 0.05); // presentation
164
+ }
165
+ /** Synth building block behind audio.tone: a short enveloped tone */
166
+ export function synthTone(audio, opts) {
167
+ const { freq = 880, to = null, dur = 0.1, vol = 0.05, type = 'sine', bus = 'sfx', out, delay = 0, pan = 0 } = opts;
168
+ if (!audio.running) return;
169
+ const ctx = audio.ctx, t0 = ctx.currentTime + delay, o = ctx.createOscillator(), g = ctx.createGain(), p = ctx.createStereoPanner();
170
+ o.type = /** @type {any} */ (type); o.frequency.setValueAtTime(freq, t0); if (to) o.frequency.exponentialRampToValueAtTime(to, t0 + dur * 0.9);
171
+ g.gain.setValueAtTime(0, t0); g.gain.linearRampToValueAtTime(vol, t0 + 0.01); g.gain.exponentialRampToValueAtTime(0.0005, t0 + dur);
172
+ p.pan.value = pan;
173
+ o.connect(g).connect(p).connect(out ?? audio._bus(bus)); o.start(t0); o.stop(t0 + dur + 0.02);
174
+ }
175
+
176
+ /** audio.load body: decode a file once (cached), or load a sound name from an asset pack through engine.assets */
177
+ export async function loadSound(audio, url) {
178
+ const asset = audio.engine.assets.entries.get(url);
179
+ // a named sound asset goes through assets (an engine.loading task, fallback to silence); its url is the file, so this never loops back
180
+ if (asset?.named && asset.type === 'sound' && asset.url !== url) return audio.engine.assets._fetch(asset);
181
+ audio._init();
182
+ if (!audio.ctx) throw codedError('audio-unsupported', 'Audio is not supported by this browser; check typeof AudioContext before calling');
183
+ if (!audio.buffers.has(url)) {
184
+ const p = fetch(url).then(r => { if (!r.ok) throw codedError('asset-load', `Audio file failed to load: ${url} (${r.status} ${r.statusText})`); return r.arrayBuffer(); })
185
+ .then(b => audio.ctx.decodeAudioData(b));
186
+ p.catch(() => { if (audio.buffers.get(url) === p) audio.buffers.delete(url); }); // a failed download is not cached: the next play tries again
187
+ audio.buffers.set(url, p);
188
+ }
189
+ return audio.buffers.get(url);
190
+ }
191
+ /** audio.play body: a file by path or asset name, no sounds entry needed */
192
+ export async function playFile(audio, url, opts) {
193
+ checkOptions('audio.play()', opts, ['bus', 'volume', 'loop', 'fadeIn', 'pitch', 'at']);
194
+ const { bus = 'sfx', volume = 1, loop = false, fadeIn = 0, pitch = 1, at } = opts;
195
+ // create the (suspended) context now: a named asset loads through engine.assets, which never creates it, and before the first click
196
+ // there would be no context to build the voice on. The sound starts when the first click / key resumes the context
197
+ audio._init();
198
+ if (!audio.ctx) return null; // no Web Audio in this browser: nothing to play (audio.load still throws with the fix)
199
+ const buf = await audio.load(url), ctx = audio.ctx;
200
+ if (!ctx) return null; // the engine was disposed while the file loaded
201
+ const v = new SoundHandle(audio, url, audio._bus(bus), at);
202
+ const src = ctx.createBufferSource(); src.buffer = buf ?? null; src.loop = loop; src.playbackRate.value = pitch;
203
+ v.gain.gain.value = fadeIn ? 0 : volume; if (fadeIn) v.fade(volume, fadeIn);
204
+ src.connect(v.gain); src.start(); v.source = src; v.endsAt = loop ? Infinity : ctx.currentTime + (buf?.duration ?? 0) / pitch;
205
+ return v;
206
+ }
207
+ /** audio.sfx body: cooldown, voice limit, variant pick, jitter, then start the source */
208
+ export function playSound(audio, name, opts) {
209
+ checkOptions('audio.sfx()', opts, SFX_KEYS);
210
+ const def = resolveDef(audio, name);
211
+ if (!def || !audio.running) return null;
212
+ const now = audio.ctx.currentTime, last = audio._last.get(name);
213
+ if (def.cooldown && last && now - last.at < def.cooldown) return null;
214
+ const list = (audio._voices.get(name) || []).filter(v => v.playing);
215
+ if (def.voices && list.length >= def.voices) list.shift().stop(0.03);
216
+ const [url, variant] = def.src != null ? pickVariant(def.src, last?.variant ?? -1) : [null, 0];
217
+ audio._last.set(name, { at: now, variant });
218
+ const bus = audio._bus(opts.bus ?? def.bus ?? audio.synths.get(def.synth)?.bus ?? 'sfx');
219
+ const v = new SoundHandle(audio, name, bus, opts.at, def.distance);
220
+ const vol = jit((def.volume ?? 1) * (opts.volume ?? 1), def.jitter?.volume), pitch = jit((def.pitch ?? 1) * (opts.pitch ?? 1), def.jitter?.pitch);
221
+ v.gain.gain.value = opts.fadeIn ? 0 : vol; if (opts.fadeIn) v.fade(vol, opts.fadeIn);
222
+ startSource(audio, v, def, { pitch, loop: opts.loop ?? def.loop ?? false, url, params: opts.params });
223
+ list.push(v); audio._voices.set(name, list);
224
+ return v;
225
+ }
@@ -0,0 +1,116 @@
1
+ // InstancedMesh side of engine.batching (core/Batching.js): build / join / leave / dissolve / grow a batch, instance colors, bounds,
2
+ // and the transform snapshots the per-frame check compares. B is the Batching instance; g a group (one cell + geometry + material + shadow flags);
3
+ // e an entry (one mesh of one placed object). Hidden instances are swap-removed, not zero-scaled (vegetation's way), so batch bounds stay tight.
4
+ import * as THREE from 'three';
5
+ import { copyPatches } from '../render/patches.js';
6
+
7
+ const noRaycast = () => {};
8
+ /** Layer a batched original is moved to: the camera does not draw it (nor its shadow), engine.rays still tests it */
9
+ export const BATCH_LAYER = 31;
10
+ const WHITE = new THREE.Color(1, 1, 1);
11
+ const _m = new THREE.Matrix4(), _c = new THREE.Color();
12
+ const hold = (B, x, d) => { const n = (B.held.get(x) ?? 0) + d; if (n > 0) B.held.set(x, n); else B.held.delete(x); };
13
+
14
+ function makeMesh(B, g, capacity) {
15
+ const im = new THREE.InstancedMesh(g.geometry, g.material, capacity);
16
+ im.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
17
+ im.castShadow = g.cast; im.receiveShadow = g.receive;
18
+ im.matrixAutoUpdate = false; im.raycast = noRaycast; // rays hit the originals (on BATCH_LAYER), never the batch
19
+ im.userData = { budgetTag: 'batch', cell: g.cell };
20
+ g.mesh = im; B.byMesh.set(im, g); B.root.add(im);
21
+ return im;
22
+ }
23
+
24
+ /** Turn a group that reached minCount into one InstancedMesh */
25
+ export function build(B, g) {
26
+ const im = makeMesh(B, g, Math.max(16, g.members.size * 2));
27
+ im.count = 0;
28
+ im.name = 'batch:' + (g.geometry.name || [...g.members][0].mesh.name || g.geometry.id);
29
+ hold(B, g.geometry, 1); hold(B, g.material, 1);
30
+ for (const e of g.members) join(B, e);
31
+ }
32
+ /** Put one entry into its group's InstancedMesh and hide its own mesh */
33
+ export function join(B, e) {
34
+ const g = e.group, m = e.mesh;
35
+ let im = g.mesh;
36
+ if (g.items.length >= im.instanceMatrix.count) im = grow(B, g);
37
+ e.slot = g.items.length; g.items.push(e);
38
+ im.count = g.items.length;
39
+ if (B.orig.has(m)) { m.material.dispose(); m.material = B.orig.get(m); B.orig.delete(m); } // a local tint clone: the instance color takes over
40
+ m.updateWorldMatrix(true, false);
41
+ im.setMatrixAt(e.slot, m.matrixWorld); im.instanceMatrix.needsUpdate = true;
42
+ if (g.colored || B.tints.has(m)) color(B, e);
43
+ m.layers.set(BATCH_LAYER); m.userData.batched = true; // not visible = false: visibility stays the game's
44
+ g.dirty = true; B.live.add(e.info);
45
+ }
46
+ /** Swap-remove an entry from its InstancedMesh and show its mesh again */
47
+ export function leave(B, g, e) {
48
+ const im = g.mesh, last = g.items.pop();
49
+ if (last !== e) {
50
+ g.items[e.slot] = last; last.slot = e.slot;
51
+ im.getMatrixAt(im.count - 1, _m); im.setMatrixAt(e.slot, _m);
52
+ if (im.instanceColor) { im.getColorAt(im.count - 1, _c); im.setColorAt(e.slot, _c); im.instanceColor.needsUpdate = true; }
53
+ }
54
+ im.count = g.items.length; im.instanceMatrix.needsUpdate = true; g.dirty = true;
55
+ e.slot = -1;
56
+ const m = e.mesh; m.layers.set(0); delete m.userData.batched;
57
+ localTint(B, m);
58
+ if (!e.info.entries.some(x => x.slot >= 0)) B.live.delete(e.info);
59
+ }
60
+ /** Back to plain meshes (the group dropped under half of minCount, or batching was switched off) */
61
+ export function dissolve(B, g) {
62
+ for (const e of [...g.items].reverse()) leave(B, g, e);
63
+ g.mesh.removeFromParent(); g.mesh.dispose(); g.mesh = null; g.colored = false;
64
+ hold(B, g.geometry, -1); hold(B, g.material, -1);
65
+ }
66
+ /** Double the capacity (InstancedMesh buffers are fixed size) */
67
+ function grow(B, g) {
68
+ const old = g.mesh, n = old.instanceMatrix.count * 2;
69
+ old.removeFromParent(); old.dispose();
70
+ const im = makeMesh(B, g, n);
71
+ im.instanceMatrix.array.set(old.instanceMatrix.array);
72
+ if (old.instanceColor) { im.instanceColor = new THREE.InstancedBufferAttribute(new Float32Array(n * 3).fill(1), 3); im.instanceColor.array.set(old.instanceColor.array); }
73
+ im.name = old.name; im.count = old.count;
74
+ return im;
75
+ }
76
+ /** Write an entry's tint (white when none) into the batch's instance colors */
77
+ export function color(B, e) {
78
+ const g = e.group, im = g.mesh;
79
+ if (!im.instanceColor) { im.instanceColor = new THREE.InstancedBufferAttribute(new Float32Array(im.instanceMatrix.count * 3).fill(1), 3); g.colored = true; }
80
+ im.setColorAt(e.slot, B.tints.get(e.mesh) ?? WHITE); im.instanceColor.needsUpdate = true;
81
+ }
82
+ /** An unbatched mesh shows its tint through a cloned material (patches carried over); the original is kept for grouping and restored on clear */
83
+ export function localTint(B, m) {
84
+ const t = B.tints.get(m), base = B.orig.get(m) ?? m.material;
85
+ if (!base || Array.isArray(base) || !base.color) return;
86
+ if (t) {
87
+ if (!B.orig.has(m)) { B.orig.set(m, base); m.material = copyPatches(base, base.clone()); }
88
+ m.material.color.copy(base.color).multiply(t);
89
+ } else if (B.orig.has(m)) { m.material.dispose(); m.material = base; B.orig.delete(m); }
90
+ }
91
+ /** Bounds follow the instances (frustum culling) */
92
+ export function bounds(g) { const im = g.mesh; if (!im) return; im.computeBoundingSphere(); im.computeBoundingBox(); }
93
+
94
+ /** Transform + visibility snapshot of a root (TRS when three composes the matrix, the matrix itself when the game does) */
95
+ export function snap(o, s) {
96
+ if (o.matrixAutoUpdate) {
97
+ const p = o.position, q = o.quaternion, k = o.scale;
98
+ s[0] = p.x; s[1] = p.y; s[2] = p.z; s[3] = q.x; s[4] = q.y; s[5] = q.z; s[6] = q.w; s[7] = k.x; s[8] = k.y; s[9] = k.z; s.length = 10;
99
+ } else { for (let i = 0; i < 16; i++) s[i] = o.matrix.elements[i]; s.length = 16; }
100
+ s.push(o.visible ? 1 : 0);
101
+ }
102
+ /** Does the root still match its snapshot */
103
+ export function same(o, s) {
104
+ if (s[s.length - 1] !== (o.visible ? 1 : 0)) return false;
105
+ if (o.matrixAutoUpdate) {
106
+ const p = o.position, q = o.quaternion, k = o.scale;
107
+ return s.length === 11 && s[0] === p.x && s[1] === p.y && s[2] === p.z && s[3] === q.x && s[4] === q.y && s[5] === q.z && s[6] === q.w
108
+ && s[7] === k.x && s[8] === k.y && s[9] === k.z;
109
+ }
110
+ if (s.length !== 17) return false;
111
+ for (let i = 0; i < 16; i++) if (s[i] !== o.matrix.elements[i]) return false;
112
+ return true;
113
+ }
114
+ /** Instance matrices are float32: compare against the float32 rounding of matrixWorld */
115
+ export function stored(a, slot, mw) { const el = mw.elements, o = slot * 16; for (let i = 0; i < 16; i++) if (a[o + i] !== Math.fround(el[i])) return false; return true; }
116
+ export function under(m, root) { for (let p = m; p; p = p.parent) if (p === root) return true; return false; }
@@ -0,0 +1,63 @@
1
+ // The canvas's CSS box and the UI root laid over it (split out of Engine.js: all about "how big is the canvas on the page").
2
+ import * as THREE from 'three';
3
+ import { warnOnce } from './validate.js';
4
+
5
+ const _size = new THREE.Vector2();
6
+ const NO_CSS_SIZE = 'createEngine(): the canvas has no CSS size of its own (it would take its size from its pixel buffer), so the engine sizes it to the window. '
7
+ + 'To embed it in a page section, split layout or editor panel, give it a CSS size, e.g. canvas { width: 100%; height: 100%; display: block } inside a sized parent';
8
+ /**
9
+ * The canvas's CSS box in CSS pixels (what the page layout gave it). The drawing buffer is this times the pixel ratio (setSize(w, h, false) leaves the CSS
10
+ * alone).
11
+ * Two cases fall back to the window: a canvas outside the page (headless tests often make one with createElement) has no box, so the aspect
12
+ * is never 0 / 0; and a canvas without a CSS size (e.auto, see sizeMode) takes its box from its own buffer, which would grow by the pixel
13
+ * ratio on every resize, so the engine sets its CSS size to the window instead (what such a page got before).
14
+ */
15
+ export function canvasBox(e) {
16
+ const c = e.renderer.domElement;
17
+ if (c.isConnected && e._autoSize === undefined) sizeMode(e);
18
+ const w = c.clientWidth, h = c.clientHeight;
19
+ return !e._autoSize && w > 0 && h > 0 ? { w, h } : { w: innerWidth || 1, h: innerHeight || 1 };
20
+ }
21
+ /** Once, when the canvas is first in the page: does its CSS box follow its width / height attributes on both axes (no CSS size at all)? Then e._autoSize = true and the engine sizes it.
22
+ * The probe doubles both attributes (same aspect): a box that follows them on both axes doubles, which is the case that would grow by the pixel ratio.
23
+ * One CSS axis plus an auto one (width: 100%; height: auto, or aspect-ratio) only takes the attributes' aspect, which the engine keeps, so its box stays and is used */
24
+ function sizeMode(e) {
25
+ const c = e.renderer.domElement, w0 = c.width, h0 = c.height, cw = c.clientWidth, ch = c.clientHeight;
26
+ c.width = Math.max(1, w0) * 2; c.height = Math.max(1, h0) * 2;
27
+ e._autoSize = c.clientWidth !== cw && c.clientHeight !== ch;
28
+ c.width = w0; c.height = h0;
29
+ if (e._autoSize) warnOnce(NO_CSS_SIZE);
30
+ // canvas put in the page after createEngine
31
+ if (e.uiRoot?.parentElement === document.body && c.parentElement && c.nextElementSibling !== e.uiRoot) c.after(e.uiRoot);
32
+ }
33
+ /**
34
+ * Lay the UI root over the canvas box. Its children are position: fixed, and contain: layout makes the root their containing block,
35
+ * so inset: 0 means "the canvas", not "the window". A fixed canvas gets a fixed root at its viewport rect; any other canvas an absolute root
36
+ * at its offset position in the same offset parent, so the two scroll together.
37
+ */
38
+ export function placeUI(e) {
39
+ const c = e.renderer.domElement, s = e.uiRoot.style;
40
+ if (!c.isConnected || !e.uiRoot.isConnected) return;
41
+ const fixed = getComputedStyle(c).position === 'fixed', b = fixed ? c.getBoundingClientRect() : null;
42
+ // set only once the root is placed: a root with contain but no box (canvas outside the page) would shrink every fixed child to 0 x 0.
43
+ // pointer-events: the root itself lets clicks through to the canvas; its children take them again (theme.js :where rule)
44
+ s.contain = 'layout'; s.pointerEvents = 'none';
45
+ s.position = fixed ? 'fixed' : 'absolute';
46
+ s.left = (fixed ? b.left + c.clientLeft : c.offsetLeft + c.clientLeft) + 'px';
47
+ s.top = (fixed ? b.top + c.clientTop : c.offsetTop + c.clientTop) + 'px';
48
+ s.width = c.clientWidth + 'px'; s.height = c.clientHeight + 'px';
49
+ }
50
+
51
+ /** Resize follow-up (mixed into Engine): re-read the canvas box, re-place the UI root, resize renderer / post / camera */
52
+ export const resizeMethods = {
53
+ _resize() {
54
+ const { w, h } = canvasBox(this);
55
+ placeUI(this);
56
+ const now = this.renderer.getSize(_size);
57
+ if (now.x === w && now.y === h) return; // ResizeObserver and the window event can both fire for one change
58
+ this.renderer.setSize(w, h, !!this._autoSize);
59
+ this.post.setSize(w, h);
60
+ this.camera.aspect = w / h;
61
+ this.camera.updateProjectionMatrix();
62
+ },
63
+ };
@@ -0,0 +1,169 @@
1
+ // engine.catalog(): what this game can do, read from the registrations that already exist (module definitions, ops.define,
2
+ // saves.register, describe.add, module hooks, params schemas). Why a reader and not a registry: a second list would drift from the code;
3
+ // this file runs no gameplay and stores only who registered what (so an op or save part can be traced back to its module).
4
+ // engine.catalog() -> short list, one line of data per module (+ 'core' and 'game' for what no module registered)
5
+ // engine.catalog('shop') -> one module expanded: dependencies, ops with args / defaults / failure codes, saved parts, time model
6
+ // engine.catalog('shop.buy') -> one op expanded (args schema, reasons, its last attempt)
7
+ // engine.catalog({ find: 'buy' }) -> the short list filtered by id, label, op or save name
8
+ // Ownership: engine.use / module init take a snapshot of the op, save and describe names before and after (catalogSnap / catalogClaim);
9
+ // what existed before the first engine.use is 'core', what appeared outside any module is 'game'. An op named '<module>.verb' or a save
10
+ // part keyed by the module name belongs to that module even when registered later (from game code calling into the module).
11
+ import { parseSchema, schemaInfo } from './params.js';
12
+ import { lookCatalog, lookSummaries } from './look/report.js';
13
+
14
+ const TIME_HOOKS = ['fixed', 'frame', 'afterRender', 'skip', 'afterLoad'];
15
+ const MAX_API = 200; // the dev bridge narrows this to what the api page lists (tools/threedog/catalog.mjs)
16
+
17
+ const keysOf = e => [
18
+ ...[...e.ops.defs.keys()].map(k => 'op:' + k),
19
+ ...[...e.saves.providers.keys()].map(k => 'save:' + k),
20
+ ...[...(e.describe?._extras?.keys() ?? [])].map(k => 'describe:' + k),
21
+ ];
22
+ const track = e => e._catalog ??= { core: null, owner: new Map() };
23
+
24
+ /** @internal before a module's install / init: names registered so far (the first call also fixes what counts as core) */
25
+ export function catalogSnap(e) {
26
+ const c = track(e), now = new Set(keysOf(e));
27
+ c.core ??= now;
28
+ return now;
29
+ }
30
+ /** @internal after it: the names that appeared since snap belong to that module */
31
+ export function catalogClaim(e, name, snap) {
32
+ const c = track(e);
33
+ for (const k of keysOf(e)) if (!snap.has(k) && !c.owner.has(k)) c.owner.set(k, name);
34
+ }
35
+
36
+ /** Who registered this 'op:x' / 'save:x' / 'describe:x' name: a module name, 'core' or 'game' */
37
+ function ownerOf(e, key) {
38
+ const c = track(e), claimed = c.owner.get(key);
39
+ if (claimed && e.modules.has(claimed)) return claimed;
40
+ const [type, name] = [key.slice(0, key.indexOf(':')), key.slice(key.indexOf(':') + 1)];
41
+ const guess = type === 'op' ? name.split('.')[0] : name;
42
+ if (e.modules.has(guess)) return guess;
43
+ return c.core?.has(key) ? 'core' : 'game';
44
+ }
45
+ function owned(e, id) {
46
+ const out = { op: [], save: [], describe: [] };
47
+ for (const k of keysOf(e)) if (ownerOf(e, k) === id) { const i = k.indexOf(':'); out[k.slice(0, i)].push(k.slice(i + 1)); }
48
+ return out;
49
+ }
50
+
51
+ /** A value shown in the catalog: plain data as is, anything else only by kind (functions, three.js objects are not JSON) */
52
+ function toData(v) {
53
+ if (v == null || ['string', 'number', 'boolean'].includes(typeof v)) return v;
54
+ if (typeof v === 'function') return '<function>';
55
+ if (Array.isArray(v)) return v.length <= 8 && v.every(x => x == null || typeof x !== 'object') ? v : `<array of ${v.length}>`;
56
+ return Object.getPrototypeOf(v) === Object.prototype && Object.keys(v).length <= 8 ? v : '<object>';
57
+ }
58
+
59
+ function opInfo(e, name, full) {
60
+ const d = e.ops.defs.get(name), args = schemaInfo(d.shape);
61
+ const o = { name, desc: d.desc, args, failures: Object.keys(d.reasons || {}) };
62
+ if (!full) return o;
63
+ const last = e.ops.recent(name).at(-1);
64
+ return { id: name, kind: 'op', owner: ownerOf(e, 'op:' + name), ...o, reasons: d.reasons || {}, can: !!d.can, offers: !!d.offers,
65
+ undo: !!d.undo, net: d.net ?? 'host', last: last ? { tick: last.tick, ok: last.ok, code: last.code, args: last.args, source: last.source } : null };
66
+ }
67
+ function saveInfo(e, key) {
68
+ const p = e.saves.providers.get(key);
69
+ return { key, version: p.version, ...(p.first ? { first: true } : {}), ...(Object.keys(p.migrate || {}).length ? { migrates: Object.keys(p.migrate).map(Number) } : {}) };
70
+ }
71
+
72
+ /** Public methods and properties of a module's api object (own and inherited, no _private ones) */
73
+ function apiNames(api) {
74
+ if (!api || typeof api !== 'object') return [];
75
+ const out = new Set();
76
+ for (let o = api; o && o !== Object.prototype; o = Object.getPrototypeOf(o))
77
+ for (const k of Object.getOwnPropertyNames(o)) if (k !== 'constructor' && !k.startsWith('_') && out.size < MAX_API) out.add(k);
78
+ return [...out];
79
+ }
80
+
81
+ /** Time model: which loop hooks it has, and the gap that breaks engine.skip (accumulates in fixed, no skip hook) */
82
+ function timeOf(m) {
83
+ const hooks = TIME_HOOKS.filter(h => typeof m[h] === 'function');
84
+ return { hooks, step: m.fixed ? 'fixed' : m.frame ? 'frame' : 'none', skip: !!m.skip, ...(m.noSkip ? { noSkip: m.noSkip } : {}) };
85
+ }
86
+
87
+ function optionalOf(e, m) {
88
+ const opt = m.optional;
89
+ if (!opt) return [];
90
+ const list = Array.isArray(opt) ? opt.map(n => [n, null]) : Object.entries(opt);
91
+ return list.map(([name, lost]) => ({ name, installed: e.modules.has(name), ...(lost ? { lost } : {}) }));
92
+ }
93
+
94
+ function paramsOf(m) {
95
+ if (!m.params) return null;
96
+ const info = schemaInfo(parseSchema(`module ${m.name} params`, m.params));
97
+ if (m.options) for (const k in info) if (m.options[k] !== undefined) info[k].value = toData(m.options[k]);
98
+ return info;
99
+ }
100
+
101
+ function problemsOf(e, m, entry) {
102
+ const out = [];
103
+ if (entry.state === 'failed') out.push('init failed (engine.errors has the reason); no hooks run');
104
+ if (m.fixed && !m.skip && !m.noSkip) out.push('fixed hook but no skip hook: engine.skip does not advance it (fine when its state derives from clock.now; or declare noSkip: "why nothing needs to catch up" on the module)');
105
+ for (const o of entry.optional) if (!o.installed && o.lost) out.push(`optional ${o.name} missing: ${o.lost}`);
106
+ return out;
107
+ }
108
+
109
+ function moduleEntry(e, m) {
110
+ const id = m.name, own = owned(e, id);
111
+ const entry = {
112
+ id, kind: 'module', ...(m.label ? { label: m.label } : {}), state: e.moduleStates[id], stage: m.stage ?? 'late', runIndex: e.moduleOrder.indexOf(id),
113
+ critical: !!m.critical, requires: m.requires ?? [], optional: optionalOf(e, m), time: timeOf(m), params: paramsOf(m),
114
+ ops: own.op.map(n => opInfo(e, n, false)), saves: own.save.map(k => saveInfo(e, k)),
115
+ queries: { describe: m.describe ? `describe().${id}` : null, extra: own.describe.map(n => `describe().${n}`), api: apiNames(e[id]) },
116
+ ...(m.docs ? { docs: m.docs } : {}),
117
+ };
118
+ entry.problems = problemsOf(e, m, entry);
119
+ return entry;
120
+ }
121
+ function looseEntry(e, id) {
122
+ const own = owned(e, id);
123
+ return { id, kind: id, ops: own.op.map(n => opInfo(e, n, false)), saves: own.save.map(k => saveInfo(e, k)),
124
+ queries: { describe: null, extra: own.describe.map(n => `describe().${n}`), api: [] }, problems: [] };
125
+ }
126
+
127
+ function summary(x) {
128
+ const s = { id: x.id, kind: x.kind };
129
+ if (x.label) s.label = x.label;
130
+ if (x.state) s.state = x.state;
131
+ if (x.stage) s.stage = x.stage;
132
+ s.ops = x.ops.map(o => o.name);
133
+ s.saves = x.saves.map(p => p.key);
134
+ if (x.time) s.time = [x.time.step, x.time.skip ? 'skip' : null].filter(Boolean).join('+');
135
+ if (x.problems.length) s.problems = x.problems.length;
136
+ return s;
137
+ }
138
+
139
+ function entries(e) {
140
+ const out = [...e.modules.values()].map(m => moduleEntry(e, m));
141
+ for (const id of ['core', 'game']) { const x = looseEntry(e, id); if (x.ops.length || x.saves.length || x.queries.extra.length) out.push(x); }
142
+ return out;
143
+ }
144
+
145
+ /**
146
+ * What this game can do, from the registrations that already exist (modules, ops, save parts, describe, params schemas); no second list to keep in sync.
147
+ * No argument: a short list (id, state, stage, op and save names, time model, problem count). A module id: that module expanded
148
+ * (requires / optional, params with defaults and the values in use, ops with args schema and failure codes, saved parts and versions,
149
+ * time hooks, describe fields and api names, problems such as "fixed hook but no skip hook"). An op name: that op expanded, with its last attempt.
150
+ * The dev bridge `threedog catalog [id]` prints the same data and adds the doc, recipe and source files.
151
+ * @param {string | { find?: string }} [id]
152
+ * @returns {any}
153
+ * @example engine.catalog(); // [{ id: 'sky', kind: 'module', state: 'running', stage: 'environment', ops: [], saves: ['sky'], time: 'fixed+skip' }, ...]
154
+ * engine.catalog('shop').ops[0]; // { name: 'shop.buy', args: { n: { type: 'int', optional: true, default: 1 } }, failures: ['soldOut', 'noMoney'] }
155
+ * engine.catalog('shop.buy').last; // { tick: 812, ok: false, code: 'noMoney', ... }
156
+ * engine.catalog({ find: 'throw' }); // only entries whose id, label, op or save mentions "throw"
157
+ */
158
+ export function catalog(e, id) {
159
+ if (typeof id === 'string') {
160
+ if (e.modules.has(id)) return moduleEntry(e, e.modules.get(id));
161
+ if (e.ops.defs.has(id)) return opInfo(e, id, true);
162
+ if (id === 'core' || id === 'game') return looseEntry(e, id);
163
+ if (id === 'look' || id.startsWith('look.')) return lookCatalog(e, id); // look parts (look/part.js): params with why / off, hooks, replace contract
164
+ return null;
165
+ }
166
+ const list = [...entries(e).map(summary), ...lookSummaries(e)];
167
+ const q = id?.find?.toLowerCase();
168
+ return q ? list.filter(s => [s.id, s.label, ...s.ops, ...s.saves].some(x => x?.toLowerCase().includes(q))) : list;
169
+ }
package/core/checks.js ADDED
@@ -0,0 +1,67 @@
1
+ // Consistency checks a game (or an AI) can call in dev and tests, mixed into Engine.prototype. They never throw on a mismatch: they return { ok, diffs }, so a test
2
+ // or the dev bridge prints the first differing paths instead of a bare "false".
3
+ // await engine.checkSkip(600) // engine.skip(600 game seconds) vs stepping the same time in fixed steps: same saved state?
4
+ // await engine.checkSave() // save -> load: same saved state?
5
+ // "State" is what engine.saves.collect() returns (every save part), so a module that keeps state outside its save part is invisible here: that is the point
6
+ // of the check, a skip or a load that loses it shows up as a diff of the part's data.
7
+
8
+ const MAX_DIFFS = 20;
9
+
10
+ /** Flatten two JSON values into the paths where they differ: [{ path, a, b }] (at most MAX_DIFFS; numbers within 1e-6 are equal) */
11
+ export function diffState(a, b, ignore = []) {
12
+ const out = [];
13
+ const walk = (x, y, path) => {
14
+ if (out.length >= MAX_DIFFS || ignore.some(p => path === p || path.startsWith(p + '.'))) return;
15
+ if (typeof x === 'number' && typeof y === 'number') { if (Math.abs(x - y) > 1e-6 && !(Number.isNaN(x) && Number.isNaN(y))) out.push({ path, a: x, b: y }); return; }
16
+ if (x && y && typeof x === 'object' && typeof y === 'object' && Array.isArray(x) === Array.isArray(y)) {
17
+ for (const k of new Set([...Object.keys(x), ...Object.keys(y)])) walk(x[k], y[k], path ? path + '.' + k : k);
18
+ return;
19
+ }
20
+ if (x !== y) out.push({ path, a: x, b: y });
21
+ };
22
+ walk(a, b, '');
23
+ return out;
24
+ }
25
+
26
+ /** The comparable state: a JSON copy of collect() without the timestamp */
27
+ function snapshot(e) { const d = JSON.parse(JSON.stringify(e.saves.collect())); delete d.savedAt; return d; }
28
+
29
+ export const checkMethods = {
30
+ /**
31
+ * Is skipping time the same as living through it? Saves the state, runs engine.skip({ seconds }), saves it again, rewinds to the first state, steps the same
32
+ * span in fixed steps (engine.step, no rendering) and compares the two end states. The world is left at the stepped state, so call it on a scratch playthrough
33
+ * or a test, not in the middle of a real one. A diff usually means a module that keeps its own time lacks (or has a wrong) skip hook.
34
+ * @param {number} seconds game seconds, > 0
35
+ * @param {{ ignore?: string[] }} [opts] ignore: state paths (or their prefix, e.g. 'random') not to compare
36
+ * Refuses ({ ok: false, reason: 'frozen' | 'timeScale0' }) while gameplay is frozen or paused, or the clock is stopped.
37
+ * @returns {Promise<{ ok: boolean, reason?: string, diffs: { path: string, a: any, b: any }[] }>} a = after skip, b = after stepping
38
+ * @example const r = await engine.checkSkip(600); if (!r.ok) console.log(r.diffs);
39
+ */
40
+ async checkSkip(seconds, { ignore = [] } = {}) {
41
+ // Refuse where the two paths cannot be the same thing: frozen gameplay does not step, and a stopped clock (timeScale 0) makes "seconds" mean nothing
42
+ const refuse = (why, b) => ({ ok: false, reason: why, diffs: [{ path: '(precondition)', a: why, b }] });
43
+ if (this.frozen) return refuse('frozen', 'unfreeze first (stepping obeys freezes): ' + [...this._freezers.keys()].join(', '));
44
+ if (!(this.clock.timeScale > 0)) return refuse('timeScale0', 'set clock.timeScale > 0');
45
+ this.commits.tick(Infinity); // pending background results land first, so they cannot sit in one path's state and not the other's
46
+ const before = JSON.parse(JSON.stringify(this.saves.collect()));
47
+ await this.skip({ seconds });
48
+ const skipped = snapshot(this);
49
+ if (!(await this.saves.apply(before, 'checkSkip'))) return { ok: false, diffs: [{ path: '(rewind)', a: 'applied', b: 'refused' }] };
50
+ this.step(seconds / this.clock.timeScale, { render: false });
51
+ const diffs = diffState(skipped, snapshot(this), ignore);
52
+ return { ok: diffs.length === 0, diffs };
53
+ },
54
+ /**
55
+ * Does save -> load give the same state back? Collects the state, applies it as a load and compares with a second collect (nothing is written to the browser).
56
+ * A diff names a save part whose load() does not restore what its save() wrote.
57
+ * @param {{ ignore?: string[] }} [opts] ignore: state paths (or their prefix) not to compare
58
+ * @returns {Promise<{ ok: boolean, diffs: { path: string, a: any, b: any }[] }>} a = before the load, b = after
59
+ * @example const r = await engine.checkSave(); if (!r.ok) console.log(r.diffs);
60
+ */
61
+ async checkSave({ ignore = [] } = {}) {
62
+ const before = snapshot(this);
63
+ if (!(await this.saves.apply(JSON.parse(JSON.stringify(this.saves.collect())), 'checkSave'))) return { ok: false, diffs: [{ path: '(load)', a: 'applied', b: 'refused' }] };
64
+ const diffs = diffState(before, snapshot(this), ignore);
65
+ return { ok: diffs.length === 0, diffs };
66
+ },
67
+ };