mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-12-22 20:08:20 -06:00
Move inj to networking
This commit is contained in:
parent
f6eef9457b
commit
615251f031
|
@ -47,7 +47,7 @@ use world::{
|
|||
loading::update_loaded_world_around_player,
|
||||
raycast::update_raycasts,
|
||||
queue::apply_queued_blocks,
|
||||
tasks::{inject_network_responses_into_manager_queue, ChunkTaskManager}, ChunkStorage
|
||||
tasks::{ChunkTaskManager}, ChunkStorage
|
||||
};
|
||||
use player::{spawn_player, MainPlayer};
|
||||
use prefabs::load_prefabs;
|
||||
|
@ -113,7 +113,6 @@ fn update() -> Workload {
|
|||
(
|
||||
update_networking,
|
||||
//I don't know why skip_if_missing_unique is required??
|
||||
inject_network_responses_into_manager_queue.run_if(is_ingame_or_loading).skip_if_missing_unique::<ChunkTaskManager>(),
|
||||
).into_sequential_workload().run_if(is_multiplayer).tag("networking"),
|
||||
(
|
||||
switch_to_loading_if_connected
|
||||
|
|
|
@ -3,11 +3,11 @@ use glium::glutin::event_loop::ControlFlow;
|
|||
use std::net::SocketAddr;
|
||||
use uflow::client::{Client, Config as ClientConfig, Event as ClientEvent};
|
||||
use kubi_shared::networking::{
|
||||
messages::{ClientToServerMessage, ServerToClientMessage, S_SERVER_HELLO},
|
||||
messages::{ClientToServerMessage, ServerToClientMessage, S_SERVER_HELLO, S_CHUNK_RESPONSE},
|
||||
state::ClientJoinState,
|
||||
channels::CHANNEL_AUTH,
|
||||
};
|
||||
use crate::{events::EventComponent, control_flow::SetControlFlow};
|
||||
use crate::{events::EventComponent, control_flow::SetControlFlow, world::tasks::{ChunkTaskResponse, ChunkTaskManager}, state::is_ingame_or_loading};
|
||||
|
||||
#[derive(Unique, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum GameType {
|
||||
|
@ -108,6 +108,26 @@ fn check_server_hello_response(
|
|||
}
|
||||
}
|
||||
|
||||
//TODO get rid of this, this is awfulll
|
||||
pub fn inject_network_responses_into_manager_queue(
|
||||
manager: UniqueView<ChunkTaskManager>,
|
||||
events: View<NetworkEvent>
|
||||
) {
|
||||
for event in events.iter() {
|
||||
if event.is_message_of_type::<S_CHUNK_RESPONSE>() {
|
||||
let NetworkEvent(ClientEvent::Receive(data)) = &event else { unreachable!() };
|
||||
let ServerToClientMessage::ChunkResponse {
|
||||
chunk, data, queued
|
||||
} = postcard::from_bytes(data).expect("Chunk decode failed") else { unreachable!() };
|
||||
manager.add_sussy_response(ChunkTaskResponse::LoadedChunk {
|
||||
position: chunk,
|
||||
chunk_data: data,
|
||||
queued
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_networking() -> Workload {
|
||||
(
|
||||
connect_client.run_if_missing_unique::<UdpClient>(),
|
||||
|
@ -118,7 +138,8 @@ pub fn update_networking() -> Workload {
|
|||
).into_sequential_workload().run_if(if_just_connected),
|
||||
(
|
||||
check_server_hello_response,
|
||||
).into_sequential_workload().run_if(is_join_state::<{ClientJoinState::Connected as u8}>)
|
||||
).into_sequential_workload().run_if(is_join_state::<{ClientJoinState::Connected as u8}>),
|
||||
inject_network_responses_into_manager_queue.run_if(is_ingame_or_loading).skip_if_missing_unique::<ChunkTaskManager>(),
|
||||
).into_sequential_workload() //HACK Weird issues with shipyard removed
|
||||
}
|
||||
|
||||
|
|
|
@ -1,21 +1,14 @@
|
|||
use flume::{Sender, Receiver};
|
||||
use glam::IVec3;
|
||||
use kubi_shared::{
|
||||
networking::messages::{S_CHUNK_RESPONSE, ServerToClientMessage},
|
||||
queue::QueuedBlock
|
||||
};
|
||||
use shipyard::{Unique, UniqueView, View, IntoIter};
|
||||
use kubi_shared::queue::QueuedBlock;
|
||||
use shipyard::Unique;
|
||||
use rayon::{ThreadPool, ThreadPoolBuilder};
|
||||
use uflow::client::Event as ClientEvent;
|
||||
use super::{
|
||||
chunk::BlockData,
|
||||
mesh::{generate_mesh, data::MeshGenData},
|
||||
worldgen::generate_world,
|
||||
};
|
||||
use crate::{
|
||||
rendering::world::ChunkVertex,
|
||||
networking::NetworkEvent,
|
||||
};
|
||||
use crate::rendering::world::ChunkVertex;
|
||||
|
||||
pub enum ChunkTask {
|
||||
LoadChunk {
|
||||
|
@ -76,31 +69,3 @@ impl ChunkTaskManager {
|
|||
self.channel.1.try_recv().ok()
|
||||
}
|
||||
}
|
||||
|
||||
//TODO get rid of this, this is awfulll
|
||||
pub fn inject_network_responses_into_manager_queue(
|
||||
manager: UniqueView<ChunkTaskManager>,
|
||||
events: View<NetworkEvent>
|
||||
) {
|
||||
for event in events.iter() {
|
||||
if event.is_message_of_type::<S_CHUNK_RESPONSE>() {
|
||||
let NetworkEvent(ClientEvent::Receive(data)) = &event else { unreachable!() };
|
||||
let ServerToClientMessage::ChunkResponse {
|
||||
chunk, data, queued
|
||||
} = postcard::from_bytes(data).expect("Chunk decode failed") else { unreachable!() };
|
||||
manager.add_sussy_response(ChunkTaskResponse::LoadedChunk {
|
||||
position: chunk,
|
||||
chunk_data: data,
|
||||
queued
|
||||
});
|
||||
}
|
||||
// if let ClientEvent::MessageReceived(ServerToClientMessage::ChunkResponse { &chunk, data, queued }) = &event.0 {
|
||||
// let position = IVec3::from_array(chunk);
|
||||
// manager.add_sussy_response(ChunkTaskResponse::LoadedChunk {
|
||||
// position,
|
||||
// chunk_data: data.clone(),
|
||||
// queued
|
||||
// });
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue