This commit is contained in:
griffi-gh 2023-02-10 01:47:37 +01:00
parent 1d82cf69ba
commit 1ce3b94cd5
7 changed files with 90 additions and 47 deletions

View file

@ -59,20 +59,20 @@ pub fn render_gui() -> Workload {
).into_workload() ).into_workload()
} }
pub fn gui_testing( // pub fn gui_testing(
mut storages: AllStoragesViewMut, // mut storages: AllStoragesViewMut,
) { // ) {
storages.add_entity(( // storages.add_entity((
GuiComponent, // GuiComponent,
Transform2d(Mat3::from_scale_angle_translation( // Transform2d(Mat3::from_scale_angle_translation(
vec2(1920., 16.), // vec2(1920., 16.),
0., // 0.,
vec2(0., 0.) // vec2(0., 0.)
)), // )),
ProgressbarComponent { // ProgressbarComponent {
progress: 0.33 // progress: 0.33
}, // },
PrimaryColor::default(), // PrimaryColor::default(),
SecondaryColor::default(), // SecondaryColor::default(),
)); // ));
} // }

View file

@ -1,21 +1,21 @@
use shipyard::AllStoragesView; use shipyard::{AllStoragesViewMut, UniqueViewMut};
use std::{env, net::SocketAddr}; use std::{env, net::SocketAddr, borrow::BorrowMut};
use crate::{ use crate::{
networking::{GameType, ServerAddress}, networking::{GameType, ServerAddress},
state::GameState state::{GameState, NextState}
}; };
pub fn initialize_from_args( pub fn initialize_from_args(
all_storages: AllStoragesView, mut all_storages: AllStoragesViewMut,
) { ) {
let args: Vec<String> = env::args().collect(); let args: Vec<String> = env::args().collect();
if args.len() > 1 { if args.len() > 1 {
let address = args[1].parse::<SocketAddr>().expect("invalid address"); let address = args[1].parse::<SocketAddr>().expect("invalid address");
all_storages.add_unique(GameType::Muliplayer); all_storages.add_unique(GameType::Muliplayer);
all_storages.add_unique(GameState::Connecting);
all_storages.add_unique(ServerAddress(address)); all_storages.add_unique(ServerAddress(address));
all_storages.borrow::<UniqueViewMut<NextState>>().unwrap().0 = Some(GameState::Connecting);
} else { } else {
all_storages.add_unique(GameType::Singleplayer); all_storages.add_unique(GameType::Singleplayer);
all_storages.add_unique(GameState::LoadingWorld); all_storages.borrow::<UniqueViewMut<NextState>>().unwrap().0 = Some(GameState::LoadingWorld);
} }
} }

View file

@ -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<ChunkStorage>,
mut state: UniqueViewMut<GameState>
) {
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()
}

View file

@ -38,10 +38,11 @@ pub(crate) mod gui;
pub(crate) mod networking; pub(crate) mod networking;
pub(crate) mod init; pub(crate) mod init;
pub(crate) mod color; pub(crate) mod color;
pub(crate) mod loading_screen;
use world::{ use world::{
init_game_world, init_game_world,
loading::{update_loaded_world_around_player, switch_to_ingame_if_loaded}, loading::update_loaded_world_around_player,
raycast::update_raycasts, raycast::update_raycasts,
queue::apply_queued_blocks queue::apply_queued_blocks
}; };
@ -50,8 +51,10 @@ use prefabs::load_prefabs;
use settings::load_settings; use settings::load_settings;
use camera::compute_cameras; use camera::compute_cameras;
use events::{ use events::{
clear_events, process_glutin_events, clear_events,
player_actions::generate_move_events, initial_resize_event process_glutin_events,
initial_resize_event,
player_actions::generate_move_events,
}; };
use input::{init_input, process_inputs}; use input::{init_input, process_inputs};
use fly_controller::update_controllers; use fly_controller::update_controllers;
@ -69,9 +72,10 @@ use block_placement::block_placement_system;
use delta_time::{DeltaTime, init_delta_time}; use delta_time::{DeltaTime, init_delta_time};
use cursor_lock::{insert_lock_state, update_cursor_lock_state, lock_cursor_now}; 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 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 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 { fn startup() -> Workload {
( (
@ -80,11 +84,11 @@ fn startup() -> Workload {
load_prefabs, load_prefabs,
init_primitives, init_primitives,
insert_lock_state, insert_lock_state,
init_state,
initialize_from_args, initialize_from_args,
lock_cursor_now, lock_cursor_now,
init_input, init_input,
init_gui, init_gui,
gui_testing,
init_game_world, init_game_world,
spawn_player, spawn_player,
insert_control_flow_unique, insert_control_flow_unique,
@ -97,7 +101,7 @@ fn update() -> Workload {
process_inputs, process_inputs,
exit_on_esc, exit_on_esc,
( (
switch_to_ingame_if_loaded, update_loading_screen,
).into_workload().run_if(is_loading), ).into_workload().run_if(is_loading),
( (
update_loaded_world_around_player, update_loaded_world_around_player,
@ -111,6 +115,7 @@ fn update() -> Workload {
).into_workload().run_if(is_ingame), ).into_workload().run_if(is_ingame),
compute_cameras, compute_cameras,
update_gui, update_gui,
update_state,
).into_workload() ).into_workload()
} }
fn render() -> Workload { fn render() -> Workload {

View file

@ -8,7 +8,7 @@ use glium::{
ContextBuilder, GlProfile ContextBuilder, GlProfile
}, },
}; };
use glam::Vec3; use glam::{Vec3, UVec2};
pub mod primitives; pub mod primitives;
pub mod world; pub mod world;

View file

@ -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)] #[track(All)]
pub enum GameState { pub enum GameState {
#[default]
Initial,
Connecting, Connecting,
LoadingWorld, LoadingWorld,
InGame InGame
} }
#[derive(Unique, PartialEq, Eq, Default, Clone, Copy)]
#[track(All)]
pub struct NextState(pub Option<GameState>);
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<GameState>,
mut next: UniqueViewMut<NextState>,
) {
*state = take(&mut next.0).unwrap_or(*state);
}
pub fn is_ingame( pub fn is_ingame(
state: UniqueView<GameState> state: UniqueView<GameState>
) -> bool { ) -> bool {

View file

@ -238,17 +238,3 @@ fn process_completed_tasks(
} }
} }
} }
pub fn switch_to_ingame_if_loaded(
world: UniqueView<ChunkStorage>,
mut state: UniqueViewMut<GameState>
) {
if world.chunks.is_empty() {
return
}
if world.chunks.iter().all(|(_, chunk)| {
chunk.desired_state.matches(chunk.current_state)
}) {
*state = GameState::InGame;
}
}