From 704eeaf94829842b91e5a37ea5c2d56fd7b65250 Mon Sep 17 00:00:00 2001 From: David Williams Date: Tue, 16 Sep 2014 17:02:53 +0200 Subject: [PATCH] Work on supporting no pager being attached. --- .../include/PolyVoxCore/LargeVolume.h | 7 ---- .../include/PolyVoxCore/LargeVolume.inl | 32 ++++++++++++------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h index ca4f60d6..1f080523 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h @@ -334,13 +334,6 @@ namespace PolyVox uint8_t m_uBlockSideLengthPower; Pager* m_pPager; - - // Compressed data for an empty block (sometimes needed for initialisation). - //CompressedBlock* m_pCompressedEmptyBlock; - - // Whether we created the compressor or whether it was provided - // by the user. This controls whether we delete it on destruction. - //bool m_bIsOurCompressor; }; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index 4cbeb632..44116cd5 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -24,6 +24,7 @@ freely, subject to the following restrictions: #include "PolyVoxCore/Impl/ErrorHandling.h" #include +#include namespace PolyVox { @@ -46,9 +47,20 @@ namespace PolyVox :BaseVolume(regValid) { m_uBlockSideLength = uBlockSideLength; - m_pPager = pPager; + if (m_pPager) + { + // If a pager is available then we can set a sensible limit on our memory usage. + m_uMaxNumberOfUncompressedBlocks = 256; + } + else + { + // If there is no pager provided then we set the block limit to the maximum + // value to ensure the system never attempts to page blocks out of memory. + m_uMaxNumberOfUncompressedBlocks = (std::numeric_limits::max)(); + } + initialise(); } @@ -215,6 +227,8 @@ namespace PolyVox template void LargeVolume::setMaxNumberOfUncompressedBlocks(uint32_t uMaxNumberOfUncompressedBlocks) { + POLYVOX_THROW_IF(!m_pPager, invalid_operation, "You cannot limit the memory usage of the volume because it was created without a pager attached."); + //clearBlockCache(); /*if (m_pBlocks.size() > uMaxNumberOfBlocksInMemory) @@ -386,6 +400,8 @@ namespace PolyVox template void LargeVolume::flushAll() { + POLYVOX_THROW_IF(!m_pPager, invalid_operation, "You cannot flush data out of the volume because it was created without a pager attached."); + // Flushing will remove the most accessed block, so invalidate the pointer. m_pLastAccessedBlock = 0; @@ -403,6 +419,8 @@ 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."); + Vector3DInt32 v3dStart; for(int i = 0; i < 3; i++) { @@ -486,6 +504,8 @@ namespace PolyVox template void LargeVolume::eraseBlock(typename UncompressedBlockMap::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. @@ -549,16 +569,6 @@ namespace PolyVox //pUncompressedBlock = new UncompressedBlock(m_uBlockSideLength); pUncompressedBlock = std::make_shared< UncompressedBlock >(m_uBlockSideLength); - // An uncompressed bock is always backed by a compressed one, and this is created by getCompressedBlock() if it doesn't - // already exist. If it does already exist and has data then we bring this across into the ucompressed version. - /*if(getCompressedBlock(uBlockX, uBlockY, uBlockZ)->getData() != 0) - { - // FIXME - multiple getCompressedBlock() calls (including the one above) - CompressedBlock* pBlock = getCompressedBlock(uBlockX, uBlockY, ); - - m_pBlockCompressor->decompress(pBlock, pUncompressedBlock); - }*/ - // Pass the block to the Pager to give it a chance to initialise it with any data Vector3DInt32 v3dLower(uBlockX << m_uBlockSideLengthPower, uBlockY << m_uBlockSideLengthPower, uBlockZ << m_uBlockSideLengthPower); Vector3DInt32 v3dUpper = v3dLower + Vector3DInt32(m_uBlockSideLength - 1, m_uBlockSideLength - 1, m_uBlockSideLength - 1);