Use a common ustring type definition instead of different custom versions
This commit is contained in:
parent
0117556550
commit
902f3b45d7
@ -881,8 +881,8 @@ void TileGenerator::renderMap()
|
|||||||
|
|
||||||
ZlibDecompressor decompressor(data, length);
|
ZlibDecompressor decompressor(data, length);
|
||||||
decompressor.setSeekPos(dataOffset);
|
decompressor.setSeekPos(dataOffset);
|
||||||
ZlibDecompressor::string mapData = decompressor.decompress();
|
ustring mapData = decompressor.decompress();
|
||||||
ZlibDecompressor::string mapMetadata = decompressor.decompress();
|
ustring mapMetadata = decompressor.decompress();
|
||||||
dataOffset = decompressor.seekPos();
|
dataOffset = decompressor.seekPos();
|
||||||
|
|
||||||
// Skip unused data
|
// Skip unused data
|
||||||
@ -973,7 +973,7 @@ void TileGenerator::renderMap()
|
|||||||
cout << std::setw(40) << "" << "\r";
|
cout << std::setw(40) << "" << "\r";
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void TileGenerator::renderMapBlock(const unsigned_string &mapBlock, const BlockPos &pos, int version)
|
inline void TileGenerator::renderMapBlock(const ustring &mapBlock, const BlockPos &pos, int version)
|
||||||
{
|
{
|
||||||
int xBegin = worldBlockX2StoredX(pos.x);
|
int xBegin = worldBlockX2StoredX(pos.x);
|
||||||
int zBegin = worldBlockZ2StoredY(pos.z);
|
int zBegin = worldBlockZ2StoredY(pos.z);
|
||||||
|
@ -18,6 +18,8 @@
|
|||||||
#include <set>
|
#include <set>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string>
|
||||||
|
#include "types.h"
|
||||||
#include "PixelAttributes.h"
|
#include "PixelAttributes.h"
|
||||||
#include "Color.h"
|
#include "Color.h"
|
||||||
#include "db.h"
|
#include "db.h"
|
||||||
@ -78,9 +80,8 @@ struct BlockPos {
|
|||||||
class TileGenerator
|
class TileGenerator
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
typedef std::basic_string<unsigned char> unsigned_string;
|
|
||||||
typedef std::map<std::string, ColorEntry> ColorMap;
|
typedef std::map<std::string, ColorEntry> ColorMap;
|
||||||
typedef std::pair<BlockPos, unsigned_string> Block;
|
typedef std::pair<BlockPos, ustring> Block;
|
||||||
typedef std::list<Block> BlockList;
|
typedef std::list<Block> BlockList;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -138,7 +139,7 @@ private:
|
|||||||
std::list<int> getZValueList() const;
|
std::list<int> getZValueList() const;
|
||||||
Block getBlockOnPos(BlockPos pos);
|
Block getBlockOnPos(BlockPos pos);
|
||||||
void pushPixelRows(int zPosLimit);
|
void pushPixelRows(int zPosLimit);
|
||||||
void renderMapBlock(const unsigned_string &mapBlock, const BlockPos &pos, int version);
|
void renderMapBlock(const ustring &mapBlock, const BlockPos &pos, int version);
|
||||||
void renderScale();
|
void renderScale();
|
||||||
void renderOrigin();
|
void renderOrigin();
|
||||||
void renderPlayers(const std::string &inputPath);
|
void renderPlayers(const std::string &inputPath);
|
||||||
|
@ -32,12 +32,12 @@ std::size_t ZlibDecompressor::seekPos() const
|
|||||||
return m_seekPos;
|
return m_seekPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZlibDecompressor::string ZlibDecompressor::decompress()
|
ustring ZlibDecompressor::decompress()
|
||||||
{
|
{
|
||||||
const unsigned char *data = m_data + m_seekPos;
|
const unsigned char *data = m_data + m_seekPos;
|
||||||
const std::size_t size = m_size - m_seekPos;
|
const std::size_t size = m_size - m_seekPos;
|
||||||
|
|
||||||
string buffer;
|
ustring buffer;
|
||||||
const size_t BUFSIZE = 128 * 1024;
|
const size_t BUFSIZE = 128 * 1024;
|
||||||
uint8_t temp_buffer[BUFSIZE];
|
uint8_t temp_buffer[BUFSIZE];
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ ZlibDecompressor::string ZlibDecompressor::decompress()
|
|||||||
strm.avail_out = BUFSIZE;
|
strm.avail_out = BUFSIZE;
|
||||||
strm.next_out = temp_buffer;
|
strm.next_out = temp_buffer;
|
||||||
ret = inflate(&strm, Z_NO_FLUSH);
|
ret = inflate(&strm, Z_NO_FLUSH);
|
||||||
buffer += string(reinterpret_cast<unsigned char *>(temp_buffer), BUFSIZE - strm.avail_out);
|
buffer += ustring(reinterpret_cast<unsigned char *>(temp_buffer), BUFSIZE - strm.avail_out);
|
||||||
} while (ret == Z_OK);
|
} while (ret == Z_OK);
|
||||||
if (ret != Z_STREAM_END) {
|
if (ret != Z_STREAM_END) {
|
||||||
throw DecompressError();
|
throw DecompressError();
|
||||||
|
@ -12,12 +12,12 @@
|
|||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
|
|
||||||
class ZlibDecompressor
|
class ZlibDecompressor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef std::basic_string<unsigned char> string;
|
|
||||||
class DecompressError {
|
class DecompressError {
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ public:
|
|||||||
~ZlibDecompressor();
|
~ZlibDecompressor();
|
||||||
void setSeekPos(std::size_t seekPos);
|
void setSeekPos(std::size_t seekPos);
|
||||||
std::size_t seekPos() const;
|
std::size_t seekPos() const;
|
||||||
string decompress();
|
ustring decompress();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const unsigned char *m_data;
|
const unsigned char *m_data;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "db-leveldb.h"
|
#include "db-leveldb.h"
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
inline int64_t stoi64(const std::string &s) {
|
inline int64_t stoi64(const std::string &s) {
|
||||||
std::stringstream tmp(s);
|
std::stringstream tmp(s);
|
||||||
@ -69,7 +70,7 @@ DBBlock DBLevelDB::getBlockOnPos(int x, int y, int z)
|
|||||||
|
|
||||||
status = m_db->Get(leveldb::ReadOptions(), i64tos(iPos), &datastr);
|
status = m_db->Get(leveldb::ReadOptions(), i64tos(iPos), &datastr);
|
||||||
if(status.ok()) {
|
if(status.ok()) {
|
||||||
block = DBBlock( iPos, std::basic_string<unsigned char>( (const unsigned char*) datastr.c_str(), datastr.size() ) );
|
block = DBBlock( iPos, ustring( (const unsigned char*) datastr.c_str(), datastr.size() ) );
|
||||||
m_blocksReadCount++;
|
m_blocksReadCount++;
|
||||||
m_blocksUnCachedCount++;
|
m_blocksUnCachedCount++;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "db-sqlite3.h"
|
#include "db-sqlite3.h"
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <unistd.h> // for usleep
|
#include <unistd.h> // for usleep
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
|
|
||||||
DBSQLite3::DBSQLite3(const std::string &mapdir) :
|
DBSQLite3::DBSQLite3(const std::string &mapdir) :
|
||||||
@ -138,7 +139,7 @@ DBBlock DBSQLite3::getBlockOnPosRaw(sqlite3_int64 psPos)
|
|||||||
sqlite3_int64 blocknum = sqlite3_column_int64(m_blockOnPosStatement, 0);
|
sqlite3_int64 blocknum = sqlite3_column_int64(m_blockOnPosStatement, 0);
|
||||||
const unsigned char *data = reinterpret_cast<const unsigned char *>(sqlite3_column_blob(m_blockOnPosStatement, 1));
|
const unsigned char *data = reinterpret_cast<const unsigned char *>(sqlite3_column_blob(m_blockOnPosStatement, 1));
|
||||||
int size = sqlite3_column_bytes(m_blockOnPosStatement, 1);
|
int size = sqlite3_column_bytes(m_blockOnPosStatement, 1);
|
||||||
block = DBBlock(blocknum, std::basic_string<unsigned char>(data, size));
|
block = DBBlock(blocknum, ustring(data, size));
|
||||||
m_blocksUnCachedCount++;
|
m_blocksUnCachedCount++;
|
||||||
//std::cerr << "Read block " << blocknum << " from database" << std::endl;
|
//std::cerr << "Read block " << blocknum << " from database" << std::endl;
|
||||||
break;
|
break;
|
||||||
@ -182,7 +183,7 @@ void DBSQLite3::cacheBlocks(sqlite3_stmt *SQLstatement)
|
|||||||
sqlite3_int64 blocknum = sqlite3_column_int64(SQLstatement, 0);
|
sqlite3_int64 blocknum = sqlite3_column_int64(SQLstatement, 0);
|
||||||
const unsigned char *data = reinterpret_cast<const unsigned char *>(sqlite3_column_blob(SQLstatement, 1));
|
const unsigned char *data = reinterpret_cast<const unsigned char *>(sqlite3_column_blob(SQLstatement, 1));
|
||||||
int size = sqlite3_column_bytes(SQLstatement, 1);
|
int size = sqlite3_column_bytes(SQLstatement, 1);
|
||||||
m_blockCache[blocknum] = DBBlock(blocknum, std::basic_string<unsigned char>(data, size));
|
m_blockCache[blocknum] = DBBlock(blocknum, ustring(data, size));
|
||||||
m_blocksCachedCount++;
|
m_blocksCachedCount++;
|
||||||
//std::cerr << "Cache block " << blocknum << " from database" << std::endl;
|
//std::cerr << "Cache block " << blocknum << " from database" << std::endl;
|
||||||
} else if (result == SQLITE_BUSY) { // Wait some time and try again
|
} else if (result == SQLITE_BUSY) { // Wait some time and try again
|
||||||
|
Loading…
x
Reference in New Issue
Block a user