]> git.localhorst.tv Git - blank.git/blobdiff - src/ui/PlayerController.hpp
make test runs depend on assets
[blank.git] / src / ui / PlayerController.hpp
index 8d9e5a37247c3ca0622b70dd11cdb5cc0218a4ad..69a15e9846ef7e7b42bd72f9b281682184eb015a 100644 (file)
@@ -1,18 +1,46 @@
 #ifndef BLANK_UI_PLAYERCONTROLLER_HPP_
 #define BLANK_UI_PLAYERCONTROLLER_HPP_
 
-#include <glm/glm.hpp>
+#include "../graphics/glm.hpp"
+#include "../world/EntityCollision.hpp"
+#include "../world/EntityController.hpp"
+#include "../world/WorldCollision.hpp"
 
 
 namespace blank {
 
-struct PlayerController {
+class Player;
+class World;
+
+class PlayerController
+: public EntityController {
+
+public:
+       PlayerController(World &, Player &);
+       ~PlayerController();
+
+       World &GetWorld() noexcept { return world; }
+       const World &GetWorld() const noexcept { return world; }
+       Player &GetPlayer() noexcept { return player; }
+       const Player &GetPlayer() const noexcept { return player; }
+
+       WorldCollision &BlockFocus() noexcept { return aim_world; }
+       const WorldCollision &BlockFocus() const noexcept { return aim_world; }
+       EntityCollision &EntityFocus() noexcept { return aim_entity; }
+       const EntityCollision &EntityFocus() const noexcept { return aim_entity; }
 
        /// set desired direction of movement
        /// the magnitude (clamped to [0..1]) can be used to attenuate target velocity
-       virtual void SetMovement(const glm::vec3 &) = 0;
+       void SetMovement(const glm::vec3 &) noexcept;
+       const glm::vec3 &GetMovement() const noexcept { return move_dir; }
+
        /// turn the controlled entity's head by given pitch and yaw deltas
-       virtual void TurnHead(float pitch, float yaw) = 0;
+       void TurnHead(float pitch, float yaw) noexcept;
+
+       /// get player pitch in radians, normalized to [-PI/2,PI/2]
+       float GetPitch() const noexcept;
+       /// get player yaw in radians, normalized to [-PI,PI]
+       float GetYaw() const noexcept;
 
        /// start doing primary action
        /// what exactly this means depends on the active item
@@ -26,7 +54,21 @@ struct PlayerController {
        virtual void StopTertiaryAction() = 0;
 
        /// set the item at given inventory slot as active
-       virtual void SelectInventory(int) = 0;
+       void SelectInventory(int) noexcept;
+       int InventorySlot() const noexcept;
+
+protected:
+       void Invalidate() noexcept;
+       void UpdatePlayer() noexcept;
+
+private:
+       World &world;
+       Player &player;
+       glm::vec3 move_dir;
+       bool dirty;
+
+       WorldCollision aim_world;
+       EntityCollision aim_entity;
 
 };