From 6b92a5ab51f112f25437139cea52a20915006e47 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Tue, 25 Jun 2013 17:04:10 +0200 Subject: [PATCH] More tidying/refaxctoring of Block class. --- .../include/PolyVoxCore/FilePager.h | 2 -- .../include/PolyVoxCore/Impl/Block.h | 3 +-- .../include/PolyVoxCore/Impl/Block.inl | 24 +++++++------------ .../include/PolyVoxCore/LargeVolume.inl | 2 +- 4 files changed, 10 insertions(+), 21 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/FilePager.h b/library/PolyVoxCore/include/PolyVoxCore/FilePager.h index 97b9f2cc..07dc94e1 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/FilePager.h +++ b/library/PolyVoxCore/include/PolyVoxCore/FilePager.h @@ -54,7 +54,6 @@ namespace PolyVox virtual void pageIn(const Region& region, Block* 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* 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; diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h index 2d4cfeee..cc6253b6 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h @@ -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; }; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl index 8a75beab..39bddb3a 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl @@ -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 const uint8_t* const Block::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 const uint32_t Block::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 - bool Block::isCompressed(void) + bool Block::hasUncompressedData(void) const { - return m_bIsCompressed; + return m_tUncompressedData != 0; } template void Block::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 void Block::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 void Block::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(uncompressedResult.ptr); - m_bIsCompressed = false; m_bIsUncompressedDataModified = false; } } diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index 9fc1d7c1..47746f4d 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -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;