]> git.localhorst.tv Git - blobs.git/commitdiff
standardized logging
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 4 Dec 2017 11:26:15 +0000 (12:26 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 4 Dec 2017 11:36:25 +0000 (12:36 +0100)
src/blobs.cpp
src/creature/creature.cpp
src/creature/goal.cpp
src/world/Body.hpp
src/world/Simulation.hpp
src/world/sim.cpp

index d6a6fede8469f0b81518b291316d6def3356a9bc..01bfb2a8ed7c1fd8c8aa99207c752a2966b49f45 100644 (file)
@@ -24,7 +24,7 @@ struct SwitchPanel {
 
        void operator ()(creature::Creature &c) {
                if (planet.Creatures().empty()) {
-                       std::cout << "no more creatures, game over" << std::endl;
+                       planet.GetSimulation().Log() << "no more creatures, game over" << std::endl;
                        state.GetCreaturePanel().Hide();
                        while (app.HasState()) {
                                app.PopState();
index 1a88dba1ab7d76831972bdaa3b0fab4d3e7b0973..376ad3ffe86438272c52ac221eb9efdaa0426863 100644 (file)
@@ -209,21 +209,21 @@ void Creature::DoWork(double amount) noexcept {
 void Creature::Hurt(double amount) noexcept {
        stats.Damage().Add(amount);
        if (stats.Damage().Full()) {
-               std::cout << "[" << ui::TimeString(sim.Time()) << "] " << name << " ";
+               std::ostream &log = sim.Log() << name << " ";
                if (stats.Exhaustion().Full()) {
-                       std::cout << "died of exhaustion";
+                       log << "died of exhaustion";
                } else if (stats.Breath().Full()) {
-                       std::cout << "suffocated";
+                       log << "suffocated";
                } else if (stats.Thirst().Full()) {
-                       std::cout << "died of thirst";
+                       log << "died of thirst";
                } else if (stats.Hunger().Full()) {
-                       std::cout << "starved to death";
+                       log << "starved to death";
                } else {
-                       std::cout << "succumed to wounds";
+                       log << "succumed to wounds";
                }
-               std::cout << " at an age of " << ui::TimeString(Age())
+               log << " at an age of " << ui::TimeString(Age())
                        << " (" << ui::PercentageString(Age() / properties.Lifetime())
-                       << "% of life expectancy of " << ui::TimeString(properties.Lifetime())
+                       << " of life expectancy of " << ui::TimeString(properties.Lifetime())
                        << ")" << std::endl;
                Die();
        }
@@ -697,8 +697,7 @@ void Split(Creature &c) {
                s.GetPlanet(), s.Surface(),
                s.Position() + glm::dvec3(0.0, 0.55 * a->Size(), 0.0));
        a->BuildVAO();
-       std::cout << "[" << ui::TimeString(c.GetSimulation().Time()) << "] "
-               << a->Name() << " was born" << std::endl;
+       c.GetSimulation().Log() << a->Name() << " was born" << std::endl;
 
        Creature *b = new Creature(c.GetSimulation());
        b->AddParent(c);
@@ -712,8 +711,7 @@ void Split(Creature &c) {
                s.GetPlanet(), s.Surface(),
                s.Position() - glm::dvec3(0.0, 0.55 * b->Size(), 0.0));
        b->BuildVAO();
-       std::cout << "[" << ui::TimeString(c.GetSimulation().Time()) << "] "
-               << b->Name() << " was born" << std::endl;
+       c.GetSimulation().Log() << b->Name() << " was born" << std::endl;
 
        c.Die();
 }
index a4f33304f3f75af56b86c376b0c653879405006e..f20ecc5b2b3d2cd99c96ad2a6685286a1b27691c 100644 (file)
@@ -100,8 +100,7 @@ void BlobBackgroundTask::CheckStats() {
 void BlobBackgroundTask::CheckSplit() {
        if (GetCreature().Mass() > GetCreature().OffspringMass() * 2.0
                && GetCreature().OffspringChance() > Assets().random.UNorm()) {
-               std::cout << "[" << ui::TimeString(GetCreature().GetSimulation().Time())
-                       << "] " << GetCreature().Name() << " split" << std::endl;
+               GetCreature().GetSimulation().Log() << GetCreature().Name() << " split" << std::endl;
                Split(GetCreature());
                return;
        }
index 5ac4fa1ddcfab52bf305b07825a03becff283612..165d8483f5cbc6d890b7280ec91d6ed85401e6b1 100644 (file)
@@ -35,6 +35,7 @@ public:
 
 public:
        bool HasSimulation() const noexcept { return sim; }
+       Simulation &GetSimulation() noexcept { return *sim; }
        const Simulation &GetSimulation() const noexcept { return *sim; }
        void SetSimulation(Simulation &) noexcept;
 
index 5df595fb26d0eab0c3d0b799a93f333b4bcf6270..19023406ace73a2466886fb2c71c960cea208bb7 100644 (file)
@@ -5,6 +5,7 @@
 #include "Set.hpp"
 #include "../app/Assets.hpp"
 
+#include <iosfwd>
 #include <set>
 #include <vector>
 
@@ -65,6 +66,8 @@ public:
        const std::vector<Record> &Records() const noexcept { return records; }
        void CheckRecords(creature::Creature &) noexcept;
 
+       std::ostream &Log();
+
 private:
        Body &root;
        app::Assets &assets;
index edf7bfe4f02f88954c2fd140161e07bff785d7fa..1d9706e80bc3af77717bb44dcd99837f1c8331bf 100644 (file)
@@ -4,8 +4,10 @@
 #include "Planet.hpp"
 #include "Sun.hpp"
 #include "../creature/Creature.hpp"
+#include "../ui/string.hpp"
 
 #include <algorithm>
+#include <iostream>
 
 
 namespace blobs {
@@ -83,41 +85,66 @@ void Simulation::SetDead(creature::Creature *c) {
 
 void Simulation::CheckRecords(creature::Creature &c) noexcept {
        if (c.Age() > records[0].value) {
+               if (records[0].holder && records[0].holder != &c) {
+                       Log() << "new age record by " << c.Name() << std::endl;
+               }
                records[0].value = c.Age();
                records[0].time = Time();
                records[0].holder = &c;
        }
        if (c.Mass() > records[1].value) {
+               if (records[1].holder && records[1].holder != &c) {
+                       Log() << "new mass record by " << c.Name() << std::endl;
+               }
                records[1].value = c.Mass();
                records[1].time = Time();
                records[1].holder = &c;
        }
        if (c.Size() > records[2].value) {
+               if (records[2].holder && records[2].holder != &c) {
+                       Log() << "new size record by " << c.Name() << std::endl;
+               }
                records[2].value = c.Size();
                records[2].time = Time();
                records[2].holder = &c;
        }
        if (c.Strength() > records[3].value) {
+               if (records[3].holder && records[3].holder != &c) {
+                       Log() << "new strength record by " << c.Name() << std::endl;
+               }
                records[3].value = c.Strength();
                records[3].time = Time();
                records[3].holder = &c;
        }
        if (c.Stamina() > records[4].value) {
+               if (records[4].holder && records[4].holder != &c) {
+                       Log() << "new stamina record by " << c.Name() << std::endl;
+               }
                records[4].value = c.Stamina();
                records[4].time = Time();
                records[4].holder = &c;
        }
        if (c.Dexerty() > records[5].value) {
+               if (records[5].holder && records[5].holder != &c) {
+                       Log() << "new dexerty record by " << c.Name() << std::endl;
+               }
                records[5].value = c.Dexerty();
                records[5].time = Time();
                records[5].holder = &c;
        }
        if (c.Intelligence() > records[6].value) {
+               if (records[6].holder && records[6].holder != &c) {
+                       Log() << "new intelligence record by " << c.Name() << std::endl;
+               }
                records[6].value = c.Intelligence();
                records[6].time = Time();
                records[6].holder = &c;
        }
 }
 
+std::ostream &Simulation::Log() {
+       return std::cout << '[' << ui::TimeString(Time()) << "] ";
+}
+
 }
 }