From ac5f39a49e48fcdcf5cbaa28a9d2929321a0ea97 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Tue, 7 Mar 2023 03:05:02 +0100 Subject: [PATCH] basic netw --- kubi-server/src/chunk.rs | 8 +++++++- kubi/src/world/loading.rs | 19 ++++++++++++++----- kubi/src/world/tasks.rs | 18 ------------------ 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/kubi-server/src/chunk.rs b/kubi-server/src/chunk.rs index c214e43..2396e84 100644 --- a/kubi-server/src/chunk.rs +++ b/kubi-server/src/chunk.rs @@ -1,9 +1,15 @@ -//TODO server-side chunk manager +use glam::IVec3; +use hashbrown::HashMap; +use kubi_shared::chunk::BlockData; +use shipyard::Unique; pub struct Chunk { + pub blocks: BlockData } +#[derive(Unique)] pub struct ChunkManager { + pub chunks: HashMap } pub fn server_chunk_response( diff --git a/kubi/src/world/loading.rs b/kubi/src/world/loading.rs index ec5e7ca..e16a72f 100644 --- a/kubi/src/world/loading.rs +++ b/kubi/src/world/loading.rs @@ -1,12 +1,14 @@ use glam::{IVec3, ivec3}; use glium::{VertexBuffer, IndexBuffer, index::PrimitiveType}; +use kubi_shared::networking::messages::ClientToServerMessage; use shipyard::{View, UniqueView, UniqueViewMut, IntoIter, Workload, IntoWorkload, NonSendSync, track}; use crate::{ player::MainPlayer, transform::Transform, settings::GameSettings, rendering::Renderer, - state::GameState + state::GameState, + networking::UdpClient, }; use super::{ ChunkStorage, ChunkMeshStorage, @@ -118,6 +120,7 @@ fn unload_downgrade_chunks( fn start_required_tasks( task_manager: UniqueView, + udp_client: Option>, mut world: UniqueViewMut, ) { if !world.is_modified() { @@ -130,10 +133,16 @@ fn start_required_tasks( match chunk.desired_state { DesiredChunkState::Loaded | DesiredChunkState::Rendered if chunk.current_state == CurrentChunkState::Nothing => { //start load task - task_manager.spawn_task(ChunkTask::LoadChunk { - seed: 0xbeef_face_dead_cafe, - position - }); + if let Some(client) = &udp_client { + client.0.send_message(ClientToServerMessage::ChunkRequest { + chunk: position.to_array() + }).unwrap(); + } else { + task_manager.spawn_task(ChunkTask::LoadChunk { + seed: 0xbeef_face_dead_cafe, + position + }); + } //Update chunk state let chunk = world.chunks.get_mut(&position).unwrap(); chunk.current_state = CurrentChunkState::Loading; diff --git a/kubi/src/world/tasks.rs b/kubi/src/world/tasks.rs index 60b39e0..705b9a5 100644 --- a/kubi/src/world/tasks.rs +++ b/kubi/src/world/tasks.rs @@ -77,24 +77,6 @@ impl ChunkTaskManager { } } -pub fn spawn_task_or_get_from_network_if_possible(client: Option<&mut UdpClient>, manager: &mut ChunkTaskManager, task: ChunkTask) { - match &task { - ChunkTask::LoadChunk { seed, position } => { - match client { - Some(client) => { - client.0.send_message(ClientToServerMessage::ChunkRequest { chunk: position.to_array() }).unwrap(); - }, - None => { - manager.spawn_task(task) - } - } - }, - _ => { - manager.spawn_task(task) - } - } -} - //TODO get rid of this, this is awfulll pub fn inject_network_responses_into_manager_queue( manager: UniqueView,