From 29e2e14c3a4d38bf65d14416197e0f0dcdc641ee Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 12 Feb 2011 22:21:17 +0000 Subject: [PATCH] More tidying up. --- examples/Basic/main.cpp | 6 ++--- .../PolyVoxCore/include/PolyVoxImpl/Block.inl | 4 ++-- library/PolyVoxCore/include/Volume.h | 23 ++++++++++++------- library/PolyVoxCore/include/Volume.inl | 8 ------- 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/examples/Basic/main.cpp b/examples/Basic/main.cpp index 95f61ade..3d71bce9 100644 --- a/examples/Basic/main.cpp +++ b/examples/Basic/main.cpp @@ -510,10 +510,10 @@ int main(int argc, char *argv[]) openGLWidget.show(); //Create an empty volume and then place a sphere in it - Volume volData(256, 256, 256); + Volume volData(2048, 2048, 256); //createSphereInVolume(volData, 30); - //createPerlinTerrain(volData); - createPerlinVolumeSlow(volData); + createPerlinTerrain(volData); + //createPerlinVolumeSlow(volData); std::cout << "Memory usage: " << volData.sizeInBytes() << std::endl; volData.setBlockCacheSize(8); std::cout << "Memory usage: " << volData.sizeInBytes() << std::endl; diff --git a/library/PolyVoxCore/include/PolyVoxImpl/Block.inl b/library/PolyVoxCore/include/PolyVoxImpl/Block.inl index 8a8d15fd..0eea8867 100644 --- a/library/PolyVoxCore/include/PolyVoxImpl/Block.inl +++ b/library/PolyVoxCore/include/PolyVoxImpl/Block.inl @@ -172,10 +172,10 @@ namespace PolyVox m_vecCompressedData.push_back(entry); - //Shrink the vectors to their contents (seems slow?): + //Shrink the vectors to their contents (maybe slow?): //http://stackoverflow.com/questions/1111078/reduce-the-capacity-of-an-stl-vector //C++0x may have a shrink_to_fit() function? - //std::vector(m_vecCompressedData).swap(m_vecCompressedData); + std::vector< RunlengthEntry >(m_vecCompressedData).swap(m_vecCompressedData); } //Flag the uncompressed data as no longer being used but don't delete it (we don't own it). diff --git a/library/PolyVoxCore/include/Volume.h b/library/PolyVoxCore/include/Volume.h index e5f537f0..43f026e5 100644 --- a/library/PolyVoxCore/include/Volume.h +++ b/library/PolyVoxCore/include/Volume.h @@ -170,13 +170,24 @@ namespace PolyVox public: Block* getUncompressedBlock(uint16_t uBlockX, uint16_t uBlockY, uint16_t uBlockZ) const; - VoxelType* m_pUncompressedBorderData; - + //The block data mutable std::vector< Block > m_pBlocks; - mutable std::vector m_pUncompressedTimestamps; + + //The cache of uncompressed blocks. The uncompressed block data and the timestamps are stored here rather + //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 + //location in memory... could be messy with threading. mutable std::vector< UncompressedBlock > m_vecUncompressedBlockCache; - uint16_t m_uMaxUncompressedBlockCacheSize; + mutable std::vector m_pUncompressedTimestamps; + mutable uint32_t m_uTimestamper; uint32_t m_ulastAccessedBlockIndex; + uint32_t m_uMaxUncompressedBlockCacheSize; + + //We don't store an actual Block for the border, just the uncompressed data. This is partly because the border + //block does not have a position (so can't be passed to getUncompressedBlock()) and partly because there's a + //good chance we'll often hit it anyway. It's a chunk of homogenous data (rather than a single value) so that + //the VolumeIterator can do it's usual pointer arithmetic without needing to know it's gone outside the volume. + VoxelType* m_pUncompressedBorderData; uint32_t m_uNoOfBlocksInVolume; @@ -194,10 +205,6 @@ namespace PolyVox uint16_t m_uLongestSideLength; uint16_t m_uShortestSideLength; float m_fDiagonalLength; - mutable uint64_t m_uTimestamper; - - mutable uint32_t m_uCompressions; - mutable uint32_t m_uUncompressions; }; //Some handy typedefs diff --git a/library/PolyVoxCore/include/Volume.inl b/library/PolyVoxCore/include/Volume.inl index 691ed70b..ec3feffb 100644 --- a/library/PolyVoxCore/include/Volume.inl +++ b/library/PolyVoxCore/include/Volume.inl @@ -50,8 +50,6 @@ namespace PolyVox Volume::Volume(uint16_t uWidth, uint16_t uHeight, uint16_t uDepth, uint16_t uBlockSideLength) :m_uTimestamper(0) ,m_uMaxUncompressedBlockCacheSize(256) - ,m_uCompressions(0) - ,m_uUncompressions(0) ,m_uBlockSideLength(uBlockSideLength) ,m_pUncompressedBorderData(0) ,m_ulastAccessedBlockIndex((std::numeric_limits::max)()) //An invalid index @@ -265,7 +263,6 @@ namespace PolyVox { m_pBlocks[m_vecUncompressedBlockCache[ct].uBlockIndex].compress(); delete[] m_vecUncompressedBlockCache[ct].data; - m_uCompressions++; } m_vecUncompressedBlockCache.clear(); } @@ -409,7 +406,6 @@ namespace PolyVox uUncompressedBlockIndex = leastRecentlyUsedBlockIndex; m_pBlocks[m_vecUncompressedBlockCache[leastRecentlyUsedBlockIndex].uBlockIndex].compress(); m_pBlocks[m_vecUncompressedBlockCache[leastRecentlyUsedBlockIndex].uBlockIndex].m_tUncompressedData = 0; - m_uCompressions++; m_vecUncompressedBlockCache[leastRecentlyUsedBlockIndex].uBlockIndex = uBlockIndex; } else @@ -422,11 +418,7 @@ namespace PolyVox uUncompressedBlockIndex = m_vecUncompressedBlockCache.size() - 1; } - //VoxelType* pData = new VoxelType[m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength]; - //VoxelType* pData = &(m_pUncompressedBlockData[uUncompressedBlockIndex][0]); - //VoxelType* pData = m_pUncompressedBlockData + (m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength * uUncompressedBlockIndex); block->uncompress(m_vecUncompressedBlockCache[uUncompressedBlockIndex].data); - m_uUncompressions++; return block; }