From 177eb16becfd3c902ef98de946f94744fc7a0578 Mon Sep 17 00:00:00 2001 From: David Williams Date: Wed, 17 Sep 2014 21:40:27 +0200 Subject: [PATCH] Tidying and commenting. --- .../include/PolyVoxCore/LargeVolume.h | 2 - .../include/PolyVoxCore/LargeVolume.inl | 40 +++++-------------- 2 files changed, 11 insertions(+), 31 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h index df966f6f..f5b22a07 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h @@ -315,8 +315,6 @@ namespace PolyVox std::shared_ptr< UncompressedBlock > getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const; - void eraseBlock(typename SharedPtrBlockMap::iterator itUncompressedBlock) const; - // The block data mutable WeakPtrBlockMap m_pAllBlocks; mutable SharedPtrBlockMap m_pRecentlyUsedBlocks; diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index 38f05adf..bb164054 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -407,10 +407,10 @@ namespace PolyVox //Replaced the for loop here as the call to //eraseBlock was invalidating the iterator. - while (m_pRecentlyUsedBlocks.size() > 0) + /*while (m_pRecentlyUsedBlocks.size() > 0) { eraseBlock(m_pRecentlyUsedBlocks.begin()); - } + }*/ } //////////////////////////////////////////////////////////////////////////////// @@ -419,7 +419,7 @@ namespace PolyVox template void LargeVolume::flush(Region regFlush) { - POLYVOX_THROW_IF(!m_pPager, invalid_operation, "You cannot flush data out of the volume because it was created without a pager attached."); + /*POLYVOX_THROW_IF(!m_pPager, invalid_operation, "You cannot flush data out of the volume because it was created without a pager attached."); Vector3DInt32 v3dStart; for(int i = 0; i < 3; i++) @@ -454,7 +454,7 @@ namespace PolyVox } } // for z } // for y - } // for x + } // for x*/ } //////////////////////////////////////////////////////////////////////////////// @@ -501,28 +501,6 @@ namespace PolyVox this->m_fDiagonalLength = sqrtf(static_cast(this->getWidth() * this->getWidth() + this->getHeight() * this->getHeight() + this->getDepth() * this->getDepth())); } - template - void LargeVolume::eraseBlock(typename SharedPtrBlockMap::iterator itUncompressedBlock) const - { - POLYVOX_ASSERT(m_pPager, "A block should never be erased if there is no pager attached to handle it"); - - std::shared_ptr< UncompressedBlock > pUncompressedBlock = itUncompressedBlock->second; - - // This should never happen as blocks are deleted based on being least recently used. - // I the case that we are flushing we delete all blocks, but the flush function will - // reset the 'm_pLastAccessedBlock' anyway to prevent it being accidentally reused. - //POLYVOX_ASSERT(pUncompressedBlock != m_pLastAccessedBlock, "Attempted to delete last accessed block."); - - // Before deleting the block we may need to recompress its data. We - // only do this if the data has been modified since it was decompressed. - - - //delete itUncompressedBlock->second; - - // We can now remove the block data from memory. - m_pRecentlyUsedBlocks.erase(itUncompressedBlock); - } - template std::shared_ptr< UncompressedBlock > LargeVolume::getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const { @@ -578,12 +556,16 @@ namespace PolyVox // The block was not found so we will create a new one. pUncompressedBlock = std::make_shared< UncompressedBlock >(v3dBlockPos, m_uBlockSideLength, m_pPager); + // As we are loading a new block we should try to ensure we don't go over our target memory usage. while (m_pRecentlyUsedBlocks.size() + 1 > m_uMaxNumberOfUncompressedBlocks) // +1 ready for new block we will add next. { + // This should never hit, because it should not have been possible for + // the user to limit the number of blocks if they did not provide a pager. + POLYVOX_ASSERT(m_pPager, "A valid pager is required to limit number of blocks"); + // Find the least recently used block. Hopefully this isn't too slow. - typename SharedPtrBlockMap::iterator i; typename SharedPtrBlockMap::iterator itUnloadBlock = m_pRecentlyUsedBlocks.begin(); - for (i = m_pRecentlyUsedBlocks.begin(); i != m_pRecentlyUsedBlocks.end(); i++) + for (typename SharedPtrBlockMap::iterator i = m_pRecentlyUsedBlocks.begin(); i != m_pRecentlyUsedBlocks.end(); i++) { if (i->second->m_uBlockLastAccessed < itUnloadBlock->second->m_uBlockLastAccessed) { @@ -592,7 +574,7 @@ namespace PolyVox } // Erase the least recently used block - eraseBlock(itUnloadBlock); + m_pRecentlyUsedBlocks.erase(itUnloadBlock); } // Add our new block to the maps.