From a15bc300719f262ff2de03f0345e1d1619653e2b Mon Sep 17 00:00:00 2001 From: Rogier Date: Sun, 16 Feb 2014 19:08:09 +0100 Subject: [PATCH] Fix computation of block number bounds (off-by-one) The block numbers could be off by one due to incorrect rounding. m_geom* now contain the minimum and maximum block numbers that should be in the map. --- TileGenerator.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/TileGenerator.cpp b/TileGenerator.cpp index 9040dc0..c726385 100644 --- a/TileGenerator.cpp +++ b/TileGenerator.cpp @@ -187,13 +187,13 @@ void TileGenerator::setShading(bool shading) void TileGenerator::setGeometry(int x, int y, int w, int h) { if (x > 0) { - m_geomX = (x + 15) / 16; + m_geomX = x / 16; } else { m_geomX = (x - 15) / 16; } if (y > 0) { - m_geomY = (y + 15) / 16; + m_geomY = y / 16; } else { m_geomY = (y - 15) / 16; @@ -203,13 +203,13 @@ void TileGenerator::setGeometry(int x, int y, int w, int h) int y2 = y + h; if (x2 > 0) { - m_geomX2 = (x2 + 15) / 16; + m_geomX2 = x2 / 16; } else { m_geomX2 = (x2 - 15) / 16; } if (y2 > 0) { - m_geomY2 = (y2 + 15) / 16; + m_geomY2 = y2 / 16; } else { m_geomY2 = (y2 - 15) / 16; @@ -308,7 +308,7 @@ void TileGenerator::loadBlocks() std::vector vec = m_db->getBlockPos(); for(unsigned int i = 0; i < vec.size(); i++) { BlockPos pos = decodeBlockPos(vec[i]); - if (pos.x < m_geomX || pos.x >= m_geomX2 || pos.z < m_geomY || pos.z >= m_geomY2) { + if (pos.x < m_geomX || pos.x > m_geomX2 || pos.z < m_geomY || pos.z > m_geomY2) { continue; } if (pos.y < m_yMin * 16) {