mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-06 17:41:04 +00:00
Restore pass-through of direction keys (#11924)
This moves relevant code into the PlayerControl class and gets rid of separate keyPressed variable.
This commit is contained in:
parent
76dbd0d2d0
commit
5eb45e1ea0
11 changed files with 165 additions and 98 deletions
33
src/player.h
33
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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue