@series-inc/rundot-syncplay 6.0.0-rc.2 → 6.0.0-rc.21

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 (329) hide show
  1. package/README.md +133 -0
  2. package/core/deterministic-math.d.ts +75 -1
  3. package/core/native/instance_ledger.hpp +1095 -0
  4. package/core/native/legacy_checkpoint_ids.hpp +107 -0
  5. package/core/native/physics/abi.cpp +39 -211
  6. package/core/native/physics/abi.hpp +2 -6
  7. package/core/native/physics/articulation.cpp +1434 -0
  8. package/core/native/physics/articulation.hpp +279 -0
  9. package/core/native/physics/buoyancy.cpp +1588 -0
  10. package/core/native/physics/buoyancy.hpp +254 -0
  11. package/core/native/physics/capsule_triangle.cpp +168 -0
  12. package/core/native/physics/capsule_triangle.hpp +40 -0
  13. package/core/native/physics/capsule_triangle_native.inc +291 -0
  14. package/core/native/physics/certified_sum.hpp +218 -0
  15. package/core/native/physics/character.cpp +638 -0
  16. package/core/native/physics/character.hpp +169 -0
  17. package/core/native/physics/checkpoint_schema.hpp +379 -0
  18. package/core/native/physics/cloth.cpp +1401 -0
  19. package/core/native/physics/cloth.hpp +357 -0
  20. package/core/native/physics/constraint_rows.cpp +363 -2
  21. package/core/native/physics/constraint_rows.hpp +72 -1
  22. package/core/native/physics/deformable_query.cpp +1630 -0
  23. package/core/native/physics/deformable_query.hpp +578 -0
  24. package/core/native/physics/distance.cpp +1166 -0
  25. package/core/native/physics/distance.hpp +151 -0
  26. package/core/native/physics/exact/exact-applied.cpp +101 -0
  27. package/core/native/physics/exact/exact-applied.hpp +112 -0
  28. package/core/native/physics/exact/exact-dyadic.cpp +691 -0
  29. package/core/native/physics/exact/exact-dyadic.hpp +58 -0
  30. package/core/native/physics/exact/exact-operation.hpp +51 -0
  31. package/core/native/physics/exact/word-core.hpp +262 -0
  32. package/core/native/physics/extended_abi.cpp +1242 -0
  33. package/core/native/physics/extended_abi.hpp +355 -0
  34. package/core/native/physics/extended_abi_characters.cpp +261 -0
  35. package/core/native/physics/extended_abi_characters.hpp +434 -0
  36. package/core/native/physics/extended_abi_core_features.cpp +713 -0
  37. package/core/native/physics/extended_abi_core_features.hpp +226 -0
  38. package/core/native/physics/extended_abi_deformables.cpp +448 -0
  39. package/core/native/physics/extended_abi_deformables.hpp +867 -0
  40. package/core/native/physics/extended_abi_vehicles.cpp +411 -0
  41. package/core/native/physics/extended_abi_vehicles.hpp +222 -0
  42. package/core/native/physics/fracture.cpp +1981 -0
  43. package/core/native/physics/fracture.hpp +460 -0
  44. package/core/native/physics/gear.cpp +563 -0
  45. package/core/native/physics/gear.hpp +158 -0
  46. package/core/native/physics/geometry_memory.hpp +476 -0
  47. package/core/native/physics/geometry_store.cpp +547 -0
  48. package/core/native/physics/geometry_store.hpp +134 -0
  49. package/core/native/physics/lag_compensation.cpp +1626 -0
  50. package/core/native/physics/lag_compensation.hpp +405 -0
  51. package/core/native/physics/mass_properties.cpp +449 -0
  52. package/core/native/physics/mass_properties.hpp +23 -0
  53. package/core/native/physics/material_pose.hpp +988 -0
  54. package/core/native/physics/particles.cpp +1065 -0
  55. package/core/native/physics/particles.hpp +261 -0
  56. package/core/native/physics/path_joint.cpp +781 -0
  57. package/core/native/physics/path_joint.hpp +154 -0
  58. package/core/native/physics/physics.cpp +13043 -1065
  59. package/core/native/physics/physics.hpp +184 -8
  60. package/core/native/physics/planar_deformable.cpp +2433 -0
  61. package/core/native/physics/planar_deformable.hpp +889 -0
  62. package/core/native/physics/platformer_2d.cpp +1353 -0
  63. package/core/native/physics/platformer_2d.hpp +340 -0
  64. package/core/native/physics/powered_ragdoll.cpp +1100 -0
  65. package/core/native/physics/powered_ragdoll.hpp +279 -0
  66. package/core/native/physics/powertrain.cpp +586 -0
  67. package/core/native/physics/powertrain.hpp +180 -0
  68. package/core/native/physics/pulley.cpp +311 -0
  69. package/core/native/physics/pulley.hpp +121 -0
  70. package/core/native/physics/ragdoll.cpp +586 -0
  71. package/core/native/physics/ragdoll.hpp +221 -0
  72. package/core/native/physics/rope.cpp +692 -0
  73. package/core/native/physics/rope.hpp +215 -0
  74. package/core/native/physics/rounded_convex.cpp +1229 -0
  75. package/core/native/physics/rounded_convex.hpp +287 -0
  76. package/core/native/physics/sdf_geometry.cpp +1821 -0
  77. package/core/native/physics/sdf_geometry.hpp +474 -0
  78. package/core/native/physics/soft_body.cpp +1449 -0
  79. package/core/native/physics/soft_body.hpp +328 -0
  80. package/core/native/physics/soft_collision.cpp +1862 -0
  81. package/core/native/physics/soft_collision.hpp +561 -0
  82. package/core/native/physics/surface_velocity.cpp +366 -0
  83. package/core/native/physics/surface_velocity.hpp +243 -0
  84. package/core/native/physics/topology.cpp +357 -39
  85. package/core/native/physics/topology.hpp +97 -6
  86. package/core/native/physics/tracks.cpp +1179 -0
  87. package/core/native/physics/tracks.hpp +404 -0
  88. package/core/native/physics/vehicle.cpp +629 -0
  89. package/core/native/physics/vehicle.hpp +191 -0
  90. package/core/native/physics/voxel_cooking.cpp +1929 -0
  91. package/core/native/physics/voxel_cooking.hpp +395 -0
  92. package/core/native/physics/world.cpp +5290 -854
  93. package/core/native/physics/world.hpp +796 -24
  94. package/core/native/physics/world_abi.cpp +3840 -306
  95. package/core/native/physics/world_abi.hpp +530 -10
  96. package/core/native/physics/world_digest_visitor.hpp +277 -0
  97. package/core/native/physics/world_strong_digest.hpp +557 -0
  98. package/core/native/physics2d/ccd.cpp +1302 -0
  99. package/core/native/physics2d/ccd.hpp +141 -0
  100. package/core/native/physics2d/checkpoint_memory.hpp +349 -0
  101. package/core/native/physics2d/clock_primitives.hpp +138 -0
  102. package/core/native/physics2d/commands.cpp +174 -28
  103. package/core/native/physics2d/commands.hpp +3 -1
  104. package/core/native/physics2d/compound.cpp +581 -0
  105. package/core/native/physics2d/compound.hpp +248 -0
  106. package/core/native/physics2d/contour.cpp +325 -0
  107. package/core/native/physics2d/contour.hpp +143 -0
  108. package/core/native/physics2d/frame_scope.hpp +124 -0
  109. package/core/native/physics2d/joint_phases.hpp +93 -0
  110. package/core/native/physics2d/joints.cpp +587 -150
  111. package/core/native/physics2d/joints.hpp +5 -0
  112. package/core/native/physics2d/memory_private.hpp +125 -0
  113. package/core/native/physics2d/owned_abi.cpp +1354 -879
  114. package/core/native/physics2d/owned_abi.hpp +190 -52
  115. package/core/native/physics2d/phase_test_hooks.hpp +17 -0
  116. package/core/native/physics2d/physics2d.cpp +2073 -120
  117. package/core/native/physics2d/physics2d.hpp +154 -2
  118. package/core/native/physics2d/queries.cpp +1055 -79
  119. package/core/native/physics2d/queries.hpp +71 -5
  120. package/core/native/physics2d/world.cpp +1313 -353
  121. package/core/native/physics2d/world.hpp +124 -13
  122. package/core/native/sha256/sha256_compress_unsigned.hpp +68 -0
  123. package/core/native/sha256/sha256_fips_constants.hpp +24 -0
  124. package/core/native/sha256/sha256_length.hpp +56 -0
  125. package/core/native/sha256/sha256_memo.hpp +48 -0
  126. package/core/native/sha256/sha256_sink.hpp +234 -0
  127. package/core/physics2d-owned.d.ts +466 -126
  128. package/core/runtime.d.ts +192 -19
  129. package/core/scripts/build-native.mjs +34 -0
  130. package/core/scripts/build-wasm-physics.mjs +272 -23
  131. package/core/scripts/extended-physics-profile.mjs +634 -0
  132. package/core/scripts/generate-physics2d-vectors.mjs +59 -0
  133. package/core/src/kinetix-deterministic-math.d.ts +2 -0
  134. package/core/src/kinetix-deterministic-math.mjs +513 -27
  135. package/core/src/kinetix-owned-runtime-adapter.mjs +788 -0
  136. package/core/src/kinetix-runtime-adapter-utils.mjs +54 -6
  137. package/core/src/kinetix-runtime-contract.mjs +55 -9
  138. package/core/src/kinetix-runtime-identity.mjs +12 -1
  139. package/core/src/kinetix-session-config.mjs +7 -2
  140. package/core/src/kinetix-state-report.mjs +36 -0
  141. package/core/src/physics/abi-constants.mjs +5 -4
  142. package/core/src/physics/articulation.d.mts +194 -0
  143. package/core/src/physics/articulation.mjs +1141 -0
  144. package/core/src/physics/buoyancy.d.mts +143 -0
  145. package/core/src/physics/buoyancy.mjs +268 -0
  146. package/core/src/physics/cloth.d.mts +314 -0
  147. package/core/src/physics/cloth.mjs +1156 -0
  148. package/core/src/physics/deformable-query.d.mts +217 -0
  149. package/core/src/physics/deformable-query.mjs +1412 -0
  150. package/core/src/physics/distance.d.mts +160 -0
  151. package/core/src/physics/distance.mjs +175 -0
  152. package/core/src/physics/extended-wasm-instance.d.mts +5 -0
  153. package/core/src/physics/extended-wasm-instance.mjs +48 -0
  154. package/core/src/physics/feature-api.d.mts +74 -0
  155. package/core/src/physics/feature-api.mjs +98 -0
  156. package/core/src/physics/fracture.d.mts +133 -0
  157. package/core/src/physics/fracture.mjs +1324 -0
  158. package/core/src/physics/gear.d.mts +585 -0
  159. package/core/src/physics/gear.mjs +955 -0
  160. package/core/src/physics/lag-compensation.d.mts +101 -0
  161. package/core/src/physics/lag-compensation.mjs +1100 -0
  162. package/core/src/physics/mass-properties.d.mts +114 -0
  163. package/core/src/physics/mass-properties.mjs +137 -468
  164. package/core/src/physics/particles.d.mts +177 -0
  165. package/core/src/physics/particles.mjs +758 -0
  166. package/core/src/physics/path-joint.d.mts +171 -0
  167. package/core/src/physics/path-joint.mjs +1231 -0
  168. package/core/src/physics/physics-extended-wasm-module.generated.mjs +13 -0
  169. package/core/src/physics/physics-profile-wasm-module.generated.mjs +48 -0
  170. package/core/src/physics/physics-wasm-module.generated.mjs +34 -5
  171. package/core/src/physics/powered-ragdoll.d.mts +188 -0
  172. package/core/src/physics/powered-ragdoll.mjs +1043 -0
  173. package/core/src/physics/powertrain.d.mts +260 -0
  174. package/core/src/physics/powertrain.mjs +621 -0
  175. package/core/src/physics/pulley.d.mts +98 -0
  176. package/core/src/physics/pulley.mjs +686 -0
  177. package/core/src/physics/ragdoll.d.mts +289 -0
  178. package/core/src/physics/ragdoll.mjs +1323 -0
  179. package/core/src/physics/rope.d.mts +241 -0
  180. package/core/src/physics/rope.mjs +319 -0
  181. package/core/src/physics/rounded-convex.d.mts +328 -0
  182. package/core/src/physics/rounded-convex.mjs +1404 -0
  183. package/core/src/physics/sdf-geometry.d.mts +117 -0
  184. package/core/src/physics/sdf-geometry.mjs +1204 -0
  185. package/core/src/physics/soft-body.d.mts +144 -0
  186. package/core/src/physics/soft-body.mjs +1285 -0
  187. package/core/src/physics/soft-collision.d.mts +651 -0
  188. package/core/src/physics/soft-collision.mjs +1883 -0
  189. package/core/src/physics/surface-velocity.d.mts +156 -0
  190. package/core/src/physics/surface-velocity.mjs +722 -0
  191. package/core/src/physics/tracks.d.mts +411 -0
  192. package/core/src/physics/tracks.mjs +1074 -0
  193. package/core/src/physics/vehicle.d.mts +3 -0
  194. package/core/src/physics/vehicle.mjs +172 -0
  195. package/core/src/physics/voxel-cooking.d.mts +219 -0
  196. package/core/src/physics/voxel-cooking.mjs +1499 -0
  197. package/core/src/physics/voxel-swept-quad.mjs +110 -0
  198. package/core/src/physics/wasm-instance.mjs +160 -23
  199. package/core/src/physics/world.d.mts +62 -0
  200. package/core/src/physics/world.mjs +1947 -152
  201. package/core/src/physics2d/body-state.mjs +218 -15
  202. package/core/src/physics2d/collision.d.mts +52 -0
  203. package/core/src/physics2d/collision.mjs +234 -0
  204. package/core/src/physics2d/compound.mjs +454 -0
  205. package/core/src/physics2d/contour-state.mjs +771 -0
  206. package/core/src/physics2d/feature-api.d.mts +211 -0
  207. package/core/src/physics2d/feature-api.mjs +3 -0
  208. package/core/src/physics2d/fluid-state.mjs +145 -0
  209. package/core/src/physics2d/joint-state.mjs +1 -1
  210. package/core/src/physics2d/owned-queries.mjs +3 -1
  211. package/core/src/physics2d/owned-transport.mjs +268 -122
  212. package/core/src/physics2d/owned-world.mjs +353 -230
  213. package/core/src/physics2d/particle-fluid.d.mts +152 -0
  214. package/core/src/physics2d/particle-fluid.mjs +233 -0
  215. package/core/src/physics2d/physics2d-wasm-module.generated.mjs +27 -10
  216. package/core/src/physics2d/query-codec.mjs +61 -13
  217. package/core/src/physics2d/submerged-geometry.d.mts +51 -0
  218. package/core/src/physics2d/submerged-geometry.mjs +186 -0
  219. package/core/src/runtime.mjs +23 -0
  220. package/core/src/shared/bytes.d.mts +2 -0
  221. package/core/src/shared/bytes.mjs +33 -0
  222. package/core/src/shared/sha256.d.mts +3 -0
  223. package/core/src/shared/sha256.mjs +72 -22
  224. package/core/units.d.ts +50 -0
  225. package/core/world.d.ts +253 -5
  226. package/dist/authority-room.d.ts +9 -0
  227. package/dist/authority-room.js +45 -16
  228. package/dist/browser.d.ts +6 -5
  229. package/dist/browser.js +4 -3
  230. package/dist/cadence.d.ts +7 -0
  231. package/dist/cadence.js +19 -0
  232. package/dist/canonical.d.ts +1 -0
  233. package/dist/canonical.js +3 -0
  234. package/dist/checksum-policy.d.ts +10 -0
  235. package/dist/checksum-policy.js +14 -0
  236. package/dist/collider-cooking-hull.d.ts +18 -0
  237. package/dist/collider-cooking-hull.js +248 -0
  238. package/dist/collider-cooking.d.ts +140 -0
  239. package/dist/collider-cooking.js +794 -0
  240. package/dist/compat/v5.d.ts +121 -0
  241. package/dist/compat/v5.js +479 -0
  242. package/dist/creator.d.ts +7 -6
  243. package/dist/creator.js +4 -3
  244. package/dist/game-byte-section.d.ts +36 -0
  245. package/dist/game-byte-section.js +350 -0
  246. package/dist/index.d.ts +13 -6
  247. package/dist/index.js +9 -4
  248. package/dist/instant-replay.d.ts +27 -2
  249. package/dist/instant-replay.js +91 -16
  250. package/dist/lag-compensation3d.js +11 -10
  251. package/dist/match-log.d.ts +21 -4
  252. package/dist/match-log.js +92 -9
  253. package/dist/math.d.ts +2 -0
  254. package/dist/math.js +1 -0
  255. package/dist/modules/character-3d.d.ts +16 -1
  256. package/dist/modules/character-3d.js +42 -5
  257. package/dist/modules/combat.js +6 -5
  258. package/dist/movement3d-revision1.d.ts +2 -0
  259. package/dist/movement3d-revision1.js +973 -0
  260. package/dist/movement3d.d.ts +53 -3
  261. package/dist/movement3d.js +917 -247
  262. package/dist/networked-client.d.ts +15 -0
  263. package/dist/networked-client.js +378 -105
  264. package/dist/node.d.ts +3 -2
  265. package/dist/node.js +2 -1
  266. package/dist/physics/2d.d.ts +38 -4
  267. package/dist/physics/2d.js +57 -36
  268. package/dist/physics/3d.d.ts +755 -111
  269. package/dist/physics/3d.js +2355 -158
  270. package/dist/physics/edit-result-graph.d.ts +36 -0
  271. package/dist/physics/edit-result-graph.js +141 -0
  272. package/dist/physics/game-codec3d.d.ts +41 -0
  273. package/dist/physics/game-codec3d.js +544 -0
  274. package/dist/physics/installed-checkpoint3d.d.ts +13 -0
  275. package/dist/physics/installed-checkpoint3d.js +120 -0
  276. package/dist/physics/installed-runtime3d.d.ts +51 -0
  277. package/dist/physics/installed-runtime3d.js +372 -0
  278. package/dist/physics/installed-state-commitment3d.d.ts +2 -0
  279. package/dist/physics/installed-state-commitment3d.js +24 -0
  280. package/dist/physics/units.d.ts +38 -0
  281. package/dist/physics/units.js +56 -0
  282. package/dist/physics/vehicle-state3d.d.ts +93 -0
  283. package/dist/physics/vehicle-state3d.js +1191 -0
  284. package/dist/physics/voxel-body-state.d.ts +61 -0
  285. package/dist/physics/voxel-body-state.js +410 -0
  286. package/dist/r3f-render-adapter.d.ts +59 -1
  287. package/dist/r3f-render-adapter.js +137 -2
  288. package/dist/replay.d.ts +13 -0
  289. package/dist/replay.js +95 -70
  290. package/dist/run-room-transport.js +5 -1
  291. package/dist/runner.d.ts +17 -2
  292. package/dist/runner.js +472 -84
  293. package/dist/runtime-cleanup.d.ts +54 -0
  294. package/dist/runtime-cleanup.js +266 -0
  295. package/dist/runtime-lease.d.ts +11 -1
  296. package/dist/runtime-lease.js +23 -10
  297. package/dist/runtime-room-metadata.d.ts +2 -8
  298. package/dist/runtime-room-metadata.js +11 -14
  299. package/dist/runtime-session.d.ts +8 -0
  300. package/dist/runtime-session.js +222 -58
  301. package/dist/schema-codegen.js +3 -0
  302. package/dist/schema-dsl-binary.d.ts +10 -4
  303. package/dist/schema-dsl-binary.js +375 -76
  304. package/dist/scratch-pool.d.ts +32 -0
  305. package/dist/scratch-pool.js +60 -0
  306. package/dist/sdk-session.d.ts +1 -0
  307. package/dist/sdk-session.js +4 -0
  308. package/dist/secret-config.js +2 -60
  309. package/dist/secret-crypto.js +70 -36
  310. package/dist/session-snapshot.d.ts +15 -4
  311. package/dist/session-snapshot.js +35 -33
  312. package/dist/session-wire.js +14 -22
  313. package/dist/sparse-set.d.ts +1 -0
  314. package/dist/sparse-set.js +22 -0
  315. package/dist/spatial/spatial-grid-3d.d.ts +41 -0
  316. package/dist/spatial/spatial-grid-3d.js +115 -0
  317. package/dist/synctest.d.ts +9 -0
  318. package/dist/synctest.js +106 -17
  319. package/dist/testing-network.d.ts +2 -0
  320. package/dist/testing-network.js +122 -18
  321. package/dist/testing.d.ts +27 -6
  322. package/dist/testing.js +297 -56
  323. package/dist/tools/index.d.ts +3 -2
  324. package/dist/tools/index.js +3 -2
  325. package/dist/tools/module-certification.d.ts +6 -0
  326. package/dist/tools/module-certification.js +26 -2
  327. package/package.json +18 -5
  328. package/core/scripts/run-box3d-benchmark.mjs +0 -350
  329. package/core/src/physics/index.mjs +0 -3169
@@ -0,0 +1,51 @@
1
+ import { type KinetixCheckpointBudget, type KinetixRuntimeIdentity, type KinetixStrongReportRuntimeIdentity, type KinetixRuntimeLease, type OwnedKinetixRuntime } from '@series-inc/rundot-syncplay/core/runtime';
2
+ import { type KinetixNativeRuntimeController } from '../../core/src/physics/world.mjs';
3
+ import { type GameCodec } from './game-codec3d.js';
4
+ import type { PhysicsCheckpointInfo3D, PhysicsCheckpointMotionBatch3D, PhysicsLatestOutputs3D, PhysicsWorld3D } from './3d.js';
5
+ export interface PhysicsCheckpointView3D {
6
+ info(): Readonly<PhysicsCheckpointInfo3D>;
7
+ latest(): Readonly<PhysicsLatestOutputs3D>;
8
+ digest(): bigint;
9
+ strongDigest(): Uint8Array;
10
+ writeBodyMotionInto(poses: Float64Array, velocities: Float64Array, ids: BigUint64Array, status: Uint8Array): Readonly<PhysicsCheckpointMotionBatch3D>;
11
+ }
12
+ export interface PhysicsInstalledGameContext3D {
13
+ readonly identity: KinetixRuntimeIdentity;
14
+ readonly sessionConfigBytes: Uint8Array;
15
+ }
16
+ export interface PhysicsInstalledPreviousState3D<Game> {
17
+ readonly game: Game;
18
+ readonly physics: PhysicsCheckpointView3D;
19
+ }
20
+ export interface PhysicsInstalledRuntimeAdapter3DOptions<Game, Input, Command = never, Projection = Game> {
21
+ readonly identity: KinetixStrongReportRuntimeIdentity;
22
+ readonly sessionConfigBytes: Uint8Array;
23
+ readonly decodeCommand: (command: unknown) => Command;
24
+ /** Use a world created by this SDK instance. Custom facades and proxies are rejected. */
25
+ readonly world: PhysicsWorld3D;
26
+ /** Ownership transfers after native attachment. Callbacks must finish synchronously. */
27
+ readonly worldOwnership: 'borrowed' | 'owned';
28
+ readonly expectedInitialPhysicsDigest: bigint;
29
+ readonly checkpointBudget: KinetixCheckpointBudget;
30
+ /**
31
+ * Return a frozen root with data properties. Keep every shared value immutable.
32
+ * These callbacks are trusted simulation code. The SDK checks the root only.
33
+ * It does not copy or check the full game graph on each frame.
34
+ */
35
+ readonly createInitialGameState: (context: PhysicsInstalledGameContext3D) => Game;
36
+ readonly stepGameState: (context: Readonly<{
37
+ game: Game;
38
+ world: PhysicsWorld3D;
39
+ frame: number;
40
+ inputs: readonly Input[];
41
+ commands: readonly Command[];
42
+ }>) => Game;
43
+ /** Encode every non-physics value that can change a future frame. */
44
+ readonly gameCodec: GameCodec<Game>;
45
+ readonly inspect?: (game: Game, physics: PhysicsCheckpointView3D) => Game;
46
+ readonly project?: (game: Game, physics: PhysicsCheckpointView3D, previous: PhysicsInstalledPreviousState3D<Game> | null) => Readonly<Projection>;
47
+ }
48
+ type LatestDecoder = (outputs: ReturnType<KinetixNativeRuntimeController['checkpointLatest']>) => PhysicsLatestOutputs3D;
49
+ /** @internal The public 3D facade supplies its shared SI output decoder. */
50
+ export declare function createPhysicsInstalledRuntimeAdapterInternal3D<Game, Input, Command, Projection>(supplied: PhysicsInstalledRuntimeAdapter3DOptions<Game, Input, Command, Projection>, checkedWorld: PhysicsWorld3D, decodeLatest: LatestDecoder): KinetixRuntimeLease<OwnedKinetixRuntime<Game, Input, unknown, Projection>>;
51
+ export {};
@@ -0,0 +1,372 @@
1
+ import { assertKinetixRuntimeIdentity, createInstalledRuntimeAdapter, kinetixSessionConfigDigest, } from '@series-inc/rundot-syncplay/core/runtime';
2
+ import { attachNativePhysicsWorld, } from '../../core/src/physics/world.mjs';
3
+ import { copyUint8Array, sha256Hex, uint8ArrayByteLength } from '@series-inc/rundot-syncplay/core/runtime';
4
+ import { ensureDeterministicMathInstalled } from '../math.js';
5
+ import { PhysicsInstalledCheckpointCodec3D } from './installed-checkpoint3d.js';
6
+ import { createGameCodec } from './game-codec3d.js';
7
+ import { physicsInstalledStateCommitment3D } from './installed-state-commitment3d.js';
8
+ const textEncoder = new TextEncoder();
9
+ function invalid(field) {
10
+ throw new Error(`KINETIX_RUNTIME_ADAPTER_INVALID: ${field}`);
11
+ }
12
+ function ownField(object, field) {
13
+ const descriptor = Object.getOwnPropertyDescriptor(object, field);
14
+ if (descriptor === undefined || !Object.hasOwn(descriptor, 'value'))
15
+ invalid(`own ${field}`);
16
+ return descriptor.value;
17
+ }
18
+ function immutableGame(game) {
19
+ const message = 'game state must be immutable and synchronous';
20
+ if (typeof game === 'function' || (typeof game === 'number' && !Number.isFinite(game))
21
+ || (game !== null && typeof game === 'object' && !Object.isFrozen(game)))
22
+ invalid(message);
23
+ if (game === null || typeof game !== 'object')
24
+ return game;
25
+ const descriptors = Object.getOwnPropertyDescriptors(game);
26
+ if (Reflect.ownKeys(descriptors).some(key => !Object.hasOwn(Reflect.get(descriptors, key), 'value')))
27
+ invalid(message);
28
+ const seen = new WeakSet();
29
+ let owner = game;
30
+ while (owner !== null) {
31
+ if (seen.has(owner))
32
+ invalid(message);
33
+ seen.add(owner);
34
+ const then = Object.getOwnPropertyDescriptor(owner, 'then');
35
+ if (then !== undefined) {
36
+ if (!Object.hasOwn(then, 'value') || typeof then.value === 'function')
37
+ invalid(message);
38
+ break;
39
+ }
40
+ owner = Object.getPrototypeOf(owner);
41
+ }
42
+ return game;
43
+ }
44
+ function synchronousProjection(projection) {
45
+ if (projection !== null && typeof projection === 'object'
46
+ && 'then' in projection && typeof projection.then === 'function') {
47
+ invalid('projection must finish synchronously');
48
+ }
49
+ return projection;
50
+ }
51
+ class CapturedPhysicsGame3D {
52
+ #gameState = { kind: 'empty' };
53
+ #gameCodec;
54
+ physics;
55
+ #controller;
56
+ #checkpoint;
57
+ #frame = 0;
58
+ #released = false;
59
+ constructor(controller, gameCodec, decodeLatest) {
60
+ this.#gameCodec = gameCodec;
61
+ this.#controller = controller;
62
+ this.physics = Object.freeze({
63
+ info: () => controller.checkpointInfo(this.checkpoint()),
64
+ latest: () => decodeLatest(controller.checkpointLatest(this.checkpoint())),
65
+ digest: () => controller.digestCheckpoint(this.checkpoint()),
66
+ strongDigest: () => controller.strongDigestCheckpoint(this.checkpoint()),
67
+ writeBodyMotionInto: (poses, velocities, ids, status) => controller.writeCheckpointBodyMotionInto(this.checkpoint(), poses, velocities, ids, status),
68
+ });
69
+ }
70
+ get game() {
71
+ this.checkpoint();
72
+ if (this.#gameState.kind !== 'ready')
73
+ invalid('game state is not ready');
74
+ return this.#gameState.game;
75
+ }
76
+ bindGame(game, memo) {
77
+ this.checkpoint();
78
+ if (this.#gameState.kind !== 'empty')
79
+ invalid('game state is already bound');
80
+ this.#gameState = { kind: 'ready', game: immutableGame(game), memo };
81
+ }
82
+ gameMemo() {
83
+ this.checkpoint();
84
+ const state = this.#gameState;
85
+ if (state.kind !== 'ready')
86
+ invalid('game state is not ready');
87
+ if (state.memo === undefined) {
88
+ state.memo = this.#controller.readOnly(() => this.#gameCodec.encodeMemo(state.game));
89
+ }
90
+ return state.memo;
91
+ }
92
+ checkpoint() {
93
+ if (this.#checkpoint === undefined || this.#released)
94
+ throw new Error('KINETIX_RUNTIME_CHECKPOINT_INVALID');
95
+ return this.#checkpoint;
96
+ }
97
+ bind(checkpoint) {
98
+ if (this.#checkpoint !== undefined)
99
+ invalid('physics state is already bound');
100
+ this.#checkpoint = checkpoint;
101
+ const frame = this.#controller.checkpointInfo(checkpoint).frame;
102
+ if (frame > BigInt(Number.MAX_SAFE_INTEGER))
103
+ throw new Error('KINETIX_RUNTIME_FRAME_MISMATCH');
104
+ this.#frame = Number(frame);
105
+ }
106
+ get frame() { this.checkpoint(); return this.#frame; }
107
+ release() {
108
+ if (this.#released || this.#checkpoint === undefined)
109
+ return;
110
+ this.#controller.releaseCheckpoint(this.#checkpoint);
111
+ this.#released = true;
112
+ this.#gameState = { kind: 'empty' };
113
+ }
114
+ }
115
+ class PhysicsInstalledGameStore3D {
116
+ kind = 'owned';
117
+ checkpointBudget;
118
+ #options;
119
+ #controller;
120
+ #codec;
121
+ #decodeLatest;
122
+ #gameCodec;
123
+ #game;
124
+ #frame = 0;
125
+ constructor(options, controller, codec, decodeLatest, gameCodec, game) {
126
+ this.#options = options;
127
+ this.#controller = controller;
128
+ this.#codec = codec;
129
+ this.#decodeLatest = decodeLatest;
130
+ this.#gameCodec = gameCodec;
131
+ this.#game = game;
132
+ this.checkpointBudget = options.checkpointBudget;
133
+ }
134
+ step(inputs, commands) {
135
+ const game = this.#options.stepGameState({ game: this.#game, world: this.#options.world,
136
+ frame: this.#frame + 1, inputs, commands });
137
+ this.#game = immutableGame(game);
138
+ this.#frame += 1;
139
+ }
140
+ #capture(game, acquire) {
141
+ const captured = new CapturedPhysicsGame3D(this.#controller, this.#gameCodec, this.#decodeLatest);
142
+ try {
143
+ captured.bind(acquire());
144
+ captured.bindGame(game);
145
+ return captured;
146
+ }
147
+ catch (error) {
148
+ try {
149
+ captured.release();
150
+ }
151
+ catch (cleanup) {
152
+ throw new AggregateError([error, cleanup], 'KINETIX_RUNTIME_CAPTURE_FAILED', { cause: error });
153
+ }
154
+ throw error;
155
+ }
156
+ }
157
+ captureState() {
158
+ const captured = this.#capture(this.#game, () => this.#controller.captureCheckpoint());
159
+ if (captured.frame !== this.#frame) {
160
+ const mismatch = new Error('KINETIX_RUNTIME_FRAME_MISMATCH');
161
+ try {
162
+ captured.release();
163
+ }
164
+ catch (cleanup) {
165
+ throw new AggregateError([mismatch, cleanup], 'KINETIX_RUNTIME_CAPTURE_FAILED', { cause: mismatch });
166
+ }
167
+ throw mismatch;
168
+ }
169
+ return captured;
170
+ }
171
+ restoreState(state) {
172
+ this.#controller.restoreCheckpoint(state.checkpoint());
173
+ this.#game = state.game;
174
+ this.#frame = state.frame;
175
+ }
176
+ releaseState(state) { state.release(); }
177
+ frameOf(state) { return state.frame; }
178
+ readLiveRevision() { return this.#controller.mutationRevision(); }
179
+ inspectState(state) {
180
+ return this.#options.inspect === undefined ? state.game
181
+ : this.#controller.readOnly(() => immutableGame(this.#options.inspect(state.game, state.physics)));
182
+ }
183
+ serializeState(state) {
184
+ const game = this.#gameCodec.serialize(state.gameMemo());
185
+ return this.#codec.encode(state.frame, game, this.#controller.serializeCheckpoint(state.checkpoint()));
186
+ }
187
+ validateSnapshot(frame, input) {
188
+ this.#codec.validateGameRegion(frame, input, region => this.#gameCodec.validateRegion(region));
189
+ }
190
+ hydrateState(frame, input) {
191
+ this.validateSnapshot(frame, input);
192
+ const bytes = this.#codec.decode(frame, input);
193
+ const captured = new CapturedPhysicsGame3D(this.#controller, this.#gameCodec, this.#decodeLatest);
194
+ try {
195
+ captured.bind(this.#controller.importCheckpoint(bytes.physics));
196
+ if (captured.frame !== frame)
197
+ throw new Error('KINETIX_RUNTIME_FRAME_MISMATCH');
198
+ const decoded = this.#controller.readOnly(() => this.#gameCodec.importRegion(frame, bytes.game, captured.physics));
199
+ captured.bindGame(decoded.game, decoded.memo);
200
+ return captured;
201
+ }
202
+ catch (error) {
203
+ try {
204
+ captured.release();
205
+ }
206
+ catch (cleanup) {
207
+ throw new AggregateError([error, cleanup], 'KINETIX_RUNTIME_HYDRATE_FAILED', { cause: error });
208
+ }
209
+ throw error;
210
+ }
211
+ }
212
+ stateCommitment(state) {
213
+ return physicsInstalledStateCommitment3D(this.#controller.strongDigestCheckpoint(state.checkpoint()), this.#gameCodec.leaf(state.gameMemo()));
214
+ }
215
+ checksumStateBytes(state) { return this.stateCommitment(state); }
216
+ projectState(state, previous) {
217
+ return this.#controller.readOnly(() => synchronousProjection(this.#options.project(state.game, state.physics, previous === null ? null : Object.freeze({ game: previous.game, physics: previous.physics }))));
218
+ }
219
+ }
220
+ /** @internal The public 3D facade supplies its shared SI output decoder. */
221
+ export function createPhysicsInstalledRuntimeAdapterInternal3D(supplied, checkedWorld, decodeLatest) {
222
+ if (supplied === null || typeof supplied !== 'object')
223
+ invalid('options');
224
+ const descriptors = Object.getOwnPropertyDescriptors(supplied);
225
+ if (Object.values(descriptors).some(item => !Object.hasOwn(item, 'value')))
226
+ invalid('option accessors');
227
+ const options = Object.freeze(Object.assign(Object.create(null), supplied, { world: checkedWorld }));
228
+ for (const name of ['decodeCommand', 'createInitialGameState', 'stepGameState']) {
229
+ if (typeof options[name] !== 'function')
230
+ invalid(name);
231
+ }
232
+ for (const legacy of ['encodeGameState', 'decodeGameState', 'maxGameStateBytes', 'gameChecksumBytes']) {
233
+ if (Object.hasOwn(options, legacy))
234
+ invalid('use gameCodec');
235
+ }
236
+ const gameCodec = createGameCodec(options.gameCodec);
237
+ if (options.inspect !== undefined && typeof options.inspect !== 'function')
238
+ invalid('inspect');
239
+ if (options.project !== undefined && typeof options.project !== 'function')
240
+ invalid('project');
241
+ if (options.worldOwnership !== 'borrowed' && options.worldOwnership !== 'owned')
242
+ invalid('worldOwnership');
243
+ const rawBudget = options.checkpointBudget;
244
+ if (rawBudget === null || typeof rawBudget !== 'object')
245
+ invalid('checkpointBudget');
246
+ const budget = Object.freeze({
247
+ maxLiveCheckpoints: ownField(rawBudget, 'maxLiveCheckpoints'),
248
+ maxAdvanceBatch: ownField(rawBudget, 'maxAdvanceBatch'),
249
+ importScratch: ownField(rawBudget, 'importScratch'),
250
+ });
251
+ if ([budget.maxLiveCheckpoints,
252
+ budget.maxAdvanceBatch, budget.importScratch].some(value => !Number.isSafeInteger(value) || value < 1)
253
+ || budget.maxAdvanceBatch + budget.importScratch + 1 > budget.maxLiveCheckpoints)
254
+ invalid('checkpointBudget');
255
+ if (options.identity === null || typeof options.identity !== 'object')
256
+ invalid('identity');
257
+ assertKinetixRuntimeIdentity(options.identity);
258
+ if (options.identity.stateDigestDomain !== 'syncplay.state-report/2')
259
+ invalid('stateDigestDomain');
260
+ const identity = Object.freeze({
261
+ abiVersion: options.identity.abiVersion, tickRate: options.identity.tickRate,
262
+ inputSchemaId: options.identity.inputSchemaId, stateSchemaId: options.identity.stateSchemaId,
263
+ deterministicVersion: options.identity.deterministicVersion, engineIdentityHash: options.identity.engineIdentityHash,
264
+ stateDigestDomain: options.identity.stateDigestDomain,
265
+ });
266
+ const identityDigest = sha256Hex(textEncoder.encode(JSON.stringify(['syncplay-physics-installed-2',
267
+ 13, 1, 1, identity.abiVersion, identity.tickRate, identity.inputSchemaId, identity.stateSchemaId,
268
+ identity.deterministicVersion, identity.engineIdentityHash, identity.stateDigestDomain])));
269
+ if (uint8ArrayByteLength(options.sessionConfigBytes) === undefined)
270
+ invalid('sessionConfigBytes');
271
+ const sessionConfigBytes = copyUint8Array(options.sessionConfigBytes);
272
+ const configDigest = kinetixSessionConfigDigest(sessionConfigBytes);
273
+ const codec = new PhysicsInstalledCheckpointCodec3D(identityDigest, configDigest, gameCodec.kind, gameCodec.gameRegionMax);
274
+ if (options.world.info().tickRate !== identity.tickRate)
275
+ invalid('world tick rate');
276
+ const normalized = Object.freeze(Object.assign(Object.create(null), options, { identity, sessionConfigBytes, checkpointBudget: budget }));
277
+ let installed;
278
+ let controller;
279
+ let disposal;
280
+ const lease = Object.freeze({
281
+ get runtime() { if (installed === undefined)
282
+ invalid('runtime not installed'); return installed.runtime; },
283
+ dispose() {
284
+ if (disposal !== undefined)
285
+ return disposal;
286
+ if (installed === undefined || controller === undefined)
287
+ invalid('runtime not installed');
288
+ const captured = installed;
289
+ const owner = controller;
290
+ // Reject reentry before this lease caches its disposal promise.
291
+ const closing = captured.dispose();
292
+ disposal = (async () => {
293
+ const errors = [];
294
+ try {
295
+ await closing;
296
+ }
297
+ catch (error) {
298
+ errors.push(error);
299
+ }
300
+ try {
301
+ owner.close();
302
+ }
303
+ catch (error) {
304
+ errors.push(error);
305
+ }
306
+ if (normalized.worldOwnership === 'owned') {
307
+ try {
308
+ normalized.world.dispose();
309
+ }
310
+ catch (error) {
311
+ errors.push(error);
312
+ }
313
+ }
314
+ if (errors.length !== 0)
315
+ throw new AggregateError(errors, 'KINETIX_RUNTIME_DISPOSE_FAILED');
316
+ })();
317
+ return disposal;
318
+ },
319
+ });
320
+ ensureDeterministicMathInstalled();
321
+ try {
322
+ controller = attachNativePhysicsWorld(normalized.world, normalized.expectedInitialPhysicsDigest);
323
+ if (controller.checkpointCapacity < budget.maxLiveCheckpoints)
324
+ throw new Error('KINETIX_RUNTIME_CAPACITY_INSUFFICIENT');
325
+ controller.checkpointPreflight(1);
326
+ const game = controller.readOnly(() => immutableGame(normalized.createInitialGameState(Object.freeze({ identity, sessionConfigBytes: copyUint8Array(sessionConfigBytes) }))));
327
+ const store = new PhysicsInstalledGameStore3D(normalized, controller, codec, decodeLatest, gameCodec, game);
328
+ const stateStorage = {
329
+ kind: 'owned', checkpointBudget: normalized.checkpointBudget,
330
+ captureState: () => store.captureState(), restoreState: state => store.restoreState(state),
331
+ releaseState: state => store.releaseState(state), frameOf: state => store.frameOf(state),
332
+ inspectState: state => store.inspectState(state), serializeState: state => store.serializeState(state),
333
+ hydrateState: (frame, bytes) => store.hydrateState(frame, bytes),
334
+ checksumStateBytes: state => store.checksumStateBytes(state),
335
+ stateCommitment: state => store.stateCommitment(state), readLiveRevision: () => store.readLiveRevision(),
336
+ preflightAdvance: (count) => controller.checkpointPreflight(count),
337
+ runReadOnly: (action) => controller.readOnly(action),
338
+ maxSnapshotBytes: codec.maxSnapshotBytes,
339
+ validateSnapshot: (frame, bytes) => store.validateSnapshot(frame, bytes),
340
+ ...(normalized.project === undefined ? {} : { projectState: (state, previous) => store.projectState(state, previous) }),
341
+ };
342
+ installed = createInstalledRuntimeAdapter({ identity, sessionConfigBytes,
343
+ decodeCommand: normalized.decodeCommand,
344
+ step: (inputs, commands) => store.step(inputs, commands),
345
+ stateStorage });
346
+ return lease;
347
+ }
348
+ catch (error) {
349
+ const errors = [error];
350
+ if (controller !== undefined) {
351
+ try {
352
+ controller.close();
353
+ }
354
+ catch (cleanup) {
355
+ errors.push(cleanup);
356
+ }
357
+ if (normalized.worldOwnership === 'owned') {
358
+ try {
359
+ normalized.world.dispose();
360
+ }
361
+ catch (cleanup) {
362
+ errors.push(cleanup);
363
+ }
364
+ }
365
+ }
366
+ if (errors.length > 1)
367
+ throw new AggregateError(errors, 'KINETIX_RUNTIME_INIT_FAILED', { cause: error });
368
+ if (error instanceof Error)
369
+ throw error;
370
+ throw new Error('KINETIX_RUNTIME_INIT_FAILED', { cause: error });
371
+ }
372
+ }
@@ -0,0 +1,2 @@
1
+ /** @internal Bind the native strong digest and the complete canonical game leaf. */
2
+ export declare function physicsInstalledStateCommitment3D(physics: Uint8Array, game: Uint8Array): Uint8Array;
@@ -0,0 +1,24 @@
1
+ import { sha256Hex, uint8ArrayByteLength } from '@series-inc/rundot-syncplay/core/runtime';
2
+ const ByteArray = Uint8Array;
3
+ const ByteView = DataView;
4
+ const setBytes = ByteArray.prototype.set;
5
+ const domain = new TextEncoder().encode('syncplay.physics-installed-state/1');
6
+ const nativeStrongRevision = 1;
7
+ /** @internal Bind the native strong digest and the complete canonical game leaf. */
8
+ export function physicsInstalledStateCommitment3D(physics, game) {
9
+ if (uint8ArrayByteLength(physics) !== 32 || uint8ArrayByteLength(game) !== 32) {
10
+ throw new Error('KINETIX_RUNTIME_CHECKPOINT_INVALID: commitment leaf');
11
+ }
12
+ const header = new ByteArray(103);
13
+ header[0] = 34;
14
+ setBytes.call(header, domain, 1);
15
+ new ByteView(header.buffer).setUint32(35, nativeStrongRevision, true);
16
+ setBytes.call(header, physics, 39);
17
+ setBytes.call(header, game, 71);
18
+ const digest = sha256Hex(header);
19
+ const output = new ByteArray(32);
20
+ for (let index = 0; index < 32; index += 1) {
21
+ output[index] = Number.parseInt(digest.slice(index * 2, index * 2 + 2), 16);
22
+ }
23
+ return output;
24
+ }
@@ -0,0 +1,38 @@
1
+ import type { Meters, Radians, MetersPerSecond, MetersPerSecondSquared, RadiansPerSecond, Newtons, NewtonMeters, NewtonSeconds, FrameVelocity, FrameGravity, Seconds, Hertz, Kilograms, InverseKilograms, InverseKilogramMetersSquared, SquareMeters, CubicMeters, KilogramMetersSquared, KilogramsPerCubicMeter, KilogramsPerSquareMeter, NewtonsPerMeter, NewtonSecondsPerMeter, Turns, TurnsPerSecond, TurnsPerMinute, PerSecond, PerSecondSquared, SquareMetersPerSecondSquared, NewtonMeterSeconds, MetersPerRadian, RadiansPerMeter, NewtonMeterSecondsPerRadian } from '../../core/units.js';
2
+ export type { Quantity, Meters, Radians, MetersPerSecond, MetersPerSecondSquared, RadiansPerSecond, Newtons, NewtonMeters, NewtonSeconds, FrameVelocity, FrameGravity, Dimensionless, Seconds, Hertz, Kilograms, InverseKilograms, InverseKilogramMetersSquared, SquareMeters, CubicMeters, KilogramMetersSquared, KilogramsPerCubicMeter, KilogramsPerSquareMeter, NewtonsPerMeter, NewtonSecondsPerMeter, Turns, TurnsPerSecond, TurnsPerMinute, PerSecond, PerSecondSquared, SquareMetersPerSecondSquared, NewtonMeterSeconds, MetersPerRadian, RadiansPerMeter, NewtonMeterSecondsPerRadian, UnitVector2, UnitVector3, } from '../../core/units.js';
3
+ export declare const meters: (value: number) => Meters;
4
+ export declare const radians: (value: number) => Radians;
5
+ export declare const metersPerSecond: (value: number) => MetersPerSecond;
6
+ export declare const metersPerSecondSquared: (value: number) => MetersPerSecondSquared;
7
+ export declare const radiansPerSecond: (value: number) => RadiansPerSecond;
8
+ export declare const newtons: (value: number) => Newtons;
9
+ export declare const newtonMeters: (value: number) => NewtonMeters;
10
+ export declare const newtonSeconds: (value: number) => NewtonSeconds;
11
+ export declare const frameVelocity: (value: number) => FrameVelocity;
12
+ export declare const frameGravity: (value: number) => FrameGravity;
13
+ export declare const seconds: (value: number) => Seconds;
14
+ export declare const hertz: (value: number) => Hertz;
15
+ export declare const kilograms: (value: number) => Kilograms;
16
+ export declare const inverseKilograms: (value: number) => InverseKilograms;
17
+ export declare const inverseKilogramMetersSquared: (value: number) => InverseKilogramMetersSquared;
18
+ export declare const squareMeters: (value: number) => SquareMeters;
19
+ export declare const cubicMeters: (value: number) => CubicMeters;
20
+ export declare const kilogramMetersSquared: (value: number) => KilogramMetersSquared;
21
+ export declare const kilogramsPerCubicMeter: (value: number) => KilogramsPerCubicMeter;
22
+ export declare const kilogramsPerSquareMeter: (value: number) => KilogramsPerSquareMeter;
23
+ export declare const newtonsPerMeter: (value: number) => NewtonsPerMeter;
24
+ export declare const newtonSecondsPerMeter: (value: number) => NewtonSecondsPerMeter;
25
+ export declare const turns: (value: number) => Turns;
26
+ export declare const turnsPerSecond: (value: number) => TurnsPerSecond;
27
+ export declare const turnsPerMinute: (value: number) => TurnsPerMinute;
28
+ export declare const perSecond: (value: number) => PerSecond;
29
+ export declare const perSecondSquared: (value: number) => PerSecondSquared;
30
+ export declare const squareMetersPerSecondSquared: (value: number) => SquareMetersPerSecondSquared;
31
+ export declare const newtonMeterSeconds: (value: number) => NewtonMeterSeconds;
32
+ export declare const metersPerRadian: (value: number) => MetersPerRadian;
33
+ export declare const radiansPerMeter: (value: number) => RadiansPerMeter;
34
+ export declare const newtonMeterSecondsPerRadian: (value: number) => NewtonMeterSecondsPerRadian;
35
+ export declare function velocityToFrame(value: MetersPerSecond, tickRate: number): FrameVelocity;
36
+ export declare function velocityToSeconds(value: FrameVelocity, tickRate: number): MetersPerSecond;
37
+ export declare function gravityToFrame(value: MetersPerSecondSquared, tickRate: number): FrameGravity;
38
+ export declare function gravityToSeconds(value: FrameGravity, tickRate: number): MetersPerSecondSquared;
@@ -0,0 +1,56 @@
1
+ function finiteQuantity(value) {
2
+ if (!Number.isFinite(value))
3
+ throw new Error('KINETIX_UNIT_VALUE_INVALID');
4
+ return value;
5
+ }
6
+ export const meters = (value) => finiteQuantity(value);
7
+ export const radians = (value) => finiteQuantity(value);
8
+ export const metersPerSecond = (value) => finiteQuantity(value);
9
+ export const metersPerSecondSquared = (value) => finiteQuantity(value);
10
+ export const radiansPerSecond = (value) => finiteQuantity(value);
11
+ export const newtons = (value) => finiteQuantity(value);
12
+ export const newtonMeters = (value) => finiteQuantity(value);
13
+ export const newtonSeconds = (value) => finiteQuantity(value);
14
+ export const frameVelocity = (value) => finiteQuantity(value);
15
+ export const frameGravity = (value) => finiteQuantity(value);
16
+ export const seconds = (value) => finiteQuantity(value);
17
+ export const hertz = (value) => finiteQuantity(value);
18
+ export const kilograms = (value) => finiteQuantity(value);
19
+ export const inverseKilograms = (value) => finiteQuantity(value);
20
+ export const inverseKilogramMetersSquared = (value) => finiteQuantity(value);
21
+ export const squareMeters = (value) => finiteQuantity(value);
22
+ export const cubicMeters = (value) => finiteQuantity(value);
23
+ export const kilogramMetersSquared = (value) => finiteQuantity(value);
24
+ export const kilogramsPerCubicMeter = (value) => finiteQuantity(value);
25
+ export const kilogramsPerSquareMeter = (value) => finiteQuantity(value);
26
+ export const newtonsPerMeter = (value) => finiteQuantity(value);
27
+ export const newtonSecondsPerMeter = (value) => finiteQuantity(value);
28
+ export const turns = (value) => finiteQuantity(value);
29
+ export const turnsPerSecond = (value) => finiteQuantity(value);
30
+ export const turnsPerMinute = (value) => finiteQuantity(value);
31
+ export const perSecond = (value) => finiteQuantity(value);
32
+ export const perSecondSquared = (value) => finiteQuantity(value);
33
+ export const squareMetersPerSecondSquared = (value) => finiteQuantity(value);
34
+ export const newtonMeterSeconds = (value) => finiteQuantity(value);
35
+ export const metersPerRadian = (value) => finiteQuantity(value);
36
+ export const radiansPerMeter = (value) => finiteQuantity(value);
37
+ export const newtonMeterSecondsPerRadian = (value) => finiteQuantity(value);
38
+ function validTickRate(tickRate) {
39
+ if (!Number.isSafeInteger(tickRate) || tickRate <= 0)
40
+ throw new Error('KINETIX_UNIT_TICK_RATE_INVALID');
41
+ return tickRate;
42
+ }
43
+ export function velocityToFrame(value, tickRate) {
44
+ return frameVelocity(value / validTickRate(tickRate));
45
+ }
46
+ export function velocityToSeconds(value, tickRate) {
47
+ return metersPerSecond(value * validTickRate(tickRate));
48
+ }
49
+ export function gravityToFrame(value, tickRate) {
50
+ const rate = validTickRate(tickRate);
51
+ return frameGravity(value / rate / rate);
52
+ }
53
+ export function gravityToSeconds(value, tickRate) {
54
+ const rate = validTickRate(tickRate);
55
+ return metersPerSecondSquared(value * rate * rate);
56
+ }
@@ -0,0 +1,93 @@
1
+ import type { DeterministicVehicleInput3D, Meters, Newtons, NewtonSecondsPerMeter, NewtonsPerMeter, PhysicsBodyId3D, PhysicsSupportRecords3D, PhysicsVector3D, PhysicsWorld3D, Turns } from './3d.js';
2
+ export interface DeterministicVehicleWheelDefinition3D {
3
+ readonly id: string;
4
+ readonly localAnchor: PhysicsVector3D<Meters>;
5
+ readonly suspensionDirection: PhysicsVector3D;
6
+ readonly suspensionRestLength: Meters;
7
+ readonly suspensionMaximumTravel: Meters;
8
+ readonly radius: Meters;
9
+ readonly stiffness: NewtonsPerMeter;
10
+ readonly damping: NewtonSecondsPerMeter;
11
+ readonly grip: number;
12
+ readonly maximumSteerAngleTurns: Turns;
13
+ readonly steered: boolean;
14
+ readonly driven: boolean;
15
+ }
16
+ export interface DeterministicVehicleDefinition3D {
17
+ readonly wheels: readonly DeterministicVehicleWheelDefinition3D[];
18
+ readonly driveForce: Newtons;
19
+ readonly brakeForce: Newtons;
20
+ }
21
+ export type DeterministicVehicleSleep3D = {
22
+ readonly status: 'active';
23
+ } | {
24
+ readonly status: 'parked';
25
+ };
26
+ export type DeterministicVehicleSupport3D = {
27
+ readonly kind: 'unknown';
28
+ } | {
29
+ readonly kind: 'airborne';
30
+ } | {
31
+ readonly kind: 'grounded';
32
+ readonly bodyId: PhysicsBodyId3D;
33
+ readonly distance: Meters;
34
+ readonly normal: PhysicsVector3D;
35
+ };
36
+ export interface DeterministicVehicleWheelState3D {
37
+ readonly id: string;
38
+ readonly accumulatedMicroTurns: number;
39
+ readonly support: DeterministicVehicleSupport3D;
40
+ }
41
+ export interface DeterministicVehicleState3D {
42
+ readonly behaviorRevision: 2;
43
+ readonly chassisId: PhysicsBodyId3D;
44
+ readonly lastInput: DeterministicVehicleInput3D;
45
+ readonly sleep: DeterministicVehicleSleep3D;
46
+ readonly wheels: readonly DeterministicVehicleWheelState3D[];
47
+ }
48
+ export type DeterministicVehicleSupportClass3D = 'static' | 'kinematic' | 'dynamic' | 'below-stable-mass' | 'unsupported-normal';
49
+ export type DeterministicVehicleWakeReason3D = 'input' | 'external' | 'support-changed' | 'support-removed' | 'support-moving' | 'support-surface-velocity' | 'support-awake';
50
+ export interface DeterministicVehicleStateWheel3D {
51
+ readonly id: string;
52
+ readonly grounded: boolean;
53
+ readonly compression: Meters;
54
+ readonly steerAngleTurns: Turns;
55
+ readonly spinDeltaTurns: Turns;
56
+ readonly accumulatedTurns: Turns;
57
+ readonly accumulatedMicroTurns: number;
58
+ readonly supportClass?: DeterministicVehicleSupportClass3D;
59
+ readonly contactBodyId?: PhysicsBodyId3D;
60
+ readonly contactPoint?: PhysicsVector3D<Meters>;
61
+ readonly contactNormal?: PhysicsVector3D;
62
+ }
63
+ export interface DeterministicVehicleStateStepOptions3D {
64
+ readonly checksumMode?: 'required' | 'disabled';
65
+ readonly apply?: boolean;
66
+ }
67
+ interface DeterministicVehicleStateStepBase3D {
68
+ readonly state: DeterministicVehicleState3D;
69
+ readonly records: PhysicsSupportRecords3D;
70
+ readonly wheels: readonly DeterministicVehicleStateWheel3D[];
71
+ readonly events: readonly ('airborne' | 'parked' | 'woke')[];
72
+ readonly wakeReason?: DeterministicVehicleWakeReason3D;
73
+ }
74
+ export interface DeterministicVehicleStateStepWithChecksum3D extends DeterministicVehicleStateStepBase3D {
75
+ readonly hasChecksum: true;
76
+ readonly checksumMode: 'required';
77
+ readonly checksum: string;
78
+ }
79
+ export interface DeterministicVehicleStateStepWithoutChecksum3D extends DeterministicVehicleStateStepBase3D {
80
+ readonly hasChecksum: false;
81
+ readonly checksumMode: 'disabled';
82
+ readonly checksum?: never;
83
+ }
84
+ export type DeterministicVehicleStateStepResult3D = DeterministicVehicleStateStepWithChecksum3D | DeterministicVehicleStateStepWithoutChecksum3D;
85
+ export declare function createDeterministicVehicleState3D(definition: DeterministicVehicleDefinition3D, chassisId: PhysicsBodyId3D): DeterministicVehicleState3D;
86
+ export declare function stepDeterministicVehicleState3D(definition: DeterministicVehicleDefinition3D, state: DeterministicVehicleState3D, input: DeterministicVehicleInput3D, world: PhysicsWorld3D, options: DeterministicVehicleStateStepOptions3D & {
87
+ readonly checksumMode: 'disabled';
88
+ }): DeterministicVehicleStateStepWithoutChecksum3D;
89
+ export declare function stepDeterministicVehicleState3D(definition: DeterministicVehicleDefinition3D, state: DeterministicVehicleState3D, input: DeterministicVehicleInput3D, world: PhysicsWorld3D, options?: DeterministicVehicleStateStepOptions3D & {
90
+ readonly checksumMode?: 'required';
91
+ }): DeterministicVehicleStateStepWithChecksum3D;
92
+ export declare function stepDeterministicVehicleState3D(definition: DeterministicVehicleDefinition3D, state: DeterministicVehicleState3D, input: DeterministicVehicleInput3D, world: PhysicsWorld3D, options?: DeterministicVehicleStateStepOptions3D): DeterministicVehicleStateStepResult3D;
93
+ export {};