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 5c3062d13f
commit 1c0409a9cf
4 changed files with 27 additions and 12 deletions

View file

@ -8,8 +8,7 @@ edition = "2021"
[dependencies] [dependencies]
glam = { version = "0.22", features = ["debug-glam-assert", "fast-math", "serde"] } glam = { version = "0.22", features = ["debug-glam-assert", "fast-math", "serde"] }
strum = { version = "0.24", features = ["derive"] } strum = { version = "0.24", features = ["derive"] }
bincode = { version = "2.0.0-rc", default_features = false, features = ["std", "serde"] } bincode = "2.0.0-rc"
serde = { version = "1.0", features = ["derive"] }
anyhow = "1.0" anyhow = "1.0"
bracket-noise = "0.8" bracket-noise = "0.8"
#laminar = "0.5.0" #laminar = "0.5.0"

View file

@ -1,6 +1,7 @@
use bincode::{Encode, Decode};
use strum::EnumIter; use strum::EnumIter;
#[derive(Clone, Copy, Debug, PartialEq, Eq, EnumIter)] #[derive(Encode, Decode, Clone, Copy, Debug, PartialEq, Eq, EnumIter)]
#[repr(u8)] #[repr(u8)]
pub enum Block { pub enum Block {
Air, Air,

View file

@ -16,7 +16,7 @@ impl Client {
}) })
} }
pub fn send(&self, message: ClientToServerMessage) -> anyhow::Result<()> { 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)?; self.socket.send(&bytes)?;
Ok(()) Ok(())
} }

View file

@ -1,7 +1,11 @@
use glam::{Vec3, Quat}; use bincode::{Encode, Decode};
use serde::{Serialize, Deserialize}; 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 { pub enum ClientToServerMessage {
ClientHello { ClientHello {
username: String, username: String,
@ -10,12 +14,17 @@ pub enum ClientToServerMessage {
PositionChanged { PositionChanged {
client_id: u8, client_id: u8,
secret: u32, secret: u32,
position: Vec3, position: Vec3Arr,
direction: Quat direction: QuatArr,
} },
ChunkRequest {
client_id: u8,
secret: u32,
chunk: IVec3Arr,
},
} }
#[derive(Serialize, Deserialize)] #[derive(Encode, Decode)]
pub enum ServerToClientMessage { pub enum ServerToClientMessage {
ServerHello { ServerHello {
client_id: u8, client_id: u8,
@ -25,6 +34,12 @@ pub enum ServerToClientMessage {
reason: String, reason: String,
}, },
PlayerPositionChanged { PlayerPositionChanged {
client_id: u8,
position: Vec3Arr,
direction: QuatArr,
}, },
ChunkResponse {
chunk: IVec3Arr,
data: BlockData
}
} }