Skip to content

Commit 6133aff

Browse files
committed
Small cast cleaning.
1 parent a69165a commit 6133aff

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

TileGenerator.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ static inline int unsignedToSigned(long i, long max_positive)
4141
}
4242
}
4343

44-
static inline int readU16(const char *data)
44+
static inline uint16_t readU16(const unsigned char *data)
4545
{
46-
return uint8_t(data[0]) * 256 + uint8_t(data[1]);
46+
return data[0] << 8 | data[1];
4747
}
4848

4949
static inline int rgb2int(uint8_t r, uint8_t g, uint8_t b)
@@ -70,7 +70,7 @@ static inline int readBlockContent(const unsigned char *mapData, int version, in
7070
}
7171
}
7272

73-
static inline std::string zlibDecompress(const char *data, std::size_t size, std::size_t *processed)
73+
static inline std::string zlibDecompress(const unsigned char *data, std::size_t size, std::size_t *processed)
7474
{
7575
string buffer;
7676
const size_t BUFSIZE = 128 * 1024;
@@ -87,7 +87,7 @@ static inline std::string zlibDecompress(const char *data, std::size_t size, std
8787
throw DecompressError();
8888
}
8989

90-
strm.next_in = reinterpret_cast<Bytef *>(const_cast<char *>(data));
90+
strm.next_in = const_cast<unsigned char *>(data);
9191
int ret = 0;
9292
do {
9393
strm.avail_out = BUFSIZE;
@@ -98,7 +98,7 @@ static inline std::string zlibDecompress(const char *data, std::size_t size, std
9898
if (ret != Z_STREAM_END) {
9999
throw DecompressError();
100100
}
101-
*processed = (const char *)strm.next_in - (const char *)data;
101+
*processed = strm.next_in - data;
102102
(void)inflateEnd(&strm);
103103

104104
return buffer;
@@ -358,7 +358,7 @@ void TileGenerator::renderMap()
358358
const BlockList &blockStack = blocks[xPos];
359359
for (BlockList::const_iterator it = blockStack.begin(); it != blockStack.end(); ++it) {
360360
const BlockPos &pos = it->first;
361-
const char *data = it->second.c_str();
361+
const unsigned char *data = it->second.c_str();
362362
size_t length = it->second.length();
363363

364364
uint8_t version = data[0];
@@ -387,7 +387,7 @@ void TileGenerator::renderMap()
387387
if (version == 24) {
388388
uint8_t ver = data[dataOffset++];
389389
if (ver == 1) {
390-
int num = readU16(data + dataOffset);
390+
uint16_t num = readU16(data + dataOffset);
391391
dataOffset += 2;
392392
dataOffset += 10 * num;
393393
}
@@ -399,7 +399,7 @@ void TileGenerator::renderMap()
399399
dataOffset += 2;
400400
for (int i = 0; i < staticObjectCount; ++i) {
401401
dataOffset += 13;
402-
int dataSize = readU16(data + dataOffset);
402+
uint16_t dataSize = readU16(data + dataOffset);
403403
dataOffset += dataSize + 2;
404404
}
405405
dataOffset += 4; // Skip timestamp
@@ -409,14 +409,14 @@ void TileGenerator::renderMap()
409409
// Read mapping
410410
if (version >= 22) {
411411
dataOffset++; // mapping version
412-
int numMappings = readU16(data + dataOffset);
412+
uint16_t numMappings = readU16(data + dataOffset);
413413
dataOffset += 2;
414414
for (int i = 0; i < numMappings; ++i) {
415-
int nodeId = readU16(data + dataOffset);
415+
uint16_t nodeId = readU16(data + dataOffset);
416416
dataOffset += 2;
417-
int nameLen = readU16(data + dataOffset);
417+
uint16_t nameLen = readU16(data + dataOffset);
418418
dataOffset += 2;
419-
string name = string(data + dataOffset, nameLen);
419+
string name = string(reinterpret_cast<const char *>(data) + dataOffset, nameLen);
420420
if (name == "air") {
421421
m_blockAirId = nodeId;
422422
}
@@ -433,7 +433,7 @@ void TileGenerator::renderMap()
433433
// Node timers
434434
if (version >= 25) {
435435
dataOffset++;
436-
int numTimers = readU16(data + dataOffset);
436+
uint16_t numTimers = readU16(data + dataOffset);
437437
dataOffset += 2;
438438
dataOffset += numTimers * 10;
439439
}
@@ -605,10 +605,10 @@ std::map<int, TileGenerator::BlockList> TileGenerator::getBlocksOnZ(int zPos, sq
605605
result = sqlite3_step(statement);
606606
if(result == SQLITE_ROW) {
607607
sqlite3_int64 blocknum = sqlite3_column_int64(statement, 0);
608-
const char *data = reinterpret_cast<const char *>(sqlite3_column_blob(statement, 1));
608+
const unsigned char *data = reinterpret_cast<const unsigned char *>(sqlite3_column_blob(statement, 1));
609609
int size = sqlite3_column_bytes(statement, 1);
610610
BlockPos pos = decodeBlockPos(blocknum);
611-
blocks[pos.x].push_back(Block(pos, string(data, size)));
611+
blocks[pos.x].push_back(Block(pos, std::basic_string<unsigned char>(data, size)));
612612
}
613613
else {
614614
break;

TileGenerator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class TileGenerator
7373
{
7474
private:
7575
typedef std::map<std::string, Color> ColorMap;
76-
typedef std::pair<BlockPos, std::string> Block;
76+
typedef std::pair<BlockPos, std::basic_string<unsigned char> > Block;
7777
typedef std::list<Block> BlockList;
7878

7979
public:

0 commit comments

Comments
 (0)