]> git.localhorst.tv Git - blank.git/blob - src/ui/PlayerController.hpp
transmit player input from client to server
[blank.git] / src / ui / PlayerController.hpp
1 #ifndef BLANK_UI_PLAYERCONTROLLER_HPP_
2 #define BLANK_UI_PLAYERCONTROLLER_HPP_
3
4 #include <glm/glm.hpp>
5
6 #include "../world/EntityCollision.hpp"
7 #include "../world/WorldCollision.hpp"
8
9
10 namespace blank {
11
12 class Player;
13 class World;
14
15 class PlayerController {
16
17 public:
18         PlayerController(World &, Player &);
19
20         Player &GetPlayer() noexcept { return player; }
21         const Player &GetPlayer() const noexcept { return player; }
22
23         WorldCollision &BlockFocus() noexcept { return aim_world; }
24         const WorldCollision &BlockFocus() const noexcept { return aim_world; }
25         EntityCollision &EntityFocus() noexcept { return aim_entity; }
26         const EntityCollision &EntityFocus() const noexcept { return aim_entity; }
27
28         /// set desired direction of movement
29         /// the magnitude (clamped to [0..1]) can be used to attenuate target velocity
30         void SetMovement(const glm::vec3 &) noexcept;
31         const glm::vec3 &GetMovement() const noexcept { return move_dir; }
32         /// turn the controlled entity's head by given pitch and yaw deltas
33         void TurnHead(float pitch, float yaw) noexcept;
34
35         /// get player pitch in radians, normalized to [-PI/2,PI/2]
36         float GetPitch() const noexcept { return pitch; }
37         /// get player yaw in radians, normalized to [-PI,PI]
38         float GetYaw() const noexcept { return yaw; }
39
40         /// start doing primary action
41         /// what exactly this means depends on the active item
42         virtual void StartPrimaryAction() = 0;
43         /// stop doing primary action
44         virtual void StopPrimaryAction() = 0;
45         // etc
46         virtual void StartSecondaryAction() = 0;
47         virtual void StopSecondaryAction() = 0;
48         virtual void StartTertiaryAction() = 0;
49         virtual void StopTertiaryAction() = 0;
50
51         /// set the item at given inventory slot as active
52         void SelectInventory(int) noexcept;
53         int InventorySlot() const noexcept;
54
55 protected:
56         void Invalidate() noexcept;
57         void UpdatePlayer() noexcept;
58
59 private:
60         World &world;
61         Player &player;
62         glm::vec3 move_dir;
63         float pitch;
64         float yaw;
65         bool dirty;
66
67         WorldCollision aim_world;
68         EntityCollision aim_entity;
69
70 };
71
72 }
73
74 #endif