From 1ce3b94cd569c54d5b86cbb14d2d43cd12eb3687 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Fri, 10 Feb 2023 01:47:37 +0100 Subject: [PATCH] uwu --- kubi/src/gui.rs | 34 +++++++++++++++++----------------- kubi/src/init.rs | 12 ++++++------ kubi/src/loading_screen.rs | 31 +++++++++++++++++++++++++++++++ kubi/src/main.rs | 19 ++++++++++++------- kubi/src/rendering.rs | 2 +- kubi/src/state.rs | 25 +++++++++++++++++++++++-- kubi/src/world/loading.rs | 14 -------------- 7 files changed, 90 insertions(+), 47 deletions(-) create mode 100644 kubi/src/loading_screen.rs diff --git a/kubi/src/gui.rs b/kubi/src/gui.rs index 8f78889..73ac0d9 100644 --- a/kubi/src/gui.rs +++ b/kubi/src/gui.rs @@ -59,20 +59,20 @@ pub fn render_gui() -> Workload { ).into_workload() } -pub fn gui_testing( - mut storages: AllStoragesViewMut, -) { - storages.add_entity(( - GuiComponent, - Transform2d(Mat3::from_scale_angle_translation( - vec2(1920., 16.), - 0., - vec2(0., 0.) - )), - ProgressbarComponent { - progress: 0.33 - }, - PrimaryColor::default(), - SecondaryColor::default(), - )); -} +// pub fn gui_testing( +// mut storages: AllStoragesViewMut, +// ) { +// storages.add_entity(( +// GuiComponent, +// Transform2d(Mat3::from_scale_angle_translation( +// vec2(1920., 16.), +// 0., +// vec2(0., 0.) +// )), +// ProgressbarComponent { +// progress: 0.33 +// }, +// PrimaryColor::default(), +// SecondaryColor::default(), +// )); +// } diff --git a/kubi/src/init.rs b/kubi/src/init.rs index 6f35e85..24536c6 100644 --- a/kubi/src/init.rs +++ b/kubi/src/init.rs @@ -1,21 +1,21 @@ -use shipyard::AllStoragesView; -use std::{env, net::SocketAddr}; +use shipyard::{AllStoragesViewMut, UniqueViewMut}; +use std::{env, net::SocketAddr, borrow::BorrowMut}; use crate::{ networking::{GameType, ServerAddress}, - state::GameState + state::{GameState, NextState} }; pub fn initialize_from_args( - all_storages: AllStoragesView, + mut all_storages: AllStoragesViewMut, ) { let args: Vec = env::args().collect(); if args.len() > 1 { let address = args[1].parse::().expect("invalid address"); all_storages.add_unique(GameType::Muliplayer); - all_storages.add_unique(GameState::Connecting); all_storages.add_unique(ServerAddress(address)); + all_storages.borrow::>().unwrap().0 = Some(GameState::Connecting); } else { all_storages.add_unique(GameType::Singleplayer); - all_storages.add_unique(GameState::LoadingWorld); + all_storages.borrow::>().unwrap().0 = Some(GameState::LoadingWorld); } } diff --git a/kubi/src/loading_screen.rs b/kubi/src/loading_screen.rs new file mode 100644 index 0000000..6ddb4e0 --- /dev/null +++ b/kubi/src/loading_screen.rs @@ -0,0 +1,31 @@ +use shipyard::{UniqueView, UniqueViewMut, Workload, IntoWorkload}; +use crate::{ + world::ChunkStorage, + state::GameState +}; + +pub fn insert_progressbar() { + +} + + +pub fn switch_to_ingame_if_loaded( + world: UniqueView, + mut state: UniqueViewMut +) { + if world.chunks.is_empty() { + return + } + if world.chunks.iter().all(|(_, chunk)| { + chunk.desired_state.matches(chunk.current_state) + }) { + *state = GameState::InGame; + } +} + +pub fn update_loading_screen() -> Workload { + ( + insert_progressbar, + switch_to_ingame_if_loaded + ).into_workload() +} diff --git a/kubi/src/main.rs b/kubi/src/main.rs index e19e65d..d29b4c7 100644 --- a/kubi/src/main.rs +++ b/kubi/src/main.rs @@ -38,10 +38,11 @@ pub(crate) mod gui; pub(crate) mod networking; pub(crate) mod init; pub(crate) mod color; +pub(crate) mod loading_screen; use world::{ init_game_world, - loading::{update_loaded_world_around_player, switch_to_ingame_if_loaded}, + loading::update_loaded_world_around_player, raycast::update_raycasts, queue::apply_queued_blocks }; @@ -50,8 +51,10 @@ use prefabs::load_prefabs; use settings::load_settings; use camera::compute_cameras; use events::{ - clear_events, process_glutin_events, - player_actions::generate_move_events, initial_resize_event + clear_events, + process_glutin_events, + initial_resize_event, + player_actions::generate_move_events, }; use input::{init_input, process_inputs}; use fly_controller::update_controllers; @@ -69,9 +72,10 @@ use block_placement::block_placement_system; use delta_time::{DeltaTime, init_delta_time}; use cursor_lock::{insert_lock_state, update_cursor_lock_state, lock_cursor_now}; use control_flow::{exit_on_esc, insert_control_flow_unique, SetControlFlow}; -use state::{is_ingame, is_ingame_or_loading, is_loading}; +use state::{is_ingame, is_ingame_or_loading, is_loading, init_state, update_state}; use init::initialize_from_args; -use gui::{render_gui, init_gui, gui_testing, update_gui}; +use gui::{render_gui, init_gui, update_gui}; +use loading_screen::update_loading_screen; fn startup() -> Workload { ( @@ -80,11 +84,11 @@ fn startup() -> Workload { load_prefabs, init_primitives, insert_lock_state, + init_state, initialize_from_args, lock_cursor_now, init_input, init_gui, - gui_testing, init_game_world, spawn_player, insert_control_flow_unique, @@ -97,7 +101,7 @@ fn update() -> Workload { process_inputs, exit_on_esc, ( - switch_to_ingame_if_loaded, + update_loading_screen, ).into_workload().run_if(is_loading), ( update_loaded_world_around_player, @@ -111,6 +115,7 @@ fn update() -> Workload { ).into_workload().run_if(is_ingame), compute_cameras, update_gui, + update_state, ).into_workload() } fn render() -> Workload { diff --git a/kubi/src/rendering.rs b/kubi/src/rendering.rs index 1e234da..a288b3a 100644 --- a/kubi/src/rendering.rs +++ b/kubi/src/rendering.rs @@ -8,7 +8,7 @@ use glium::{ ContextBuilder, GlProfile }, }; -use glam::Vec3; +use glam::{Vec3, UVec2}; pub mod primitives; pub mod world; diff --git a/kubi/src/state.rs b/kubi/src/state.rs index 1f1297f..305f7c4 100644 --- a/kubi/src/state.rs +++ b/kubi/src/state.rs @@ -1,13 +1,34 @@ -use shipyard::{Unique, UniqueView}; +use shipyard::{Unique, UniqueView, UniqueViewMut, AllStoragesView}; +use std::mem::take; -#[derive(Unique, PartialEq, Eq)] +#[derive(Unique, PartialEq, Eq, Default, Clone, Copy)] #[track(All)] pub enum GameState { + #[default] + Initial, Connecting, LoadingWorld, InGame } +#[derive(Unique, PartialEq, Eq, Default, Clone, Copy)] +#[track(All)] +pub struct NextState(pub Option); + +pub fn init_state( + all_storages: AllStoragesView, +) { + all_storages.add_unique(GameState::default()); + all_storages.add_unique(NextState::default()); +} + +pub fn update_state( + mut state: UniqueViewMut, + mut next: UniqueViewMut, +) { + *state = take(&mut next.0).unwrap_or(*state); +} + pub fn is_ingame( state: UniqueView ) -> bool { diff --git a/kubi/src/world/loading.rs b/kubi/src/world/loading.rs index 307b898..e5c01ce 100644 --- a/kubi/src/world/loading.rs +++ b/kubi/src/world/loading.rs @@ -238,17 +238,3 @@ fn process_completed_tasks( } } } - -pub fn switch_to_ingame_if_loaded( - world: UniqueView, - mut state: UniqueViewMut -) { - if world.chunks.is_empty() { - return - } - if world.chunks.iter().all(|(_, chunk)| { - chunk.desired_state.matches(chunk.current_state) - }) { - *state = GameState::InGame; - } -}