@woosh/meep-engine 2.169.6 → 2.170.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1552) hide show
  1. package/build/bundle-worker-terrain.js +1 -1
  2. package/editor/Editor.d.ts +161 -65
  3. package/editor/Editor.d.ts.map +1 -1
  4. package/editor/Editor.js +669 -794
  5. package/editor/EditorCameraNavigation.d.ts +21 -0
  6. package/editor/EditorCameraNavigation.d.ts.map +1 -0
  7. package/editor/EditorCameraNavigation.js +191 -0
  8. package/editor/EditorKeyMap.d.ts +28 -0
  9. package/editor/EditorKeyMap.d.ts.map +1 -0
  10. package/editor/EditorKeyMap.js +182 -0
  11. package/editor/REWORK_PLAN_2026_08.md +692 -0
  12. package/editor/SelectionVisualizer.d.ts +48 -19
  13. package/editor/SelectionVisualizer.d.ts.map +1 -1
  14. package/editor/SelectionVisualizer.js +163 -156
  15. package/editor/actions/concrete/ActionUpdateTexture.d.ts +11 -11
  16. package/editor/actions/concrete/ArrayCopyAction.d.ts +19 -19
  17. package/editor/actions/concrete/ArrayCopyAction.d.ts.map +1 -1
  18. package/editor/actions/concrete/ArrayCopyAction.js +7 -7
  19. package/editor/actions/concrete/ComponentAddAction.d.ts +14 -14
  20. package/editor/actions/concrete/ComponentAddAction.d.ts.map +1 -1
  21. package/editor/actions/concrete/ComponentAddAction.js +6 -5
  22. package/editor/actions/concrete/ComponentRemoveAction.d.ts +10 -10
  23. package/editor/actions/concrete/ComponentRemoveAction.d.ts.map +1 -1
  24. package/editor/actions/concrete/ComponentRemoveAction.js +10 -12
  25. package/editor/actions/concrete/EntityCreateAction.d.ts +17 -17
  26. package/editor/actions/concrete/EntityCreateAction.d.ts.map +1 -1
  27. package/editor/actions/concrete/EntityCreateAction.js +11 -14
  28. package/editor/actions/concrete/EntityRemoveAction.d.ts +10 -10
  29. package/editor/actions/concrete/EntityRemoveAction.d.ts.map +1 -1
  30. package/editor/actions/concrete/EntityRemoveAction.js +2 -1
  31. package/editor/actions/concrete/ModifyPatchSampler2DAction.d.ts +46 -46
  32. package/editor/actions/concrete/ModifyPatchTextureArray2DAction.d.ts +37 -37
  33. package/editor/actions/concrete/ModifyPatchTextureArray2DAction.d.ts.map +1 -1
  34. package/editor/actions/concrete/ModifyPatchTextureArray2DAction.js +3 -1
  35. package/editor/actions/concrete/PaintTerrainOverlayAction.d.ts +22 -22
  36. package/editor/actions/concrete/PaintTerrainOverlayAction.d.ts.map +1 -1
  37. package/editor/actions/concrete/PaintTerrainOverlayAction.js +3 -3
  38. package/editor/actions/concrete/PatchTerrainHeightAction.d.ts +31 -18
  39. package/editor/actions/concrete/PatchTerrainHeightAction.d.ts.map +1 -1
  40. package/editor/actions/concrete/PatchTerrainHeightAction.js +28 -9
  41. package/editor/actions/concrete/SelectionAddAction.d.ts +18 -18
  42. package/editor/actions/concrete/SelectionAddAction.d.ts.map +1 -1
  43. package/editor/actions/concrete/SelectionAddAction.js +2 -1
  44. package/editor/actions/concrete/SelectionClearAction.d.ts +8 -8
  45. package/editor/actions/concrete/SelectionClearAction.d.ts.map +1 -1
  46. package/editor/actions/concrete/SelectionClearAction.js +1 -4
  47. package/editor/actions/concrete/SelectionRemoveAction.d.ts +9 -9
  48. package/editor/actions/concrete/SelectionRemoveAction.d.ts.map +1 -1
  49. package/editor/actions/concrete/SelectionRemoveAction.js +2 -1
  50. package/editor/actions/concrete/TransformModifyAction.d.ts +16 -16
  51. package/editor/actions/concrete/TransformModifyAction.d.ts.map +1 -1
  52. package/editor/actions/concrete/TransformModifyAction.js +8 -8
  53. package/editor/actions/concrete/WriteGridValueAction.d.ts +13 -14
  54. package/editor/actions/concrete/WriteGridValueAction.d.ts.map +1 -1
  55. package/editor/actions/concrete/WriteGridValueAction.js +3 -3
  56. package/editor/camera/camera_framing.d.ts +30 -0
  57. package/editor/camera/camera_framing.d.ts.map +1 -0
  58. package/editor/camera/camera_framing.js +98 -0
  59. package/editor/clipboard.d.ts +19 -0
  60. package/editor/clipboard.d.ts.map +1 -0
  61. package/editor/clipboard.js +184 -0
  62. package/editor/ecs/EditorEntity.d.ts +15 -15
  63. package/editor/ecs/EditorEntitySystem.d.ts +7 -7
  64. package/editor/ecs/EditorEntitySystem.d.ts.map +1 -1
  65. package/editor/ecs/EditorEntitySystem.js +1 -6
  66. package/editor/ecs/component/FieldDescriptor.d.ts +26 -26
  67. package/editor/ecs/component/FieldDescriptor.d.ts.map +1 -1
  68. package/editor/ecs/component/FieldDescriptor.js +20 -22
  69. package/editor/ecs/component/FieldValueAdapter.d.ts +6 -6
  70. package/editor/ecs/component/FieldValueAdapter.d.ts.map +1 -1
  71. package/editor/ecs/component/FieldValueAdapter.js +2 -5
  72. package/editor/ecs/component/TypeEditor.d.ts +24 -24
  73. package/editor/ecs/component/createFieldEditor.d.ts +8 -8
  74. package/editor/ecs/component/createObjectEditor.d.ts +13 -13
  75. package/editor/ecs/component/editors/ColorEditor.d.ts +6 -6
  76. package/editor/ecs/component/editors/HTMLElementEditor.d.ts +6 -6
  77. package/editor/ecs/component/editors/HTMLElementEditor.d.ts.map +1 -1
  78. package/editor/ecs/component/editors/ImagePathEditor.d.ts +6 -6
  79. package/editor/ecs/component/editors/LargeStringEditor.d.ts +15 -15
  80. package/editor/ecs/component/editors/NumericIntervalEditor.d.ts +6 -6
  81. package/editor/ecs/component/editors/NumericIntervalEditor.d.ts.map +1 -1
  82. package/editor/ecs/component/editors/ObservedBooleanEditor.d.ts +6 -6
  83. package/editor/ecs/component/editors/ObservedEnumEditor.d.ts +6 -6
  84. package/editor/ecs/component/editors/ObservedIntegerEditor.d.ts +6 -6
  85. package/editor/ecs/component/editors/ObservedIntegerEditor.d.ts.map +1 -1
  86. package/editor/ecs/component/editors/ObservedStringEditor.d.ts +6 -6
  87. package/editor/ecs/component/editors/ObservedStringEditor.d.ts.map +1 -1
  88. package/editor/ecs/component/editors/Sampler2DEditor.d.ts +6 -6
  89. package/editor/ecs/component/editors/collection/ListEditor.d.ts +7 -7
  90. package/editor/ecs/component/editors/common/BitFlagsEditor.d.ts +11 -11
  91. package/editor/ecs/component/editors/common/EnumEditor.d.ts +7 -7
  92. package/editor/ecs/component/editors/common/makeV3_editor.d.ts +14 -14
  93. package/editor/ecs/component/editors/common/makeV3_editor.d.ts.map +1 -1
  94. package/editor/ecs/component/editors/common/noEditor.d.ts +2 -2
  95. package/editor/ecs/component/editors/common/two_way_sync.d.ts +22 -0
  96. package/editor/ecs/component/editors/common/two_way_sync.d.ts.map +1 -0
  97. package/editor/ecs/component/editors/ecs/GridObstacleEditor.d.ts +6 -6
  98. package/editor/ecs/component/editors/ecs/GridObstacleEditor.js +1 -1
  99. package/editor/ecs/component/editors/ecs/ParameterLookupTableEditor.d.ts +19 -66
  100. package/editor/ecs/component/editors/ecs/ParameterLookupTableEditor.d.ts.map +1 -1
  101. package/editor/ecs/component/editors/ecs/ParameterLookupTableEditor.js +35 -239
  102. package/editor/ecs/component/editors/ecs/ParameterTrackEditor.d.ts +11 -11
  103. package/editor/ecs/component/editors/ecs/ParameterTrackEditor.d.ts.map +1 -1
  104. package/editor/ecs/component/editors/ecs/ParameterTrackEditor.js +17 -17
  105. package/editor/ecs/component/editors/ecs/ParameterTrackSetEditor.d.ts +13 -13
  106. package/editor/ecs/component/editors/ecs/ParticleEmitterEditor.d.ts +51 -51
  107. package/editor/ecs/component/editors/ecs/ParticleEmitterEditor.js +1 -1
  108. package/editor/ecs/component/editors/ecs/ParticleEmitterLayerEditor.d.ts +46 -47
  109. package/editor/ecs/component/editors/ecs/ParticleEmitterLayerEditor.d.ts.map +1 -1
  110. package/editor/ecs/component/editors/ecs/SimulationStepDefinitionEditor.d.ts +15 -15
  111. package/editor/ecs/component/editors/ecs/Trail2DEditor.d.ts +29 -29
  112. package/editor/ecs/component/editors/ecs/Trail3DEditor.d.ts +42 -0
  113. package/editor/ecs/component/editors/ecs/Trail3DEditor.d.ts.map +1 -0
  114. package/editor/ecs/component/editors/ecs/TransformEditor.d.ts +19 -19
  115. package/editor/ecs/component/editors/ecs/buildGridObstaclePreview.d.ts +8 -0
  116. package/editor/ecs/component/editors/ecs/buildGridObstaclePreview.d.ts.map +1 -0
  117. package/editor/ecs/component/editors/ecs/buildGridObstaclePreview.js +19 -0
  118. package/editor/ecs/component/editors/ecs/terrain/SplatMappingEditor.d.ts +18 -18
  119. package/editor/ecs/component/editors/ecs/terrain/TerrainEditor.d.ts +38 -38
  120. package/editor/ecs/component/editors/ecs/terrain/TerrainLayerEditor.d.ts +15 -15
  121. package/editor/ecs/component/editors/ecs/terrain/TerrainLayersEditor.d.ts +18 -18
  122. package/editor/ecs/component/editors/ecs/terrain/TerrainOverlayEditor.d.ts +17 -17
  123. package/editor/ecs/component/editors/geom/QuaternionEditor.d.ts +5 -5
  124. package/editor/ecs/component/editors/geom/QuaternionEditor.d.ts.map +1 -1
  125. package/editor/ecs/component/editors/geom/Vector1Editor.d.ts +6 -6
  126. package/editor/ecs/component/editors/geom/Vector1Editor.d.ts.map +1 -1
  127. package/editor/ecs/component/editors/geom/Vector2Editor.d.ts +5 -5
  128. package/editor/ecs/component/editors/geom/Vector3Editor.d.ts +5 -5
  129. package/editor/ecs/component/editors/geom/Vector4Editor.d.ts +5 -5
  130. package/editor/ecs/component/editors/primitive/ArrayEditor.d.ts +7 -7
  131. package/editor/ecs/component/editors/primitive/BooleanEditor.d.ts +6 -6
  132. package/editor/ecs/component/editors/primitive/FunctionEditor.d.ts +6 -6
  133. package/editor/ecs/component/editors/primitive/NumberEditor.d.ts +7 -7
  134. package/editor/ecs/component/editors/primitive/NumberEditor.d.ts.map +1 -1
  135. package/editor/ecs/component/editors/primitive/ObjectEditor.d.ts +5 -5
  136. package/editor/ecs/component/editors/primitive/StringEditor.d.ts +6 -6
  137. package/editor/ecs/component/editors/three/BufferGeometryEditor.d.ts +6 -6
  138. package/editor/ecs/component/editors/three/MaterialEditor.d.ts +6 -6
  139. package/editor/ecs/component/editors/three/MeshEditor.d.ts +6 -6
  140. package/editor/ecs/component/editors/three/TextureEditor.d.ts +6 -6
  141. package/editor/ecs/component/findNearestRegisteredType.d.ts +7 -7
  142. package/editor/ecs/component/registerEngineComponentEditors.d.ts +8 -0
  143. package/editor/ecs/component/registerEngineComponentEditors.d.ts.map +1 -0
  144. package/editor/ecs/component/registerEngineComponentEditors.js +85 -0
  145. package/editor/enableEditor.d.ts +13 -13
  146. package/editor/enableEditor.d.ts.map +1 -1
  147. package/editor/enableEditor.js +14 -4
  148. package/editor/library/MeshLibrary.d.ts +12 -12
  149. package/editor/library/MeshLibrary.d.ts.map +1 -1
  150. package/editor/library/MeshLibrary.js +4 -7
  151. package/editor/particles/lut_ops.d.ts +34 -0
  152. package/editor/particles/lut_ops.d.ts.map +1 -0
  153. package/editor/particles/lut_ops.js +148 -0
  154. package/editor/particles/particleEditEvents.d.ts +11 -0
  155. package/editor/particles/particleEditEvents.d.ts.map +1 -0
  156. package/editor/particles/particleEditEvents.js +12 -0
  157. package/editor/particles/rebuildParticleEmitter.d.ts +11 -0
  158. package/editor/particles/rebuildParticleEmitter.d.ts.map +1 -0
  159. package/editor/particles/rebuildParticleEmitter.js +49 -0
  160. package/editor/persistence/EditorLayoutStore.d.ts +30 -0
  161. package/editor/persistence/EditorLayoutStore.d.ts.map +1 -0
  162. package/editor/persistence/EditorLayoutStore.js +71 -0
  163. package/editor/persistence/SceneMetadata.d.ts +38 -0
  164. package/editor/persistence/SceneMetadata.d.ts.map +1 -0
  165. package/editor/persistence/SceneMetadata.js +52 -0
  166. package/editor/persistence/SceneSlotManager.d.ts +40 -0
  167. package/editor/persistence/SceneSlotManager.d.ts.map +1 -0
  168. package/editor/persistence/SceneSlotManager.js +144 -0
  169. package/editor/persistence/buildNewSceneDataset.d.ts +10 -0
  170. package/editor/persistence/buildNewSceneDataset.d.ts.map +1 -0
  171. package/editor/persistence/buildNewSceneDataset.js +67 -0
  172. package/editor/persistence/files.d.ts +24 -0
  173. package/editor/persistence/files.d.ts.map +1 -0
  174. package/editor/persistence/files.js +68 -0
  175. package/editor/persistence/scene_import.d.ts +45 -0
  176. package/editor/persistence/scene_import.d.ts.map +1 -0
  177. package/editor/persistence/scene_import.js +143 -0
  178. package/editor/persistence/scene_serialization.d.ts +36 -0
  179. package/editor/persistence/scene_serialization.d.ts.map +1 -0
  180. package/editor/persistence/scene_serialization.js +79 -0
  181. package/editor/persistence/string_buffer_codec.d.ts +20 -0
  182. package/editor/persistence/string_buffer_codec.d.ts.map +1 -0
  183. package/editor/persistence/string_buffer_codec.js +41 -0
  184. package/editor/process/DisableGameUIProcess.d.ts +7 -7
  185. package/editor/process/DisableGameUIProcess.d.ts.map +1 -1
  186. package/editor/process/DisableGameUIProcess.js +1 -5
  187. package/editor/process/EditorProcess.d.ts +18 -18
  188. package/editor/process/GridDisplayProcess.d.ts +16 -0
  189. package/editor/process/GridDisplayProcess.d.ts.map +1 -0
  190. package/editor/process/GridDisplayProcess.js +53 -0
  191. package/editor/process/ObstacleGridDisplayProcess.d.ts +12 -12
  192. package/editor/process/ObstacleGridDisplayProcess.d.ts.map +1 -1
  193. package/editor/process/ObstacleGridDisplayProcess.js +7 -9
  194. package/editor/process/ParticleEmitterRebuildProcess.d.ts +66 -0
  195. package/editor/process/ParticleEmitterRebuildProcess.d.ts.map +1 -0
  196. package/editor/process/ParticleEmitterRebuildProcess.js +217 -0
  197. package/editor/process/ProcessEngine.d.ts +29 -29
  198. package/editor/process/ProcessEngine.d.ts.map +1 -1
  199. package/editor/process/ProcessEngine.js +11 -4
  200. package/editor/process/SymbolicDisplayProcess.d.ts +18 -18
  201. package/editor/process/SymbolicDisplayProcess.js +2 -2
  202. package/editor/process/symbolic/ComponentSymbolicDisplay.d.ts +10 -10
  203. package/editor/process/symbolic/SymbolicDisplayInternalAPI.d.ts +67 -64
  204. package/editor/process/symbolic/SymbolicDisplayInternalAPI.d.ts.map +1 -1
  205. package/editor/process/symbolic/SymbolicDisplayInternalAPI.js +42 -45
  206. package/editor/process/symbolic/buildThreeJSHelperEntity.d.ts +8 -8
  207. package/editor/process/symbolic/make3DSymbolicDisplay.d.ts +9 -9
  208. package/editor/process/symbolic/makeCameraSymbolicDisplay.d.ts +6 -6
  209. package/editor/process/symbolic/makeGridPositionSymbolDisplay.d.ts +5 -5
  210. package/editor/process/symbolic/makeHelperBoxGeometry.d.ts +2 -2
  211. package/editor/process/symbolic/makeHelperSphereGeometry.d.ts +8 -8
  212. package/editor/process/symbolic/makeLightSymbolicDisplay.d.ts +6 -6
  213. package/editor/process/symbolic/makeParticleEmitterSymbolicDisplay.d.ts +5 -5
  214. package/editor/process/symbolic/makeParticleEmitterSymbolicDisplay.d.ts.map +1 -1
  215. package/editor/process/symbolic/makeParticleEmitterSymbolicDisplay.js +21 -1
  216. package/editor/process/symbolic/makePathSymbolicDisplay.d.ts +6 -6
  217. package/editor/process/symbolic/makePositionedIconDisplaySymbol.d.ts +8 -8
  218. package/editor/process/symbolic/makePositionedIconDisplaySymbol.d.ts.map +1 -1
  219. package/editor/process/symbolic/makePositionedIconDisplaySymbol.js +3 -0
  220. package/editor/process/symbolic/makeSocketsSymbolicDisplay.d.ts +6 -6
  221. package/editor/process/symbolic/makeSolidArrowGeometry.d.ts +25 -25
  222. package/editor/process/symbolic/makeSoundEmitterSymbolicDisplay.d.ts +5 -5
  223. package/editor/process/symbolic/synchronizeTransform.d.ts +11 -11
  224. package/editor/prototypeEditorShell.js +102 -0
  225. package/editor/style/controls.scss +168 -0
  226. package/editor/style/editor.scss +313 -0
  227. package/editor/style/inspector.scss +223 -0
  228. package/editor/templates/entity_templates.d.ts +19 -0
  229. package/editor/templates/entity_templates.d.ts.map +1 -0
  230. package/editor/templates/entity_templates.js +167 -0
  231. package/editor/tools/GridPaintTool.d.ts +17 -16
  232. package/editor/tools/GridPaintTool.d.ts.map +1 -1
  233. package/editor/tools/GridPaintTool.js +13 -14
  234. package/editor/tools/SelectionTool.d.ts +25 -26
  235. package/editor/tools/SelectionTool.d.ts.map +1 -1
  236. package/editor/tools/SelectionTool.js +46 -13
  237. package/editor/tools/TransformToolV2.d.ts +76 -0
  238. package/editor/tools/TransformToolV2.d.ts.map +1 -0
  239. package/editor/tools/TransformToolV2.js +396 -0
  240. package/editor/tools/engine/Tool.d.ts +87 -63
  241. package/editor/tools/engine/Tool.d.ts.map +1 -1
  242. package/editor/tools/engine/Tool.js +72 -28
  243. package/editor/tools/engine/ToolEngine.d.ts +21 -22
  244. package/editor/tools/engine/ToolEngine.d.ts.map +1 -1
  245. package/editor/tools/engine/ToolEngine.js +52 -54
  246. package/editor/tools/engine/ToolState.d.ts +6 -6
  247. package/editor/tools/paint/TerrainHeightPaintTool.d.ts +17 -17
  248. package/editor/tools/paint/TerrainHeightPaintTool.d.ts.map +1 -1
  249. package/editor/tools/paint/TerrainHeightPaintTool.js +12 -7
  250. package/editor/tools/paint/TerrainPaintTool.d.ts +81 -30
  251. package/editor/tools/paint/TerrainPaintTool.d.ts.map +1 -1
  252. package/editor/tools/paint/TerrainPaintTool.js +58 -21
  253. package/editor/tools/paint/TerrainTexturePaintTool.d.ts +18 -17
  254. package/editor/tools/paint/TerrainTexturePaintTool.d.ts.map +1 -1
  255. package/editor/tools/paint/TerrainTexturePaintTool.js +75 -12
  256. package/editor/tools/v2/BlenderCameraOrientationGizmo.js +24 -26
  257. package/editor/tools/v2/GizmoNode.d.ts.map +1 -1
  258. package/editor/tools/v2/GizmoNode.js +14 -13
  259. package/editor/tools/v2/TransformControls.d.ts.map +1 -1
  260. package/editor/tools/v2/TransformControls.js +18 -45
  261. package/editor/tools/v2/TransformControlsGizmo.d.ts.map +1 -1
  262. package/editor/tools/v2/TransformControlsGizmo.js +3 -6
  263. package/editor/tools/v2/TransformControlsPlane.d.ts.map +1 -1
  264. package/editor/tools/v2/TransformControlsPlane.js +3 -5
  265. package/editor/tools/v2/TransformMode.d.ts +6 -6
  266. package/editor/view/ecs/ComponentControlView.d.ts +23 -23
  267. package/editor/view/ecs/ComponentControlView.d.ts.map +1 -1
  268. package/editor/view/ecs/ComponentControlView.js +4 -4
  269. package/editor/view/ecs/EntityEditor.d.ts +24 -29
  270. package/editor/view/ecs/EntityEditor.d.ts.map +1 -1
  271. package/editor/view/ecs/EntityEditor.js +34 -10
  272. package/editor/view/ecs/EntityList.js +2 -3
  273. package/editor/view/ecs/HierarchicalEntityListView.d.ts +24 -7
  274. package/editor/view/ecs/HierarchicalEntityListView.d.ts.map +1 -1
  275. package/editor/view/ecs/HierarchicalEntityListView.js +339 -191
  276. package/editor/view/ecs/components/DatGuiController.js +2 -216
  277. package/editor/view/ecs/components/color/GaugeView.d.ts +12 -12
  278. package/editor/view/ecs/components/common/AutoCanvasView.d.ts +29 -19
  279. package/editor/view/ecs/components/common/AutoCanvasView.d.ts.map +1 -1
  280. package/editor/view/ecs/components/common/LineView.d.ts +11 -11
  281. package/editor/view/ecs/components/common/LineView.d.ts.map +1 -1
  282. package/editor/view/ecs/components/common/LineView.js +2 -1
  283. package/editor/view/ecs/components/common/NumberController.d.ts +17 -17
  284. package/editor/view/ecs/components/common/TextController.d.ts +21 -0
  285. package/editor/view/ecs/components/common/TextController.d.ts.map +1 -0
  286. package/editor/view/library/MeshLibraryView.d.ts +17 -0
  287. package/editor/view/library/MeshLibraryView.d.ts.map +1 -0
  288. package/editor/view/library/MeshLibraryView.js +35 -20
  289. package/editor/view/node-graph/NodeGraphCamera.d.ts +48 -0
  290. package/editor/view/node-graph/NodeGraphCamera.d.ts.map +1 -0
  291. package/editor/view/node-graph/NodeGraphCamera.js +88 -90
  292. package/editor/view/node-graph/NodeGraphEditorView.d.ts +25 -2
  293. package/editor/view/node-graph/NodeGraphEditorView.d.ts.map +1 -1
  294. package/editor/view/node-graph/NodeGraphSelection.d.ts +56 -0
  295. package/editor/view/node-graph/NodeGraphSelection.d.ts.map +1 -0
  296. package/editor/view/node-graph/NodeGraphView.d.ts +35 -18
  297. package/editor/view/node-graph/NodeGraphView.d.ts.map +1 -1
  298. package/editor/view/node-graph/NodeGraphView.js +666 -669
  299. package/editor/view/node-graph/NodeView.d.ts +3 -2
  300. package/editor/view/node-graph/NodeView.d.ts.map +1 -1
  301. package/editor/view/node-graph/PortView.d.ts +2 -2
  302. package/editor/view/node-graph/PortView.d.ts.map +1 -1
  303. package/editor/view/node-graph/PortView.js +2 -2
  304. package/editor/view/node-graph/actions/ConnectionCreateAction.d.ts +34 -0
  305. package/editor/view/node-graph/actions/ConnectionCreateAction.d.ts.map +1 -0
  306. package/editor/view/node-graph/actions/ConnectionCreateAction.js +53 -53
  307. package/editor/view/node-graph/actions/ConnectionDeleteAction.d.ts +26 -0
  308. package/editor/view/node-graph/actions/ConnectionDeleteAction.d.ts.map +1 -0
  309. package/editor/view/node-graph/actions/NodeDeleteAction.d.ts +47 -0
  310. package/editor/view/node-graph/actions/NodeDeleteAction.d.ts.map +1 -0
  311. package/editor/view/node-graph/actions/NodeDeleteAction.js +88 -88
  312. package/editor/view/node-graph/actions/NodeParameterSetAction.d.ts +34 -0
  313. package/editor/view/node-graph/actions/NodeParameterSetAction.d.ts.map +1 -0
  314. package/editor/view/node-graph/actions/NodeParameterSetAction.js +52 -52
  315. package/editor/view/node-graph/actions/NodesMoveAction.d.ts +38 -0
  316. package/editor/view/node-graph/actions/NodesMoveAction.d.ts.map +1 -0
  317. package/editor/view/node-graph/actions/SelectionSetAction.d.ts +38 -0
  318. package/editor/view/node-graph/actions/SelectionSetAction.d.ts.map +1 -0
  319. package/editor/view/node-graph/actions/SelectionSetAction.js +60 -60
  320. package/editor/view/node-graph/connection_wire_geometry.d.ts +46 -0
  321. package/editor/view/node-graph/connection_wire_geometry.d.ts.map +1 -0
  322. package/editor/view/particles/ColorLutGradientView.d.ts +19 -0
  323. package/editor/view/particles/ColorLutGradientView.d.ts.map +1 -0
  324. package/editor/view/particles/ColorLutGradientView.js +291 -0
  325. package/editor/view/particles/ScalarLutCurveView.d.ts +19 -0
  326. package/editor/view/particles/ScalarLutCurveView.d.ts.map +1 -0
  327. package/editor/view/particles/ScalarLutCurveView.js +279 -0
  328. package/editor/view/prepareMeshLibrary.d.ts +7 -0
  329. package/editor/view/prepareMeshLibrary.d.ts.map +1 -0
  330. package/editor/view/prepareMeshLibrary.js +34 -14
  331. package/editor/view/shell/EditorShellView.d.ts +18 -0
  332. package/editor/view/shell/EditorShellView.d.ts.map +1 -0
  333. package/editor/view/shell/EditorShellView.js +442 -0
  334. package/editor/view/shell/SceneTreePanelView.d.ts +17 -0
  335. package/editor/view/shell/SceneTreePanelView.d.ts.map +1 -0
  336. package/editor/view/shell/SceneTreePanelView.js +119 -0
  337. package/editor/view/shell/ViewportPanelView.d.ts +18 -0
  338. package/editor/view/shell/ViewportPanelView.d.ts.map +1 -0
  339. package/editor/view/shell/ViewportPanelView.js +64 -0
  340. package/editor/view/tools/ToolSettingsView.d.ts +21 -10
  341. package/editor/view/tools/ToolSettingsView.d.ts.map +1 -1
  342. package/editor/view/tools/ToolSettingsView.js +114 -100
  343. package/editor/view/tools/ToolView.d.ts +12 -12
  344. package/editor/view/v2/SplitView.js +2 -104
  345. package/package.json +7 -1
  346. package/samples/terrain/editor.js +9 -13
  347. package/src/core/binary/BitSet.d.ts.map +1 -1
  348. package/src/core/binary/BitSet.js +7 -7
  349. package/src/core/binary/type/Field.d.ts +2 -2
  350. package/src/core/binary/type/Field.d.ts.map +1 -1
  351. package/src/core/binary/type/Field.js +3 -2
  352. package/src/core/binary/type/Type.d.ts +5 -5
  353. package/src/core/binary/type/Type.d.ts.map +1 -1
  354. package/src/core/binary/type/Type.js +18 -15
  355. package/src/core/binary/type/TypeBuilder.d.ts +1 -1
  356. package/src/core/binary/type/TypeBuilder.d.ts.map +1 -1
  357. package/src/core/binary/type/TypeBuilder.js +2 -1
  358. package/src/core/binary/type/TypeRegistry.d.ts.map +1 -1
  359. package/src/core/binary/type/TypeRegistry.js +1 -3
  360. package/src/core/cache/Cache.d.ts +8 -8
  361. package/src/core/cache/Cache.d.ts.map +1 -1
  362. package/src/core/cache/Cache.js +14 -15
  363. package/src/core/cache/CacheV2.d.ts.map +1 -1
  364. package/src/core/cache/CacheV2.js +15 -20
  365. package/src/core/cache/LoadingCache.d.ts.map +1 -1
  366. package/src/core/cache/LoadingCache.js +3 -2
  367. package/src/core/collection/CuckooFilter.d.ts +23 -23
  368. package/src/core/collection/CuckooFilter.d.ts.map +1 -1
  369. package/src/core/collection/CuckooFilter.js +27 -26
  370. package/src/core/collection/PairUint32Map.d.ts +1 -1
  371. package/src/core/collection/PairUint32Map.d.ts.map +1 -1
  372. package/src/core/collection/PairUint32Map.js +322 -321
  373. package/src/core/collection/RingBuffer.d.ts +5 -5
  374. package/src/core/collection/RingBuffer.d.ts.map +1 -1
  375. package/src/core/collection/RingBuffer.js +18 -18
  376. package/src/core/collection/Uint32Map.d.ts +5 -5
  377. package/src/core/collection/Uint32Map.d.ts.map +1 -1
  378. package/src/core/collection/Uint32Map.js +346 -345
  379. package/src/core/collection/Uint32MinHeap.d.ts +4 -4
  380. package/src/core/collection/Uint32MinHeap.d.ts.map +1 -1
  381. package/src/core/collection/Uint32MinHeap.js +109 -109
  382. package/src/core/collection/array/iterator/ArrayIteratorRandom.d.ts.map +1 -1
  383. package/src/core/collection/array/iterator/ArrayIteratorRandom.js +3 -8
  384. package/src/core/collection/heap/FibonacciHeap.d.ts +6 -6
  385. package/src/core/collection/heap/FibonacciHeap.d.ts.map +1 -1
  386. package/src/core/collection/heap/FibonacciHeap.js +586 -586
  387. package/src/core/collection/heap/IndexedFloatMaxHeap.d.ts +1 -1
  388. package/src/core/collection/heap/IndexedFloatMaxHeap.d.ts.map +1 -1
  389. package/src/core/collection/heap/IndexedFloatMaxHeap.js +261 -261
  390. package/src/core/collection/heap/IndexedFloatMinHeap.d.ts +1 -1
  391. package/src/core/collection/heap/IndexedFloatMinHeap.d.ts.map +1 -1
  392. package/src/core/collection/heap/IndexedFloatMinHeap.js +268 -268
  393. package/src/core/collection/heap/Uint32Heap.d.ts +6 -6
  394. package/src/core/collection/heap/Uint32Heap.d.ts.map +1 -1
  395. package/src/core/collection/heap/Uint32Heap.js +7 -7
  396. package/src/core/collection/heap/Uint32Heap4.d.ts +6 -6
  397. package/src/core/collection/heap/Uint32Heap4.d.ts.map +1 -1
  398. package/src/core/collection/heap/Uint32Heap4.js +490 -490
  399. package/src/core/collection/list/FilteredListProjection.d.ts +7 -7
  400. package/src/core/collection/list/FilteredListProjection.d.ts.map +1 -1
  401. package/src/core/collection/list/FilteredListProjection.js +12 -12
  402. package/src/core/collection/list/SortedListProjection.d.ts +2 -2
  403. package/src/core/collection/list/SortedListProjection.d.ts.map +1 -1
  404. package/src/core/collection/list/SortedListProjection.js +6 -6
  405. package/src/core/collection/table/RowFirstTable.d.ts +5 -5
  406. package/src/core/collection/table/RowFirstTable.d.ts.map +1 -1
  407. package/src/core/collection/table/RowFirstTable.js +6 -7
  408. package/src/core/collection/table/RowFirstTableSpec.d.ts +10 -2
  409. package/src/core/collection/table/RowFirstTableSpec.d.ts.map +1 -1
  410. package/src/core/collection/table/RowFirstTableSpec.js +10 -1
  411. package/src/core/function/FunctionCompiler.d.ts.map +1 -1
  412. package/src/core/function/FunctionCompiler.js +13 -15
  413. package/src/core/geom/3d/shape/BoxShape3D.d.ts.map +1 -1
  414. package/src/core/geom/3d/shape/BoxShape3D.js +171 -175
  415. package/src/core/geom/3d/shape/CapsuleShape3D.d.ts.map +1 -1
  416. package/src/core/geom/3d/shape/CapsuleShape3D.js +238 -242
  417. package/src/core/geom/3d/shape/ConvexHullShape3D.d.ts.map +1 -1
  418. package/src/core/geom/3d/shape/ConvexHullShape3D.js +43 -44
  419. package/src/core/geom/3d/shape/CylinderShape3D.d.ts.map +1 -1
  420. package/src/core/geom/3d/shape/CylinderShape3D.js +220 -224
  421. package/src/core/geom/3d/shape/HeightMapShape3D.d.ts.map +1 -1
  422. package/src/core/geom/3d/shape/HeightMapShape3D.js +58 -61
  423. package/src/core/geom/3d/shape/MeshShape3D.d.ts.map +1 -1
  424. package/src/core/geom/3d/shape/MeshShape3D.js +76 -80
  425. package/src/core/geom/3d/shape/PosedShape3D.d.ts.map +1 -1
  426. package/src/core/geom/3d/shape/PosedShape3D.js +160 -159
  427. package/src/core/geom/3d/shape/SphereShape3D.d.ts.map +1 -1
  428. package/src/core/geom/3d/shape/SphereShape3D.js +143 -146
  429. package/src/core/geom/3d/shape/TransformedShape3D.d.ts.map +1 -1
  430. package/src/core/geom/3d/shape/TransformedShape3D.js +20 -24
  431. package/src/core/geom/3d/shape/Triangle3D.d.ts.map +1 -1
  432. package/src/core/geom/3d/shape/Triangle3D.js +293 -297
  433. package/src/core/geom/3d/shape/UnionShape3D.d.ts.map +1 -1
  434. package/src/core/geom/3d/shape/UnionShape3D.js +15 -19
  435. package/src/core/geom/3d/tetrahedra/TetrahedralMesh.d.ts +15 -15
  436. package/src/core/geom/3d/tetrahedra/TetrahedralMesh.d.ts.map +1 -1
  437. package/src/core/geom/3d/tetrahedra/TetrahedralMesh.js +21 -21
  438. package/src/core/geom/3d/topology/simplify/EdgeCollapseCandidate.d.ts.map +1 -1
  439. package/src/core/geom/3d/topology/simplify/EdgeCollapseCandidate.js +36 -36
  440. package/src/core/geom/packing/max-rect/MaxRectanglesPacker.d.ts +6 -6
  441. package/src/core/geom/packing/max-rect/MaxRectanglesPacker.d.ts.map +1 -1
  442. package/src/core/geom/packing/max-rect/MaxRectanglesPacker.js +8 -8
  443. package/src/core/graph/layout/Connection.d.ts +2 -2
  444. package/src/core/graph/layout/Connection.d.ts.map +1 -1
  445. package/src/core/graph/layout/Connection.js +6 -6
  446. package/src/core/graph/metis/native/MetisGraph.d.ts.map +1 -1
  447. package/src/core/graph/metis/native/MetisGraph.js +232 -231
  448. package/src/core/graph/metis/native/bisection/BisectionScratch.d.ts +3 -3
  449. package/src/core/graph/metis/native/bisection/BisectionScratch.d.ts.map +1 -1
  450. package/src/core/graph/metis/native/bisection/BisectionScratch.js +104 -103
  451. package/src/core/localization/Localization.d.ts.map +1 -1
  452. package/src/core/localization/Localization.js +35 -37
  453. package/src/core/model/BooleanVector3.d.ts +1 -1
  454. package/src/core/model/BooleanVector3.d.ts.map +1 -1
  455. package/src/core/model/BooleanVector3.js +2 -2
  456. package/src/core/model/ObservedValue.d.ts +2 -2
  457. package/src/core/model/ObservedValue.d.ts.map +1 -1
  458. package/src/core/model/ObservedValue.js +8 -6
  459. package/src/core/model/object/ImmutableObjectPool.d.ts +5 -5
  460. package/src/core/model/object/ImmutableObjectPool.d.ts.map +1 -1
  461. package/src/core/model/object/ImmutableObjectPool.js +6 -7
  462. package/src/core/model/reactive/evaluation/MultiPredicateEvaluator.d.ts +5 -5
  463. package/src/core/model/reactive/evaluation/MultiPredicateEvaluator.d.ts.map +1 -1
  464. package/src/core/model/reactive/evaluation/MultiPredicateEvaluator.js +93 -96
  465. package/src/core/model/reactive/model/terminal/ReactiveReference.d.ts +4 -4
  466. package/src/core/model/reactive/model/terminal/ReactiveReference.d.ts.map +1 -1
  467. package/src/core/model/reactive/model/terminal/ReactiveReference.js +6 -6
  468. package/src/core/model/stat/LinearModifier.d.ts +10 -10
  469. package/src/core/model/stat/LinearModifier.d.ts.map +1 -1
  470. package/src/core/model/stat/LinearModifier.js +12 -12
  471. package/src/core/process/Future.d.ts +1 -1
  472. package/src/core/process/Future.d.ts.map +1 -1
  473. package/src/core/process/Future.js +6 -7
  474. package/src/core/process/action/AsynchronousActionSequence.d.ts +5 -5
  475. package/src/core/process/action/AsynchronousActionSequence.d.ts.map +1 -1
  476. package/src/core/process/action/AsynchronousActionSequence.js +9 -9
  477. package/src/core/process/executor/profile/ConcurrentExecutorProfiler.d.ts.map +1 -1
  478. package/src/core/process/executor/profile/ConcurrentExecutorProfiler.js +19 -20
  479. package/src/core/process/filter/MutableFilter.d.ts.map +1 -1
  480. package/src/core/process/filter/MutableFilter.js +1 -6
  481. package/src/core/process/task/RemainingTimeEstimator.d.ts +1 -1
  482. package/src/core/process/task/RemainingTimeEstimator.d.ts.map +1 -1
  483. package/src/core/process/task/RemainingTimeEstimator.js +2 -1
  484. package/src/core/process/undo/ActionProcessor.d.ts +36 -17
  485. package/src/core/process/undo/ActionProcessor.d.ts.map +1 -1
  486. package/src/core/process/undo/ActionProcessor.js +131 -136
  487. package/src/core/science/units/UnitMatrix.d.ts.map +1 -1
  488. package/src/core/science/units/UnitMatrix.js +249 -251
  489. package/src/engine/EngineHarness.d.ts +5 -5
  490. package/src/engine/EngineHarness.d.ts.map +1 -1
  491. package/src/engine/EngineHarness.js +6 -6
  492. package/src/engine/achievements/Achievement.d.ts.map +1 -1
  493. package/src/engine/achievements/Achievement.js +35 -35
  494. package/src/engine/achievements/AchievementManager.d.ts.map +1 -1
  495. package/src/engine/achievements/AchievementManager.js +33 -35
  496. package/src/engine/achievements/gateway/StorageAchievementGateway.d.ts +1 -1
  497. package/src/engine/achievements/gateway/StorageAchievementGateway.d.ts.map +1 -1
  498. package/src/engine/achievements/gateway/StorageAchievementGateway.js +2 -2
  499. package/src/engine/animation/EntityAnimation.d.ts +5 -5
  500. package/src/engine/animation/EntityAnimation.d.ts.map +1 -1
  501. package/src/engine/animation/EntityAnimation.js +6 -6
  502. package/src/engine/animation/curve/editor/CurveEditorView.d.ts +2 -2
  503. package/src/engine/animation/curve/editor/CurveEditorView.d.ts.map +1 -1
  504. package/src/engine/animation/curve/editor/CurveEditorView.js +3 -3
  505. package/src/engine/animation/curve/editor/DragHandler.d.ts +1 -1
  506. package/src/engine/animation/curve/editor/DragHandler.d.ts.map +1 -1
  507. package/src/engine/animation/curve/editor/DragHandler.js +2 -2
  508. package/src/engine/animation/curve/editor/OperationRouter.d.ts +1 -1
  509. package/src/engine/animation/curve/editor/OperationRouter.d.ts.map +1 -1
  510. package/src/engine/animation/curve/editor/OperationRouter.js +2 -2
  511. package/src/engine/animation/keyed2/AnimationTrack.d.ts +10 -10
  512. package/src/engine/animation/keyed2/AnimationTrack.d.ts.map +1 -1
  513. package/src/engine/animation/keyed2/AnimationTrack.js +27 -27
  514. package/src/engine/animation/keyed2/AnimationTrackPlayback.d.ts +4 -4
  515. package/src/engine/animation/keyed2/AnimationTrackPlayback.d.ts.map +1 -1
  516. package/src/engine/animation/keyed2/AnimationTrackPlayback.js +6 -9
  517. package/src/engine/asset/Asset.d.ts +10 -10
  518. package/src/engine/asset/Asset.d.ts.map +1 -1
  519. package/src/engine/asset/Asset.js +13 -14
  520. package/src/engine/asset/AssetRequest.d.ts +14 -14
  521. package/src/engine/asset/AssetRequest.d.ts.map +1 -1
  522. package/src/engine/asset/AssetRequest.js +18 -18
  523. package/src/engine/asset/PendingAsset.d.ts +5 -5
  524. package/src/engine/asset/PendingAsset.d.ts.map +1 -1
  525. package/src/engine/asset/PendingAsset.js +108 -108
  526. package/src/engine/asset/loaders/GLTFAssetLoader.d.ts +2 -2
  527. package/src/engine/asset/loaders/GLTFAssetLoader.d.ts.map +1 -1
  528. package/src/engine/asset/loaders/GLTFAssetLoader.js +16 -18
  529. package/src/engine/asset/loaders/JavascriptAssetLoader.d.ts.map +1 -1
  530. package/src/engine/asset/loaders/JavascriptAssetLoader.js +30 -31
  531. package/src/engine/asset/loaders/gltf/extensions/MSFT_texture_dds.d.ts.map +1 -1
  532. package/src/engine/asset/loaders/gltf/extensions/MSFT_texture_dds.js +2 -2
  533. package/src/engine/asset/loaders/material/StaticMaterialCache.d.ts.map +1 -1
  534. package/src/engine/asset/loaders/material/StaticMaterialCache.js +9 -12
  535. package/src/engine/control/StatefulController.d.ts +4 -4
  536. package/src/engine/control/StatefulController.d.ts.map +1 -1
  537. package/src/engine/control/StatefulController.js +6 -6
  538. package/src/engine/control/first-person/FirstPersonPlayerController.d.ts.map +1 -1
  539. package/src/engine/control/first-person/FirstPersonPlayerController.js +31 -33
  540. package/src/engine/control/first-person/FirstPersonPlayerControllerSystem.d.ts.map +1 -1
  541. package/src/engine/control/first-person/FirstPersonPlayerControllerSystem.js +2052 -2028
  542. package/src/engine/control/first-person/abilities/Ability.d.ts.map +1 -1
  543. package/src/engine/control/first-person/abilities/Ability.js +117 -119
  544. package/src/engine/control/first-person/abilities/AbilitySet.d.ts.map +1 -1
  545. package/src/engine/control/first-person/abilities/AbilitySet.js +183 -185
  546. package/src/engine/control/first-person/abilities/LedgeGrab.d.ts.map +1 -1
  547. package/src/engine/control/first-person/abilities/LedgeGrab.js +404 -405
  548. package/src/engine/control/first-person/abilities/Mantle.d.ts.map +1 -1
  549. package/src/engine/control/first-person/abilities/Mantle.js +24 -23
  550. package/src/engine/control/first-person/abilities/ScrambleUp.d.ts.map +1 -1
  551. package/src/engine/control/first-person/abilities/ScrambleUp.js +181 -182
  552. package/src/engine/control/first-person/abilities/Slide.d.ts.map +1 -1
  553. package/src/engine/control/first-person/abilities/Slide.js +164 -166
  554. package/src/engine/control/first-person/abilities/WallJump.d.ts.map +1 -1
  555. package/src/engine/control/first-person/abilities/WallJump.js +136 -139
  556. package/src/engine/control/first-person/abilities/WallRun.d.ts.map +1 -1
  557. package/src/engine/control/first-person/abilities/WallRun.js +7 -9
  558. package/src/engine/control/first-person/collision/KinematicMover.d.ts +7 -13
  559. package/src/engine/control/first-person/collision/KinematicMover.d.ts.map +1 -1
  560. package/src/engine/control/first-person/collision/KinematicMover.js +11 -10
  561. package/src/engine/control/first-person/composer/EyeOffsetStack.d.ts.map +1 -1
  562. package/src/engine/control/first-person/composer/EyeOffsetStack.js +58 -60
  563. package/src/engine/control/first-person/mastery/BreathRhythmEvaluator.d.ts +2 -2
  564. package/src/engine/control/first-person/mastery/BreathRhythmEvaluator.d.ts.map +1 -1
  565. package/src/engine/control/first-person/mastery/BreathRhythmEvaluator.js +133 -133
  566. package/src/engine/control/first-person/mastery/FootAsymmetryTurnEvaluator.d.ts.map +1 -1
  567. package/src/engine/control/first-person/mastery/FootAsymmetryTurnEvaluator.js +106 -109
  568. package/src/engine/control/first-person/mastery/MasteryEvaluator.d.ts.map +1 -1
  569. package/src/engine/control/first-person/mastery/MasteryEvaluator.js +43 -45
  570. package/src/engine/control/first-person/mastery/MasteryScore.d.ts +6 -6
  571. package/src/engine/control/first-person/mastery/MasteryScore.d.ts.map +1 -1
  572. package/src/engine/control/first-person/mastery/MasteryScore.js +100 -100
  573. package/src/engine/control/first-person/mastery/MasterySet.d.ts.map +1 -1
  574. package/src/engine/control/first-person/mastery/MasterySet.js +84 -86
  575. package/src/engine/control/first-person/mastery/SlideInitiationTimingEvaluator.d.ts.map +1 -1
  576. package/src/engine/control/first-person/mastery/SlideInitiationTimingEvaluator.js +80 -83
  577. package/src/engine/control/first-person/mastery/StrideTimingJumpEvaluator.d.ts.map +1 -1
  578. package/src/engine/control/first-person/mastery/StrideTimingJumpEvaluator.js +106 -109
  579. package/src/engine/control/first-person/sensors/FirstPersonSensors.d.ts.map +1 -1
  580. package/src/engine/control/first-person/sensors/FirstPersonSensors.js +45 -40
  581. package/src/engine/control/first-person/sensors/FirstPersonSensorsSystem.d.ts.map +1 -1
  582. package/src/engine/control/first-person/sensors/FirstPersonSensorsSystem.js +35 -39
  583. package/src/engine/development/performance/monitor/PeriodicConsolePrinter.d.ts +1 -1
  584. package/src/engine/development/performance/monitor/PeriodicConsolePrinter.d.ts.map +1 -1
  585. package/src/engine/development/performance/monitor/PeriodicConsolePrinter.js +2 -2
  586. package/src/engine/ecs/ASYNC_SYSTEMS_PROPOSAL.md +531 -0
  587. package/src/engine/ecs/EntityManager.d.ts +16 -0
  588. package/src/engine/ecs/EntityManager.d.ts.map +1 -1
  589. package/src/engine/ecs/EntityManager.js +81 -0
  590. package/src/engine/ecs/animation/Animation.d.ts.map +1 -1
  591. package/src/engine/ecs/animation/Animation.js +8 -8
  592. package/src/engine/ecs/async/SystemWorkerHost.d.ts +98 -0
  593. package/src/engine/ecs/async/SystemWorkerHost.d.ts.map +1 -0
  594. package/src/engine/ecs/async/SystemWorkerHost.js +329 -0
  595. package/src/engine/ecs/async/SystemWorkerLoopback.d.ts +80 -0
  596. package/src/engine/ecs/async/SystemWorkerLoopback.d.ts.map +1 -0
  597. package/src/engine/ecs/async/SystemWorkerLoopback.js +143 -0
  598. package/src/engine/ecs/async/WORKER_SYSTEM_PLAN.md +246 -0
  599. package/src/engine/ecs/async/WorkerSystem.d.ts +173 -0
  600. package/src/engine/ecs/async/WorkerSystem.d.ts.map +1 -0
  601. package/src/engine/ecs/async/WorkerSystem.js +702 -0
  602. package/src/engine/ecs/async/WorkerSystemProtocol.d.ts +62 -0
  603. package/src/engine/ecs/async/WorkerSystemProtocol.d.ts.map +1 -0
  604. package/src/engine/ecs/async/WorkerSystemProtocol.js +150 -0
  605. package/src/engine/ecs/binding/EntityProxyScope.d.ts.map +1 -1
  606. package/src/engine/ecs/binding/EntityProxyScope.js +11 -12
  607. package/src/engine/ecs/components/PropertySet.d.ts.map +1 -1
  608. package/src/engine/ecs/components/PropertySet.js +2 -2
  609. package/src/engine/ecs/components/TagSerializationUpgrader_0_1.d.ts.map +1 -1
  610. package/src/engine/ecs/components/TagSerializationUpgrader_0_1.js +2 -6
  611. package/src/engine/ecs/components/Timer.d.ts +7 -7
  612. package/src/engine/ecs/components/Timer.d.ts.map +1 -1
  613. package/src/engine/ecs/components/Timer.js +18 -18
  614. package/src/engine/ecs/dynamic_actions/DataScope.d.ts.map +1 -1
  615. package/src/engine/ecs/dynamic_actions/DataScope.js +6 -8
  616. package/src/engine/ecs/evaluation/PointFitnessBinary.d.ts.map +1 -1
  617. package/src/engine/ecs/evaluation/PointFitnessBinary.js +10 -13
  618. package/src/engine/ecs/evaluation/PointFitnessConstant.d.ts.map +1 -1
  619. package/src/engine/ecs/evaluation/PointFitnessConstant.js +5 -9
  620. package/src/engine/ecs/evaluation/world/ReadTerrainLayerWeightPointFitness.d.ts.map +1 -1
  621. package/src/engine/ecs/evaluation/world/ReadTerrainLayerWeightPointFitness.js +5 -9
  622. package/src/engine/ecs/fow/FogOfWarRevealerSystem.d.ts.map +1 -1
  623. package/src/engine/ecs/fow/FogOfWarRevealerSystem.js +6 -8
  624. package/src/engine/ecs/fow/FogOfWarSystem.d.ts +2 -2
  625. package/src/engine/ecs/fow/FogOfWarSystem.d.ts.map +1 -1
  626. package/src/engine/ecs/fow/FogOfWarSystem.js +5 -6
  627. package/src/engine/ecs/fow/FogOfWarVisibilityPredicate.d.ts.map +1 -1
  628. package/src/engine/ecs/fow/FogOfWarVisibilityPredicate.js +11 -14
  629. package/src/engine/ecs/fow/serialization/FogOfWarSerializationUpdater_0_1.d.ts.map +1 -1
  630. package/src/engine/ecs/fow/serialization/FogOfWarSerializationUpdater_0_1.js +2 -6
  631. package/src/engine/ecs/gui/position/ViewportPositionSystem.d.ts.map +1 -1
  632. package/src/engine/ecs/gui/position/ViewportPositionSystem.js +5 -6
  633. package/src/engine/ecs/gui/view/LocalizedLabelViewEntity.d.ts.map +1 -1
  634. package/src/engine/ecs/gui/view/LocalizedLabelViewEntity.js +2 -2
  635. package/src/engine/ecs/parent/ChildEntities.d.ts.map +1 -1
  636. package/src/engine/ecs/parent/ChildEntities.js +6 -8
  637. package/src/engine/ecs/parent/FaceEditor.d.ts.map +1 -1
  638. package/src/engine/ecs/parent/FaceEditor.js +42 -41
  639. package/src/engine/ecs/parent/ParentEntity.d.ts.map +1 -1
  640. package/src/engine/ecs/parent/ParentEntity.js +4 -9
  641. package/src/engine/ecs/parent/ParentEntitySystem.d.ts.map +1 -1
  642. package/src/engine/ecs/parent/ParentEntitySystem.js +2 -2
  643. package/src/engine/ecs/sockets/AttachmentSocket.d.ts.map +1 -1
  644. package/src/engine/ecs/sockets/AttachmentSocket.js +12 -14
  645. package/src/engine/ecs/sockets/AttachmentSockets.d.ts.map +1 -1
  646. package/src/engine/ecs/sockets/AttachmentSockets.js +5 -7
  647. package/src/engine/ecs/sockets/BoneAttachmentSocket.d.ts.map +1 -1
  648. package/src/engine/ecs/sockets/BoneAttachmentSocket.js +1 -5
  649. package/src/engine/ecs/speaker/VoiceSystem.d.ts +5 -5
  650. package/src/engine/ecs/speaker/VoiceSystem.d.ts.map +1 -1
  651. package/src/engine/ecs/speaker/VoiceSystem.js +42 -45
  652. package/src/engine/ecs/storage/binary/object/BinaryObjectSerializationAdapter.d.ts.map +1 -1
  653. package/src/engine/ecs/storage/binary/object/BinaryObjectSerializationAdapter.js +17 -19
  654. package/src/engine/ecs/storage/populateEngineSerializationRegistry.d.ts +11 -0
  655. package/src/engine/ecs/storage/populateEngineSerializationRegistry.d.ts.map +1 -0
  656. package/src/engine/ecs/storage/populateEngineSerializationRegistry.js +260 -0
  657. package/src/engine/ecs/system/AbstractContextSystem.d.ts +8 -8
  658. package/src/engine/ecs/system/AbstractContextSystem.d.ts.map +1 -1
  659. package/src/engine/ecs/system/AbstractContextSystem.js +14 -14
  660. package/src/engine/ecs/systems/AnimationSystem.d.ts.map +1 -1
  661. package/src/engine/ecs/systems/AnimationSystem.js +2 -2
  662. package/src/engine/ecs/systems/ScriptSystem.d.ts.map +1 -1
  663. package/src/engine/ecs/systems/ScriptSystem.js +3 -6
  664. package/src/engine/ecs/terrain/ecs/Terrain.d.ts +27 -27
  665. package/src/engine/ecs/terrain/ecs/Terrain.d.ts.map +1 -1
  666. package/src/engine/ecs/terrain/ecs/Terrain.js +35 -38
  667. package/src/engine/ecs/terrain/ecs/layers/TerrainLayers.d.ts.map +1 -1
  668. package/src/engine/ecs/terrain/ecs/layers/TerrainLayers.js +11 -13
  669. package/src/engine/ecs/terrain/ecs/makeTerrainWorkerProxy.d.ts.map +1 -1
  670. package/src/engine/ecs/terrain/ecs/makeTerrainWorkerProxy.js +4 -2
  671. package/src/engine/ecs/terrain/ecs/splat/SplatMapping.d.ts +5 -5
  672. package/src/engine/ecs/terrain/ecs/splat/SplatMapping.d.ts.map +1 -1
  673. package/src/engine/ecs/terrain/ecs/splat/SplatMapping.js +6 -7
  674. package/src/engine/ecs/terrain/overlay/TerrainOverlay.d.ts +9 -9
  675. package/src/engine/ecs/terrain/overlay/TerrainOverlay.d.ts.map +1 -1
  676. package/src/engine/ecs/terrain/overlay/TerrainOverlay.js +13 -12
  677. package/src/engine/ecs/terrain/serialization/TerrainSerializationUpgrader_0_1.d.ts.map +1 -1
  678. package/src/engine/ecs/terrain/serialization/TerrainSerializationUpgrader_0_1.js +2 -6
  679. package/src/engine/ecs/terrain/serialization/TerrainSerializationUpgrader_1_2.d.ts.map +1 -1
  680. package/src/engine/ecs/terrain/serialization/TerrainSerializationUpgrader_1_2.js +2 -6
  681. package/src/engine/ecs/terrain/tiles/TerrainTileManager.d.ts +44 -3
  682. package/src/engine/ecs/terrain/tiles/TerrainTileManager.d.ts.map +1 -1
  683. package/src/engine/ecs/terrain/tiles/TerrainTileManager.js +81 -17
  684. package/src/engine/ecs/terrain/util/obtainTerrain.d.ts.map +1 -1
  685. package/src/engine/ecs/terrain/util/obtainTerrain.js +2 -0
  686. package/src/engine/ecs/tooltip/TooltipComponentSystem.d.ts +20 -20
  687. package/src/engine/ecs/tooltip/TooltipComponentSystem.d.ts.map +1 -1
  688. package/src/engine/ecs/tooltip/TooltipComponentSystem.js +36 -38
  689. package/src/engine/ecs/transform/TransformSerializationUpgrader_0_1.d.ts.map +1 -1
  690. package/src/engine/ecs/transform/TransformSerializationUpgrader_0_1.js +2 -6
  691. package/src/engine/ecs/transform-attachment/TransformAttachmentSystem.d.ts.map +1 -1
  692. package/src/engine/ecs/transform-attachment/TransformAttachmentSystem.js +34 -41
  693. package/src/engine/graphics/camera/CameraShake.d.ts.map +1 -1
  694. package/src/engine/graphics/camera/CameraShake.js +12 -16
  695. package/src/engine/graphics/camera/CameraShakeBehavior.d.ts +2 -2
  696. package/src/engine/graphics/camera/CameraShakeBehavior.d.ts.map +1 -1
  697. package/src/engine/graphics/camera/CameraShakeBehavior.js +3 -4
  698. package/src/engine/graphics/camera/CameraShakeTraumaBehavior.d.ts +2 -2
  699. package/src/engine/graphics/camera/CameraShakeTraumaBehavior.d.ts.map +1 -1
  700. package/src/engine/graphics/camera/CameraShakeTraumaBehavior.js +3 -5
  701. package/src/engine/graphics/composit/CompositLayer.d.ts.map +1 -1
  702. package/src/engine/graphics/composit/CompositLayer.js +6 -6
  703. package/src/engine/graphics/composit/LayerCompositer.d.ts.map +1 -1
  704. package/src/engine/graphics/composit/LayerCompositer.js +17 -19
  705. package/src/engine/graphics/debug/VisualSymbolLine.d.ts.map +1 -1
  706. package/src/engine/graphics/debug/VisualSymbolLine.js +11 -13
  707. package/src/engine/graphics/ecs/animation/AnimationControllerSystem.d.ts.map +1 -1
  708. package/src/engine/graphics/ecs/animation/AnimationControllerSystem.js +2 -5
  709. package/src/engine/graphics/ecs/animation/AnimationRule.d.ts +2 -2
  710. package/src/engine/graphics/ecs/animation/AnimationRule.d.ts.map +1 -1
  711. package/src/engine/graphics/ecs/animation/AnimationRule.js +3 -2
  712. package/src/engine/graphics/ecs/animation/animator/AnimationClip.d.ts.map +1 -1
  713. package/src/engine/graphics/ecs/animation/animator/AnimationClip.js +20 -22
  714. package/src/engine/graphics/ecs/animation/animator/AnimationClipDefinition.d.ts.map +1 -1
  715. package/src/engine/graphics/ecs/animation/animator/AnimationClipDefinition.js +23 -25
  716. package/src/engine/graphics/ecs/animation/animator/AnimationGraphSystem.d.ts +4 -4
  717. package/src/engine/graphics/ecs/animation/animator/AnimationGraphSystem.d.ts.map +1 -1
  718. package/src/engine/graphics/ecs/animation/animator/AnimationGraphSystem.js +32 -33
  719. package/src/engine/graphics/ecs/animation/animator/AnimationNotification.d.ts.map +1 -1
  720. package/src/engine/graphics/ecs/animation/animator/AnimationNotification.js +10 -12
  721. package/src/engine/graphics/ecs/animation/animator/AnimationNotificationDefinition.d.ts.map +1 -1
  722. package/src/engine/graphics/ecs/animation/animator/AnimationNotificationDefinition.js +10 -12
  723. package/src/engine/graphics/ecs/animation/animator/blending/BlendSpace.d.ts +1 -1
  724. package/src/engine/graphics/ecs/animation/animator/blending/BlendSpace.d.ts.map +1 -1
  725. package/src/engine/graphics/ecs/animation/animator/blending/BlendSpace.js +10 -12
  726. package/src/engine/graphics/ecs/animation/animator/blending/BlendSpaceDefinition.d.ts.map +1 -1
  727. package/src/engine/graphics/ecs/animation/animator/blending/BlendSpaceDefinition.js +5 -7
  728. package/src/engine/graphics/ecs/animation/animator/blending/BlendSpacePoint.d.ts.map +1 -1
  729. package/src/engine/graphics/ecs/animation/animator/blending/BlendSpacePoint.js +10 -12
  730. package/src/engine/graphics/ecs/animation/animator/blending/BlendState.d.ts.map +1 -1
  731. package/src/engine/graphics/ecs/animation/animator/blending/BlendState.js +5 -7
  732. package/src/engine/graphics/ecs/animation/animator/blending/BlendStateDatabase.d.ts.map +1 -1
  733. package/src/engine/graphics/ecs/animation/animator/blending/BlendStateDatabase.js +18 -21
  734. package/src/engine/graphics/ecs/animation/animator/graph/AnimationGraph.d.ts.map +1 -1
  735. package/src/engine/graphics/ecs/animation/animator/graph/AnimationGraph.js +75 -77
  736. package/src/engine/graphics/ecs/animation/animator/graph/AnimationState.d.ts.map +1 -1
  737. package/src/engine/graphics/ecs/animation/animator/graph/AnimationState.js +35 -38
  738. package/src/engine/graphics/ecs/animation/animator/graph/AnimationTransition.d.ts.map +1 -1
  739. package/src/engine/graphics/ecs/animation/animator/graph/AnimationTransition.js +30 -32
  740. package/src/engine/graphics/ecs/animation/animator/graph/definition/AnimationStateDefinition.d.ts.map +1 -1
  741. package/src/engine/graphics/ecs/animation/animator/graph/definition/AnimationStateDefinition.js +31 -33
  742. package/src/engine/graphics/ecs/animation/animator/graph/definition/AnimationTransitionDefinition.d.ts.map +1 -1
  743. package/src/engine/graphics/ecs/animation/animator/graph/definition/AnimationTransitionDefinition.js +20 -23
  744. package/src/engine/graphics/ecs/camera/Camera.d.ts.map +1 -1
  745. package/src/engine/graphics/ecs/camera/Camera.js +45 -47
  746. package/src/engine/graphics/ecs/camera/CameraSystem.d.ts +1 -1
  747. package/src/engine/graphics/ecs/camera/CameraSystem.d.ts.map +1 -1
  748. package/src/engine/graphics/ecs/camera/CameraSystem.js +8 -9
  749. package/src/engine/graphics/ecs/camera/serialization/CameraSerializationUpgrader_0_1.d.ts.map +1 -1
  750. package/src/engine/graphics/ecs/camera/serialization/CameraSerializationUpgrader_0_1.js +37 -41
  751. package/src/engine/graphics/ecs/camera/topdown/TopDownCameraController.d.ts.map +1 -1
  752. package/src/engine/graphics/ecs/camera/topdown/TopDownCameraController.js +8 -10
  753. package/src/engine/graphics/ecs/camera/topdown/TopDownCameraControllerSerializationUpgrader_0_1.d.ts.map +1 -1
  754. package/src/engine/graphics/ecs/camera/topdown/TopDownCameraControllerSerializationUpgrader_0_1.js +2 -6
  755. package/src/engine/graphics/ecs/camera/topdown/TopDownCameraControllerSystem.d.ts.map +1 -1
  756. package/src/engine/graphics/ecs/camera/topdown/TopDownCameraControllerSystem.js +5 -10
  757. package/src/engine/graphics/ecs/camera/topdown/TopDownCameraLanderSystem.d.ts.map +1 -1
  758. package/src/engine/graphics/ecs/camera/topdown/TopDownCameraLanderSystem.js +20 -25
  759. package/src/engine/graphics/ecs/decal/v2/FPDecalSystem.d.ts.map +1 -1
  760. package/src/engine/graphics/ecs/decal/v2/FPDecalSystem.js +2 -2
  761. package/src/engine/graphics/ecs/highlight/HighlightSerializationUpgrader_0_1.d.ts.map +1 -1
  762. package/src/engine/graphics/ecs/highlight/HighlightSerializationUpgrader_0_1.js +2 -6
  763. package/src/engine/graphics/ecs/highlight/plugin/OutlineRenderPlugin.d.ts.map +1 -1
  764. package/src/engine/graphics/ecs/highlight/plugin/OutlineRenderPlugin.js +23 -25
  765. package/src/engine/graphics/ecs/highlight/renderer/HighlightRenderElement.d.ts.map +1 -1
  766. package/src/engine/graphics/ecs/highlight/renderer/HighlightRenderElement.js +13 -16
  767. package/src/engine/graphics/ecs/highlight/renderer/HighlightRenderGroup.d.ts.map +1 -1
  768. package/src/engine/graphics/ecs/highlight/renderer/HighlightRenderGroup.js +5 -7
  769. package/src/engine/graphics/ecs/highlight/renderer/OutlineRenderer.d.ts +12 -12
  770. package/src/engine/graphics/ecs/highlight/renderer/OutlineRenderer.d.ts.map +1 -1
  771. package/src/engine/graphics/ecs/highlight/renderer/OutlineRenderer.js +54 -57
  772. package/src/engine/graphics/ecs/highlight/system/HighlightSystemBase.js +205 -205
  773. package/src/engine/graphics/ecs/light/Light.d.ts.map +1 -1
  774. package/src/engine/graphics/ecs/light/Light.js +59 -65
  775. package/src/engine/graphics/ecs/light/LightSystem.d.ts +16 -16
  776. package/src/engine/graphics/ecs/light/LightSystem.d.ts.map +1 -1
  777. package/src/engine/graphics/ecs/light/LightSystem.js +23 -25
  778. package/src/engine/graphics/ecs/light/binding/LightBinding.d.ts.map +1 -1
  779. package/src/engine/graphics/ecs/light/binding/LightBinding.js +13 -14
  780. package/src/engine/graphics/ecs/light/binding/fp/FPLightBinding.d.ts.map +1 -1
  781. package/src/engine/graphics/ecs/light/binding/fp/FPLightBinding.js +11 -15
  782. package/src/engine/graphics/ecs/light/shadow/ShadowMap.d.ts.map +1 -1
  783. package/src/engine/graphics/ecs/light/shadow/ShadowMap.js +5 -9
  784. package/src/engine/graphics/ecs/light/three/ThreeLightCache.d.ts.map +1 -1
  785. package/src/engine/graphics/ecs/light/three/ThreeLightCache.js +20 -22
  786. package/src/engine/graphics/ecs/mesh/Mesh.d.ts.map +1 -1
  787. package/src/engine/graphics/ecs/mesh/Mesh.js +35 -37
  788. package/src/engine/graphics/ecs/mesh/MeshSystem.d.ts +15 -15
  789. package/src/engine/graphics/ecs/mesh/MeshSystem.d.ts.map +1 -1
  790. package/src/engine/graphics/ecs/mesh/MeshSystem.js +21 -22
  791. package/src/engine/graphics/ecs/mesh/skeleton/BoneMapping.d.ts.map +1 -1
  792. package/src/engine/graphics/ecs/mesh/skeleton/BoneMapping.js +1 -3
  793. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.d.ts.map +1 -1
  794. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +51 -52
  795. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.d.ts +6 -6
  796. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.d.ts.map +1 -1
  797. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +37 -37
  798. package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMeshAnimationControllerSystem.d.ts +1 -1
  799. package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMeshAnimationControllerSystem.d.ts.map +1 -1
  800. package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMeshAnimationControllerSystem.js +9 -11
  801. package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMeshHighlightSystem.d.ts.map +1 -1
  802. package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMeshHighlightSystem.js +1 -5
  803. package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMeshSystem.d.ts +10 -10
  804. package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMeshSystem.d.ts.map +1 -1
  805. package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMeshSystem.js +22 -22
  806. package/src/engine/graphics/ecs/mesh-v2/render/SGThreeObjectCache.d.ts.map +1 -1
  807. package/src/engine/graphics/ecs/mesh-v2/render/SGThreeObjectCache.js +6 -8
  808. package/src/engine/graphics/ecs/mesh-v2/render/ShadedGeometryRendererContext.d.ts.map +1 -1
  809. package/src/engine/graphics/ecs/mesh-v2/render/ShadedGeometryRendererContext.js +8 -10
  810. package/src/engine/graphics/ecs/mesh-v2/render/adapters/AbstractRenderAdapter.d.ts.map +1 -1
  811. package/src/engine/graphics/ecs/mesh-v2/render/adapters/AbstractRenderAdapter.js +12 -15
  812. package/src/engine/graphics/ecs/mesh-v2/render/adapters/GenericRendererAdapter.d.ts.map +1 -1
  813. package/src/engine/graphics/ecs/mesh-v2/render/adapters/GenericRendererAdapter.js +6 -10
  814. package/src/engine/graphics/ecs/mesh-v2/render/optimization/RuntimeDrawMethodOptimizer.d.ts.map +1 -1
  815. package/src/engine/graphics/ecs/mesh-v2/render/optimization/RuntimeDrawMethodOptimizer.js +12 -15
  816. package/src/engine/graphics/ecs/path/PathDisplay.d.ts.map +1 -1
  817. package/src/engine/graphics/ecs/path/PathDisplay.js +5 -7
  818. package/src/engine/graphics/ecs/path/PathDisplaySpec.d.ts.map +1 -1
  819. package/src/engine/graphics/ecs/path/PathDisplaySpec.js +10 -12
  820. package/src/engine/graphics/ecs/path/PathDisplaySystem.d.ts +6 -6
  821. package/src/engine/graphics/ecs/path/PathDisplaySystem.d.ts.map +1 -1
  822. package/src/engine/graphics/ecs/path/PathDisplaySystem.js +12 -17
  823. package/src/engine/graphics/ecs/path/entity/EntityPath.d.ts.map +1 -1
  824. package/src/engine/graphics/ecs/path/entity/EntityPath.js +15 -17
  825. package/src/engine/graphics/ecs/path/entity/EntityPathMarker.d.ts.map +1 -1
  826. package/src/engine/graphics/ecs/path/entity/EntityPathMarker.js +15 -17
  827. package/src/engine/graphics/ecs/path/entity/EntityPathMarkerDefinition.d.ts.map +1 -1
  828. package/src/engine/graphics/ecs/path/entity/EntityPathMarkerDefinition.js +15 -17
  829. package/src/engine/graphics/ecs/path/entity/EntityPathStyle.d.ts.map +1 -1
  830. package/src/engine/graphics/ecs/path/entity/EntityPathStyle.js +20 -23
  831. package/src/engine/graphics/ecs/path/highlight/PathDisplayHighlightSystem.d.ts.map +1 -1
  832. package/src/engine/graphics/ecs/path/highlight/PathDisplayHighlightSystem.js +1 -5
  833. package/src/engine/graphics/ecs/path/ribbon/RibbonPathBuilder.d.ts.map +1 -1
  834. package/src/engine/graphics/ecs/path/ribbon/RibbonPathBuilder.js +15 -17
  835. package/src/engine/graphics/ecs/path/ribbon/RibbonPathStyle.d.ts.map +1 -1
  836. package/src/engine/graphics/ecs/path/ribbon/RibbonPathStyle.js +15 -17
  837. package/src/engine/graphics/ecs/path/tube/MatcapMaterialDefinition.d.ts.map +1 -1
  838. package/src/engine/graphics/ecs/path/tube/MatcapMaterialDefinition.js +5 -7
  839. package/src/engine/graphics/ecs/path/tube/StandardMaterialDefinition.d.ts.map +1 -1
  840. package/src/engine/graphics/ecs/path/tube/StandardMaterialDefinition.js +2 -4
  841. package/src/engine/graphics/ecs/path/tube/TubePathStyle.d.ts.map +1 -1
  842. package/src/engine/graphics/ecs/path/tube/TubePathStyle.js +84 -86
  843. package/src/engine/graphics/ecs/path/tube/build/StreamGeometryBuilder.d.ts.map +1 -1
  844. package/src/engine/graphics/ecs/path/tube/build/StreamGeometryBuilder.js +37 -36
  845. package/src/engine/graphics/ecs/path/tube/build/TubePathBuilder.d.ts.map +1 -1
  846. package/src/engine/graphics/ecs/path/tube/build/TubePathBuilder.js +23 -25
  847. package/src/engine/graphics/ecs/sprite/SpriteSystemPE.d.ts.map +1 -1
  848. package/src/engine/graphics/ecs/sprite/SpriteSystemPE.js +2 -3
  849. package/src/engine/graphics/ecs/trail2d/Trail2DSystem.d.ts +5 -5
  850. package/src/engine/graphics/ecs/trail2d/Trail2DSystem.d.ts.map +1 -1
  851. package/src/engine/graphics/ecs/trail2d/Trail2DSystem.js +6 -9
  852. package/src/engine/graphics/ecs/trail3d/Trail3DSystem.d.ts +4 -4
  853. package/src/engine/graphics/ecs/trail3d/Trail3DSystem.d.ts.map +1 -1
  854. package/src/engine/graphics/ecs/trail3d/Trail3DSystem.js +5 -5
  855. package/src/engine/graphics/ecs/water/WaterSerializationUpgrader_0_1.d.ts.map +1 -1
  856. package/src/engine/graphics/ecs/water/WaterSerializationUpgrader_0_1.js +2 -6
  857. package/src/engine/graphics/ecs/water/WaterSystem.d.ts +1 -1
  858. package/src/engine/graphics/ecs/water/WaterSystem.d.ts.map +1 -1
  859. package/src/engine/graphics/ecs/water/WaterSystem.js +13 -15
  860. package/src/engine/graphics/geometry/MikkT/MikkTSpace.d.ts.map +1 -1
  861. package/src/engine/graphics/geometry/MikkT/MikkTSpace.js +97 -95
  862. package/src/engine/graphics/geometry/MikkT/SSubGroup.d.ts.map +1 -1
  863. package/src/engine/graphics/geometry/MikkT/SSubGroup.js +10 -12
  864. package/src/engine/graphics/geometry/instancing/InstancedMeshGroup.d.ts.map +1 -1
  865. package/src/engine/graphics/geometry/instancing/InstancedMeshGroup.js +103 -110
  866. package/src/engine/graphics/geometry/optimization/geometry_optimize_uv_tension.d.ts +18 -3
  867. package/src/engine/graphics/geometry/optimization/geometry_optimize_uv_tension.d.ts.map +1 -1
  868. package/src/engine/graphics/geometry/optimization/geometry_optimize_uv_tension.js +135 -85
  869. package/src/engine/graphics/geometry/optimization/merge/merge_geometry_hierarchy.d.ts.map +1 -1
  870. package/src/engine/graphics/geometry/optimization/merge/merge_geometry_hierarchy.js +3 -5
  871. package/src/engine/graphics/geometry/ribbon/Quad.d.ts +2 -2
  872. package/src/engine/graphics/geometry/ribbon/Quad.d.ts.map +1 -1
  873. package/src/engine/graphics/geometry/ribbon/Quad.js +17 -17
  874. package/src/engine/graphics/material/manager/ManagedMaterial.d.ts +6 -6
  875. package/src/engine/graphics/material/manager/ManagedMaterial.d.ts.map +1 -1
  876. package/src/engine/graphics/material/manager/ManagedMaterial.js +20 -20
  877. package/src/engine/graphics/material/optimization/MaterialDescriptor.d.ts.map +1 -1
  878. package/src/engine/graphics/material/optimization/MaterialDescriptor.js +11 -14
  879. package/src/engine/graphics/material/optimization/MaterialOptimizationContext.d.ts.map +1 -1
  880. package/src/engine/graphics/material/optimization/MaterialOptimizationContext.js +20 -23
  881. package/src/engine/graphics/material/optimization/UvContext.d.ts.map +1 -1
  882. package/src/engine/graphics/material/optimization/UvContext.js +10 -12
  883. package/src/engine/graphics/particles/node-based/editor/ParticleSpecificationEditorView.d.ts.map +1 -1
  884. package/src/engine/graphics/particles/node-based/editor/ParticleSpecificationEditorView.js +23 -23
  885. package/src/engine/graphics/particles/node-based/rendering/AbstractParticleRenderer.d.ts.map +1 -1
  886. package/src/engine/graphics/particles/node-based/rendering/AbstractParticleRenderer.js +5 -7
  887. package/src/engine/graphics/particles/node-based/rendering/billboard/BillboardParticleRenderer.d.ts +11 -11
  888. package/src/engine/graphics/particles/node-based/rendering/billboard/BillboardParticleRenderer.d.ts.map +1 -1
  889. package/src/engine/graphics/particles/node-based/rendering/billboard/BillboardParticleRenderer.js +21 -23
  890. package/src/engine/graphics/particles/node-based/simulation/EmitterAttributeData.d.ts.map +1 -1
  891. package/src/engine/graphics/particles/node-based/simulation/EmitterAttributeData.js +17 -19
  892. package/src/engine/graphics/particles/node-based/simulation/GLDataBuffer.d.ts.map +1 -1
  893. package/src/engine/graphics/particles/node-based/simulation/GLDataBuffer.js +25 -27
  894. package/src/engine/graphics/particles/node-based/simulation/GLSLSimulationShader.d.ts.map +1 -1
  895. package/src/engine/graphics/particles/node-based/simulation/GLSLSimulationShader.js +12 -16
  896. package/src/engine/graphics/particles/node-based/simulation/TransformFeedback.d.ts.map +1 -1
  897. package/src/engine/graphics/particles/node-based/simulation/TransformFeedback.js +64 -67
  898. package/src/engine/graphics/particles/particular/engine/MovingBoundingBox.d.ts +3 -0
  899. package/src/engine/graphics/particles/particular/engine/MovingBoundingBox.d.ts.map +1 -1
  900. package/src/engine/graphics/particles/particular/engine/MovingBoundingBox.js +36 -39
  901. package/src/engine/graphics/particles/particular/engine/emitter/serde/ParticleEmitterSerializationUpgrader_0_1.d.ts.map +1 -1
  902. package/src/engine/graphics/particles/particular/engine/emitter/serde/ParticleEmitterSerializationUpgrader_0_1.js +2 -6
  903. package/src/engine/graphics/particles/particular/engine/parameter/ParameterSet.d.ts.map +1 -1
  904. package/src/engine/graphics/particles/particular/engine/parameter/ParameterSet.js +5 -7
  905. package/src/engine/graphics/particles/particular/engine/shader/ShaderManager.d.ts +10 -10
  906. package/src/engine/graphics/particles/particular/engine/shader/ShaderManager.d.ts.map +1 -1
  907. package/src/engine/graphics/particles/particular/engine/shader/ShaderManager.js +12 -12
  908. package/src/engine/graphics/particles/particular/engine/simulator/AbstractSimulationStep.d.ts.map +1 -1
  909. package/src/engine/graphics/particles/particular/engine/simulator/AbstractSimulationStep.js +35 -37
  910. package/src/engine/graphics/particles/particular/engine/simulator/SimulationStepCurlNoiseVelocity.d.ts.map +1 -1
  911. package/src/engine/graphics/particles/particular/engine/simulator/SimulationStepCurlNoiseVelocity.js +1 -5
  912. package/src/engine/graphics/particles/particular/engine/simulator/SimulationStepDefinition.d.ts.map +1 -1
  913. package/src/engine/graphics/particles/particular/engine/simulator/SimulationStepDefinition.js +11 -12
  914. package/src/engine/graphics/particles/particular/engine/utils/volume/AttributeValue.d.ts.map +1 -1
  915. package/src/engine/graphics/particles/particular/engine/utils/volume/AttributeValue.js +199 -201
  916. package/src/engine/graphics/particles/particular/engine/utils/volume/ParticleVolume.d.ts +11 -11
  917. package/src/engine/graphics/particles/particular/engine/utils/volume/ParticleVolume.d.ts.map +1 -1
  918. package/src/engine/graphics/particles/particular/engine/utils/volume/ParticleVolume.js +13 -13
  919. package/src/engine/graphics/particles/particular/group/ParticleGroup.d.ts +6 -6
  920. package/src/engine/graphics/particles/particular/group/ParticleGroup.d.ts.map +1 -1
  921. package/src/engine/graphics/particles/particular/group/ParticleGroup.js +33 -34
  922. package/src/engine/graphics/particles/particular/group/ParticleSpecification.d.ts.map +1 -1
  923. package/src/engine/graphics/particles/particular/group/ParticleSpecification.js +2 -8
  924. package/src/engine/graphics/render/Lines.d.ts.map +1 -1
  925. package/src/engine/graphics/render/Lines.js +2 -2
  926. package/src/engine/graphics/render/buffer/FrameBufferManager.d.ts.map +1 -1
  927. package/src/engine/graphics/render/buffer/FrameBufferManager.js +20 -22
  928. package/src/engine/graphics/render/buffer/simple-fx/DepthLimitedBlur.d.ts +2 -2
  929. package/src/engine/graphics/render/buffer/simple-fx/DepthLimitedBlur.d.ts.map +1 -1
  930. package/src/engine/graphics/render/buffer/simple-fx/DepthLimitedBlur.js +16 -19
  931. package/src/engine/graphics/render/buffer/simple-fx/SimplePostProcessEffect.d.ts.map +1 -1
  932. package/src/engine/graphics/render/buffer/simple-fx/SimplePostProcessEffect.js +5 -8
  933. package/src/engine/graphics/render/buffer/simple-fx/ao/AmbientOcclusionPostProcessEffect.d.ts +2 -2
  934. package/src/engine/graphics/render/buffer/simple-fx/ao/AmbientOcclusionPostProcessEffect.d.ts.map +1 -1
  935. package/src/engine/graphics/render/buffer/simple-fx/ao/AmbientOcclusionPostProcessEffect.js +37 -38
  936. package/src/engine/graphics/render/buffer/slot/ProgramSlotValue.d.ts +5 -5
  937. package/src/engine/graphics/render/buffer/slot/ProgramSlotValue.d.ts.map +1 -1
  938. package/src/engine/graphics/render/buffer/slot/ProgramSlotValue.js +8 -6
  939. package/src/engine/graphics/render/buffer/slot/ProgramValueSlotDefinition.d.ts +5 -5
  940. package/src/engine/graphics/render/buffer/slot/ProgramValueSlotDefinition.d.ts.map +1 -1
  941. package/src/engine/graphics/render/buffer/slot/ProgramValueSlotDefinition.js +6 -6
  942. package/src/engine/graphics/render/buffer/slot/parameter/ProgramValueSlotParameterSet.d.ts.map +1 -1
  943. package/src/engine/graphics/render/buffer/slot/parameter/ProgramValueSlotParameterSet.js +11 -13
  944. package/src/engine/graphics/render/forward_plus/LightManager.d.ts +6 -6
  945. package/src/engine/graphics/render/forward_plus/LightManager.d.ts.map +1 -1
  946. package/src/engine/graphics/render/forward_plus/LightManager.js +15 -18
  947. package/src/engine/graphics/render/forward_plus/LightRenderMetadata.d.ts +5 -5
  948. package/src/engine/graphics/render/forward_plus/LightRenderMetadata.d.ts.map +1 -1
  949. package/src/engine/graphics/render/forward_plus/LightRenderMetadata.js +7 -8
  950. package/src/engine/graphics/render/forward_plus/model/Decal.d.ts +1 -1
  951. package/src/engine/graphics/render/forward_plus/model/Decal.d.ts.map +1 -1
  952. package/src/engine/graphics/render/forward_plus/model/Decal.js +22 -22
  953. package/src/engine/graphics/render/gizmo/GizmoShapeRenderingInterface.d.ts.map +1 -1
  954. package/src/engine/graphics/render/gizmo/GizmoShapeRenderingInterface.js +8 -8
  955. package/src/engine/graphics/render/layers/RenderLayerManager.d.ts.map +1 -1
  956. package/src/engine/graphics/render/layers/RenderLayerManager.js +10 -12
  957. package/src/engine/graphics/render/layers/RenderLayerManagerState.d.ts.map +1 -1
  958. package/src/engine/graphics/render/layers/RenderLayerManagerState.js +5 -9
  959. package/src/engine/graphics/render/layers/RenderLayerState.d.ts.map +1 -1
  960. package/src/engine/graphics/render/layers/RenderLayerState.js +5 -7
  961. package/src/engine/graphics/render/utils/ThreeBypassRenderer.d.ts.map +1 -1
  962. package/src/engine/graphics/render/utils/ThreeBypassRenderer.js +6 -9
  963. package/src/engine/graphics/render/view/CameraView.d.ts.map +1 -1
  964. package/src/engine/graphics/render/view/CameraView.js +56 -59
  965. package/src/engine/graphics/render/view/CameraViewManager.d.ts.map +1 -1
  966. package/src/engine/graphics/render/view/CameraViewManager.js +18 -20
  967. package/src/engine/graphics/render/visibility/IncrementalDeltaSet.d.ts +6 -6
  968. package/src/engine/graphics/render/visibility/IncrementalDeltaSet.d.ts.map +1 -1
  969. package/src/engine/graphics/render/visibility/IncrementalDeltaSet.js +40 -39
  970. package/src/engine/graphics/render/visibility/VisibilityComputer.d.ts.map +1 -1
  971. package/src/engine/graphics/render/visibility/VisibilityComputer.js +19 -22
  972. package/src/engine/graphics/render/visibility/VisibilityFilter.d.ts +5 -5
  973. package/src/engine/graphics/render/visibility/VisibilityFilter.d.ts.map +1 -1
  974. package/src/engine/graphics/render/visibility/VisibilityFilter.js +6 -6
  975. package/src/engine/graphics/render/visibility/hiz/buffer/HierarchicalZBuffer.d.ts.map +1 -1
  976. package/src/engine/graphics/render/visibility/hiz/buffer/HierarchicalZBuffer.js +40 -43
  977. package/src/engine/graphics/render/visibility/hiz/query/BatchOcclusionQuery.d.ts +1 -1
  978. package/src/engine/graphics/render/visibility/hiz/query/BatchOcclusionQuery.d.ts.map +1 -1
  979. package/src/engine/graphics/render/visibility/hiz/query/BatchOcclusionQuery.js +2 -2
  980. package/src/engine/graphics/sh3/lpv/WebGLCubeProbeRenderer.d.ts.map +1 -1
  981. package/src/engine/graphics/sh3/lpv/WebGLCubeProbeRenderer.js +7 -9
  982. package/src/engine/graphics/sh3/path_tracer/BufferedGeometryBVH.d.ts.map +1 -1
  983. package/src/engine/graphics/sh3/path_tracer/BufferedGeometryBVH.js +24 -28
  984. package/src/engine/graphics/shadows/ShadowMapRenderer.d.ts.map +1 -1
  985. package/src/engine/graphics/shadows/ShadowMapRenderer.js +11 -15
  986. package/src/engine/graphics/texture/AttributeDataTexture.d.ts +11 -11
  987. package/src/engine/graphics/texture/AttributeDataTexture.d.ts.map +1 -1
  988. package/src/engine/graphics/texture/AttributeDataTexture.js +14 -14
  989. package/src/engine/graphics/texture/TextureBackedMemoryRegion.d.ts +6 -6
  990. package/src/engine/graphics/texture/TextureBackedMemoryRegion.d.ts.map +1 -1
  991. package/src/engine/graphics/texture/TextureBackedMemoryRegion.js +33 -32
  992. package/src/engine/graphics/texture/atlas/AtlasLookupTexture.d.ts.map +1 -1
  993. package/src/engine/graphics/texture/atlas/AtlasLookupTexture.js +12 -12
  994. package/src/engine/graphics/texture/atlas/CachingTextureAtlas.d.ts.map +1 -1
  995. package/src/engine/graphics/texture/atlas/CachingTextureAtlas.js +17 -20
  996. package/src/engine/graphics/texture/atlas/ReferencedTextureAtlas.d.ts +1 -1
  997. package/src/engine/graphics/texture/atlas/ReferencedTextureAtlas.d.ts.map +1 -1
  998. package/src/engine/graphics/texture/atlas/ReferencedTextureAtlas.js +14 -14
  999. package/src/engine/graphics/texture/atlas/TextureAtlas.d.ts +10 -10
  1000. package/src/engine/graphics/texture/atlas/TextureAtlas.d.ts.map +1 -1
  1001. package/src/engine/graphics/texture/atlas/TextureAtlas.js +13 -14
  1002. package/src/engine/graphics/texture/atlas/gpu/WebGLTextureAtlas.d.ts.map +1 -1
  1003. package/src/engine/graphics/texture/atlas/gpu/WebGLTextureAtlas.js +49 -49
  1004. package/src/engine/graphics/texture/sampler/Sampler2D.d.ts +5 -5
  1005. package/src/engine/graphics/texture/sampler/Sampler2D.d.ts.map +1 -1
  1006. package/src/engine/graphics/texture/sampler/Sampler2D.js +6 -6
  1007. package/src/engine/graphics/trail/tube/TubeX.d.ts +6 -6
  1008. package/src/engine/graphics/trail/tube/TubeX.d.ts.map +1 -1
  1009. package/src/engine/graphics/trail/tube/TubeX.js +3 -3
  1010. package/src/engine/graphics/trail/x/RibbonX.d.ts.map +1 -1
  1011. package/src/engine/graphics/trail/x/RibbonX.js +36 -39
  1012. package/src/engine/grid/area/AreaTrigger.d.ts +1 -1
  1013. package/src/engine/grid/area/AreaTrigger.d.ts.map +1 -1
  1014. package/src/engine/grid/area/AreaTrigger.js +8 -7
  1015. package/src/engine/grid/area/TriggerAction.d.ts.map +1 -1
  1016. package/src/engine/grid/area/TriggerAction.js +2 -4
  1017. package/src/engine/grid/grid2transform/GridPosition2TransformSerializationUpgrader_0_1.d.ts.map +1 -1
  1018. package/src/engine/grid/grid2transform/GridPosition2TransformSerializationUpgrader_0_1.js +3 -6
  1019. package/src/engine/grid/grid2transform/GridPosition2TransformSystem.d.ts +3 -3
  1020. package/src/engine/grid/grid2transform/GridPosition2TransformSystem.d.ts.map +1 -1
  1021. package/src/engine/grid/grid2transform/GridPosition2TransformSystem.js +6 -9
  1022. package/src/engine/grid/position/GridPositionSerializationUpdater_0_1.d.ts.map +1 -1
  1023. package/src/engine/grid/position/GridPositionSerializationUpdater_0_1.js +2 -6
  1024. package/src/engine/grid/position/GridPositionSystem.d.ts.map +1 -1
  1025. package/src/engine/grid/position/GridPositionSystem.js +7 -11
  1026. package/src/engine/grid/transform2grid/Transform2GridPositionSystem.d.ts.map +1 -1
  1027. package/src/engine/grid/transform2grid/Transform2GridPositionSystem.js +32 -40
  1028. package/src/engine/input/devices/PointerDevice.d.ts +8 -0
  1029. package/src/engine/input/devices/PointerDevice.d.ts.map +1 -1
  1030. package/src/engine/input/devices/PointerDevice.js +10 -4
  1031. package/src/engine/input/ecs/systems/InputControllerSystem.d.ts.map +1 -1
  1032. package/src/engine/input/ecs/systems/InputControllerSystem.js +9 -13
  1033. package/src/engine/input/ecs/systems/InputSystem.d.ts +1 -1
  1034. package/src/engine/input/ecs/systems/InputSystem.d.ts.map +1 -1
  1035. package/src/engine/input/ecs/systems/InputSystem.js +8 -8
  1036. package/src/engine/intelligence/behavior/SelectorBehavior.d.ts.map +1 -1
  1037. package/src/engine/intelligence/behavior/SelectorBehavior.js +13 -17
  1038. package/src/engine/intelligence/behavior/composite/ParallelBehavior.d.ts +10 -10
  1039. package/src/engine/intelligence/behavior/composite/ParallelBehavior.d.ts.map +1 -1
  1040. package/src/engine/intelligence/behavior/composite/ParallelBehavior.js +12 -11
  1041. package/src/engine/intelligence/behavior/composite/ParallelBehaviorSerializationAdapter.d.ts.map +1 -1
  1042. package/src/engine/intelligence/behavior/composite/ParallelBehaviorSerializationAdapter.js +2 -6
  1043. package/src/engine/intelligence/behavior/composite/SequenceBehavior.d.ts.map +1 -1
  1044. package/src/engine/intelligence/behavior/composite/SequenceBehavior.js +19 -22
  1045. package/src/engine/intelligence/behavior/composite/SequenceBehaviorSerializationAdapter.d.ts.map +1 -1
  1046. package/src/engine/intelligence/behavior/composite/SequenceBehaviorSerializationAdapter.js +2 -6
  1047. package/src/engine/intelligence/behavior/decorator/AbstractDecoratorBehavior.d.ts.map +1 -1
  1048. package/src/engine/intelligence/behavior/decorator/AbstractDecoratorBehavior.js +6 -10
  1049. package/src/engine/intelligence/behavior/decorator/InvertStatusBehaviorSerializationAdapter.d.ts.map +1 -1
  1050. package/src/engine/intelligence/behavior/decorator/InvertStatusBehaviorSerializationAdapter.js +2 -6
  1051. package/src/engine/intelligence/behavior/decorator/RepeatBehavior.d.ts +5 -5
  1052. package/src/engine/intelligence/behavior/decorator/RepeatBehavior.d.ts.map +1 -1
  1053. package/src/engine/intelligence/behavior/decorator/RepeatBehavior.js +7 -7
  1054. package/src/engine/intelligence/behavior/decorator/RepeatBehaviorSerializationAdapter.d.ts.map +1 -1
  1055. package/src/engine/intelligence/behavior/decorator/RepeatBehaviorSerializationAdapter.js +2 -6
  1056. package/src/engine/intelligence/behavior/decorator/RepeatUntilSuccessBehavior.d.ts +2 -2
  1057. package/src/engine/intelligence/behavior/decorator/RepeatUntilSuccessBehavior.d.ts.map +1 -1
  1058. package/src/engine/intelligence/behavior/decorator/RepeatUntilSuccessBehavior.js +7 -7
  1059. package/src/engine/intelligence/behavior/ecs/BehaviorSystem.d.ts.map +1 -1
  1060. package/src/engine/intelligence/behavior/ecs/BehaviorSystem.js +3 -5
  1061. package/src/engine/intelligence/behavior/primitive/PromiseBehavior.d.ts +2 -2
  1062. package/src/engine/intelligence/behavior/primitive/PromiseBehavior.d.ts.map +1 -1
  1063. package/src/engine/intelligence/behavior/primitive/PromiseBehavior.js +3 -4
  1064. package/src/engine/intelligence/behavior/util/RotationBehavior.d.ts.map +1 -1
  1065. package/src/engine/intelligence/behavior/util/RotationBehavior.js +8 -13
  1066. package/src/engine/intelligence/blackboard/Blackboard.d.ts.map +1 -1
  1067. package/src/engine/intelligence/blackboard/Blackboard.js +14 -14
  1068. package/src/engine/intelligence/blackboard/BlackboardDynamicStorageAdapter.d.ts.map +1 -1
  1069. package/src/engine/intelligence/blackboard/BlackboardDynamicStorageAdapter.js +52 -55
  1070. package/src/engine/intelligence/blackboard/BlackboardStack.d.ts.map +1 -1
  1071. package/src/engine/intelligence/blackboard/BlackboardStack.js +12 -16
  1072. package/src/engine/intelligence/blackboard/BlackboardValue.d.ts.map +1 -1
  1073. package/src/engine/intelligence/blackboard/BlackboardValue.js +6 -5
  1074. package/src/engine/intelligence/controller/graph/StateGraph.d.ts +1 -1
  1075. package/src/engine/intelligence/controller/graph/StateGraph.d.ts.map +1 -1
  1076. package/src/engine/intelligence/controller/graph/StateGraph.js +2 -2
  1077. package/src/engine/intelligence/controller/graph/StateGraphDescription.js +6 -8
  1078. package/src/engine/intelligence/controller/graph/StateGraphSystem.d.ts.map +1 -1
  1079. package/src/engine/intelligence/controller/graph/StateGraphSystem.js +1 -5
  1080. package/src/engine/intelligence/mcts/MoveEdge.d.ts.map +1 -1
  1081. package/src/engine/intelligence/mcts/MoveEdge.js +5 -8
  1082. package/src/engine/intelligence/resource/ResourceAllocationBid.d.ts +5 -5
  1083. package/src/engine/intelligence/resource/ResourceAllocationBid.d.ts.map +1 -1
  1084. package/src/engine/intelligence/resource/ResourceAllocationBid.js +6 -6
  1085. package/src/engine/interpolation/InterpolationLog.d.ts.map +1 -1
  1086. package/src/engine/interpolation/InterpolationLog.js +564 -583
  1087. package/src/engine/interpolation/InterpolationSystem.d.ts.map +1 -1
  1088. package/src/engine/interpolation/InterpolationSystem.js +232 -233
  1089. package/src/engine/knowledge/database/StaticKnowledgeDataTableDescriptor.d.ts.map +1 -1
  1090. package/src/engine/knowledge/database/StaticKnowledgeDataTableDescriptor.js +17 -20
  1091. package/src/engine/logging/elastic/ElasticSearchLogger.d.ts +6 -6
  1092. package/src/engine/logging/elastic/ElasticSearchLogger.d.ts.map +1 -1
  1093. package/src/engine/logging/elastic/ElasticSearchLogger.js +31 -32
  1094. package/src/engine/metrics/ProxyMetricsGateway.d.ts.map +1 -1
  1095. package/src/engine/metrics/ProxyMetricsGateway.js +5 -9
  1096. package/src/engine/navigation/ecs/components/Path.d.ts.map +1 -1
  1097. package/src/engine/navigation/ecs/components/Path.js +30 -32
  1098. package/src/engine/navigation/ecs/components/PathSerializationUpgrader_0_1.d.ts.map +1 -1
  1099. package/src/engine/navigation/ecs/components/PathSerializationUpgrader_0_1.js +2 -6
  1100. package/src/engine/navigation/ecs/components/PathSerializationUpgrader_1_2.d.ts.map +1 -1
  1101. package/src/engine/navigation/ecs/components/PathSerializationUpgrader_1_2.js +2 -6
  1102. package/src/engine/navigation/ecs/components/PathSerializationUpgrader_2_3.d.ts.map +1 -1
  1103. package/src/engine/navigation/ecs/components/PathSerializationUpgrader_2_3.js +34 -38
  1104. package/src/engine/navigation/ecs/path_following/PathFollowerSerializationUpgrader_0_1.d.ts.map +1 -1
  1105. package/src/engine/navigation/ecs/path_following/PathFollowerSerializationUpgrader_0_1.js +2 -6
  1106. package/src/engine/navigation/ecs/path_following/PathFollowerSerializationUpgrader_1_2.d.ts.map +1 -1
  1107. package/src/engine/navigation/ecs/path_following/PathFollowerSerializationUpgrader_1_2.js +2 -6
  1108. package/src/engine/navigation/ecs/path_following/PathFollowingSystem.d.ts.map +1 -1
  1109. package/src/engine/navigation/ecs/path_following/PathFollowingSystem.js +12 -17
  1110. package/src/engine/network/NetworkSession.d.ts.map +1 -1
  1111. package/src/engine/network/NetworkSession.js +2037 -2036
  1112. package/src/engine/network/PriorityFetch.d.ts +6 -6
  1113. package/src/engine/network/PriorityFetch.d.ts.map +1 -1
  1114. package/src/engine/network/PriorityFetch.js +14 -14
  1115. package/src/engine/network/diagnostics/BandwidthMeter.d.ts.map +1 -1
  1116. package/src/engine/network/diagnostics/BandwidthMeter.js +150 -155
  1117. package/src/engine/network/diagnostics/ReplayLog.d.ts +2 -2
  1118. package/src/engine/network/diagnostics/ReplayLog.d.ts.map +1 -1
  1119. package/src/engine/network/diagnostics/ReplayLog.js +132 -137
  1120. package/src/engine/network/diagnostics/SyncTest.d.ts.map +1 -1
  1121. package/src/engine/network/diagnostics/SyncTest.js +146 -151
  1122. package/src/engine/network/orchestrator/NetworkPeer.d.ts.map +1 -1
  1123. package/src/engine/network/orchestrator/NetworkPeer.js +1202 -1209
  1124. package/src/engine/network/orchestrator/ServerAuthoritativeClient.d.ts +4 -4
  1125. package/src/engine/network/orchestrator/ServerAuthoritativeClient.d.ts.map +1 -1
  1126. package/src/engine/network/orchestrator/ServerAuthoritativeClient.js +8 -10
  1127. package/src/engine/network/orchestrator/ServerAuthoritativeServer.d.ts +7 -7
  1128. package/src/engine/network/orchestrator/ServerAuthoritativeServer.d.ts.map +1 -1
  1129. package/src/engine/network/orchestrator/ServerAuthoritativeServer.js +643 -654
  1130. package/src/engine/network/replication/Replicator.d.ts +24 -24
  1131. package/src/engine/network/replication/Replicator.d.ts.map +1 -1
  1132. package/src/engine/network/replication/Replicator.js +405 -410
  1133. package/src/engine/network/sim/ReplicatedComponentRegistry.d.ts.map +1 -1
  1134. package/src/engine/network/sim/ReplicatedComponentRegistry.js +133 -140
  1135. package/src/engine/network/sim/RewindEngine.d.ts.map +1 -1
  1136. package/src/engine/network/sim/RewindEngine.js +179 -182
  1137. package/src/engine/network/sim/SimActionExecutor.d.ts +34 -34
  1138. package/src/engine/network/sim/SimActionExecutor.d.ts.map +1 -1
  1139. package/src/engine/network/sim/SimActionExecutor.js +305 -306
  1140. package/src/engine/network/sim/SimActionRegistry.d.ts.map +1 -1
  1141. package/src/engine/network/sim/SimActionRegistry.js +121 -128
  1142. package/src/engine/network/sim/SmoothingState.d.ts.map +1 -1
  1143. package/src/engine/network/sim/SmoothingState.js +220 -222
  1144. package/src/engine/network/sim/SpeculationLog.d.ts.map +1 -1
  1145. package/src/engine/network/sim/SpeculationLog.js +79 -84
  1146. package/src/engine/network/state/Baseline.d.ts.map +1 -1
  1147. package/src/engine/network/state/Baseline.js +78 -83
  1148. package/src/engine/network/state/ChangedEntitySet.d.ts.map +1 -1
  1149. package/src/engine/network/state/ChangedEntitySet.js +253 -256
  1150. package/src/engine/network/state/MutationLedger.d.ts.map +1 -1
  1151. package/src/engine/network/state/MutationLedger.js +179 -182
  1152. package/src/engine/network/state/ReplicationSlotTable.d.ts.map +1 -1
  1153. package/src/engine/network/state/ReplicationSlotTable.js +206 -211
  1154. package/src/engine/network/time/AdaptiveRenderDelay.d.ts.map +1 -1
  1155. package/src/engine/network/time/AdaptiveRenderDelay.js +250 -258
  1156. package/src/engine/network/time/JitterBuffer.d.ts.map +1 -1
  1157. package/src/engine/network/time/JitterBuffer.js +113 -116
  1158. package/src/engine/network/time/TimeSync.d.ts.map +1 -1
  1159. package/src/engine/network/time/TimeSync.js +145 -152
  1160. package/src/engine/network/transport/LoopbackTransport.d.ts.map +1 -1
  1161. package/src/engine/network/transport/LoopbackTransport.js +165 -173
  1162. package/src/engine/network/transport/ReliableCommandPipeline.d.ts.map +1 -1
  1163. package/src/engine/network/transport/ReliableCommandPipeline.js +315 -320
  1164. package/src/engine/network/transport/adapters/SimulatedTransport.d.ts.map +1 -1
  1165. package/src/engine/network/transport/adapters/SimulatedTransport.js +235 -241
  1166. package/src/engine/network/transport/adapters/WebSocketTransport.d.ts.map +1 -1
  1167. package/src/engine/network/transport/adapters/WebSocketTransport.js +154 -154
  1168. package/src/engine/network/transport/adapters/WebTransportTransport.d.ts.map +1 -1
  1169. package/src/engine/network/transport/adapters/WebTransportTransport.js +195 -199
  1170. package/src/engine/network/transport/fragments/FragmentAssembler.d.ts.map +1 -1
  1171. package/src/engine/network/transport/fragments/FragmentAssembler.js +286 -291
  1172. package/src/engine/network/transport/fragments/FragmentRetention.d.ts.map +1 -1
  1173. package/src/engine/network/transport/fragments/FragmentRetention.js +191 -194
  1174. package/src/engine/physics/body/BodyStorage.d.ts +2 -2
  1175. package/src/engine/physics/body/BodyStorage.d.ts.map +1 -1
  1176. package/src/engine/physics/body/BodyStorage.js +406 -406
  1177. package/src/engine/physics/body/SolverBodyState.d.ts +8 -8
  1178. package/src/engine/physics/body/SolverBodyState.d.ts.map +1 -1
  1179. package/src/engine/physics/body/SolverBodyState.js +10 -10
  1180. package/src/engine/physics/broadphase/PairList.d.ts +1 -1
  1181. package/src/engine/physics/broadphase/PairList.d.ts.map +1 -1
  1182. package/src/engine/physics/broadphase/PairList.js +98 -97
  1183. package/src/engine/physics/contact/ManifoldStore.d.ts +2 -2
  1184. package/src/engine/physics/contact/ManifoldStore.d.ts.map +1 -1
  1185. package/src/engine/physics/contact/ManifoldStore.js +3 -4
  1186. package/src/engine/physics/ecs/ColliderObserverSystem.d.ts +2 -2
  1187. package/src/engine/physics/ecs/ColliderObserverSystem.d.ts.map +1 -1
  1188. package/src/engine/physics/ecs/ColliderObserverSystem.js +102 -103
  1189. package/src/engine/physics/ecs/PhysicsSystem.d.ts +2 -2
  1190. package/src/engine/physics/ecs/PhysicsSystem.d.ts.map +1 -1
  1191. package/src/engine/physics/ecs/PhysicsSystem.js +248 -249
  1192. package/src/engine/physics/events/ContactEventBuffer.d.ts +1 -1
  1193. package/src/engine/physics/events/ContactEventBuffer.d.ts.map +1 -1
  1194. package/src/engine/physics/events/ContactEventBuffer.js +2 -1
  1195. package/src/engine/physics/fluid/FluidField.d.ts +54 -0
  1196. package/src/engine/physics/fluid/FluidField.d.ts.map +1 -1
  1197. package/src/engine/physics/fluid/FluidField.js +198 -15
  1198. package/src/engine/physics/fluid/FluidSimulator.d.ts.map +1 -1
  1199. package/src/engine/physics/fluid/FluidSimulator.js +14 -4
  1200. package/src/engine/physics/fluid/ecs/FluidObstacleSystem.d.ts +4 -4
  1201. package/src/engine/physics/fluid/ecs/FluidSystem.d.ts +0 -45
  1202. package/src/engine/physics/fluid/ecs/FluidSystem.d.ts.map +1 -1
  1203. package/src/engine/physics/fluid/ecs/FluidSystem.js +8 -144
  1204. package/src/engine/physics/fluid/ecs/FluidWorkerCore.d.ts +43 -0
  1205. package/src/engine/physics/fluid/ecs/FluidWorkerCore.d.ts.map +1 -0
  1206. package/src/engine/physics/fluid/ecs/FluidWorkerCore.js +123 -0
  1207. package/src/engine/physics/fluid/ecs/WorkerFluidSystem.d.ts +119 -0
  1208. package/src/engine/physics/fluid/ecs/WorkerFluidSystem.d.ts.map +1 -0
  1209. package/src/engine/physics/fluid/ecs/WorkerFluidSystem.js +395 -0
  1210. package/src/engine/physics/fluid/ecs/fluid.worker.d.ts +2 -0
  1211. package/src/engine/physics/fluid/ecs/fluid.worker.d.ts.map +1 -0
  1212. package/src/engine/physics/fluid/ecs/fluid.worker.js +12 -0
  1213. package/src/engine/physics/fluid/ecs/fluid_build_world_to_grid.d.ts +20 -0
  1214. package/src/engine/physics/fluid/ecs/fluid_build_world_to_grid.d.ts.map +1 -0
  1215. package/src/engine/physics/fluid/ecs/fluid_build_world_to_grid.js +32 -0
  1216. package/src/engine/physics/fluid/ecs/fluid_gather_visible_effectors.d.ts +22 -0
  1217. package/src/engine/physics/fluid/ecs/fluid_gather_visible_effectors.d.ts.map +1 -0
  1218. package/src/engine/physics/fluid/ecs/fluid_gather_visible_effectors.js +47 -0
  1219. package/src/engine/physics/fluid/ecs/fluid_reanchor_field.d.ts +28 -0
  1220. package/src/engine/physics/fluid/ecs/fluid_reanchor_field.d.ts.map +1 -0
  1221. package/src/engine/physics/fluid/ecs/fluid_reanchor_field.js +85 -0
  1222. package/src/engine/physics/fluid/ecs/fluid_sync_effectors_from_transform.d.ts +11 -0
  1223. package/src/engine/physics/fluid/ecs/fluid_sync_effectors_from_transform.d.ts.map +1 -0
  1224. package/src/engine/physics/fluid/ecs/fluid_sync_effectors_from_transform.js +16 -0
  1225. package/src/engine/physics/fluid/ecs/fluid_worker_protocol.d.ts +51 -0
  1226. package/src/engine/physics/fluid/ecs/fluid_worker_protocol.d.ts.map +1 -0
  1227. package/src/engine/physics/fluid/ecs/fluid_worker_protocol.js +111 -0
  1228. package/src/engine/physics/fluid/ecs/makeFluidWorker.d.ts +17 -0
  1229. package/src/engine/physics/fluid/ecs/makeFluidWorker.d.ts.map +1 -0
  1230. package/src/engine/physics/fluid/ecs/makeFluidWorker.js +18 -0
  1231. package/src/engine/physics/island/IslandBuilder.d.ts.map +1 -1
  1232. package/src/engine/physics/island/IslandBuilder.js +84 -86
  1233. package/src/engine/physics/mls-mpm/MLS_MPM.d.ts.map +1 -1
  1234. package/src/engine/physics/mls-mpm/MLS_MPM.js +24 -26
  1235. package/src/engine/physics/queries/PhysicsSurfacePoint.d.ts.map +1 -1
  1236. package/src/engine/physics/queries/PhysicsSurfacePoint.js +98 -100
  1237. package/src/engine/physics/vehicle/RaycastVehicle.d.ts +6 -6
  1238. package/src/engine/physics/vehicle/RaycastVehicle.d.ts.map +1 -1
  1239. package/src/engine/physics/vehicle/RaycastVehicle.js +357 -344
  1240. package/src/engine/plugin/PluginReferenceContext.d.ts +12 -12
  1241. package/src/engine/plugin/PluginReferenceContext.d.ts.map +1 -1
  1242. package/src/engine/plugin/PluginReferenceContext.js +24 -25
  1243. package/src/engine/scene/Scene.d.ts +5 -5
  1244. package/src/engine/scene/Scene.d.ts.map +1 -1
  1245. package/src/engine/scene/Scene.js +24 -23
  1246. package/src/engine/scene/SceneManager.d.ts +5 -5
  1247. package/src/engine/scene/SceneManager.d.ts.map +1 -1
  1248. package/src/engine/scene/SceneManager.js +13 -14
  1249. package/src/engine/sound/SoundEngine.d.ts +2 -2
  1250. package/src/engine/sound/SoundEngine.d.ts.map +1 -1
  1251. package/src/engine/sound/SoundEngine.js +7 -8
  1252. package/src/engine/sound/asset/SoundAssetPlaybackSpec.d.ts.map +1 -1
  1253. package/src/engine/sound/asset/SoundAssetPlaybackSpec.js +16 -20
  1254. package/src/engine/sound/ecs/SoundController.d.ts.map +1 -1
  1255. package/src/engine/sound/ecs/SoundController.js +37 -33
  1256. package/src/engine/sound/ecs/SoundControllerSystem.d.ts.map +1 -1
  1257. package/src/engine/sound/ecs/SoundControllerSystem.js +5 -11
  1258. package/src/engine/sound/ecs/SoundListener.d.ts.map +1 -1
  1259. package/src/engine/sound/ecs/SoundListener.js +4 -6
  1260. package/src/engine/sound/ecs/SoundListenerSystem.d.ts +6 -6
  1261. package/src/engine/sound/ecs/SoundListenerSystem.d.ts.map +1 -1
  1262. package/src/engine/sound/ecs/SoundListenerSystem.js +22 -23
  1263. package/src/engine/sound/ecs/audio/AudioEmitter.d.ts +10 -4
  1264. package/src/engine/sound/ecs/audio/AudioEmitter.d.ts.map +1 -1
  1265. package/src/engine/sound/ecs/audio/AudioEmitter.js +131 -122
  1266. package/src/engine/sound/ecs/audio/AudioEmitterSerializationAdapter.d.ts +34 -0
  1267. package/src/engine/sound/ecs/audio/AudioEmitterSerializationAdapter.d.ts.map +1 -0
  1268. package/src/engine/sound/ecs/audio/AudioEmitterSerializationAdapter.js +68 -0
  1269. package/src/engine/sound/ecs/audio/AudioEmitterSystem.d.ts +6 -6
  1270. package/src/engine/sound/ecs/audio/AudioEmitterSystem.d.ts.map +1 -1
  1271. package/src/engine/sound/ecs/audio/AudioEmitterSystem.js +314 -316
  1272. package/src/engine/sound/ecs/emitter/SoundEmitterComponentContext.d.ts.map +1 -1
  1273. package/src/engine/sound/ecs/emitter/SoundEmitterComponentContext.js +31 -1
  1274. package/src/engine/sound/ecs/emitter/SoundEmitterSerializationUpgrader_0_1.d.ts.map +1 -1
  1275. package/src/engine/sound/ecs/emitter/SoundEmitterSerializationUpgrader_0_1.js +2 -6
  1276. package/src/engine/sound/ecs/emitter/SoundEmitterSerializationUpgrader_1_2.d.ts.map +1 -1
  1277. package/src/engine/sound/ecs/emitter/SoundEmitterSerializationUpgrader_1_2.js +2 -6
  1278. package/src/engine/sound/ecs/emitter/SoundEmitterSystem.d.ts +5 -5
  1279. package/src/engine/sound/ecs/emitter/SoundEmitterSystem.d.ts.map +1 -1
  1280. package/src/engine/sound/ecs/emitter/SoundEmitterSystem.js +159 -159
  1281. package/src/engine/sound/material/concrete/RandomSoundMaterial.d.ts.map +1 -1
  1282. package/src/engine/sound/material/concrete/RandomSoundMaterial.js +5 -9
  1283. package/src/engine/sound/material/concrete/SingleSoundMaterial.d.ts.map +1 -1
  1284. package/src/engine/sound/material/concrete/SingleSoundMaterial.js +1 -6
  1285. package/src/engine/sound/material/concrete/SoundMaterialComposition.d.ts.map +1 -1
  1286. package/src/engine/sound/material/concrete/SoundMaterialComposition.js +18 -21
  1287. package/src/engine/sound/material/detector/terrain/TerrainSoundMaterialSurfaceDetector.d.ts.map +1 -1
  1288. package/src/engine/sound/material/detector/terrain/TerrainSoundMaterialSurfaceDetector.js +13 -15
  1289. package/src/engine/sound/simulation/core/OccluderBody.d.ts +12 -12
  1290. package/src/engine/sound/simulation/core/OccluderBody.d.ts.map +1 -1
  1291. package/src/engine/sound/simulation/core/OccluderBody.js +74 -74
  1292. package/src/engine/sound/simulation/prototypeAcousticSolver.js +5 -4
  1293. package/src/engine/sound/sopra/definition/SopraPanningModel.d.ts +7 -3
  1294. package/src/engine/sound/sopra/definition/SopraPanningModel.d.ts.map +1 -1
  1295. package/src/engine/sound/sopra/definition/SopraPanningModel.js +34 -20
  1296. package/src/engine/sound/sopra/legacy/soundEmitterToEventDescription.d.ts +15 -0
  1297. package/src/engine/sound/sopra/legacy/soundEmitterToEventDescription.d.ts.map +1 -1
  1298. package/src/engine/sound/sopra/legacy/soundEmitterToEventDescription.js +122 -106
  1299. package/src/engine/sound/sopra/runtime/EventInstance.d.ts.map +1 -1
  1300. package/src/engine/sound/sopra/runtime/EventInstance.js +852 -815
  1301. package/src/engine/sound/sopra/util/buildAttenuationCurve.d.ts +20 -6
  1302. package/src/engine/sound/sopra/util/buildAttenuationCurve.d.ts.map +1 -1
  1303. package/src/engine/sound/sopra/util/buildAttenuationCurve.js +56 -21
  1304. package/src/engine/ui/bindings/DomElementBinding.d.ts.map +1 -1
  1305. package/src/engine/ui/bindings/DomElementBinding.js +15 -18
  1306. package/src/engine/ui/bindings/DomElementBindingDescription.d.ts.map +1 -1
  1307. package/src/engine/ui/bindings/DomElementBindingDescription.js +10 -14
  1308. package/src/engine/ui/bindings/DomElementProcessor.d.ts.map +1 -1
  1309. package/src/engine/ui/bindings/DomElementProcessor.js +5 -7
  1310. package/src/engine/ui/bindings/DomElementProcessorManager.d.ts.map +1 -1
  1311. package/src/engine/ui/bindings/DomElementProcessorManager.js +26 -26
  1312. package/src/engine/ui/bindings/processors/DomElementProcessorTilt3D.d.ts.map +1 -1
  1313. package/src/engine/ui/bindings/processors/DomElementProcessorTilt3D.js +15 -19
  1314. package/src/engine/ui/cursor/CursorCoalescence.d.ts.map +1 -1
  1315. package/src/engine/ui/cursor/CursorCoalescence.js +11 -14
  1316. package/src/engine/ui/modal/ModalStack.d.ts.map +1 -1
  1317. package/src/engine/ui/modal/ModalStack.js +19 -22
  1318. package/src/engine/ui/notification/AnimatedObjectEmitter.d.ts +4 -4
  1319. package/src/engine/ui/notification/AnimatedObjectEmitter.d.ts.map +1 -1
  1320. package/src/engine/ui/notification/AnimatedObjectEmitter.js +68 -70
  1321. package/src/engine/ui/notification/NotificationManager.d.ts +4 -4
  1322. package/src/engine/ui/notification/NotificationManager.d.ts.map +1 -1
  1323. package/src/engine/ui/notification/NotificationManager.js +27 -29
  1324. package/src/engine/ui/notification/ViewEmitter.d.ts.map +1 -1
  1325. package/src/engine/ui/notification/ViewEmitter.js +2 -2
  1326. package/src/engine/ui/scene/SceneGUIContext.d.ts.map +1 -1
  1327. package/src/engine/ui/scene/SceneGUIContext.js +20 -22
  1328. package/src/engine/ui/tiles2d/TileMoveProgram.d.ts.map +1 -1
  1329. package/src/engine/ui/tiles2d/TileMoveProgram.js +5 -7
  1330. package/src/generation/GraphGenerationRule.d.ts.map +1 -1
  1331. package/src/generation/GraphGenerationRule.js +10 -14
  1332. package/src/generation/GridGeneratorConfig.d.ts.map +1 -1
  1333. package/src/generation/GridGeneratorConfig.js +15 -19
  1334. package/src/generation/filtering/CellFilterCellMatcher.d.ts.map +1 -1
  1335. package/src/generation/filtering/CellFilterCellMatcher.js +5 -9
  1336. package/src/generation/filtering/numeric/complex/CellFilterAngleToNormal.d.ts.map +1 -1
  1337. package/src/generation/filtering/numeric/complex/CellFilterAngleToNormal.js +11 -15
  1338. package/src/generation/grid/actions/ContinuousGridCellActionSetTerrainObstacle.d.ts.map +1 -1
  1339. package/src/generation/grid/actions/ContinuousGridCellActionSetTerrainObstacle.js +11 -15
  1340. package/src/generation/grid/actions/ContinuousGridCellActionWriteObstacle.d.ts +10 -10
  1341. package/src/generation/grid/actions/ContinuousGridCellActionWriteObstacle.d.ts.map +1 -1
  1342. package/src/generation/grid/actions/ContinuousGridCellActionWriteObstacle.js +20 -19
  1343. package/src/generation/markers/matcher/MarkerNodeMatcherByType.d.ts.map +1 -1
  1344. package/src/generation/markers/matcher/MarkerNodeMatcherByType.js +5 -9
  1345. package/src/generation/placement/action/random/CellActionSelectRandom.d.ts.map +1 -1
  1346. package/src/generation/placement/action/random/CellActionSelectRandom.js +11 -16
  1347. package/src/view/ViewGroup.d.ts.map +1 -1
  1348. package/src/view/ViewGroup.js +11 -14
  1349. package/src/view/common/HTMLElementCacheKey.d.ts.map +1 -1
  1350. package/src/view/common/HTMLElementCacheKey.js +21 -24
  1351. package/src/view/common/TabbedView.d.ts +56 -26
  1352. package/src/view/common/TabbedView.d.ts.map +1 -1
  1353. package/src/view/common/TabbedView.js +128 -30
  1354. package/src/view/common/dnd/DragAndDropContext.d.ts.map +1 -1
  1355. package/src/view/common/dnd/DragAndDropContext.js +11 -12
  1356. package/src/view/common/dnd/Draggable.d.ts +5 -5
  1357. package/src/view/common/dnd/Draggable.d.ts.map +1 -1
  1358. package/src/view/common/dnd/Draggable.js +6 -6
  1359. package/src/view/controller/GuiController.d.ts +1 -1
  1360. package/src/view/controller/GuiController.d.ts.map +1 -1
  1361. package/src/view/controller/GuiController.js +3 -3
  1362. package/src/view/controller/controls/BooleanVector3Control.d.ts.map +1 -1
  1363. package/src/view/controller/controls/BooleanVector3Control.js +2 -2
  1364. package/src/view/controller/controls/NumericIntervalControl.d.ts +1 -1
  1365. package/src/view/controller/controls/NumericIntervalControl.d.ts.map +1 -1
  1366. package/src/view/controller/controls/NumericIntervalControl.js +90 -90
  1367. package/src/view/controller/controls/Vector2Control.d.ts +1 -1
  1368. package/src/view/controller/controls/Vector2Control.d.ts.map +1 -1
  1369. package/src/view/controller/controls/Vector2Control.js +83 -83
  1370. package/src/view/controller/controls/Vector3Control.d.ts +1 -1
  1371. package/src/view/controller/controls/Vector3Control.d.ts.map +1 -1
  1372. package/src/view/controller/controls/Vector3Control.js +90 -90
  1373. package/{editor/view/ecs/components → src/view/controller/dat}/DatGuiController.d.ts +45 -45
  1374. package/src/view/controller/dat/DatGuiController.d.ts.map +1 -0
  1375. package/src/view/controller/dat/DatGuiController.js +216 -0
  1376. package/src/view/currency/CompositeCurrencyLabelView.d.ts.map +1 -1
  1377. package/src/view/currency/CompositeCurrencyLabelView.js +2 -2
  1378. package/src/view/currency/CurrencyDenominationLabelView.d.ts.map +1 -1
  1379. package/src/view/currency/CurrencyDenominationLabelView.js +2 -3
  1380. package/src/view/currency/CurrencyDenominationSpec.d.ts.map +1 -1
  1381. package/src/view/currency/CurrencyDenominationSpec.js +11 -12
  1382. package/src/view/currency/CurrencyDisplaySpec.d.ts.map +1 -1
  1383. package/src/view/currency/CurrencyDisplaySpec.js +5 -9
  1384. package/src/view/elements/ColorPickerView.js +1 -1
  1385. package/src/view/elements/EmptyView.js +1 -1
  1386. package/src/view/elements/MeshPreview.d.ts +1 -1
  1387. package/src/view/elements/MeshPreview.d.ts.map +1 -1
  1388. package/src/view/elements/MeshPreview.js +4 -10
  1389. package/{editor/view/ecs/components/particles/ColorParameterLUTController.d.ts → src/view/elements/drawCheckers.d.ts} +13 -14
  1390. package/src/view/elements/drawCheckers.d.ts.map +1 -0
  1391. package/src/view/elements/drawCheckers.js +33 -0
  1392. package/src/view/elements/progress/segmented/SegmentDefinition.d.ts.map +1 -1
  1393. package/src/view/elements/progress/segmented/SegmentDefinition.js +1 -3
  1394. package/src/view/elements/radial/RadialMenu.d.ts.map +1 -1
  1395. package/src/view/elements/radial/RadialMenu.js +18 -19
  1396. package/src/view/elements/radial/RadialMenuElementDefinition.d.ts.map +1 -1
  1397. package/src/view/elements/radial/RadialMenuElementDefinition.js +95 -87
  1398. package/src/view/elements/radial/RadialText.d.ts +3 -3
  1399. package/src/view/elements/radial/RadialText.d.ts.map +1 -1
  1400. package/src/view/elements/radial/RadialText.js +19 -22
  1401. package/src/view/elements/tiles2d/Tile.d.ts +1 -1
  1402. package/src/view/elements/tiles2d/Tile.d.ts.map +1 -1
  1403. package/src/view/elements/tiles2d/Tile.js +2 -2
  1404. package/src/view/elements/tiles2d/TileGrid.d.ts.map +1 -1
  1405. package/src/view/elements/tiles2d/TileGrid.js +1 -4
  1406. package/src/view/game/achievements/AchievementNotificationView.d.ts.map +1 -1
  1407. package/src/view/game/achievements/AchievementNotificationView.js +2 -3
  1408. package/src/view/interaction/InteractionCommandSet.d.ts.map +1 -1
  1409. package/src/view/interaction/InteractionCommandSet.js +5 -7
  1410. package/src/view/layout/DockDragOverlayView.d.ts +24 -0
  1411. package/src/view/layout/DockDragOverlayView.d.ts.map +1 -0
  1412. package/src/view/layout/DockDragOverlayView.js +63 -0
  1413. package/src/view/layout/DockDropPlan.d.ts +46 -0
  1414. package/src/view/layout/DockDropPlan.d.ts.map +1 -0
  1415. package/src/view/layout/DockDropPlan.js +53 -0
  1416. package/src/view/layout/DockGroupNode.d.ts +29 -0
  1417. package/src/view/layout/DockGroupNode.d.ts.map +1 -0
  1418. package/src/view/layout/DockGroupNode.js +38 -0
  1419. package/src/view/layout/DockLayoutView.d.ts +125 -0
  1420. package/src/view/layout/DockLayoutView.d.ts.map +1 -0
  1421. package/src/view/layout/DockLayoutView.js +1193 -0
  1422. package/src/view/layout/DockPanel.d.ts +38 -0
  1423. package/src/view/layout/DockPanel.d.ts.map +1 -0
  1424. package/src/view/layout/DockPanel.js +51 -0
  1425. package/src/view/layout/DockSide.d.ts +48 -0
  1426. package/src/view/layout/DockSide.d.ts.map +1 -0
  1427. package/src/view/layout/DockSide.js +88 -0
  1428. package/src/view/layout/DockSplitNode.d.ts +59 -0
  1429. package/src/view/layout/DockSplitNode.d.ts.map +1 -0
  1430. package/src/view/layout/DockSplitNode.js +78 -0
  1431. package/src/view/layout/DrawerView.d.ts +53 -0
  1432. package/src/view/layout/DrawerView.d.ts.map +1 -0
  1433. package/src/view/layout/DrawerView.js +163 -0
  1434. package/src/view/layout/FloatingPanelView.d.ts +38 -0
  1435. package/src/view/layout/FloatingPanelView.d.ts.map +1 -0
  1436. package/src/view/layout/FloatingPanelView.js +251 -0
  1437. package/src/view/layout/SplitView.d.ts +73 -0
  1438. package/src/view/layout/SplitView.d.ts.map +1 -0
  1439. package/src/view/layout/SplitView.js +365 -0
  1440. package/src/view/layout/layout.scss +236 -0
  1441. package/src/view/layout/show_popup_menu.d.ts +19 -0
  1442. package/src/view/layout/show_popup_menu.d.ts.map +1 -0
  1443. package/src/view/layout/show_popup_menu.js +81 -0
  1444. package/src/view/minimap/Minimap.d.ts.map +1 -1
  1445. package/src/view/minimap/Minimap.js +2 -6
  1446. package/src/view/minimap/dom/MinimapMarkerView.d.ts.map +1 -1
  1447. package/src/view/minimap/dom/MinimapMarkerView.js +2 -3
  1448. package/src/view/minimap/gl/MarkerGL.d.ts +6 -6
  1449. package/src/view/minimap/gl/MarkerGL.d.ts.map +1 -1
  1450. package/src/view/minimap/gl/MarkerGL.js +8 -9
  1451. package/src/view/minimap/gl/MinimapFogOfWar.d.ts +7 -7
  1452. package/src/view/minimap/gl/MinimapFogOfWar.d.ts.map +1 -1
  1453. package/src/view/minimap/gl/MinimapFogOfWar.js +10 -12
  1454. package/src/view/minimap/gl/MinimapWorldGL.d.ts +15 -15
  1455. package/src/view/minimap/gl/MinimapWorldGL.d.ts.map +1 -1
  1456. package/src/view/minimap/gl/MinimapWorldGL.js +18 -16
  1457. package/src/view/minimap/gl/MinimapWorldLayer.d.ts.map +1 -1
  1458. package/src/view/minimap/gl/MinimapWorldLayer.js +4 -8
  1459. package/src/view/tooltip/DomTooltipManager.d.ts +6 -6
  1460. package/src/view/tooltip/DomTooltipManager.d.ts.map +1 -1
  1461. package/src/view/tooltip/DomTooltipManager.js +21 -22
  1462. package/src/view/tooltip/TooltipManager.d.ts.map +1 -1
  1463. package/src/view/tooltip/TooltipManager.js +6 -8
  1464. package/src/view/tooltip/TooltipView.d.ts +1 -1
  1465. package/src/view/tooltip/TooltipView.d.ts.map +1 -1
  1466. package/src/view/tooltip/TooltipView.js +3 -4
  1467. package/src/view/tooltip/VisualTip.d.ts +5 -5
  1468. package/src/view/tooltip/VisualTip.d.ts.map +1 -1
  1469. package/src/view/tooltip/VisualTip.js +6 -7
  1470. package/src/view/tooltip/gml/GMLEngine.d.ts.map +1 -1
  1471. package/src/view/tooltip/gml/GMLEngine.js +57 -63
  1472. package/src/view/util/DomSizeObserver.d.ts +6 -6
  1473. package/src/view/util/DomSizeObserver.d.ts.map +1 -1
  1474. package/src/view/util/DomSizeObserver.js +27 -20
  1475. package/editor/actions/concrete/PatchTerrainTextureAction.js +0 -153
  1476. package/editor/ecs/component/editors/ecs/MinimapMarkerEditor.d.ts +0 -14
  1477. package/editor/ecs/component/editors/ecs/MinimapMarkerEditor.d.ts.map +0 -1
  1478. package/editor/process/symbolic/makeStoryTriggerSetAreaDisplay.js +0 -114
  1479. package/editor/tools/TopDownCameraControlTool.d.ts +0 -13
  1480. package/editor/tools/TopDownCameraControlTool.d.ts.map +0 -1
  1481. package/editor/tools/TopDownCameraControlTool.js +0 -56
  1482. package/editor/tools/TransformTool.js +0 -385
  1483. package/editor/tools/paint/prototypeTerrainEditor.js +0 -135
  1484. package/editor/view/EditorView.d.ts +0 -39
  1485. package/editor/view/EditorView.d.ts.map +0 -1
  1486. package/editor/view/EditorView.js +0 -304
  1487. package/editor/view/ecs/ComponentControlFactory.d.ts +0 -19
  1488. package/editor/view/ecs/ComponentControlFactory.d.ts.map +0 -1
  1489. package/editor/view/ecs/ComponentControlFactory.js +0 -45
  1490. package/editor/view/ecs/EntityList.d.ts +0 -22
  1491. package/editor/view/ecs/EntityList.d.ts.map +0 -1
  1492. package/editor/view/ecs/HierarchicalEntityListView.module.scss +0 -13
  1493. package/editor/view/ecs/components/BlackboardController.js +0 -50
  1494. package/editor/view/ecs/components/DatGuiController.d.ts.map +0 -1
  1495. package/editor/view/ecs/components/FogOfWarController.js +0 -78
  1496. package/editor/view/ecs/components/FogOfWarRevealerController.js +0 -44
  1497. package/editor/view/ecs/components/GeneratedArmyController.js +0 -42
  1498. package/editor/view/ecs/components/GridObstacleController.d.ts +0 -14
  1499. package/editor/view/ecs/components/GridObstacleController.d.ts.map +0 -1
  1500. package/editor/view/ecs/components/GridObstacleController.js +0 -72
  1501. package/editor/view/ecs/components/GridPositionController.js +0 -40
  1502. package/editor/view/ecs/components/HeadsUpDisplayController.js +0 -30
  1503. package/editor/view/ecs/components/HighlightController.js +0 -47
  1504. package/editor/view/ecs/components/MeshController.js +0 -122
  1505. package/editor/view/ecs/components/PathFollowerController.js +0 -87
  1506. package/editor/view/ecs/components/TagController.js +0 -80
  1507. package/editor/view/ecs/components/TerrainController.js +0 -215
  1508. package/editor/view/ecs/components/TransformController.js +0 -97
  1509. package/editor/view/ecs/components/UnitShopController.js +0 -112
  1510. package/editor/view/ecs/components/army/ArmyController.js +0 -130
  1511. package/editor/view/ecs/components/gui/GUIElementController.js +0 -117
  1512. package/editor/view/ecs/components/items/ItemContainerController.js +0 -132
  1513. package/editor/view/ecs/components/items/ItemContainerController.stories.js +0 -50
  1514. package/editor/view/ecs/components/items/ItemController.js +0 -52
  1515. package/editor/view/ecs/components/particles/ColorParameterLUTController.d.ts.map +0 -1
  1516. package/editor/view/ecs/components/particles/ColorParameterLUTController.js +0 -444
  1517. package/editor/view/ecs/components/particles/ParameterTrackController.js +0 -51
  1518. package/editor/view/ecs/components/particles/ParticleEmitterController.js +0 -213
  1519. package/editor/view/ecs/components/particles/ParticleLayerController.js +0 -213
  1520. package/editor/view/ecs/components/particles/ScalarParameterLUTController.js +0 -401
  1521. package/editor/view/ecs/components/sockets/AttachmentSocketsController.js +0 -51
  1522. package/editor/view/ecs/components/sound/SoundEmitterController.js +0 -137
  1523. package/editor/view/ecs/components/story/StoryTriggerSetController.js +0 -214
  1524. package/editor/view/ecs/components/unit/AuraController.js +0 -45
  1525. package/editor/view/makeEntityDecorators.d.ts +0 -6
  1526. package/editor/view/makeEntityDecorators.d.ts.map +0 -1
  1527. package/editor/view/v2/SplitView.d.ts +0 -17
  1528. package/editor/view/v2/SplitView.d.ts.map +0 -1
  1529. package/editor/view/v2/ViewManagementSystem.js +0 -0
  1530. package/editor/view/v2/prototypeEditor.js +0 -127
  1531. package/src/engine/graphics/ecs/sprite/prototypeSpriteSystem.d.ts +0 -2
  1532. package/src/engine/graphics/ecs/sprite/prototypeSpriteSystem.d.ts.map +0 -1
  1533. package/src/engine/graphics/ecs/sprite/prototypeSpriteSystem.js +0 -1570
  1534. package/src/engine/graphics/three/TransfromControls.js +0 -1495
  1535. package/src/view/controller/controls_v2/AbstractPropertyBinding.d.ts +0 -8
  1536. package/src/view/controller/controls_v2/AbstractPropertyBinding.d.ts.map +0 -1
  1537. package/src/view/controller/controls_v2/AbstractPropertyBinding.ts +0 -10
  1538. package/src/view/controller/controls_v2/Controller.d.ts +0 -21
  1539. package/src/view/controller/controls_v2/Controller.d.ts.map +0 -1
  1540. package/src/view/controller/controls_v2/Controller.ts +0 -32
  1541. package/src/view/controller/controls_v2/IPropertyBinding.d.ts +0 -5
  1542. package/src/view/controller/controls_v2/IPropertyBinding.d.ts.map +0 -1
  1543. package/src/view/controller/controls_v2/IPropertyBinding.ts +0 -6
  1544. package/src/view/controller/controls_v2/PrimitivePropertyBinding.d.ts +0 -6
  1545. package/src/view/controller/controls_v2/PrimitivePropertyBinding.d.ts.map +0 -1
  1546. package/src/view/controller/controls_v2/PrimitivePropertyBinding.ts +0 -12
  1547. package/src/view/controller/controls_v2/SliderController.d.ts +0 -6
  1548. package/src/view/controller/controls_v2/SliderController.d.ts.map +0 -1
  1549. package/src/view/controller/controls_v2/SliderController.ts +0 -10
  1550. package/src/view/elements/button/ButtonView.stories.d.ts +0 -2
  1551. package/src/view/elements/button/ButtonView.stories.d.ts.map +0 -1
  1552. package/src/view/elements/button/ButtonView.stories.js +0 -14
@@ -1,1209 +1,1202 @@
1
- import { assert } from "../../../core/assert.js";
2
- import { BinaryBuffer } from "../../../core/binary/BinaryBuffer.js";
3
- import Signal from "../../../core/events/signal/Signal.js";
4
- import { MalformedPacketError } from "../core/MalformedPacketError.js";
5
- import { seq16_advance } from "../core/sequence/seq16.js";
6
- import { Replicator } from "../replication/Replicator.js";
7
- import { AlwaysRelevantScope } from "../replication/ScopeFilter.js";
8
- import { ActionLog } from "../sim/ActionLog.js";
9
- import { ReplicatedComponentRegistry } from "../sim/ReplicatedComponentRegistry.js";
10
- import { SimActionExecutor } from "../sim/SimActionExecutor.js";
11
- import { SimActionRegistry } from "../sim/SimActionRegistry.js";
12
- import { snapshotter_emit } from "../sim/Snapshotter.js";
13
- import { Baseline } from "../state/Baseline.js";
14
- import { ChangedEntitySet } from "../state/ChangedEntitySet.js";
15
- import { MutationLedger } from "../state/MutationLedger.js";
16
- import { ReplicationSlotTable } from "../state/ReplicationSlotTable.js";
17
- import { Channel } from "../transport/Channel.js";
18
- import { resend_fragment_chunk, send_fragmented } from "../transport/fragments/fragment_send.js";
19
- import { FragmentAssembler } from "../transport/fragments/FragmentAssembler.js";
20
- import { FragmentRetention } from "../transport/fragments/FragmentRetention.js";
21
- import { MAX_CHANNEL_PAYLOAD_BYTES } from "../transport/fragments/packet_size.js";
22
- import { ReliableCommandPipeline } from "../transport/ReliableCommandPipeline.js";
23
-
24
- // DISCONNECT packets carry a short UTF-8 reason label. The encoder/decoder
25
- // pair are stateless after construction; sharing module-level singletons
26
- // avoids allocating a fresh pair on every send/receive of this packet type.
27
- const DISCONNECT_TEXT_ENCODER = new TextEncoder();
28
- const DISCONNECT_TEXT_DECODER = new TextDecoder();
29
-
30
- /**
31
- * Wire packet types. The first byte of every NetworkPeer-routed payload picks
32
- * the dispatch path. New types can be added without breaking the action stream
33
- * because old peers will just see an unknown type and drop the packet.
34
- *
35
- * @readonly
36
- * @enum {number}
37
- */
38
- export const NetworkPacketType = {
39
- ACTION_STREAM: 0,
40
- RECOVERY_REQUEST: 1,
41
- STATE_BURST: 2,
42
- /**
43
- * Server → client authoritative state for one entity, tagged with the
44
- * server frame the state represents. Used by client-side prediction to
45
- * trigger rewind+replay reconciliation: "your entity should have looked
46
- * like this at frame F."
47
- */
48
- AUTH_STATE: 3,
49
- /**
50
- * One chunk of a fragmented logical payload. Used transparently by the
51
- * peer when an outgoing message exceeds the channel's single-packet
52
- * capacity. The fragment header (uint16 message_id, uint8 chunk_index,
53
- * uint8 total_chunks) follows this type byte; the chunk payload follows
54
- * that. The reassembled bytes are re-dispatched through this same
55
- * switch (so any of the other packet types can be carried fragmented).
56
- */
57
- FRAGMENT: 4,
58
- /**
59
- * Reliable command. Carries a uintVar logical_seq followed by a
60
- * caller-defined payload. Delivered at-least-once with sender-side
61
- * retransmit and receiver-side dedup via {@link ReliableCommandPipeline}.
62
- * Used for chat, level transitions, lobby state — anything where
63
- * loss-tolerance of the action-stream model isn't acceptable.
64
- */
65
- RELIABLE_COMMAND: 5,
66
- /**
67
- * Selective-retransmit request from the receiver of a fragmented
68
- * message. Wire layout (after the leading type byte):
69
- *
70
- * uint16 message_id (LE)
71
- * uint8 missing_count
72
- * uint8 missing_indices[missing_count]
73
- *
74
- * The sender's {@link FragmentRetention} looks up the retained
75
- * source bytes and re-emits the listed chunks via
76
- * {@link resend_fragment_chunk}. Receiver drives NACK timing
77
- * via {@link FragmentAssembler#service}.
78
- */
79
- NACK_FRAGMENT: 6,
80
- /**
81
- * Server → client time-dilation feedback. Wire layout:
82
- * int16 buffer_depth (LE)
83
- *
84
- * `buffer_depth = max_received_frame - current_sim_frame` from the
85
- * server's POV. Client feeds it to {@link TimeDilation} and dilates
86
- * its tick clock to keep the buffer near target.
87
- */
88
- TIME_DILATION: 7,
89
- /**
90
- * Server → newly-connected peer initial-state snapshot. Wire layout:
91
- * 16 bytes session_token (UUID v1, identifies this peer-session
92
- * for later RESUME_HELLO authentication)
93
- * varint frame_number (server sim_frame this snapshot represents)
94
- * bytes payload (Snapshotter wire format)
95
- *
96
- * Typically exceeds MTU; fragment-send handles chunking.
97
- */
98
- INITIAL_SYNC: 8,
99
- /**
100
- * Client → server reconnection request. Sent after a transport rebuild
101
- * to claim continuity with a prior session record. Wire layout:
102
- * uintVar local_peer_id
103
- * uintVar last_acked_frame
104
- * 16 bytes session_token (from a prior INITIAL_SYNC)
105
- */
106
- RESUME_HELLO: 9,
107
- /**
108
- * Server → client: resume accepted. Empty payload — the action
109
- * stream will resume from `last_acked + 1` on the next host tick.
110
- */
111
- RESUME_ACCEPT: 10,
112
- /**
113
- * Server → client: resume rejected. Wire layout:
114
- * uint8 reason_code (see {@link ResumeRejectReason})
115
- *
116
- * A fresh INITIAL_SYNC typically follows on the next host tick;
117
- * the client drops unconfirmed predictions and accepts the resync.
118
- */
119
- RESUME_REJECT: 11,
120
- /**
121
- * Either direction. Wire layout:
122
- * uint8 reason_label_length
123
- * bytes reason_label (UTF-8, opaque to engine)
124
- *
125
- * Client → server: lets the host free state immediately instead of
126
- * waiting for the grace timer.
127
- * Server → client: the host called `drop_peer(peer_id, reason)`;
128
- * the client surfaces `onConnectionPermanentlyLost(reason)` and
129
- * does NOT attempt reconnect.
130
- */
131
- DISCONNECT: 12,
132
- };
133
-
134
- /**
135
- * Reason codes for {@link NetworkPacketType.RESUME_REJECT}.
136
- * @readonly @enum {number}
137
- */
138
- export const ResumeRejectReason = Object.freeze({
139
- UnknownPeer: 0,
140
- GraceExpired: 1,
141
- TokenMismatch: 2,
142
- PeerIdCollision: 3,
143
- /**
144
- * The peer's token validated, but the frame it asks to resume from has
145
- * already aged out of the host's action-log ring — the action stream
146
- * cannot back-fill the gap. The client must fall through to a full
147
- * INITIAL_SYNC re-sync rather than resume into a silent desync.
148
- */
149
- StaleFrame: 4,
150
- });
151
-
152
- /**
153
- * Per-tick orchestrator that wires the action infrastructure to one or more
154
- * peers over a Transport.
155
- *
156
- * Holds a single world (`EntityComponentDataset`) plus the action machinery
157
- * (executor, replicator, action log). For each connected peer it owns a
158
- * `Channel` and a `seq → frame_end` map so that ack notifications advance the
159
- * `Baseline.last_acked(peer_id)` watermark.
160
- *
161
- * Use as both server (many connected peers) and client (one peer = the server).
162
- * The asymmetry is in *who* connects — the orchestrator itself is symmetric.
163
- *
164
- * Lifecycle:
165
- * 1. `connect_peer(peer_id, transport)` — wire a transport for a peer.
166
- * 2. Per tick:
167
- * - `begin_tick(frame_number)` — open the action log for this frame.
168
- * - User code runs game logic, calling `executor.execute(action)` for each
169
- * replicated state mutation. Inbound actions from peers also flow into
170
- * the executor automatically (via the channel.onPayload wiring).
171
- * - `end_tick()` — close the frame and dispatch outgoing packets to every peer.
172
- * 3. `disconnect_peer(peer_id)` — release the channel + baseline state.
173
- *
174
- * @author Alex Goldring
175
- * @copyright Company Named Limited (c) 2026
176
- */
177
- export class NetworkPeer {
178
- #changed_entities;
179
- #peers;
180
- #send_buffer;
181
- #recv_buffer;
182
- #fragment_scratch;
183
- #next_fragment_message_id;
184
- #tick_open;
185
- #current_frame;
186
- #malformed_packets_dropped;
187
-
188
-
189
- /**
190
- * @param {{
191
- * world: EntityComponentDataset,
192
- * binary_registry: BinarySerializationRegistry,
193
- * replicated_components: Function[],
194
- * action_classes: Function[],
195
- * scope_filter?: { is_entity_in_scope(peer_id: number, network_id: number): boolean },
196
- * frame_capacity?: number,
197
- * initial_buffer_size?: number,
198
- * mutation_ledger?: MutationLedger|null,
199
- * changed_set_capacity?: number,
200
- * }} options
201
- */
202
- constructor({
203
- world,
204
- binary_registry,
205
- replicated_components,
206
- action_classes,
207
- scope_filter = new AlwaysRelevantScope(),
208
- frame_capacity = 32,
209
- initial_buffer_size = 1024,
210
- mutation_ledger = null,
211
- changed_set_capacity = 256,
212
- }) {
213
- assert.ok(world && typeof world.createEntity === 'function', 'world must be an EntityComponentDataset');
214
- assert.ok(binary_registry, 'binary_registry required');
215
- assert.isFunction(replicated_components.forEach, 'replicated_components must be iterable');
216
- assert.isFunction(action_classes.forEach, 'action_classes must be iterable');
217
-
218
- /** @type {EntityComponentDataset} */
219
- this.world = world;
220
-
221
- /** @type {ReplicatedComponentRegistry} */
222
- this.component_registry = new ReplicatedComponentRegistry(binary_registry);
223
- for (const klass of replicated_components) {
224
- this.component_registry.register(klass);
225
- }
226
-
227
- /** @type {SimActionRegistry} */
228
- this.action_registry = new SimActionRegistry();
229
- for (const klass of action_classes) {
230
- this.action_registry.register(klass);
231
- }
232
-
233
- /** @type {ReplicationSlotTable} */
234
- this.slot_table = new ReplicationSlotTable();
235
-
236
- /** @type {ActionLog} */
237
- this.action_log = new ActionLog({ frame_capacity, initial_buffer_size });
238
-
239
- /**
240
- * Optional per-tick mutation tracker. When a `MutationLedger` is supplied,
241
- * this peer records each tick's affected network IDs into a fresh
242
- * `ChangedEntitySet`, then compacts the set into the ledger at `end_tick`.
243
- * Server-side peers should provide a ledger so they can answer recovery
244
- * queries. Receive-only client peers don't need one.
245
- *
246
- * @type {MutationLedger|null}
247
- */
248
- this.mutation_ledger = mutation_ledger;
249
-
250
- /**
251
- * Per-tick "what mutated this tick" sink, used only when
252
- * {@link mutation_ledger} is set. Cleared at the start of each tick;
253
- * compacted into the ledger at end-of-tick.
254
- * @type {ChangedEntitySet|null}
255
- * @private
256
- */
257
- this.#changed_entities = mutation_ledger === null
258
- ? null
259
- : new ChangedEntitySet({ capacity: changed_set_capacity });
260
-
261
- /** @type {SimActionExecutor} */
262
- this.executor = new SimActionExecutor({
263
- world,
264
- action_log: this.action_log,
265
- action_registry: this.action_registry,
266
- component_registry: this.component_registry,
267
- slot_table: this.slot_table,
268
- changed_entities: this.#changed_entities,
269
- });
270
-
271
- /** @type {Replicator} */
272
- this.replicator = new Replicator({
273
- action_log: this.action_log,
274
- action_registry: this.action_registry,
275
- executor: this.executor,
276
- slot_table: this.slot_table,
277
- scope_filter,
278
- });
279
-
280
- /** @type {Baseline} */
281
- this.baseline = new Baseline();
282
-
283
- /**
284
- * peer_id → { channel, transport, seq_to_frame_end, on_payload, on_acked }
285
- * @type {Map<number, { channel: Channel, transport: Object, seq_to_frame_end: Map<number, number>, on_payload: Function, on_acked: Function }>}
286
- * @private
287
- */
288
- this.#peers = new Map();
289
-
290
- /**
291
- * Pre-allocated send buffer for `end_tick` packing.
292
- * @type {BinaryBuffer}
293
- * @private
294
- */
295
- this.#send_buffer = new BinaryBuffer();
296
-
297
- /**
298
- * Reusable scratch buffer for wrapping inbound payloads as BinaryBuffers
299
- * for the Replicator to consume. Reused per packet (sequential delivery).
300
- * @type {BinaryBuffer}
301
- * @private
302
- */
303
- this.#recv_buffer = new BinaryBuffer();
304
-
305
- /**
306
- * Reusable scratch buffer for outgoing fragment packets. Sized for one
307
- * channel-level packet (MTU minus channel header).
308
- * @type {Uint8Array}
309
- * @private
310
- */
311
- this.#fragment_scratch = new Uint8Array(MAX_CHANNEL_PAYLOAD_BYTES);
312
-
313
- /**
314
- * Monotonically-increasing identifier for fragmented messages.
315
- * Wraps at uint16. The receiver's FragmentAssembler keys reassembly
316
- * state on this; collisions would only matter if more than 65536
317
- * messages were in flight simultaneously, which is impossible
318
- * under any realistic transport pressure.
319
- * @type {number}
320
- * @private
321
- */
322
- this.#next_fragment_message_id = 0;
323
-
324
- /** @type {boolean} @private */
325
- this.#tick_open = false;
326
-
327
- /**
328
- * Count of inbound packets dropped because they were structurally
329
- * malformed (a declared length/count that didn't fit the bytes
330
- * received, or any other parse fault at the untrusted boundary).
331
- * Read via {@link malformed_packets_dropped}.
332
- * @type {number}
333
- * @private
334
- */
335
- this.#malformed_packets_dropped = 0;
336
-
337
- /**
338
- * Fired when an inbound packet is dropped as malformed. Args:
339
- * `(peer_id, error)`. Lets callers log / rate-limit / disconnect an
340
- * abusive peer. The receive loop continues regardless a bad packet
341
- * never tears down the connection.
342
- * @type {Signal}
343
- */
344
- this.onMalformedPacket = new Signal();
345
-
346
- /**
347
- * Fired when an inbound packet is a `RECOVERY_REQUEST` (peer is asking
348
- * which entities mutated in a tick range so it can request their state).
349
- * Args: `(peer_id, start_tick, end_tick)`. Subscriber typically responds
350
- * via {@link send_state_burst_for_range}.
351
- * @type {Signal}
352
- */
353
- this.onRecoveryRequest = new Signal();
354
-
355
- /**
356
- * Fired when an inbound packet is a `STATE_BURST` carrying current state
357
- * for a list of entities (response to a recovery request, or push).
358
- * Args: `(peer_id, buffer, length)` where `buffer` is positioned just
359
- * past the packet-type prefix and `length` is the byte count of the
360
- * burst payload (not counting the prefix). Apply via
361
- * {@link snapshotter_apply_to_existing}.
362
- * @type {Signal}
363
- */
364
- this.onStateBurst = new Signal();
365
-
366
- /**
367
- * Fired when an inbound packet is an `AUTH_STATE` (server's authoritative
368
- * state for one entity, tagged with the frame the state represents).
369
- * Args: `(peer_id, frame_number, network_id, buffer)` where `buffer` is
370
- * positioned at the start of the entity's state payload. The handler
371
- * is responsible for deserializing the bytes and triggering whatever
372
- * reconciliation policy the application wants (snap, rewind+replay).
373
- * @type {Signal}
374
- */
375
- this.onAuthState = new Signal();
376
-
377
- /**
378
- * Fires on TIME_DILATION packet arrival.
379
- * Args: `(peer_id, buffer_depth)` signed int16.
380
- * @type {Signal}
381
- */
382
- this.onTimeDilationFeedback = new Signal();
383
-
384
- /**
385
- * Fires on INITIAL_SYNC packet arrival.
386
- * Args: `(peer_id, session_token, frame_number, buffer, payload_end)`.
387
- * `session_token` is a `Uint8Array(16)` (UUID v1 raw bytes); the
388
- * buffer is positioned at the start of the Snapshotter payload.
389
- * @type {Signal}
390
- */
391
- this.onInitialSync = new Signal();
392
-
393
- /**
394
- * Fires on RESUME_HELLO arrival (host-only path in practice).
395
- * Args: `(peer_id, local_peer_id, last_acked_frame, session_token)`.
396
- * Subscriber decides whether to accept (call
397
- * {@link send_resume_accept}) or reject (call
398
- * {@link send_resume_reject}).
399
- * @type {Signal}
400
- */
401
- this.onResumeHello = new Signal();
402
-
403
- /**
404
- * Fires on RESUME_ACCEPT arrival (client-only in practice).
405
- * Args: `(peer_id)`.
406
- * @type {Signal}
407
- */
408
- this.onResumeAccept = new Signal();
409
-
410
- /**
411
- * Fires on RESUME_REJECT arrival (client-only in practice).
412
- * Args: `(peer_id, reason_code)` — see {@link ResumeRejectReason}.
413
- * @type {Signal}
414
- */
415
- this.onResumeReject = new Signal();
416
-
417
- /**
418
- * Fires on DISCONNECT arrival.
419
- * Args: `(peer_id, reason_label)` `reason_label` is a string,
420
- * opaque to the engine.
421
- * @type {Signal}
422
- */
423
- this.onDisconnectPacket = new Signal();
424
-
425
- /**
426
- * Fired when a reliable command arrives from a peer (delivered via
427
- * {@link ReliableCommandPipeline}, dedup'd against retransmits).
428
- *
429
- * Args: `(peer_id, buffer, payload_offset, payload_length)`. The
430
- * buffer is the per-peer scratch and may be reused after the handler
431
- * returns; consumers must copy the payload bytes if they need them
432
- * to outlive the call.
433
- *
434
- * Used for chat, level transitions, lobby/room state — application-
435
- * level messages that need at-least-once delivery semantics rather
436
- * than the action stream's best-effort.
437
- * @type {Signal}
438
- */
439
- this.onReliableCommand = new Signal();
440
- }
441
-
442
- /**
443
- * Wire `transport` to the peer identified by `peer_id`. Creates a Channel
444
- * over the transport and connects ack/payload notifications to the local
445
- * Baseline / Replicator.
446
- *
447
- * @param {number} peer_id
448
- * @param {{ send(bytes: Uint8Array, length: number): void, onReceive: any }} transport
449
- */
450
- connect_peer(peer_id, transport) {
451
- assert.isNonNegativeInteger(peer_id, 'peer_id');
452
- if (this.#peers.has(peer_id)) {
453
- throw new Error(`NetworkPeer.connect_peer: peer ${peer_id} already connected`);
454
- }
455
-
456
- const channel = new Channel({ transport });
457
- const seq_to_frame_end = new Map();
458
- const fragment_assembler = new FragmentAssembler();
459
- const fragment_retention = new FragmentRetention();
460
- const reliable_pipeline = new ReliableCommandPipeline({
461
- channel,
462
- packet_type: NetworkPacketType.RELIABLE_COMMAND,
463
- });
464
-
465
- // Closure captured once at connect time so the per-tick service
466
- // call doesn't allocate. Builds a NACK_FRAGMENT packet inside
467
- // the orchestrator's shared __send_buffer and ships it over the
468
- // peer's channel. `indices[0..count)` is a reused internal
469
- // scratch from the assembler — only valid for the call.
470
- const on_nack = (message_id, indices, count) => {
471
- this.#send_buffer.position = 0;
472
- this.#send_buffer.writeUint8(NetworkPacketType.NACK_FRAGMENT);
473
- this.#send_buffer.writeUint16LE(message_id);
474
- this.#send_buffer.writeUint8(count);
475
- for (let i = 0; i < count; i++) {
476
- this.#send_buffer.writeUint8(indices[i]);
477
- }
478
- channel.send(this.#send_buffer.raw_bytes, this.#send_buffer.position);
479
- };
480
- // Forward pipeline deliveries to the user-facing signal, attributing
481
- // them to the originating peer.
482
- reliable_pipeline.onCommand.add((buf, payload_offset, payload_length) => {
483
- this.onReliableCommand.send4(peer_id, buf, payload_offset, payload_length);
484
- });
485
-
486
- // Recursive dispatch helper. Used for both incoming transport bytes
487
- // AND for reassembled FRAGMENT payloads (so the same switch handles
488
- // both transparent and fragmented delivery of any packet type).
489
- const dispatch = (bytes, length) => {
490
- if (length < 1) {
491
- // malformed: no type byte
492
- return;
493
- }
494
-
495
- this.#recv_buffer.position = 0;
496
- this.#recv_buffer.writeBytes(bytes, 0, length);
497
- this.#recv_buffer.position = 0;
498
-
499
- const packet_type = this.#recv_buffer.readUint8();
500
-
501
- switch (packet_type) {
502
- case NetworkPacketType.ACTION_STREAM:
503
- // The Replicator opens a frame on the action log per packet
504
- // (one per sender frame).
505
- this.replicator.unpack_from_peer(peer_id, this.#recv_buffer, length);
506
- break;
507
- case NetworkPacketType.RECOVERY_REQUEST: {
508
- const start_tick = this.#recv_buffer.readUintVar();
509
- const end_tick = this.#recv_buffer.readUintVar();
510
- this.onRecoveryRequest.send3(peer_id, start_tick, end_tick);
511
- break;
512
- }
513
- case NetworkPacketType.STATE_BURST:
514
- this.onStateBurst.send3(peer_id, this.#recv_buffer, length);
515
- break;
516
- case NetworkPacketType.AUTH_STATE: {
517
- const frame_number = this.#recv_buffer.readUintVar();
518
- const network_id = this.#recv_buffer.readUintVar();
519
- this.onAuthState.send4(peer_id, frame_number, network_id, this.#recv_buffer);
520
- break;
521
- }
522
- case NetworkPacketType.FRAGMENT: {
523
- // Fragment header layout (after the leading type byte):
524
- // uint16 message_id (LE), uint8 chunk_index, uint8 total_chunks
525
- const message_id = this.#recv_buffer.readUint16LE();
526
- const chunk_index = this.#recv_buffer.readUint8();
527
- const total_chunks = this.#recv_buffer.readUint8();
528
- const chunk_offset = this.#recv_buffer.position;
529
- const chunk_length = length - chunk_offset;
530
- const reassembled = fragment_assembler.receive(
531
- message_id, chunk_index, total_chunks,
532
- bytes, chunk_offset, chunk_length,
533
- );
534
- if (reassembled !== null) {
535
- // Defence-in-depth: don't allow nested fragmentation
536
- // (would indicate a sender bug; ignore silently).
537
- if (reassembled[0] !== NetworkPacketType.FRAGMENT) {
538
- dispatch(reassembled, reassembled.length);
539
- }
540
- }
541
- break;
542
- }
543
- case NetworkPacketType.NACK_FRAGMENT: {
544
- // Receiver is asking for specific chunks of a
545
- // previously-sent fragmented message.
546
- // uint16 message_id (LE), uint8 missing_count,
547
- // uint8 missing_indices[missing_count]
548
- const message_id = this.#recv_buffer.readUint16LE();
549
- const missing_count = this.#recv_buffer.readUint8();
550
- const entry = fragment_retention.consume_nack(message_id);
551
- if (entry === null) {
552
- // Either we never retained this id (already evicted /
553
- // never sent), or the retry budget for it is exhausted.
554
- // Either way: nothing to retransmit. Drop silently.
555
- break;
556
- }
557
- for (let i = 0; i < missing_count; i++) {
558
- const chunk_index = this.#recv_buffer.readUint8();
559
- resend_fragment_chunk(
560
- entry.payload, entry.length, message_id, chunk_index,
561
- NetworkPacketType.FRAGMENT, this.#fragment_scratch,
562
- (chunk_bytes, chunk_length) => channel.send(chunk_bytes, chunk_length),
563
- );
564
- }
565
- break;
566
- }
567
- case NetworkPacketType.RELIABLE_COMMAND:
568
- // Pipeline reads logical_seq, dedups, fires its onCommand
569
- // (which we forward to the user's onReliableCommand above).
570
- reliable_pipeline.handle_inbound(this.#recv_buffer, length);
571
- break;
572
- case NetworkPacketType.TIME_DILATION: {
573
- const depth = this.#recv_buffer.readInt16();
574
- this.onTimeDilationFeedback.send2(peer_id, depth);
575
- break;
576
- }
577
- case NetworkPacketType.INITIAL_SYNC: {
578
- if (this.#recv_buffer.position + 16 > length) {
579
- throw new MalformedPacketError(`NetworkPeer.dispatch: INITIAL_SYNC truncated before 16-byte session token`);
580
- }
581
- const session_token = new Uint8Array(16);
582
- this.#recv_buffer.readBytes(session_token, 0, 16);
583
- const frame_number = this.#recv_buffer.readUintVar();
584
- this.onInitialSync.send5(peer_id, session_token, frame_number, this.#recv_buffer, length);
585
- break;
586
- }
587
- case NetworkPacketType.RESUME_HELLO: {
588
- const local_peer_id = this.#recv_buffer.readUintVar();
589
- const last_acked_frame = this.#recv_buffer.readUintVar();
590
- if (this.#recv_buffer.position + 16 > length) {
591
- throw new MalformedPacketError(`NetworkPeer.dispatch: RESUME_HELLO truncated before 16-byte session token`);
592
- }
593
- const session_token = new Uint8Array(16);
594
- this.#recv_buffer.readBytes(session_token, 0, 16);
595
- this.onResumeHello.send4(peer_id, local_peer_id, last_acked_frame, session_token);
596
- break;
597
- }
598
- case NetworkPacketType.RESUME_ACCEPT: {
599
- this.onResumeAccept.send1(peer_id);
600
- break;
601
- }
602
- case NetworkPacketType.RESUME_REJECT: {
603
- const reason_code = this.#recv_buffer.readUint8();
604
- this.onResumeReject.send2(peer_id, reason_code);
605
- break;
606
- }
607
- case NetworkPacketType.DISCONNECT: {
608
- const label_length = this.#recv_buffer.readUint8();
609
- let label = '';
610
- if (label_length > 0) {
611
- if (this.#recv_buffer.position + label_length > length) {
612
- throw new MalformedPacketError(`NetworkPeer.dispatch: DISCONNECT label_length ${label_length} overruns packet`);
613
- }
614
- const label_bytes = new Uint8Array(label_length);
615
- this.#recv_buffer.readBytes(label_bytes, 0, label_length);
616
- label = DISCONNECT_TEXT_DECODER.decode(label_bytes);
617
- }
618
- this.onDisconnectPacket.send2(peer_id, label);
619
- break;
620
- }
621
- default:
622
- // Unknown type — drop. Forward-compat for newer peers.
623
- break;
624
- }
625
- };
626
-
627
- // Ack: advance Baseline to the highest acked frame_end for this peer.
628
- const on_acked = (seq) => {
629
- const frame_end = seq_to_frame_end.get(seq);
630
- if (frame_end !== undefined) {
631
- this.baseline.set_acked(peer_id, frame_end);
632
- seq_to_frame_end.delete(seq);
633
- }
634
- };
635
-
636
- // Loss: a packet that aged out of the ack window without being acked
637
- // leaves a dead seq→frame_end entry. The baseline must NOT advance (the
638
- // frame was never confirmed; back-fill resends it under a fresh seq), but
639
- // the stale mapping should be reclaimed — otherwise lost-packet entries
640
- // accumulate across the session until the seq value is reused on wrap.
641
- const on_lost = (seq) => {
642
- seq_to_frame_end.delete(seq);
643
- };
644
-
645
- // Untrusted-input boundary. A structurally-malformed or truncated
646
- // packet (truncated datagram, spoofed/corrupt bytes, mismatched peer
647
- // build) is dropped and countedthe "discard the bad record, keep the
648
- // connection" posture rather than throwing out of the transport's
649
- // receive callback and crashing the process. A RangeError is a
650
- // BinaryBuffer read past its backing store, i.e. the same malformed-
651
- // input symptom. Any OTHER error is a genuine bug in a packet handler
652
- // and is rethrown so it is not silently swallowed.
653
- const payload_handler = (bytes, length) => {
654
- // Liveness: any packet that reaches dispatch — including empty-ack,
655
- // and malformed ones dropped below is evidence the peer/transport
656
- // is alive. Bump the per-peer inbound counter idle-detection polls.
657
- const conn = this.#peers.get(peer_id);
658
- if (conn !== undefined) conn.inbound_count++;
659
- try {
660
- dispatch(bytes, length);
661
- } catch (e) {
662
- if (e instanceof MalformedPacketError || e instanceof RangeError) {
663
- this.#malformed_packets_dropped++;
664
- this.onMalformedPacket.send2(peer_id, e);
665
- return;
666
- }
667
- throw e;
668
- }
669
- };
670
-
671
- channel.onPayload.add(payload_handler);
672
- channel.onPacketAcked.add(on_acked);
673
- channel.onPacketLost.add(on_lost);
674
-
675
- this.#peers.set(peer_id, {
676
- channel, transport, seq_to_frame_end,
677
- on_payload: payload_handler, on_acked, on_lost, on_nack,
678
- fragment_assembler, fragment_retention,
679
- reliable_pipeline,
680
- inbound_count: 0,
681
- });
682
- }
683
-
684
- /**
685
- * Unwire and forget a peer.
686
- * @param {number} peer_id
687
- */
688
- disconnect_peer(peer_id) {
689
- assert.isNonNegativeInteger(peer_id, 'peer_id');
690
- const conn = this.#peers.get(peer_id);
691
- if (conn === undefined) return;
692
-
693
- conn.channel.onPayload.remove(conn.on_payload);
694
- conn.channel.onPacketAcked.remove(conn.on_acked);
695
- conn.channel.onPacketLost.remove(conn.on_lost);
696
- // Drop the channel's subscription on the transport. Required for the
697
- // common case of reusing the same transport on a subsequent reconnect:
698
- // without this, the orphaned channel keeps consuming inbound packets
699
- // and corrupts ack state in parallel with whatever channel replaces it.
700
- conn.channel.dispose();
701
-
702
- // Drop any in-flight fragment reassemblies for this peer — a fresh
703
- // connection on the same peer_id should start clean.
704
- conn.fragment_assembler.clear();
705
- // Same for the sender-side retention buffer: nothing about the
706
- // previous connection's retransmit history should leak across.
707
- conn.fragment_retention.clear();
708
-
709
- // Detach the reliable pipeline (drops its channel subscriptions and
710
- // any unacked / received state).
711
- conn.reliable_pipeline.dispose();
712
-
713
- this.#peers.delete(peer_id);
714
- this.baseline.forget(peer_id);
715
- // Drop the replicator's apply watermark for this peer so a reconnect
716
- // (or id reuse) isn't deduped against the previous connection's frames.
717
- this.replicator.forget_peer(peer_id);
718
- }
719
-
720
- /**
721
- * Whether `peer_id` is currently connected.
722
- * @param {number} peer_id
723
- * @returns {boolean}
724
- */
725
- is_connected(peer_id) {
726
- return this.#peers.has(peer_id);
727
- }
728
-
729
- /**
730
- * Number of inbound packets dropped so far because they were malformed
731
- * (see {@link onMalformedPacket}). Monotonic for the life of the peer.
732
- * @returns {number}
733
- */
734
- malformed_packets_dropped() {
735
- return this.#malformed_packets_dropped;
736
- }
737
-
738
- /**
739
- * Monotonic count of inbound packets delivered for `peer_id` since it
740
- * connected — any packet that reached the dispatch boundary, including
741
- * empty-ack and malformed ones (all evidence the peer/transport is alive).
742
- * Returns 0 for an unknown peer. Idle/liveness detection polls this and
743
- * reaps a peer whose count stops advancing.
744
- * @param {number} peer_id
745
- * @returns {number}
746
- */
747
- inbound_count(peer_id) {
748
- const conn = this.#peers.get(peer_id);
749
- return conn === undefined ? 0 : conn.inbound_count;
750
- }
751
-
752
- /**
753
- * Direct access to a peer's channel (for sending acks-only packets, raw payloads, etc.).
754
- * @param {number} peer_id
755
- * @returns {Channel|undefined}
756
- */
757
- channel_for(peer_id) {
758
- const conn = this.#peers.get(peer_id);
759
- return conn === undefined ? undefined : conn.channel;
760
- }
761
-
762
- /**
763
- * Open the action log for `frame_number`. Call before running game logic
764
- * for the tick. The user's code (or the engine's `EntityManager.simulate`)
765
- * runs between `begin_tick` and `end_tick`, calling `executor.execute()`
766
- * for each replicated state mutation.
767
- *
768
- * @param {number} frame_number
769
- */
770
- begin_tick(frame_number) {
771
- assert.isNonNegativeInteger(frame_number, 'frame_number');
772
- if (this.#tick_open) {
773
- throw new Error(`NetworkPeer.begin_tick: previous tick still open; call end_tick first`);
774
- }
775
- // Reset the per-tick changed-set so this tick starts with a blank slate.
776
- if (this.#changed_entities !== null) this.#changed_entities.clear();
777
- this.action_log.begin_frame(frame_number);
778
- this.#tick_open = true;
779
- this.#current_frame = frame_number;
780
- }
781
-
782
- /**
783
- * Close the current tick and send pending action records to every peer.
784
- * For each peer, packs frames `[Baseline.last_acked(peer) + 1, current_frame]`
785
- * and sends via the channel; records the seq→frame_end mapping so the next
786
- * ack from that peer advances the baseline.
787
- *
788
- * If a {@link MutationLedger} was supplied at construction, this tick's
789
- * accumulated changed-entity set is also compacted into the ledger.
790
- */
791
- end_tick() {
792
- if (!this.#tick_open) {
793
- throw new Error(`NetworkPeer.end_tick: no tick is open; call begin_tick first`);
794
- }
795
- this.action_log.end_frame();
796
- this.#tick_open = false;
797
-
798
- this.flush_outbound(this.#current_frame);
799
-
800
- // Per-tick fragment maintenance: age out sender-side retention
801
- // and drive NACK emission for any incomplete inbound messages.
802
- // Runs AFTER the action-stream send loop so the shared
803
- // __send_buffer is free for the on_nack closure to reuse.
804
- const now_ms = performance.now();
805
- for (const [, conn] of this.#peers) {
806
- conn.fragment_retention.service(now_ms);
807
- conn.fragment_assembler.service(now_ms, conn.on_nack);
808
- }
809
- }
810
-
811
- /**
812
- * Pack and dispatch the outbound action stream for `current_frame` to
813
- * every connected peer. Second half of {@link end_tick} exposed
814
- * separately so orchestrators that manage action_log frames directly
815
- * (e.g. {@link ServerAuthoritativeServer}'s rollback flow, which
816
- * begin_frame/end_frames many frames per tick) can drive the
817
- * outbound dispatch without going through begin_tick/end_tick.
818
- *
819
- * Assumes the action_log frame for `current_frame` is already CLOSED
820
- * by the caller. Records the tick's accumulated mutations into the
821
- * MutationLedger (if configured), then packs frames
822
- * `[last_acked+1, current_frame]` for each peer via
823
- * `Replicator.pack_for_peer`. Empty packs (no in-scope actions) are
824
- * not sent. Clears the per-tick changed-entity set after recording.
825
- *
826
- * @param {number} current_frame
827
- */
828
- flush_outbound(current_frame) {
829
- assert.isNonNegativeInteger(current_frame, 'current_frame');
830
-
831
- // Record this tick's mutations into the persistent ledger BEFORE sending.
832
- // (Order doesn't strictly matter for correctness, but keeping the ledger
833
- // up-to-date as soon as possible reduces edge-case race windows for
834
- // recovery requests that arrive immediately after.)
835
- if (this.mutation_ledger !== null && this.#changed_entities !== null) {
836
- this.mutation_ledger.record_tick(current_frame, this.#changed_entities);
837
- }
838
-
839
- for (const [peer_id, conn] of this.#peers) {
840
- const last_acked = this.baseline.last_acked(peer_id);
841
- // Pack-range start.
842
- //
843
- // For peers with at least one acked frame, this is just
844
- // last_acked+1 the standard "catch up since you last
845
- // confirmed receipt."
846
- //
847
- // For freshly-connected peers (no ack yet), we cover the
848
- // action_log's full ring: max(0, current_frame -
849
- // frame_capacity + 1). Two competing constraints:
850
- //
851
- // - Don't pack `current_frame` only: under any non-zero
852
- // latency, A's actions tagged at frame X land on the
853
- // server in `action_log[X]`, not `action_log[current]`.
854
- // A relay peer (B) whose start is `current` would see
855
- // an empty pack every tick → no packet sent → B can't
856
- // ack baseline never advances bootstrap deadlock.
857
- // - Don't pack from frame 0: would waste bandwidth
858
- // iterating frames the ring no longer holds. The `has_frame`
859
- // guard inside pack_for_peer would skip them, but the
860
- // loop bound itself can grow unboundedly with
861
- // current_frame.
862
- //
863
- // `current_frame - frame_capacity + 1` is the oldest frame
864
- // the ring could still hold, so we naturally cap at the
865
- // ring's actual content. Actions referencing entities the
866
- // peer's slot_table doesn't yet know about silently no-op
867
- // (Replicator translates via network_for → -1; SimAction
868
- // apply hits the `if (local < 0) return` guard). For first-
869
- // connect scenarios the app is still expected to send a
870
- // state-burst seed; this just makes the action-stream
871
- // bootstrap work in addition to that.
872
- const start = last_acked < 0
873
- ? Math.max(0, current_frame - this.action_log.frame_capacity + 1)
874
- : last_acked + 1;
875
- if (start > current_frame) continue;
876
-
877
- this.#send_buffer.position = 0;
878
- // Packet-type prefix.
879
- this.#send_buffer.writeUint8(NetworkPacketType.ACTION_STREAM);
880
- this.replicator.pack_for_peer(peer_id, start, current_frame, this.#send_buffer);
881
- const length = this.#send_buffer.position;
882
- // Just the prefix no in-scope actions to send.
883
- if (length === 1) continue;
884
-
885
- const seq = this.#send_to_peer(conn, this.#send_buffer.raw_bytes, length);
886
- conn.seq_to_frame_end.set(seq, current_frame);
887
- }
888
-
889
- // Reset the per-tick changed-entity set so the next tick starts clean.
890
- // (begin_tick also clears it; the dual call is harmless.)
891
- if (this.#changed_entities !== null) this.#changed_entities.clear();
892
- }
893
-
894
- /**
895
- * Send a logical payload to a connected peer, fragmenting transparently
896
- * if it exceeds the channel's single-packet capacity.
897
- *
898
- * Returns the seq of the FIRST transport packet emitted. For non-
899
- * fragmented sends that's the only packet; for fragmented sends, that
900
- * seq is what callers should record in `seq_to_frame_end` — when it
901
- * acks, the first fragment arrived, which is a sufficient signal that
902
- * the message is in flight. Fragments either all arrive (and the
903
- * receiver reassembles) or the message is lost; the action-stream's
904
- * back-fill mechanism naturally recovers from the latter on subsequent
905
- * sends.
906
- *
907
- * @param {object} conn entry from __peers
908
- * @param {Uint8Array} payload starts with the packet-type byte
909
- * @param {number} length
910
- * @returns {number} seq of the first packet sent
911
- * @private
912
- */
913
- #send_to_peer(conn, payload, length) {
914
- if (length <= MAX_CHANNEL_PAYLOAD_BYTES) {
915
- return conn.channel.send(payload, length);
916
- }
917
- const message_id = this.#next_fragment_message_id;
918
- this.#next_fragment_message_id = seq16_advance(this.#next_fragment_message_id);
919
- // Retain the source bytes so we can satisfy NACK retransmits.
920
- // Copy happens inside retain(); `payload` is the orchestrator's
921
- // shared send buffer and will be overwritten by the next call.
922
- conn.fragment_retention.retain(message_id, payload, length, performance.now());
923
- let first_seq = -1;
924
- send_fragmented(
925
- payload, length, message_id,
926
- NetworkPacketType.FRAGMENT, this.#fragment_scratch,
927
- (chunk_bytes, chunk_length) => {
928
- const seq = conn.channel.send(chunk_bytes, chunk_length);
929
- if (first_seq < 0) first_seq = seq;
930
- },
931
- );
932
- return first_seq;
933
- }
934
-
935
- /**
936
- * Send a recovery request to `peer_id`: "tell me the current state of every
937
- * entity that mutated between `start_tick` and `end_tick`." The peer's
938
- * server-side handler ({@link onRecoveryRequest}) is expected to respond by
939
- * calling {@link send_state_burst_for_range}.
940
- *
941
- * Best-effort delivery via the same UDP-style channel — if the request is
942
- * lost, the client is expected to retry.
943
- *
944
- * @param {number} peer_id
945
- * @param {number} start_tick
946
- * @param {number} end_tick
947
- */
948
- send_recovery_request(peer_id, start_tick, end_tick) {
949
- assert.isNonNegativeInteger(peer_id, 'peer_id');
950
- assert.isNonNegativeInteger(start_tick, 'start_tick');
951
- assert.isNonNegativeInteger(end_tick, 'end_tick');
952
- const conn = this.#peers.get(peer_id);
953
- if (conn === undefined) throw new Error(`NetworkPeer.send_recovery_request: peer ${peer_id} not connected`);
954
-
955
- this.#send_buffer.position = 0;
956
- this.#send_buffer.writeUint8(NetworkPacketType.RECOVERY_REQUEST);
957
- this.#send_buffer.writeUintVar(start_tick);
958
- this.#send_buffer.writeUintVar(end_tick);
959
- this.#send_to_peer(conn, this.#send_buffer.raw_bytes, this.#send_buffer.position);
960
- }
961
-
962
- /**
963
- * Server-side recovery response. Looks up which entities mutated in
964
- * `[start_tick, end_tick]` via the local `MutationLedger` (must be present),
965
- * then sends the current state of those entities to `peer_id` via a
966
- * `STATE_BURST` packet. Receiver applies via `snapshotter_apply_to_existing`.
967
- *
968
- * If no entities are in the range (or the range is older than the ledger
969
- * retains), nothing is sent. The requester should treat absence of response
970
- * after a timeout as "needs full re-init."
971
- *
972
- * @param {number} peer_id
973
- * @param {number} start_tick
974
- * @param {number} end_tick
975
- */
976
- send_state_burst_for_range(peer_id, start_tick, end_tick) {
977
- assert.isNonNegativeInteger(peer_id, 'peer_id');
978
- assert.isNonNegativeInteger(start_tick, 'start_tick');
979
- assert.isNonNegativeInteger(end_tick, 'end_tick');
980
- if (this.mutation_ledger === null) {
981
- throw new Error('NetworkPeer.send_state_burst_for_range: requires mutation_ledger to be configured');
982
- }
983
- const conn = this.#peers.get(peer_id);
984
- if (conn === undefined) throw new Error(`NetworkPeer.send_state_burst_for_range: peer ${peer_id} not connected`);
985
-
986
- // Reuse the changed-set as a scratch dedupe surface for the union.
987
- // It's been cleared at the start of this tick (or hasn't been used yet);
988
- // it will be cleared again at the start of the next tick.
989
- const scratch = this.#changed_entities !== null
990
- ? this.#changed_entities
991
- : new ChangedEntitySet({ capacity: 1024 });
992
- // Don't clobber an in-progress tick's accumulated mutations. If a tick
993
- // is currently open we use a fresh set just for this query.
994
- const set = this.#tick_open
995
- ? new ChangedEntitySet({ capacity: 1024 })
996
- : scratch;
997
- set.clear();
998
-
999
- this.mutation_ledger.entities_changed_in_range(set, start_tick, end_tick);
1000
- if (set.size() === 0) return;
1001
-
1002
- this.#send_buffer.position = 0;
1003
- this.#send_buffer.writeUint8(NetworkPacketType.STATE_BURST);
1004
- snapshotter_emit({
1005
- buffer: this.#send_buffer,
1006
- world: this.world,
1007
- slot_table: this.slot_table,
1008
- component_registry: this.component_registry,
1009
- entity_iter: cb => {
1010
- set.for_each(network_id => {
1011
- const eid = this.slot_table.entity_for(network_id);
1012
- if (eid >= 0) cb(eid);
1013
- });
1014
- },
1015
- });
1016
- // STATE_BURST is the primary path that can exceed MTU a recovery
1017
- // response covering many entities easily lands in the multi-KB range.
1018
- // The fragmenting wrapper splits it across packets transparently.
1019
- this.#send_to_peer(conn, this.#send_buffer.raw_bytes, this.#send_buffer.position);
1020
- }
1021
-
1022
- /**
1023
- * Send the authoritative state of one entity to `peer_id`, tagged with
1024
- * the frame the state represents. Used by client-side prediction: the
1025
- * server emits this every tick (or every N ticks) for client-owned
1026
- * entities; the client compares to its predicted state at the same frame
1027
- * and reconciles via rewind+replay if they differ.
1028
- *
1029
- * The payload is whatever `write_fn(buffer)` writes typically a
1030
- * `BinaryClassSerializationAdapter.serialize(buffer, component)` call.
1031
- * The receiver's `onAuthState` handler reads the same bytes via the
1032
- * matching deserializer.
1033
- *
1034
- * @param {number} peer_id
1035
- * @param {number} frame_number sender's frame the state corresponds to
1036
- * @param {number} network_id which entity this state is for
1037
- * @param {function(BinaryBuffer): void} write_fn writes the entity's state bytes
1038
- */
1039
- send_auth_state(peer_id, frame_number, network_id, write_fn) {
1040
- assert.isNonNegativeInteger(peer_id, 'peer_id');
1041
- assert.isNonNegativeInteger(frame_number, 'frame_number');
1042
- assert.isNonNegativeInteger(network_id, 'network_id');
1043
- assert.isFunction(write_fn, 'write_fn');
1044
- const conn = this.#peers.get(peer_id);
1045
- if (conn === undefined) throw new Error(`NetworkPeer.send_auth_state: peer ${peer_id} not connected`);
1046
-
1047
- this.#send_buffer.position = 0;
1048
- this.#send_buffer.writeUint8(NetworkPacketType.AUTH_STATE);
1049
- this.#send_buffer.writeUintVar(frame_number);
1050
- this.#send_buffer.writeUintVar(network_id);
1051
- write_fn(this.#send_buffer);
1052
- this.#send_to_peer(conn, this.#send_buffer.raw_bytes, this.#send_buffer.position);
1053
- }
1054
-
1055
- /**
1056
- * Send an INITIAL_SYNC packet. `write_fn` receives the send-buffer
1057
- * positioned just past the `(packet_type, session_token, frame_number)`
1058
- * header and writes the Snapshotter payload. Fragments transparently.
1059
- *
1060
- * @param {number} peer_id
1061
- * @param {Uint8Array} session_token 16-byte UUID v1 identifying this peer-session
1062
- * @param {number} frame_number server sim frame this snapshot represents
1063
- * @param {function(BinaryBuffer): void} write_fn
1064
- */
1065
- send_initial_sync(peer_id, session_token, frame_number, write_fn) {
1066
- assert.isNonNegativeInteger(peer_id, 'peer_id');
1067
- assert.ok(session_token instanceof Uint8Array && session_token.length === 16,
1068
- 'session_token must be a 16-byte Uint8Array');
1069
- assert.isNonNegativeInteger(frame_number, 'frame_number');
1070
- assert.isFunction(write_fn, 'write_fn');
1071
- const conn = this.#peers.get(peer_id);
1072
- if (conn === undefined) throw new Error(`NetworkPeer.send_initial_sync: peer ${peer_id} not connected`);
1073
-
1074
- this.#send_buffer.position = 0;
1075
- this.#send_buffer.writeUint8(NetworkPacketType.INITIAL_SYNC);
1076
- this.#send_buffer.writeBytes(session_token, 0, 16);
1077
- this.#send_buffer.writeUintVar(frame_number);
1078
- write_fn(this.#send_buffer);
1079
- this.#send_to_peer(conn, this.#send_buffer.raw_bytes, this.#send_buffer.position);
1080
- }
1081
-
1082
- /**
1083
- * Send a RESUME_HELLO packet to the server. Client-only direction.
1084
- *
1085
- * @param {number} peer_id remote peer (the server)
1086
- * @param {number} local_peer_id the client's own peer id
1087
- * @param {number} last_acked_frame the client's view of last-acked frame
1088
- * @param {Uint8Array} session_token 16-byte token from a prior INITIAL_SYNC
1089
- */
1090
- send_resume_hello(peer_id, local_peer_id, last_acked_frame, session_token) {
1091
- assert.isNonNegativeInteger(peer_id, 'peer_id');
1092
- assert.isNonNegativeInteger(local_peer_id, 'local_peer_id');
1093
- assert.isNonNegativeInteger(last_acked_frame, 'last_acked_frame');
1094
- assert.ok(session_token instanceof Uint8Array && session_token.length === 16,
1095
- 'session_token must be a 16-byte Uint8Array');
1096
- const conn = this.#peers.get(peer_id);
1097
- if (conn === undefined) throw new Error(`NetworkPeer.send_resume_hello: peer ${peer_id} not connected`);
1098
-
1099
- this.#send_buffer.position = 0;
1100
- this.#send_buffer.writeUint8(NetworkPacketType.RESUME_HELLO);
1101
- this.#send_buffer.writeUintVar(local_peer_id);
1102
- this.#send_buffer.writeUintVar(last_acked_frame);
1103
- this.#send_buffer.writeBytes(session_token, 0, 16);
1104
- this.#send_to_peer(conn, this.#send_buffer.raw_bytes, this.#send_buffer.position);
1105
- }
1106
-
1107
- /**
1108
- * Send a RESUME_ACCEPT packet. Host-only direction.
1109
- * @param {number} peer_id
1110
- */
1111
- send_resume_accept(peer_id) {
1112
- assert.isNonNegativeInteger(peer_id, 'peer_id');
1113
- const conn = this.#peers.get(peer_id);
1114
- if (conn === undefined) throw new Error(`NetworkPeer.send_resume_accept: peer ${peer_id} not connected`);
1115
-
1116
- this.#send_buffer.position = 0;
1117
- this.#send_buffer.writeUint8(NetworkPacketType.RESUME_ACCEPT);
1118
- this.#send_to_peer(conn, this.#send_buffer.raw_bytes, this.#send_buffer.position);
1119
- }
1120
-
1121
- /**
1122
- * Send a RESUME_REJECT packet. Host-only direction.
1123
- * @param {number} peer_id
1124
- * @param {number} reason_code one of {@link ResumeRejectReason}
1125
- */
1126
- send_resume_reject(peer_id, reason_code) {
1127
- assert.isNonNegativeInteger(peer_id, 'peer_id');
1128
- assert.isNonNegativeInteger(reason_code, 'reason_code');
1129
- const conn = this.#peers.get(peer_id);
1130
- if (conn === undefined) throw new Error(`NetworkPeer.send_resume_reject: peer ${peer_id} not connected`);
1131
-
1132
- this.#send_buffer.position = 0;
1133
- this.#send_buffer.writeUint8(NetworkPacketType.RESUME_REJECT);
1134
- this.#send_buffer.writeUint8(reason_code & 0xFF);
1135
- this.#send_to_peer(conn, this.#send_buffer.raw_bytes, this.#send_buffer.position);
1136
- }
1137
-
1138
- /**
1139
- * Send a DISCONNECT packet. Either direction. `reason_label` is an
1140
- * opaque string (255 byte cap after UTF-8 encoding).
1141
- *
1142
- * @param {number} peer_id
1143
- * @param {string} [reason_label]
1144
- */
1145
- send_disconnect(peer_id, reason_label = '') {
1146
- assert.isNonNegativeInteger(peer_id, 'peer_id');
1147
- assert.isString(reason_label, 'reason_label');
1148
- const conn = this.#peers.get(peer_id);
1149
- if (conn === undefined) throw new Error(`NetworkPeer.send_disconnect: peer ${peer_id} not connected`);
1150
-
1151
- const encoded = DISCONNECT_TEXT_ENCODER.encode(reason_label);
1152
- const len = Math.min(encoded.length, 255);
1153
-
1154
- this.#send_buffer.position = 0;
1155
- this.#send_buffer.writeUint8(NetworkPacketType.DISCONNECT);
1156
- this.#send_buffer.writeUint8(len);
1157
- if (len > 0) this.#send_buffer.writeBytes(encoded, 0, len);
1158
- this.#send_to_peer(conn, this.#send_buffer.raw_bytes, this.#send_buffer.position);
1159
- }
1160
-
1161
- /**
1162
- * Send a TIME_DILATION feedback packet. `buffer_depth` is clamped
1163
- * to the int16 range — saturating is fine since the controller
1164
- * doesn't need sub-int16 precision.
1165
- *
1166
- * @param {number} peer_id
1167
- * @param {number} buffer_depth signed integer; clamped to int16
1168
- */
1169
- send_time_dilation_feedback(peer_id, buffer_depth) {
1170
- assert.isNonNegativeInteger(peer_id, 'peer_id');
1171
- assert.isNumber(buffer_depth, 'buffer_depth');
1172
- const conn = this.#peers.get(peer_id);
1173
- if (conn === undefined) throw new Error(`NetworkPeer.send_time_dilation_feedback: peer ${peer_id} not connected`);
1174
-
1175
- let depth = buffer_depth | 0;
1176
- if (depth > 32767) depth = 32767;
1177
- else if (depth < -32768) depth = -32768;
1178
-
1179
- this.#send_buffer.position = 0;
1180
- this.#send_buffer.writeUint8(NetworkPacketType.TIME_DILATION);
1181
- this.#send_buffer.writeInt16(depth);
1182
- this.#send_to_peer(conn, this.#send_buffer.raw_bytes, this.#send_buffer.position);
1183
- }
1184
-
1185
- /**
1186
- * Send a reliable command to a connected peer. Delivered at-least-once
1187
- * with sender-side retransmit on Channel-detected loss and receiver-
1188
- * side dedup by logical seq. Use for messages where the action-stream
1189
- * model (best-effort, per-frame back-fill) isn't suitable — chat,
1190
- * lobby/room state, level transitions.
1191
- *
1192
- * Returns the logical seq the pipeline assigned (diagnostic only; the
1193
- * receiver dedups internally regardless).
1194
- *
1195
- * @param {number} peer_id
1196
- * @param {Uint8Array} payload
1197
- * @param {number} length
1198
- * @returns {number} logical seq
1199
- */
1200
- send_reliable_command(peer_id, payload, length) {
1201
- assert.isNonNegativeInteger(peer_id, 'peer_id');
1202
- assert.isNonNegativeInteger(length, 'length');
1203
- const conn = this.#peers.get(peer_id);
1204
- if (conn === undefined) {
1205
- throw new Error(`NetworkPeer.send_reliable_command: peer ${peer_id} not connected`);
1206
- }
1207
- return conn.reliable_pipeline.send(payload, length);
1208
- }
1209
- }
1
+ import { assert } from "../../../core/assert.js";
2
+ import { BinaryBuffer } from "../../../core/binary/BinaryBuffer.js";
3
+ import Signal from "../../../core/events/signal/Signal.js";
4
+ import { MalformedPacketError } from "../core/MalformedPacketError.js";
5
+ import { seq16_advance } from "../core/sequence/seq16.js";
6
+ import { Replicator } from "../replication/Replicator.js";
7
+ import { AlwaysRelevantScope } from "../replication/ScopeFilter.js";
8
+ import { ActionLog } from "../sim/ActionLog.js";
9
+ import { ReplicatedComponentRegistry } from "../sim/ReplicatedComponentRegistry.js";
10
+ import { SimActionExecutor } from "../sim/SimActionExecutor.js";
11
+ import { SimActionRegistry } from "../sim/SimActionRegistry.js";
12
+ import { snapshotter_emit } from "../sim/Snapshotter.js";
13
+ import { Baseline } from "../state/Baseline.js";
14
+ import { ChangedEntitySet } from "../state/ChangedEntitySet.js";
15
+ import { MutationLedger } from "../state/MutationLedger.js";
16
+ import { ReplicationSlotTable } from "../state/ReplicationSlotTable.js";
17
+ import { Channel } from "../transport/Channel.js";
18
+ import { resend_fragment_chunk, send_fragmented } from "../transport/fragments/fragment_send.js";
19
+ import { FragmentAssembler } from "../transport/fragments/FragmentAssembler.js";
20
+ import { FragmentRetention } from "../transport/fragments/FragmentRetention.js";
21
+ import { MAX_CHANNEL_PAYLOAD_BYTES } from "../transport/fragments/packet_size.js";
22
+ import { ReliableCommandPipeline } from "../transport/ReliableCommandPipeline.js";
23
+
24
+ // DISCONNECT packets carry a short UTF-8 reason label. The encoder/decoder
25
+ // pair are stateless after construction; sharing module-level singletons
26
+ // avoids allocating a fresh pair on every send/receive of this packet type.
27
+ const DISCONNECT_TEXT_ENCODER = new TextEncoder();
28
+ const DISCONNECT_TEXT_DECODER = new TextDecoder();
29
+
30
+ /**
31
+ * Wire packet types. The first byte of every NetworkPeer-routed payload picks
32
+ * the dispatch path. New types can be added without breaking the action stream
33
+ * because old peers will just see an unknown type and drop the packet.
34
+ *
35
+ * @readonly
36
+ * @enum {number}
37
+ */
38
+ export const NetworkPacketType = {
39
+ ACTION_STREAM: 0,
40
+ RECOVERY_REQUEST: 1,
41
+ STATE_BURST: 2,
42
+ /**
43
+ * Server → client authoritative state for one entity, tagged with the
44
+ * server frame the state represents. Used by client-side prediction to
45
+ * trigger rewind+replay reconciliation: "your entity should have looked
46
+ * like this at frame F."
47
+ */
48
+ AUTH_STATE: 3,
49
+ /**
50
+ * One chunk of a fragmented logical payload. Used transparently by the
51
+ * peer when an outgoing message exceeds the channel's single-packet
52
+ * capacity. The fragment header (uint16 message_id, uint8 chunk_index,
53
+ * uint8 total_chunks) follows this type byte; the chunk payload follows
54
+ * that. The reassembled bytes are re-dispatched through this same
55
+ * switch (so any of the other packet types can be carried fragmented).
56
+ */
57
+ FRAGMENT: 4,
58
+ /**
59
+ * Reliable command. Carries a uintVar logical_seq followed by a
60
+ * caller-defined payload. Delivered at-least-once with sender-side
61
+ * retransmit and receiver-side dedup via {@link ReliableCommandPipeline}.
62
+ * Used for chat, level transitions, lobby state — anything where
63
+ * loss-tolerance of the action-stream model isn't acceptable.
64
+ */
65
+ RELIABLE_COMMAND: 5,
66
+ /**
67
+ * Selective-retransmit request from the receiver of a fragmented
68
+ * message. Wire layout (after the leading type byte):
69
+ *
70
+ * uint16 message_id (LE)
71
+ * uint8 missing_count
72
+ * uint8 missing_indices[missing_count]
73
+ *
74
+ * The sender's {@link FragmentRetention} looks up the retained
75
+ * source bytes and re-emits the listed chunks via
76
+ * {@link resend_fragment_chunk}. Receiver drives NACK timing
77
+ * via {@link FragmentAssembler#service}.
78
+ */
79
+ NACK_FRAGMENT: 6,
80
+ /**
81
+ * Server → client time-dilation feedback. Wire layout:
82
+ * int16 buffer_depth (LE)
83
+ *
84
+ * `buffer_depth = max_received_frame - current_sim_frame` from the
85
+ * server's POV. Client feeds it to {@link TimeDilation} and dilates
86
+ * its tick clock to keep the buffer near target.
87
+ */
88
+ TIME_DILATION: 7,
89
+ /**
90
+ * Server → newly-connected peer initial-state snapshot. Wire layout:
91
+ * 16 bytes session_token (UUID v1, identifies this peer-session
92
+ * for later RESUME_HELLO authentication)
93
+ * varint frame_number (server sim_frame this snapshot represents)
94
+ * bytes payload (Snapshotter wire format)
95
+ *
96
+ * Typically exceeds MTU; fragment-send handles chunking.
97
+ */
98
+ INITIAL_SYNC: 8,
99
+ /**
100
+ * Client → server reconnection request. Sent after a transport rebuild
101
+ * to claim continuity with a prior session record. Wire layout:
102
+ * uintVar local_peer_id
103
+ * uintVar last_acked_frame
104
+ * 16 bytes session_token (from a prior INITIAL_SYNC)
105
+ */
106
+ RESUME_HELLO: 9,
107
+ /**
108
+ * Server → client: resume accepted. Empty payload — the action
109
+ * stream will resume from `last_acked + 1` on the next host tick.
110
+ */
111
+ RESUME_ACCEPT: 10,
112
+ /**
113
+ * Server → client: resume rejected. Wire layout:
114
+ * uint8 reason_code (see {@link ResumeRejectReason})
115
+ *
116
+ * A fresh INITIAL_SYNC typically follows on the next host tick;
117
+ * the client drops unconfirmed predictions and accepts the resync.
118
+ */
119
+ RESUME_REJECT: 11,
120
+ /**
121
+ * Either direction. Wire layout:
122
+ * uint8 reason_label_length
123
+ * bytes reason_label (UTF-8, opaque to engine)
124
+ *
125
+ * Client → server: lets the host free state immediately instead of
126
+ * waiting for the grace timer.
127
+ * Server → client: the host called `drop_peer(peer_id, reason)`;
128
+ * the client surfaces `onConnectionPermanentlyLost(reason)` and
129
+ * does NOT attempt reconnect.
130
+ */
131
+ DISCONNECT: 12,
132
+ };
133
+
134
+ /**
135
+ * Reason codes for {@link NetworkPacketType.RESUME_REJECT}.
136
+ * @readonly @enum {number}
137
+ */
138
+ export const ResumeRejectReason = Object.freeze({
139
+ UnknownPeer: 0,
140
+ GraceExpired: 1,
141
+ TokenMismatch: 2,
142
+ PeerIdCollision: 3,
143
+ /**
144
+ * The peer's token validated, but the frame it asks to resume from has
145
+ * already aged out of the host's action-log ring — the action stream
146
+ * cannot back-fill the gap. The client must fall through to a full
147
+ * INITIAL_SYNC re-sync rather than resume into a silent desync.
148
+ */
149
+ StaleFrame: 4,
150
+ });
151
+
152
+ /**
153
+ * Per-tick orchestrator that wires the action infrastructure to one or more
154
+ * peers over a Transport.
155
+ *
156
+ * Holds a single world (`EntityComponentDataset`) plus the action machinery
157
+ * (executor, replicator, action log). For each connected peer it owns a
158
+ * `Channel` and a `seq → frame_end` map so that ack notifications advance the
159
+ * `Baseline.last_acked(peer_id)` watermark.
160
+ *
161
+ * Use as both server (many connected peers) and client (one peer = the server).
162
+ * The asymmetry is in *who* connects — the orchestrator itself is symmetric.
163
+ *
164
+ * Lifecycle:
165
+ * 1. `connect_peer(peer_id, transport)` — wire a transport for a peer.
166
+ * 2. Per tick:
167
+ * - `begin_tick(frame_number)` — open the action log for this frame.
168
+ * - User code runs game logic, calling `executor.execute(action)` for each
169
+ * replicated state mutation. Inbound actions from peers also flow into
170
+ * the executor automatically (via the channel.onPayload wiring).
171
+ * - `end_tick()` — close the frame and dispatch outgoing packets to every peer.
172
+ * 3. `disconnect_peer(peer_id)` — release the channel + baseline state.
173
+ *
174
+ * @author Alex Goldring
175
+ * @copyright Company Named Limited (c) 2026
176
+ */
177
+ export class NetworkPeer {
178
+ #changed_entities;
179
+ #peers;
180
+ #send_buffer;
181
+ #recv_buffer;
182
+ #fragment_scratch;
183
+ /**
184
+ * Monotonically-increasing identifier for fragmented messages.
185
+ * Wraps at uint16. The receiver's FragmentAssembler keys reassembly
186
+ * state on this; collisions would only matter if more than 65536
187
+ * messages were in flight simultaneously, which is impossible
188
+ * under any realistic transport pressure.
189
+ * @type {number}
190
+ * @private
191
+ */
192
+ #next_fragment_message_id = 0;
193
+ /** @type {boolean} @private */
194
+ #tick_open = false;
195
+ #current_frame;
196
+ /**
197
+ * Count of inbound packets dropped because they were structurally
198
+ * malformed (a declared length/count that didn't fit the bytes
199
+ * received, or any other parse fault at the untrusted boundary).
200
+ * Read via {@link malformed_packets_dropped}.
201
+ * @type {number}
202
+ * @private
203
+ */
204
+ #malformed_packets_dropped = 0;
205
+
206
+ /**
207
+ * @param {{
208
+ * world: EntityComponentDataset,
209
+ * binary_registry: BinarySerializationRegistry,
210
+ * replicated_components: Function[],
211
+ * action_classes: Function[],
212
+ * scope_filter?: { is_entity_in_scope(peer_id: number, network_id: number): boolean },
213
+ * frame_capacity?: number,
214
+ * initial_buffer_size?: number,
215
+ * mutation_ledger?: MutationLedger|null,
216
+ * changed_set_capacity?: number,
217
+ * }} options
218
+ */
219
+ constructor({
220
+ world,
221
+ binary_registry,
222
+ replicated_components,
223
+ action_classes,
224
+ scope_filter = new AlwaysRelevantScope(),
225
+ frame_capacity = 32,
226
+ initial_buffer_size = 1024,
227
+ mutation_ledger = null,
228
+ changed_set_capacity = 256,
229
+ }) {
230
+ assert.ok(world && typeof world.createEntity === 'function', 'world must be an EntityComponentDataset');
231
+ assert.ok(binary_registry, 'binary_registry required');
232
+ assert.isFunction(replicated_components.forEach, 'replicated_components must be iterable');
233
+ assert.isFunction(action_classes.forEach, 'action_classes must be iterable');
234
+
235
+ /** @type {EntityComponentDataset} */
236
+ this.world = world;
237
+
238
+ /** @type {ReplicatedComponentRegistry} */
239
+ this.component_registry = new ReplicatedComponentRegistry(binary_registry);
240
+ for (const klass of replicated_components) {
241
+ this.component_registry.register(klass);
242
+ }
243
+
244
+ /** @type {SimActionRegistry} */
245
+ this.action_registry = new SimActionRegistry();
246
+ for (const klass of action_classes) {
247
+ this.action_registry.register(klass);
248
+ }
249
+
250
+ /** @type {ReplicationSlotTable} */
251
+ this.slot_table = new ReplicationSlotTable();
252
+
253
+ /** @type {ActionLog} */
254
+ this.action_log = new ActionLog({ frame_capacity, initial_buffer_size });
255
+
256
+ /**
257
+ * Optional per-tick mutation tracker. When a `MutationLedger` is supplied,
258
+ * this peer records each tick's affected network IDs into a fresh
259
+ * `ChangedEntitySet`, then compacts the set into the ledger at `end_tick`.
260
+ * Server-side peers should provide a ledger so they can answer recovery
261
+ * queries. Receive-only client peers don't need one.
262
+ *
263
+ * @type {MutationLedger|null}
264
+ */
265
+ this.mutation_ledger = mutation_ledger;
266
+
267
+ /**
268
+ * Per-tick "what mutated this tick" sink, used only when
269
+ * {@link mutation_ledger} is set. Cleared at the start of each tick;
270
+ * compacted into the ledger at end-of-tick.
271
+ * @type {ChangedEntitySet|null}
272
+ * @private
273
+ */
274
+ this.#changed_entities = mutation_ledger === null
275
+ ? null
276
+ : new ChangedEntitySet({ capacity: changed_set_capacity });
277
+
278
+ /** @type {SimActionExecutor} */
279
+ this.executor = new SimActionExecutor({
280
+ world,
281
+ action_log: this.action_log,
282
+ action_registry: this.action_registry,
283
+ component_registry: this.component_registry,
284
+ slot_table: this.slot_table,
285
+ changed_entities: this.#changed_entities,
286
+ });
287
+
288
+ /** @type {Replicator} */
289
+ this.replicator = new Replicator({
290
+ action_log: this.action_log,
291
+ action_registry: this.action_registry,
292
+ executor: this.executor,
293
+ slot_table: this.slot_table,
294
+ scope_filter,
295
+ });
296
+
297
+ /** @type {Baseline} */
298
+ this.baseline = new Baseline();
299
+
300
+ /**
301
+ * peer_id → { channel, transport, seq_to_frame_end, on_payload, on_acked }
302
+ * @type {Map<number, { channel: Channel, transport: Object, seq_to_frame_end: Map<number, number>, on_payload: Function, on_acked: Function }>}
303
+ * @private
304
+ */
305
+ this.#peers = new Map();
306
+
307
+ /**
308
+ * Pre-allocated send buffer for `end_tick` packing.
309
+ * @type {BinaryBuffer}
310
+ * @private
311
+ */
312
+ this.#send_buffer = new BinaryBuffer();
313
+
314
+ /**
315
+ * Reusable scratch buffer for wrapping inbound payloads as BinaryBuffers
316
+ * for the Replicator to consume. Reused per packet (sequential delivery).
317
+ * @type {BinaryBuffer}
318
+ * @private
319
+ */
320
+ this.#recv_buffer = new BinaryBuffer();
321
+
322
+ /**
323
+ * Reusable scratch buffer for outgoing fragment packets. Sized for one
324
+ * channel-level packet (MTU minus channel header).
325
+ * @type {Uint8Array}
326
+ * @private
327
+ */
328
+ this.#fragment_scratch = new Uint8Array(MAX_CHANNEL_PAYLOAD_BYTES);
329
+
330
+ /**
331
+ * Fired when an inbound packet is dropped as malformed. Args:
332
+ * `(peer_id, error)`. Lets callers log / rate-limit / disconnect an
333
+ * abusive peer. The receive loop continues regardless — a bad packet
334
+ * never tears down the connection.
335
+ * @type {Signal}
336
+ */
337
+ this.onMalformedPacket = new Signal();
338
+
339
+ /**
340
+ * Fired when an inbound packet is a `RECOVERY_REQUEST` (peer is asking
341
+ * which entities mutated in a tick range so it can request their state).
342
+ * Args: `(peer_id, start_tick, end_tick)`. Subscriber typically responds
343
+ * via {@link send_state_burst_for_range}.
344
+ * @type {Signal}
345
+ */
346
+ this.onRecoveryRequest = new Signal();
347
+
348
+ /**
349
+ * Fired when an inbound packet is a `STATE_BURST` carrying current state
350
+ * for a list of entities (response to a recovery request, or push).
351
+ * Args: `(peer_id, buffer, length)` where `buffer` is positioned just
352
+ * past the packet-type prefix and `length` is the byte count of the
353
+ * burst payload (not counting the prefix). Apply via
354
+ * {@link snapshotter_apply_to_existing}.
355
+ * @type {Signal}
356
+ */
357
+ this.onStateBurst = new Signal();
358
+
359
+ /**
360
+ * Fired when an inbound packet is an `AUTH_STATE` (server's authoritative
361
+ * state for one entity, tagged with the frame the state represents).
362
+ * Args: `(peer_id, frame_number, network_id, buffer)` where `buffer` is
363
+ * positioned at the start of the entity's state payload. The handler
364
+ * is responsible for deserializing the bytes and triggering whatever
365
+ * reconciliation policy the application wants (snap, rewind+replay).
366
+ * @type {Signal}
367
+ */
368
+ this.onAuthState = new Signal();
369
+
370
+ /**
371
+ * Fires on TIME_DILATION packet arrival.
372
+ * Args: `(peer_id, buffer_depth)` signed int16.
373
+ * @type {Signal}
374
+ */
375
+ this.onTimeDilationFeedback = new Signal();
376
+
377
+ /**
378
+ * Fires on INITIAL_SYNC packet arrival.
379
+ * Args: `(peer_id, session_token, frame_number, buffer, payload_end)`.
380
+ * `session_token` is a `Uint8Array(16)` (UUID v1 raw bytes); the
381
+ * buffer is positioned at the start of the Snapshotter payload.
382
+ * @type {Signal}
383
+ */
384
+ this.onInitialSync = new Signal();
385
+
386
+ /**
387
+ * Fires on RESUME_HELLO arrival (host-only path in practice).
388
+ * Args: `(peer_id, local_peer_id, last_acked_frame, session_token)`.
389
+ * Subscriber decides whether to accept (call
390
+ * {@link send_resume_accept}) or reject (call
391
+ * {@link send_resume_reject}).
392
+ * @type {Signal}
393
+ */
394
+ this.onResumeHello = new Signal();
395
+
396
+ /**
397
+ * Fires on RESUME_ACCEPT arrival (client-only in practice).
398
+ * Args: `(peer_id)`.
399
+ * @type {Signal}
400
+ */
401
+ this.onResumeAccept = new Signal();
402
+
403
+ /**
404
+ * Fires on RESUME_REJECT arrival (client-only in practice).
405
+ * Args: `(peer_id, reason_code)` — see {@link ResumeRejectReason}.
406
+ * @type {Signal}
407
+ */
408
+ this.onResumeReject = new Signal();
409
+
410
+ /**
411
+ * Fires on DISCONNECT arrival.
412
+ * Args: `(peer_id, reason_label)` — `reason_label` is a string,
413
+ * opaque to the engine.
414
+ * @type {Signal}
415
+ */
416
+ this.onDisconnectPacket = new Signal();
417
+
418
+ /**
419
+ * Fired when a reliable command arrives from a peer (delivered via
420
+ * {@link ReliableCommandPipeline}, dedup'd against retransmits).
421
+ *
422
+ * Args: `(peer_id, buffer, payload_offset, payload_length)`. The
423
+ * buffer is the per-peer scratch and may be reused after the handler
424
+ * returns; consumers must copy the payload bytes if they need them
425
+ * to outlive the call.
426
+ *
427
+ * Used for chat, level transitions, lobby/room state — application-
428
+ * level messages that need at-least-once delivery semantics rather
429
+ * than the action stream's best-effort.
430
+ * @type {Signal}
431
+ */
432
+ this.onReliableCommand = new Signal();
433
+ }
434
+
435
+ /**
436
+ * Wire `transport` to the peer identified by `peer_id`. Creates a Channel
437
+ * over the transport and connects ack/payload notifications to the local
438
+ * Baseline / Replicator.
439
+ *
440
+ * @param {number} peer_id
441
+ * @param {{ send(bytes: Uint8Array, length: number): void, onReceive: any }} transport
442
+ */
443
+ connect_peer(peer_id, transport) {
444
+ assert.isNonNegativeInteger(peer_id, 'peer_id');
445
+ if (this.#peers.has(peer_id)) {
446
+ throw new Error(`NetworkPeer.connect_peer: peer ${peer_id} already connected`);
447
+ }
448
+
449
+ const channel = new Channel({ transport });
450
+ const seq_to_frame_end = new Map();
451
+ const fragment_assembler = new FragmentAssembler();
452
+ const fragment_retention = new FragmentRetention();
453
+ const reliable_pipeline = new ReliableCommandPipeline({
454
+ channel,
455
+ packet_type: NetworkPacketType.RELIABLE_COMMAND,
456
+ });
457
+
458
+ // Closure captured once at connect time so the per-tick service
459
+ // call doesn't allocate. Builds a NACK_FRAGMENT packet inside
460
+ // the orchestrator's shared __send_buffer and ships it over the
461
+ // peer's channel. `indices[0..count)` is a reused internal
462
+ // scratch from the assembler — only valid for the call.
463
+ const on_nack = (message_id, indices, count) => {
464
+ this.#send_buffer.position = 0;
465
+ this.#send_buffer.writeUint8(NetworkPacketType.NACK_FRAGMENT);
466
+ this.#send_buffer.writeUint16LE(message_id);
467
+ this.#send_buffer.writeUint8(count);
468
+ for (let i = 0; i < count; i++) {
469
+ this.#send_buffer.writeUint8(indices[i]);
470
+ }
471
+ channel.send(this.#send_buffer.raw_bytes, this.#send_buffer.position);
472
+ };
473
+ // Forward pipeline deliveries to the user-facing signal, attributing
474
+ // them to the originating peer.
475
+ reliable_pipeline.onCommand.add((buf, payload_offset, payload_length) => {
476
+ this.onReliableCommand.send4(peer_id, buf, payload_offset, payload_length);
477
+ });
478
+
479
+ // Recursive dispatch helper. Used for both incoming transport bytes
480
+ // AND for reassembled FRAGMENT payloads (so the same switch handles
481
+ // both transparent and fragmented delivery of any packet type).
482
+ const dispatch = (bytes, length) => {
483
+ if (length < 1) {
484
+ // malformed: no type byte
485
+ return;
486
+ }
487
+
488
+ this.#recv_buffer.position = 0;
489
+ this.#recv_buffer.writeBytes(bytes, 0, length);
490
+ this.#recv_buffer.position = 0;
491
+
492
+ const packet_type = this.#recv_buffer.readUint8();
493
+
494
+ switch (packet_type) {
495
+ case NetworkPacketType.ACTION_STREAM:
496
+ // The Replicator opens a frame on the action log per packet
497
+ // (one per sender frame).
498
+ this.replicator.unpack_from_peer(peer_id, this.#recv_buffer, length);
499
+ break;
500
+ case NetworkPacketType.RECOVERY_REQUEST: {
501
+ const start_tick = this.#recv_buffer.readUintVar();
502
+ const end_tick = this.#recv_buffer.readUintVar();
503
+ this.onRecoveryRequest.send3(peer_id, start_tick, end_tick);
504
+ break;
505
+ }
506
+ case NetworkPacketType.STATE_BURST:
507
+ this.onStateBurst.send3(peer_id, this.#recv_buffer, length);
508
+ break;
509
+ case NetworkPacketType.AUTH_STATE: {
510
+ const frame_number = this.#recv_buffer.readUintVar();
511
+ const network_id = this.#recv_buffer.readUintVar();
512
+ this.onAuthState.send4(peer_id, frame_number, network_id, this.#recv_buffer);
513
+ break;
514
+ }
515
+ case NetworkPacketType.FRAGMENT: {
516
+ // Fragment header layout (after the leading type byte):
517
+ // uint16 message_id (LE), uint8 chunk_index, uint8 total_chunks
518
+ const message_id = this.#recv_buffer.readUint16LE();
519
+ const chunk_index = this.#recv_buffer.readUint8();
520
+ const total_chunks = this.#recv_buffer.readUint8();
521
+ const chunk_offset = this.#recv_buffer.position;
522
+ const chunk_length = length - chunk_offset;
523
+ const reassembled = fragment_assembler.receive(
524
+ message_id, chunk_index, total_chunks,
525
+ bytes, chunk_offset, chunk_length,
526
+ );
527
+ if (reassembled !== null) {
528
+ // Defence-in-depth: don't allow nested fragmentation
529
+ // (would indicate a sender bug; ignore silently).
530
+ if (reassembled[0] !== NetworkPacketType.FRAGMENT) {
531
+ dispatch(reassembled, reassembled.length);
532
+ }
533
+ }
534
+ break;
535
+ }
536
+ case NetworkPacketType.NACK_FRAGMENT: {
537
+ // Receiver is asking for specific chunks of a
538
+ // previously-sent fragmented message.
539
+ // uint16 message_id (LE), uint8 missing_count,
540
+ // uint8 missing_indices[missing_count]
541
+ const message_id = this.#recv_buffer.readUint16LE();
542
+ const missing_count = this.#recv_buffer.readUint8();
543
+ const entry = fragment_retention.consume_nack(message_id);
544
+ if (entry === null) {
545
+ // Either we never retained this id (already evicted /
546
+ // never sent), or the retry budget for it is exhausted.
547
+ // Either way: nothing to retransmit. Drop silently.
548
+ break;
549
+ }
550
+ for (let i = 0; i < missing_count; i++) {
551
+ const chunk_index = this.#recv_buffer.readUint8();
552
+ resend_fragment_chunk(
553
+ entry.payload, entry.length, message_id, chunk_index,
554
+ NetworkPacketType.FRAGMENT, this.#fragment_scratch,
555
+ (chunk_bytes, chunk_length) => channel.send(chunk_bytes, chunk_length),
556
+ );
557
+ }
558
+ break;
559
+ }
560
+ case NetworkPacketType.RELIABLE_COMMAND:
561
+ // Pipeline reads logical_seq, dedups, fires its onCommand
562
+ // (which we forward to the user's onReliableCommand above).
563
+ reliable_pipeline.handle_inbound(this.#recv_buffer, length);
564
+ break;
565
+ case NetworkPacketType.TIME_DILATION: {
566
+ const depth = this.#recv_buffer.readInt16();
567
+ this.onTimeDilationFeedback.send2(peer_id, depth);
568
+ break;
569
+ }
570
+ case NetworkPacketType.INITIAL_SYNC: {
571
+ if (this.#recv_buffer.position + 16 > length) {
572
+ throw new MalformedPacketError(`NetworkPeer.dispatch: INITIAL_SYNC truncated before 16-byte session token`);
573
+ }
574
+ const session_token = new Uint8Array(16);
575
+ this.#recv_buffer.readBytes(session_token, 0, 16);
576
+ const frame_number = this.#recv_buffer.readUintVar();
577
+ this.onInitialSync.send5(peer_id, session_token, frame_number, this.#recv_buffer, length);
578
+ break;
579
+ }
580
+ case NetworkPacketType.RESUME_HELLO: {
581
+ const local_peer_id = this.#recv_buffer.readUintVar();
582
+ const last_acked_frame = this.#recv_buffer.readUintVar();
583
+ if (this.#recv_buffer.position + 16 > length) {
584
+ throw new MalformedPacketError(`NetworkPeer.dispatch: RESUME_HELLO truncated before 16-byte session token`);
585
+ }
586
+ const session_token = new Uint8Array(16);
587
+ this.#recv_buffer.readBytes(session_token, 0, 16);
588
+ this.onResumeHello.send4(peer_id, local_peer_id, last_acked_frame, session_token);
589
+ break;
590
+ }
591
+ case NetworkPacketType.RESUME_ACCEPT: {
592
+ this.onResumeAccept.send1(peer_id);
593
+ break;
594
+ }
595
+ case NetworkPacketType.RESUME_REJECT: {
596
+ const reason_code = this.#recv_buffer.readUint8();
597
+ this.onResumeReject.send2(peer_id, reason_code);
598
+ break;
599
+ }
600
+ case NetworkPacketType.DISCONNECT: {
601
+ const label_length = this.#recv_buffer.readUint8();
602
+ let label = '';
603
+ if (label_length > 0) {
604
+ if (this.#recv_buffer.position + label_length > length) {
605
+ throw new MalformedPacketError(`NetworkPeer.dispatch: DISCONNECT label_length ${label_length} overruns packet`);
606
+ }
607
+ const label_bytes = new Uint8Array(label_length);
608
+ this.#recv_buffer.readBytes(label_bytes, 0, label_length);
609
+ label = DISCONNECT_TEXT_DECODER.decode(label_bytes);
610
+ }
611
+ this.onDisconnectPacket.send2(peer_id, label);
612
+ break;
613
+ }
614
+ default:
615
+ // Unknown type — drop. Forward-compat for newer peers.
616
+ break;
617
+ }
618
+ };
619
+
620
+ // Ack: advance Baseline to the highest acked frame_end for this peer.
621
+ const on_acked = (seq) => {
622
+ const frame_end = seq_to_frame_end.get(seq);
623
+ if (frame_end !== undefined) {
624
+ this.baseline.set_acked(peer_id, frame_end);
625
+ seq_to_frame_end.delete(seq);
626
+ }
627
+ };
628
+
629
+ // Loss: a packet that aged out of the ack window without being acked
630
+ // leaves a dead seq→frame_end entry. The baseline must NOT advance (the
631
+ // frame was never confirmed; back-fill resends it under a fresh seq), but
632
+ // the stale mapping should be reclaimed — otherwise lost-packet entries
633
+ // accumulate across the session until the seq value is reused on wrap.
634
+ const on_lost = (seq) => {
635
+ seq_to_frame_end.delete(seq);
636
+ };
637
+
638
+ // Untrusted-input boundary. A structurally-malformed or truncated
639
+ // packet (truncated datagram, spoofed/corrupt bytes, mismatched peer
640
+ // build) is dropped and counted the "discard the bad record, keep the
641
+ // connection" posture rather than throwing out of the transport's
642
+ // receive callback and crashing the process. A RangeError is a
643
+ // BinaryBuffer read past its backing store, i.e. the same malformed-
644
+ // input symptom. Any OTHER error is a genuine bug in a packet handler
645
+ // and is rethrown so it is not silently swallowed.
646
+ const payload_handler = (bytes, length) => {
647
+ // Liveness: any packet that reaches dispatch including empty-ack,
648
+ // and malformed ones dropped below is evidence the peer/transport
649
+ // is alive. Bump the per-peer inbound counter idle-detection polls.
650
+ const conn = this.#peers.get(peer_id);
651
+ if (conn !== undefined) conn.inbound_count++;
652
+ try {
653
+ dispatch(bytes, length);
654
+ } catch (e) {
655
+ if (e instanceof MalformedPacketError || e instanceof RangeError) {
656
+ this.#malformed_packets_dropped++;
657
+ this.onMalformedPacket.send2(peer_id, e);
658
+ return;
659
+ }
660
+ throw e;
661
+ }
662
+ };
663
+
664
+ channel.onPayload.add(payload_handler);
665
+ channel.onPacketAcked.add(on_acked);
666
+ channel.onPacketLost.add(on_lost);
667
+
668
+ this.#peers.set(peer_id, {
669
+ channel, transport, seq_to_frame_end,
670
+ on_payload: payload_handler, on_acked, on_lost, on_nack,
671
+ fragment_assembler, fragment_retention,
672
+ reliable_pipeline,
673
+ inbound_count: 0,
674
+ });
675
+ }
676
+
677
+ /**
678
+ * Unwire and forget a peer.
679
+ * @param {number} peer_id
680
+ */
681
+ disconnect_peer(peer_id) {
682
+ assert.isNonNegativeInteger(peer_id, 'peer_id');
683
+ const conn = this.#peers.get(peer_id);
684
+ if (conn === undefined) return;
685
+
686
+ conn.channel.onPayload.remove(conn.on_payload);
687
+ conn.channel.onPacketAcked.remove(conn.on_acked);
688
+ conn.channel.onPacketLost.remove(conn.on_lost);
689
+ // Drop the channel's subscription on the transport. Required for the
690
+ // common case of reusing the same transport on a subsequent reconnect:
691
+ // without this, the orphaned channel keeps consuming inbound packets
692
+ // and corrupts ack state in parallel with whatever channel replaces it.
693
+ conn.channel.dispose();
694
+
695
+ // Drop any in-flight fragment reassemblies for this peer — a fresh
696
+ // connection on the same peer_id should start clean.
697
+ conn.fragment_assembler.clear();
698
+ // Same for the sender-side retention buffer: nothing about the
699
+ // previous connection's retransmit history should leak across.
700
+ conn.fragment_retention.clear();
701
+
702
+ // Detach the reliable pipeline (drops its channel subscriptions and
703
+ // any unacked / received state).
704
+ conn.reliable_pipeline.dispose();
705
+
706
+ this.#peers.delete(peer_id);
707
+ this.baseline.forget(peer_id);
708
+ // Drop the replicator's apply watermark for this peer so a reconnect
709
+ // (or id reuse) isn't deduped against the previous connection's frames.
710
+ this.replicator.forget_peer(peer_id);
711
+ }
712
+
713
+ /**
714
+ * Whether `peer_id` is currently connected.
715
+ * @param {number} peer_id
716
+ * @returns {boolean}
717
+ */
718
+ is_connected(peer_id) {
719
+ return this.#peers.has(peer_id);
720
+ }
721
+
722
+ /**
723
+ * Number of inbound packets dropped so far because they were malformed
724
+ * (see {@link onMalformedPacket}). Monotonic for the life of the peer.
725
+ * @returns {number}
726
+ */
727
+ malformed_packets_dropped() {
728
+ return this.#malformed_packets_dropped;
729
+ }
730
+
731
+ /**
732
+ * Monotonic count of inbound packets delivered for `peer_id` since it
733
+ * connected — any packet that reached the dispatch boundary, including
734
+ * empty-ack and malformed ones (all evidence the peer/transport is alive).
735
+ * Returns 0 for an unknown peer. Idle/liveness detection polls this and
736
+ * reaps a peer whose count stops advancing.
737
+ * @param {number} peer_id
738
+ * @returns {number}
739
+ */
740
+ inbound_count(peer_id) {
741
+ const conn = this.#peers.get(peer_id);
742
+ return conn === undefined ? 0 : conn.inbound_count;
743
+ }
744
+
745
+ /**
746
+ * Direct access to a peer's channel (for sending acks-only packets, raw payloads, etc.).
747
+ * @param {number} peer_id
748
+ * @returns {Channel|undefined}
749
+ */
750
+ channel_for(peer_id) {
751
+ const conn = this.#peers.get(peer_id);
752
+ return conn === undefined ? undefined : conn.channel;
753
+ }
754
+
755
+ /**
756
+ * Open the action log for `frame_number`. Call before running game logic
757
+ * for the tick. The user's code (or the engine's `EntityManager.simulate`)
758
+ * runs between `begin_tick` and `end_tick`, calling `executor.execute()`
759
+ * for each replicated state mutation.
760
+ *
761
+ * @param {number} frame_number
762
+ */
763
+ begin_tick(frame_number) {
764
+ assert.isNonNegativeInteger(frame_number, 'frame_number');
765
+ if (this.#tick_open) {
766
+ throw new Error(`NetworkPeer.begin_tick: previous tick still open; call end_tick first`);
767
+ }
768
+ // Reset the per-tick changed-set so this tick starts with a blank slate.
769
+ if (this.#changed_entities !== null) this.#changed_entities.clear();
770
+ this.action_log.begin_frame(frame_number);
771
+ this.#tick_open = true;
772
+ this.#current_frame = frame_number;
773
+ }
774
+
775
+ /**
776
+ * Close the current tick and send pending action records to every peer.
777
+ * For each peer, packs frames `[Baseline.last_acked(peer) + 1, current_frame]`
778
+ * and sends via the channel; records the seq→frame_end mapping so the next
779
+ * ack from that peer advances the baseline.
780
+ *
781
+ * If a {@link MutationLedger} was supplied at construction, this tick's
782
+ * accumulated changed-entity set is also compacted into the ledger.
783
+ */
784
+ end_tick() {
785
+ if (!this.#tick_open) {
786
+ throw new Error(`NetworkPeer.end_tick: no tick is open; call begin_tick first`);
787
+ }
788
+ this.action_log.end_frame();
789
+ this.#tick_open = false;
790
+
791
+ this.flush_outbound(this.#current_frame);
792
+
793
+ // Per-tick fragment maintenance: age out sender-side retention
794
+ // and drive NACK emission for any incomplete inbound messages.
795
+ // Runs AFTER the action-stream send loop so the shared
796
+ // __send_buffer is free for the on_nack closure to reuse.
797
+ const now_ms = performance.now();
798
+ for (const [, conn] of this.#peers) {
799
+ conn.fragment_retention.service(now_ms);
800
+ conn.fragment_assembler.service(now_ms, conn.on_nack);
801
+ }
802
+ }
803
+
804
+ /**
805
+ * Pack and dispatch the outbound action stream for `current_frame` to
806
+ * every connected peer. Second half of {@link end_tick} — exposed
807
+ * separately so orchestrators that manage action_log frames directly
808
+ * (e.g. {@link ServerAuthoritativeServer}'s rollback flow, which
809
+ * begin_frame/end_frames many frames per tick) can drive the
810
+ * outbound dispatch without going through begin_tick/end_tick.
811
+ *
812
+ * Assumes the action_log frame for `current_frame` is already CLOSED
813
+ * by the caller. Records the tick's accumulated mutations into the
814
+ * MutationLedger (if configured), then packs frames
815
+ * `[last_acked+1, current_frame]` for each peer via
816
+ * `Replicator.pack_for_peer`. Empty packs (no in-scope actions) are
817
+ * not sent. Clears the per-tick changed-entity set after recording.
818
+ *
819
+ * @param {number} current_frame
820
+ */
821
+ flush_outbound(current_frame) {
822
+ assert.isNonNegativeInteger(current_frame, 'current_frame');
823
+
824
+ // Record this tick's mutations into the persistent ledger BEFORE sending.
825
+ // (Order doesn't strictly matter for correctness, but keeping the ledger
826
+ // up-to-date as soon as possible reduces edge-case race windows for
827
+ // recovery requests that arrive immediately after.)
828
+ if (this.mutation_ledger !== null && this.#changed_entities !== null) {
829
+ this.mutation_ledger.record_tick(current_frame, this.#changed_entities);
830
+ }
831
+
832
+ for (const [peer_id, conn] of this.#peers) {
833
+ const last_acked = this.baseline.last_acked(peer_id);
834
+ // Pack-range start.
835
+ //
836
+ // For peers with at least one acked frame, this is just
837
+ // last_acked+1 — the standard "catch up since you last
838
+ // confirmed receipt."
839
+ //
840
+ // For freshly-connected peers (no ack yet), we cover the
841
+ // action_log's full ring: max(0, current_frame -
842
+ // frame_capacity + 1). Two competing constraints:
843
+ //
844
+ // - Don't pack `current_frame` only: under any non-zero
845
+ // latency, A's actions tagged at frame X land on the
846
+ // server in `action_log[X]`, not `action_log[current]`.
847
+ // A relay peer (B) whose start is `current` would see
848
+ // an empty pack every tick no packet sent → B can't
849
+ // ack baseline never advances bootstrap deadlock.
850
+ // - Don't pack from frame 0: would waste bandwidth
851
+ // iterating frames the ring no longer holds. The `has_frame`
852
+ // guard inside pack_for_peer would skip them, but the
853
+ // loop bound itself can grow unboundedly with
854
+ // current_frame.
855
+ //
856
+ // `current_frame - frame_capacity + 1` is the oldest frame
857
+ // the ring could still hold, so we naturally cap at the
858
+ // ring's actual content. Actions referencing entities the
859
+ // peer's slot_table doesn't yet know about silently no-op
860
+ // (Replicator translates via network_for -1; SimAction
861
+ // apply hits the `if (local < 0) return` guard). For first-
862
+ // connect scenarios the app is still expected to send a
863
+ // state-burst seed; this just makes the action-stream
864
+ // bootstrap work in addition to that.
865
+ const start = last_acked < 0
866
+ ? Math.max(0, current_frame - this.action_log.frame_capacity + 1)
867
+ : last_acked + 1;
868
+ if (start > current_frame) continue;
869
+
870
+ this.#send_buffer.position = 0;
871
+ // Packet-type prefix.
872
+ this.#send_buffer.writeUint8(NetworkPacketType.ACTION_STREAM);
873
+ this.replicator.pack_for_peer(peer_id, start, current_frame, this.#send_buffer);
874
+ const length = this.#send_buffer.position;
875
+ // Just the prefix → no in-scope actions to send.
876
+ if (length === 1) continue;
877
+
878
+ const seq = this.#send_to_peer(conn, this.#send_buffer.raw_bytes, length);
879
+ conn.seq_to_frame_end.set(seq, current_frame);
880
+ }
881
+
882
+ // Reset the per-tick changed-entity set so the next tick starts clean.
883
+ // (begin_tick also clears it; the dual call is harmless.)
884
+ if (this.#changed_entities !== null) this.#changed_entities.clear();
885
+ }
886
+
887
+ /**
888
+ * Send a logical payload to a connected peer, fragmenting transparently
889
+ * if it exceeds the channel's single-packet capacity.
890
+ *
891
+ * Returns the seq of the FIRST transport packet emitted. For non-
892
+ * fragmented sends that's the only packet; for fragmented sends, that
893
+ * seq is what callers should record in `seq_to_frame_end` — when it
894
+ * acks, the first fragment arrived, which is a sufficient signal that
895
+ * the message is in flight. Fragments either all arrive (and the
896
+ * receiver reassembles) or the message is lost; the action-stream's
897
+ * back-fill mechanism naturally recovers from the latter on subsequent
898
+ * sends.
899
+ *
900
+ * @param {object} conn entry from __peers
901
+ * @param {Uint8Array} payload starts with the packet-type byte
902
+ * @param {number} length
903
+ * @returns {number} seq of the first packet sent
904
+ * @private
905
+ */
906
+ #send_to_peer(conn, payload, length) {
907
+ if (length <= MAX_CHANNEL_PAYLOAD_BYTES) {
908
+ return conn.channel.send(payload, length);
909
+ }
910
+ const message_id = this.#next_fragment_message_id;
911
+ this.#next_fragment_message_id = seq16_advance(this.#next_fragment_message_id);
912
+ // Retain the source bytes so we can satisfy NACK retransmits.
913
+ // Copy happens inside retain(); `payload` is the orchestrator's
914
+ // shared send buffer and will be overwritten by the next call.
915
+ conn.fragment_retention.retain(message_id, payload, length, performance.now());
916
+ let first_seq = -1;
917
+ send_fragmented(
918
+ payload, length, message_id,
919
+ NetworkPacketType.FRAGMENT, this.#fragment_scratch,
920
+ (chunk_bytes, chunk_length) => {
921
+ const seq = conn.channel.send(chunk_bytes, chunk_length);
922
+ if (first_seq < 0) first_seq = seq;
923
+ },
924
+ );
925
+ return first_seq;
926
+ }
927
+
928
+ /**
929
+ * Send a recovery request to `peer_id`: "tell me the current state of every
930
+ * entity that mutated between `start_tick` and `end_tick`." The peer's
931
+ * server-side handler ({@link onRecoveryRequest}) is expected to respond by
932
+ * calling {@link send_state_burst_for_range}.
933
+ *
934
+ * Best-effort delivery via the same UDP-style channel — if the request is
935
+ * lost, the client is expected to retry.
936
+ *
937
+ * @param {number} peer_id
938
+ * @param {number} start_tick
939
+ * @param {number} end_tick
940
+ */
941
+ send_recovery_request(peer_id, start_tick, end_tick) {
942
+ assert.isNonNegativeInteger(peer_id, 'peer_id');
943
+ assert.isNonNegativeInteger(start_tick, 'start_tick');
944
+ assert.isNonNegativeInteger(end_tick, 'end_tick');
945
+ const conn = this.#peers.get(peer_id);
946
+ if (conn === undefined) throw new Error(`NetworkPeer.send_recovery_request: peer ${peer_id} not connected`);
947
+
948
+ this.#send_buffer.position = 0;
949
+ this.#send_buffer.writeUint8(NetworkPacketType.RECOVERY_REQUEST);
950
+ this.#send_buffer.writeUintVar(start_tick);
951
+ this.#send_buffer.writeUintVar(end_tick);
952
+ this.#send_to_peer(conn, this.#send_buffer.raw_bytes, this.#send_buffer.position);
953
+ }
954
+
955
+ /**
956
+ * Server-side recovery response. Looks up which entities mutated in
957
+ * `[start_tick, end_tick]` via the local `MutationLedger` (must be present),
958
+ * then sends the current state of those entities to `peer_id` via a
959
+ * `STATE_BURST` packet. Receiver applies via `snapshotter_apply_to_existing`.
960
+ *
961
+ * If no entities are in the range (or the range is older than the ledger
962
+ * retains), nothing is sent. The requester should treat absence of response
963
+ * after a timeout as "needs full re-init."
964
+ *
965
+ * @param {number} peer_id
966
+ * @param {number} start_tick
967
+ * @param {number} end_tick
968
+ */
969
+ send_state_burst_for_range(peer_id, start_tick, end_tick) {
970
+ assert.isNonNegativeInteger(peer_id, 'peer_id');
971
+ assert.isNonNegativeInteger(start_tick, 'start_tick');
972
+ assert.isNonNegativeInteger(end_tick, 'end_tick');
973
+ if (this.mutation_ledger === null) {
974
+ throw new Error('NetworkPeer.send_state_burst_for_range: requires mutation_ledger to be configured');
975
+ }
976
+ const conn = this.#peers.get(peer_id);
977
+ if (conn === undefined) throw new Error(`NetworkPeer.send_state_burst_for_range: peer ${peer_id} not connected`);
978
+
979
+ // Reuse the changed-set as a scratch dedupe surface for the union.
980
+ // It's been cleared at the start of this tick (or hasn't been used yet);
981
+ // it will be cleared again at the start of the next tick.
982
+ const scratch = this.#changed_entities !== null
983
+ ? this.#changed_entities
984
+ : new ChangedEntitySet({ capacity: 1024 });
985
+ // Don't clobber an in-progress tick's accumulated mutations. If a tick
986
+ // is currently open we use a fresh set just for this query.
987
+ const set = this.#tick_open
988
+ ? new ChangedEntitySet({ capacity: 1024 })
989
+ : scratch;
990
+ set.clear();
991
+
992
+ this.mutation_ledger.entities_changed_in_range(set, start_tick, end_tick);
993
+ if (set.size() === 0) return;
994
+
995
+ this.#send_buffer.position = 0;
996
+ this.#send_buffer.writeUint8(NetworkPacketType.STATE_BURST);
997
+ snapshotter_emit({
998
+ buffer: this.#send_buffer,
999
+ world: this.world,
1000
+ slot_table: this.slot_table,
1001
+ component_registry: this.component_registry,
1002
+ entity_iter: cb => {
1003
+ set.for_each(network_id => {
1004
+ const eid = this.slot_table.entity_for(network_id);
1005
+ if (eid >= 0) cb(eid);
1006
+ });
1007
+ },
1008
+ });
1009
+ // STATE_BURST is the primary path that can exceed MTU — a recovery
1010
+ // response covering many entities easily lands in the multi-KB range.
1011
+ // The fragmenting wrapper splits it across packets transparently.
1012
+ this.#send_to_peer(conn, this.#send_buffer.raw_bytes, this.#send_buffer.position);
1013
+ }
1014
+
1015
+ /**
1016
+ * Send the authoritative state of one entity to `peer_id`, tagged with
1017
+ * the frame the state represents. Used by client-side prediction: the
1018
+ * server emits this every tick (or every N ticks) for client-owned
1019
+ * entities; the client compares to its predicted state at the same frame
1020
+ * and reconciles via rewind+replay if they differ.
1021
+ *
1022
+ * The payload is whatever `write_fn(buffer)` writes — typically a
1023
+ * `BinaryClassSerializationAdapter.serialize(buffer, component)` call.
1024
+ * The receiver's `onAuthState` handler reads the same bytes via the
1025
+ * matching deserializer.
1026
+ *
1027
+ * @param {number} peer_id
1028
+ * @param {number} frame_number sender's frame the state corresponds to
1029
+ * @param {number} network_id which entity this state is for
1030
+ * @param {function(BinaryBuffer): void} write_fn writes the entity's state bytes
1031
+ */
1032
+ send_auth_state(peer_id, frame_number, network_id, write_fn) {
1033
+ assert.isNonNegativeInteger(peer_id, 'peer_id');
1034
+ assert.isNonNegativeInteger(frame_number, 'frame_number');
1035
+ assert.isNonNegativeInteger(network_id, 'network_id');
1036
+ assert.isFunction(write_fn, 'write_fn');
1037
+ const conn = this.#peers.get(peer_id);
1038
+ if (conn === undefined) throw new Error(`NetworkPeer.send_auth_state: peer ${peer_id} not connected`);
1039
+
1040
+ this.#send_buffer.position = 0;
1041
+ this.#send_buffer.writeUint8(NetworkPacketType.AUTH_STATE);
1042
+ this.#send_buffer.writeUintVar(frame_number);
1043
+ this.#send_buffer.writeUintVar(network_id);
1044
+ write_fn(this.#send_buffer);
1045
+ this.#send_to_peer(conn, this.#send_buffer.raw_bytes, this.#send_buffer.position);
1046
+ }
1047
+
1048
+ /**
1049
+ * Send an INITIAL_SYNC packet. `write_fn` receives the send-buffer
1050
+ * positioned just past the `(packet_type, session_token, frame_number)`
1051
+ * header and writes the Snapshotter payload. Fragments transparently.
1052
+ *
1053
+ * @param {number} peer_id
1054
+ * @param {Uint8Array} session_token 16-byte UUID v1 identifying this peer-session
1055
+ * @param {number} frame_number server sim frame this snapshot represents
1056
+ * @param {function(BinaryBuffer): void} write_fn
1057
+ */
1058
+ send_initial_sync(peer_id, session_token, frame_number, write_fn) {
1059
+ assert.isNonNegativeInteger(peer_id, 'peer_id');
1060
+ assert.ok(session_token instanceof Uint8Array && session_token.length === 16,
1061
+ 'session_token must be a 16-byte Uint8Array');
1062
+ assert.isNonNegativeInteger(frame_number, 'frame_number');
1063
+ assert.isFunction(write_fn, 'write_fn');
1064
+ const conn = this.#peers.get(peer_id);
1065
+ if (conn === undefined) throw new Error(`NetworkPeer.send_initial_sync: peer ${peer_id} not connected`);
1066
+
1067
+ this.#send_buffer.position = 0;
1068
+ this.#send_buffer.writeUint8(NetworkPacketType.INITIAL_SYNC);
1069
+ this.#send_buffer.writeBytes(session_token, 0, 16);
1070
+ this.#send_buffer.writeUintVar(frame_number);
1071
+ write_fn(this.#send_buffer);
1072
+ this.#send_to_peer(conn, this.#send_buffer.raw_bytes, this.#send_buffer.position);
1073
+ }
1074
+
1075
+ /**
1076
+ * Send a RESUME_HELLO packet to the server. Client-only direction.
1077
+ *
1078
+ * @param {number} peer_id remote peer (the server)
1079
+ * @param {number} local_peer_id the client's own peer id
1080
+ * @param {number} last_acked_frame the client's view of last-acked frame
1081
+ * @param {Uint8Array} session_token 16-byte token from a prior INITIAL_SYNC
1082
+ */
1083
+ send_resume_hello(peer_id, local_peer_id, last_acked_frame, session_token) {
1084
+ assert.isNonNegativeInteger(peer_id, 'peer_id');
1085
+ assert.isNonNegativeInteger(local_peer_id, 'local_peer_id');
1086
+ assert.isNonNegativeInteger(last_acked_frame, 'last_acked_frame');
1087
+ assert.ok(session_token instanceof Uint8Array && session_token.length === 16,
1088
+ 'session_token must be a 16-byte Uint8Array');
1089
+ const conn = this.#peers.get(peer_id);
1090
+ if (conn === undefined) throw new Error(`NetworkPeer.send_resume_hello: peer ${peer_id} not connected`);
1091
+
1092
+ this.#send_buffer.position = 0;
1093
+ this.#send_buffer.writeUint8(NetworkPacketType.RESUME_HELLO);
1094
+ this.#send_buffer.writeUintVar(local_peer_id);
1095
+ this.#send_buffer.writeUintVar(last_acked_frame);
1096
+ this.#send_buffer.writeBytes(session_token, 0, 16);
1097
+ this.#send_to_peer(conn, this.#send_buffer.raw_bytes, this.#send_buffer.position);
1098
+ }
1099
+
1100
+ /**
1101
+ * Send a RESUME_ACCEPT packet. Host-only direction.
1102
+ * @param {number} peer_id
1103
+ */
1104
+ send_resume_accept(peer_id) {
1105
+ assert.isNonNegativeInteger(peer_id, 'peer_id');
1106
+ const conn = this.#peers.get(peer_id);
1107
+ if (conn === undefined) throw new Error(`NetworkPeer.send_resume_accept: peer ${peer_id} not connected`);
1108
+
1109
+ this.#send_buffer.position = 0;
1110
+ this.#send_buffer.writeUint8(NetworkPacketType.RESUME_ACCEPT);
1111
+ this.#send_to_peer(conn, this.#send_buffer.raw_bytes, this.#send_buffer.position);
1112
+ }
1113
+
1114
+ /**
1115
+ * Send a RESUME_REJECT packet. Host-only direction.
1116
+ * @param {number} peer_id
1117
+ * @param {number} reason_code one of {@link ResumeRejectReason}
1118
+ */
1119
+ send_resume_reject(peer_id, reason_code) {
1120
+ assert.isNonNegativeInteger(peer_id, 'peer_id');
1121
+ assert.isNonNegativeInteger(reason_code, 'reason_code');
1122
+ const conn = this.#peers.get(peer_id);
1123
+ if (conn === undefined) throw new Error(`NetworkPeer.send_resume_reject: peer ${peer_id} not connected`);
1124
+
1125
+ this.#send_buffer.position = 0;
1126
+ this.#send_buffer.writeUint8(NetworkPacketType.RESUME_REJECT);
1127
+ this.#send_buffer.writeUint8(reason_code & 0xFF);
1128
+ this.#send_to_peer(conn, this.#send_buffer.raw_bytes, this.#send_buffer.position);
1129
+ }
1130
+
1131
+ /**
1132
+ * Send a DISCONNECT packet. Either direction. `reason_label` is an
1133
+ * opaque string (255 byte cap after UTF-8 encoding).
1134
+ *
1135
+ * @param {number} peer_id
1136
+ * @param {string} [reason_label]
1137
+ */
1138
+ send_disconnect(peer_id, reason_label = '') {
1139
+ assert.isNonNegativeInteger(peer_id, 'peer_id');
1140
+ assert.isString(reason_label, 'reason_label');
1141
+ const conn = this.#peers.get(peer_id);
1142
+ if (conn === undefined) throw new Error(`NetworkPeer.send_disconnect: peer ${peer_id} not connected`);
1143
+
1144
+ const encoded = DISCONNECT_TEXT_ENCODER.encode(reason_label);
1145
+ const len = Math.min(encoded.length, 255);
1146
+
1147
+ this.#send_buffer.position = 0;
1148
+ this.#send_buffer.writeUint8(NetworkPacketType.DISCONNECT);
1149
+ this.#send_buffer.writeUint8(len);
1150
+ if (len > 0) this.#send_buffer.writeBytes(encoded, 0, len);
1151
+ this.#send_to_peer(conn, this.#send_buffer.raw_bytes, this.#send_buffer.position);
1152
+ }
1153
+
1154
+ /**
1155
+ * Send a TIME_DILATION feedback packet. `buffer_depth` is clamped
1156
+ * to the int16 range — saturating is fine since the controller
1157
+ * doesn't need sub-int16 precision.
1158
+ *
1159
+ * @param {number} peer_id
1160
+ * @param {number} buffer_depth signed integer; clamped to int16
1161
+ */
1162
+ send_time_dilation_feedback(peer_id, buffer_depth) {
1163
+ assert.isNonNegativeInteger(peer_id, 'peer_id');
1164
+ assert.isNumber(buffer_depth, 'buffer_depth');
1165
+ const conn = this.#peers.get(peer_id);
1166
+ if (conn === undefined) throw new Error(`NetworkPeer.send_time_dilation_feedback: peer ${peer_id} not connected`);
1167
+
1168
+ let depth = buffer_depth | 0;
1169
+ if (depth > 32767) depth = 32767;
1170
+ else if (depth < -32768) depth = -32768;
1171
+
1172
+ this.#send_buffer.position = 0;
1173
+ this.#send_buffer.writeUint8(NetworkPacketType.TIME_DILATION);
1174
+ this.#send_buffer.writeInt16(depth);
1175
+ this.#send_to_peer(conn, this.#send_buffer.raw_bytes, this.#send_buffer.position);
1176
+ }
1177
+
1178
+ /**
1179
+ * Send a reliable command to a connected peer. Delivered at-least-once
1180
+ * with sender-side retransmit on Channel-detected loss and receiver-
1181
+ * side dedup by logical seq. Use for messages where the action-stream
1182
+ * model (best-effort, per-frame back-fill) isn't suitable — chat,
1183
+ * lobby/room state, level transitions.
1184
+ *
1185
+ * Returns the logical seq the pipeline assigned (diagnostic only; the
1186
+ * receiver dedups internally regardless).
1187
+ *
1188
+ * @param {number} peer_id
1189
+ * @param {Uint8Array} payload
1190
+ * @param {number} length
1191
+ * @returns {number} logical seq
1192
+ */
1193
+ send_reliable_command(peer_id, payload, length) {
1194
+ assert.isNonNegativeInteger(peer_id, 'peer_id');
1195
+ assert.isNonNegativeInteger(length, 'length');
1196
+ const conn = this.#peers.get(peer_id);
1197
+ if (conn === undefined) {
1198
+ throw new Error(`NetworkPeer.send_reliable_command: peer ${peer_id} not connected`);
1199
+ }
1200
+ return conn.reliable_pipeline.send(payload, length);
1201
+ }
1202
+ }