diff --git a/library/PolyVoxCore/include/SimpleVolume.h b/library/PolyVoxCore/include/SimpleVolume.h index 45e36484..ed00833f 100644 --- a/library/PolyVoxCore/include/SimpleVolume.h +++ b/library/PolyVoxCore/include/SimpleVolume.h @@ -41,19 +41,8 @@ namespace PolyVox public: class Block { - template - struct RunlengthEntry - { - LengthType length; - VoxelType value; - - //We can parametise the length on anything up to uint32_t. - //This lets us experiment with the optimal size in the future. - static uint32_t maxRunlength(void) {return (std::numeric_limits::max)();} - }; - //Make Sampler a friend - friend class LargeVolume::Sampler; + friend class SimpleVolume::Sampler; public: Block(uint16_t uSideLength = 0); @@ -69,12 +58,9 @@ namespace PolyVox uint32_t calculateSizeInBytes(void); public: - std::vector< RunlengthEntry > m_vecCompressedData; VoxelType* m_tUncompressedData; uint16_t m_uSideLength; uint8_t m_uSideLengthPower; - bool m_bIsCompressed; - bool m_bIsUncompressedDataModified; }; class Sampler @@ -147,19 +133,6 @@ namespace PolyVox VoxelType* mCurrentVoxel; }; - struct LoadedBlock - { - public: - LoadedBlock(uint16_t uSideLength = 0) - :block(uSideLength) - ,timestamp(0) - { - } - - Block block; - uint32_t timestamp; - }; - public: /// Constructor for creating a fixed size volume. SimpleVolume @@ -225,14 +198,12 @@ private: polyvox_function&, const Region&)> m_funcDataOverflowHandler; Block* getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const; - void eraseBlock(typename std::map::iterator itBlock) const; /// this function can be called by m_funcDataRequiredHandler without causing any weird effects bool setVoxelAtConst(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue) const; //The block data - mutable std::map m_pBlocks; + mutable std::map m_pBlocks; - mutable uint32_t m_uTimestamper; mutable Vector3DInt32 m_v3dLastAccessedBlockPos; mutable Block* m_pLastAccessedBlock; diff --git a/library/PolyVoxCore/include/SimpleVolume.inl b/library/PolyVoxCore/include/SimpleVolume.inl index 39165c49..e0294879 100644 --- a/library/PolyVoxCore/include/SimpleVolume.inl +++ b/library/PolyVoxCore/include/SimpleVolume.inl @@ -284,11 +284,8 @@ namespace PolyVox throw std::invalid_argument("Block side length must be a power of two."); } - m_uTimestamper = 0; m_uBlockSideLength = uBlockSideLength; m_pUncompressedBorderData = 0; - m_v3dLastAccessedBlockPos = Vector3DInt32(0,0,0); //There are no invalid positions, but initially the m_pLastAccessedBlock pointer will be null; - m_pLastAccessedBlock = 0; m_regValidRegion = regValidRegion; @@ -315,12 +312,6 @@ namespace PolyVox m_fDiagonalLength = sqrtf(static_cast(getWidth() * getWidth() + getHeight() * getHeight() + getDepth() * getDepth())); } - template - void SimpleVolume::eraseBlock(typename std::map::iterator itBlock) const - { - m_pBlocks.erase(itBlock); - } - template bool SimpleVolume::setVoxelAtConst(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue) const { @@ -350,32 +341,17 @@ namespace PolyVox { Vector3DInt32 v3dBlockPos(uBlockX, uBlockY, uBlockZ); - typename std::map::iterator itBlock = m_pBlocks.find(v3dBlockPos); + typename std::map::iterator itBlock = m_pBlocks.find(v3dBlockPos); // check whether the block is already loaded if(itBlock == m_pBlocks.end()) { // create the new block - LoadedBlock newBlock(m_uBlockSideLength); + Block newBlock(m_uBlockSideLength); itBlock = m_pBlocks.insert(std::make_pair(v3dBlockPos, newBlock)).first; } - //Get the block and mark that we accessed it - LoadedBlock& loadedBlock = itBlock->second; - loadedBlock.timestamp = ++m_uTimestamper; - m_v3dLastAccessedBlockPos = v3dBlockPos; - m_pLastAccessedBlock = &(loadedBlock.block); - - if(loadedBlock.block.m_bIsCompressed == false) - { - assert(m_pLastAccessedBlock->m_tUncompressedData); - return m_pLastAccessedBlock; - } - - //loadedBlock.block.uncompress(); - - m_pLastAccessedBlock = &(loadedBlock.block); - assert(m_pLastAccessedBlock->m_tUncompressedData); - return m_pLastAccessedBlock; + Block& block = itBlock->second; + return █ } //////////////////////////////////////////////////////////////////////////////// diff --git a/library/PolyVoxCore/include/SimpleVolumeBlock.inl b/library/PolyVoxCore/include/SimpleVolumeBlock.inl index ffb24974..f7298256 100644 --- a/library/PolyVoxCore/include/SimpleVolumeBlock.inl +++ b/library/PolyVoxCore/include/SimpleVolumeBlock.inl @@ -36,8 +36,6 @@ namespace PolyVox :m_uSideLength(0) ,m_uSideLengthPower(0) ,m_tUncompressedData(0) - ,m_bIsCompressed(true) - ,m_bIsUncompressedDataModified(true) { if(uSideLength != 0) { @@ -89,8 +87,6 @@ namespace PolyVox uYPos * m_uSideLength + uZPos * m_uSideLength * m_uSideLength ] = tValue; - - m_bIsUncompressedDataModified = true; } template @@ -102,12 +98,8 @@ namespace PolyVox template void SimpleVolume::Block::fill(VoxelType tValue) { - //The memset *may* be faster than the std::fill(), but it doesn't compile nicely - //in 64-bit mode as casting the pointer to an int causes a loss of precision. - const uint32_t uNoOfVoxels = m_uSideLength * m_uSideLength * m_uSideLength; - std::fill(m_tUncompressedData, m_tUncompressedData + uNoOfVoxels, tValue); - - m_bIsUncompressedDataModified = true; + const uint32_t uNoOfVoxels = m_uSideLength * m_uSideLength * m_uSideLength; + std::fill(m_tUncompressedData, m_tUncompressedData + uNoOfVoxels, tValue); } template @@ -135,7 +127,7 @@ namespace PolyVox uint32_t SimpleVolume::Block::calculateSizeInBytes(void) { uint32_t uSizeInBytes = sizeof(Block); - uSizeInBytes += m_vecCompressedData.capacity() * sizeof(RunlengthEntry); + uSizeInBytes += sizeof(VoxelType) * m_uSideLength * m_uSideLength * m_uSideLength; return uSizeInBytes; } }