diff --git a/kubi/src/main.rs b/kubi/src/main.rs index 5e3ea5b..f4354dc 100644 --- a/kubi/src/main.rs +++ b/kubi/src/main.rs @@ -51,7 +51,7 @@ use world::{ }; use player::{spawn_player, MainPlayer}; use prefabs::load_prefabs; -use settings::load_settings; +use settings::{load_settings, GameSettings}; use camera::compute_cameras; use events::{ clear_events, @@ -84,11 +84,17 @@ use gui::{render_gui, init_gui, update_gui}; use loading_screen::update_loading_screen; use connecting_screen::switch_to_loading_if_connected; +/// stuff required to init the renderer and other basic systems +fn pre_startup() -> Workload { + ( + load_settings, + ).into_sequential_workload() +} + fn startup() -> Workload { ( initial_resize_event, init_window_size, - load_settings, load_prefabs, init_primitives, insert_lock_state, @@ -170,19 +176,26 @@ fn main() { //Create a shipyard world let mut world = World::new(); - - //Create event loop - let event_loop = EventLoop::new(); - - //Add systems and uniques, Init and load things - world.add_unique_non_send_sync(Renderer::init(&event_loop)); - world.add_unique(BackgroundColor(vec3(0.5, 0.5, 1.))); - + //Register workloads + world.add_workload(pre_startup); world.add_workload(startup); world.add_workload(update); world.add_workload(render); world.add_workload(after_frame_end); + + //Run pre-startup procedure + world.run_workload(pre_startup).unwrap(); + + //Create event loop + let event_loop = EventLoop::new(); + + //Initialize renderer + { + let settings = world.borrow::>().unwrap(); + world.add_unique_non_send_sync(Renderer::init(&event_loop, &settings)); + } + world.add_unique(BackgroundColor(vec3(0.5, 0.5, 1.))); //Save _visualizer.json #[cfg(feature = "generate_visualizer_data")] diff --git a/kubi/src/rendering.rs b/kubi/src/rendering.rs index f0b621a..aa16e02 100644 --- a/kubi/src/rendering.rs +++ b/kubi/src/rendering.rs @@ -9,7 +9,7 @@ use glium::{ }, }; use glam::{Vec3, UVec2}; -use crate::events::WindowResizedEvent; +use crate::{events::WindowResizedEvent, settings::GameSettings}; pub mod primitives; pub mod world; @@ -29,13 +29,14 @@ pub struct Renderer { pub display: Display } impl Renderer { - pub fn init(event_loop: &EventLoop<()>) -> Self { + pub fn init(event_loop: &EventLoop<()>, settings: &GameSettings) -> Self { log::info!("initializing display"); let wb = WindowBuilder::new() .with_title("uwu") .with_maximized(true); let cb = ContextBuilder::new() .with_depth_buffer(24) + .with_multisampling(settings.msaa.unwrap_or_default()) .with_gl_profile(GlProfile::Core); let display = Display::new(wb, cb, event_loop) .expect("Failed to create a glium Display"); diff --git a/kubi/src/settings.rs b/kubi/src/settings.rs index 4df17d8..bf6d8f8 100644 --- a/kubi/src/settings.rs +++ b/kubi/src/settings.rs @@ -2,7 +2,7 @@ use shipyard::{Unique, AllStoragesView}; #[derive(Unique)] pub struct GameSettings { - pub msaa: Option, + pub msaa: Option, pub max_anisotropy: Option, /// there's a 1 chunk border of loaded but invisible around this pub render_distance: u8, @@ -24,6 +24,7 @@ impl Default for GameSettings { pub fn load_settings( storages: AllStoragesView ) { + log::info!("loading game settings"); //todo storages.add_unique(GameSettings::default()); }