From 4c31eab0f4c1c659e2bc235d5598041fcc4d5b54 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Tue, 7 Mar 2023 17:05:55 +0100 Subject: [PATCH] wip server chunks --- kubi-server/src/world.rs | 2 ++ kubi-udp/tests/test.rs | 2 +- kubi/src/loading_screen.rs | 15 ++++++++++++++- kubi/src/main.rs | 2 +- kubi/src/world/tasks.rs | 4 ++-- 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/kubi-server/src/world.rs b/kubi-server/src/world.rs index 84c1561..29006c3 100644 --- a/kubi-server/src/world.rs +++ b/kubi-server/src/world.rs @@ -54,6 +54,7 @@ fn process_chunk_requests( } else { let mut chunk = Chunk::new(chunk_position); chunk.state = ChunkState::Loading; + chunk.subscriptions.insert(*client_id); chunk_manager.chunks.insert(chunk_position, chunk); task_manager.spawn_task(ChunkTask::LoadChunk { position: chunk_position, @@ -88,6 +89,7 @@ fn process_finished_tasks( queued: queue.iter().map(|item| (item.position.to_array(), item.block_type)).collect() }).map_err(log_error).ok(); } + log::debug!("Chunk {chunk_position} loaded, {} subs", chunk.subscriptions.len()) } } diff --git a/kubi-udp/tests/test.rs b/kubi-udp/tests/test.rs index 6de54d2..7deb52c 100644 --- a/kubi-udp/tests/test.rs +++ b/kubi-udp/tests/test.rs @@ -80,7 +80,7 @@ fn test_connection() { log::info!("client received message"); assert_eq!(data, STC_MSG, "Received message not equal"); message_received = true; - client.disconnect(); + client.disconnect().unwrap(); }, _ => () } diff --git a/kubi/src/loading_screen.rs b/kubi/src/loading_screen.rs index cb01e21..550a7db 100644 --- a/kubi/src/loading_screen.rs +++ b/kubi/src/loading_screen.rs @@ -1,4 +1,5 @@ use shipyard::{UniqueView, UniqueViewMut, Workload, IntoWorkload, EntityId, Unique, AllStoragesViewMut, ViewMut, Get, SystemModificator, track}; +use glium::glutin::event::VirtualKeyCode; use glam::{Mat3, vec2}; use crate::{ world::ChunkStorage, @@ -7,7 +8,9 @@ use crate::{ gui::{ GuiComponent, progressbar::ProgressbarComponent - }, rendering::{WindowSize, if_resized}, + }, + rendering::{WindowSize, if_resized}, + input::RawKbmInputState, }; #[derive(Unique, Clone, Copy)] @@ -69,6 +72,15 @@ fn switch_to_ingame_if_loaded( } } +fn override_loading( + kbm_state: UniqueView, + mut state: UniqueViewMut +) { + if kbm_state.keyboard_state.contains(&VirtualKeyCode::F) { + state.0 = Some(GameState::InGame); + } +} + fn despawn_loading_screen_if_switching_state( mut storages: AllStoragesViewMut, ) { @@ -85,6 +97,7 @@ pub fn update_loading_screen() -> Workload { spawn_loading_screen.run_if_missing_unique::(), resize_progress_bar.run_if(if_resized), update_progress_bar_progress, + override_loading, switch_to_ingame_if_loaded, despawn_loading_screen_if_switching_state.run_if(is_changing_state), ).into_workload() diff --git a/kubi/src/main.rs b/kubi/src/main.rs index 472d3c0..76481e5 100644 --- a/kubi/src/main.rs +++ b/kubi/src/main.rs @@ -110,7 +110,7 @@ fn update() -> Workload { ( update_networking, inject_network_responses_into_manager_queue, - ).into_workload().run_if(is_multiplayer), + ).into_sequential_workload().run_if(is_multiplayer), ( switch_to_loading_if_connected ).into_workload().run_if(is_connecting), diff --git a/kubi/src/world/tasks.rs b/kubi/src/world/tasks.rs index 5d855e1..0bc05ad 100644 --- a/kubi/src/world/tasks.rs +++ b/kubi/src/world/tasks.rs @@ -1,7 +1,7 @@ use flume::{Sender, Receiver}; use glam::IVec3; use kubi_shared::{ - networking::messages::{ClientToServerMessage, ServerToClientMessage}, + networking::messages::ServerToClientMessage, worldgen::QueuedBlock }; use shipyard::{Unique, UniqueView, View, IntoIter}; @@ -13,7 +13,7 @@ use super::{ }; use crate::{ rendering::world::ChunkVertex, - networking::{UdpClient, NetworkEvent} + networking::NetworkEvent, }; use kubi_udp::client::ClientEvent;