forked from mmccoo/minecraft_mmccoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BiomeVectors.cpp
66 lines (50 loc) · 1.57 KB
/
BiomeVectors.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <BiomeVectors.h>
#include <biome.h>
#include <sstream>
#include <fstream>
//https://github.com/nlohmann/json#json-as-first-class-data-type
// this json header is copied from the above github. I don't know how to include
// a single file as a submodule and the git report itself is pretty large.
#include <nlohmann/json.hpp>
BiomeVectors::BiomeVectors()
{
/* empty */
}
void BiomeVectors::add_chunk(int chunkx, int chunkz, Grid16 biomes)
{
for(int x=0; x<16; x++) {
for(int z=0; z<16; z++) {
auto b = get_biome(biomes[x][z]);
int xl = (chunkx*16+x);
int zl = (chunkz*16+z);
int xh = xl + 1;
int zh = zl + 1;
if (b.name == "") {
std::cout << "adding blank biome\n";
}
add_rectangle_to_polygon_set(polysets[b.id], xl, zl, xh, zh);
}
}
}
void BiomeVectors::write(std::string filename)
{
nlohmann::json top;
top["type"] = "FeatureCollection";
for(auto ps : polysets) {
const Biome &b = get_biome(ps.first);
PolygonHolesSet merged;
gtl::assign(merged, ps.second);
for (auto poly : merged) {
nlohmann::json feature;
feature["type"] = "Feature";
feature["properties"]["biome"] = b.name;
feature["geometry"]["type"] = "Polygon";
feature["geometry"]["coordinates"] = polygon_to_json(poly);
top["features"].push_back(feature);
}
}
std::ofstream file;
file.open(filename);
file << top.dump(2);
file.close();
}