wallhammer-web 0.0.0-stage → 0.4.1

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 (408) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +92 -2
  3. package/dist/base/data.d.ts +67 -0
  4. package/dist/base/data.js +10 -0
  5. package/dist/base/destructible.d.ts +167 -0
  6. package/dist/base/destructible.js +47 -0
  7. package/dist/base/env-slot.d.ts +101 -0
  8. package/dist/base/env-slot.js +8 -0
  9. package/dist/base/frames.d.ts +138 -0
  10. package/dist/base/frames.js +459 -0
  11. package/dist/base/index.d.ts +21 -0
  12. package/dist/base/index.js +11 -0
  13. package/dist/base/mat34.d.ts +46 -0
  14. package/dist/base/mat34.js +173 -0
  15. package/dist/base/material.d.ts +87 -0
  16. package/dist/base/material.js +6 -0
  17. package/dist/base/math.d.ts +27 -0
  18. package/dist/base/math.js +60 -0
  19. package/dist/base/progress.d.ts +38 -0
  20. package/dist/base/progress.js +81 -0
  21. package/dist/base/rig.d.ts +177 -0
  22. package/dist/base/rig.js +97 -0
  23. package/dist/base/trig.d.ts +29 -0
  24. package/dist/base/trig.js +169 -0
  25. package/dist/base/up.d.ts +26 -0
  26. package/dist/base/up.js +40 -0
  27. package/dist/base/view.d.ts +128 -0
  28. package/dist/base/view.js +136 -0
  29. package/dist/camera/camera.d.ts +99 -0
  30. package/dist/camera/camera.js +228 -0
  31. package/dist/camera/follow.d.ts +120 -0
  32. package/dist/camera/follow.js +320 -0
  33. package/dist/camera/free.d.ts +153 -0
  34. package/dist/camera/free.js +359 -0
  35. package/dist/camera/index.d.ts +10 -0
  36. package/dist/camera/index.js +6 -0
  37. package/dist/camera/orbit.d.ts +93 -0
  38. package/dist/camera/orbit.js +261 -0
  39. package/dist/camera/path.d.ts +48 -0
  40. package/dist/camera/path.js +179 -0
  41. package/dist/core/ballistic.d.ts +66 -0
  42. package/dist/core/ballistic.js +104 -0
  43. package/dist/core/bodies.d.ts +77 -0
  44. package/dist/core/bodies.js +125 -0
  45. package/dist/core/clock.d.ts +37 -0
  46. package/dist/core/clock.js +87 -0
  47. package/dist/core/cover-fade.d.ts +14 -0
  48. package/dist/core/cover-fade.js +38 -0
  49. package/dist/core/index.d.ts +13 -0
  50. package/dist/core/index.js +8 -0
  51. package/dist/core/kepler.d.ts +74 -0
  52. package/dist/core/kepler.js +108 -0
  53. package/dist/core/level-fade.d.ts +66 -0
  54. package/dist/core/level-fade.js +123 -0
  55. package/dist/core/palette.d.ts +15 -0
  56. package/dist/core/palette.js +47 -0
  57. package/dist/env/atmosphere.d.ts +129 -0
  58. package/dist/env/atmosphere.js +707 -0
  59. package/dist/env/cloud-field.d.ts +44 -0
  60. package/dist/env/cloud-field.js +111 -0
  61. package/dist/env/environment.d.ts +217 -0
  62. package/dist/env/environment.js +441 -0
  63. package/dist/env/frame-block.d.ts +29 -0
  64. package/dist/env/frame-block.js +152 -0
  65. package/dist/env/glsl.d.ts +35 -0
  66. package/dist/env/glsl.js +246 -0
  67. package/dist/env/index.d.ts +13 -0
  68. package/dist/env/index.js +9 -0
  69. package/dist/env/sky.d.ts +48 -0
  70. package/dist/env/sky.js +227 -0
  71. package/dist/env/sun.d.ts +31 -0
  72. package/dist/env/sun.js +42 -0
  73. package/dist/gen-arch/build.d.ts +17 -0
  74. package/dist/gen-arch/build.js +414 -0
  75. package/dist/gen-arch/damage/damaged.d.ts +44 -0
  76. package/dist/gen-arch/damage/damaged.js +1119 -0
  77. package/dist/gen-arch/damage/fall-material.d.ts +10 -0
  78. package/dist/gen-arch/damage/fall-material.js +47 -0
  79. package/dist/gen-arch/damage/fall.d.ts +78 -0
  80. package/dist/gen-arch/damage/fall.js +797 -0
  81. package/dist/gen-arch/damage/rubble.d.ts +22 -0
  82. package/dist/gen-arch/damage/rubble.js +188 -0
  83. package/dist/gen-arch/index.d.ts +25 -0
  84. package/dist/gen-arch/index.js +16 -0
  85. package/dist/gen-arch/interior/interior-plan.d.ts +114 -0
  86. package/dist/gen-arch/interior/interior-plan.js +615 -0
  87. package/dist/gen-arch/interior/interior.d.ts +97 -0
  88. package/dist/gen-arch/interior/interior.js +966 -0
  89. package/dist/gen-arch/structure/building-shader.d.ts +25 -0
  90. package/dist/gen-arch/structure/building-shader.js +946 -0
  91. package/dist/gen-arch/structure/buildings.d.ts +248 -0
  92. package/dist/gen-arch/structure/buildings.js +294 -0
  93. package/dist/gen-arch/structure/dims.d.ts +77 -0
  94. package/dist/gen-arch/structure/dims.js +39 -0
  95. package/dist/gen-arch/structure/distant.d.ts +62 -0
  96. package/dist/gen-arch/structure/distant.js +316 -0
  97. package/dist/gen-arch/structure/env-slots.d.ts +18 -0
  98. package/dist/gen-arch/structure/env-slots.js +47 -0
  99. package/dist/gen-arch/structure/facade.d.ts +193 -0
  100. package/dist/gen-arch/structure/facade.js +159 -0
  101. package/dist/gen-arch/structure/parts.d.ts +31 -0
  102. package/dist/gen-arch/structure/parts.js +69 -0
  103. package/dist/gen-arch/structure/roof.d.ts +76 -0
  104. package/dist/gen-arch/structure/roof.js +568 -0
  105. package/dist/gen-arch/structure/structure-material.d.ts +23 -0
  106. package/dist/gen-arch/structure/structure-material.js +55 -0
  107. package/dist/gen-arch/structure/writer.d.ts +94 -0
  108. package/dist/gen-arch/structure/writer.js +195 -0
  109. package/dist/gen-core/cell.d.ts +138 -0
  110. package/dist/gen-core/cell.js +150 -0
  111. package/dist/gen-core/cube-sphere.d.ts +57 -0
  112. package/dist/gen-core/cube-sphere.js +159 -0
  113. package/dist/gen-core/field.d.ts +55 -0
  114. package/dist/gen-core/field.js +154 -0
  115. package/dist/gen-core/geometry.d.ts +31 -0
  116. package/dist/gen-core/geometry.js +231 -0
  117. package/dist/gen-core/hash.d.ts +18 -0
  118. package/dist/gen-core/hash.js +58 -0
  119. package/dist/gen-core/height-field.d.ts +33 -0
  120. package/dist/gen-core/height-field.js +137 -0
  121. package/dist/gen-core/index.d.ts +22 -0
  122. package/dist/gen-core/index.js +17 -0
  123. package/dist/gen-core/instance-cells.d.ts +37 -0
  124. package/dist/gen-core/instance-cells.js +72 -0
  125. package/dist/gen-core/near-scatter.d.ts +56 -0
  126. package/dist/gen-core/near-scatter.js +120 -0
  127. package/dist/gen-core/noise.d.ts +23 -0
  128. package/dist/gen-core/noise.js +72 -0
  129. package/dist/gen-core/occupancy.d.ts +21 -0
  130. package/dist/gen-core/occupancy.js +104 -0
  131. package/dist/gen-core/sphere-patch.d.ts +138 -0
  132. package/dist/gen-core/sphere-patch.js +544 -0
  133. package/dist/gen-core/strip-surface.d.ts +34 -0
  134. package/dist/gen-core/strip-surface.js +246 -0
  135. package/dist/gen-core/strip.d.ts +102 -0
  136. package/dist/gen-core/strip.js +817 -0
  137. package/dist/gen-ground/env-slots.d.ts +48 -0
  138. package/dist/gen-ground/env-slots.js +78 -0
  139. package/dist/gen-ground/ground.d.ts +78 -0
  140. package/dist/gen-ground/ground.js +208 -0
  141. package/dist/gen-ground/index.d.ts +9 -0
  142. package/dist/gen-ground/index.js +7 -0
  143. package/dist/gen-ground/markings.d.ts +46 -0
  144. package/dist/gen-ground/markings.js +124 -0
  145. package/dist/gen-ground/materials.d.ts +18 -0
  146. package/dist/gen-ground/materials.js +22 -0
  147. package/dist/gen-ground/terrain-shader.d.ts +5 -0
  148. package/dist/gen-ground/terrain-shader.js +151 -0
  149. package/dist/gen-mesh/bare-shapes.d.ts +194 -0
  150. package/dist/gen-mesh/bare-shapes.js +596 -0
  151. package/dist/gen-mesh/bisect-surface.d.ts +47 -0
  152. package/dist/gen-mesh/bisect-surface.js +261 -0
  153. package/dist/gen-mesh/box.d.ts +18 -0
  154. package/dist/gen-mesh/box.js +2 -0
  155. package/dist/gen-mesh/cell-morph-mesh.d.ts +52 -0
  156. package/dist/gen-mesh/cell-morph-mesh.js +258 -0
  157. package/dist/gen-mesh/cell-surface-mesh.d.ts +32 -0
  158. package/dist/gen-mesh/cell-surface-mesh.js +140 -0
  159. package/dist/gen-mesh/chunk-mesh.d.ts +25 -0
  160. package/dist/gen-mesh/chunk-mesh.js +112 -0
  161. package/dist/gen-mesh/drape-mesh.d.ts +36 -0
  162. package/dist/gen-mesh/drape-mesh.js +98 -0
  163. package/dist/gen-mesh/height-field-mesh.d.ts +14 -0
  164. package/dist/gen-mesh/height-field-mesh.js +98 -0
  165. package/dist/gen-mesh/index.d.ts +26 -0
  166. package/dist/gen-mesh/index.js +15 -0
  167. package/dist/gen-mesh/line-mesh.d.ts +25 -0
  168. package/dist/gen-mesh/line-mesh.js +62 -0
  169. package/dist/gen-mesh/mesh-builder.d.ts +115 -0
  170. package/dist/gen-mesh/mesh-builder.js +315 -0
  171. package/dist/gen-mesh/packed-mesh.d.ts +53 -0
  172. package/dist/gen-mesh/packed-mesh.js +205 -0
  173. package/dist/gen-mesh/prism-mesh.d.ts +33 -0
  174. package/dist/gen-mesh/prism-mesh.js +176 -0
  175. package/dist/gen-mesh/rig-mesh.d.ts +9 -0
  176. package/dist/gen-mesh/rig-mesh.js +135 -0
  177. package/dist/gen-mesh/strip-mesh.d.ts +45 -0
  178. package/dist/gen-mesh/strip-mesh.js +258 -0
  179. package/dist/gen-plan/drain.d.ts +58 -0
  180. package/dist/gen-plan/drain.js +270 -0
  181. package/dist/gen-plan/grid.d.ts +37 -0
  182. package/dist/gen-plan/grid.js +182 -0
  183. package/dist/gen-plan/horizon.d.ts +50 -0
  184. package/dist/gen-plan/horizon.js +185 -0
  185. package/dist/gen-plan/index.d.ts +15 -0
  186. package/dist/gen-plan/index.js +13 -0
  187. package/dist/gen-plan/line-tiles.d.ts +35 -0
  188. package/dist/gen-plan/line-tiles.js +190 -0
  189. package/dist/gen-plan/lines.d.ts +31 -0
  190. package/dist/gen-plan/lines.js +183 -0
  191. package/dist/gen-plan/plots.d.ts +40 -0
  192. package/dist/gen-plan/plots.js +282 -0
  193. package/dist/gen-plan/route.d.ts +55 -0
  194. package/dist/gen-plan/route.js +297 -0
  195. package/dist/gen-plan/sites.d.ts +32 -0
  196. package/dist/gen-plan/sites.js +209 -0
  197. package/dist/gen-tex/code-stamp.d.ts +31 -0
  198. package/dist/gen-tex/code-stamp.js +137 -0
  199. package/dist/gen-tex/index.d.ts +7 -0
  200. package/dist/gen-tex/index.js +5 -0
  201. package/dist/gen-tex/light-horizon.d.ts +47 -0
  202. package/dist/gen-tex/light-horizon.js +180 -0
  203. package/dist/gen-tex/textures.d.ts +8 -0
  204. package/dist/gen-tex/textures.js +49 -0
  205. package/dist/gen-tex/value-textures.d.ts +46 -0
  206. package/dist/gen-tex/value-textures.js +102 -0
  207. package/dist/gen-vegetation/env-slots.d.ts +20 -0
  208. package/dist/gen-vegetation/env-slots.js +29 -0
  209. package/dist/gen-vegetation/index.d.ts +8 -0
  210. package/dist/gen-vegetation/index.js +7 -0
  211. package/dist/gen-vegetation/materials.d.ts +7 -0
  212. package/dist/gen-vegetation/materials.js +17 -0
  213. package/dist/gen-vegetation/planting.d.ts +170 -0
  214. package/dist/gen-vegetation/planting.js +363 -0
  215. package/dist/gen-vegetation/tree-shader.d.ts +23 -0
  216. package/dist/gen-vegetation/tree-shader.js +229 -0
  217. package/dist/gen-vegetation/trees.d.ts +59 -0
  218. package/dist/gen-vegetation/trees.js +329 -0
  219. package/dist/gpu/device.d.ts +286 -0
  220. package/dist/gpu/device.js +1157 -0
  221. package/dist/gpu/gl.d.ts +134 -0
  222. package/dist/gpu/gl.js +276 -0
  223. package/dist/gpu/index.d.ts +4 -0
  224. package/dist/gpu/index.js +3 -0
  225. package/dist/index.d.ts +11 -0
  226. package/dist/index.js +13 -0
  227. package/dist/motion/graph.d.ts +244 -0
  228. package/dist/motion/graph.js +739 -0
  229. package/dist/motion/index.d.ts +8 -0
  230. package/dist/motion/index.js +8 -0
  231. package/dist/motion/pose-ops.d.ts +30 -0
  232. package/dist/motion/pose-ops.js +232 -0
  233. package/dist/motion/reach.d.ts +45 -0
  234. package/dist/motion/reach.js +264 -0
  235. package/dist/motion/skeleton.d.ts +49 -0
  236. package/dist/motion/skeleton.js +99 -0
  237. package/dist/platform/byte-store.d.ts +21 -0
  238. package/dist/platform/byte-store.js +137 -0
  239. package/dist/platform/canvas.d.ts +29 -0
  240. package/dist/platform/canvas.js +76 -0
  241. package/dist/platform/context-loss.d.ts +8 -0
  242. package/dist/platform/context-loss.js +17 -0
  243. package/dist/platform/free-input.d.ts +51 -0
  244. package/dist/platform/free-input.js +100 -0
  245. package/dist/platform/index.d.ts +18 -0
  246. package/dist/platform/index.js +10 -0
  247. package/dist/platform/input.d.ts +48 -0
  248. package/dist/platform/input.js +117 -0
  249. package/dist/platform/keys.d.ts +12 -0
  250. package/dist/platform/keys.js +29 -0
  251. package/dist/platform/loop.d.ts +41 -0
  252. package/dist/platform/loop.js +84 -0
  253. package/dist/platform/walk-input.d.ts +74 -0
  254. package/dist/platform/walk-input.js +226 -0
  255. package/dist/platform/worker.d.ts +51 -0
  256. package/dist/platform/worker.js +170 -0
  257. package/dist/render/bone-instances.d.ts +24 -0
  258. package/dist/render/bone-instances.js +74 -0
  259. package/dist/render/cells.d.ts +70 -0
  260. package/dist/render/cells.js +144 -0
  261. package/dist/render/glsl.d.ts +66 -0
  262. package/dist/render/glsl.js +173 -0
  263. package/dist/render/index.d.ts +26 -0
  264. package/dist/render/index.js +16 -0
  265. package/dist/render/instance-sets.d.ts +97 -0
  266. package/dist/render/instance-sets.js +241 -0
  267. package/dist/render/near-instances.d.ts +75 -0
  268. package/dist/render/near-instances.js +219 -0
  269. package/dist/render/particles.d.ts +63 -0
  270. package/dist/render/particles.js +215 -0
  271. package/dist/render/pieces.d.ts +57 -0
  272. package/dist/render/pieces.js +151 -0
  273. package/dist/render/point-lights.d.ts +97 -0
  274. package/dist/render/point-lights.js +243 -0
  275. package/dist/render/renderer.d.ts +447 -0
  276. package/dist/render/renderer.js +1100 -0
  277. package/dist/render/rig.d.ts +74 -0
  278. package/dist/render/rig.js +576 -0
  279. package/dist/render/shadow-areas.d.ts +49 -0
  280. package/dist/render/shadow-areas.js +125 -0
  281. package/dist/render/shadow-glsl.d.ts +12 -0
  282. package/dist/render/shadow-glsl.js +146 -0
  283. package/dist/render/transient.d.ts +61 -0
  284. package/dist/render/transient.js +213 -0
  285. package/dist/render/value-glsl.d.ts +17 -0
  286. package/dist/render/value-glsl.js +208 -0
  287. package/dist/render/value-layers.d.ts +180 -0
  288. package/dist/render/value-layers.js +333 -0
  289. package/dist/runtime/atmosphere.d.ts +37 -0
  290. package/dist/runtime/atmosphere.js +304 -0
  291. package/dist/runtime/cloud-shell.d.ts +29 -0
  292. package/dist/runtime/cloud-shell.js +158 -0
  293. package/dist/runtime/engine.d.ts +155 -0
  294. package/dist/runtime/engine.js +305 -0
  295. package/dist/runtime/environment-link.d.ts +22 -0
  296. package/dist/runtime/environment-link.js +49 -0
  297. package/dist/runtime/index.d.ts +13 -0
  298. package/dist/runtime/index.js +12 -0
  299. package/dist/runtime/precipitation-glsl.d.ts +2 -0
  300. package/dist/runtime/precipitation-glsl.js +70 -0
  301. package/dist/runtime/precipitation.d.ts +11 -0
  302. package/dist/runtime/precipitation.js +78 -0
  303. package/dist/runtime/sky.d.ts +30 -0
  304. package/dist/runtime/sky.js +114 -0
  305. package/dist/runtime/streaming.d.ts +245 -0
  306. package/dist/runtime/streaming.js +602 -0
  307. package/dist/sim/agenda.d.ts +167 -0
  308. package/dist/sim/agenda.js +425 -0
  309. package/dist/sim/bytes.d.ts +34 -0
  310. package/dist/sim/bytes.js +125 -0
  311. package/dist/sim/destruction/apply.d.ts +59 -0
  312. package/dist/sim/destruction/apply.js +243 -0
  313. package/dist/sim/destruction/cell-states.d.ts +54 -0
  314. package/dist/sim/destruction/cell-states.js +198 -0
  315. package/dist/sim/destruction/index.d.ts +11 -0
  316. package/dist/sim/destruction/index.js +10 -0
  317. package/dist/sim/destruction/int-geometry.d.ts +17 -0
  318. package/dist/sim/destruction/int-geometry.js +131 -0
  319. package/dist/sim/destruction/pick.d.ts +13 -0
  320. package/dist/sim/destruction/pick.js +59 -0
  321. package/dist/sim/destruction/rubble.d.ts +8 -0
  322. package/dist/sim/destruction/rubble.js +159 -0
  323. package/dist/sim/destruction/state.d.ts +15 -0
  324. package/dist/sim/destruction/state.js +83 -0
  325. package/dist/sim/destruction/structure.d.ts +30 -0
  326. package/dist/sim/destruction/structure.js +139 -0
  327. package/dist/sim/events.d.ts +37 -0
  328. package/dist/sim/events.js +106 -0
  329. package/dist/sim/fixed.d.ts +21 -0
  330. package/dist/sim/fixed.js +64 -0
  331. package/dist/sim/flow-probe.d.ts +58 -0
  332. package/dist/sim/flow-probe.js +158 -0
  333. package/dist/sim/flow.d.ts +257 -0
  334. package/dist/sim/flow.js +967 -0
  335. package/dist/sim/index.d.ts +28 -0
  336. package/dist/sim/index.js +20 -0
  337. package/dist/sim/interlock.d.ts +47 -0
  338. package/dist/sim/interlock.js +252 -0
  339. package/dist/sim/movers.d.ts +228 -0
  340. package/dist/sim/movers.js +1083 -0
  341. package/dist/sim/nav.d.ts +72 -0
  342. package/dist/sim/nav.js +292 -0
  343. package/dist/sim/paths.d.ts +80 -0
  344. package/dist/sim/paths.js +197 -0
  345. package/dist/sim/regions.d.ts +87 -0
  346. package/dist/sim/regions.js +517 -0
  347. package/dist/sim/simulation.d.ts +114 -0
  348. package/dist/sim/simulation.js +291 -0
  349. package/dist/sim/states.d.ts +23 -0
  350. package/dist/sim/states.js +54 -0
  351. package/dist/sim/table.d.ts +49 -0
  352. package/dist/sim/table.js +126 -0
  353. package/dist/sim/zones.d.ts +11 -0
  354. package/dist/sim/zones.js +196 -0
  355. package/dist/tools/collision-lines.d.ts +12 -0
  356. package/dist/tools/collision-lines.js +50 -0
  357. package/dist/tools/data-view-glsl.d.ts +3 -0
  358. package/dist/tools/data-view-glsl.js +63 -0
  359. package/dist/tools/data-view-layers.d.ts +20 -0
  360. package/dist/tools/data-view-layers.js +60 -0
  361. package/dist/tools/debug-view.d.ts +30 -0
  362. package/dist/tools/debug-view.js +4 -0
  363. package/dist/tools/index.d.ts +10 -0
  364. package/dist/tools/index.js +7 -0
  365. package/dist/tools/mesh-checks.d.ts +67 -0
  366. package/dist/tools/mesh-checks.js +188 -0
  367. package/dist/tools/profile.d.ts +85 -0
  368. package/dist/tools/profile.js +173 -0
  369. package/dist/world/cell-cache.d.ts +32 -0
  370. package/dist/world/cell-cache.js +60 -0
  371. package/dist/world/cell-format.d.ts +25 -0
  372. package/dist/world/cell-format.js +232 -0
  373. package/dist/world/collide.d.ts +192 -0
  374. package/dist/world/collide.js +822 -0
  375. package/dist/world/index.d.ts +16 -0
  376. package/dist/world/index.js +12 -0
  377. package/dist/world/mesh-solids.d.ts +48 -0
  378. package/dist/world/mesh-solids.js +169 -0
  379. package/dist/world/pick.d.ts +34 -0
  380. package/dist/world/pick.js +177 -0
  381. package/dist/world/providers.d.ts +66 -0
  382. package/dist/world/providers.js +83 -0
  383. package/dist/world/sphere.d.ts +69 -0
  384. package/dist/world/sphere.js +271 -0
  385. package/dist/world/streaming.d.ts +288 -0
  386. package/dist/world/streaming.js +801 -0
  387. package/dist/world/walker.d.ts +145 -0
  388. package/dist/world/walker.js +502 -0
  389. package/docs/architecture.md +111 -0
  390. package/docs/cameras.md +302 -0
  391. package/docs/concepts.md +123 -0
  392. package/docs/destruction.md +127 -0
  393. package/docs/frames.md +199 -0
  394. package/docs/generators.md +575 -0
  395. package/docs/getting-started.md +123 -0
  396. package/docs/headless.md +50 -0
  397. package/docs/motion.md +160 -0
  398. package/docs/planet.md +152 -0
  399. package/docs/recipes.md +521 -0
  400. package/docs/reference.md +364 -0
  401. package/docs/rendering.md +823 -0
  402. package/docs/rigs.md +203 -0
  403. package/docs/simulation.md +235 -0
  404. package/docs/streaming.md +590 -0
  405. package/docs/system.md +166 -0
  406. package/docs/tools.md +175 -0
  407. package/docs/walking.md +262 -0
  408. package/package.json +131 -3
@@ -0,0 +1,167 @@
1
+ import { ByteReader, ByteWriter } from './bytes.ts';
2
+ import type { Movers, SpawnOptions } from './movers.ts';
3
+ import type { NavGraph } from './nav.ts';
4
+ import type { PathDef } from './paths.ts';
5
+ import type { SimState, Simulation } from './simulation.ts';
6
+ import { StateMachine } from './states.ts';
7
+ import { EntityTable } from './table.ts';
8
+ export interface AgendaPlace {
9
+ /** Node of the navigation graph where routes to and from the place end. */
10
+ node: number;
11
+ /** A point off the graph where the entity stands (a door, a spot on a platform), metres. Default the node. */
12
+ x?: number;
13
+ z?: number;
14
+ /** Staying here hides the entity (it is inside). */
15
+ inside?: boolean;
16
+ }
17
+ export interface AgendaActivity {
18
+ place: number;
19
+ /** Seconds on the agenda clock: when the trip there starts (or, with `arrive`, when to be there by). */
20
+ at: number;
21
+ arrive?: boolean;
22
+ /** Seconds to stay. */
23
+ stay: number;
24
+ /** Free integer for the app (how the place is reached or left). */
25
+ mode?: number;
26
+ }
27
+ export interface AgendaEntity {
28
+ activities: readonly AgendaActivity[];
29
+ /** Free integer for the app. */
30
+ tag?: number;
31
+ }
32
+ export interface AgendaOptions {
33
+ movers: Movers;
34
+ nav: NavGraph;
35
+ places: readonly AgendaPlace[];
36
+ /** Agenda clock at tick 0, seconds. Default 0. */
37
+ origin?: number;
38
+ /** Routes run this far right of the graph edges, metres (people keep to one side). Default 0. */
39
+ rightOffset?: number;
40
+ /** Mover settings of an entity (its index in the order of `add`). Default: 1.3 m/s walking. */
41
+ spawn?: (index: number) => Omit<SpawnOptions, 'path' | 'at'>;
42
+ /** Called when an entity's first activity begins: return a state to go to instead of appearing at the place. */
43
+ onAppear?: (entity: number, agendas: Agendas) => number | void;
44
+ /** Called when an entity reaches the place of an activity: return a state instead of `stay`. */
45
+ onArrive?: (entity: number, agendas: Agendas) => number | void;
46
+ }
47
+ declare const COLUMNS: {
48
+ /** Index of the current activity (being stayed at, or travelled to). */
49
+ readonly act: 'i32';
50
+ readonly state: 'i32';
51
+ /** Mover id (0: not out of doors). */
52
+ readonly mover: 'f64';
53
+ /** Tick a stay ends, or a state's own timer. */
54
+ readonly timer: 'i32';
55
+ /** Planned start of the next trip (for `arrive` activities, computed from the route), or UNSET. */
56
+ readonly dep: 'i32';
57
+ /** Index of the entity in the order of `add`, and the app's integers. */
58
+ readonly index: 'i32';
59
+ readonly tag: 'i32';
60
+ readonly data: 'i32';
61
+ };
62
+ export declare class Agendas implements SimState {
63
+ readonly name: string;
64
+ readonly table: EntityTable<typeof COLUMNS>;
65
+ readonly states: StateMachine<Agendas>;
66
+ readonly BEFORE: number;
67
+ readonly STAY: number;
68
+ readonly TRAVEL: number;
69
+ readonly DONE: number;
70
+ readonly movers: Movers;
71
+ readonly nav: NavGraph;
72
+ readonly places: readonly AgendaPlace[];
73
+ /** Agenda clock at tick 0, seconds (see `setOrigin`). */
74
+ origin: number;
75
+ private readonly hz;
76
+ private readonly options;
77
+ /** Activities of all entities, flat; `first[index]` and `count[index]` locate an entity's list. */
78
+ private readonly aPlace;
79
+ private readonly aAt;
80
+ /** Activity times in seconds, as given (`aAt` holds them in ticks from the origin). */
81
+ private readonly aAtS;
82
+ private readonly aArrive;
83
+ private readonly aStay;
84
+ private readonly aMode;
85
+ private readonly first;
86
+ private readonly count;
87
+ private sim;
88
+ constructor(name: string, options: AgendaOptions);
89
+ /** Adds an entity and returns its id. */
90
+ add(entity: AgendaEntity): number;
91
+ get size(): number;
92
+ /**
93
+ * Moves tick 0 to another time of the agenda clock. Only for a state in which no entity has begun (all `before`):
94
+ * restore such a snapshot with `Simulation.rebase(snapshot)` and set the origin before the next tick. A jump of the
95
+ * app's clock then sets everything up anew from the agendas, caught up at once.
96
+ */
97
+ setOrigin(seconds: number): void;
98
+ /** Current tick and agenda time in seconds (valid inside the system). */
99
+ get now(): number;
100
+ get time(): number;
101
+ /** Ticks of a time on the agenda clock. */
102
+ tickOf(seconds: number): number;
103
+ private row;
104
+ /** The current activity of an entity. */
105
+ activity(e: number): {
106
+ index: number;
107
+ place: number;
108
+ at: number;
109
+ stay: number;
110
+ mode: number;
111
+ last: boolean;
112
+ };
113
+ /** The activity after the current one, or null. */
114
+ nextActivity(e: number): {
115
+ place: number;
116
+ at: number;
117
+ stay: number;
118
+ mode: number;
119
+ } | null;
120
+ /** Mover id of an entity (0 when it is not out of doors), its index, state and the app's integers. */
121
+ mover(e: number): number;
122
+ indexOf(e: number): number;
123
+ state(e: number): number;
124
+ timer(e: number): number;
125
+ setTimer(e: number, tick: number): void;
126
+ data(e: number): number;
127
+ setData(e: number, v: number): void;
128
+ tag(e: number): number;
129
+ /** Has the entity's mover reached the end of its path (and stands)? */
130
+ standing(e: number): boolean;
131
+ private spot;
132
+ private spawnMover;
133
+ /** Shows the entity standing at a point, facing `dirX, dirZ` (spawns its mover if it has none). */
134
+ show(e: number, x: number, z: number, dirX?: number, dirZ?: number): void;
135
+ /** Removes the entity's mover (it goes inside, boards, leaves the map). */
136
+ hide(e: number): void;
137
+ /** Walks the entity in a straight line from where it is to a point. */
138
+ walkTo(e: number, x: number, z: number): void;
139
+ /** Puts the entity into `stay` at its current activity until `tick`; returns the state id for an `update`. */
140
+ stayUntil(e: number, tick: number): number;
141
+ /** Ends the entity's agenda: hides it. Returns the state id for an `update`. */
142
+ finish(e: number): number;
143
+ /** Starts the trip to the next activity now (or ends the agenda); returns the state id for an `update`. */
144
+ leave(e: number, lateTicks?: number): number;
145
+ /**
146
+ * Moves the entity on to its next activity without a trip, as if it was carried there (it rides a vehicle, takes a
147
+ * lift): its mover is removed and the arrival at the next place runs at once (`onArrive`, or `stay`). Returns the
148
+ * state id for an `update`; ends the agenda at the last activity.
149
+ */
150
+ arriveNext(e: number): number;
151
+ /** Route between two places as a path definition (spots at both ends), or null when there is none. */
152
+ route(from: number, to: number): PathDef | null;
153
+ /** Walking length of a route between two places, metres (straight line when there is no route). */
154
+ routeLength(from: number, to: number): number;
155
+ /** Arrival at the current activity's place: the app's hook or `stay`. */
156
+ private arrive;
157
+ private updateBefore;
158
+ /** When the trip to the next activity is due (tick), or null at the last one. */
159
+ private departure;
160
+ private updateStay;
161
+ private updateTravel;
162
+ /** The system: one tick of every agenda. Register it after the movers' system. */
163
+ readonly system: (sim: Simulation) => void;
164
+ save(w: ByteWriter): void;
165
+ load(r: ByteReader): void;
166
+ }
167
+ export {};
@@ -0,0 +1,425 @@
1
+ // Agendas: entities that follow a list of activities. An activity is a place, a time and a stay: the system turns the
2
+ // next activity into a route through the navigation graph, hands it to a mover set, waits for the arrival, waits out
3
+ // the stay and goes on. What places and activities mean (a door, a stop, a lecture) belongs to the app; the engine
4
+ // only knows nodes, points and times.
5
+ //
6
+ // - The agenda clock is seconds; tick 0 is `origin`. Activity times are converted to ticks once, on `add`.
7
+ // - The first activity is where the entity appears, at its time; later ones are reached by walking a route. An
8
+ // activity with `arrive` sets the time to be there by: the trip starts the route's walking time earlier.
9
+ // - A place marked `inside` hides the entity while it stays there (its mover is removed, and spawned again when it
10
+ // leaves), so only the ones out of doors cost anything.
11
+ // - Late starts are caught up: an entity whose trip should have begun before tick 0 (or before a stay ended) starts
12
+ // it at the distance it would have walked by now. Setting up the agenda world at any time of day therefore gives a
13
+ // plausible picture at once.
14
+ // - States are a `StateMachine` with four built in (`before`, `stay`, `travel`, `done`). An app adds its own (waiting,
15
+ // boarding, riding) and switches to them from the hooks `onAppear` and `onArrive`; their `update` may use the
16
+ // helpers below (`show`, `walkTo`, `hide`, `stayUntil`, `leave`, `arriveNext`).
17
+ //
18
+ // Events: agenda.appear, agenda.arrive, agenda.leave { place, activity }, agenda.done, agenda.unreachable { place }.
19
+ // The activities are setup data: add every entity before the first tick (a snapshot holds the table, not the lists).
20
+ import { ByteReader, ByteWriter } from './bytes.js';
21
+ import { mmPerTick } from './fixed.js';
22
+ import { MOVER_STATE } from './movers.js';
23
+ import { StateMachine } from './states.js';
24
+ import { EntityTable } from './table.js';
25
+ const COLUMNS = {
26
+ /** Index of the current activity (being stayed at, or travelled to). */
27
+ act: 'i32',
28
+ state: 'i32',
29
+ /** Mover id (0: not out of doors). */
30
+ mover: 'f64',
31
+ /** Tick a stay ends, or a state's own timer. */
32
+ timer: 'i32',
33
+ /** Planned start of the next trip (for `arrive` activities, computed from the route), or UNSET. */
34
+ dep: 'i32',
35
+ /** Index of the entity in the order of `add`, and the app's integers. */
36
+ index: 'i32',
37
+ tag: 'i32',
38
+ data: 'i32',
39
+ };
40
+ const UNSET = -0x7fffffff;
41
+ export class Agendas {
42
+ name;
43
+ table;
44
+ states = new StateMachine();
45
+ BEFORE;
46
+ STAY;
47
+ TRAVEL;
48
+ DONE;
49
+ movers;
50
+ nav;
51
+ places;
52
+ /** Agenda clock at tick 0, seconds (see `setOrigin`). */
53
+ origin;
54
+ hz;
55
+ options;
56
+ /** Activities of all entities, flat; `first[index]` and `count[index]` locate an entity's list. */
57
+ aPlace = [];
58
+ aAt = [];
59
+ /** Activity times in seconds, as given (`aAt` holds them in ticks from the origin). */
60
+ aAtS = [];
61
+ aArrive = [];
62
+ aStay = [];
63
+ aMode = [];
64
+ first = [];
65
+ count = [];
66
+ sim = null;
67
+ constructor(name, options) {
68
+ this.name = name;
69
+ this.options = options;
70
+ this.movers = options.movers;
71
+ this.nav = options.nav;
72
+ this.places = options.places;
73
+ this.origin = options.origin ?? 0;
74
+ this.hz = options.movers.hz;
75
+ this.table = new EntityTable(name, COLUMNS);
76
+ this.BEFORE = this.states.define('before', { update: (e) => this.updateBefore(e) });
77
+ this.STAY = this.states.define('stay', { update: (e) => this.updateStay(e) });
78
+ this.TRAVEL = this.states.define('travel', { update: (e) => this.updateTravel(e) });
79
+ this.DONE = this.states.define('done');
80
+ }
81
+ /** Adds an entity and returns its id. */
82
+ add(entity) {
83
+ if (entity.activities.length === 0)
84
+ throw new Error('Agendas: an entity needs at least one activity');
85
+ const index = this.first.length;
86
+ this.first.push(this.aPlace.length);
87
+ this.count.push(entity.activities.length);
88
+ for (const a of entity.activities) {
89
+ if (a.place < 0 || a.place >= this.places.length)
90
+ throw new Error(`Agendas: no place ${a.place}`);
91
+ this.aPlace.push(a.place);
92
+ this.aAt.push(Math.round((a.at - this.origin) * this.hz));
93
+ this.aAtS.push(a.at);
94
+ this.aArrive.push(a.arrive ?? false);
95
+ this.aStay.push(Math.round(a.stay * this.hz));
96
+ this.aMode.push(a.mode ?? 0);
97
+ }
98
+ const id = this.table.create();
99
+ const row = this.table.rowOf(id);
100
+ const c = this.table.col;
101
+ c.state[row] = this.BEFORE;
102
+ c.index[row] = index;
103
+ c.tag[row] = entity.tag ?? 0;
104
+ c.dep[row] = UNSET;
105
+ return id;
106
+ }
107
+ get size() {
108
+ return this.table.count;
109
+ }
110
+ /**
111
+ * Moves tick 0 to another time of the agenda clock. Only for a state in which no entity has begun (all `before`):
112
+ * restore such a snapshot with `Simulation.rebase(snapshot)` and set the origin before the next tick. A jump of the
113
+ * app's clock then sets everything up anew from the agendas, caught up at once.
114
+ */
115
+ setOrigin(seconds) {
116
+ this.origin = seconds;
117
+ for (let i = 0; i < this.aAt.length; i++)
118
+ this.aAt[i] = Math.round((this.aAtS[i] - seconds) * this.hz);
119
+ }
120
+ /** Current tick and agenda time in seconds (valid inside the system). */
121
+ get now() {
122
+ return this.sim?.tick ?? 0;
123
+ }
124
+ get time() {
125
+ return this.origin + this.now / this.hz;
126
+ }
127
+ /** Ticks of a time on the agenda clock. */
128
+ tickOf(seconds) {
129
+ return Math.round((seconds - this.origin) * this.hz);
130
+ }
131
+ row(e) {
132
+ const r = this.table.rowOf(e);
133
+ if (r < 0)
134
+ throw new Error(`Agendas: no entity ${e}`);
135
+ return r;
136
+ }
137
+ /** The current activity of an entity. */
138
+ activity(e) {
139
+ const r = this.row(e);
140
+ const c = this.table.col;
141
+ const i = this.first[c.index[r]] + c.act[r];
142
+ return { index: c.act[r], place: this.aPlace[i], at: this.aAt[i], stay: this.aStay[i], mode: this.aMode[i], last: c.act[r] === this.count[c.index[r]] - 1 };
143
+ }
144
+ /** The activity after the current one, or null. */
145
+ nextActivity(e) {
146
+ const r = this.row(e);
147
+ const c = this.table.col;
148
+ const k = c.act[r] + 1;
149
+ if (k >= this.count[c.index[r]])
150
+ return null;
151
+ const i = this.first[c.index[r]] + k;
152
+ return { place: this.aPlace[i], at: this.aAt[i], stay: this.aStay[i], mode: this.aMode[i] };
153
+ }
154
+ /** Mover id of an entity (0 when it is not out of doors), its index, state and the app's integers. */
155
+ mover(e) {
156
+ return this.table.col.mover[this.row(e)];
157
+ }
158
+ indexOf(e) {
159
+ return this.table.col.index[this.row(e)];
160
+ }
161
+ state(e) {
162
+ return this.table.col.state[this.row(e)];
163
+ }
164
+ timer(e) {
165
+ return this.table.col.timer[this.row(e)];
166
+ }
167
+ setTimer(e, tick) {
168
+ this.table.col.timer[this.row(e)] = tick;
169
+ }
170
+ data(e) {
171
+ return this.table.col.data[this.row(e)];
172
+ }
173
+ setData(e, v) {
174
+ this.table.col.data[this.row(e)] = v;
175
+ }
176
+ tag(e) {
177
+ return this.table.col.tag[this.row(e)];
178
+ }
179
+ /** Has the entity's mover reached the end of its path (and stands)? */
180
+ standing(e) {
181
+ const m = this.mover(e);
182
+ if (m === 0)
183
+ return false;
184
+ return this.movers.info(m).state === MOVER_STATE.done;
185
+ }
186
+ spot(place) {
187
+ const p = this.places[place];
188
+ return [p.x ?? this.nav.nodeX[p.node], p.z ?? this.nav.nodeZ[p.node]];
189
+ }
190
+ spawnMover(e, def, at) {
191
+ const r = this.row(e);
192
+ const c = this.table.col;
193
+ const path = this.movers.paths.add(def, { owned: true });
194
+ const o = this.options.spawn?.(c.index[r]) ?? { cruise: 1.3, gap: 0.8 };
195
+ const id = this.movers.spawn({ ...o, path, at, tag: c.index[r] });
196
+ c.mover[r] = id;
197
+ return id;
198
+ }
199
+ /** Shows the entity standing at a point, facing `dirX, dirZ` (spawns its mover if it has none). */
200
+ show(e, x, z, dirX = 0, dirZ = 1) {
201
+ const def = { points: [x - dirX * 0.5, z - dirZ * 0.5, x, z] };
202
+ const m = this.mover(e);
203
+ if (m === 0)
204
+ this.spawnMover(e, def, 0.5);
205
+ else
206
+ this.movers.send(m, def, 0.5);
207
+ }
208
+ /** Removes the entity's mover (it goes inside, boards, leaves the map). */
209
+ hide(e) {
210
+ const r = this.row(e);
211
+ const c = this.table.col;
212
+ const m = c.mover[r];
213
+ if (m !== 0)
214
+ this.movers.remove(m);
215
+ c.mover[r] = 0;
216
+ }
217
+ /** Walks the entity in a straight line from where it is to a point. */
218
+ walkTo(e, x, z) {
219
+ const m = this.mover(e);
220
+ if (m === 0)
221
+ return;
222
+ const [px, pz] = this.movers.position(m);
223
+ if ((x - px) * (x - px) + (z - pz) * (z - pz) < 0.0025)
224
+ x += 0.05;
225
+ this.movers.send(m, { points: [px, pz, x, z] }, 0);
226
+ }
227
+ /** Puts the entity into `stay` at its current activity until `tick`; returns the state id for an `update`. */
228
+ stayUntil(e, tick) {
229
+ const r = this.row(e);
230
+ this.table.col.timer[r] = tick;
231
+ this.table.col.dep[r] = UNSET;
232
+ return this.STAY;
233
+ }
234
+ /** Ends the entity's agenda: hides it. Returns the state id for an `update`. */
235
+ finish(e) {
236
+ this.hide(e);
237
+ this.sim?.events.post('agenda.done', e);
238
+ return this.DONE;
239
+ }
240
+ /** Starts the trip to the next activity now (or ends the agenda); returns the state id for an `update`. */
241
+ leave(e, lateTicks = 0) {
242
+ const r = this.row(e);
243
+ const c = this.table.col;
244
+ const idx = c.index[r];
245
+ const from = this.first[idx] + c.act[r];
246
+ if (c.act[r] + 1 >= this.count[idx])
247
+ return this.finish(e);
248
+ const to = from + 1;
249
+ this.sim?.events.post('agenda.leave', e, { place: this.aPlace[from], activity: c.act[r] });
250
+ c.act[r] = c.act[r] + 1;
251
+ c.dep[r] = UNSET;
252
+ const def = this.route(this.aPlace[from], this.aPlace[to]);
253
+ if (!def) {
254
+ // No way there: the entity skips the trip and appears at the place (a gap in the data, reported as an event).
255
+ this.sim?.events.post('agenda.unreachable', e, { place: this.aPlace[to] });
256
+ this.hide(e);
257
+ return this.arrive(e);
258
+ }
259
+ const speed = mmPerTick(this.options.spawn?.(idx).cruise ?? 1.3, this.hz);
260
+ const at = Math.max(0, lateTicks) * speed;
261
+ const m = c.mover[r];
262
+ if (m === 0)
263
+ this.spawnMover(e, def, at / 1000);
264
+ else {
265
+ // Out of doors already: the trip starts where it stands.
266
+ const [px, pz] = this.movers.position(m);
267
+ const pts = [px, pz, ...def.points];
268
+ this.movers.send(m, { points: pts }, at / 1000);
269
+ }
270
+ return this.TRAVEL;
271
+ }
272
+ /**
273
+ * Moves the entity on to its next activity without a trip, as if it was carried there (it rides a vehicle, takes a
274
+ * lift): its mover is removed and the arrival at the next place runs at once (`onArrive`, or `stay`). Returns the
275
+ * state id for an `update`; ends the agenda at the last activity.
276
+ */
277
+ arriveNext(e) {
278
+ const r = this.row(e);
279
+ const c = this.table.col;
280
+ const idx = c.index[r];
281
+ if (c.act[r] + 1 >= this.count[idx])
282
+ return this.finish(e);
283
+ this.sim?.events.post('agenda.leave', e, { place: this.aPlace[this.first[idx] + c.act[r]], activity: c.act[r] });
284
+ c.act[r] = c.act[r] + 1;
285
+ c.dep[r] = UNSET;
286
+ this.hide(e);
287
+ return this.arrive(e);
288
+ }
289
+ /** Route between two places as a path definition (spots at both ends), or null when there is none. */
290
+ route(from, to) {
291
+ const a = this.places[from];
292
+ const b = this.places[to];
293
+ const [ax, az] = this.spot(from);
294
+ const [bx, bz] = this.spot(to);
295
+ const pts = [ax, az];
296
+ if (a.node !== b.node) {
297
+ const edges = this.nav.findPath(a.node, b.node);
298
+ if (!edges || edges.length === 0)
299
+ return null;
300
+ const def = this.nav.path(edges, { rightOffset: this.options.rightOffset ?? 0 });
301
+ pts.push(...def.points);
302
+ }
303
+ pts.push(bx, bz);
304
+ // Drop points closer than 5 cm to the previous one.
305
+ const out = [pts[0], pts[1]];
306
+ for (let i = 2; i < pts.length; i += 2) {
307
+ const dx = pts[i] - out[out.length - 2];
308
+ const dz = pts[i + 1] - out[out.length - 1];
309
+ if (dx * dx + dz * dz >= 0.0025)
310
+ out.push(pts[i], pts[i + 1]);
311
+ }
312
+ if (out.length < 4)
313
+ out.push(out[0] + 0.05, out[1]);
314
+ return { points: out };
315
+ }
316
+ /** Walking length of a route between two places, metres (straight line when there is no route). */
317
+ routeLength(from, to) {
318
+ const def = this.route(from, to);
319
+ if (!def)
320
+ return 0;
321
+ let l = 0;
322
+ for (let i = 2; i < def.points.length; i += 2) {
323
+ const dx = def.points[i] - def.points[i - 2];
324
+ const dz = def.points[i + 1] - def.points[i - 1];
325
+ l += Math.sqrt(dx * dx + dz * dz);
326
+ }
327
+ return l;
328
+ }
329
+ /** Arrival at the current activity's place: the app's hook or `stay`. */
330
+ arrive(e) {
331
+ const r = this.row(e);
332
+ const c = this.table.col;
333
+ const i = this.first[c.index[r]] + c.act[r];
334
+ this.sim?.events.post('agenda.arrive', e, { place: this.aPlace[i], activity: c.act[r] });
335
+ const s = this.options.onArrive?.(e, this);
336
+ if (s !== undefined)
337
+ return s;
338
+ if (this.places[this.aPlace[i]].inside)
339
+ this.hide(e);
340
+ return this.stayUntil(e, this.now + this.aStay[i]);
341
+ }
342
+ updateBefore(e) {
343
+ const r = this.row(e);
344
+ const c = this.table.col;
345
+ const i = this.first[c.index[r]];
346
+ if (this.now < this.aAt[i])
347
+ return;
348
+ this.sim?.events.post('agenda.appear', e, { place: this.aPlace[i], activity: 0 });
349
+ const s = this.options.onAppear?.(e, this);
350
+ if (s !== undefined)
351
+ return s;
352
+ const place = this.places[this.aPlace[i]];
353
+ if (!place.inside) {
354
+ const [x, z] = this.spot(this.aPlace[i]);
355
+ this.show(e, x, z);
356
+ }
357
+ return this.stayUntil(e, this.aAt[i] + this.aStay[i]);
358
+ }
359
+ /** When the trip to the next activity is due (tick), or null at the last one. */
360
+ departure(e) {
361
+ const r = this.row(e);
362
+ const c = this.table.col;
363
+ const idx = c.index[r];
364
+ const k = c.act[r] + 1;
365
+ if (k >= this.count[idx])
366
+ return null;
367
+ const i = this.first[idx] + k;
368
+ if (!this.aArrive[i])
369
+ return this.aAt[i];
370
+ if (c.dep[r] === UNSET) {
371
+ // Arrive by `at`: leave the walking time earlier (route length at the entity's speed).
372
+ const len = this.routeLength(this.aPlace[i - 1], this.aPlace[i]);
373
+ const speed = this.options.spawn?.(idx).cruise ?? 1.3;
374
+ c.dep[r] = this.aAt[i] - Math.ceil((len / speed) * this.hz);
375
+ }
376
+ return c.dep[r];
377
+ }
378
+ updateStay(e) {
379
+ const end = this.timer(e);
380
+ const dep = this.departure(e);
381
+ if (dep === null) {
382
+ if (this.now >= end)
383
+ return this.finish(e);
384
+ return;
385
+ }
386
+ const leave = Math.max(end, dep);
387
+ if (this.now < leave)
388
+ return;
389
+ return this.leave(e, this.now - leave);
390
+ }
391
+ updateTravel(e) {
392
+ const m = this.mover(e);
393
+ if (m !== 0 && this.movers.info(m).state !== MOVER_STATE.done)
394
+ return;
395
+ return this.arrive(e);
396
+ }
397
+ /** The system: one tick of every agenda. Register it after the movers' system. */
398
+ system = (sim) => {
399
+ this.sim = sim;
400
+ const c = this.table.col;
401
+ // Rows can be removed by nobody but the app; iterate by id order of the rows at the start of the tick.
402
+ const ids = Array.from(this.table.ids.subarray(0, this.table.count));
403
+ for (const e of ids) {
404
+ const r = this.table.rowOf(e);
405
+ if (r < 0)
406
+ continue;
407
+ const s = c.state[r];
408
+ if (s === this.DONE)
409
+ continue;
410
+ const next = this.states.step(e, s, this);
411
+ const r2 = this.table.rowOf(e);
412
+ if (r2 >= 0)
413
+ c.state[r2] = next;
414
+ }
415
+ };
416
+ save(w) {
417
+ w.u32(this.aPlace.length);
418
+ this.table.save(w);
419
+ }
420
+ load(r) {
421
+ if (r.u32() !== this.aPlace.length)
422
+ throw new Error('Agendas: the snapshot has other activities than this setup');
423
+ this.table.load(r);
424
+ }
425
+ }
@@ -0,0 +1,34 @@
1
+ /** Growable little-endian byte buffer. */
2
+ export declare class ByteWriter {
3
+ private buf;
4
+ private view;
5
+ private at;
6
+ private room;
7
+ get length(): number;
8
+ u8(v: number): void;
9
+ i32(v: number): void;
10
+ u32(v: number): void;
11
+ /** A 64-bit float; used for ids (integers below 2^53) and for app-supplied geometry. */
12
+ f64(v: number): void;
13
+ str(s: string): void;
14
+ /** The raw bytes of a typed array (no length prefix). */
15
+ bytes(a: ArrayBufferView): void;
16
+ /** A copy of what was written. */
17
+ finish(): Uint8Array;
18
+ }
19
+ export declare class ByteReader {
20
+ private readonly bytesIn;
21
+ private readonly view;
22
+ private at;
23
+ constructor(bytes: Uint8Array);
24
+ get done(): boolean;
25
+ u8(): number;
26
+ i32(): number;
27
+ u32(): number;
28
+ f64(): number;
29
+ str(): string;
30
+ /** Copies `target.byteLength` bytes into a typed array. */
31
+ into(target: ArrayBufferView): void;
32
+ }
33
+ /** 64-bit hash of bytes as 16 hex digits: two independent 32-bit FNV-1a lanes with a final avalanche. */
34
+ export declare function hashBytes(bytes: Uint8Array): string;