X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fworld%2Fworld.cpp;h=1b2e058f90d666dfd79d52474ad12ad0fe652686;hb=475f28f06c9e14912bab8119264e247ef466513d;hp=19f6f4af6603607c3eb709a832defcad0215a26c;hpb=838022c799cecd0e93826565e537a0667bded024;p=blobs.git diff --git a/src/world/world.cpp b/src/world/world.cpp index 19f6f4a..1b2e058 100644 --- a/src/world/world.cpp +++ b/src/world/world.cpp @@ -9,6 +9,7 @@ #include "TileType.hpp" #include "../app/Assets.hpp" +#include "../creature/Composition.hpp" #include "../creature/Creature.hpp" #include "../graphics/Viewport.hpp" #include "../math/const.hpp" @@ -138,11 +139,15 @@ glm::dmat4 Body::FromUniverse() const noexcept { return m; } +namespace { +std::vector ccache; +} + void Body::Tick(double dt) { rotation += dt * AngularMomentum() / Inertia(); Cache(); - for (creature::Creature *c : Creatures()) { - // TODO: this is self modifying, fix it fix it fix it + ccache = Creatures(); + for (creature::Creature *c : ccache) { c->Tick(dt); } for (auto c = Creatures().begin(); c != Creatures().end();) { @@ -343,34 +348,34 @@ void Planet::BuildVAO(const Set &ts) { for (int y = 0; y < sidelength; ++y) { for (int x = 0; x < sidelength; ++x, ++index) { float tex = ts[TileAt(surface, x, y).type].texture; - const float tex_u_begin = surface < 3 ? 1.0f : 0.0f; - const float tex_u_end = surface < 3 ? 0.0f : 1.0f; + const float tex_v_begin = surface < 3 ? 1.0f : 0.0f; + const float tex_v_end = surface < 3 ? 0.0f : 1.0f; attrib[4 * index + 0].position[(surface + 0) % 3] = x + 0 - offset; attrib[4 * index + 0].position[(surface + 1) % 3] = y + 0 - offset; attrib[4 * index + 0].position[(surface + 2) % 3] = surface < 3 ? offset : -offset; - attrib[4 * index + 0].tex_coord[0] = tex_u_begin; - attrib[4 * index + 0].tex_coord[1] = 1.0f; + attrib[4 * index + 0].tex_coord[0] = 0.0f; + attrib[4 * index + 0].tex_coord[1] = tex_v_begin; attrib[4 * index + 0].tex_coord[2] = tex; attrib[4 * index + 1].position[(surface + 0) % 3] = x + 0 - offset; attrib[4 * index + 1].position[(surface + 1) % 3] = y + 1 - offset; attrib[4 * index + 1].position[(surface + 2) % 3] = surface < 3 ? offset : -offset; - attrib[4 * index + 1].tex_coord[0] = tex_u_end; - attrib[4 * index + 1].tex_coord[1] = 1.0f; + attrib[4 * index + 1].tex_coord[0] = 0.0f; + attrib[4 * index + 1].tex_coord[1] = tex_v_end; attrib[4 * index + 1].tex_coord[2] = tex; attrib[4 * index + 2].position[(surface + 0) % 3] = x + 1 - offset; attrib[4 * index + 2].position[(surface + 1) % 3] = y + 0 - offset; attrib[4 * index + 2].position[(surface + 2) % 3] = surface < 3 ? offset : -offset; - attrib[4 * index + 2].tex_coord[0] = tex_u_begin; - attrib[4 * index + 2].tex_coord[1] = 0.0f; + attrib[4 * index + 2].tex_coord[0] = 1.0f; + attrib[4 * index + 2].tex_coord[1] = tex_v_begin; attrib[4 * index + 2].tex_coord[2] = tex; attrib[4 * index + 3].position[(surface + 0) % 3] = x + 1 - offset; attrib[4 * index + 3].position[(surface + 1) % 3] = y + 1 - offset; attrib[4 * index + 3].position[(surface + 2) % 3] = surface < 3 ? offset : -offset; - attrib[4 * index + 3].tex_coord[0] = tex_u_end; - attrib[4 * index + 3].tex_coord[1] = 0.0f; + attrib[4 * index + 3].tex_coord[0] = 1.0f; + attrib[4 * index + 3].tex_coord[1] = tex_v_end; attrib[4 * index + 3].tex_coord[2] = tex; } } @@ -570,5 +575,18 @@ std::vector::const_iterator TileType::FindResource(int r) const return yield; } +std::vector::const_iterator TileType::FindBestResource(const creature::Composition &comp) const { + auto best = resources.cend(); + double best_value = 0.0; + for (auto yield = resources.cbegin(); yield != resources.cend(); ++yield) { + double value = comp.Get(yield->resource); + if (value > best_value) { + best = yield; + best_value = value; + } + } + return best; +} + } }