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