summaryrefslogtreecommitdiff
path: root/src/gpu/effect.cc
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-01-31 15:44:30 +0100
committerskal <pascal.massimino@gmail.com>2026-01-31 15:44:30 +0100
commit0bb7fa35cc340a65c944e546231632379bcfa30c (patch)
tree23913b4d5d26686b45acee5648b147a44877e3a0 /src/gpu/effect.cc
parent72c0cbcb38732b698d33d52459fed67af56ee2ec (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/gpu/effect.cc')
-rw-r--r--src/gpu/effect.cc38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/gpu/effect.cc b/src/gpu/effect.cc
index cfef7f9..040b523 100644
--- a/src/gpu/effect.cc
+++ b/src/gpu/effect.cc
@@ -195,6 +195,44 @@ void MainSequence::render_frame(float global_time, float beat, float peak,
wgpuTextureRelease(surface_texture.texture);
}
+void MainSequence::simulate_until(float target_time, float step_rate) {
+#ifndef STRIP_ALL
+ // Assuming 128 BPM as per main.cc.
+ // Ideally this should be passed in or shared.
+ const float bpm = 128.0f;
+ const float aspect_ratio = 16.0f / 9.0f; // Dummy aspect
+
+ for (float t = 0.0f; t < target_time; t += step_rate) {
+ WGPUCommandEncoderDescriptor encoder_desc = {};
+ WGPUCommandEncoder encoder = wgpuDeviceCreateCommandEncoder(device, &encoder_desc);
+
+ float beat = fmodf(t * bpm / 60.0f, 1.0f);
+
+ // Update active lists
+ for (auto &entry : sequences_) {
+ if (t >= entry.start_time) {
+ entry.seq->update_active_list(t - entry.start_time);
+ }
+ }
+
+ // Dispatch compute
+ for (auto &entry : sequences_) {
+ if (t >= entry.start_time) {
+ // peak = 0.0f during simulation (no audio analysis)
+ entry.seq->dispatch_compute(encoder, t - entry.start_time, beat, 0.0f, aspect_ratio);
+ }
+ }
+
+ WGPUCommandBufferDescriptor cmd_desc = {};
+ WGPUCommandBuffer commands = wgpuCommandEncoderFinish(encoder, &cmd_desc);
+ wgpuQueueSubmit(queue, 1, &commands);
+ }
+#else
+ (void)target_time;
+ (void)step_rate;
+#endif
+}
+
void MainSequence::shutdown() {
for (auto &entry : sequences_) {
entry.seq->reset();