]> git.localhorst.tv Git - blank.git/commitdiff
try to cleanly destruct world
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 13 Nov 2015 11:58:36 +0000 (12:58 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 13 Nov 2015 11:58:36 +0000 (12:58 +0100)
this might still cause problems if there's circular references

src/world/world.cpp

index b07d05ade64d3788ca8ea953a07ad1f8398ba42b..738fa4ad9b06bb7256f66886bfeca86bd5e3bd2c 100644 (file)
@@ -340,7 +340,20 @@ World::World(const BlockTypeRegistry &types, const Config &config)
 }
 
 World::~World() {
-
+       for (Entity &e : entities) {
+               e.Kill();
+       }
+       std::size_t removed = 0;
+       do {
+               removed = 0;
+               for (auto e = entities.begin(), end = entities.end(); e != end; ++e) {
+                       if (e->CanRemove()) {
+                               e = RemoveEntity(e);
+                               end = entities.end();
+                               ++removed;
+                       }
+               }
+       } while (removed > 0 && !entities.empty());
 }