use bincode derive instead of serde due to potential issues

This commit is contained in:
griffi-gh 2023-01-31 03:06:30 +01:00
parent a61f419f3b
commit f1a8b87672
4 changed files with 27 additions and 12 deletions

View file

@ -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"

View file

@ -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,

View file

@ -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(())
}

View file

@ -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
}
}