More tidying/refaxctoring of Block class.

This commit is contained in:
Daviw Williams 2013-06-25 17:04:10 +02:00
parent baed7ddccc
commit 6b92a5ab51
4 changed files with 10 additions and 21 deletions

View File

@ -54,7 +54,6 @@ namespace PolyVox
virtual void pageIn(const Region& region, Block<VoxelType>* pBlockData)
{
POLYVOX_ASSERT(pBlockData, "Attempting to page in NULL block");
POLYVOX_ASSERT(pBlockData->isCompressed(), "Attempting to page in uncompressed block");
std::stringstream ss;
ss << region.getLowerX() << "_" << region.getLowerY() << "_" << region.getLowerZ() << "_"
@ -95,7 +94,6 @@ namespace PolyVox
virtual void pageOut(const Region& region, Block<VoxelType>* pBlockData)
{
POLYVOX_ASSERT(pBlockData, "Attempting to page out NULL block");
POLYVOX_ASSERT(pBlockData->isCompressed(), "Attempting to page out uncompressed block");
logTrace() << "Paging out data for " << region;

View File

@ -46,7 +46,7 @@ namespace PolyVox
VoxelType getVoxel(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const;
VoxelType getVoxel(const Vector3DUint16& v3dPos) const;
bool isCompressed(void);
bool hasUncompressedData(void) const;
void setCompressedData(const uint8_t* const data, uint32_t dataLength);
void setVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos, VoxelType tValue);
@ -65,7 +65,6 @@ namespace PolyVox
VoxelType* m_tUncompressedData;
uint16_t m_uSideLength;
uint8_t m_uSideLengthPower;
bool m_bIsCompressed;
bool m_bIsUncompressedDataModified;
};
}

View File

@ -43,7 +43,6 @@ namespace PolyVox
,m_tUncompressedData(0)
,m_uSideLength(0)
,m_uSideLengthPower(0)
,m_bIsCompressed(false)
,m_bIsUncompressedDataModified(true)
{
if(uSideLength == 0)
@ -75,18 +74,14 @@ namespace PolyVox
template <typename VoxelType>
const uint8_t* const Block<VoxelType>::getCompressedData(void) const
{
POLYVOX_ASSERT(m_bIsCompressed, "You cannot call getCompressedData() when the block is not compressed");
POLYVOX_ASSERT(m_pCompressedData, "Compressed data is NULL");
return m_pCompressedData;
}
template <typename VoxelType>
const uint32_t Block<VoxelType>::getCompressedDataLength(void) const
{
POLYVOX_ASSERT(m_bIsCompressed, "You cannot call getCompressedData() when the block is not compressed");
POLYVOX_ASSERT(m_pCompressedData, "Compressed data is NULL");
return m_uCompressedDataLength;
}
@ -103,7 +98,7 @@ namespace PolyVox
POLYVOX_ASSERT(uXPos < m_uSideLength, "Supplied position is outside of the block");
POLYVOX_ASSERT(uYPos < m_uSideLength, "Supplied position is outside of the block");
POLYVOX_ASSERT(uZPos < m_uSideLength, "Supplied position is outside of the block");
POLYVOX_ASSERT(!m_bIsCompressed, "You cannot call getVoxel() when a block is compressed");
POLYVOX_ASSERT(hasUncompressedData(), "The block must have uncompressed data to call getVoxel()");
POLYVOX_ASSERT(m_tUncompressedData, "No uncompressed data - block must be decompressed before accessing voxels.");
return m_tUncompressedData
@ -121,15 +116,14 @@ namespace PolyVox
}
template <typename VoxelType>
bool Block<VoxelType>::isCompressed(void)
bool Block<VoxelType>::hasUncompressedData(void) const
{
return m_bIsCompressed;
return m_tUncompressedData != 0;
}
template <typename VoxelType>
void Block<VoxelType>::setCompressedData(const uint8_t* const data, uint32_t dataLength)
{
POLYVOX_ASSERT(m_bIsCompressed, "You cannot call setCompressedData() when the block is not compressed");
POLYVOX_ASSERT(m_pCompressedData, "Compressed data is NULL");
POLYVOX_ASSERT(m_pCompressedData != data, "Attempting to copy data onto itself");
@ -147,7 +141,7 @@ namespace PolyVox
POLYVOX_ASSERT(uXPos < m_uSideLength, "Supplied position is outside of the block");
POLYVOX_ASSERT(uYPos < m_uSideLength, "Supplied position is outside of the block");
POLYVOX_ASSERT(uZPos < m_uSideLength, "Supplied position is outside of the block");
POLYVOX_ASSERT(!m_bIsCompressed, "You cannot call setVoxelAt() when a block is compressed");
POLYVOX_ASSERT(hasUncompressedData(), "The block must have uncompressed data to call setVoxelAt()");
POLYVOX_ASSERT(m_tUncompressedData, "No uncompressed data - block must be decompressed before accessing voxels.");
m_tUncompressedData
@ -177,9 +171,9 @@ namespace PolyVox
template <typename VoxelType>
void Block<VoxelType>::compress()
{
if(m_bIsCompressed)
if(!hasUncompressedData())
{
POLYVOX_THROW(invalid_operation, "Attempted to compress block which is already flagged as compressed.");
POLYVOX_THROW(invalid_operation, "No uncompressed data to compress.");
}
POLYVOX_ASSERT(m_tUncompressedData != 0, "No uncompressed data is present.");
@ -247,15 +241,14 @@ namespace PolyVox
//Flag the uncompressed data as no longer being used.
delete[] m_tUncompressedData;
m_tUncompressedData = 0;
m_bIsCompressed = true;
}
template <typename VoxelType>
void Block<VoxelType>::uncompress()
{
if(!m_bIsCompressed)
if(hasUncompressedData())
{
POLYVOX_THROW(invalid_operation, "Attempted to uncompress block which is not flagged as compressed.");
POLYVOX_THROW(invalid_operation, "Uncompressed data already exists.");
}
POLYVOX_ASSERT(m_tUncompressedData == 0, "Uncompressed data already exists.");
@ -275,7 +268,6 @@ namespace PolyVox
//m_tUncompressedData = reinterpret_cast<VoxelType*>(uncompressedResult.ptr);
m_bIsCompressed = false;
m_bIsUncompressedDataModified = false;
}
}

View File

@ -663,7 +663,7 @@ namespace PolyVox
m_v3dLastAccessedBlockPos = v3dBlockPos;
m_pLastAccessedBlock = &(loadedBlock.block);
if(loadedBlock.block.m_bIsCompressed == false)
if(loadedBlock.block.hasUncompressedData())
{
POLYVOX_ASSERT(m_pLastAccessedBlock->m_tUncompressedData, "Block has no uncompressed data");
return m_pLastAccessedBlock;