minetestmapper/TileGenerator.h

142 lines
3.2 KiB
C
Raw Normal View History

2012-08-23 12:46:22 +02: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 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 13:32:22 +02:00
#include <sqlite3.h>
#include <stdint.h>
2012-08-23 12:46:22 +02:00
#include <string>
2012-08-25 13:19:58 +02:00
#include "PixelAttributes.h"
struct Color {
2012-08-24 14:48:55 +02:00
Color(): r(255), g(255), b(255) {};
2012-08-24 09:46:14 +02:00
Color(uint8_t r, uint8_t g, uint8_t b): r(r), g(g), b(b) {};
uint8_t r;
uint8_t g;
uint8_t b;
};
2012-08-23 12:46:22 +02:00
2012-08-23 13:32:22 +02:00
struct BlockPos {
int x;
int y;
int z;
2012-08-24 11:01:48 +02:00
bool operator<(const BlockPos& p) const
{
if (z > p.z) {
return true;
}
if (z < p.z) {
return false;
}
if (y > p.y) {
return true;
}
if (y < p.y) {
return false;
}
if (x > p.x) {
return true;
}
if (x < p.x) {
return false;
}
return false;
}
2012-08-23 13:32:22 +02:00
};
2012-08-25 13:19:58 +02:00
2012-08-23 12:46:22 +02:00
class TileGenerator
{
private:
2012-09-18 10:43:34 +02:00
typedef std::basic_string<unsigned char> unsigned_string;
typedef std::map<std::string, Color> ColorMap;
2012-09-18 10:43:34 +02:00
typedef std::pair<BlockPos, unsigned_string> Block;
2012-08-24 10:44:48 +02:00
typedef std::list<Block> BlockList;
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);
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);
void parseColorsFile(const std::string &fileName);
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-24 09:46:14 +02:00
BlockPos decodeBlockPos(sqlite3_int64 blockId) const;
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;
2012-08-24 10:44:48 +02:00
std::map<int, BlockList> getBlocksOnZ(int zPos, sqlite3_stmt *statement) const;
2012-09-18 10:43:34 +02:00
void renderMapBlock(const unsigned_string &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;
bool m_shading;
2012-08-25 14:11:55 +02:00
int m_border;
2012-08-23 14:06:16 +02:00
2012-08-23 13:32:22 +02:00
sqlite3 *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;
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;
2012-08-23 12:46:22 +02:00
}; /* ----- end of class TileGenerator ----- */
#endif /* end of include guard: TILEGENERATOR_H_JJNUCARH */