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