mirror of
https://github.com/minetest/minetestmapper.git
synced 2024-11-21 23:13:53 +01:00
Added --geometry support.
This commit is contained in:
parent
5969c61e54
commit
7d15dbf4ed
@ -55,6 +55,9 @@ drawplayers:
|
|||||||
draworigin:
|
draworigin:
|
||||||
Draw origin indicator, `--draworigin`
|
Draw origin indicator, `--draworigin`
|
||||||
|
|
||||||
|
geometry:
|
||||||
|
Limit area to specific geometry, `--geometry -800:-800+1600+1600`
|
||||||
|
|
||||||
Customization of colors.txt
|
Customization of colors.txt
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
@ -97,7 +97,11 @@ TileGenerator::TileGenerator():
|
|||||||
m_xMin(0),
|
m_xMin(0),
|
||||||
m_xMax(0),
|
m_xMax(0),
|
||||||
m_zMin(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);
|
string colors_txt_data(reinterpret_cast<char *>(colors_txt), colors_txt_len);
|
||||||
istringstream colors_stream(colors_txt_data);
|
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)
|
void TileGenerator::parseColorsFile(const std::string &fileName)
|
||||||
{
|
{
|
||||||
ifstream in;
|
ifstream in;
|
||||||
@ -248,6 +284,9 @@ void TileGenerator::loadBlocks()
|
|||||||
if(result == SQLITE_ROW) {
|
if(result == SQLITE_ROW) {
|
||||||
sqlite3_int64 blocknum = sqlite3_column_int64(statement, 0);
|
sqlite3_int64 blocknum = sqlite3_column_int64(statement, 0);
|
||||||
BlockPos pos = decodeBlockPos(blocknum);
|
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) {
|
if (pos.x < m_xMin) {
|
||||||
m_xMin = pos.x;
|
m_xMin = pos.x;
|
||||||
}
|
}
|
||||||
|
@ -84,6 +84,7 @@ public:
|
|||||||
void setDrawOrigin(bool drawOrigin);
|
void setDrawOrigin(bool drawOrigin);
|
||||||
void setDrawPlayers(bool drawPlayers);
|
void setDrawPlayers(bool drawPlayers);
|
||||||
void setDrawScale(bool drawScale);
|
void setDrawScale(bool drawScale);
|
||||||
|
void setGeometry(int x, int y, int w, int h);
|
||||||
void parseColorsFile(const std::string &fileName);
|
void parseColorsFile(const std::string &fileName);
|
||||||
void generate(const std::string &input, const std::string &output);
|
void generate(const std::string &input, const std::string &output);
|
||||||
|
|
||||||
@ -123,6 +124,10 @@ private:
|
|||||||
int m_xMax;
|
int m_xMax;
|
||||||
int m_zMin;
|
int m_zMin;
|
||||||
int m_zMax;
|
int m_zMax;
|
||||||
|
int m_geomX;
|
||||||
|
int m_geomY;
|
||||||
|
int m_geomX2;
|
||||||
|
int m_geomY2;
|
||||||
int m_mapWidth;
|
int m_mapWidth;
|
||||||
int m_mapHeight;
|
int m_mapHeight;
|
||||||
std::list<std::pair<int, int> > m_positions;
|
std::list<std::pair<int, int> > m_positions;
|
||||||
|
16
mapper.cpp
16
mapper.cpp
@ -12,6 +12,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
#include "TileGenerator.h"
|
#include "TileGenerator.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@ -28,6 +29,7 @@ void usage()
|
|||||||
--drawscale\n\
|
--drawscale\n\
|
||||||
--drawplayers\n\
|
--drawplayers\n\
|
||||||
--draworigin\n\
|
--draworigin\n\
|
||||||
|
--geometry x:y+w+h\n\
|
||||||
Color format: '#000000'\n";
|
Color format: '#000000'\n";
|
||||||
std::cout << usage_text;
|
std::cout << usage_text;
|
||||||
}
|
}
|
||||||
@ -46,6 +48,7 @@ int main(int argc, char *argv[])
|
|||||||
{"draworigin", no_argument, 0, 'R'},
|
{"draworigin", no_argument, 0, 'R'},
|
||||||
{"drawplayers", no_argument, 0, 'P'},
|
{"drawplayers", no_argument, 0, 'P'},
|
||||||
{"drawscale", no_argument, 0, 'S'},
|
{"drawscale", no_argument, 0, 'S'},
|
||||||
|
{"geometry", required_argument, 0, 'g'},
|
||||||
};
|
};
|
||||||
|
|
||||||
string input;
|
string input;
|
||||||
@ -96,6 +99,19 @@ int main(int argc, char *argv[])
|
|||||||
case 'S':
|
case 'S':
|
||||||
generator.setDrawScale(true);
|
generator.setDrawScale(true);
|
||||||
break;
|
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:
|
default:
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user