2021-09-03 21:04:40 +02:00
|
|
|
#pragma once
|
2012-08-23 12:46:22 +02:00
|
|
|
|
2020-05-08 22:10:49 +02:00
|
|
|
#include <iostream>
|
2020-03-27 16:12:26 +01:00
|
|
|
#include <map>
|
|
|
|
#include <set>
|
2014-08-02 16:30:52 +02:00
|
|
|
#include <unordered_map>
|
2020-05-08 22:10:49 +02:00
|
|
|
#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"
|
2016-11-18 23:34:31 +01:00
|
|
|
#include "Image.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
|
|
|
|
2020-05-08 22:10:49 +02:00
|
|
|
class BlockDecoder;
|
|
|
|
class Image;
|
|
|
|
|
2016-11-18 22:01:15 +01:00
|
|
|
enum {
|
|
|
|
SCALE_TOP = (1 << 0),
|
|
|
|
SCALE_BOTTOM = (1 << 1),
|
|
|
|
SCALE_LEFT = (1 << 2),
|
|
|
|
SCALE_RIGHT = (1 << 3),
|
|
|
|
};
|
|
|
|
|
2020-03-27 21:10:00 +01:00
|
|
|
enum {
|
|
|
|
EXH_NEVER, // Always use range queries
|
2020-03-28 00:14:47 +01:00
|
|
|
EXH_Y, // Exhaustively search Y space, range queries for X/Z
|
2020-03-27 21:10:00 +01:00
|
|
|
EXH_FULL, // Exhaustively search entire requested geometry
|
|
|
|
EXH_AUTO, // Automatically pick one of the previous modes
|
|
|
|
};
|
|
|
|
|
2014-04-03 20:32:48 +02:00
|
|
|
struct ColorEntry {
|
2020-05-08 22:10:49 +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 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;
|
|
|
|
}
|
2022-02-09 23:06:29 +01:00
|
|
|
inline bool any_neq(uint16_t v) const {
|
2018-03-25 15:44:30 +02:00
|
|
|
for (int i = 0; i < 16; ++i) {
|
2022-02-09 23:06:29 +01:00
|
|
|
if (val[i] != v)
|
|
|
|
return true;
|
2018-03-25 15:44:30 +02:00
|
|
|
}
|
2022-02-09 23:06:29 +01:00
|
|
|
return false;
|
2018-03-25 15:44:30 +02:00
|
|
|
}
|
2022-02-09 23:06:29 +01:00
|
|
|
inline bool any() const { return any_neq(0); }
|
|
|
|
inline bool full() const { return !any_neq(0xffff); }
|
2018-03-25 15:44:30 +02:00
|
|
|
inline void set(unsigned int x, unsigned int z) {
|
|
|
|
val[z] |= (1 << x);
|
|
|
|
}
|
2022-02-09 23:06:29 +01:00
|
|
|
inline bool get(unsigned int x, unsigned int z) const {
|
2018-03-25 15:44:30 +02:00
|
|
|
return !!(val[z] & (1 << x));
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t val[16];
|
2014-04-03 20:32:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-08-23 12:46:22 +02:00
|
|
|
class TileGenerator
|
|
|
|
{
|
2012-08-23 12:55:31 +02:00
|
|
|
private:
|
2014-08-02 16:30:52 +02:00
|
|
|
typedef std::unordered_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);
|
2020-03-27 16:12:26 +01:00
|
|
|
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);
|
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);
|
2020-03-27 21:10:00 +01:00
|
|
|
void setExhaustiveSearch(int mode);
|
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);
|
2016-07-06 21:45:38 +02:00
|
|
|
void setZoom(int zoom);
|
2016-11-18 22:01:15 +01:00
|
|
|
void setScales(uint flags);
|
2018-10-31 16:18:29 +01:00
|
|
|
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);
|
2022-02-09 21:52:28 +01:00
|
|
|
void dumpBlock(const std::string &input, BlockPos pos);
|
|
|
|
|
2020-03-28 14:02:27 +01:00
|
|
|
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);
|
2016-10-13 23:26:59 +02:00
|
|
|
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();
|
2021-09-03 21:04:40 +02:00
|
|
|
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;
|
2016-11-18 23:34:31 +01:00
|
|
|
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;
|
2014-04-03 20:32:48 +02:00
|
|
|
bool m_drawAlpha;
|
2014-03-05 17:19:37 +01:00
|
|
|
bool m_shading;
|
2018-10-31 16:18:29 +01:00
|
|
|
bool m_dontWriteEmpty;
|
2014-07-11 10:54:50 +02:00
|
|
|
std::string m_backend;
|
2016-11-18 22:01:15 +01:00
|
|
|
int m_xBorder, m_yBorder;
|
2012-08-23 14:06:16 +02:00
|
|
|
|
2014-03-05 21:41:27 +01:00
|
|
|
DB *m_db;
|
2016-11-18 23:34:31 +01:00
|
|
|
Image *m_image;
|
2012-08-25 13:19:58 +02:00
|
|
|
PixelAttributes m_blockPixelAttributes;
|
2020-03-27 16:12:26 +01:00
|
|
|
/* 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;
|
2020-03-27 16:12:26 +01:00
|
|
|
/* Y limits for rendered area (node units) */
|
2014-03-05 18:06:05 +01:00
|
|
|
int m_yMin;
|
|
|
|
int m_yMax;
|
2020-03-27 16:12:26 +01:00
|
|
|
/* 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;
|
2021-09-03 21:04:40 +02:00
|
|
|
|
2012-08-25 13:19:58 +02:00
|
|
|
int m_mapWidth;
|
|
|
|
int m_mapHeight;
|
2020-03-27 21:10:00 +01:00
|
|
|
int m_exhaustiveSearch;
|
2022-02-09 23:06:29 +01:00
|
|
|
std::set<std::string> m_unknownNodes;
|
|
|
|
bool m_renderedAny;
|
2020-03-27 16:12:26 +01:00
|
|
|
std::map<int16_t, std::set<int16_t>> m_positions; /* indexed by Z, contains X coords */
|
2015-03-18 22:49:19 +01:00
|
|
|
ColorMap m_colorMap;
|
2018-03-25 15:44:30 +02:00
|
|
|
BitmapThing m_readPixels;
|
|
|
|
BitmapThing m_readInfo;
|
2015-03-18 22:49:19 +01:00
|
|
|
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;
|
2016-11-18 22:01:15 +01:00
|
|
|
uint m_scales;
|
2012-08-23 12:46:22 +02:00
|
|
|
|
2021-09-03 21:04:40 +02:00
|
|
|
size_t m_progressMax;
|
|
|
|
int m_progressLast; // percentage
|
|
|
|
}; // class TileGenerator
|