react-three-game 0.0.102 → 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);
@@ -139,15 +139,12 @@ function TextureSphere({ url, onError }) {
139
139
  const onErrorRef = useRef(onError);
140
140
  onErrorRef.current = onError;
141
141
  useEffect(() => {
142
- var _a;
143
142
  let cancelled = false;
144
- (_a = textureRef.current) === null || _a === void 0 ? void 0 : _a.dispose();
145
143
  textureRef.current = null;
146
144
  setTexture(null);
147
145
  const loader = new TextureLoader();
148
146
  loader.load(url, loadedTexture => {
149
147
  if (cancelled) {
150
- loadedTexture.dispose();
151
148
  return;
152
149
  }
153
150
  textureRef.current = loadedTexture;
@@ -159,9 +156,7 @@ function TextureSphere({ url, onError }) {
159
156
  }
160
157
  });
161
158
  return () => {
162
- var _a;
163
159
  cancelled = true;
164
- (_a = textureRef.current) === null || _a === void 0 ? void 0 : _a.dispose();
165
160
  textureRef.current = null;
166
161
  };
167
162
  }, [url]);
@@ -10,7 +10,7 @@ var __rest = (this && this.__rest) || function (s, e) {
10
10
  return t;
11
11
  };
12
12
  import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
13
- import { createContext, useContext, useEffect, useLayoutEffect, useMemo, useRef } from 'react';
13
+ import { createContext, useContext, useLayoutEffect, useMemo, useRef } from 'react';
14
14
  import { extend } from '@react-three/fiber';
15
15
  import { useFrame } from '@react-three/fiber';
16
16
  import { assetRef, assetRefs } from './ComponentRegistry';
@@ -57,32 +57,28 @@ function configureTexture(texture, options) {
57
57
  texture.magFilter = options.magFilter;
58
58
  texture.needsUpdate = true;
59
59
  }
60
- function cloneConfiguredTexture(texture, options) {
61
- if (!texture)
62
- return undefined;
63
- const nextTexture = texture.clone();
64
- configureTexture(nextTexture, options);
65
- return nextTexture;
66
- }
67
60
  function useConfiguredTexture(texture, options) {
68
- var _a, _b, _c, _d;
69
- const configuredTexture = useMemo(() => cloneConfiguredTexture(texture, options), [texture]);
70
- useEffect(() => {
71
- return () => configuredTexture === null || configuredTexture === void 0 ? void 0 : configuredTexture.dispose();
72
- }, [configuredTexture]);
61
+ const { colorSpace, repeat, repeatCount, offset, generateMipmaps, minFilter, magFilter, } = options;
62
+ const configuredTexture = useMemo(() => texture === null || texture === void 0 ? void 0 : texture.clone(), [texture]);
73
63
  useLayoutEffect(() => {
74
- configureTexture(configuredTexture, options);
64
+ configureTexture(configuredTexture, {
65
+ colorSpace,
66
+ repeat,
67
+ repeatCount,
68
+ offset,
69
+ generateMipmaps,
70
+ minFilter,
71
+ magFilter,
72
+ });
75
73
  }, [
76
74
  configuredTexture,
77
- options.colorSpace,
78
- options.repeat,
79
- (_a = options.repeatCount) === null || _a === void 0 ? void 0 : _a[0],
80
- (_b = options.repeatCount) === null || _b === void 0 ? void 0 : _b[1],
81
- (_c = options.offset) === null || _c === void 0 ? void 0 : _c[0],
82
- (_d = options.offset) === null || _d === void 0 ? void 0 : _d[1],
83
- options.generateMipmaps,
84
- options.minFilter,
85
- options.magFilter,
75
+ colorSpace,
76
+ repeat,
77
+ repeatCount,
78
+ offset,
79
+ generateMipmaps,
80
+ minFilter,
81
+ magFilter,
86
82
  ]);
87
83
  return configuredTexture;
88
84
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-three-game",
3
- "version": "0.0.102",
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",