]> git.localhorst.tv Git - blobs.git/commitdiff
simple name generator
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 27 Nov 2017 20:19:49 +0000 (21:19 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 27 Nov 2017 20:19:49 +0000 (21:19 +0100)
src/app/Assets.hpp
src/blobs.cpp
src/creature/NameGenerator.hpp [new file with mode: 0644]
src/creature/creature.cpp

index 5f971c689ddba201d7cbc700a6b1c1e79c975692..0512f7e5642c3f67c85a6a92b56d11ea233648df 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef BLOBS_APP_ASSETS_HPP_
 #define BLOBS_APP_ASSETS_HPP_
 
+#include "../creature/NameGenerator.hpp"
 #include "../graphics/AlphaSprite.hpp"
 #include "../graphics/ArrayTexture.hpp"
 #include "../graphics/Canvas.hpp"
@@ -32,6 +33,8 @@ struct Assets {
 
        math::GaloisLFSR random;
 
+       creature::NameGenerator name;
+
        struct {
                world::Set<world::Resource> resources;
                world::Set<world::TileType> tile_types;
index ee5e427293ddadc5d794c1c5135de7da3a813110..c1dfbbc250491500c7e2b785c4be2b4d100d3d3f 100644 (file)
@@ -97,7 +97,7 @@ int main(int argc, char *argv[]) {
        std::cout << "moon cycles per year: " << (planet.OrbitalPeriod() / moon.OrbitalPeriod()) << std::endl;
 
        auto blob = new creature::Creature(sim);
-       blob->Name("Blob");
+       blob->Name(assets.name.Sequential());
        Spawn(*blob, planet);
        blob->BuildVAO();
 
diff --git a/src/creature/NameGenerator.hpp b/src/creature/NameGenerator.hpp
new file mode 100644 (file)
index 0000000..a6da069
--- /dev/null
@@ -0,0 +1,27 @@
+#ifndef BLOBS_CREATURE_NAMEGENERATOR_HPP_
+#define BLOBS_CREATURE_NAMEGENERATOR_HPP_
+
+#include <string>
+
+
+namespace blobs {
+namespace creature {
+
+class NameGenerator {
+
+public:
+       NameGenerator();
+       ~NameGenerator();
+
+public:
+       std::string Sequential();
+
+private:
+       int counter;
+
+};
+
+}
+}
+
+#endif
index 4345bd9837b668bdd96a2cc612514c22a25ae686..f51f52ca4a16427cf75ab870577b8f5e71df45b6 100644 (file)
@@ -1,6 +1,7 @@
 #include "Creature.hpp"
 #include "Genome.hpp"
 #include "Memory.hpp"
+#include "NameGenerator.hpp"
 #include "Situation.hpp"
 #include "Steering.hpp"
 
@@ -16,6 +17,7 @@
 #include "../world/TileType.hpp"
 
 #include <algorithm>
+#include <sstream>
 #include <glm/gtx/transform.hpp>
 
 #include <iostream>
@@ -371,7 +373,7 @@ void Split(Creature &c) {
        Creature *a = new Creature(c.GetSimulation());
        const Situation &s = c.GetSituation();
        // TODO: generate names
-       a->Name("Blobby");
+       a->Name(c.GetSimulation().Assets().name.Sequential());
        // TODO: mutate
        c.GetGenome().Configure(*a);
        s.GetPlanet().AddCreature(a);
@@ -382,7 +384,7 @@ void Split(Creature &c) {
        a->BuildVAO();
 
        Creature *b = new Creature(c.GetSimulation());
-       b->Name("Sir Blobalot");
+       b->Name(c.GetSimulation().Assets().name.Sequential());
        c.GetGenome().Configure(*b);
        s.GetPlanet().AddCreature(b);
        b->GetSituation().SetPlanetSurface(
@@ -427,6 +429,20 @@ void Memory::TrackStay(const Location &l, double t) {
 }
 
 
+NameGenerator::NameGenerator()
+: counter(0) {
+}
+
+NameGenerator::~NameGenerator() {
+}
+
+std::string NameGenerator::Sequential() {
+       std::stringstream ss;
+       ss << "Blob " << ++counter;
+       return ss.str();
+}
+
+
 Situation::Situation()
 : planet(nullptr)
 , position(0.0)