From 0bb7fa35cc340a65c944e546231632379bcfa30c Mon Sep 17 00:00:00 2001 From: skal Date: Sat, 31 Jan 2026 15:44:30 +0100 Subject: 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. --- src/gpu/effect.cc | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/gpu/effect.cc') 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(); -- cgit v1.2.3