mirror of
https://github.com/minetest/minetestmapper.git
synced 2024-11-21 23:13:53 +01:00
Added selection of blocks.
This commit is contained in:
parent
b7f69cc3df
commit
ace6f3b5b5
@ -137,6 +137,7 @@ void TileGenerator::generate(const std::string &input, const std::string &output
|
|||||||
openDb(input);
|
openDb(input);
|
||||||
loadBlocks();
|
loadBlocks();
|
||||||
createImage();
|
createImage();
|
||||||
|
renderMap();
|
||||||
writeImage(output);
|
writeImage(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,11 +175,14 @@ void TileGenerator::loadBlocks()
|
|||||||
if (pos.z > m_zMax) {
|
if (pos.z > m_zMax) {
|
||||||
m_zMax = pos.z;
|
m_zMax = pos.z;
|
||||||
}
|
}
|
||||||
|
m_positions.push_back(std::pair<int, int>(pos.x, pos.z));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
m_positions.sort();
|
||||||
|
m_positions.unique();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw DbError();
|
throw DbError();
|
||||||
@ -196,6 +200,11 @@ inline BlockPos TileGenerator::decodeBlockPos(sqlite3_int64 blockId)
|
|||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline sqlite3_int64 TileGenerator::encodeBlockPos(int x, int y, int z)
|
||||||
|
{
|
||||||
|
return sqlite3_int64(z) * 16777216l + sqlite3_int64(y) * 4096l + sqlite3_int64(x);
|
||||||
|
}
|
||||||
|
|
||||||
inline int TileGenerator::unsignedToSigned(long i, long max_positive)
|
inline int TileGenerator::unsignedToSigned(long i, long max_positive)
|
||||||
{
|
{
|
||||||
if (i < max_positive) {
|
if (i < max_positive) {
|
||||||
@ -215,6 +224,35 @@ void TileGenerator::createImage()
|
|||||||
gdImageColorAllocate(m_image, m_bgColor.r, m_bgColor.g, m_bgColor.b);
|
gdImageColorAllocate(m_image, m_bgColor.r, m_bgColor.g, m_bgColor.b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TileGenerator::renderMap()
|
||||||
|
{
|
||||||
|
sqlite3_stmt *statement;
|
||||||
|
string sql = "SELECT pos FROM blocks WHERE pos >= ? AND pos <= ? AND (pos - ?) % 4096 = 0";
|
||||||
|
if (sqlite3_prepare_v2(m_db, sql.c_str(), sql.length(), &statement, 0) != SQLITE_OK) {
|
||||||
|
throw DbError();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto position = m_positions.begin(); position != m_positions.end(); ++position) {
|
||||||
|
int xPos = position->first;
|
||||||
|
int zPos = position->second;
|
||||||
|
|
||||||
|
sqlite3_int64 psMin = encodeBlockPos(xPos, -2048, zPos);
|
||||||
|
sqlite3_int64 psMax = encodeBlockPos(xPos, 2047, zPos);
|
||||||
|
sqlite3_bind_int64(statement, 1, psMin);
|
||||||
|
sqlite3_bind_int64(statement, 2, psMax);
|
||||||
|
sqlite3_bind_int64(statement, 3, psMin);
|
||||||
|
int result = 0;
|
||||||
|
while (true) {
|
||||||
|
result = sqlite3_step(statement);
|
||||||
|
if(result == SQLITE_ROW) {
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void TileGenerator::writeImage(const std::string &output)
|
void TileGenerator::writeImage(const std::string &output)
|
||||||
{
|
{
|
||||||
FILE *out;
|
FILE *out;
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#define TILEGENERATOR_H_JJNUCARH
|
#define TILEGENERATOR_H_JJNUCARH
|
||||||
|
|
||||||
#include <gd.h>
|
#include <gd.h>
|
||||||
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <sqlite3.h>
|
#include <sqlite3.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@ -58,8 +59,10 @@ private:
|
|||||||
void openDb(const std::string &input);
|
void openDb(const std::string &input);
|
||||||
void loadBlocks();
|
void loadBlocks();
|
||||||
BlockPos decodeBlockPos(sqlite3_int64 blockId);
|
BlockPos decodeBlockPos(sqlite3_int64 blockId);
|
||||||
|
sqlite3_int64 encodeBlockPos(int x, int y, int z);
|
||||||
int unsignedToSigned(long i, long max_positive);
|
int unsignedToSigned(long i, long max_positive);
|
||||||
void createImage();
|
void createImage();
|
||||||
|
void renderMap();
|
||||||
void writeImage(const std::string &output);
|
void writeImage(const std::string &output);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -80,6 +83,7 @@ private:
|
|||||||
int m_zMax;
|
int m_zMax;
|
||||||
int m_imgWidth;
|
int m_imgWidth;
|
||||||
int m_imgHeight;
|
int m_imgHeight;
|
||||||
|
std::list<std::pair<int, int> > m_positions;
|
||||||
ColorMap m_colors;
|
ColorMap m_colors;
|
||||||
|
|
||||||
static const int SectorXMin = -1500/16;
|
static const int SectorXMin = -1500/16;
|
||||||
|
Loading…
Reference in New Issue
Block a user