mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-03-05 17:44:52 +01:00
Info: restructure mipmap level data structure
This commit is contained in:
parent
cbc4a946c6
commit
c06af49068
2 changed files with 22 additions and 13 deletions
10
src/Info.cpp
10
src/Info.cpp
|
@ -46,12 +46,14 @@ void Info::writeJSON(const char *filename) const {
|
||||||
std::fprintf(f, "{");
|
std::fprintf(f, "{");
|
||||||
std::fprintf(f, "\"mipmaps\":[");
|
std::fprintf(f, "\"mipmaps\":[");
|
||||||
|
|
||||||
for (size_t level = 0; level < regions.size(); level++) {
|
bool first_level = true;
|
||||||
if (level != 0)
|
for (const auto &level : levels) {
|
||||||
|
if (!first_level)
|
||||||
std::fprintf(f, ",");
|
std::fprintf(f, ",");
|
||||||
|
first_level = false;
|
||||||
|
|
||||||
int minX, maxX, minZ, maxZ;
|
int minX, maxX, minZ, maxZ;
|
||||||
std::tie(minX, maxX, minZ, maxZ) = getBounds(level);
|
std::tie(minX, maxX, minZ, maxZ) = level.bounds;
|
||||||
|
|
||||||
std::fprintf(f, "{");
|
std::fprintf(f, "{");
|
||||||
std::fprintf(f, "\"bounds\":{");
|
std::fprintf(f, "\"bounds\":{");
|
||||||
|
@ -63,7 +65,7 @@ void Info::writeJSON(const char *filename) const {
|
||||||
std::fprintf(f, "\"regions\":{");
|
std::fprintf(f, "\"regions\":{");
|
||||||
|
|
||||||
bool first_z = true;
|
bool first_z = true;
|
||||||
for (const auto &item : regions[level]) {
|
for (const auto &item : level.regions) {
|
||||||
if (!first_z)
|
if (!first_z)
|
||||||
std::fprintf(f, ",");
|
std::fprintf(f, ",");
|
||||||
first_z = false;
|
first_z = false;
|
||||||
|
|
25
src/Info.hpp
25
src/Info.hpp
|
@ -39,9 +39,14 @@
|
||||||
namespace MinedMap {
|
namespace MinedMap {
|
||||||
|
|
||||||
class Info {
|
class Info {
|
||||||
|
public:
|
||||||
|
struct Level {
|
||||||
|
std::map<int, std::set<int>> regions;
|
||||||
|
std::tuple<int, int, int, int> bounds;
|
||||||
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<std::map<int, std::set<int>>> regions;
|
std::vector<Level> levels;
|
||||||
std::vector<std::tuple<int, int, int, int>> bounds;
|
|
||||||
|
|
||||||
int32_t spawnX, spawnZ;
|
int32_t spawnX, spawnZ;
|
||||||
|
|
||||||
|
@ -51,18 +56,18 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
std::tuple<int, int, int, int> getBounds(size_t level) const {
|
std::tuple<int, int, int, int> getBounds(size_t level) const {
|
||||||
return bounds[level];
|
return levels[level].bounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
void addRegion(int x, int z, size_t level) {
|
void addRegion(int x, int z, size_t level) {
|
||||||
auto &level_r = regions[level];
|
auto &the_level = levels[level];
|
||||||
auto z_regions = level_r.emplace(
|
auto z_regions = the_level.regions.emplace(
|
||||||
std::piecewise_construct,
|
std::piecewise_construct,
|
||||||
std::make_tuple(z),
|
std::make_tuple(z),
|
||||||
std::make_tuple()).first;
|
std::make_tuple()).first;
|
||||||
z_regions->second.insert(x);
|
z_regions->second.insert(x);
|
||||||
|
|
||||||
std::tuple<int, int, int, int> &b = bounds[level];
|
std::tuple<int, int, int, int> &b = the_level.bounds;
|
||||||
|
|
||||||
if (x < std::get<0>(b)) std::get<0>(b) = x;
|
if (x < std::get<0>(b)) std::get<0>(b) = x;
|
||||||
if (x > std::get<1>(b)) std::get<1>(b) = x;
|
if (x > std::get<1>(b)) std::get<1>(b) = x;
|
||||||
|
@ -71,12 +76,14 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void addMipmapLevel() {
|
void addMipmapLevel() {
|
||||||
regions.emplace_back();
|
levels.emplace_back(Level {
|
||||||
bounds.emplace_back(INT_MAX, INT_MIN, INT_MAX, INT_MIN);
|
.regions = {},
|
||||||
|
.bounds = {INT_MAX, INT_MIN, INT_MAX, INT_MIN},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t getMipmapLevel() const {
|
size_t getMipmapLevel() const {
|
||||||
return regions.size()-1;
|
return levels.size()-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setSpawn(const std::pair<int32_t, int32_t> &v) {
|
void setSpawn(const std::pair<int32_t, int32_t> &v) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue