@woosh/meep-engine 2.145.0 → 2.147.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 (99) hide show
  1. package/package.json +1 -1
  2. package/src/core/geom/3d/shape/HeightMapShape3D.d.ts +33 -3
  3. package/src/core/geom/3d/shape/HeightMapShape3D.d.ts.map +1 -1
  4. package/src/core/geom/3d/shape/HeightMapShape3D.js +486 -451
  5. package/src/engine/control/first-person/DESIGN_COLLISION.md +365 -352
  6. package/src/engine/control/first-person/FirstPersonPlayerController.d.ts +1 -14
  7. package/src/engine/control/first-person/FirstPersonPlayerController.d.ts.map +1 -1
  8. package/src/engine/control/first-person/FirstPersonPlayerControllerConfig.d.ts +20 -8
  9. package/src/engine/control/first-person/FirstPersonPlayerControllerConfig.d.ts.map +1 -1
  10. package/src/engine/control/first-person/FirstPersonPlayerControllerConfig.js +552 -546
  11. package/src/engine/control/first-person/TODO.md +13 -11
  12. package/src/engine/control/first-person/abilities/LedgeGrab.d.ts +8 -3
  13. package/src/engine/control/first-person/abilities/LedgeGrab.d.ts.map +1 -1
  14. package/src/engine/control/first-person/abilities/LedgeGrab.js +213 -199
  15. package/src/engine/control/first-person/abilities/Mantle.d.ts.map +1 -1
  16. package/src/engine/control/first-person/abilities/Mantle.js +195 -188
  17. package/src/engine/control/first-person/abilities/WallJump.d.ts.map +1 -1
  18. package/src/engine/control/first-person/abilities/WallJump.js +11 -3
  19. package/src/engine/control/first-person/abilities/WallRun.d.ts.map +1 -1
  20. package/src/engine/control/first-person/abilities/WallRun.js +183 -163
  21. package/src/engine/control/first-person/collision/KinematicMover.d.ts.map +1 -1
  22. package/src/engine/control/first-person/collision/KinematicMover.js +634 -592
  23. package/src/engine/control/first-person/prototype_first_person_controller.js +1003 -901
  24. package/src/engine/control/first-person/sensors/FirstPersonSensors.d.ts +9 -0
  25. package/src/engine/control/first-person/sensors/FirstPersonSensors.d.ts.map +1 -1
  26. package/src/engine/control/first-person/sensors/FirstPersonSensors.js +87 -77
  27. package/src/engine/control/first-person/sensors/FirstPersonSensorsSystem.d.ts +8 -0
  28. package/src/engine/control/first-person/sensors/FirstPersonSensorsSystem.d.ts.map +1 -1
  29. package/src/engine/control/first-person/sensors/FirstPersonSensorsSystem.js +229 -196
  30. package/src/engine/ecs/EntityManager.d.ts +34 -11
  31. package/src/engine/ecs/EntityManager.d.ts.map +1 -1
  32. package/src/engine/ecs/EntityManager.js +71 -42
  33. package/src/engine/interpolation/BinaryInterpolationAdapter.d.ts.map +1 -0
  34. package/src/engine/interpolation/Interpoland.d.ts +48 -0
  35. package/src/engine/interpolation/Interpoland.d.ts.map +1 -0
  36. package/src/engine/interpolation/Interpoland.js +49 -0
  37. package/src/engine/interpolation/Interpolated.d.ts +101 -0
  38. package/src/engine/interpolation/Interpolated.d.ts.map +1 -0
  39. package/src/engine/interpolation/Interpolated.js +149 -0
  40. package/src/engine/{network/sim → interpolation}/InterpolationLog.d.ts +1 -1
  41. package/src/engine/interpolation/InterpolationLog.d.ts.map +1 -0
  42. package/src/engine/{network/sim → interpolation}/InterpolationLog.js +2 -2
  43. package/src/engine/interpolation/InterpolationSystem.d.ts +116 -0
  44. package/src/engine/interpolation/InterpolationSystem.d.ts.map +1 -0
  45. package/src/engine/interpolation/InterpolationSystem.js +233 -0
  46. package/src/engine/interpolation/PoseInterpolationAdapter.d.ts +17 -0
  47. package/src/engine/interpolation/PoseInterpolationAdapter.d.ts.map +1 -0
  48. package/src/engine/interpolation/PoseInterpolationAdapter.js +61 -0
  49. package/src/engine/interpolation/TransformPoseSerializationAdapter.d.ts +35 -0
  50. package/src/engine/interpolation/TransformPoseSerializationAdapter.d.ts.map +1 -0
  51. package/src/engine/interpolation/TransformPoseSerializationAdapter.js +57 -0
  52. package/src/engine/interpolation/pose_interpoland.d.ts +18 -0
  53. package/src/engine/interpolation/pose_interpoland.d.ts.map +1 -0
  54. package/src/engine/interpolation/pose_interpoland.js +27 -0
  55. package/src/engine/network/NetworkSession.d.ts +2 -2
  56. package/src/engine/network/NetworkSession.d.ts.map +1 -1
  57. package/src/engine/network/NetworkSession.js +2 -2
  58. package/src/engine/network/adapters/QuaternionInterpolationAdapter.d.ts +1 -1
  59. package/src/engine/network/adapters/QuaternionInterpolationAdapter.d.ts.map +1 -1
  60. package/src/engine/network/adapters/QuaternionInterpolationAdapter.js +1 -1
  61. package/src/engine/network/adapters/TransformInterpolationAdapter.d.ts +1 -1
  62. package/src/engine/network/adapters/TransformInterpolationAdapter.d.ts.map +1 -1
  63. package/src/engine/network/adapters/TransformInterpolationAdapter.js +1 -1
  64. package/src/engine/network/adapters/Vector3InterpolationAdapter.d.ts +1 -1
  65. package/src/engine/network/adapters/Vector3InterpolationAdapter.d.ts.map +1 -1
  66. package/src/engine/network/adapters/Vector3InterpolationAdapter.js +1 -1
  67. package/src/engine/physics/INTEPOLATION_SYSTEM_PLAN.md +287 -0
  68. package/src/engine/physics/PLAN.md +944 -809
  69. package/src/engine/physics/body/BodyStorage.d.ts +9 -0
  70. package/src/engine/physics/body/BodyStorage.d.ts.map +1 -1
  71. package/src/engine/physics/body/BodyStorage.js +23 -0
  72. package/src/engine/physics/broadphase/generate_pairs.d.ts.map +1 -1
  73. package/src/engine/physics/broadphase/generate_pairs.js +7 -0
  74. package/src/engine/physics/ccd/linear_sweep.d.ts +97 -0
  75. package/src/engine/physics/ccd/linear_sweep.d.ts.map +1 -0
  76. package/src/engine/physics/ccd/linear_sweep.js +238 -0
  77. package/src/engine/physics/ecs/PhysicsSystem.d.ts +82 -3
  78. package/src/engine/physics/ecs/PhysicsSystem.d.ts.map +1 -1
  79. package/src/engine/physics/ecs/PhysicsSystem.js +227 -8
  80. package/src/engine/physics/ecs/RigidBodyFlags.d.ts +6 -0
  81. package/src/engine/physics/ecs/RigidBodyFlags.d.ts.map +1 -1
  82. package/src/engine/physics/ecs/RigidBodyFlags.js +6 -0
  83. package/src/engine/physics/narrowphase/box_triangle_contact.js +814 -811
  84. package/src/engine/physics/narrowphase/compute_penetration.d.ts.map +1 -1
  85. package/src/engine/physics/narrowphase/compute_penetration.js +325 -323
  86. package/src/engine/physics/narrowphase/decomposition/heightmap_enumerate_triangles.d.ts +27 -8
  87. package/src/engine/physics/narrowphase/decomposition/heightmap_enumerate_triangles.d.ts.map +1 -1
  88. package/src/engine/physics/narrowphase/decomposition/heightmap_enumerate_triangles.js +235 -204
  89. package/src/engine/physics/narrowphase/narrowphase_step.d.ts.map +1 -1
  90. package/src/engine/physics/narrowphase/narrowphase_step.js +97 -13
  91. package/src/engine/physics/queries/overlap_shape.d.ts.map +1 -1
  92. package/src/engine/physics/queries/overlap_shape.js +185 -183
  93. package/src/engine/simulation/Ticker.d.ts +14 -0
  94. package/src/engine/simulation/Ticker.d.ts.map +1 -1
  95. package/src/engine/simulation/Ticker.js +136 -1
  96. package/src/engine/network/sim/BinaryInterpolationAdapter.d.ts.map +0 -1
  97. package/src/engine/network/sim/InterpolationLog.d.ts.map +0 -1
  98. /package/src/engine/{network/sim → interpolation}/BinaryInterpolationAdapter.d.ts +0 -0
  99. /package/src/engine/{network/sim → interpolation}/BinaryInterpolationAdapter.js +0 -0
@@ -24,12 +24,34 @@ class Ticker {
24
24
  */
25
25
  clock = new Clock();
26
26
 
27
+ /**
28
+ * When `true`, ticking is suspended while the host document/tab is in the
29
+ * background (hidden, or stored in the back/forward cache) and resumes from
30
+ * the current moment once it returns to the foreground.
31
+ *
32
+ * This avoids dispatching a flood of catch-up ticks (or one huge delta) for
33
+ * the time spent suspended, which would otherwise destabilise the simulation.
34
+ *
35
+ * Has no effect in environments without document/visibility support (e.g.
36
+ * Node.js), where the relevant lifecycle events simply never fire.
37
+ *
38
+ * @type {boolean}
39
+ */
40
+ suspend_in_background = true;
41
+
27
42
  /**
28
43
  * @private
29
44
  * @type {boolean}
30
45
  */
31
46
  #isRunning = false;
32
47
 
48
+ /**
49
+ * Whether ticking is currently suspended because the host page is in the background
50
+ * @private
51
+ * @type {boolean}
52
+ */
53
+ #isSuspended = false;
54
+
33
55
  #animationFrameHandle = -1;
34
56
  #timeoutHandle = -1;
35
57
 
@@ -54,6 +76,107 @@ class Ticker {
54
76
  return this.#timeoutHandle !== -1 && this.#animationFrameHandle !== -1;
55
77
  }
56
78
 
79
+ /**
80
+ * Stop dispatching ticks because the host page moved to the background.
81
+ * The clock is paused so no simulation time accrues while suspended. The
82
+ * update loop itself keeps cycling so it can pick back up cleanly, but
83
+ * {@link Ticker#onTick} stays silent until the page returns to the foreground.
84
+ * @private
85
+ */
86
+ #suspend() {
87
+ if (!this.suspend_in_background) {
88
+ return;
89
+ }
90
+
91
+ if (!this.#isRunning) {
92
+ // not actively ticking, nothing to suspend
93
+ return;
94
+ }
95
+
96
+ if (this.#isSuspended) {
97
+ return;
98
+ }
99
+
100
+ this.#isSuspended = true;
101
+
102
+ this.clock.pause();
103
+ }
104
+
105
+ /**
106
+ * Resume after the host page returned to the foreground.
107
+ *
108
+ * The clock is always restarted here (it was paused while suspended), with the
109
+ * delta accumulated for the suspended period discarded so that time continues
110
+ * from the current moment rather than catching up all at once. Whether ticks
111
+ * actually flow afterwards is still governed by the running flag, so a manual
112
+ * {@link Ticker#pause} taken during suspension is preserved.
113
+ * @private
114
+ */
115
+ #resume() {
116
+ if (!this.#isSuspended) {
117
+ return;
118
+ }
119
+
120
+ this.#isSuspended = false;
121
+
122
+ this.clock.getDelta(); //discard time spent suspended
123
+ this.clock.start();
124
+ }
125
+
126
+ #handleVisibilityChange = () => {
127
+ const doc = globalThis.document;
128
+
129
+ if (doc === undefined) {
130
+ return;
131
+ }
132
+
133
+ if (doc.visibilityState === 'hidden') {
134
+ this.#suspend();
135
+ } else {
136
+ this.#resume();
137
+ }
138
+ };
139
+
140
+ #handlePageHide = () => {
141
+ this.#suspend();
142
+ };
143
+
144
+ #handlePageShow = () => {
145
+ this.#resume();
146
+ };
147
+
148
+ /**
149
+ * Subscribe to page lifecycle events where the host environment provides them.
150
+ * Degrades gracefully where there is no DOM event target (e.g. Node.js).
151
+ * @private
152
+ */
153
+ #addLifecycleListeners() {
154
+ const doc = globalThis.document;
155
+ if (doc !== undefined && typeof doc.addEventListener === 'function') {
156
+ doc.addEventListener('visibilitychange', this.#handleVisibilityChange);
157
+ }
158
+
159
+ if (typeof globalThis.addEventListener === 'function') {
160
+ globalThis.addEventListener('pagehide', this.#handlePageHide);
161
+ globalThis.addEventListener('pageshow', this.#handlePageShow);
162
+ }
163
+ }
164
+
165
+ /**
166
+ * @private
167
+ */
168
+ #removeLifecycleListeners() {
169
+ const doc = globalThis.document;
170
+ if (doc !== undefined && typeof doc.removeEventListener === 'function') {
171
+ doc.removeEventListener('visibilitychange', this.#handleVisibilityChange);
172
+ }
173
+
174
+ if (typeof globalThis.removeEventListener === 'function') {
175
+ globalThis.removeEventListener('pagehide', this.#handlePageHide);
176
+ globalThis.removeEventListener('pageshow', this.#handlePageShow);
177
+ }
178
+ }
179
+
57
180
  /**
58
181
  *
59
182
  * @param {number} [maxTimeout]
@@ -67,9 +190,10 @@ class Ticker {
67
190
  }
68
191
 
69
192
  this.#isRunning = true;
193
+ this.#isSuspended = false;
70
194
 
71
195
  const update = () => {
72
- if (!this.#isRunning) {
196
+ if (!this.#isRunning || this.#isSuspended) {
73
197
  return;
74
198
  }
75
199
 
@@ -103,7 +227,15 @@ class Ticker {
103
227
  this.clock.getDelta(); //purge delta
104
228
  this.clock.start();
105
229
 
230
+ this.#addLifecycleListeners();
231
+
106
232
  requestAnimationFrame(animationFrameCallback);
233
+
234
+ //if we are starting while the page is already in the background, suspend right away
235
+ const doc = globalThis.document;
236
+ if (doc !== undefined && doc.visibilityState === 'hidden') {
237
+ this.#suspend();
238
+ }
107
239
  }
108
240
 
109
241
  pause() {
@@ -126,9 +258,12 @@ class Ticker {
126
258
  }
127
259
 
128
260
  stop() {
261
+ this.#removeLifecycleListeners();
262
+
129
263
  clearTimeout(this.#timeoutHandle);
130
264
  cancelAnimationFrame(this.#animationFrameHandle);
131
265
  this.#isRunning = false;
266
+ this.#isSuspended = false;
132
267
 
133
268
  this.#timeoutHandle = -1;
134
269
  this.#animationFrameHandle = -1;
@@ -1 +0,0 @@
1
- {"version":3,"file":"BinaryInterpolationAdapter.d.ts","sourceRoot":"","sources":["../../../../../src/engine/network/sim/BinaryInterpolationAdapter.js"],"names":[],"mappings":";;;;;gCAMU,MAAM;AANhB;;;;;;;GAOG;AACH;IACI,gEAAgE;;IAEhE,qEAAqE;;IAErE,+DAA+D;;GAEhE;AAEH;;;;;;;;;;;;;;;GAeG;AACH;IAEI,sDAAsD;IACtD,MADW,MAAM,CACe;IAEhC;;;;;;;;;;;;;OAaG;IACH,0EAJW,MAAM,iBACN,MAAM,KACN,MAAM,QAIhB;CACJ"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"InterpolationLog.d.ts","sourceRoot":"","sources":["../../../../../src/engine/network/sim/InterpolationLog.js"],"names":[],"mappings":"AA6EA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH;IAkBI;;;;;OAKG;IACH,0DALW;QAAE,qBAAqB,CAAC,EAAE,MAAM,CAAC;QAAC,gBAAgB,CAAC,EAAE,MAAM,CAAA;KAAE,EAkGvE;IA9EG,+BAA+B;IAC/B,0BADqB,MAAM,CACiB;IAe5C,+BAA+B;IAC/B,2BADqB,MAAM,CACa;IA+D5C;;;;;;;;OAQG;IACH,iBAFW,MAAM,QAkEhB;IAED;;;;;;;;;;;;;OAaG;IACH,yBAJW,MAAM,WACN,MAAM,GACJ,YAAY,CAmCxB;IAED;;;;;OAKG;IACH,mBAsDC;IAED;;;;;;;OAOG;IACH,iBAeC;IAED;;;OAGG;IACH,eAHW,MAAM,GACJ,OAAO,CAInB;IAED;;;;;;;;;;;;;;OAcG;IACH,YAPW,MAAM,EAAE,GAAC,WAAW,cACpB,MAAM,QACN,MAAM,cACN,MAAM,WACN,MAAM,GACJ,OAAO,CA+BnB;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,wBATW,YAAY,cACZ,MAAM,WACN,MAAM,UACN,MAAM,UACN,MAAM,KACN,MAAM,wCAEJ,OAAO,CAuBnB;IAED;;;OAGG;IACH,QAFa,MAAM,CAIlB;IAED;;;OAGG;IACH,eAFa,MAAM,CAIlB;IAED;;;OAGG;IACH,cASC;;CACJ;6BArkB4B,sCAAsC"}