From 404f12a43e57ea4222bd1a515389cc54ce101a86 Mon Sep 17 00:00:00 2001 From: David Williams Date: Wed, 17 Jul 2013 16:33:46 +0200 Subject: [PATCH] Added typedefs to simplify code. --- .../include/PolyVoxCore/LargeVolume.h | 11 ++++++---- .../include/PolyVoxCore/LargeVolume.inl | 20 +++++++++---------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h index 01781cc6..02e226a5 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h @@ -312,7 +312,10 @@ namespace PolyVox } return false; } - }; + }; + + typedef std::map*, BlockPositionCompare> CompressedBlockMap; + typedef std::map*, BlockPositionCompare> UncompressedBlockMap; uint32_t calculateBlockMemoryUsage(void) const; @@ -331,11 +334,11 @@ namespace PolyVox CompressedBlock* getCompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const; UncompressedBlock* getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const; - void eraseBlock(typename std::map*, BlockPositionCompare>::iterator itBlock) const; + void eraseBlock(typename CompressedBlockMap::iterator itBlock) const; // The block data - mutable std::map*, BlockPositionCompare> m_pUncompressedBlockCache; - mutable std::map*, BlockPositionCompare> m_pBlocks; + mutable CompressedBlockMap m_pBlocks; + mutable UncompressedBlockMap m_pUncompressedBlockCache; mutable uint32_t m_uTimestamper; mutable Vector3DInt32 m_v3dLastAccessedBlockPos; diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index 42692706..5ba67966 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -405,7 +405,7 @@ namespace PolyVox for(int32_t z = v3dStart.getZ(); z <= v3dEnd.getZ(); z++) { Vector3DInt32 pos(x,y,z); - typename std::map*, BlockPositionCompare>::iterator itBlock = m_pBlocks.find(pos); + typename CompressedBlockMap::iterator itBlock = m_pBlocks.find(pos); if(itBlock != m_pBlocks.end()) { @@ -436,7 +436,7 @@ namespace PolyVox template void LargeVolume::flushAll() { - typename std::map*, BlockPositionCompare>::iterator i; + typename CompressedBlockMap::iterator i; //Replaced the for loop here as the call to //eraseBlock was invalidating the iterator. while(m_pBlocks.size() > 0) @@ -470,7 +470,7 @@ namespace PolyVox for(int32_t z = v3dStart.getZ(); z <= v3dEnd.getZ(); z++) { Vector3DInt32 pos(x,y,z); - typename std::map*, BlockPositionCompare>::iterator itBlock = m_pBlocks.find(pos); + typename CompressedBlockMap::iterator itBlock = m_pBlocks.find(pos); if(itBlock == m_pBlocks.end()) { // not loaded, not unloading @@ -548,7 +548,7 @@ namespace PolyVox } template - void LargeVolume::eraseBlock(typename std::map*, BlockPositionCompare>::iterator itBlock) const + void LargeVolume::eraseBlock(typename CompressedBlockMap::iterator itBlock) const { POLYVOX_ASSERT(false, "This function has not been implemented properly"); @@ -591,7 +591,7 @@ namespace PolyVox { Vector3DInt32 v3dBlockPos(uBlockX, uBlockY, uBlockZ); - typename std::map*, BlockPositionCompare>::iterator itBlock = m_pBlocks.find(v3dBlockPos); + typename CompressedBlockMap::iterator itBlock = m_pBlocks.find(v3dBlockPos); // check whether the block is already loaded if(itBlock == m_pBlocks.end()) { @@ -635,7 +635,7 @@ namespace PolyVox CompressedBlock* block = getCompressedBlock(uBlockX, uBlockY, uBlockZ); - typename std::map*, BlockPositionCompare>::iterator itUncompressedBlock = m_pUncompressedBlockCache.find(v3dBlockPos); + typename UncompressedBlockMap::iterator itUncompressedBlock = m_pUncompressedBlockCache.find(v3dBlockPos); // check whether the block is already loaded if(itUncompressedBlock == m_pUncompressedBlockCache.end()) { @@ -681,7 +681,7 @@ namespace PolyVox uint32_t uSizeInBytes = sizeof(LargeVolume); //Memory used by the blocks - typename std::map*, BlockPositionCompare>::iterator i; + typename CompressedBlockMap::iterator i; for(i = m_pBlocks.begin(); i != m_pBlocks.end(); i++) { //Inaccurate - account for rest of loaded block. @@ -700,7 +700,7 @@ namespace PolyVox { uint32_t uMemoryUsage = 0; - typename std::map*, BlockPositionCompare>::iterator i; + typename CompressedBlockMap::iterator i; for(i = m_pBlocks.begin(); i != m_pBlocks.end(); i++) { //Inaccurate - account for rest of loaded block. @@ -720,8 +720,8 @@ namespace PolyVox while(calculateBlockMemoryUsage() > m_uCompressedBlockMemoryLimitInBytes) //FIXME - This calculation of size is slow and should be outside the loop. { // find the least recently used block - typename std::map*, BlockPositionCompare>::iterator i; - typename std::map*, BlockPositionCompare>::iterator itUnloadBlock = m_pBlocks.begin(); + typename CompressedBlockMap::iterator i; + typename CompressedBlockMap::iterator itUnloadBlock = m_pBlocks.begin(); for(i = m_pBlocks.begin(); i != m_pBlocks.end(); i++) { if(i->second->m_uBlockLastAccessed < itUnloadBlock->second->m_uBlockLastAccessed)