react-three-game 0.0.106 → 0.0.107
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,9 +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
|
|
11
|
+
const MAX_PHYSICS_STEP_DELTA = 1 / 60;
|
|
12
12
|
const MAX_PHYSICS_CATCH_UP_DELTA = 1 / 10;
|
|
13
|
-
const MAX_PHYSICS_STEPS_PER_FRAME = 4;
|
|
14
13
|
let didRegisterCrashcat = false;
|
|
15
14
|
function ensureCrashcatRegistered() {
|
|
16
15
|
if (didRegisterCrashcat)
|
|
@@ -69,7 +68,6 @@ export function CrashcatRuntime({ debug = false, children }) {
|
|
|
69
68
|
const bodiesRef = useRef(new Map());
|
|
70
69
|
const bodyByIdRef = useRef(new Map());
|
|
71
70
|
const apiRef = useRef(null);
|
|
72
|
-
const accumulatedDeltaRef = useRef(0);
|
|
73
71
|
const [debugState] = useState(() => debug ? createDebugState() : null);
|
|
74
72
|
const listener = useMemo(() => ({
|
|
75
73
|
onContactAdded: (bodyA, bodyB, manifold) => {
|
|
@@ -133,10 +131,8 @@ export function CrashcatRuntime({ debug = false, children }) {
|
|
|
133
131
|
getBody: (nodeId) => { var _a, _b; return (_b = (_a = bodies.get(nodeId)) === null || _a === void 0 ? void 0 : _a.body) !== null && _b !== void 0 ? _b : null; },
|
|
134
132
|
};
|
|
135
133
|
apiRef.current = runtimeApi;
|
|
136
|
-
accumulatedDeltaRef.current = 0;
|
|
137
134
|
setCrashcatApi(runtimeApi);
|
|
138
135
|
return () => {
|
|
139
|
-
accumulatedDeltaRef.current = 0;
|
|
140
136
|
for (const entry of bodies.values()) {
|
|
141
137
|
rigidBody.remove(world, entry.body);
|
|
142
138
|
}
|
|
@@ -156,20 +152,11 @@ export function CrashcatRuntime({ debug = false, children }) {
|
|
|
156
152
|
const { world } = runtimeApi;
|
|
157
153
|
const frameDelta = Math.min(delta, MAX_PHYSICS_CATCH_UP_DELTA);
|
|
158
154
|
if (mode === PrefabEditorMode.Play) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
updateWorld(world, listener, FIXED_PHYSICS_STEP_DELTA);
|
|
164
|
-
accumulatedDeltaRef.current -= FIXED_PHYSICS_STEP_DELTA;
|
|
165
|
-
stepCount += 1;
|
|
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);
|
|
166
159
|
}
|
|
167
|
-
if (stepCount === MAX_PHYSICS_STEPS_PER_FRAME) {
|
|
168
|
-
accumulatedDeltaRef.current = Math.min(accumulatedDeltaRef.current, FIXED_PHYSICS_STEP_DELTA);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
accumulatedDeltaRef.current = 0;
|
|
173
160
|
}
|
|
174
161
|
if (debugState)
|
|
175
162
|
debugRenderer.update(debugState, world);
|