Refactoring some LargeVolume code...
This commit is contained in:
parent
a2210fc3f0
commit
900e4e0ecd
@ -363,7 +363,7 @@ namespace PolyVox
|
|||||||
//than in the Block class. This is so that in the future each VolumeIterator might to maintain its own cache
|
//than in the Block class. This is so that in the future each VolumeIterator might to maintain its own cache
|
||||||
//of blocks. However, this could mean the same block data is uncompressed and modified in more than one
|
//of blocks. However, this could mean the same block data is uncompressed and modified in more than one
|
||||||
//location in memory... could be messy with threading.
|
//location in memory... could be messy with threading.
|
||||||
mutable std::vector< LoadedBlock* > m_vecUncompressedBlockCache;
|
mutable std::vector< LoadedBlock* > m_vecBlocksWithUncompressedData;
|
||||||
mutable uint32_t m_uTimestamper;
|
mutable uint32_t m_uTimestamper;
|
||||||
mutable Vector3DInt32 m_v3dLastAccessedBlockPos;
|
mutable Vector3DInt32 m_v3dLastAccessedBlockPos;
|
||||||
mutable Block<VoxelType>* m_pLastAccessedBlock;
|
mutable Block<VoxelType>* m_pLastAccessedBlock;
|
||||||
|
@ -469,11 +469,11 @@ namespace PolyVox
|
|||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
void LargeVolume<VoxelType>::clearBlockCache(void)
|
void LargeVolume<VoxelType>::clearBlockCache(void)
|
||||||
{
|
{
|
||||||
for(uint32_t ct = 0; ct < m_vecUncompressedBlockCache.size(); ct++)
|
for(uint32_t ct = 0; ct < m_vecBlocksWithUncompressedData.size(); ct++)
|
||||||
{
|
{
|
||||||
m_vecUncompressedBlockCache[ct]->block.destroyUncompressedData();
|
m_vecBlocksWithUncompressedData[ct]->block.destroyUncompressedData();
|
||||||
}
|
}
|
||||||
m_vecUncompressedBlockCache.clear();
|
m_vecBlocksWithUncompressedData.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -544,23 +544,22 @@ namespace PolyVox
|
|||||||
|
|
||||||
m_pPager->dataOverflowHandler(ConstVolumeProxy, reg);
|
m_pPager->dataOverflowHandler(ConstVolumeProxy, reg);
|
||||||
}
|
}
|
||||||
if(m_pCompressor)
|
|
||||||
|
for(uint32_t ct = 0; ct < m_vecBlocksWithUncompressedData.size(); ct++)
|
||||||
{
|
{
|
||||||
for(uint32_t ct = 0; ct < m_vecUncompressedBlockCache.size(); ct++)
|
// find the block in the uncompressed cache
|
||||||
|
if(m_vecBlocksWithUncompressedData[ct] == &(itBlock->second))
|
||||||
{
|
{
|
||||||
// find the block in the uncompressed cache
|
// TODO: compression is unneccessary? or will not compressing this cause a memleak?
|
||||||
if(m_vecUncompressedBlockCache[ct] == &(itBlock->second))
|
itBlock->second.block.destroyUncompressedData();
|
||||||
{
|
// put last object in cache here
|
||||||
// TODO: compression is unneccessary? or will not compressing this cause a memleak?
|
m_vecBlocksWithUncompressedData[ct] = m_vecBlocksWithUncompressedData.back();
|
||||||
itBlock->second.block.destroyUncompressedData();
|
// decrease cache size by one since last element is now in here twice
|
||||||
// put last object in cache here
|
m_vecBlocksWithUncompressedData.resize(m_vecBlocksWithUncompressedData.size()-1);
|
||||||
m_vecUncompressedBlockCache[ct] = m_vecUncompressedBlockCache.back();
|
break;
|
||||||
// decrease cache size by one since last element is now in here twice
|
|
||||||
m_vecUncompressedBlockCache.resize(m_vecUncompressedBlockCache.size()-1);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pBlocks.erase(itBlock);
|
m_pBlocks.erase(itBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -635,7 +634,7 @@ namespace PolyVox
|
|||||||
// Blocks start out compressed - should we change this?
|
// Blocks start out compressed - should we change this?
|
||||||
// Or maybe we should just 'seed' them with compressed data,
|
// Or maybe we should just 'seed' them with compressed data,
|
||||||
// rather than creating an empty block and then compressing?
|
// rather than creating an empty block and then compressing?
|
||||||
newBlock.block.destroyUncompressedData();
|
//newBlock.block.destroyUncompressedData();
|
||||||
|
|
||||||
itBlock = m_pBlocks.insert(std::make_pair(v3dBlockPos, newBlock)).first;
|
itBlock = m_pBlocks.insert(std::make_pair(v3dBlockPos, newBlock)).first;
|
||||||
|
|
||||||
@ -670,7 +669,7 @@ namespace PolyVox
|
|||||||
}
|
}
|
||||||
|
|
||||||
//If we are allowed to compress then check whether we need to
|
//If we are allowed to compress then check whether we need to
|
||||||
if((m_pCompressor) && (m_vecUncompressedBlockCache.size() == m_uMaxNumberOfUncompressedBlocks))
|
if(m_vecBlocksWithUncompressedData.size() == m_uMaxNumberOfUncompressedBlocks)
|
||||||
{
|
{
|
||||||
int32_t leastRecentlyUsedBlockIndex = -1;
|
int32_t leastRecentlyUsedBlockIndex = -1;
|
||||||
uint32_t uLeastRecentTimestamp = (std::numeric_limits<uint32_t>::max)();
|
uint32_t uLeastRecentTimestamp = (std::numeric_limits<uint32_t>::max)();
|
||||||
@ -678,25 +677,25 @@ namespace PolyVox
|
|||||||
//Currently we find the oldest block by iterating over the whole array. Of course we could store the blocks sorted by
|
//Currently we find the oldest block by iterating over the whole array. Of course we could store the blocks sorted by
|
||||||
//timestamp (set, priority_queue, etc) but then we'll need to move them around as the timestamp changes. Can come back
|
//timestamp (set, priority_queue, etc) but then we'll need to move them around as the timestamp changes. Can come back
|
||||||
//to this if it proves to be a bottleneck (compraed to the cost of actually doing the compression/decompression).
|
//to this if it proves to be a bottleneck (compraed to the cost of actually doing the compression/decompression).
|
||||||
for(uint32_t ct = 0; ct < m_vecUncompressedBlockCache.size(); ct++)
|
for(uint32_t ct = 0; ct < m_vecBlocksWithUncompressedData.size(); ct++)
|
||||||
{
|
{
|
||||||
if(m_vecUncompressedBlockCache[ct]->timestamp < uLeastRecentTimestamp)
|
if(m_vecBlocksWithUncompressedData[ct]->timestamp < uLeastRecentTimestamp)
|
||||||
{
|
{
|
||||||
uLeastRecentTimestamp = m_vecUncompressedBlockCache[ct]->timestamp;
|
uLeastRecentTimestamp = m_vecBlocksWithUncompressedData[ct]->timestamp;
|
||||||
leastRecentlyUsedBlockIndex = ct;
|
leastRecentlyUsedBlockIndex = ct;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Compress the least recently used block.
|
//Compress the least recently used block.
|
||||||
m_vecUncompressedBlockCache[leastRecentlyUsedBlockIndex]->block.destroyUncompressedData();
|
m_vecBlocksWithUncompressedData[leastRecentlyUsedBlockIndex]->block.destroyUncompressedData();
|
||||||
|
|
||||||
//We don't actually remove any elements from this vector, we
|
//We don't actually remove any elements from this vector, we
|
||||||
//simply change the pointer to point at the new uncompressed bloack.
|
//simply change the pointer to point at the new uncompressed bloack.
|
||||||
m_vecUncompressedBlockCache[leastRecentlyUsedBlockIndex] = &loadedBlock;
|
m_vecBlocksWithUncompressedData[leastRecentlyUsedBlockIndex] = &loadedBlock;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_vecUncompressedBlockCache.push_back(&loadedBlock);
|
m_vecBlocksWithUncompressedData.push_back(&loadedBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
loadedBlock.block.createUncompressedData();
|
loadedBlock.block.createUncompressedData();
|
||||||
@ -734,8 +733,8 @@ namespace PolyVox
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Memory used by the block cache.
|
//Memory used by the block cache.
|
||||||
uSizeInBytes += m_vecUncompressedBlockCache.capacity() * sizeof(LoadedBlock);
|
uSizeInBytes += m_vecBlocksWithUncompressedData.capacity() * sizeof(LoadedBlock);
|
||||||
uSizeInBytes += m_vecUncompressedBlockCache.size() * m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength * sizeof(VoxelType);
|
uSizeInBytes += m_vecBlocksWithUncompressedData.size() * m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength * sizeof(VoxelType);
|
||||||
|
|
||||||
return uSizeInBytes;
|
return uSizeInBytes;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user