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
60 lines
1.8 KiB
C
60 lines
1.8 KiB
C
#ifndef JNR_INPUT_H
|
|
#define JNR_INPUT_H
|
|
|
|
#include <stdbool.h>
|
|
#include <SDL2/SDL.h>
|
|
|
|
typedef enum Action {
|
|
ACTION_LEFT,
|
|
ACTION_RIGHT,
|
|
ACTION_UP,
|
|
ACTION_DOWN,
|
|
ACTION_JUMP,
|
|
ACTION_SHOOT,
|
|
ACTION_DASH,
|
|
ACTION_PAUSE,
|
|
ACTION_COUNT
|
|
} Action;
|
|
|
|
void input_init(void);
|
|
void input_poll(void); /* call once per frame before updates */
|
|
void input_consume(void); /* call after each fixed update tick */
|
|
bool input_pressed(Action a); /* pressed since last consume */
|
|
bool input_held(Action a); /* currently held down */
|
|
bool input_released(Action a); /* released since last consume */
|
|
void input_shutdown(void);
|
|
|
|
/* Returns true if SDL_QUIT was received */
|
|
bool input_quit_requested(void);
|
|
|
|
/* ── Mouse state ────────────────────────────────── */
|
|
typedef enum MouseButton {
|
|
MOUSE_LEFT = 0,
|
|
MOUSE_MIDDLE = 1,
|
|
MOUSE_RIGHT = 2,
|
|
MOUSE_BUTTON_COUNT
|
|
} MouseButton;
|
|
|
|
/* Mouse position in logical (game) coordinates */
|
|
void input_mouse_pos(int *x, int *y);
|
|
|
|
/* Mouse button queries (same semantics as keyboard) */
|
|
bool input_mouse_pressed(MouseButton btn);
|
|
bool input_mouse_held(MouseButton btn);
|
|
bool input_mouse_released(MouseButton btn);
|
|
|
|
/* Scroll wheel delta since last poll (positive = up) */
|
|
int input_mouse_scroll(void);
|
|
|
|
/* Raw keyboard access for text-like input in editor */
|
|
bool input_key_pressed(SDL_Scancode key);
|
|
bool input_key_held(SDL_Scancode key);
|
|
|
|
/* Pack current input state into a compact bitmask snapshot.
|
|
* Used by the debug log to record per-tick input without
|
|
* exposing internal arrays. */
|
|
typedef struct InputSnapshot InputSnapshot; /* defined in debuglog.h */
|
|
void input_get_snapshot(InputSnapshot *out);
|
|
|
|
#endif /* JNR_INPUT_H */
|