assets.shaders.creature_skin.SetTexture(assets.textures.skins);
// TODO: extend to nearby bodies as well
for (auto c : cam.Reference().Creatures()) {
- assets.shaders.creature_skin.SetM(cam.Model(c->GetBody()) * glm::mat4(c->LocalTransform()));
+ assets.shaders.creature_skin.SetM(cam.Model(cam.Reference()) * glm::mat4(c->LocalTransform()));
c->Draw(assets, viewport);
}
#define BLOBS_CREATURE_CREATURE_HPP_
#include "Need.hpp"
+#include "Situation.hpp"
#include "../graphics/glm.hpp"
#include "../graphics/SimpleVAO.hpp"
Creature &operator =(Creature &&) = delete;
public:
- void SetBody(world::Body &b) noexcept { body = &b; }
- world::Body &GetBody() noexcept { return *body; }
- const world::Body &GetBody() const noexcept { return *body; }
-
- void Surface(int s) noexcept { surface = s; }
- void Position(const glm::dvec3 &p) noexcept { position = p; }
-
void Name(const std::string &n) noexcept { name = n; }
const std::string &Name() const noexcept { return name; }
void Tick(double dt);
+ Situation &GetSituation() noexcept { return situation; }
+ const Situation &GetSituation() const noexcept { return situation; }
+
glm::dmat4 LocalTransform() noexcept;
void BuildVAO();
void Draw(app::Assets &, graphics::Viewport &);
private:
- world::Body *body;
- int surface;
- glm::dvec3 position;
-
std::string name;
double health;
std::vector<Need> needs;
+ Situation situation;
+
struct Attributes {
glm::vec3 position;
glm::vec3 normal;
--- /dev/null
+#ifndef BLOBS_CREATURE_SITUATION_HPP_
+#define BLOBS_CREATURE_SITUATION_HPP_
+
+#include "../graphics/glm.hpp"
+
+
+namespace blobs {
+namespace world {
+ class Planet;
+}
+namespace creature {
+
+class Situation {
+
+public:
+ Situation();
+ ~Situation();
+
+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; }
+
+ void SetPlanetSurface(world::Planet &, int srf, const glm::dvec3 &pos) noexcept;
+
+public:
+ world::Planet *planet;
+ glm::dvec3 position;
+ int surface;
+ enum {
+ LOST,
+ PLANET_SURFACE,
+ } type;
+
+};
+
+}
+}
+
+#endif
#include "Creature.hpp"
#include "Need.hpp"
+#include "Situation.hpp"
#include "../app/Assets.hpp"
#include "../world/Body.hpp"
namespace creature {
Creature::Creature()
-: body(nullptr)
-, surface(0)
-, position()
-, name()
+: name()
, health(1.0)
, needs()
+, situation()
, vao() {
}
glm::dmat4 Creature::LocalTransform() noexcept {
// TODO: surface transform
constexpr double half_height = 0.25;
- return glm::translate(glm::dvec3(position.x, position.y, position.z + body->Radius() + half_height))
+ const glm::dvec3 &pos = situation.Position();
+ return glm::translate(glm::dvec3(pos.x, pos.y, pos.z + situation.GetPlanet().Radius() + half_height))
* glm::scale(glm::dvec3(half_height, half_height, half_height));
}
void Spawn(Creature &c, world::Planet &p, app::Assets &assets) {
p.AddCreature(&c);
- c.Surface(0);
- c.Position(glm::dvec3(0.0, 0.0, 0.0));
+ c.GetSituation().SetPlanetSurface(p, 0, glm::dvec3(0.0, 0.0, 0.0));
// probe surrounding area for common resources
int start = p.SideLength() / 2 - 2;
value = std::min(1.0, value + gain * dt);
}
+
+Situation::Situation()
+: planet(nullptr)
+, position(0.0)
+, surface(0)
+, type(LOST) {
+}
+
+Situation::~Situation() {
+}
+
+bool Situation::OnPlanet() const noexcept {
+ return type == PLANET_SURFACE;
+}
+
+void Situation::SetPlanetSurface(world::Planet &p, int srf, const glm::dvec3 &pos) noexcept {
+ type = PLANET_SURFACE;
+ planet = &p;
+ surface = srf;
+ position = pos;
+}
+
}
}
}
void Body::AddCreature(creature::Creature *c) {
- c->SetBody(*this);
creatures.push_back(c);
}