mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-21 22:38:41 -06:00
basic netw
This commit is contained in:
parent
12fee77087
commit
a46c5baab8
|
@ -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<IVec3, Chunk>
|
||||
}
|
||||
|
||||
pub fn server_chunk_response(
|
||||
|
|
|
@ -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<ChunkTaskManager>,
|
||||
udp_client: Option<UniqueView<UdpClient>>,
|
||||
mut world: UniqueViewMut<ChunkStorage>,
|
||||
) {
|
||||
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;
|
||||
|
|
|
@ -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<ChunkTaskManager>,
|
||||
|
|
Loading…
Reference in a new issue