minetest-mapper-cpp/TileGenerator.h

194 lines
5.2 KiB
C
Raw Normal View History

2012-08-23 03:46:22 -07: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 05:21:34 -07:00
#include <gd.h>
#include <climits>
2012-09-01 06:51:02 -07:00
#include <iosfwd>
2012-08-23 06:35:00 -07:00
#include <list>
#if __cplusplus >= 201103L
#include <unordered_map>
#else
2012-08-23 04:32:22 -07:00
#include <map>
#endif
2012-09-01 06:51:02 -07:00
#include <set>
#include <stdint.h>
2012-08-23 03:46:22 -07:00
#include <string>
#include <string>
#include "types.h"
2012-08-25 04:19:58 -07:00
#include "PixelAttributes.h"
2014-05-06 07:20:22 -07:00
#include "BlockPos.h"
#include "Color.h"
2014-03-05 12:41:27 -08:00
#include "db.h"
#define TILECENTER_IS_WORLDCENTER INT_MAX
#define TILECENTER_IS_MAPCENTER INT_MIN
2012-08-23 03:46:22 -07:00
class TileGenerator
{
private:
#if __cplusplus >= 201103L
typedef std::unordered_map<std::string, ColorEntry> ColorMap;
typedef std::unordered_map<int, std::string> NodeID2NameMap;
#else
typedef std::map<std::string, ColorEntry> ColorMap;
typedef std::map<int, std::string> NodeID2NameMap;
#endif
2012-08-23 03:46:22 -07:00
public:
struct UnpackError
{
BlockPos pos;
const char *type;
size_t offset;
size_t length;
size_t dataLength;
UnpackError(const char *t, size_t o, size_t l, size_t dl) : type(t), offset(o), length(l), dataLength(dl) {}
};
2012-08-23 03:46:22 -07:00
TileGenerator();
~TileGenerator();
void setBgColor(const Color &bgColor);
void setScaleColor(const Color &scaleColor);
void setOriginColor(const Color &originColor);
void setPlayerColor(const Color &playerColor);
Color parseColor(const Color &color);
2012-08-23 03:46:22 -07:00
void setDrawOrigin(bool drawOrigin);
void setDrawPlayers(bool drawPlayers);
void setDrawScale(bool drawScale);
void setDrawAlpha(bool drawAlpha);
void setShading(bool shading);
2012-11-24 10:25:13 -08:00
void setGeometry(int x, int y, int w, int h);
2014-03-05 09:06:05 -08:00
void setMinY(int y);
void setMaxY(int y);
Make the geometry pixel-accurate instead of map-block accurate When requesting, for instance, a 75x85 map, the mapper will now create a 75x85 map, instead of an 80x96 (or even 96x108) map as it did before. This new behavior is the default when using one of the options --centergeometry or --cornergeometry. In addition, both of these options will no longer shrink the map, to remove rows or columns of empty blocks at the edges. Previously, this behavior was enabled with --forcegeometry. An option --geometrymode has been added as well, to tune the interpretation of the geometry. It supports 4 flags: - pixel: the requested geometry is interpreted with pixel granularity. The map is not enlarged to include entire map blocks. - block: the requested geometry is interpreted with block granularity. The map is enlarged with at most 15 nodes at each of the four edges, so that it includes entire map blocks only. - fixed: a map of the requested geometry is created (after adjustmens for 'block' mode). Empty rows or columns at the edges are not removed. - shrink: Empty rows and columns at the map edges are removed to generate the smallest picture possible. Lastly, a new geometry syntax has been added, which is more compatible with known syntax (i.e. X-Windows), and which allows the offset to be optional. If the offset is omitted, the picture defaults to be centered around 0,0. `<width>x<height>[+|-<xoffset>+|-<yoffset>]` For compatibility, the behavior of the option --geometry was not changed. If (and only if) used before --geometrymode, it enables block granularity and shrink. The old option --forcegeometry is no longer documented, but still recognised for compatibility.
2014-04-15 01:46:21 -07:00
void setShrinkGeometry(bool shrink);
void setBlockGeometry(bool block);
void setSqliteCacheWorldRow(bool cacheWorldRow);
void setTileBorderColor(const Color &tileBorderColor);
void setTileBorderSize(int size);
void setTileSize(int width, int heigth);
void setTileOrigin(int x, int y);
void enableProgressIndicator(void);
void parseColorsFile(const std::string &fileName);
2014-03-05 12:41:27 -08:00
void setBackend(std::string backend);
2012-08-23 04:32:22 -07:00
void generate(const std::string &input, const std::string &output);
private:
void parseColorsStream(std::istream &in, const std::string &filename);
std::string getWorldDatabaseBackend(const std::string &input);
2012-08-23 04:32:22 -07:00
void openDb(const std::string &input);
void loadBlocks();
2014-03-05 12:41:27 -08:00
BlockPos decodeBlockPos(int64_t blockId) const;
2012-08-23 05:21:34 -07:00
void createImage();
Make the geometry pixel-accurate instead of map-block accurate When requesting, for instance, a 75x85 map, the mapper will now create a 75x85 map, instead of an 80x96 (or even 96x108) map as it did before. This new behavior is the default when using one of the options --centergeometry or --cornergeometry. In addition, both of these options will no longer shrink the map, to remove rows or columns of empty blocks at the edges. Previously, this behavior was enabled with --forcegeometry. An option --geometrymode has been added as well, to tune the interpretation of the geometry. It supports 4 flags: - pixel: the requested geometry is interpreted with pixel granularity. The map is not enlarged to include entire map blocks. - block: the requested geometry is interpreted with block granularity. The map is enlarged with at most 15 nodes at each of the four edges, so that it includes entire map blocks only. - fixed: a map of the requested geometry is created (after adjustmens for 'block' mode). Empty rows or columns at the edges are not removed. - shrink: Empty rows and columns at the map edges are removed to generate the smallest picture possible. Lastly, a new geometry syntax has been added, which is more compatible with known syntax (i.e. X-Windows), and which allows the offset to be optional. If the offset is omitted, the picture defaults to be centered around 0,0. `<width>x<height>[+|-<xoffset>+|-<yoffset>]` For compatibility, the behavior of the option --geometry was not changed. If (and only if) used before --geometrymode, it enables block granularity and shrink. The old option --forcegeometry is no longer documented, but still recognised for compatibility.
2014-04-15 01:46:21 -07:00
void computeMapParameters();
void computeTileParameters(
// Input parameters
int minPos,
int maxPos,
int mapStartNodeOffset,
int mapEndNodeOffset,
int tileOrigin,
int tileSize,
// Input / Output parameters
int &pictSize,
// Output parameters
int &tileBorderCount,
int &tileMapOffset,
int &tileMapExcess,
// Behavior selection
bool ascending);
2012-08-23 06:35:00 -07:00
void renderMap();
2012-08-24 00:46:14 -07:00
std::list<int> getZValueList() const;
Make the geometry pixel-accurate instead of map-block accurate When requesting, for instance, a 75x85 map, the mapper will now create a 75x85 map, instead of an 80x96 (or even 96x108) map as it did before. This new behavior is the default when using one of the options --centergeometry or --cornergeometry. In addition, both of these options will no longer shrink the map, to remove rows or columns of empty blocks at the edges. Previously, this behavior was enabled with --forcegeometry. An option --geometrymode has been added as well, to tune the interpretation of the geometry. It supports 4 flags: - pixel: the requested geometry is interpreted with pixel granularity. The map is not enlarged to include entire map blocks. - block: the requested geometry is interpreted with block granularity. The map is enlarged with at most 15 nodes at each of the four edges, so that it includes entire map blocks only. - fixed: a map of the requested geometry is created (after adjustmens for 'block' mode). Empty rows or columns at the edges are not removed. - shrink: Empty rows and columns at the map edges are removed to generate the smallest picture possible. Lastly, a new geometry syntax has been added, which is more compatible with known syntax (i.e. X-Windows), and which allows the offset to be optional. If the offset is omitted, the picture defaults to be centered around 0,0. `<width>x<height>[+|-<xoffset>+|-<yoffset>]` For compatibility, the behavior of the option --geometry was not changed. If (and only if) used before --geometrymode, it enables block granularity and shrink. The old option --forcegeometry is no longer documented, but still recognised for compatibility.
2014-04-15 01:46:21 -07:00
void pushPixelRows(int zPosLimit);
void processMapBlock(const DB::Block &block);
void renderMapBlock(const ustring &mapBlock, const BlockPos &pos, int version);
2012-08-25 05:11:55 -07:00
void renderScale();
2012-08-25 06:21:51 -07:00
void renderOrigin();
2012-08-25 07:29:41 -07:00
void renderPlayers(const std::string &inputPath);
2012-08-23 05:21:34 -07:00
void writeImage(const std::string &output);
2012-08-25 07:41:53 -07:00
void printUnknown();
Make the geometry pixel-accurate instead of map-block accurate When requesting, for instance, a 75x85 map, the mapper will now create a 75x85 map, instead of an 80x96 (or even 96x108) map as it did before. This new behavior is the default when using one of the options --centergeometry or --cornergeometry. In addition, both of these options will no longer shrink the map, to remove rows or columns of empty blocks at the edges. Previously, this behavior was enabled with --forcegeometry. An option --geometrymode has been added as well, to tune the interpretation of the geometry. It supports 4 flags: - pixel: the requested geometry is interpreted with pixel granularity. The map is not enlarged to include entire map blocks. - block: the requested geometry is interpreted with block granularity. The map is enlarged with at most 15 nodes at each of the four edges, so that it includes entire map blocks only. - fixed: a map of the requested geometry is created (after adjustmens for 'block' mode). Empty rows or columns at the edges are not removed. - shrink: Empty rows and columns at the map edges are removed to generate the smallest picture possible. Lastly, a new geometry syntax has been added, which is more compatible with known syntax (i.e. X-Windows), and which allows the offset to be optional. If the offset is omitted, the picture defaults to be centered around 0,0. `<width>x<height>[+|-<xoffset>+|-<yoffset>]` For compatibility, the behavior of the option --geometry was not changed. If (and only if) used before --geometrymode, it enables block granularity and shrink. The old option --forcegeometry is no longer documented, but still recognised for compatibility.
2014-04-15 01:46:21 -07:00
int mapX2ImageX(int val) const;
int mapY2ImageY(int val) const;
int worldX2ImageX(int val) const;
int worldZ2ImageY(int val) const;
int worldBlockX2StoredX(int xPos) const { return (xPos - m_xMin) * 16; }
int worldBlockZ2StoredY(int zPos) const { return (m_zMax - zPos) * 16; }
2012-08-23 03:46:22 -07:00
public:
int verboseCoordinates;
bool verboseStatistics;
bool progressIndicator;
2012-08-23 03:46:22 -07:00
private:
2012-08-23 05:43:11 -07:00
Color m_bgColor;
Color m_scaleColor;
Color m_originColor;
Color m_playerColor;
Color m_tileBorderColor;
2012-08-23 03:46:22 -07:00
bool m_drawOrigin;
bool m_drawPlayers;
bool m_drawScale;
bool m_drawAlpha;
bool m_shading;
2012-08-25 05:11:55 -07:00
int m_border;
2014-03-05 12:41:27 -08:00
std::string m_backend;
Make the geometry pixel-accurate instead of map-block accurate When requesting, for instance, a 75x85 map, the mapper will now create a 75x85 map, instead of an 80x96 (or even 96x108) map as it did before. This new behavior is the default when using one of the options --centergeometry or --cornergeometry. In addition, both of these options will no longer shrink the map, to remove rows or columns of empty blocks at the edges. Previously, this behavior was enabled with --forcegeometry. An option --geometrymode has been added as well, to tune the interpretation of the geometry. It supports 4 flags: - pixel: the requested geometry is interpreted with pixel granularity. The map is not enlarged to include entire map blocks. - block: the requested geometry is interpreted with block granularity. The map is enlarged with at most 15 nodes at each of the four edges, so that it includes entire map blocks only. - fixed: a map of the requested geometry is created (after adjustmens for 'block' mode). Empty rows or columns at the edges are not removed. - shrink: Empty rows and columns at the map edges are removed to generate the smallest picture possible. Lastly, a new geometry syntax has been added, which is more compatible with known syntax (i.e. X-Windows), and which allows the offset to be optional. If the offset is omitted, the picture defaults to be centered around 0,0. `<width>x<height>[+|-<xoffset>+|-<yoffset>]` For compatibility, the behavior of the option --geometry was not changed. If (and only if) used before --geometrymode, it enables block granularity and shrink. The old option --forcegeometry is no longer documented, but still recognised for compatibility.
2014-04-15 01:46:21 -07:00
bool m_shrinkGeometry;
bool m_blockGeometry;
bool m_sqliteCacheWorldRow;
2012-08-23 05:06:16 -07:00
2014-03-05 12:41:27 -08:00
DB *m_db;
2012-08-23 05:21:34 -07:00
gdImagePtr m_image;
2012-08-25 04:19:58 -07:00
PixelAttributes m_blockPixelAttributes;
2012-08-23 05:06:16 -07:00
int m_xMin;
int m_xMax;
int m_zMin;
int m_zMax;
2014-03-05 09:06:05 -08:00
int m_yMin;
int m_yMax;
int m_reqXMin;
int m_reqXMax;
int m_reqYMin;
int m_reqYMax;
int m_reqZMin;
int m_reqZMax;
int m_reqYMinNode; // Node offset within a map block
int m_reqYMaxNode; // Node offset within a map block
Make the geometry pixel-accurate instead of map-block accurate When requesting, for instance, a 75x85 map, the mapper will now create a 75x85 map, instead of an 80x96 (or even 96x108) map as it did before. This new behavior is the default when using one of the options --centergeometry or --cornergeometry. In addition, both of these options will no longer shrink the map, to remove rows or columns of empty blocks at the edges. Previously, this behavior was enabled with --forcegeometry. An option --geometrymode has been added as well, to tune the interpretation of the geometry. It supports 4 flags: - pixel: the requested geometry is interpreted with pixel granularity. The map is not enlarged to include entire map blocks. - block: the requested geometry is interpreted with block granularity. The map is enlarged with at most 15 nodes at each of the four edges, so that it includes entire map blocks only. - fixed: a map of the requested geometry is created (after adjustmens for 'block' mode). Empty rows or columns at the edges are not removed. - shrink: Empty rows and columns at the map edges are removed to generate the smallest picture possible. Lastly, a new geometry syntax has been added, which is more compatible with known syntax (i.e. X-Windows), and which allows the offset to be optional. If the offset is omitted, the picture defaults to be centered around 0,0. `<width>x<height>[+|-<xoffset>+|-<yoffset>]` For compatibility, the behavior of the option --geometry was not changed. If (and only if) used before --geometrymode, it enables block granularity and shrink. The old option --forcegeometry is no longer documented, but still recognised for compatibility.
2014-04-15 01:46:21 -07:00
int m_storedWidth;
int m_storedHeight;
int m_mapXStartNodeOffset;
int m_mapYStartNodeOffset;
int m_mapXEndNodeOffset;
int m_mapYEndNodeOffset;
int m_nextStoredYCoord;
int m_tileXOrigin;
int m_tileZOrigin;
int m_tileWidth;
int m_tileHeight;
int m_tileBorderSize;
int m_tileMapXOffset;
int m_tileMapYOffset;
Make the geometry pixel-accurate instead of map-block accurate When requesting, for instance, a 75x85 map, the mapper will now create a 75x85 map, instead of an 80x96 (or even 96x108) map as it did before. This new behavior is the default when using one of the options --centergeometry or --cornergeometry. In addition, both of these options will no longer shrink the map, to remove rows or columns of empty blocks at the edges. Previously, this behavior was enabled with --forcegeometry. An option --geometrymode has been added as well, to tune the interpretation of the geometry. It supports 4 flags: - pixel: the requested geometry is interpreted with pixel granularity. The map is not enlarged to include entire map blocks. - block: the requested geometry is interpreted with block granularity. The map is enlarged with at most 15 nodes at each of the four edges, so that it includes entire map blocks only. - fixed: a map of the requested geometry is created (after adjustmens for 'block' mode). Empty rows or columns at the edges are not removed. - shrink: Empty rows and columns at the map edges are removed to generate the smallest picture possible. Lastly, a new geometry syntax has been added, which is more compatible with known syntax (i.e. X-Windows), and which allows the offset to be optional. If the offset is omitted, the picture defaults to be centered around 0,0. `<width>x<height>[+|-<xoffset>+|-<yoffset>]` For compatibility, the behavior of the option --geometry was not changed. If (and only if) used before --geometrymode, it enables block granularity and shrink. The old option --forcegeometry is no longer documented, but still recognised for compatibility.
2014-04-15 01:46:21 -07:00
int m_tileBorderXCount;
int m_tileBorderYCount;
int m_pictWidth;
int m_pictHeight;
std::list<BlockPos> m_positions;
NodeID2NameMap m_nameMap;
ColorMap m_colors;
2012-08-24 13:51:17 -07:00
uint16_t m_readedPixels[16];
2012-08-25 07:41:53 -07:00
std::set<std::string> m_unknownNodes;
2012-08-24 13:51:17 -07:00
int m_blockAirId;
int m_blockIgnoreId;
2012-08-23 03:46:22 -07:00
}; /* ----- end of class TileGenerator ----- */
#endif /* end of include guard: TILEGENERATOR_H_JJNUCARH */