roamwright 0.20.1 → 0.54.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 (516) hide show
  1. package/.prettierrc.yaml +12 -0
  2. package/CONTRIBUTING.md +19 -14
  3. package/README.md +35 -16
  4. package/examples/animals.html +49 -0
  5. package/examples/animals.js +209 -0
  6. package/examples/crowds.html +50 -0
  7. package/examples/crowds.js +268 -0
  8. package/examples/effects.html +53 -0
  9. package/examples/effects.js +343 -0
  10. package/examples/figure-motion.html +55 -0
  11. package/examples/figure-motion.js +265 -0
  12. package/examples/figure.html +49 -0
  13. package/examples/figure.js +238 -0
  14. package/examples/fliers.html +53 -0
  15. package/examples/fliers.js +292 -0
  16. package/examples/fortification.html +54 -0
  17. package/examples/fortification.js +288 -0
  18. package/examples/house-kit.html +48 -0
  19. package/examples/house-kit.js +175 -0
  20. package/examples/index.html +26 -16
  21. package/examples/island.html +48 -0
  22. package/examples/island.js +134 -52
  23. package/examples/land.html +54 -0
  24. package/examples/land.js +392 -0
  25. package/examples/props-and-plants.html +53 -0
  26. package/examples/props-and-plants.js +275 -0
  27. package/examples/rooms.html +48 -0
  28. package/examples/rooms.js +242 -0
  29. package/examples/ships.html +51 -0
  30. package/examples/ships.js +235 -0
  31. package/examples/showcase.css +320 -0
  32. package/examples/small-world-land.js +151 -0
  33. package/examples/small-world-life.js +160 -0
  34. package/examples/small-world-town.js +127 -0
  35. package/examples/small-world.html +57 -0
  36. package/examples/small-world.js +226 -0
  37. package/examples/soundscape.html +138 -0
  38. package/examples/soundscape.js +467 -0
  39. package/examples/stage-kits.js +300 -0
  40. package/examples/stage.js +374 -0
  41. package/examples/towns.html +50 -0
  42. package/examples/towns.js +325 -0
  43. package/examples/viaduct-camera.js +8 -4
  44. package/examples/viaduct-landscape.js +28 -17
  45. package/examples/viaduct.html +45 -43
  46. package/examples/viaduct.js +68 -92
  47. package/geometry/animal-camel-body.js +410 -0
  48. package/geometry/animal-camel-head.js +118 -0
  49. package/geometry/animal-canine-body.js +361 -0
  50. package/geometry/animal-canine-breeds.js +316 -0
  51. package/geometry/animal-canine-head.js +337 -0
  52. package/geometry/animal-cattle-body.js +391 -0
  53. package/geometry/animal-cattle-coat.js +42 -0
  54. package/geometry/animal-cattle-head.js +152 -0
  55. package/geometry/animal-hen.js +248 -0
  56. package/geometry/animal-horse-body.js +446 -0
  57. package/geometry/animal-horse-bridle.js +171 -0
  58. package/geometry/animal-horse-coat.js +68 -0
  59. package/geometry/animal-horse-face.js +162 -0
  60. package/geometry/animal-horse-hair.js +304 -0
  61. package/geometry/animal-horse-head.js +133 -0
  62. package/geometry/animal-horse-tack.js +157 -0
  63. package/geometry/animal-options.js +59 -0
  64. package/geometry/animal-shapes.js +21 -0
  65. package/geometry/animal-skin.js +390 -0
  66. package/geometry/builder-cells.js +10 -2
  67. package/geometry/builder-frame.js +2 -1
  68. package/geometry/builder.js +15 -4
  69. package/geometry/card-emblem.js +437 -0
  70. package/geometry/catenary-canvas.js +396 -0
  71. package/geometry/cloth-folds.js +143 -0
  72. package/geometry/crawl-shapes.js +71 -0
  73. package/geometry/creased-sheet.js +7 -2
  74. package/geometry/crowd-dress.js +315 -0
  75. package/geometry/crowd-far.js +174 -0
  76. package/geometry/crowd-look.js +42 -0
  77. package/geometry/crowd-weld.js +218 -0
  78. package/geometry/ear.js +9 -4
  79. package/geometry/erosion.js +7 -4
  80. package/geometry/face-grid.js +26 -6
  81. package/geometry/field-map.js +59 -0
  82. package/geometry/figure-arms.js +339 -0
  83. package/geometry/figure-beard.js +250 -0
  84. package/geometry/figure-body.js +297 -0
  85. package/geometry/figure-bow.js +105 -0
  86. package/geometry/figure-cloak.js +189 -0
  87. package/geometry/figure-clothes.js +337 -0
  88. package/geometry/figure-face-grids.js +75 -0
  89. package/geometry/figure-gear.js +446 -0
  90. package/geometry/figure-hair-far.js +151 -0
  91. package/geometry/figure-hair-hangs.js +108 -0
  92. package/geometry/figure-hair-patch.js +66 -0
  93. package/geometry/figure-hair.js +320 -0
  94. package/geometry/figure-hands.js +321 -0
  95. package/geometry/figure-head-features.js +280 -0
  96. package/geometry/figure-head.js +375 -0
  97. package/geometry/figure-headwear.js +223 -0
  98. package/geometry/figure-legs.js +231 -0
  99. package/geometry/figure-limbs.js +39 -0
  100. package/geometry/figure-sculpt.js +82 -0
  101. package/geometry/figure-skin.js +97 -0
  102. package/geometry/figure-skirts.js +303 -0
  103. package/geometry/figure-trunk.js +411 -0
  104. package/geometry/flier-corvid-body.js +322 -0
  105. package/geometry/flier-corvid-wings.js +154 -0
  106. package/geometry/flier-long-body.js +195 -0
  107. package/geometry/flier-shapes.js +219 -0
  108. package/geometry/flier-soaring-bird.js +84 -0
  109. package/geometry/foliage.js +177 -4
  110. package/geometry/fort-city-walls.js +479 -0
  111. package/geometry/fort-gate-approach.js +233 -0
  112. package/geometry/fort-great-walls.js +280 -0
  113. package/geometry/fort-keep.js +297 -0
  114. package/geometry/fort-parts.js +261 -0
  115. package/geometry/fort-polyline.js +261 -0
  116. package/geometry/fort-portal.js +96 -0
  117. package/geometry/fort-ring-wall.js +267 -0
  118. package/geometry/fort-seawall.js +104 -0
  119. package/geometry/fort-terrace-gates.js +323 -0
  120. package/geometry/fort-terrace-plan.js +250 -0
  121. package/geometry/fort-terrace-wall.js +345 -0
  122. package/geometry/garment-tags.js +11 -3
  123. package/geometry/grid-gather.js +69 -0
  124. package/geometry/grid-sample.js +185 -0
  125. package/geometry/hair-gathers.js +19 -4
  126. package/geometry/hair-locks.js +1 -1
  127. package/geometry/hair-patch.js +6 -2
  128. package/geometry/hair-shell.js +14 -2
  129. package/geometry/head-presets.js +103 -0
  130. package/geometry/head-profile.js +13 -2
  131. package/geometry/head-shape.js +51 -23
  132. package/geometry/heightfield.js +26 -9
  133. package/geometry/horizon-angles.js +166 -0
  134. package/geometry/house-kit-body.js +195 -0
  135. package/geometry/house-kit-courtyard-parts.js +340 -0
  136. package/geometry/house-kit-courtyard-roof.js +223 -0
  137. package/geometry/house-kit-courtyard.js +409 -0
  138. package/geometry/house-kit-cut.js +29 -0
  139. package/geometry/house-kit-extras.js +192 -0
  140. package/geometry/house-kit-forms.js +298 -0
  141. package/geometry/house-kit-frame.js +74 -0
  142. package/geometry/house-kit-marks.js +93 -0
  143. package/geometry/house-kit-openings.js +193 -0
  144. package/geometry/house-kit-palette.js +54 -0
  145. package/geometry/house-kit-pool.js +71 -0
  146. package/geometry/house-kit-roofs.js +151 -0
  147. package/geometry/house-kit.js +202 -0
  148. package/geometry/instances.js +4 -4
  149. package/geometry/lamp-wash.js +65 -0
  150. package/geometry/land-clearings.js +83 -0
  151. package/geometry/land-ditches.js +290 -0
  152. package/geometry/land-dry-basin.js +327 -0
  153. package/geometry/land-dunes.js +150 -0
  154. package/geometry/land-earthworks.js +432 -0
  155. package/geometry/land-edge.js +292 -0
  156. package/geometry/land-mound-faces.js +349 -0
  157. package/geometry/land-near-relief.js +102 -0
  158. package/geometry/land-sheet.js +220 -0
  159. package/geometry/land-town-ground.js +256 -0
  160. package/geometry/land-waters.js +228 -0
  161. package/geometry/land-wildness.js +123 -0
  162. package/geometry/lathed-vessel.js +293 -0
  163. package/geometry/outline-grid.js +5 -4
  164. package/geometry/outline-segments.js +74 -0
  165. package/geometry/part-ranges.js +35 -0
  166. package/geometry/path-field.js +35 -1
  167. package/geometry/planked-floor.js +149 -0
  168. package/geometry/plant-broadleaf.js +268 -0
  169. package/geometry/plant-shrub.js +198 -0
  170. package/geometry/plant-tints.js +80 -0
  171. package/geometry/plant-trees.js +453 -0
  172. package/geometry/plant-tussock.js +107 -0
  173. package/geometry/primitives.js +65 -23
  174. package/geometry/prop-battlefield.js +69 -0
  175. package/geometry/prop-camp.js +175 -0
  176. package/geometry/prop-door.js +26 -0
  177. package/geometry/prop-harbour.js +105 -0
  178. package/geometry/prop-haycock.js +60 -0
  179. package/geometry/prop-sacks.js +74 -0
  180. package/geometry/prop-sheaf.js +68 -0
  181. package/geometry/prop-street.js +69 -0
  182. package/geometry/prop-tents.js +396 -0
  183. package/geometry/prop-tombs.js +80 -0
  184. package/geometry/prop-trade.js +393 -0
  185. package/geometry/prop-vehicles.js +218 -0
  186. package/geometry/props.js +58 -0
  187. package/geometry/room-arcade.js +134 -0
  188. package/geometry/room-dome.js +188 -0
  189. package/geometry/room-flames.js +138 -0
  190. package/geometry/room-frame.js +106 -0
  191. package/geometry/room-furniture.js +260 -0
  192. package/geometry/room-hearth.js +98 -0
  193. package/geometry/room-kit.js +59 -0
  194. package/geometry/room-openings.js +142 -0
  195. package/geometry/room-stairs.js +180 -0
  196. package/geometry/room-surfaces.js +272 -0
  197. package/geometry/sampled-surface.js +24 -10
  198. package/geometry/scatter-grid.js +6 -3
  199. package/geometry/sculpt.js +5 -1
  200. package/geometry/ship-fittings.js +350 -0
  201. package/geometry/ship-hull.js +460 -0
  202. package/geometry/ship-kit.js +208 -0
  203. package/geometry/ship-lines.js +69 -0
  204. package/geometry/ship-oars.js +150 -0
  205. package/geometry/ship-presets.js +131 -0
  206. package/geometry/ship-rig.js +374 -0
  207. package/geometry/ship-sails.js +148 -0
  208. package/geometry/shore-grid.js +5 -1
  209. package/geometry/strata-field.js +44 -11
  210. package/geometry/strata-tiles.js +20 -6
  211. package/geometry/stream.js +32 -17
  212. package/geometry/swept-tube.js +124 -0
  213. package/geometry/terrain-chunks.js +139 -51
  214. package/geometry/terrain-extension.js +24 -8
  215. package/geometry/town-courtyard-inn.js +272 -0
  216. package/geometry/town-ground.js +76 -0
  217. package/geometry/town-houses.js +343 -0
  218. package/geometry/town-lights.js +254 -0
  219. package/geometry/town-lots.js +172 -0
  220. package/geometry/town-plan.js +370 -0
  221. package/geometry/town-works.js +465 -0
  222. package/geometry/village-layout.js +181 -0
  223. package/geometry/village-yards.js +167 -0
  224. package/geometry/wall-runs.js +64 -0
  225. package/index.js +134 -3
  226. package/math/cloud-textures.js +3 -7
  227. package/math/curve.js +5 -1
  228. package/math/lamp-texels.js +43 -0
  229. package/math/lit-share.js +22 -0
  230. package/math/mountain-ranges.js +177 -54
  231. package/math/periodic.js +6 -0
  232. package/math/rectangles.js +8 -2
  233. package/math/rock-texture.js +17 -12
  234. package/math/surface-textures.js +24 -9
  235. package/math/wandering-path.js +40 -0
  236. package/math/ways.js +120 -0
  237. package/motion/action-dynamics.js +398 -0
  238. package/motion/animal-bearing.js +247 -0
  239. package/motion/animal-canine-bearing.js +178 -0
  240. package/motion/animal-canine-cast.js +131 -0
  241. package/motion/animal-cattle-cast.js +64 -0
  242. package/motion/animal-herd-cast.js +154 -0
  243. package/motion/animal-horse-still.js +161 -0
  244. package/motion/animal-troop-cast.js +43 -0
  245. package/motion/arm-reach.js +3 -2
  246. package/motion/ballistic-arc.js +182 -2
  247. package/motion/biped-cycle.js +4 -2
  248. package/motion/biped-leg.js +4 -1
  249. package/motion/biped-posture.js +459 -0
  250. package/motion/biped-stride.js +142 -32
  251. package/motion/boat-sailing.js +214 -0
  252. package/motion/contact-transition.js +5 -6
  253. package/motion/crowd-alarms.js +36 -6
  254. package/motion/crowd-attention.js +108 -0
  255. package/motion/crowd-beasts.js +203 -0
  256. package/motion/crowd-camp.js +295 -0
  257. package/motion/crowd-figure.js +100 -0
  258. package/motion/crowd-herd.js +86 -0
  259. package/motion/crowd-hold.js +130 -0
  260. package/motion/crowd-pose.js +296 -0
  261. package/motion/crowd-poses.js +481 -0
  262. package/motion/crowd-routine.js +44 -14
  263. package/motion/crowd-town.js +166 -0
  264. package/motion/crowd-water.js +143 -0
  265. package/motion/deck-surface.js +4 -2
  266. package/motion/figure-acts.js +411 -0
  267. package/motion/figure-arms.js +437 -0
  268. package/motion/figure-blade-slide.js +149 -0
  269. package/motion/figure-body-place.js +180 -0
  270. package/motion/figure-bones.js +118 -0
  271. package/motion/figure-bow-draw.js +70 -0
  272. package/motion/figure-fingers.js +215 -0
  273. package/motion/figure-gaze.js +205 -0
  274. package/motion/figure-gestures.js +452 -0
  275. package/motion/figure-grip.js +134 -0
  276. package/motion/figure-head.js +287 -0
  277. package/motion/figure-legs.js +264 -0
  278. package/motion/figure-links.js +293 -0
  279. package/motion/figure-locomotion.js +391 -0
  280. package/motion/figure-mount-up.js +180 -0
  281. package/motion/figure-mount.js +201 -0
  282. package/motion/figure-pose-frame.js +375 -0
  283. package/motion/figure-pose-table.js +156 -0
  284. package/motion/figure-pose.js +343 -0
  285. package/motion/figure-seat.js +267 -0
  286. package/motion/figure-sway.js +125 -0
  287. package/motion/flier-corvid-pose.js +74 -0
  288. package/motion/flier-flight-air.js +122 -0
  289. package/motion/flier-flight-echelon.js +164 -0
  290. package/motion/flier-flight-roost.js +131 -0
  291. package/motion/flier-swarm-flight.js +252 -0
  292. package/motion/formation.js +193 -0
  293. package/motion/instance-sight.js +8 -1
  294. package/motion/melee-contact.js +143 -0
  295. package/motion/moorings.js +48 -0
  296. package/motion/path-steering.js +358 -0
  297. package/motion/player.js +7 -6
  298. package/motion/quadruped.js +109 -33
  299. package/motion/spaces.js +58 -6
  300. package/motion/speech-cadence.js +304 -0
  301. package/motion/vessel-motion.js +57 -0
  302. package/motion/walk-grid.js +235 -0
  303. package/motion/weather.js +70 -12
  304. package/motion/wind.js +27 -1
  305. package/package.json +27 -4
  306. package/rendering/alpha-mips.js +340 -0
  307. package/rendering/animal-camel-figure.js +29 -0
  308. package/rendering/animal-canine-figure.js +59 -0
  309. package/rendering/animal-cattle-figure.js +36 -0
  310. package/rendering/animal-horse-figure.js +49 -0
  311. package/rendering/atmosphere.js +86 -0
  312. package/rendering/camera-track.js +156 -0
  313. package/rendering/{road-surface.js → cart-track.js} +40 -11
  314. package/rendering/caster-motion.js +2 -1
  315. package/rendering/cell-lod-options.js +46 -0
  316. package/rendering/cell-lod.js +665 -80
  317. package/rendering/cloth-material.js +140 -0
  318. package/rendering/cloud-dome.js +2 -2
  319. package/rendering/compilation-schedule.js +18 -10
  320. package/rendering/contact-shadows.js +5 -2
  321. package/rendering/context.js +47 -8
  322. package/rendering/crowd-batches.js +420 -0
  323. package/rendering/crowd-herd.js +198 -0
  324. package/rendering/crowd-rig.js +132 -0
  325. package/rendering/crowd-skinning.js +52 -9
  326. package/rendering/crowd-update.js +419 -0
  327. package/rendering/crowd-visibility.js +107 -0
  328. package/rendering/day-cycle-defaults.js +200 -0
  329. package/rendering/day-cycle.js +487 -0
  330. package/rendering/daylight.js +1 -3
  331. package/rendering/detail-range.js +6 -5
  332. package/rendering/dof.js +11 -4
  333. package/rendering/effects-frame.js +149 -0
  334. package/rendering/effects-water-rises.js +221 -0
  335. package/rendering/energy-stream.js +128 -0
  336. package/rendering/facade-glass-material.js +105 -0
  337. package/rendering/far-shadow.js +81 -54
  338. package/rendering/field-surface.js +138 -0
  339. package/rendering/figure-shield.js +105 -0
  340. package/rendering/figure-skeleton.js +329 -0
  341. package/rendering/fire-light-watch.js +197 -0
  342. package/rendering/fire-pools.js +148 -0
  343. package/rendering/flame-sources.js +86 -0
  344. package/rendering/flier-bird-looks.js +97 -0
  345. package/rendering/flier-corvid-figure.js +67 -0
  346. package/rendering/flier-long-body-company.js +169 -0
  347. package/rendering/flier-swarm.js +186 -0
  348. package/rendering/flocks.js +6 -2
  349. package/rendering/garment-material.js +145 -49
  350. package/rendering/glsl-literal.js +19 -0
  351. package/rendering/ground-marks.js +316 -0
  352. package/rendering/hair-strands.js +38 -24
  353. package/rendering/height-haze.js +80 -33
  354. package/rendering/height-probe.js +15 -3
  355. package/rendering/house-kit-meshes.js +124 -0
  356. package/rendering/interior-bake.js +807 -0
  357. package/rendering/label-layout.js +13 -3
  358. package/rendering/label-range.js +5 -2
  359. package/rendering/lamp-light-map.js +159 -0
  360. package/rendering/lamp-maps.js +62 -0
  361. package/rendering/lamp-wash.js +51 -0
  362. package/rendering/light-budget.js +19 -3
  363. package/rendering/light-points.js +21 -5
  364. package/rendering/local-lights.js +27 -7
  365. package/rendering/material-lod.js +5 -6
  366. package/rendering/memory-estimate.js +84 -0
  367. package/rendering/moored-fleet.js +186 -0
  368. package/rendering/part-costs.js +104 -0
  369. package/rendering/particle-bursts.js +386 -0
  370. package/rendering/particle-emitters.js +61 -25
  371. package/rendering/particle-light-bursts.js +189 -0
  372. package/rendering/particles.js +134 -34
  373. package/rendering/pen-flocks.js +118 -0
  374. package/rendering/piece-batch.js +282 -6
  375. package/rendering/planar-reflection-options.js +159 -0
  376. package/rendering/planar-reflection.js +780 -77
  377. package/rendering/plant-cells.js +122 -0
  378. package/rendering/plant-reeds.js +113 -0
  379. package/rendering/plant-shade-trees.js +239 -0
  380. package/rendering/plant-tuft-patch.js +122 -0
  381. package/rendering/post-shaders.js +84 -21
  382. package/rendering/post.js +39 -19
  383. package/rendering/pressed-cover.js +135 -0
  384. package/rendering/prop-dig.js +136 -0
  385. package/rendering/room-light.js +250 -0
  386. package/rendering/room-materials.js +78 -0
  387. package/rendering/room-space.js +111 -0
  388. package/rendering/scene-lights.js +106 -0
  389. package/rendering/sea-shaders.js +83 -26
  390. package/rendering/settlement-approach.js +226 -0
  391. package/rendering/settlement-dissolve.js +89 -0
  392. package/rendering/settlement-quarter-warm.js +55 -0
  393. package/rendering/settlement-quarter.js +477 -0
  394. package/rendering/settlement-switch.js +42 -0
  395. package/rendering/settlement-town.js +110 -0
  396. package/rendering/shader-warmup.js +80 -36
  397. package/rendering/shadow-depth.js +40 -18
  398. package/rendering/ship-meshes.js +150 -0
  399. package/rendering/shot-cuts.js +68 -0
  400. package/rendering/sky-occlusion.js +42 -15
  401. package/rendering/sky-pmrem.js +216 -0
  402. package/rendering/sky.js +112 -50
  403. package/rendering/smoke-shadows.js +201 -0
  404. package/rendering/stage-framing.js +182 -0
  405. package/rendering/stage-lights.js +46 -39
  406. package/rendering/stain-material.js +74 -0
  407. package/rendering/static-point-shadow.js +62 -23
  408. package/rendering/still-casters.js +77 -27
  409. package/rendering/strata-material.js +2 -2
  410. package/rendering/street-lamps.js +166 -0
  411. package/rendering/sunbeam-motes.js +670 -0
  412. package/rendering/surface-light.js +65 -6
  413. package/rendering/surface-material.js +306 -0
  414. package/rendering/surface-projection.js +32 -0
  415. package/rendering/surface-snippets.js +314 -0
  416. package/rendering/taa.js +49 -18
  417. package/rendering/tree-impostor.js +929 -0
  418. package/rendering/vehicle-train.js +92 -0
  419. package/rendering/viewport.js +67 -4
  420. package/rendering/water-material.js +270 -82
  421. package/rendering/waypoint-beacons.js +191 -0
  422. package/rendering/world-matrices.js +0 -2
  423. package/ruff.toml +20 -0
  424. package/runtime/cue-cursor.js +21 -0
  425. package/runtime/device-quality.js +13 -2
  426. package/runtime/device.js +73 -0
  427. package/runtime/diagnostic-log.js +11 -3
  428. package/runtime/effect-sites.js +85 -0
  429. package/runtime/figure-orders.js +59 -0
  430. package/runtime/first-use.js +8 -5
  431. package/runtime/foley-script.js +124 -0
  432. package/runtime/foley-strides.js +333 -0
  433. package/runtime/frame-pacing.js +18 -4
  434. package/runtime/frame-yield.js +18 -0
  435. package/runtime/gpu-timing.js +8 -4
  436. package/runtime/grid-cache.js +16 -6
  437. package/runtime/grid-rows.js +5 -5
  438. package/runtime/hand-over.js +7 -2
  439. package/runtime/land-bake.js +78 -0
  440. package/runtime/lazy-sets.js +105 -0
  441. package/runtime/pool.js +17 -3
  442. package/runtime/quality-fit.js +59 -27
  443. package/runtime/region-pass-lay.js +40 -0
  444. package/runtime/region-pass.js +78 -0
  445. package/runtime/search.js +6 -2
  446. package/runtime/settlement-reach.js +42 -0
  447. package/runtime/sound-calls.js +113 -0
  448. package/runtime/sound-impacts.js +297 -0
  449. package/runtime/sound-voices.js +194 -0
  450. package/runtime/soundscape.js +282 -0
  451. package/runtime/spatial-audio.js +69 -20
  452. package/runtime/steady-frames.js +221 -0
  453. package/runtime/withdrawable-task.js +19 -8
  454. package/scripts/app-parts.mjs +118 -0
  455. package/scripts/bake-revisions.mjs +81 -0
  456. package/scripts/browser-scripts.mjs +64 -0
  457. package/scripts/bundle.mjs +192 -0
  458. package/scripts/check-app.sh +26 -0
  459. package/scripts/eslint-config.mjs +119 -0
  460. package/scripts/format.sh +92 -0
  461. package/scripts/keep-builds.mjs +158 -0
  462. package/scripts/layers.mjs +112 -0
  463. package/scripts/lint.sh +49 -0
  464. package/scripts/module-graph.mjs +123 -0
  465. package/scripts/pre-commit.sh +38 -0
  466. package/scripts/serve.py +5 -3
  467. package/scripts/site.mjs +358 -0
  468. package/scripts/test-runner.sh +42 -0
  469. package/scripts/vendor.mjs +221 -0
  470. package/scripts/verify-publish.mjs +175 -0
  471. package/scripts/world.mk +59 -0
  472. package/tools/README.md +73 -0
  473. package/tools/contact-sheet.cjs +137 -0
  474. package/tools/cpu-profile.cjs +275 -0
  475. package/tools/cpu-profile.test.cjs +98 -0
  476. package/tools/first-draws.cjs +395 -0
  477. package/tools/flight-guard.cjs +482 -0
  478. package/tools/flight-guard.test.cjs +153 -0
  479. package/tools/flight-profile.cjs +145 -0
  480. package/tools/frame-bench.cjs +336 -0
  481. package/tools/frame-parts.cjs +365 -0
  482. package/tools/ios-sim.sh +145 -0
  483. package/tools/load-audit.cjs +201 -0
  484. package/tools/look-compare.cjs +304 -0
  485. package/tools/look-guard.cjs +407 -0
  486. package/tools/look-guard.test.cjs +93 -0
  487. package/tools/look-stats.cjs +185 -0
  488. package/tools/look-stats.test.cjs +71 -0
  489. package/tools/memory-audit.cjs +323 -0
  490. package/tools/page-driver.cjs +320 -0
  491. package/tools/page-driver.test.cjs +219 -0
  492. package/tools/program-census-report.cjs +191 -0
  493. package/tools/program-census.cjs +465 -0
  494. package/tools/program-census.test.cjs +332 -0
  495. package/tools/remote-runner.sh +265 -0
  496. package/tools/runners.test.cjs +59 -0
  497. package/tools/scene-audit-beat.cjs +344 -0
  498. package/tools/scene-audit-sheet.cjs +282 -0
  499. package/tools/scene-audit.cjs +471 -0
  500. package/tools/scene-audit.test.cjs +201 -0
  501. package/tools/scene-batch.cjs +219 -0
  502. package/tools/scene-bench.cjs +149 -0
  503. package/tools/scene-bench.test.cjs +33 -0
  504. package/tools/scene-run.cjs +443 -0
  505. package/tools/scene-run.test.cjs +94 -0
  506. package/tools/servers.sh +59 -0
  507. package/tools/shader-arrival.cjs +316 -0
  508. package/tools/shader-renewal.cjs +53 -0
  509. package/tools/shader-renewal.test.cjs +115 -0
  510. package/tools/speed-guard.cjs +258 -0
  511. package/tools/stills.cjs +492 -0
  512. package/tools/stills.test.cjs +49 -0
  513. package/tools/turns.sh +7 -0
  514. package/tools/yaml.cjs +158 -0
  515. package/examples/viaduct.css +0 -75
  516. package/rendering/light-shafts.js +0 -131
@@ -0,0 +1,320 @@
1
+ // The headless page driver: what every tool that opens a world's built page starts from. It finds Playwright and a headless
2
+ // Chrome shell on this machine, launches on the graphics card, prints the page's own log and the card's warnings when the
3
+ // browser closes, offers a switch inside the page's shaders, and stops a run that has gone on too long.
4
+ //
5
+ // const { chromium, shell, BASE, OUT, GPU } = require('roamwright/tools/page-driver.cjs').createPageDriver({ env: 'MYWORLD', debug: 'APP' });
6
+ // const browser = await chromium.launch({ executablePath: shell, ...GPU });
7
+ //
8
+ // A world's tools make one driver in a file of their own and take everything from it. Environment variables, with the world's
9
+ // prefix: <ENV>_PW (Playwright's folder), <ENV>_SHELL (the headless shell), <ENV>_BASE (the page's address), <ENV>_OUT (where
10
+ // stills and reports go), <ENV>_VERBOSE (plain notes of the log too), <ENV>_MOST_S (seconds a run may last).
11
+ 'use strict';
12
+ const fs = require('fs'),
13
+ os = require('os'),
14
+ path = require('path');
15
+
16
+ function npxCached(name) {
17
+ const root = path.join(os.homedir(), '.npm', '_npx');
18
+ try {
19
+ return fs.readdirSync(root).map(entry => path.join(root, entry, 'node_modules', name));
20
+ } catch {
21
+ return [];
22
+ }
23
+ }
24
+
25
+ /**
26
+ * Makes a page driver.
27
+ *
28
+ * @param {object} [options]
29
+ * @param {string} [options.env='ROAMWRIGHT'] The prefix of the environment variables that override what is found.
30
+ * @param {string} [options.debug='APP'] The name of the page's debug object (`window[debug]`): its `log()`, `state`, and `clearCamera()` are read.
31
+ * @param {string} [options.base='http://localhost:8765/'] The built page's address unless <ENV>_BASE names another.
32
+ * @param {string} [options.out] Where stills and reports go unless <ENV>_OUT says (the current folder's `out`).
33
+ * @param {string[]} [options.playwright] Folders to look for Playwright in first (a checkout's `node_modules/playwright`);
34
+ * npx's cache is looked in after them.
35
+ * @param {string[]} [options.shells] More folders of headless shells, beside `~/.cache/puppeteer/chrome-headless-shell`.
36
+ * @param {string} [options.skipNotes] Plain notes of the log that begin with this are not printed (a visit's own line).
37
+ * @param {string} [options.storagePrefix] LocalStorage key prefix (e.g. `'myworld'` for `myworld:quality`). Defaults to `env.toLowerCase()`.
38
+ * @param {string} [options.titleId='t-enter'] Element id shown when the title screen is ready for entry.
39
+ * @param {string} [options.startId='start'] Default button id clicked to enter the world from the title screen.
40
+ * @param {string} [options.crossingClass='crossing'] Body class present when a direct address enters without the title screen.
41
+ * @param {string} [options.canvasSelector='#c'] CSS selector of the WebGL canvas element.
42
+ * @returns {{ chromium: object, shell: string, BASE: string, OUT: string, GPU: object, env: string, debug: string,
43
+ * storagePrefix: string, canvasSelector: string, printLog: Function, installCuts: Function, longRun: Function,
44
+ * enter: Function, routeUrl: Function, clearView: Function, closeBrowser: Function, applyStorage: Function }}
45
+ */
46
+ function createPageDriver({
47
+ env = 'ROAMWRIGHT',
48
+ debug = 'APP',
49
+ base = 'http://localhost:8765/',
50
+ out = path.join(process.cwd(), 'out'),
51
+ playwright = [],
52
+ shells: shellRoots = [],
53
+ skipNotes = '',
54
+ storagePrefix = env.toLowerCase(),
55
+ titleId = 't-enter',
56
+ startId = 'start',
57
+ crossingClass = 'crossing',
58
+ canvasSelector = '#c',
59
+ } = {}) {
60
+ // Playwright and the headless shell are looked for where they are kept on this machine, newest first, so that a cleared /tmp
61
+ // or npx cache breaks no tool; <ENV>_PW and <ENV>_SHELL name them outright (a runner on another machine sets both).
62
+ function findPlaywright() {
63
+ if (process.env[env + '_PW']) return process.env[env + '_PW']; // named outright: taken as it is (a test names a stand-in)
64
+ const found = [...playwright, ...npxCached('playwright')].find(place => fs.existsSync(path.join(place, 'package.json')));
65
+ if (!found) throw new Error(`No Playwright found: install it where the driver is told to look, or set ${env}_PW`);
66
+ return found;
67
+ }
68
+ function findShell() {
69
+ if (process.env[env + '_SHELL']) return process.env[env + '_SHELL'];
70
+ const roots = [path.join(os.homedir(), '.cache/puppeteer/chrome-headless-shell'), ...shellRoots];
71
+ const version = dir => dir.replace(/^.*-/, '').split('.').map(Number);
72
+ const found = [];
73
+ for (const root of roots) {
74
+ let versions = [];
75
+ try {
76
+ versions = fs.readdirSync(root);
77
+ } catch {}
78
+ for (const dir of versions) {
79
+ const shell = path.join(root, dir, 'chrome-headless-shell-mac-arm64', 'chrome-headless-shell');
80
+ if (fs.existsSync(shell)) found.push({ shell, version: version(dir) });
81
+ }
82
+ }
83
+ found.sort((a, b) => b.version[0] - a.version[0] || b.version[2] - a.version[2] || b.version[3] - a.version[3]);
84
+ if (!found.length)
85
+ throw new Error(
86
+ `No headless shell found: run \`npx @puppeteer/browsers install chrome-headless-shell@stable --path ~/.cache/puppeteer\`, or set ${env}_SHELL`,
87
+ );
88
+ return found[0].shell;
89
+ }
90
+ const chromium = require(findPlaywright()).chromium,
91
+ shell = findShell(),
92
+ BASE = process.env[env + '_BASE'] || base,
93
+ OUT = process.env[env + '_OUT'] || out,
94
+ GPU = {
95
+ args: ['--use-angle=metal', '--use-gl=angle', '--enable-gpu', '--ignore-gpu-blocklist', '--mute-audio'],
96
+ ignoreDefaultArgs: ['--enable-unsafe-swiftshader'],
97
+ }; // the hardware card through Metal, muted
98
+
99
+ // Prints the page's own log (errors, warnings and 'perf' notes: `window[debug].log()`, as runtime/diagnostic-log.js keeps it) plus
100
+ // the card's console warnings when the browser closes.
101
+ const RUN_BEGAN = new Date().toISOString();
102
+ const LOG_WAIT_MS = 5000; // a page too busy to answer in this time is closed without its log
103
+ // What is printed of a run's log is what a reader acts on: errors, warnings and performance problems, each kind's first
104
+ // LOG_LINES_MOST lines (the rest counted), and one line of totals. <ENV>_VERBOSE=1 prints the plain notes as well.
105
+ const LOG_LINES_MOST = 8;
106
+ async function printLog(page) {
107
+ const read = page.evaluate(
108
+ ([name, since, skip]) => {
109
+ const log = window[name]?.log;
110
+ return log ? log().filter(e => e.t >= since && !(skip && e.kind === 'note' && e.text.startsWith(skip))) : null;
111
+ },
112
+ [debug, RUN_BEGAN, skipNotes],
113
+ );
114
+ const entries = await Promise.race([read, new Promise(r => setTimeout(() => r('busy'), LOG_WAIT_MS))]).catch(() => null);
115
+ if (entries === 'busy') return console.log('LOG: the page did not answer: its log is unread');
116
+ if (!entries) return;
117
+ const count = { error: 0, warn: 0, perf: 0 },
118
+ printed = {};
119
+ for (const e of entries) {
120
+ if (e.kind in count) count[e.kind]++;
121
+ else if (!process.env[env + '_VERBOSE']) continue;
122
+ printed[e.kind] = (printed[e.kind] || 0) + 1;
123
+ if (printed[e.kind] > LOG_LINES_MOST) continue;
124
+ console.log('LOG', e.kind, (e.n > 1 ? e.n + ' x ' : '') + e.text.slice(0, 300) + (e.ctx ? ` [${e.ctx}]` : ''));
125
+ }
126
+ for (const kind in printed)
127
+ if (printed[kind] > LOG_LINES_MOST) console.log(`LOG ${kind}: ${printed[kind] - LOG_LINES_MOST} more not shown`);
128
+ console.log(`LOG: ${count.error} errors, ${count.warn} warnings, ${count.perf} performance problems in this run`);
129
+ }
130
+ const watchedPages = new WeakSet();
131
+ function watchEngine(engine) {
132
+ const launch = engine.launch.bind(engine);
133
+ engine.launch = async (...options) => {
134
+ const browser = await launch(...options),
135
+ open = new Set();
136
+ const watch = page => {
137
+ if (watchedPages.has(page)) return;
138
+ watchedPages.add(page);
139
+ open.add(page);
140
+ page.on('close', () => open.delete(page));
141
+ // the card's own complaints, each said once: a broken shader repeats its message for every material that uses it
142
+ const said = new Set();
143
+ page.on('console', m => {
144
+ const text = m.text().slice(0, 300);
145
+ if (!/WebGL|INVALID|GL_|GPU stall/.test(text) || said.has(text)) return;
146
+ said.add(text);
147
+ if (said.size <= 12) console.log('GL', m.type(), text);
148
+ else if (said.size === 13) console.log('GL: more messages of the card are not shown');
149
+ });
150
+ };
151
+ const newContext = browser.newContext.bind(browser),
152
+ newPage = browser.newPage.bind(browser),
153
+ close = browser.close.bind(browser);
154
+ browser.newContext = async (...o) => {
155
+ const context = await newContext(...o);
156
+ context.on('page', watch);
157
+ return context;
158
+ };
159
+ browser.newPage = async (...o) => {
160
+ const page = await newPage(...o);
161
+ watch(page);
162
+ return page;
163
+ };
164
+ browser.close = async (...o) => {
165
+ for (const page of open) await printLog(page);
166
+ open.clear();
167
+ return close(...o);
168
+ };
169
+ return browser;
170
+ };
171
+ }
172
+ watchEngine(chromium);
173
+
174
+ // No run holds a page for ever: a tool stuck waiting on the page (a scene that never reached its second) once kept the second
175
+ // Mac's graphics card busy for an hour. A run is stopped after <ENV>_MOST_S seconds (30 minutes unless set); a long run says
176
+ // so itself (longRun).
177
+ let stopAt = 0;
178
+ function longRun(seconds) {
179
+ clearTimeout(stopAt);
180
+ stopAt = setTimeout(() => {
181
+ console.error(`FAILED: the run passed ${seconds} s and was stopped (${env}_MOST_S sets the limit)`);
182
+ process.exit(3);
183
+ }, seconds * 1000);
184
+ stopAt.unref();
185
+ }
186
+ longRun(+process.env[env + '_MOST_S'] || 1800);
187
+
188
+ // Opens `url` (when given), waits for the title screen or a direct crossing, clicks the start button if needed, and
189
+ // waits until `window[debug].state.mode === 'play'`. Pass `url = null` after `page.reload()` to reuse the current page.
190
+ async function enter(
191
+ page,
192
+ url,
193
+ { waitUntil = 'domcontentloaded', titledMs = 120000, readyMs = 180000, button = startId, direct = false, polling } = {},
194
+ ) {
195
+ if (url != null) await page.goto(url, waitUntil ? { waitUntil } : undefined);
196
+ if (!direct) {
197
+ const waitOptions = polling ? { timeout: titledMs, polling } : { timeout: titledMs };
198
+ await page.waitForFunction(
199
+ ([d, tId, bId, cls]) => {
200
+ if (window[d]?.state?.mode === 'play') return true;
201
+ if (!window[d]) return false;
202
+ if (cls && document.body.classList.contains(cls)) return true;
203
+ const wrap = tId && document.getElementById(tId);
204
+ if (wrap) return !wrap.hidden;
205
+ const btn = bId && document.getElementById(bId);
206
+ return !!(btn && !btn.disabled);
207
+ },
208
+ [debug, titleId, button, crossingClass],
209
+ waitOptions,
210
+ );
211
+ await page.evaluate(
212
+ ([d, bId, cls]) => {
213
+ if (window[d]?.state?.mode === 'play') return;
214
+ if (cls && document.body.classList.contains(cls)) return;
215
+ const btn = bId && document.getElementById(bId);
216
+ if (btn) btn.click();
217
+ },
218
+ [debug, button, crossingClass],
219
+ );
220
+ }
221
+ const readyOptions = polling ? { timeout: readyMs, polling } : { timeout: readyMs };
222
+ await page.waitForFunction(d => window[d]?.state?.mode === 'play', debug, readyOptions);
223
+ }
224
+
225
+ // Builds a cache-busted page URL from a base URL and optional route address (`?r=<address>&v=<timestamp>`).
226
+ function routeUrl(address = '', { base: baseUrl = BASE, bust = true, param = 'r', extra = '' } = {}) {
227
+ const root = baseUrl.endsWith('/') ? baseUrl : baseUrl + '/';
228
+ const parts = [];
229
+ if (address) parts.push(`${param}=${address}`);
230
+ if (bust) parts.push(`v=${Date.now()}`);
231
+ if (extra) parts.push(extra.replace(/^[?&]/, ''));
232
+ return parts.length ? `${root}?${parts.join('&')}` : root;
233
+ }
234
+
235
+ // Nudges an inspect-mode camera out of any solid obstacle before taking a screenshot.
236
+ function clearView(page) {
237
+ return page.evaluate(d => window[d]?.state?.mode === 'inspect' && !!window[d]?.clearCamera && window[d].clearCamera(), debug);
238
+ }
239
+
240
+ // Closes a browser with a fallback timeout so a wedged headless shell does not hang after results are saved.
241
+ function closeBrowser(browser, timeoutMs = 8000) {
242
+ return Promise.race([browser.close(), new Promise(resolve => setTimeout(resolve, timeoutMs))]);
243
+ }
244
+
245
+ // Sets prefixed localStorage entries before scripts run in a browser context or page.
246
+ async function applyStorage(target, entries) {
247
+ const pairs = Object.entries(entries || {})
248
+ .filter(([, value]) => value !== undefined && value !== null)
249
+ .map(([key, value]) => [storagePrefix ? `${storagePrefix}:${key}` : key, String(value)]);
250
+ if (!pairs.length) return;
251
+ await target.addInitScript(items => {
252
+ try {
253
+ for (const [key, value] of items) localStorage.setItem(key, value);
254
+ } catch {}
255
+ }, pairs);
256
+ }
257
+
258
+ return {
259
+ chromium,
260
+ shell,
261
+ BASE,
262
+ OUT,
263
+ GPU,
264
+ env,
265
+ debug,
266
+ storagePrefix,
267
+ canvasSelector,
268
+ printLog,
269
+ installCuts,
270
+ longRun,
271
+ enter,
272
+ routeUrl,
273
+ clearView,
274
+ closeBrowser,
275
+ applyStorage,
276
+ };
277
+ }
278
+
279
+ // A switch inside the page's shaders, for timing or comparing a part of one on a single page.
280
+ // Give it to context.addInitScript with a list of cuts, each [text the fragment shader holds, where, GLSL]: the GLSL is put
281
+ // into every fragment shader that holds the first text, before the first place `where` stands, or in place of every match
282
+ // of a pattern when `where` is 're:<pattern>' ($& stands for the match). In the GLSL, CUT is a switch of the cut's own,
283
+ // off until the page calls window.setCut(gl, renderer.info.programs, index, true).
284
+ function installCuts(cuts) {
285
+ const original = WebGL2RenderingContext.prototype.shaderSource;
286
+ window.cutsMade = cuts.map(() => 0);
287
+ WebGL2RenderingContext.prototype.shaderSource = function (shader, source) {
288
+ if (this.getShaderParameter(shader, this.SHADER_TYPE) === this.FRAGMENT_SHADER)
289
+ cuts.forEach(([holds, before, glsl], i) => {
290
+ if (!source.includes(holds)) return;
291
+ const code = glsl.replaceAll('CUT', `(uFrameCut${i} > 0.5)`);
292
+ if (before.startsWith('re:')) {
293
+ // every match of a pattern replaced ($& in the GLSL stands for what was matched)
294
+ const pattern = new RegExp(before.slice(3), 'g');
295
+ if (!pattern.test(source)) return;
296
+ source = source.replace(pattern, code);
297
+ } else {
298
+ const at = source.indexOf(before);
299
+ if (at < 0) return;
300
+ source = source.slice(0, at) + code + '\n' + source.slice(at);
301
+ }
302
+ source = source.replace(/^(#version[^\n]*\n)?/, `$1uniform highp float uFrameCut${i};\n`);
303
+ window.cutsMade[i]++;
304
+ });
305
+ return original.call(this, shader, source);
306
+ };
307
+ // Turns cut i on or off in every program that holds it, leaving the program Three.js believes current as it was.
308
+ window.setCut = (gl, programs, i, on) => {
309
+ const current = gl.getParameter(gl.CURRENT_PROGRAM);
310
+ for (const { program } of programs) {
311
+ const at = program && gl.getUniformLocation(program, 'uFrameCut' + i);
312
+ if (!at) continue;
313
+ gl.useProgram(program);
314
+ gl.uniform1f(at, on ? 1 : 0);
315
+ }
316
+ gl.useProgram(current);
317
+ };
318
+ }
319
+
320
+ module.exports = { createPageDriver, installCuts };
@@ -0,0 +1,219 @@
1
+ 'use strict';
2
+ const test = require('node:test');
3
+ const assert = require('node:assert/strict');
4
+ const fs = require('fs'),
5
+ os = require('os'),
6
+ path = require('path');
7
+ const { createPageDriver, installCuts } = require('./page-driver.cjs');
8
+
9
+ // A stand-in for Playwright and for the headless shell, named outright through the driver's environment variables.
10
+ function standIn() {
11
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'page-driver-'));
12
+ fs.writeFileSync(path.join(dir, 'package.json'), '{"name":"playwright","main":"index.js"}');
13
+ fs.writeFileSync(
14
+ path.join(dir, 'index.js'),
15
+ `const pages = [];
16
+ exports.pages = pages;
17
+ exports.chromium = { launch: async options => ({ options, close: async () => 'closed', newContext: async () => ({ on() {} }),
18
+ newPage: async () => { const page = { handlers: {}, on(name, f) { this.handlers[name] = f; }, evaluate: async (f, a) => page.answer(a) }; pages.push(page); return page; } }) };`,
19
+ );
20
+ return dir;
21
+ }
22
+
23
+ test('the driver takes what its world`s environment names, and its defaults otherwise', () => {
24
+ const dir = standIn();
25
+ Object.assign(process.env, { TESTWORLD_PW: dir, TESTWORLD_SHELL: '/a/shell', TESTWORLD_MOST_S: '5' });
26
+ const plain = createPageDriver({ env: 'TESTWORLD', base: 'http://localhost:9000/', out: '/tmp/out' });
27
+ assert.equal(plain.shell, '/a/shell');
28
+ assert.equal(plain.BASE, 'http://localhost:9000/');
29
+ assert.equal(plain.OUT, '/tmp/out');
30
+ assert.ok(plain.GPU.args.includes('--mute-audio'));
31
+ Object.assign(process.env, { TESTWORLD_BASE: 'http://localhost:7/', TESTWORLD_OUT: '/elsewhere' });
32
+ const named = createPageDriver({ env: 'TESTWORLD' });
33
+ assert.equal(named.BASE, 'http://localhost:7/');
34
+ assert.equal(named.OUT, '/elsewhere');
35
+ plain.longRun(1e6);
36
+ named.longRun(1e6);
37
+ for (const name of ['PW', 'SHELL', 'MOST_S', 'BASE', 'OUT']) delete process.env['TESTWORLD_' + name];
38
+ });
39
+
40
+ test('with nothing to find the driver says what to set', () => {
41
+ // A home folder with neither npx's cache nor a headless shell in it: the machine the tests run on has both.
42
+ const home = process.env.HOME,
43
+ empty = fs.mkdtempSync(path.join(os.tmpdir(), 'page-driver-home-'));
44
+ process.env.HOME = empty;
45
+ try {
46
+ assert.throws(() => createPageDriver({ env: 'NOWHERE', playwright: ['/no/such/place'] }), /No Playwright found.*NOWHERE_PW/);
47
+ process.env.NOWHERE_PW = standIn();
48
+ assert.throws(() => createPageDriver({ env: 'NOWHERE' }), /No headless shell found.*NOWHERE_SHELL/);
49
+ } finally {
50
+ process.env.HOME = home;
51
+ delete process.env.NOWHERE_PW;
52
+ }
53
+ });
54
+
55
+ test('the page`s own log is printed when the browser closes: errors, warnings and performance notes, and a line of totals', async () => {
56
+ const dir = standIn();
57
+ Object.assign(process.env, { LOGWORLD_PW: dir, LOGWORLD_SHELL: '/a/shell' });
58
+ const driver = createPageDriver({ env: 'LOGWORLD', debug: 'WORLD', skipNotes: 'visit:' });
59
+ const browser = await driver.chromium.launch({});
60
+ const page = await browser.newPage();
61
+ let asked = null;
62
+ page.answer = ([name, since, skip]) => {
63
+ asked = { name, skip, since };
64
+ return [
65
+ { t: since, kind: 'error', text: 'a shader failed', n: 2, ctx: 'at the harbour' },
66
+ { t: since, kind: 'perf', text: 'a long frame' },
67
+ { t: since, kind: 'note', text: 'a plain note' },
68
+ ];
69
+ };
70
+ const lines = [],
71
+ log = console.log;
72
+ console.log = (...parts) => lines.push(parts.join(' '));
73
+ try {
74
+ page.handlers.console({ text: () => 'WebGL: INVALID_OPERATION', type: () => 'warning' });
75
+ page.handlers.console({ text: () => 'WebGL: INVALID_OPERATION', type: () => 'warning' });
76
+ page.handlers.console({ text: () => 'an ordinary line', type: () => 'log' });
77
+ assert.equal(await browser.close(), 'closed');
78
+ } finally {
79
+ console.log = log;
80
+ }
81
+ assert.deepEqual(asked.name, 'WORLD');
82
+ assert.equal(asked.skip, 'visit:');
83
+ assert.deepEqual(lines, [
84
+ 'GL warning WebGL: INVALID_OPERATION',
85
+ 'LOG error 2 x a shader failed [at the harbour]',
86
+ 'LOG perf a long frame',
87
+ 'LOG: 1 errors, 0 warnings, 1 performance problems in this run',
88
+ ]);
89
+ for (const name of ['PW', 'SHELL']) delete process.env['LOGWORLD_' + name];
90
+ });
91
+
92
+ test('a cut is written into the fragment shaders that hold its text, with a switch of its own', () => {
93
+ const sources = [];
94
+ class FakeContext {
95
+ getShaderParameter(shader) {
96
+ return shader.type;
97
+ }
98
+ shaderSource(shader, source) {
99
+ sources.push(source);
100
+ }
101
+ }
102
+ FakeContext.prototype.SHADER_TYPE = 1;
103
+ FakeContext.prototype.FRAGMENT_SHADER = 'fragment';
104
+ const before = { WebGL2RenderingContext: global.WebGL2RenderingContext, window: global.window };
105
+ global.WebGL2RenderingContext = FakeContext;
106
+ global.window = {};
107
+ try {
108
+ installCuts([['uGround', 'void main', 'if (CUT) discard;']]);
109
+ const gl = new FakeContext();
110
+ gl.shaderSource({ type: 'fragment' }, '#version 300 es\nuniform float uGround;\nvoid main() {}');
111
+ gl.shaderSource({ type: 'fragment' }, '#version 300 es\nvoid main() {}');
112
+ gl.shaderSource({ type: 'vertex' }, 'uniform float uGround;\nvoid main() {}');
113
+ assert.equal(
114
+ sources[0],
115
+ '#version 300 es\nuniform highp float uFrameCut0;\nuniform float uGround;\nif ((uFrameCut0 > 0.5)) discard;\nvoid main() {}',
116
+ );
117
+ assert.equal(sources[1], '#version 300 es\nvoid main() {}');
118
+ assert.equal(sources[2], 'uniform float uGround;\nvoid main() {}');
119
+ assert.deepEqual(global.window.cutsMade, [1]);
120
+ } finally {
121
+ global.WebGL2RenderingContext = before.WebGL2RenderingContext;
122
+ global.window = before.window;
123
+ }
124
+ });
125
+
126
+ test('enter navigates, waits for the title screen, clicks start, and waits for play mode', async () => {
127
+ const dir = standIn();
128
+ Object.assign(process.env, { ENTERWORLD_PW: dir, ENTERWORLD_SHELL: '/a/shell' });
129
+ const driver = createPageDriver({ env: 'ENTERWORLD', debug: 'WORLD', base: 'http://localhost:8765/' });
130
+ const calls = [];
131
+ let mode = 'title',
132
+ clicked = false;
133
+ const fakeWindow = {
134
+ WORLD: {
135
+ state: {
136
+ get mode() {
137
+ return mode;
138
+ },
139
+ },
140
+ },
141
+ };
142
+ const fakeDocument = {
143
+ body: { classList: { contains: () => false } },
144
+ getElementById(id) {
145
+ if (id === 't-enter') return { hidden: false };
146
+ if (id === 'start')
147
+ return {
148
+ disabled: false,
149
+ click() {
150
+ clicked = true;
151
+ mode = 'play';
152
+ },
153
+ };
154
+ return null;
155
+ },
156
+ };
157
+ const page = {
158
+ async goto(url, opts) {
159
+ calls.push(['goto', url, opts]);
160
+ },
161
+ async waitForFunction(fn, arg, opts) {
162
+ calls.push(['wait', opts]);
163
+ const prevW = global.window,
164
+ prevD = global.document;
165
+ global.window = fakeWindow;
166
+ global.document = fakeDocument;
167
+ try {
168
+ assert.equal(fn(arg), true);
169
+ } finally {
170
+ global.window = prevW;
171
+ global.document = prevD;
172
+ }
173
+ },
174
+ async evaluate(fn, arg) {
175
+ calls.push(['eval']);
176
+ const prevW = global.window,
177
+ prevD = global.document;
178
+ global.window = fakeWindow;
179
+ global.document = fakeDocument;
180
+ try {
181
+ return fn(arg);
182
+ } finally {
183
+ global.window = prevW;
184
+ global.document = prevD;
185
+ }
186
+ },
187
+ };
188
+ await driver.enter(page, 'http://localhost:8765/?v=1', { titledMs: 5000, readyMs: 9000 });
189
+ assert.equal(clicked, true);
190
+ assert.equal(calls[0][0], 'goto');
191
+ assert.deepEqual(calls[0][2], { waitUntil: 'domcontentloaded' });
192
+ assert.deepEqual(calls[1][1], { timeout: 5000 });
193
+ assert.deepEqual(calls[3][1], { timeout: 9000 });
194
+
195
+ // Direct route URLs and routeUrl formatting
196
+ assert.match(driver.routeUrl('location/town'), /^http:\/\/localhost:8765\/\?r=location\/town&v=\d+$/);
197
+ assert.equal(driver.routeUrl('', { bust: false }), 'http://localhost:8765/');
198
+ assert.equal(driver.routeUrl('harbour', { bust: false, extra: 'mute' }), 'http://localhost:8765/?r=harbour&mute');
199
+
200
+ // applyStorage prefixes keys with storagePrefix
201
+ const initCalls = [];
202
+ await driver.applyStorage(
203
+ {
204
+ async addInitScript(fn, arg) {
205
+ initCalls.push(arg);
206
+ },
207
+ },
208
+ { quality: 'high', muted: '1' },
209
+ );
210
+ assert.deepEqual(initCalls, [
211
+ [
212
+ ['enterworld:quality', 'high'],
213
+ ['enterworld:muted', '1'],
214
+ ],
215
+ ]);
216
+
217
+ driver.longRun(1e6);
218
+ for (const name of ['PW', 'SHELL']) delete process.env['ENTERWORLD_' + name];
219
+ });