mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-03-04 17:23:33 +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, "\"mipmaps\":[");
|
||||
|
||||
for (size_t level = 0; level < regions.size(); level++) {
|
||||
if (level != 0)
|
||||
bool first_level = true;
|
||||
for (const auto &level : levels) {
|
||||
if (!first_level)
|
||||
std::fprintf(f, ",");
|
||||
first_level = false;
|
||||
|
||||
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, "\"bounds\":{");
|
||||
|
@ -63,7 +65,7 @@ void Info::writeJSON(const char *filename) const {
|
|||
std::fprintf(f, "\"regions\":{");
|
||||
|
||||
bool first_z = true;
|
||||
for (const auto &item : regions[level]) {
|
||||
for (const auto &item : level.regions) {
|
||||
if (!first_z)
|
||||
std::fprintf(f, ",");
|
||||
first_z = false;
|
||||
|
|
25
src/Info.hpp
25
src/Info.hpp
|
@ -39,9 +39,14 @@
|
|||
namespace MinedMap {
|
||||
|
||||
class Info {
|
||||
public:
|
||||
struct Level {
|
||||
std::map<int, std::set<int>> regions;
|
||||
std::tuple<int, int, int, int> bounds;
|
||||
};
|
||||
|
||||
private:
|
||||
std::vector<std::map<int, std::set<int>>> regions;
|
||||
std::vector<std::tuple<int, int, int, int>> bounds;
|
||||
std::vector<Level> levels;
|
||||
|
||||
int32_t spawnX, spawnZ;
|
||||
|
||||
|
@ -51,18 +56,18 @@ public:
|
|||
}
|
||||
|
||||
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) {
|
||||
auto &level_r = regions[level];
|
||||
auto z_regions = level_r.emplace(
|
||||
auto &the_level = levels[level];
|
||||
auto z_regions = the_level.regions.emplace(
|
||||
std::piecewise_construct,
|
||||
std::make_tuple(z),
|
||||
std::make_tuple()).first;
|
||||
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<1>(b)) std::get<1>(b) = x;
|
||||
|
@ -71,12 +76,14 @@ public:
|
|||
}
|
||||
|
||||
void addMipmapLevel() {
|
||||
regions.emplace_back();
|
||||
bounds.emplace_back(INT_MAX, INT_MIN, INT_MAX, INT_MIN);
|
||||
levels.emplace_back(Level {
|
||||
.regions = {},
|
||||
.bounds = {INT_MAX, INT_MIN, INT_MAX, INT_MIN},
|
||||
});
|
||||
}
|
||||
|
||||
size_t getMipmapLevel() const {
|
||||
return regions.size()-1;
|
||||
return levels.size()-1;
|
||||
}
|
||||
|
||||
void setSpawn(const std::pair<int32_t, int32_t> &v) {
|
||||
|
|
Loading…
Add table
Reference in a new issue