From 50c1c7c64b6580794dc30c4915b2d14698d1035c Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Thu, 7 Feb 2013 15:55:10 +0100 Subject: [PATCH] Removed setCompressionEnabled() from LargeVolume. --- .../include/PolyVoxCore/LargeVolume.h | 3 -- .../include/PolyVoxCore/LargeVolume.inl | 38 +++++-------------- tests/testvolume.cpp | 12 +++--- tests/testvolume.h | 4 +- 4 files changed, 18 insertions(+), 39 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h index 5cae0359..7b8316b2 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h @@ -279,8 +279,6 @@ namespace PolyVox /// Gets a voxel at the position given by a 3D vector VoxelType getVoxelWithWrapping(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::Border, VoxelType tBorder = VoxelType(0)) const; - //Sets whether or not blocks are compressed in memory - void setCompressionEnabled(bool bCompressionEnabled); /// Sets the number of blocks for which uncompressed data is stored void setMaxNumberOfUncompressedBlocks(uint32_t uMaxNumberOfUncompressedBlocks); /// Sets the number of blocks which can be in memory before the paging system starts unloading them @@ -368,7 +366,6 @@ namespace PolyVox //The compressor used by the Blocks to compress their data if required. Compressor* m_pCompressor; - bool m_bCompressionEnabled; bool m_bPagingEnabled; }; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index 91efdf80..e92bda05 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -53,6 +53,7 @@ namespace PolyVox //////////////////////////////////////////////////////////////////////////////// /// This constructor creates a volume with a fixed size which is specified as a parameter. By default this constructor will not enable paging but you can override this if desired. If you do wish to enable paging then you are required to provide the call back function (see the other LargeVolume constructor). /// \param regValid Specifies the minimum and maximum valid voxel positions. + /// \param pCompressor An implementation of the Compressor interface which is used to compress blocks in memory. /// \param dataRequiredHandler The callback function which will be called when PolyVox tries to use data which is not currently in momory. /// \param dataOverflowHandler The callback function which will be called when PolyVox has too much data and needs to remove some from memory. /// \param bPagingEnabled Controls whether or not paging is enabled for this LargeVolume. @@ -82,7 +83,7 @@ namespace PolyVox //////////////////////////////////////////////////////////////////////////////// /// This function should never be called. Copying volumes by value would be expensive, and we want to prevent users from doing /// it by accident (such as when passing them as paramenters to functions). That said, there are times when you really do want to - /// make a copy of a volume and in this case you should look at the Volumeresampler. + /// make a copy of a volume and in this case you should look at the VolumeResampler. /// /// \sa VolumeResampler //////////////////////////////////////////////////////////////////////////////// @@ -243,30 +244,6 @@ namespace PolyVox return getVoxelWithWrapping(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), eWrapMode, tBorder); } - //////////////////////////////////////////////////////////////////////////////// - /// Enabling compression allows significantly more data to be stored in memory. - /// \param bCompressionEnabled Specifies whether compression is enabled. - //////////////////////////////////////////////////////////////////////////////// - template - void LargeVolume::setCompressionEnabled(bool bCompressionEnabled) - { - //Early out - nothing to do - if(m_bCompressionEnabled == bCompressionEnabled) - { - return; - } - - m_bCompressionEnabled = bCompressionEnabled; - - if(m_bCompressionEnabled) - { - //If compression has been enabled then we need to start honouring the max number of - //uncompressed blocks. Because compression has been disabled for a while we might have - //gone above that limit. Easiest solution is just to clear the cache and start again. - clearBlockCache(); - } - } - //////////////////////////////////////////////////////////////////////////////// /// Increasing the size of the block cache will increase memory but may improve performance. /// You may want to set this to a large value (e.g. 1024) when you are first loading your @@ -472,6 +449,7 @@ namespace PolyVox //Debug mode validation POLYVOX_ASSERT(uBlockSideLength > 0, "Block side length cannot be zero."); POLYVOX_ASSERT(isPowerOf2(uBlockSideLength), "Block side length must be a power of two."); + POLYVOX_ASSERT(m_pCompressor, "You must provide a compressor for the LargeVolume to use."); //Release mode validation if(uBlockSideLength == 0) @@ -482,6 +460,10 @@ namespace PolyVox { POLYVOX_THROW(std::invalid_argument, "Block side length must be a power of two."); } + if(!m_pCompressor) + { + POLYVOX_THROW(std::invalid_argument, "You must provide a compressor for the LargeVolume to use."); + } m_uTimestamper = 0; m_uMaxNumberOfUncompressedBlocks = 16; @@ -489,7 +471,6 @@ namespace PolyVox m_uMaxNumberOfBlocksInMemory = 1024; m_v3dLastAccessedBlockPos = Vector3DInt32(0,0,0); //There are no invalid positions, but initially the m_pLastAccessedBlock pointer will be null; m_pLastAccessedBlock = 0; - m_bCompressionEnabled = true; this->m_regValidRegion = regValidRegion; @@ -532,7 +513,8 @@ namespace PolyVox m_funcDataOverflowHandler(ConstVolumeProxy, reg); } - if(m_bCompressionEnabled) { + if(m_pCompressor) + { for(uint32_t ct = 0; ct < m_vecUncompressedBlockCache.size(); ct++) { // find the block in the uncompressed cache @@ -657,7 +639,7 @@ namespace PolyVox } //If we are allowed to compress then check whether we need to - if((m_bCompressionEnabled) && (m_vecUncompressedBlockCache.size() == m_uMaxNumberOfUncompressedBlocks)) + if((m_pCompressor) && (m_vecUncompressedBlockCache.size() == m_uMaxNumberOfUncompressedBlocks)) { int32_t leastRecentlyUsedBlockIndex = -1; uint32_t uLeastRecentTimestamp = (std::numeric_limits::max)(); diff --git a/tests/testvolume.cpp b/tests/testvolume.cpp index 74a3ffa1..03a35b53 100644 --- a/tests/testvolume.cpp +++ b/tests/testvolume.cpp @@ -271,8 +271,8 @@ TestVolume::TestVolume() { Region region(-57, -31, 12, 64, 96, 131); // Deliberatly awkward size - //m_pCompressor = new RLECompressor; - m_pCompressor = new MinizCompressor; + m_pCompressor = new RLECompressor; + //m_pCompressor = new MinizCompressor; //Create the volumes m_pRawVolume = new RawVolume(region); @@ -312,7 +312,7 @@ TestVolume::~TestVolume() * RawVolume Tests */ -/*void TestVolume::testRawVolumeDirectAccessAllInternalForwards() +void TestVolume::testRawVolumeDirectAccessAllInternalForwards() { int32_t result = 0; @@ -398,13 +398,13 @@ void TestVolume::testRawVolumeSamplersWithExternalBackwards() result = testSamplersWithWrappingBackwards(m_pRawVolume, -1, -3, -2, 2, 5, 4); } QCOMPARE(result, static_cast(-769775893)); -}*/ +} /* * SimpleVolume Tests */ -/*void TestVolume::testSimpleVolumeDirectAccessAllInternalForwards() +void TestVolume::testSimpleVolumeDirectAccessAllInternalForwards() { int32_t result = 0; QBENCHMARK @@ -482,7 +482,7 @@ void TestVolume::testSimpleVolumeSamplersWithExternalBackwards() result = testSamplersWithWrappingBackwards(m_pSimpleVolume, -1, -3, -2, 2, 5, 4); } QCOMPARE(result, static_cast(-769775893)); -}*/ +} /* * LargeVolume Tests diff --git a/tests/testvolume.h b/tests/testvolume.h index 59a63ec8..0c363109 100644 --- a/tests/testvolume.h +++ b/tests/testvolume.h @@ -37,7 +37,7 @@ public: ~TestVolume(); private slots: - /*void testRawVolumeDirectAccessAllInternalForwards(); + void testRawVolumeDirectAccessAllInternalForwards(); void testRawVolumeSamplersAllInternalForwards(); void testRawVolumeDirectAccessWithExternalForwards(); void testRawVolumeSamplersWithExternalForwards(); @@ -53,7 +53,7 @@ private slots: void testSimpleVolumeDirectAccessAllInternalBackwards(); void testSimpleVolumeSamplersAllInternalBackwards(); void testSimpleVolumeDirectAccessWithExternalBackwards(); - void testSimpleVolumeSamplersWithExternalBackwards();*/ + void testSimpleVolumeSamplersWithExternalBackwards(); void testLargeVolumeDirectAccessAllInternalForwards(); void testLargeVolumeSamplersAllInternalForwards();