config is neater
This commit is contained in:
parent
3349576aa1
commit
d4bc05b803
2 changed files with 11 additions and 11 deletions
|
@ -80,8 +80,10 @@ struct Configs {
|
|||
config_dir: PathBuf,
|
||||
}
|
||||
|
||||
impl Configs {
|
||||
fn get() -> Self {
|
||||
static CONFIGS: OnceLock<Configs> = OnceLock::new();
|
||||
|
||||
fn access_config<'a>() -> &'a Configs {
|
||||
CONFIGS.get_or_init(|| {
|
||||
let config_manager = ConfigManager::get().expect("Could not open config folder");
|
||||
let emu_config = config_manager.load_or_create_base_config();
|
||||
let vst_config = config_manager.load_or_create_config::<VstConfig>("vst");
|
||||
|
@ -90,12 +92,12 @@ impl Configs {
|
|||
panic!("no rom provided!!");
|
||||
}
|
||||
|
||||
Self {
|
||||
Configs {
|
||||
vst_config,
|
||||
emu_config,
|
||||
config_dir: config_manager.dir(),
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
|
@ -116,8 +118,6 @@ type JoypadSender = Mutex<Option<Sender<JoypadInfo>>>;
|
|||
const BUFFERS_PER_FRAME: usize = 1;
|
||||
const DOWNSAMPLE_TYPE: DownsampleType = DownsampleType::Linear;
|
||||
|
||||
static CONFIGS: OnceLock<Configs> = OnceLock::new();
|
||||
|
||||
impl Plugin for GameboyEmu {
|
||||
const NAME: &'static str = "Gameboy";
|
||||
|
||||
|
@ -248,7 +248,7 @@ impl Plugin for GameboyEmu {
|
|||
}
|
||||
|
||||
fn editor(&mut self, _: AsyncExecutor<Self>) -> Option<Box<dyn Editor>> {
|
||||
let configs = CONFIGS.get_or_init(Configs::get);
|
||||
let configs = access_config();
|
||||
|
||||
let size = Size::new(
|
||||
(WIDTH * configs.vst_config.scale_factor) as f64,
|
||||
|
@ -279,8 +279,7 @@ impl Plugin for GameboyEmu {
|
|||
vars.emulator_core.replace_output(output);
|
||||
vars.rx = rx;
|
||||
} else {
|
||||
let configs = CONFIGS.get_or_init(Configs::get);
|
||||
|
||||
let configs = access_config();
|
||||
let rom_path = configs.config_dir.join(configs.vst_config.rom.clone());
|
||||
if !rom_path.is_file() {
|
||||
panic!("{rom_path:?} is not a file!");
|
||||
|
@ -350,6 +349,7 @@ impl Plugin for GameboyEmu {
|
|||
}
|
||||
|
||||
fn deactivate(&mut self) {
|
||||
eprintln!("DEACTIVATE FUNCTION");
|
||||
if let Some(ref mut vars) = self.vars {
|
||||
match vars.sender.send(EmulatorMessage::Stop) {
|
||||
Ok(_) => self.vars = None,
|
||||
|
|
|
@ -14,7 +14,7 @@ use gb_emu_lib::{
|
|||
use keyboard_types::{Code, KeyState};
|
||||
use nih_plug::prelude::*;
|
||||
|
||||
use crate::{Configs, Frame, FrameReceiver, JoypadInfo, JoypadSender, CONFIGS};
|
||||
use crate::{access_config, Frame, FrameReceiver, JoypadInfo, JoypadSender};
|
||||
|
||||
pub struct Emulator {
|
||||
frame_receiver: Arc<FrameReceiver>,
|
||||
|
@ -63,7 +63,7 @@ impl Editor for Emulator {
|
|||
#[cfg(feature = "vulkan")]
|
||||
let shader_path = self.shader_path.lock().unwrap().clone();
|
||||
// let shader_path = None;
|
||||
let scale_factor = CONFIGS.get_or_init(Configs::get).vst_config.scale_factor;
|
||||
let scale_factor = access_config().vst_config.scale_factor;
|
||||
|
||||
let size = Size::new(
|
||||
(WIDTH * scale_factor) as f64,
|
||||
|
|
Loading…
Add table
Reference in a new issue