From: Daniel Karbach Date: Mon, 27 Nov 2017 20:19:49 +0000 (+0100) Subject: simple name generator X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=c475ecb15fb2222977cf64ca7bdbea0f303a4192;p=blobs.git simple name generator --- diff --git a/src/app/Assets.hpp b/src/app/Assets.hpp index 5f971c6..0512f7e 100644 --- a/src/app/Assets.hpp +++ b/src/app/Assets.hpp @@ -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 resources; world::Set tile_types; diff --git a/src/blobs.cpp b/src/blobs.cpp index ee5e427..c1dfbbc 100644 --- a/src/blobs.cpp +++ b/src/blobs.cpp @@ -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 index 0000000..a6da069 --- /dev/null +++ b/src/creature/NameGenerator.hpp @@ -0,0 +1,27 @@ +#ifndef BLOBS_CREATURE_NAMEGENERATOR_HPP_ +#define BLOBS_CREATURE_NAMEGENERATOR_HPP_ + +#include + + +namespace blobs { +namespace creature { + +class NameGenerator { + +public: + NameGenerator(); + ~NameGenerator(); + +public: + std::string Sequential(); + +private: + int counter; + +}; + +} +} + +#endif diff --git a/src/creature/creature.cpp b/src/creature/creature.cpp index 4345bd9..f51f52c 100644 --- a/src/creature/creature.cpp +++ b/src/creature/creature.cpp @@ -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 +#include #include #include @@ -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)