Adding new caching mechanism.
This commit is contained in:
parent
a589c6e4ac
commit
abd1920d80
@ -334,6 +334,7 @@ namespace PolyVox
|
|||||||
void eraseBlock(typename std::map<Vector3DInt32, Block<VoxelType>, BlockPositionCompare>::iterator itBlock) const;
|
void eraseBlock(typename std::map<Vector3DInt32, Block<VoxelType>, BlockPositionCompare>::iterator itBlock) const;
|
||||||
|
|
||||||
// The block data
|
// The block data
|
||||||
|
mutable std::map<Vector3DInt32, VoxelType*, BlockPositionCompare> m_pUncompressedBlockCache;
|
||||||
mutable std::map<Vector3DInt32, Block<VoxelType>, BlockPositionCompare> m_pBlocks;
|
mutable std::map<Vector3DInt32, Block<VoxelType>, BlockPositionCompare> m_pBlocks;
|
||||||
|
|
||||||
// The cache of uncompressed blocks. The uncompressed block data and the timestamps are stored here rather
|
// The cache of uncompressed blocks. The uncompressed block data and the timestamps are stored here rather
|
||||||
|
@ -638,6 +638,27 @@ namespace PolyVox
|
|||||||
//Get the block and mark that we accessed it
|
//Get the block and mark that we accessed it
|
||||||
Block<VoxelType>* block = getCompressedBlock(uBlockX, uBlockY, uBlockZ);
|
Block<VoxelType>* block = getCompressedBlock(uBlockX, uBlockY, uBlockZ);
|
||||||
|
|
||||||
|
|
||||||
|
typename std::map<Vector3DInt32, VoxelType*, BlockPositionCompare>::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<void*>(block->m_pCompressedData);
|
||||||
|
void* pDstData = reinterpret_cast<void*>(pUncompressedBlock);
|
||||||
|
uint32_t uSrcLength = block->m_uCompressedDataLength;
|
||||||
|
uint32_t uDstLength = m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength * sizeof(VoxelType);
|
||||||
|
|
||||||
|
//MinizCompressor compressor;
|
||||||
|
//RLECompressor<VoxelType, uint16_t> 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())
|
if(block->hasUncompressedData())
|
||||||
{
|
{
|
||||||
return block;
|
return block;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user