dont have that weird chain of shader path

This commit is contained in:
Alex Janka 2023-10-06 09:32:07 +11:00
parent d4bc05b803
commit 141d213cb3
2 changed files with 15 additions and 18 deletions

View file

@ -81,6 +81,7 @@ struct Configs {
} }
static CONFIGS: OnceLock<Configs> = OnceLock::new(); static CONFIGS: OnceLock<Configs> = OnceLock::new();
static IS_CGB: OnceLock<bool> = OnceLock::new();
fn access_config<'a>() -> &'a Configs { fn access_config<'a>() -> &'a Configs {
CONFIGS.get_or_init(|| { CONFIGS.get_or_init(|| {
@ -106,7 +107,6 @@ pub struct GameboyEmu {
frame_receiver: Arc<FrameReceiver>, frame_receiver: Arc<FrameReceiver>,
key_handler: Arc<JoypadSender>, key_handler: Arc<JoypadSender>,
params: Arc<EmuParams>, params: Arc<EmuParams>,
shader_path: Arc<Mutex<Option<PathBuf>>>,
} }
type Frame = Vec<[u8; 4]>; type Frame = Vec<[u8; 4]>;
@ -258,7 +258,6 @@ impl Plugin for GameboyEmu {
Some(Box::new(Emulator::new( Some(Box::new(Emulator::new(
self.frame_receiver.clone(), self.frame_receiver.clone(),
self.key_handler.clone(), self.key_handler.clone(),
self.shader_path.clone(),
size, size,
))) )))
} }
@ -289,13 +288,8 @@ impl Plugin for GameboyEmu {
.load(gb_emu_lib::connect::SramType::None, NoCamera::default()) .load(gb_emu_lib::connect::SramType::None, NoCamera::default())
.expect("failed to load rom"); .expect("failed to load rom");
let shader_path = let _ =
if rom.rom_type == CgbRomType::CgbOnly || configs.emu_config.prefer_cgb { IS_CGB.set(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 (sender, receiver) = channel::<EmulatorMessage>(); let (sender, receiver) = channel::<EmulatorMessage>();
@ -309,7 +303,6 @@ impl Plugin for GameboyEmu {
*self.frame_receiver.lock().unwrap() = Some(frame_receiver); *self.frame_receiver.lock().unwrap() = Some(frame_receiver);
*self.key_handler.lock().unwrap() = Some(key_handler); *self.key_handler.lock().unwrap() = Some(key_handler);
*self.shader_path.lock().unwrap() = shader_path;
let (serial_tx, gb_serial_rx) = mpsc::channel::<u8>(); let (serial_tx, gb_serial_rx) = mpsc::channel::<u8>();
let serial_target = SerialTarget::Custom { let serial_target = SerialTarget::Custom {

View file

@ -2,7 +2,7 @@ use std::{
path::PathBuf, path::PathBuf,
sync::{ sync::{
mpsc::{self, Receiver, Sender}, mpsc::{self, Receiver, Sender},
Arc, Mutex, Arc,
}, },
}; };
@ -14,12 +14,11 @@ use gb_emu_lib::{
use keyboard_types::{Code, KeyState}; use keyboard_types::{Code, KeyState};
use nih_plug::prelude::*; 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 { pub struct Emulator {
frame_receiver: Arc<FrameReceiver>, frame_receiver: Arc<FrameReceiver>,
joypad_sender: Arc<JoypadSender>, joypad_sender: Arc<JoypadSender>,
shader_path: Arc<Mutex<Option<PathBuf>>>,
size: Size, size: Size,
} }
@ -27,13 +26,11 @@ impl Emulator {
pub fn new( pub fn new(
frame_receiver: Arc<FrameReceiver>, frame_receiver: Arc<FrameReceiver>,
joypad_sender: Arc<JoypadSender>, joypad_sender: Arc<JoypadSender>,
shader_path: Arc<Mutex<Option<PathBuf>>>,
size: Size, size: Size,
) -> Self { ) -> Self {
Self { Self {
frame_receiver, frame_receiver,
joypad_sender, joypad_sender,
shader_path,
size, size,
} }
} }
@ -60,9 +57,16 @@ impl Editor for Emulator {
// ) // )
// }; // };
let config = access_config();
#[cfg(feature = "vulkan")] #[cfg(feature = "vulkan")]
let shader_path = self.shader_path.lock().unwrap().clone(); let shader_path = if IS_CGB.get().is_some_and(|v| *v) {
// let shader_path = None; 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 scale_factor = access_config().vst_config.scale_factor;
let size = Size::new( let size = Size::new(
@ -92,7 +96,6 @@ impl Editor for Emulator {
Box::new(Self::new( Box::new(Self::new(
self.frame_receiver.clone(), self.frame_receiver.clone(),
self.joypad_sender.clone(), self.joypad_sender.clone(),
self.shader_path.clone(),
size, size,
)) ))
} }
@ -206,6 +209,7 @@ impl WindowHandler for EmulatorWindow {
EventStatus::Ignored EventStatus::Ignored
} }
} }
Event::Window(WindowEvent::WillClose) => EventStatus::Ignored,
_ => EventStatus::Ignored, _ => EventStatus::Ignored,
} }
} }