Open History to see the last commit
1/**
2 * Debug configuration for performance testing.
3 * Toggle individual rendering features to isolate performance bottlenecks.
4 */
5
6export interface DebugConfig {
7 /** Show FPS counter overlay */
8 showFps: boolean
9 /** Render unplaced grid lines */
10 renderGridLines: boolean
11 /** Render dots at grid intersections */
12 renderDots: boolean
13 /** Render placed/drawn edges */
14 renderDrawnLines: boolean
15 /** Render shaded boxes */
16 renderShadedBoxes: boolean
17}
18
19// Default config (all features enabled, debug off)
20const defaultConfig: DebugConfig = {
21 showFps: false,
22 renderGridLines: true,
23 renderDots: true,
24 renderDrawnLines: true,
25 renderShadedBoxes: true,
26}
27
28// Current config (mutable for easy toggling)
29let currentConfig: DebugConfig = { ...defaultConfig }
30
31// Listeners for config changes
32type ConfigListener = (config: DebugConfig) => void
33const listeners: Set<ConfigListener> = new Set()
34
35/**
36 * Get the current debug config.
37 */
38export function getDebugConfig(): DebugConfig {
39 return currentConfig
40}
41
42/**
43 * Update debug config (partial update).
44 */
45export function setDebugConfig(updates: Partial<DebugConfig>): void {
46 currentConfig = { ...currentConfig, ...updates }
47 listeners.forEach((listener) => listener(currentConfig))
48}
49
50/**
51 * Reset debug config to defaults.
52 */
53export function resetDebugConfig(): void {
54 currentConfig = { ...defaultConfig }
55 listeners.forEach((listener) => listener(currentConfig))
56}
57
58/**
59 * Subscribe to config changes.
60 */
61export function subscribeDebugConfig(listener: ConfigListener): () => void {
62 listeners.add(listener)
63 return () => listeners.delete(listener)
64}
65
66/**
67 * Toggle debug mode (shows FPS and enables toggles).
68 */
69export function toggleDebugMode(): void {
70 setDebugConfig({ showFps: !currentConfig.showFps })
71}
72
73// Expose to window for easy console access
74interface DebugConfigAPI {
75 getDebugConfig: typeof getDebugConfig
76 setDebugConfig: typeof setDebugConfig
77 resetDebugConfig: typeof resetDebugConfig
78 subscribeDebugConfig: typeof subscribeDebugConfig
79 toggleDebugMode: typeof toggleDebugMode
80}
81
82if (typeof window !== `undefined`) {
83 ;(window as unknown as { debugConfig: DebugConfigAPI }).debugConfig = {
84 getDebugConfig,
85 setDebugConfig,
86 resetDebugConfig,
87 subscribeDebugConfig,
88 toggleDebugMode,
89 }
90}