From 85d55e42119ea80cd1cd9e9e34c05ea7d07b3a88 Mon Sep 17 00:00:00 2001 From: Lizzy Fleckenstein Date: Tue, 28 Feb 2023 18:08:41 +0100 Subject: Use cgmath and support BS constant --- src/to_srv.rs | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) (limited to 'src/to_srv.rs') diff --git a/src/to_srv.rs b/src/to_srv.rs index dc9a342..0611bb9 100644 --- a/src/to_srv.rs +++ b/src/to_srv.rs @@ -14,14 +14,34 @@ pub enum Key { Zoom, } +#[cfg(feature = "client")] +fn ser_cast_err() -> mt_ser::SerializeError { + mt_ser::SerializeError::Other("cast failed".into()) +} + +#[cfg(feature = "server")] +fn des_cast_err() -> mt_ser::DeserializeError { + mt_ser::DeserializeError::Other("cast failed".into()) +} + #[mt_derive(to = "srv")] pub struct PlayerPos { - pub pos_100: [i32; 3], - pub vel_100: [i32; 3], - pub pitch_100: i32, - pub yaw_100: i32, + #[mt(multiplier = "100.0 * BS")] + #[mt(map_ser = "|x| x.cast::().ok_or_else(ser_cast_err)")] + #[mt(map_des = "|x: Point3| x.cast::().ok_or_else(des_cast_err)")] + pub pos: Point3, + #[mt(multiplier = "100.0 * BS")] + #[mt(map_ser = "|x| x.cast::().ok_or_else(ser_cast_err)")] + #[mt(map_des = "|x: Vector3| x.cast::().ok_or_else(des_cast_err)")] + pub vel: Vector3, + #[mt(map_ser = "|x| Ok(x.0 as i32)", map_des = "|x: i32| Ok(Deg(x as f32))")] + pub pitch: Deg, + #[mt(map_ser = "|x| Ok(x.0 as i32)", map_des = "|x: i32| Ok(Deg(x as f32))")] + pub yaw: Deg, pub keys: EnumSet, - pub fov_80: u8, + #[mt(multiplier = "80.0")] + #[mt(map_ser = "|x| Ok(x.0 as u8)", map_des = "|x: u8| Ok(Rad(x as f32))")] + pub fov: Rad, pub wanted_range: u8, } @@ -39,8 +59,13 @@ pub enum Interaction { #[mt(const_before = "0u8")] // version pub enum PointedThing { None = 0, - Node { under: [i16; 3], above: [i16; 3] }, - Obj { obj: u16 }, + Node { + under: Point3, + above: Point3, + }, + Obj { + obj: u16, + }, } #[mt_derive(to = "srv", repr = "u16", tag = "type", content = "data")] @@ -49,8 +74,7 @@ pub enum ToSrvPkt { Init { serialize_version: u8, #[mt(const_before = "1u16")] // supported compression - min_proto_version: u16, - max_proto_version: u16, + proto_version: RangeInclusive, player_name: String, #[mt(default)] send_full_item_meta: bool, @@ -71,7 +95,7 @@ pub enum ToSrvPkt { PlayerPos(PlayerPos) = 35, GotBlocks { #[mt(len = "u8")] - blocks: Vec<[i16; 3]>, + blocks: Vec>, } = 36, DeletedBlocks { #[mt(len = "u8")] -- cgit v1.2.3