Skip to content

Commit

Permalink
Improvements to Node name/ID mapping code
Browse files Browse the repository at this point in the history
* Clean m_nameMap between blocks
* Warn about invalid node name IDs
* Early drop of non-significant blocks
  • Loading branch information
Nestorfish authored and sfan5 committed Oct 9, 2016
1 parent 09945ca commit c45965e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions TileGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ void TileGenerator::renderMap()

m_blockAirId = -1;
m_blockIgnoreId = -1;
m_nameMap.clear();
// Read mapping
if (version >= 22) {
dataOffset++; // mapping version
Expand All @@ -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
Expand Down Expand Up @@ -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()) {
Expand Down

0 comments on commit c45965e

Please sign in to comment.