mirror of
https://github.com/minetest/minetestmapper.git
synced 2025-06-28 06:40:16 +02:00
Move include files
This commit is contained in:
37
include/Image.h
Normal file
37
include/Image.h
Normal file
@ -0,0 +1,37 @@
|
||||
#ifndef IMAGE_HEADER
|
||||
#define IMAGE_HEADER
|
||||
|
||||
#include "types.h"
|
||||
#include <string>
|
||||
#include <gd.h>
|
||||
|
||||
struct Color {
|
||||
Color() : r(0), g(0), b(0), a(0) {};
|
||||
Color(u8 r, u8 g, u8 b) : r(r), g(g), b(b), a(255) {};
|
||||
Color(u8 r, u8 g, u8 b, u8 a) : r(r), g(g), b(b), a(a) {};
|
||||
inline Color noAlpha() const { return Color(r, g, b); }
|
||||
|
||||
u8 r, g, b, a;
|
||||
};
|
||||
|
||||
class Image {
|
||||
public:
|
||||
Image(int width, int height);
|
||||
~Image();
|
||||
|
||||
void setPixel(int x, int y, const Color &c);
|
||||
Color getPixel(int x, int y);
|
||||
void drawLine(int x1, int y1, int x2, int y2, const Color &c);
|
||||
void drawText(int x, int y, const std::string &s, const Color &c);
|
||||
void drawFilledRect(int x, int y, int w, int h, const Color &c);
|
||||
void drawCircle(int x, int y, int diameter, const Color &c);
|
||||
void save(const std::string &filename);
|
||||
|
||||
private:
|
||||
Image(const Image&);
|
||||
|
||||
int m_width, m_height;
|
||||
gdImagePtr m_image;
|
||||
};
|
||||
|
||||
#endif // IMAGE_HEADER
|
50
include/PixelAttributes.h
Normal file
50
include/PixelAttributes.h
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* =====================================================================
|
||||
* Version: 1.0
|
||||
* Created: 25.08.2012 10:55:29
|
||||
* Author: Miroslav Bendík
|
||||
* Company: LinuxOS.sk
|
||||
* =====================================================================
|
||||
*/
|
||||
|
||||
#ifndef PIXELATTRIBUTES_H_ADZ35GYF
|
||||
#define PIXELATTRIBUTES_H_ADZ35GYF
|
||||
|
||||
#include <limits>
|
||||
#include <stdint.h>
|
||||
#include "config.h"
|
||||
|
||||
struct PixelAttribute {
|
||||
PixelAttribute(): height(std::numeric_limits<int>::min()), thickness(0) {};
|
||||
int height;
|
||||
uint8_t thickness;
|
||||
inline bool valid_height() {
|
||||
return height != std::numeric_limits<int>::min();
|
||||
}
|
||||
};
|
||||
|
||||
class PixelAttributes
|
||||
{
|
||||
public:
|
||||
PixelAttributes();
|
||||
virtual ~PixelAttributes();
|
||||
void setWidth(int width);
|
||||
void scroll();
|
||||
inline PixelAttribute &attribute(int z, int x) { return m_pixelAttributes[z + 1][x + 1]; };
|
||||
|
||||
private:
|
||||
void freeAttributes();
|
||||
|
||||
private:
|
||||
enum Line {
|
||||
FirstLine = 0,
|
||||
LastLine = BLOCK_SIZE,
|
||||
EmptyLine = BLOCK_SIZE + 1,
|
||||
LineCount = BLOCK_SIZE + 2
|
||||
};
|
||||
PixelAttribute *m_pixelAttributes[BLOCK_SIZE + 2]; // 1px gradient + empty
|
||||
int m_width;
|
||||
};
|
||||
|
||||
#endif /* end of include guard: PIXELATTRIBUTES_H_ADZ35GYF */
|
||||
|
38
include/PlayerAttributes.h
Normal file
38
include/PlayerAttributes.h
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* =====================================================================
|
||||
* Version: 1.0
|
||||
* Created: 01.09.2012 14:38:08
|
||||
* Author: Miroslav Bendík
|
||||
* Company: LinuxOS.sk
|
||||
* =====================================================================
|
||||
*/
|
||||
|
||||
#ifndef PLAYERATTRIBUTES_H_D7THWFVV
|
||||
#define PLAYERATTRIBUTES_H_D7THWFVV
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
struct Player
|
||||
{
|
||||
std::string name;
|
||||
double x;
|
||||
double y;
|
||||
double z;
|
||||
}; /* ----- end of struct Player ----- */
|
||||
|
||||
class PlayerAttributes
|
||||
{
|
||||
public:
|
||||
typedef std::list<Player> Players;
|
||||
|
||||
PlayerAttributes(const std::string &sourceDirectory);
|
||||
Players::iterator begin();
|
||||
Players::iterator end();
|
||||
|
||||
private:
|
||||
Players m_players;
|
||||
}; /* ----- end of class PlayerAttributes ----- */
|
||||
|
||||
#endif /* end of include guard: PLAYERATTRIBUTES_H_D7THWFVV */
|
||||
|
138
include/TileGenerator.h
Normal file
138
include/TileGenerator.h
Normal file
@ -0,0 +1,138 @@
|
||||
#ifndef TILEGENERATOR_HEADER
|
||||
#define TILEGENERATOR_HEADER
|
||||
|
||||
#include <gd.h>
|
||||
#include <iosfwd>
|
||||
#include <list>
|
||||
#include <config.h>
|
||||
#if __cplusplus >= 201103L
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#else
|
||||
#include <map>
|
||||
#include <set>
|
||||
#endif
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include "PixelAttributes.h"
|
||||
#include "Image.h"
|
||||
#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 {
|
||||
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); }
|
||||
uint8_t r;
|
||||
uint8_t g;
|
||||
uint8_t b;
|
||||
uint8_t a;
|
||||
uint8_t t;
|
||||
};
|
||||
|
||||
|
||||
class TileGenerator
|
||||
{
|
||||
private:
|
||||
#if __cplusplus >= 201103L
|
||||
typedef std::unordered_map<std::string, ColorEntry> ColorMap;
|
||||
typedef std::unordered_map<int, std::string> NameMap;
|
||||
typedef std::unordered_set<std::string> NameSet;
|
||||
#else
|
||||
typedef std::map<std::string, ColorEntry> ColorMap;
|
||||
typedef std::map<int, std::string> NameMap;
|
||||
typedef std::set<std::string> NameSet;
|
||||
#endif
|
||||
|
||||
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); Color parseColor(const std::string &color);
|
||||
void setDrawOrigin(bool drawOrigin);
|
||||
void setDrawPlayers(bool drawPlayers);
|
||||
void setDrawScale(bool drawScale);
|
||||
void setDrawAlpha(bool drawAlpha);
|
||||
void setShading(bool shading);
|
||||
void setGeometry(int x, int y, int w, int h);
|
||||
void setMinY(int y);
|
||||
void setMaxY(int y);
|
||||
void parseColorsFile(const std::string &fileName);
|
||||
void setBackend(std::string backend);
|
||||
void generate(const std::string &input, const std::string &output);
|
||||
void setZoom(int zoom);
|
||||
void setScales(uint flags);
|
||||
|
||||
private:
|
||||
void parseColorsStream(std::istream &in);
|
||||
void openDb(const std::string &input);
|
||||
void closeDatabase();
|
||||
void loadBlocks();
|
||||
void createImage();
|
||||
void renderMap();
|
||||
std::list<int> getZValueList() const;
|
||||
void renderMapBlock(const ustring &mapBlock, const BlockPos &pos, int version);
|
||||
void renderMapBlockBottom(const BlockPos &pos);
|
||||
void renderShading(int zPos);
|
||||
void renderScale();
|
||||
void renderOrigin();
|
||||
void renderPlayers(const std::string &inputPath);
|
||||
void writeImage(const std::string &output);
|
||||
void printUnknown();
|
||||
int getImageX(int val, bool absolute=false) const;
|
||||
int getImageY(int val, bool absolute=false) const;
|
||||
void setZoomed(int x, int y, Color color);
|
||||
|
||||
private:
|
||||
Color m_bgColor;
|
||||
Color m_scaleColor;
|
||||
Color m_originColor;
|
||||
Color m_playerColor;
|
||||
bool m_drawOrigin;
|
||||
bool m_drawPlayers;
|
||||
bool m_drawScale;
|
||||
bool m_drawAlpha;
|
||||
bool m_shading;
|
||||
std::string m_backend;
|
||||
int m_xBorder, m_yBorder;
|
||||
|
||||
DB *m_db;
|
||||
Image *m_image;
|
||||
PixelAttributes m_blockPixelAttributes;
|
||||
int m_xMin;
|
||||
int m_xMax;
|
||||
int m_zMin;
|
||||
int m_zMax;
|
||||
int m_yMin;
|
||||
int m_yMax;
|
||||
int m_geomX;
|
||||
int m_geomY;
|
||||
int m_geomX2;
|
||||
int m_geomY2;
|
||||
int m_mapWidth;
|
||||
int m_mapHeight;
|
||||
std::list<std::pair<int, int> > m_positions;
|
||||
NameMap m_nameMap;
|
||||
ColorMap m_colorMap;
|
||||
uint16_t m_readPixels[16];
|
||||
uint16_t m_readInfo[16];
|
||||
NameSet m_unknownNodes;
|
||||
Color m_color[16][16];
|
||||
uint8_t m_thickness[16][16];
|
||||
|
||||
int m_blockAirId;
|
||||
int m_blockIgnoreId;
|
||||
int m_zoom;
|
||||
uint m_scales;
|
||||
}; // class TileGenerator
|
||||
|
||||
#endif // TILEGENERATOR_HEADER
|
37
include/ZlibDecompressor.h
Normal file
37
include/ZlibDecompressor.h
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* =====================================================================
|
||||
* Version: 1.0
|
||||
* Created: 18.09.2012 10:20:51
|
||||
* Author: Miroslav Bendík
|
||||
* Company: LinuxOS.sk
|
||||
* =====================================================================
|
||||
*/
|
||||
|
||||
#ifndef ZLIBDECOMPRESSOR_H_ZQL1PN8Q
|
||||
#define ZLIBDECOMPRESSOR_H_ZQL1PN8Q
|
||||
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include "types.h"
|
||||
|
||||
|
||||
class ZlibDecompressor
|
||||
{
|
||||
public:
|
||||
class DecompressError {
|
||||
};
|
||||
|
||||
ZlibDecompressor(const unsigned char *data, std::size_t size);
|
||||
~ZlibDecompressor();
|
||||
void setSeekPos(std::size_t seekPos);
|
||||
std::size_t seekPos() const;
|
||||
ustring decompress();
|
||||
|
||||
private:
|
||||
const unsigned char *m_data;
|
||||
std::size_t m_seekPos;
|
||||
std::size_t m_size;
|
||||
}; /* ----- end of class ZlibDecompressor ----- */
|
||||
|
||||
#endif /* end of include guard: ZLIBDECOMPRESSOR_H_ZQL1PN8Q */
|
||||
|
13
include/cmake_config.h.in
Normal file
13
include/cmake_config.h.in
Normal file
@ -0,0 +1,13 @@
|
||||
// Filled in by the build system
|
||||
|
||||
#ifndef CMAKE_CONFIG_H
|
||||
#define CMAKE_CONFIG_H
|
||||
|
||||
#define USE_POSTGRESQL @USE_POSTGRESQL@
|
||||
#define USE_LEVELDB @USE_LEVELDB@
|
||||
#define USE_REDIS @USE_REDIS@
|
||||
|
||||
#define SHAREDIR "@SHAREDIR@"
|
||||
|
||||
#endif
|
||||
|
17
include/config.h
Normal file
17
include/config.h
Normal file
@ -0,0 +1,17 @@
|
||||
#if MSDOS || __OS2__ || __NT__ || _WIN32
|
||||
#define PATH_SEPARATOR '\\'
|
||||
#else
|
||||
#define PATH_SEPARATOR '/'
|
||||
#endif
|
||||
|
||||
#define BLOCK_SIZE 16
|
||||
|
||||
#ifdef USE_CMAKE_CONFIG_H
|
||||
#include "cmake_config.h"
|
||||
#else
|
||||
#define USE_POSTGRESQL 0
|
||||
#define USE_LEVELDB 0
|
||||
#define USE_REDIS 0
|
||||
|
||||
#define SHAREDIR "/usr/share/minetest"
|
||||
#endif
|
21
include/db-leveldb.h
Normal file
21
include/db-leveldb.h
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef DB_LEVELDB_HEADER
|
||||
#define DB_LEVELDB_HEADER
|
||||
|
||||
#include "db.h"
|
||||
#include <leveldb/db.h>
|
||||
|
||||
class DBLevelDB : public DB {
|
||||
public:
|
||||
DBLevelDB(const std::string &mapdir);
|
||||
virtual std::vector<BlockPos> getBlockPos();
|
||||
virtual void getBlocksOnZ(std::map<int16_t, BlockList> &blocks, int16_t zPos);
|
||||
virtual ~DBLevelDB();
|
||||
private:
|
||||
void loadPosCache();
|
||||
|
||||
std::vector<BlockPos> posCache;
|
||||
|
||||
leveldb::DB *db;
|
||||
};
|
||||
|
||||
#endif // DB_LEVELDB_HEADER
|
29
include/db-postgresql.h
Normal file
29
include/db-postgresql.h
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef _DB_POSTGRESQL_H
|
||||
#define _DB_POSTGRESQL_H
|
||||
|
||||
#include "db.h"
|
||||
#include <libpq-fe.h>
|
||||
|
||||
class DBPostgreSQL : public DB {
|
||||
public:
|
||||
DBPostgreSQL(const std::string &mapdir);
|
||||
virtual std::vector<BlockPos> getBlockPos();
|
||||
virtual void getBlocksOnZ(std::map<int16_t, BlockList> &blocks, int16_t zPos);
|
||||
virtual ~DBPostgreSQL();
|
||||
protected:
|
||||
PGresult *checkResults(PGresult *res, bool clear = true);
|
||||
void prepareStatement(const std::string &name, const std::string &sql);
|
||||
PGresult *execPrepared(
|
||||
const char *stmtName, const int paramsNumber,
|
||||
const void **params,
|
||||
const int *paramsLengths = NULL, const int *paramsFormats = NULL,
|
||||
bool clear = true, bool nobinary = true
|
||||
);
|
||||
int pg_to_int(PGresult *res, int row, int col);
|
||||
int pg_binary_to_int(PGresult *res, int row, int col);
|
||||
BlockPos pg_to_blockpos(PGresult *res, int row, int col);
|
||||
private:
|
||||
PGconn *db;
|
||||
};
|
||||
|
||||
#endif // _DB_POSTGRESQL_H
|
25
include/db-redis.h
Normal file
25
include/db-redis.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef DB_REDIS_HEADER
|
||||
#define DB_REDIS_HEADER
|
||||
|
||||
#include "db.h"
|
||||
#include <hiredis.h>
|
||||
|
||||
class DBRedis : public DB {
|
||||
public:
|
||||
DBRedis(const std::string &mapdir);
|
||||
virtual std::vector<BlockPos> getBlockPos();
|
||||
virtual void getBlocksOnZ(std::map<int16_t, BlockList> &blocks, int16_t zPos);
|
||||
virtual ~DBRedis();
|
||||
private:
|
||||
static std::string replyTypeStr(int type);
|
||||
|
||||
void loadPosCache();
|
||||
void HMGET(const std::vector<BlockPos> &positions, std::vector<ustring> *result);
|
||||
|
||||
std::vector<BlockPos> posCache;
|
||||
|
||||
redisContext *ctx;
|
||||
std::string hash;
|
||||
};
|
||||
|
||||
#endif // DB_REDIS_HEADER
|
20
include/db-sqlite3.h
Normal file
20
include/db-sqlite3.h
Normal file
@ -0,0 +1,20 @@
|
||||
#ifndef _DB_SQLITE3_H
|
||||
#define _DB_SQLITE3_H
|
||||
|
||||
#include "db.h"
|
||||
#include <sqlite3.h>
|
||||
|
||||
class DBSQLite3 : public DB {
|
||||
public:
|
||||
DBSQLite3(const std::string &mapdir);
|
||||
virtual std::vector<BlockPos> getBlockPos();
|
||||
virtual void getBlocksOnZ(std::map<int16_t, BlockList> &blocks, int16_t zPos);
|
||||
virtual ~DBSQLite3();
|
||||
private:
|
||||
sqlite3 *db;
|
||||
|
||||
sqlite3_stmt *stmt_get_block_pos;
|
||||
sqlite3_stmt *stmt_get_blocks_z;
|
||||
};
|
||||
|
||||
#endif // _DB_SQLITE3_H
|
113
include/db.h
Normal file
113
include/db.h
Normal file
@ -0,0 +1,113 @@
|
||||
#ifndef DB_HEADER
|
||||
#define DB_HEADER
|
||||
|
||||
#include <stdint.h>
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include "types.h"
|
||||
|
||||
|
||||
class BlockPos {
|
||||
public:
|
||||
int16_t x;
|
||||
int16_t y;
|
||||
int16_t z;
|
||||
|
||||
BlockPos() : x(0), y(0), z(0) {}
|
||||
BlockPos(int16_t x, int16_t y, int16_t z) : x(x), y(y), z(z) {}
|
||||
bool operator < (const BlockPos &p) const
|
||||
{
|
||||
if (z > p.z) {
|
||||
return true;
|
||||
}
|
||||
if (z < p.z) {
|
||||
return false;
|
||||
}
|
||||
if (y > p.y) {
|
||||
return true;
|
||||
}
|
||||
if (y < p.y) {
|
||||
return false;
|
||||
}
|
||||
if (x > p.x) {
|
||||
return true;
|
||||
}
|
||||
if (x < p.x) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
typedef std::pair<BlockPos, ustring> Block;
|
||||
typedef std::list<Block> BlockList;
|
||||
|
||||
|
||||
class DB {
|
||||
protected:
|
||||
inline int64_t encodeBlockPos(const BlockPos pos) const;
|
||||
inline BlockPos decodeBlockPos(int64_t hash) const;
|
||||
|
||||
public:
|
||||
virtual std::vector<BlockPos> getBlockPos() = 0;
|
||||
virtual void getBlocksOnZ(std::map<int16_t, BlockList> &blocks, int16_t zPos) = 0;
|
||||
virtual ~DB() {};
|
||||
};
|
||||
|
||||
|
||||
|
||||
/****************
|
||||
* Black magic! *
|
||||
****************
|
||||
* The position hashing is seriously messed up,
|
||||
* and is a lot more complicated than it looks.
|
||||
*/
|
||||
|
||||
static inline int16_t unsigned_to_signed(uint16_t i, uint16_t max_positive)
|
||||
{
|
||||
if (i < max_positive) {
|
||||
return i;
|
||||
} else {
|
||||
return i - (max_positive * 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Modulo of a negative number does not work consistently in C
|
||||
static inline int64_t pythonmodulo(int64_t i, int64_t mod)
|
||||
{
|
||||
if (i >= 0) {
|
||||
return i % mod;
|
||||
}
|
||||
return mod - ((-i) % mod);
|
||||
}
|
||||
|
||||
|
||||
inline int64_t DB::encodeBlockPos(const BlockPos pos) const
|
||||
{
|
||||
return (uint64_t) pos.z * 0x1000000 +
|
||||
(uint64_t) pos.y * 0x1000 +
|
||||
(uint64_t) pos.x;
|
||||
}
|
||||
|
||||
|
||||
inline BlockPos DB::decodeBlockPos(int64_t hash) const
|
||||
{
|
||||
BlockPos pos;
|
||||
pos.x = unsigned_to_signed(pythonmodulo(hash, 4096), 2048);
|
||||
hash = (hash - pos.x) / 4096;
|
||||
pos.y = unsigned_to_signed(pythonmodulo(hash, 4096), 2048);
|
||||
hash = (hash - pos.y) / 4096;
|
||||
pos.z = unsigned_to_signed(pythonmodulo(hash, 4096), 2048);
|
||||
return pos;
|
||||
}
|
||||
|
||||
/*******************
|
||||
* End black magic *
|
||||
*******************/
|
||||
|
||||
#endif // DB_HEADER
|
5
include/types.h
Normal file
5
include/types.h
Normal file
@ -0,0 +1,5 @@
|
||||
#include <string>
|
||||
|
||||
typedef std::basic_string<unsigned char> ustring;
|
||||
typedef unsigned int uint;
|
||||
typedef unsigned char u8;
|
10
include/util.h
Normal file
10
include/util.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef _UTIL_H
|
||||
#define _UTIL_H
|
||||
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <fstream>
|
||||
|
||||
std::string get_setting(std::string name, std::istream &is);
|
||||
|
||||
#endif // _UTIL_H
|
Reference in New Issue
Block a user