diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h index 934336bc..a87f2796 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h @@ -334,6 +334,7 @@ namespace PolyVox void eraseBlock(typename std::map, BlockPositionCompare>::iterator itBlock) const; // The block data + mutable std::map m_pUncompressedBlockCache; mutable std::map, BlockPositionCompare> m_pBlocks; // The cache of uncompressed blocks. The uncompressed block data and the timestamps are stored here rather diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index fac37e2a..db604532 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -638,6 +638,27 @@ namespace PolyVox //Get the block and mark that we accessed it Block* block = getCompressedBlock(uBlockX, uBlockY, uBlockZ); + + typename std::map::iterator itUncompressedBlock = m_pUncompressedBlockCache.find(v3dBlockPos); + // check whether the block is already loaded + if(itUncompressedBlock == m_pUncompressedBlockCache.end()) + { + VoxelType* pUncompressedBlock = new VoxelType[m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength]; + + void* pSrcData = reinterpret_cast(block->m_pCompressedData); + void* pDstData = reinterpret_cast(pUncompressedBlock); + uint32_t uSrcLength = block->m_uCompressedDataLength; + uint32_t uDstLength = m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength * sizeof(VoxelType); + + //MinizCompressor compressor; + //RLECompressor compressor; + uint32_t uUncompressedLength = m_pCompressor->decompress(pSrcData, uSrcLength, pDstData, uDstLength); + + POLYVOX_ASSERT(uUncompressedLength == m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength * sizeof(VoxelType), "Destination length has changed."); + + itUncompressedBlock = m_pUncompressedBlockCache.insert(std::make_pair(v3dBlockPos, pUncompressedBlock)).first; + } + if(block->hasUncompressedData()) { return block;