mirror of
https://github.com/minetest/minetestmapper.git
synced 2024-11-22 07:23:46 +01:00
Add --noshading option, Fix SIGABRT because of uncaught exception when any exception occured
This commit is contained in:
parent
3be2d489e2
commit
33f323b1e3
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <climits>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <gdfontmb.h>
|
#include <gdfontmb.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -66,7 +67,9 @@ static inline int readBlockContent(const unsigned char *mapData, int version, in
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw VersionError();
|
std::ostringstream oss;
|
||||||
|
oss << "Unsupported map version " << version;
|
||||||
|
throw std::runtime_error(oss.str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,13 +94,14 @@ TileGenerator::TileGenerator():
|
|||||||
m_drawOrigin(false),
|
m_drawOrigin(false),
|
||||||
m_drawPlayers(false),
|
m_drawPlayers(false),
|
||||||
m_drawScale(false),
|
m_drawScale(false),
|
||||||
|
m_shading(true),
|
||||||
m_border(0),
|
m_border(0),
|
||||||
m_db(0),
|
m_db(0),
|
||||||
m_image(0),
|
m_image(0),
|
||||||
m_xMin(0),
|
m_xMin(INT_MAX),
|
||||||
m_xMax(0),
|
m_xMax(INT_MIN),
|
||||||
m_zMin(0),
|
m_zMin(INT_MAX),
|
||||||
m_zMax(0),
|
m_zMax(INT_MIN),
|
||||||
m_geomX(-50),
|
m_geomX(-50),
|
||||||
m_geomY(-50),
|
m_geomY(-50),
|
||||||
m_geomX2(50),
|
m_geomX2(50),
|
||||||
@ -140,10 +144,10 @@ Color TileGenerator::parseColor(const std::string &color)
|
|||||||
{
|
{
|
||||||
Color parsed;
|
Color parsed;
|
||||||
if (color.length() != 7) {
|
if (color.length() != 7) {
|
||||||
throw ColorError();
|
throw std::runtime_error("Color not 7 characters long");
|
||||||
}
|
}
|
||||||
if (color[0] != '#') {
|
if (color[0] != '#') {
|
||||||
throw ColorError();
|
throw std::runtime_error("Color does not begin with #");
|
||||||
}
|
}
|
||||||
long col = strtol(color.c_str() + 1, NULL, 16);
|
long col = strtol(color.c_str() + 1, NULL, 16);
|
||||||
parsed.b = col % 256;
|
parsed.b = col % 256;
|
||||||
@ -172,6 +176,11 @@ void TileGenerator::setDrawScale(bool drawScale)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TileGenerator::setShading(bool shading)
|
||||||
|
{
|
||||||
|
m_shading = shading;
|
||||||
|
}
|
||||||
|
|
||||||
void TileGenerator::setGeometry(int x, int y, int w, int h)
|
void TileGenerator::setGeometry(int x, int y, int w, int h)
|
||||||
{
|
{
|
||||||
if (x > 0) {
|
if (x > 0) {
|
||||||
@ -268,8 +277,7 @@ void TileGenerator::openDb(const std::string &input)
|
|||||||
{
|
{
|
||||||
string db_name = input + "map.sqlite";
|
string db_name = input + "map.sqlite";
|
||||||
if (sqlite3_open_v2(db_name.c_str(), &m_db, SQLITE_OPEN_READONLY | SQLITE_OPEN_PRIVATECACHE, 0) != SQLITE_OK) {
|
if (sqlite3_open_v2(db_name.c_str(), &m_db, SQLITE_OPEN_READONLY | SQLITE_OPEN_PRIVATECACHE, 0) != SQLITE_OK) {
|
||||||
std::cerr << sqlite3_errmsg(m_db) << ", Database file: " << db_name << std::endl;
|
throw std::runtime_error(std::string(sqlite3_errmsg(m_db)) + ", Database file: " + db_name);
|
||||||
throw DbError();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,7 +317,7 @@ void TileGenerator::loadBlocks()
|
|||||||
m_positions.unique();
|
m_positions.unique();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw DbError();
|
throw std::runtime_error("Failed to get list of MapBlocks");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -339,7 +347,7 @@ void TileGenerator::renderMap()
|
|||||||
sqlite3_stmt *statement;
|
sqlite3_stmt *statement;
|
||||||
string sql = "SELECT pos, data FROM blocks WHERE (pos >= ? AND pos <= ?)";
|
string sql = "SELECT pos, data FROM blocks WHERE (pos >= ? AND pos <= ?)";
|
||||||
if (sqlite3_prepare_v2(m_db, sql.c_str(), sql.length(), &statement, 0) != SQLITE_OK) {
|
if (sqlite3_prepare_v2(m_db, sql.c_str(), sql.length(), &statement, 0) != SQLITE_OK) {
|
||||||
throw DbError();
|
throw std::runtime_error("Failed to get MapBlock");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<int> zlist = getZValueList();
|
std::list<int> zlist = getZValueList();
|
||||||
@ -454,6 +462,7 @@ void TileGenerator::renderMap()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(m_shading)
|
||||||
renderShading(zPos);
|
renderShading(zPos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,15 +56,6 @@ struct BlockPos {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class DbError {
|
|
||||||
};
|
|
||||||
|
|
||||||
class ColorError {
|
|
||||||
};
|
|
||||||
|
|
||||||
class VersionError {
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class TileGenerator
|
class TileGenerator
|
||||||
{
|
{
|
||||||
@ -84,6 +75,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 setShading(bool shading);
|
||||||
void setGeometry(int x, int y, int w, int h);
|
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);
|
||||||
@ -115,6 +107,7 @@ private:
|
|||||||
bool m_drawOrigin;
|
bool m_drawOrigin;
|
||||||
bool m_drawPlayers;
|
bool m_drawPlayers;
|
||||||
bool m_drawScale;
|
bool m_drawScale;
|
||||||
|
bool m_shading;
|
||||||
int m_border;
|
int m_border;
|
||||||
|
|
||||||
sqlite3 *m_db;
|
sqlite3 *m_db;
|
||||||
|
15
mapper.cpp
15
mapper.cpp
@ -29,6 +29,7 @@ void usage()
|
|||||||
" --drawscale\n"
|
" --drawscale\n"
|
||||||
" --drawplayers\n"
|
" --drawplayers\n"
|
||||||
" --draworigin\n"
|
" --draworigin\n"
|
||||||
|
" --noshading\n"
|
||||||
" --geometry x:y+w+h\n"
|
" --geometry x:y+w+h\n"
|
||||||
"Color format: '#000000'\n";
|
"Color format: '#000000'\n";
|
||||||
std::cout << usage_text;
|
std::cout << usage_text;
|
||||||
@ -48,6 +49,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'},
|
||||||
|
{"noshading", no_argument, 0, 'H'},
|
||||||
{"geometry", required_argument, 0, 'g'},
|
{"geometry", required_argument, 0, 'g'},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -63,14 +65,14 @@ int main(int argc, char *argv[])
|
|||||||
if (c == -1) {
|
if (c == -1) {
|
||||||
if (input.empty() || output.empty()) {
|
if (input.empty() || output.empty()) {
|
||||||
usage();
|
usage();
|
||||||
exit(-1);
|
return -1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'h':
|
case 'h':
|
||||||
usage();
|
usage();
|
||||||
exit(0);
|
return 0;
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
input = optarg;
|
input = optarg;
|
||||||
@ -99,6 +101,9 @@ int main(int argc, char *argv[])
|
|||||||
case 'S':
|
case 'S':
|
||||||
generator.setDrawScale(true);
|
generator.setDrawScale(true);
|
||||||
break;
|
break;
|
||||||
|
case 'H':
|
||||||
|
generator.setShading(false);
|
||||||
|
break;
|
||||||
case 'g': {
|
case 'g': {
|
||||||
istringstream geometry;
|
istringstream geometry;
|
||||||
geometry.str(optarg);
|
geometry.str(optarg);
|
||||||
@ -116,5 +121,11 @@ int main(int argc, char *argv[])
|
|||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
generator.generate(input, output);
|
generator.generate(input, output);
|
||||||
|
} catch(std::runtime_error e) {
|
||||||
|
std::cout<<"Exception: "<<e.what()<<std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user