From c45965eb8d4e30b8efc3e881b64f5abbdc4e046c Mon Sep 17 00:00:00 2001 From: Christophe Le Roy Date: Sat, 24 Sep 2016 21:08:26 +0200 Subject: [PATCH] Improvements to Node name/ID mapping code * Clean m_nameMap between blocks * Warn about invalid node name IDs * Early drop of non-significant blocks --- TileGenerator.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/TileGenerator.cpp b/TileGenerator.cpp index f547f15..26e91f5 100644 --- a/TileGenerator.cpp +++ b/TileGenerator.cpp @@ -441,6 +441,7 @@ void TileGenerator::renderMap() m_blockAirId = -1; m_blockIgnoreId = -1; + m_nameMap.clear(); // Read mapping if (version >= 22) { dataOffset++; // mapping version @@ -463,6 +464,9 @@ void TileGenerator::renderMap() } dataOffset += nameLen; } + // Skip block if made of only air or ignore nodes + if (m_nameMap.empty()) + continue; } // Node timers @@ -518,12 +522,14 @@ inline void TileGenerator::renderMapBlock(const ustring &mapBlock, const BlockPo for (int y = maxY; y >= minY; --y) { int position = x + (y << 4) + (z << 8); int content = readBlockContent(mapData, version, position); - if (content == m_blockIgnoreId || content == m_blockAirId) { + if (content == m_blockAirId || content == m_blockIgnoreId) { continue; } NameMap::iterator blockName = m_nameMap.find(content); - if (blockName == m_nameMap.end()) + if (blockName == m_nameMap.end()) { + std::cerr << "Skipping node with invalid ID." << std::endl; continue; + } const string &name = blockName->second; ColorMap::const_iterator color = m_colorMap.find(name); if (color != m_colorMap.end()) {