Added node name reading.

This commit is contained in:
Miroslav Bendík 2012-08-24 14:13:46 +02:00
parent feb945b1f9
commit 2319d5f0ed
2 changed files with 39 additions and 4 deletions

@ -266,7 +266,9 @@ void TileGenerator::renderMap()
string mapData = zlibDecompress(data + dataOffset, length - dataOffset, &processed);
dataOffset += processed;
string mapMetadata = zlibDecompress(data + dataOffset, length - dataOffset, &processed);
dataOffset += processed;
// Skip unused data
if (version <= 21) {
dataOffset += 2;
}
@ -274,11 +276,37 @@ void TileGenerator::renderMap()
dataOffset += 1;
}
if (version == 24) {
uint8_t ver = data[dataOffset + 1];
dataOffset++;
uint8_t ver = data[dataOffset++];
if (ver == 1) {
int num = int(data[dataOffset + 1]) * 256 + data[dataOffset + 2];
dataOffset += 10 * num + 2;
int 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;
int dataSize = readU16(data + dataOffset);
dataOffset += dataSize + 2;
}
dataOffset += 4; // Skip timestamp
// Read mapping
if (version >= 22) {
dataOffset++; // mapping version
int numMappings = readU16(data + dataOffset);
dataOffset += 2;
for (int i = 0; i < numMappings; ++i) {
int nodeId = readU16(data + dataOffset);
dataOffset += 2;
int nameLen = readU16(data + dataOffset);
dataOffset += 2;
dataOffset += nameLen;
m_nameMap[nodeId] = string(data + dataOffset, nameLen);
}
}
}
@ -373,3 +401,8 @@ inline std::string TileGenerator::zlibDecompress(const char *data, std::size_t s
return buffer;
}
inline int TileGenerator::readU16(const char *data)
{
return int(data[0]) * 256 + data[1];
}

@ -95,6 +95,7 @@ private:
std::map<int, BlockList> getBlocksOnZ(int zPos, sqlite3_stmt *statement) const;
void writeImage(const std::string &output);
inline std::string zlibDecompress(const char *data, std::size_t size, std::size_t *processed) const;
inline int readU16(const char *data);
private:
Color m_bgColor;
@ -115,6 +116,7 @@ private:
int m_imgWidth;
int m_imgHeight;
std::list<std::pair<int, int> > m_positions;
std::map<int, std::string> m_nameMap;
ColorMap m_colors;
static const int SectorXMin = -1500/16;