@threenative/core 0.1.0 → 0.3.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.
package/dist/hot.d.ts CHANGED
@@ -1,9 +1,11 @@
1
- import { a as audioRuntimeSnapshot } from './audio-3vkjtiuo.js';
2
- import { G as Game } from './game-DRPs3M7r.js';
1
+ import { a as audioRuntimeSnapshot } from './audio-Dp2mXpD3.js';
2
+ import { I as IGame } from './game-CYIaKhgl.js';
3
3
  import 'three';
4
+ import './canvas-layer-CtrZHgIh.js';
5
+ import 'three/webgpu';
4
6
  import 'zustand/vanilla';
5
7
 
6
- interface HotDiagnostics {
8
+ interface IHotDiagnostics {
7
9
  readonly reloads: number;
8
10
  readonly entities: number;
9
11
  readonly sceneObjects: number;
@@ -11,7 +13,33 @@ interface HotDiagnostics {
11
13
  readonly audio: ReturnType<typeof audioRuntimeSnapshot>;
12
14
  readonly physics: number | null;
13
15
  }
16
+ /**
17
+ * Validate that hot-reload state can cross the Vite boundary.
18
+ * @situation preserve JSON-shaped state during hot reload
19
+ * @situation reject a non-portable game state before reload
20
+ * @constraint state must contain finite numbers and plain objects only
21
+ * @example assertPortableState(game.state.getState());
22
+ */
14
23
  declare function assertPortableState(state: unknown): void;
15
- declare function acceptHotUpdate<TState extends Record<string, unknown>, TPhysics>(game: Game<TState, TPhysics>, hot: ImportMeta["hot"]): void;
24
+ /**
25
+ * Register hot-reload state preservation for a game.
26
+ * @situation keep game state while editing source in development
27
+ * @situation diagnose state shape changes during hot reload
28
+ * @constraint use only in the web development entry
29
+ * @example acceptHotUpdate(game, import.meta.hot);
30
+ */
31
+ declare function acceptHotUpdate<TState extends Record<string, unknown>, TPhysics>(game: IGame<TState, TPhysics>, hot: IImportMeta["hot"]): void;
32
+ interface IImportMeta {
33
+ readonly env?: {
34
+ readonly DEV?: boolean;
35
+ };
36
+ readonly hot?: IViteHotContext;
37
+ }
38
+ interface IViteHotContext {
39
+ readonly data: Record<string, unknown>;
40
+ accept(): void;
41
+ dispose(callback: (data: Record<string, unknown>) => void): void;
42
+ invalidate(message?: string): void;
43
+ }
16
44
 
17
- export { type HotDiagnostics, acceptHotUpdate, assertPortableState };
45
+ export { type IHotDiagnostics, acceptHotUpdate, assertPortableState };
package/dist/hot.js CHANGED
@@ -5,11 +5,13 @@ var buses = /* @__PURE__ */ new Set();
5
5
  function audioRuntimeSnapshot() {
6
6
  let queued = 0;
7
7
  let voices = 0;
8
+ let pooled = 0;
8
9
  for (const bus of buses) {
9
10
  queued += bus.queued;
10
11
  voices += bus.voices;
12
+ pooled += bus.pooled;
11
13
  }
12
- return { queued, voices };
14
+ return { pooled, queued, voices };
13
15
  }
14
16
 
15
17
  // src/hot.ts
@@ -23,6 +25,12 @@ function acceptHotUpdate(game, hot) {
23
25
  const carried = hot.data.threenative;
24
26
  const reloads = carried?.reloads ?? 0;
25
27
  if (carried !== void 0) restoreState(game, carried.state);
28
+ if (carried?.sceneName !== void 0) {
29
+ try {
30
+ game.resumeScene(carried.sceneName);
31
+ } catch {
32
+ }
33
+ }
26
34
  if (isDev && typeof window !== "undefined") {
27
35
  const host = window;
28
36
  host.__THREENATIVE__ = {
@@ -39,7 +47,7 @@ function acceptHotUpdate(game, hot) {
39
47
  game.state.flush();
40
48
  const state = game.state.getState();
41
49
  assertPortableState(state);
42
- data.threenative = { reloads: reloads + 1, state };
50
+ data.threenative = { reloads: reloads + 1, sceneName: game.sceneName, state };
43
51
  } catch (error) {
44
52
  data.threenative = void 0;
45
53
  hot.invalidate(error instanceof Error ? error.message : String(error));