config improvements

This commit is contained in:
Alex Janka 2023-10-05 11:23:07 +11:00
parent ffe677088f
commit 167d461c35
3 changed files with 47 additions and 7 deletions

View file

@ -133,29 +133,49 @@ impl EmulatorHandler {
) )
.expect("Error parsing rom"); .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() config.vulkan_config.cgb_shader_path.as_ref()
} else { } else {
config.vulkan_config.dmg_shader_path.as_ref() config.vulkan_config.dmg_shader_path.as_ref()
} }
.map(|v| config_manager.dir().join(v)); .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 mut window_manager = WindowManager::new(sender);
let window = window_manager.add( let window = window_manager.add(
standalone_config.scale_factor, scale_override,
Some(Gilrs::new().unwrap()), Some(Gilrs::new().unwrap()),
shader_path, shader_path,
resizable,
); );
let tile_window: Option<WindowRenderer> = if args.tile_window { let tile_window: Option<WindowRenderer> = 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 { } else {
None None
}; };
let layer_window: Option<WindowRenderer> = if args.layer_window { let layer_window: Option<WindowRenderer> = 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 { } else {
None None
}; };

View file

@ -64,6 +64,7 @@ impl WindowManager {
factor: usize, factor: usize,
gamepad_handler: Option<Gilrs>, gamepad_handler: Option<Gilrs>,
shader_path: Option<PathBuf>, shader_path: Option<PathBuf>,
resizable: bool,
) -> WindowRenderer { ) -> WindowRenderer {
let (r, info) = WindowRenderer::new( let (r, info) = WindowRenderer::new(
factor, factor,
@ -72,6 +73,7 @@ impl WindowManager {
&self.event_loop, &self.event_loop,
self.window_data_manager.clone(), self.window_data_manager.clone(),
shader_path, shader_path,
resizable,
); );
self.windows.insert(info.id, info.data); self.windows.insert(info.id, info.data);
r r
@ -137,10 +139,11 @@ impl WindowRenderer {
event_loop: &EventLoop<()>, event_loop: &EventLoop<()>,
manager: Arc<RendererBackendManager>, manager: Arc<RendererBackendManager>,
shader_path: Option<PathBuf>, shader_path: Option<PathBuf>,
resizable: bool,
) -> (Self, WindowInfo) { ) -> (Self, WindowInfo) {
let window = WindowBuilder::new() let window = WindowBuilder::new()
.with_title("Gameboy") .with_title("Gameboy")
.with_resizable(shader_path.is_some()) .with_resizable(resizable)
.build(event_loop) .build(event_loop)
.unwrap(); .unwrap();

View file

@ -34,8 +34,11 @@ impl ConfigManager {
where where
C: Serialize + DeserializeOwned + Default + Clone, C: Serialize + DeserializeOwned + Default + Clone,
{ {
match self.load_custom_config(name) { match self.load_custom_config::<C>(name) {
Some(v) => v, Some(v) => {
let _ = self.save_custom_config(name, v.clone());
v
}
None => { None => {
let config = C::default(); let config = C::default();
if let Ok(true) = self.path.join(name).try_exists() { if let Ok(true) = self.path.join(name).try_exists() {
@ -86,7 +89,17 @@ pub struct Config {
#[serde(default)] #[serde(default)]
pub struct VulkanRendererConfig { pub struct VulkanRendererConfig {
pub dmg_shader_path: Option<String>, pub dmg_shader_path: Option<String>,
pub dmg_shader_resizable: bool,
pub dmg_resolution_override: ResolutionOverride,
pub cgb_shader_path: Option<String>, pub cgb_shader_path: Option<String>,
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)] #[allow(clippy::derivable_impls)]
@ -107,7 +120,11 @@ impl Default for VulkanRendererConfig {
fn default() -> Self { fn default() -> Self {
Self { Self {
dmg_shader_path: None, dmg_shader_path: None,
dmg_shader_resizable: false,
dmg_resolution_override: ResolutionOverride::Default,
cgb_shader_path: None, cgb_shader_path: None,
cgb_shader_resizable: false,
cgb_resolution_override: ResolutionOverride::Default,
} }
} }
} }