mirror of
https://github.com/minetest/minetestmapper.git
synced 2025-07-04 17:40:22 +02:00
Compare commits
51 Commits
20170606
...
night_rend
Author | SHA1 | Date | |
---|---|---|---|
55e407c130 | |||
2979dc5b6b | |||
92f6b051a5 | |||
2ae790c0b7 | |||
539bdbd30c | |||
48bf44c72d | |||
cb8341aeab | |||
7ff2288627 | |||
5b264fd443 | |||
ecc2b31f78 | |||
04b9dffb11 | |||
84c4fc40f8 | |||
a160dc051c | |||
9096f70188 | |||
1d678ffa82 | |||
2c16966d67 | |||
3e8720313b | |||
037193eec8 | |||
0fd3dc1e25 | |||
cd0d1ad2a6 | |||
f7b0d5c532 | |||
97c5dc0a83 | |||
ee5b8a9f86 | |||
ac15bacf36 | |||
b2406db169 | |||
657499e981 | |||
f909304e1e | |||
8e8cc3d1f2 | |||
48d9e0bb42 | |||
0a91fe6cbd | |||
42395587b9 | |||
d327a84841 | |||
0d9ed247f9 | |||
b6ad40feb9 | |||
1f471b369b | |||
2f78c39d9c | |||
2ebc3afc7c | |||
e543517eb8 | |||
405951f8f6 | |||
a8f7b47000 | |||
0f36b6e37a | |||
6af6be4632 | |||
7c71138fec | |||
c15adfd325 | |||
75599e8569 | |||
b16f93f183 | |||
976c690357 | |||
7288e60cd2 | |||
cca7072eab | |||
179651e83c | |||
6afe1b78c5 |
17
.travis.yml
17
.travis.yml
@ -2,23 +2,16 @@ language: cpp
|
||||
compiler:
|
||||
- gcc
|
||||
- clang
|
||||
sudo: false
|
||||
dist: bionic
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- llvm-toolchain-precise-3.8
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- cmake
|
||||
- libgd2-noxpm-dev
|
||||
- libgd-dev
|
||||
- libsqlite3-dev
|
||||
- p7zip
|
||||
- g++-6
|
||||
- clang-3.8
|
||||
before_install:
|
||||
- # Nothing ever works correctly with precise, use a custom libleveldb build
|
||||
- wget http://minetest.kitsunemimi.pw/libleveldb-1.18-ubuntu12.04.7z
|
||||
- 7zr x -olibleveldb libleveldb-1.18-ubuntu12.04.7z
|
||||
- libleveldb-dev
|
||||
- libpq-dev
|
||||
- postgresql-server-dev-all
|
||||
script: ./util/travis/script.sh
|
||||
notifications:
|
||||
email: false
|
||||
|
160
BlockDecoder.cpp
Normal file
160
BlockDecoder.cpp
Normal file
@ -0,0 +1,160 @@
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include "BlockDecoder.h"
|
||||
#include "ZlibDecompressor.h"
|
||||
|
||||
static inline uint16_t readU16(const unsigned char *data)
|
||||
{
|
||||
return data[0] << 8 | data[1];
|
||||
}
|
||||
|
||||
static int readBlockContent(const unsigned char *mapData, u8 contentWidth, unsigned int datapos)
|
||||
{
|
||||
if (contentWidth == 2) {
|
||||
size_t index = datapos << 1;
|
||||
return (mapData[index] << 8) | mapData[index + 1];
|
||||
} else {
|
||||
u8 param = mapData[datapos];
|
||||
if (param <= 0x7f)
|
||||
return param;
|
||||
else
|
||||
return (int(param) << 4) | (int(mapData[datapos + 0x2000]) >> 4);
|
||||
}
|
||||
}
|
||||
|
||||
BlockDecoder::BlockDecoder()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
void BlockDecoder::reset()
|
||||
{
|
||||
m_blockAirId = -1;
|
||||
m_blockIgnoreId = -1;
|
||||
m_nameMap.clear();
|
||||
|
||||
m_version = 0;
|
||||
m_contentWidth = 0;
|
||||
m_mapData = ustring();
|
||||
}
|
||||
|
||||
void BlockDecoder::decode(const ustring &datastr)
|
||||
{
|
||||
const unsigned char *data = datastr.c_str();
|
||||
size_t length = datastr.length();
|
||||
// TODO: bounds checks
|
||||
|
||||
uint8_t version = data[0];
|
||||
//uint8_t flags = data[1];
|
||||
if (version < 22) {
|
||||
std::ostringstream oss;
|
||||
oss << "Unsupported map version " << (int)version;
|
||||
throw std::runtime_error(oss.str());
|
||||
}
|
||||
m_version = version;
|
||||
|
||||
size_t dataOffset = 0;
|
||||
if (version >= 27)
|
||||
dataOffset = 4;
|
||||
else
|
||||
dataOffset = 2;
|
||||
|
||||
uint8_t contentWidth = data[dataOffset];
|
||||
dataOffset++;
|
||||
uint8_t paramsWidth = data[dataOffset];
|
||||
dataOffset++;
|
||||
if (contentWidth != 1 && contentWidth != 2)
|
||||
throw std::runtime_error("unsupported map version (contentWidth)");
|
||||
if (paramsWidth != 2)
|
||||
throw std::runtime_error("unsupported map version (paramsWidth)");
|
||||
m_contentWidth = contentWidth;
|
||||
|
||||
|
||||
ZlibDecompressor decompressor(data, length);
|
||||
decompressor.setSeekPos(dataOffset);
|
||||
m_mapData = decompressor.decompress();
|
||||
decompressor.decompress(); // unused metadata
|
||||
dataOffset = decompressor.seekPos();
|
||||
|
||||
// Skip unused data
|
||||
if (version == 23)
|
||||
dataOffset += 1;
|
||||
if (version == 24) {
|
||||
uint8_t ver = data[dataOffset++];
|
||||
if (ver == 1) {
|
||||
uint16_t num = readU16(data + dataOffset);
|
||||
dataOffset += 2;
|
||||
dataOffset += 10 * num;
|
||||
}
|
||||
}
|
||||
|
||||
// Skip unused static objects
|
||||
dataOffset++; // Skip static object version
|
||||
int staticObjectCount = readU16(data + dataOffset);
|
||||
dataOffset += 2;
|
||||
for (int i = 0; i < staticObjectCount; ++i) {
|
||||
dataOffset += 13;
|
||||
uint16_t dataSize = readU16(data + dataOffset);
|
||||
dataOffset += dataSize + 2;
|
||||
}
|
||||
dataOffset += 4; // Skip timestamp
|
||||
|
||||
// Read mapping
|
||||
{
|
||||
dataOffset++; // mapping version
|
||||
uint16_t numMappings = readU16(data + dataOffset);
|
||||
dataOffset += 2;
|
||||
for (int i = 0; i < numMappings; ++i) {
|
||||
uint16_t nodeId = readU16(data + dataOffset);
|
||||
dataOffset += 2;
|
||||
uint16_t nameLen = readU16(data + dataOffset);
|
||||
dataOffset += 2;
|
||||
std::string name(reinterpret_cast<const char *>(data) + dataOffset, nameLen);
|
||||
if (name == "air")
|
||||
m_blockAirId = nodeId;
|
||||
else if (name == "ignore")
|
||||
m_blockIgnoreId = nodeId;
|
||||
else
|
||||
m_nameMap[nodeId] = name;
|
||||
dataOffset += nameLen;
|
||||
}
|
||||
}
|
||||
|
||||
// Node timers
|
||||
if (version >= 25) {
|
||||
dataOffset++;
|
||||
uint16_t numTimers = readU16(data + dataOffset);
|
||||
dataOffset += 2;
|
||||
dataOffset += numTimers * 10;
|
||||
}
|
||||
}
|
||||
|
||||
bool BlockDecoder::isEmpty() const
|
||||
{
|
||||
// only contains ignore and air nodes?
|
||||
return m_nameMap.empty();
|
||||
}
|
||||
|
||||
std::string BlockDecoder::getNode(u8 x, u8 y, u8 z) const
|
||||
{
|
||||
unsigned int position = x + (y << 4) + (z << 8);
|
||||
int content = readBlockContent(m_mapData.c_str(), m_contentWidth, position);
|
||||
if (content == m_blockAirId || content == m_blockIgnoreId)
|
||||
return "";
|
||||
NameMap::const_iterator it = m_nameMap.find(content);
|
||||
if (it == m_nameMap.end()) {
|
||||
std::cerr << "Skipping node with invalid ID." << std::endl;
|
||||
return "";
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
u8 BlockDecoder::getParam1(u8 x, u8 y, u8 z) const
|
||||
{
|
||||
unsigned int position = x + (y << 4) + (z << 8);
|
||||
unsigned int offset = (m_contentWidth == 2) ? 0x2000 : 0x1000;
|
||||
return m_mapData.c_str()[offset + position];
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
project(minetestmapper CXX)
|
||||
cmake_minimum_required(VERSION 2.6)
|
||||
cmake_policy(SET CMP0003 NEW)
|
||||
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
|
||||
|
||||
set(VERSION_MAJOR 1)
|
||||
set(VERSION_MINOR 0)
|
||||
@ -13,7 +12,8 @@ if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE)
|
||||
endif()
|
||||
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Wall")
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Wall -DNDEBUG")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g2 -Wall")
|
||||
|
||||
if(WIN32)
|
||||
@ -45,6 +45,9 @@ if(NOT CUSTOM_DOCDIR STREQUAL "")
|
||||
message(STATUS "Using DOCDIR=${DOCDIR}")
|
||||
endif()
|
||||
|
||||
#set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
|
||||
find_package(PkgConfig)
|
||||
include(FindPackageHandleStandardArgs)
|
||||
|
||||
# Libraries: gd
|
||||
|
||||
@ -66,9 +69,6 @@ if(NOT ZLIB_LIBRARY OR NOT ZLIB_INCLUDE_DIR)
|
||||
message(FATAL_ERROR "zlib not found!")
|
||||
endif(NOT ZLIB_LIBRARY OR NOT ZLIB_INCLUDE_DIR)
|
||||
|
||||
find_package(PkgConfig)
|
||||
include(FindPackageHandleStandardArgs)
|
||||
|
||||
# Libraries: sqlite3
|
||||
|
||||
find_library(SQLITE3_LIBRARY sqlite3)
|
||||
@ -82,84 +82,68 @@ endif(NOT SQLITE3_LIBRARY OR NOT SQLITE3_INCLUDE_DIR)
|
||||
# Libraries: postgresql
|
||||
|
||||
option(ENABLE_POSTGRESQL "Enable PostgreSQL backend" TRUE)
|
||||
set(USE_POSTGRESQL 0)
|
||||
set(USE_POSTGRESQL FALSE)
|
||||
|
||||
if(ENABLE_POSTGRESQL)
|
||||
find_program(POSTGRESQL_CONFIG_EXECUTABLE pg_config DOC "pg_config")
|
||||
find_library(POSTGRESQL_LIBRARY pq)
|
||||
if(POSTGRESQL_CONFIG_EXECUTABLE)
|
||||
execute_process(COMMAND ${POSTGRESQL_CONFIG_EXECUTABLE} --includedir-server
|
||||
OUTPUT_VARIABLE POSTGRESQL_SERVER_INCLUDE_DIRS
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
execute_process(COMMAND ${POSTGRESQL_CONFIG_EXECUTABLE}
|
||||
OUTPUT_VARIABLE POSTGRESQL_CLIENT_INCLUDE_DIRS
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
# This variable is case sensitive for the cmake PostgreSQL module
|
||||
set(PostgreSQL_ADDITIONAL_SEARCH_PATHS ${POSTGRESQL_SERVER_INCLUDE_DIRS} ${POSTGRESQL_CLIENT_INCLUDE_DIRS})
|
||||
endif()
|
||||
|
||||
find_package("PostgreSQL")
|
||||
|
||||
if(POSTGRESQL_FOUND)
|
||||
set(USE_POSTGRESQL 1)
|
||||
if(PostgreSQL_FOUND)
|
||||
set(USE_POSTGRESQL TRUE)
|
||||
message(STATUS "PostgreSQL backend enabled")
|
||||
# This variable is case sensitive, don't try to change it to POSTGRESQL_INCLUDE_DIR
|
||||
message(STATUS "PostgreSQL includes: ${PostgreSQL_INCLUDE_DIR}")
|
||||
include_directories(${PostgreSQL_INCLUDE_DIR})
|
||||
set(POSTGRESQL_LIBRARY ${PostgreSQL_LIBRARIES})
|
||||
message(STATUS "PostgreSQL includes: ${PostgreSQL_INCLUDE_DIRS}")
|
||||
include_directories(${PostgreSQL_INCLUDE_DIRS})
|
||||
else()
|
||||
message(STATUS "PostgreSQL not found.")
|
||||
set(POSTGRESQL_LIBRARY "")
|
||||
message(STATUS "PostgreSQL not found!")
|
||||
set(PostgreSQL_LIBRARIES "")
|
||||
endif()
|
||||
endif(ENABLE_POSTGRESQL)
|
||||
|
||||
# Libraries: leveldb
|
||||
|
||||
set(USE_LEVELDB 0)
|
||||
|
||||
OPTION(ENABLE_LEVELDB "Enable LevelDB backend")
|
||||
OPTION(ENABLE_LEVELDB "Enable LevelDB backend" TRUE)
|
||||
set(USE_LEVELDB FALSE)
|
||||
|
||||
if(ENABLE_LEVELDB)
|
||||
find_library(LEVELDB_LIBRARY leveldb)
|
||||
find_path(LEVELDB_INCLUDE_DIR db.h PATH_SUFFIXES leveldb)
|
||||
find_path(LEVELDB_INCLUDE_DIR leveldb/db.h)
|
||||
message (STATUS "LevelDB library: ${LEVELDB_LIBRARY}")
|
||||
message (STATUS "LevelDB headers: ${LEVELDB_INCLUDE_DIR}")
|
||||
if(LEVELDB_LIBRARY AND LEVELDB_INCLUDE_DIR)
|
||||
set(USE_LEVELDB 1)
|
||||
set(USE_LEVELDB TRUE)
|
||||
message(STATUS "LevelDB backend enabled")
|
||||
include_directories(${LEVELDB_INCLUDE_DIR})
|
||||
else(LEVELDB_LIBRARY AND LEVELDB_INCLUDE_DIR)
|
||||
set(USE_LEVELDB 0)
|
||||
else()
|
||||
message(STATUS "LevelDB not found!")
|
||||
endif(LEVELDB_LIBRARY AND LEVELDB_INCLUDE_DIR)
|
||||
set(LEVELDB_LIBRARY "")
|
||||
endif()
|
||||
endif(ENABLE_LEVELDB)
|
||||
|
||||
# Libraries: redis
|
||||
|
||||
set(USE_REDIS 0)
|
||||
|
||||
OPTION(ENABLE_REDIS "Enable redis backend")
|
||||
OPTION(ENABLE_REDIS "Enable redis backend" TRUE)
|
||||
set(USE_REDIS FALSE)
|
||||
|
||||
if(ENABLE_REDIS)
|
||||
find_library(REDIS_LIBRARY hiredis)
|
||||
find_path(REDIS_INCLUDE_DIR hiredis.h PATH_SUFFIXES hiredis)
|
||||
find_path(REDIS_INCLUDE_DIR hiredis/hiredis.h)
|
||||
message (STATUS "redis library: ${REDIS_LIBRARY}")
|
||||
message (STATUS "redis headers: ${REDIS_INCLUDE_DIR}")
|
||||
if(REDIS_LIBRARY AND REDIS_INCLUDE_DIR)
|
||||
set(USE_REDIS 1)
|
||||
set(USE_REDIS TRUE)
|
||||
message(STATUS "redis backend enabled")
|
||||
include_directories(${REDIS_INCLUDE_DIR})
|
||||
else(REDIS_LIBRARY AND REDIS_INCLUDE_DIR)
|
||||
set(USE_REDIS 0)
|
||||
else()
|
||||
message(STATUS "redis not found!")
|
||||
endif(REDIS_LIBRARY AND REDIS_INCLUDE_DIR)
|
||||
set(REDIS_LIBRARY "")
|
||||
endif()
|
||||
endif(ENABLE_REDIS)
|
||||
|
||||
# Compiling & Linking
|
||||
|
||||
include_directories(
|
||||
"${PROJECT_BINARY_DIR}"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/include"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}"
|
||||
${SQLITE3_INCLUDE_DIR}
|
||||
${LIBGD_INCLUDE_DIR}
|
||||
@ -167,12 +151,13 @@ include_directories(
|
||||
)
|
||||
|
||||
configure_file(
|
||||
"${PROJECT_SOURCE_DIR}/cmake_config.h.in"
|
||||
"${PROJECT_SOURCE_DIR}/include/cmake_config.h.in"
|
||||
"${PROJECT_BINARY_DIR}/cmake_config.h"
|
||||
)
|
||||
add_definitions ( -DUSE_CMAKE_CONFIG_H )
|
||||
|
||||
set(mapper_SRCS
|
||||
BlockDecoder.cpp
|
||||
PixelAttributes.cpp
|
||||
PlayerAttributes.cpp
|
||||
TileGenerator.cpp
|
||||
@ -202,7 +187,7 @@ add_executable(minetestmapper
|
||||
target_link_libraries(
|
||||
minetestmapper
|
||||
${SQLITE3_LIBRARY}
|
||||
${POSTGRESQL_LIBRARY}
|
||||
${PostgreSQL_LIBRARIES}
|
||||
${LEVELDB_LIBRARY}
|
||||
${REDIS_LIBRARY}
|
||||
${LIBGD_LIBRARY}
|
||||
|
48
Image.cpp
48
Image.cpp
@ -10,12 +10,7 @@
|
||||
#include "Image.h"
|
||||
|
||||
#ifndef NDEBUG
|
||||
#define SIZECHECK(x, y) do { \
|
||||
if((x) < 0 || (x) >= m_width) \
|
||||
throw std::out_of_range("sizecheck x"); \
|
||||
if((y) < 0 || (y) >= m_height) \
|
||||
throw std::out_of_range("sizecheck y"); \
|
||||
} while(0)
|
||||
#define SIZECHECK(x, y) check_bounds((x), (y), m_width, m_height)
|
||||
#else
|
||||
#define SIZECHECK(x, y) do {} while(0)
|
||||
#endif
|
||||
@ -24,7 +19,7 @@
|
||||
|
||||
static inline int color2int(Color c)
|
||||
{
|
||||
u8 a = 255 - c.a;
|
||||
u8 a = (255 - c.a) * gdAlphaMax / 255;
|
||||
return (a << 24) | (c.r << 16) | (c.g << 8) | c.b;
|
||||
}
|
||||
|
||||
@ -36,10 +31,26 @@ static inline Color int2color(int c)
|
||||
c2.g = (c >> 8) & 0xff;
|
||||
c2.r = (c >> 16) & 0xff;
|
||||
a = (c >> 24) & 0xff;
|
||||
c2.a = 255 - a;
|
||||
c2.a = 255 - (a*255 / gdAlphaMax);
|
||||
return c2;
|
||||
}
|
||||
|
||||
static inline void check_bounds(int x, int y, int width, int height)
|
||||
{
|
||||
if(x < 0 || x >= width) {
|
||||
std::ostringstream oss;
|
||||
oss << "Access outside image bounds (x), 0 < "
|
||||
<< x << " < " << width << " is false.";
|
||||
throw std::out_of_range(oss.str());
|
||||
}
|
||||
if(y < 0 || y >= height) {
|
||||
std::ostringstream oss;
|
||||
oss << "Access outside image bounds (y), 0 < "
|
||||
<< y << " < " << height << " is false.";
|
||||
throw std::out_of_range(oss.str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Image::Image(int width, int height) :
|
||||
m_width(width), m_height(height), m_image(NULL)
|
||||
@ -60,10 +71,7 @@ void Image::setPixel(int x, int y, const Color &c)
|
||||
|
||||
Color Image::getPixel(int x, int y)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
if(x < 0 || x > m_width || y < 0 || y > m_height)
|
||||
throw std::out_of_range("sizecheck");
|
||||
#endif
|
||||
SIZECHECK(x, y);
|
||||
return int2color(m_image->tpixels[y][x]);
|
||||
}
|
||||
|
||||
@ -95,12 +103,22 @@ void Image::drawCircle(int x, int y, int diameter, const Color &c)
|
||||
|
||||
void Image::save(const std::string &filename)
|
||||
{
|
||||
#if (GD_MAJOR_VERSION == 2 && GD_MINOR_VERSION == 1 && GD_RELEASE_VERSION >= 1) || (GD_MAJOR_VERSION == 2 && GD_MINOR_VERSION > 1) || GD_MAJOR_VERSION > 2
|
||||
const char *f = filename.c_str();
|
||||
if (gdSupportsFileType(f, 1) == GD_FALSE)
|
||||
throw std::runtime_error("Image format not supported by gd");
|
||||
if (gdImageFile(m_image, f) == GD_FALSE)
|
||||
throw std::runtime_error("Error saving image");
|
||||
#else
|
||||
if (filename.compare(filename.length() - 4, 4, ".png") != 0)
|
||||
throw std::runtime_error("Only PNG is supported");
|
||||
FILE *f = fopen(filename.c_str(), "wb");
|
||||
if(!f) {
|
||||
if (!f) {
|
||||
std::ostringstream oss;
|
||||
oss << "Error writing image file: " << std::strerror(errno);
|
||||
oss << "Error opening image file: " << std::strerror(errno);
|
||||
throw std::runtime_error(oss.str());
|
||||
}
|
||||
gdImagePng(m_image, f); // other formats?
|
||||
gdImagePng(m_image, f);
|
||||
fclose(f);
|
||||
#endif
|
||||
}
|
||||
|
@ -7,17 +7,14 @@
|
||||
* =====================================================================
|
||||
*/
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include "PixelAttributes.h"
|
||||
|
||||
using namespace std;
|
||||
#include <cstring>
|
||||
|
||||
PixelAttributes::PixelAttributes():
|
||||
m_width(0)
|
||||
{
|
||||
for (size_t i = 0; i < LineCount; ++i) {
|
||||
m_pixelAttributes[i] = 0;
|
||||
m_pixelAttributes[i] = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,9 +44,9 @@ void PixelAttributes::scroll()
|
||||
void PixelAttributes::freeAttributes()
|
||||
{
|
||||
for (size_t i = 0; i < LineCount; ++i) {
|
||||
if (m_pixelAttributes[i] != 0) {
|
||||
if (m_pixelAttributes[i] != nullptr) {
|
||||
delete[] m_pixelAttributes[i];
|
||||
m_pixelAttributes[i] = 0;
|
||||
m_pixelAttributes[i] = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,66 +1,126 @@
|
||||
/*
|
||||
* =====================================================================
|
||||
* Version: 1.0
|
||||
* Created: 01.09.2012 14:38:05
|
||||
* Author: Miroslav Bendík
|
||||
* Company: LinuxOS.sk
|
||||
* =====================================================================
|
||||
*/
|
||||
|
||||
#include <dirent.h>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h> // for usleep
|
||||
#include <sqlite3.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "PlayerAttributes.h"
|
||||
#include "util.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
PlayerAttributes::PlayerAttributes(const std::string &sourceDirectory)
|
||||
PlayerAttributes::PlayerAttributes(const std::string &worldDir)
|
||||
{
|
||||
std::ifstream ifs((worldDir + "world.mt").c_str());
|
||||
if (!ifs.good())
|
||||
throw std::runtime_error("Failed to read world.mt");
|
||||
std::string backend = read_setting_default("player_backend", ifs, "files");
|
||||
ifs.close();
|
||||
|
||||
string playersPath = sourceDirectory + "players";
|
||||
if (backend == "files")
|
||||
readFiles(worldDir + "players");
|
||||
else if (backend == "sqlite3")
|
||||
readSqlite(worldDir + "players.sqlite");
|
||||
else
|
||||
throw std::runtime_error(((std::string) "Unknown player backend: ") + backend);
|
||||
}
|
||||
|
||||
void PlayerAttributes::readFiles(const std::string &playersPath)
|
||||
{
|
||||
DIR *dir;
|
||||
dir = opendir (playersPath.c_str());
|
||||
if (dir == NULL) {
|
||||
if (dir == NULL)
|
||||
return;
|
||||
}
|
||||
|
||||
struct dirent *ent;
|
||||
while ((ent = readdir (dir)) != NULL) {
|
||||
if (ent->d_name[0] == '.') {
|
||||
if (ent->d_name[0] == '.')
|
||||
continue;
|
||||
}
|
||||
|
||||
string path = playersPath + PATH_SEPARATOR + ent->d_name;
|
||||
ifstream in(path.c_str());
|
||||
if(!in.good())
|
||||
continue;
|
||||
|
||||
string name, position;
|
||||
name = read_setting("name", in);
|
||||
in.seekg(0);
|
||||
position = read_setting("position", in);
|
||||
|
||||
ifstream in;
|
||||
in.open(path.c_str(), ifstream::in);
|
||||
string buffer;
|
||||
string name;
|
||||
string position;
|
||||
while (getline(in, buffer)) {
|
||||
if (buffer.find("name = ") == 0) {
|
||||
name = buffer.substr(7);
|
||||
}
|
||||
else if (buffer.find("position = ") == 0) {
|
||||
position = buffer.substr(12, buffer.length() - 13);
|
||||
}
|
||||
}
|
||||
char comma;
|
||||
Player player;
|
||||
istringstream positionStream(position, istringstream::in);
|
||||
positionStream >> player.x;
|
||||
positionStream >> comma;
|
||||
positionStream >> player.y;
|
||||
positionStream >> comma;
|
||||
positionStream >> player.z;
|
||||
istringstream iss(position);
|
||||
char tmp;
|
||||
iss >> tmp; // '('
|
||||
iss >> player.x;
|
||||
iss >> tmp; // ','
|
||||
iss >> player.y;
|
||||
iss >> tmp; // ','
|
||||
iss >> player.z;
|
||||
iss >> tmp; // ')'
|
||||
if(tmp != ')')
|
||||
continue;
|
||||
player.name = name;
|
||||
|
||||
player.x /= 10.0;
|
||||
player.y /= 10.0;
|
||||
player.z /= 10.0;
|
||||
|
||||
m_players.push_back(player);
|
||||
}
|
||||
closedir(dir);
|
||||
}
|
||||
|
||||
/**********/
|
||||
|
||||
#define SQLRES(f, good) \
|
||||
result = (sqlite3_##f); \
|
||||
if (result != good) { \
|
||||
throw std::runtime_error(sqlite3_errmsg(db));\
|
||||
}
|
||||
#define SQLOK(f) SQLRES(f, SQLITE_OK)
|
||||
|
||||
void PlayerAttributes::readSqlite(const std::string &db_name)
|
||||
{
|
||||
int result;
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *stmt_get_player_pos;
|
||||
|
||||
SQLOK(open_v2(db_name.c_str(), &db, SQLITE_OPEN_READONLY |
|
||||
SQLITE_OPEN_PRIVATECACHE, 0))
|
||||
|
||||
SQLOK(prepare_v2(db,
|
||||
"SELECT name, posX, posY, posZ FROM player",
|
||||
-1, &stmt_get_player_pos, NULL))
|
||||
|
||||
while ((result = sqlite3_step(stmt_get_player_pos)) != SQLITE_DONE) {
|
||||
if (result == SQLITE_BUSY) { // Wait some time and try again
|
||||
usleep(10000);
|
||||
} else if (result != SQLITE_ROW) {
|
||||
throw std::runtime_error(sqlite3_errmsg(db));
|
||||
}
|
||||
|
||||
Player player;
|
||||
const unsigned char *name_ = sqlite3_column_text(stmt_get_player_pos, 0);
|
||||
player.name = std::string(reinterpret_cast<const char*>(name_));
|
||||
player.x = sqlite3_column_double(stmt_get_player_pos, 1);
|
||||
player.y = sqlite3_column_double(stmt_get_player_pos, 2);
|
||||
player.z = sqlite3_column_double(stmt_get_player_pos, 3);
|
||||
|
||||
player.x /= 10.0;
|
||||
player.y /= 10.0;
|
||||
player.z /= 10.0;
|
||||
|
||||
m_players.push_back(player);
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt_get_player_pos);
|
||||
sqlite3_close(db);
|
||||
}
|
||||
|
||||
/**********/
|
||||
|
||||
PlayerAttributes::Players::iterator PlayerAttributes::begin()
|
||||
{
|
||||
return m_players.begin();
|
||||
|
@ -1,38 +0,0 @@
|
||||
/*
|
||||
* =====================================================================
|
||||
* 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 */
|
||||
|
39
README.rst
39
README.rst
@ -12,8 +12,8 @@ Requirements
|
||||
|
||||
* libgd
|
||||
* sqlite3
|
||||
* leveldb (optional, set ENABLE_LEVELDB=1 in CMake to enable)
|
||||
* hiredis (optional, set ENABLE_REDIS=1 in CMake to enable)
|
||||
* LevelDB (optional, set ENABLE_LEVELDB=1 in CMake to enable)
|
||||
* hiredis library (optional, set ENABLE_REDIS=1 in CMake to enable)
|
||||
* Postgres libraries (optional, set ENABLE_POSTGRES=1 in CMake to enable)
|
||||
|
||||
e.g. on Debian:
|
||||
@ -25,7 +25,7 @@ Windows
|
||||
^^^^^^^
|
||||
Minetestmapper for Windows can be downloaded here: https://github.com/minetest/minetestmapper/releases
|
||||
|
||||
After extracting the archive somewhere minetestmapper will be available from cmd.exe:
|
||||
After extracting the archive, minetestmapper can be invoked from cmd.exe:
|
||||
::
|
||||
|
||||
cd C:\Users\yourname\Desktop\example\path
|
||||
@ -54,32 +54,38 @@ Parameters
|
||||
^^^^^^^^^^
|
||||
|
||||
bgcolor:
|
||||
Background color of image, e.g. ``--bgcolor #ffffff``
|
||||
Background color of image, e.g. ``--bgcolor '#ffffff'``
|
||||
|
||||
scalecolor:
|
||||
Color of scale, e.g. ``--scalecolor #000000``
|
||||
Color of scale marks and text, e.g. ``--scalecolor '#000000'``
|
||||
|
||||
playercolor:
|
||||
Color of player indicators, e.g. ``--playercolor #ff0000``
|
||||
Color of player indicators, e.g. ``--playercolor '#ff0000'``
|
||||
|
||||
origincolor:
|
||||
Color of origin indicator, e.g. ``--origincolor #ff0000``
|
||||
Color of origin indicator, e.g. ``--origincolor '#ff0000'``
|
||||
|
||||
drawscale:
|
||||
Draw tick marks, ``--drawscale``
|
||||
Draw scale(s) with tick marks and numbers, ``--drawscale``
|
||||
|
||||
drawplayers:
|
||||
Draw player indicators, ``--drawplayers``
|
||||
Draw player indicators with name, ``--drawplayers``
|
||||
|
||||
draworigin:
|
||||
Draw origin indicator, ``--draworigin``
|
||||
|
||||
drawalpha:
|
||||
Allow nodes to be drawn with transparency, ``--drawalpha``
|
||||
Allow nodes to be drawn with transparency (e.g. water), ``--drawalpha``
|
||||
|
||||
extent:
|
||||
Don't output any imagery, just print the extent of the full map, ``--extent``
|
||||
|
||||
noshading:
|
||||
Don't draw shading on nodes, ``--noshading``
|
||||
|
||||
noemptyimage:
|
||||
Don't output anything when the image would be empty, ``--noemptyimage``
|
||||
|
||||
min-y:
|
||||
Don't draw nodes below this y value, e.g. ``--min-y -25``
|
||||
|
||||
@ -87,16 +93,21 @@ max-y:
|
||||
Don't draw nodes above this y value, e.g. ``--max-y 75``
|
||||
|
||||
backend:
|
||||
Use specific map backend; supported: *sqlite3*, *leveldb*, *redis*, *postgresql*, e.g. ``--backend leveldb``
|
||||
Override auto-detected map backend; supported: *sqlite3*, *leveldb*, *redis*, *postgresql*, e.g. ``--backend leveldb``
|
||||
|
||||
geometry:
|
||||
Limit area to specific geometry (*x:y+w+h* where x and y specify the lower left corner), e.g. ``--geometry -800:-800+1600+1600``
|
||||
Limit area to specific geometry (*x:z+w+h* where x and z specify the lower left corner), e.g. ``--geometry -800:-800+1600+1600``
|
||||
|
||||
zoom:
|
||||
"Zoom" the image by using more than one pixel per node, e.g. ``--zoom 4``
|
||||
Apply zoom to drawn nodes by enlarging them to n*n squares, e.g. ``--zoom 4``
|
||||
|
||||
colors:
|
||||
Forcefully set path to colors.txt file (it's autodetected otherwise), e.g. ``--colors ../minetest/mycolors.txt``
|
||||
Override auto-detected path to colors.txt, e.g. ``--colors ../minetest/mycolors.txt``
|
||||
|
||||
scales:
|
||||
Draw scales on specified image edges (letters *t b l r* meaning top, bottom, left and right), e.g. ``--scales tbr``
|
||||
|
||||
exhaustive:
|
||||
| Select if database should be traversed exhaustively or using range queries, available: *never*, *y*, *full*, *auto*
|
||||
| Defaults to *auto*. You shouldn't need to change this, but doing so can improve rendering times on large maps.
|
||||
| For these optimizations to work it is important that you set ``min-y`` and ``max-y`` when you don't care about the world below e.g. -60 and above 1000 nodes.
|
||||
|
@ -1,16 +1,19 @@
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <climits>
|
||||
#include <cassert>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
|
||||
#include "TileGenerator.h"
|
||||
#include "config.h"
|
||||
#include "PlayerAttributes.h"
|
||||
#include "TileGenerator.h"
|
||||
#include "ZlibDecompressor.h"
|
||||
#include "BlockDecoder.h"
|
||||
#include "util.h"
|
||||
#include "db-sqlite3.h"
|
||||
#if USE_POSTGRESQL
|
||||
@ -25,9 +28,16 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
static inline uint16_t readU16(const unsigned char *data)
|
||||
template<typename T>
|
||||
static inline T mymax(T a, T b)
|
||||
{
|
||||
return data[0] << 8 | data[1];
|
||||
return (a > b) ? a : b;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static inline T mymin(T a, T b)
|
||||
{
|
||||
return (a > b) ? b : a;
|
||||
}
|
||||
|
||||
// rounds n (away from 0) to a multiple of f while preserving the sign of n
|
||||
@ -42,27 +52,9 @@ static int round_multiple_nosign(int n, int f)
|
||||
return sign * (abs_n + f - (abs_n % f));
|
||||
}
|
||||
|
||||
static int readBlockContent(const unsigned char *mapData, int version, int datapos)
|
||||
static inline unsigned int colorSafeBounds (int channel)
|
||||
{
|
||||
if (version >= 24) {
|
||||
size_t index = datapos << 1;
|
||||
return (mapData[index] << 8) | mapData[index + 1];
|
||||
} else if (version >= 20) {
|
||||
if (mapData[datapos] <= 0x80)
|
||||
return mapData[datapos];
|
||||
else
|
||||
return (int(mapData[datapos]) << 4) | (int(mapData[datapos + 0x2000]) >> 4);
|
||||
}
|
||||
std::ostringstream oss;
|
||||
oss << "Unsupported map version " << version;
|
||||
throw std::runtime_error(oss.str());
|
||||
}
|
||||
|
||||
static inline int colorSafeBounds(int color)
|
||||
{
|
||||
color = (color > 255) ? 255 : color;
|
||||
color = (color < 0) ? 0 : color;
|
||||
return color;
|
||||
return mymin(mymax(channel, 0), 255);
|
||||
}
|
||||
|
||||
static Color mixColors(Color a, Color b)
|
||||
@ -89,6 +81,7 @@ TileGenerator::TileGenerator():
|
||||
m_drawScale(false),
|
||||
m_drawAlpha(false),
|
||||
m_shading(true),
|
||||
m_dontWriteEmpty(false),
|
||||
m_backend(""),
|
||||
m_xBorder(0),
|
||||
m_yBorder(0),
|
||||
@ -98,12 +91,13 @@ TileGenerator::TileGenerator():
|
||||
m_xMax(INT_MIN),
|
||||
m_zMin(INT_MAX),
|
||||
m_zMax(INT_MIN),
|
||||
m_yMin(-30000),
|
||||
m_yMax(30000),
|
||||
m_yMin(INT16_MIN),
|
||||
m_yMax(INT16_MAX),
|
||||
m_geomX(-2048),
|
||||
m_geomY(-2048),
|
||||
m_geomX2(2048),
|
||||
m_geomY2(2048),
|
||||
m_exhaustiveSearch(EXH_AUTO),
|
||||
m_zoom(1),
|
||||
m_scales(SCALE_LEFT | SCALE_TOP)
|
||||
{
|
||||
@ -193,6 +187,7 @@ void TileGenerator::setBackend(std::string backend)
|
||||
|
||||
void TileGenerator::setGeometry(int x, int y, int w, int h)
|
||||
{
|
||||
assert(w > 0 && h > 0);
|
||||
m_geomX = round_multiple_nosign(x, 16) / 16;
|
||||
m_geomY = round_multiple_nosign(y, 16) / 16;
|
||||
m_geomX2 = round_multiple_nosign(x + w, 16) / 16;
|
||||
@ -202,11 +197,20 @@ void TileGenerator::setGeometry(int x, int y, int w, int h)
|
||||
void TileGenerator::setMinY(int y)
|
||||
{
|
||||
m_yMin = y;
|
||||
if (m_yMin > m_yMax)
|
||||
std::swap(m_yMin, m_yMax);
|
||||
}
|
||||
|
||||
void TileGenerator::setMaxY(int y)
|
||||
{
|
||||
m_yMax = y;
|
||||
if (m_yMin > m_yMax)
|
||||
std::swap(m_yMin, m_yMax);
|
||||
}
|
||||
|
||||
void TileGenerator::setExhaustiveSearch(int mode)
|
||||
{
|
||||
m_exhaustiveSearch = mode;
|
||||
}
|
||||
|
||||
void TileGenerator::parseColorsFile(const std::string &fileName)
|
||||
@ -218,6 +222,32 @@ void TileGenerator::parseColorsFile(const std::string &fileName)
|
||||
parseColorsStream(in);
|
||||
}
|
||||
|
||||
void TileGenerator::printGeometry(const std::string &input)
|
||||
{
|
||||
string input_path = input;
|
||||
if (input_path[input.length() - 1] != PATH_SEPARATOR) {
|
||||
input_path += PATH_SEPARATOR;
|
||||
}
|
||||
|
||||
setExhaustiveSearch(EXH_NEVER);
|
||||
openDb(input_path);
|
||||
loadBlocks();
|
||||
|
||||
std::cout << "Map extent: "
|
||||
<< m_xMin*16 << ":" << m_zMin*16
|
||||
<< "+" << (m_xMax - m_xMin+1)*16
|
||||
<< "+" << (m_zMax - m_zMin+1)*16
|
||||
<< std::endl;
|
||||
|
||||
closeDatabase();
|
||||
|
||||
}
|
||||
|
||||
void TileGenerator::setDontWriteEmpty(bool f)
|
||||
{
|
||||
m_dontWriteEmpty = f;
|
||||
}
|
||||
|
||||
void TileGenerator::generate(const std::string &input, const std::string &output)
|
||||
{
|
||||
string input_path = input;
|
||||
@ -225,8 +255,17 @@ void TileGenerator::generate(const std::string &input, const std::string &output
|
||||
input_path += PATH_SEPARATOR;
|
||||
}
|
||||
|
||||
if (m_dontWriteEmpty) // FIXME: possible too, just needs to be done differently
|
||||
setExhaustiveSearch(EXH_NEVER);
|
||||
openDb(input_path);
|
||||
loadBlocks();
|
||||
|
||||
if (m_dontWriteEmpty && m_positions.empty())
|
||||
{
|
||||
closeDatabase();
|
||||
return;
|
||||
}
|
||||
|
||||
createImage();
|
||||
renderMap();
|
||||
closeDatabase();
|
||||
@ -245,9 +284,9 @@ void TileGenerator::generate(const std::string &input, const std::string &output
|
||||
|
||||
void TileGenerator::parseColorsStream(std::istream &in)
|
||||
{
|
||||
char line[128];
|
||||
char line[512];
|
||||
while (in.good()) {
|
||||
in.getline(line, 128);
|
||||
in.getline(line, sizeof(line));
|
||||
|
||||
for(char *p = line; *p; p++) {
|
||||
if(*p != '#')
|
||||
@ -258,29 +297,45 @@ void TileGenerator::parseColorsStream(std::istream &in)
|
||||
if(strlen(line) == 0)
|
||||
continue;
|
||||
|
||||
char name[64];
|
||||
char name[128 + 1] = {0};
|
||||
unsigned int r, g, b, a, t;
|
||||
a = 255;
|
||||
t = 0;
|
||||
int items = sscanf(line, "%64s %u %u %u %u %u", name, &r, &g, &b, &a, &t);
|
||||
int items = sscanf(line, "%128s %u %u %u %u %u", name, &r, &g, &b, &a, &t);
|
||||
if(items < 4) {
|
||||
std::cerr << "Failed to parse color entry '" << line << "'" << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
ColorEntry color = ColorEntry(r, g, b, a, t);
|
||||
ColorEntry color(r, g, b, a, t);
|
||||
m_colorMap[name] = color;
|
||||
}
|
||||
}
|
||||
|
||||
std::set<std::string> TileGenerator::getSupportedBackends()
|
||||
{
|
||||
std::set<std::string> r;
|
||||
r.insert("sqlite3");
|
||||
#if USE_POSTGRESQL
|
||||
r.insert("postgresql");
|
||||
#endif
|
||||
#if USE_LEVELDB
|
||||
r.insert("leveldb");
|
||||
#endif
|
||||
#if USE_REDIS
|
||||
r.insert("redis");
|
||||
#endif
|
||||
return r;
|
||||
}
|
||||
|
||||
void TileGenerator::openDb(const std::string &input)
|
||||
{
|
||||
std::string backend = m_backend;
|
||||
if(backend == "") {
|
||||
std::ifstream ifs((input + "/world.mt").c_str());
|
||||
if (backend == "") {
|
||||
std::ifstream ifs(input + "/world.mt");
|
||||
if(!ifs.good())
|
||||
throw std::runtime_error("Failed to read world.mt");
|
||||
backend = get_setting("backend", ifs);
|
||||
throw std::runtime_error("Failed to open world.mt");
|
||||
backend = read_setting_default("backend", ifs, "sqlite3");
|
||||
ifs.close();
|
||||
}
|
||||
|
||||
@ -300,6 +355,33 @@ void TileGenerator::openDb(const std::string &input)
|
||||
#endif
|
||||
else
|
||||
throw std::runtime_error(((std::string) "Unknown map backend: ") + backend);
|
||||
|
||||
// Determine how we're going to traverse the database (heuristic)
|
||||
if (m_exhaustiveSearch == EXH_AUTO) {
|
||||
using u64 = uint64_t;
|
||||
u64 y_range = (m_yMax / 16 + 1) - (m_yMin / 16);
|
||||
u64 blocks = (u64)(m_geomX2 - m_geomX) * y_range * (u64)(m_geomY2 - m_geomY);
|
||||
#ifndef NDEBUG
|
||||
std::cout << "Heuristic parameters:"
|
||||
<< " preferRangeQueries()=" << m_db->preferRangeQueries()
|
||||
<< " y_range=" << y_range << " blocks=" << blocks << std::endl;
|
||||
#endif
|
||||
if (m_db->preferRangeQueries())
|
||||
m_exhaustiveSearch = EXH_NEVER;
|
||||
else if (blocks < 200000)
|
||||
m_exhaustiveSearch = EXH_FULL;
|
||||
else if (y_range < 42)
|
||||
m_exhaustiveSearch = EXH_Y;
|
||||
else
|
||||
m_exhaustiveSearch = EXH_NEVER;
|
||||
} else if (m_exhaustiveSearch == EXH_FULL || m_exhaustiveSearch == EXH_Y) {
|
||||
if (m_db->preferRangeQueries()) {
|
||||
std::cerr << "Note: The current database backend supports efficient "
|
||||
"range queries, forcing exhaustive search should always result "
|
||||
" in worse performance." << std::endl;
|
||||
}
|
||||
}
|
||||
assert(m_exhaustiveSearch != EXH_AUTO);
|
||||
}
|
||||
|
||||
void TileGenerator::closeDatabase()
|
||||
@ -310,242 +392,267 @@ void TileGenerator::closeDatabase()
|
||||
|
||||
void TileGenerator::loadBlocks()
|
||||
{
|
||||
std::vector<BlockPos> vec = m_db->getBlockPos();
|
||||
for (std::vector<BlockPos>::iterator it = vec.begin(); it != vec.end(); ++it) {
|
||||
BlockPos pos = *it;
|
||||
// Check that it's in geometry (from --geometry option)
|
||||
if (pos.x < m_geomX || pos.x >= m_geomX2 || pos.z < m_geomY || pos.z >= m_geomY2)
|
||||
continue;
|
||||
// Check that it's between --min-y and --max-y
|
||||
if (pos.y * 16 < m_yMin || pos.y * 16 > m_yMax)
|
||||
continue;
|
||||
// Adjust minimum and maximum positions to the nearest block
|
||||
if (pos.x < m_xMin)
|
||||
m_xMin = pos.x;
|
||||
if (pos.x > m_xMax)
|
||||
m_xMax = pos.x;
|
||||
const int16_t yMax = m_yMax / 16 + 1;
|
||||
|
||||
if (pos.z < m_zMin)
|
||||
m_zMin = pos.z;
|
||||
if (pos.z > m_zMax)
|
||||
m_zMax = pos.z;
|
||||
m_positions.push_back(std::pair<int, int>(pos.x, pos.z));
|
||||
if (m_exhaustiveSearch == EXH_NEVER || m_exhaustiveSearch == EXH_Y) {
|
||||
std::vector<BlockPos> vec = m_db->getBlockPos(
|
||||
BlockPos(m_geomX, m_yMin / 16, m_geomY),
|
||||
BlockPos(m_geomX2, yMax, m_geomY2)
|
||||
);
|
||||
|
||||
for (auto pos : vec) {
|
||||
assert(pos.x >= m_geomX && pos.x < m_geomX2);
|
||||
assert(pos.y >= m_yMin / 16 && pos.y < yMax);
|
||||
assert(pos.z >= m_geomY && pos.z < m_geomY2);
|
||||
|
||||
// Adjust minimum and maximum positions to the nearest block
|
||||
if (pos.x < m_xMin)
|
||||
m_xMin = pos.x;
|
||||
if (pos.x > m_xMax)
|
||||
m_xMax = pos.x;
|
||||
|
||||
if (pos.z < m_zMin)
|
||||
m_zMin = pos.z;
|
||||
if (pos.z > m_zMax)
|
||||
m_zMax = pos.z;
|
||||
|
||||
m_positions[pos.z].emplace(pos.x);
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
int count = 0;
|
||||
for (const auto &it : m_positions)
|
||||
count += it.second.size();
|
||||
std::cout << "Loaded " << count
|
||||
<< " positions (across Z: " << m_positions.size() << ") for rendering" << std::endl;
|
||||
#endif
|
||||
}
|
||||
m_positions.sort();
|
||||
m_positions.unique();
|
||||
}
|
||||
|
||||
void TileGenerator::createImage()
|
||||
{
|
||||
const int scale_d = 40; // pixels reserved for a scale
|
||||
if(!m_drawScale)
|
||||
m_scales = 0;
|
||||
|
||||
|
||||
// If a geometry is explicitly set, set the bounding box to the requested geometry
|
||||
// instead of cropping to the content. This way we will always output a full tile
|
||||
// of the correct size.
|
||||
if (m_geomX > -2048 && m_geomX2 < 2048)
|
||||
{
|
||||
m_xMin = m_geomX;
|
||||
m_xMax = m_geomX2-1;
|
||||
}
|
||||
|
||||
if (m_geomY > -2048 && m_geomY2 < 2048)
|
||||
{
|
||||
m_zMin = m_geomY;
|
||||
m_zMax = m_geomY2-1;
|
||||
}
|
||||
|
||||
m_mapWidth = (m_xMax - m_xMin + 1) * 16;
|
||||
m_mapHeight = (m_zMax - m_zMin + 1) * 16;
|
||||
if(m_drawScale) {
|
||||
m_xBorder = (m_scales & SCALE_LEFT) ? 40 : 0;
|
||||
m_yBorder = (m_scales & SCALE_TOP) ? 40 : 0;
|
||||
}
|
||||
|
||||
m_xBorder = (m_scales & SCALE_LEFT) ? scale_d : 0;
|
||||
m_yBorder = (m_scales & SCALE_TOP) ? scale_d : 0;
|
||||
m_blockPixelAttributes.setWidth(m_mapWidth);
|
||||
|
||||
int image_width, image_height;
|
||||
image_width = (m_mapWidth * m_zoom) + m_xBorder;
|
||||
image_width += m_drawScale && (m_scales & SCALE_RIGHT) ? 40 : 0;
|
||||
image_width += (m_scales & SCALE_RIGHT) ? scale_d : 0;
|
||||
image_height = (m_mapHeight * m_zoom) + m_yBorder;
|
||||
image_height += m_drawScale && (m_scales & SCALE_BOTTOM) ? 40 : 0;
|
||||
image_height += (m_scales & SCALE_BOTTOM) ? scale_d : 0;
|
||||
|
||||
if(image_width > 4096 || image_height > 4096)
|
||||
if(image_width > 4096 || image_height > 4096) {
|
||||
std::cerr << "Warning: The width or height of the image to be created exceeds 4096 pixels!"
|
||||
<< " (Dimensions: " << image_width << "x" << image_height << ")"
|
||||
<< std::endl;
|
||||
}
|
||||
m_image = new Image(image_width, image_height);
|
||||
m_image->drawFilledRect(0, 0, image_width, image_height, m_bgColor); // Background
|
||||
}
|
||||
|
||||
void TileGenerator::renderMap()
|
||||
{
|
||||
std::list<int> zlist = getZValueList();
|
||||
for (std::list<int>::iterator zPosition = zlist.begin(); zPosition != zlist.end(); ++zPosition) {
|
||||
int zPos = *zPosition;
|
||||
std::map<int16_t, BlockList> blocks;
|
||||
m_db->getBlocksOnZ(blocks, zPos);
|
||||
for (std::list<std::pair<int, int> >::const_iterator position = m_positions.begin(); position != m_positions.end(); ++position) {
|
||||
if (position->second != zPos)
|
||||
continue;
|
||||
BlockDecoder blk;
|
||||
const int16_t yMax = m_yMax / 16 + 1;
|
||||
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
m_readPixels[i] = 0;
|
||||
m_readInfo[i] = 0;
|
||||
auto renderSingle = [&] (int16_t xPos, int16_t zPos, BlockList &blockStack) {
|
||||
m_readPixels.reset();
|
||||
m_readInfo.reset();
|
||||
for (int i = 0; i < 16; i++) {
|
||||
for (int j = 0; j < 16; j++) {
|
||||
m_color[i][j] = m_bgColor; // This will be drawn by renderMapBlockBottom() for y-rows with only 'air', 'ignore' or unknown nodes if --drawalpha is used
|
||||
m_color[i][j].a = 0; // ..but set alpha to 0 to tell renderMapBlock() not to use this color to mix a shade
|
||||
m_thickness[i][j] = 0;
|
||||
}
|
||||
for (int i = 0; i < 16; i++) {
|
||||
for (int j = 0; j < 16; j++) {
|
||||
m_color[i][j] = m_bgColor; // This will be drawn by renderMapBlockBottom() for y-rows with only 'air', 'ignore' or unknown nodes if --drawalpha is used
|
||||
m_color[i][j].a = 0; // ..but set alpha to 0 to tell renderMapBlock() not to use this color to mix a shade
|
||||
m_thickness[i][j] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int xPos = position->first;
|
||||
blocks[xPos].sort();
|
||||
const BlockList &blockStack = blocks[xPos];
|
||||
for (BlockList::const_iterator it = blockStack.begin(); it != blockStack.end(); ++it) {
|
||||
const BlockPos &pos = it->first;
|
||||
const unsigned char *data = it->second.c_str();
|
||||
size_t length = it->second.length();
|
||||
|
||||
uint8_t version = data[0];
|
||||
//uint8_t flags = data[1];
|
||||
|
||||
size_t dataOffset = 0;
|
||||
if (version >= 27)
|
||||
dataOffset = 6;
|
||||
else if (version >= 22)
|
||||
dataOffset = 4;
|
||||
else
|
||||
dataOffset = 2;
|
||||
|
||||
ZlibDecompressor decompressor(data, length);
|
||||
decompressor.setSeekPos(dataOffset);
|
||||
ustring mapData = decompressor.decompress();
|
||||
ustring mapMetadata = decompressor.decompress();
|
||||
dataOffset = decompressor.seekPos();
|
||||
|
||||
// Skip unused data
|
||||
if (version <= 21)
|
||||
dataOffset += 2;
|
||||
if (version == 23)
|
||||
dataOffset += 1;
|
||||
if (version == 24) {
|
||||
uint8_t ver = data[dataOffset++];
|
||||
if (ver == 1) {
|
||||
uint16_t num = readU16(data + dataOffset);
|
||||
dataOffset += 2;
|
||||
dataOffset += 10 * num;
|
||||
}
|
||||
}
|
||||
|
||||
// Skip unused static objects
|
||||
dataOffset++; // Skip static object version
|
||||
int staticObjectCount = readU16(data + dataOffset);
|
||||
dataOffset += 2;
|
||||
for (int i = 0; i < staticObjectCount; ++i) {
|
||||
dataOffset += 13;
|
||||
uint16_t dataSize = readU16(data + dataOffset);
|
||||
dataOffset += dataSize + 2;
|
||||
}
|
||||
dataOffset += 4; // Skip timestamp
|
||||
|
||||
m_blockAirId = -1;
|
||||
m_blockIgnoreId = -1;
|
||||
m_nameMap.clear();
|
||||
// Read mapping
|
||||
if (version >= 22) {
|
||||
dataOffset++; // mapping version
|
||||
uint16_t numMappings = readU16(data + dataOffset);
|
||||
dataOffset += 2;
|
||||
for (int i = 0; i < numMappings; ++i) {
|
||||
uint16_t nodeId = readU16(data + dataOffset);
|
||||
dataOffset += 2;
|
||||
uint16_t nameLen = readU16(data + dataOffset);
|
||||
dataOffset += 2;
|
||||
string name = string(reinterpret_cast<const char *>(data) + dataOffset, nameLen);
|
||||
if (name == "air")
|
||||
m_blockAirId = nodeId;
|
||||
else if (name == "ignore")
|
||||
m_blockIgnoreId = nodeId;
|
||||
else
|
||||
m_nameMap[nodeId] = name;
|
||||
dataOffset += nameLen;
|
||||
}
|
||||
// Skip block if made of only air or ignore nodes
|
||||
if (m_nameMap.empty())
|
||||
continue;
|
||||
}
|
||||
|
||||
// Node timers
|
||||
if (version >= 25) {
|
||||
dataOffset++;
|
||||
uint16_t numTimers = readU16(data + dataOffset);
|
||||
dataOffset += 2;
|
||||
dataOffset += numTimers * 10;
|
||||
}
|
||||
|
||||
renderMapBlock(mapData, pos, version);
|
||||
|
||||
bool allRead = true;
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
if (m_readPixels[i] != 0xffff)
|
||||
allRead = false;
|
||||
}
|
||||
if (allRead)
|
||||
break;
|
||||
}
|
||||
bool allRead = true;
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
if (m_readPixels[i] != 0xffff)
|
||||
allRead = false;
|
||||
}
|
||||
if (!allRead)
|
||||
renderMapBlockBottom(blockStack.begin()->first);
|
||||
}
|
||||
if(m_shading)
|
||||
|
||||
for (const auto &it : blockStack) {
|
||||
const BlockPos pos = it.first;
|
||||
assert(pos.x == xPos && pos.z == zPos);
|
||||
assert(pos.y >= m_yMin / 16 && pos.y < yMax);
|
||||
|
||||
blk.reset();
|
||||
blk.decode(it.second);
|
||||
renderMapBlock(blk, pos);
|
||||
|
||||
// Exit out if all pixels for this MapBlock are covered
|
||||
if (m_readPixels.full())
|
||||
break;
|
||||
}
|
||||
if (!m_readPixels.full())
|
||||
renderMapBlockBottom(blockStack.begin()->first);
|
||||
};
|
||||
auto postRenderRow = [&] (int16_t zPos) {
|
||||
if (m_shading)
|
||||
renderShading(zPos);
|
||||
};
|
||||
|
||||
if (m_exhaustiveSearch == EXH_NEVER) {
|
||||
for (auto it = m_positions.rbegin(); it != m_positions.rend(); ++it) {
|
||||
int16_t zPos = it->first;
|
||||
for (auto it2 = it->second.rbegin(); it2 != it->second.rend(); ++it2) {
|
||||
int16_t xPos = *it2;
|
||||
|
||||
BlockList blockStack;
|
||||
m_db->getBlocksOnXZ(blockStack, xPos, zPos, m_yMin / 16, yMax);
|
||||
blockStack.sort();
|
||||
|
||||
renderSingle(xPos, zPos, blockStack);
|
||||
}
|
||||
postRenderRow(zPos);
|
||||
}
|
||||
} else if (m_exhaustiveSearch == EXH_Y) {
|
||||
#ifndef NDEBUG
|
||||
std::cerr << "Exhaustively searching height of "
|
||||
<< (yMax - (m_yMin / 16)) << " blocks" << std::endl;
|
||||
#endif
|
||||
std::vector<BlockPos> positions;
|
||||
positions.reserve(yMax - (m_yMin / 16));
|
||||
for (auto it = m_positions.rbegin(); it != m_positions.rend(); ++it) {
|
||||
int16_t zPos = it->first;
|
||||
for (auto it2 = it->second.rbegin(); it2 != it->second.rend(); ++it2) {
|
||||
int16_t xPos = *it2;
|
||||
|
||||
positions.clear();
|
||||
for (int16_t yPos = m_yMin / 16; yPos < yMax; yPos++)
|
||||
positions.emplace_back(xPos, yPos, zPos);
|
||||
|
||||
BlockList blockStack;
|
||||
m_db->getBlocksByPos(blockStack, positions);
|
||||
blockStack.sort();
|
||||
|
||||
renderSingle(xPos, zPos, blockStack);
|
||||
}
|
||||
postRenderRow(zPos);
|
||||
}
|
||||
} else if (m_exhaustiveSearch == EXH_FULL) {
|
||||
#ifndef NDEBUG
|
||||
std::cerr << "Exhaustively searching "
|
||||
<< (m_geomX2 - m_geomX) << "x" << (yMax - (m_yMin / 16)) << "x"
|
||||
<< (m_geomY2 - m_geomY) << " blocks" << std::endl;
|
||||
#endif
|
||||
std::vector<BlockPos> positions;
|
||||
positions.reserve(yMax - (m_yMin / 16));
|
||||
for (int16_t zPos = m_geomY2 - 1; zPos >= m_geomY; zPos--) {
|
||||
for (int16_t xPos = m_geomX2 - 1; xPos >= m_geomX; xPos--) {
|
||||
positions.clear();
|
||||
for (int16_t yPos = m_yMin / 16; yPos < yMax; yPos++)
|
||||
positions.emplace_back(xPos, yPos, zPos);
|
||||
|
||||
BlockList blockStack;
|
||||
m_db->getBlocksByPos(blockStack, positions);
|
||||
blockStack.sort();
|
||||
|
||||
renderSingle(xPos, zPos, blockStack);
|
||||
}
|
||||
postRenderRow(zPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TileGenerator::renderMapBlock(const ustring &mapBlock, const BlockPos &pos, int version)
|
||||
void TileGenerator::renderMapBlock(const BlockDecoder &blk, const BlockPos &pos)
|
||||
{
|
||||
/***/
|
||||
static bool light_curve_init = false;
|
||||
static float light_curve[16];
|
||||
if (!light_curve_init) {
|
||||
for (u8 i = 0; i < 16; i++)
|
||||
light_curve[i] = expf((i - 15) / 12.0f);
|
||||
light_curve_init = true;
|
||||
}
|
||||
/***/
|
||||
auto light_at = [blk] (u8 x, u8 y, u8 z) -> u8 {
|
||||
return blk.getParam1(x, y, z) >> 4; // night bank
|
||||
};
|
||||
static u8 m_light[16][16];
|
||||
if (blk.isEmpty()) {
|
||||
for (int z = 0; z < 16; ++z) {
|
||||
for (int x = 0; x < 16; ++x) {
|
||||
m_light[z][x] = light_at(x, 0, z);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int xBegin = (pos.x - m_xMin) * 16;
|
||||
int zBegin = (m_zMax - pos.z) * 16;
|
||||
const unsigned char *mapData = mapBlock.c_str();
|
||||
int minY = (pos.y * 16 > m_yMin) ? 0 : m_yMin - pos.y * 16;
|
||||
int maxY = (pos.y * 16 < m_yMax) ? 15 : m_yMax - pos.y * 16;
|
||||
int maxY = (pos.y * 16 + 15 < m_yMax) ? 15 : m_yMax - pos.y * 16;
|
||||
for (int z = 0; z < 16; ++z) {
|
||||
int imageY = zBegin + 15 - z;
|
||||
for (int x = 0; x < 16; ++x) {
|
||||
if (m_readPixels[z] & (1 << x))
|
||||
if (m_readPixels.get(x, z))
|
||||
continue;
|
||||
int imageX = xBegin + x;
|
||||
|
||||
for (int y = maxY; y >= minY; --y) {
|
||||
int position = x + (y << 4) + (z << 8);
|
||||
int content = readBlockContent(mapData, version, position);
|
||||
if (content == m_blockAirId || content == m_blockIgnoreId)
|
||||
continue;
|
||||
NameMap::iterator blockName = m_nameMap.find(content);
|
||||
if (blockName == m_nameMap.end()) {
|
||||
std::cerr << "Skipping node with invalid ID." << std::endl;
|
||||
string name = blk.getNode(x, y, z);
|
||||
if (name == "") {
|
||||
if (y == 0) m_light[z][x] = light_at(x, 0, z);
|
||||
continue;
|
||||
}
|
||||
const string &name = blockName->second;
|
||||
ColorMap::const_iterator color = m_colorMap.find(name);
|
||||
if (color != m_colorMap.end()) {
|
||||
const Color c = color->second.to_color();
|
||||
if (m_drawAlpha) {
|
||||
// mix with previous color (unless first visible time)
|
||||
if (m_color[z][x].a == 0)
|
||||
m_color[z][x] = c;
|
||||
else
|
||||
m_color[z][x] = mixColors(m_color[z][x], c);
|
||||
if(m_color[z][x].a == 0xff) {
|
||||
// color is opaque at this depth (no point continuing)
|
||||
setZoomed(imageX, imageY, m_color[z][x]);
|
||||
m_readPixels[z] |= (1 << x);
|
||||
m_blockPixelAttributes.attribute(15 - z, xBegin + x).thickness = m_thickness[z][x];
|
||||
} else {
|
||||
// near thickness value to thickness of current node
|
||||
m_thickness[z][x] = (m_thickness[z][x] + color->second.t) / 2.0;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
setZoomed(imageX, imageY, c.noAlpha());
|
||||
m_readPixels[z] |= (1 << x);
|
||||
}
|
||||
if(!(m_readInfo[z] & (1 << x))) {
|
||||
m_blockPixelAttributes.attribute(15 - z, xBegin + x).height = pos.y * 16 + y;
|
||||
m_readInfo[z] |= (1 << x);
|
||||
}
|
||||
} else {
|
||||
ColorMap::const_iterator it = m_colorMap.find(name);
|
||||
if (it == m_colorMap.end()) {
|
||||
m_unknownNodes.insert(name);
|
||||
continue;
|
||||
}
|
||||
Color c = it->second.to_color();
|
||||
u8 light = (y == 15) ? m_light[z][x] : light_at(x, y+1, z);
|
||||
if (light < 15) light = mymax(light, light_at(x, y, z));
|
||||
if (1) {
|
||||
float l2 = light_curve[light];
|
||||
c.r = colorSafeBounds(c.r * l2);
|
||||
c.g = colorSafeBounds(c.g * l2);
|
||||
c.b = colorSafeBounds(c.b * l2);
|
||||
} else
|
||||
c = Color(light * 17, light * 17, light * 17);
|
||||
if (m_drawAlpha) {
|
||||
if (m_color[z][x].a == 0)
|
||||
m_color[z][x] = c; // first visible time, no color mixing
|
||||
else
|
||||
m_color[z][x] = mixColors(m_color[z][x], c);
|
||||
if(m_color[z][x].a < 0xff) {
|
||||
// near thickness value to thickness of current node
|
||||
m_thickness[z][x] = (m_thickness[z][x] + it->second.t) / 2.0;
|
||||
continue;
|
||||
}
|
||||
// color became opaque, draw it
|
||||
setZoomed(imageX, imageY, m_color[z][x]);
|
||||
m_blockPixelAttributes.attribute(15 - z, xBegin + x).thickness = m_thickness[z][x];
|
||||
} else {
|
||||
setZoomed(imageX, imageY, c.noAlpha());
|
||||
}
|
||||
m_readPixels.set(x, z);
|
||||
|
||||
// do this afterwards so we can record height values
|
||||
// inside transparent nodes (water) too
|
||||
if (!m_readInfo.get(x, z)) {
|
||||
m_blockPixelAttributes.attribute(15 - z, xBegin + x).height = pos.y * 16 + y;
|
||||
m_readInfo.set(x, z);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -554,21 +661,22 @@ void TileGenerator::renderMapBlock(const ustring &mapBlock, const BlockPos &pos,
|
||||
|
||||
void TileGenerator::renderMapBlockBottom(const BlockPos &pos)
|
||||
{
|
||||
if (!m_drawAlpha)
|
||||
return; // "missing" pixels can only happen with --drawalpha
|
||||
|
||||
int xBegin = (pos.x - m_xMin) * 16;
|
||||
int zBegin = (m_zMax - pos.z) * 16;
|
||||
for (int z = 0; z < 16; ++z) {
|
||||
int imageY = zBegin + 15 - z;
|
||||
for (int x = 0; x < 16; ++x) {
|
||||
if (m_readPixels[z] & (1 << x))
|
||||
if (m_readPixels.get(x, z))
|
||||
continue;
|
||||
int imageX = xBegin + x;
|
||||
|
||||
if (m_drawAlpha) {
|
||||
// set color in case it wasn't done in renderMapBlock()
|
||||
setZoomed(imageX, imageY, m_color[z][x]);
|
||||
m_readPixels[z] |= (1 << x);
|
||||
m_blockPixelAttributes.attribute(15 - z, xBegin + x).thickness = m_thickness[z][x];
|
||||
}
|
||||
// set color since it wasn't done in renderMapBlock()
|
||||
setZoomed(imageX, imageY, m_color[z][x]);
|
||||
m_readPixels.set(x, z);
|
||||
m_blockPixelAttributes.attribute(15 - z, xBegin + x).thickness = m_thickness[z][x];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -593,11 +701,11 @@ void TileGenerator::renderShading(int zPos)
|
||||
int y1 = m_blockPixelAttributes.attribute(z, x - 1).height;
|
||||
int y2 = m_blockPixelAttributes.attribute(z - 1, x).height;
|
||||
int d = ((y - y1) + (y - y2)) * 12;
|
||||
if (d > 36)
|
||||
d = 36;
|
||||
// more thickness -> less visible shadows: t=0 -> 100% visible, t=255 -> 0% visible
|
||||
if (m_drawAlpha)
|
||||
d = d * ((0xFF - m_blockPixelAttributes.attribute(z, x).thickness) / 255.0);
|
||||
if (m_drawAlpha) { // less visible shadow with increasing "thickness"
|
||||
double t = m_blockPixelAttributes.attribute(z, x).thickness * 1.2;
|
||||
d *= 1.0 - mymin(t, 255.0) / 255.0;
|
||||
}
|
||||
d = mymin(d, 36);
|
||||
|
||||
Color c = m_image->getPixel(getImageX(x), getImageY(imageY));
|
||||
c.r = colorSafeBounds(c.r + d);
|
||||
@ -611,85 +719,97 @@ void TileGenerator::renderShading(int zPos)
|
||||
|
||||
void TileGenerator::renderScale()
|
||||
{
|
||||
const int scale_d = 40; // see createImage()
|
||||
|
||||
if (m_scales & SCALE_TOP) {
|
||||
m_image->drawText(24, 0, "X", m_scaleColor);
|
||||
for (int i = (m_xMin / 4) * 4; i <= m_xMax; i += 4) {
|
||||
stringstream buf;
|
||||
std::ostringstream buf;
|
||||
buf << i * 16;
|
||||
|
||||
int xPos = (m_xMin * -16 + i * 16)*m_zoom + m_xBorder;
|
||||
m_image->drawText(xPos + 2, 0, buf.str(), m_scaleColor);
|
||||
m_image->drawLine(xPos, 0, xPos, m_yBorder - 1, m_scaleColor);
|
||||
int xPos = getImageX(i * 16, true);
|
||||
if (xPos >= 0) {
|
||||
m_image->drawText(xPos + 2, 0, buf.str(), m_scaleColor);
|
||||
m_image->drawLine(xPos, 0, xPos, m_yBorder - 1, m_scaleColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (m_scales & SCALE_LEFT) {
|
||||
m_image->drawText(2, 24, "Z", m_scaleColor);
|
||||
for (int i = (m_zMax / 4) * 4; i >= m_zMin; i -= 4) {
|
||||
stringstream buf;
|
||||
std::ostringstream buf;
|
||||
buf << i * 16;
|
||||
|
||||
int yPos = (m_mapHeight - 1 - (i * 16 - m_zMin * 16))*m_zoom + m_yBorder;
|
||||
m_image->drawText(2, yPos, buf.str(), m_scaleColor);
|
||||
m_image->drawLine(0, yPos, m_xBorder - 1, yPos, m_scaleColor);
|
||||
int yPos = getImageY(i * 16 + 1, true);
|
||||
if (yPos >= 0) {
|
||||
m_image->drawText(2, yPos, buf.str(), m_scaleColor);
|
||||
m_image->drawLine(0, yPos, m_xBorder - 1, yPos, m_scaleColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (m_scales & SCALE_BOTTOM) {
|
||||
int xPos = m_xBorder + m_mapWidth*m_zoom - 24 - 8,
|
||||
yPos = m_yBorder + m_mapHeight*m_zoom + scale_d - 12;
|
||||
m_image->drawText(xPos, yPos, "X", m_scaleColor);
|
||||
for (int i = (m_xMin / 4) * 4; i <= m_xMax; i += 4) {
|
||||
stringstream buf;
|
||||
std::ostringstream buf;
|
||||
buf << i * 16;
|
||||
|
||||
int xPos = (m_xMin * -16 + i * 16)*m_zoom + m_xBorder;
|
||||
int yPos = m_yBorder + m_mapHeight*m_zoom;
|
||||
m_image->drawText(xPos + 2, yPos, buf.str(), m_scaleColor);
|
||||
m_image->drawLine(xPos, yPos, xPos, yPos + 39, m_scaleColor);
|
||||
xPos = getImageX(i * 16, true);
|
||||
yPos = m_yBorder + m_mapHeight*m_zoom;
|
||||
if (xPos >= 0) {
|
||||
m_image->drawText(xPos + 2, yPos, buf.str(), m_scaleColor);
|
||||
m_image->drawLine(xPos, yPos, xPos, yPos + 39, m_scaleColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (m_scales & SCALE_RIGHT) {
|
||||
int xPos = m_xBorder + m_mapWidth*m_zoom + scale_d - 2 - 8,
|
||||
yPos = m_yBorder + m_mapHeight*m_zoom - 24 - 12;
|
||||
m_image->drawText(xPos, yPos, "Z", m_scaleColor);
|
||||
for (int i = (m_zMax / 4) * 4; i >= m_zMin; i -= 4) {
|
||||
stringstream buf;
|
||||
std::ostringstream buf;
|
||||
buf << i * 16;
|
||||
|
||||
int xPos = m_xBorder + m_mapWidth*m_zoom;
|
||||
int yPos = (m_mapHeight - 1 - (i * 16 - m_zMin * 16))*m_zoom + m_yBorder;
|
||||
m_image->drawText(xPos + 2, yPos, buf.str(), m_scaleColor);
|
||||
m_image->drawLine(xPos, yPos, xPos + 39, yPos, m_scaleColor);
|
||||
xPos = m_xBorder + m_mapWidth*m_zoom;
|
||||
yPos = getImageY(i * 16 + 1, true);
|
||||
if (yPos >= 0) {
|
||||
m_image->drawText(xPos + 2, yPos, buf.str(), m_scaleColor);
|
||||
m_image->drawLine(xPos, yPos, xPos + 39, yPos, m_scaleColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TileGenerator::renderOrigin()
|
||||
{
|
||||
int imageX = (-m_xMin * 16)*m_zoom + m_xBorder;
|
||||
int imageY = (m_mapHeight - m_zMin * -16)*m_zoom + m_yBorder;
|
||||
m_image->drawCircle(imageX, imageY, 12, m_originColor);
|
||||
if (m_xMin > 0 || m_xMax < 0 ||
|
||||
m_zMin > 0 || m_zMax < 0)
|
||||
return;
|
||||
m_image->drawCircle(getImageX(0, true), getImageY(0, true), 12, m_originColor);
|
||||
}
|
||||
|
||||
void TileGenerator::renderPlayers(const std::string &inputPath)
|
||||
{
|
||||
PlayerAttributes players(inputPath);
|
||||
for (PlayerAttributes::Players::iterator player = players.begin(); player != players.end(); ++player) {
|
||||
int imageX = (player->x / 10 - m_xMin * 16)*m_zoom + m_xBorder;
|
||||
int imageY = (m_mapHeight - (player->z / 10 - m_zMin * 16))*m_zoom + m_yBorder;
|
||||
for (auto &player : players) {
|
||||
if (player.x < m_xMin * 16 || player.x > m_xMax * 16 ||
|
||||
player.z < m_zMin * 16 || player.z > m_zMax * 16)
|
||||
continue;
|
||||
if (player.y < m_yMin || player.y > m_yMax)
|
||||
continue;
|
||||
int imageX = getImageX(player.x, true),
|
||||
imageY = getImageY(player.z, true);
|
||||
|
||||
m_image->drawCircle(imageX, imageY, 5, m_playerColor);
|
||||
m_image->drawText(imageX + 2, imageY + 2, player->name, m_playerColor);
|
||||
m_image->drawFilledRect(imageX - 1, imageY, 3, 1, m_playerColor);
|
||||
m_image->drawFilledRect(imageX, imageY - 1, 1, 3, m_playerColor);
|
||||
m_image->drawText(imageX + 2, imageY, player.name, m_playerColor);
|
||||
}
|
||||
}
|
||||
|
||||
inline std::list<int> TileGenerator::getZValueList() const
|
||||
{
|
||||
std::list<int> zlist;
|
||||
for (std::list<std::pair<int, int> >::const_iterator position = m_positions.begin(); position != m_positions.end(); ++position)
|
||||
zlist.push_back(position->second);
|
||||
zlist.sort();
|
||||
zlist.unique();
|
||||
zlist.reverse();
|
||||
return zlist;
|
||||
}
|
||||
|
||||
void TileGenerator::writeImage(const std::string &output)
|
||||
{
|
||||
m_image->save(output);
|
||||
@ -699,21 +819,24 @@ void TileGenerator::writeImage(const std::string &output)
|
||||
|
||||
void TileGenerator::printUnknown()
|
||||
{
|
||||
if (m_unknownNodes.size() > 0) {
|
||||
std::cerr << "Unknown nodes:" << std::endl;
|
||||
for (NameSet::iterator node = m_unknownNodes.begin(); node != m_unknownNodes.end(); ++node) {
|
||||
std::cerr << *node << std::endl;
|
||||
}
|
||||
}
|
||||
if (m_unknownNodes.size() == 0)
|
||||
return;
|
||||
std::cerr << "Unknown nodes:" << std::endl;
|
||||
for (const auto &node : m_unknownNodes)
|
||||
std::cerr << "\t" << node << std::endl;
|
||||
}
|
||||
|
||||
inline int TileGenerator::getImageX(int val) const
|
||||
inline int TileGenerator::getImageX(int val, bool absolute) const
|
||||
{
|
||||
if (absolute)
|
||||
val = (val - m_xMin * 16);
|
||||
return (m_zoom*val) + m_xBorder;
|
||||
}
|
||||
|
||||
inline int TileGenerator::getImageY(int val) const
|
||||
inline int TileGenerator::getImageY(int val, bool absolute) const
|
||||
{
|
||||
if (absolute)
|
||||
val = m_mapHeight - (val - m_zMin * 16); // Z axis is flipped on image
|
||||
return (m_zoom*val) + m_yBorder;
|
||||
}
|
||||
|
||||
|
@ -65,11 +65,9 @@ minetest.register_chatcommand("dumpnodes", {
|
||||
==FILE== avgcolor.py
|
||||
#!/usr/bin/env python
|
||||
import sys
|
||||
from math import sqrt
|
||||
from PIL import Image
|
||||
|
||||
def tadd(a, b):
|
||||
return tuple(sum(e) for e in zip(a, b))
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
print("Prints average color (RGB) of input image")
|
||||
print("Usage: %s <input>" % sys.argv[0])
|
||||
@ -78,20 +76,20 @@ if len(sys.argv) < 2:
|
||||
inp = Image.open(sys.argv[1]).convert('RGBA')
|
||||
ind = inp.load()
|
||||
|
||||
cl = (0, 0, 0)
|
||||
counted = 0
|
||||
cl = ([], [], [])
|
||||
for x in range(inp.size[0]):
|
||||
for y in range(inp.size[1]):
|
||||
px = ind[x, y]
|
||||
if px[3] < 128: continue # alpha
|
||||
cl = tadd(cl, px[:3])
|
||||
counted += 1
|
||||
cl[0].append(px[0]**2)
|
||||
cl[1].append(px[1]**2)
|
||||
cl[2].append(px[2]**2)
|
||||
|
||||
if counted == 0:
|
||||
sys.stderr.write("did not find avg color for %s\n" % sys.argv[1])
|
||||
if len(cl[0]) == 0:
|
||||
print("Didn't find average color for %s" % sys.argv[1], file=sys.stderr)
|
||||
print("0 0 0")
|
||||
else:
|
||||
cl = tuple(int(n / counted) for n in cl)
|
||||
cl = tuple(sqrt(sum(x)/len(x)) for x in cl)
|
||||
print("%d %d %d" % cl)
|
||||
==SCRIPT==
|
||||
#!/bin/bash -e
|
||||
@ -118,11 +116,14 @@ done < $NODESTXT_PATH > $COLORSTXT_PATH
|
||||
# Use nicer colors for water and lava:
|
||||
sed -re 's/^default:((river_)?water_(flowing|source)) [0-9 ]+$/default:\1 39 66 106 128 224/g' $COLORSTXT_PATH -i
|
||||
sed -re 's/^default:(lava_(flowing|source)) [0-9 ]+$/default:\1 255 100 0/g' $COLORSTXT_PATH -i
|
||||
# Add transparency to glass nodes:
|
||||
# Add transparency to glass nodes and xpanes:
|
||||
sed -re 's/^default:(.*glass) ([0-9 ]+)$/default:\1 \2 64 16/g' $COLORSTXT_PATH -i
|
||||
sed -re 's/^doors:(.*glass[^ ]*) ([0-9 ]+)$/doors:\1 \2 64 16/g' $COLORSTXT_PATH -i
|
||||
# Fix xpanes color:
|
||||
sed -re 's/^xpanes:((pane|bar)(_flat)?) [0-9 ]+$/xpanes:\1 194 194 227 64 16/g' $COLORSTXT_PATH -i
|
||||
sed -re 's/^xpanes:(.*(pane|bar)[^ ]*) ([0-9 ]+)$/xpanes:\1 \3 64 16/g' $COLORSTXT_PATH -i
|
||||
# Delete some usually hidden nodes:
|
||||
sed '/^doors:hidden /d' $COLORSTXT_PATH -i
|
||||
sed '/^fireflies:firefly /d' $COLORSTXT_PATH -i
|
||||
sed '/^butterflies:butterfly_/d' $COLORSTXT_PATH -i
|
||||
==INSTRUCTIONS==
|
||||
1) Make sure avgcolors.py works (outputs the usage instructions when run)
|
||||
2) Add the dumpnodes mod to Minetest
|
||||
|
635
colors.txt
635
colors.txt
@ -1,127 +1,159 @@
|
||||
# beds
|
||||
beds:bed_bottom 130 3 3
|
||||
beds:bed_top 178 116 116
|
||||
beds:fancy_bed_bottom 135 23 14
|
||||
beds:fancy_bed_top 172 112 103
|
||||
beds:bed_top 185 162 163
|
||||
beds:fancy_bed_bottom 136 49 28
|
||||
beds:fancy_bed_top 179 153 148
|
||||
|
||||
# bones
|
||||
bones:bones 86 86 86
|
||||
bones:bones 117 117 117
|
||||
|
||||
# butterflies
|
||||
|
||||
# carts
|
||||
carts:brakerail 129 110 81
|
||||
carts:powerrail 154 136 81
|
||||
carts:rail 143 123 90
|
||||
carts:brakerail 138 121 102
|
||||
carts:powerrail 160 145 102
|
||||
carts:rail 146 128 108
|
||||
|
||||
# default
|
||||
default:acacia_bush_leaves 90 124 55
|
||||
default:acacia_bush_sapling 85 118 58
|
||||
default:acacia_bush_stem 84 76 69
|
||||
default:acacia_leaves 108 147 67
|
||||
default:acacia_sapling 87 116 61
|
||||
default:acacia_tree 188 109 90
|
||||
default:acacia_wood 146 60 37
|
||||
default:apple 145 20 9
|
||||
default:aspen_leaves 70 104 27
|
||||
default:aspen_sapling 82 110 43
|
||||
default:aspen_tree 218 197 166
|
||||
default:aspen_wood 209 198 169
|
||||
default:bookshelf 128 99 55
|
||||
default:brick 117 71 69
|
||||
default:bronzeblock 185 110 15
|
||||
default:bush_leaves 34 52 29
|
||||
default:bush_sapling 65 60 40
|
||||
default:bush_stem 45 33 23
|
||||
default:cactus 52 116 15
|
||||
default:chest 140 108 65
|
||||
default:chest_locked 140 108 65
|
||||
default:chest_locked_open 140 108 65
|
||||
default:chest_open 140 108 65
|
||||
default:clay 182 182 182
|
||||
default:acacia_bush_leaves 109 133 87
|
||||
default:acacia_bush_sapling 85 121 61
|
||||
default:acacia_bush_stem 84 77 70
|
||||
default:acacia_leaves 126 153 101
|
||||
default:acacia_sapling 87 120 64
|
||||
default:acacia_tree 195 119 97
|
||||
default:acacia_wood 150 61 39
|
||||
default:apple 161 34 19
|
||||
default:aspen_leaves 72 105 29
|
||||
default:aspen_sapling 85 123 45
|
||||
default:aspen_tree 218 198 168
|
||||
default:aspen_wood 210 199 170
|
||||
default:blueberry_bush_leaves 63 99 22
|
||||
default:blueberry_bush_leaves_with_berries 63 99 22
|
||||
default:blueberry_bush_sapling 81 112 33
|
||||
default:bookshelf 131 102 57
|
||||
default:brick 123 99 95
|
||||
default:bronzeblock 186 111 15
|
||||
default:bush_leaves 35 55 29
|
||||
default:bush_sapling 66 64 40
|
||||
default:bush_stem 46 34 24
|
||||
default:cactus 70 119 52
|
||||
default:cave_ice 168 206 247
|
||||
default:chest 149 115 69
|
||||
default:chest_locked 149 115 69
|
||||
default:chest_locked_open 149 115 69
|
||||
default:chest_open 149 115 69
|
||||
default:clay 183 183 183
|
||||
default:cloud 255 255 255
|
||||
default:coalblock 57 57 57
|
||||
default:cobble 88 84 82
|
||||
default:copperblock 192 126 63
|
||||
default:coral_brown 139 104 72
|
||||
default:coral_orange 191 62 12
|
||||
default:coral_skeleton 235 230 214
|
||||
default:desert_cobble 146 95 76
|
||||
default:coalblock 58 58 58
|
||||
default:cobble 89 86 84
|
||||
default:copperblock 193 126 65
|
||||
default:coral_brown 146 113 77
|
||||
default:coral_cyan 235 230 215
|
||||
default:coral_green 235 230 215
|
||||
default:coral_orange 197 68 17
|
||||
default:coral_pink 235 230 215
|
||||
default:coral_skeleton 235 230 215
|
||||
default:desert_cobble 110 67 50
|
||||
default:desert_sand 206 165 98
|
||||
default:desert_sandstone 195 152 92
|
||||
default:desert_sandstone_block 192 151 94
|
||||
default:desert_sandstone_brick 191 151 94
|
||||
default:desert_stone 129 79 60
|
||||
default:desert_stone_block 130 79 60
|
||||
default:desert_stonebrick 129 79 60
|
||||
default:diamondblock 135 217 223
|
||||
default:dirt 95 64 39
|
||||
default:dirt_with_dry_grass 187 148 77
|
||||
default:dirt_with_grass 66 112 31
|
||||
default:dirt_with_grass_footsteps 66 112 31
|
||||
default:dirt_with_rainforest_litter 74 38 8
|
||||
default:dirt_with_snow 224 225 238
|
||||
default:desert_sandstone_block 193 152 94
|
||||
default:desert_sandstone_brick 191 151 95
|
||||
default:desert_stone 130 79 61
|
||||
default:desert_stone_block 131 80 61
|
||||
default:desert_stonebrick 131 80 61
|
||||
default:diamondblock 140 218 223
|
||||
default:dirt 97 67 43
|
||||
default:dirt_with_coniferous_litter 109 90 71
|
||||
default:dirt_with_dry_grass 187 148 78
|
||||
default:dirt_with_grass 64 111 26
|
||||
default:dirt_with_grass_footsteps 64 111 26
|
||||
default:dirt_with_rainforest_litter 76 39 10
|
||||
default:dirt_with_snow 225 225 238
|
||||
default:dry_dirt 178 136 90
|
||||
default:dry_dirt_with_dry_grass 187 148 78
|
||||
default:dry_grass_1 208 172 87
|
||||
default:dry_grass_2 210 174 87
|
||||
default:dry_grass_3 210 174 87
|
||||
default:dry_grass_4 211 175 88
|
||||
default:dry_grass_5 213 178 92
|
||||
default:dry_shrub 101 66 17
|
||||
default:fence_acacia_wood 147 60 38
|
||||
default:dry_grass_5 214 178 92
|
||||
default:dry_shrub 103 67 18
|
||||
default:emergent_jungle_sapling 51 40 16
|
||||
default:fence_acacia_wood 151 62 39
|
||||
default:fence_aspen_wood 210 199 170
|
||||
default:fence_junglewood 54 37 11
|
||||
default:fence_pine_wood 221 184 129
|
||||
default:fence_wood 129 100 55
|
||||
default:furnace 100 96 94
|
||||
default:furnace_active 100 96 94
|
||||
default:glass 194 194 227 64 16
|
||||
default:goldblock 230 201 29
|
||||
default:grass_1 97 138 53
|
||||
default:grass_2 95 136 54
|
||||
default:grass_3 91 133 52
|
||||
default:grass_4 86 130 45
|
||||
default:grass_5 83 124 47
|
||||
default:gravel 131 131 131
|
||||
default:ice 167 206 247
|
||||
default:junglegrass 63 105 25
|
||||
default:jungleleaves 20 28 15
|
||||
default:junglesapling 48 38 14
|
||||
default:jungletree 105 76 41
|
||||
default:junglewood 54 37 11
|
||||
default:ladder_steel 126 126 126
|
||||
default:ladder_wood 123 90 34
|
||||
default:fence_junglewood 57 39 14
|
||||
default:fence_pine_wood 221 185 131
|
||||
default:fence_rail_acacia_wood 150 61 39
|
||||
default:fence_rail_aspen_wood 209 198 170
|
||||
default:fence_rail_junglewood 56 39 14
|
||||
default:fence_rail_pine_wood 221 184 130
|
||||
default:fence_rail_wood 131 102 57
|
||||
default:fence_wood 132 103 57
|
||||
default:fern_1 85 118 51
|
||||
default:fern_2 90 123 53
|
||||
default:fern_3 91 125 54
|
||||
default:furnace 101 98 96
|
||||
default:furnace_active 101 98 96
|
||||
default:glass 247 247 247 64 16
|
||||
default:goldblock 231 203 35
|
||||
default:grass_1 100 140 54
|
||||
default:grass_2 98 139 55
|
||||
default:grass_3 94 136 53
|
||||
default:grass_4 89 133 48
|
||||
default:grass_5 86 126 48
|
||||
default:gravel 132 132 132
|
||||
default:ice 168 206 247
|
||||
default:junglegrass 67 110 28
|
||||
default:jungleleaves 22 31 16
|
||||
default:junglesapling 51 39 15
|
||||
default:jungletree 121 97 62
|
||||
default:junglewood 56 39 14
|
||||
default:ladder_steel 132 132 132
|
||||
default:ladder_wood 125 93 43
|
||||
default:large_cactus_seedling 67 107 52
|
||||
default:lava_flowing 255 100 0
|
||||
default:lava_source 255 100 0
|
||||
default:leaves 34 52 29
|
||||
default:mese 220 220 0
|
||||
default:mese_post_light 131 102 57
|
||||
default:meselamp 211 213 139
|
||||
default:mossycobble 86 90 68
|
||||
default:obsidian 19 21 24
|
||||
default:obsidian_block 20 22 25
|
||||
default:obsidian_glass 19 21 23 64 16
|
||||
default:obsidianbrick 20 22 24
|
||||
default:papyrus 94 132 33
|
||||
default:pine_needles 13 36 21
|
||||
default:pine_sapling 27 48 25
|
||||
default:pine_tree 182 155 124
|
||||
default:pine_wood 221 184 128
|
||||
default:leaves 36 55 29
|
||||
default:marram_grass_1 113 139 96
|
||||
default:marram_grass_2 102 131 90
|
||||
default:marram_grass_3 99 130 88
|
||||
default:mese 222 222 0
|
||||
default:mese_post_light 134 105 59
|
||||
default:meselamp 213 215 143
|
||||
default:mossycobble 88 91 73
|
||||
default:obsidian 21 24 29
|
||||
default:obsidian_block 23 25 30
|
||||
default:obsidian_glass 20 23 27 64 16
|
||||
default:obsidianbrick 23 25 29
|
||||
default:papyrus 97 134 38
|
||||
default:permafrost 71 66 61
|
||||
default:permafrost_with_moss 108 150 51
|
||||
default:permafrost_with_stones 71 66 61
|
||||
default:pine_bush_needles 16 50 19
|
||||
default:pine_bush_sapling 58 51 40
|
||||
default:pine_bush_stem 73 62 53
|
||||
default:pine_needles 16 50 19
|
||||
default:pine_sapling 41 48 26
|
||||
default:pine_tree 191 165 132
|
||||
default:pine_wood 221 185 130
|
||||
default:river_water_flowing 39 66 106 128 224
|
||||
default:river_water_source 39 66 106 128 224
|
||||
default:sand 214 207 158
|
||||
default:sandstone 197 193 143
|
||||
default:sandstone_block 195 190 141
|
||||
default:sandstonebrick 193 189 140
|
||||
default:sapling 65 59 40
|
||||
default:sign_wall_steel 144 144 144
|
||||
default:sign_wall_wood 145 101 64
|
||||
default:sand_with_kelp 214 207 158
|
||||
default:sandstone 198 193 143
|
||||
default:sandstone_block 195 191 142
|
||||
default:sandstonebrick 194 190 141
|
||||
default:sapling 67 63 41
|
||||
default:sign_wall_steel 147 147 147
|
||||
default:sign_wall_wood 148 103 66
|
||||
default:silver_sand 193 191 179
|
||||
default:silver_sandstone 195 192 181
|
||||
default:silver_sandstone_block 192 190 179
|
||||
default:silver_sandstone_brick 190 188 178
|
||||
default:snow 224 225 238
|
||||
default:snowblock 224 225 238
|
||||
default:steelblock 194 194 194
|
||||
default:silver_sandstone_block 192 190 180
|
||||
default:silver_sandstone_brick 191 189 179
|
||||
default:snow 225 225 238
|
||||
default:snowblock 225 225 238
|
||||
default:steelblock 195 195 195
|
||||
default:stone 97 94 93
|
||||
default:stone_block 99 96 95
|
||||
default:stone_block 100 97 96
|
||||
default:stone_with_coal 97 94 93
|
||||
default:stone_with_copper 97 94 93
|
||||
default:stone_with_diamond 97 94 93
|
||||
@ -129,188 +161,281 @@ default:stone_with_gold 97 94 93
|
||||
default:stone_with_iron 97 94 93
|
||||
default:stone_with_mese 97 94 93
|
||||
default:stone_with_tin 97 94 93
|
||||
default:stonebrick 99 96 95
|
||||
default:tinblock 149 149 149
|
||||
default:torch 120 98 67
|
||||
default:torch_ceiling 120 98 67
|
||||
default:torch_wall 120 98 67
|
||||
default:tree 164 131 88
|
||||
default:stonebrick 102 99 98
|
||||
default:tinblock 150 150 150
|
||||
default:torch 141 123 93
|
||||
default:torch_ceiling 141 123 93
|
||||
default:torch_wall 141 123 93
|
||||
default:tree 179 145 99
|
||||
default:water_flowing 39 66 106 128 224
|
||||
default:water_source 39 66 106 128 224
|
||||
default:wood 128 99 55
|
||||
default:wood 131 102 57
|
||||
|
||||
# doors
|
||||
doors:door_glass_a 184 184 216 64 16
|
||||
doors:door_glass_b 184 184 216 64 16
|
||||
doors:door_obsidian_glass_a 27 28 29 64 16
|
||||
doors:door_obsidian_glass_b 27 28 29 64 16
|
||||
doors:door_steel_a 201 201 201
|
||||
doors:door_steel_b 201 201 201
|
||||
doors:door_wood_a 87 67 35
|
||||
doors:door_wood_b 87 67 35
|
||||
doors:gate_acacia_wood_closed 146 60 37
|
||||
doors:gate_acacia_wood_open 146 60 37
|
||||
doors:gate_aspen_wood_closed 209 198 169
|
||||
doors:gate_aspen_wood_open 209 198 169
|
||||
doors:gate_junglewood_closed 54 37 11
|
||||
doors:gate_junglewood_open 54 37 11
|
||||
doors:gate_pine_wood_closed 221 184 128
|
||||
doors:gate_pine_wood_open 221 184 128
|
||||
doors:gate_wood_closed 128 99 55
|
||||
doors:gate_wood_open 128 99 55
|
||||
doors:hidden 0 0 0
|
||||
doors:trapdoor 128 99 50
|
||||
doors:trapdoor_open 225 217 206
|
||||
doors:trapdoor_steel 199 199 199
|
||||
doors:trapdoor_steel_open 206 206 206
|
||||
doors:door_glass_a 245 245 245 64 16
|
||||
doors:door_glass_b 245 245 245 64 16
|
||||
doors:door_obsidian_glass_a 48 49 50 64 16
|
||||
doors:door_obsidian_glass_b 48 49 50 64 16
|
||||
doors:door_steel_a 203 203 203
|
||||
doors:door_steel_b 203 203 203
|
||||
doors:door_wood_a 89 68 37
|
||||
doors:door_wood_b 89 68 37
|
||||
doors:gate_acacia_wood_closed 150 61 39
|
||||
doors:gate_acacia_wood_open 150 61 39
|
||||
doors:gate_aspen_wood_closed 210 199 170
|
||||
doors:gate_aspen_wood_open 210 199 170
|
||||
doors:gate_junglewood_closed 56 39 14
|
||||
doors:gate_junglewood_open 56 39 14
|
||||
doors:gate_pine_wood_closed 221 185 130
|
||||
doors:gate_pine_wood_open 221 185 130
|
||||
doors:gate_wood_closed 131 102 57
|
||||
doors:gate_wood_open 131 102 57
|
||||
doors:trapdoor 130 100 51
|
||||
doors:trapdoor_open 68 53 30
|
||||
doors:trapdoor_steel 200 200 200
|
||||
doors:trapdoor_steel_open 97 97 97
|
||||
|
||||
# farming
|
||||
farming:cotton_1 88 116 39
|
||||
farming:cotton_2 87 116 38
|
||||
farming:cotton_3 97 120 41
|
||||
farming:cotton_4 106 113 47
|
||||
farming:cotton_5 114 104 53
|
||||
farming:cotton_6 119 94 59
|
||||
farming:cotton_7 92 69 37
|
||||
farming:cotton_8 110 91 61
|
||||
farming:desert_sand_soil 159 131 70
|
||||
farming:desert_sand_soil_wet 119 98 52
|
||||
farming:seed_cotton 90 85 57
|
||||
farming:seed_wheat 175 159 93
|
||||
farming:soil 95 64 39
|
||||
farming:soil_wet 95 64 39
|
||||
farming:straw 211 182 67
|
||||
farming:wheat_1 107 174 32
|
||||
farming:wheat_2 133 175 50
|
||||
farming:wheat_3 162 182 82
|
||||
farming:wheat_4 169 187 93
|
||||
farming:wheat_5 169 178 94
|
||||
farming:wheat_6 172 176 85
|
||||
farming:wheat_7 192 181 81
|
||||
farming:wheat_8 186 161 35
|
||||
farming:cotton_1 89 117 39
|
||||
farming:cotton_2 89 116 38
|
||||
farming:cotton_3 99 121 41
|
||||
farming:cotton_4 108 114 47
|
||||
farming:cotton_5 116 105 53
|
||||
farming:cotton_6 121 95 59
|
||||
farming:cotton_7 94 70 37
|
||||
farming:cotton_8 122 108 93
|
||||
farming:desert_sand_soil 161 132 72
|
||||
farming:desert_sand_soil_wet 120 99 53
|
||||
farming:dry_soil 178 136 90
|
||||
farming:dry_soil_wet 178 136 90
|
||||
farming:seed_cotton 92 87 60
|
||||
farming:seed_wheat 177 161 96
|
||||
farming:soil 97 67 43
|
||||
farming:soil_wet 97 67 43
|
||||
farming:straw 212 184 68
|
||||
farming:wheat_1 110 175 36
|
||||
farming:wheat_2 136 177 53
|
||||
farming:wheat_3 163 182 84
|
||||
farming:wheat_4 170 188 95
|
||||
farming:wheat_5 171 179 97
|
||||
farming:wheat_6 173 177 87
|
||||
farming:wheat_7 193 181 83
|
||||
farming:wheat_8 187 162 40
|
||||
|
||||
# fire
|
||||
fire:basic_flame 218 120 36
|
||||
fire:permanent_flame 218 120 36
|
||||
fire:basic_flame 223 136 44
|
||||
fire:permanent_flame 223 136 44
|
||||
|
||||
# fireflies
|
||||
fireflies:firefly_bottle 191 194 202
|
||||
|
||||
# flowers
|
||||
flowers:dandelion_white 178 176 140
|
||||
flowers:dandelion_yellow 178 148 24
|
||||
flowers:geranium 72 87 155
|
||||
flowers:mushroom_brown 106 79 72
|
||||
flowers:mushroom_red 192 85 85
|
||||
flowers:rose 118 48 24
|
||||
flowers:tulip 130 99 36
|
||||
flowers:viola 106 60 159
|
||||
flowers:waterlily 102 158 61
|
||||
flowers:chrysanthemum_green 118 152 44
|
||||
flowers:dandelion_white 199 191 176
|
||||
flowers:dandelion_yellow 212 167 31
|
||||
flowers:geranium 77 91 168
|
||||
flowers:mushroom_brown 109 84 78
|
||||
flowers:mushroom_red 195 102 102
|
||||
flowers:rose 130 68 33
|
||||
flowers:tulip 156 101 44
|
||||
flowers:tulip_black 78 120 72
|
||||
flowers:viola 115 69 184
|
||||
flowers:waterlily 107 160 68
|
||||
flowers:waterlily_waving 107 160 68
|
||||
|
||||
# stairs
|
||||
stairs:slab_acacia_wood 146 60 37
|
||||
stairs:slab_aspen_wood 209 198 169
|
||||
stairs:slab_brick 117 71 69
|
||||
stairs:slab_bronzeblock 185 110 15
|
||||
stairs:slab_cobble 88 84 82
|
||||
stairs:slab_copperblock 192 126 63
|
||||
stairs:slab_desert_cobble 146 95 76
|
||||
stairs:slab_acacia_wood 150 61 39
|
||||
stairs:slab_aspen_wood 210 199 170
|
||||
stairs:slab_brick 123 99 95
|
||||
stairs:slab_bronzeblock 186 111 15
|
||||
stairs:slab_cobble 89 86 84
|
||||
stairs:slab_copperblock 193 126 65
|
||||
stairs:slab_desert_cobble 110 67 50
|
||||
stairs:slab_desert_sandstone 195 152 92
|
||||
stairs:slab_desert_sandstone_block 192 151 94
|
||||
stairs:slab_desert_sandstone_brick 191 151 94
|
||||
stairs:slab_desert_stone 129 79 60
|
||||
stairs:slab_desert_stone_block 130 79 60
|
||||
stairs:slab_desert_stonebrick 129 79 60
|
||||
stairs:slab_goldblock 230 201 29
|
||||
stairs:slab_ice 167 206 247
|
||||
stairs:slab_junglewood 54 37 11
|
||||
stairs:slab_mossycobble 86 90 68
|
||||
stairs:slab_obsidian 19 21 24
|
||||
stairs:slab_obsidian_block 20 22 25
|
||||
stairs:slab_obsidianbrick 20 22 24
|
||||
stairs:slab_pine_wood 221 184 128
|
||||
stairs:slab_sandstone 197 193 143
|
||||
stairs:slab_sandstone_block 195 190 141
|
||||
stairs:slab_sandstonebrick 193 189 140
|
||||
stairs:slab_desert_sandstone_block 193 152 94
|
||||
stairs:slab_desert_sandstone_brick 191 151 95
|
||||
stairs:slab_desert_stone 130 79 61
|
||||
stairs:slab_desert_stone_block 131 80 61
|
||||
stairs:slab_desert_stonebrick 131 80 61
|
||||
stairs:slab_glass 247 247 247
|
||||
stairs:slab_goldblock 231 203 35
|
||||
stairs:slab_ice 168 206 247
|
||||
stairs:slab_junglewood 56 39 14
|
||||
stairs:slab_mossycobble 88 91 73
|
||||
stairs:slab_obsidian 21 24 29
|
||||
stairs:slab_obsidian_block 23 25 30
|
||||
stairs:slab_obsidian_glass 20 23 27
|
||||
stairs:slab_obsidianbrick 23 25 29
|
||||
stairs:slab_pine_wood 221 185 130
|
||||
stairs:slab_sandstone 198 193 143
|
||||
stairs:slab_sandstone_block 195 191 142
|
||||
stairs:slab_sandstonebrick 194 190 141
|
||||
stairs:slab_silver_sandstone 195 192 181
|
||||
stairs:slab_silver_sandstone_block 192 190 179
|
||||
stairs:slab_silver_sandstone_brick 190 188 178
|
||||
stairs:slab_snowblock 224 225 238
|
||||
stairs:slab_steelblock 194 194 194
|
||||
stairs:slab_silver_sandstone_block 192 190 180
|
||||
stairs:slab_silver_sandstone_brick 191 189 179
|
||||
stairs:slab_snowblock 225 225 238
|
||||
stairs:slab_steelblock 195 195 195
|
||||
stairs:slab_stone 97 94 93
|
||||
stairs:slab_stone_block 99 96 95
|
||||
stairs:slab_stonebrick 99 96 95
|
||||
stairs:slab_straw 211 182 67
|
||||
stairs:slab_wood 128 99 55
|
||||
stairs:stair_acacia_wood 146 60 37
|
||||
stairs:stair_aspen_wood 209 198 169
|
||||
stairs:stair_brick 117 71 69
|
||||
stairs:stair_bronzeblock 185 110 15
|
||||
stairs:stair_cobble 88 84 82
|
||||
stairs:stair_copperblock 192 126 63
|
||||
stairs:stair_desert_cobble 146 95 76
|
||||
stairs:slab_stone_block 100 97 96
|
||||
stairs:slab_stonebrick 102 99 98
|
||||
stairs:slab_straw 212 184 68
|
||||
stairs:slab_tinblock 150 150 150
|
||||
stairs:slab_wood 131 102 57
|
||||
stairs:stair_acacia_wood 150 61 39
|
||||
stairs:stair_aspen_wood 210 199 170
|
||||
stairs:stair_brick 123 99 95
|
||||
stairs:stair_bronzeblock 186 111 15
|
||||
stairs:stair_cobble 89 86 84
|
||||
stairs:stair_copperblock 193 126 65
|
||||
stairs:stair_desert_cobble 110 67 50
|
||||
stairs:stair_desert_sandstone 195 152 92
|
||||
stairs:stair_desert_sandstone_block 192 151 94
|
||||
stairs:stair_desert_sandstone_brick 191 151 94
|
||||
stairs:stair_desert_stone 129 79 60
|
||||
stairs:stair_desert_stone_block 130 79 60
|
||||
stairs:stair_desert_stonebrick 129 79 60
|
||||
stairs:stair_goldblock 230 201 29
|
||||
stairs:stair_ice 167 206 247
|
||||
stairs:stair_junglewood 54 37 11
|
||||
stairs:stair_mossycobble 86 90 68
|
||||
stairs:stair_obsidian 19 21 24
|
||||
stairs:stair_obsidian_block 20 22 25
|
||||
stairs:stair_obsidianbrick 20 22 24
|
||||
stairs:stair_pine_wood 221 184 128
|
||||
stairs:stair_sandstone 197 193 143
|
||||
stairs:stair_sandstone_block 195 190 141
|
||||
stairs:stair_sandstonebrick 193 189 140
|
||||
stairs:stair_desert_sandstone_block 193 152 94
|
||||
stairs:stair_desert_sandstone_brick 191 151 95
|
||||
stairs:stair_desert_stone 130 79 61
|
||||
stairs:stair_desert_stone_block 131 80 61
|
||||
stairs:stair_desert_stonebrick 131 80 61
|
||||
stairs:stair_glass 249 249 249
|
||||
stairs:stair_goldblock 231 203 35
|
||||
stairs:stair_ice 168 206 247
|
||||
stairs:stair_inner_acacia_wood 150 61 39
|
||||
stairs:stair_inner_aspen_wood 210 199 170
|
||||
stairs:stair_inner_brick 123 99 95
|
||||
stairs:stair_inner_bronzeblock 186 111 15
|
||||
stairs:stair_inner_cobble 89 86 84
|
||||
stairs:stair_inner_copperblock 193 126 65
|
||||
stairs:stair_inner_desert_cobble 110 67 50
|
||||
stairs:stair_inner_desert_sandstone 195 152 92
|
||||
stairs:stair_inner_desert_sandstone_block 193 152 94
|
||||
stairs:stair_inner_desert_sandstone_brick 191 151 95
|
||||
stairs:stair_inner_desert_stone 130 79 61
|
||||
stairs:stair_inner_desert_stone_block 131 80 61
|
||||
stairs:stair_inner_desert_stonebrick 131 80 61
|
||||
stairs:stair_inner_glass 250 250 250
|
||||
stairs:stair_inner_goldblock 231 203 35
|
||||
stairs:stair_inner_ice 168 206 247
|
||||
stairs:stair_inner_junglewood 56 39 14
|
||||
stairs:stair_inner_mossycobble 88 91 73
|
||||
stairs:stair_inner_obsidian 21 24 29
|
||||
stairs:stair_inner_obsidian_block 23 25 30
|
||||
stairs:stair_inner_obsidian_glass 20 22 27
|
||||
stairs:stair_inner_obsidianbrick 23 25 29
|
||||
stairs:stair_inner_pine_wood 221 185 130
|
||||
stairs:stair_inner_sandstone 198 193 143
|
||||
stairs:stair_inner_sandstone_block 195 191 142
|
||||
stairs:stair_inner_sandstonebrick 194 190 141
|
||||
stairs:stair_inner_silver_sandstone 195 192 181
|
||||
stairs:stair_inner_silver_sandstone_block 192 190 180
|
||||
stairs:stair_inner_silver_sandstone_brick 191 189 179
|
||||
stairs:stair_inner_snowblock 225 225 238
|
||||
stairs:stair_inner_steelblock 195 195 195
|
||||
stairs:stair_inner_stone 97 94 93
|
||||
stairs:stair_inner_stone_block 100 97 96
|
||||
stairs:stair_inner_stonebrick 102 99 98
|
||||
stairs:stair_inner_straw 212 184 68
|
||||
stairs:stair_inner_tinblock 150 150 150
|
||||
stairs:stair_inner_wood 131 102 57
|
||||
stairs:stair_junglewood 56 39 14
|
||||
stairs:stair_mossycobble 88 91 73
|
||||
stairs:stair_obsidian 21 24 29
|
||||
stairs:stair_obsidian_block 23 25 30
|
||||
stairs:stair_obsidian_glass 20 22 27
|
||||
stairs:stair_obsidianbrick 23 25 29
|
||||
stairs:stair_outer_acacia_wood 150 61 39
|
||||
stairs:stair_outer_aspen_wood 210 199 170
|
||||
stairs:stair_outer_brick 123 99 95
|
||||
stairs:stair_outer_bronzeblock 186 111 15
|
||||
stairs:stair_outer_cobble 89 86 84
|
||||
stairs:stair_outer_copperblock 193 126 65
|
||||
stairs:stair_outer_desert_cobble 110 67 50
|
||||
stairs:stair_outer_desert_sandstone 195 152 92
|
||||
stairs:stair_outer_desert_sandstone_block 193 152 94
|
||||
stairs:stair_outer_desert_sandstone_brick 191 151 95
|
||||
stairs:stair_outer_desert_stone 130 79 61
|
||||
stairs:stair_outer_desert_stone_block 131 80 61
|
||||
stairs:stair_outer_desert_stonebrick 131 80 61
|
||||
stairs:stair_outer_glass 250 250 250
|
||||
stairs:stair_outer_goldblock 231 203 35
|
||||
stairs:stair_outer_ice 168 206 247
|
||||
stairs:stair_outer_junglewood 56 39 14
|
||||
stairs:stair_outer_mossycobble 88 91 73
|
||||
stairs:stair_outer_obsidian 21 24 29
|
||||
stairs:stair_outer_obsidian_block 23 25 30
|
||||
stairs:stair_outer_obsidian_glass 20 22 27
|
||||
stairs:stair_outer_obsidianbrick 23 25 29
|
||||
stairs:stair_outer_pine_wood 221 185 130
|
||||
stairs:stair_outer_sandstone 198 193 143
|
||||
stairs:stair_outer_sandstone_block 195 191 142
|
||||
stairs:stair_outer_sandstonebrick 194 190 141
|
||||
stairs:stair_outer_silver_sandstone 195 192 181
|
||||
stairs:stair_outer_silver_sandstone_block 192 190 180
|
||||
stairs:stair_outer_silver_sandstone_brick 191 189 179
|
||||
stairs:stair_outer_snowblock 225 225 238
|
||||
stairs:stair_outer_steelblock 195 195 195
|
||||
stairs:stair_outer_stone 97 94 93
|
||||
stairs:stair_outer_stone_block 100 97 96
|
||||
stairs:stair_outer_stonebrick 102 99 98
|
||||
stairs:stair_outer_straw 212 184 68
|
||||
stairs:stair_outer_tinblock 150 150 150
|
||||
stairs:stair_outer_wood 131 102 57
|
||||
stairs:stair_pine_wood 221 185 130
|
||||
stairs:stair_sandstone 198 193 143
|
||||
stairs:stair_sandstone_block 195 191 142
|
||||
stairs:stair_sandstonebrick 194 190 141
|
||||
stairs:stair_silver_sandstone 195 192 181
|
||||
stairs:stair_silver_sandstone_block 192 190 179
|
||||
stairs:stair_silver_sandstone_brick 190 188 178
|
||||
stairs:stair_snowblock 224 225 238
|
||||
stairs:stair_steelblock 194 194 194
|
||||
stairs:stair_silver_sandstone_block 192 190 180
|
||||
stairs:stair_silver_sandstone_brick 191 189 179
|
||||
stairs:stair_snowblock 225 225 238
|
||||
stairs:stair_steelblock 195 195 195
|
||||
stairs:stair_stone 97 94 93
|
||||
stairs:stair_stone_block 99 96 95
|
||||
stairs:stair_stonebrick 99 96 95
|
||||
stairs:stair_straw 211 182 67
|
||||
stairs:stair_wood 128 99 55
|
||||
stairs:stair_stone_block 100 97 96
|
||||
stairs:stair_stonebrick 102 99 98
|
||||
stairs:stair_straw 212 184 68
|
||||
stairs:stair_tinblock 150 150 150
|
||||
stairs:stair_wood 131 102 57
|
||||
|
||||
# tnt
|
||||
tnt:gunpowder 6 6 6
|
||||
tnt:gunpowder_burning 112 103 2
|
||||
tnt:tnt 181 0 0
|
||||
tnt:tnt_burning 190 8 0
|
||||
tnt:gunpowder 12 12 12
|
||||
tnt:gunpowder_burning 156 143 7
|
||||
tnt:tnt 196 0 0
|
||||
tnt:tnt_burning 201 41 0
|
||||
|
||||
# vessels
|
||||
vessels:drinking_glass 206 214 228
|
||||
vessels:glass_bottle 188 190 201
|
||||
vessels:shelf 128 99 55
|
||||
vessels:steel_bottle 193 192 191
|
||||
vessels:drinking_glass 207 214 228
|
||||
vessels:glass_bottle 189 192 204
|
||||
vessels:shelf 131 102 57
|
||||
vessels:steel_bottle 194 193 193
|
||||
|
||||
# walls
|
||||
walls:cobble 88 84 82
|
||||
walls:desertcobble 146 95 76
|
||||
walls:mossycobble 86 90 68
|
||||
walls:cobble 89 86 84
|
||||
walls:desertcobble 110 67 50
|
||||
walls:mossycobble 88 91 73
|
||||
|
||||
# wool
|
||||
wool:black 29 29 29
|
||||
wool:blue 0 72 145
|
||||
wool:brown 86 42 0
|
||||
wool:cyan 0 130 139
|
||||
wool:dark_green 32 102 0
|
||||
wool:dark_grey 59 59 59
|
||||
wool:green 92 216 28
|
||||
wool:grey 131 131 131
|
||||
wool:magenta 200 3 109
|
||||
wool:orange 213 81 21
|
||||
wool:pink 255 131 131
|
||||
wool:red 168 17 17
|
||||
wool:violet 92 2 169
|
||||
wool:black 30 30 30
|
||||
wool:blue 0 73 146
|
||||
wool:brown 88 44 0
|
||||
wool:cyan 0 132 140
|
||||
wool:dark_green 33 103 0
|
||||
wool:dark_grey 60 60 60
|
||||
wool:green 93 218 28
|
||||
wool:grey 133 133 133
|
||||
wool:magenta 201 3 112
|
||||
wool:orange 214 83 22
|
||||
wool:pink 255 133 133
|
||||
wool:red 170 18 18
|
||||
wool:violet 93 5 169
|
||||
wool:white 220 220 220
|
||||
wool:yellow 254 225 15
|
||||
wool:yellow 254 226 16
|
||||
|
||||
# xpanes
|
||||
xpanes:bar 194 194 227 64 16
|
||||
xpanes:bar_flat 194 194 227 64 16
|
||||
xpanes:pane 194 194 227 64 16
|
||||
xpanes:pane_flat 194 194 227 64 16
|
||||
xpanes:bar 114 114 114 64 16
|
||||
xpanes:bar_flat 114 114 114 64 16
|
||||
xpanes:door_steel_bar_a 133 133 133 64 16
|
||||
xpanes:door_steel_bar_b 133 133 133 64 16
|
||||
xpanes:obsidian_pane 16 17 18 64 16
|
||||
xpanes:obsidian_pane_flat 16 17 18 64 16
|
||||
xpanes:pane 249 249 249 64 16
|
||||
xpanes:pane_flat 249 249 249 64 16
|
||||
xpanes:trapdoor_steel_bar 127 127 127 64 16
|
||||
xpanes:trapdoor_steel_bar_open 77 77 77 64 16
|
||||
|
||||
|
@ -11,7 +11,6 @@ static inline int64_t stoi64(const std::string &s)
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
static inline std::string i64tos(int64_t i)
|
||||
{
|
||||
std::ostringstream os;
|
||||
@ -19,6 +18,7 @@ static inline std::string i64tos(int64_t i)
|
||||
return os.str();
|
||||
}
|
||||
|
||||
|
||||
DBLevelDB::DBLevelDB(const std::string &mapdir)
|
||||
{
|
||||
leveldb::Options options;
|
||||
@ -28,6 +28,9 @@ DBLevelDB::DBLevelDB(const std::string &mapdir)
|
||||
throw std::runtime_error(std::string("Failed to open Database: ") + status.ToString());
|
||||
}
|
||||
|
||||
/* LevelDB is a dumb key-value store, so the only optimization we can do
|
||||
* is to cache the block positions that exist in the db.
|
||||
*/
|
||||
loadPosCache();
|
||||
}
|
||||
|
||||
@ -38,9 +41,21 @@ DBLevelDB::~DBLevelDB()
|
||||
}
|
||||
|
||||
|
||||
std::vector<BlockPos> DBLevelDB::getBlockPos()
|
||||
std::vector<BlockPos> DBLevelDB::getBlockPos(BlockPos min, BlockPos max)
|
||||
{
|
||||
return posCache;
|
||||
std::vector<BlockPos> res;
|
||||
for (const auto &it : posCache) {
|
||||
if (it.first < min.z || it.first >= max.z)
|
||||
continue;
|
||||
for (auto pos2 : it.second) {
|
||||
if (pos2.first < min.x || pos2.first >= max.x)
|
||||
continue;
|
||||
if (pos2.second < min.y || pos2.second >= max.y)
|
||||
continue;
|
||||
res.emplace_back(pos2.first, pos2.second, it.first);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
@ -49,26 +64,51 @@ void DBLevelDB::loadPosCache()
|
||||
leveldb::Iterator * it = db->NewIterator(leveldb::ReadOptions());
|
||||
for (it->SeekToFirst(); it->Valid(); it->Next()) {
|
||||
int64_t posHash = stoi64(it->key().ToString());
|
||||
posCache.push_back(decodeBlockPos(posHash));
|
||||
BlockPos pos = decodeBlockPos(posHash);
|
||||
|
||||
posCache[pos.z].emplace_back(pos.x, pos.y);
|
||||
}
|
||||
delete it;
|
||||
}
|
||||
|
||||
|
||||
void DBLevelDB::getBlocksOnZ(std::map<int16_t, BlockList> &blocks, int16_t zPos)
|
||||
void DBLevelDB::getBlocksOnXZ(BlockList &blocks, int16_t x, int16_t z,
|
||||
int16_t min_y, int16_t max_y)
|
||||
{
|
||||
std::string datastr;
|
||||
leveldb::Status status;
|
||||
|
||||
for (std::vector<BlockPos>::iterator it = posCache.begin(); it != posCache.end(); ++it) {
|
||||
if (it->z != zPos) {
|
||||
auto it = posCache.find(z);
|
||||
if (it == posCache.cend())
|
||||
return;
|
||||
for (auto pos2 : it->second) {
|
||||
if (pos2.first != x)
|
||||
continue;
|
||||
}
|
||||
status = db->Get(leveldb::ReadOptions(), i64tos(encodeBlockPos(*it)), &datastr);
|
||||
if (pos2.second < min_y || pos2.second >= max_y)
|
||||
continue;
|
||||
|
||||
BlockPos pos(x, pos2.second, z);
|
||||
status = db->Get(leveldb::ReadOptions(), i64tos(encodeBlockPos(pos)), &datastr);
|
||||
if (status.ok()) {
|
||||
Block b(*it, ustring((const unsigned char *) datastr.data(), datastr.size()));
|
||||
blocks[b.first.x].push_back(b);
|
||||
blocks.emplace_back(
|
||||
pos, ustring((unsigned char *) datastr.data(), datastr.size())
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DBLevelDB::getBlocksByPos(BlockList &blocks,
|
||||
const std::vector<BlockPos> &positions)
|
||||
{
|
||||
std::string datastr;
|
||||
leveldb::Status status;
|
||||
|
||||
for (auto pos : positions) {
|
||||
status = db->Get(leveldb::ReadOptions(), i64tos(encodeBlockPos(pos)), &datastr);
|
||||
if (status.ok()) {
|
||||
blocks.emplace_back(
|
||||
pos, ustring((unsigned char *) datastr.data(), datastr.size())
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
21
db-leveldb.h
21
db-leveldb.h
@ -1,21 +0,0 @@
|
||||
#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
|
@ -14,7 +14,7 @@ DBPostgreSQL::DBPostgreSQL(const std::string &mapdir)
|
||||
std::ifstream ifs((mapdir + "/world.mt").c_str());
|
||||
if(!ifs.good())
|
||||
throw std::runtime_error("Failed to read world.mt");
|
||||
std::string const connect_string = get_setting("pgsql_connection", ifs);
|
||||
std::string connect_string = read_setting("pgsql_connection", ifs);
|
||||
ifs.close();
|
||||
db = PQconnectdb(connect_string.c_str());
|
||||
|
||||
@ -27,11 +27,21 @@ DBPostgreSQL::DBPostgreSQL(const std::string &mapdir)
|
||||
|
||||
prepareStatement(
|
||||
"get_block_pos",
|
||||
"SELECT posX, posY, posZ FROM blocks"
|
||||
"SELECT posX::int4, posY::int4, posZ::int4 FROM blocks WHERE"
|
||||
" (posX BETWEEN $1::int4 AND $2::int4) AND"
|
||||
" (posY BETWEEN $3::int4 AND $4::int4) AND"
|
||||
" (posZ BETWEEN $5::int4 AND $6::int4)"
|
||||
);
|
||||
prepareStatement(
|
||||
"get_blocks_z",
|
||||
"SELECT posX, posY, data FROM blocks WHERE posZ = $1::int4"
|
||||
"get_blocks",
|
||||
"SELECT posY::int4, data FROM blocks WHERE"
|
||||
" posX = $1::int4 AND posZ = $2::int4"
|
||||
" AND (posY BETWEEN $3::int4 AND $4::int4)"
|
||||
);
|
||||
prepareStatement(
|
||||
"get_block_exact",
|
||||
"SELECT data FROM blocks WHERE"
|
||||
" posX = $1::int4 AND posY = $2::int4 AND posZ = $3::int4"
|
||||
);
|
||||
|
||||
checkResults(PQexec(db, "START TRANSACTION;"));
|
||||
@ -43,25 +53,38 @@ DBPostgreSQL::~DBPostgreSQL()
|
||||
{
|
||||
try {
|
||||
checkResults(PQexec(db, "COMMIT;"));
|
||||
} catch (std::exception& caught) {
|
||||
} catch (const std::exception& caught) {
|
||||
std::cerr << "could not finalize: " << caught.what() << std::endl;
|
||||
}
|
||||
PQfinish(db);
|
||||
}
|
||||
|
||||
std::vector<BlockPos> DBPostgreSQL::getBlockPos()
|
||||
|
||||
std::vector<BlockPos> DBPostgreSQL::getBlockPos(BlockPos min, BlockPos max)
|
||||
{
|
||||
std::vector<BlockPos> positions;
|
||||
int32_t const x1 = htonl(min.x);
|
||||
int32_t const x2 = htonl(max.x - 1);
|
||||
int32_t const y1 = htonl(min.y);
|
||||
int32_t const y2 = htonl(max.y - 1);
|
||||
int32_t const z1 = htonl(min.z);
|
||||
int32_t const z2 = htonl(max.z - 1);
|
||||
|
||||
const void *args[] = { &x1, &x2, &y1, &y2, &z1, &z2 };
|
||||
const int argLen[] = { 4, 4, 4, 4, 4, 4 };
|
||||
const int argFmt[] = { 1, 1, 1, 1, 1, 1 };
|
||||
|
||||
PGresult *results = execPrepared(
|
||||
"get_block_pos", 0,
|
||||
NULL, NULL, NULL, false, false
|
||||
"get_block_pos", ARRLEN(args), args,
|
||||
argLen, argFmt, false
|
||||
);
|
||||
|
||||
int numrows = PQntuples(results);
|
||||
|
||||
std::vector<BlockPos> positions;
|
||||
positions.reserve(numrows);
|
||||
|
||||
for (int row = 0; row < numrows; ++row)
|
||||
positions.push_back(pg_to_blockpos(results, row, 0));
|
||||
positions.emplace_back(pg_to_blockpos(results, row, 0));
|
||||
|
||||
PQclear(results);
|
||||
|
||||
@ -69,16 +92,20 @@ std::vector<BlockPos> DBPostgreSQL::getBlockPos()
|
||||
}
|
||||
|
||||
|
||||
void DBPostgreSQL::getBlocksOnZ(std::map<int16_t, BlockList> &blocks, int16_t zPos)
|
||||
void DBPostgreSQL::getBlocksOnXZ(BlockList &blocks, int16_t xPos, int16_t zPos,
|
||||
int16_t min_y, int16_t max_y)
|
||||
{
|
||||
int32_t const x = htonl(xPos);
|
||||
int32_t const z = htonl(zPos);
|
||||
int32_t const y1 = htonl(min_y);
|
||||
int32_t const y2 = htonl(max_y - 1);
|
||||
|
||||
const void *args[] = { &z };
|
||||
const int argLen[] = { sizeof(z) };
|
||||
const int argFmt[] = { 1 };
|
||||
const void *args[] = { &x, &z, &y1, &y2 };
|
||||
const int argLen[] = { 4, 4, 4, 4 };
|
||||
const int argFmt[] = { 1, 1, 1, 1 };
|
||||
|
||||
PGresult *results = execPrepared(
|
||||
"get_blocks_z", ARRLEN(args), args,
|
||||
"get_blocks", ARRLEN(args), args,
|
||||
argLen, argFmt, false
|
||||
);
|
||||
|
||||
@ -86,24 +113,60 @@ void DBPostgreSQL::getBlocksOnZ(std::map<int16_t, BlockList> &blocks, int16_t zP
|
||||
|
||||
for (int row = 0; row < numrows; ++row) {
|
||||
BlockPos position;
|
||||
position.x = pg_binary_to_int(results, row, 0);
|
||||
position.y = pg_binary_to_int(results, row, 1);
|
||||
position.x = xPos;
|
||||
position.y = pg_binary_to_int(results, row, 0);
|
||||
position.z = zPos;
|
||||
Block const b(
|
||||
blocks.emplace_back(
|
||||
position,
|
||||
ustring(
|
||||
reinterpret_cast<unsigned char*>(
|
||||
PQgetvalue(results, row, 2)
|
||||
PQgetvalue(results, row, 1)
|
||||
),
|
||||
PQgetlength(results, row, 2)
|
||||
PQgetlength(results, row, 1)
|
||||
)
|
||||
);
|
||||
blocks[position.x].push_back(b);
|
||||
}
|
||||
|
||||
PQclear(results);
|
||||
}
|
||||
|
||||
|
||||
void DBPostgreSQL::getBlocksByPos(BlockList &blocks,
|
||||
const std::vector<BlockPos> &positions)
|
||||
{
|
||||
int32_t x, y, z;
|
||||
|
||||
const void *args[] = { &x, &y, &z };
|
||||
const int argLen[] = { 4, 4, 4 };
|
||||
const int argFmt[] = { 1, 1, 1 };
|
||||
|
||||
for (auto pos : positions) {
|
||||
x = htonl(pos.x);
|
||||
y = htonl(pos.y);
|
||||
z = htonl(pos.z);
|
||||
|
||||
PGresult *results = execPrepared(
|
||||
"get_block_exact", ARRLEN(args), args,
|
||||
argLen, argFmt, false
|
||||
);
|
||||
|
||||
if (PQntuples(results) > 0) {
|
||||
blocks.emplace_back(
|
||||
pos,
|
||||
ustring(
|
||||
reinterpret_cast<unsigned char*>(
|
||||
PQgetvalue(results, 0, 0)
|
||||
),
|
||||
PQgetlength(results, 0, 0)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
PQclear(results);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PGresult *DBPostgreSQL::checkResults(PGresult *res, bool clear)
|
||||
{
|
||||
ExecStatusType statusType = PQresultStatus(res);
|
||||
@ -138,20 +201,15 @@ PGresult *DBPostgreSQL::execPrepared(
|
||||
const char *stmtName, const int paramsNumber,
|
||||
const void **params,
|
||||
const int *paramsLengths, const int *paramsFormats,
|
||||
bool clear, bool nobinary
|
||||
bool clear
|
||||
)
|
||||
{
|
||||
return checkResults(PQexecPrepared(db, stmtName, paramsNumber,
|
||||
(const char* const*) params, paramsLengths, paramsFormats,
|
||||
nobinary ? 1 : 0), clear
|
||||
1 /* binary output */), clear
|
||||
);
|
||||
}
|
||||
|
||||
int DBPostgreSQL::pg_to_int(PGresult *res, int row, int col)
|
||||
{
|
||||
return atoi(PQgetvalue(res, row, col));
|
||||
}
|
||||
|
||||
int DBPostgreSQL::pg_binary_to_int(PGresult *res, int row, int col)
|
||||
{
|
||||
int32_t* raw = reinterpret_cast<int32_t*>(PQgetvalue(res, row, col));
|
||||
@ -161,8 +219,8 @@ int DBPostgreSQL::pg_binary_to_int(PGresult *res, int row, int col)
|
||||
BlockPos DBPostgreSQL::pg_to_blockpos(PGresult *res, int row, int col)
|
||||
{
|
||||
BlockPos result;
|
||||
result.x = pg_to_int(res, row, col);
|
||||
result.y = pg_to_int(res, row, col + 1);
|
||||
result.z = pg_to_int(res, row, col + 2);
|
||||
result.x = pg_binary_to_int(res, row, col);
|
||||
result.y = pg_binary_to_int(res, row, col + 1);
|
||||
result.z = pg_binary_to_int(res, row, col + 2);
|
||||
return result;
|
||||
}
|
||||
|
120
db-redis.cpp
120
db-redis.cpp
@ -28,40 +28,32 @@ static inline std::string i64tos(int64_t i)
|
||||
return os.str();
|
||||
}
|
||||
|
||||
std::string get_setting_default(std::string name, std::istream &is, const std::string def)
|
||||
{
|
||||
try {
|
||||
return get_setting(name, is);
|
||||
} catch(std::runtime_error e) {
|
||||
return def;
|
||||
}
|
||||
}
|
||||
|
||||
DBRedis::DBRedis(const std::string &mapdir)
|
||||
{
|
||||
std::ifstream ifs((mapdir + "/world.mt").c_str());
|
||||
if(!ifs.good())
|
||||
throw std::runtime_error("Failed to read world.mt");
|
||||
std::string tmp;
|
||||
try {
|
||||
tmp = get_setting("redis_address", ifs);
|
||||
ifs.seekg(0);
|
||||
hash = get_setting("redis_hash", ifs);
|
||||
ifs.seekg(0);
|
||||
} catch(std::runtime_error e) {
|
||||
throw std::runtime_error("Set redis_address and redis_hash in world.mt to use the redis backend");
|
||||
}
|
||||
|
||||
tmp = read_setting("redis_address", ifs);
|
||||
ifs.seekg(0);
|
||||
hash = read_setting("redis_hash", ifs);
|
||||
ifs.seekg(0);
|
||||
|
||||
const char *addr = tmp.c_str();
|
||||
int port = stoi64(get_setting_default("redis_port", ifs, "6379"));
|
||||
ctx = redisConnect(addr, port);
|
||||
if(!ctx)
|
||||
int port = stoi64(read_setting_default("redis_port", ifs, "6379"));
|
||||
ctx = tmp.find('/') != std::string::npos ? redisConnectUnix(addr) : redisConnect(addr, port);
|
||||
if(!ctx) {
|
||||
throw std::runtime_error("Cannot allocate redis context");
|
||||
else if(ctx->err) {
|
||||
} else if(ctx->err) {
|
||||
std::string err = std::string("Connection error: ") + ctx->errstr;
|
||||
redisFree(ctx);
|
||||
throw std::runtime_error(err);
|
||||
}
|
||||
|
||||
/* Redis is just a key-value store, so the only optimization we can do
|
||||
* is to cache the block positions that exist in the db.
|
||||
*/
|
||||
loadPosCache();
|
||||
}
|
||||
|
||||
@ -72,13 +64,25 @@ DBRedis::~DBRedis()
|
||||
}
|
||||
|
||||
|
||||
std::vector<BlockPos> DBRedis::getBlockPos()
|
||||
std::vector<BlockPos> DBRedis::getBlockPos(BlockPos min, BlockPos max)
|
||||
{
|
||||
return posCache;
|
||||
std::vector<BlockPos> res;
|
||||
for (const auto &it : posCache) {
|
||||
if (it.first < min.z || it.first >= max.z)
|
||||
continue;
|
||||
for (auto pos2 : it.second) {
|
||||
if (pos2.first < min.x || pos2.first >= max.x)
|
||||
continue;
|
||||
if (pos2.second < min.y || pos2.second >= max.y)
|
||||
continue;
|
||||
res.emplace_back(pos2.first, pos2.second, it.first);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
std::string DBRedis::replyTypeStr(int type) {
|
||||
const char *DBRedis::replyTypeStr(int type) {
|
||||
switch(type) {
|
||||
case REDIS_REPLY_STATUS:
|
||||
return "REDIS_REPLY_STATUS";
|
||||
@ -109,14 +113,16 @@ void DBRedis::loadPosCache()
|
||||
for(size_t i = 0; i < reply->elements; i++) {
|
||||
if(reply->element[i]->type != REDIS_REPLY_STRING)
|
||||
REPLY_TYPE_ERR(reply->element[i], "HKEYS subreply");
|
||||
posCache.push_back(decodeBlockPos(stoi64(reply->element[i]->str)));
|
||||
BlockPos pos = decodeBlockPos(stoi64(reply->element[i]->str));
|
||||
posCache[pos.z].emplace_back(pos.x, pos.y);
|
||||
}
|
||||
|
||||
freeReplyObject(reply);
|
||||
}
|
||||
|
||||
|
||||
void DBRedis::HMGET(const std::vector<BlockPos> &positions, std::vector<ustring> *result)
|
||||
void DBRedis::HMGET(const std::vector<BlockPos> &positions,
|
||||
std::function<void(std::size_t, ustring)> result)
|
||||
{
|
||||
const char *argv[DB_REDIS_HMGET_NUMFIELDS + 2];
|
||||
argv[0] = "HMGET";
|
||||
@ -124,6 +130,7 @@ void DBRedis::HMGET(const std::vector<BlockPos> &positions, std::vector<ustring>
|
||||
|
||||
std::vector<BlockPos>::const_iterator position = positions.begin();
|
||||
std::size_t remaining = positions.size();
|
||||
std::size_t abs_i = 0;
|
||||
while (remaining > 0) {
|
||||
const std::size_t batch_size =
|
||||
(remaining > DB_REDIS_HMGET_NUMFIELDS) ? DB_REDIS_HMGET_NUMFIELDS : remaining;
|
||||
@ -141,50 +148,51 @@ void DBRedis::HMGET(const std::vector<BlockPos> &positions, std::vector<ustring>
|
||||
|
||||
if(!reply)
|
||||
throw std::runtime_error("Redis command HMGET failed");
|
||||
if (reply->type != REDIS_REPLY_ARRAY) {
|
||||
freeReplyObject(reply);
|
||||
REPLY_TYPE_ERR(reply, "HKEYS subreply");
|
||||
}
|
||||
if (reply->type != REDIS_REPLY_ARRAY)
|
||||
REPLY_TYPE_ERR(reply, "HMGET reply");
|
||||
if (reply->elements != batch_size) {
|
||||
freeReplyObject(reply);
|
||||
throw std::runtime_error("HMGET wrong number of elements");
|
||||
}
|
||||
for (std::size_t i = 0; i < batch_size; ++i) {
|
||||
for (std::size_t i = 0; i < reply->elements; ++i) {
|
||||
redisReply *subreply = reply->element[i];
|
||||
if(!subreply)
|
||||
throw std::runtime_error("Redis command HMGET failed");
|
||||
if (subreply->type != REDIS_REPLY_STRING) {
|
||||
freeReplyObject(reply);
|
||||
REPLY_TYPE_ERR(reply, "HKEYS subreply");
|
||||
}
|
||||
if (subreply->len == 0) {
|
||||
freeReplyObject(reply);
|
||||
if (subreply->type == REDIS_REPLY_NIL)
|
||||
continue;
|
||||
else if (subreply->type != REDIS_REPLY_STRING)
|
||||
REPLY_TYPE_ERR(subreply, "HMGET subreply");
|
||||
if (subreply->len == 0)
|
||||
throw std::runtime_error("HMGET empty string");
|
||||
}
|
||||
result->push_back(ustring((const unsigned char *) subreply->str, subreply->len));
|
||||
result(abs_i + i, ustring((const unsigned char *) subreply->str, subreply->len));
|
||||
}
|
||||
freeReplyObject(reply);
|
||||
abs_i += reply->elements;
|
||||
remaining -= batch_size;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DBRedis::getBlocksOnZ(std::map<int16_t, BlockList> &blocks, int16_t zPos)
|
||||
void DBRedis::getBlocksOnXZ(BlockList &blocks, int16_t x, int16_t z,
|
||||
int16_t min_y, int16_t max_y)
|
||||
{
|
||||
std::vector<BlockPos> z_positions;
|
||||
for (std::vector<BlockPos>::const_iterator it = posCache.begin(); it != posCache.end(); ++it) {
|
||||
if (it->z != zPos) {
|
||||
continue;
|
||||
}
|
||||
z_positions.push_back(*it);
|
||||
}
|
||||
std::vector<ustring> z_blocks;
|
||||
HMGET(z_positions, &z_blocks);
|
||||
auto it = posCache.find(z);
|
||||
if (it == posCache.cend())
|
||||
return;
|
||||
|
||||
std::vector<ustring>::const_iterator z_block = z_blocks.begin();
|
||||
for (std::vector<BlockPos>::const_iterator pos = z_positions.begin();
|
||||
pos != z_positions.end();
|
||||
++pos, ++z_block) {
|
||||
blocks[pos->x].push_back(Block(*pos, *z_block));
|
||||
std::vector<BlockPos> positions;
|
||||
for (auto pos2 : it->second) {
|
||||
if (pos2.first == x && pos2.second >= min_y && pos2.second < max_y)
|
||||
positions.emplace_back(x, pos2.second, z);
|
||||
}
|
||||
|
||||
getBlocksByPos(blocks, positions);
|
||||
}
|
||||
|
||||
|
||||
void DBRedis::getBlocksByPos(BlockList &blocks,
|
||||
const std::vector<BlockPos> &positions)
|
||||
{
|
||||
auto result = [&] (std::size_t i, ustring data) {
|
||||
blocks.emplace_back(positions[i], std::move(data));
|
||||
};
|
||||
HMGET(positions, result);
|
||||
}
|
||||
|
25
db-redis.h
25
db-redis.h
@ -1,25 +0,0 @@
|
||||
#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
|
154
db-sqlite3.cpp
154
db-sqlite3.cpp
@ -1,6 +1,8 @@
|
||||
#include <stdexcept>
|
||||
#include <unistd.h> // for usleep
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <time.h>
|
||||
#include "db-sqlite3.h"
|
||||
#include "types.h"
|
||||
|
||||
@ -11,7 +13,6 @@
|
||||
}
|
||||
#define SQLOK(f) SQLRES(f, SQLITE_OK)
|
||||
|
||||
|
||||
DBSQLite3::DBSQLite3(const std::string &mapdir)
|
||||
{
|
||||
int result;
|
||||
@ -24,9 +25,17 @@ DBSQLite3::DBSQLite3(const std::string &mapdir)
|
||||
"SELECT pos, data FROM blocks WHERE pos BETWEEN ? AND ?",
|
||||
-1, &stmt_get_blocks_z, NULL))
|
||||
|
||||
SQLOK(prepare_v2(db,
|
||||
"SELECT data FROM blocks WHERE pos = ?",
|
||||
-1, &stmt_get_block_exact, NULL))
|
||||
|
||||
SQLOK(prepare_v2(db,
|
||||
"SELECT pos FROM blocks",
|
||||
-1, &stmt_get_block_pos, NULL))
|
||||
|
||||
SQLOK(prepare_v2(db,
|
||||
"SELECT pos FROM blocks WHERE pos BETWEEN ? AND ?",
|
||||
-1, &stmt_get_block_pos_z, NULL))
|
||||
}
|
||||
|
||||
|
||||
@ -34,59 +43,154 @@ DBSQLite3::~DBSQLite3()
|
||||
{
|
||||
sqlite3_finalize(stmt_get_blocks_z);
|
||||
sqlite3_finalize(stmt_get_block_pos);
|
||||
sqlite3_finalize(stmt_get_block_pos_z);
|
||||
sqlite3_finalize(stmt_get_block_exact);
|
||||
|
||||
if (sqlite3_close(db) != SQLITE_OK) {
|
||||
std::cerr << "Error closing SQLite database." << std::endl;
|
||||
};
|
||||
}
|
||||
|
||||
std::vector<BlockPos> DBSQLite3::getBlockPos()
|
||||
|
||||
inline void DBSQLite3::getPosRange(int64_t &min, int64_t &max, int16_t zPos,
|
||||
int16_t zPos2) const
|
||||
{
|
||||
/* The range of block positions is [-2048, 2047], which turns into [0, 4095]
|
||||
* when casted to unsigned. This didn't actually help me understand the
|
||||
* numbers below, but I wanted to write it down.
|
||||
*/
|
||||
|
||||
// Magic numbers!
|
||||
min = encodeBlockPos(BlockPos(0, -2048, zPos));
|
||||
max = encodeBlockPos(BlockPos(0, 2048, zPos2)) - 1;
|
||||
}
|
||||
|
||||
|
||||
std::vector<BlockPos> DBSQLite3::getBlockPos(BlockPos min, BlockPos max)
|
||||
{
|
||||
int result;
|
||||
sqlite3_stmt *stmt;
|
||||
|
||||
if(min.z <= -2048 && max.z >= 2048) {
|
||||
stmt = stmt_get_block_pos;
|
||||
} else {
|
||||
stmt = stmt_get_block_pos_z;
|
||||
int64_t minPos, maxPos;
|
||||
if (min.z < -2048)
|
||||
min.z = -2048;
|
||||
if (max.z > 2048)
|
||||
max.z = 2048;
|
||||
getPosRange(minPos, maxPos, min.z, max.z - 1);
|
||||
SQLOK(bind_int64(stmt, 1, minPos))
|
||||
SQLOK(bind_int64(stmt, 2, maxPos))
|
||||
}
|
||||
|
||||
std::vector<BlockPos> positions;
|
||||
while ((result = sqlite3_step(stmt_get_block_pos)) != SQLITE_DONE) {
|
||||
if (result == SQLITE_ROW) {
|
||||
int64_t posHash = sqlite3_column_int64(stmt_get_block_pos, 0);
|
||||
positions.push_back(decodeBlockPos(posHash));
|
||||
} else if (result == SQLITE_BUSY) { // Wait some time and try again
|
||||
while ((result = sqlite3_step(stmt)) != SQLITE_DONE) {
|
||||
if (result == SQLITE_BUSY) { // Wait some time and try again
|
||||
usleep(10000);
|
||||
} else {
|
||||
} else if (result != SQLITE_ROW) {
|
||||
throw std::runtime_error(sqlite3_errmsg(db));
|
||||
}
|
||||
|
||||
int64_t posHash = sqlite3_column_int64(stmt, 0);
|
||||
BlockPos pos = decodeBlockPos(posHash);
|
||||
if(pos.x >= min.x && pos.x < max.x && pos.y >= min.y && pos.y < max.y)
|
||||
positions.emplace_back(pos);
|
||||
}
|
||||
SQLOK(reset(stmt_get_block_pos));
|
||||
SQLOK(reset(stmt));
|
||||
return positions;
|
||||
}
|
||||
|
||||
|
||||
void DBSQLite3::getBlocksOnZ(std::map<int16_t, BlockList> &blocks, int16_t zPos)
|
||||
void DBSQLite3::loadBlockCache(int16_t zPos)
|
||||
{
|
||||
int result;
|
||||
blockCache.clear();
|
||||
|
||||
// Magic numbers!
|
||||
int64_t minPos = encodeBlockPos(BlockPos(0, -2048, zPos));
|
||||
int64_t maxPos = encodeBlockPos(BlockPos(0, 2048, zPos)) - 1;
|
||||
int64_t minPos, maxPos;
|
||||
getPosRange(minPos, maxPos, zPos, zPos);
|
||||
|
||||
SQLOK(bind_int64(stmt_get_blocks_z, 1, minPos));
|
||||
SQLOK(bind_int64(stmt_get_blocks_z, 2, maxPos));
|
||||
|
||||
while ((result = sqlite3_step(stmt_get_blocks_z)) != SQLITE_DONE) {
|
||||
if (result == SQLITE_ROW) {
|
||||
int64_t posHash = sqlite3_column_int64(stmt_get_blocks_z, 0);
|
||||
const unsigned char *data = reinterpret_cast<const unsigned char *>(
|
||||
sqlite3_column_blob(stmt_get_blocks_z, 1));
|
||||
size_t size = sqlite3_column_bytes(stmt_get_blocks_z, 1);
|
||||
Block b(decodeBlockPos(posHash), ustring(data, size));
|
||||
blocks[b.first.x].push_back(b);
|
||||
} else if (result == SQLITE_BUSY) { // Wait some time and try again
|
||||
if (result == SQLITE_BUSY) { // Wait some time and try again
|
||||
usleep(10000);
|
||||
} else {
|
||||
} else if (result != SQLITE_ROW) {
|
||||
throw std::runtime_error(sqlite3_errmsg(db));
|
||||
}
|
||||
|
||||
int64_t posHash = sqlite3_column_int64(stmt_get_blocks_z, 0);
|
||||
BlockPos pos = decodeBlockPos(posHash);
|
||||
const unsigned char *data = reinterpret_cast<const unsigned char *>(
|
||||
sqlite3_column_blob(stmt_get_blocks_z, 1));
|
||||
size_t size = sqlite3_column_bytes(stmt_get_blocks_z, 1);
|
||||
blockCache[pos.x].emplace_back(pos, ustring(data, size));
|
||||
}
|
||||
SQLOK(reset(stmt_get_blocks_z));
|
||||
SQLOK(reset(stmt_get_blocks_z))
|
||||
}
|
||||
|
||||
#undef SQLRES
|
||||
#undef SQLOK
|
||||
|
||||
void DBSQLite3::getBlocksOnXZ(BlockList &blocks, int16_t x, int16_t z,
|
||||
int16_t min_y, int16_t max_y)
|
||||
{
|
||||
/* Cache the blocks on the given Z coordinate between calls, this only
|
||||
* works due to order in which the TileGenerator asks for blocks. */
|
||||
if (z != blockCachedZ) {
|
||||
loadBlockCache(z);
|
||||
blockCachedZ = z;
|
||||
}
|
||||
|
||||
auto it = blockCache.find(x);
|
||||
if (it == blockCache.end())
|
||||
return;
|
||||
|
||||
if (it->second.empty()) {
|
||||
/* We have swapped this list before, this is not supposed to happen
|
||||
* because it's bad for performance. But rather than silently breaking
|
||||
* do the right thing and load the blocks again. */
|
||||
#ifndef NDEBUG
|
||||
std::cout << "Warning: suboptimal access pattern for sqlite3 backend" << std::endl;
|
||||
#endif
|
||||
loadBlockCache(z);
|
||||
}
|
||||
// Swap lists to avoid copying contents
|
||||
blocks.clear();
|
||||
std::swap(blocks, it->second);
|
||||
|
||||
for (auto it = blocks.begin(); it != blocks.end(); ) {
|
||||
if (it->first.y < min_y || it->first.y >= max_y)
|
||||
it = blocks.erase(it);
|
||||
else
|
||||
it++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DBSQLite3::getBlocksByPos(BlockList &blocks,
|
||||
const std::vector<BlockPos> &positions)
|
||||
{
|
||||
int result;
|
||||
|
||||
for (auto pos : positions) {
|
||||
int64_t dbPos = encodeBlockPos(pos);
|
||||
SQLOK(bind_int64(stmt_get_block_exact, 1, dbPos));
|
||||
|
||||
while ((result = sqlite3_step(stmt_get_block_exact)) == SQLITE_BUSY) {
|
||||
usleep(10000); // Wait some time and try again
|
||||
}
|
||||
if (result == SQLITE_DONE) {
|
||||
// no data
|
||||
} else if (result != SQLITE_ROW) {
|
||||
throw std::runtime_error(sqlite3_errmsg(db));
|
||||
} else {
|
||||
const unsigned char *data = reinterpret_cast<const unsigned char *>(
|
||||
sqlite3_column_blob(stmt_get_block_exact, 0));
|
||||
size_t size = sqlite3_column_bytes(stmt_get_block_exact, 0);
|
||||
blocks.emplace_back(pos, ustring(data, size));
|
||||
}
|
||||
|
||||
SQLOK(reset(stmt_get_block_exact))
|
||||
}
|
||||
}
|
||||
|
20
db-sqlite3.h
20
db-sqlite3.h
@ -1,20 +0,0 @@
|
||||
#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
|
28
include/BlockDecoder.h
Normal file
28
include/BlockDecoder.h
Normal file
@ -0,0 +1,28 @@
|
||||
#ifndef BLOCKDECODER_H
|
||||
#define BLOCKDECODER_H
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include "types.h"
|
||||
|
||||
class BlockDecoder {
|
||||
public:
|
||||
BlockDecoder();
|
||||
|
||||
void reset();
|
||||
void decode(const ustring &data);
|
||||
bool isEmpty() const;
|
||||
std::string getNode(u8 x, u8 y, u8 z) const; // returns "" for air, ignore and invalid nodes
|
||||
u8 getParam1(u8 x, u8 y, u8 z) const;
|
||||
|
||||
private:
|
||||
typedef std::unordered_map<int, std::string> NameMap;
|
||||
NameMap m_nameMap;
|
||||
int m_blockAirId;
|
||||
int m_blockIgnoreId;
|
||||
|
||||
u8 m_version, m_contentWidth;
|
||||
ustring m_mapData;
|
||||
};
|
||||
|
||||
#endif // BLOCKDECODER_H
|
30
include/PlayerAttributes.h
Normal file
30
include/PlayerAttributes.h
Normal file
@ -0,0 +1,30 @@
|
||||
#ifndef PLAYERATTRIBUTES_H_D7THWFVV
|
||||
#define PLAYERATTRIBUTES_H_D7THWFVV
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
struct Player
|
||||
{
|
||||
std::string name;
|
||||
double x, y, z;
|
||||
};
|
||||
|
||||
class PlayerAttributes
|
||||
{
|
||||
public:
|
||||
typedef std::list<Player> Players;
|
||||
|
||||
PlayerAttributes(const std::string &worldDir);
|
||||
Players::iterator begin();
|
||||
Players::iterator end();
|
||||
|
||||
private:
|
||||
void readFiles(const std::string &playersPath);
|
||||
void readSqlite(const std::string &db_name);
|
||||
|
||||
Players m_players;
|
||||
};
|
||||
|
||||
#endif /* end of include guard: PLAYERATTRIBUTES_H_D7THWFVV */
|
||||
|
@ -1,20 +1,17 @@
|
||||
#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 <config.h>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
|
||||
#include "PixelAttributes.h"
|
||||
#include "BlockDecoder.h"
|
||||
#include "Image.h"
|
||||
#include "db.h"
|
||||
#include "types.h"
|
||||
@ -26,30 +23,48 @@ enum {
|
||||
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 to_color() const { return Color(r, g, b, a); }
|
||||
uint8_t r;
|
||||
uint8_t g;
|
||||
uint8_t b;
|
||||
uint8_t a;
|
||||
uint8_t t;
|
||||
uint8_t r, g, b, a, t;
|
||||
};
|
||||
|
||||
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];
|
||||
};
|
||||
|
||||
|
||||
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();
|
||||
@ -57,7 +72,8 @@ public:
|
||||
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 setPlayerColor(const std::string &playerColor);
|
||||
Color parseColor(const std::string &color);
|
||||
void setDrawOrigin(bool drawOrigin);
|
||||
void setDrawPlayers(bool drawPlayers);
|
||||
void setDrawScale(bool drawScale);
|
||||
@ -66,11 +82,16 @@ public:
|
||||
void setGeometry(int x, int y, int w, int h);
|
||||
void setMinY(int y);
|
||||
void setMaxY(int y);
|
||||
void setExhaustiveSearch(int mode);
|
||||
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);
|
||||
void setDontWriteEmpty(bool f);
|
||||
|
||||
void generate(const std::string &input, const std::string &output);
|
||||
void printGeometry(const std::string &input);
|
||||
static std::set<std::string> getSupportedBackends();
|
||||
|
||||
private:
|
||||
void parseColorsStream(std::istream &in);
|
||||
@ -79,8 +100,7 @@ private:
|
||||
void loadBlocks();
|
||||
void createImage();
|
||||
void renderMap();
|
||||
std::list<int> getZValueList() const;
|
||||
void renderMapBlock(const ustring &mapBlock, const BlockPos &pos, int version);
|
||||
void renderMapBlock(const BlockDecoder &blk, const BlockPos &pos);
|
||||
void renderMapBlockBottom(const BlockPos &pos);
|
||||
void renderShading(int zPos);
|
||||
void renderScale();
|
||||
@ -88,8 +108,8 @@ private:
|
||||
void renderPlayers(const std::string &inputPath);
|
||||
void writeImage(const std::string &output);
|
||||
void printUnknown();
|
||||
int getImageX(int val) const;
|
||||
int getImageY(int val) const;
|
||||
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:
|
||||
@ -102,35 +122,38 @@ private:
|
||||
bool m_drawScale;
|
||||
bool m_drawAlpha;
|
||||
bool m_shading;
|
||||
bool m_dontWriteEmpty;
|
||||
std::string m_backend;
|
||||
int m_xBorder, m_yBorder;
|
||||
|
||||
DB *m_db;
|
||||
Image *m_image;
|
||||
PixelAttributes m_blockPixelAttributes;
|
||||
/* smallest/largest seen X or Z block coordinate */
|
||||
int m_xMin;
|
||||
int m_xMax;
|
||||
int m_zMin;
|
||||
int m_zMax;
|
||||
/* Y limits for rendered area (node units) */
|
||||
int m_yMin;
|
||||
int m_yMax;
|
||||
int m_geomX;
|
||||
int m_geomY;
|
||||
int m_geomX2;
|
||||
int m_geomY2;
|
||||
/* 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;
|
||||
/* */
|
||||
int m_mapWidth;
|
||||
int m_mapHeight;
|
||||
std::list<std::pair<int, int> > m_positions;
|
||||
NameMap m_nameMap;
|
||||
int m_exhaustiveSearch;
|
||||
std::map<int16_t, std::set<int16_t>> m_positions; /* indexed by Z, contains X coords */
|
||||
ColorMap m_colorMap;
|
||||
uint16_t m_readPixels[16];
|
||||
uint16_t m_readInfo[16];
|
||||
BitmapThing m_readPixels;
|
||||
BitmapThing m_readInfo;
|
||||
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
|
@ -3,9 +3,9 @@
|
||||
#ifndef CMAKE_CONFIG_H
|
||||
#define CMAKE_CONFIG_H
|
||||
|
||||
#define USE_POSTGRESQL @USE_POSTGRESQL@
|
||||
#define USE_LEVELDB @USE_LEVELDB@
|
||||
#define USE_REDIS @USE_REDIS@
|
||||
#cmakedefine01 USE_POSTGRESQL
|
||||
#cmakedefine01 USE_LEVELDB
|
||||
#cmakedefine01 USE_REDIS
|
||||
|
||||
#define SHAREDIR "@SHAREDIR@"
|
||||
|
31
include/db-leveldb.h
Normal file
31
include/db-leveldb.h
Normal file
@ -0,0 +1,31 @@
|
||||
#ifndef DB_LEVELDB_HEADER
|
||||
#define DB_LEVELDB_HEADER
|
||||
|
||||
#include "db.h"
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
#include <leveldb/db.h>
|
||||
|
||||
class DBLevelDB : public DB {
|
||||
public:
|
||||
DBLevelDB(const std::string &mapdir);
|
||||
std::vector<BlockPos> getBlockPos(BlockPos min, BlockPos max) override;
|
||||
void getBlocksOnXZ(BlockList &blocks, int16_t x, int16_t z,
|
||||
int16_t min_y, int16_t max_y) override;
|
||||
void getBlocksByPos(BlockList &blocks,
|
||||
const std::vector<BlockPos> &positions) override;
|
||||
~DBLevelDB() override;
|
||||
|
||||
bool preferRangeQueries() const override { return false; }
|
||||
|
||||
private:
|
||||
using pos2d = std::pair<int16_t, int16_t>;
|
||||
|
||||
void loadPosCache();
|
||||
|
||||
// indexed by Z, contains all (x,y) position pairs
|
||||
std::unordered_map<int16_t, std::vector<pos2d>> posCache;
|
||||
leveldb::DB *db;
|
||||
};
|
||||
|
||||
#endif // DB_LEVELDB_HEADER
|
@ -7,9 +7,15 @@
|
||||
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();
|
||||
std::vector<BlockPos> getBlockPos(BlockPos min, BlockPos max) override;
|
||||
void getBlocksOnXZ(BlockList &blocks, int16_t x, int16_t z,
|
||||
int16_t min_y, int16_t max_y) override;
|
||||
void getBlocksByPos(BlockList &blocks,
|
||||
const std::vector<BlockPos> &positions) override;
|
||||
~DBPostgreSQL() override;
|
||||
|
||||
bool preferRangeQueries() const override { return true; }
|
||||
|
||||
protected:
|
||||
PGresult *checkResults(PGresult *res, bool clear = true);
|
||||
void prepareStatement(const std::string &name, const std::string &sql);
|
||||
@ -17,11 +23,11 @@ protected:
|
||||
const char *stmtName, const int paramsNumber,
|
||||
const void **params,
|
||||
const int *paramsLengths = NULL, const int *paramsFormats = NULL,
|
||||
bool clear = true, bool nobinary = true
|
||||
bool clear = 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;
|
||||
};
|
37
include/db-redis.h
Normal file
37
include/db-redis.h
Normal file
@ -0,0 +1,37 @@
|
||||
#ifndef DB_REDIS_HEADER
|
||||
#define DB_REDIS_HEADER
|
||||
|
||||
#include "db.h"
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
#include <functional>
|
||||
#include <hiredis/hiredis.h>
|
||||
|
||||
class DBRedis : public DB {
|
||||
public:
|
||||
DBRedis(const std::string &mapdir);
|
||||
std::vector<BlockPos> getBlockPos(BlockPos min, BlockPos max) override;
|
||||
void getBlocksOnXZ(BlockList &blocks, int16_t x, int16_t z,
|
||||
int16_t min_y, int16_t max_y) override;
|
||||
void getBlocksByPos(BlockList &blocks,
|
||||
const std::vector<BlockPos> &positions) override;
|
||||
~DBRedis() override;
|
||||
|
||||
bool preferRangeQueries() const override { return false; }
|
||||
|
||||
private:
|
||||
using pos2d = std::pair<int16_t, int16_t>;
|
||||
static const char *replyTypeStr(int type);
|
||||
|
||||
void loadPosCache();
|
||||
void HMGET(const std::vector<BlockPos> &positions,
|
||||
std::function<void(std::size_t, ustring)> result);
|
||||
|
||||
// indexed by Z, contains all (x,y) position pairs
|
||||
std::unordered_map<int16_t, std::vector<pos2d>> posCache;
|
||||
|
||||
redisContext *ctx;
|
||||
std::string hash;
|
||||
};
|
||||
|
||||
#endif // DB_REDIS_HEADER
|
36
include/db-sqlite3.h
Normal file
36
include/db-sqlite3.h
Normal file
@ -0,0 +1,36 @@
|
||||
#ifndef _DB_SQLITE3_H
|
||||
#define _DB_SQLITE3_H
|
||||
|
||||
#include "db.h"
|
||||
#include <unordered_map>
|
||||
#include <sqlite3.h>
|
||||
|
||||
class DBSQLite3 : public DB {
|
||||
public:
|
||||
DBSQLite3(const std::string &mapdir);
|
||||
std::vector<BlockPos> getBlockPos(BlockPos min, BlockPos max) override;
|
||||
void getBlocksOnXZ(BlockList &blocks, int16_t x, int16_t z,
|
||||
int16_t min_y, int16_t max_y) override;
|
||||
void getBlocksByPos(BlockList &blocks,
|
||||
const std::vector<BlockPos> &positions) override;
|
||||
~DBSQLite3() override;
|
||||
|
||||
bool preferRangeQueries() const override { return false; }
|
||||
|
||||
private:
|
||||
inline void getPosRange(int64_t &min, int64_t &max, int16_t zPos,
|
||||
int16_t zPos2) const;
|
||||
void loadBlockCache(int16_t zPos);
|
||||
|
||||
sqlite3 *db;
|
||||
|
||||
sqlite3_stmt *stmt_get_block_pos;
|
||||
sqlite3_stmt *stmt_get_block_pos_z;
|
||||
sqlite3_stmt *stmt_get_blocks_z;
|
||||
sqlite3_stmt *stmt_get_block_exact;
|
||||
|
||||
int16_t blockCachedZ = -10000;
|
||||
std::unordered_map<int16_t, BlockList> blockCache; // indexed by X
|
||||
};
|
||||
|
||||
#endif // _DB_SQLITE3_H
|
@ -5,39 +5,33 @@
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include "types.h"
|
||||
|
||||
|
||||
class BlockPos {
|
||||
public:
|
||||
struct BlockPos {
|
||||
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) {}
|
||||
|
||||
// Implements the inverse ordering so that (2,2,2) < (1,1,1)
|
||||
bool operator < (const BlockPos &p) const
|
||||
{
|
||||
if (z > p.z) {
|
||||
if (z > p.z)
|
||||
return true;
|
||||
}
|
||||
if (z < p.z) {
|
||||
if (z < p.z)
|
||||
return false;
|
||||
}
|
||||
if (y > p.y) {
|
||||
if (y > p.y)
|
||||
return true;
|
||||
}
|
||||
if (y < p.y) {
|
||||
if (y < p.y)
|
||||
return false;
|
||||
}
|
||||
if (x > p.x) {
|
||||
if (x > p.x)
|
||||
return true;
|
||||
}
|
||||
if (x < p.x) {
|
||||
if (x < p.x)
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
@ -49,13 +43,31 @@ typedef std::list<Block> BlockList;
|
||||
|
||||
class DB {
|
||||
protected:
|
||||
// Helpers that implement the hashed positions used by most backends
|
||||
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() {};
|
||||
/* Return all block positions inside the range given by min and max,
|
||||
* so that min.x <= x < max.x, ...
|
||||
*/
|
||||
virtual std::vector<BlockPos> getBlockPos(BlockPos min, BlockPos max) = 0;
|
||||
/* Read all blocks in column given by x and z
|
||||
* and inside the given Y range (min_y <= y < max_y) into list
|
||||
*/
|
||||
virtual void getBlocksOnXZ(BlockList &blocks, int16_t x, int16_t z,
|
||||
int16_t min_y, int16_t max_y) = 0;
|
||||
/* Read blocks at given positions into list
|
||||
*/
|
||||
virtual void getBlocksByPos(BlockList &blocks,
|
||||
const std::vector<BlockPos> &positions) = 0;
|
||||
/* Can this database efficiently do range queries?
|
||||
* (for large data sets, more efficient that brute force)
|
||||
*/
|
||||
virtual bool preferRangeQueries() const = 0;
|
||||
|
||||
|
||||
virtual ~DB() {}
|
||||
};
|
||||
|
||||
|
18
include/util.h
Normal file
18
include/util.h
Normal file
@ -0,0 +1,18 @@
|
||||
#ifndef UTIL_H
|
||||
#define UTIL_H
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
|
||||
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)
|
||||
{
|
||||
try {
|
||||
return read_setting(name, is);
|
||||
} catch(const std::runtime_error &e) {
|
||||
return def;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // UTIL_H
|
145
mapper.cpp
145
mapper.cpp
@ -1,47 +1,68 @@
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <getopt.h>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <utility>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include "cmake_config.h"
|
||||
#include "TileGenerator.h"
|
||||
|
||||
void usage()
|
||||
static void usage()
|
||||
{
|
||||
const char *usage_text = "minetestmapper [options]\n"
|
||||
" -i/--input <world_path>\n"
|
||||
" -o/--output <output_image.png>\n"
|
||||
" --bgcolor <color>\n"
|
||||
" --scalecolor <color>\n"
|
||||
" --playercolor <color>\n"
|
||||
" --origincolor <color>\n"
|
||||
" --drawscale\n"
|
||||
" --drawplayers\n"
|
||||
" --draworigin\n"
|
||||
" --drawalpha\n"
|
||||
" --noshading\n"
|
||||
" --min-y <y>\n"
|
||||
" --max-y <y>\n"
|
||||
" --backend <backend>\n"
|
||||
" --geometry x:y+w+h\n"
|
||||
" --zoom <zoomlevel>\n"
|
||||
" --colors <colors.txt>\n"
|
||||
" --scales [t][b][l][r]\n"
|
||||
"Color format: '#000000'\n";
|
||||
std::cout << usage_text;
|
||||
const std::pair<const char*, const char*> options[] = {
|
||||
{"-i/--input", "<world_path>"},
|
||||
{"-o/--output", "<output_image.png>"},
|
||||
{"--bgcolor", "<color>"},
|
||||
{"--scalecolor", "<color>"},
|
||||
{"--playercolor", "<color>"},
|
||||
{"--origincolor", "<color>"},
|
||||
{"--drawscale", ""},
|
||||
{"--drawplayers", ""},
|
||||
{"--draworigin", ""},
|
||||
{"--drawalpha", ""},
|
||||
{"--noshading", ""},
|
||||
{"--noemptyimage", ""},
|
||||
{"--min-y", "<y>"},
|
||||
{"--max-y", "<y>"},
|
||||
{"--backend", "<backend>"},
|
||||
{"--geometry", "x:y+w+h"},
|
||||
{"--extent", ""},
|
||||
{"--zoom", "<zoomlevel>"},
|
||||
{"--colors", "<colors.txt>"},
|
||||
{"--scales", "[t][b][l][r]"},
|
||||
{"--exhaustive", "never|y|full|auto"},
|
||||
};
|
||||
const char *top_text =
|
||||
"minetestmapper -i <world_path> -o <output_image.png> [options]\n"
|
||||
"Generate an overview image of a Minetest map.\n"
|
||||
"\n"
|
||||
"Options:\n";
|
||||
const char *bottom_text =
|
||||
"\n"
|
||||
"Color format: hexadecimal '#RRGGBB', e.g. '#FF0000' = red\n";
|
||||
|
||||
printf("%s", top_text);
|
||||
for (const auto &p : options)
|
||||
printf(" %-18s%s\n", p.first, p.second);
|
||||
printf("%s", bottom_text);
|
||||
auto backends = TileGenerator::getSupportedBackends();
|
||||
printf("Supported backends: ");
|
||||
for (auto s : backends)
|
||||
printf("%s ", s.c_str());
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
bool file_exists(const std::string &path)
|
||||
static bool file_exists(const std::string &path)
|
||||
{
|
||||
std::ifstream ifs(path.c_str());
|
||||
return ifs.is_open();
|
||||
}
|
||||
|
||||
std::string search_colors(const std::string &worldpath)
|
||||
static std::string search_colors(const std::string &worldpath)
|
||||
{
|
||||
if(file_exists(worldpath + "/colors.txt"))
|
||||
return worldpath + "/colors.txt";
|
||||
@ -55,7 +76,8 @@ std::string search_colors(const std::string &worldpath)
|
||||
}
|
||||
#endif
|
||||
|
||||
if(!(SHAREDIR[0] == '.' || SHAREDIR[0] == '\0') && file_exists(SHAREDIR "/colors.txt"))
|
||||
constexpr bool sharedir_valid = !(SHAREDIR[0] == '.' || SHAREDIR[0] == '\0');
|
||||
if(sharedir_valid && file_exists(SHAREDIR "/colors.txt"))
|
||||
return SHAREDIR "/colors.txt";
|
||||
|
||||
std::cerr << "Warning: Falling back to using colors.txt from current directory." << std::endl;
|
||||
@ -64,7 +86,7 @@ std::string search_colors(const std::string &worldpath)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
static struct option long_options[] =
|
||||
const static struct option long_options[] =
|
||||
{
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{"input", required_argument, 0, 'i'},
|
||||
@ -80,11 +102,14 @@ int main(int argc, char *argv[])
|
||||
{"noshading", no_argument, 0, 'H'},
|
||||
{"backend", required_argument, 0, 'd'},
|
||||
{"geometry", required_argument, 0, 'g'},
|
||||
{"extent", no_argument, 0, 'E'},
|
||||
{"min-y", required_argument, 0, 'a'},
|
||||
{"max-y", required_argument, 0, 'c'},
|
||||
{"zoom", required_argument, 0, 'z'},
|
||||
{"colors", required_argument, 0, 'C'},
|
||||
{"scales", required_argument, 0, 'f'},
|
||||
{"noemptyimage", no_argument, 0, 'n'},
|
||||
{"exhaustive", required_argument, 0, 'j'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
@ -93,17 +118,13 @@ int main(int argc, char *argv[])
|
||||
std::string colors = "";
|
||||
|
||||
TileGenerator generator;
|
||||
int option_index = 0;
|
||||
int c = 0;
|
||||
bool onlyPrintExtent = false;
|
||||
while (1) {
|
||||
c = getopt_long(argc, argv, "hi:o:", long_options, &option_index);
|
||||
if (c == -1) {
|
||||
if (input.empty() || output.empty()) {
|
||||
usage();
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
int option_index;
|
||||
int c = getopt_long(argc, argv, "hi:o:", long_options, &option_index);
|
||||
if (c == -1)
|
||||
break; // done
|
||||
|
||||
switch (c) {
|
||||
case 'h':
|
||||
usage();
|
||||
@ -139,6 +160,9 @@ int main(int argc, char *argv[])
|
||||
case 'e':
|
||||
generator.setDrawAlpha(true);
|
||||
break;
|
||||
case 'E':
|
||||
onlyPrintExtent = true;
|
||||
break;
|
||||
case 'H':
|
||||
generator.setShading(false);
|
||||
break;
|
||||
@ -146,24 +170,21 @@ int main(int argc, char *argv[])
|
||||
generator.setBackend(optarg);
|
||||
break;
|
||||
case 'a': {
|
||||
std::istringstream iss;
|
||||
iss.str(optarg);
|
||||
std::istringstream iss(optarg);
|
||||
int miny;
|
||||
iss >> miny;
|
||||
generator.setMinY(miny);
|
||||
}
|
||||
break;
|
||||
case 'c': {
|
||||
std::istringstream iss;
|
||||
iss.str(optarg);
|
||||
std::istringstream iss(optarg);
|
||||
int maxy;
|
||||
iss >> maxy;
|
||||
generator.setMaxY(maxy);
|
||||
}
|
||||
break;
|
||||
case 'g': {
|
||||
std::istringstream geometry;
|
||||
geometry.str(optarg);
|
||||
std::istringstream geometry(optarg);
|
||||
int x, y, w, h;
|
||||
char c;
|
||||
geometry >> x >> c >> y >> w >> h;
|
||||
@ -188,8 +209,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
break;
|
||||
case 'z': {
|
||||
std::istringstream iss;
|
||||
iss.str(optarg);
|
||||
std::istringstream iss(optarg);
|
||||
int zoom;
|
||||
iss >> zoom;
|
||||
generator.setZoom(zoom);
|
||||
@ -198,16 +218,45 @@ int main(int argc, char *argv[])
|
||||
case 'C':
|
||||
colors = optarg;
|
||||
break;
|
||||
case 'n':
|
||||
generator.setDontWriteEmpty(true);
|
||||
break;
|
||||
case 'j': {
|
||||
int mode;
|
||||
if (!strcmp(optarg, "never"))
|
||||
mode = EXH_NEVER;
|
||||
else if (!strcmp(optarg, "y"))
|
||||
mode = EXH_Y;
|
||||
else if (!strcmp(optarg, "full"))
|
||||
mode = EXH_FULL;
|
||||
else
|
||||
mode = EXH_AUTO;
|
||||
generator.setExhaustiveSearch(mode);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
if(colors == "")
|
||||
colors = search_colors(input);
|
||||
|
||||
if (input.empty() || (!onlyPrintExtent && output.empty())) {
|
||||
usage();
|
||||
return 0;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
if (onlyPrintExtent) {
|
||||
generator.printGeometry(input);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(colors == "")
|
||||
colors = search_colors(input);
|
||||
generator.parseColorsFile(colors);
|
||||
generator.generate(input, output);
|
||||
} catch(std::runtime_error e) {
|
||||
|
||||
} catch(std::runtime_error &e) {
|
||||
std::cerr << "Exception: " << e.what() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ See additional optional parameters below.
|
||||
.B minetestmapper
|
||||
generates an overview image of a minetest map. This is a port of
|
||||
the original minetestmapper.py to C++, that is both faster and
|
||||
provides more funtionality than the deprecated Python script.
|
||||
provides more functionality than the deprecated Python script.
|
||||
.SH MANDATORY PARAMETERS
|
||||
.TP
|
||||
.BR \-i " " \fIworld_path\fR
|
||||
@ -56,6 +56,10 @@ Allow nodes to be drawn with transparency
|
||||
.BR \-\-noshading
|
||||
Don't draw shading on nodes
|
||||
|
||||
.TP
|
||||
.BR \-\-noemptyimage
|
||||
Don't output anything when the image would be empty.
|
||||
|
||||
.TP
|
||||
.BR \-\-min-y " " \fInumber\fR
|
||||
Don't draw nodes below this y value, e.g. "--min-y -25"
|
||||
@ -66,11 +70,15 @@ Don't draw nodes above this y value, e.g. "--max-y 75"
|
||||
|
||||
.TP
|
||||
.BR \-\-backend " " \fIbackend\fR
|
||||
Use specific map backend; supported: *sqlite3*, *leveldb*, *redis*, *postgresql*, e.g. "--backend leveldb"
|
||||
Use specific map backend; supported: \fIsqlite3\fP, \fIleveldb\fP, \fIredis\fP, \fIpostgresql\fP, e.g. "--backend leveldb"
|
||||
|
||||
.TP
|
||||
.BR \-\-geometry " " \fIgeometry\fR
|
||||
Limit area to specific geometry (*x:y+w+h* where x and y specify the lower left corner), e.g. "--geometry -800:-800+1600+1600"
|
||||
Limit area to specific geometry (\fIx:y+w+h\fP where x and y specify the lower left corner), e.g. "--geometry -800:-800+1600+1600"
|
||||
|
||||
.TP
|
||||
.BR \-\-extent " " \fIextent\fR
|
||||
Don't render the image, just print the extent of the map that would be generated, in the same format as the geometry above.
|
||||
|
||||
.TP
|
||||
.BR \-\-zoom " " \fIfactor\fR
|
||||
@ -82,7 +90,18 @@ Forcefully set path to colors.txt file (it's autodetected otherwise), e.g. "--co
|
||||
|
||||
.TP
|
||||
.BR \-\-scales " " \fIedges\fR
|
||||
Draw scales on specified image edges (letters *t b l r* meaning top, bottom, left and right), e.g. "--scales tbr"
|
||||
Draw scales on specified image edges (letters \fIt b l r\fP meaning top, bottom, left and right), e.g. "--scales tbr"
|
||||
|
||||
.TP
|
||||
.BR \-\-exhaustive " \fImode\fR
|
||||
Select if database should be traversed exhaustively or using range queries, available: \fInever\fP, \fIy\fP, \fIfull\fP, \fIauto\fP
|
||||
|
||||
Defaults to \fIauto\fP. You shouldn't need to change this, but doing so can improve rendering times on large maps.
|
||||
For these optimizations to work it is important that you set
|
||||
.B min-y
|
||||
and
|
||||
.B max-y
|
||||
when you don't care about the world below e.g. -60 and above 1000 nodes.
|
||||
|
||||
.SH MORE INFORMATION
|
||||
Website: https://github.com/minetest/minetestmapper
|
||||
|
81
util.cpp
81
util.cpp
@ -1,56 +1,45 @@
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
inline std::string trim(const std::string &s)
|
||||
static inline std::string trim(const std::string &s)
|
||||
{
|
||||
size_t front = 0;
|
||||
while(s[front] == ' ' ||
|
||||
s[front] == '\t' ||
|
||||
s[front] == '\r' ||
|
||||
s[front] == '\n'
|
||||
)
|
||||
++front;
|
||||
auto isspace = [] (char c) -> bool { return c == ' ' || c == '\t' || c == '\r' || c == '\n'; };
|
||||
|
||||
size_t back = s.size();
|
||||
while(back > front &&
|
||||
(s[back-1] == ' ' ||
|
||||
s[back-1] == '\t' ||
|
||||
s[back-1] == '\r' ||
|
||||
s[back-1] == '\n'
|
||||
)
|
||||
)
|
||||
--back;
|
||||
size_t front = 0;
|
||||
while(isspace(s[front]))
|
||||
++front;
|
||||
size_t back = s.size() - 1;
|
||||
while(back > front && isspace(s[back]))
|
||||
--back;
|
||||
|
||||
return s.substr(front, back - front);
|
||||
return s.substr(front, back - front + 1);
|
||||
}
|
||||
|
||||
#define EOFCHECK() \
|
||||
if(is.eof()) \
|
||||
throw std::runtime_error(((std::string) "Setting '") + name + "' not found");
|
||||
|
||||
std::string get_setting(std::string name, std::istream &is)
|
||||
std::string read_setting(const std::string &name, std::istream &is)
|
||||
{
|
||||
char c;
|
||||
char s[256];
|
||||
std::string nm, value;
|
||||
char linebuf[512];
|
||||
while (is.good()) {
|
||||
is.getline(linebuf, sizeof(linebuf));
|
||||
|
||||
next:
|
||||
while((c = is.get()) == ' ' || c == '\t' || c == '\r' || c == '\n')
|
||||
;
|
||||
EOFCHECK();
|
||||
if(c == '#') // Ignore comments
|
||||
is.ignore(0xffff, '\n');
|
||||
EOFCHECK();
|
||||
s[0] = c; // The current char belongs to the name too
|
||||
is.get(&s[1], 255, '=');
|
||||
is.ignore(1); // Jump over the =
|
||||
EOFCHECK();
|
||||
nm = trim(std::string(s));
|
||||
is.get(s, 256, '\n');
|
||||
value = trim(std::string(s));
|
||||
if(name == nm)
|
||||
return value;
|
||||
else
|
||||
goto next;
|
||||
for(char *p = linebuf; *p; p++) {
|
||||
if(*p != '#')
|
||||
continue;
|
||||
*p = '\0'; // Cut off at the first #
|
||||
break;
|
||||
}
|
||||
std::string line(linebuf);
|
||||
|
||||
auto pos = line.find('=');
|
||||
if (pos == std::string::npos)
|
||||
continue;
|
||||
auto key = trim(line.substr(0, pos));
|
||||
if (key != name)
|
||||
continue;
|
||||
return trim(line.substr(pos+1));
|
||||
}
|
||||
std::ostringstream oss;
|
||||
oss << "Setting '" << name << "' not found";
|
||||
throw std::runtime_error(oss.str());
|
||||
}
|
||||
|
||||
#undef EOFCHECK
|
||||
|
10
util.h
10
util.h
@ -1,10 +0,0 @@
|
||||
#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
|
73
util/build_win.sh
Executable file
73
util/build_win.sh
Executable file
@ -0,0 +1,73 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
#######
|
||||
# this expects an env similar to what minetest's buildbot uses
|
||||
# extradll_path will typically contain libgcc, libstdc++ and libpng
|
||||
toolchain_file=
|
||||
toolchain_file64=
|
||||
libgd_dir=
|
||||
libgd_dir64=
|
||||
zlib_dir=
|
||||
zlib_dir64=
|
||||
sqlite_dir=
|
||||
sqlite_dir64=
|
||||
leveldb_dir=
|
||||
leveldb_dir64=
|
||||
extradll_path=
|
||||
extradll_path64=
|
||||
#######
|
||||
|
||||
[ -f ./CMakeLists.txt ] || exit 1
|
||||
|
||||
if [ "$1" == "32" ]; then
|
||||
:
|
||||
elif [ "$1" == "64" ]; then
|
||||
toolchain_file=$toolchain_file64
|
||||
libgd_dir=$libgd_dir64
|
||||
zlib_dir=$zlib_dir64
|
||||
sqlite_dir=$sqlite_dir64
|
||||
leveldb_dir=$leveldb_dir64
|
||||
extradll_path=$extradll_path64
|
||||
else
|
||||
echo "Usage: $0 <32 / 64>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cmake . \
|
||||
-DCMAKE_INSTALL_PREFIX=/tmp \
|
||||
-DCMAKE_TOOLCHAIN_FILE=$toolchain_file \
|
||||
-DCMAKE_EXE_LINKER_FLAGS="-s" \
|
||||
\
|
||||
-DENABLE_LEVELDB=1 \
|
||||
\
|
||||
-DLIBGD_INCLUDE_DIR=$libgd_dir/include \
|
||||
-DLIBGD_LIBRARY=$libgd_dir/lib/libgd.dll.a \
|
||||
\
|
||||
-DZLIB_INCLUDE_DIR=$zlib_dir/include \
|
||||
-DZLIB_LIBRARY=$zlib_dir/lib/libz.dll.a \
|
||||
\
|
||||
-DSQLITE3_INCLUDE_DIR=$sqlite_dir/include \
|
||||
-DSQLITE3_LIBRARY=$sqlite_dir/lib/libsqlite3.dll.a \
|
||||
\
|
||||
-DLEVELDB_INCLUDE_DIR=$leveldb_dir/include \
|
||||
-DLEVELDB_LIBRARY=$leveldb_dir/lib/libleveldb.dll.a
|
||||
|
||||
make -j4
|
||||
|
||||
mkdir pack
|
||||
cp -p \
|
||||
AUTHORS colors.txt COPYING README.rst \
|
||||
minetestmapper.exe \
|
||||
$libgd_dir/bin/libgd-3.dll \
|
||||
$zlib_dir/bin/zlib1.dll \
|
||||
$sqlite_dir/bin/libsqlite3-0.dll \
|
||||
$leveldb_dir/bin/libleveldb.dll \
|
||||
$extradll_path/*.dll \
|
||||
pack/
|
||||
zipfile=minetestmapper-win$1.zip
|
||||
(cd pack; zip -9r ../$zipfile *)
|
||||
|
||||
make clean
|
||||
rm -r pack CMakeCache.txt
|
||||
|
||||
echo "Done."
|
@ -1,17 +1,8 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
CXX=g++-6
|
||||
[ $CC == "clang" ] && CXX=clang-3.8
|
||||
export CXX
|
||||
|
||||
|
||||
mkdir -p travisbuild
|
||||
cd travisbuild
|
||||
|
||||
cmake \
|
||||
-DENABLE_LEVELDB=1 \
|
||||
-DLEVELDB_LIBRARY=../libleveldb/lib/libleveldb.so \
|
||||
-DLEVELDB_INCLUDE_DIR=../libleveldb/include \
|
||||
..
|
||||
cmake .. \
|
||||
-DENABLE_LEVELDB=1
|
||||
|
||||
make -j2
|
||||
|
Reference in New Issue
Block a user