kobodl/bench.h
Ville Lindholm 0263be65d4
Add deterministic bench harness (KOBO_BENCH=1)
When KOBO_BENCH=1 is set in the environment, the game becomes a
hands-off benchmark:

  * Skips the intro/menu sequence and pushes st_game directly with
    scene=0, skill=CLASSIC, invulnerable ship, always_fire = constant
    auto-fire, countdown = 0 so "GET READY" auto-pops in 700ms.
  * Seeds pubrand and gamerand from KOBO_BENCH_SEED (default 12345)
    so the map, stress spawn pattern, and enemy AI are identical
    run-to-run.
  * Defaults KOBO_STRESS=1500 unless overridden, so the move pass has
    a steady workload, and KOBO_PROF=1 so the profiler is on.
  * Counts frames in run_game; after KOBO_BENCH_FRAMES (default 1800)
    it dumps prof to stderr and exits cleanly.

Usage from repo root (the cwd matters — relative GFX paths only
resolve from here):
    KOBO_BENCH=1 ./build/kobodl 2>bench-logs/phaseN.log

A single command produces a comparable profiler dump at every phase
of the DOD refactor — no menus to navigate, no keyboard input,
identical workload.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-04 15:37:44 +03:00

37 lines
1.2 KiB
C

// Deterministic, hands-off benchmark mode.
//
// Activated by KOBO_BENCH=1 in the environment. When on, the game:
// * skips the intro/menu sequence and drops straight into stage 0
// * seeds gamerand and pubrand from KOBO_BENCH_SEED (default 12345)
// * enables cmd_indicator (collisions register but neither side takes
// damage — true invulnerability for deterministic workload),
// cmd_cheat (skip score recording), and always_fire (auto-fire)
// * defaults KOBO_STRESS=1500 unless overridden, for a steady workload
// * dumps the profiler table and exits after KOBO_BENCH_FRAMES
// run_game frames (default 1800 = ~60s at the game's tick rate)
//
// Together this makes a single command (`KOBO_BENCH=1 ./kobodl`) produce a
// reproducible profiler dump across phases — no menu navigation, no keyboard
// input, identical RNG and spawn pattern run-to-run.
#ifndef KOBO_BENCH_H
#define KOBO_BENCH_H
#include "sdl_compat.h"
#ifdef __cplusplus
extern "C" {
#endif
extern int kobo_bench_enabled;
extern int kobo_bench_frames;
extern Uint32 kobo_bench_seed;
void kobo_bench_init_env(void);
#ifdef __cplusplus
}
#endif
#endif // KOBO_BENCH_H