]> git.localhorst.tv Git - blobs.git/blobdiff - src/creature/creature.cpp
fix double deletes on app exit
[blobs.git] / src / creature / creature.cpp
index de82f86ad9a7db52924106735450f49ee8033a8c..3c03e576770d71ac2a5310c09c3176e9ffe6866c 100644 (file)
@@ -92,7 +92,7 @@ Creature::Creature(world::Simulation &sim)
 , mass(1.0)
 , size(1.0)
 , birth(sim.Time())
-, death(0.0)
+, death(-1.0)
 , on_death()
 , removable(false)
 , parents()
@@ -230,6 +230,8 @@ void Creature::Hurt(double amount) noexcept {
 }
 
 void Creature::Die() noexcept {
+       if (Dead()) return;
+
        sim.SetDead(this);
        death = sim.Time();
        steering.Halt();
@@ -239,6 +241,10 @@ void Creature::Die() noexcept {
        Remove();
 }
 
+bool Creature::Dead() const noexcept {
+       return death > birth;
+}
+
 void Creature::Remove() noexcept {
        removable = true;
 }