minetestmapper/include/TileGenerator.h

165 lines
4.1 KiB
C
Raw Normal View History

#pragma once
2012-08-23 12:46:22 +02:00
#include <iostream>
#include <map>
#include <set>
2014-08-02 16:30:52 +02:00
#include <unordered_map>
#include <unordered_set>
#include <cstdint>
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"
#include "Image.h"
2014-03-05 21:41:27 +01:00
#include "db.h"
#include "types.h"
class BlockDecoder;
class Image;
enum {
SCALE_TOP = (1 << 0),
SCALE_BOTTOM = (1 << 1),
SCALE_LEFT = (1 << 2),
SCALE_RIGHT = (1 << 3),
};
enum {
EXH_NEVER, // Always use range queries
EXH_Y, // Exhaustively search Y space, range queries for X/Z
EXH_FULL, // Exhaustively search entire requested geometry
EXH_AUTO, // Automatically pick one of the previous modes
};
struct ColorEntry {
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 toColor() const { return Color(r, g, b, a); }
uint8_t r, g, b, a; // Red, Green, Blue, Alpha
uint8_t t; // "thickness" value
2018-03-25 15:44:30 +02:00
};
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];
};
2012-08-23 12:46:22 +02:00
class TileGenerator
{
private:
2014-08-02 16:30:52 +02:00
typedef std::unordered_map<std::string, ColorEntry> ColorMap;
typedef std::unordered_set<std::string> NameSet;
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 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);
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 setExhaustiveSearch(int mode);
void parseColorsFile(const std::string &fileName);
2014-03-05 21:41:27 +01:00
void setBackend(std::string backend);
2016-07-06 21:45:38 +02:00
void setZoom(int zoom);
void setScales(uint flags);
void setDontWriteEmpty(bool f);
2012-08-23 13:32:22 +02:00
2020-03-28 14:02:27 +01:00
void generate(const std::string &input, const std::string &output);
void printGeometry(const std::string &input);
static std::set<std::string> getSupportedBackends();
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();
2012-08-23 15:35:00 +02:00
void renderMap();
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();
void reportProgress(size_t count);
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:
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_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;
/* smallest/largest seen X or Z block coordinate */
2012-08-23 14:06:16 +02:00
int m_xMin;
int m_xMax;
int m_zMin;
int m_zMax;
/* Y limits for rendered area (node units) */
2014-03-05 18:06:05 +01:00
int m_yMin;
int m_yMax;
/* limits for rendered area (block units) */
int16_t m_geomX;
int16_t m_geomY; /* Y in terms of rendered image, Z in the world */
int16_t m_geomX2;
int16_t m_geomY2;
2012-08-25 13:19:58 +02:00
int m_mapWidth;
int m_mapHeight;
int m_exhaustiveSearch;
std::map<int16_t, std::set<int16_t>> m_positions; /* indexed by Z, contains X coords */
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
2016-07-06 21:45:38 +02:00
int m_zoom;
uint m_scales;
2012-08-23 12:46:22 +02:00
size_t m_progressMax;
int m_progressLast; // percentage
}; // class TileGenerator