]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/player.h
Merge branch 'master' of https://github.com/minetest/minetest
[dragonfireclient.git] / src / player.h
index 8f7b0a3fecac53732f5ae9f80a459481f1fa72b1..0216cfe9cbbc89e8c012176bbe7b05b0ce2fd8fa 100644 (file)
@@ -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;
 };
@@ -190,8 +201,6 @@ class Player
                return m_fov_override_spec;
        }
 
-       u32 keyPressed = 0;
-
        HudElement* getHud(u32 id);
        u32         addHud(HudElement* hud);
        HudElement* removeHud(u32 id);