summaryrefslogtreecommitdiff
path: root/src/main.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cc')
-rw-r--r--src/main.cc30
1 files changed, 27 insertions, 3 deletions
diff --git a/src/main.cc b/src/main.cc
index 2d630ac..42adf6b 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -12,6 +12,7 @@
#endif
#include "generated/assets.h" // Include generated asset header
#include "gpu/gpu.h"
+#include "gpu/demo_effects.h" // For GetDemoDuration()
#include "platform.h"
#include "util/math.h"
#include <cmath>
@@ -227,6 +228,9 @@ int main(int argc, char** argv) {
int last_width = platform_state.width;
int last_height = platform_state.height;
+ // Get demo duration from sequence file (or -1 if not specified)
+ const float demo_duration = GetDemoDuration();
+
while (!platform_should_close(&platform_state)) {
platform_poll(&platform_state);
@@ -239,6 +243,14 @@ int main(int argc, char** argv) {
double current_time = platform_state.time + seek_time; // Offset logic time
+ // Auto-exit when demo finishes (if duration is specified)
+ if (demo_duration > 0.0f && current_time >= demo_duration) {
+#if !defined(STRIP_ALL)
+ printf("Demo finished at %.2f seconds. Exiting...\n", current_time);
+#endif
+ break;
+ }
+
update_game_logic(current_time);
float aspect_ratio = platform_state.aspect_ratio;
@@ -247,9 +259,21 @@ int main(int argc, char** argv) {
float raw_peak = synth_get_output_peak();
float visual_peak = fminf(raw_peak * 8.0f, 1.0f);
- // float beat = fmodf((float)current_time * DEMO_BPM / 60.0f, 1.0f); // Use
- // tracker BPM
- float beat = fmodf((float)current_time * g_tracker_score.bpm / 60.0f, 1.0f);
+ // Calculate beat information for synchronization
+ float beat_time = (float)current_time * g_tracker_score.bpm / 60.0f;
+ int beat_number = (int)beat_time;
+ float beat = fmodf(beat_time, 1.0f); // Fractional part (0.0 to 1.0)
+
+#if !defined(STRIP_ALL)
+ // Print beat/time info periodically for identifying sync points
+ static float last_print_time = -1.0f;
+ if (current_time - last_print_time >= 0.5f) { // Print every 0.5 seconds
+ printf("[T=%.2f, Beat=%d, Frac=%.2f, Peak=%.2f]\n",
+ (float)current_time, beat_number, beat, visual_peak);
+ last_print_time = (float)current_time;
+ }
+#endif /* !defined(STRIP_ALL) */
+
gpu_draw(visual_peak, aspect_ratio, (float)current_time, beat);
audio_update();
}