#include "world/Planet.hpp"
#include "world/Simulation.hpp"
#include "world/Sun.hpp"
+#include "world/TileSet.hpp"
+#include "world/TileType.hpp"
#include <cstdint>
#include <iostream>
app::Init init(true, 8);
app::Assets assets;
+ world::TileSet tiles;
+ tiles.Add({ "ice", "Ice", 0, 0 });
+ tiles.Add({ "black", "Black", 0, 1 });
+ tiles.Add({ "red", "Red", 0, 2 });
+ tiles.Add({ "grass", "Grass", 0, 3 });
+ tiles.Add({ "water", "Water", 0, 4 });
+ tiles.Add({ "sand", "Sand", 0, 5 });
+ tiles.Add({ "tundra", "Tundra", 0, 6 });
+ tiles.Add({ "magenta", "Magenta", 0, 7 });
+ tiles.Add({ "rock", "Rock", 0, 8 });
+
world::Sun sun;
sun.Mass(1.0e12);
sun.Radius(10.0);
sim.AddPlanet(second_planet);
sim.AddPlanet(moon);
- world::GenerateEarthlike(planet);
- world::GenerateTest(moon);
- world::GenerateTest(second_planet);
+ world::GenerateEarthlike(tiles, planet);
+ world::GenerateTest(tiles, moon);
+ world::GenerateTest(tiles, second_planet);
std::cout << "length of year: " << planet.OrbitalPeriod() << "s" << std::endl;
std::cout << "length of moon cycle: " << moon.OrbitalPeriod() << "s" << std::endl;
// .Reference(sun)
// .Orbital(glm::vec3(-500.0f, 500.0f, 500.0f))
//;
- planet.BuildVAOs();
app::Application app(init.window, init.viewport);
app.PushState(&state);
namespace blobs {
namespace world {
-struct Tile;
+class TileSet;
/// A planet has six surfaces, numbered 0 to 5, each filled with
/// sidelength² tiles.
glm::dvec3 TileCenter(int surface, int x, int y) const noexcept;
- void BuildVAOs();
+ void BuildVAOs(const TileSet &);
void Draw(app::Assets &, graphics::Viewport &) override;
private:
};
-void GenerateEarthlike(Planet &) noexcept;
-void GenerateTest(Planet &) noexcept;
+void GenerateEarthlike(const TileSet &, Planet &) noexcept;
+void GenerateTest(const TileSet &, Planet &) noexcept;
}
}
--- /dev/null
+#ifndef BLOBS_WORLD_TILESET_HPP_
+#define BLOBS_WORLD_TILESET_HPP_
+
+#include <map>
+#include <string>
+#include <vector>
+
+namespace blobs {
+namespace world {
+
+class TileType;
+
+class TileSet {
+
+public:
+ TileSet();
+ ~TileSet();
+
+ TileSet(const TileSet &) = delete;
+ TileSet &operator =(const TileSet &) = delete;
+
+ TileSet(TileSet &&) = delete;
+ TileSet &operator =(TileSet &&) = delete;
+
+public:
+ int Add(const TileType &);
+
+ TileType &operator [](int id) noexcept { return types[id]; }
+ const TileType &operator [](int id) const noexcept { return types[id]; }
+
+ TileType &operator [](const std::string &name);
+ const TileType &operator [](const std::string &name) const;
+
+private:
+ std::vector<TileType> types;
+ std::map<std::string, int> names;
+
+};
+
+}
+}
+
+#endif
--- /dev/null
+#ifndef BLOBS_WORLD_TILETYPE_HPP_
+#define BLOBS_WORLD_TILETYPE_HPP_
+
+#include <string>
+
+
+namespace blobs {
+namespace world {
+
+struct TileType {
+
+ std::string name;
+ std::string label;
+
+ int id;
+ int texture;
+
+};
+
+}
+}
+
+#endif
#include "Simulation.hpp"
#include "Sun.hpp"
#include "Tile.hpp"
+#include "TileSet.hpp"
+#include "TileType.hpp"
#include "../const.hpp"
#include "../app/Assets.hpp"
return center;
}
-void Planet::BuildVAOs() {
+void Planet::BuildVAOs(const TileSet &ts) {
vao.Bind();
vao.BindAttributes();
vao.EnableAttribute(0);
for (int index = 0, surface = 0; surface < 6; ++surface) {
for (int y = 0; y < sidelength; ++y) {
for (int x = 0; x < sidelength; ++x, ++index) {
- float tex = TileAt(surface, x, y).type;
+ float tex = ts[TileAt(surface, x, y).type].texture;
const float tex_u_begin = surface < 3 ? 1.0f : 0.0f;
const float tex_u_end = surface < 3 ? 0.0f : 1.0f;
attrib[4 * index + 0].position[(surface + 0) % 3] = x + 0 - offset;
}
-void GenerateEarthlike(Planet &p) noexcept {
+void GenerateEarthlike(const TileSet &tiles, Planet &p) noexcept {
rand::SimplexNoise elevation_gen(0);
- constexpr int ice = 0;
- constexpr int grass = 3;
- constexpr int water = 4;
- constexpr int sand = 5;
- constexpr int rock = 8;
+ const int ice = tiles["ice"].id;
+ const int grass = tiles["grass"].id;
+ const int water = tiles["water"].id;
+ const int sand = tiles["sand"].id;
+ const int rock = tiles["rock"].id;
constexpr double water_thresh = 0.0;
constexpr double beach_thresh = 0.1;
}
}
}
- p.BuildVAOs();
+ p.BuildVAOs(tiles);
}
-void GenerateTest(Planet &p) noexcept {
+void GenerateTest(const TileSet &tiles, Planet &p) noexcept {
for (int surface = 0; surface <= 5; ++surface) {
for (int y = 0; y < p.SideLength(); ++y) {
for (int x = 0; x < p.SideLength(); ++x) {
}
}
}
- p.BuildVAOs();
+ p.BuildVAOs(tiles);
}
Sun::~Sun() {
}
+TileSet::TileSet()
+: types()
+, names() {
+}
+
+TileSet::~TileSet() {
+}
+
+int TileSet::Add(const TileType &t) {
+ int id = types.size();
+ if (!names.emplace(t.name, id).second) {
+ throw std::runtime_error("duplicate tile type name " + t.name);
+ }
+ types.emplace_back(t);
+ types.back().id = id;
+ return id;
+}
+
+TileType &TileSet::operator [](const std::string &name) {
+ auto entry = names.find(name);
+ if (entry != names.end()) {
+ return types[entry->second];
+ } else {
+ throw std::runtime_error("unknown tile type " + name);
+ }
+}
+
+const TileType &TileSet::operator [](const std::string &name) const {
+ auto entry = names.find(name);
+ if (entry != names.end()) {
+ return types[entry->second];
+ } else {
+ throw std::runtime_error("unknown tile type " + name);
+ }
+}
+
}
}