diff --git a/source/graphics/LOSTexture.cpp b/source/graphics/LOSTexture.cpp index 8048b70b7c..107cccd3ab 100644 --- a/source/graphics/LOSTexture.cpp +++ b/source/graphics/LOSTexture.cpp @@ -194,9 +194,9 @@ void CLOSTexture::GenerateBitmap(ICmpRangeManager::CLosQuerier los, u8* losData, // Fill in the visibility data for (size_t i = 0; i < w; ++i) { - if (los.IsVisible(i, j)) + if (los.IsVisible_UncheckedRange(i, j)) *dataPtr++ = 255; - else if (los.IsExplored(i, j)) + else if (los.IsExplored_UncheckedRange(i, j)) *dataPtr++ = 127; else *dataPtr++ = 0; diff --git a/source/simulation2/components/CCmpRangeManager.cpp b/source/simulation2/components/CCmpRangeManager.cpp index 67e170398f..eca60942fc 100644 --- a/source/simulation2/components/CCmpRangeManager.cpp +++ b/source/simulation2/components/CCmpRangeManager.cpp @@ -1194,7 +1194,7 @@ public: if (!LosIsOffWorld(i, j)) { overallVisibleVertices++; - exploredVertices += (i32)los.IsExplored(i, j); + exploredVertices += (i32)los.IsExplored_UncheckedRange(i, j); } } } diff --git a/source/simulation2/components/ICmpRangeManager.h b/source/simulation2/components/ICmpRangeManager.h index 9dcd569b11..03d4ebd9d8 100644 --- a/source/simulation2/components/ICmpRangeManager.h +++ b/source/simulation2/components/ICmpRangeManager.h @@ -185,10 +185,40 @@ public: public: /** * Returns whether the given vertex is visible (i.e. is within a unit's LOS). - * i and j must be in the range [0, verticesPerSide). */ inline bool IsVisible(ssize_t i, ssize_t j) { + if (!(i >= 0 && j >= 0 && i < m_VerticesPerSide && j < m_VerticesPerSide)) + return false; + + // Check high bit of each bit-pair + if ((m_Data[j*m_VerticesPerSide + i] & m_PlayerMask) & 0xAAAAAAAAu) + return true; + else + return false; + } + + /** + * Returns whether the given vertex is explored (i.e. was (or still is) within a unit's LOS). + */ + inline bool IsExplored(ssize_t i, ssize_t j) + { + if (!(i >= 0 && j >= 0 && i < m_VerticesPerSide && j < m_VerticesPerSide)) + return false; + + // Check low bit of each bit-pair + if ((m_Data[j*m_VerticesPerSide + i] & m_PlayerMask) & 0x55555555u) + return true; + else + return false; + } + + /** + * Returns whether the given vertex is visible (i.e. is within a unit's LOS). + * i and j must be in the range [0, verticesPerSide), else behaviour is undefined. + */ + inline bool IsVisible_UncheckedRange(ssize_t i, ssize_t j) + { #ifndef NDEBUG debug_assert(i >= 0 && j >= 0 && i < m_VerticesPerSide && j < m_VerticesPerSide); #endif @@ -201,9 +231,9 @@ public: /** * Returns whether the given vertex is explored (i.e. was (or still is) within a unit's LOS). - * i and j must be in the range [0, verticesPerSide). + * i and j must be in the range [0, verticesPerSide), else behaviour is undefined. */ - inline bool IsExplored(ssize_t i, ssize_t j) + inline bool IsExplored_UncheckedRange(ssize_t i, ssize_t j) { #ifndef NDEBUG debug_assert(i >= 0 && j >= 0 && i < m_VerticesPerSide && j < m_VerticesPerSide);