From 6fb30a40f54f2f277f287ccb8d1f209c18dc92ac Mon Sep 17 00:00:00 2001 From: David Williams Date: Fri, 9 Aug 2013 20:39:17 +0200 Subject: [PATCH 1/2] Bringing across Region enhancements from Cubiquity branch. --- .../PolyVoxCore/include/PolyVoxCore/Region.h | 43 +++++++++++++++++++ library/PolyVoxCore/source/Region.cpp | 27 +++++++++--- 2 files changed, 64 insertions(+), 6 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Region.h b/library/PolyVoxCore/include/PolyVoxCore/Region.h index 7312bc67..8d654cd0 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Region.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Region.h @@ -74,6 +74,12 @@ namespace PolyVox /// Inequality Operator. bool operator!=(const Region& rhs) const; + /// Gets the 'x' position of the centre. + int32_t getCentreX(void) const; + /// Gets the 'y' position of the centre. + int32_t getCentreY(void) const; + /// Gets the 'z' position of the centrer. + int32_t getCentreZ(void) const; /// Gets the 'x' position of the lower corner. int32_t getLowerX(void) const; /// Gets the 'y' position of the lower corner. @@ -87,6 +93,8 @@ namespace PolyVox /// Gets the 'z' position of the upper corner. int32_t getUpperZ(void) const; + /// Gets the centre of the region + Vector3DInt32 getCentre(void) const; /// Gets the position of the lower corner. Vector3DInt32 getLowerCorner(void) const; /// Gets the position of the upper corner. @@ -202,6 +210,9 @@ namespace PolyVox int32_t m_iUpperZ; }; + // Non-member functions + bool intersects(const Region& a, const Region& b); + // Non-member overloaded operators. /// Stream insertion operator. std::ostream& operator<<(std::ostream& os, const Region& region); @@ -210,6 +221,30 @@ namespace PolyVox // 'inline' keyword is used for the definition rather than the declaration. // See also http://www.parashift.com/c++-faq-lite/inline-functions.html + /** + * \return The 'x' position of the centre. + */ + inline int32_t Region::getCentreX(void) const + { + return (m_iLowerX + m_iUpperX) / 2; + } + + /** + * \return The 'y' position of the centre. + */ + inline int32_t Region::getCentreY(void) const + { + return (m_iLowerY + m_iUpperY) / 2; + } + + /** + * \return The 'z' position of the centre. + */ + inline int32_t Region::getCentreZ(void) const + { + return (m_iLowerZ + m_iUpperZ) / 2; + } + /** * \return The 'x' position of the lower corner. */ @@ -258,6 +293,14 @@ namespace PolyVox return m_iUpperZ; } + /** + * \return The position of the lower corner. + */ + inline Vector3DInt32 Region::getCentre(void) const + { + return Vector3DInt32(getCentreX(), getCentreY(), getCentreZ()); + } + /** * \return The position of the lower corner. */ diff --git a/library/PolyVoxCore/source/Region.cpp b/library/PolyVoxCore/source/Region.cpp index 4ac22dbd..50e837af 100644 --- a/library/PolyVoxCore/source/Region.cpp +++ b/library/PolyVoxCore/source/Region.cpp @@ -150,12 +150,12 @@ namespace PolyVox && (m_iUpperX == rhs.m_iUpperX) && (m_iUpperY == rhs.m_iUpperY) && (m_iUpperZ == rhs.m_iUpperZ)); } - //////////////////////////////////////////////////////////////////////////////// - /// Two regions are considered different if any of their extents differ. - /// \param rhs The Region to compare to. - /// \return true if the Regions are different. - /// \sa operator== - //////////////////////////////////////////////////////////////////////////////// + /** + * Two regions are considered different if any of their extents differ. + * \param rhs The Region to compare to. + * \return true if the Regions are different. + * \sa operator== + */ bool Region::operator!=(const Region& rhs) const { return !(*this == rhs); @@ -488,6 +488,21 @@ namespace PolyVox shrink(v3dAmount.getX(), v3dAmount.getY(), v3dAmount.getZ()); } + /** + * This function only returns true if the regions are really intersecting and not simply touching. + */ + + bool intersects(const Region& a, const Region& b) + { + // No intersection if seperated along an axis. + if(a.getUpperX() < b.getLowerX() || a.getLowerX() > b.getUpperX()) return false; + if(a.getUpperY() < b.getLowerY() || a.getLowerY() > b.getUpperY()) return false; + if(a.getUpperZ() < b.getLowerZ() || a.getLowerZ() > b.getUpperZ()) return false; + + // Overlapping on all axes means Regions are intersecting. + return true; + } + /** * Enables the Region to be used intuitively with output streams such as cout. * \param os The output stream to write to. From 07f1ca42d2322ba613f5141c2efee7c730931919 Mon Sep 17 00:00:00 2001 From: David Williams Date: Mon, 12 Aug 2013 21:04:55 +0200 Subject: [PATCH 2/2] Uncompressed blocks are now flushed before compressed blocks. --- library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index c9fe8fa6..133a6ef8 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -435,8 +435,14 @@ namespace PolyVox void LargeVolume::flushAll() { typename CompressedBlockMap::iterator i; + //Replaced the for loop here as the call to //eraseBlock was invalidating the iterator. + while(m_pUncompressedBlockCache.size() > 0) + { + eraseBlock(m_pUncompressedBlockCache.begin()); + } + while(m_pBlocks.size() > 0) { eraseBlock(m_pBlocks.begin());