2012-08-23 03:46:22 -07:00
|
|
|
/*
|
|
|
|
* =====================================================================
|
|
|
|
* Version: 1.0
|
|
|
|
* Created: 23.08.2012 12:35:59
|
|
|
|
* Author: Miroslav Bendík
|
|
|
|
* Company: LinuxOS.sk
|
|
|
|
* =====================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TILEGENERATOR_H_JJNUCARH
|
|
|
|
#define TILEGENERATOR_H_JJNUCARH
|
|
|
|
|
2012-08-23 05:21:34 -07:00
|
|
|
#include <gd.h>
|
2014-04-07 19:40:09 -07:00
|
|
|
#include <climits>
|
2012-09-01 06:51:02 -07:00
|
|
|
#include <iosfwd>
|
2012-08-23 06:35:00 -07:00
|
|
|
#include <list>
|
2012-08-23 04:32:22 -07:00
|
|
|
#include <map>
|
2012-09-01 06:51:02 -07:00
|
|
|
#include <set>
|
2012-08-23 03:55:31 -07:00
|
|
|
#include <stdint.h>
|
2012-08-23 03:46:22 -07:00
|
|
|
#include <string>
|
2012-08-25 04:19:58 -07:00
|
|
|
#include "PixelAttributes.h"
|
2014-03-05 12:41:27 -08:00
|
|
|
#include "db.h"
|
2012-08-23 03:55:31 -07:00
|
|
|
|
2014-03-26 00:55:20 -07:00
|
|
|
#define MINETEST_MAPBLOCK_MIN (-2048)
|
|
|
|
#define MINETEST_MAPBLOCK_MAX 2047
|
|
|
|
|
2014-04-07 19:40:09 -07:00
|
|
|
#define TILECENTER_IS_WORLDCENTER INT_MAX
|
|
|
|
#define TILECENTER_IS_MAPCENTER INT_MIN
|
|
|
|
|
2012-08-23 03:55:31 -07:00
|
|
|
struct Color {
|
2014-04-03 11:32:48 -07:00
|
|
|
Color(): r(0xFF), g(0xFF), b(0xFF), a(0) {};
|
|
|
|
Color(uint8_t r, uint8_t g, uint8_t b): r(r), g(g), b(b), a(0xFF) {};
|
|
|
|
Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a): r(r), g(g), b(b), a(a) {};
|
2012-08-23 03:55:31 -07:00
|
|
|
uint8_t r;
|
|
|
|
uint8_t g;
|
|
|
|
uint8_t b;
|
2014-04-03 11:32:48 -07:00
|
|
|
uint8_t a;
|
2012-08-23 03:55:31 -07:00
|
|
|
};
|
2012-08-23 03:46:22 -07:00
|
|
|
|
2014-04-03 11:32:48 -07:00
|
|
|
struct ColorEntry {
|
2014-04-03 11:38:09 -07:00
|
|
|
ColorEntry(): r(0), g(0), b(0), a(0), t(0) {};
|
2014-04-03 11:32:48 -07:00
|
|
|
ColorEntry(uint8_t r, uint8_t g, uint8_t b, uint8_t a, uint8_t t): r(r), g(g), b(b), a(a), t(t) {};
|
|
|
|
inline Color to_color() const { return Color(r, g, b, a); }
|
|
|
|
uint8_t r;
|
|
|
|
uint8_t g;
|
|
|
|
uint8_t b;
|
|
|
|
uint8_t a;
|
|
|
|
uint8_t t;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-08-23 04:32:22 -07:00
|
|
|
struct BlockPos {
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
int z;
|
2014-03-24 14:43:32 -07:00
|
|
|
// operator< should order the positions in the
|
|
|
|
// order the corresponding pixels are generated:
|
|
|
|
// First (most significant): z coordinate, descending (i.e. reversed)
|
|
|
|
// Then : x coordinate, ascending
|
|
|
|
// Last (least significant): y coordinate, descending (i.e. reversed)
|
2012-08-24 02:01:48 -07:00
|
|
|
bool operator<(const BlockPos& p) const
|
|
|
|
{
|
|
|
|
if (z > p.z) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (z < p.z) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-24 14:43:32 -07:00
|
|
|
if (x < p.x) {
|
2012-08-24 02:01:48 -07:00
|
|
|
return true;
|
|
|
|
}
|
2014-03-24 14:43:32 -07:00
|
|
|
if (x > p.x) {
|
2012-08-24 02:01:48 -07:00
|
|
|
return false;
|
|
|
|
}
|
2014-03-24 14:43:32 -07:00
|
|
|
if (y > p.y) {
|
2012-08-24 02:01:48 -07:00
|
|
|
return true;
|
|
|
|
}
|
2014-03-24 14:43:32 -07:00
|
|
|
if (y < p.y) {
|
2012-08-24 02:01:48 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-24 14:43:32 -07:00
|
|
|
bool operator==(const BlockPos& p) const
|
|
|
|
{
|
|
|
|
if (z != p.z) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (y != p.y) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (x != p.x) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2012-08-23 04:32:22 -07:00
|
|
|
};
|
|
|
|
|
2012-08-25 04:19:58 -07:00
|
|
|
|
2012-08-23 03:46:22 -07:00
|
|
|
class TileGenerator
|
|
|
|
{
|
2012-08-23 03:55:31 -07:00
|
|
|
private:
|
2012-09-18 01:43:34 -07:00
|
|
|
typedef std::basic_string<unsigned char> unsigned_string;
|
2014-04-03 11:32:48 -07:00
|
|
|
typedef std::map<std::string, ColorEntry> ColorMap;
|
2012-09-18 01:43:34 -07:00
|
|
|
typedef std::pair<BlockPos, unsigned_string> Block;
|
2012-08-24 01:44:48 -07:00
|
|
|
typedef std::list<Block> BlockList;
|
2012-08-23 03:55:31 -07:00
|
|
|
|
2012-08-23 03:46:22 -07:00
|
|
|
public:
|
|
|
|
TileGenerator();
|
|
|
|
~TileGenerator();
|
|
|
|
void setBgColor(const std::string &bgColor);
|
|
|
|
void setScaleColor(const std::string &scaleColor);
|
|
|
|
void setOriginColor(const std::string &originColor);
|
2014-04-09 02:47:18 -07:00
|
|
|
void setPlayerColor(const std::string &playerColor);
|
|
|
|
Color parseColor(const std::string &color);
|
2012-08-23 03:46:22 -07:00
|
|
|
void setDrawOrigin(bool drawOrigin);
|
|
|
|
void setDrawPlayers(bool drawPlayers);
|
|
|
|
void setDrawScale(bool drawScale);
|
2014-04-03 11:32:48 -07:00
|
|
|
void setDrawAlpha(bool drawAlpha);
|
2014-03-05 08:19:37 -08:00
|
|
|
void setShading(bool shading);
|
2012-11-24 10:25:13 -08:00
|
|
|
void setGeometry(int x, int y, int w, int h);
|
2014-03-05 09:06:05 -08:00
|
|
|
void setMinY(int y);
|
|
|
|
void setMaxY(int y);
|
2014-02-16 12:24:32 -08:00
|
|
|
void setForceGeom(bool forceGeom);
|
2014-03-25 16:23:33 -07:00
|
|
|
void setSqliteCacheWorldRow(bool cacheWorldRow);
|
2014-04-07 19:40:09 -07:00
|
|
|
void setTileBorderColor(const std::string &tileBorderColor);
|
|
|
|
void setTileBorderSize(int size);
|
|
|
|
void setTileSize(int width, int heigth);
|
|
|
|
void setTileOrigin(int x, int y);
|
2012-08-23 03:55:31 -07:00
|
|
|
void parseColorsFile(const std::string &fileName);
|
2014-03-05 12:41:27 -08:00
|
|
|
void setBackend(std::string backend);
|
2012-08-23 04:32:22 -07:00
|
|
|
void generate(const std::string &input, const std::string &output);
|
|
|
|
|
|
|
|
private:
|
2014-04-09 02:47:18 -07:00
|
|
|
void parseColorsStream(std::istream &in, const std::string &filename);
|
2012-08-23 04:32:22 -07:00
|
|
|
void openDb(const std::string &input);
|
|
|
|
void loadBlocks();
|
2014-03-05 12:41:27 -08:00
|
|
|
BlockPos decodeBlockPos(int64_t blockId) const;
|
2012-08-23 05:21:34 -07:00
|
|
|
void createImage();
|
2012-08-23 06:35:00 -07:00
|
|
|
void renderMap();
|
2012-08-24 00:46:14 -07:00
|
|
|
std::list<int> getZValueList() const;
|
2014-03-24 14:43:32 -07:00
|
|
|
Block getBlockOnPos(BlockPos pos);
|
2012-09-18 01:43:34 -07:00
|
|
|
void renderMapBlock(const unsigned_string &mapBlock, const BlockPos &pos, int version);
|
2012-08-25 04:19:58 -07:00
|
|
|
void renderShading(int zPos);
|
2012-08-25 05:11:55 -07:00
|
|
|
void renderScale();
|
2012-08-25 06:21:51 -07:00
|
|
|
void renderOrigin();
|
2012-08-25 07:29:41 -07:00
|
|
|
void renderPlayers(const std::string &inputPath);
|
2012-08-23 05:21:34 -07:00
|
|
|
void writeImage(const std::string &output);
|
2012-08-25 07:41:53 -07:00
|
|
|
void printUnknown();
|
2012-08-25 05:11:55 -07:00
|
|
|
int getImageX(int val) const;
|
|
|
|
int getImageY(int val) const;
|
2012-08-23 03:46:22 -07:00
|
|
|
|
2014-03-23 10:35:00 -07:00
|
|
|
public:
|
|
|
|
bool verboseCoordinates;
|
2014-03-24 14:43:32 -07:00
|
|
|
bool verboseStatistics;
|
2014-03-23 10:35:00 -07:00
|
|
|
|
2012-08-23 03:46:22 -07:00
|
|
|
private:
|
2012-08-23 05:43:11 -07:00
|
|
|
Color m_bgColor;
|
|
|
|
Color m_scaleColor;
|
|
|
|
Color m_originColor;
|
|
|
|
Color m_playerColor;
|
2014-04-07 19:40:09 -07:00
|
|
|
Color m_tileBorderColor;
|
2012-08-23 03:46:22 -07:00
|
|
|
bool m_drawOrigin;
|
|
|
|
bool m_drawPlayers;
|
|
|
|
bool m_drawScale;
|
2014-04-03 11:32:48 -07:00
|
|
|
bool m_drawAlpha;
|
2014-03-05 08:19:37 -08:00
|
|
|
bool m_shading;
|
2012-08-25 05:11:55 -07:00
|
|
|
int m_border;
|
2014-03-05 12:41:27 -08:00
|
|
|
std::string m_backend;
|
2014-02-16 12:24:32 -08:00
|
|
|
bool m_forceGeom;
|
2014-03-25 16:23:33 -07:00
|
|
|
bool m_sqliteCacheWorldRow;
|
2012-08-23 05:06:16 -07:00
|
|
|
|
2014-03-05 12:41:27 -08:00
|
|
|
DB *m_db;
|
2012-08-23 05:21:34 -07:00
|
|
|
gdImagePtr m_image;
|
2012-08-25 04:19:58 -07:00
|
|
|
PixelAttributes m_blockPixelAttributes;
|
2012-08-23 05:06:16 -07:00
|
|
|
int m_xMin;
|
|
|
|
int m_xMax;
|
|
|
|
int m_zMin;
|
|
|
|
int m_zMax;
|
2014-03-05 09:06:05 -08:00
|
|
|
int m_yMin;
|
|
|
|
int m_yMax;
|
2014-03-23 11:47:49 -07:00
|
|
|
int m_reqXMin;
|
|
|
|
int m_reqXMax;
|
|
|
|
int m_reqYMin;
|
|
|
|
int m_reqYMax;
|
|
|
|
int m_reqZMin;
|
|
|
|
int m_reqZMax;
|
|
|
|
int m_reqYMinNode; // Node offset within a map block
|
|
|
|
int m_reqYMaxNode; // Node offset within a map block
|
2012-08-25 04:19:58 -07:00
|
|
|
int m_mapWidth;
|
|
|
|
int m_mapHeight;
|
2014-04-07 19:40:09 -07:00
|
|
|
int m_tileXOrigin;
|
|
|
|
int m_tileZOrigin;
|
|
|
|
int m_tileWidth;
|
|
|
|
int m_tileHeight;
|
|
|
|
int m_tileBorderSize;
|
|
|
|
int m_tileMapXOffset;
|
|
|
|
int m_tileMapYOffset;
|
2014-03-24 14:43:32 -07:00
|
|
|
std::list<BlockPos> m_positions;
|
2012-08-24 05:13:46 -07:00
|
|
|
std::map<int, std::string> m_nameMap;
|
2012-08-23 03:55:31 -07:00
|
|
|
ColorMap m_colors;
|
2012-08-24 13:51:17 -07:00
|
|
|
uint16_t m_readedPixels[16];
|
2012-08-25 07:41:53 -07:00
|
|
|
std::set<std::string> m_unknownNodes;
|
2012-08-24 13:51:17 -07:00
|
|
|
|
|
|
|
int m_blockAirId;
|
|
|
|
int m_blockIgnoreId;
|
2012-08-23 03:46:22 -07:00
|
|
|
}; /* ----- end of class TileGenerator ----- */
|
|
|
|
|
|
|
|
#endif /* end of include guard: TILEGENERATOR_H_JJNUCARH */
|
|
|
|
|