]> git.localhorst.tv Git - blobs.git/blobdiff - src/world/world.cpp
fix creature iteration
[blobs.git] / src / world / world.cpp
index 4f98d9a63bdef3b241123e8cf2bbdf30b76ce3de..eee12833b39ca80d467d0f8fc19868284f796419 100644 (file)
@@ -138,12 +138,25 @@ glm::dmat4 Body::FromUniverse() const noexcept {
        return m;
 }
 
+namespace {
+std::vector<creature::Creature *> ccache;
+}
+
 void Body::Tick(double dt) {
        rotation += dt * AngularMomentum() / Inertia();
        Cache();
-       for (creature::Creature *c : Creatures()) {
+       ccache = Creatures();
+       for (creature::Creature *c : ccache) {
                c->Tick(dt);
        }
+       for (auto c = Creatures().begin(); c != Creatures().end();) {
+               if ((*c)->Removable()) {
+                       delete *c;
+                       c = Creatures().erase(c);
+               } else {
+                       ++c;
+               }
+       }
 }
 
 void Body::Cache() noexcept {