Add Settings with fullscreen and windowed options, a config file
(settings.toml) to persist settings, fix a bug in platform code where innner window size wasn't updated on resize, various other tweaks
This commit is contained in:
parent
b17a7636d8
commit
f5a16213fa
10 changed files with 277 additions and 19 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::sync::{Arc, Mutex, RwLock};
|
||||
use raidillon_platform::{Platform, PlatformContext, TimeContext};
|
||||
use glium::backend::glutin::Display;
|
||||
use glium::backend::glutin::SimpleWindowBuilder;
|
||||
|
|
@ -19,6 +19,7 @@ use crate::GliumAssetManager;
|
|||
use glam::Vec3;
|
||||
use winit::event::DeviceEvent::MouseMotion;
|
||||
use raidillon_core::EguiQueue;
|
||||
use raidillon_platform::settings::{Settings, default_config_path};
|
||||
|
||||
pub struct GliumPlatform<E: EngineTrait<PlatformCtx = PlatformContext>> {
|
||||
event_loop: EventLoop<()>,
|
||||
|
|
@ -29,6 +30,7 @@ pub struct GliumPlatform<E: EngineTrait<PlatformCtx = PlatformContext>> {
|
|||
engine: E,
|
||||
time: time::Time,
|
||||
egui_queue: Rc<RefCell<EguiQueue>>,
|
||||
settings: Arc<RwLock<Settings>>,
|
||||
}
|
||||
|
||||
impl<E: EngineTrait<PlatformCtx = PlatformContext>> Platform<E> for GliumPlatform<E> {
|
||||
|
|
@ -57,6 +59,12 @@ impl<E: EngineTrait<PlatformCtx = PlatformContext>> Platform<E> for GliumPlatfor
|
|||
|
||||
let egui_queue = Rc::new(RefCell::new(EguiQueue::new()));
|
||||
|
||||
let settings = Arc::new(
|
||||
RwLock::new(
|
||||
Settings::load_or_default(default_config_path()).unwrap()
|
||||
)
|
||||
);
|
||||
|
||||
Self {
|
||||
event_loop,
|
||||
window,
|
||||
|
|
@ -66,6 +74,7 @@ impl<E: EngineTrait<PlatformCtx = PlatformContext>> Platform<E> for GliumPlatfor
|
|||
engine,
|
||||
time,
|
||||
egui_queue,
|
||||
settings,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -82,9 +91,18 @@ impl<E: EngineTrait<PlatformCtx = PlatformContext>> Platform<E> for GliumPlatfor
|
|||
time_ctx: self.construct_time_ctx(),
|
||||
window: self.window.clone(),
|
||||
egui_queue: self.egui_queue.clone(),
|
||||
settings: self.settings.clone(),
|
||||
};
|
||||
self.engine.initialize(ctx.clone());
|
||||
self.settings.read().unwrap().display_settings.apply(&*self.window.lock().unwrap());
|
||||
|
||||
let _ = &self.event_loop.run(move |event, el| {
|
||||
let settings_handle = self.settings.read().unwrap();
|
||||
if settings_handle.display_settings.dirty {
|
||||
settings_handle.display_settings.apply(&*self.window.lock().unwrap());
|
||||
}
|
||||
drop(settings_handle);
|
||||
|
||||
self.rendering_system_manager
|
||||
.systems
|
||||
.values_mut()
|
||||
|
|
@ -96,8 +114,14 @@ impl<E: EngineTrait<PlatformCtx = PlatformContext>> Platform<E> for GliumPlatfor
|
|||
|
||||
match event {
|
||||
Event::WindowEvent { event, .. } => match event {
|
||||
WindowEvent::Resized(size) => {
|
||||
if size.width > 0 && size.height > 0 {
|
||||
self.display.resize((size.width, size.height));
|
||||
}
|
||||
},
|
||||
WindowEvent::CloseRequested => {
|
||||
// TODO: Run uninitialize on renderer and engine
|
||||
self.settings.read().unwrap().save_to_file(default_config_path());
|
||||
el.exit();
|
||||
},
|
||||
WindowEvent::RedrawRequested => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue