minetestmapper/include/TileGenerator.h

173 lines
4.1 KiB
C
Raw Normal View History

#ifndef TILEGENERATOR_HEADER
#define TILEGENERATOR_HEADER
2012-08-23 12:46:22 +02:00
2012-09-01 15:51:02 +02:00
#include <iosfwd>
2012-08-23 15:35:00 +02:00
#include <list>
2014-08-02 16:30:52 +02:00
#include <config.h>
#if __cplusplus >= 201103L
2014-08-02 16:30:52 +02:00
#include <unordered_map>
#include <unordered_set>
#else
2012-08-23 13:32:22 +02:00
#include <map>
2012-09-01 15:51:02 +02:00
#include <set>
2014-08-02 16:30:52 +02:00
#endif
#include <stdint.h>
2012-08-23 12:46:22 +02:00
#include <string>
2018-03-25 15:19:48 +02:00
2012-08-25 13:19:58 +02:00
#include "PixelAttributes.h"
2018-03-25 15:19:48 +02:00
#include "BlockDecoder.h"
#include "Image.h"
2014-03-05 21:41:27 +01:00
#include "db.h"
#include "types.h"
enum {
SCALE_TOP = (1 << 0),
SCALE_BOTTOM = (1 << 1),
SCALE_LEFT = (1 << 2),
SCALE_RIGHT = (1 << 3),
};
struct ColorEntry {
2014-04-03 20:38:09 +02:00
ColorEntry(): r(0), g(0), b(0), a(0), t(0) {};
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); }
2018-03-25 15:44:30 +02:00
uint8_t r, g, b, a, t;
};
struct BitmapThing { // 16x16 bitmap
inline void reset() {
for (int i = 0; i < 16; ++i)
val[i] = 0;
}
inline bool full() const {
for (int i = 0; i < 16; ++i) {
if (val[i] != 0xffff)
return false;
}
return true;
}
inline void set(unsigned int x, unsigned int z) {
val[z] |= (1 << x);
}
inline bool get(unsigned int x, unsigned int z) {
return !!(val[z] & (1 << x));
}
uint16_t val[16];
};
typedef std::list<std::pair<int, int> > PositionsList;
2012-08-23 12:46:22 +02:00
class TileGenerator
{
private:
#if __cplusplus >= 201103L
2014-08-02 16:30:52 +02:00
typedef std::unordered_map<std::string, ColorEntry> ColorMap;
typedef std::unordered_set<std::string> NameSet;
typedef std::unordered_map<int, PositionsList> TileMap;
2014-08-02 16:30:52 +02:00
#else
typedef std::map<std::string, ColorEntry> ColorMap;
2014-08-02 16:30:52 +02:00
typedef std::set<std::string> NameSet;
typedef std::map<int, PositionsList> TileMap;
2014-08-02 16:30:52 +02:00
#endif
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 setDrawAlpha(bool drawAlpha);
void setShading(bool shading);
void setLeaflet(bool leaflet);
2012-11-24 19:25:13 +01:00
void setGeometry(int x, int y, int w, int h);
void setTileSize(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);
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);
void printGeometry(const std::string &input);
2016-07-06 21:45:38 +02:00
void setZoom(int zoom);
void setScales(uint flags);
void setDontWriteEmpty(bool f);
void tilePositions();
2012-08-23 13:32:22 +02:00
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 closeDatabase();
2012-08-23 13:32:22 +02:00
void loadBlocks();
2012-08-23 14:21:34 +02:00
void createImage();
void renderMap(PositionsList &positions);
std::list<int> getZValueList(PositionsList &positions) const;
2018-03-25 15:19:48 +02:00
void renderMapBlock(const BlockDecoder &blk, const BlockPos &pos);
2014-07-08 14:58:40 +02:00
void renderMapBlockBottom(const BlockPos &pos);
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();
2018-03-24 14:54:45 +01:00
int getImageX(int val, bool absolute=false) const;
int getImageY(int val, bool absolute=false) const;
void setZoomed(int x, int y, Color color);
2012-08-23 12:46:22 +02:00
private:
void outputLeafletCode(std::string const &output);
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_drawAlpha;
bool m_shading;
bool m_leaflet;
bool m_dontWriteEmpty;
std::string m_backend;
int m_xBorder, m_yBorder;
2012-08-23 14:06:16 +02:00
2014-03-05 21:41:27 +01:00
DB *m_db;
Image *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;
int m_tileW;
int m_tileH;
2012-08-25 13:19:58 +02:00
int m_mapWidth;
int m_mapHeight;
ColorMap m_colorMap;
2018-03-25 15:44:30 +02:00
BitmapThing m_readPixels;
BitmapThing m_readInfo;
2014-08-02 16:30:52 +02:00
NameSet m_unknownNodes;
Color m_color[16][16];
uint8_t m_thickness[16][16];
2012-08-24 22:51:17 +02:00
PositionsList m_positions;
TileMap m_tiles;
int m_numTilesX, m_numTilesY;
2016-07-06 21:45:38 +02:00
int m_zoom;
uint m_scales;
}; // class TileGenerator
2012-08-23 12:46:22 +02:00
#endif // TILEGENERATOR_HEADER