Skip to content

Commit

Permalink
Coordinates -> Map::Coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
spoutn1k committed Jan 30, 2021
1 parent 3adf552 commit e347fc0
Show file tree
Hide file tree
Showing 18 changed files with 298 additions and 291 deletions.
6 changes: 4 additions & 2 deletions src/block_drawers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,14 @@ void drawLog(IsometricCanvas *canvas, const uint32_t x, const uint32_t y,
axis = metadata["Properties"]["axis"].get<string>();

if (axis == "x") {
if (canvas->map.orientation == NW || canvas->map.orientation == SE)
if (canvas->map.orientation == Map::NW ||
canvas->map.orientation == Map::SE)
target = &spriteZ;
else
target = &spriteX;
} else if (axis == "z") {
if (canvas->map.orientation == NW || canvas->map.orientation == SE)
if (canvas->map.orientation == Map::NW ||
canvas->map.orientation == Map::SE)
target = &spriteX;
else
target = &spriteZ;
Expand Down
36 changes: 17 additions & 19 deletions src/canvas.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include "./canvas.h"
#include "VERSION"
#include "fmt/color.h"
#include "png.h"
#include <vector>

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

void IsometricCanvas::setMap(const Terrain::Coordinates &_map) {
void IsometricCanvas::setMap(const World::Coordinates &_map) {
map = _map;

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

switch (map.orientation) {
case NW:
case Map::NW:
offsetX = map.minX & 0x0f;
offsetZ = map.minZ & 0x0f;
break;
case NE:
case Map::NE:
offsetX = 15 - (map.maxX & 0x0f);
offsetZ = map.minZ & 0x0f;
break;
case SW:
case Map::SW:
offsetX = map.minX & 0x0f;
offsetZ = 15 - (map.maxZ & 0x0f);
break;
case SE:
case Map::SE:
offsetX = 15 - (map.maxX & 0x0f);
offsetZ = 15 - (map.maxZ & 0x0f);
break;
}

if (map.orientation == NE || map.orientation == SW) {
if (map.orientation == Map::NE || map.orientation == Map::SW) {
std::swap(sizeX, sizeZ);
std::swap(offsetX, offsetZ);
}
Expand Down Expand Up @@ -217,21 +215,21 @@ void IsometricCanvas::setMap(const Terrain::Coordinates &_map) {
// y, they come out as the real coordinates.
void IsometricCanvas::orientChunk(int32_t &x, int32_t &z) {
switch (map.orientation) {
case NW:
case Map::NW:
x = (map.minX >> 4) + x;
z = (map.minZ >> 4) + z;
break;
case SW:
case Map::SW:
std::swap(x, z);
x = (map.minX >> 4) + x;
z = (map.maxZ >> 4) - z;
break;
case NE:
case Map::NE:
std::swap(x, z);
x = (map.maxX >> 4) - x;
z = (map.minZ >> 4) + z;
break;
case SE:
case Map::SE:
x = (map.maxX >> 4) - x;
z = (map.maxZ >> 4) - z;
break;
Expand All @@ -244,7 +242,7 @@ void IsometricCanvas::renderTerrain(Terrain::Data &world) {
nXChunks = CHUNK(map.maxX) - CHUNK(map.minX) + 1;
nZChunks = CHUNK(map.maxZ) - CHUNK(map.minZ) + 1;

if (map.orientation == NE || map.orientation == SW)
if (map.orientation == Map::NE || map.orientation == Map::SW)
std::swap(nXChunks, nZChunks);

// world is supposed to have the SAME set of coordinates as the canvas
Expand Down Expand Up @@ -312,17 +310,17 @@ void IsometricCanvas::renderChunk(Terrain::Data &terrain) {
// plane ?
inline void IsometricCanvas::orientSection(uint8_t &x, uint8_t &z) {
switch (map.orientation) {
case NW:
case Map::NW:
return;
case NE:
case Map::NE:
std::swap(x, z);
x = 15 - x;
return;
case SW:
case Map::SW:
std::swap(x, z);
z = 15 - z;
return;
case SE:
case Map::SE:
x = 15 - x;
z = 15 - z;
return;
Expand Down Expand Up @@ -568,8 +566,8 @@ const Colors::Block *IsometricCanvas::nextBlock() {
bool compare(const Canvas &p1, const Canvas &p2) {
// This method is used to order a list of maps. The ordering is done by the
// distance to the top-right corner of the map in North Western orientation.
Terrain::Coordinates c1 = p1.map.orient(Orientation::NW);
Terrain::Coordinates c2 = p2.map.orient(Orientation::NW);
World::Coordinates c1 = p1.map.orient(Map::NW);
World::Coordinates c2 = p2.map.orient(Map::NW);

return (c1.minX + c1.minZ) > (c2.minX + c2.minZ);
}
Expand Down
13 changes: 6 additions & 7 deletions src/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "./section.h"
#include "./worldloader.h"
#include <filesystem>
#include <vector>
#include <map.hpp>

#define CHANSPERPIXEL 4
#define BYTESPERCHAN 1
Expand Down Expand Up @@ -41,7 +41,7 @@ struct Beam {
struct Canvas {
enum BufferType { BYTES, CANVAS, IMAGE, EMPTY };

Terrain::Coordinates map; // The coordinates describing the 3D map
World::Coordinates map; // The coordinates describing the 3D map

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

Canvas(const Terrain::Coordinates &map, const std::filesystem::path &file)
Canvas(const World::Coordinates &map, const fs::path &file)
: map(map), type(IMAGE), drawing(file) {
assert(width() == drawing.image_buffer->get_width());
assert(height() == drawing.image_buffer->get_height());
Expand Down Expand Up @@ -208,8 +208,7 @@ struct Canvas {
struct ImageCanvas : Canvas {
const std::filesystem::path file;

ImageCanvas(const Terrain::Coordinates &map,
const std::filesystem::path &file)
ImageCanvas(const World::Coordinates &map, const fs::path &file)
: Canvas(map, file), file(file) {}
};

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

void setColors(const Colors::Palette &);
void setMap(const Terrain::Coordinates &);
void setMap(const World::Coordinates &);
void setMarkers(uint8_t n, Colors::Marker (*array)[256]) {
totalMarkers = n;
markers = array;
Expand Down
1 change: 1 addition & 0 deletions src/colors.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <filesystem>
#include <json.hpp>
#include <list>
#include <logger.hpp>
#include <map>
#include <string>

Expand Down
2 changes: 1 addition & 1 deletion src/compat.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#if defined(_OPENMP) && defined(_WINDOWS)
#define OMP_FOR_INDEX int
#else
#define OMP_FOR_INDEX std::vector<Terrain::Coordinates>::size_type
#define OMP_FOR_INDEX std::vector<World::Coordinates>::size_type
#endif

#ifdef _WINDOWS
Expand Down
12 changes: 6 additions & 6 deletions src/graphical/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void MainWindow::reset_selection() {
void MainWindow::on_saveSelectButton_clicked() {
QString filename = QFileDialog::getExistingDirectory(
this, tr("Open Save Folder"),
fmt::format("{}/.minecraft/saves", getHome()).c_str());
fmt::format("{}/.minecraft/saves", getHome().string()).c_str());

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

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

ui->minX->setEnabled(true);
ui->minXLabel->setEnabled(true);
Expand Down Expand Up @@ -292,20 +292,20 @@ void MainWindow::on_renderButton_clicked() {

void MainWindow::on_orientationNW_toggled(bool checked) {
if (checked)
options.boundaries.orientation = Orientation::NW;
options.boundaries.orientation = Map::NW;
}

void MainWindow::on_orientationSW_toggled(bool checked) {
if (checked)
options.boundaries.orientation = Orientation::SW;
options.boundaries.orientation = Map::SW;
}

void MainWindow::on_orientationSE_toggled(bool checked) {
if (checked)
options.boundaries.orientation = Orientation::SE;
options.boundaries.orientation = Map::SE;
}

void MainWindow::on_orientationNE_toggled(bool checked) {
if (checked)
options.boundaries.orientation = Orientation::NE;
options.boundaries.orientation = Map::NE;
}
4 changes: 2 additions & 2 deletions src/helper.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "helper.h"
#include <vector>
#include <logger.hpp>

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

std::string getHome() { return std::string(getenv("HOME")); }
fs::path getHome() { return std::string(getenv("HOME")); }
Loading

0 comments on commit e347fc0

Please sign in to comment.