Add game state debug log with binary ring buffer
Implement src/engine/debuglog module that records a comprehensive snapshot of game state every tick into a 4 MB in-memory ring buffer. Activated by --debug-log command-line flag. Press F12 during gameplay to dump the ring buffer to a human-readable debug_log.txt file. The buffer also auto-flushes every 10 seconds as a safety net. Each tick snapshot captures: input state (held/pressed/released bitmasks), full player state (position, velocity, health, dash, aim, timers), camera position, physics globals, level name, and a variable-length list of all active entity positions/velocities/health. New files: - src/engine/debuglog.h — API and snapshot data structures - src/engine/debuglog.c — ring buffer, record, and dump logic Modified files: - include/config.h — DEBUGLOG_BUFFER_SIZE constant - src/engine/input.h/c — input_get_snapshot() to pack input bitmasks - src/engine/core.c — debuglog_record_tick() call after update - src/main.c — CLI flag, init/shutdown, F12 hotkey, set_level calls Closes #19
This commit was merged in pull request #27.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "engine/input.h"
|
||||
#include "engine/debuglog.h"
|
||||
#include <string.h>
|
||||
|
||||
static bool s_current[ACTION_COUNT];
|
||||
@@ -196,6 +197,19 @@ bool input_key_held(SDL_Scancode key) {
|
||||
return s_key_state && s_key_state[key];
|
||||
}
|
||||
|
||||
/* ── Debug log snapshot ───────────────────────────── */
|
||||
|
||||
void input_get_snapshot(InputSnapshot *out) {
|
||||
out->held = 0;
|
||||
out->pressed = 0;
|
||||
out->released = 0;
|
||||
for (int i = 0; i < ACTION_COUNT && i < 8; i++) {
|
||||
if (s_current[i]) out->held |= (uint8_t)(1 << i);
|
||||
if (s_latched_pressed[i]) out->pressed |= (uint8_t)(1 << i);
|
||||
if (s_latched_released[i]) out->released |= (uint8_t)(1 << i);
|
||||
}
|
||||
}
|
||||
|
||||
void input_shutdown(void) {
|
||||
/* Nothing to clean up */
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user