From 8f6530c75730f901efd6708e4fde7e68a178adf1 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Sun, 26 Nov 2017 18:29:12 +0100 Subject: [PATCH] randomize creature properties a bit --- assets | 2 +- src/app/Assets.hpp | 3 ++ src/app/app.cpp | 3 ++ src/blobs.cpp | 4 +- src/creature/Creature.hpp | 15 +++++- src/creature/Genome.hpp | 38 ++++++++++++++ src/creature/LocateResourceGoal.hpp | 2 +- src/creature/Situation.hpp | 2 +- src/creature/Steering.hpp | 2 +- src/creature/creature.cpp | 76 ++++++++++++++++++++------- src/graphics/AlphaSprite.hpp | 2 - src/graphics/Camera.hpp | 2 +- src/graphics/Canvas.hpp | 2 +- src/graphics/CreatureSkin.hpp | 2 - src/graphics/Font.hpp | 2 +- src/graphics/PlanetSurface.hpp | 2 - src/graphics/Program.hpp | 2 +- src/graphics/SunSurface.hpp | 2 - src/graphics/gl_traits.hpp | 2 +- src/graphics/viewport.cpp | 2 +- src/io/TokenStreamReader.hpp | 2 +- src/math/Distribution.hpp | 38 ++++++++++++++ src/{rand => math}/GaloisLFSR.hpp | 14 ++--- src/{rand => math}/OctaveNoise.hpp | 8 +-- src/{rand => math}/SimplexNoise.hpp | 8 +-- src/{rand => math}/WorleyNoise.hpp | 8 +-- src/{ => math}/const.hpp | 5 +- src/{graphics => math}/glm.hpp | 4 +- src/{rand => math}/noise.cpp | 2 +- src/ui/Widget.hpp | 2 +- src/ui/align.hpp | 2 +- src/world/Body.hpp | 2 +- src/world/Orbit.hpp | 2 +- src/world/Planet.hpp | 2 +- src/world/Resource.hpp | 6 ++- src/world/world.cpp | 14 ++--- tst/assert.hpp | 2 +- tst/{rand => math}/GaloisLFSRTest.cpp | 6 +-- tst/{rand => math}/GaloisLFSRTest.hpp | 6 +-- tst/{rand => math}/StabilityTest.cpp | 10 ++-- tst/{rand => math}/StabilityTest.hpp | 8 +-- tst/world/OrbitTest.cpp | 2 +- 42 files changed, 222 insertions(+), 98 deletions(-) create mode 100644 src/creature/Genome.hpp create mode 100644 src/math/Distribution.hpp rename src/{rand => math}/GaloisLFSR.hpp (84%) rename src/{rand => math}/OctaveNoise.hpp (78%) rename src/{rand => math}/SimplexNoise.hpp (80%) rename src/{rand => math}/WorleyNoise.hpp (71%) rename src/{ => math}/const.hpp (81%) rename src/{graphics => math}/glm.hpp (91%) rename src/{rand => math}/noise.cpp (99%) rename tst/{rand => math}/GaloisLFSRTest.cpp (92%) rename tst/{rand => math}/GaloisLFSRTest.hpp (86%) rename tst/{rand => math}/StabilityTest.cpp (97%) rename tst/{rand => math}/StabilityTest.hpp (83%) diff --git a/assets b/assets index ce337a6..7703c13 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit ce337a6b5afd87607a94f006631a390eefceeec1 +Subproject commit 7703c130c0be3b33f4f267d2662f36b999826f33 diff --git a/src/app/Assets.hpp b/src/app/Assets.hpp index 22b6087..5f971c6 100644 --- a/src/app/Assets.hpp +++ b/src/app/Assets.hpp @@ -8,6 +8,7 @@ #include "../graphics/Font.hpp" #include "../graphics/PlanetSurface.hpp" #include "../graphics/SunSurface.hpp" +#include "../math/GaloisLFSR.hpp" #include "../world/Resource.hpp" #include "../world/Set.hpp" #include "../world/TileType.hpp" @@ -29,6 +30,8 @@ struct Assets { std::string skin_path; std::string tile_path; + math::GaloisLFSR random; + struct { world::Set resources; world::Set tile_types; diff --git a/src/app/app.cpp b/src/app/app.cpp index e4dc1a5..5a4cd67 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -176,6 +176,7 @@ Assets::Assets() , font_path(path + "fonts/") , skin_path(path + "skins/") , tile_path(path + "tiles/") +, random(0) , fonts{ graphics::Font(font_path + "DejaVuSans.ttf", 32), graphics::Font(font_path + "DejaVuSans.ttf", 24), @@ -251,6 +252,8 @@ void Assets::ReadResources(io::TokenStreamReader &in) { in.Skip(io::Token::EQUALS); if (name == "label") { in.ReadString(data.resources[id].label); + } else if (name == "density") { + data.resources[id].density = in.GetDouble(); } else if (name == "state") { in.ReadIdentifier(name); if (name == "solid") { diff --git a/src/blobs.cpp b/src/blobs.cpp index 006644b..b32c4ab 100644 --- a/src/blobs.cpp +++ b/src/blobs.cpp @@ -1,9 +1,9 @@ -#include "const.hpp" #include "app/Application.hpp" #include "app/Assets.hpp" #include "app/init.hpp" #include "app/MasterState.hpp" #include "creature/Creature.hpp" +#include "math/const.hpp" #include "world/Planet.hpp" #include "world/Set.hpp" #include "world/Simulation.hpp" @@ -80,7 +80,7 @@ int main(int argc, char *argv[]) { // sunset //.FirstPerson(3, glm::vec3(0.0f, 0.0f, 0.1f), glm::vec3(1.0f, -0.75f, 0.1f)) // from afar - .MapView(0, glm::vec3(0.0f, 0.0f, 31.0f), 0.0f) + .MapView(0, glm::vec3(0.0f, 0.0f, 10.0f), 0.0f) // from afar, rotating //.Orbital(glm::vec3(-60.0f, 0.0f, 0.0f)) ; diff --git a/src/creature/Creature.hpp b/src/creature/Creature.hpp index ce56dfb..2a40d51 100644 --- a/src/creature/Creature.hpp +++ b/src/creature/Creature.hpp @@ -1,12 +1,13 @@ #ifndef BLOBS_CREATURE_CREATURE_HPP_ #define BLOBS_CREATURE_CREATURE_HPP_ +#include "Genome.hpp" #include "Goal.hpp" #include "Need.hpp" #include "Situation.hpp" #include "Steering.hpp" -#include "../graphics/glm.hpp" #include "../graphics/SimpleVAO.hpp" +#include "../math/glm.hpp" #include #include @@ -46,6 +47,12 @@ public: void Name(const std::string &n) noexcept { name = n; } const std::string &Name() const noexcept { return name; } + Genome &GetGenome() noexcept { return genome; } + const Genome &GetGenome() const noexcept { return genome; } + + void Mass(double m) noexcept { mass = m; } + double Mass() const noexcept { return mass; } + void Size(double s) noexcept { size = s; } double Size() const noexcept { return size; } @@ -69,7 +76,7 @@ public: void Velocity(const glm::dvec3 &v) noexcept { vel = v; } const glm::dvec3 &Velocity() const noexcept { return vel; } - bool Moving() const noexcept { return !allzero(vel); } + bool Moving() const noexcept { return glm::length2(vel) < 0.000001; } glm::dmat4 LocalTransform() noexcept; @@ -79,6 +86,10 @@ public: private: world::Simulation ∼ std::string name; + + Genome genome; + + double mass; double size; double health; diff --git a/src/creature/Genome.hpp b/src/creature/Genome.hpp new file mode 100644 index 0000000..4437150 --- /dev/null +++ b/src/creature/Genome.hpp @@ -0,0 +1,38 @@ +#ifndef BLOBS_CREATURE_GENOME_HPP_ +#define BLOBS_CREATURE_GENOME_HPP_ + +#include "../math/Distribution.hpp" + +#include + + +namespace blobs { +namespace app { + struct Assets; +} +namespace creature { + +class Creature; + +struct Genome { + + struct Composition { + // which resource + int resource; + // how much contained in the body + math::Distribution mass; + // how much to circulate + math::Distribution intake; + // how important for alive-being + math::Distribution penalty; + }; + std::vector composition; + + void Configure(app::Assets &, Creature &) const; + +}; + +} +} + +#endif diff --git a/src/creature/LocateResourceGoal.hpp b/src/creature/LocateResourceGoal.hpp index afa5b93..a472fd5 100644 --- a/src/creature/LocateResourceGoal.hpp +++ b/src/creature/LocateResourceGoal.hpp @@ -1,7 +1,7 @@ #ifndef BLOBS_CREATURE_LOCATERESOURCEGOAL_HPP_ #define BLOBS_CREATURE_LOCATERESOURCEGOAL_HPP_ -#include "../graphics/glm.hpp" +#include "../math/glm.hpp" namespace blobs { diff --git a/src/creature/Situation.hpp b/src/creature/Situation.hpp index 12b7490..d421b69 100644 --- a/src/creature/Situation.hpp +++ b/src/creature/Situation.hpp @@ -1,7 +1,7 @@ #ifndef BLOBS_CREATURE_SITUATION_HPP_ #define BLOBS_CREATURE_SITUATION_HPP_ -#include "../graphics/glm.hpp" +#include "../math/glm.hpp" namespace blobs { diff --git a/src/creature/Steering.hpp b/src/creature/Steering.hpp index 6d5b40a..51f2c63 100644 --- a/src/creature/Steering.hpp +++ b/src/creature/Steering.hpp @@ -1,7 +1,7 @@ #ifndef BLOBS_CREATURE_STEERING_HPP_ #define BLOBS_CREATURE_STEERING_HPP_ -#include "../graphics/glm.hpp" +#include "../math/glm.hpp" namespace blobs { diff --git a/src/creature/creature.cpp b/src/creature/creature.cpp index 043aed7..0f25da8 100644 --- a/src/creature/creature.cpp +++ b/src/creature/creature.cpp @@ -1,4 +1,5 @@ #include "Creature.hpp" +#include "Genome.hpp" #include "Situation.hpp" #include "Steering.hpp" @@ -25,6 +26,8 @@ namespace creature { Creature::Creature(world::Simulation &sim) : sim(sim) , name() +, genome() +, mass(1.0) , size(1.0) , health(1.0) , needs() @@ -195,7 +198,6 @@ void Creature::Draw(app::Assets &assets, graphics::Viewport &viewport) { void Spawn(Creature &c, world::Planet &p, app::Assets &assets) { p.AddCreature(&c); c.GetSituation().SetPlanetSurface(p, 0, p.TileCenter(0, p.SideLength() / 2, p.SideLength() / 2)); - c.Size(0.5); // probe surrounding area for common resources int start = p.SideLength() / 2 - 2; @@ -223,33 +225,67 @@ void Spawn(Creature &c, world::Planet &p, app::Assets &assets) { } } + Genome genome; if (p.HasAtmosphere()) { - std::cout << "require breathing " << assets.data.resources[p.Atmosphere()].label << std::endl; - std::unique_ptr need(new InhaleNeed(p.Atmosphere(), 0.5, 0.1)); - need->name = assets.data.resources[p.Atmosphere()].label; - need->gain = 0.2; - need->inconvenient = 0.4; - need->critical = 0.95; - c.AddNeed(std::move(need)); + genome.composition.push_back({ + p.Atmosphere(), // resource + { 0.01, 0.00001 }, // mass + { 0.5, 0.001 }, // intake + { 0.1, 0.0005 } // penalty + }); } if (liquid > -1) { - std::cout << "require drinking " << assets.data.resources[liquid].label << std::endl; - std::unique_ptr need(new IngestNeed(liquid, 0.2, 0.01)); - need->name = assets.data.resources[liquid].label; - need->gain = 0.02; - need->inconvenient = 0.6; - need->critical = 0.95; - c.AddNeed(std::move(need)); + genome.composition.push_back({ + liquid, // resource + { 0.6, 0.01 }, // mass + { 0.2, 0.001 }, // intake + { 0.01, 0.002 } // penalty + }); } if (solid > -1) { - std::cout << "require eating " << assets.data.resources[solid].label << std::endl; - std::unique_ptr need(new IngestNeed(solid, 0.1, 0.001)); - need->name = assets.data.resources[solid].label; - need->gain = 0.017; - need->inconvenient = 0.6; + genome.composition.push_back({ + solid, // resource + { 0.4, 0.01 }, // mass + { 0.1, 0.001 }, // intake + { 0.001, 0.0001 } // penalty + }); + } + + genome.Configure(assets, c); + c.GetSteering().MaxAcceleration(1.4); + c.GetSteering().MaxSpeed(4.4); +} + +void Genome::Configure(app::Assets &assets, Creature &c) const { + c.GetGenome() = *this; + double mass = 0.0; + double volume = 0.0; + for (const auto &comp : composition) { + double comp_mass = comp.mass.FakeNormal(assets.random.SNorm()); + double intake = comp.intake.FakeNormal(assets.random.SNorm()); + double penalty = comp.intake.FakeNormal(assets.random.SNorm()); + + mass += comp_mass; + volume += comp_mass / assets.data.resources[comp.resource].density; + + std::unique_ptr need; + if (assets.data.resources[comp.resource].state == world::Resource::SOLID) { + need.reset(new IngestNeed(comp.resource, intake, penalty)); + need->gain = intake * 0.05; + } else if (assets.data.resources[comp.resource].state == world::Resource::LIQUID) { + need.reset(new IngestNeed(comp.resource, intake, penalty)); + need->gain = intake * 0.1; + } else { + need.reset(new InhaleNeed(comp.resource, intake, penalty)); + need->gain = intake * 0.5; + } + need->name = assets.data.resources[comp.resource].label; + need->inconvenient = 0.5; need->critical = 0.95; c.AddNeed(std::move(need)); } + c.Mass(mass); + c.Size(std::cbrt(volume)); } Situation::Situation() diff --git a/src/graphics/AlphaSprite.hpp b/src/graphics/AlphaSprite.hpp index 3cc6a83..c62150d 100644 --- a/src/graphics/AlphaSprite.hpp +++ b/src/graphics/AlphaSprite.hpp @@ -4,8 +4,6 @@ #include "Program.hpp" #include "SimpleVAO.hpp" -#include "glm.hpp" - #include diff --git a/src/graphics/Camera.hpp b/src/graphics/Camera.hpp index f4a98d5..51dd8f1 100644 --- a/src/graphics/Camera.hpp +++ b/src/graphics/Camera.hpp @@ -1,7 +1,7 @@ #ifndef BLOBS_GRAPHICS_CAMERA_HPP_ #define BLOBS_GRAPHICS_CAMERA_HPP_ -#include "glm.hpp" +#include "../math/glm.hpp" namespace blobs { diff --git a/src/graphics/Canvas.hpp b/src/graphics/Canvas.hpp index bc2a47a..4e924f1 100644 --- a/src/graphics/Canvas.hpp +++ b/src/graphics/Canvas.hpp @@ -1,9 +1,9 @@ #ifndef BLOBS_GRAPHICS_CANVAS_HPP_ #define BLOBS_GRAPHICS_CANVAS_HPP_ -#include "glm.hpp" #include "Program.hpp" #include "SimpleVAO.hpp" +#include "../math/glm.hpp" #include diff --git a/src/graphics/CreatureSkin.hpp b/src/graphics/CreatureSkin.hpp index 0d83563..1b5b6b8 100644 --- a/src/graphics/CreatureSkin.hpp +++ b/src/graphics/CreatureSkin.hpp @@ -3,8 +3,6 @@ #include "Program.hpp" -#include "glm.hpp" - namespace blobs { namespace graphics { diff --git a/src/graphics/Font.hpp b/src/graphics/Font.hpp index 6088d95..d7aa4fa 100644 --- a/src/graphics/Font.hpp +++ b/src/graphics/Font.hpp @@ -1,7 +1,7 @@ #ifndef BLOBS_GRAPHICS_FONT_HPP_ #define BLOBS_GRAPHICS_FONT_HPP_ -#include "glm.hpp" +#include "../math/glm.hpp" #include #include diff --git a/src/graphics/PlanetSurface.hpp b/src/graphics/PlanetSurface.hpp index 178fcab..a5f177d 100644 --- a/src/graphics/PlanetSurface.hpp +++ b/src/graphics/PlanetSurface.hpp @@ -3,8 +3,6 @@ #include "Program.hpp" -#include "glm.hpp" - namespace blobs { namespace graphics { diff --git a/src/graphics/Program.hpp b/src/graphics/Program.hpp index 2add96c..d068972 100644 --- a/src/graphics/Program.hpp +++ b/src/graphics/Program.hpp @@ -1,7 +1,7 @@ #ifndef BLOBS_GRAPHICS_PROGRAM_HPP_ #define BLOBS_GRAPHICS_PROGRAM_HPP_ -#include "glm.hpp" +#include "../math/glm.hpp" #include #include diff --git a/src/graphics/SunSurface.hpp b/src/graphics/SunSurface.hpp index b5a056b..6572761 100644 --- a/src/graphics/SunSurface.hpp +++ b/src/graphics/SunSurface.hpp @@ -4,8 +4,6 @@ #include "Program.hpp" #include "SimpleVAO.hpp" -#include "glm.hpp" - #include diff --git a/src/graphics/gl_traits.hpp b/src/graphics/gl_traits.hpp index a399893..33b0069 100644 --- a/src/graphics/gl_traits.hpp +++ b/src/graphics/gl_traits.hpp @@ -1,7 +1,7 @@ #ifndef BLOBS_GRAPHICS_GL_TRAITS_HPP_ #define BLOBS_GRAPHICS_GL_TRAITS_HPP_ -#include "glm.hpp" +#include "../math/glm.hpp" #include diff --git a/src/graphics/viewport.cpp b/src/graphics/viewport.cpp index 636f3c3..ac0b9e5 100644 --- a/src/graphics/viewport.cpp +++ b/src/graphics/viewport.cpp @@ -1,7 +1,7 @@ #include "Camera.hpp" #include "Viewport.hpp" -#include "../const.hpp" +#include "../math/const.hpp" #include "../world/Body.hpp" #include diff --git a/src/io/TokenStreamReader.hpp b/src/io/TokenStreamReader.hpp index c9043d1..ccdad90 100644 --- a/src/io/TokenStreamReader.hpp +++ b/src/io/TokenStreamReader.hpp @@ -3,7 +3,7 @@ #include "Token.hpp" #include "Tokenizer.hpp" -#include "../graphics/glm.hpp" +#include "../math/glm.hpp" #include #include diff --git a/src/math/Distribution.hpp b/src/math/Distribution.hpp new file mode 100644 index 0000000..7f444f8 --- /dev/null +++ b/src/math/Distribution.hpp @@ -0,0 +1,38 @@ +#ifndef BLOBS_MATH_DISTRIBUTION_HPP_ +#define BLOBS_MATH_DISTRIBUTION_HPP_ + +#include + + +namespace blobs { +namespace math { + +class Distribution { + +public: + Distribution(double mean = 0.0, double stddev = 1.0) noexcept + : mean(mean) + , stddev(stddev) + { } + +public: + double Mean() const noexcept { return mean; } + double StandardDeviation() const noexcept { return stddev; } + double Variance() const noexcept { return stddev * stddev; } + + /// convert uniform random value in [-1,1] to fake normal distribution + /// in [mean - 2 stdddev,mean + 2 stddev] + double FakeNormal(double uniform) const noexcept { + return mean + (uniform * uniform * stddev) + std::abs(uniform * uniform * uniform) * stddev; + } + +private: + double mean; + double stddev; + +}; + +} +} + +#endif diff --git a/src/rand/GaloisLFSR.hpp b/src/math/GaloisLFSR.hpp similarity index 84% rename from src/rand/GaloisLFSR.hpp rename to src/math/GaloisLFSR.hpp index 83dc0e5..592c9af 100644 --- a/src/rand/GaloisLFSR.hpp +++ b/src/math/GaloisLFSR.hpp @@ -1,5 +1,5 @@ -#ifndef BLOBS_RAND_GALOISLFSR_HPP_ -#define BLOBS_RAND_GALOISLFSR_HPP_ +#ifndef BLOBS_MATH_GALOISLFSR_HPP_ +#define BLOBS_MATH_GALOISLFSR_HPP_ #include #include @@ -7,7 +7,7 @@ namespace blobs { -namespace rand { +namespace math { class GaloisLFSR { @@ -55,12 +55,12 @@ public: return (*this)(next); } - float SNorm() noexcept { - return float(Next()) * (1.0f / 2147483647.5f) - 1.0f; + double SNorm() noexcept { + return 2.0 * UNorm() - 1.0; } - float UNorm() noexcept { - return float(Next()) * (1.0f / 4294967295.0f); + double UNorm() noexcept { + return double(Next()) * (1.0 / double(std::numeric_limits::max())); } template diff --git a/src/rand/OctaveNoise.hpp b/src/math/OctaveNoise.hpp similarity index 78% rename from src/rand/OctaveNoise.hpp rename to src/math/OctaveNoise.hpp index 6a91c85..1b2419e 100644 --- a/src/rand/OctaveNoise.hpp +++ b/src/math/OctaveNoise.hpp @@ -1,11 +1,11 @@ -#ifndef BLOBS_RAND_OCTAVENOISE_HPP_ -#define BLOBS_RAND_OCTAVENOISE_HPP_ +#ifndef BLOBS_MATH_OCTAVENOISE_HPP_ +#define BLOBS_MATH_OCTAVENOISE_HPP_ -#include "../graphics/glm.hpp" +#include "glm.hpp" namespace blobs { -namespace rand { +namespace math { template float OctaveNoise( diff --git a/src/rand/SimplexNoise.hpp b/src/math/SimplexNoise.hpp similarity index 80% rename from src/rand/SimplexNoise.hpp rename to src/math/SimplexNoise.hpp index 9a72e64..cb9f07c 100644 --- a/src/rand/SimplexNoise.hpp +++ b/src/math/SimplexNoise.hpp @@ -1,13 +1,13 @@ -#ifndef BLOBS_RAND_SIMPLEXNOISE_HPP_ -#define BLOBS_RAND_SIMPLEXNOISE_HPP_ +#ifndef BLOBS_MATH_SIMPLEXNOISE_HPP_ +#define BLOBS_MATH_SIMPLEXNOISE_HPP_ -#include "../graphics/glm.hpp" +#include "glm.hpp" #include namespace blobs { -namespace rand { +namespace math { class SimplexNoise { diff --git a/src/rand/WorleyNoise.hpp b/src/math/WorleyNoise.hpp similarity index 71% rename from src/rand/WorleyNoise.hpp rename to src/math/WorleyNoise.hpp index 34c4871..f585496 100644 --- a/src/rand/WorleyNoise.hpp +++ b/src/math/WorleyNoise.hpp @@ -1,11 +1,11 @@ -#ifndef BLOBS_RAND_WORLEYNOISE_HPP_ -#define BLOBS_RAND_WORLEYNOISE_HPP_ +#ifndef BLOBS_MATH_WORLEYNOISE_HPP_ +#define BLOBS_MATH_WORLEYNOISE_HPP_ -#include "../graphics/glm.hpp" +#include "glm.hpp" namespace blobs { -namespace rand { +namespace math { /// implementation of Worley noise (aka Cell or Voroni noise) class WorleyNoise { diff --git a/src/const.hpp b/src/math/const.hpp similarity index 81% rename from src/const.hpp rename to src/math/const.hpp index edbbe7c..082cca1 100644 --- a/src/const.hpp +++ b/src/math/const.hpp @@ -1,5 +1,5 @@ -#ifndef BLOBS_CONST_HPP_ -#define BLOBS_CONST_HPP_ +#ifndef BLOBS_MATH_CONST_HPP_ +#define BLOBS_MATH_CONST_HPP_ namespace blobs { @@ -13,6 +13,7 @@ constexpr double PI_2p0 = PI * 2.0; constexpr double PI_inv = 1.0 / PI; constexpr double PI_0p5_inv = 1.0 / PI_0p5; +/// gravitational constant constexpr double G = 6.674e-11; // m³kg¯¹s¯² } diff --git a/src/graphics/glm.hpp b/src/math/glm.hpp similarity index 91% rename from src/graphics/glm.hpp rename to src/math/glm.hpp index 8003f0b..4b1bf33 100644 --- a/src/graphics/glm.hpp +++ b/src/math/glm.hpp @@ -1,5 +1,5 @@ -#ifndef BLOBS_GRAPHICS_GLM_HPP_ -#define BLOBS_GRAPHICS_GLM_HPP_ +#ifndef BLOBS_MATH_GLM_HPP_ +#define BLOBS_MATH_GLM_HPP_ #ifndef GLM_FORCE_RADIANS # define GLM_FORCE_RADIANS 1 diff --git a/src/rand/noise.cpp b/src/math/noise.cpp similarity index 99% rename from src/rand/noise.cpp rename to src/math/noise.cpp index 07ab817..5c6f72d 100644 --- a/src/rand/noise.cpp +++ b/src/math/noise.cpp @@ -14,7 +14,7 @@ constexpr float one_sixth = 1.0f/6.0f; } namespace blobs { -namespace rand { +namespace math { SimplexNoise::SimplexNoise(std::uint64_t seed) noexcept : grad({ diff --git a/src/ui/Widget.hpp b/src/ui/Widget.hpp index 0f9c8d9..a69defb 100644 --- a/src/ui/Widget.hpp +++ b/src/ui/Widget.hpp @@ -1,7 +1,7 @@ #ifndef BLOBS_UI_WIDGET_HPP_ #define BLOBS_UI_WIDGET_HPP_ -#include "../graphics/glm.hpp" +#include "../math/glm.hpp" namespace blobs { diff --git a/src/ui/align.hpp b/src/ui/align.hpp index 15dce20..24fb9a2 100644 --- a/src/ui/align.hpp +++ b/src/ui/align.hpp @@ -1,7 +1,7 @@ #ifndef BLOBS_UI_ALIGN_HPP_ #define BLOBS_UI_ALIGN_HPP_ -#include "../graphics/glm.hpp" +#include "../math/glm.hpp" namespace blobs { diff --git a/src/world/Body.hpp b/src/world/Body.hpp index 3db5e37..df68984 100644 --- a/src/world/Body.hpp +++ b/src/world/Body.hpp @@ -2,7 +2,7 @@ #define BLOBS_WORLD_BODY_HPP_ #include "Orbit.hpp" -#include "../graphics/glm.hpp" +#include "../math/glm.hpp" #include diff --git a/src/world/Orbit.hpp b/src/world/Orbit.hpp index 7def521..8ed415e 100644 --- a/src/world/Orbit.hpp +++ b/src/world/Orbit.hpp @@ -1,7 +1,7 @@ #ifndef BLOBS_WORLD_ORBIT_HPP_ #define BLOBS_WORLD_ORBIT_HPP_ -#include "../graphics/glm.hpp" +#include "../math/glm.hpp" namespace blobs { diff --git a/src/world/Planet.hpp b/src/world/Planet.hpp index 2274d04..28ecaa0 100644 --- a/src/world/Planet.hpp +++ b/src/world/Planet.hpp @@ -5,8 +5,8 @@ #include "Set.hpp" #include "Tile.hpp" -#include "../graphics/glm.hpp" #include "../graphics/SimpleVAO.hpp" +#include "../math/glm.hpp" #include #include diff --git a/src/world/Resource.hpp b/src/world/Resource.hpp index 6250fc6..492a7f8 100644 --- a/src/world/Resource.hpp +++ b/src/world/Resource.hpp @@ -12,7 +12,9 @@ struct Resource { std::string name; std::string label; - int id; + double density = 1.0; + + int id = -1; enum State { SOLID = 0, @@ -22,7 +24,7 @@ struct Resource { }; // the resource's natural state // TODO: something about temperature and pressure and stuff - int state; + int state = SOLID; }; diff --git a/src/world/world.cpp b/src/world/world.cpp index 0b1260f..4f98d9a 100644 --- a/src/world/world.cpp +++ b/src/world/world.cpp @@ -8,12 +8,12 @@ #include "Tile.hpp" #include "TileType.hpp" -#include "../const.hpp" #include "../app/Assets.hpp" #include "../creature/Creature.hpp" #include "../graphics/Viewport.hpp" -#include "../rand/OctaveNoise.hpp" -#include "../rand/SimplexNoise.hpp" +#include "../math/const.hpp" +#include "../math/OctaveNoise.hpp" +#include "../math/SimplexNoise.hpp" #include #include @@ -421,8 +421,8 @@ void Planet::Draw(app::Assets &assets, graphics::Viewport &viewport) { void GenerateEarthlike(const Set &tiles, Planet &p) noexcept { - rand::SimplexNoise elevation_gen(0); - rand::SimplexNoise variation_gen(45623752346); + math::SimplexNoise elevation_gen(0); + math::SimplexNoise variation_gen(45623752346); const int ice = tiles["ice"].id; const int ocean = tiles["ocean"].id; @@ -460,7 +460,7 @@ void GenerateEarthlike(const Set &tiles, Planet &p) noexcept { p.TileAt(surface, x, y).type = ice; continue; } - float elevation = rand::OctaveNoise( + float elevation = math::OctaveNoise( elevation_gen, to_tile / p.Radius(), 3, // octaves @@ -469,7 +469,7 @@ void GenerateEarthlike(const Set &tiles, Planet &p) noexcept { 2, // amplitude 2 // growth ); - float variation = rand::OctaveNoise( + float variation = math::OctaveNoise( variation_gen, to_tile / p.Radius(), 3, // octaves diff --git a/tst/assert.hpp b/tst/assert.hpp index 5042180..66a9704 100644 --- a/tst/assert.hpp +++ b/tst/assert.hpp @@ -1,7 +1,7 @@ #ifndef BLOBS_TEST_ASSETS_HPP_ #define BLOBS_TEST_ASSETS_HPP_ -#include "graphics/glm.hpp" +#include "math/glm.hpp" #include #include diff --git a/tst/rand/GaloisLFSRTest.cpp b/tst/math/GaloisLFSRTest.cpp similarity index 92% rename from tst/rand/GaloisLFSRTest.cpp rename to tst/math/GaloisLFSRTest.cpp index 0078207..958ac76 100644 --- a/tst/rand/GaloisLFSRTest.cpp +++ b/tst/math/GaloisLFSRTest.cpp @@ -1,17 +1,17 @@ #include "GaloisLFSRTest.hpp" -#include "rand/GaloisLFSR.hpp" +#include "math/GaloisLFSR.hpp" #include #include -CPPUNIT_TEST_SUITE_REGISTRATION(blobs::rand::test::GaloisLFSRTest); +CPPUNIT_TEST_SUITE_REGISTRATION(blobs::math::test::GaloisLFSRTest); using namespace std; namespace blobs { -namespace rand { +namespace math { namespace test { void GaloisLFSRTest::setUp() { diff --git a/tst/rand/GaloisLFSRTest.hpp b/tst/math/GaloisLFSRTest.hpp similarity index 86% rename from tst/rand/GaloisLFSRTest.hpp rename to tst/math/GaloisLFSRTest.hpp index 512bb99..87c92d6 100644 --- a/tst/rand/GaloisLFSRTest.hpp +++ b/tst/math/GaloisLFSRTest.hpp @@ -1,5 +1,5 @@ -#ifndef BLOBS_TEST_RAND_GALOISLFSRTEST_HPP -#define BLOBS_TEST_RAND_GALOISLFSRTEST_HPP +#ifndef BLOBS_TEST_MATH_GALOISLFSRTEST_HPP +#define BLOBS_TEST_MATH_GALOISLFSRTEST_HPP #include @@ -8,7 +8,7 @@ namespace blobs { -namespace rand { +namespace math { namespace test { class GaloisLFSRTest diff --git a/tst/rand/StabilityTest.cpp b/tst/math/StabilityTest.cpp similarity index 97% rename from tst/rand/StabilityTest.cpp rename to tst/math/StabilityTest.cpp index c6c6339..8b0011f 100644 --- a/tst/rand/StabilityTest.cpp +++ b/tst/math/StabilityTest.cpp @@ -1,21 +1,21 @@ #include "StabilityTest.hpp" -#include "rand/GaloisLFSR.hpp" -#include "rand/SimplexNoise.hpp" -#include "rand/WorleyNoise.hpp" +#include "math/GaloisLFSR.hpp" +#include "math/SimplexNoise.hpp" +#include "math/WorleyNoise.hpp" #include #include #include #include -CPPUNIT_TEST_SUITE_REGISTRATION(blobs::rand::test::StabilityTest); +CPPUNIT_TEST_SUITE_REGISTRATION(blobs::math::test::StabilityTest); using namespace std; namespace blobs { -namespace rand { +namespace math { namespace test { void StabilityTest::setUp() { diff --git a/tst/rand/StabilityTest.hpp b/tst/math/StabilityTest.hpp similarity index 83% rename from tst/rand/StabilityTest.hpp rename to tst/math/StabilityTest.hpp index 8f38114..8b6409e 100644 --- a/tst/rand/StabilityTest.hpp +++ b/tst/math/StabilityTest.hpp @@ -1,14 +1,14 @@ -#ifndef BLOBS_TEST_RAND_STABILITYTEST_HPP -#define BLOBS_TEST_RAND_STABILITYTEST_HPP +#ifndef BLOBS_TEST_MATH_STABILITYTEST_HPP +#define BLOBS_TEST_MATH_STABILITYTEST_HPP -#include "graphics/glm.hpp" +#include "math/glm.hpp" #include namespace blobs { -namespace rand { +namespace math { class SimplexNoise; class WorleyNoise; diff --git a/tst/world/OrbitTest.cpp b/tst/world/OrbitTest.cpp index ce16909..a7ef681 100644 --- a/tst/world/OrbitTest.cpp +++ b/tst/world/OrbitTest.cpp @@ -2,7 +2,7 @@ #include "../assert.hpp" -#include "const.hpp" +#include "math/const.hpp" #include "world/Orbit.hpp" CPPUNIT_TEST_SUITE_REGISTRATION(blobs::world::test::OrbitTest); -- 2.39.2