From 5eb45e1ea03c6104f007efec6dd9c351f310193d Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 9 Jan 2022 18:46:36 +0100 Subject: Restore pass-through of direction keys (#11924) This moves relevant code into the PlayerControl class and gets rid of separate keyPressed variable. --- src/player.h | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'src/player.h') diff --git a/src/player.h b/src/player.h index 3800e1a33..d769acdad 100644 --- a/src/player.h +++ b/src/player.h @@ -49,18 +49,18 @@ struct PlayerControl PlayerControl() = default; PlayerControl( - bool a_jump, - bool a_aux1, - bool a_sneak, + bool a_up, bool a_down, bool a_left, bool a_right, + bool a_jump, bool a_aux1, bool a_sneak, bool a_zoom, - bool a_dig, - bool a_place, - float a_pitch, - float a_yaw, - float a_movement_speed, - float a_movement_direction + bool a_dig, bool a_place, + float a_pitch, float a_yaw, + float a_movement_speed, float a_movement_direction ) { + // Encode direction keys into a single value so nobody uses it accidentally + // as movement_{speed,direction} is supposed to be the source of truth. + direction_keys = (a_up&1) | ((a_down&1) << 1) | + ((a_left&1) << 2) | ((a_right&1) << 3); jump = a_jump; aux1 = a_aux1; sneak = a_sneak; @@ -72,15 +72,26 @@ struct PlayerControl movement_speed = a_movement_speed; movement_direction = a_movement_direction; } + +#ifndef SERVER + // For client use + u32 getKeysPressed() const; + inline bool isMoving() const { return movement_speed > 0.001f; } +#endif + + // For server use + void unpackKeysPressed(u32 keypress_bits); + + u8 direction_keys = 0; bool jump = false; bool aux1 = false; bool sneak = false; bool zoom = false; bool dig = false; bool place = false; + // Note: These four are NOT available on the server float pitch = 0.0f; float yaw = 0.0f; - // Note: These two are NOT available on the server float movement_speed = 0.0f; float movement_direction = 0.0f; }; @@ -189,8 +200,6 @@ public: return m_fov_override_spec; } - u32 keyPressed = 0; - HudElement* getHud(u32 id); u32 addHud(HudElement* hud); HudElement* removeHud(u32 id); -- cgit v1.2.3