@flare-engine/debug 0.2.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/index.d.mts CHANGED
@@ -1,72 +1,101 @@
1
- import { Clock } from '@flare-engine/core';
2
-
1
+ import { Clock } from "@flare-engine/core";
2
+ //#region src/boot-trace.d.ts
3
+ type BootEntry = {
4
+ readonly name: string;
5
+ readonly t: number;
6
+ };
7
+ type BootTraceHandle = {
8
+ mark(name: string): void;
9
+ dump(): string | null;
10
+ reset(): void;
11
+ getEntries(): readonly BootEntry[];
12
+ };
13
+ declare function createBootTrace(label?: string): BootTraceHandle;
14
+ //#endregion
15
+ //#region src/stats.d.ts
3
16
  /** Snapshot of engine stats for a single frame. */
4
17
  interface DebugStats {
5
- /** Frames per second (smoothed). */
6
- fps: number;
7
- /** Raw delta time in seconds. */
8
- rawDt: number;
9
- /** Scaled delta time in seconds. */
10
- dt: number;
11
- /** Current frame number. */
12
- frame: number;
13
- /** Total active entities (set by user). */
14
- entityCount: number;
15
- /** Draw calls this frame (set by user). */
16
- drawCalls: number;
18
+ /** Frames per second (smoothed). */
19
+ fps: number;
20
+ /** Raw delta time in seconds. */
21
+ rawDt: number;
22
+ /** Scaled delta time in seconds. */
23
+ dt: number;
24
+ /** Current frame number. */
25
+ frame: number;
26
+ /** Total active entities (set by user). */
27
+ entityCount: number;
28
+ /** Draw calls this frame (set by user). */
29
+ drawCalls: number;
17
30
  }
18
31
  /**
19
32
  * StatsTracker — collects and exposes per-frame debug statistics.
20
33
  * Wrap in `__DEV__` checks at the call site for tree-shaking.
21
34
  */
22
35
  declare class StatsTracker {
23
- /** Current frame stats (read-only snapshot). */
24
- readonly stats: DebugStats;
25
- /** Update timing stats from the clock. */
26
- updateFromClock(fps: number, rawDt: number, dt: number, frame: number): void;
27
- /** Set entity count for this frame. */
28
- setEntityCount(count: number): void;
29
- /** Set draw call count for this frame. */
30
- setDrawCalls(count: number): void;
31
- /** Reset all counters to zero. */
32
- reset(): void;
36
+ /** Current frame stats (read-only snapshot). */
37
+ readonly stats: DebugStats;
38
+ /** Update timing stats from the clock. */
39
+ updateFromClock(fps: number, rawDt: number, dt: number, frame: number): void;
40
+ /** Set entity count for this frame. */
41
+ setEntityCount(count: number): void;
42
+ /** Set draw call count for this frame. */
43
+ setDrawCalls(count: number): void;
44
+ /** Reset all counters to zero. */
45
+ reset(): void;
33
46
  }
34
-
47
+ //#endregion
48
+ //#region src/fps-widget.d.ts
35
49
  /**
36
- * TimeControl — pause, step-frame, and slow-motion via Clock.timescale.
37
- * Wrap in `__DEV__` checks at the call site for tree-shaking.
50
+ * Formatter for a compact FPS / stats overlay.
51
+ *
52
+ * Consumes a `DebugStats` snapshot and exposes formatted strings ready
53
+ * for the host to draw (Skia `canvas.drawText`, an RN `<Text>` overlay,
54
+ * whatever). The widget itself has no rendering dependency so it stays
55
+ * drop-in across renderers.
56
+ *
57
+ * Wrap in `__DEV__` at the call site for tree-shaking.
38
58
  */
39
- declare class TimeControl {
40
- private _clock;
41
- private _savedTimescale;
42
- private _paused;
43
- private _stepRequested;
44
- constructor(clock: Clock);
45
- /** Whether the game is currently paused. */
46
- get paused(): boolean;
47
- /** Current time scale. */
48
- get timescale(): number;
49
- /** Pause the game (sets timescale to 0). */
50
- pause(): void;
51
- /** Resume the game (restores previous timescale). */
52
- resume(): void;
53
- /** Toggle pause/resume. */
54
- toggle(): void;
55
- /**
56
- * Request a single-frame step while paused.
57
- * Call this, then on the next update check `consumeStep()`.
58
- */
59
- step(): void;
60
- /**
61
- * Consume a pending step request. Returns true if a step was requested.
62
- * When true, the caller should run one frame with the saved timescale,
63
- * then re-pause.
64
- */
65
- consumeStep(): boolean;
66
- /** Set slow-motion multiplier (e.g., 0.5 for half-speed). */
67
- setTimescale(scale: number): void;
59
+ interface FpsWidget {
60
+ /** Rebuild `line` / `lines` from the latest stats. */
61
+ update(stats: DebugStats): void;
62
+ /** Compact one-line summary, e.g. "60 FPS | 16.7ms | e:42 d:8". */
63
+ line: string;
64
+ /** Multi-line breakdown — one string per stat row. */
65
+ readonly lines: string[];
66
+ }
67
+ /** Options for the FPS widget formatter. */
68
+ interface FpsWidgetOptions {
69
+ /** Show entity count in the one-line summary. Default true. */
70
+ showEntities?: boolean;
71
+ /** Show draw call count in the one-line summary. Default true. */
72
+ showDrawCalls?: boolean;
73
+ /** Number of decimals for milliseconds. Default 1. */
74
+ msPrecision?: number;
68
75
  }
69
-
76
+ /** Create a new FPS widget formatter. */
77
+ declare function createFpsWidget(options?: FpsWidgetOptions): FpsWidget;
78
+ //#endregion
79
+ //#region src/frame-budget.d.ts
80
+ type FrameBudgetLimits = Record<string, number>;
81
+ type FrameBudgetSnapshot = Record<string, number>;
82
+ type FrameBudgetHandle = {
83
+ recordFrame(dtSec: number): void;
84
+ recordCounters(snapshot: FrameBudgetSnapshot): void;
85
+ getSnapshot(): Readonly<FrameBudgetSnapshot>;
86
+ getAvgFps(): number;
87
+ resetFpsRing(): void;
88
+ };
89
+ type FrameBudgetOpts = {
90
+ limits: FrameBudgetLimits;
91
+ fpsThreshold?: number;
92
+ ringSize?: number;
93
+ onWatchdog?: () => void;
94
+ debug?: boolean;
95
+ };
96
+ declare function createFrameBudget(opts: FrameBudgetOpts): FrameBudgetHandle;
97
+ //#endregion
98
+ //#region src/overlay.d.ts
70
99
  /**
71
100
  * DebugOverlay — configuration for debug visualization overlays.
72
101
  * The actual rendering is done by the host (e.g., @flare-engine/react) reading
@@ -74,38 +103,38 @@ declare class TimeControl {
74
103
  * Wrap in `__DEV__` checks at the call site for tree-shaking.
75
104
  */
76
105
  interface OverlayFlags {
77
- /** Show collision bounding boxes. */
78
- showCollisionBounds: boolean;
79
- /** Show entity origin points. */
80
- showEntityOrigins: boolean;
81
- /** Show velocity vectors. */
82
- showVelocityVectors: boolean;
83
- /** Show FPS/stats overlay. */
84
- showStats: boolean;
106
+ /** Show collision bounding boxes. */
107
+ showCollisionBounds: boolean;
108
+ /** Show entity origin points. */
109
+ showEntityOrigins: boolean;
110
+ /** Show velocity vectors. */
111
+ showVelocityVectors: boolean;
112
+ /** Show FPS/stats overlay. */
113
+ showStats: boolean;
85
114
  }
86
115
  /** Debug draw command types. */
87
116
  interface DebugRect {
88
- readonly type: 'rect';
89
- x: number;
90
- y: number;
91
- width: number;
92
- height: number;
93
- color: string;
117
+ readonly type: 'rect';
118
+ x: number;
119
+ y: number;
120
+ width: number;
121
+ height: number;
122
+ color: string;
94
123
  }
95
124
  interface DebugCircle {
96
- readonly type: 'circle';
97
- x: number;
98
- y: number;
99
- radius: number;
100
- color: string;
125
+ readonly type: 'circle';
126
+ x: number;
127
+ y: number;
128
+ radius: number;
129
+ color: string;
101
130
  }
102
131
  interface DebugLine {
103
- readonly type: 'line';
104
- x1: number;
105
- y1: number;
106
- x2: number;
107
- y2: number;
108
- color: string;
132
+ readonly type: 'line';
133
+ x1: number;
134
+ y1: number;
135
+ x2: number;
136
+ y2: number;
137
+ color: string;
109
138
  }
110
139
  /** Union of debug draw primitive commands. */
111
140
  type DebugDrawCommand = DebugRect | DebugCircle | DebugLine;
@@ -115,129 +144,108 @@ type DebugDrawCommand = DebugRect | DebugCircle | DebugLine;
115
144
  * by the renderer.
116
145
  */
117
146
  declare class DebugOverlay {
118
- /** Active overlay flags. */
119
- readonly flags: OverlayFlags;
120
- /** Queued debug draw commands for the current frame. */
121
- private _commands;
122
- /** Number of queued commands. */
123
- get commandCount(): number;
124
- /** Get all commands (read-only view). */
125
- get commands(): readonly DebugDrawCommand[];
126
- /** Add a debug rectangle. */
127
- drawRect(x: number, y: number, width: number, height: number, color?: string): void;
128
- /** Add a debug circle. */
129
- drawCircle(x: number, y: number, radius: number, color?: string): void;
130
- /** Add a debug line. */
131
- drawLine(x1: number, y1: number, x2: number, y2: number, color?: string): void;
132
- /** Clear all commands. Call at the start of each frame. */
133
- clear(): void;
134
- /** Toggle a specific overlay flag. */
135
- toggleFlag(flag: keyof OverlayFlags): void;
136
- /** Enable all overlays. */
137
- enableAll(): void;
138
- /** Disable all overlays. */
139
- disableAll(): void;
140
- }
141
-
142
- /**
143
- * Formatter for a compact FPS / stats overlay.
144
- *
145
- * Consumes a `DebugStats` snapshot and exposes formatted strings ready
146
- * for the host to draw (Skia `canvas.drawText`, an RN `<Text>` overlay,
147
- * whatever). The widget itself has no rendering dependency so it stays
148
- * drop-in across renderers.
149
- *
150
- * Wrap in `__DEV__` at the call site for tree-shaking.
151
- */
152
- interface FpsWidget {
153
- /** Rebuild `line` / `lines` from the latest stats. */
154
- update(stats: DebugStats): void;
155
- /** Compact one-line summary, e.g. "60 FPS | 16.7ms | e:42 d:8". */
156
- line: string;
157
- /** Multi-line breakdown — one string per stat row. */
158
- readonly lines: string[];
159
- }
160
- /** Options for the FPS widget formatter. */
161
- interface FpsWidgetOptions {
162
- /** Show entity count in the one-line summary. Default true. */
163
- showEntities?: boolean;
164
- /** Show draw call count in the one-line summary. Default true. */
165
- showDrawCalls?: boolean;
166
- /** Number of decimals for milliseconds. Default 1. */
167
- msPrecision?: number;
147
+ /** Active overlay flags. */
148
+ readonly flags: OverlayFlags;
149
+ /** Queued debug draw commands for the current frame. */
150
+ private _commands;
151
+ /** Number of queued commands. */
152
+ get commandCount(): number;
153
+ /** Get all commands (read-only view). */
154
+ get commands(): readonly DebugDrawCommand[];
155
+ /** Add a debug rectangle. */
156
+ drawRect(x: number, y: number, width: number, height: number, color?: string): void;
157
+ /** Add a debug circle. */
158
+ drawCircle(x: number, y: number, radius: number, color?: string): void;
159
+ /** Add a debug line. */
160
+ drawLine(x1: number, y1: number, x2: number, y2: number, color?: string): void;
161
+ /** Clear all commands. Call at the start of each frame. */
162
+ clear(): void;
163
+ /** Toggle a specific overlay flag. */
164
+ toggleFlag(flag: keyof OverlayFlags): void;
165
+ /** Enable all overlays. */
166
+ enableAll(): void;
167
+ /** Disable all overlays. */
168
+ disableAll(): void;
168
169
  }
169
- /** Create a new FPS widget formatter. */
170
- declare function createFpsWidget(options?: FpsWidgetOptions): FpsWidget;
171
-
172
- type FrameBudgetLimits = Record<string, number>;
173
- type FrameBudgetSnapshot = Record<string, number>;
174
- type FrameBudgetHandle = {
175
- recordFrame(dtSec: number): void;
176
- recordCounters(snapshot: FrameBudgetSnapshot): void;
177
- getSnapshot(): Readonly<FrameBudgetSnapshot>;
178
- getAvgFps(): number;
179
- resetFpsRing(): void;
180
- };
181
- type FrameBudgetOpts = {
182
- limits: FrameBudgetLimits;
183
- fpsThreshold?: number;
184
- ringSize?: number;
185
- onWatchdog?: () => void;
186
- debug?: boolean;
187
- };
188
- declare function createFrameBudget(opts: FrameBudgetOpts): FrameBudgetHandle;
189
-
190
- type BootEntry = {
191
- readonly name: string;
192
- readonly t: number;
193
- };
194
- type BootTraceHandle = {
195
- mark(name: string): void;
196
- dump(): string | null;
197
- reset(): void;
198
- getEntries(): readonly BootEntry[];
199
- };
200
- declare function createBootTrace(label?: string): BootTraceHandle;
201
-
170
+ //#endregion
171
+ //#region src/perf-recorder.d.ts
202
172
  type PerfSectionStats = {
203
- readonly name: string;
204
- readonly count: number;
205
- readonly min: number;
206
- readonly max: number;
207
- readonly mean: number;
208
- readonly p50: number;
209
- readonly p95: number;
210
- readonly p99: number;
173
+ readonly name: string;
174
+ readonly count: number;
175
+ readonly min: number;
176
+ readonly max: number;
177
+ readonly mean: number;
178
+ readonly p50: number;
179
+ readonly p95: number;
180
+ readonly p99: number;
211
181
  };
212
182
  type PerfCounterStats = {
213
- readonly name: string;
214
- readonly count: number;
215
- readonly min: number;
216
- readonly max: number;
217
- readonly sum: number;
218
- readonly mean: number;
183
+ readonly name: string;
184
+ readonly count: number;
185
+ readonly min: number;
186
+ readonly max: number;
187
+ readonly sum: number;
188
+ readonly mean: number;
219
189
  };
220
190
  type PerfReport = {
221
- readonly label: string;
222
- readonly durationMs: number;
223
- readonly frameCount: number;
224
- readonly sections: readonly PerfSectionStats[];
225
- readonly counters: readonly PerfCounterStats[];
191
+ readonly label: string;
192
+ readonly durationMs: number;
193
+ readonly frameCount: number;
194
+ readonly sections: readonly PerfSectionStats[];
195
+ readonly counters: readonly PerfCounterStats[];
226
196
  };
227
197
  type PerfRecorderHandle = {
228
- beginSection(name: string): void;
229
- endSection(name: string): void;
230
- recordFrame(counters?: Record<string, number>): void;
231
- flush(): PerfReport;
232
- reset(): void;
198
+ beginSection(name: string): void;
199
+ endSection(name: string): void;
200
+ recordFrame(counters?: Record<string, number>): void;
201
+ flush(): PerfReport;
202
+ reset(): void;
233
203
  };
234
204
  type PerfRecorderOpts = {
235
- label?: string;
236
- ringSize?: number;
205
+ label?: string;
206
+ ringSize?: number;
237
207
  };
238
208
  declare function createPerfRecorder(opts?: PerfRecorderOpts): PerfRecorderHandle;
239
-
209
+ //#endregion
210
+ //#region src/perf-output.d.ts
240
211
  declare const PERF_BENCH_TAG = "[perf-bench]";
241
212
  declare function emitPerfReport(report: PerfReport): void;
242
-
213
+ //#endregion
214
+ //#region src/time-control.d.ts
215
+ /**
216
+ * TimeControl — pause, step-frame, and slow-motion via Clock.timescale.
217
+ * Wrap in `__DEV__` checks at the call site for tree-shaking.
218
+ */
219
+ declare class TimeControl {
220
+ private _clock;
221
+ private _savedTimescale;
222
+ private _paused;
223
+ private _stepRequested;
224
+ constructor(clock: Clock);
225
+ /** Whether the game is currently paused. */
226
+ get paused(): boolean;
227
+ /** Current time scale. */
228
+ get timescale(): number;
229
+ /** Pause the game (sets timescale to 0). */
230
+ pause(): void;
231
+ /** Resume the game (restores previous timescale). */
232
+ resume(): void;
233
+ /** Toggle pause/resume. */
234
+ toggle(): void;
235
+ /**
236
+ * Request a single-frame step while paused.
237
+ * Call this, then on the next update check `consumeStep()`.
238
+ */
239
+ step(): void;
240
+ /**
241
+ * Consume a pending step request. Returns true if a step was requested.
242
+ * When true, the caller should run one frame with the saved timescale,
243
+ * then re-pause.
244
+ */
245
+ consumeStep(): boolean;
246
+ /** Set slow-motion multiplier (e.g., 0.5 for half-speed). */
247
+ setTimescale(scale: number): void;
248
+ }
249
+ //#endregion
243
250
  export { type BootEntry, type BootTraceHandle, type DebugCircle, type DebugDrawCommand, type DebugLine, DebugOverlay, type DebugRect, type DebugStats, type FpsWidget, type FpsWidgetOptions, type FrameBudgetHandle, type FrameBudgetLimits, type FrameBudgetSnapshot, type OverlayFlags, PERF_BENCH_TAG, type PerfCounterStats, type PerfRecorderHandle, type PerfReport, type PerfSectionStats, StatsTracker, TimeControl, createBootTrace, createFpsWidget, createFrameBudget, createPerfRecorder, emitPerfReport };
251
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/boot-trace.ts","../src/stats.ts","../src/fps-widget.ts","../src/frame-budget.ts","../src/overlay.ts","../src/perf-recorder.ts","../src/perf-output.ts","../src/time-control.ts"],"mappings":";;KAAY;WACD;WACA;;KAGC;EACV,KAAK;EACL;EACA;EACA,uBAAuB;;iBAUT,gBAAgB,iBAAuB;;;;UClBtC;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;;;;;cAOW;;WAEF,OAAO;;EAUhB,gBAAgB,aAAa,eAAe,YAAY;;EAQxD,eAAe;;EAKf,aAAa;;EAKb;;;;;;;;;;;;;;UCtCe;;EAEf,OAAO,OAAO;;EAEd;;WAES;;;UAIM;;EAEf;;EAEA;;EAEA;;;iBAIc,gBAAgB,UAAS,mBAAwB;;;KChCrD,oBAAoB;KACpB,sBAAsB;KAEtB;EACV,YAAY;EACZ,eAAe,UAAU;EACzB,eAAe,SAAS;EACxB;EACA;;KAGG;EACH,QAAQ;EACR;EACA;EACA;EACA;;iBAGc,kBAAkB,MAAM,kBAAkB;;;;;;;;;UCbzC;;EAEf;;EAEA;;EAEA;;EAEA;;;UAIe;WACN;EACT;EACA;EACA;EACA;EACA;;UAGe;WACN;EACT;EACA;EACA;EACA;;UAGe;WACN;EACT;EACA;EACA;EACA;EACA;;;KAIU,mBAAmB,YAAY,cAAc;;;;;;cAO5C;;WAEF,OAAO;;UAQR;;MAGJ;;MAKA,qBAAqB;;EAKzB,SAAS,WAAW,WAAW,eAAe,gBAAgB;;EAK9D,WAAW,WAAW,WAAW,gBAAgB;;EAKjD,SAAS,YAAY,YAAY,YAAY,YAAY;;EAKzD;;EAKA,WAAW,YAAY;;EAKvB;;EAQA;;;;KC5GU;WACD;WACA;WACA;WACA;WACA;WACA;WACA;WACA;;KAGC;WACD;WACA;WACA;WACA;WACA;WACA;;KAGC;WACD;WACA;WACA;WACA,mBAAmB;WACnB,mBAAmB;;KAGlB;EACV,aAAa;EACb,WAAW;EACX,YAAY,WAAW;EACvB,SAAS;EACT;;KAoBG;EACH;EACA;;iBAqBc,mBAAmB,OAAM,mBAAwB;;;cC1EpD;iBAEG,eAAe,QAAQ;;;;;;;cCE1B;UACH;UACA;UACA;UACA;cAEI,OAAO;;MAKf;;MAKA;;EAKJ;;EAQA;;EAQA;;;;;EAYA;;;;;;EAUA;;EAOA,aAAa"}