From 141d213cb31017cde462e9e03c0c47e13d425cb3 Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Fri, 6 Oct 2023 09:32:07 +1100 Subject: [PATCH] dont have that weird chain of shader path --- gb-vst/src/lib.rs | 13 +++---------- gb-vst/src/ui.rs | 20 ++++++++++++-------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/gb-vst/src/lib.rs b/gb-vst/src/lib.rs index 54fcba9..7c79e46 100644 --- a/gb-vst/src/lib.rs +++ b/gb-vst/src/lib.rs @@ -81,6 +81,7 @@ struct Configs { } static CONFIGS: OnceLock = OnceLock::new(); +static IS_CGB: OnceLock = OnceLock::new(); fn access_config<'a>() -> &'a Configs { CONFIGS.get_or_init(|| { @@ -106,7 +107,6 @@ pub struct GameboyEmu { frame_receiver: Arc, key_handler: Arc, params: Arc, - shader_path: Arc>>, } type Frame = Vec<[u8; 4]>; @@ -258,7 +258,6 @@ impl Plugin for GameboyEmu { Some(Box::new(Emulator::new( self.frame_receiver.clone(), self.key_handler.clone(), - self.shader_path.clone(), size, ))) } @@ -289,13 +288,8 @@ impl Plugin for GameboyEmu { .load(gb_emu_lib::connect::SramType::None, NoCamera::default()) .expect("failed to load rom"); - let shader_path = - if rom.rom_type == CgbRomType::CgbOnly || configs.emu_config.prefer_cgb { - configs.emu_config.vulkan_config.cgb_shader_path.as_ref() - } else { - configs.emu_config.vulkan_config.dmg_shader_path.as_ref() - } - .map(|v| configs.config_dir.join(v)); + let _ = + IS_CGB.set(rom.rom_type == CgbRomType::CgbOnly || configs.emu_config.prefer_cgb); let (sender, receiver) = channel::(); @@ -309,7 +303,6 @@ impl Plugin for GameboyEmu { *self.frame_receiver.lock().unwrap() = Some(frame_receiver); *self.key_handler.lock().unwrap() = Some(key_handler); - *self.shader_path.lock().unwrap() = shader_path; let (serial_tx, gb_serial_rx) = mpsc::channel::(); let serial_target = SerialTarget::Custom { diff --git a/gb-vst/src/ui.rs b/gb-vst/src/ui.rs index 82cc6be..a699efb 100644 --- a/gb-vst/src/ui.rs +++ b/gb-vst/src/ui.rs @@ -2,7 +2,7 @@ use std::{ path::PathBuf, sync::{ mpsc::{self, Receiver, Sender}, - Arc, Mutex, + Arc, }, }; @@ -14,12 +14,11 @@ use gb_emu_lib::{ use keyboard_types::{Code, KeyState}; use nih_plug::prelude::*; -use crate::{access_config, Frame, FrameReceiver, JoypadInfo, JoypadSender}; +use crate::{access_config, Frame, FrameReceiver, JoypadInfo, JoypadSender, IS_CGB}; pub struct Emulator { frame_receiver: Arc, joypad_sender: Arc, - shader_path: Arc>>, size: Size, } @@ -27,13 +26,11 @@ impl Emulator { pub fn new( frame_receiver: Arc, joypad_sender: Arc, - shader_path: Arc>>, size: Size, ) -> Self { Self { frame_receiver, joypad_sender, - shader_path, size, } } @@ -60,9 +57,16 @@ impl Editor for Emulator { // ) // }; + let config = access_config(); + #[cfg(feature = "vulkan")] - let shader_path = self.shader_path.lock().unwrap().clone(); - // let shader_path = None; + let shader_path = if IS_CGB.get().is_some_and(|v| *v) { + config.emu_config.vulkan_config.cgb_shader_path.as_ref() + } else { + config.emu_config.vulkan_config.dmg_shader_path.as_ref() + } + .map(|p| config.config_dir.join(p)); + let scale_factor = access_config().vst_config.scale_factor; let size = Size::new( @@ -92,7 +96,6 @@ impl Editor for Emulator { Box::new(Self::new( self.frame_receiver.clone(), self.joypad_sender.clone(), - self.shader_path.clone(), size, )) } @@ -206,6 +209,7 @@ impl WindowHandler for EmulatorWindow { EventStatus::Ignored } } + Event::Window(WindowEvent::WillClose) => EventStatus::Ignored, _ => EventStatus::Ignored, } }