mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-26 08:48:50 -06:00
uwu
This commit is contained in:
parent
4e357af959
commit
2f23f39604
|
@ -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(),
|
||||||
));
|
// ));
|
||||||
}
|
// }
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
31
kubi/src/loading_screen.rs
Normal file
31
kubi/src/loading_screen.rs
Normal 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()
|
||||||
|
}
|
|
@ -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 {
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue