From bf9f5aee480974f62e3b7db760b5977c4dc488e3 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 12 Feb 2011 21:47:02 +0000 Subject: [PATCH] More tidying up. --- examples/Basic/main.cpp | 2 + .../PolyVoxCore/include/PolyVoxImpl/Block.h | 4 -- .../PolyVoxCore/include/PolyVoxImpl/Block.inl | 15 +----- library/PolyVoxCore/include/Volume.h | 5 +- library/PolyVoxCore/include/Volume.inl | 51 ++++++++----------- library/PolyVoxCore/include/VolumeSampler.inl | 3 -- 6 files changed, 26 insertions(+), 54 deletions(-) diff --git a/examples/Basic/main.cpp b/examples/Basic/main.cpp index 85ef2f9e..95f61ade 100644 --- a/examples/Basic/main.cpp +++ b/examples/Basic/main.cpp @@ -514,7 +514,9 @@ int main(int argc, char *argv[]) //createSphereInVolume(volData, 30); //createPerlinTerrain(volData); createPerlinVolumeSlow(volData); + std::cout << "Memory usage: " << volData.sizeInBytes() << std::endl; volData.setBlockCacheSize(8); + std::cout << "Memory usage: " << volData.sizeInBytes() << std::endl; /*srand(12345); for(int ct = 0; ct < 1000; ct++) diff --git a/library/PolyVoxCore/include/PolyVoxImpl/Block.h b/library/PolyVoxCore/include/PolyVoxImpl/Block.h index 78529a0d..111e5870 100644 --- a/library/PolyVoxCore/include/PolyVoxImpl/Block.h +++ b/library/PolyVoxCore/include/PolyVoxImpl/Block.h @@ -70,10 +70,6 @@ namespace PolyVox uint8_t m_uSideLengthPower; bool m_bIsCompressed; bool m_bIsUncompressedDataModified; - - private: - Block(const Block& rhs); - Block& operator=(const Block& rhs); }; } diff --git a/library/PolyVoxCore/include/PolyVoxImpl/Block.inl b/library/PolyVoxCore/include/PolyVoxImpl/Block.inl index 9a65f63d..8a8d15fd 100644 --- a/library/PolyVoxCore/include/PolyVoxImpl/Block.inl +++ b/library/PolyVoxCore/include/PolyVoxImpl/Block.inl @@ -46,19 +46,6 @@ namespace PolyVox } } - template - Block::Block(const Block& rhs) - { - assert(false); - } - - template - Block& Block::operator=(const Block& rhs) - { - assert(false); - return 0; - } - template uint16_t Block::getSideLength(void) const { @@ -147,7 +134,7 @@ namespace PolyVox uint32_t Block::sizeInBytes(void) { uint32_t uSizeInBytes = sizeof(Block); - uSizeInBytes += m_vecCompressedData.capacity() * sizeof(RunlengthEntry); + uSizeInBytes += m_vecCompressedData.capacity() * sizeof(RunlengthEntry); return uSizeInBytes; } diff --git a/library/PolyVoxCore/include/Volume.h b/library/PolyVoxCore/include/Volume.h index 85a454b0..e5f537f0 100644 --- a/library/PolyVoxCore/include/Volume.h +++ b/library/PolyVoxCore/include/Volume.h @@ -170,11 +170,10 @@ namespace PolyVox public: Block* getUncompressedBlock(uint16_t uBlockX, uint16_t uBlockY, uint16_t uBlockZ) const; - //Block m_pBorderBlock; VoxelType* m_pUncompressedBorderData; - Block* m_pBlocks; - uint32_t* m_pUncompressedTimestamps; + mutable std::vector< Block > m_pBlocks; + mutable std::vector m_pUncompressedTimestamps; mutable std::vector< UncompressedBlock > m_vecUncompressedBlockCache; uint16_t m_uMaxUncompressedBlockCacheSize; uint32_t m_ulastAccessedBlockIndex; diff --git a/library/PolyVoxCore/include/Volume.inl b/library/PolyVoxCore/include/Volume.inl index fe20f60a..691ed70b 100644 --- a/library/PolyVoxCore/include/Volume.inl +++ b/library/PolyVoxCore/include/Volume.inl @@ -53,8 +53,6 @@ namespace PolyVox ,m_uCompressions(0) ,m_uUncompressions(0) ,m_uBlockSideLength(uBlockSideLength) - ,m_pBlocks(0) - ,m_pUncompressedTimestamps(0) ,m_pUncompressedBorderData(0) ,m_ulastAccessedBlockIndex((std::numeric_limits::max)()) //An invalid index { @@ -182,13 +180,6 @@ namespace PolyVox const uint16_t yOffset = uYPos - (blockY << m_uBlockSideLengthPower); const uint16_t zOffset = uZPos - (blockZ << m_uBlockSideLengthPower); - /*const Block& block = m_pBlocks - [ - blockX + - blockY * m_uWidthInBlocks + - blockZ * m_uWidthInBlocks * m_uHeightInBlocks - ];*/ - Block* pUncompressedBlock = getUncompressedBlock(blockX, blockY, blockZ); return pUncompressedBlock->getVoxelAt(xOffset,yOffset,zOffset); @@ -242,13 +233,6 @@ namespace PolyVox const uint16_t yOffset = uYPos - (blockY << m_uBlockSideLengthPower); const uint16_t zOffset = uZPos - (blockZ << m_uBlockSideLengthPower); - /*uint32_t uBlockIndex = - blockX + - blockY * m_uWidthInBlocks + - blockZ * m_uWidthInBlocks * m_uHeightInBlocks; - - Block& block = m_pBlocks[uBlockIndex];*/ - Block* pUncompressedBlock = getUncompressedBlock(blockX, blockY, blockZ); pUncompressedBlock->setVoxelAt(xOffset,yOffset,zOffset, tValue); @@ -331,11 +315,8 @@ namespace PolyVox } //Clear the previous data - delete[] m_pBlocks; - m_pBlocks = 0; - - delete[] m_pUncompressedTimestamps; - m_pUncompressedTimestamps = 0; + m_pBlocks.clear(); + m_pUncompressedTimestamps.clear(); //Compute the volume side lengths m_uWidth = uWidth; @@ -355,18 +336,16 @@ namespace PolyVox m_uNoOfBlocksInVolume = m_uWidthInBlocks * m_uHeightInBlocks * m_uDepthInBlocks; //Create the blocks - m_pBlocks = new Block[m_uNoOfBlocksInVolume]; - m_pUncompressedTimestamps = new uint32_t[m_uNoOfBlocksInVolume]; + m_pBlocks.resize(m_uNoOfBlocksInVolume); for(uint32_t i = 0; i < m_uNoOfBlocksInVolume; ++i) { m_pBlocks[i].initialise(m_uBlockSideLength); - m_pUncompressedTimestamps[i] = 0; //Use memset/std::fill } + m_pUncompressedTimestamps.resize(m_uNoOfBlocksInVolume); + std::fill(m_pUncompressedTimestamps.begin(), m_pUncompressedTimestamps.end(), 0); + //Create the border block - /*m_pBorderBlock.initialise(uBlockSideLength); - Block* pUncompressedBorderBlock = getUncompressedBlock(&m_pBorderBlock); - pUncompressedBorderBlock->fill(VoxelType());*/ m_pUncompressedBorderData = new VoxelType[m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength]; std::fill(m_pUncompressedBorderData, m_pUncompressedBorderData + m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength, VoxelType()); @@ -421,10 +400,8 @@ namespace PolyVox for(uint32_t ct = 0; ct < m_vecUncompressedBlockCache.size(); ct++) { if(m_pUncompressedTimestamps[m_vecUncompressedBlockCache[ct].uBlockIndex] < uLeastRecentTimestamp) - //if(m_pBlocks[m_vecUncompressedBlockCache[ct].uBlockIndex].m_uTimestamp < uLeastRecentTimestamp) { uLeastRecentTimestamp = m_pUncompressedTimestamps[m_vecUncompressedBlockCache[ct].uBlockIndex]; - //uLeastRecentTimestamp = m_pBlocks[m_vecUncompressedBlockCache[ct].uBlockIndex].m_uTimestamp; leastRecentlyUsedBlockIndex = ct; } } @@ -457,11 +434,25 @@ namespace PolyVox template uint32_t Volume::sizeInBytes(void) { - uint32_t uSizeInBytes = 0; + uint32_t uSizeInBytes = sizeof(Volume); + + //Memory used by the blocks for(uint32_t i = 0; i < m_uNoOfBlocksInVolume; ++i) { uSizeInBytes += m_pBlocks[i].sizeInBytes(); } + + //Memory used by the block cache. + uSizeInBytes += m_vecUncompressedBlockCache.capacity() * sizeof(UncompressedBlock); + uSizeInBytes += m_vecUncompressedBlockCache.size() * m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength * sizeof(VoxelType); + uSizeInBytes += m_pUncompressedTimestamps.capacity() * sizeof(uint32_t); + + //Memory used by border data. + if(m_pUncompressedBorderData) + { + uSizeInBytes += m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength * sizeof(VoxelType); + } + return uSizeInBytes; } } diff --git a/library/PolyVoxCore/include/VolumeSampler.inl b/library/PolyVoxCore/include/VolumeSampler.inl index 881c1d1d..3a772c53 100644 --- a/library/PolyVoxCore/include/VolumeSampler.inl +++ b/library/PolyVoxCore/include/VolumeSampler.inl @@ -161,9 +161,6 @@ namespace PolyVox } else { - /*Block* pUncompressedBorderBlock = mVolume->getUncompressedBlock(&(mVolume->m_pBorderBlock)); - mCurrentVoxel = pUncompressedBorderBlock->m_tUncompressedData + uVoxelIndexInBlock;*/ - mCurrentVoxel = mVolume->m_pUncompressedBorderData + uVoxelIndexInBlock; } }