diff --git a/include/PolyVox/PagedVolume.h b/include/PolyVox/PagedVolume.h index 9126caab..f000bbb6 100644 --- a/include/PolyVox/PagedVolume.h +++ b/include/PolyVox/PagedVolume.h @@ -282,11 +282,7 @@ namespace PolyVox /// Assignment operator PagedVolume& operator=(const PagedVolume& rhs); - private: - - // FIXME - We can probably ove this into the constructor - void initialise(); - + private: std::shared_ptr getChunk(int32_t uChunkX, int32_t uChunkY, int32_t uChunkZ) const; void purgeNullPtrsFromAllChunks(void) const; @@ -310,10 +306,10 @@ namespace PolyVox typedef std::unordered_map > SharedPtrChunkMap; mutable SharedPtrChunkMap m_pRecentlyUsedChunks; - mutable uint32_t m_uTimestamper; - mutable Vector3DInt32 m_v3dLastAccessedChunkPos; - mutable std::shared_ptr m_pLastAccessedChunk; - uint32_t m_uChunkCountLimit; + mutable uint32_t m_uTimestamper = 0; + mutable Vector3DInt32 m_v3dLastAccessedChunkPos = Vector3DInt32(0, 0, 0); //There are no invalid positions, but initially the m_pLastAccessedChunk pointer will be null + mutable std::shared_ptr m_pLastAccessedChunk = nullptr; + uint32_t m_uChunkCountLimit = 0; // The size of the volume //Region m_regValidRegionInChunks; diff --git a/include/PolyVox/PagedVolume.inl b/include/PolyVox/PagedVolume.inl index c4dd07e7..f87d347b 100644 --- a/include/PolyVox/PagedVolume.inl +++ b/include/PolyVox/PagedVolume.inl @@ -42,7 +42,12 @@ namespace PolyVox { // Validation of parameters POLYVOX_THROW_IF(uTargetMemoryUsageInBytes < 1 * 1024 * 1024, std::invalid_argument, "Target memory usage is too small to be practical"); - POLYVOX_THROW_IF(uChunkSideLength > 256, std::invalid_argument, "Chunk size is too large to be practical"); + POLYVOX_THROW_IF(m_uChunkSideLength == 0, std::invalid_argument, "Chunk side length cannot be zero."); + POLYVOX_THROW_IF(m_uChunkSideLength > 256, std::invalid_argument, "Chunk size is too large to be practical."); + POLYVOX_THROW_IF(!isPowerOf2(m_uChunkSideLength), std::invalid_argument, "Chunk side length must be a power of two."); + + // Used to perform multiplications and divisions by bit shifting. + m_uChunkSideLengthPower = logBase2(m_uChunkSideLength); // Calculate the number of chunks based on the memory limit and the size of each chunk. uint32_t uChunkSizeInBytes = PagedVolume::Chunk::calculateSizeInBytes(m_uChunkSideLength); @@ -59,8 +64,6 @@ namespace PolyVox // Inform the user about the chosen memory configuration. POLYVOX_LOG_DEBUG("Memory usage limit for volume now set to " << (m_uChunkCountLimit * uChunkSizeInBytes) / (1024 * 1024) << "Mb (" << m_uChunkCountLimit << " chunks of " << uChunkSizeInBytes / 1024 << "Kb each)."); - - initialise(); } //////////////////////////////////////////////////////////////////////////////// @@ -73,7 +76,7 @@ namespace PolyVox template PagedVolume::PagedVolume(const PagedVolume& /*rhs*/) { - POLYVOX_THROW(not_implemented, "Volume copy constructor not implemented for performance reasons."); + POLYVOX_THROW(not_implemented, "Volume copy constructor not implemented to prevent accidental copying."); } //////////////////////////////////////////////////////////////////////////////// @@ -265,43 +268,6 @@ namespace PolyVox purgeNullPtrsFromAllChunks(); } - //////////////////////////////////////////////////////////////////////////////// - /// This function should probably be made internal... - //////////////////////////////////////////////////////////////////////////////// - template - void PagedVolume::initialise() - { - //Validate parameters - if(m_uChunkSideLength == 0) - { - POLYVOX_THROW(std::invalid_argument, "Chunk side length cannot be zero."); - } - - if(!isPowerOf2(m_uChunkSideLength)) - { - POLYVOX_THROW(std::invalid_argument, "Chunk side length must be a power of two."); - } - - m_uTimestamper = 0; - m_v3dLastAccessedChunkPos = Vector3DInt32(0,0,0); //There are no invalid positions, but initially the m_pLastAccessedChunk pointer will be null; - m_pLastAccessedChunk = nullptr; - - //Compute the chunk side length - m_uChunkSideLengthPower = logBase2(m_uChunkSideLength); - - /*m_regValidRegionInChunks.setLowerX(this->m_regValidRegion.getLowerX() >> m_uChunkSideLengthPower); - m_regValidRegionInChunks.setLowerY(this->m_regValidRegion.getLowerY() >> m_uChunkSideLengthPower); - m_regValidRegionInChunks.setLowerZ(this->m_regValidRegion.getLowerZ() >> m_uChunkSideLengthPower); - m_regValidRegionInChunks.setUpperX(this->m_regValidRegion.getUpperX() >> m_uChunkSideLengthPower); - m_regValidRegionInChunks.setUpperY(this->m_regValidRegion.getUpperY() >> m_uChunkSideLengthPower); - m_regValidRegionInChunks.setUpperZ(this->m_regValidRegion.getUpperZ() >> m_uChunkSideLengthPower);*/ - - //setMaxNumberOfChunks(m_uChunkCountLimit); - - //Clear the previous data - m_pRecentlyUsedChunks.clear(); - } - template std::shared_ptr::Chunk> PagedVolume::getChunk(int32_t uChunkX, int32_t uChunkY, int32_t uChunkZ) const {