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