]> git.localhorst.tv Git - blobs.git/blobdiff - src/world/world.cpp
basic creature model
[blobs.git] / src / world / world.cpp
index a939b3e586e129e748984e0c55ef9386701ea95d..fb57c7c09bde150172b0304ceabd580624728e90 100644 (file)
@@ -7,6 +7,7 @@
 #include "TileSet.hpp"
 #include "TileType.hpp"
 
+#include "Creature.hpp"
 #include "../const.hpp"
 #include "../app/Assets.hpp"
 #include "../graphics/Viewport.hpp"
@@ -47,10 +48,14 @@ Body::Body()
 , orbital(1.0)
 , inverse_orbital(1.0)
 , local(1.0)
-, inverse_local(1.0) {
+, inverse_local(1.0)
+, creatures() {
 }
 
 Body::~Body() {
+       for (Creature *c : creatures) {
+               delete c;
+       }
 }
 
 void Body::SetSimulation(Simulation &s) noexcept {
@@ -151,6 +156,11 @@ void Body::Cache() noexcept {
                * glm::eulerAngleY(-rotation);
 }
 
+void Body::AddCreature(Creature *c) {
+       c->SetBody(*this);
+       creatures.push_back(c);
+}
+
 
 Orbit::Orbit()
 : sma(1.0)
@@ -256,7 +266,7 @@ glm::dmat4 Orbit::InverseMatrix(double t) const noexcept {
 Planet::Planet(int sidelength)
 : Body()
 , sidelength(sidelength)
-, tiles(new Tile[TilesTotal()])
+, tiles(TilesTotal())
 , vao() {
        Radius(double(sidelength) / 2.0);
 }
@@ -272,7 +282,7 @@ glm::dvec3 Planet::TileCenter(int surface, int x, int y) const noexcept {
        return center;
 }
 
-void Planet::BuildVAOs(const TileSet &ts) {
+void Planet::BuildVAO(const TileSet &ts) {
        vao.Bind();
        vao.BindAttributes();
        vao.EnableAttribute(0);
@@ -421,7 +431,7 @@ void GenerateEarthlike(const TileSet &tiles, Planet &p) noexcept {
                        }
                }
        }
-       p.BuildVAOs(tiles);
+       p.BuildVAO(tiles);
 }
 
 void GenerateTest(const TileSet &tiles, Planet &p) noexcept {
@@ -436,7 +446,7 @@ void GenerateTest(const TileSet &tiles, Planet &p) noexcept {
                        }
                }
        }
-       p.BuildVAOs(tiles);
+       p.BuildVAO(tiles);
 }