summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
Diffstat (limited to 'server/src')
-rw-r--r--server/src/entity/customers/mod.rs16
-rw-r--r--server/src/game.rs28
-rw-r--r--server/src/state.rs2
3 files changed, 24 insertions, 22 deletions
diff --git a/server/src/entity/customers/mod.rs b/server/src/entity/customers/mod.rs
index 0bb3f918..97b94942 100644
--- a/server/src/entity/customers/mod.rs
+++ b/server/src/entity/customers/mod.rs
@@ -102,7 +102,9 @@ impl EntityT for Customers {
match state {
CustomerState::Entering { path, chair } => {
- playerdata.direction = path.next_direction(playerdata.position());
+ playerdata
+ .movement
+ .input(path.next_direction(playerdata.position()), false);
if path.is_done() {
let demand = DemandIndex(random::<usize>() % self.demands.len());
self.cpackets.push_back(PacketS::Communicate {
@@ -123,7 +125,9 @@ impl EntityT for Customers {
demand,
timeout,
} => {
- playerdata.direction = (chair.as_vec2() + 0.5) - playerdata.position();
+ playerdata
+ .movement
+ .input((chair.as_vec2() + 0.5) - playerdata.position(), false);
*timeout -= dt;
if *timeout <= 0. {
self.cpackets.push_back(PacketS::Communicate {
@@ -203,7 +207,9 @@ impl EntityT for Customers {
progress,
chair,
} => {
- playerdata.direction = (chair.as_vec2() + 0.5) - playerdata.position();
+ playerdata
+ .movement
+ .input((chair.as_vec2() + 0.5) - playerdata.position(), false);
let demand = &self.demands[demand.0];
*progress += dt / demand.duration;
if *progress >= 1. {
@@ -234,7 +240,9 @@ impl EntityT for Customers {
}
}
CustomerState::Exiting { path } => {
- playerdata.direction = path.next_direction(playerdata.position());
+ playerdata
+ .movement
+ .input(path.next_direction(playerdata.position()), false);
if path.is_done() {
info!("{player:?} -> leave");
self.cpackets.push_back(PacketS::Leave { player });
diff --git a/server/src/game.rs b/server/src/game.rs
index c010c8b8..5af9658e 100644
--- a/server/src/game.rs
+++ b/server/src/game.rs
@@ -61,8 +61,6 @@ pub struct Player {
pub communicate_persist: Option<Message>,
pub movement: MovementBase,
- pub direction: Vec2,
- pub boost: bool,
pub last_position_update: Instant,
}
@@ -178,7 +176,8 @@ impl Game {
} else {
self.data.chef_spawn
},
- direction: Vec2::ZERO,
+ input_direction: Vec2::ZERO,
+ input_boost: false,
facing: Vec2::X,
rotation: 0.,
velocity: Vec2::ZERO,
@@ -186,8 +185,6 @@ impl Game {
stamina: 0.,
},
last_position_update: Instant::now(),
- boost: false,
- direction: Vec2::ZERO,
communicate_persist: None,
interacting: None,
name: name.clone(),
@@ -298,7 +295,8 @@ impl Game {
} else {
self.data.chef_spawn
},
- direction: Vec2::ZERO,
+ input_direction: Vec2::ZERO,
+ input_boost: false,
facing: Vec2::X,
rotation: 0.,
velocity: Vec2::ZERO,
@@ -306,8 +304,6 @@ impl Game {
stamina: 0.,
},
last_position_update: Instant::now(),
- boost: false,
- direction: Vec2::ZERO,
communicate_persist: None,
interacting: None,
name: name.clone(),
@@ -358,8 +354,8 @@ impl Game {
}
PacketS::Movement {
pos,
- boosting,
- direction,
+ boost,
+ dir: direction,
player,
} => {
let pd = self
@@ -367,8 +363,7 @@ impl Game {
.get_mut(&player)
.ok_or(anyhow!("player does not exist"))?;
- pd.direction = direction;
- pd.boost = boosting;
+ pd.movement.input(direction, boost);
if let Some(pos) = pos {
let dt = pd.last_position_update.elapsed();
@@ -541,9 +536,7 @@ impl Game {
}
for (&pid, player) in &mut self.players {
- player
- .movement
- .update(&self.walkable, player.direction, player.boost, dt);
+ player.movement.update(&self.walkable, dt);
self.players_spatial_index
.update_entry(pid, player.movement.position);
@@ -558,10 +551,11 @@ impl Game {
});
for (&pid, player) in &mut self.players {
- packet_out.push_back(PacketC::Position {
+ packet_out.push_back(PacketC::Movement {
player: pid,
pos: player.movement.position,
- boosting: player.movement.boosting,
+ dir: player.movement.input_direction,
+ boost: player.movement.boosting,
rot: player.movement.rotation,
});
diff --git a/server/src/state.rs b/server/src/state.rs
index 43ca29bd..526f70aa 100644
--- a/server/src/state.rs
+++ b/server/src/state.rs
@@ -106,7 +106,7 @@ impl State {
);
}
while let Some(p) = self.packet_out.pop_front() {
- if matches!(p, PacketC::UpdateMap { .. } | PacketC::Position { .. }) {
+ if matches!(p, PacketC::UpdateMap { .. } | PacketC::Movement { .. }) {
trace!("-> {p:?}");
} else {
debug!("-> {p:?}");