From 167d461c353a09835ff11b6b56b51ac6918d2f8c Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Thu, 5 Oct 2023 11:23:07 +1100 Subject: [PATCH] config improvements --- gb-emu/src/main.rs | 28 ++++++++++++++++++++++++---- gb-emu/src/window.rs | 5 ++++- lib/src/config/mod.rs | 21 +++++++++++++++++++-- 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/gb-emu/src/main.rs b/gb-emu/src/main.rs index 2d4322b..afb33ba 100644 --- a/gb-emu/src/main.rs +++ b/gb-emu/src/main.rs @@ -133,29 +133,49 @@ impl EmulatorHandler { ) .expect("Error parsing rom"); - let shader_path = if rom.rom_type == CgbRomType::CgbOnly || config.prefer_cgb { + let will_be_cgb = rom.rom_type == CgbRomType::CgbOnly || config.prefer_cgb; + + let shader_path = if will_be_cgb { config.vulkan_config.cgb_shader_path.as_ref() } else { config.vulkan_config.dmg_shader_path.as_ref() } .map(|v| config_manager.dir().join(v)); + let resizable = shader_path.is_some() + && if will_be_cgb { + config.vulkan_config.cgb_shader_resizable + } else { + config.vulkan_config.dmg_shader_resizable + }; + + let scale_override = match if will_be_cgb { + config.vulkan_config.cgb_resolution_override + } else { + config.vulkan_config.dmg_resolution_override + } { + gb_emu_lib::config::ResolutionOverride::Scale(scale) => Some(scale), + gb_emu_lib::config::ResolutionOverride::Default => None, + } + .unwrap_or(standalone_config.scale_factor); + let mut window_manager = WindowManager::new(sender); let window = window_manager.add( - standalone_config.scale_factor, + scale_override, Some(Gilrs::new().unwrap()), shader_path, + resizable, ); let tile_window: Option = if args.tile_window { - Some(window_manager.add(standalone_config.scale_factor, None, None)) + Some(window_manager.add(standalone_config.scale_factor, None, None, false)) } else { None }; let layer_window: Option = if args.layer_window { - Some(window_manager.add(standalone_config.scale_factor.min(2), None, None)) + Some(window_manager.add(standalone_config.scale_factor.min(2), None, None, false)) } else { None }; diff --git a/gb-emu/src/window.rs b/gb-emu/src/window.rs index b5bc175..31341ca 100644 --- a/gb-emu/src/window.rs +++ b/gb-emu/src/window.rs @@ -64,6 +64,7 @@ impl WindowManager { factor: usize, gamepad_handler: Option, shader_path: Option, + resizable: bool, ) -> WindowRenderer { let (r, info) = WindowRenderer::new( factor, @@ -72,6 +73,7 @@ impl WindowManager { &self.event_loop, self.window_data_manager.clone(), shader_path, + resizable, ); self.windows.insert(info.id, info.data); r @@ -137,10 +139,11 @@ impl WindowRenderer { event_loop: &EventLoop<()>, manager: Arc, shader_path: Option, + resizable: bool, ) -> (Self, WindowInfo) { let window = WindowBuilder::new() .with_title("Gameboy") - .with_resizable(shader_path.is_some()) + .with_resizable(resizable) .build(event_loop) .unwrap(); diff --git a/lib/src/config/mod.rs b/lib/src/config/mod.rs index 8076454..574d3c6 100644 --- a/lib/src/config/mod.rs +++ b/lib/src/config/mod.rs @@ -34,8 +34,11 @@ impl ConfigManager { where C: Serialize + DeserializeOwned + Default + Clone, { - match self.load_custom_config(name) { - Some(v) => v, + match self.load_custom_config::(name) { + Some(v) => { + let _ = self.save_custom_config(name, v.clone()); + v + } None => { let config = C::default(); if let Ok(true) = self.path.join(name).try_exists() { @@ -86,7 +89,17 @@ pub struct Config { #[serde(default)] pub struct VulkanRendererConfig { pub dmg_shader_path: Option, + pub dmg_shader_resizable: bool, + pub dmg_resolution_override: ResolutionOverride, pub cgb_shader_path: Option, + pub cgb_shader_resizable: bool, + pub cgb_resolution_override: ResolutionOverride, +} + +#[derive(Debug, Serialize, Deserialize, Clone, Copy)] +pub enum ResolutionOverride { + Scale(usize), + Default, } #[allow(clippy::derivable_impls)] @@ -107,7 +120,11 @@ impl Default for VulkanRendererConfig { fn default() -> Self { Self { dmg_shader_path: None, + dmg_shader_resizable: false, + dmg_resolution_override: ResolutionOverride::Default, cgb_shader_path: None, + cgb_shader_resizable: false, + cgb_resolution_override: ResolutionOverride::Default, } } }