From 1141095b65bee22b37cb85f3ee623c8e440dc706 Mon Sep 17 00:00:00 2001 From: Logan McNaughton <848146+loganmc10@users.noreply.github.com> Date: Sat, 22 Nov 2025 14:14:22 +0100 Subject: [PATCH] some code cleanup --- src/device.rs | 1 - src/device/controller/vru.rs | 1 + src/device/pif.rs | 2 -- src/device/vi.rs | 8 +++----- src/ui/video.rs | 4 ++-- src/ui/vru.rs | 3 ++- 6 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/device.rs b/src/device.rs index 4290f562..34ba6e50 100644 --- a/src/device.rs +++ b/src/device.rs @@ -322,7 +322,6 @@ impl Device { pif: pif::Pif { rom: [0; 1984], ram: [0; 64], - input_gathered: false, channels: [pif::PifChannel { tx: None, tx_buf: None, diff --git a/src/device/controller/vru.rs b/src/device/controller/vru.rs index aad48dba..40263505 100644 --- a/src/device/controller/vru.rs +++ b/src/device/controller/vru.rs @@ -192,6 +192,7 @@ pub fn process(device: &mut device::Device, channel: usize) { &device.vru.words, device.vru_window.window_notifier.as_ref().unwrap(), device.vru_window.word_receiver.as_mut().unwrap(), + device.vi.frame_time, ) } else { 0x7FFF diff --git a/src/device/pif.rs b/src/device/pif.rs index b24711c6..2022193c 100644 --- a/src/device/pif.rs +++ b/src/device/pif.rs @@ -8,7 +8,6 @@ pub struct Pif { #[serde(with = "serde_big_array::BigArray")] pub ram: [u8; 64], pub channels: [PifChannel; 5], - pub input_gathered: bool, } #[derive(Copy, Clone, serde::Serialize, serde::Deserialize)] @@ -97,7 +96,6 @@ fn process_channel(device: &mut device::Device, channel: usize) -> usize { pub fn update_pif_ram(device: &mut device::Device) -> u64 { unsafe { sdl3_sys::events::SDL_PumpEvents() }; - device.pif.input_gathered = true; let mut active_channels = 0; for k in 0..PIF_CHANNELS_COUNT { diff --git a/src/device/vi.rs b/src/device/vi.rs index 8110118c..5fceb21f 100644 --- a/src/device/vi.rs +++ b/src/device/vi.rs @@ -158,13 +158,11 @@ pub fn vertical_interrupt_event(device: &mut device::Device) { device.vi.vi_counter += 1; if device.netplay.is_none() && paused { - ui::video::pause_loop(); - } else if !device.pif.input_gathered { - unsafe { sdl3_sys::events::SDL_PumpEvents() }; // in case the game isn't prompting for input - } else { - device.pif.input_gathered = false; + ui::video::pause_loop(device.vi.frame_time); } + unsafe { sdl3_sys::events::SDL_PumpEvents() }; // in case the game isn't prompting for input + /* let vis = if device.cart.pal { 50 } else { 60 }; if device.vi.vi_counter % vis == 0 { diff --git a/src/ui/video.rs b/src/ui/video.rs index 952449b4..28e36602 100644 --- a/src/ui/video.rs +++ b/src/ui/video.rs @@ -133,11 +133,11 @@ pub fn load_state(device: &mut device::Device, rdp_state: *const u8) { } } -pub fn pause_loop() { +pub fn pause_loop(frame_time: f64) { let mut paused = true; let mut frame_advance = false; while paused && !frame_advance { - std::thread::sleep(std::time::Duration::from_secs_f64(1.0 / 60.0)); + std::thread::sleep(std::time::Duration::from_secs_f64(frame_time)); unsafe { sdl3_sys::events::SDL_PumpEvents() }; let callback = unsafe { rdp_check_callback() }; paused = callback.paused; diff --git a/src/ui/vru.rs b/src/ui/vru.rs index 50a93ceb..457f83f1 100644 --- a/src/ui/vru.rs +++ b/src/ui/vru.rs @@ -2,6 +2,7 @@ pub fn prompt_for_match( words: &[String], window_notifier: &tokio::sync::mpsc::Sender>>, word_index_receiver: &mut tokio::sync::mpsc::Receiver, + frame_time: f64, ) -> u16 { let mut dedup_words = words.to_owned(); dedup_words.sort(); @@ -10,7 +11,7 @@ pub fn prompt_for_match( let mut result = word_index_receiver.try_recv(); while result.is_err() { result = word_index_receiver.try_recv(); - std::thread::sleep(std::time::Duration::from_secs_f64(1.0 / 60.0)); + std::thread::sleep(std::time::Duration::from_secs_f64(frame_time)); unsafe { sdl3_sys::events::SDL_PumpEvents() }; // so the OS doesn't complain about the game window being frozen } for (i, v) in words.iter().enumerate() {