Added function to purge null blocks.
This commit is contained in:
parent
177eb16bec
commit
916fe310ad
@ -315,6 +315,8 @@ namespace PolyVox
|
|||||||
|
|
||||||
std::shared_ptr< UncompressedBlock<VoxelType> > getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const;
|
std::shared_ptr< UncompressedBlock<VoxelType> > getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const;
|
||||||
|
|
||||||
|
void purgeNullPtrsFromAllBlocks(void) const;
|
||||||
|
|
||||||
// The block data
|
// The block data
|
||||||
mutable WeakPtrBlockMap m_pAllBlocks;
|
mutable WeakPtrBlockMap m_pAllBlocks;
|
||||||
mutable SharedPtrBlockMap m_pRecentlyUsedBlocks;
|
mutable SharedPtrBlockMap m_pRecentlyUsedBlocks;
|
||||||
|
@ -557,6 +557,7 @@ namespace PolyVox
|
|||||||
pUncompressedBlock = std::make_shared< UncompressedBlock<VoxelType> >(v3dBlockPos, m_uBlockSideLength, m_pPager);
|
pUncompressedBlock = std::make_shared< UncompressedBlock<VoxelType> >(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.
|
// As we are loading a new block we should try to ensure we don't go over our target memory usage.
|
||||||
|
bool erasedBlock = false;
|
||||||
while (m_pRecentlyUsedBlocks.size() + 1 > m_uMaxNumberOfUncompressedBlocks) // +1 ready for new block we will add next.
|
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
|
// This should never hit, because it should not have been possible for
|
||||||
@ -575,6 +576,14 @@ namespace PolyVox
|
|||||||
|
|
||||||
// Erase the least recently used block
|
// Erase the least recently used block
|
||||||
m_pRecentlyUsedBlocks.erase(itUnloadBlock);
|
m_pRecentlyUsedBlocks.erase(itUnloadBlock);
|
||||||
|
erasedBlock = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we've deleted any blocks from the recently used list then this
|
||||||
|
// seems like a good place to purge the 'all blocks' list as well.
|
||||||
|
if (erasedBlock)
|
||||||
|
{
|
||||||
|
purgeNullPtrsFromAllBlocks();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add our new block to the maps.
|
// Add our new block to the maps.
|
||||||
@ -612,6 +621,18 @@ namespace PolyVox
|
|||||||
return uSizeInBytes;
|
return uSizeInBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename VoxelType>
|
||||||
|
void LargeVolume<VoxelType>::purgeNullPtrsFromAllBlocks(void) const
|
||||||
|
{
|
||||||
|
for (auto blockIter = m_pAllBlocks.begin(); blockIter != m_pAllBlocks.end(); blockIter++)
|
||||||
|
{
|
||||||
|
if (blockIter->second.expired())
|
||||||
|
{
|
||||||
|
blockIter = m_pAllBlocks.erase(blockIter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
template <WrapMode eWrapMode>
|
template <WrapMode eWrapMode>
|
||||||
VoxelType LargeVolume<VoxelType>::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType<eWrapMode>, VoxelType tBorder) const
|
VoxelType LargeVolume<VoxelType>::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType<eWrapMode>, VoxelType tBorder) const
|
||||||
|
Loading…
x
Reference in New Issue
Block a user