#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);
+ }
+}
+
}
}