2012-08-23 03:46:22 -07:00
|
|
|
/*
|
|
|
|
* =====================================================================
|
|
|
|
* Version: 1.0
|
|
|
|
* Created: 23.08.2012 12:35:53
|
|
|
|
* Author: Miroslav Bendík
|
|
|
|
* Company: LinuxOS.sk
|
|
|
|
* =====================================================================
|
|
|
|
*/
|
|
|
|
|
2012-08-23 05:21:34 -07:00
|
|
|
#include <cstdio>
|
2012-08-23 03:55:31 -07:00
|
|
|
#include <cstdlib>
|
2014-03-05 08:19:37 -08:00
|
|
|
#include <climits>
|
2012-08-23 03:55:31 -07:00
|
|
|
#include <fstream>
|
2012-08-25 06:06:11 -07:00
|
|
|
#include <gdfontmb.h>
|
2012-08-23 03:55:31 -07:00
|
|
|
#include <iostream>
|
2012-08-24 00:46:14 -07:00
|
|
|
#include <sstream>
|
2014-03-09 04:32:13 -07:00
|
|
|
#include <stdexcept>
|
2014-02-16 13:13:31 -08:00
|
|
|
#include <cerrno>
|
|
|
|
#include <cstring>
|
2012-09-01 04:01:31 -07:00
|
|
|
#include "config.h"
|
2012-09-01 07:40:18 -07:00
|
|
|
#include "PlayerAttributes.h"
|
2012-08-23 03:46:22 -07:00
|
|
|
#include "TileGenerator.h"
|
2012-09-18 01:43:34 -07:00
|
|
|
#include "ZlibDecompressor.h"
|
2012-09-01 06:51:02 -07:00
|
|
|
#include "colors.h"
|
2014-03-05 12:41:27 -08:00
|
|
|
#include "db-sqlite3.h"
|
|
|
|
#if USE_LEVELDB
|
|
|
|
#include "db-leveldb.h"
|
|
|
|
#endif
|
2012-08-23 03:46:22 -07:00
|
|
|
|
2012-08-23 03:55:31 -07:00
|
|
|
using namespace std;
|
|
|
|
|
2014-03-05 12:41:27 -08:00
|
|
|
static inline int64_t pythonmodulo(int64_t i, int64_t mod)
|
2012-08-24 22:49:46 -07:00
|
|
|
{
|
|
|
|
if (i >= 0) {
|
|
|
|
return i % mod;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return mod - ((-i) % mod);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int unsignedToSigned(long i, long max_positive)
|
|
|
|
{
|
|
|
|
if (i < max_positive) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return i - 2l * max_positive;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-18 01:15:50 -07:00
|
|
|
static inline uint16_t readU16(const unsigned char *data)
|
2012-08-24 22:49:46 -07:00
|
|
|
{
|
2012-09-18 01:15:50 -07:00
|
|
|
return data[0] << 8 | data[1];
|
2012-08-24 22:49:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int rgb2int(uint8_t r, uint8_t g, uint8_t b)
|
|
|
|
{
|
|
|
|
return (r << 16) + (g << 8) + b;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int readBlockContent(const unsigned char *mapData, int version, int datapos)
|
|
|
|
{
|
|
|
|
if (version >= 24) {
|
|
|
|
size_t index = datapos << 1;
|
|
|
|
return (mapData[index] << 8) | mapData[index + 1];
|
|
|
|
}
|
|
|
|
else if (version >= 20) {
|
|
|
|
if (mapData[datapos] <= 0x80) {
|
|
|
|
return mapData[datapos];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return (int(mapData[datapos]) << 4) | (int(mapData[datapos + 0x2000]) >> 4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2014-03-05 08:19:37 -08:00
|
|
|
std::ostringstream oss;
|
|
|
|
oss << "Unsupported map version " << version;
|
|
|
|
throw std::runtime_error(oss.str());
|
2012-08-24 22:49:46 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-25 04:19:58 -07:00
|
|
|
static inline int colorSafeBounds(int color)
|
|
|
|
{
|
|
|
|
if (color > 255) {
|
|
|
|
return 255;
|
|
|
|
}
|
|
|
|
else if (color < 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-23 03:46:22 -07:00
|
|
|
TileGenerator::TileGenerator():
|
2014-03-23 10:35:00 -07:00
|
|
|
verboseCoordinates(false),
|
2014-03-24 14:43:32 -07:00
|
|
|
verboseStatistics(false),
|
2012-08-24 00:46:14 -07:00
|
|
|
m_bgColor(255, 255, 255),
|
|
|
|
m_scaleColor(0, 0, 0),
|
|
|
|
m_originColor(255, 0, 0),
|
|
|
|
m_playerColor(255, 0, 0),
|
2012-08-23 03:46:22 -07:00
|
|
|
m_drawOrigin(false),
|
|
|
|
m_drawPlayers(false),
|
|
|
|
m_drawScale(false),
|
2014-03-05 08:19:37 -08:00
|
|
|
m_shading(true),
|
2012-08-25 05:11:55 -07:00
|
|
|
m_border(0),
|
2014-03-05 12:41:27 -08:00
|
|
|
m_backend("sqlite3"),
|
2014-02-16 12:24:32 -08:00
|
|
|
m_forceGeom(false),
|
2012-08-23 05:21:34 -07:00
|
|
|
m_image(0),
|
2014-03-23 11:47:49 -07:00
|
|
|
m_xMin(INT_MAX/16-1),
|
|
|
|
m_xMax(INT_MIN/16+1),
|
|
|
|
m_zMin(INT_MAX/16-1),
|
|
|
|
m_zMax(INT_MIN/16+1),
|
|
|
|
m_yMin(INT_MAX/16-1),
|
|
|
|
m_yMax(INT_MIN/16+1),
|
|
|
|
m_reqXMin(INT_MIN/16+1),
|
|
|
|
m_reqXMax(INT_MAX/16-1),
|
|
|
|
m_reqYMin(INT_MIN/16+1),
|
|
|
|
m_reqYMax(INT_MAX/16-1),
|
|
|
|
m_reqZMin(INT_MIN/16+1),
|
|
|
|
m_reqZMax(INT_MAX/16-1),
|
|
|
|
m_reqYMinNode(0),
|
|
|
|
m_reqYMaxNode(15)
|
2012-08-23 03:46:22 -07:00
|
|
|
{
|
2012-09-01 06:51:02 -07:00
|
|
|
string colors_txt_data(reinterpret_cast<char *>(colors_txt), colors_txt_len);
|
|
|
|
istringstream colors_stream(colors_txt_data);
|
|
|
|
parseColorsStream(colors_stream);
|
2012-08-23 03:46:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TileGenerator::~TileGenerator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void TileGenerator::setBgColor(const std::string &bgColor)
|
|
|
|
{
|
2012-08-23 05:43:11 -07:00
|
|
|
m_bgColor = parseColor(bgColor);
|
2012-08-23 03:46:22 -07:00
|
|
|
}
|
|
|
|
|
2014-02-16 12:24:32 -08:00
|
|
|
void TileGenerator::setForceGeom(bool forceGeom)
|
|
|
|
{
|
|
|
|
m_forceGeom = forceGeom;
|
|
|
|
}
|
|
|
|
|
2012-08-23 03:46:22 -07:00
|
|
|
void TileGenerator::setScaleColor(const std::string &scaleColor)
|
|
|
|
{
|
2012-08-23 05:43:11 -07:00
|
|
|
m_scaleColor = parseColor(scaleColor);
|
2012-08-23 03:46:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void TileGenerator::setOriginColor(const std::string &originColor)
|
|
|
|
{
|
2012-08-23 05:43:11 -07:00
|
|
|
m_originColor = parseColor(originColor);
|
2012-08-23 03:46:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void TileGenerator::setPlayerColor(const std::string &playerColor)
|
|
|
|
{
|
2012-08-23 05:43:11 -07:00
|
|
|
m_playerColor = parseColor(playerColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
Color TileGenerator::parseColor(const std::string &color)
|
|
|
|
{
|
|
|
|
Color parsed;
|
|
|
|
if (color.length() != 7) {
|
2014-03-05 08:19:37 -08:00
|
|
|
throw std::runtime_error("Color not 7 characters long");
|
2012-08-23 05:43:11 -07:00
|
|
|
}
|
|
|
|
if (color[0] != '#') {
|
2014-03-05 08:19:37 -08:00
|
|
|
throw std::runtime_error("Color does not begin with #");
|
2012-08-23 05:43:11 -07:00
|
|
|
}
|
|
|
|
long col = strtol(color.c_str() + 1, NULL, 16);
|
|
|
|
parsed.b = col % 256;
|
|
|
|
col = col / 256;
|
|
|
|
parsed.g = col % 256;
|
|
|
|
col = col / 256;
|
|
|
|
parsed.r = col % 256;
|
|
|
|
return parsed;
|
2012-08-23 03:46:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void TileGenerator::setDrawOrigin(bool drawOrigin)
|
|
|
|
{
|
|
|
|
m_drawOrigin = drawOrigin;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TileGenerator::setDrawPlayers(bool drawPlayers)
|
|
|
|
{
|
|
|
|
m_drawPlayers = drawPlayers;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TileGenerator::setDrawScale(bool drawScale)
|
|
|
|
{
|
|
|
|
m_drawScale = drawScale;
|
2012-08-25 05:11:55 -07:00
|
|
|
if (m_drawScale) {
|
|
|
|
m_border = 40;
|
|
|
|
}
|
2012-08-23 03:46:22 -07:00
|
|
|
}
|
|
|
|
|
2014-03-05 08:19:37 -08:00
|
|
|
void TileGenerator::setShading(bool shading)
|
|
|
|
{
|
|
|
|
m_shading = shading;
|
|
|
|
}
|
|
|
|
|
2012-11-24 10:25:13 -08:00
|
|
|
void TileGenerator::setGeometry(int x, int y, int w, int h)
|
|
|
|
{
|
|
|
|
if (x > 0) {
|
2014-03-23 11:47:49 -07:00
|
|
|
m_reqXMin = x / 16;
|
2012-11-24 10:25:13 -08:00
|
|
|
}
|
|
|
|
else {
|
2014-03-23 11:47:49 -07:00
|
|
|
m_reqXMin = (x - 15) / 16;
|
2012-11-24 10:25:13 -08:00
|
|
|
}
|
|
|
|
if (y > 0) {
|
2014-03-23 11:47:49 -07:00
|
|
|
m_reqZMin = y / 16;
|
2012-11-24 10:25:13 -08:00
|
|
|
}
|
|
|
|
else {
|
2014-03-23 11:47:49 -07:00
|
|
|
m_reqZMin = (y - 15) / 16;
|
2012-11-24 10:25:13 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
int x2 = x + w;
|
|
|
|
int y2 = y + h;
|
|
|
|
|
|
|
|
if (x2 > 0) {
|
2014-03-23 11:47:49 -07:00
|
|
|
m_reqXMax = x2 / 16;
|
2012-11-24 10:25:13 -08:00
|
|
|
}
|
|
|
|
else {
|
2014-03-23 11:47:49 -07:00
|
|
|
m_reqXMax = (x2 - 15) / 16;
|
2012-11-24 10:25:13 -08:00
|
|
|
}
|
|
|
|
if (y2 > 0) {
|
2014-03-23 11:47:49 -07:00
|
|
|
m_reqZMax = y2 / 16;
|
2012-11-24 10:25:13 -08:00
|
|
|
}
|
|
|
|
else {
|
2014-03-23 11:47:49 -07:00
|
|
|
m_reqZMax = (y2 - 15) / 16;
|
2012-11-24 10:25:13 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-05 09:06:05 -08:00
|
|
|
void TileGenerator::setMinY(int y)
|
|
|
|
{
|
2014-03-23 11:47:49 -07:00
|
|
|
if (y > 0) {
|
|
|
|
m_reqYMin = y / 16;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_reqYMin = (y - 15) / 16;
|
|
|
|
}
|
|
|
|
m_reqYMinNode = y - 16 * m_reqYMin;
|
2014-03-05 09:06:05 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TileGenerator::setMaxY(int y)
|
|
|
|
{
|
2014-03-23 11:47:49 -07:00
|
|
|
if (y > 0) {
|
|
|
|
m_reqYMax = y / 16;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_reqYMax = (y - 15) / 16;
|
|
|
|
}
|
|
|
|
m_reqYMaxNode = y - 16 * m_reqYMax;
|
2014-03-05 09:06:05 -08:00
|
|
|
}
|
|
|
|
|
2012-08-23 03:55:31 -07:00
|
|
|
void TileGenerator::parseColorsFile(const std::string &fileName)
|
|
|
|
{
|
|
|
|
ifstream in;
|
|
|
|
in.open(fileName.c_str(), ifstream::in);
|
|
|
|
if (!in.is_open()) {
|
2012-09-01 06:51:02 -07:00
|
|
|
return;
|
2012-08-23 03:55:31 -07:00
|
|
|
}
|
2012-09-01 06:51:02 -07:00
|
|
|
parseColorsStream(in);
|
2012-08-23 03:55:31 -07:00
|
|
|
}
|
|
|
|
|
2014-03-05 12:41:27 -08:00
|
|
|
void TileGenerator::setBackend(std::string backend)
|
|
|
|
{
|
|
|
|
m_backend = backend;
|
|
|
|
}
|
|
|
|
|
2012-08-23 05:21:34 -07:00
|
|
|
void TileGenerator::generate(const std::string &input, const std::string &output)
|
2012-08-23 04:32:22 -07:00
|
|
|
{
|
2012-09-01 04:41:00 -07:00
|
|
|
string input_path = input;
|
|
|
|
if (input_path[input.length() - 1] != PATH_SEPARATOR) {
|
|
|
|
input_path += PATH_SEPARATOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
openDb(input_path);
|
2012-08-23 04:32:22 -07:00
|
|
|
loadBlocks();
|
2012-08-23 05:21:34 -07:00
|
|
|
createImage();
|
2012-08-23 06:35:00 -07:00
|
|
|
renderMap();
|
2012-08-25 05:11:55 -07:00
|
|
|
if (m_drawScale) {
|
|
|
|
renderScale();
|
|
|
|
}
|
2012-08-25 06:21:51 -07:00
|
|
|
if (m_drawOrigin) {
|
|
|
|
renderOrigin();
|
|
|
|
}
|
2012-08-25 07:29:41 -07:00
|
|
|
if (m_drawPlayers) {
|
2012-09-01 04:41:00 -07:00
|
|
|
renderPlayers(input_path);
|
2012-08-25 07:29:41 -07:00
|
|
|
}
|
2012-08-23 05:21:34 -07:00
|
|
|
writeImage(output);
|
2012-08-25 07:41:53 -07:00
|
|
|
printUnknown();
|
2012-08-23 04:32:22 -07:00
|
|
|
}
|
|
|
|
|
2012-09-01 06:51:02 -07:00
|
|
|
void TileGenerator::parseColorsStream(std::istream &in)
|
|
|
|
{
|
|
|
|
while (in.good()) {
|
|
|
|
string name;
|
|
|
|
Color color;
|
|
|
|
in >> name;
|
|
|
|
if (name[0] == '#') {
|
|
|
|
in.ignore(65536, '\n');
|
|
|
|
in >> name;
|
|
|
|
}
|
|
|
|
while (name == "\n" && in.good()) {
|
|
|
|
in >> name;
|
|
|
|
}
|
|
|
|
int r, g, b;
|
|
|
|
in >> r;
|
|
|
|
in >> g;
|
|
|
|
in >> b;
|
|
|
|
if (in.good()) {
|
|
|
|
color.r = r;
|
|
|
|
color.g = g;
|
|
|
|
color.b = b;
|
|
|
|
m_colors[name] = color;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-23 04:32:22 -07:00
|
|
|
void TileGenerator::openDb(const std::string &input)
|
|
|
|
{
|
2014-03-05 12:41:27 -08:00
|
|
|
if(m_backend == "sqlite3")
|
|
|
|
m_db = new DBSQLite3(input);
|
|
|
|
#if USE_LEVELDB
|
2014-03-05 13:40:01 -08:00
|
|
|
else if(m_backend == "leveldb")
|
2014-03-05 12:41:27 -08:00
|
|
|
m_db = new DBLevelDB(input);
|
|
|
|
#endif
|
|
|
|
else
|
|
|
|
throw std::runtime_error(((std::string) "Unknown map backend: ") + m_backend);
|
2012-08-23 04:32:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void TileGenerator::loadBlocks()
|
|
|
|
{
|
2014-03-23 12:52:58 -07:00
|
|
|
int mapXMin, mapXMax;
|
|
|
|
int mapYMin, mapYMax;
|
|
|
|
int mapZMin, mapZMax;
|
|
|
|
int geomYMin, geomYMax;
|
2014-03-23 12:39:02 -07:00
|
|
|
long long world_blocks;
|
|
|
|
long long map_blocks;
|
2014-03-23 10:35:00 -07:00
|
|
|
if (verboseCoordinates) {
|
2014-03-23 12:52:58 -07:00
|
|
|
cout << "Requested Geometry: "
|
2014-03-23 11:47:49 -07:00
|
|
|
<< m_reqXMin*16 << "," << m_reqYMin*16+m_reqYMinNode << "," << m_reqZMin*16 << ".."
|
|
|
|
<< m_reqXMax*16+15 << "," << m_reqYMax*16+m_reqYMaxNode << "," << m_reqZMax*16+15
|
2014-03-23 10:35:00 -07:00
|
|
|
<< " ("
|
2014-03-23 11:47:49 -07:00
|
|
|
<< m_reqXMin << "," << m_reqYMin << "," << m_reqZMin << ".."
|
|
|
|
<< m_reqXMax << "," << m_reqYMax << "," << m_reqZMax
|
2014-03-23 10:35:00 -07:00
|
|
|
<< ")\n";
|
|
|
|
}
|
2014-03-23 12:52:58 -07:00
|
|
|
mapXMin = INT_MAX/16-1;
|
|
|
|
mapXMax = -INT_MIN/16+1;
|
|
|
|
mapYMin = INT_MAX/16-1;
|
|
|
|
mapYMax = -INT_MIN/16+1;
|
|
|
|
mapZMin = INT_MAX/16-1;
|
|
|
|
mapZMax = -INT_MIN/16+1;
|
|
|
|
geomYMin = INT_MAX/16-1;
|
|
|
|
geomYMax = -INT_MIN/16+1;
|
2014-03-05 12:41:27 -08:00
|
|
|
std::vector<int64_t> vec = m_db->getBlockPos();
|
2014-03-23 12:39:02 -07:00
|
|
|
world_blocks = 0;
|
|
|
|
map_blocks = 0;
|
2014-03-05 12:41:27 -08:00
|
|
|
for(unsigned int i = 0; i < vec.size(); i++) {
|
2014-03-23 12:39:02 -07:00
|
|
|
world_blocks ++;
|
2014-03-05 12:41:27 -08:00
|
|
|
BlockPos pos = decodeBlockPos(vec[i]);
|
2014-03-23 12:52:58 -07:00
|
|
|
if (pos.x < mapXMin) {
|
|
|
|
mapXMin = pos.x;
|
|
|
|
}
|
|
|
|
if (pos.x > mapXMax) {
|
|
|
|
mapXMax = pos.x;
|
|
|
|
}
|
|
|
|
if (pos.y < mapYMin) {
|
|
|
|
mapYMin = pos.y;
|
|
|
|
}
|
|
|
|
if (pos.y > mapYMax) {
|
|
|
|
mapYMax = pos.y;
|
|
|
|
}
|
|
|
|
if (pos.z < mapZMin) {
|
|
|
|
mapZMin = pos.z;
|
|
|
|
}
|
|
|
|
if (pos.z > mapZMax) {
|
|
|
|
mapZMax = pos.z;
|
|
|
|
}
|
|
|
|
if (pos.x < m_reqXMin || pos.x > m_reqXMax || pos.z < m_reqZMin || pos.z > m_reqZMax) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (pos.y < geomYMin) {
|
|
|
|
geomYMin = pos.y;
|
|
|
|
}
|
|
|
|
if (pos.y > geomYMax) {
|
|
|
|
geomYMax = pos.y;
|
|
|
|
}
|
|
|
|
if (pos.y < m_reqYMin || pos.y > m_reqYMax) {
|
2014-03-05 12:41:27 -08:00
|
|
|
continue;
|
|
|
|
}
|
2014-03-23 12:39:02 -07:00
|
|
|
map_blocks++;
|
2014-03-05 12:41:27 -08:00
|
|
|
if (pos.y < m_yMin) {
|
2014-03-23 11:47:49 -07:00
|
|
|
m_yMin = pos.y;
|
2014-03-05 12:41:27 -08:00
|
|
|
}
|
|
|
|
if (pos.y > m_yMax) {
|
2014-03-23 11:47:49 -07:00
|
|
|
m_yMax = pos.y;
|
2012-08-23 04:32:22 -07:00
|
|
|
}
|
2014-03-05 12:41:27 -08:00
|
|
|
if (pos.x < m_xMin) {
|
|
|
|
m_xMin = pos.x;
|
|
|
|
}
|
|
|
|
if (pos.x > m_xMax) {
|
|
|
|
m_xMax = pos.x;
|
|
|
|
}
|
|
|
|
if (pos.z < m_zMin) {
|
|
|
|
m_zMin = pos.z;
|
|
|
|
}
|
|
|
|
if (pos.z > m_zMax) {
|
|
|
|
m_zMax = pos.z;
|
|
|
|
}
|
2014-03-24 14:43:32 -07:00
|
|
|
m_positions.push_back(pos);
|
2012-08-23 04:32:22 -07:00
|
|
|
}
|
2014-03-23 12:52:58 -07:00
|
|
|
if (verboseCoordinates) {
|
|
|
|
cout << "World Geometry: "
|
|
|
|
<< mapXMin*16 << "," << mapYMin*16 << "," << mapZMin*16 << ".."
|
|
|
|
<< mapXMax*16+15 << "," << mapYMax*16+15 << "," << mapZMax*16+15
|
|
|
|
<< " ("
|
|
|
|
<< mapXMin << "," << mapYMin << "," << mapZMin << ".."
|
|
|
|
<< mapXMax << "," << mapYMax << "," << mapZMax
|
2014-03-23 12:39:02 -07:00
|
|
|
<< ") blocks: " << world_blocks << "\n";
|
2014-03-23 12:52:58 -07:00
|
|
|
}
|
2014-02-16 12:24:32 -08:00
|
|
|
if (m_forceGeom) {
|
|
|
|
if (verboseCoordinates) {
|
2014-03-23 12:52:58 -07:00
|
|
|
cout << "Minimal Map Geometry: "
|
2014-02-16 12:24:32 -08:00
|
|
|
<< m_xMin*16 << "," << m_yMin*16+m_reqYMinNode << "," << m_zMin*16 << ".."
|
|
|
|
<< m_xMax*16+15 << "," << m_yMax*16+m_reqYMaxNode << "," << m_zMax*16+15
|
|
|
|
<< " ("
|
|
|
|
<< m_xMin << "," << m_yMin << "," << m_zMin << ".."
|
|
|
|
<< m_xMax << "," << m_yMax << "," << m_zMax
|
|
|
|
<< ")\n";
|
|
|
|
}
|
|
|
|
m_xMin = m_reqXMin;
|
|
|
|
m_xMax = m_reqXMax;
|
|
|
|
m_zMin = m_reqZMin;
|
|
|
|
m_zMax = m_reqZMax;
|
|
|
|
}
|
2014-03-23 10:35:00 -07:00
|
|
|
if (verboseCoordinates) {
|
2014-03-23 12:52:58 -07:00
|
|
|
cout << "Map Vertical Limits: x," << geomYMin*16 << ",z..x," << geomYMax*16+15 << ",z (x," << geomYMin << ",z..x," << geomYMax << ",z)\n";
|
|
|
|
cout << "Map Output Geometry: "
|
2014-03-23 11:47:49 -07:00
|
|
|
<< m_xMin*16 << "," << m_yMin*16+m_reqYMinNode << "," << m_zMin*16 << ".."
|
|
|
|
<< m_xMax*16+15 << "," << m_yMax*16+m_reqYMaxNode << "," << m_zMax*16+15
|
2014-03-23 10:35:00 -07:00
|
|
|
<< " ("
|
2014-03-23 11:47:49 -07:00
|
|
|
<< m_xMin << "," << m_yMin << "," << m_zMin << ".."
|
|
|
|
<< m_xMax << "," << m_yMax << "," << m_zMax
|
2014-03-23 12:39:02 -07:00
|
|
|
<< ") blocks: " << map_blocks << "\n";
|
2014-03-23 10:35:00 -07:00
|
|
|
}
|
2014-03-22 01:30:14 -07:00
|
|
|
m_positions.sort();
|
2012-08-23 04:32:22 -07:00
|
|
|
}
|
|
|
|
|
2014-03-05 12:41:27 -08:00
|
|
|
inline BlockPos TileGenerator::decodeBlockPos(int64_t blockId) const
|
2012-08-23 04:32:22 -07:00
|
|
|
{
|
|
|
|
BlockPos pos;
|
2012-08-24 22:49:46 -07:00
|
|
|
pos.x = unsignedToSigned(pythonmodulo(blockId, 4096), 2048);
|
2012-08-23 05:06:16 -07:00
|
|
|
blockId = (blockId - pos.x) / 4096;
|
2012-08-24 22:49:46 -07:00
|
|
|
pos.y = unsignedToSigned(pythonmodulo(blockId, 4096), 2048);
|
2012-08-23 05:06:16 -07:00
|
|
|
blockId = (blockId - pos.y) / 4096;
|
2012-08-24 22:49:46 -07:00
|
|
|
pos.z = unsignedToSigned(pythonmodulo(blockId, 4096), 2048);
|
2012-08-23 04:32:22 -07:00
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
2012-08-23 05:21:34 -07:00
|
|
|
void TileGenerator::createImage()
|
|
|
|
{
|
2012-08-25 04:19:58 -07:00
|
|
|
m_mapWidth = (m_xMax - m_xMin + 1) * 16;
|
|
|
|
m_mapHeight = (m_zMax - m_zMin + 1) * 16;
|
2012-08-25 05:11:55 -07:00
|
|
|
m_image = gdImageCreateTrueColor(m_mapWidth + m_border, m_mapHeight + m_border);
|
2012-08-25 04:19:58 -07:00
|
|
|
m_blockPixelAttributes.setWidth(m_mapWidth);
|
2012-08-23 05:21:34 -07:00
|
|
|
// Background
|
2012-08-25 05:11:55 -07:00
|
|
|
gdImageFilledRectangle(m_image, 0, 0, m_mapWidth + m_border - 1, m_mapHeight + m_border -1, rgb2int(m_bgColor.r, m_bgColor.g, m_bgColor.b));
|
2012-08-23 05:21:34 -07:00
|
|
|
}
|
|
|
|
|
2014-03-05 12:41:27 -08:00
|
|
|
std::map<int, TileGenerator::BlockList> TileGenerator::getBlocksOnZ(int zPos)
|
2012-08-23 06:35:00 -07:00
|
|
|
{
|
2014-03-05 12:41:27 -08:00
|
|
|
DBBlockList in = m_db->getBlocksOnZ(zPos);
|
|
|
|
std::map<int, BlockList> out;
|
|
|
|
for(DBBlockList::const_iterator it = in.begin(); it != in.end(); ++it) {
|
|
|
|
Block b = Block(decodeBlockPos(it->first), it->second);
|
|
|
|
if(out.find(b.first.x) == out.end()) {
|
|
|
|
BlockList bl;
|
|
|
|
out[b.first.x] = bl;
|
|
|
|
}
|
|
|
|
out[b.first.x].push_back(b);
|
2012-08-23 06:35:00 -07:00
|
|
|
}
|
2014-03-05 12:41:27 -08:00
|
|
|
return out;
|
|
|
|
}
|
2012-08-23 06:35:00 -07:00
|
|
|
|
2014-03-24 14:43:32 -07:00
|
|
|
TileGenerator::Block TileGenerator::getBlockOnPos(BlockPos pos)
|
|
|
|
{
|
|
|
|
int64_t iPos;
|
|
|
|
iPos = pos.x;
|
|
|
|
iPos += static_cast<int64_t>(pos.y) << 12;
|
|
|
|
iPos += static_cast<int64_t>(pos.z) << 24;
|
|
|
|
DBBlock in = m_db->getBlockOnPos(iPos);
|
|
|
|
Block out(pos,(const unsigned char *)"");
|
|
|
|
|
|
|
|
if (!in.second.empty()) {
|
|
|
|
out = Block(decodeBlockPos(in.first), in.second);
|
|
|
|
// Verify. Just to be sure...
|
|
|
|
if (pos.x != out.first.x || pos.y != out.first.y || pos.z != out.first.z) {
|
|
|
|
std::ostringstream oss;
|
|
|
|
oss << "Got unexpexted block: "
|
|
|
|
<< out.first.x << "," << out.first.y << "," << out.first.z
|
|
|
|
<< " from database. Requested: "
|
|
|
|
<< pos.x << "," << pos.y << "," << pos.z;
|
|
|
|
throw std::runtime_error(oss.str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// I can't imagine this to be possible...
|
|
|
|
std::ostringstream oss;
|
|
|
|
oss << "Failed to get block: "
|
|
|
|
<< pos.x << "," << pos.y << "," << pos.z
|
|
|
|
<< " from database.";
|
|
|
|
throw std::runtime_error(oss.str());
|
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2014-03-05 12:41:27 -08:00
|
|
|
void TileGenerator::renderMap()
|
|
|
|
{
|
2014-03-24 14:43:32 -07:00
|
|
|
int blocks_selected = 0;
|
|
|
|
int blocks_rendered = 0;
|
|
|
|
BlockPos currentPos;
|
|
|
|
currentPos.x = INT_MIN;
|
|
|
|
currentPos.y = 0;
|
|
|
|
currentPos.z = INT_MIN;
|
|
|
|
bool allReaded = false;
|
|
|
|
for (std::list<BlockPos>::const_iterator position = m_positions.begin(); position != m_positions.end(); ++position) {
|
|
|
|
const BlockPos &pos = *position;
|
|
|
|
if (currentPos.x != pos.x || currentPos.z != pos.z) {
|
|
|
|
if (currentPos.z != pos.z && currentPos.z != INT_MIN && m_shading)
|
|
|
|
renderShading(currentPos.z);
|
2012-08-24 13:51:17 -07:00
|
|
|
for (int i = 0; i < 16; ++i) {
|
|
|
|
m_readedPixels[i] = 0;
|
|
|
|
}
|
2014-03-24 14:43:32 -07:00
|
|
|
currentPos = pos;
|
|
|
|
}
|
|
|
|
else if (allReaded) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Block block = getBlockOnPos(pos);
|
|
|
|
blocks_selected++;
|
|
|
|
if (!block.second.empty()) {
|
|
|
|
const unsigned char *data = block.second.c_str();
|
|
|
|
size_t length = block.second.length();
|
|
|
|
|
|
|
|
uint8_t version = data[0];
|
|
|
|
//uint8_t flags = data[1];
|
|
|
|
|
|
|
|
size_t dataOffset = 0;
|
|
|
|
if (version >= 22) {
|
|
|
|
dataOffset = 4;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dataOffset = 2;
|
|
|
|
}
|
2012-08-24 13:51:17 -07:00
|
|
|
|
2014-03-24 14:43:32 -07:00
|
|
|
ZlibDecompressor decompressor(data, length);
|
|
|
|
decompressor.setSeekPos(dataOffset);
|
|
|
|
ZlibDecompressor::string mapData = decompressor.decompress();
|
|
|
|
ZlibDecompressor::string mapMetadata = decompressor.decompress();
|
|
|
|
dataOffset = decompressor.seekPos();
|
2012-08-24 03:10:26 -07:00
|
|
|
|
2014-03-24 14:43:32 -07:00
|
|
|
// Skip unused data
|
|
|
|
if (version <= 21) {
|
|
|
|
dataOffset += 2;
|
|
|
|
}
|
|
|
|
if (version == 23) {
|
|
|
|
dataOffset += 1;
|
|
|
|
}
|
|
|
|
if (version == 24) {
|
|
|
|
uint8_t ver = data[dataOffset++];
|
|
|
|
if (ver == 1) {
|
|
|
|
uint16_t num = readU16(data + dataOffset);
|
2012-08-24 03:10:26 -07:00
|
|
|
dataOffset += 2;
|
2014-03-24 14:43:32 -07:00
|
|
|
dataOffset += 10 * num;
|
2012-08-24 03:10:26 -07:00
|
|
|
}
|
2014-03-24 14:43:32 -07:00
|
|
|
}
|
2012-08-24 05:13:46 -07:00
|
|
|
|
2014-03-24 14:43:32 -07:00
|
|
|
// Skip unused static objects
|
|
|
|
dataOffset++; // Skip static object version
|
|
|
|
int staticObjectCount = readU16(data + dataOffset);
|
|
|
|
dataOffset += 2;
|
|
|
|
for (int i = 0; i < staticObjectCount; ++i) {
|
|
|
|
dataOffset += 13;
|
|
|
|
uint16_t dataSize = readU16(data + dataOffset);
|
|
|
|
dataOffset += dataSize + 2;
|
|
|
|
}
|
|
|
|
dataOffset += 4; // Skip timestamp
|
|
|
|
|
|
|
|
m_blockAirId = -1;
|
|
|
|
m_blockIgnoreId = -1;
|
|
|
|
// Read mapping
|
|
|
|
if (version >= 22) {
|
|
|
|
dataOffset++; // mapping version
|
|
|
|
uint16_t numMappings = readU16(data + dataOffset);
|
2012-08-24 05:13:46 -07:00
|
|
|
dataOffset += 2;
|
2014-03-24 14:43:32 -07:00
|
|
|
for (int i = 0; i < numMappings; ++i) {
|
|
|
|
uint16_t nodeId = readU16(data + dataOffset);
|
2012-08-24 05:13:46 -07:00
|
|
|
dataOffset += 2;
|
2014-03-24 14:43:32 -07:00
|
|
|
uint16_t nameLen = readU16(data + dataOffset);
|
|
|
|
dataOffset += 2;
|
|
|
|
string name = string(reinterpret_cast<const char *>(data) + dataOffset, nameLen);
|
|
|
|
if (name == "air") {
|
|
|
|
m_blockAirId = nodeId;
|
|
|
|
}
|
|
|
|
else if (name == "ignore") {
|
|
|
|
m_blockIgnoreId = nodeId;
|
2012-08-24 03:10:26 -07:00
|
|
|
}
|
2014-03-24 14:43:32 -07:00
|
|
|
else {
|
|
|
|
m_nameMap[nodeId] = name;
|
|
|
|
}
|
|
|
|
dataOffset += nameLen;
|
2012-08-24 03:10:26 -07:00
|
|
|
}
|
2014-03-24 14:43:32 -07:00
|
|
|
}
|
2012-08-24 05:48:55 -07:00
|
|
|
|
2014-03-24 14:43:32 -07:00
|
|
|
// Node timers
|
|
|
|
if (version >= 25) {
|
|
|
|
dataOffset++;
|
|
|
|
uint16_t numTimers = readU16(data + dataOffset);
|
|
|
|
dataOffset += 2;
|
|
|
|
dataOffset += numTimers * 10;
|
|
|
|
}
|
2012-08-24 13:51:17 -07:00
|
|
|
|
2014-03-24 14:43:32 -07:00
|
|
|
renderMapBlock(mapData, pos, version);
|
|
|
|
blocks_rendered++;
|
2012-08-24 13:51:17 -07:00
|
|
|
|
2014-03-24 14:43:32 -07:00
|
|
|
allReaded = true;
|
|
|
|
for (int i = 0; i < 16; ++i) {
|
|
|
|
if (m_readedPixels[i] != 0xffff) {
|
|
|
|
allReaded = false;
|
2012-08-24 13:51:17 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-24 14:43:32 -07:00
|
|
|
if(currentPos.z != INT_MIN && m_shading)
|
|
|
|
renderShading(currentPos.z);
|
|
|
|
if (verboseStatistics)
|
|
|
|
cout << "Statistics: Blocks selected: " << blocks_selected << "; blocks rendered: " << blocks_rendered << std::endl;
|
2012-08-24 13:51:17 -07:00
|
|
|
}
|
|
|
|
|
2012-09-18 01:43:34 -07:00
|
|
|
inline void TileGenerator::renderMapBlock(const unsigned_string &mapBlock, const BlockPos &pos, int version)
|
2012-08-24 13:51:17 -07:00
|
|
|
{
|
|
|
|
int xBegin = (pos.x - m_xMin) * 16;
|
|
|
|
int zBegin = (m_zMax - pos.z) * 16;
|
2012-09-18 01:43:34 -07:00
|
|
|
const unsigned char *mapData = mapBlock.c_str();
|
2014-03-23 11:47:49 -07:00
|
|
|
int minY = (pos.y < m_reqYMin) ? 16 : (pos.y > m_reqYMin) ? 0 : m_reqYMinNode;
|
|
|
|
int maxY = (pos.y > m_reqYMax) ? -1 : (pos.y < m_reqYMax) ? 15 : m_reqYMaxNode;
|
2012-08-24 13:51:17 -07:00
|
|
|
for (int z = 0; z < 16; ++z) {
|
2012-08-25 05:11:55 -07:00
|
|
|
int imageY = getImageY(zBegin + 15 - z);
|
2012-08-24 13:51:17 -07:00
|
|
|
for (int x = 0; x < 16; ++x) {
|
|
|
|
if (m_readedPixels[z] & (1 << x)) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-08-25 05:11:55 -07:00
|
|
|
int imageX = getImageX(xBegin + x);
|
2014-03-05 09:06:05 -08:00
|
|
|
for (int y = maxY; y >= minY; --y) {
|
2012-08-24 13:51:17 -07:00
|
|
|
int position = x + (y << 4) + (z << 8);
|
|
|
|
int content = readBlockContent(mapData, version, position);
|
|
|
|
if (content == m_blockIgnoreId || content == m_blockAirId) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
std::map<int, std::string>::iterator blockName = m_nameMap.find(content);
|
|
|
|
if (blockName != m_nameMap.end()) {
|
|
|
|
const string &name = blockName->second;
|
|
|
|
ColorMap::const_iterator color = m_colors.find(name);
|
|
|
|
if (color != m_colors.end()) {
|
|
|
|
const Color &c = color->second;
|
|
|
|
m_image->tpixels[imageY][imageX] = rgb2int(c.r, c.g, c.b);
|
|
|
|
m_readedPixels[z] |= (1 << x);
|
2012-08-25 04:19:58 -07:00
|
|
|
m_blockPixelAttributes.attribute(15 - z, xBegin + x).height = pos.y * 16 + y;
|
2013-03-18 11:12:02 -07:00
|
|
|
} else {
|
2012-08-25 07:41:53 -07:00
|
|
|
m_unknownNodes.insert(name);
|
2013-03-18 11:12:02 -07:00
|
|
|
continue;
|
2012-08-25 07:41:53 -07:00
|
|
|
}
|
2012-08-24 13:51:17 -07:00
|
|
|
break;
|
|
|
|
}
|
2012-08-24 02:01:48 -07:00
|
|
|
}
|
|
|
|
}
|
2012-08-24 00:46:14 -07:00
|
|
|
}
|
|
|
|
}
|
2012-08-23 06:35:00 -07:00
|
|
|
|
2012-08-25 04:19:58 -07:00
|
|
|
inline void TileGenerator::renderShading(int zPos)
|
|
|
|
{
|
|
|
|
int zBegin = (m_zMax - zPos) * 16;
|
2012-09-01 04:34:27 -07:00
|
|
|
for (int z = 0; z < 16; ++z) {
|
2012-08-25 04:19:58 -07:00
|
|
|
int imageY = zBegin + z;
|
|
|
|
if (imageY >= m_mapHeight) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-08-25 05:11:55 -07:00
|
|
|
imageY = getImageY(imageY);
|
2012-08-25 04:19:58 -07:00
|
|
|
for (int x = 0; x < m_mapWidth; ++x) {
|
2012-08-25 04:27:40 -07:00
|
|
|
if (!m_blockPixelAttributes.attribute(z, x).valid_height() || !m_blockPixelAttributes.attribute(z, x - 1).valid_height() || !m_blockPixelAttributes.attribute(z - 1, x).valid_height()) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-08-25 04:19:58 -07:00
|
|
|
int y = m_blockPixelAttributes.attribute(z, x).height;
|
|
|
|
int y1 = m_blockPixelAttributes.attribute(z, x - 1).height;
|
|
|
|
int y2 = m_blockPixelAttributes.attribute(z - 1, x).height;
|
|
|
|
int d = ((y - y1) + (y - y2)) * 12;
|
|
|
|
if (d > 36) {
|
|
|
|
d = 36;
|
|
|
|
}
|
2012-08-25 05:11:55 -07:00
|
|
|
int sourceColor = m_image->tpixels[imageY][getImageX(x)] & 0xffffff;
|
2012-08-25 04:19:58 -07:00
|
|
|
int r = (sourceColor & 0xff0000) >> 16;
|
|
|
|
int g = (sourceColor & 0x00ff00) >> 8;
|
|
|
|
int b = (sourceColor & 0x0000ff);
|
|
|
|
r = colorSafeBounds(r + d);
|
|
|
|
g = colorSafeBounds(g + d);
|
|
|
|
b = colorSafeBounds(b + d);
|
2012-08-25 05:11:55 -07:00
|
|
|
m_image->tpixels[imageY][getImageX(x)] = rgb2int(r, g, b);
|
2012-08-25 04:19:58 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
m_blockPixelAttributes.scroll();
|
|
|
|
}
|
|
|
|
|
2012-08-25 05:11:55 -07:00
|
|
|
void TileGenerator::renderScale()
|
|
|
|
{
|
2012-08-25 06:06:11 -07:00
|
|
|
int color = rgb2int(m_scaleColor.r, m_scaleColor.g, m_scaleColor.b);
|
|
|
|
gdImageString(m_image, gdFontGetMediumBold(), 24, 0, reinterpret_cast<unsigned char *>(const_cast<char *>("X")), color);
|
|
|
|
gdImageString(m_image, gdFontGetMediumBold(), 2, 24, reinterpret_cast<unsigned char *>(const_cast<char *>("Z")), color);
|
|
|
|
|
|
|
|
string scaleText;
|
|
|
|
|
|
|
|
for (int i = (m_xMin / 4) * 4; i <= m_xMax; i += 4) {
|
|
|
|
stringstream buf;
|
|
|
|
buf << i * 16;
|
|
|
|
scaleText = buf.str();
|
|
|
|
|
|
|
|
int xPos = m_xMin * -16 + i * 16 + m_border;
|
|
|
|
gdImageString(m_image, gdFontGetMediumBold(), xPos + 2, 0, reinterpret_cast<unsigned char *>(const_cast<char *>(scaleText.c_str())), color);
|
|
|
|
gdImageLine(m_image, xPos, 0, xPos, m_border - 1, color);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = (m_zMax / 4) * 4; i >= m_zMin; i -= 4) {
|
|
|
|
stringstream buf;
|
|
|
|
buf << i * 16;
|
|
|
|
scaleText = buf.str();
|
|
|
|
|
|
|
|
int yPos = m_mapHeight - 1 - (i * 16 - m_zMin * 16) + m_border;
|
|
|
|
gdImageString(m_image, gdFontGetMediumBold(), 2, yPos, reinterpret_cast<unsigned char *>(const_cast<char *>(scaleText.c_str())), color);
|
|
|
|
gdImageLine(m_image, 0, yPos, m_border - 1, yPos, color);
|
|
|
|
}
|
2012-08-25 05:11:55 -07:00
|
|
|
}
|
|
|
|
|
2012-08-25 06:21:51 -07:00
|
|
|
void TileGenerator::renderOrigin()
|
|
|
|
{
|
|
|
|
int imageX = -m_xMin * 16 + m_border;
|
|
|
|
int imageY = m_mapHeight - m_zMin * -16 + m_border;
|
|
|
|
gdImageArc(m_image, imageX, imageY, 12, 12, 0, 360, rgb2int(m_originColor.r, m_originColor.g, m_originColor.b));
|
|
|
|
}
|
|
|
|
|
2012-08-25 07:29:41 -07:00
|
|
|
void TileGenerator::renderPlayers(const std::string &inputPath)
|
|
|
|
{
|
|
|
|
int color = rgb2int(m_playerColor.r, m_playerColor.g, m_playerColor.b);
|
|
|
|
|
2012-09-01 07:40:18 -07:00
|
|
|
PlayerAttributes players(inputPath);
|
|
|
|
for (PlayerAttributes::Players::iterator player = players.begin(); player != players.end(); ++player) {
|
|
|
|
int imageX = player->x / 10 - m_xMin * 16 + m_border;
|
|
|
|
int imageY = m_mapHeight - (player->z / 10 - m_zMin * 16) + m_border;
|
2012-09-01 04:01:31 -07:00
|
|
|
|
|
|
|
gdImageArc(m_image, imageX, imageY, 5, 5, 0, 360, color);
|
2012-09-01 07:40:18 -07:00
|
|
|
gdImageString(m_image, gdFontGetMediumBold(), imageX + 2, imageY + 2, reinterpret_cast<unsigned char *>(const_cast<char *>(player->name.c_str())), color);
|
2012-09-01 04:01:31 -07:00
|
|
|
}
|
2012-08-25 07:29:41 -07:00
|
|
|
}
|
|
|
|
|
2012-08-24 00:46:14 -07:00
|
|
|
inline std::list<int> TileGenerator::getZValueList() const
|
|
|
|
{
|
|
|
|
std::list<int> zlist;
|
2014-03-24 14:43:32 -07:00
|
|
|
for (std::list<BlockPos>::const_iterator position = m_positions.begin(); position != m_positions.end(); ++position) {
|
|
|
|
zlist.push_back(position->z);
|
2012-08-24 00:46:14 -07:00
|
|
|
}
|
|
|
|
zlist.sort();
|
|
|
|
zlist.unique();
|
2012-09-01 04:34:27 -07:00
|
|
|
zlist.reverse();
|
2012-08-24 00:46:14 -07:00
|
|
|
return zlist;
|
|
|
|
}
|
|
|
|
|
2012-08-23 05:21:34 -07:00
|
|
|
void TileGenerator::writeImage(const std::string &output)
|
|
|
|
{
|
|
|
|
FILE *out;
|
2012-08-28 02:27:51 -07:00
|
|
|
out = fopen(output.c_str(), "wb");
|
2014-02-16 13:13:31 -08:00
|
|
|
if (!out) {
|
|
|
|
std::ostringstream oss;
|
|
|
|
oss << "Error opening '" << output.c_str() << "': " << std::strerror(errno);
|
|
|
|
throw std::runtime_error(oss.str());
|
|
|
|
}
|
2012-08-23 05:21:34 -07:00
|
|
|
gdImagePng(m_image, out);
|
|
|
|
fclose(out);
|
|
|
|
gdImageDestroy(m_image);
|
|
|
|
}
|
|
|
|
|
2012-08-25 07:41:53 -07:00
|
|
|
void TileGenerator::printUnknown()
|
|
|
|
{
|
|
|
|
if (m_unknownNodes.size() > 0) {
|
|
|
|
std::cerr << "Unknown nodes:" << std::endl;
|
|
|
|
for (std::set<std::string>::iterator node = m_unknownNodes.begin(); node != m_unknownNodes.end(); ++node) {
|
|
|
|
std::cerr << *node << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-25 05:11:55 -07:00
|
|
|
inline int TileGenerator::getImageX(int val) const
|
|
|
|
{
|
|
|
|
return val + m_border;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int TileGenerator::getImageY(int val) const
|
|
|
|
{
|
|
|
|
return val + m_border;
|
|
|
|
}
|
|
|
|
|