blecsd 0.1.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.
Files changed (109) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +220 -0
  3. package/dist/3d/index.d.ts +5 -0
  4. package/dist/3d/index.js +1 -0
  5. package/dist/audio/index.d.ts +177 -0
  6. package/dist/audio/index.js +1 -0
  7. package/dist/border-D_Jb4ZJV.d.ts +257 -0
  8. package/dist/cell-DwIu2ryP.d.ts +505 -0
  9. package/dist/chunk-2UBBZFE4.js +1 -0
  10. package/dist/chunk-35LCBY6P.js +1 -0
  11. package/dist/chunk-3B7MIVW6.js +1 -0
  12. package/dist/chunk-3EGGGI5J.js +3 -0
  13. package/dist/chunk-4LWWONFK.js +1 -0
  14. package/dist/chunk-4X4N4HNQ.js +2 -0
  15. package/dist/chunk-5PELJRUQ.js +1 -0
  16. package/dist/chunk-AEJIX2MW.js +1 -0
  17. package/dist/chunk-AQ7LW75B.js +1 -0
  18. package/dist/chunk-AXZQAH4X.js +1 -0
  19. package/dist/chunk-B6Z2JFRY.js +1 -0
  20. package/dist/chunk-BCADUCOZ.js +1 -0
  21. package/dist/chunk-C5PCEQ6G.js +1 -0
  22. package/dist/chunk-CIK4AMUA.js +1 -0
  23. package/dist/chunk-DNRXW56C.js +1 -0
  24. package/dist/chunk-FC5FFAAC.js +12 -0
  25. package/dist/chunk-FGHEFXLK.js +1 -0
  26. package/dist/chunk-FYEBZAWN.js +1 -0
  27. package/dist/chunk-G7GIWWLE.js +1 -0
  28. package/dist/chunk-GYHI26UE.js +1 -0
  29. package/dist/chunk-H2YAOJDW.js +1 -0
  30. package/dist/chunk-J4JZ2NU2.js +1 -0
  31. package/dist/chunk-JKVHO4LH.js +1 -0
  32. package/dist/chunk-K2B2OXQ5.js +5 -0
  33. package/dist/chunk-K37L3G4Z.js +4 -0
  34. package/dist/chunk-KD55INV7.js +1 -0
  35. package/dist/chunk-KFAK4A3G.js +1 -0
  36. package/dist/chunk-LCN2ZITE.js +1 -0
  37. package/dist/chunk-LYSK5S63.js +1 -0
  38. package/dist/chunk-NZ55KBM6.js +1 -0
  39. package/dist/chunk-OMMJ7B5P.js +1 -0
  40. package/dist/chunk-OUXUPF3V.js +33 -0
  41. package/dist/chunk-OVT2PPGW.js +19 -0
  42. package/dist/chunk-P6CJO3BC.js +1 -0
  43. package/dist/chunk-PSXXMBVJ.js +1 -0
  44. package/dist/chunk-PXXGH3BV.js +1 -0
  45. package/dist/chunk-QIKIOVP2.js +1 -0
  46. package/dist/chunk-SHUC6JWA.js +1 -0
  47. package/dist/chunk-TDXJDLY6.js +6 -0
  48. package/dist/chunk-TWSWTBYL.js +1 -0
  49. package/dist/chunk-TYMY2TBR.js +3 -0
  50. package/dist/chunk-VNZ6CWJA.js +2 -0
  51. package/dist/chunk-VOCM5T2G.js +5 -0
  52. package/dist/chunk-W5OU7Z6J.js +1 -0
  53. package/dist/chunk-WNG4A3K7.js +4 -0
  54. package/dist/chunk-XQIGERNI.js +1 -0
  55. package/dist/chunk-XZA63ZPO.js +1 -0
  56. package/dist/chunk-YAMOSPWB.js +4 -0
  57. package/dist/chunk-YD6ULIUR.js +1 -0
  58. package/dist/chunk-Z4EZERNE.js +1 -0
  59. package/dist/cli/init.d.ts +86 -0
  60. package/dist/cli/init.js +179 -0
  61. package/dist/color-B78w3zH-.d.ts +79 -0
  62. package/dist/components/index.d.ts +10298 -0
  63. package/dist/components/index.js +1 -0
  64. package/dist/core/index.d.ts +6700 -0
  65. package/dist/core/index.js +1 -0
  66. package/dist/debug/index.d.ts +711 -0
  67. package/dist/debug/index.js +1 -0
  68. package/dist/doubleBuffer-CKQFmlPN.d.ts +95 -0
  69. package/dist/errors/index.d.ts +1110 -0
  70. package/dist/errors/index.js +1 -0
  71. package/dist/events-BbbxkgvX.d.ts +125 -0
  72. package/dist/game/index.d.ts +486 -0
  73. package/dist/game/index.js +1 -0
  74. package/dist/gameLoop-BIPW7-OY.d.ts +219 -0
  75. package/dist/index-zSGJ2eUk.d.ts +3156 -0
  76. package/dist/index.d.ts +246 -0
  77. package/dist/index.js +1 -0
  78. package/dist/input/index.d.ts +158 -0
  79. package/dist/input/index.js +1 -0
  80. package/dist/inputActions-CefRUBuT.d.ts +2637 -0
  81. package/dist/keyParser-Bwm8-l7v.d.ts +229 -0
  82. package/dist/mouseParser-Cfrbn3AX.d.ts +177 -0
  83. package/dist/parser-iMHmQuUh.d.ts +265 -0
  84. package/dist/program-BZaKqDKH.d.ts +141 -0
  85. package/dist/renderable-jTMOA-GK.d.ts +302 -0
  86. package/dist/scheduler-DcfoFuum.d.ts +86 -0
  87. package/dist/schemas/index.d.ts +936 -0
  88. package/dist/schemas/index.js +1 -0
  89. package/dist/systems/index.d.ts +4036 -0
  90. package/dist/systems/index.js +1 -0
  91. package/dist/terminal/index.d.ts +7357 -0
  92. package/dist/terminal/index.js +1 -0
  93. package/dist/terminus-14-bold-HWSPRLJD.js +1 -0
  94. package/dist/terminus-14-normal-T3SWMH4D.js +1 -0
  95. package/dist/tilemap-D1HJvKy3.d.ts +1211 -0
  96. package/dist/types-BcsvoKzf.d.ts +68 -0
  97. package/dist/utils/index.d.ts +6104 -0
  98. package/dist/utils/index.js +1 -0
  99. package/dist/viewport3d-xI33-_wq.d.ts +182 -0
  100. package/dist/virtualScrollback-DvZTRU8a.d.ts +274 -0
  101. package/dist/virtualViewport-Dx2iJliO.d.ts +2334 -0
  102. package/dist/virtualizedLineStore-DwPEvPkk.d.ts +297 -0
  103. package/dist/widgets/bigText.d.ts +230 -0
  104. package/dist/widgets/bigText.js +1 -0
  105. package/dist/widgets/fonts/index.d.ts +211 -0
  106. package/dist/widgets/fonts/index.js +1 -0
  107. package/dist/widgets/index.d.ts +8591 -0
  108. package/dist/widgets/index.js +1 -0
  109. package/package.json +213 -0
@@ -0,0 +1,219 @@
1
+ import { S as Scheduler } from './scheduler-DcfoFuum.js';
2
+ import { W as World, S as System } from './types-BcsvoKzf.js';
3
+
4
+ /**
5
+ * Game loop with input priority and lifecycle management.
6
+ * @module core/gameLoop
7
+ */
8
+
9
+ /**
10
+ * Hook function called at specific points in the game loop.
11
+ * @param world - The current ECS world
12
+ * @param deltaTime - Time since last frame in seconds
13
+ */
14
+ type LoopHook = (world: World, deltaTime: number) => void;
15
+ /**
16
+ * Configuration for fixed timestep mode.
17
+ *
18
+ * Fixed timestep runs game logic at a consistent rate, independent of
19
+ * rendering frame rate. This is essential for:
20
+ * - Deterministic physics simulations
21
+ * - Network synchronization
22
+ * - Replays and recording
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * const loop = createGameLoop(world, {
27
+ * fixedTimestepMode: {
28
+ * tickRate: 60, // 60 physics updates per second
29
+ * maxUpdatesPerFrame: 5, // Prevent spiral of death
30
+ * interpolate: true, // Smooth rendering between ticks
31
+ * },
32
+ * });
33
+ * ```
34
+ */
35
+ interface FixedTimestepConfig {
36
+ /**
37
+ * Number of fixed updates per second.
38
+ * Common values: 30, 60, 120 (higher = more precision, more CPU)
39
+ * @default 60
40
+ */
41
+ readonly tickRate: number;
42
+ /**
43
+ * Maximum fixed updates to run per frame.
44
+ * Prevents "spiral of death" when game can't keep up.
45
+ * If exceeded, game will run slower than real-time.
46
+ * @default 5
47
+ */
48
+ readonly maxUpdatesPerFrame: number;
49
+ /**
50
+ * Whether to interpolate render state between fixed updates.
51
+ * When true, rendering will be smooth even at low tick rates.
52
+ * When false, rendering shows the last completed tick state.
53
+ * @default true
54
+ */
55
+ readonly interpolate: boolean;
56
+ }
57
+ /**
58
+ * Configuration options for the game loop.
59
+ */
60
+ interface GameLoopOptions {
61
+ /**
62
+ * Target frames per second. 0 means uncapped (as fast as possible).
63
+ * @default 60
64
+ */
65
+ targetFPS?: number;
66
+ /**
67
+ * Whether to use fixed timestep for physics stability.
68
+ * When true, deltaTime will be capped to prevent spiral of death.
69
+ * @default true
70
+ * @deprecated Use fixedTimestepMode for true fixed timestep with interpolation
71
+ */
72
+ fixedTimestep?: boolean;
73
+ /**
74
+ * Maximum delta time in seconds. Prevents large time jumps.
75
+ * @default 0.1 (100ms)
76
+ */
77
+ maxDeltaTime?: number;
78
+ /**
79
+ * Fixed timestep mode configuration.
80
+ * When set, the loop will use true fixed timestep with optional interpolation.
81
+ * INPUT is still processed every frame for responsiveness.
82
+ */
83
+ fixedTimestepMode?: FixedTimestepConfig;
84
+ }
85
+ /**
86
+ * Hook function for fixed timestep updates.
87
+ * @param world - The current ECS world
88
+ * @param fixedDeltaTime - Fixed delta time (always the same)
89
+ * @param tickNumber - The current tick number since loop start
90
+ */
91
+ type FixedUpdateHook = (world: World, fixedDeltaTime: number, tickNumber: number) => void;
92
+ /**
93
+ * Hook function for interpolated rendering.
94
+ * @param world - The current ECS world
95
+ * @param alpha - Interpolation factor (0-1) between previous and current tick
96
+ */
97
+ type InterpolateHook = (world: World, alpha: number) => void;
98
+ /**
99
+ * Lifecycle hooks for the game loop.
100
+ */
101
+ interface GameLoopHooks {
102
+ onBeforeInput?: LoopHook;
103
+ onAfterInput?: LoopHook;
104
+ onBeforeUpdate?: LoopHook;
105
+ onAfterUpdate?: LoopHook;
106
+ onBeforeRender?: LoopHook;
107
+ onAfterRender?: LoopHook;
108
+ onStart?: () => void;
109
+ onStop?: () => void;
110
+ onPause?: () => void;
111
+ onResume?: () => void;
112
+ onBeforeFixedUpdate?: FixedUpdateHook;
113
+ onAfterFixedUpdate?: FixedUpdateHook;
114
+ onInterpolate?: InterpolateHook;
115
+ }
116
+ /**
117
+ * Statistics about the game loop performance.
118
+ */
119
+ interface LoopStats {
120
+ fps: number;
121
+ frameTime: number;
122
+ frameCount: number;
123
+ runningTime: number;
124
+ tickCount: number;
125
+ ticksPerSecond: number;
126
+ interpolationAlpha: number;
127
+ skippedUpdates: number;
128
+ }
129
+ /**
130
+ * Game loop state enum.
131
+ */
132
+ declare enum LoopState {
133
+ STOPPED = 0,
134
+ RUNNING = 1,
135
+ PAUSED = 2
136
+ }
137
+ /**
138
+ * GameLoop interface for type-safe access.
139
+ */
140
+ interface GameLoop {
141
+ getState(): LoopState;
142
+ isRunning(): boolean;
143
+ isPaused(): boolean;
144
+ isStopped(): boolean;
145
+ getStats(): LoopStats;
146
+ getInterpolationAlpha(): number;
147
+ getFixedTimestepConfig(): FixedTimestepConfig | undefined;
148
+ isFixedTimestepMode(): boolean;
149
+ getScheduler(): Scheduler;
150
+ getWorld(): World;
151
+ setWorld(world: World): void;
152
+ setTargetFPS(fps: number): void;
153
+ getTargetFPS(): number;
154
+ registerSystem(phase: number, system: System, priority?: number): void;
155
+ unregisterSystem(system: System): void;
156
+ registerInputSystem(system: System, priority?: number): void;
157
+ setHooks(hooks: GameLoopHooks): void;
158
+ start(): void;
159
+ stop(): void;
160
+ pause(): void;
161
+ resume(): void;
162
+ step(deltaTime?: number): void;
163
+ stepFixed(): void;
164
+ }
165
+ /**
166
+ * Creates a new game loop instance.
167
+ *
168
+ * The GameLoop wraps a Scheduler and provides:
169
+ * - Lifecycle management (start/stop/pause/resume)
170
+ * - Hook points for custom logic at specific phases
171
+ * - FPS limiting and frame timing
172
+ * - Performance statistics
173
+ *
174
+ * HARD REQUIREMENT: Input is ALWAYS processed first every frame.
175
+ *
176
+ * @param world - The ECS world to process
177
+ * @param options - Loop configuration options
178
+ * @param hooks - Lifecycle hooks
179
+ * @returns A new GameLoop instance
180
+ *
181
+ * @example
182
+ * ```typescript
183
+ * import { createGameLoop, createWorld, LoopPhase } from 'blecsd';
184
+ *
185
+ * const world = createWorld();
186
+ * const loop = createGameLoop(world, {
187
+ * targetFPS: 60,
188
+ * }, {
189
+ * onStart: () => console.log('Game started!'),
190
+ * onStop: () => console.log('Game stopped!'),
191
+ * });
192
+ *
193
+ * // Register systems
194
+ * loop.registerSystem(LoopPhase.UPDATE, myUpdateSystem);
195
+ *
196
+ * // Start the game
197
+ * loop.start();
198
+ *
199
+ * // Stop after 5 seconds
200
+ * setTimeout(() => loop.stop(), 5000);
201
+ * ```
202
+ */
203
+ declare function createGameLoop(initialWorld: World, options?: GameLoopOptions, initialHooks?: GameLoopHooks): GameLoop;
204
+ /**
205
+ * Checks if a game loop exists and is running.
206
+ *
207
+ * @param loop - The game loop to check (may be undefined)
208
+ * @returns true if loop exists and is running
209
+ */
210
+ declare function isLoopRunning(loop: GameLoop | undefined): boolean;
211
+ /**
212
+ * Checks if a game loop exists and is paused.
213
+ *
214
+ * @param loop - The game loop to check (may be undefined)
215
+ * @returns true if loop exists and is paused
216
+ */
217
+ declare function isLoopPaused(loop: GameLoop | undefined): boolean;
218
+
219
+ export { type FixedTimestepConfig as F, type GameLoop as G, type InterpolateHook as I, type LoopStats as L, type FixedUpdateHook as a, type GameLoopHooks as b, type GameLoopOptions as c, type LoopHook as d, LoopState as e, createGameLoop as f, isLoopRunning as g, isLoopPaused as i };