From f1a8b87672629de5fa8b9bf4258c0b6c451c39bf Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Tue, 31 Jan 2023 03:06:30 +0100 Subject: [PATCH] use bincode derive instead of serde due to potential issues --- kubi-shared/Cargo.toml | 3 +-- kubi-shared/src/blocks.rs | 3 ++- kubi-shared/src/networking/client.rs | 2 +- kubi-shared/src/networking/messages.rs | 31 +++++++++++++++++++------- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/kubi-shared/Cargo.toml b/kubi-shared/Cargo.toml index 0cae1ee..d3d65bb 100644 --- a/kubi-shared/Cargo.toml +++ b/kubi-shared/Cargo.toml @@ -8,8 +8,7 @@ edition = "2021" [dependencies] glam = { version = "0.22", features = ["debug-glam-assert", "fast-math", "serde"] } strum = { version = "0.24", features = ["derive"] } -bincode = { version = "2.0.0-rc", default_features = false, features = ["std", "serde"] } -serde = { version = "1.0", features = ["derive"] } +bincode = "2.0.0-rc" anyhow = "1.0" bracket-noise = "0.8" #laminar = "0.5.0" diff --git a/kubi-shared/src/blocks.rs b/kubi-shared/src/blocks.rs index ced61a8..3e601fc 100644 --- a/kubi-shared/src/blocks.rs +++ b/kubi-shared/src/blocks.rs @@ -1,6 +1,7 @@ +use bincode::{Encode, Decode}; use strum::EnumIter; -#[derive(Clone, Copy, Debug, PartialEq, Eq, EnumIter)] +#[derive(Encode, Decode, Clone, Copy, Debug, PartialEq, Eq, EnumIter)] #[repr(u8)] pub enum Block { Air, diff --git a/kubi-shared/src/networking/client.rs b/kubi-shared/src/networking/client.rs index d112490..863715f 100644 --- a/kubi-shared/src/networking/client.rs +++ b/kubi-shared/src/networking/client.rs @@ -16,7 +16,7 @@ impl Client { }) } pub fn send(&self, message: ClientToServerMessage) -> anyhow::Result<()> { - let bytes = bincode::serde::encode_to_vec(message, BINCODE_CONFIG)?; + let bytes = bincode::encode_to_vec(message, BINCODE_CONFIG)?; self.socket.send(&bytes)?; Ok(()) } diff --git a/kubi-shared/src/networking/messages.rs b/kubi-shared/src/networking/messages.rs index 5940f24..2e2609b 100644 --- a/kubi-shared/src/networking/messages.rs +++ b/kubi-shared/src/networking/messages.rs @@ -1,7 +1,11 @@ -use glam::{Vec3, Quat}; -use serde::{Serialize, Deserialize}; +use bincode::{Encode, Decode}; +use crate::chunk::BlockData; -#[derive(Serialize, Deserialize)] +type IVec3Arr = [i32; 3]; +type Vec3Arr = [f32; 3]; +type QuatArr = [f32; 3]; + +#[derive(Encode, Decode)] pub enum ClientToServerMessage { ClientHello { username: String, @@ -10,12 +14,17 @@ pub enum ClientToServerMessage { PositionChanged { client_id: u8, secret: u32, - position: Vec3, - direction: Quat - } + position: Vec3Arr, + direction: QuatArr, + }, + ChunkRequest { + client_id: u8, + secret: u32, + chunk: IVec3Arr, + }, } -#[derive(Serialize, Deserialize)] +#[derive(Encode, Decode)] pub enum ServerToClientMessage { ServerHello { client_id: u8, @@ -25,6 +34,12 @@ pub enum ServerToClientMessage { reason: String, }, PlayerPositionChanged { - + client_id: u8, + position: Vec3Arr, + direction: QuatArr, }, + ChunkResponse { + chunk: IVec3Arr, + data: BlockData + } }