mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-12-25 21:28:20 -06:00
basic netw
This commit is contained in:
parent
1bb785df1d
commit
ac5f39a49e
|
@ -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 struct Chunk {
|
||||||
|
pub blocks: BlockData
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Unique)]
|
||||||
pub struct ChunkManager {
|
pub struct ChunkManager {
|
||||||
|
pub chunks: HashMap<IVec3, Chunk>
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn server_chunk_response(
|
pub fn server_chunk_response(
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
use glam::{IVec3, ivec3};
|
use glam::{IVec3, ivec3};
|
||||||
use glium::{VertexBuffer, IndexBuffer, index::PrimitiveType};
|
use glium::{VertexBuffer, IndexBuffer, index::PrimitiveType};
|
||||||
|
use kubi_shared::networking::messages::ClientToServerMessage;
|
||||||
use shipyard::{View, UniqueView, UniqueViewMut, IntoIter, Workload, IntoWorkload, NonSendSync, track};
|
use shipyard::{View, UniqueView, UniqueViewMut, IntoIter, Workload, IntoWorkload, NonSendSync, track};
|
||||||
use crate::{
|
use crate::{
|
||||||
player::MainPlayer,
|
player::MainPlayer,
|
||||||
transform::Transform,
|
transform::Transform,
|
||||||
settings::GameSettings,
|
settings::GameSettings,
|
||||||
rendering::Renderer,
|
rendering::Renderer,
|
||||||
state::GameState
|
state::GameState,
|
||||||
|
networking::UdpClient,
|
||||||
};
|
};
|
||||||
use super::{
|
use super::{
|
||||||
ChunkStorage, ChunkMeshStorage,
|
ChunkStorage, ChunkMeshStorage,
|
||||||
|
@ -118,6 +120,7 @@ fn unload_downgrade_chunks(
|
||||||
|
|
||||||
fn start_required_tasks(
|
fn start_required_tasks(
|
||||||
task_manager: UniqueView<ChunkTaskManager>,
|
task_manager: UniqueView<ChunkTaskManager>,
|
||||||
|
udp_client: Option<UniqueView<UdpClient>>,
|
||||||
mut world: UniqueViewMut<ChunkStorage>,
|
mut world: UniqueViewMut<ChunkStorage>,
|
||||||
) {
|
) {
|
||||||
if !world.is_modified() {
|
if !world.is_modified() {
|
||||||
|
@ -130,10 +133,16 @@ fn start_required_tasks(
|
||||||
match chunk.desired_state {
|
match chunk.desired_state {
|
||||||
DesiredChunkState::Loaded | DesiredChunkState::Rendered if chunk.current_state == CurrentChunkState::Nothing => {
|
DesiredChunkState::Loaded | DesiredChunkState::Rendered if chunk.current_state == CurrentChunkState::Nothing => {
|
||||||
//start load task
|
//start load task
|
||||||
task_manager.spawn_task(ChunkTask::LoadChunk {
|
if let Some(client) = &udp_client {
|
||||||
seed: 0xbeef_face_dead_cafe,
|
client.0.send_message(ClientToServerMessage::ChunkRequest {
|
||||||
position
|
chunk: position.to_array()
|
||||||
});
|
}).unwrap();
|
||||||
|
} else {
|
||||||
|
task_manager.spawn_task(ChunkTask::LoadChunk {
|
||||||
|
seed: 0xbeef_face_dead_cafe,
|
||||||
|
position
|
||||||
|
});
|
||||||
|
}
|
||||||
//Update chunk state
|
//Update chunk state
|
||||||
let chunk = world.chunks.get_mut(&position).unwrap();
|
let chunk = world.chunks.get_mut(&position).unwrap();
|
||||||
chunk.current_state = CurrentChunkState::Loading;
|
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
|
//TODO get rid of this, this is awfulll
|
||||||
pub fn inject_network_responses_into_manager_queue(
|
pub fn inject_network_responses_into_manager_queue(
|
||||||
manager: UniqueView<ChunkTaskManager>,
|
manager: UniqueView<ChunkTaskManager>,
|
||||||
|
|
Loading…
Reference in a new issue