Added --geometry support.

master
Miroslav Bendík 2012-11-24 19:25:13 +01:00
parent 5969c61e54
commit 7d15dbf4ed
4 changed files with 64 additions and 1 deletions

View File

@ -55,6 +55,9 @@ drawplayers:
draworigin:
Draw origin indicator, `--draworigin`
geometry:
Limit area to specific geometry, `--geometry -800:-800+1600+1600`
Customization of colors.txt
^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -97,7 +97,11 @@ TileGenerator::TileGenerator():
m_xMin(0),
m_xMax(0),
m_zMin(0),
m_zMax(0)
m_zMax(0),
m_geomX(-50),
m_geomY(-50),
m_geomX2(50),
m_geomY2(50)
{
string colors_txt_data(reinterpret_cast<char *>(colors_txt), colors_txt_len);
istringstream colors_stream(colors_txt_data);
@ -168,6 +172,38 @@ void TileGenerator::setDrawScale(bool drawScale)
}
}
void TileGenerator::setGeometry(int x, int y, int w, int h)
{
if (x > 0) {
m_geomX = (x + 15) / 16;
}
else {
m_geomX = (x - 15) / 16;
}
if (y > 0) {
m_geomY = (y + 15) / 16;
}
else {
m_geomY = (y - 15) / 16;
}
int x2 = x + w;
int y2 = y + h;
if (x2 > 0) {
m_geomX2 = (x2 + 15) / 16;
}
else {
m_geomX2 = (x2 - 15) / 16;
}
if (y2 > 0) {
m_geomY2 = (y2 + 15) / 16;
}
else {
m_geomY2 = (y2 - 15) / 16;
}
}
void TileGenerator::parseColorsFile(const std::string &fileName)
{
ifstream in;
@ -248,6 +284,9 @@ void TileGenerator::loadBlocks()
if(result == SQLITE_ROW) {
sqlite3_int64 blocknum = sqlite3_column_int64(statement, 0);
BlockPos pos = decodeBlockPos(blocknum);
if (pos.x < m_geomX || pos.x >= m_geomX2 || pos.z < m_geomY || pos.z >= m_geomY2) {
continue;
}
if (pos.x < m_xMin) {
m_xMin = pos.x;
}

View File

@ -84,6 +84,7 @@ public:
void setDrawOrigin(bool drawOrigin);
void setDrawPlayers(bool drawPlayers);
void setDrawScale(bool drawScale);
void setGeometry(int x, int y, int w, int h);
void parseColorsFile(const std::string &fileName);
void generate(const std::string &input, const std::string &output);
@ -123,6 +124,10 @@ private:
int m_xMax;
int m_zMin;
int m_zMax;
int m_geomX;
int m_geomY;
int m_geomX2;
int m_geomY2;
int m_mapWidth;
int m_mapHeight;
std::list<std::pair<int, int> > m_positions;

View File

@ -12,6 +12,7 @@
#include <iostream>
#include <map>
#include <string>
#include <sstream>
#include "TileGenerator.h"
using namespace std;
@ -28,6 +29,7 @@ void usage()
--drawscale\n\
--drawplayers\n\
--draworigin\n\
--geometry x:y+w+h\n\
Color format: '#000000'\n";
std::cout << usage_text;
}
@ -46,6 +48,7 @@ int main(int argc, char *argv[])
{"draworigin", no_argument, 0, 'R'},
{"drawplayers", no_argument, 0, 'P'},
{"drawscale", no_argument, 0, 'S'},
{"geometry", required_argument, 0, 'g'},
};
string input;
@ -96,6 +99,19 @@ int main(int argc, char *argv[])
case 'S':
generator.setDrawScale(true);
break;
case 'g': {
istringstream geometry;
geometry.str(optarg);
int x, y, w, h;
char c;
geometry >> x >> c >> y >> w >> h;
if (geometry.fail() || c != ':' || w < 1 || h < 1) {
usage();
exit(-1);
}
generator.setGeometry(x, y, w, h);
}
break;
default:
abort();
}