minetestmapper/TileGenerator.h

101 lines
2.3 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-08-23 15:35:00 +02:00
#include <list>
2012-08-23 13:32:22 +02:00
#include <map>
#include <sqlite3.h>
#include <stdint.h>
2012-08-23 12:46:22 +02:00
#include <string>
struct Color {
2012-08-24 09:46:14 +02:00
Color() {};
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;
};
class DbError {
};
2012-08-23 14:43:11 +02:00
class ColorError {
};
2012-08-23 12:46:22 +02:00
class TileGenerator
{
private:
typedef std::map<std::string, Color> ColorMap;
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);
void setPlayerColor(const std::string &playerColor);
2012-08-23 14:43:11 +02:00
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 setDrawUnderground(bool drawUnderground);
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:
void openDb(const std::string &input);
void loadBlocks();
2012-08-24 09:46:14 +02:00
BlockPos decodeBlockPos(sqlite3_int64 blockId) const;
sqlite3_int64 encodeBlockPos(int x, int y, int z) const;
int unsignedToSigned(long i, long max_positive) 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;
void getBlocksOnZ(int zPos, sqlite3_stmt *statement) const;
2012-08-23 14:21:34 +02:00
void writeImage(const std::string &output);
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_drawUnderground;
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-23 14:06:16 +02:00
int m_xMin;
int m_xMax;
int m_zMin;
int m_zMax;
int m_imgWidth;
int m_imgHeight;
2012-08-23 15:35:00 +02:00
std::list<std::pair<int, int> > m_positions;
ColorMap m_colors;
2012-08-23 14:06:16 +02:00
static const int SectorXMin = -1500/16;
static const int SectorXMax = 1500/16;
static const int SectorZMin = -1500/16;
static const int SectorZMax = 1500/16;
2012-08-23 12:46:22 +02:00
}; /* ----- end of class TileGenerator ----- */
#endif /* end of include guard: TILEGENERATOR_H_JJNUCARH */