@woosh/meep-engine 2.169.1 → 2.169.2

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 (680) hide show
  1. package/editor/ecs/component/editors/NumericIntervalEditor.js +18 -35
  2. package/editor/ecs/component/editors/ObservedIntegerEditor.js +22 -43
  3. package/editor/ecs/component/editors/ObservedStringEditor.js +34 -51
  4. package/editor/ecs/component/editors/common/makeV3_editor.js +12 -30
  5. package/editor/ecs/component/editors/common/two_way_sync.js +50 -0
  6. package/editor/ecs/component/editors/geom/QuaternionEditor.js +20 -35
  7. package/editor/ecs/component/editors/geom/Vector1Editor.js +5 -28
  8. package/editor/ecs/component/editors/primitive/NumberEditor.js +15 -31
  9. package/editor/tools/paint/TerrainHeightPaintTool.js +22 -31
  10. package/editor/tools/paint/TerrainPaintTool.js +85 -13
  11. package/editor/tools/paint/TerrainTexturePaintTool.js +18 -29
  12. package/editor/view/ecs/components/TerrainController.js +1 -4
  13. package/package.json +1 -1
  14. package/src/DUPLICATION_AUDIT_2026_08_07/00_core_reuse_surface.md +738 -0
  15. package/src/DUPLICATION_AUDIT_2026_08_07/A_core_math_geom.md +79 -0
  16. package/src/DUPLICATION_AUDIT_2026_08_07/B_core_data.md +93 -0
  17. package/src/DUPLICATION_AUDIT_2026_08_07/C_gfx_render.md +80 -0
  18. package/src/DUPLICATION_AUDIT_2026_08_07/D_gfx_features.md +164 -0
  19. package/src/DUPLICATION_AUDIT_2026_08_07/E_physics.md +69 -0
  20. package/src/DUPLICATION_AUDIT_2026_08_07/F_sound.md +102 -0
  21. package/src/DUPLICATION_AUDIT_2026_08_07/G_net_save.md +129 -0
  22. package/src/DUPLICATION_AUDIT_2026_08_07/H_engine_misc.md +72 -0
  23. package/src/DUPLICATION_AUDIT_2026_08_07/I_generation_view.md +74 -0
  24. package/src/DUPLICATION_AUDIT_2026_08_07/K_crosscutting.md +169 -0
  25. package/src/DUPLICATION_AUDIT_2026_08_07.md +254 -0
  26. package/src/DUPLICATION_AUDIT_REMEDIATION.md +250 -0
  27. package/src/core/bvh2/bvh3/query/bvh_collect_user_data.js +2 -2
  28. package/src/core/bvh2/bvh3/query/bvh_query_leaves_generic.js +77 -77
  29. package/src/core/bvh2/bvh3/query/bvh_query_leaves_ray.js +90 -90
  30. package/src/core/bvh2/bvh3/query/bvh_query_leaves_ray_segment.js +94 -94
  31. package/src/core/bvh2/bvh3/query/bvh_query_user_data_generic.js +86 -86
  32. package/src/core/bvh2/bvh3/query/bvh_query_user_data_intersects_aabb.js +2 -2
  33. package/src/core/bvh2/bvh3/query/bvh_query_user_data_intersects_capsule.js +2 -2
  34. package/src/core/bvh2/bvh3/query/bvh_query_user_data_intersects_frustum.js +2 -2
  35. package/src/core/bvh2/bvh3/query/bvh_query_user_data_intersects_sphere.js +2 -2
  36. package/src/core/bvh2/bvh3/query/bvh_query_user_data_ray.js +96 -96
  37. package/src/core/bvh2/bvh3/query/bvh_query_user_data_ray_segment.js +100 -100
  38. package/src/core/bvh2/bvh3/query/compute_tight_near_far_clipping_planes.js +2 -2
  39. package/src/core/bvh8/aabb3_round_to_float32.d.ts +16 -0
  40. package/src/core/bvh8/aabb3_round_to_float32.d.ts.map +1 -0
  41. package/src/core/bvh8/aabb3_round_to_float32.js +22 -0
  42. package/src/core/bvh8/bvh8_geometry_validate.d.ts.map +1 -1
  43. package/src/core/bvh8/bvh8_geometry_validate.js +1 -12
  44. package/src/core/bvh8/bvh8_geometry_validate_indirect.d.ts.map +1 -1
  45. package/src/core/bvh8/bvh8_geometry_validate_indirect.js +1 -12
  46. package/src/core/cache/Cache.d.ts +13 -0
  47. package/src/core/cache/Cache.d.ts.map +1 -1
  48. package/src/core/cache/Cache.js +13 -0
  49. package/src/core/color/operations/color_darken.d.ts +5 -2
  50. package/src/core/color/operations/color_darken.d.ts.map +1 -1
  51. package/src/core/color/operations/color_darken.js +24 -33
  52. package/src/core/color/operations/color_desaturate.d.ts +5 -2
  53. package/src/core/color/operations/color_desaturate.d.ts.map +1 -1
  54. package/src/core/color/operations/color_desaturate.js +24 -33
  55. package/src/core/color/operations/color_lighten.d.ts +5 -2
  56. package/src/core/color/operations/color_lighten.d.ts.map +1 -1
  57. package/src/core/color/operations/color_lighten.js +24 -33
  58. package/src/core/color/operations/color_saturate.d.ts +5 -2
  59. package/src/core/color/operations/color_saturate.d.ts.map +1 -1
  60. package/src/core/color/operations/color_saturate.js +24 -33
  61. package/src/core/color/operations/color_scale_okhsv_channel.d.ts +28 -0
  62. package/src/core/color/operations/color_scale_okhsv_channel.d.ts.map +1 -0
  63. package/src/core/color/operations/color_scale_okhsv_channel.js +45 -0
  64. package/src/core/geom/2d/hash-grid/SpatialHashGrid.d.ts.map +1 -1
  65. package/src/core/geom/2d/hash-grid/SpatialHashGrid.js +12 -0
  66. package/src/core/geom/2d/line/segment2_intersects_segment2_2d.d.ts.map +1 -1
  67. package/src/core/geom/2d/line/segment2_intersects_segment2_2d.js +25 -29
  68. package/src/core/geom/2d/line/segment2_segment_compute_intersection_array_2d.d.ts.map +1 -1
  69. package/src/core/geom/2d/line/segment2_segment_compute_intersection_array_2d.js +46 -51
  70. package/src/core/geom/2d/line/segment2_segment_intersection_fractions.d.ts +31 -0
  71. package/src/core/geom/2d/line/segment2_segment_intersection_fractions.d.ts.map +1 -0
  72. package/src/core/geom/2d/line/segment2_segment_intersection_fractions.js +52 -0
  73. package/src/core/geom/2d/quad-tree/qt_collect_by_circle.d.ts +6 -1
  74. package/src/core/geom/2d/quad-tree/qt_collect_by_circle.d.ts.map +1 -1
  75. package/src/core/geom/2d/quad-tree/qt_collect_by_circle.js +39 -65
  76. package/src/core/geom/2d/quad-tree/qt_match_data_by_circle.d.ts +15 -5
  77. package/src/core/geom/2d/quad-tree/qt_match_data_by_circle.d.ts.map +1 -1
  78. package/src/core/geom/2d/quad-tree/qt_match_data_by_circle.js +101 -70
  79. package/src/core/geom/2d/r-tree/StaticR2Tree.d.ts.map +1 -1
  80. package/src/core/geom/2d/r-tree/StaticR2Tree.js +7 -3
  81. package/src/core/geom/3d/aabb/aabb3_intersects_ray_segment.d.ts +7 -8
  82. package/src/core/geom/3d/aabb/aabb3_intersects_ray_segment.d.ts.map +1 -1
  83. package/src/core/geom/3d/aabb/aabb3_intersects_ray_segment.js +15 -51
  84. package/src/core/geom/3d/atlas/param/atlas_chart_parameterize_bff.d.ts.map +1 -1
  85. package/src/core/geom/3d/atlas/param/atlas_chart_parameterize_bff.js +13 -14
  86. package/src/core/geom/3d/atlas/param/atlas_chart_parameterize_lscm.d.ts.map +1 -1
  87. package/src/core/geom/3d/atlas/param/atlas_chart_parameterize_lscm.js +2 -17
  88. package/src/core/geom/3d/atlas/segment/atlas_chart_roundness_delta.d.ts +22 -0
  89. package/src/core/geom/3d/atlas/segment/atlas_chart_roundness_delta.d.ts.map +1 -0
  90. package/src/core/geom/3d/atlas/segment/atlas_chart_roundness_delta.js +30 -0
  91. package/src/core/geom/3d/atlas/segment/atlas_segment_charts.d.ts +19 -0
  92. package/src/core/geom/3d/atlas/segment/atlas_segment_charts.d.ts.map +1 -1
  93. package/src/core/geom/3d/atlas/segment/atlas_segment_charts.js +5 -9
  94. package/src/core/geom/3d/atlas/segment/atlas_segment_charts_atomic.d.ts.map +1 -1
  95. package/src/core/geom/3d/atlas/segment/atlas_segment_charts_atomic.js +4 -12
  96. package/src/core/geom/3d/frustum/read_frustum_corner.d.ts +5 -0
  97. package/src/core/geom/3d/frustum/read_frustum_corner.d.ts.map +1 -1
  98. package/src/core/geom/3d/frustum/read_frustum_corner.js +8 -5
  99. package/src/core/geom/3d/line/line3_segment_segment_closest_point_pair.d.ts +33 -0
  100. package/src/core/geom/3d/line/line3_segment_segment_closest_point_pair.d.ts.map +1 -0
  101. package/src/core/geom/3d/line/line3_segment_segment_closest_point_pair.js +71 -0
  102. package/src/core/geom/3d/mat4/m4_compose.d.ts +5 -0
  103. package/src/core/geom/3d/mat4/m4_compose.d.ts.map +1 -1
  104. package/src/core/geom/3d/mat4/m4_compose.js +22 -53
  105. package/src/core/geom/3d/mat4/m4_decompose.d.ts +8 -0
  106. package/src/core/geom/3d/mat4/m4_decompose.d.ts.map +1 -1
  107. package/src/core/geom/3d/mat4/m4_decompose.js +84 -76
  108. package/src/core/geom/3d/mat4/m4_from_rotation_translation_scale.d.ts +2 -0
  109. package/src/core/geom/3d/mat4/m4_from_rotation_translation_scale.d.ts.map +1 -1
  110. package/src/core/geom/3d/mat4/m4_from_rotation_translation_scale.js +10 -44
  111. package/src/core/geom/3d/mat4/m4_from_rotation_translation_scale_scalar.d.ts +27 -0
  112. package/src/core/geom/3d/mat4/m4_from_rotation_translation_scale_scalar.d.ts.map +1 -0
  113. package/src/core/geom/3d/mat4/m4_from_rotation_translation_scale_scalar.js +67 -0
  114. package/src/core/geom/3d/plane/orient3d_fast.d.ts.map +1 -1
  115. package/src/core/geom/3d/plane/orient3d_fast.js +2 -22
  116. package/src/core/geom/3d/plane/orient3d_fast_point.d.ts +28 -0
  117. package/src/core/geom/3d/plane/orient3d_fast_point.d.ts.map +1 -0
  118. package/src/core/geom/3d/plane/orient3d_fast_point.js +47 -0
  119. package/src/core/geom/3d/quaternion/quat3_nlerp.d.ts +48 -0
  120. package/src/core/geom/3d/quaternion/quat3_nlerp.d.ts.map +1 -0
  121. package/src/core/geom/3d/quaternion/quat3_nlerp.js +72 -0
  122. package/src/core/geom/3d/shape/AbstractShape3D.d.ts +9 -0
  123. package/src/core/geom/3d/shape/AbstractShape3D.d.ts.map +1 -1
  124. package/src/core/geom/3d/shape/AbstractShape3D.js +44 -1
  125. package/src/core/geom/3d/shape/BoxShape3D.d.ts.map +1 -1
  126. package/src/core/geom/3d/shape/BoxShape3D.js +2 -1
  127. package/src/core/geom/3d/shape/CapsuleShape3D.d.ts.map +1 -1
  128. package/src/core/geom/3d/shape/CapsuleShape3D.js +2 -1
  129. package/src/core/geom/3d/shape/ConvexHullShape3D.d.ts +0 -1
  130. package/src/core/geom/3d/shape/ConvexHullShape3D.d.ts.map +1 -1
  131. package/src/core/geom/3d/shape/ConvexHullShape3D.js +25 -56
  132. package/src/core/geom/3d/shape/CylinderShape3D.d.ts.map +1 -1
  133. package/src/core/geom/3d/shape/CylinderShape3D.js +2 -1
  134. package/src/core/geom/3d/shape/HeightMapShape3D.d.ts.map +1 -1
  135. package/src/core/geom/3d/shape/HeightMapShape3D.js +3 -5
  136. package/src/core/geom/3d/shape/MeshShape3D.d.ts +0 -11
  137. package/src/core/geom/3d/shape/MeshShape3D.d.ts.map +1 -1
  138. package/src/core/geom/3d/shape/MeshShape3D.js +27 -106
  139. package/src/core/geom/3d/shape/Triangle3D.d.ts +1 -1
  140. package/src/core/geom/3d/shape/Triangle3D.d.ts.map +1 -1
  141. package/src/core/geom/3d/shape/Triangle3D.js +10 -31
  142. package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_carve_outside_surface.d.ts.map +1 -1
  143. package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_carve_outside_surface.js +8 -57
  144. package/src/core/geom/3d/topology/simplify/decimate_edge_collapse_snap.d.ts +8 -1
  145. package/src/core/geom/3d/topology/simplify/decimate_edge_collapse_snap.d.ts.map +1 -1
  146. package/src/core/geom/3d/topology/simplify/decimate_edge_collapse_snap.js +281 -272
  147. package/src/core/geom/3d/topology/simplify/quadratic/build_vertex_quadrics.d.ts.map +1 -1
  148. package/src/core/geom/3d/topology/simplify/quadratic/build_vertex_quadrics.js +3 -4
  149. package/src/core/geom/3d/topology/simplify/quadratic/quadric3_set_from_plane_through_point.d.ts +22 -0
  150. package/src/core/geom/3d/topology/simplify/quadratic/quadric3_set_from_plane_through_point.d.ts.map +1 -0
  151. package/src/core/geom/3d/topology/simplify/quadratic/quadric3_set_from_plane_through_point.js +27 -0
  152. package/src/core/geom/3d/topology/struct/binary/io/bt_boundary_loop.d.ts +24 -0
  153. package/src/core/geom/3d/topology/struct/binary/io/bt_boundary_loop.d.ts.map +1 -0
  154. package/src/core/geom/3d/topology/struct/binary/io/bt_boundary_loop.js +73 -0
  155. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_close_boundary_holes.d.ts.map +1 -1
  156. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_close_boundary_holes.js +2 -53
  157. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_compute_vertex_quadrics.d.ts.map +1 -1
  158. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_compute_vertex_quadrics.js +3 -4
  159. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_fill_small_holes.d.ts.map +1 -1
  160. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_fill_small_holes.js +3 -33
  161. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_from_indexed_geometry.d.ts.map +1 -1
  162. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_from_indexed_geometry.js +4 -37
  163. package/src/core/geom/3d/topology/struct/binary/io/face/bt_face_poke.d.ts.map +1 -1
  164. package/src/core/geom/3d/topology/struct/binary/io/face/bt_face_poke.js +3 -32
  165. package/src/core/geom/3d/topology/struct/binary/query/bt_face_read_triangle.d.ts +32 -0
  166. package/src/core/geom/3d/topology/struct/binary/query/bt_face_read_triangle.d.ts.map +1 -0
  167. package/src/core/geom/3d/topology/struct/binary/query/bt_face_read_triangle.js +66 -0
  168. package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_face_find_path.d.ts.map +1 -1
  169. package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_face_find_path.js +703 -728
  170. package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_face_find_path_polyanya.d.ts.map +1 -1
  171. package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_face_find_path_polyanya.js +13 -24
  172. package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_sample_interior_grid_points.d.ts.map +1 -1
  173. package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_sample_interior_grid_points.js +8 -54
  174. package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_surface_ray_parity.d.ts +35 -0
  175. package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_surface_ray_parity.d.ts.map +1 -0
  176. package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_surface_ray_parity.js +82 -0
  177. package/src/core/geom/3d/triangle/tri3_closest_point.d.ts +29 -0
  178. package/src/core/geom/3d/triangle/tri3_closest_point.d.ts.map +1 -0
  179. package/src/core/geom/3d/triangle/tri3_closest_point.js +65 -0
  180. package/src/core/geom/3d/triangle/tri3_flatten_isometric.d.ts +42 -0
  181. package/src/core/geom/3d/triangle/tri3_flatten_isometric.d.ts.map +1 -0
  182. package/src/core/geom/3d/triangle/tri3_flatten_isometric.js +79 -0
  183. package/src/core/geom/Vector2.d.ts.map +1 -1
  184. package/src/core/geom/Vector2.js +2 -1
  185. package/src/core/geom/random/random_orthonormal_basis.d.ts +21 -0
  186. package/src/core/geom/random/random_orthonormal_basis.d.ts.map +1 -0
  187. package/src/core/geom/random/random_orthonormal_basis.js +31 -0
  188. package/src/core/geom/vec2/v2_rotate.d.ts +18 -0
  189. package/src/core/geom/vec2/v2_rotate.d.ts.map +1 -0
  190. package/src/core/geom/vec2/v2_rotate.js +21 -0
  191. package/src/core/geom/vec2/v2_rotate_cos_sin.d.ts +19 -0
  192. package/src/core/geom/vec2/v2_rotate_cos_sin.d.ts.map +1 -0
  193. package/src/core/geom/vec2/v2_rotate_cos_sin.js +21 -0
  194. package/src/core/graph/csr/csr_graph_from_undirected_edge_list.d.ts +30 -0
  195. package/src/core/graph/csr/csr_graph_from_undirected_edge_list.d.ts.map +1 -0
  196. package/src/core/graph/csr/csr_graph_from_undirected_edge_list.js +94 -0
  197. package/src/core/graph/layout/CircleLayout.d.ts.map +1 -1
  198. package/src/core/graph/layout/CircleLayout.js +6 -29
  199. package/src/core/graph/layout/box/BoxLayouter.d.ts.map +1 -1
  200. package/src/core/graph/layout/box/BoxLayouter.js +2 -26
  201. package/src/core/graph/layout/box/position_box_next_to_box.d.ts.map +1 -1
  202. package/src/core/graph/layout/box/position_box_next_to_box.js +2 -1
  203. package/src/core/graph/layout/computeDisconnectedSubGraphs.d.ts.map +1 -1
  204. package/src/core/graph/layout/computeDisconnectedSubGraphs.js +14 -3
  205. package/src/core/graph/layout/graph_peel_topological_layer.d.ts +25 -0
  206. package/src/core/graph/layout/graph_peel_topological_layer.d.ts.map +1 -0
  207. package/src/core/graph/layout/graph_peel_topological_layer.js +45 -0
  208. package/src/core/math/hash/hash_mix2.d.ts +21 -0
  209. package/src/core/math/hash/hash_mix2.d.ts.map +1 -0
  210. package/src/core/math/hash/hash_mix2.js +22 -0
  211. package/src/core/math/hash/hash_mix3.d.ts +16 -0
  212. package/src/core/math/hash/hash_mix3.d.ts.map +1 -0
  213. package/src/core/math/hash/hash_mix3.js +19 -0
  214. package/src/core/math/lookup/LUT_HEATMAP.d.ts +17 -0
  215. package/src/core/math/lookup/LUT_HEATMAP.d.ts.map +1 -0
  216. package/src/core/math/lookup/LUT_HEATMAP.js +30 -0
  217. package/src/core/math/noise/curl_noise_3d.d.ts +6 -0
  218. package/src/core/math/noise/curl_noise_3d.d.ts.map +1 -1
  219. package/src/core/math/noise/curl_noise_3d.js +18 -27
  220. package/src/core/math/statistics/hammersley_sequence.d.ts +28 -16
  221. package/src/core/math/statistics/hammersley_sequence.d.ts.map +1 -1
  222. package/src/core/math/statistics/hammersley_sequence.js +53 -34
  223. package/src/core/science/units/MEASUREMENT_UNITS_SI.d.ts +3 -0
  224. package/src/core/science/units/MEASUREMENT_UNITS_SI.d.ts.map +1 -1
  225. package/src/core/science/units/MEASUREMENT_UNITS_SI.js +5 -16
  226. package/src/engine/animation/TransitionFunctions.d.ts +31 -0
  227. package/src/engine/animation/TransitionFunctions.d.ts.map +1 -1
  228. package/src/engine/animation/TransitionFunctions.js +44 -0
  229. package/src/engine/animation/curve/animation_curve_binary_codec.d.ts +29 -0
  230. package/src/engine/animation/curve/animation_curve_binary_codec.d.ts.map +1 -0
  231. package/src/engine/animation/curve/animation_curve_binary_codec.js +60 -0
  232. package/src/engine/animation/curve/draw/canvas_point_to_curve.d.ts +16 -0
  233. package/src/engine/animation/curve/draw/canvas_point_to_curve.d.ts.map +1 -0
  234. package/src/engine/animation/curve/draw/canvas_point_to_curve.js +22 -0
  235. package/src/engine/animation/curve/draw/curve_point_to_canvas.d.ts +27 -0
  236. package/src/engine/animation/curve/draw/curve_point_to_canvas.d.ts.map +1 -0
  237. package/src/engine/animation/curve/draw/curve_point_to_canvas.js +38 -0
  238. package/src/engine/animation/curve/draw/position_canvas_to_curve.d.ts +2 -0
  239. package/src/engine/animation/curve/draw/position_canvas_to_curve.d.ts.map +1 -1
  240. package/src/engine/animation/curve/draw/position_canvas_to_curve.js +22 -24
  241. package/src/engine/animation/curve/draw/position_curve_to_canvas.d.ts +2 -0
  242. package/src/engine/animation/curve/draw/position_curve_to_canvas.d.ts.map +1 -1
  243. package/src/engine/animation/curve/draw/position_curve_to_canvas.js +22 -25
  244. package/src/engine/animation/curve/editor/canvas2dDrawWorldAxisLabels.d.ts.map +1 -1
  245. package/src/engine/animation/curve/editor/canvas2dDrawWorldAxisLabels.js +3 -2
  246. package/src/engine/animation/curve/editor/canvas2dPlotCurvePoints.d.ts.map +1 -1
  247. package/src/engine/animation/curve/editor/canvas2dPlotCurvePoints.js +14 -14
  248. package/src/engine/animation/removeEntityWithMeshParticlesEffect.d.ts.map +1 -1
  249. package/src/engine/animation/removeEntityWithMeshParticlesEffect.js +5 -0
  250. package/src/engine/asset/loaders/GLTFAssetLoader.d.ts.map +1 -1
  251. package/src/engine/asset/loaders/GLTFAssetLoader.js +25 -51
  252. package/src/engine/asset/loaders/material/StaticMaterialCache.d.ts +3 -2
  253. package/src/engine/asset/loaders/material/StaticMaterialCache.d.ts.map +1 -1
  254. package/src/engine/asset/loaders/material/StaticMaterialCache.js +16 -55
  255. package/src/engine/asset/loaders/material/TextureCoalescer.d.ts +32 -0
  256. package/src/engine/asset/loaders/material/TextureCoalescer.d.ts.map +1 -0
  257. package/src/engine/asset/loaders/material/TextureCoalescer.js +68 -0
  258. package/src/engine/asset/loaders/material/traverseMaterialTextures.d.ts +10 -2
  259. package/src/engine/asset/loaders/material/traverseMaterialTextures.d.ts.map +1 -1
  260. package/src/engine/asset/loaders/material/traverseMaterialTextures.js +10 -2
  261. package/src/engine/control/first-person/abilities/Mantle.d.ts.map +1 -1
  262. package/src/engine/control/first-person/abilities/Mantle.js +10 -26
  263. package/src/engine/ecs/dynamic_actions/actions/definition/WeightedRandomActionDescription.d.ts.map +1 -1
  264. package/src/engine/ecs/dynamic_actions/actions/definition/WeightedRandomActionDescription.js +5 -0
  265. package/src/engine/ecs/evaluation/complex/PointFitnessGaussianBlur.d.ts +22 -2
  266. package/src/engine/ecs/evaluation/complex/PointFitnessGaussianBlur.d.ts.map +1 -1
  267. package/src/engine/ecs/evaluation/complex/PointFitnessGaussianBlur.js +92 -41
  268. package/src/engine/ecs/gui/hud/HeadsUpDisplaySystem.d.ts +3 -1
  269. package/src/engine/ecs/gui/hud/HeadsUpDisplaySystem.d.ts.map +1 -1
  270. package/src/engine/ecs/gui/hud/HeadsUpDisplaySystem.js +14 -16
  271. package/src/engine/ecs/gui/parallax/GuiElementParallaxSystem.d.ts.map +1 -1
  272. package/src/engine/ecs/gui/parallax/GuiElementParallaxSystem.js +16 -29
  273. package/src/engine/ecs/ik/OneBoneSurfaceAlignmentSolver.d.ts.map +1 -1
  274. package/src/engine/ecs/ik/OneBoneSurfaceAlignmentSolver.js +12 -74
  275. package/src/engine/ecs/ik/TwoBoneInverseKinematicsSolver.d.ts.map +1 -1
  276. package/src/engine/ecs/ik/TwoBoneInverseKinematicsSolver.js +10 -73
  277. package/src/engine/ecs/ik/ik_probe_terrain_contact.d.ts +38 -0
  278. package/src/engine/ecs/ik/ik_probe_terrain_contact.d.ts.map +1 -0
  279. package/src/engine/ecs/ik/ik_probe_terrain_contact.js +119 -0
  280. package/src/engine/ecs/terrain/util/paintTerrainOverlayViaLookupTable.d.ts +0 -1
  281. package/src/engine/ecs/terrain/util/paintTerrainOverlayViaLookupTable.d.ts.map +1 -1
  282. package/src/engine/ecs/terrain/util/paintTerrainOverlayViaLookupTable.js +2 -14
  283. package/src/engine/graphics/FULL_SCREEN_QUAD_VERTEX_SHADER.d.ts +12 -1
  284. package/src/engine/graphics/FULL_SCREEN_QUAD_VERTEX_SHADER.d.ts.map +1 -1
  285. package/src/engine/graphics/FULL_SCREEN_QUAD_VERTEX_SHADER.js +14 -10
  286. package/src/engine/graphics/ecs/camera/auto_set_camera_clipping_planes.d.ts.map +1 -1
  287. package/src/engine/graphics/ecs/camera/auto_set_camera_clipping_planes.js +7 -28
  288. package/src/engine/graphics/ecs/highlight/renderer/HighlightDecodeShader.d.ts +1 -2
  289. package/src/engine/graphics/ecs/highlight/renderer/HighlightDecodeShader.d.ts.map +1 -1
  290. package/src/engine/graphics/ecs/highlight/renderer/HighlightDecodeShader.js +4 -12
  291. package/src/engine/graphics/ecs/highlight/renderer/OutlineRenderer.d.ts.map +1 -1
  292. package/src/engine/graphics/ecs/highlight/renderer/OutlineRenderer.js +2 -11
  293. package/src/engine/graphics/ecs/highlight/renderer/makeBlurShader_9.d.ts +1 -2
  294. package/src/engine/graphics/ecs/highlight/renderer/makeBlurShader_9.d.ts.map +1 -1
  295. package/src/engine/graphics/ecs/highlight/renderer/makeBlurShader_9.js +3 -11
  296. package/src/engine/graphics/ecs/highlight/renderer/makeDilationShader.d.ts +1 -2
  297. package/src/engine/graphics/ecs/highlight/renderer/makeDilationShader.d.ts.map +1 -1
  298. package/src/engine/graphics/ecs/highlight/renderer/makeDilationShader.js +3 -11
  299. package/src/engine/graphics/ecs/highlight/renderer/make_screen_space_quad_material.d.ts +33 -0
  300. package/src/engine/graphics/ecs/highlight/renderer/make_screen_space_quad_material.d.ts.map +1 -0
  301. package/src/engine/graphics/ecs/highlight/renderer/make_screen_space_quad_material.js +44 -0
  302. package/src/engine/graphics/ecs/highlight/system/HighlightSystemBase.d.ts +55 -0
  303. package/src/engine/graphics/ecs/highlight/system/HighlightSystemBase.d.ts.map +1 -0
  304. package/src/engine/graphics/ecs/highlight/system/HighlightSystemBase.js +205 -0
  305. package/src/engine/graphics/ecs/highlight/system/MeshHighlightSystem.d.ts +4 -45
  306. package/src/engine/graphics/ecs/highlight/system/MeshHighlightSystem.d.ts.map +1 -1
  307. package/src/engine/graphics/ecs/highlight/system/MeshHighlightSystem.js +39 -162
  308. package/src/engine/graphics/ecs/highlight/system/RenderableHighlightSystem.d.ts +4 -51
  309. package/src/engine/graphics/ecs/highlight/system/RenderableHighlightSystem.d.ts.map +1 -1
  310. package/src/engine/graphics/ecs/highlight/system/RenderableHighlightSystem.js +34 -164
  311. package/src/engine/graphics/ecs/highlight/system/ShadedGeometryHighlightSystem.d.ts +5 -57
  312. package/src/engine/graphics/ecs/highlight/system/ShadedGeometryHighlightSystem.d.ts.map +1 -1
  313. package/src/engine/graphics/ecs/highlight/system/ShadedGeometryHighlightSystem.js +48 -175
  314. package/src/engine/graphics/ecs/light/shadow/extend_shadow_camera_near_for_casters.d.ts.map +1 -1
  315. package/src/engine/graphics/ecs/light/shadow/extend_shadow_camera_near_for_casters.js +7 -25
  316. package/src/engine/graphics/ecs/make_bvh_depth_range_computer.d.ts +26 -0
  317. package/src/engine/graphics/ecs/make_bvh_depth_range_computer.d.ts.map +1 -0
  318. package/src/engine/graphics/ecs/make_bvh_depth_range_computer.js +33 -0
  319. package/src/engine/graphics/ecs/mesh/MeshSystem.d.ts.map +1 -1
  320. package/src/engine/graphics/ecs/mesh/MeshSystem.js +2 -5
  321. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.d.ts.map +1 -1
  322. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +2 -5
  323. package/src/engine/graphics/ecs/render_layers_compute_depth_range.d.ts +35 -0
  324. package/src/engine/graphics/ecs/render_layers_compute_depth_range.d.ts.map +1 -0
  325. package/src/engine/graphics/ecs/render_layers_compute_depth_range.js +64 -0
  326. package/src/engine/graphics/ecs/trail2d/Trail2DSystem.d.ts.map +1 -1
  327. package/src/engine/graphics/ecs/trail2d/Trail2DSystem.js +2 -5
  328. package/src/engine/graphics/ecs/trail3d/Trail3DSystem.d.ts.map +1 -1
  329. package/src/engine/graphics/ecs/trail3d/Trail3DSystem.js +2 -5
  330. package/src/engine/graphics/ecs/water/WaterSystem.d.ts.map +1 -1
  331. package/src/engine/graphics/ecs/water/WaterSystem.js +2 -5
  332. package/src/engine/graphics/geometry/buffered/query/bvh32_geometry_nearest.d.ts.map +1 -1
  333. package/src/engine/graphics/geometry/buffered/query/bvh32_geometry_nearest.js +22 -94
  334. package/src/engine/graphics/geometry/buffered/query/bvh32_geometry_overlap_clipping_volume.d.ts.map +1 -1
  335. package/src/engine/graphics/geometry/buffered/query/bvh32_geometry_overlap_clipping_volume.js +17 -57
  336. package/src/engine/graphics/geometry/buffered/query/bvh32_geometry_raycast.d.ts.map +1 -1
  337. package/src/engine/graphics/geometry/buffered/query/bvh32_geometry_raycast.js +17 -57
  338. package/src/engine/graphics/geometry/buffered/query/nearest_point_on_triangle_record.d.ts +30 -0
  339. package/src/engine/graphics/geometry/buffered/query/nearest_point_on_triangle_record.d.ts.map +1 -0
  340. package/src/engine/graphics/geometry/buffered/query/nearest_point_on_triangle_record.js +87 -0
  341. package/src/engine/graphics/geometry/buffered/query/query_bvh_geometry_nearest.d.ts.map +1 -1
  342. package/src/engine/graphics/geometry/buffered/query/query_bvh_geometry_nearest.js +11 -55
  343. package/src/engine/graphics/geometry/buffered/read_triangle_vertices.d.ts +29 -0
  344. package/src/engine/graphics/geometry/buffered/read_triangle_vertices.d.ts.map +1 -0
  345. package/src/engine/graphics/geometry/buffered/read_triangle_vertices.js +102 -0
  346. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderDepthV0.d.ts.map +1 -1
  347. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderDepthV0.js +17 -122
  348. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderLitV0.d.ts.map +1 -1
  349. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderLitV0.js +15 -194
  350. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderNormalsV0.d.ts.map +1 -1
  351. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderNormalsV0.js +12 -108
  352. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderPerPixelV0.d.ts.map +1 -1
  353. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderPerPixelV0.js +14 -183
  354. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderV0.d.ts.map +1 -1
  355. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderV0.js +12 -154
  356. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderViewportDepthV0.d.ts.map +1 -1
  357. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderViewportDepthV0.js +10 -94
  358. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderWireframeV0.d.ts.map +1 -1
  359. package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderWireframeV0.js +8 -72
  360. package/src/engine/graphics/impostors/octahedral/shader/glsl/common.glsl +10 -0
  361. package/src/engine/graphics/impostors/voxel/bake/read_atlas_to_samples.d.ts.map +1 -1
  362. package/src/engine/graphics/impostors/voxel/bake/read_atlas_to_samples.js +79 -58
  363. package/src/engine/graphics/impostors/voxel/shader/VoxelImpostorShaderDepthV0.d.ts.map +1 -1
  364. package/src/engine/graphics/impostors/voxel/shader/VoxelImpostorShaderDepthV0.js +11 -22
  365. package/src/engine/graphics/impostors/voxel/shader/VoxelImpostorShaderLitV0.d.ts.map +1 -1
  366. package/src/engine/graphics/impostors/voxel/shader/VoxelImpostorShaderLitV0.js +7 -16
  367. package/src/engine/graphics/impostors/voxel/shader/VoxelImpostorShaderNormalsV0.d.ts.map +1 -1
  368. package/src/engine/graphics/impostors/voxel/shader/VoxelImpostorShaderNormalsV0.js +5 -9
  369. package/src/engine/graphics/impostors/voxel/shader/VoxelImpostorShaderV0.d.ts.map +1 -1
  370. package/src/engine/graphics/impostors/voxel/shader/VoxelImpostorShaderV0.js +4 -19
  371. package/src/engine/graphics/impostors/voxel/shader/VoxelImpostorShaderViewportDepthV0.d.ts.map +1 -1
  372. package/src/engine/graphics/impostors/voxel/shader/VoxelImpostorShaderViewportDepthV0.js +5 -9
  373. package/src/engine/graphics/material/SplatMaterial.d.ts.map +1 -1
  374. package/src/engine/graphics/material/SplatMaterial.js +2 -17
  375. package/src/engine/graphics/material/WaterMaterial.d.ts.map +1 -1
  376. package/src/engine/graphics/material/WaterMaterial.js +3 -18
  377. package/src/engine/graphics/material/manager/compilers/CoalesceTextures.d.ts +4 -4
  378. package/src/engine/graphics/material/manager/compilers/CoalesceTextures.d.ts.map +1 -1
  379. package/src/engine/graphics/material/manager/compilers/CoalesceTextures.js +25 -70
  380. package/src/engine/graphics/particles/ecs/ParticleEmitterSystem.d.ts.map +1 -1
  381. package/src/engine/graphics/particles/ecs/ParticleEmitterSystem.js +2 -5
  382. package/src/engine/graphics/particles/node-based/codegen/glsl/getTypeByteSize.d.ts +8 -11
  383. package/src/engine/graphics/particles/node-based/codegen/glsl/getTypeByteSize.d.ts.map +1 -1
  384. package/src/engine/graphics/particles/node-based/codegen/glsl/getTypeByteSize.js +20 -21
  385. package/src/engine/graphics/particles/node-based/nodes/particle_data_type_component_count.d.ts +39 -0
  386. package/src/engine/graphics/particles/node-based/nodes/particle_data_type_component_count.d.ts.map +1 -0
  387. package/src/engine/graphics/particles/node-based/nodes/particle_data_type_component_count.js +45 -0
  388. package/src/engine/graphics/particles/node-based/particle/ParticleAttributeSpecification.d.ts +6 -8
  389. package/src/engine/graphics/particles/node-based/particle/ParticleAttributeSpecification.d.ts.map +1 -1
  390. package/src/engine/graphics/particles/node-based/particle/ParticleAttributeSpecification.js +2 -13
  391. package/src/engine/graphics/particles/particular/engine/utils/distributeParticlesOnObject3D.d.ts.map +1 -1
  392. package/src/engine/graphics/particles/particular/engine/utils/distributeParticlesOnObject3D.js +16 -78
  393. package/src/engine/graphics/particles/particular/engine/utils/distribute_points_on_indexed_triangles.d.ts +45 -0
  394. package/src/engine/graphics/particles/particular/engine/utils/distribute_points_on_indexed_triangles.d.ts.map +1 -0
  395. package/src/engine/graphics/particles/particular/engine/utils/distribute_points_on_indexed_triangles.js +168 -0
  396. package/src/engine/graphics/particles/particular/engine/utils/distrubuteParticlesOnMesh.d.ts.map +1 -1
  397. package/src/engine/graphics/particles/particular/engine/utils/distrubuteParticlesOnMesh.js +11 -115
  398. package/src/engine/graphics/postprocess/threejs/shaders/CopyShader.d.ts +24 -16
  399. package/src/engine/graphics/postprocess/threejs/shaders/CopyShader.d.ts.map +1 -1
  400. package/src/engine/graphics/postprocess/threejs/shaders/CopyShader.js +15 -47
  401. package/src/engine/graphics/render/buffer/simple-fx/ao/AmbientOcclusionPostProcessEffect.d.ts +4 -0
  402. package/src/engine/graphics/render/buffer/simple-fx/ao/AmbientOcclusionPostProcessEffect.d.ts.map +1 -1
  403. package/src/engine/graphics/render/buffer/simple-fx/ao/AmbientOcclusionPostProcessEffect.js +4 -0
  404. package/src/engine/graphics/sh3/build_injected_shader.d.ts +51 -0
  405. package/src/engine/graphics/sh3/build_injected_shader.d.ts.map +1 -0
  406. package/src/engine/graphics/sh3/build_injected_shader.js +56 -0
  407. package/src/engine/graphics/sh3/gi/material/MaterialTransformer.d.ts.map +1 -1
  408. package/src/engine/graphics/sh3/gi/material/MaterialTransformer.js +10 -1
  409. package/src/engine/graphics/sh3/gi/material/chunk_lpv_get_irradiance_at.d.ts.map +1 -1
  410. package/src/engine/graphics/sh3/gi/material/chunk_lpv_get_irradiance_at.js +17 -0
  411. package/src/engine/graphics/sh3/gi/material/common.d.ts +1 -1
  412. package/src/engine/graphics/sh3/gi/material/common.js +6 -222
  413. package/src/engine/graphics/sh3/gi/material/space_fragment/build_fragment_shader.d.ts.map +1 -1
  414. package/src/engine/graphics/sh3/gi/material/space_fragment/build_fragment_shader.js +7 -11
  415. package/src/engine/graphics/sh3/gi/material/space_fragment/build_vertex_shader.d.ts.map +1 -1
  416. package/src/engine/graphics/sh3/gi/material/space_fragment/build_vertex_shader.js +27 -29
  417. package/src/engine/graphics/sh3/gi/material/space_vertex/build_fragment_shader.d.ts.map +1 -1
  418. package/src/engine/graphics/sh3/gi/material/space_vertex/build_fragment_shader.js +7 -11
  419. package/src/engine/graphics/sh3/gi/material/space_vertex/build_vertex_shader.d.ts.map +1 -1
  420. package/src/engine/graphics/sh3/gi/material/space_vertex/build_vertex_shader.js +7 -12
  421. package/src/engine/graphics/sh3/grid_dilate_average.d.ts +38 -0
  422. package/src/engine/graphics/sh3/grid_dilate_average.d.ts.map +1 -0
  423. package/src/engine/graphics/sh3/grid_dilate_average.js +175 -0
  424. package/src/engine/graphics/sh3/lightmap/lightmap_dilate.d.ts +4 -0
  425. package/src/engine/graphics/sh3/lightmap/lightmap_dilate.d.ts.map +1 -1
  426. package/src/engine/graphics/sh3/lightmap/lightmap_dilate.js +7 -70
  427. package/src/engine/graphics/sh3/lpg/light_probe_grid_dilate.d.ts +6 -0
  428. package/src/engine/graphics/sh3/lpg/light_probe_grid_dilate.d.ts.map +1 -1
  429. package/src/engine/graphics/sh3/lpg/light_probe_grid_dilate.js +14 -113
  430. package/src/engine/graphics/sh3/lpg/material/chunk_lpg_get_irradiance_at.d.ts.map +1 -1
  431. package/src/engine/graphics/sh3/lpg/material/chunk_lpg_get_irradiance_at.js +7 -0
  432. package/src/engine/graphics/sh3/lpg/material/space_fragment/build_fragment_shader.d.ts.map +1 -1
  433. package/src/engine/graphics/sh3/lpg/material/space_fragment/build_fragment_shader.js +5 -8
  434. package/src/engine/graphics/sh3/lpg/material/space_fragment/build_vertex_shader.d.ts.map +1 -1
  435. package/src/engine/graphics/sh3/lpg/material/space_fragment/build_vertex_shader.js +5 -8
  436. package/src/engine/graphics/sh3/lpg/material/space_vertex/build_fragment_shader.d.ts.map +1 -1
  437. package/src/engine/graphics/sh3/lpg/material/space_vertex/build_fragment_shader.js +5 -8
  438. package/src/engine/graphics/sh3/lpg/material/space_vertex/build_vertex_shader.d.ts.map +1 -1
  439. package/src/engine/graphics/sh3/lpg/material/space_vertex/build_vertex_shader.js +5 -8
  440. package/src/engine/graphics/sh3/lpv/depth/chunk_probe_depth_sampling.d.ts +38 -0
  441. package/src/engine/graphics/sh3/lpv/depth/chunk_probe_depth_sampling.d.ts.map +1 -0
  442. package/src/engine/graphics/sh3/lpv/depth/chunk_probe_depth_sampling.js +265 -0
  443. package/src/engine/graphics/sh3/lpv/depth/octahedral/shader/visualize.frag.glsl +11 -0
  444. package/src/engine/graphics/sh3/lpv/depth/octahedral/v2/VLPDepthMapVisualisation.d.ts.map +1 -1
  445. package/src/engine/graphics/sh3/lpv/depth/octahedral/v2/VLPDepthMapVisualisation.js +5 -1
  446. package/src/engine/graphics/sh3/lpv/depth/octahedral/v2/visualise.frag.glsl +189 -419
  447. package/src/engine/graphics/sh3/shader/visualize.frag.d.ts +1 -1
  448. package/src/engine/graphics/sh3/shader/visualize.frag.js +7 -0
  449. package/src/engine/graphics/shaders/chunks/glsl_octahedral_impostor.d.ts +102 -0
  450. package/src/engine/graphics/shaders/chunks/glsl_octahedral_impostor.d.ts.map +1 -0
  451. package/src/engine/graphics/shaders/chunks/glsl_octahedral_impostor.js +277 -0
  452. package/src/engine/graphics/shaders/chunks/glsl_packing.d.ts +29 -0
  453. package/src/engine/graphics/shaders/chunks/glsl_packing.d.ts.map +1 -0
  454. package/src/engine/graphics/shaders/chunks/glsl_packing.js +30 -0
  455. package/src/engine/graphics/shaders/chunks/glsl_voxel_impostor_splat.d.ts +40 -0
  456. package/src/engine/graphics/shaders/chunks/glsl_voxel_impostor_splat.d.ts.map +1 -0
  457. package/src/engine/graphics/shaders/chunks/glsl_voxel_impostor_splat.js +57 -0
  458. package/src/engine/graphics/shaders/lib/make_clouds_uniforms.d.ts +22 -0
  459. package/src/engine/graphics/shaders/lib/make_clouds_uniforms.d.ts.map +1 -0
  460. package/src/engine/graphics/shaders/lib/make_clouds_uniforms.js +39 -0
  461. package/src/engine/graphics/texture/attribute_spec_to_three_format.d.ts +6 -0
  462. package/src/engine/graphics/texture/attribute_spec_to_three_format.d.ts.map +1 -1
  463. package/src/engine/graphics/texture/attribute_spec_to_three_format.js +9 -9
  464. package/src/engine/graphics/texture/channel_count_to_format_prefix.d.ts +14 -0
  465. package/src/engine/graphics/texture/channel_count_to_format_prefix.d.ts.map +1 -0
  466. package/src/engine/graphics/texture/channel_count_to_format_prefix.js +26 -0
  467. package/src/engine/graphics/texture/computeThreeTextureInternalFormatFromDataType.d.ts.map +1 -1
  468. package/src/engine/graphics/texture/computeThreeTextureInternalFormatFromDataType.js +2 -20
  469. package/src/engine/graphics/texture/normalized_internal_format.d.ts.map +1 -1
  470. package/src/engine/graphics/texture/normalized_internal_format.js +2 -20
  471. package/src/engine/graphics/texture/sampler/convertTexture2Sampler2D.d.ts.map +1 -1
  472. package/src/engine/graphics/texture/sampler/convertTexture2Sampler2D.js +9 -3
  473. package/src/engine/input/devices/gamepad/GamepadDeviceLayout.d.ts +54 -0
  474. package/src/engine/input/devices/gamepad/GamepadDeviceLayout.d.ts.map +1 -0
  475. package/src/engine/input/devices/gamepad/GamepadDeviceLayout.js +323 -0
  476. package/src/engine/input/devices/gamepad/GamepadHandle.d.ts +21 -2
  477. package/src/engine/input/devices/gamepad/GamepadHandle.d.ts.map +1 -1
  478. package/src/engine/input/devices/gamepad/GamepadHandle.js +39 -11
  479. package/src/engine/input/devices/gamepad/GamepadLayout.d.ts +128 -0
  480. package/src/engine/input/devices/gamepad/GamepadLayout.d.ts.map +1 -0
  481. package/src/engine/input/devices/gamepad/GamepadLayout.js +160 -0
  482. package/src/engine/input/devices/gamepad/GamepadStandardMapping.d.ts +10 -0
  483. package/src/engine/input/devices/gamepad/GamepadStandardMapping.d.ts.map +1 -1
  484. package/src/engine/input/devices/gamepad/GamepadStandardMapping.js +11 -0
  485. package/src/engine/input/devices/gamepad/GamepadStick.d.ts +5 -1
  486. package/src/engine/input/devices/gamepad/GamepadStick.d.ts.map +1 -1
  487. package/src/engine/input/devices/gamepad/GamepadStick.js +5 -1
  488. package/src/engine/input/devices/gamepad/gamepad_layout_database.d.ts +27 -0
  489. package/src/engine/input/devices/gamepad/gamepad_layout_database.d.ts.map +1 -0
  490. package/src/engine/input/devices/gamepad/gamepad_layout_database.js +144 -0
  491. package/src/engine/input/devices/gamepad/gamepad_read_hat_axis.d.ts +25 -0
  492. package/src/engine/input/devices/gamepad/gamepad_read_hat_axis.d.ts.map +1 -0
  493. package/src/engine/input/devices/gamepad/gamepad_read_hat_axis.js +61 -0
  494. package/src/engine/input/devices/gamepad/prototypeGamepadTester.d.ts +2 -0
  495. package/src/engine/input/devices/gamepad/prototypeGamepadTester.d.ts.map +1 -0
  496. package/src/engine/input/devices/gamepad/prototypeGamepadTester.js +2124 -0
  497. package/src/engine/input/ecs/util/TopDownCameraControllerHelper.d.ts.map +1 -1
  498. package/src/engine/input/ecs/util/TopDownCameraControllerHelper.js +3 -33
  499. package/src/engine/intelligence/behavior/util/RandomDelayBehavior.d.ts.map +1 -1
  500. package/src/engine/intelligence/behavior/util/RandomDelayBehavior.js +5 -0
  501. package/src/engine/network/adapters/QuaternionInterpolationAdapter.d.ts.map +1 -1
  502. package/src/engine/network/adapters/QuaternionInterpolationAdapter.js +18 -19
  503. package/src/engine/network/adapters/TransformInterpolationAdapter.d.ts.map +1 -1
  504. package/src/engine/network/adapters/TransformInterpolationAdapter.js +18 -13
  505. package/src/engine/network/orchestrator/NetworkPeer.d.ts.map +1 -1
  506. package/src/engine/network/orchestrator/NetworkPeer.js +2 -1
  507. package/src/engine/network/sim/ActionLog.d.ts +9 -6
  508. package/src/engine/network/sim/ActionLog.d.ts.map +1 -1
  509. package/src/engine/network/sim/ActionLog.js +43 -80
  510. package/src/engine/network/sim/SmoothingState.d.ts.map +1 -1
  511. package/src/engine/network/sim/SmoothingState.js +27 -28
  512. package/src/engine/network/state/FrameBufferRing.d.ts +84 -0
  513. package/src/engine/network/state/FrameBufferRing.d.ts.map +1 -0
  514. package/src/engine/network/state/FrameBufferRing.js +168 -0
  515. package/src/engine/network/state/InputRing.d.ts +14 -12
  516. package/src/engine/network/state/InputRing.d.ts.map +1 -1
  517. package/src/engine/network/state/InputRing.js +37 -76
  518. package/src/engine/network/transport/LoopbackTransport.d.ts.map +1 -1
  519. package/src/engine/network/transport/LoopbackTransport.js +10 -31
  520. package/src/engine/network/transport/Transport.d.ts +42 -2
  521. package/src/engine/network/transport/Transport.d.ts.map +1 -1
  522. package/src/engine/network/transport/Transport.js +87 -3
  523. package/src/engine/network/transport/adapters/NodeUDPTransport.d.ts.map +1 -1
  524. package/src/engine/network/transport/adapters/NodeUDPTransport.js +7 -33
  525. package/src/engine/network/transport/adapters/SimulatedTransport.d.ts.map +1 -1
  526. package/src/engine/network/transport/adapters/SimulatedTransport.js +17 -28
  527. package/src/engine/network/transport/adapters/WebRTCDataChannelTransport.d.ts.map +1 -1
  528. package/src/engine/network/transport/adapters/WebRTCDataChannelTransport.js +6 -32
  529. package/src/engine/network/transport/adapters/WebSocketTransport.d.ts.map +1 -1
  530. package/src/engine/network/transport/adapters/WebSocketTransport.js +6 -32
  531. package/src/engine/network/transport/adapters/WebTransportTransport.d.ts.map +1 -1
  532. package/src/engine/network/transport/adapters/WebTransportTransport.js +11 -22
  533. package/src/engine/physics/constraint/solve_constraints.d.ts.map +1 -1
  534. package/src/engine/physics/constraint/solve_constraints.js +18 -48
  535. package/src/engine/physics/fluid/ecs/FluidObstacleSystem.d.ts +4 -4
  536. package/src/engine/physics/fluid/ecs/FluidSystem.d.ts +3 -3
  537. package/src/engine/physics/fluid/solver/v3_grid_advect_maccormack_scalar.d.ts.map +1 -1
  538. package/src/engine/physics/fluid/solver/v3_grid_advect_maccormack_scalar.js +7 -0
  539. package/src/engine/physics/fluid/solver/v3_grid_advect_maccormack_velocity.d.ts.map +1 -1
  540. package/src/engine/physics/fluid/solver/v3_grid_advect_maccormack_velocity.js +11 -18
  541. package/src/engine/physics/fluid/solver/v3_grid_advect_sl_velocity.d.ts.map +1 -1
  542. package/src/engine/physics/fluid/solver/v3_grid_advect_sl_velocity.js +7 -0
  543. package/src/engine/physics/fluid/solver/v3_grid_apply_advection_forward.d.ts.map +1 -1
  544. package/src/engine/physics/fluid/solver/v3_grid_apply_advection_forward.js +15 -57
  545. package/src/engine/physics/fluid/solver/v3_grid_apply_scalar_advection.d.ts.map +1 -1
  546. package/src/engine/physics/fluid/solver/v3_grid_apply_scalar_advection.js +7 -0
  547. package/src/engine/physics/fluid/solver/v3_grid_limit8_at_indices.d.ts +28 -0
  548. package/src/engine/physics/fluid/solver/v3_grid_limit8_at_indices.d.ts.map +1 -0
  549. package/src/engine/physics/fluid/solver/v3_grid_limit8_at_indices.js +38 -0
  550. package/src/engine/physics/fluid/solver/v3_mac_advect_maccormack_velocity.d.ts.map +1 -1
  551. package/src/engine/physics/fluid/solver/v3_mac_advect_maccormack_velocity.js +12 -14
  552. package/src/engine/physics/fluid/solver/v3_mac_apply_vorticity_confinement.d.ts.map +1 -1
  553. package/src/engine/physics/fluid/solver/v3_mac_apply_vorticity_confinement.js +9 -0
  554. package/src/engine/physics/mls-mpm/MLS_MPM.d.ts +13 -1
  555. package/src/engine/physics/mls-mpm/MLS_MPM.d.ts.map +1 -1
  556. package/src/engine/physics/mls-mpm/MLS_MPM.js +15 -4
  557. package/src/engine/physics/narrowphase/box_triangle_contact.d.ts.map +1 -1
  558. package/src/engine/physics/narrowphase/box_triangle_contact.js +9 -0
  559. package/src/engine/physics/narrowphase/capsule_contacts.d.ts.map +1 -1
  560. package/src/engine/physics/narrowphase/capsule_contacts.js +10 -11
  561. package/src/engine/physics/narrowphase/sphere_triangle_contact.d.ts.map +1 -1
  562. package/src/engine/physics/narrowphase/sphere_triangle_contact.js +7 -12
  563. package/src/engine/physics/solver/apply_impulse_to_body.d.ts +36 -0
  564. package/src/engine/physics/solver/apply_impulse_to_body.d.ts.map +1 -0
  565. package/src/engine/physics/solver/apply_impulse_to_body.js +86 -0
  566. package/src/engine/physics/solver/solve_contacts.d.ts.map +1 -1
  567. package/src/engine/physics/solver/solve_contacts.js +1 -53
  568. package/src/engine/plugin/EnginePlugin.d.ts +3 -0
  569. package/src/engine/plugin/EnginePlugin.d.ts.map +1 -1
  570. package/src/engine/plugin/EnginePlugin.js +3 -0
  571. package/src/engine/save/storage/IndexedDBStorage.d.ts +1 -0
  572. package/src/engine/save/storage/IndexedDBStorage.d.ts.map +1 -1
  573. package/src/engine/save/storage/IndexedDBStorage.js +50 -50
  574. package/src/engine/sound/ecs/SoundControllerSystem.d.ts.map +1 -1
  575. package/src/engine/sound/ecs/SoundControllerSystem.js +2 -10
  576. package/src/engine/sound/simulation/AcousticSimulator.d.ts.map +1 -1
  577. package/src/engine/sound/simulation/AcousticSimulator.js +2 -1
  578. package/src/engine/sound/simulation/core/AcousticOccluderIndex.d.ts.map +1 -1
  579. package/src/engine/sound/simulation/core/AcousticOccluderIndex.js +4 -6
  580. package/src/engine/sound/simulation/core/OcclusionSolver.d.ts.map +1 -1
  581. package/src/engine/sound/simulation/core/OcclusionSolver.js +2 -9
  582. package/src/engine/sound/simulation/probe/ProbeVisibilityRecheck.d.ts.map +1 -1
  583. package/src/engine/sound/simulation/probe/ProbeVisibilityRecheck.js +9 -14
  584. package/src/engine/sound/simulation/probe/bakeReverbBands.d.ts.map +1 -1
  585. package/src/engine/sound/simulation/probe/bakeReverbBands.js +2 -6
  586. package/src/engine/sound/simulation/probe/bakeVisibility.d.ts.map +1 -1
  587. package/src/engine/sound/simulation/probe/bakeVisibility.js +4 -34
  588. package/src/engine/sound/simulation/probe/probe_densify_portals.d.ts.map +1 -1
  589. package/src/engine/sound/simulation/probe/probe_densify_portals.js +3 -6
  590. package/src/engine/sound/simulation/probe/probe_edge_key.d.ts +31 -0
  591. package/src/engine/sound/simulation/probe/probe_edge_key.d.ts.map +1 -0
  592. package/src/engine/sound/simulation/probe/probe_edge_key.js +38 -0
  593. package/src/engine/sound/simulation/probe/probe_sdf_grid.d.ts +10 -3
  594. package/src/engine/sound/simulation/probe/probe_sdf_grid.d.ts.map +1 -1
  595. package/src/engine/sound/simulation/probe/probe_sdf_grid.js +10 -22
  596. package/src/engine/sound/simulation/probe/probe_visibility_augment.d.ts.map +1 -1
  597. package/src/engine/sound/simulation/probe/probe_visibility_augment.js +12 -48
  598. package/src/engine/sound/simulation/probe/probe_visibility_bridge_components.d.ts.map +1 -1
  599. package/src/engine/sound/simulation/probe/probe_visibility_bridge_components.js +4 -3
  600. package/src/engine/sound/simulation/render/foaReverbImpulseResponse.d.ts +5 -4
  601. package/src/engine/sound/simulation/render/foaReverbImpulseResponse.d.ts.map +1 -1
  602. package/src/engine/sound/simulation/render/foaReverbImpulseResponse.js +23 -31
  603. package/src/engine/sound/simulation/render/reverbImpulseResponse.d.ts +1 -8
  604. package/src/engine/sound/simulation/render/reverbImpulseResponse.d.ts.map +1 -1
  605. package/src/engine/sound/simulation/render/reverbImpulseResponse.js +21 -31
  606. package/src/engine/sound/simulation/render/reverb_band_tails.d.ts +55 -0
  607. package/src/engine/sound/simulation/render/reverb_band_tails.d.ts.map +1 -0
  608. package/src/engine/sound/simulation/render/reverb_band_tails.js +93 -0
  609. package/src/engine/sound/sopra/definition/EventDescriptionSerializationAdapter.d.ts.map +1 -1
  610. package/src/engine/sound/sopra/definition/EventDescriptionSerializationAdapter.js +6 -22
  611. package/src/engine/sound/sopra/definition/clip/BlendContainerAudioClip.d.ts.map +1 -1
  612. package/src/engine/sound/sopra/definition/clip/BlendContainerAudioClip.js +7 -3
  613. package/src/engine/sound/sopra/definition/clip/BlendContainerAudioClipSerializationAdapter.d.ts.map +1 -1
  614. package/src/engine/sound/sopra/definition/clip/BlendContainerAudioClipSerializationAdapter.js +7 -22
  615. package/src/engine/sound/sopra/definition/clip/ContainerAudioClip.d.ts.map +1 -1
  616. package/src/engine/sound/sopra/definition/clip/ContainerAudioClip.js +28 -0
  617. package/src/engine/sound/sopra/definition/clip/RandomContainerAudioClip.d.ts.map +1 -1
  618. package/src/engine/sound/sopra/definition/clip/RandomContainerAudioClip.js +1 -5
  619. package/src/engine/sound/sopra/definition/clip/SequenceContainerAudioClip.d.ts.map +1 -1
  620. package/src/engine/sound/sopra/definition/clip/SequenceContainerAudioClip.js +1 -13
  621. package/src/engine/sound/sopra/definition/clip/SwitchContainerAudioClip.d.ts.map +1 -1
  622. package/src/engine/sound/sopra/definition/clip/SwitchContainerAudioClip.js +2 -8
  623. package/src/engine/sound/sopra/definition/effect/ReverbEffect.d.ts +3 -0
  624. package/src/engine/sound/sopra/definition/effect/ReverbEffect.d.ts.map +1 -1
  625. package/src/engine/sound/sopra/definition/effect/ReverbEffect.js +26 -14
  626. package/src/engine/sound/sopra/runtime/BusGraph.d.ts.map +1 -1
  627. package/src/engine/sound/sopra/runtime/BusGraph.js +21 -33
  628. package/src/engine/sound/sopra/runtime/EventInstance.js +1 -1
  629. package/src/engine/ui/apply_pointer_tilt_3d.d.ts +25 -0
  630. package/src/engine/ui/apply_pointer_tilt_3d.d.ts.map +1 -0
  631. package/src/engine/ui/apply_pointer_tilt_3d.js +50 -0
  632. package/src/engine/ui/bindings/processors/DomElementProcessorTilt3D.d.ts.map +1 -1
  633. package/src/engine/ui/bindings/processors/DomElementProcessorTilt3D.js +9 -26
  634. package/src/generation/filtering/numeric/CellFilterCache.d.ts.map +1 -1
  635. package/src/generation/filtering/numeric/CellFilterCache.js +4 -21
  636. package/src/generation/filtering/numeric/complex/CellFilterSobel.d.ts.map +1 -1
  637. package/src/generation/filtering/numeric/complex/CellFilterSobel.js +11 -20
  638. package/src/generation/filtering/numeric/math/CellFilterPower.d.ts +1 -1
  639. package/src/generation/filtering/numeric/math/CellFilterPower.d.ts.map +1 -1
  640. package/src/generation/filtering/numeric/math/CellFilterPower.js +1 -5
  641. package/src/generation/filtering/numeric/process/computeCellFilterGradient.d.ts.map +1 -1
  642. package/src/generation/filtering/numeric/process/computeCellFilterGradient.js +13 -15
  643. package/src/generation/filtering/numeric/process/computeCellFilterSobel.d.ts +20 -0
  644. package/src/generation/filtering/numeric/process/computeCellFilterSobel.d.ts.map +1 -0
  645. package/src/generation/filtering/numeric/process/computeCellFilterSobel.js +36 -0
  646. package/src/generation/filtering/numeric/util/CellFilterDisplaced.d.ts.map +1 -1
  647. package/src/generation/filtering/numeric/util/CellFilterDisplaced.js +11 -6
  648. package/src/generation/filtering/numeric/util/populateSampler2DFromCellFilter.d.ts.map +1 -1
  649. package/src/generation/filtering/numeric/util/populateSampler2DFromCellFilter.js +18 -36
  650. package/src/generation/filtering/numeric/util/write_cell_filter_to_sampler2d.d.ts +21 -0
  651. package/src/generation/filtering/numeric/util/write_cell_filter_to_sampler2d.d.ts.map +1 -0
  652. package/src/generation/filtering/numeric/util/write_cell_filter_to_sampler2d.js +47 -0
  653. package/src/generation/filtering/util/cell_filter_weights_pick.d.ts +25 -0
  654. package/src/generation/filtering/util/cell_filter_weights_pick.d.ts.map +1 -0
  655. package/src/generation/filtering/util/cell_filter_weights_pick.js +54 -0
  656. package/src/generation/grid/generation/discrete/GridTaskConnectRooms.d.ts.map +1 -1
  657. package/src/generation/grid/generation/discrete/GridTaskConnectRooms.js +14 -1
  658. package/src/generation/markers/GridActionRuleSet.d.ts.map +1 -1
  659. package/src/generation/markers/GridActionRuleSet.js +10 -7
  660. package/src/generation/markers/GridCellActionPlaceMarker.d.ts.map +1 -1
  661. package/src/generation/markers/GridCellActionPlaceMarker.js +10 -12
  662. package/src/generation/markers/actions/probability/MarkerNodeActionSelectWeighted.d.ts.map +1 -1
  663. package/src/generation/markers/actions/probability/MarkerNodeActionSelectWeighted.js +7 -42
  664. package/src/generation/markers/transform/MarkerNodeTransformerOffsetPosition.d.ts.map +1 -1
  665. package/src/generation/markers/transform/MarkerNodeTransformerOffsetPosition.js +11 -6
  666. package/src/generation/placement/GridCellPlacementRule.d.ts.map +1 -1
  667. package/src/generation/placement/GridCellPlacementRule.js +10 -7
  668. package/src/generation/placement/action/GridCellActionPlaceTags.d.ts.map +1 -1
  669. package/src/generation/placement/action/GridCellActionPlaceTags.js +10 -4
  670. package/src/generation/placement/action/random/weighted/CellActionSelectWeightedRandom.d.ts.map +1 -1
  671. package/src/generation/placement/action/random/weighted/CellActionSelectWeightedRandom.js +2 -38
  672. package/src/generation/placement/action/util/GridCellDisplacedAction.d.ts.map +1 -1
  673. package/src/generation/placement/action/util/GridCellDisplacedAction.js +11 -6
  674. package/src/generation/rules/cell/CellMatcherGridPattern.d.ts.map +1 -1
  675. package/src/generation/rules/cell/CellMatcherGridPattern.js +11 -4
  676. package/src/generation/theme/ThemeEngine.d.ts.map +1 -1
  677. package/src/generation/theme/ThemeEngine.js +7 -12
  678. package/src/view/elements/Group.d.ts +24 -3
  679. package/src/view/elements/Group.d.ts.map +1 -1
  680. package/src/view/elements/Group.js +56 -34
@@ -0,0 +1,2124 @@
1
+ import Vector2 from "../../../../core/geom/Vector2.js";
2
+ import { EngineHarness } from "../../../EngineHarness.js";
3
+ import { apply_radial_dead_zone } from "../../analog/apply_radial_dead_zone.js";
4
+ import { GamepadAxes } from "./GamepadAxes.js";
5
+ import { GamepadButtons } from "./GamepadButtons.js";
6
+ import { GAMEPAD_LAYOUT_ABSENT, GAMEPAD_STANDARD_LAYOUT } from "./GamepadLayout.js";
7
+ import { gamepad_write_dpad_vector } from "./gamepad_write_dpad_vector.js";
8
+ import { GAMEPAD_STANDARD_AXIS_COUNT, GAMEPAD_STANDARD_BUTTON_COUNT } from "./GamepadStandardMapping.js";
9
+
10
+ /**
11
+ * Gamepad tester.
12
+ *
13
+ * Two layers over the same hardware, drawn one above the other so they can be read against each other:
14
+ *
15
+ * - Layer 1 is {@link GamepadDevice}, reached through `engine.devices.gamepad`. It shows what a consumer of the
16
+ * engine sees: the persistent {@link GamepadDevice#main} handle, switches and their press counts, raw axes,
17
+ * per-stick calibration, and the composition the device documents (dead zone + D-pad vector + fusion).
18
+ * - Layer 2 is `navigator.getGamepads()` read directly, with no engine in the path. It shows what the browser
19
+ * reports, unfiltered.
20
+ *
21
+ * Between them sits a parity strip that diffs the two, because the device layer's contract is that `axes` and
22
+ * button values are a byte-exact mirror of the hardware snapshot. Anything that layer changes shows up there.
23
+ *
24
+ * Both layers are read from one animation frame, and the device's own poll runs earlier in that same frame
25
+ * (it registers its callback when the engine is constructed), so the two views describe the same instant.
26
+ *
27
+ * @author Alex Goldring
28
+ * @copyright Company Named Limited (c) 2026
29
+ */
30
+
31
+ /**
32
+ * Button index -> name of the standard mapping, derived so the two never drift apart
33
+ * @readonly
34
+ * @type {string[]}
35
+ */
36
+ const BUTTON_NAMES = [];
37
+
38
+ for (const name in GamepadButtons) {
39
+ BUTTON_NAMES[GamepadButtons[name]] = name;
40
+ }
41
+
42
+ /**
43
+ * Axis index -> name of the standard mapping
44
+ * @readonly
45
+ * @type {string[]}
46
+ */
47
+ const AXIS_NAMES = [];
48
+
49
+ for (const name in GamepadAxes) {
50
+ AXIS_NAMES[GamepadAxes[name]] = name;
51
+ }
52
+
53
+ /**
54
+ * Edge length of a stick scope, in CSS pixels
55
+ * @type {number}
56
+ */
57
+ const SCOPE_SIZE = 176;
58
+
59
+ /**
60
+ * How many past raw samples a scope draws as a trail. At 60Hz this is about 1.5 seconds, enough to see a
61
+ * snap-back overshoot or a slow drift walk.
62
+ * @type {number}
63
+ */
64
+ const TRAIL_SAMPLE_COUNT = 90;
65
+
66
+ const TIMELINE_WIDTH = 680;
67
+ const TIMELINE_HEIGHT = 150;
68
+
69
+ /**
70
+ * About 8 seconds at 60Hz
71
+ * @type {number}
72
+ */
73
+ const TIMELINE_SAMPLE_COUNT = 480;
74
+
75
+ /**
76
+ * Channels plotted by {@link AxisTimelineView}. Triggers are included because they are the analog inputs that
77
+ * are not axes, and their travel is exactly what a tester is here to look at.
78
+ * @readonly
79
+ */
80
+ const TIMELINE_CHANNELS = [
81
+ { label: "left stick x", color: "#4ade80" },
82
+ { label: "left stick y", color: "#22d3ee" },
83
+ { label: "right stick x", color: "#f472b6" },
84
+ { label: "right stick y", color: "#fbbf24" },
85
+ { label: "left trigger", color: "#a78bfa" },
86
+ { label: "right trigger", color: "#fb923c" }
87
+ ];
88
+
89
+ const MAX_LOG_ENTRIES = 200;
90
+
91
+ /**
92
+ * Standard button indices that form the D-pad, which a non-standard pad may drive from a hat axis instead
93
+ * @readonly
94
+ * @type {number[]}
95
+ */
96
+ const DPAD_BUTTONS = [
97
+ GamepadButtons.dpad_up,
98
+ GamepadButtons.dpad_right,
99
+ GamepadButtons.dpad_down,
100
+ GamepadButtons.dpad_left
101
+ ];
102
+
103
+ const STYLE = `
104
+ .gpt-root {
105
+ position: fixed;
106
+ left: 0;
107
+ top: 0;
108
+ width: 100%;
109
+ height: 100%;
110
+ overflow: auto;
111
+ box-sizing: border-box;
112
+ padding: 16px;
113
+ background: #0f1216;
114
+ color: #d7dee8;
115
+ font: 12px/1.45 "Consolas", "Menlo", monospace;
116
+ z-index: 100;
117
+ }
118
+ .gpt-root h1 {
119
+ margin: 0 0 2px 0;
120
+ font-size: 17px;
121
+ font-weight: 600;
122
+ letter-spacing: 0.4px;
123
+ }
124
+ .gpt-root h2 {
125
+ margin: 0;
126
+ font-size: 13px;
127
+ font-weight: 600;
128
+ letter-spacing: 0.4px;
129
+ }
130
+ .gpt-muted {
131
+ color: #7d8899;
132
+ }
133
+ .gpt-header {
134
+ margin-bottom: 14px;
135
+ }
136
+ .gpt-layer {
137
+ border: 1px solid #262d38;
138
+ border-radius: 6px;
139
+ background: #161a21;
140
+ margin-bottom: 12px;
141
+ }
142
+ .gpt-layer-head {
143
+ display: flex;
144
+ align-items: baseline;
145
+ gap: 10px;
146
+ padding: 8px 12px;
147
+ border-bottom: 1px solid #262d38;
148
+ background: #1a1f28;
149
+ border-radius: 6px 6px 0 0;
150
+ }
151
+ .gpt-layer-badge {
152
+ padding: 1px 7px;
153
+ border-radius: 10px;
154
+ background: #2b3442;
155
+ color: #9fb0c6;
156
+ font-size: 11px;
157
+ }
158
+ .gpt-layer-body {
159
+ padding: 12px;
160
+ display: flex;
161
+ flex-wrap: wrap;
162
+ gap: 12px;
163
+ }
164
+ .gpt-panel {
165
+ border: 1px solid #232a35;
166
+ border-radius: 5px;
167
+ padding: 9px 10px;
168
+ background: #12161c;
169
+ }
170
+ .gpt-panel-title {
171
+ color: #8fa0b6;
172
+ font-size: 11px;
173
+ text-transform: uppercase;
174
+ letter-spacing: 0.7px;
175
+ margin-bottom: 7px;
176
+ }
177
+ .gpt-kv {
178
+ display: grid;
179
+ grid-template-columns: auto 1fr;
180
+ gap: 1px 10px;
181
+ }
182
+ .gpt-kv > .gpt-k {
183
+ color: #7d8899;
184
+ }
185
+ .gpt-kv > .gpt-v {
186
+ color: #d7dee8;
187
+ word-break: break-all;
188
+ }
189
+ .gpt-buttons {
190
+ display: grid;
191
+ grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
192
+ gap: 5px;
193
+ width: 480px;
194
+ }
195
+ .gpt-button {
196
+ border: 1px solid #232a35;
197
+ border-radius: 4px;
198
+ padding: 4px 6px;
199
+ background: #12161c;
200
+ }
201
+ .gpt-button.gpt-down {
202
+ border-color: #4ade80;
203
+ background: #16241c;
204
+ }
205
+ .gpt-button-head {
206
+ display: flex;
207
+ align-items: center;
208
+ gap: 5px;
209
+ }
210
+ .gpt-pip {
211
+ width: 8px;
212
+ height: 8px;
213
+ border-radius: 50%;
214
+ background: #2b3442;
215
+ flex: none;
216
+ }
217
+ .gpt-down .gpt-pip {
218
+ background: #4ade80;
219
+ box-shadow: 0 0 6px #4ade80;
220
+ }
221
+ .gpt-button-name {
222
+ flex: 1;
223
+ overflow: hidden;
224
+ text-overflow: ellipsis;
225
+ white-space: nowrap;
226
+ }
227
+ .gpt-button-index, .gpt-button-count {
228
+ color: #7d8899;
229
+ font-size: 10px;
230
+ }
231
+ .gpt-bar {
232
+ position: relative;
233
+ height: 5px;
234
+ margin-top: 4px;
235
+ border-radius: 3px;
236
+ background: #1e242e;
237
+ overflow: hidden;
238
+ }
239
+ .gpt-bar-fill {
240
+ position: absolute;
241
+ top: 0;
242
+ height: 100%;
243
+ background: #4ade80;
244
+ }
245
+ .gpt-bar-fill.gpt-signed {
246
+ background: #22d3ee;
247
+ }
248
+ .gpt-axis {
249
+ display: grid;
250
+ grid-template-columns: 92px 1fr 64px;
251
+ align-items: center;
252
+ gap: 8px;
253
+ margin-bottom: 3px;
254
+ }
255
+ .gpt-axis .gpt-bar {
256
+ margin-top: 0;
257
+ height: 8px;
258
+ }
259
+ .gpt-axis-value {
260
+ text-align: right;
261
+ color: #b9c4d3;
262
+ }
263
+ .gpt-sticks {
264
+ display: flex;
265
+ gap: 12px;
266
+ }
267
+ .gpt-stick canvas {
268
+ display: block;
269
+ border: 1px solid #232a35;
270
+ border-radius: 4px;
271
+ background: #0d1014;
272
+ }
273
+ .gpt-legend {
274
+ display: flex;
275
+ flex-wrap: wrap;
276
+ gap: 8px;
277
+ margin-top: 5px;
278
+ font-size: 11px;
279
+ }
280
+ .gpt-legend span:before {
281
+ content: "";
282
+ display: inline-block;
283
+ width: 7px;
284
+ height: 7px;
285
+ border-radius: 50%;
286
+ margin-right: 4px;
287
+ background: currentColor;
288
+ }
289
+ .gpt-controls {
290
+ display: flex;
291
+ flex-direction: column;
292
+ gap: 6px;
293
+ }
294
+ .gpt-control {
295
+ display: grid;
296
+ grid-template-columns: 96px 1fr 44px;
297
+ align-items: center;
298
+ gap: 8px;
299
+ }
300
+ .gpt-root input[type="range"] {
301
+ width: 100%;
302
+ }
303
+ .gpt-root button {
304
+ font: inherit;
305
+ color: #d7dee8;
306
+ background: #232a35;
307
+ border: 1px solid #303a48;
308
+ border-radius: 4px;
309
+ padding: 3px 9px;
310
+ cursor: pointer;
311
+ }
312
+ .gpt-root button:hover {
313
+ background: #2c3543;
314
+ }
315
+ .gpt-log {
316
+ height: 150px;
317
+ overflow: auto;
318
+ background: #0d1014;
319
+ border: 1px solid #232a35;
320
+ border-radius: 4px;
321
+ padding: 6px 8px;
322
+ width: 100%;
323
+ box-sizing: border-box;
324
+ }
325
+ .gpt-log-entry {
326
+ white-space: pre;
327
+ }
328
+ .gpt-sync {
329
+ display: flex;
330
+ align-items: center;
331
+ gap: 10px;
332
+ padding: 7px 12px;
333
+ margin-bottom: 12px;
334
+ border: 1px solid #262d38;
335
+ border-radius: 6px;
336
+ background: #161a21;
337
+ }
338
+ .gpt-status {
339
+ padding: 1px 8px;
340
+ border-radius: 10px;
341
+ font-size: 11px;
342
+ background: #2b3442;
343
+ color: #9fb0c6;
344
+ }
345
+ .gpt-status.gpt-ok {
346
+ background: #16351f;
347
+ color: #4ade80;
348
+ }
349
+ .gpt-status.gpt-bad {
350
+ background: #3a1b1b;
351
+ color: #f87171;
352
+ }
353
+ .gpt-native-pads {
354
+ display: flex;
355
+ flex-wrap: wrap;
356
+ gap: 12px;
357
+ width: 100%;
358
+ }
359
+ .gpt-native-buttons {
360
+ display: grid;
361
+ grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
362
+ gap: 3px;
363
+ }
364
+ .gpt-native-button {
365
+ display: flex;
366
+ align-items: center;
367
+ gap: 4px;
368
+ padding: 2px 4px;
369
+ border-radius: 3px;
370
+ background: #12161c;
371
+ border: 1px solid #232a35;
372
+ font-size: 11px;
373
+ }
374
+ .gpt-native-button.gpt-down {
375
+ border-color: #4ade80;
376
+ color: #4ade80;
377
+ }
378
+ .gpt-native-button.gpt-touched {
379
+ border-color: #fbbf24;
380
+ }
381
+ .gpt-pads-summary {
382
+ width: 100%;
383
+ }
384
+ .gpt-pad-row {
385
+ display: grid;
386
+ grid-template-columns: 46px 90px 1fr;
387
+ gap: 10px;
388
+ padding: 2px 0;
389
+ border-top: 1px solid #1c222b;
390
+ }
391
+ `;
392
+
393
+ /**
394
+ *
395
+ * @param {string} tag
396
+ * @param {string} className
397
+ * @param {HTMLElement} [parent]
398
+ * @returns {HTMLElement}
399
+ */
400
+ function make_element(tag, className, parent) {
401
+ const el = document.createElement(tag);
402
+
403
+ if (className !== "") {
404
+ el.className = className;
405
+ }
406
+
407
+ if (parent !== undefined) {
408
+ parent.appendChild(el);
409
+ }
410
+
411
+ return el;
412
+ }
413
+
414
+ /**
415
+ *
416
+ * @param {HTMLElement} el
417
+ * @param {string} text
418
+ * @returns {void}
419
+ */
420
+ function write_text(el, text) {
421
+ if (el.textContent !== text) {
422
+ el.textContent = text;
423
+ }
424
+ }
425
+
426
+ /**
427
+ * Key/value grid where values are addressed by key, saving every panel from holding a field per row.
428
+ */
429
+ class PropertyTableView {
430
+
431
+ /**
432
+ * @readonly
433
+ * @type {HTMLElement}
434
+ */
435
+ el;
436
+
437
+ /**
438
+ * @type {Map<string,HTMLElement>}
439
+ */
440
+ #values = new Map();
441
+
442
+ /**
443
+ *
444
+ * @param {string[]} keys
445
+ */
446
+ constructor(keys) {
447
+ this.el = make_element("div", "gpt-kv");
448
+
449
+ const n = keys.length;
450
+
451
+ for (let i = 0; i < n; i++) {
452
+ const key = keys[i];
453
+
454
+ const k = make_element("div", "gpt-k", this.el);
455
+ k.textContent = key;
456
+
457
+ const v = make_element("div", "gpt-v", this.el);
458
+ v.textContent = "-";
459
+
460
+ this.#values.set(key, v);
461
+ }
462
+ }
463
+
464
+ /**
465
+ *
466
+ * @param {string} key one of the keys this table was built with
467
+ * @param {string} value
468
+ * @returns {void}
469
+ */
470
+ write(key, value) {
471
+ write_text(this.#values.get(key), value);
472
+ }
473
+ }
474
+
475
+ /**
476
+ * One button of {@link GamepadHandle}: state, analog travel, and how many times it has been pressed.
477
+ *
478
+ * The press count comes from the switch's own signal rather than from comparing frames, so a button that
479
+ * chatters - firing two presses for one physical push - shows up as a count climbing faster than the presses,
480
+ * which polling this view every frame could not tell you.
481
+ */
482
+ class ButtonView {
483
+
484
+ /**
485
+ * @readonly
486
+ * @type {HTMLElement}
487
+ */
488
+ el;
489
+
490
+ /**
491
+ * @type {HTMLElement}
492
+ */
493
+ #fill;
494
+
495
+ /**
496
+ * @type {HTMLElement}
497
+ */
498
+ #value;
499
+
500
+ /**
501
+ * @type {HTMLElement}
502
+ */
503
+ #count;
504
+
505
+ /**
506
+ * @type {number}
507
+ */
508
+ #pressCount = 0;
509
+
510
+ /**
511
+ * @type {InputDeviceSwitch}
512
+ */
513
+ #source;
514
+
515
+ /**
516
+ *
517
+ * @param {number} index
518
+ * @param {InputDeviceSwitch} button
519
+ */
520
+ constructor(index, button) {
521
+ this.#source = button;
522
+
523
+ this.el = make_element("div", "gpt-button");
524
+
525
+ const head = make_element("div", "gpt-button-head", this.el);
526
+
527
+ make_element("div", "gpt-pip", head);
528
+
529
+ const name = make_element("div", "gpt-button-name", head);
530
+ name.textContent = BUTTON_NAMES[index] !== undefined ? BUTTON_NAMES[index] : "extra";
531
+
532
+ const indexLabel = make_element("div", "gpt-button-index", head);
533
+ indexLabel.textContent = String(index);
534
+
535
+ const bar = make_element("div", "gpt-bar", this.el);
536
+ this.#fill = make_element("div", "gpt-bar-fill", bar);
537
+
538
+ const foot = make_element("div", "gpt-button-head", this.el);
539
+
540
+ this.#value = make_element("div", "gpt-button-name gpt-muted", foot);
541
+ this.#count = make_element("div", "gpt-button-count", foot);
542
+
543
+ button.down.add(this.#handleDown);
544
+ }
545
+
546
+ #handleDown = () => {
547
+ this.#pressCount++;
548
+ }
549
+
550
+ /**
551
+ * Stop counting presses. Used when the grid is rebuilt for a handle with a different button count.
552
+ * @returns {void}
553
+ */
554
+ dispose() {
555
+ this.#source.down.remove(this.#handleDown);
556
+ }
557
+
558
+ /**
559
+ *
560
+ * @param {number} value analog travel in [0,1]
561
+ * @returns {void}
562
+ */
563
+ update(value) {
564
+ const is_down = this.#source.is_down;
565
+
566
+ this.el.classList.toggle("gpt-down", is_down);
567
+
568
+ const width = `${(value * 100).toFixed(1)}%`;
569
+
570
+ if (this.#fill.style.width !== width) {
571
+ this.#fill.style.width = width;
572
+ }
573
+
574
+ write_text(this.#value, value.toFixed(3));
575
+ write_text(this.#count, `x${this.#pressCount}`);
576
+ }
577
+ }
578
+
579
+ /**
580
+ * A signed [-1,1] bar with a numeric readout, drawn from the middle out.
581
+ */
582
+ class AxisView {
583
+
584
+ /**
585
+ * @readonly
586
+ * @type {HTMLElement}
587
+ */
588
+ el;
589
+
590
+ /**
591
+ * @type {HTMLElement}
592
+ */
593
+ #fill;
594
+
595
+ /**
596
+ * @type {HTMLElement}
597
+ */
598
+ #value;
599
+
600
+ /**
601
+ *
602
+ * @param {string} label
603
+ */
604
+ constructor(label) {
605
+ this.el = make_element("div", "gpt-axis");
606
+
607
+ const name = make_element("div", "", this.el);
608
+ name.textContent = label;
609
+
610
+ const bar = make_element("div", "gpt-bar", this.el);
611
+ this.#fill = make_element("div", "gpt-bar-fill gpt-signed", bar);
612
+
613
+ this.#value = make_element("div", "gpt-axis-value", this.el);
614
+ }
615
+
616
+ /**
617
+ *
618
+ * @param {number} value
619
+ * @returns {void}
620
+ */
621
+ update(value) {
622
+ const half = Math.min(Math.abs(value), 1) * 50;
623
+
624
+ const left = value < 0 ? `${50 - half}%` : "50%";
625
+ const width = `${half}%`;
626
+
627
+ if (this.#fill.style.left !== left) {
628
+ this.#fill.style.left = left;
629
+ }
630
+
631
+ if (this.#fill.style.width !== width) {
632
+ this.#fill.style.width = width;
633
+ }
634
+
635
+ write_text(this.#value, value.toFixed(4));
636
+ }
637
+ }
638
+
639
+ /**
640
+ * 2D scope for one {@link GamepadStick}.
641
+ *
642
+ * Drawn in the hardware frame, so +y is down and the canvas needs no flip. Four things are plotted on top of
643
+ * each other, and the point of the view is that they are usually not in the same place:
644
+ *
645
+ * - the raw hardware value, with a trail of where it has just been;
646
+ * - the learned rest position and noise radius, which is the correction the device applies;
647
+ * - the calibrated value the engine hands to gameplay;
648
+ * - the same value after a gameplay dead zone, which is what a game would actually move on.
649
+ */
650
+ class StickScopeView {
651
+
652
+ /**
653
+ * @readonly
654
+ * @type {HTMLElement}
655
+ */
656
+ el;
657
+
658
+ /**
659
+ * @type {CanvasRenderingContext2D}
660
+ */
661
+ #ctx;
662
+
663
+ /**
664
+ * @type {PropertyTableView}
665
+ */
666
+ #properties;
667
+
668
+ /**
669
+ * Interleaved x,y of past raw samples, used as a ring buffer
670
+ * @type {Float32Array}
671
+ */
672
+ #trail = new Float32Array(TRAIL_SAMPLE_COUNT * 2);
673
+
674
+ /**
675
+ * @type {number}
676
+ */
677
+ #trailCursor = 0;
678
+
679
+ /**
680
+ * @type {number}
681
+ */
682
+ #trailCount = 0;
683
+
684
+ /**
685
+ * @type {Vector2}
686
+ */
687
+ #shaped = new Vector2();
688
+
689
+ /**
690
+ *
691
+ * @param {string} label
692
+ */
693
+ constructor(label) {
694
+ this.el = make_element("div", "gpt-panel gpt-stick");
695
+
696
+ const title = make_element("div", "gpt-panel-title", this.el);
697
+ title.textContent = label;
698
+
699
+ const canvas = make_element("canvas", "", this.el);
700
+
701
+ const dpr = window.devicePixelRatio;
702
+
703
+ canvas.width = SCOPE_SIZE * dpr;
704
+ canvas.height = SCOPE_SIZE * dpr;
705
+ canvas.style.width = `${SCOPE_SIZE}px`;
706
+ canvas.style.height = `${SCOPE_SIZE}px`;
707
+
708
+ this.#ctx = canvas.getContext("2d");
709
+ this.#ctx.scale(dpr, dpr);
710
+
711
+ const legend = make_element("div", "gpt-legend", this.el);
712
+
713
+ const raw = make_element("span", "", legend);
714
+ raw.textContent = "raw";
715
+ raw.style.color = "#7d8899";
716
+
717
+ const value = make_element("span", "", legend);
718
+ value.textContent = "calibrated";
719
+ value.style.color = "#4ade80";
720
+
721
+ const shaped = make_element("span", "", legend);
722
+ shaped.textContent = "dead zoned";
723
+ shaped.style.color = "#fbbf24";
724
+
725
+ this.#properties = new PropertyTableView([
726
+ "raw",
727
+ "value",
728
+ "magnitude",
729
+ "dead zoned",
730
+ "center",
731
+ "noise radius",
732
+ "locked"
733
+ ]);
734
+
735
+ this.el.appendChild(this.#properties.el);
736
+ }
737
+
738
+ /**
739
+ *
740
+ * @param {GamepadStick} stick
741
+ * @param {number} inner gameplay dead zone, inner bound
742
+ * @param {number} outer gameplay dead zone, outer bound
743
+ * @returns {void}
744
+ */
745
+ update(stick, inner, outer) {
746
+ const raw = stick.raw;
747
+ const value = stick.value;
748
+ const calibration = stick.calibration;
749
+
750
+ apply_radial_dead_zone(this.#shaped, value.x, value.y, inner, outer);
751
+
752
+ const trail = this.#trail;
753
+
754
+ trail[this.#trailCursor * 2] = raw.x;
755
+ trail[this.#trailCursor * 2 + 1] = raw.y;
756
+
757
+ this.#trailCursor = (this.#trailCursor + 1) % TRAIL_SAMPLE_COUNT;
758
+ this.#trailCount = Math.min(this.#trailCount + 1, TRAIL_SAMPLE_COUNT);
759
+
760
+ this.#draw(stick);
761
+
762
+ this.#properties.write("raw", `${raw.x.toFixed(4)}, ${raw.y.toFixed(4)}`);
763
+ this.#properties.write("value", `${value.x.toFixed(4)}, ${value.y.toFixed(4)}`);
764
+ this.#properties.write("magnitude", value.length().toFixed(4));
765
+ this.#properties.write("dead zoned", `${this.#shaped.x.toFixed(4)}, ${this.#shaped.y.toFixed(4)}`);
766
+ this.#properties.write("center", `${calibration.center.x.toFixed(4)}, ${calibration.center.y.toFixed(4)}`);
767
+ this.#properties.write("noise radius", calibration.noiseRadius.toFixed(4));
768
+ this.#properties.write("locked", String(calibration.locked));
769
+ }
770
+
771
+ /**
772
+ *
773
+ * @param {number} v stick coordinate in [-1,1]
774
+ * @returns {number} canvas coordinate
775
+ */
776
+ #project(v) {
777
+ return (v + 1) * 0.5 * SCOPE_SIZE;
778
+ }
779
+
780
+ /**
781
+ *
782
+ * @param {GamepadStick} stick
783
+ */
784
+ #draw(stick) {
785
+ const ctx = this.#ctx;
786
+
787
+ const half = SCOPE_SIZE / 2;
788
+
789
+ ctx.clearRect(0, 0, SCOPE_SIZE, SCOPE_SIZE);
790
+
791
+ // gate
792
+ ctx.strokeStyle = "#232a35";
793
+ ctx.lineWidth = 1;
794
+
795
+ ctx.beginPath();
796
+ ctx.moveTo(0, half);
797
+ ctx.lineTo(SCOPE_SIZE, half);
798
+ ctx.moveTo(half, 0);
799
+ ctx.lineTo(half, SCOPE_SIZE);
800
+ ctx.stroke();
801
+
802
+ ctx.beginPath();
803
+ ctx.arc(half, half, half - 1, 0, Math.PI * 2);
804
+ ctx.stroke();
805
+
806
+ // learned rest position and noise radius
807
+ const calibration = stick.calibration;
808
+
809
+ const cx = this.#project(calibration.center.x);
810
+ const cy = this.#project(calibration.center.y);
811
+
812
+ ctx.strokeStyle = "#556070";
813
+ ctx.setLineDash([3, 3]);
814
+
815
+ ctx.beginPath();
816
+ ctx.arc(cx, cy, Math.max(calibration.noiseRadius * half, 1.5), 0, Math.PI * 2);
817
+ ctx.stroke();
818
+
819
+ ctx.setLineDash([]);
820
+
821
+ // trail of raw samples, oldest first
822
+ const trail = this.#trail;
823
+ const count = this.#trailCount;
824
+
825
+ ctx.lineWidth = 1;
826
+
827
+ for (let i = 1; i < count; i++) {
828
+ const previous = (this.#trailCursor - count + i - 1 + TRAIL_SAMPLE_COUNT * 2) % TRAIL_SAMPLE_COUNT;
829
+ const current = (this.#trailCursor - count + i + TRAIL_SAMPLE_COUNT * 2) % TRAIL_SAMPLE_COUNT;
830
+
831
+ ctx.strokeStyle = `rgba(125, 136, 153, ${(i / count) * 0.8})`;
832
+
833
+ ctx.beginPath();
834
+ ctx.moveTo(this.#project(trail[previous * 2]), this.#project(trail[previous * 2 + 1]));
835
+ ctx.lineTo(this.#project(trail[current * 2]), this.#project(trail[current * 2 + 1]));
836
+ ctx.stroke();
837
+ }
838
+
839
+ this.#dot(this.#project(stick.raw.x), this.#project(stick.raw.y), 4, "#9fb0c6");
840
+ this.#dot(this.#project(this.#shaped.x), this.#project(this.#shaped.y), 3, "#fbbf24");
841
+ this.#dot(this.#project(stick.value.x), this.#project(stick.value.y), 3, "#4ade80");
842
+ }
843
+
844
+ /**
845
+ *
846
+ * @param {number} x
847
+ * @param {number} y
848
+ * @param {number} radius
849
+ * @param {string} color
850
+ */
851
+ #dot(x, y, radius, color) {
852
+ const ctx = this.#ctx;
853
+
854
+ ctx.fillStyle = color;
855
+
856
+ ctx.beginPath();
857
+ ctx.arc(x, y, radius, 0, Math.PI * 2);
858
+ ctx.fill();
859
+ }
860
+ }
861
+
862
+ /**
863
+ * Scrolling plot of the analog channels over the last few seconds.
864
+ *
865
+ * A scope shows where a stick is, this shows how it got there: snap-back overshoot, trigger travel, and the
866
+ * flat line of a calibrated stick at rest are all shapes in time rather than positions.
867
+ */
868
+ class AxisTimelineView {
869
+
870
+ /**
871
+ * @readonly
872
+ * @type {HTMLElement}
873
+ */
874
+ el;
875
+
876
+ /**
877
+ * @type {CanvasRenderingContext2D}
878
+ */
879
+ #ctx;
880
+
881
+ /**
882
+ * One row per channel of {@link TIMELINE_CHANNELS}, each a ring buffer sharing {@link #cursor}
883
+ * @type {Float32Array[]}
884
+ */
885
+ #channels = [];
886
+
887
+ /**
888
+ * @type {number}
889
+ */
890
+ #cursor = 0;
891
+
892
+ /**
893
+ * @type {number}
894
+ */
895
+ #count = 0;
896
+
897
+ constructor() {
898
+ this.el = make_element("div", "gpt-panel");
899
+
900
+ const title = make_element("div", "gpt-panel-title", this.el);
901
+ title.textContent = "analog channels over time";
902
+
903
+ const canvas = make_element("canvas", "", this.el);
904
+
905
+ const dpr = window.devicePixelRatio;
906
+
907
+ canvas.width = TIMELINE_WIDTH * dpr;
908
+ canvas.height = TIMELINE_HEIGHT * dpr;
909
+ canvas.style.width = `${TIMELINE_WIDTH}px`;
910
+ canvas.style.height = `${TIMELINE_HEIGHT}px`;
911
+ canvas.style.display = "block";
912
+ canvas.style.background = "#0d1014";
913
+ canvas.style.borderRadius = "4px";
914
+
915
+ this.#ctx = canvas.getContext("2d");
916
+ this.#ctx.scale(dpr, dpr);
917
+
918
+ const legend = make_element("div", "gpt-legend", this.el);
919
+
920
+ const n = TIMELINE_CHANNELS.length;
921
+
922
+ for (let i = 0; i < n; i++) {
923
+ const channel = TIMELINE_CHANNELS[i];
924
+
925
+ this.#channels[i] = new Float32Array(TIMELINE_SAMPLE_COUNT);
926
+
927
+ const entry = make_element("span", "", legend);
928
+ entry.textContent = channel.label;
929
+ entry.style.color = channel.color;
930
+ }
931
+ }
932
+
933
+ /**
934
+ *
935
+ * @param {GamepadHandle} pad
936
+ * @returns {void}
937
+ */
938
+ update(pad) {
939
+ const axes = pad.axes;
940
+ const buttonValues = pad.buttonValues;
941
+
942
+ const cursor = this.#cursor;
943
+
944
+ this.#channels[0][cursor] = axes[GamepadAxes.left_stick_x];
945
+ this.#channels[1][cursor] = axes[GamepadAxes.left_stick_y];
946
+ this.#channels[2][cursor] = axes[GamepadAxes.right_stick_x];
947
+ this.#channels[3][cursor] = axes[GamepadAxes.right_stick_y];
948
+ this.#channels[4][cursor] = buttonValues[GamepadButtons.left_trigger];
949
+ this.#channels[5][cursor] = buttonValues[GamepadButtons.right_trigger];
950
+
951
+ this.#cursor = (cursor + 1) % TIMELINE_SAMPLE_COUNT;
952
+ this.#count = Math.min(this.#count + 1, TIMELINE_SAMPLE_COUNT);
953
+
954
+ this.#draw();
955
+ }
956
+
957
+ #draw() {
958
+ const ctx = this.#ctx;
959
+
960
+ ctx.clearRect(0, 0, TIMELINE_WIDTH, TIMELINE_HEIGHT);
961
+
962
+ // zero line and unit bounds
963
+ ctx.strokeStyle = "#232a35";
964
+ ctx.lineWidth = 1;
965
+
966
+ ctx.beginPath();
967
+ ctx.moveTo(0, TIMELINE_HEIGHT * 0.5);
968
+ ctx.lineTo(TIMELINE_WIDTH, TIMELINE_HEIGHT * 0.5);
969
+ ctx.stroke();
970
+
971
+ const count = this.#count;
972
+
973
+ if (count < 2) {
974
+ return;
975
+ }
976
+
977
+ const step = TIMELINE_WIDTH / (TIMELINE_SAMPLE_COUNT - 1);
978
+
979
+ const n = this.#channels.length;
980
+
981
+ for (let i = 0; i < n; i++) {
982
+ const samples = this.#channels[i];
983
+
984
+ ctx.strokeStyle = TIMELINE_CHANNELS[i].color;
985
+ ctx.beginPath();
986
+
987
+ for (let j = 0; j < count; j++) {
988
+ const index = (this.#cursor - count + j + TIMELINE_SAMPLE_COUNT * 2) % TIMELINE_SAMPLE_COUNT;
989
+
990
+ const x = j * step;
991
+ const y = (1 - samples[index]) * 0.5 * TIMELINE_HEIGHT;
992
+
993
+ if (j === 0) {
994
+ ctx.moveTo(x, y);
995
+ } else {
996
+ ctx.lineTo(x, y);
997
+ }
998
+ }
999
+
1000
+ ctx.stroke();
1001
+ }
1002
+ }
1003
+ }
1004
+
1005
+ /**
1006
+ * Newest-first log of the device's signals.
1007
+ *
1008
+ * Everything here arrives by subscription rather than by sampling, so it records what a consumer bound to these
1009
+ * signals would have received - including presses too short to survive being sampled once a frame.
1010
+ */
1011
+ class EventLogView {
1012
+
1013
+ /**
1014
+ * @readonly
1015
+ * @type {HTMLElement}
1016
+ */
1017
+ el;
1018
+
1019
+ /**
1020
+ * @type {HTMLElement}
1021
+ */
1022
+ #entries;
1023
+
1024
+ /**
1025
+ * @type {number}
1026
+ */
1027
+ #startTime = performance.now();
1028
+
1029
+ /**
1030
+ * Axis signals fire at hardware sample rate on a drifting pad, so they are counted rather than logged
1031
+ * @type {number}
1032
+ */
1033
+ #axisEventCount = 0;
1034
+
1035
+ /**
1036
+ * @type {PropertyTableView}
1037
+ */
1038
+ #counters;
1039
+
1040
+ /**
1041
+ * @type {number}
1042
+ */
1043
+ #downCount = 0;
1044
+
1045
+ /**
1046
+ * @type {number}
1047
+ */
1048
+ #upCount = 0;
1049
+
1050
+ /**
1051
+ *
1052
+ * @param {GamepadDevice} device
1053
+ */
1054
+ constructor(device) {
1055
+ this.el = make_element("div", "gpt-panel gpt-pads-summary");
1056
+
1057
+ const title = make_element("div", "gpt-panel-title", this.el);
1058
+ title.textContent = "device signals";
1059
+
1060
+ this.#counters = new PropertyTableView(["down", "up", "axis"]);
1061
+ this.el.appendChild(this.#counters.el);
1062
+
1063
+ this.#entries = make_element("div", "gpt-log", this.el);
1064
+
1065
+ device.on.connected.add(pad => {
1066
+ this.#write(`connected pad ${pad.index} "${pad.id}" mapping="${pad.mapping}"`);
1067
+ });
1068
+
1069
+ device.on.disconnected.add(pad => {
1070
+ this.#write(`disconnected pad ${pad.index} "${pad.id}"`);
1071
+ });
1072
+
1073
+ device.on.down.add((buttonIndex, pad) => {
1074
+ this.#downCount++;
1075
+ this.#write(`down pad ${pad.index} button ${buttonIndex} ${this.#buttonName(buttonIndex)}`);
1076
+ });
1077
+
1078
+ device.on.up.add((buttonIndex, pad) => {
1079
+ this.#upCount++;
1080
+ this.#write(`up pad ${pad.index} button ${buttonIndex} ${this.#buttonName(buttonIndex)}`);
1081
+ });
1082
+
1083
+ device.on.axis.add(() => {
1084
+ this.#axisEventCount++;
1085
+ });
1086
+ }
1087
+
1088
+ /**
1089
+ *
1090
+ * @param {number} index
1091
+ * @returns {string}
1092
+ */
1093
+ #buttonName(index) {
1094
+ return BUTTON_NAMES[index] !== undefined ? BUTTON_NAMES[index] : "";
1095
+ }
1096
+
1097
+ /**
1098
+ *
1099
+ * @param {string} text
1100
+ */
1101
+ #write(text) {
1102
+ const seconds = (performance.now() - this.#startTime) / 1000;
1103
+
1104
+ const entry = make_element("div", "gpt-log-entry");
1105
+ entry.textContent = `${seconds.toFixed(3).padStart(9)} ${text}`;
1106
+
1107
+ this.#entries.insertBefore(entry, this.#entries.firstChild);
1108
+
1109
+ while (this.#entries.childElementCount > MAX_LOG_ENTRIES) {
1110
+ this.#entries.removeChild(this.#entries.lastChild);
1111
+ }
1112
+ }
1113
+
1114
+ /**
1115
+ *
1116
+ * @returns {void}
1117
+ */
1118
+ update() {
1119
+ this.#counters.write("down", String(this.#downCount));
1120
+ this.#counters.write("up", String(this.#upCount));
1121
+ this.#counters.write("axis", String(this.#axisEventCount));
1122
+ }
1123
+ }
1124
+
1125
+ /**
1126
+ * Which device input each standard input is being read from.
1127
+ *
1128
+ * The thing you want when a pad misbehaves: a browser that has not recognised a device reports its inputs in
1129
+ * the device's own order, and this is the translation being applied to get back to the standard mapping.
1130
+ * Read it against layer 2's raw indices to check an entry, or to write a new one.
1131
+ */
1132
+ class LayoutView {
1133
+
1134
+ /**
1135
+ * @readonly
1136
+ * @type {HTMLElement}
1137
+ */
1138
+ el;
1139
+
1140
+ /**
1141
+ * @type {HTMLElement}
1142
+ */
1143
+ #body;
1144
+
1145
+ /**
1146
+ * Layout the body was built for, so it is rebuilt only when the pad starts being read differently
1147
+ * @type {GamepadLayout|undefined}
1148
+ */
1149
+ #rendered = undefined;
1150
+
1151
+ constructor() {
1152
+ this.el = make_element("div", "gpt-panel");
1153
+
1154
+ const title = make_element("div", "gpt-panel-title", this.el);
1155
+ title.textContent = "resolved layout";
1156
+
1157
+ this.#body = make_element("div", "gpt-kv", this.el);
1158
+ }
1159
+
1160
+ /**
1161
+ *
1162
+ * @param {GamepadHandle} pad
1163
+ * @returns {void}
1164
+ */
1165
+ update(pad) {
1166
+ const layout = pad.layout;
1167
+
1168
+ if (this.#rendered === layout) {
1169
+ return;
1170
+ }
1171
+
1172
+ this.#rendered = layout;
1173
+
1174
+ this.#body.textContent = "";
1175
+
1176
+ this.#write("layout", layout.name);
1177
+
1178
+ if (layout === GAMEPAD_STANDARD_LAYOUT) {
1179
+ this.#write("", "the browser mapped this pad, every index is passed through unchanged");
1180
+
1181
+ return;
1182
+ }
1183
+
1184
+ for (let i = 0; i < GAMEPAD_STANDARD_AXIS_COUNT; i++) {
1185
+ const source = layout.axisSource(i);
1186
+
1187
+ this.#write(AXIS_NAMES[i], source === GAMEPAD_LAYOUT_ABSENT ? "-" : `axis ${source}`);
1188
+ }
1189
+
1190
+ for (let i = 0; i < GAMEPAD_STANDARD_BUTTON_COUNT; i++) {
1191
+ this.#write(BUTTON_NAMES[i], this.#describeButtonSource(layout, i));
1192
+ }
1193
+ }
1194
+
1195
+ /**
1196
+ *
1197
+ * @param {GamepadLayout} layout
1198
+ * @param {number} index standard button index
1199
+ * @returns {string}
1200
+ */
1201
+ #describeButtonSource(layout, index) {
1202
+ const button = layout.buttonSource(index);
1203
+
1204
+ if (button !== GAMEPAD_LAYOUT_ABSENT) {
1205
+ return `button ${button}`;
1206
+ }
1207
+
1208
+ const axis = layout.buttonAxisSource(index);
1209
+
1210
+ if (axis !== GAMEPAD_LAYOUT_ABSENT) {
1211
+ return `axis ${axis}`;
1212
+ }
1213
+
1214
+ if (DPAD_BUTTONS.indexOf(index) !== -1 && layout.hatAxis !== GAMEPAD_LAYOUT_ABSENT) {
1215
+ return `hat on axis ${layout.hatAxis}`;
1216
+ }
1217
+
1218
+ return "-";
1219
+ }
1220
+
1221
+ /**
1222
+ *
1223
+ * @param {string} key
1224
+ * @param {string} value
1225
+ */
1226
+ #write(key, value) {
1227
+ const k = make_element("div", "gpt-k", this.#body);
1228
+ k.textContent = key;
1229
+
1230
+ const v = make_element("div", "gpt-v", this.#body);
1231
+ v.textContent = value;
1232
+ }
1233
+ }
1234
+
1235
+ /**
1236
+ * Layer 1 - everything read through {@link GamepadDevice}.
1237
+ */
1238
+ class EngineLayerView {
1239
+
1240
+ /**
1241
+ * @readonly
1242
+ * @type {HTMLElement}
1243
+ */
1244
+ el;
1245
+
1246
+ /**
1247
+ * @type {GamepadDevice}
1248
+ */
1249
+ #device;
1250
+
1251
+ /**
1252
+ * @type {PropertyTableView}
1253
+ */
1254
+ #summary;
1255
+
1256
+ /**
1257
+ * @type {HTMLElement}
1258
+ */
1259
+ #buttonGrid;
1260
+
1261
+ /**
1262
+ * @type {ButtonView[]}
1263
+ */
1264
+ #buttons = [];
1265
+
1266
+ /**
1267
+ * @type {HTMLElement}
1268
+ */
1269
+ #axisList;
1270
+
1271
+ /**
1272
+ * @type {AxisView[]}
1273
+ */
1274
+ #axes = [];
1275
+
1276
+ /**
1277
+ * @type {StickScopeView}
1278
+ */
1279
+ #stickLeft = new StickScopeView("left stick");
1280
+
1281
+ /**
1282
+ * @type {StickScopeView}
1283
+ */
1284
+ #stickRight = new StickScopeView("right stick");
1285
+
1286
+ /**
1287
+ * @type {AxisTimelineView}
1288
+ */
1289
+ #timeline = new AxisTimelineView();
1290
+
1291
+ /**
1292
+ * @type {EventLogView}
1293
+ */
1294
+ #log;
1295
+
1296
+ /**
1297
+ * @type {LayoutView}
1298
+ */
1299
+ #layout = new LayoutView();
1300
+
1301
+ /**
1302
+ * @type {PropertyTableView}
1303
+ */
1304
+ #composition;
1305
+
1306
+ /**
1307
+ * @type {HTMLElement}
1308
+ */
1309
+ #padRows;
1310
+
1311
+ /**
1312
+ * @type {HTMLElement}
1313
+ */
1314
+ #pressedList;
1315
+
1316
+ /**
1317
+ * @type {HTMLInputElement}
1318
+ */
1319
+ #innerInput;
1320
+
1321
+ /**
1322
+ * @type {HTMLInputElement}
1323
+ */
1324
+ #outerInput;
1325
+
1326
+ /**
1327
+ * @type {HTMLElement}
1328
+ */
1329
+ #innerValue;
1330
+
1331
+ /**
1332
+ * @type {HTMLElement}
1333
+ */
1334
+ #outerValue;
1335
+
1336
+ /**
1337
+ * @type {Vector2}
1338
+ */
1339
+ #dpad = new Vector2();
1340
+
1341
+ /**
1342
+ * @type {Vector2}
1343
+ */
1344
+ #stick = new Vector2();
1345
+
1346
+ /**
1347
+ * @type {Vector2}
1348
+ */
1349
+ #move = new Vector2();
1350
+
1351
+ /**
1352
+ *
1353
+ * @param {GamepadDevice} device
1354
+ */
1355
+ constructor(device) {
1356
+ this.#device = device;
1357
+
1358
+ this.el = make_element("div", "gpt-layer");
1359
+
1360
+ const head = make_element("div", "gpt-layer-head", this.el);
1361
+
1362
+ const badge = make_element("div", "gpt-layer-badge", head);
1363
+ badge.textContent = "layer 1";
1364
+
1365
+ const title = make_element("h2", "", head);
1366
+ title.textContent = "engine.devices.gamepad";
1367
+
1368
+ const subtitle = make_element("div", "gpt-muted", head);
1369
+ subtitle.textContent = "GamepadDevice.main - calibrated, edge-detected, stable across pad swaps";
1370
+
1371
+ const body = make_element("div", "gpt-layer-body", this.el);
1372
+
1373
+ // main handle
1374
+ const summaryPanel = make_element("div", "gpt-panel", body);
1375
+
1376
+ const summaryTitle = make_element("div", "gpt-panel-title", summaryPanel);
1377
+ summaryTitle.textContent = "main handle";
1378
+
1379
+ /*
1380
+ No connection index here on purpose - main is not a member of pads and is never stamped with one, so
1381
+ the field would read -1 for the whole session. The pad it mirrors carries the real value, and the known
1382
+ pads panel below shows it.
1383
+ */
1384
+ this.#summary = new PropertyTableView([
1385
+ "connected",
1386
+ "index",
1387
+ "id",
1388
+ "mapping",
1389
+ "read as",
1390
+ "buttons",
1391
+ "axes",
1392
+ "known pads"
1393
+ ]);
1394
+
1395
+ summaryPanel.appendChild(this.#summary.el);
1396
+
1397
+ this.#pressedList = make_element("div", "gpt-muted", summaryPanel);
1398
+ this.#pressedList.style.marginTop = "7px";
1399
+
1400
+ // buttons
1401
+ const buttonPanel = make_element("div", "gpt-panel", body);
1402
+
1403
+ const buttonTitle = make_element("div", "gpt-panel-title", buttonPanel);
1404
+ buttonTitle.textContent = "buttons - x is the press count from the switch signal";
1405
+
1406
+ this.#buttonGrid = make_element("div", "gpt-buttons", buttonPanel);
1407
+
1408
+ body.appendChild(this.#layout.el);
1409
+
1410
+ // axes
1411
+ const axisPanel = make_element("div", "gpt-panel", body);
1412
+
1413
+ const axisTitle = make_element("div", "gpt-panel-title", axisPanel);
1414
+ axisTitle.textContent = "axes - standard slots, values as reported";
1415
+
1416
+ this.#axisList = make_element("div", "", axisPanel);
1417
+
1418
+ // sticks
1419
+ const sticks = make_element("div", "gpt-sticks", body);
1420
+ sticks.appendChild(this.#stickLeft.el);
1421
+ sticks.appendChild(this.#stickRight.el);
1422
+
1423
+ // composition
1424
+ const compositionPanel = make_element("div", "gpt-panel", body);
1425
+
1426
+ const compositionTitle = make_element("div", "gpt-panel-title", compositionPanel);
1427
+ compositionTitle.textContent = "documented composition";
1428
+
1429
+ this.#composition = new PropertyTableView([
1430
+ "dpad vector",
1431
+ "shaped stick",
1432
+ "fused move (y up)"
1433
+ ]);
1434
+
1435
+ compositionPanel.appendChild(this.#composition.el);
1436
+
1437
+ const controls = make_element("div", "gpt-controls", compositionPanel);
1438
+ controls.style.marginTop = "8px";
1439
+
1440
+ const inner = this.#makeSlider(controls, "dead zone inner", 0.15);
1441
+ const outer = this.#makeSlider(controls, "dead zone outer", 0.95);
1442
+
1443
+ this.#innerInput = inner.input;
1444
+ this.#innerValue = inner.value;
1445
+ this.#outerInput = outer.input;
1446
+ this.#outerValue = outer.value;
1447
+
1448
+ const forget = make_element("button", "", controls);
1449
+ forget.textContent = "forget calibration";
1450
+ forget.addEventListener("click", () => {
1451
+ device.main.forgetCalibration();
1452
+ });
1453
+
1454
+ body.appendChild(this.#timeline.el);
1455
+
1456
+ // other pads
1457
+ const padPanel = make_element("div", "gpt-panel gpt-pads-summary", body);
1458
+
1459
+ const padTitle = make_element("div", "gpt-panel-title", padPanel);
1460
+ padTitle.textContent = "known pads - GamepadDevice.pads, indexed by hardware slot";
1461
+
1462
+ this.#padRows = make_element("div", "", padPanel);
1463
+
1464
+ this.#log = new EventLogView(device);
1465
+ body.appendChild(this.#log.el);
1466
+ }
1467
+
1468
+ /**
1469
+ *
1470
+ * @param {HTMLElement} parent
1471
+ * @param {string} label
1472
+ * @param {number} initial
1473
+ * @returns {{input:HTMLInputElement, value:HTMLElement}}
1474
+ */
1475
+ #makeSlider(parent, label, initial) {
1476
+ const row = make_element("div", "gpt-control", parent);
1477
+
1478
+ const name = make_element("div", "gpt-muted", row);
1479
+ name.textContent = label;
1480
+
1481
+ const input = make_element("input", "", row);
1482
+ input.type = "range";
1483
+ input.min = "0";
1484
+ input.max = "1";
1485
+ input.step = "0.01";
1486
+ input.value = String(initial);
1487
+
1488
+ const value = make_element("div", "gpt-axis-value", row);
1489
+ value.textContent = initial.toFixed(2);
1490
+
1491
+ return { input, value };
1492
+ }
1493
+
1494
+ /**
1495
+ * Rebuild the per-button views when the handle grows past the standard mapping
1496
+ *
1497
+ * @param {GamepadHandle} pad
1498
+ */
1499
+ #syncButtonViews(pad) {
1500
+ const count = pad.buttons.length;
1501
+
1502
+ if (this.#buttons.length === count) {
1503
+ return;
1504
+ }
1505
+
1506
+ const previous = this.#buttons;
1507
+ const n = previous.length;
1508
+
1509
+ for (let i = 0; i < n; i++) {
1510
+ previous[i].dispose();
1511
+ }
1512
+
1513
+ this.#buttons = [];
1514
+ this.#buttonGrid.textContent = "";
1515
+
1516
+ for (let i = 0; i < count; i++) {
1517
+ const view = new ButtonView(i, pad.buttons[i]);
1518
+
1519
+ this.#buttons[i] = view;
1520
+ this.#buttonGrid.appendChild(view.el);
1521
+ }
1522
+ }
1523
+
1524
+ /**
1525
+ *
1526
+ * @param {GamepadHandle} pad
1527
+ */
1528
+ #syncAxisViews(pad) {
1529
+ const count = pad.axes.length;
1530
+
1531
+ if (this.#axes.length === count) {
1532
+ return;
1533
+ }
1534
+
1535
+ this.#axes = [];
1536
+ this.#axisList.textContent = "";
1537
+
1538
+ for (let i = 0; i < count; i++) {
1539
+ const name = AXIS_NAMES[i] !== undefined ? AXIS_NAMES[i] : `axis ${i}`;
1540
+
1541
+ const view = new AxisView(`${i} ${name}`);
1542
+
1543
+ this.#axes[i] = view;
1544
+ this.#axisList.appendChild(view.el);
1545
+ }
1546
+ }
1547
+
1548
+ /**
1549
+ *
1550
+ * @returns {number}
1551
+ */
1552
+ get deadZoneInner() {
1553
+ return Number.parseFloat(this.#innerInput.value);
1554
+ }
1555
+
1556
+ /**
1557
+ *
1558
+ * @returns {number}
1559
+ */
1560
+ get deadZoneOuter() {
1561
+ return Number.parseFloat(this.#outerInput.value);
1562
+ }
1563
+
1564
+ /**
1565
+ *
1566
+ * @returns {void}
1567
+ */
1568
+ update() {
1569
+ const device = this.#device;
1570
+ const pad = device.main;
1571
+
1572
+ this.#syncButtonViews(pad);
1573
+ this.#syncAxisViews(pad);
1574
+
1575
+ this.#layout.update(pad);
1576
+
1577
+ this.#summary.write("connected", String(pad.connected));
1578
+ this.#summary.write("index", String(pad.index));
1579
+ this.#summary.write("id", pad.id !== "" ? pad.id : "-");
1580
+ this.#summary.write("mapping", pad.mapping !== "" ? pad.mapping : "- (browser did not map this pad)");
1581
+ this.#summary.write("read as", pad.layout.name);
1582
+ this.#summary.write("buttons", `${pad.buttons.length} (standard ${GAMEPAD_STANDARD_BUTTON_COUNT})`);
1583
+ this.#summary.write("axes", `${pad.axes.length} (standard ${GAMEPAD_STANDARD_AXIS_COUNT})`);
1584
+ this.#summary.write("known pads", String(device.pads.filter(p => p !== undefined).length));
1585
+
1586
+ const pressed = [];
1587
+
1588
+ const buttonCount = this.#buttons.length;
1589
+
1590
+ for (let i = 0; i < buttonCount; i++) {
1591
+ this.#buttons[i].update(pad.buttonValues[i]);
1592
+
1593
+ if (pad.buttons[i].is_down) {
1594
+ pressed.push(BUTTON_NAMES[i] !== undefined ? BUTTON_NAMES[i] : String(i));
1595
+ }
1596
+ }
1597
+
1598
+ write_text(this.#pressedList, pressed.length > 0 ? `pressed: ${pressed.join(", ")}` : "pressed: nothing");
1599
+
1600
+ const axisCount = this.#axes.length;
1601
+
1602
+ for (let i = 0; i < axisCount; i++) {
1603
+ this.#axes[i].update(pad.axes[i]);
1604
+ }
1605
+
1606
+ const inner = this.deadZoneInner;
1607
+ const outer = this.deadZoneOuter;
1608
+
1609
+ write_text(this.#innerValue, inner.toFixed(2));
1610
+ write_text(this.#outerValue, outer.toFixed(2));
1611
+
1612
+ this.#stickLeft.update(pad.stickLeft, inner, outer);
1613
+ this.#stickRight.update(pad.stickRight, inner, outer);
1614
+
1615
+ this.#timeline.update(pad);
1616
+
1617
+ this.#updateComposition(pad, inner, outer);
1618
+ this.#updatePadRows();
1619
+
1620
+ this.#log.update();
1621
+ }
1622
+
1623
+ /**
1624
+ * The locomotion example from the {@link GamepadDevice} class doc, evaluated live
1625
+ *
1626
+ * @param {GamepadHandle} pad
1627
+ * @param {number} inner
1628
+ * @param {number} outer
1629
+ */
1630
+ #updateComposition(pad, inner, outer) {
1631
+ const left = pad.stickLeft.value;
1632
+
1633
+ gamepad_write_dpad_vector(this.#dpad, pad);
1634
+ apply_radial_dead_zone(this.#stick, left.x, left.y, inner, outer);
1635
+
1636
+ const stick = this.#stick;
1637
+ const dpad = this.#dpad;
1638
+
1639
+ const x = stick.x !== 0 || stick.y !== 0 ? stick.x : dpad.x;
1640
+ const y = stick.x !== 0 || stick.y !== 0 ? stick.y : dpad.y;
1641
+
1642
+ this.#move.set(x, -y);
1643
+
1644
+ this.#composition.write("dpad vector", `${dpad.x.toFixed(0)}, ${dpad.y.toFixed(0)}`);
1645
+ this.#composition.write("shaped stick", `${stick.x.toFixed(4)}, ${stick.y.toFixed(4)}`);
1646
+ this.#composition.write("fused move (y up)", `${this.#move.x.toFixed(4)}, ${this.#move.y.toFixed(4)}`);
1647
+ }
1648
+
1649
+ #updatePadRows() {
1650
+ const pads = this.#device.pads;
1651
+
1652
+ const rows = this.#padRows;
1653
+
1654
+ const n = pads.length;
1655
+
1656
+ let index = 0;
1657
+
1658
+ for (let i = 0; i < n; i++) {
1659
+ const pad = pads[i];
1660
+
1661
+ if (pad === undefined) {
1662
+ continue;
1663
+ }
1664
+
1665
+ let row = rows.children[index];
1666
+
1667
+ if (row === undefined) {
1668
+ row = make_element("div", "gpt-pad-row", rows);
1669
+
1670
+ make_element("div", "", row);
1671
+ make_element("div", "", row);
1672
+ make_element("div", "", row);
1673
+ }
1674
+
1675
+ const held = [];
1676
+
1677
+ const buttonCount = pad.buttons.length;
1678
+
1679
+ for (let j = 0; j < buttonCount; j++) {
1680
+ if (pad.buttons[j].is_down) {
1681
+ held.push(BUTTON_NAMES[j] !== undefined ? BUTTON_NAMES[j] : String(j));
1682
+ }
1683
+ }
1684
+
1685
+ write_text(row.children[0], `slot ${pad.index}`);
1686
+ write_text(row.children[1], pad.connected ? `connected #${pad.connectionIndex}` : "disconnected");
1687
+ write_text(row.children[2], `${pad.id} ${held.length > 0 ? `[${held.join(" ")}]` : ""}`);
1688
+
1689
+ index++;
1690
+ }
1691
+
1692
+ while (rows.childElementCount > index) {
1693
+ rows.removeChild(rows.lastChild);
1694
+ }
1695
+ }
1696
+ }
1697
+
1698
+ /**
1699
+ * One native {@link Gamepad}, straight from `navigator.getGamepads()`.
1700
+ */
1701
+ class NativeGamepadCard {
1702
+
1703
+ /**
1704
+ * @readonly
1705
+ * @type {HTMLElement}
1706
+ */
1707
+ el;
1708
+
1709
+ /**
1710
+ * @type {PropertyTableView}
1711
+ */
1712
+ #summary;
1713
+
1714
+ /**
1715
+ * @type {HTMLElement}
1716
+ */
1717
+ #buttonGrid;
1718
+
1719
+ /**
1720
+ * @type {HTMLElement[]}
1721
+ */
1722
+ #buttonCells = [];
1723
+
1724
+ /**
1725
+ * @type {HTMLElement}
1726
+ */
1727
+ #axisList;
1728
+
1729
+ /**
1730
+ * @type {AxisView[]}
1731
+ */
1732
+ #axes = [];
1733
+
1734
+ /**
1735
+ * @type {HTMLElement}
1736
+ */
1737
+ #rumble;
1738
+
1739
+ constructor() {
1740
+ this.el = make_element("div", "gpt-panel");
1741
+
1742
+ this.#summary = new PropertyTableView([
1743
+ "index",
1744
+ "id",
1745
+ "mapping",
1746
+ "connected",
1747
+ "timestamp",
1748
+ "buttons",
1749
+ "axes",
1750
+ "vibration"
1751
+ ]);
1752
+
1753
+ this.el.appendChild(this.#summary.el);
1754
+
1755
+ this.#buttonGrid = make_element("div", "gpt-native-buttons", this.el);
1756
+ this.#buttonGrid.style.marginTop = "8px";
1757
+
1758
+ this.#axisList = make_element("div", "", this.el);
1759
+ this.#axisList.style.marginTop = "8px";
1760
+
1761
+ this.#rumble = make_element("button", "", this.el);
1762
+ this.#rumble.textContent = "rumble";
1763
+ this.#rumble.style.marginTop = "8px";
1764
+ }
1765
+
1766
+ /**
1767
+ *
1768
+ * @param {Gamepad} gamepad
1769
+ * @returns {void}
1770
+ */
1771
+ update(gamepad) {
1772
+ const buttons = gamepad.buttons;
1773
+ const axes = gamepad.axes;
1774
+
1775
+ const actuator = gamepad.vibrationActuator;
1776
+
1777
+ this.#summary.write("index", String(gamepad.index));
1778
+ this.#summary.write("id", gamepad.id);
1779
+ this.#summary.write("mapping", gamepad.mapping);
1780
+ this.#summary.write("connected", String(gamepad.connected));
1781
+ this.#summary.write("timestamp", gamepad.timestamp.toFixed(1));
1782
+ this.#summary.write("buttons", String(buttons.length));
1783
+ this.#summary.write("axes", String(axes.length));
1784
+ this.#summary.write("vibration", actuator !== undefined && actuator !== null ? actuator.type : "none");
1785
+
1786
+ this.#syncButtonCells(buttons.length);
1787
+
1788
+ for (let i = 0; i < buttons.length; i++) {
1789
+ const button = buttons[i];
1790
+ const cell = this.#buttonCells[i];
1791
+
1792
+ cell.classList.toggle("gpt-down", button.pressed);
1793
+ cell.classList.toggle("gpt-touched", !button.pressed && button.touched);
1794
+
1795
+ write_text(cell, `${i} ${button.value.toFixed(2)}`);
1796
+ }
1797
+
1798
+ this.#syncAxisViews(axes.length);
1799
+
1800
+ for (let i = 0; i < axes.length; i++) {
1801
+ this.#axes[i].update(axes[i]);
1802
+ }
1803
+
1804
+ const canRumble = actuator !== undefined && actuator !== null && typeof actuator.playEffect === "function";
1805
+
1806
+ this.#rumble.disabled = !canRumble;
1807
+
1808
+ if (canRumble) {
1809
+ this.#rumble.onclick = () => {
1810
+ actuator.playEffect("dual-rumble", {
1811
+ duration: 400,
1812
+ strongMagnitude: 1,
1813
+ weakMagnitude: 1
1814
+ });
1815
+ };
1816
+ }
1817
+ }
1818
+
1819
+ /**
1820
+ *
1821
+ * @param {number} count
1822
+ */
1823
+ #syncButtonCells(count) {
1824
+ if (this.#buttonCells.length === count) {
1825
+ return;
1826
+ }
1827
+
1828
+ this.#buttonCells = [];
1829
+ this.#buttonGrid.textContent = "";
1830
+
1831
+ for (let i = 0; i < count; i++) {
1832
+ this.#buttonCells[i] = make_element("div", "gpt-native-button", this.#buttonGrid);
1833
+ }
1834
+ }
1835
+
1836
+ /**
1837
+ *
1838
+ * @param {number} count
1839
+ */
1840
+ #syncAxisViews(count) {
1841
+ if (this.#axes.length === count) {
1842
+ return;
1843
+ }
1844
+
1845
+ this.#axes = [];
1846
+ this.#axisList.textContent = "";
1847
+
1848
+ for (let i = 0; i < count; i++) {
1849
+ const view = new AxisView(`axis ${i}`);
1850
+
1851
+ this.#axes[i] = view;
1852
+ this.#axisList.appendChild(view.el);
1853
+ }
1854
+ }
1855
+ }
1856
+
1857
+ /**
1858
+ * Layer 2 - `navigator.getGamepads()` with nothing in front of it.
1859
+ *
1860
+ * Polled from the same animation frame as layer 1 and holding no state of its own, so a difference between the
1861
+ * two panels is a difference the device layer introduced, not a difference in when they looked.
1862
+ */
1863
+ class NativeLayerView {
1864
+
1865
+ /**
1866
+ * @readonly
1867
+ * @type {HTMLElement}
1868
+ */
1869
+ el;
1870
+
1871
+ /**
1872
+ * @type {HTMLElement}
1873
+ */
1874
+ #pads;
1875
+
1876
+ /**
1877
+ * @type {Map<number,NativeGamepadCard>}
1878
+ */
1879
+ #cards = new Map();
1880
+
1881
+ /**
1882
+ * @type {HTMLElement}
1883
+ */
1884
+ #status;
1885
+
1886
+ constructor() {
1887
+ this.el = make_element("div", "gpt-layer");
1888
+
1889
+ const head = make_element("div", "gpt-layer-head", this.el);
1890
+
1891
+ const badge = make_element("div", "gpt-layer-badge", head);
1892
+ badge.textContent = "layer 2";
1893
+
1894
+ const title = make_element("h2", "", head);
1895
+ title.textContent = "navigator.getGamepads()";
1896
+
1897
+ const subtitle = make_element("div", "gpt-muted", head);
1898
+ subtitle.textContent = "browser Gamepad API, read directly - no engine in the path";
1899
+
1900
+ this.#status = make_element("div", "gpt-status", head);
1901
+
1902
+ const body = make_element("div", "gpt-layer-body", this.el);
1903
+
1904
+ this.#pads = make_element("div", "gpt-native-pads", body);
1905
+ }
1906
+
1907
+ /**
1908
+ *
1909
+ * @param {(Gamepad|null)[]} gamepads
1910
+ * @returns {void}
1911
+ */
1912
+ update(gamepads) {
1913
+ let live = 0;
1914
+
1915
+ const seen = new Set();
1916
+
1917
+ const n = gamepads.length;
1918
+
1919
+ for (let i = 0; i < n; i++) {
1920
+ const gamepad = gamepads[i];
1921
+
1922
+ if (gamepad === null || gamepad === undefined) {
1923
+ continue;
1924
+ }
1925
+
1926
+ live++;
1927
+ seen.add(gamepad.index);
1928
+
1929
+ let card = this.#cards.get(gamepad.index);
1930
+
1931
+ if (card === undefined) {
1932
+ card = new NativeGamepadCard();
1933
+
1934
+ this.#cards.set(gamepad.index, card);
1935
+ this.#pads.appendChild(card.el);
1936
+ }
1937
+
1938
+ card.update(gamepad);
1939
+ }
1940
+
1941
+ for (const [index, card] of this.#cards) {
1942
+ if (!seen.has(index)) {
1943
+ this.#pads.removeChild(card.el);
1944
+ this.#cards.delete(index);
1945
+ }
1946
+ }
1947
+
1948
+ write_text(this.#status, `${live} of ${n} slots occupied`);
1949
+ }
1950
+ }
1951
+
1952
+ /**
1953
+ * Diff of the two layers.
1954
+ *
1955
+ * {@link GamepadHandle} promises it presents the hardware's own values in the standard mapping's slots, with
1956
+ * the only correction applied further along in {@link GamepadStick#value}. This asserts that promise against
1957
+ * the hardware every frame, which is the one thing neither layer can show on its own.
1958
+ *
1959
+ * The comparison goes through {@link GamepadHandle#layout}, because on a pad the browser did not map, slot
1960
+ * `i` deliberately does not come from device index `i` - that translation is the whole point of the layout.
1961
+ * What is being checked is that nothing else changed the values on the way through.
1962
+ */
1963
+ class LayerParityView {
1964
+
1965
+ /**
1966
+ * @readonly
1967
+ * @type {HTMLElement}
1968
+ */
1969
+ el;
1970
+
1971
+ /**
1972
+ * @type {HTMLElement}
1973
+ */
1974
+ #status;
1975
+
1976
+ /**
1977
+ * @type {HTMLElement}
1978
+ */
1979
+ #detail;
1980
+
1981
+ constructor() {
1982
+ this.el = make_element("div", "gpt-sync");
1983
+
1984
+ const title = make_element("div", "", this.el);
1985
+ title.textContent = "layer 1 vs layer 2";
1986
+
1987
+ this.#status = make_element("div", "gpt-status", this.el);
1988
+ this.#detail = make_element("div", "gpt-muted", this.el);
1989
+ }
1990
+
1991
+ /**
1992
+ *
1993
+ * @param {GamepadHandle} main
1994
+ * @param {(Gamepad|null)[]} gamepads
1995
+ * @returns {void}
1996
+ */
1997
+ update(main, gamepads) {
1998
+ if (!main.connected) {
1999
+ this.#write("", "idle", "main is not bound to any pad");
2000
+
2001
+ return;
2002
+ }
2003
+
2004
+ const source = gamepads[main.index];
2005
+
2006
+ if (source === null || source === undefined) {
2007
+ this.#write("gpt-bad", "no source", `main is bound to slot ${main.index}, which the browser reports as empty`);
2008
+
2009
+ return;
2010
+ }
2011
+
2012
+ const layout = main.layout;
2013
+
2014
+ const mismatches = [];
2015
+
2016
+ const buttonCount = layout.presentedButtonCount(source);
2017
+
2018
+ for (let i = 0; i < buttonCount; i++) {
2019
+ const pressed = layout.isButtonPressed(i, source);
2020
+
2021
+ if (main.buttons[i].is_down !== pressed) {
2022
+ mismatches.push(`button ${i} pressed ${main.buttons[i].is_down} vs ${pressed}`);
2023
+ }
2024
+
2025
+ const value = layout.readButtonValue(i, source);
2026
+
2027
+ if (main.buttonValues[i] !== value) {
2028
+ mismatches.push(`button ${i} value ${main.buttonValues[i]} vs ${value}`);
2029
+ }
2030
+ }
2031
+
2032
+ const axisCount = layout.presentedAxisCount(source);
2033
+
2034
+ for (let i = 0; i < axisCount; i++) {
2035
+ const value = layout.readAxis(i, source);
2036
+
2037
+ if (main.axes[i] !== value) {
2038
+ mismatches.push(`axis ${i} ${main.axes[i]} vs ${value}`);
2039
+ }
2040
+ }
2041
+
2042
+ const through = layout === GAMEPAD_STANDARD_LAYOUT ? "passed through" : `via ${layout.name}`;
2043
+
2044
+ if (mismatches.length === 0) {
2045
+ this.#write("gpt-ok", "mirrored", `slot ${main.index} ${through}: ${buttonCount} buttons and ${axisCount} axes identical`);
2046
+ } else {
2047
+ this.#write("gpt-bad", `${mismatches.length} differ`, mismatches.slice(0, 3).join(" "));
2048
+ }
2049
+ }
2050
+
2051
+ /**
2052
+ *
2053
+ * @param {string} modifier
2054
+ * @param {string} status
2055
+ * @param {string} detail
2056
+ */
2057
+ #write(modifier, status, detail) {
2058
+ this.#status.className = `gpt-status ${modifier}`;
2059
+
2060
+ write_text(this.#status, status);
2061
+ write_text(this.#detail, detail);
2062
+ }
2063
+ }
2064
+
2065
+ /**
2066
+ * @param {Engine} engine
2067
+ */
2068
+ function main(engine) {
2069
+ const style = make_element("style", "", document.head);
2070
+ style.textContent = STYLE;
2071
+
2072
+ const root = make_element("div", "gpt-root", document.body);
2073
+
2074
+ const header = make_element("div", "gpt-header", root);
2075
+
2076
+ const title = make_element("h1", "", header);
2077
+ title.textContent = "gamepad tester";
2078
+
2079
+ const subtitle = make_element("div", "gpt-muted", header);
2080
+ subtitle.textContent = "press buttons and move sticks. hardware frame throughout: +x is right, +y is down.";
2081
+
2082
+ const supported = typeof navigator.getGamepads === "function";
2083
+
2084
+ if (!supported) {
2085
+ const warning = make_element("div", "gpt-status gpt-bad", header);
2086
+ warning.textContent = "navigator.getGamepads is not available in this browser";
2087
+ }
2088
+
2089
+ const device = engine.devices.gamepad;
2090
+
2091
+ const engineLayer = new EngineLayerView(device);
2092
+ const parity = new LayerParityView();
2093
+ const nativeLayer = new NativeLayerView();
2094
+
2095
+ root.appendChild(engineLayer.el);
2096
+ root.appendChild(parity.el);
2097
+ root.appendChild(nativeLayer.el);
2098
+
2099
+ /*
2100
+ The device registers its own poll when the engine is constructed, so it has already refreshed by the time
2101
+ this callback runs in the same frame - both layers describe one instant
2102
+ */
2103
+ function update() {
2104
+ const gamepads = supported ? navigator.getGamepads() : [];
2105
+
2106
+ engineLayer.update();
2107
+ parity.update(device.main, gamepads);
2108
+ nativeLayer.update(gamepads);
2109
+
2110
+ requestAnimationFrame(update);
2111
+ }
2112
+
2113
+ requestAnimationFrame(update);
2114
+
2115
+ window.__gamepad_tester = {
2116
+ engine,
2117
+ device,
2118
+ engineLayer,
2119
+ nativeLayer,
2120
+ parity
2121
+ };
2122
+ }
2123
+
2124
+ EngineHarness.bootstrap().then(main);