react-three-game 0.0.103 → 0.0.104

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.
@@ -8,7 +8,8 @@ import { gameEvents } from "../../tools/prefabeditor/GameEvents";
8
8
  import { PrefabEditorMode, useScene } from "../../tools/prefabeditor/PrefabRoot";
9
9
  const SLEEP_TIME_BEFORE_REST = 0.1;
10
10
  const SLEEP_POINT_VELOCITY_THRESHOLD = 0.06;
11
- const MAX_PHYSICS_DELTA = 1 / 30;
11
+ const MAX_PHYSICS_STEP_DELTA = 1 / 60;
12
+ const MAX_PHYSICS_CATCH_UP_DELTA = 1 / 10;
12
13
  let didRegisterCrashcat = false;
13
14
  function ensureCrashcatRegistered() {
14
15
  if (didRegisterCrashcat)
@@ -19,11 +20,18 @@ function ensureCrashcatRegistered() {
19
20
  const crashcatListeners = new Set();
20
21
  let crashcatApi = null;
21
22
  export function useCrashcat() {
22
- return useSyncExternalStore((listener) => (crashcatListeners.add(listener), () => crashcatListeners.delete(listener)), () => crashcatApi, () => crashcatApi);
23
+ return useSyncExternalStore((listener) => {
24
+ crashcatListeners.add(listener);
25
+ return () => {
26
+ crashcatListeners.delete(listener);
27
+ };
28
+ }, () => crashcatApi, () => crashcatApi);
23
29
  }
24
30
  function setCrashcatApi(api) {
25
31
  crashcatApi = api;
26
- crashcatListeners.forEach((listener) => listener());
32
+ crashcatListeners.forEach((listener) => {
33
+ listener();
34
+ });
27
35
  }
28
36
  function emitConfiguredEvent(eventName, sourceNodeId, targetNodeId, collisionNormal) {
29
37
  const trimmed = eventName === null || eventName === void 0 ? void 0 : eventName.trim();
@@ -142,9 +150,14 @@ export function CrashcatRuntime({ debug = false, children }) {
142
150
  if (!runtimeApi)
143
151
  return;
144
152
  const { world } = runtimeApi;
145
- const stepDelta = Math.min(delta, MAX_PHYSICS_DELTA);
146
- if (mode === PrefabEditorMode.Play)
147
- updateWorld(world, listener, stepDelta);
153
+ const frameDelta = Math.min(delta, MAX_PHYSICS_CATCH_UP_DELTA);
154
+ if (mode === PrefabEditorMode.Play) {
155
+ const stepCount = Math.max(1, Math.ceil(frameDelta / MAX_PHYSICS_STEP_DELTA));
156
+ const stepDelta = frameDelta / stepCount;
157
+ for (let stepIndex = 0; stepIndex < stepCount; stepIndex += 1) {
158
+ updateWorld(world, listener, stepDelta);
159
+ }
160
+ }
148
161
  if (debugState)
149
162
  debugRenderer.update(debugState, world);
150
163
  }, -1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-three-game",
3
- "version": "0.0.103",
3
+ "version": "0.0.104",
4
4
  "description": "high performance 3D game engine built in React",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",