Skip to content

Commit 7d15dbf

Browse files
committed
Added --geometry support.
1 parent 5969c61 commit 7d15dbf

File tree

4 files changed

+64
-1
lines changed

4 files changed

+64
-1
lines changed

README.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ drawplayers:
5555
draworigin:
5656
Draw origin indicator, `--draworigin`
5757

58+
geometry:
59+
Limit area to specific geometry, `--geometry -800:-800+1600+1600`
60+
5861
Customization of colors.txt
5962
^^^^^^^^^^^^^^^^^^^^^^^^^^^
6063

TileGenerator.cpp

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ TileGenerator::TileGenerator():
9797
m_xMin(0),
9898
m_xMax(0),
9999
m_zMin(0),
100-
m_zMax(0)
100+
m_zMax(0),
101+
m_geomX(-50),
102+
m_geomY(-50),
103+
m_geomX2(50),
104+
m_geomY2(50)
101105
{
102106
string colors_txt_data(reinterpret_cast<char *>(colors_txt), colors_txt_len);
103107
istringstream colors_stream(colors_txt_data);
@@ -168,6 +172,38 @@ void TileGenerator::setDrawScale(bool drawScale)
168172
}
169173
}
170174

175+
void TileGenerator::setGeometry(int x, int y, int w, int h)
176+
{
177+
if (x > 0) {
178+
m_geomX = (x + 15) / 16;
179+
}
180+
else {
181+
m_geomX = (x - 15) / 16;
182+
}
183+
if (y > 0) {
184+
m_geomY = (y + 15) / 16;
185+
}
186+
else {
187+
m_geomY = (y - 15) / 16;
188+
}
189+
190+
int x2 = x + w;
191+
int y2 = y + h;
192+
193+
if (x2 > 0) {
194+
m_geomX2 = (x2 + 15) / 16;
195+
}
196+
else {
197+
m_geomX2 = (x2 - 15) / 16;
198+
}
199+
if (y2 > 0) {
200+
m_geomY2 = (y2 + 15) / 16;
201+
}
202+
else {
203+
m_geomY2 = (y2 - 15) / 16;
204+
}
205+
}
206+
171207
void TileGenerator::parseColorsFile(const std::string &fileName)
172208
{
173209
ifstream in;
@@ -248,6 +284,9 @@ void TileGenerator::loadBlocks()
248284
if(result == SQLITE_ROW) {
249285
sqlite3_int64 blocknum = sqlite3_column_int64(statement, 0);
250286
BlockPos pos = decodeBlockPos(blocknum);
287+
if (pos.x < m_geomX || pos.x >= m_geomX2 || pos.z < m_geomY || pos.z >= m_geomY2) {
288+
continue;
289+
}
251290
if (pos.x < m_xMin) {
252291
m_xMin = pos.x;
253292
}

TileGenerator.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class TileGenerator
8484
void setDrawOrigin(bool drawOrigin);
8585
void setDrawPlayers(bool drawPlayers);
8686
void setDrawScale(bool drawScale);
87+
void setGeometry(int x, int y, int w, int h);
8788
void parseColorsFile(const std::string &fileName);
8889
void generate(const std::string &input, const std::string &output);
8990

@@ -123,6 +124,10 @@ class TileGenerator
123124
int m_xMax;
124125
int m_zMin;
125126
int m_zMax;
127+
int m_geomX;
128+
int m_geomY;
129+
int m_geomX2;
130+
int m_geomY2;
126131
int m_mapWidth;
127132
int m_mapHeight;
128133
std::list<std::pair<int, int> > m_positions;

mapper.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <iostream>
1313
#include <map>
1414
#include <string>
15+
#include <sstream>
1516
#include "TileGenerator.h"
1617

1718
using namespace std;
@@ -28,6 +29,7 @@ void usage()
2829
--drawscale\n\
2930
--drawplayers\n\
3031
--draworigin\n\
32+
--geometry x:y+w+h\n\
3133
Color format: '#000000'\n";
3234
std::cout << usage_text;
3335
}
@@ -46,6 +48,7 @@ int main(int argc, char *argv[])
4648
{"draworigin", no_argument, 0, 'R'},
4749
{"drawplayers", no_argument, 0, 'P'},
4850
{"drawscale", no_argument, 0, 'S'},
51+
{"geometry", required_argument, 0, 'g'},
4952
};
5053

5154
string input;
@@ -96,6 +99,19 @@ int main(int argc, char *argv[])
9699
case 'S':
97100
generator.setDrawScale(true);
98101
break;
102+
case 'g': {
103+
istringstream geometry;
104+
geometry.str(optarg);
105+
int x, y, w, h;
106+
char c;
107+
geometry >> x >> c >> y >> w >> h;
108+
if (geometry.fail() || c != ':' || w < 1 || h < 1) {
109+
usage();
110+
exit(-1);
111+
}
112+
generator.setGeometry(x, y, w, h);
113+
}
114+
break;
99115
default:
100116
abort();
101117
}

0 commit comments

Comments
 (0)