A GameCube/Wii emulator and debugger written in Rust.
throttle in main launcher
Layle8ce0860c25c6
diff --git a/crates/app/src/app.rs b/crates/app/src/app.rsindex f77eafa..9928b07 100644--- a/crates/app/src/app.rs+++ b/crates/app/src/app.rs@@ -46,6 +46,7 @@ pub enum Message {SystemThemeChanged(Mode),PlayerToggleFullscreen(window::Id),PlayerToggleOverlay(window::Id),+ PlayerToggleUncapped(window::Id),PlayerScreenshot(window::Id),}@@ -55,6 +56,16 @@ pub struct Toast {expires: Instant,}+impl Toast {+ fn new(title: impl Into<String>, detail: impl Into<String>) -> Self {+ Self {+ title: title.into(),+ detail: detail.into(),+ expires: Instant::now() + TOAST_DURATION,+ }+ }+}+pub struct PlayerWindow {pub(crate) game: Game,pub(crate) state: Arc<PlayerState>,@@ -347,6 +358,20 @@ impl App {}Task::none()}+ Message::PlayerToggleUncapped(id) => {+ let Some(player) = self.players.get_mut(&id) else {+ return Task::none();+ };++ let (title, detail) = if player.state.toggle_throttle() {+ ("Speed limit on", "Throttled to native speed")+ } else {+ ("Speed limit off", "Running uncapped")+ };++ player.toast = Some(Toast::new(title, detail));+ Task::none()+ }Message::PlayerScreenshot(id) => {let Some(player) = self.players.get_mut(&id) else {return Task::none();@@ -365,11 +390,7 @@ impl App {None => ("Screenshot failed", "No frame to capture yet".to_owned()),};- player.toast = Some(Toast {- title: title.to_owned(),- detail,- expires: Instant::now() + TOAST_DURATION,- });+ player.toast = Some(Toast::new(title, detail));Task::none()}}diff --git a/crates/app/src/player/emu_thread.rs b/crates/app/src/player/emu_thread.rsindex 6e1a117..59ec514 100644--- a/crates/app/src/player/emu_thread.rs+++ b/crates/app/src/player/emu_thread.rs@@ -9,14 +9,14 @@ pub fn run<const SYSTEM: SystemId>(mut emulator: System<SYSTEM>,input: Arc<Mutex<HostInput>>,game_id: Option<String>,- throttle: bool,+ throttle: Arc<AtomicBool>,shutdown: Arc<AtomicBool>,) {let sleeper = SpinSleeper::default();let throttle_step = Duration::from_micros(5);while !shutdown.load(Ordering::Relaxed) {- while throttle && emulator.audio_sink.should_throttle() {+ while throttle.load(Ordering::Relaxed) && emulator.audio_sink.should_throttle() {if shutdown.load(Ordering::Relaxed) {break;}diff --git a/crates/app/src/player/state.rs b/crates/app/src/player/state.rsindex f473f16..dd7ad1e 100644--- a/crates/app/src/player/state.rs+++ b/crates/app/src/player/state.rs@@ -35,6 +35,7 @@ pub struct PlayerState {boot: Mutex<Option<BootParams>>,initialized: OnceLock<Initialized>,shutdown: Arc<AtomicBool>,+ throttle: Arc<AtomicBool>,aspect: TargetAspect,input: Arc<Mutex<HostInput>>,platform: Platform,@@ -84,6 +85,7 @@ impl PlayerState {})),initialized: OnceLock::new(),shutdown: Arc::new(AtomicBool::new(false)),+ throttle: Arc::new(AtomicBool::new(true)),aspect,input: Arc::new(Mutex::new(neutral)),platform: game.platform,@@ -197,6 +199,10 @@ impl PlayerState {self.initialized.get().and_then(|init| init.renderer.capture_xfb())}+ pub fn toggle_throttle(&self) -> bool {+ !self.throttle.fetch_xor(true, Ordering::Relaxed)+ }+pub fn shutdown(&self) {self.shutdown.store(true, Ordering::Relaxed);}@@ -272,7 +278,13 @@ fn player_thread(let audio = self::install_audio_sink(&mut emu);let _ = emu.load_jit_cache(&game_id);self::set_initialized(&state, renderer, audio, &game_id);- emu_thread::run::<{ system::WII }>(emu, state.input.clone(), Some(game_id), true, shutdown);+ emu_thread::run::<{ system::WII }>(+ emu,+ state.input.clone(),+ Some(game_id),+ state.throttle.clone(),+ shutdown,+ );}Platform::Gcn => {let mut emu = self::build_gamecube(dvd, ¶ms);@@ -281,7 +293,13 @@ fn player_thread(let audio = self::install_audio_sink(&mut emu);let _ = emu.load_jit_cache(&game_id);self::set_initialized(&state, renderer, audio, &game_id);- emu_thread::run::<{ system::GC }>(emu, state.input.clone(), Some(game_id), true, shutdown);+ emu_thread::run::<{ system::GC }>(+ emu,+ state.input.clone(),+ Some(game_id),+ state.throttle.clone(),+ shutdown,+ );}}}diff --git a/crates/app/src/player/widget.rs b/crates/app/src/player/widget.rsindex c4a2724..010a6ca 100644--- a/crates/app/src/player/widget.rs+++ b/crates/app/src/player/widget.rs@@ -40,6 +40,7 @@ impl Program<Message> for PlayerProgram {iced::Event::Keyboard(kbd) => match kbd {iced::keyboard::Event::KeyPressed { physical_key, .. } => {let hotkey = match state::physical_to_code(physical_key) {+ Some(Code::Tab) => Some(Message::PlayerToggleUncapped(self.window)),Some(Code::F10) => Some(Message::PlayerToggleFullscreen(self.window)),Some(Code::F11) => Some(Message::PlayerToggleOverlay(self.window)),Some(Code::F12) => Some(Message::PlayerScreenshot(self.window)),