2014-04-19 08:13:34 +02:00
|
|
|
#ifndef TILEGENERATOR_HEADER
|
|
|
|
#define TILEGENERATOR_HEADER
|
2012-08-23 12:46:22 +02:00
|
|
|
|
2012-08-23 14:21:34 +02:00
|
|
|
#include <gd.h>
|
2012-09-01 15:51:02 +02:00
|
|
|
#include <iosfwd>
|
2012-08-23 15:35:00 +02:00
|
|
|
#include <list>
|
2012-08-23 13:32:22 +02:00
|
|
|
#include <map>
|
2012-09-01 15:51:02 +02:00
|
|
|
#include <set>
|
2012-08-23 12:55:31 +02:00
|
|
|
#include <stdint.h>
|
2012-08-23 12:46:22 +02:00
|
|
|
#include <string>
|
2012-08-25 13:19:58 +02:00
|
|
|
#include "PixelAttributes.h"
|
2014-03-05 21:41:27 +01:00
|
|
|
#include "db.h"
|
2014-04-19 08:13:34 +02:00
|
|
|
#include "types.h"
|
2012-08-23 12:55:31 +02:00
|
|
|
|
|
|
|
struct Color {
|
2014-04-03 20:32:48 +02: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 12:55:31 +02:00
|
|
|
uint8_t r;
|
|
|
|
uint8_t g;
|
|
|
|
uint8_t b;
|
2014-04-03 20:32:48 +02:00
|
|
|
uint8_t a;
|
2012-08-23 12:55:31 +02:00
|
|
|
};
|
2012-08-23 12:46:22 +02:00
|
|
|
|
2014-04-03 20:32:48 +02:00
|
|
|
struct ColorEntry {
|
2014-04-03 20:38:09 +02:00
|
|
|
ColorEntry(): r(0), g(0), b(0), a(0), t(0) {};
|
2014-04-03 20:32:48 +02: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 12:46:22 +02:00
|
|
|
class TileGenerator
|
|
|
|
{
|
2012-08-23 12:55:31 +02:00
|
|
|
private:
|
2014-04-03 20:32:48 +02:00
|
|
|
typedef std::map<std::string, ColorEntry> ColorMap;
|
2012-08-23 12:55:31 +02:00
|
|
|
|
2012-08-23 12:46:22 +02:00
|
|
|
public:
|
|
|
|
TileGenerator();
|
|
|
|
~TileGenerator();
|
|
|
|
void setBgColor(const std::string &bgColor);
|
|
|
|
void setScaleColor(const std::string &scaleColor);
|
|
|
|
void setOriginColor(const std::string &originColor);
|
2012-08-24 10:44:48 +02:00
|
|
|
void setPlayerColor(const std::string &playerColor); Color parseColor(const std::string &color);
|
2012-08-23 12:46:22 +02:00
|
|
|
void setDrawOrigin(bool drawOrigin);
|
|
|
|
void setDrawPlayers(bool drawPlayers);
|
|
|
|
void setDrawScale(bool drawScale);
|
2014-04-03 20:32:48 +02:00
|
|
|
void setDrawAlpha(bool drawAlpha);
|
2014-03-05 17:19:37 +01:00
|
|
|
void setShading(bool shading);
|
2012-11-24 19:25:13 +01:00
|
|
|
void setGeometry(int x, int y, int w, int h);
|
2014-03-05 18:06:05 +01:00
|
|
|
void setMinY(int y);
|
|
|
|
void setMaxY(int y);
|
2012-08-23 12:55:31 +02:00
|
|
|
void parseColorsFile(const std::string &fileName);
|
2014-03-05 21:41:27 +01:00
|
|
|
void setBackend(std::string backend);
|
2012-08-23 13:32:22 +02:00
|
|
|
void generate(const std::string &input, const std::string &output);
|
|
|
|
|
|
|
|
private:
|
2012-09-01 15:51:02 +02:00
|
|
|
void parseColorsStream(std::istream &in);
|
2012-08-23 13:32:22 +02:00
|
|
|
void openDb(const std::string &input);
|
|
|
|
void loadBlocks();
|
2012-08-23 14:21:34 +02:00
|
|
|
void createImage();
|
2012-08-23 15:35:00 +02:00
|
|
|
void renderMap();
|
2012-08-24 09:46:14 +02:00
|
|
|
std::list<int> getZValueList() const;
|
2014-04-19 08:13:34 +02:00
|
|
|
void renderMapBlock(const ustring &mapBlock, const BlockPos &pos, int version);
|
2012-08-25 13:19:58 +02:00
|
|
|
void renderShading(int zPos);
|
2012-08-25 14:11:55 +02:00
|
|
|
void renderScale();
|
2012-08-25 15:21:51 +02:00
|
|
|
void renderOrigin();
|
2012-08-25 16:29:41 +02:00
|
|
|
void renderPlayers(const std::string &inputPath);
|
2012-08-23 14:21:34 +02:00
|
|
|
void writeImage(const std::string &output);
|
2012-08-25 16:41:53 +02:00
|
|
|
void printUnknown();
|
2012-08-25 14:11:55 +02:00
|
|
|
int getImageX(int val) const;
|
|
|
|
int getImageY(int val) const;
|
2012-08-23 12:46:22 +02:00
|
|
|
|
|
|
|
private:
|
2012-08-23 14:43:11 +02:00
|
|
|
Color m_bgColor;
|
|
|
|
Color m_scaleColor;
|
|
|
|
Color m_originColor;
|
|
|
|
Color m_playerColor;
|
2012-08-23 12:46:22 +02:00
|
|
|
bool m_drawOrigin;
|
|
|
|
bool m_drawPlayers;
|
|
|
|
bool m_drawScale;
|
2014-04-03 20:32:48 +02:00
|
|
|
bool m_drawAlpha;
|
2014-03-05 17:19:37 +01:00
|
|
|
bool m_shading;
|
2012-08-25 14:11:55 +02:00
|
|
|
int m_border;
|
2014-03-05 21:41:27 +01:00
|
|
|
std::string m_backend;
|
2012-08-23 14:06:16 +02:00
|
|
|
|
2014-03-05 21:41:27 +01:00
|
|
|
DB *m_db;
|
2012-08-23 14:21:34 +02:00
|
|
|
gdImagePtr m_image;
|
2012-08-25 13:19:58 +02:00
|
|
|
PixelAttributes m_blockPixelAttributes;
|
2012-08-23 14:06:16 +02:00
|
|
|
int m_xMin;
|
|
|
|
int m_xMax;
|
|
|
|
int m_zMin;
|
|
|
|
int m_zMax;
|
2014-03-05 18:06:05 +01:00
|
|
|
int m_yMin;
|
|
|
|
int m_yMax;
|
2012-11-24 19:25:13 +01:00
|
|
|
int m_geomX;
|
|
|
|
int m_geomY;
|
|
|
|
int m_geomX2;
|
|
|
|
int m_geomY2;
|
2012-08-25 13:19:58 +02:00
|
|
|
int m_mapWidth;
|
|
|
|
int m_mapHeight;
|
2012-08-23 15:35:00 +02:00
|
|
|
std::list<std::pair<int, int> > m_positions;
|
2012-08-24 14:13:46 +02:00
|
|
|
std::map<int, std::string> m_nameMap;
|
2012-08-23 12:55:31 +02:00
|
|
|
ColorMap m_colors;
|
2012-08-24 22:51:17 +02:00
|
|
|
uint16_t m_readedPixels[16];
|
2012-08-25 16:41:53 +02:00
|
|
|
std::set<std::string> m_unknownNodes;
|
2012-08-24 22:51:17 +02:00
|
|
|
|
|
|
|
int m_blockAirId;
|
|
|
|
int m_blockIgnoreId;
|
2014-04-19 08:13:34 +02:00
|
|
|
}; // class TileGenerator
|
2012-08-23 12:46:22 +02:00
|
|
|
|
2014-04-19 08:13:34 +02:00
|
|
|
#endif // TILEGENERATOR_HEADER
|
2012-08-23 12:46:22 +02:00
|
|
|
|