mirror of
https://github.com/minetest/minetestmapper.git
synced 2024-11-22 07:23:46 +01:00
Some more code modernization
also a few small performance improvements
This commit is contained in:
parent
2979dc5b6b
commit
8e83ce6464
@ -11,7 +11,8 @@ static inline uint16_t readU16(const unsigned char *data)
|
|||||||
return data[0] << 8 | data[1];
|
return data[0] << 8 | data[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
static int readBlockContent(const unsigned char *mapData, u8 contentWidth, unsigned int datapos)
|
static inline uint16_t readBlockContent(const unsigned char *mapData,
|
||||||
|
u8 contentWidth, unsigned int datapos)
|
||||||
{
|
{
|
||||||
if (contentWidth == 2) {
|
if (contentWidth == 2) {
|
||||||
size_t index = datapos << 1;
|
size_t index = datapos << 1;
|
||||||
@ -21,7 +22,7 @@ static int readBlockContent(const unsigned char *mapData, u8 contentWidth, unsig
|
|||||||
if (param <= 0x7f)
|
if (param <= 0x7f)
|
||||||
return param;
|
return param;
|
||||||
else
|
else
|
||||||
return (int(param) << 4) | (int(mapData[datapos + 0x2000]) >> 4);
|
return (param << 4) | (mapData[datapos + 0x2000] >> 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,10 +126,10 @@ void BlockDecoder::decode(const ustring &datastr)
|
|||||||
|
|
||||||
// Node timers
|
// Node timers
|
||||||
if (version >= 25) {
|
if (version >= 25) {
|
||||||
dataOffset++;
|
uint8_t timerLength = data[dataOffset++];
|
||||||
uint16_t numTimers = readU16(data + dataOffset);
|
uint16_t numTimers = readU16(data + dataOffset);
|
||||||
dataOffset += 2;
|
dataOffset += 2;
|
||||||
dataOffset += numTimers * 10;
|
dataOffset += numTimers * timerLength;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,16 +139,18 @@ bool BlockDecoder::isEmpty() const
|
|||||||
return m_nameMap.empty();
|
return m_nameMap.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string BlockDecoder::getNode(u8 x, u8 y, u8 z) const
|
const static std::string empty;
|
||||||
|
|
||||||
|
const std::string &BlockDecoder::getNode(u8 x, u8 y, u8 z) const
|
||||||
{
|
{
|
||||||
unsigned int position = x + (y << 4) + (z << 8);
|
unsigned int position = x + (y << 4) + (z << 8);
|
||||||
int content = readBlockContent(m_mapData.c_str(), m_contentWidth, position);
|
uint16_t content = readBlockContent(m_mapData.c_str(), m_contentWidth, position);
|
||||||
if (content == m_blockAirId || content == m_blockIgnoreId)
|
if (content == m_blockAirId || content == m_blockIgnoreId)
|
||||||
return "";
|
return empty;
|
||||||
NameMap::const_iterator it = m_nameMap.find(content);
|
NameMap::const_iterator it = m_nameMap.find(content);
|
||||||
if (it == m_nameMap.end()) {
|
if (it == m_nameMap.end()) {
|
||||||
std::cerr << "Skipping node with invalid ID." << std::endl;
|
std::cerr << "Skipping node with invalid ID." << std::endl;
|
||||||
return "";
|
return empty;
|
||||||
}
|
}
|
||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
// ARGB but with inverted alpha
|
// ARGB but with inverted alpha
|
||||||
|
|
||||||
static inline int color2int(Color c)
|
static inline int color2int(const Color &c)
|
||||||
{
|
{
|
||||||
u8 a = (255 - c.a) * gdAlphaMax / 255;
|
u8 a = (255 - c.a) * gdAlphaMax / 255;
|
||||||
return (a << 24) | (c.r << 16) | (c.g << 8) | c.b;
|
return (a << 24) | (c.r << 16) | (c.g << 8) | c.b;
|
||||||
@ -35,6 +35,7 @@ static inline Color int2color(int c)
|
|||||||
return c2;
|
return c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
static inline void check_bounds(int x, int y, int width, int height)
|
static inline void check_bounds(int x, int y, int width, int height)
|
||||||
{
|
{
|
||||||
if(x < 0 || x >= width) {
|
if(x < 0 || x >= width) {
|
||||||
@ -50,11 +51,13 @@ static inline void check_bounds(int x, int y, int width, int height)
|
|||||||
throw std::out_of_range(oss.str());
|
throw std::out_of_range(oss.str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
Image::Image(int width, int height) :
|
Image::Image(int width, int height) :
|
||||||
m_width(width), m_height(height), m_image(NULL)
|
m_width(width), m_height(height), m_image(NULL)
|
||||||
{
|
{
|
||||||
|
SIZECHECK(0, 0);
|
||||||
m_image = gdImageCreateTrueColor(m_width, m_height);
|
m_image = gdImageCreateTrueColor(m_width, m_height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,14 +1,6 @@
|
|||||||
/*
|
#include <cstring>
|
||||||
* =====================================================================
|
|
||||||
* Version: 1.0
|
|
||||||
* Created: 25.08.2012 10:55:27
|
|
||||||
* Author: Miroslav Bendík
|
|
||||||
* Company: LinuxOS.sk
|
|
||||||
* =====================================================================
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "PixelAttributes.h"
|
#include "PixelAttributes.h"
|
||||||
#include <cstring>
|
|
||||||
|
|
||||||
PixelAttributes::PixelAttributes():
|
PixelAttributes::PixelAttributes():
|
||||||
m_width(0)
|
m_width(0)
|
||||||
|
@ -9,11 +9,9 @@
|
|||||||
#include "PlayerAttributes.h"
|
#include "PlayerAttributes.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
PlayerAttributes::PlayerAttributes(const std::string &worldDir)
|
PlayerAttributes::PlayerAttributes(const std::string &worldDir)
|
||||||
{
|
{
|
||||||
std::ifstream ifs((worldDir + "world.mt").c_str());
|
std::ifstream ifs(worldDir + "world.mt");
|
||||||
if (!ifs.good())
|
if (!ifs.good())
|
||||||
throw std::runtime_error("Failed to read world.mt");
|
throw std::runtime_error("Failed to read world.mt");
|
||||||
std::string backend = read_setting_default("player_backend", ifs, "files");
|
std::string backend = read_setting_default("player_backend", ifs, "files");
|
||||||
@ -39,18 +37,18 @@ void PlayerAttributes::readFiles(const std::string &playersPath)
|
|||||||
if (ent->d_name[0] == '.')
|
if (ent->d_name[0] == '.')
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
string path = playersPath + PATH_SEPARATOR + ent->d_name;
|
std::string path = playersPath + PATH_SEPARATOR + ent->d_name;
|
||||||
ifstream in(path.c_str());
|
std::ifstream in(path);
|
||||||
if(!in.good())
|
if(!in.good())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
string name, position;
|
std::string name, position;
|
||||||
name = read_setting("name", in);
|
name = read_setting("name", in);
|
||||||
in.seekg(0);
|
in.seekg(0);
|
||||||
position = read_setting("position", in);
|
position = read_setting("position", in);
|
||||||
|
|
||||||
Player player;
|
Player player;
|
||||||
istringstream iss(position);
|
std::istringstream iss(position);
|
||||||
char tmp;
|
char tmp;
|
||||||
iss >> tmp; // '('
|
iss >> tmp; // '('
|
||||||
iss >> player.x;
|
iss >> player.x;
|
||||||
@ -121,13 +119,13 @@ void PlayerAttributes::readSqlite(const std::string &db_name)
|
|||||||
|
|
||||||
/**********/
|
/**********/
|
||||||
|
|
||||||
PlayerAttributes::Players::iterator PlayerAttributes::begin()
|
PlayerAttributes::Players::const_iterator PlayerAttributes::begin() const
|
||||||
{
|
{
|
||||||
return m_players.begin();
|
return m_players.cbegin();
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerAttributes::Players::iterator PlayerAttributes::end()
|
PlayerAttributes::Players::const_iterator PlayerAttributes::end() const
|
||||||
{
|
{
|
||||||
return m_players.end();
|
return m_players.cend();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
12
README.rst
12
README.rst
@ -4,6 +4,8 @@ Minetest Mapper C++
|
|||||||
.. image:: https://travis-ci.org/minetest/minetestmapper.svg?branch=master
|
.. image:: https://travis-ci.org/minetest/minetestmapper.svg?branch=master
|
||||||
:target: https://travis-ci.org/minetest/minetestmapper
|
:target: https://travis-ci.org/minetest/minetestmapper
|
||||||
|
|
||||||
|
Minetestmapper generates an overview image from a Minetest map.
|
||||||
|
|
||||||
A port of minetestmapper.py to C++ from https://github.com/minetest/minetest/tree/master/util.
|
A port of minetestmapper.py to C++ from https://github.com/minetest/minetest/tree/master/util.
|
||||||
This version is both faster and provides more features than the now deprecated Python script.
|
This version is both faster and provides more features than the now deprecated Python script.
|
||||||
|
|
||||||
@ -12,14 +14,14 @@ Requirements
|
|||||||
|
|
||||||
* libgd
|
* libgd
|
||||||
* sqlite3
|
* sqlite3
|
||||||
* LevelDB (optional, set ENABLE_LEVELDB=1 in CMake to enable)
|
* LevelDB (optional)
|
||||||
* hiredis library (optional, set ENABLE_REDIS=1 in CMake to enable)
|
* hiredis (optional)
|
||||||
* Postgres libraries (optional, set ENABLE_POSTGRES=1 in CMake to enable)
|
* Postgres libraries (optional)
|
||||||
|
|
||||||
e.g. on Debian:
|
e.g. on Debian:
|
||||||
^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
sudo apt-get install libgd-dev libsqlite3-dev libleveldb-dev libhiredis-dev libpq-dev
|
sudo apt install libgd-dev libsqlite3-dev libleveldb-dev libhiredis-dev libpq-dev
|
||||||
|
|
||||||
Windows
|
Windows
|
||||||
^^^^^^^
|
^^^^^^^
|
||||||
@ -37,7 +39,7 @@ Compilation
|
|||||||
::
|
::
|
||||||
|
|
||||||
cmake . -DENABLE_LEVELDB=1
|
cmake . -DENABLE_LEVELDB=1
|
||||||
make -j2
|
make -j4
|
||||||
|
|
||||||
Usage
|
Usage
|
||||||
-----
|
-----
|
||||||
|
@ -13,7 +13,9 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "PlayerAttributes.h"
|
#include "PlayerAttributes.h"
|
||||||
#include "BlockDecoder.h"
|
#include "BlockDecoder.h"
|
||||||
|
#include "Image.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
#include "db-sqlite3.h"
|
#include "db-sqlite3.h"
|
||||||
#if USE_POSTGRESQL
|
#if USE_POSTGRESQL
|
||||||
#include "db-postgresql.h"
|
#include "db-postgresql.h"
|
||||||
@ -25,8 +27,6 @@
|
|||||||
#include "db-redis.h"
|
#include "db-redis.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static inline T mymax(T a, T b)
|
static inline T mymax(T a, T b)
|
||||||
{
|
{
|
||||||
@ -56,6 +56,20 @@ static inline unsigned int colorSafeBounds (int channel)
|
|||||||
return mymin(mymax(channel, 0), 255);
|
return mymin(mymax(channel, 0), 255);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Color parseColor(const std::string &color)
|
||||||
|
{
|
||||||
|
if (color.length() != 7)
|
||||||
|
throw std::runtime_error("Color needs to be 7 characters long");
|
||||||
|
if (color[0] != '#')
|
||||||
|
throw std::runtime_error("Color needs to begin with #");
|
||||||
|
unsigned long col = strtoul(color.c_str() + 1, NULL, 16);
|
||||||
|
u8 b, g, r;
|
||||||
|
b = col & 0xff;
|
||||||
|
g = (col >> 8) & 0xff;
|
||||||
|
r = (col >> 16) & 0xff;
|
||||||
|
return Color(r, g, b);
|
||||||
|
}
|
||||||
|
|
||||||
static Color mixColors(Color a, Color b)
|
static Color mixColors(Color a, Color b)
|
||||||
{
|
{
|
||||||
Color result;
|
Color result;
|
||||||
@ -139,21 +153,6 @@ void TileGenerator::setScales(uint flags)
|
|||||||
m_scales = flags;
|
m_scales = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
Color TileGenerator::parseColor(const std::string &color)
|
|
||||||
{
|
|
||||||
Color parsed;
|
|
||||||
if (color.length() != 7)
|
|
||||||
throw std::runtime_error("Color needs to be 7 characters long");
|
|
||||||
if (color[0] != '#')
|
|
||||||
throw std::runtime_error("Color needs to begin with #");
|
|
||||||
unsigned long col = strtoul(color.c_str() + 1, NULL, 16);
|
|
||||||
parsed.b = col & 0xff;
|
|
||||||
parsed.g = (col >> 8) & 0xff;
|
|
||||||
parsed.r = (col >> 16) & 0xff;
|
|
||||||
parsed.a = 255;
|
|
||||||
return parsed;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TileGenerator::setDrawOrigin(bool drawOrigin)
|
void TileGenerator::setDrawOrigin(bool drawOrigin)
|
||||||
{
|
{
|
||||||
m_drawOrigin = drawOrigin;
|
m_drawOrigin = drawOrigin;
|
||||||
@ -214,16 +213,15 @@ void TileGenerator::setExhaustiveSearch(int mode)
|
|||||||
|
|
||||||
void TileGenerator::parseColorsFile(const std::string &fileName)
|
void TileGenerator::parseColorsFile(const std::string &fileName)
|
||||||
{
|
{
|
||||||
ifstream in;
|
std::ifstream in(fileName);
|
||||||
in.open(fileName.c_str(), ifstream::in);
|
if (!in.good())
|
||||||
if (!in.is_open())
|
|
||||||
throw std::runtime_error("Specified colors file could not be found");
|
throw std::runtime_error("Specified colors file could not be found");
|
||||||
parseColorsStream(in);
|
parseColorsStream(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TileGenerator::printGeometry(const std::string &input)
|
void TileGenerator::printGeometry(const std::string &input)
|
||||||
{
|
{
|
||||||
string input_path = input;
|
std::string input_path = input;
|
||||||
if (input_path[input.length() - 1] != PATH_SEPARATOR) {
|
if (input_path[input.length() - 1] != PATH_SEPARATOR) {
|
||||||
input_path += PATH_SEPARATOR;
|
input_path += PATH_SEPARATOR;
|
||||||
}
|
}
|
||||||
@ -249,7 +247,7 @@ void TileGenerator::setDontWriteEmpty(bool f)
|
|||||||
|
|
||||||
void TileGenerator::generate(const std::string &input, const std::string &output)
|
void TileGenerator::generate(const std::string &input, const std::string &output)
|
||||||
{
|
{
|
||||||
string input_path = input;
|
std::string input_path = input;
|
||||||
if (input_path[input.length() - 1] != PATH_SEPARATOR) {
|
if (input_path[input.length() - 1] != PATH_SEPARATOR) {
|
||||||
input_path += PATH_SEPARATOR;
|
input_path += PATH_SEPARATOR;
|
||||||
}
|
}
|
||||||
@ -306,8 +304,7 @@ void TileGenerator::parseColorsStream(std::istream &in)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ColorEntry color(r, g, b, a, t);
|
m_colorMap[name] = ColorEntry(r, g, b, a, t);
|
||||||
m_colorMap[name] = color;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -586,39 +583,43 @@ void TileGenerator::renderMapBlock(const BlockDecoder &blk, const BlockPos &pos)
|
|||||||
if (m_readPixels.get(x, z))
|
if (m_readPixels.get(x, z))
|
||||||
continue;
|
continue;
|
||||||
int imageX = xBegin + x;
|
int imageX = xBegin + x;
|
||||||
|
auto &attr = m_blockPixelAttributes.attribute(15 - z, xBegin + x);
|
||||||
|
|
||||||
for (int y = maxY; y >= minY; --y) {
|
for (int y = maxY; y >= minY; --y) {
|
||||||
string name = blk.getNode(x, y, z);
|
const std::string &name = blk.getNode(x, y, z);
|
||||||
if (name == "")
|
if (name.empty())
|
||||||
continue;
|
continue;
|
||||||
ColorMap::const_iterator it = m_colorMap.find(name);
|
ColorMap::const_iterator it = m_colorMap.find(name);
|
||||||
if (it == m_colorMap.end()) {
|
if (it == m_colorMap.end()) {
|
||||||
m_unknownNodes.insert(name);
|
m_unknownNodes.insert(name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const Color c = it->second.to_color();
|
|
||||||
|
Color c = it->second.toColor();
|
||||||
|
if (c.a == 0)
|
||||||
|
continue; // node is fully invisible
|
||||||
if (m_drawAlpha) {
|
if (m_drawAlpha) {
|
||||||
if (m_color[z][x].a == 0)
|
if (m_color[z][x].a != 0)
|
||||||
m_color[z][x] = c; // first visible time, no color mixing
|
c = mixColors(m_color[z][x], c);
|
||||||
else
|
if (c.a < 255) {
|
||||||
m_color[z][x] = mixColors(m_color[z][x], c);
|
// remember color and near thickness value
|
||||||
if(m_color[z][x].a < 0xff) {
|
m_color[z][x] = c;
|
||||||
// near thickness value to thickness of current node
|
m_thickness[z][x] = (m_thickness[z][x] + it->second.t) / 2;
|
||||||
m_thickness[z][x] = (m_thickness[z][x] + it->second.t) / 2.0;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// color became opaque, draw it
|
// color became opaque, draw it
|
||||||
setZoomed(imageX, imageY, m_color[z][x]);
|
setZoomed(imageX, imageY, c);
|
||||||
m_blockPixelAttributes.attribute(15 - z, xBegin + x).thickness = m_thickness[z][x];
|
attr.thickness = m_thickness[z][x];
|
||||||
} else {
|
} else {
|
||||||
setZoomed(imageX, imageY, c.noAlpha());
|
c.a = 255;
|
||||||
|
setZoomed(imageX, imageY, c);
|
||||||
}
|
}
|
||||||
m_readPixels.set(x, z);
|
m_readPixels.set(x, z);
|
||||||
|
|
||||||
// do this afterwards so we can record height values
|
// do this afterwards so we can record height values
|
||||||
// inside transparent nodes (water) too
|
// inside transparent nodes (water) too
|
||||||
if (!m_readInfo.get(x, z)) {
|
if (!m_readInfo.get(x, z)) {
|
||||||
m_blockPixelAttributes.attribute(15 - z, xBegin + x).height = pos.y * 16 + y;
|
attr.height = pos.y * 16 + y;
|
||||||
m_readInfo.set(x, z);
|
m_readInfo.set(x, z);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -640,17 +641,19 @@ void TileGenerator::renderMapBlockBottom(const BlockPos &pos)
|
|||||||
if (m_readPixels.get(x, z))
|
if (m_readPixels.get(x, z))
|
||||||
continue;
|
continue;
|
||||||
int imageX = xBegin + x;
|
int imageX = xBegin + x;
|
||||||
|
auto &attr = m_blockPixelAttributes.attribute(15 - z, xBegin + x);
|
||||||
|
|
||||||
// set color since it wasn't done in renderMapBlock()
|
// set color since it wasn't done in renderMapBlock()
|
||||||
setZoomed(imageX, imageY, m_color[z][x]);
|
setZoomed(imageX, imageY, m_color[z][x]);
|
||||||
m_readPixels.set(x, z);
|
m_readPixels.set(x, z);
|
||||||
m_blockPixelAttributes.attribute(15 - z, xBegin + x).thickness = m_thickness[z][x];
|
attr.thickness = m_thickness[z][x];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TileGenerator::renderShading(int zPos)
|
void TileGenerator::renderShading(int zPos)
|
||||||
{
|
{
|
||||||
|
auto &a = m_blockPixelAttributes;
|
||||||
int zBegin = (m_zMax - zPos) * 16;
|
int zBegin = (m_zMax - zPos) * 16;
|
||||||
for (int z = 0; z < 16; ++z) {
|
for (int z = 0; z < 16; ++z) {
|
||||||
int imageY = zBegin + z;
|
int imageY = zBegin + z;
|
||||||
@ -658,23 +661,27 @@ void TileGenerator::renderShading(int zPos)
|
|||||||
continue;
|
continue;
|
||||||
for (int x = 0; x < m_mapWidth; ++x) {
|
for (int x = 0; x < m_mapWidth; ++x) {
|
||||||
if(
|
if(
|
||||||
!m_blockPixelAttributes.attribute(z, x).valid_height() ||
|
!a.attribute(z, x).valid_height() ||
|
||||||
!m_blockPixelAttributes.attribute(z, x - 1).valid_height() ||
|
!a.attribute(z, x - 1).valid_height() ||
|
||||||
!m_blockPixelAttributes.attribute(z - 1, x).valid_height()
|
!a.attribute(z - 1, x).valid_height()
|
||||||
)
|
)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// calculate shadow to apply
|
// calculate shadow to apply
|
||||||
int y = m_blockPixelAttributes.attribute(z, x).height;
|
int y = a.attribute(z, x).height;
|
||||||
int y1 = m_blockPixelAttributes.attribute(z, x - 1).height;
|
int y1 = a.attribute(z, x - 1).height;
|
||||||
int y2 = m_blockPixelAttributes.attribute(z - 1, x).height;
|
int y2 = a.attribute(z - 1, x).height;
|
||||||
int d = ((y - y1) + (y - y2)) * 12;
|
int d = ((y - y1) + (y - y2)) * 12;
|
||||||
|
|
||||||
if (m_drawAlpha) { // less visible shadow with increasing "thickness"
|
if (m_drawAlpha) { // less visible shadow with increasing "thickness"
|
||||||
double t = m_blockPixelAttributes.attribute(z, x).thickness * 1.2;
|
float t = a.attribute(z, x).thickness * 1.2f;
|
||||||
d *= 1.0 - mymin(t, 255.0) / 255.0;
|
t = mymin(t, 255.0f);
|
||||||
|
d *= 1.0f - t / 255.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
d = mymin(d, 36);
|
d = mymin(d, 36);
|
||||||
|
|
||||||
|
// apply shadow/light by just adding to it pixel values
|
||||||
Color c = m_image->getPixel(getImageX(x), getImageY(imageY));
|
Color c = m_image->getPixel(getImageX(x), getImageY(imageY));
|
||||||
c.r = colorSafeBounds(c.r + d);
|
c.r = colorSafeBounds(c.r + d);
|
||||||
c.g = colorSafeBounds(c.g + d);
|
c.g = colorSafeBounds(c.g + d);
|
||||||
@ -682,7 +689,7 @@ void TileGenerator::renderShading(int zPos)
|
|||||||
setZoomed(x, imageY, c);
|
setZoomed(x, imageY, c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_blockPixelAttributes.scroll();
|
a.scroll();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TileGenerator::renderScale()
|
void TileGenerator::renderScale()
|
||||||
|
@ -1,12 +1,3 @@
|
|||||||
/*
|
|
||||||
* =====================================================================
|
|
||||||
* Version: 1.0
|
|
||||||
* Created: 18.09.2012 10:20:47
|
|
||||||
* Author: Miroslav Bendík
|
|
||||||
* Company: LinuxOS.sk
|
|
||||||
* =====================================================================
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "ZlibDecompressor.h"
|
#include "ZlibDecompressor.h"
|
||||||
@ -38,8 +29,8 @@ ustring ZlibDecompressor::decompress()
|
|||||||
const std::size_t size = m_size - m_seekPos;
|
const std::size_t size = m_size - m_seekPos;
|
||||||
|
|
||||||
ustring buffer;
|
ustring buffer;
|
||||||
const size_t BUFSIZE = 128 * 1024;
|
constexpr size_t BUFSIZE = 128 * 1024;
|
||||||
uint8_t temp_buffer[BUFSIZE];
|
unsigned char temp_buffer[BUFSIZE];
|
||||||
|
|
||||||
z_stream strm;
|
z_stream strm;
|
||||||
strm.zalloc = Z_NULL;
|
strm.zalloc = Z_NULL;
|
||||||
@ -48,9 +39,8 @@ ustring ZlibDecompressor::decompress()
|
|||||||
strm.next_in = Z_NULL;
|
strm.next_in = Z_NULL;
|
||||||
strm.avail_in = size;
|
strm.avail_in = size;
|
||||||
|
|
||||||
if (inflateInit(&strm) != Z_OK) {
|
if (inflateInit(&strm) != Z_OK)
|
||||||
throw DecompressError();
|
throw DecompressError();
|
||||||
}
|
|
||||||
|
|
||||||
strm.next_in = const_cast<unsigned char *>(data);
|
strm.next_in = const_cast<unsigned char *>(data);
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
@ -58,11 +48,11 @@ ustring ZlibDecompressor::decompress()
|
|||||||
strm.avail_out = BUFSIZE;
|
strm.avail_out = BUFSIZE;
|
||||||
strm.next_out = temp_buffer;
|
strm.next_out = temp_buffer;
|
||||||
ret = inflate(&strm, Z_NO_FLUSH);
|
ret = inflate(&strm, Z_NO_FLUSH);
|
||||||
buffer += ustring(reinterpret_cast<unsigned char *>(temp_buffer), BUFSIZE - strm.avail_out);
|
buffer.append(temp_buffer, BUFSIZE - strm.avail_out);
|
||||||
} while (ret == Z_OK);
|
} while (ret == Z_OK);
|
||||||
if (ret != Z_STREAM_END) {
|
if (ret != Z_STREAM_END)
|
||||||
throw DecompressError();
|
throw DecompressError();
|
||||||
}
|
|
||||||
m_seekPos += strm.next_in - data;
|
m_seekPos += strm.next_in - data;
|
||||||
(void)inflateEnd(&strm);
|
(void)inflateEnd(&strm);
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#ifndef BLOCKDECODER_H
|
#pragma once
|
||||||
#define BLOCKDECODER_H
|
|
||||||
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
@ -12,10 +11,11 @@ public:
|
|||||||
void reset();
|
void reset();
|
||||||
void decode(const ustring &data);
|
void decode(const ustring &data);
|
||||||
bool isEmpty() const;
|
bool isEmpty() const;
|
||||||
std::string getNode(u8 x, u8 y, u8 z) const; // returns "" for air, ignore and invalid nodes
|
// returns "" for air, ignore and invalid nodes
|
||||||
|
const std::string &getNode(u8 x, u8 y, u8 z) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::unordered_map<int, std::string> NameMap;
|
typedef std::unordered_map<uint16_t, std::string> NameMap;
|
||||||
NameMap m_nameMap;
|
NameMap m_nameMap;
|
||||||
int m_blockAirId;
|
int m_blockAirId;
|
||||||
int m_blockIgnoreId;
|
int m_blockIgnoreId;
|
||||||
@ -23,5 +23,3 @@ private:
|
|||||||
u8 m_version, m_contentWidth;
|
u8 m_version, m_contentWidth;
|
||||||
ustring m_mapData;
|
ustring m_mapData;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BLOCKDECODER_H
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#ifndef IMAGE_HEADER
|
#pragma once
|
||||||
#define IMAGE_HEADER
|
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -9,7 +8,6 @@ struct Color {
|
|||||||
Color() : r(0), g(0), b(0), a(0) {};
|
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) : 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) {};
|
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;
|
u8 r, g, b, a;
|
||||||
};
|
};
|
||||||
@ -19,6 +17,9 @@ public:
|
|||||||
Image(int width, int height);
|
Image(int width, int height);
|
||||||
~Image();
|
~Image();
|
||||||
|
|
||||||
|
Image(const Image&) = delete;
|
||||||
|
Image& operator=(const Image&) = delete;
|
||||||
|
|
||||||
void setPixel(int x, int y, const Color &c);
|
void setPixel(int x, int y, const Color &c);
|
||||||
Color getPixel(int x, int y);
|
Color getPixel(int x, int y);
|
||||||
void drawLine(int x1, int y1, int x2, int y2, const Color &c);
|
void drawLine(int x1, int y1, int x2, int y2, const Color &c);
|
||||||
@ -28,10 +29,6 @@ public:
|
|||||||
void save(const std::string &filename);
|
void save(const std::string &filename);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Image(const Image&);
|
|
||||||
|
|
||||||
int m_width, m_height;
|
int m_width, m_height;
|
||||||
gdImagePtr m_image;
|
gdImagePtr m_image;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // IMAGE_HEADER
|
|
||||||
|
@ -1,25 +1,15 @@
|
|||||||
/*
|
#pragma once
|
||||||
* =====================================================================
|
|
||||||
* Version: 1.0
|
|
||||||
* Created: 25.08.2012 10:55:29
|
|
||||||
* Author: Miroslav Bendík
|
|
||||||
* Company: LinuxOS.sk
|
|
||||||
* =====================================================================
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef PIXELATTRIBUTES_H_ADZ35GYF
|
#include <climits>
|
||||||
#define PIXELATTRIBUTES_H_ADZ35GYF
|
#include <cstdint>
|
||||||
|
|
||||||
#include <limits>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
struct PixelAttribute {
|
struct PixelAttribute {
|
||||||
PixelAttribute(): height(std::numeric_limits<int>::min()), thickness(0) {};
|
PixelAttribute(): height(INT16_MIN), thickness(0) {};
|
||||||
int height;
|
int16_t height;
|
||||||
uint8_t thickness;
|
uint8_t thickness;
|
||||||
inline bool valid_height() {
|
inline bool valid_height() {
|
||||||
return height != std::numeric_limits<int>::min();
|
return height != INT16_MIN;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -30,7 +20,9 @@ public:
|
|||||||
virtual ~PixelAttributes();
|
virtual ~PixelAttributes();
|
||||||
void setWidth(int width);
|
void setWidth(int width);
|
||||||
void scroll();
|
void scroll();
|
||||||
inline PixelAttribute &attribute(int z, int x) { return m_pixelAttributes[z + 1][x + 1]; };
|
inline PixelAttribute &attribute(int z, int x) {
|
||||||
|
return m_pixelAttributes[z + 1][x + 1];
|
||||||
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void freeAttributes();
|
void freeAttributes();
|
||||||
@ -45,6 +37,3 @@ private:
|
|||||||
PixelAttribute *m_pixelAttributes[BLOCK_SIZE + 2]; // 1px gradient + empty
|
PixelAttribute *m_pixelAttributes[BLOCK_SIZE + 2]; // 1px gradient + empty
|
||||||
int m_width;
|
int m_width;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* end of include guard: PIXELATTRIBUTES_H_ADZ35GYF */
|
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#ifndef PLAYERATTRIBUTES_H_D7THWFVV
|
#pragma once
|
||||||
#define PLAYERATTRIBUTES_H_D7THWFVV
|
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -16,8 +15,8 @@ public:
|
|||||||
typedef std::list<Player> Players;
|
typedef std::list<Player> Players;
|
||||||
|
|
||||||
PlayerAttributes(const std::string &worldDir);
|
PlayerAttributes(const std::string &worldDir);
|
||||||
Players::iterator begin();
|
Players::const_iterator begin() const;
|
||||||
Players::iterator end();
|
Players::const_iterator end() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void readFiles(const std::string &playersPath);
|
void readFiles(const std::string &playersPath);
|
||||||
@ -25,6 +24,3 @@ private:
|
|||||||
|
|
||||||
Players m_players;
|
Players m_players;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* end of include guard: PLAYERATTRIBUTES_H_D7THWFVV */
|
|
||||||
|
|
||||||
|
@ -1,21 +1,22 @@
|
|||||||
#ifndef TILEGENERATOR_HEADER
|
#ifndef TILEGENERATOR_HEADER
|
||||||
#define TILEGENERATOR_HEADER
|
#define TILEGENERATOR_HEADER
|
||||||
|
|
||||||
#include <iosfwd>
|
#include <iostream>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <config.h>
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include <stdint.h>
|
#include <cstdint>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "PixelAttributes.h"
|
#include "PixelAttributes.h"
|
||||||
#include "BlockDecoder.h"
|
|
||||||
#include "Image.h"
|
#include "Image.h"
|
||||||
#include "db.h"
|
#include "db.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
|
class BlockDecoder;
|
||||||
|
class Image;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
SCALE_TOP = (1 << 0),
|
SCALE_TOP = (1 << 0),
|
||||||
SCALE_BOTTOM = (1 << 1),
|
SCALE_BOTTOM = (1 << 1),
|
||||||
@ -31,10 +32,12 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct ColorEntry {
|
struct ColorEntry {
|
||||||
ColorEntry(): r(0), g(0), b(0), a(0), t(0) {};
|
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) {};
|
ColorEntry(uint8_t r, uint8_t g, uint8_t b, uint8_t a, uint8_t t) :
|
||||||
inline Color to_color() const { return Color(r, g, b, a); }
|
r(r), g(g), b(b), a(a), t(t) {};
|
||||||
uint8_t r, g, b, a, 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
|
||||||
};
|
};
|
||||||
|
|
||||||
struct BitmapThing { // 16x16 bitmap
|
struct BitmapThing { // 16x16 bitmap
|
||||||
@ -73,7 +76,6 @@ public:
|
|||||||
void setScaleColor(const std::string &scaleColor);
|
void setScaleColor(const std::string &scaleColor);
|
||||||
void setOriginColor(const std::string &originColor);
|
void setOriginColor(const std::string &originColor);
|
||||||
void setPlayerColor(const std::string &playerColor);
|
void setPlayerColor(const std::string &playerColor);
|
||||||
Color parseColor(const std::string &color);
|
|
||||||
void setDrawOrigin(bool drawOrigin);
|
void setDrawOrigin(bool drawOrigin);
|
||||||
void setDrawPlayers(bool drawPlayers);
|
void setDrawPlayers(bool drawPlayers);
|
||||||
void setDrawScale(bool drawScale);
|
void setDrawScale(bool drawScale);
|
||||||
|
@ -1,14 +1,4 @@
|
|||||||
/*
|
#pragma once
|
||||||
* =====================================================================
|
|
||||||
* 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 <cstdlib>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -31,7 +21,4 @@ private:
|
|||||||
const unsigned char *m_data;
|
const unsigned char *m_data;
|
||||||
std::size_t m_seekPos;
|
std::size_t m_seekPos;
|
||||||
std::size_t m_size;
|
std::size_t m_size;
|
||||||
}; /* ----- end of class ZlibDecompressor ----- */
|
};
|
||||||
|
|
||||||
#endif /* end of include guard: ZLIBDECOMPRESSOR_H_ZQL1PN8Q */
|
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#ifndef DB_LEVELDB_HEADER
|
#pragma once
|
||||||
#define DB_LEVELDB_HEADER
|
|
||||||
|
|
||||||
#include "db.h"
|
#include "db.h"
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
@ -27,5 +26,3 @@ private:
|
|||||||
std::unordered_map<int16_t, std::vector<pos2d>> posCache;
|
std::unordered_map<int16_t, std::vector<pos2d>> posCache;
|
||||||
leveldb::DB *db;
|
leveldb::DB *db;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DB_LEVELDB_HEADER
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#ifndef _DB_POSTGRESQL_H
|
#pragma once
|
||||||
#define _DB_POSTGRESQL_H
|
|
||||||
|
|
||||||
#include "db.h"
|
#include "db.h"
|
||||||
#include <libpq-fe.h>
|
#include <libpq-fe.h>
|
||||||
@ -31,5 +30,3 @@ protected:
|
|||||||
private:
|
private:
|
||||||
PGconn *db;
|
PGconn *db;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _DB_POSTGRESQL_H
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#ifndef DB_REDIS_HEADER
|
#pragma once
|
||||||
#define DB_REDIS_HEADER
|
|
||||||
|
|
||||||
#include "db.h"
|
#include "db.h"
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
@ -33,5 +32,3 @@ private:
|
|||||||
redisContext *ctx;
|
redisContext *ctx;
|
||||||
std::string hash;
|
std::string hash;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DB_REDIS_HEADER
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#ifndef _DB_SQLITE3_H
|
#pragma once
|
||||||
#define _DB_SQLITE3_H
|
|
||||||
|
|
||||||
#include "db.h"
|
#include "db.h"
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
@ -32,5 +31,3 @@ private:
|
|||||||
int16_t blockCachedZ = -10000;
|
int16_t blockCachedZ = -10000;
|
||||||
std::unordered_map<int16_t, BlockList> blockCache; // indexed by X
|
std::unordered_map<int16_t, BlockList> blockCache; // indexed by X
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _DB_SQLITE3_H
|
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
#ifndef DB_HEADER
|
#pragma once
|
||||||
#define DB_HEADER
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <cstdint>
|
||||||
#include <map>
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
@ -122,4 +120,3 @@ inline BlockPos DB::decodeBlockPos(int64_t hash) const
|
|||||||
* End black magic *
|
* End black magic *
|
||||||
*******************/
|
*******************/
|
||||||
|
|
||||||
#endif // DB_HEADER
|
|
||||||
|
@ -1,18 +1,9 @@
|
|||||||
#ifndef UTIL_H
|
#pragma once
|
||||||
#define UTIL_H
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
std::string read_setting(const std::string &name, std::istream &is);
|
std::string read_setting(const std::string &name, std::istream &is);
|
||||||
|
|
||||||
inline std::string read_setting_default(const std::string &name, std::istream &is, const std::string &def)
|
std::string read_setting_default(const std::string &name, std::istream &is,
|
||||||
{
|
const std::string &def);
|
||||||
try {
|
|
||||||
return read_setting(name, is);
|
|
||||||
} catch(const std::runtime_error &e) {
|
|
||||||
return def;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // UTIL_H
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include "cmake_config.h"
|
#include "config.h"
|
||||||
#include "TileGenerator.h"
|
#include "TileGenerator.h"
|
||||||
|
|
||||||
static void usage()
|
static void usage()
|
||||||
@ -58,7 +58,7 @@ static void usage()
|
|||||||
|
|
||||||
static bool file_exists(const std::string &path)
|
static bool file_exists(const std::string &path)
|
||||||
{
|
{
|
||||||
std::ifstream ifs(path.c_str());
|
std::ifstream ifs(path);
|
||||||
return ifs.is_open();
|
return ifs.is_open();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,7 +256,7 @@ int main(int argc, char *argv[])
|
|||||||
generator.parseColorsFile(colors);
|
generator.parseColorsFile(colors);
|
||||||
generator.generate(input, output);
|
generator.generate(input, output);
|
||||||
|
|
||||||
} catch(std::runtime_error &e) {
|
} catch (const std::runtime_error &e) {
|
||||||
std::cerr << "Exception: " << e.what() << std::endl;
|
std::cerr << "Exception: " << e.what() << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
10
util.cpp
10
util.cpp
@ -43,3 +43,13 @@ std::string read_setting(const std::string &name, std::istream &is)
|
|||||||
oss << "Setting '" << name << "' not found";
|
oss << "Setting '" << name << "' not found";
|
||||||
throw std::runtime_error(oss.str());
|
throw std::runtime_error(oss.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string read_setting_default(const std::string &name, std::istream &is,
|
||||||
|
const std::string &def)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return read_setting(name, is);
|
||||||
|
} catch(const std::runtime_error &e) {
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user