@flare-engine/devtools 0.2.1 → 0.3.1

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/index.d.ts CHANGED
@@ -1,10 +1,7 @@
1
- import { GameLoop } from '@flare-engine/core';
2
- import * as react from 'react';
3
- import { ReactNode } from 'react';
4
- import { World } from '@flare-engine/ecs';
5
-
6
- declare function isDevMode(): boolean;
7
-
1
+ import { GameLoop } from "@flare-engine/core";
2
+ import { World } from "@flare-engine/ecs";
3
+ import { ReactNode } from "react";
4
+ //#region src/ring-buffer.d.ts
8
5
  /**
9
6
  * Source callback used by `createSnapshotRingBuffer` to produce a snapshot
10
7
  * each capture tick. The ring buffer never introspects the snapshot — it is
@@ -20,21 +17,22 @@ type SnapshotSource<T> = () => T;
20
17
  * number of snapshots currently held.
21
18
  */
22
19
  interface SnapshotRingBuffer<T> {
23
- /** Maximum number of snapshots retained. */
24
- readonly size: number;
25
- /** Number of snapshots currently held (0…size). */
26
- readonly length: number;
27
- /** Most recent snapshot, or `null` if `length === 0`. */
28
- readonly latest: T | null;
29
- /** Capture a new snapshot. Overwrites the oldest slot once full. */
30
- capture(): void;
31
- /** Return the snapshot from `framesAgo` captures back, or `null`. */
32
- rewind(framesAgo: number): T | null;
33
- /** Drop all retained snapshots. */
34
- reset(): void;
20
+ /** Maximum number of snapshots retained. */
21
+ readonly size: number;
22
+ /** Number of snapshots currently held (0…size). */
23
+ readonly length: number;
24
+ /** Most recent snapshot, or `null` if `length === 0`. */
25
+ readonly latest: T | null;
26
+ /** Capture a new snapshot. Overwrites the oldest slot once full. */
27
+ capture(): void;
28
+ /** Return the snapshot from `framesAgo` captures back, or `null`. */
29
+ rewind(framesAgo: number): T | null;
30
+ /** Drop all retained snapshots. */
31
+ reset(): void;
35
32
  }
36
33
  declare function createSnapshotRingBuffer<T>(size: number, source: SnapshotSource<T>): SnapshotRingBuffer<T>;
37
-
34
+ //#endregion
35
+ //#region src/time-scrubber.d.ts
38
36
  /**
39
37
  * Restore callback invoked by `TimeScrubber.rewind()` to apply a historical
40
38
  * snapshot back to world state. Consumers implement deserialize semantics
@@ -42,10 +40,10 @@ declare function createSnapshotRingBuffer<T>(size: number, source: SnapshotSourc
42
40
  */
43
41
  type RestoreCallback<T> = (snapshot: T) => void;
44
42
  interface TimeScrubberOptions<T> {
45
- loop: GameLoop;
46
- buffer: SnapshotRingBuffer<T>;
47
- /** Optional restore callback. If omitted, `rewind()` is a no-op beyond pausing the loop. */
48
- restore?: RestoreCallback<T>;
43
+ loop: GameLoop;
44
+ buffer: SnapshotRingBuffer<T>;
45
+ /** Optional restore callback. If omitted, `rewind()` is a no-op beyond pausing the loop. */
46
+ restore?: RestoreCallback<T>;
49
47
  }
50
48
  /**
51
49
  * TimeScrubber — imperative controller binding a `GameLoop` to a snapshot
@@ -53,111 +51,126 @@ interface TimeScrubberOptions<T> {
53
51
  * pauses the loop and hands the historical snapshot to the restore callback.
54
52
  */
55
53
  declare class TimeScrubber<T> {
56
- private readonly loop;
57
- private readonly buffer;
58
- private readonly restore;
59
- private _stepRequested;
60
- private _scrubFrames;
61
- constructor(options: TimeScrubberOptions<T>);
62
- /** Whether the loop is currently paused. */
63
- get paused(): boolean;
64
- /** Whether the scrubber is currently displaying a historical snapshot. */
65
- get scrubbing(): boolean;
66
- /** Current scrub offset (0 = latest, N = N frames back). */
67
- get scrubOffset(): number;
68
- /** Pause the loop (timescale → 0). */
69
- pause(): void;
70
- /** Resume the loop at normal speed and clear any scrub state. */
71
- resume(): void;
72
- /** Request a single-frame step. Caller polls `consumeStep()` each frame. */
73
- step(): void;
74
- /** Ring-buffer depth available for rewind. */
75
- get available(): number;
76
- /**
77
- * Pause the loop and restore the snapshot from `framesAgo` captures back.
78
- * Clamps to available history. Returns the snapshot applied, or `null`
79
- * when the buffer is empty.
80
- */
81
- rewind(framesAgo: number): T | null;
82
- /**
83
- * Returns true once per `step()` call, then resets. Frame-driver code is
84
- * expected to advance the simulation by one fixed tick when this is true.
85
- */
86
- consumeStep(): boolean;
54
+ private readonly loop;
55
+ private readonly buffer;
56
+ private readonly restore;
57
+ private _stepRequested;
58
+ private _scrubFrames;
59
+ /** Timescale captured at `pause()`, restored by `resume()`. Defaults to 1. */
60
+ private _savedTimescale;
61
+ constructor(options: TimeScrubberOptions<T>);
62
+ /** Whether the loop is currently paused. */
63
+ get paused(): boolean;
64
+ /** Whether the scrubber is currently displaying a historical snapshot. */
65
+ get scrubbing(): boolean;
66
+ /** Current scrub offset (0 = latest, N = N frames back). */
67
+ get scrubOffset(): number;
68
+ /** Pause the loop (timescale → 0), remembering the running speed.
69
+ * The `!== 0` guard means a double pause (e.g. `rewind()` calls `pause()`
70
+ * while already paused) keeps the first saved value instead of storing 0. */
71
+ pause(): void;
72
+ /** Resume the loop at its pre-pause speed and clear any scrub state.
73
+ * Restores the timescale captured at `pause()` (defaults to 1 if never
74
+ * paused), so resuming an active slow-mo returns to that rate, not 1×. */
75
+ resume(): void;
76
+ /** Request a single-frame step. Caller polls `consumeStep()` each frame. */
77
+ step(): void;
78
+ /** Ring-buffer depth available for rewind. */
79
+ get available(): number;
80
+ /**
81
+ * Pause the loop and restore the snapshot from `framesAgo` captures back.
82
+ * Clamps to available history. Returns the snapshot applied, or `null`
83
+ * when the buffer is empty.
84
+ */
85
+ rewind(framesAgo: number): T | null;
86
+ /**
87
+ * Returns true once per `step()` call, then resets. Frame-driver code is
88
+ * expected to advance the simulation by one fixed tick when this is true.
89
+ */
90
+ consumeStep(): boolean;
87
91
  }
88
-
92
+ //#endregion
93
+ //#region src/context.d.ts
89
94
  /** Devtools configuration. */
90
95
  interface DevtoolsConfig {
91
- /** Ring-buffer depth in frames. Default 120 (~2 s @ 60 fps). */
92
- ringSize?: number;
93
- /** Capture every Nth `onUpdate`. Default 1 (every frame). */
94
- captureInterval?: number;
95
- /** Enable the native HUD surface. Default true. */
96
- enabledOnNative?: boolean;
96
+ /** Ring-buffer depth in frames. Default 120 (~2 s @ 60 fps). */
97
+ ringSize?: number;
98
+ /** Capture every Nth `onUpdate`. Default 1 (every frame). */
99
+ captureInterval?: number;
100
+ /** Enable the native HUD surface. Default true. */
101
+ enabledOnNative?: boolean;
97
102
  }
98
103
  /** Value exposed via `DevtoolsContext`. */
99
104
  interface DevtoolsContextValue {
100
- world: World;
101
- loop: GameLoop;
102
- buffer: SnapshotRingBuffer<unknown>;
103
- scrubber: TimeScrubber<unknown>;
104
- selectedEntity: number | null;
105
- select(entity: number | null): void;
106
- pause(): void;
107
- step(): void;
108
- resume(): void;
109
- }
110
- declare const DevtoolsContext: react.Context<DevtoolsContextValue | null>;
111
-
112
- interface DevtoolsProviderProps<T = unknown> {
113
- world: World;
114
- loop: GameLoop;
115
- /** Snapshot producer. Called on every capture tick. Must be cheap. */
116
- snapshot: SnapshotSource<T>;
117
- /** Optional restore callback for `TimeScrubber.rewind()`. */
118
- restore?: RestoreCallback<T>;
119
- config?: DevtoolsConfig;
120
- children?: ReactNode;
105
+ world: World;
106
+ loop: GameLoop;
107
+ buffer: SnapshotRingBuffer<unknown>;
108
+ scrubber: TimeScrubber<unknown>;
109
+ selectedEntity: number | null;
110
+ select(entity: number | null): void;
111
+ pause(): void;
112
+ step(): void;
113
+ resume(): void;
121
114
  }
122
- /**
123
- * DevtoolsProvider — mounts a devtools session for a given `World` + `GameLoop`.
124
- * Subscribes to `loop.onUpdate` and captures snapshots into a pre-allocated
125
- * ring buffer; exposes scrubber controls via `DevtoolsContext`.
126
- */
127
- declare function DevtoolsProvider<T>({ world, loop, snapshot, restore, config, children, }: DevtoolsProviderProps<T>): ReactNode;
128
-
115
+ declare const DevtoolsContext: import("react").Context<DevtoolsContextValue | null>;
116
+ //#endregion
117
+ //#region src/dev-mode.d.ts
118
+ declare function isDevMode(): boolean;
119
+ //#endregion
120
+ //#region src/hooks.d.ts
129
121
  /** Returns the active devtools context, or throws if no provider is mounted. */
130
122
  declare function useDevtools(): DevtoolsContextValue;
131
123
  interface EntityInspectorView {
132
- selected: number | null;
133
- select(entity: number | null): void;
134
- /** Entity IDs present in the world at the moment the hook was read. */
135
- entities: readonly number[];
124
+ selected: number | null;
125
+ select(entity: number | null): void;
126
+ /** Entity IDs present in the world at the moment the hook was read. */
127
+ entities: readonly number[];
136
128
  }
137
129
  /** Entity-inspector hook. Never mutates the world — read-only snapshot. */
138
130
  declare function useEntityInspector(): EntityInspectorView;
139
131
  interface TimeScrubView {
140
- paused: boolean;
141
- scrubbing: boolean;
142
- available: number;
143
- pause(): void;
144
- resume(): void;
145
- step(): void;
146
- rewind(framesAgo: number): void;
132
+ paused: boolean;
133
+ scrubbing: boolean;
134
+ available: number;
135
+ pause(): void;
136
+ resume(): void;
137
+ step(): void;
138
+ rewind(framesAgo: number): void;
147
139
  }
148
140
  /** Time-scrub hook — exposes the scrubber's imperative controls. */
149
141
  declare function useTimeScrub(): TimeScrubView;
150
-
142
+ //#endregion
143
+ //#region src/hud.d.ts
144
+ /**
145
+ * DevtoolsHUD — compact native overlay. Shows buffer depth + pause/step/resume
146
+ * buttons. No-op on web (renders `null`).
147
+ */
148
+ declare function DevtoolsHUD(): ReactNode;
149
+ //#endregion
150
+ //#region src/panel.d.ts
151
151
  /**
152
152
  * DevtoolsPanel — full web-side panel. Renders the entity tree, scrub
153
153
  * controls, and buffer depth. No-op on native (renders `null`).
154
154
  */
155
155
  declare function DevtoolsPanel(): ReactNode;
156
-
156
+ //#endregion
157
+ //#region src/provider.d.ts
158
+ interface DevtoolsProviderProps<T = unknown> {
159
+ world: World;
160
+ loop: GameLoop;
161
+ /** Snapshot producer. Called on every capture tick. Must be cheap. */
162
+ snapshot: SnapshotSource<T>;
163
+ /** Optional restore callback for `TimeScrubber.rewind()`. */
164
+ restore?: RestoreCallback<T>;
165
+ config?: DevtoolsConfig;
166
+ children?: ReactNode;
167
+ }
157
168
  /**
158
- * DevtoolsHUD — compact native overlay. Shows buffer depth + pause/step/resume
159
- * buttons. No-op on web (renders `null`).
169
+ * DevtoolsProvider — mounts a devtools session for a given `World` + `GameLoop`.
170
+ * Subscribes to `loop.onUpdate` and captures snapshots into a pre-allocated
171
+ * ring buffer; exposes scrubber controls via `DevtoolsContext`.
160
172
  */
161
- declare function DevtoolsHUD(): ReactNode;
162
-
173
+ declare function DevtoolsProvider<T>({ world, loop, snapshot, restore, config, children }: DevtoolsProviderProps<T>): ReactNode;
174
+ //#endregion
163
175
  export { type DevtoolsConfig, DevtoolsContext, type DevtoolsContextValue, DevtoolsHUD, DevtoolsPanel, DevtoolsProvider, type DevtoolsProviderProps, type EntityInspectorView, type RestoreCallback, type SnapshotRingBuffer, type SnapshotSource, type TimeScrubView, TimeScrubber, type TimeScrubberOptions, createSnapshotRingBuffer, isDevMode, useDevtools, useEntityInspector, useTimeScrub };
176
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/ring-buffer.ts","../src/time-scrubber.ts","../src/context.ts","../src/dev-mode.ts","../src/hooks.ts","../src/hud.tsx","../src/panel.tsx","../src/provider.tsx"],"mappings":";;;;;;;;;;KAMY,eAAe,WAAW;;;;;;;;UASrB,mBAAmB;;WAEzB;;WAEA;;WAEA,QAAQ;;EAEjB;;EAEA,OAAO,oBAAoB;;EAE3B;;iBAGc,yBAAyB,GACvC,cACA,QAAQ,eAAe,KACtB,mBAAmB;;;;;;;;KCzBV,gBAAgB,MAAM,UAAU;UAE3B,oBAAoB;EACnC,MAAM;EACN,QAAQ,mBAAmB;;EAE3B,UAAU,gBAAgB;;;;;;;cAQf,aAAa;mBACP;mBACA;mBACA;UACT;UACA;;UAEA;cAEI,SAAS,oBAAoB;;MAOrC;;MAKA;;MAKA;;;;EAOJ;;;;EAUA;;EAOA;;MAKI;;;;;;EASJ,OAAO,oBAAoB;;;;;EAiB3B;;;;;UChGe;;EAEf;;EAEA;;EAEA;;;UAIe;EACf,OAAO;EACP,MAAM;EACN,QAAQ;EACR,UAAU;EACV;EACA,OAAO;EACP;EACA;EACA;;cAGW,iCAAe,QAAA;;;iBC3BZ;;;;iBCEA,eAAe;UAQd;EACf;EACA,OAAO;;EAEP;;;iBAIc,sBAAsB;UAOrB;EACf;EACA;EACA;EACA;EACA;EACA;EACA,OAAO;;;iBAIO,gBAAgB;;;;;;;iBC9BhB,eAAe;;;;;;;iBCAf,iBAAiB;;;UCDhB,sBAAsB;EACrC,OAAO;EACP,MAAM;;EAEN,UAAU,eAAe;;EAEzB,UAAU,gBAAgB;EAC1B,SAAS;EACT,WAAW;;;;;;;iBAcG,iBAAiB,KAC/B,OACA,MACA,UACA,SACA,QACA,YACC,sBAAsB,KAAK"}