mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-22 06:48:43 -06:00
changed a lot of stuff, too lazy to write
This commit is contained in:
parent
f88e2733f3
commit
1ae34def21
|
@ -4,7 +4,7 @@
|
||||||
use shipyard::{
|
use shipyard::{
|
||||||
World, Workload, IntoWorkload,
|
World, Workload, IntoWorkload,
|
||||||
UniqueView, UniqueViewMut,
|
UniqueView, UniqueViewMut,
|
||||||
NonSendSync
|
NonSendSync, WorkloadModificator
|
||||||
};
|
};
|
||||||
use glium::{
|
use glium::{
|
||||||
glutin::{
|
glutin::{
|
||||||
|
@ -13,7 +13,6 @@ use glium::{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
use glam::vec3;
|
use glam::vec3;
|
||||||
use state::GameState;
|
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
mod logging;
|
mod logging;
|
||||||
|
@ -38,7 +37,7 @@ pub(crate) mod init;
|
||||||
|
|
||||||
use world::{
|
use world::{
|
||||||
init_game_world,
|
init_game_world,
|
||||||
loading::update_loaded_world_around_player,
|
loading::{update_loaded_world_around_player, switch_to_ingame_if_loaded},
|
||||||
raycast::update_raycasts, queue::apply_queued_blocks
|
raycast::update_raycasts, queue::apply_queued_blocks
|
||||||
};
|
};
|
||||||
use player::spawn_player;
|
use player::spawn_player;
|
||||||
|
@ -65,6 +64,7 @@ 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::{GameState, is_ingame, is_ingame_or_loading, is_loading};
|
||||||
use init::initialize_from_args;
|
use init::initialize_from_args;
|
||||||
|
|
||||||
fn startup() -> Workload {
|
fn startup() -> Workload {
|
||||||
|
@ -84,24 +84,33 @@ fn startup() -> Workload {
|
||||||
}
|
}
|
||||||
fn update() -> Workload {
|
fn update() -> Workload {
|
||||||
(
|
(
|
||||||
process_inputs,
|
|
||||||
update_controllers,
|
|
||||||
generate_move_events,
|
|
||||||
update_loaded_world_around_player,
|
|
||||||
update_raycasts,
|
|
||||||
block_placement_system,
|
|
||||||
apply_queued_blocks,
|
|
||||||
update_cursor_lock_state,
|
update_cursor_lock_state,
|
||||||
compute_cameras,
|
process_inputs,
|
||||||
exit_on_esc,
|
exit_on_esc,
|
||||||
|
(
|
||||||
|
switch_to_ingame_if_loaded,
|
||||||
|
).into_workload().run_if(is_loading),
|
||||||
|
(
|
||||||
|
update_loaded_world_around_player,
|
||||||
|
).into_workload().run_if(is_ingame_or_loading),
|
||||||
|
(
|
||||||
|
update_controllers,
|
||||||
|
generate_move_events,
|
||||||
|
update_raycasts,
|
||||||
|
block_placement_system,
|
||||||
|
apply_queued_blocks,
|
||||||
|
).into_workload().run_if(is_ingame),
|
||||||
|
compute_cameras,
|
||||||
).into_workload()
|
).into_workload()
|
||||||
}
|
}
|
||||||
fn render() -> Workload {
|
fn render() -> Workload {
|
||||||
(
|
(
|
||||||
clear_background,
|
clear_background,
|
||||||
draw_world,
|
(
|
||||||
draw_current_chunk_border,
|
draw_world,
|
||||||
render_selection_box,
|
draw_current_chunk_border,
|
||||||
|
render_selection_box,
|
||||||
|
).into_sequential_workload().run_if(is_ingame)
|
||||||
).into_sequential_workload()
|
).into_sequential_workload()
|
||||||
}
|
}
|
||||||
fn after_frame_end() -> Workload {
|
fn after_frame_end() -> Workload {
|
||||||
|
|
|
@ -1,10 +1,27 @@
|
||||||
use strum::EnumIter;
|
use shipyard::{Unique, UniqueView};
|
||||||
use shipyard::Unique;
|
|
||||||
|
|
||||||
#[derive(Unique, EnumIter)]
|
#[derive(Unique, PartialEq, Eq)]
|
||||||
#[track(All)]
|
#[track(All)]
|
||||||
pub enum GameState {
|
pub enum GameState {
|
||||||
Connecting,
|
Connecting,
|
||||||
LoadingWorld,
|
LoadingWorld,
|
||||||
InGame
|
InGame
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_ingame(
|
||||||
|
state: UniqueView<GameState>
|
||||||
|
) -> bool {
|
||||||
|
*state == GameState::InGame
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_loading(
|
||||||
|
state: UniqueView<GameState>
|
||||||
|
) -> bool {
|
||||||
|
matches!(*state, GameState::LoadingWorld)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_ingame_or_loading(
|
||||||
|
state: UniqueView<GameState>
|
||||||
|
) -> bool {
|
||||||
|
matches!(*state, GameState::InGame | GameState::LoadingWorld)
|
||||||
|
}
|
||||||
|
|
|
@ -30,6 +30,11 @@ pub enum CurrentChunkState {
|
||||||
RecalculatingMesh,
|
RecalculatingMesh,
|
||||||
Unloading,
|
Unloading,
|
||||||
}
|
}
|
||||||
|
impl CurrentChunkState {
|
||||||
|
pub fn matches(self, desired: DesiredChunkState) -> bool {
|
||||||
|
desired.matches(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
|
||||||
pub enum DesiredChunkState {
|
pub enum DesiredChunkState {
|
||||||
|
@ -39,6 +44,13 @@ pub enum DesiredChunkState {
|
||||||
Rendered,
|
Rendered,
|
||||||
ToUnload,
|
ToUnload,
|
||||||
}
|
}
|
||||||
|
impl DesiredChunkState {
|
||||||
|
pub fn matches(self, current: CurrentChunkState) -> bool {
|
||||||
|
(matches!(self, DesiredChunkState::Nothing) && matches!(current, CurrentChunkState::Nothing)) ||
|
||||||
|
(matches!(self, DesiredChunkState::Loaded) && matches!(current, CurrentChunkState::Loaded)) ||
|
||||||
|
(matches!(self, DesiredChunkState::Rendered) && matches!(current, CurrentChunkState::Rendered))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Chunk {
|
pub struct Chunk {
|
||||||
pub position: IVec3,
|
pub position: IVec3,
|
||||||
|
|
|
@ -5,7 +5,8 @@ use crate::{
|
||||||
player::MainPlayer,
|
player::MainPlayer,
|
||||||
transform::Transform,
|
transform::Transform,
|
||||||
settings::GameSettings,
|
settings::GameSettings,
|
||||||
rendering::Renderer
|
rendering::Renderer,
|
||||||
|
state::GameState
|
||||||
};
|
};
|
||||||
use super::{
|
use super::{
|
||||||
ChunkStorage, ChunkMeshStorage,
|
ChunkStorage, ChunkMeshStorage,
|
||||||
|
@ -168,7 +169,8 @@ fn process_completed_tasks(
|
||||||
task_manager: UniqueView<ChunkTaskManager>,
|
task_manager: UniqueView<ChunkTaskManager>,
|
||||||
mut world: UniqueViewMut<ChunkStorage>,
|
mut world: UniqueViewMut<ChunkStorage>,
|
||||||
mut meshes: NonSendSync<UniqueViewMut<ChunkMeshStorage>>,
|
mut meshes: NonSendSync<UniqueViewMut<ChunkMeshStorage>>,
|
||||||
renderer: NonSendSync<UniqueView<Renderer>>
|
renderer: NonSendSync<UniqueView<Renderer>>,
|
||||||
|
state: UniqueView<GameState>
|
||||||
) {
|
) {
|
||||||
let mut ops: usize = 0;
|
let mut ops: usize = 0;
|
||||||
while let Some(res) = task_manager.receive() {
|
while let Some(res) = task_manager.receive() {
|
||||||
|
@ -231,8 +233,19 @@ fn process_completed_tasks(
|
||||||
ops += 1;
|
ops += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ops >= MAX_CHUNK_OPS {
|
if (ops >= MAX_CHUNK_OPS) && matches!(*state, GameState::InGame) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn switch_to_ingame_if_loaded(
|
||||||
|
world: UniqueView<ChunkStorage>,
|
||||||
|
mut state: UniqueViewMut<GameState>
|
||||||
|
) {
|
||||||
|
if world.chunks.iter().all(|(_, chunk)| {
|
||||||
|
chunk.desired_state.matches(chunk.current_state)
|
||||||
|
}) {
|
||||||
|
*state = GameState::InGame;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue