X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fcreature%2FSituation.hpp;h=561f106c78b848ce3f4ca6c79a7b44c81c747e99;hb=75398ab9230c15215e7a378a26d2d55de67b47f0;hp=4dbb1c694d96b8ea5d534b353ec9c6e5f9a8e2a2;hpb=bcf776b6d51aeb9147bde32da8dd0768b10db993;p=blobs.git diff --git a/src/creature/Situation.hpp b/src/creature/Situation.hpp index 4dbb1c6..561f106 100644 --- a/src/creature/Situation.hpp +++ b/src/creature/Situation.hpp @@ -1,33 +1,80 @@ #ifndef BLOBS_CREATURE_SITUATION_HPP_ #define BLOBS_CREATURE_SITUATION_HPP_ -#include "../graphics/glm.hpp" +#include "../math/glm.hpp" namespace blobs { namespace world { class Planet; + class Tile; + class TileType; } namespace creature { class Situation { +public: + struct State { + // position + glm::dvec3 pos; + // velocity + glm::dvec3 vel; + // face direction, normalized + glm::dvec3 dir; + State( + const glm::dvec3 &pos = glm::dvec3(0.0), + const glm::dvec3 &vel = glm::dvec3(0.0), + const glm::dvec3 &dir = glm::dvec3(0.0, 0.0, -1.0)) + : pos(pos), vel(vel), dir(dir) { } + }; + struct Derivative { + // velocity + glm::dvec3 vel; + // acceleration + glm::dvec3 acc; + Derivative( + const glm::dvec3 &vel = glm::dvec3(0.0), + const glm::dvec3 &acc = glm::dvec3(0.0)) + : vel(vel), acc(acc) { } + }; + public: Situation(); ~Situation(); + Situation(const Situation &) = delete; + Situation &operator =(const Situation &) = delete; + + Situation(Situation &&) = delete; + Situation &operator =(Situation &&) = delete; + public: bool OnPlanet() const noexcept; world::Planet &GetPlanet() const noexcept { return *planet; } - int Surface() const noexcept { return surface; } - const glm::dvec3 &Position() const noexcept { return position; } + bool OnSurface() const noexcept; + const glm::dvec3 &Position() const noexcept { return state.pos; } + world::Tile &GetTile() const noexcept; + const world::TileType &GetTileType() const noexcept; + + void SetState(const State &s) noexcept { state = s; } + const State &GetState() const noexcept { return state; } + + const glm::dvec3 &Velocity() const noexcept { return state.vel; } + bool Moving() const noexcept { return glm::length2(state.vel) > 0.000001; } + void Move(const glm::dvec3 &dp) noexcept; + void Accelerate(const glm::dvec3 &dv) noexcept; + void EnforceConstraints(State &) noexcept; + void CheckWrap() noexcept; + + void Heading(const glm::dvec3 &h) noexcept { state.dir = h; } + const glm::dvec3 &Heading() const noexcept { return state.dir; } - void SetPlanetSurface(world::Planet &, int srf, const glm::dvec3 &pos) noexcept; + void SetPlanetSurface(world::Planet &, const glm::dvec3 &pos) noexcept; public: world::Planet *planet; - glm::dvec3 position; - int surface; + State state; enum { LOST, PLANET_SURFACE,