Skip to content

Commit e347fc0

Browse files
committed
Coordinates -> Map::Coordinates
1 parent 3adf552 commit e347fc0

18 files changed

+298
-291
lines changed

src/block_drawers.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,14 @@ void drawLog(IsometricCanvas *canvas, const uint32_t x, const uint32_t y,
331331
axis = metadata["Properties"]["axis"].get<string>();
332332

333333
if (axis == "x") {
334-
if (canvas->map.orientation == NW || canvas->map.orientation == SE)
334+
if (canvas->map.orientation == Map::NW ||
335+
canvas->map.orientation == Map::SE)
335336
target = &spriteZ;
336337
else
337338
target = &spriteX;
338339
} else if (axis == "z") {
339-
if (canvas->map.orientation == NW || canvas->map.orientation == SE)
340+
if (canvas->map.orientation == Map::NW ||
341+
canvas->map.orientation == Map::SE)
340342
target = &spriteX;
341343
else
342344
target = &spriteZ;

src/canvas.cpp

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#include "./canvas.h"
22
#include "VERSION"
3-
#include "fmt/color.h"
43
#include "png.h"
5-
#include <vector>
64

75
size_t Canvas::_get_line(const uint8_t *data, uint8_t *buffer, size_t bufSize,
86
uint64_t y) const {
@@ -159,32 +157,32 @@ void IsometricCanvas::setColors(const Colors::Palette &colors) {
159157
brightnessLookup[y] = -100 + 200 * float(y) / 255;
160158
}
161159

162-
void IsometricCanvas::setMap(const Terrain::Coordinates &_map) {
160+
void IsometricCanvas::setMap(const World::Coordinates &_map) {
163161
map = _map;
164162

165163
sizeX = map.maxX - map.minX + 1;
166164
sizeZ = map.maxZ - map.minZ + 1;
167165

168166
switch (map.orientation) {
169-
case NW:
167+
case Map::NW:
170168
offsetX = map.minX & 0x0f;
171169
offsetZ = map.minZ & 0x0f;
172170
break;
173-
case NE:
171+
case Map::NE:
174172
offsetX = 15 - (map.maxX & 0x0f);
175173
offsetZ = map.minZ & 0x0f;
176174
break;
177-
case SW:
175+
case Map::SW:
178176
offsetX = map.minX & 0x0f;
179177
offsetZ = 15 - (map.maxZ & 0x0f);
180178
break;
181-
case SE:
179+
case Map::SE:
182180
offsetX = 15 - (map.maxX & 0x0f);
183181
offsetZ = 15 - (map.maxZ & 0x0f);
184182
break;
185183
}
186184

187-
if (map.orientation == NE || map.orientation == SW) {
185+
if (map.orientation == Map::NE || map.orientation == Map::SW) {
188186
std::swap(sizeX, sizeZ);
189187
std::swap(offsetX, offsetZ);
190188
}
@@ -217,21 +215,21 @@ void IsometricCanvas::setMap(const Terrain::Coordinates &_map) {
217215
// y, they come out as the real coordinates.
218216
void IsometricCanvas::orientChunk(int32_t &x, int32_t &z) {
219217
switch (map.orientation) {
220-
case NW:
218+
case Map::NW:
221219
x = (map.minX >> 4) + x;
222220
z = (map.minZ >> 4) + z;
223221
break;
224-
case SW:
222+
case Map::SW:
225223
std::swap(x, z);
226224
x = (map.minX >> 4) + x;
227225
z = (map.maxZ >> 4) - z;
228226
break;
229-
case NE:
227+
case Map::NE:
230228
std::swap(x, z);
231229
x = (map.maxX >> 4) - x;
232230
z = (map.minZ >> 4) + z;
233231
break;
234-
case SE:
232+
case Map::SE:
235233
x = (map.maxX >> 4) - x;
236234
z = (map.maxZ >> 4) - z;
237235
break;
@@ -244,7 +242,7 @@ void IsometricCanvas::renderTerrain(Terrain::Data &world) {
244242
nXChunks = CHUNK(map.maxX) - CHUNK(map.minX) + 1;
245243
nZChunks = CHUNK(map.maxZ) - CHUNK(map.minZ) + 1;
246244

247-
if (map.orientation == NE || map.orientation == SW)
245+
if (map.orientation == Map::NE || map.orientation == Map::SW)
248246
std::swap(nXChunks, nZChunks);
249247

250248
// world is supposed to have the SAME set of coordinates as the canvas
@@ -312,17 +310,17 @@ void IsometricCanvas::renderChunk(Terrain::Data &terrain) {
312310
// plane ?
313311
inline void IsometricCanvas::orientSection(uint8_t &x, uint8_t &z) {
314312
switch (map.orientation) {
315-
case NW:
313+
case Map::NW:
316314
return;
317-
case NE:
315+
case Map::NE:
318316
std::swap(x, z);
319317
x = 15 - x;
320318
return;
321-
case SW:
319+
case Map::SW:
322320
std::swap(x, z);
323321
z = 15 - z;
324322
return;
325-
case SE:
323+
case Map::SE:
326324
x = 15 - x;
327325
z = 15 - z;
328326
return;
@@ -568,8 +566,8 @@ const Colors::Block *IsometricCanvas::nextBlock() {
568566
bool compare(const Canvas &p1, const Canvas &p2) {
569567
// This method is used to order a list of maps. The ordering is done by the
570568
// distance to the top-right corner of the map in North Western orientation.
571-
Terrain::Coordinates c1 = p1.map.orient(Orientation::NW);
572-
Terrain::Coordinates c2 = p2.map.orient(Orientation::NW);
569+
World::Coordinates c1 = p1.map.orient(Map::NW);
570+
World::Coordinates c2 = p2.map.orient(Map::NW);
573571

574572
return (c1.minX + c1.minZ) > (c2.minX + c2.minZ);
575573
}

src/canvas.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "./section.h"
77
#include "./worldloader.h"
88
#include <filesystem>
9-
#include <vector>
9+
#include <map.hpp>
1010

1111
#define CHANSPERPIXEL 4
1212
#define BYTESPERCHAN 1
@@ -41,7 +41,7 @@ struct Beam {
4141
struct Canvas {
4242
enum BufferType { BYTES, CANVAS, IMAGE, EMPTY };
4343

44-
Terrain::Coordinates map; // The coordinates describing the 3D map
44+
World::Coordinates map; // The coordinates describing the 3D map
4545

4646
inline size_t width() const {
4747
if (type != EMPTY)
@@ -159,12 +159,12 @@ struct Canvas {
159159
// Determine the size of the virtual map
160160
// All the maps are oriented as NW to simplify the process
161161
for (auto &fragment : *drawing.canvas_buffer) {
162-
Terrain::Coordinates oriented = fragment.map.orient(Orientation::NW);
162+
World::Coordinates oriented = fragment.map.orient(Map::NW);
163163
map += oriented;
164164
}
165165
}
166166

167-
Canvas(const Terrain::Coordinates &map, const std::filesystem::path &file)
167+
Canvas(const World::Coordinates &map, const fs::path &file)
168168
: map(map), type(IMAGE), drawing(file) {
169169
assert(width() == drawing.image_buffer->get_width());
170170
assert(height() == drawing.image_buffer->get_height());
@@ -208,8 +208,7 @@ struct Canvas {
208208
struct ImageCanvas : Canvas {
209209
const std::filesystem::path file;
210210

211-
ImageCanvas(const Terrain::Coordinates &map,
212-
const std::filesystem::path &file)
211+
ImageCanvas(const World::Coordinates &map, const fs::path &file)
213212
: Canvas(map, file), file(file) {}
214213
};
215214

@@ -255,7 +254,7 @@ struct IsometricCanvas : Canvas {
255254
inline bool empty() const { return !rendered; }
256255

257256
void setColors(const Colors::Palette &);
258-
void setMap(const Terrain::Coordinates &);
257+
void setMap(const World::Coordinates &);
259258
void setMarkers(uint8_t n, Colors::Marker (*array)[256]) {
260259
totalMarkers = n;
261260
markers = array;

src/colors.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <filesystem>
66
#include <json.hpp>
77
#include <list>
8+
#include <logger.hpp>
89
#include <map>
910
#include <string>
1011

src/compat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#if defined(_OPENMP) && defined(_WINDOWS)
22
#define OMP_FOR_INDEX int
33
#else
4-
#define OMP_FOR_INDEX std::vector<Terrain::Coordinates>::size_type
4+
#define OMP_FOR_INDEX std::vector<World::Coordinates>::size_type
55
#endif
66

77
#ifdef _WINDOWS

src/graphical/mainwindow.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void MainWindow::reset_selection() {
8181
void MainWindow::on_saveSelectButton_clicked() {
8282
QString filename = QFileDialog::getExistingDirectory(
8383
this, tr("Open Save Folder"),
84-
fmt::format("{}/.minecraft/saves", getHome()).c_str());
84+
fmt::format("{}/.minecraft/saves", getHome().string()).c_str());
8585

8686
if (filename.isEmpty()) {
8787
statusBar()->showMessage(tr("No directory selected"), 2000);
@@ -163,7 +163,7 @@ void MainWindow::on_dimensionSelectDropDown_currentIndexChanged(int index) {
163163
options.dim = options.save.dimensions[index];
164164
statusBar()->showMessage(tr("Scanning ") + options.regionDir().c_str(), 2000);
165165

166-
Terrain::scanWorldDirectory(options.regionDir(), &options.boundaries);
166+
options.boundaries = options.save.getWorld(options.dim);
167167

168168
ui->minX->setEnabled(true);
169169
ui->minXLabel->setEnabled(true);
@@ -292,20 +292,20 @@ void MainWindow::on_renderButton_clicked() {
292292

293293
void MainWindow::on_orientationNW_toggled(bool checked) {
294294
if (checked)
295-
options.boundaries.orientation = Orientation::NW;
295+
options.boundaries.orientation = Map::NW;
296296
}
297297

298298
void MainWindow::on_orientationSW_toggled(bool checked) {
299299
if (checked)
300-
options.boundaries.orientation = Orientation::SW;
300+
options.boundaries.orientation = Map::SW;
301301
}
302302

303303
void MainWindow::on_orientationSE_toggled(bool checked) {
304304
if (checked)
305-
options.boundaries.orientation = Orientation::SE;
305+
options.boundaries.orientation = Map::SE;
306306
}
307307

308308
void MainWindow::on_orientationNE_toggled(bool checked) {
309309
if (checked)
310-
options.boundaries.orientation = Orientation::NE;
310+
options.boundaries.orientation = Map::NE;
311311
}

src/helper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "helper.h"
2-
#include <vector>
2+
#include <logger.hpp>
33

44
uint32_t _ntohl(uint8_t *val) {
55
return (uint32_t(val[0]) << 24) + (uint32_t(val[1]) << 16) +
@@ -73,4 +73,4 @@ bool prepare_cache(const std::filesystem::path &cache) {
7373
return true;
7474
}
7575

76-
std::string getHome() { return std::string(getenv("HOME")); }
76+
fs::path getHome() { return std::string(getenv("HOME")); }

0 commit comments

Comments
 (0)