diff options
| author | skal <pascal.massimino@gmail.com> | 2026-01-31 15:44:30 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-01-31 15:44:30 +0100 |
| commit | 0bb7fa35cc340a65c944e546231632379bcfa30c (patch) | |
| tree | 23913b4d5d26686b45acee5648b147a44877e3a0 /src/main.cc | |
| parent | 72c0cbcb38732b698d33d52459fed67af56ee2ec (diff) | |
feat: Add --seek command line option for fast-forward debugging
This feature allows developers to jump to a specific time in the demo sequence (e.g., './demo64k --seek 10.5'). It simulates the game logic, audio state (rendering silent buffers), and visual physics (compute shaders) from t=0 up to the target time before starting real-time playback. Audio initialization is refactored to separate device init and start.
Diffstat (limited to 'src/main.cc')
| -rw-r--r-- | src/main.cc | 44 |
1 files changed, 36 insertions, 8 deletions
diff --git a/src/main.cc b/src/main.cc index fb0b412..75143c0 100644 --- a/src/main.cc +++ b/src/main.cc @@ -130,12 +130,15 @@ float* generate_tone(float *buffer, float freq) { int main(int argc, char **argv) { bool fullscreen_enabled = false; + double seek_time = 0.0; #ifndef STRIP_ALL for (int i = 1; i < argc; ++i) { if (strcmp(argv[i], "--fullscreen") == 0) { fullscreen_enabled = true; - break; + } else if (strcmp(argv[i], "--seek") == 0 && i + 1 < argc) { + seek_time = atof(argv[i + 1]); + i++; } } #else @@ -166,12 +169,9 @@ int main(int argc, char **argv) { double last_beat_time = 0.0; int beat_count = 0; - while (!platform_should_close()) { - platform_poll(); - - double current_time = platform_get_time(); - if (current_time - last_beat_time > SECONDS_PER_BEAT / 2.0) { // 8th notes - last_beat_time = current_time; + auto update_game_logic = [&](double t) { + if (t - last_beat_time > SECONDS_PER_BEAT / 2.0) { // 8th notes + last_beat_time = t; // Sync to t const int step = beat_count % 16; @@ -203,6 +203,34 @@ int main(int argc, char **argv) { ++beat_count; } + }; + +#ifndef STRIP_ALL + if (seek_time > 0.0) { + printf("Seeking to %.2f seconds...\n", seek_time); + + // Simulate audio/game logic + // We step at ~60hz + const double step = 1.0/60.0; + for (double t = 0.0; t < seek_time; t += step) { + update_game_logic(t); + audio_render_silent((float)step); + } + + // Simulate Visuals + gpu_simulate_until((float)seek_time); + } +#endif + + // Start real audio + audio_start(); + + while (!platform_should_close()) { + platform_poll(); + + double current_time = platform_get_time() + seek_time; // Offset logic time + + update_game_logic(current_time); int width, height; glfwGetFramebufferSize(platform_get_window(), &width, &height); @@ -221,4 +249,4 @@ int main(int argc, char **argv) { gpu_shutdown(); platform_shutdown(); return 0; -} +}
\ No newline at end of file |
