summaryrefslogtreecommitdiff
path: root/server/protocol
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-08-11 01:30:59 +0200
committermetamuffin <metamuffin@disroot.org>2024-08-11 01:35:05 +0200
commit218da36b4f963a5dfcd619d543cb95c5c196d214 (patch)
tree244ecd10f4ca3d9798cedf7149394a1d4827b5d9 /server/protocol
parentf753629acd906ff7acd42a18a266cc93a883330c (diff)
downloadhurrycurry-218da36b4f963a5dfcd619d543cb95c5c196d214.tar
hurrycurry-218da36b4f963a5dfcd619d543cb95c5c196d214.tar.bz2
hurrycurry-218da36b4f963a5dfcd619d543cb95c5c196d214.tar.zst
update movement in protocol and all clients
Diffstat (limited to 'server/protocol')
-rw-r--r--server/protocol/src/lib.rs12
-rw-r--r--server/protocol/src/movement.rs19
2 files changed, 20 insertions, 11 deletions
diff --git a/server/protocol/src/lib.rs b/server/protocol/src/lib.rs
index 1a4e41a9..8f8e9784 100644
--- a/server/protocol/src/lib.rs
+++ b/server/protocol/src/lib.rs
@@ -30,7 +30,7 @@ pub use glam;
pub mod movement;
-pub const VERSION: (u32, u32) = (3, 0);
+pub const VERSION: (u32, u32) = (4, 0);
pub const BINCODE_CONFIG: Configuration<LittleEndian, Varint, Limit<4096>> =
standard().with_limit();
@@ -94,8 +94,8 @@ pub enum PacketS {
Movement {
player: PlayerID,
#[bincode(with_serde)]
- direction: Vec2,
- boosting: bool,
+ dir: Vec2,
+ boost: bool,
#[bincode(with_serde)]
pos: Option<Vec2>,
},
@@ -155,12 +155,14 @@ pub enum PacketC {
RemovePlayer {
id: PlayerID,
},
- Position {
+ Movement {
player: PlayerID,
#[bincode(with_serde)]
pos: Vec2,
rot: f32,
- boosting: bool,
+ #[bincode(with_serde)]
+ dir: Vec2,
+ boost: bool,
},
MoveItem {
from: ItemLocation,
diff --git a/server/protocol/src/movement.rs b/server/protocol/src/movement.rs
index dad9d300..ebcc627d 100644
--- a/server/protocol/src/movement.rs
+++ b/server/protocol/src/movement.rs
@@ -29,7 +29,8 @@ const BOOST_DURATION: f32 = 0.3;
const BOOST_RESTORE: f32 = 0.5;
pub struct MovementBase {
- pub direction: Vec2,
+ pub input_direction: Vec2,
+ pub input_boost: bool,
pub position: Vec2,
pub facing: Vec2,
pub rotation: f32,
@@ -41,8 +42,9 @@ pub struct MovementBase {
impl MovementBase {
pub fn new(position: Vec2) -> Self {
Self {
+ input_direction: Vec2::ZERO,
+ input_boost: false,
position,
- direction: Vec2::ZERO,
facing: Vec2::X,
velocity: Vec2::ZERO,
boosting: false,
@@ -50,8 +52,13 @@ impl MovementBase {
rotation: 0.,
}
}
- pub fn update(&mut self, map: &HashSet<IVec2>, direction: Vec2, mut boost: bool, dt: f32) {
- self.direction = direction.clamp_length_max(1.);
+ pub fn input(&mut self, direction: Vec2, boost: bool) {
+ self.input_boost = boost;
+ self.input_direction = direction;
+ }
+ pub fn update(&mut self, map: &HashSet<IVec2>, dt: f32) {
+ let mut boost = self.input_boost;
+ let direction = self.input_direction.clamp_length_max(1.);
if direction.length() > 0.1 {
self.facing = direction + (self.facing - direction) * (-dt * 10.).exp();
}
@@ -74,8 +81,8 @@ impl MovementBase {
pub fn movement_packet(&self, player: PlayerID) -> PacketS {
PacketS::Movement {
pos: Some(self.position),
- boosting: self.boosting,
- direction: self.direction,
+ boost: self.input_boost,
+ dir: self.input_direction,
player,
}
}