summaryrefslogtreecommitdiff
path: root/src/player.h
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2022-01-09 18:46:36 +0100
committerGitHub <noreply@github.com>2022-01-09 18:46:36 +0100
commit5eb45e1ea03c6104f007efec6dd9c351f310193d (patch)
tree28a40addf99493aedfbf67e4d85fa6cf88723419 /src/player.h
parent76dbd0d2d04712dcad4f7c6afecb97fa8d662d6d (diff)
downloadminetest-5eb45e1ea03c6104f007efec6dd9c351f310193d.tar.gz
minetest-5eb45e1ea03c6104f007efec6dd9c351f310193d.tar.bz2
minetest-5eb45e1ea03c6104f007efec6dd9c351f310193d.zip
Restore pass-through of direction keys (#11924)
This moves relevant code into the PlayerControl class and gets rid of separate keyPressed variable.
Diffstat (limited to 'src/player.h')
-rw-r--r--src/player.h33
1 files changed, 21 insertions, 12 deletions
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);