From 7f831fb97a373561005f573aa31449f75dc6163b Mon Sep 17 00:00:00 2001 From: David Williams Date: Wed, 9 Feb 2011 22:21:44 +0000 Subject: [PATCH] Made Block copy constructor private. --- .../PolyVoxCore/include/PolyVoxImpl/Block.h | 8 +++-- .../PolyVoxCore/include/PolyVoxImpl/Block.inl | 36 ++++--------------- library/PolyVoxCore/include/Volume.h | 4 ++- library/PolyVoxCore/include/Volume.inl | 21 ++++++++--- 4 files changed, 32 insertions(+), 37 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxImpl/Block.h b/library/PolyVoxCore/include/PolyVoxImpl/Block.h index 28cbf8dd..5432518b 100644 --- a/library/PolyVoxCore/include/PolyVoxImpl/Block.h +++ b/library/PolyVoxCore/include/PolyVoxImpl/Block.h @@ -37,11 +37,8 @@ namespace PolyVox friend class VolumeSampler; public: Block(uint16_t uSideLength = 0); - Block(const Block& rhs); ~Block(); - Block& operator=(const Block& rhs); - uint16_t getSideLength(void) const; VoxelType getVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const; VoxelType getVoxelAt(const Vector3DUint16& v3dPos) const; @@ -66,6 +63,11 @@ namespace PolyVox std::vector runlengths; std::vector values; + + 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 ff8572e9..65844807 100644 --- a/library/PolyVoxCore/include/PolyVoxImpl/Block.inl +++ b/library/PolyVoxCore/include/PolyVoxImpl/Block.inl @@ -50,7 +50,7 @@ namespace PolyVox template Block::Block(const Block& rhs) { - *this = rhs; + assert(false); } template @@ -63,33 +63,8 @@ namespace PolyVox template Block& Block::operator=(const Block& rhs) { - //We don't often need to assign blocks as they should be passed around by pointer. - //And I'm pretty sure we don't want to be passing around uncompressed ones becauses - //it means duplicating the uncompressed data which is expensive. This assert is to - //make sure that uncompressed blocks don't get assigned by accident. - assert(rhs.m_bIsCompressed == true); - - if (this == &rhs) - { - return *this; - } - - //Copy the data - m_uSideLength = rhs.m_uSideLength; - m_uSideLengthPower = rhs.m_uSideLengthPower; - m_bIsCompressed = rhs.m_bIsCompressed; - m_bIsUncompressedDataModified = rhs.m_bIsUncompressedDataModified; - m_uTimestamp = rhs.m_uTimestamp; - runlengths = rhs.runlengths; - values = rhs.values; - - if(m_bIsCompressed == false) - { - m_tUncompressedData = new VoxelType[rhs.m_uSideLength * rhs.m_uSideLength * rhs.m_uSideLength]; - memcpy(m_tUncompressedData, rhs.m_tUncompressedData, m_uSideLength * m_uSideLength * m_uSideLength * sizeof(VoxelType)); - } - - return *this; + assert(false); + return 0; } template @@ -194,7 +169,7 @@ namespace PolyVox template uint32_t Block::sizeInChars(void) { - uint32_t uSizeInChars = sizeof(Block); + uint32_t uSizeInChars = 0; //sizeof(Block); if(m_tUncompressedData != 0) { @@ -202,6 +177,9 @@ namespace PolyVox uSizeInChars += uNoOfVoxels * sizeof(VoxelType); } + uSizeInChars += values.size() * sizeof(VoxelType); + uSizeInChars += runlengths.size() * sizeof(uint16_t); + return uSizeInChars; } diff --git a/library/PolyVoxCore/include/Volume.h b/library/PolyVoxCore/include/Volume.h index c00ef68b..e66b4ec4 100644 --- a/library/PolyVoxCore/include/Volume.h +++ b/library/PolyVoxCore/include/Volume.h @@ -158,11 +158,13 @@ namespace PolyVox void setBlockCacheSize(uint16_t uBlockCacheSize); void clearBlockCache(void); + uint32_t sizeInChars(void); + public: Block* getUncompressedBlock(Block* block) const; Block m_pBorderBlock; - std::vector< Block > m_pBlocks; + Block* m_pBlocks; mutable std::vector*> m_pUncompressedBlocks; uint16_t m_uBlockCacheSize; diff --git a/library/PolyVoxCore/include/Volume.inl b/library/PolyVoxCore/include/Volume.inl index 269dbaca..763c415b 100644 --- a/library/PolyVoxCore/include/Volume.inl +++ b/library/PolyVoxCore/include/Volume.inl @@ -49,10 +49,11 @@ namespace PolyVox template Volume::Volume(uint16_t uWidth, uint16_t uHeight, uint16_t uDepth, uint16_t uBlockSideLength) :m_uTimestamper(0) - ,m_uBlockCacheSize(1024) + ,m_uBlockCacheSize(256) ,m_uCompressions(0) ,m_uUncompressions(0) ,m_uBlockSideLength(uBlockSideLength) + ,m_pBlocks(0) { setBlockCacheSize(m_uBlockCacheSize); @@ -325,7 +326,8 @@ namespace PolyVox } //Clear the previous data - m_pBlocks.clear(); + delete[] m_pBlocks; + m_pBlocks = 0; //Compute the volume side lengths m_uWidth = uWidth; @@ -345,7 +347,7 @@ namespace PolyVox m_uNoOfBlocksInVolume = m_uWidthInBlocks * m_uHeightInBlocks * m_uDepthInBlocks; //Create the blocks - m_pBlocks.resize(m_uNoOfBlocksInVolume); + m_pBlocks = new Block[m_uNoOfBlocksInVolume]; for(uint32_t i = 0; i < m_uNoOfBlocksInVolume; ++i) { m_pBlocks[i].resize(m_uBlockSideLength); @@ -386,7 +388,7 @@ namespace PolyVox if(m_pUncompressedBlocks.size() == m_uBlockCacheSize) { int32_t leastRecentlyUsedBlockIndex = -1; - uint32_t uLeastRecentTimestamp = 1000000000000000; + uint64_t uLeastRecentTimestamp = 1000000000000000; for(uint32_t ct = 0; ct < m_pUncompressedBlocks.size(); ct++) { if(m_pUncompressedBlocks[ct]->m_uTimestamp < uLeastRecentTimestamp) @@ -410,4 +412,15 @@ namespace PolyVox return block; } + + template + uint32_t Volume::sizeInChars(void) + { + uint32_t uSizeInChars = 0; + for(uint32_t i = 0; i < m_uNoOfBlocksInVolume; ++i) + { + uSizeInChars += m_pBlocks[i].sizeInChars(); + } + return uSizeInChars; + } }