Made Block copy constructor private.

This commit is contained in:
David Williams 2011-02-09 22:21:44 +00:00
parent b1eab6c6a3
commit 7f831fb97a
4 changed files with 32 additions and 37 deletions

View File

@ -37,11 +37,8 @@ namespace PolyVox
friend class VolumeSampler<VoxelType>;
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<uint16_t> runlengths;
std::vector<VoxelType> values;
private:
Block(const Block& rhs);
Block& operator=(const Block& rhs);
};
}

View File

@ -50,7 +50,7 @@ namespace PolyVox
template <typename VoxelType>
Block<VoxelType>::Block(const Block<VoxelType>& rhs)
{
*this = rhs;
assert(false);
}
template <typename VoxelType>
@ -63,33 +63,8 @@ namespace PolyVox
template <typename VoxelType>
Block<VoxelType>& Block<VoxelType>::operator=(const Block<VoxelType>& 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 <typename VoxelType>
@ -194,7 +169,7 @@ namespace PolyVox
template <typename VoxelType>
uint32_t Block<VoxelType>::sizeInChars(void)
{
uint32_t uSizeInChars = sizeof(Block<VoxelType>);
uint32_t uSizeInChars = 0; //sizeof(Block<VoxelType>);
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;
}

View File

@ -158,11 +158,13 @@ namespace PolyVox
void setBlockCacheSize(uint16_t uBlockCacheSize);
void clearBlockCache(void);
uint32_t sizeInChars(void);
public:
Block<VoxelType>* getUncompressedBlock(Block<VoxelType>* block) const;
Block<VoxelType> m_pBorderBlock;
std::vector< Block<VoxelType> > m_pBlocks;
Block<VoxelType>* m_pBlocks;
mutable std::vector<Block<VoxelType>*> m_pUncompressedBlocks;
uint16_t m_uBlockCacheSize;

View File

@ -49,10 +49,11 @@ namespace PolyVox
template <typename VoxelType>
Volume<VoxelType>::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<VoxelType>[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 <typename VoxelType>
uint32_t Volume<VoxelType>::sizeInChars(void)
{
uint32_t uSizeInChars = 0;
for(uint32_t i = 0; i < m_uNoOfBlocksInVolume; ++i)
{
uSizeInChars += m_pBlocks[i].sizeInChars();
}
return uSizeInChars;
}
}