From b5d930062bae0ca20ef5df64a7f71cb8360bb406 Mon Sep 17 00:00:00 2001 From: David Williams Date: Tue, 16 Jul 2013 16:09:57 +0200 Subject: [PATCH] Const fixes. --- library/PolyVoxCore/include/PolyVoxCore/Compressor.h | 4 ++-- library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h | 3 ++- .../PolyVoxCore/include/PolyVoxCore/Impl/Block.inl | 10 ++++++++++ .../PolyVoxCore/include/PolyVoxCore/LargeVolume.inl | 4 ++-- .../include/PolyVoxCore/MinizCompressor.h | 4 ++-- .../PolyVoxCore/include/PolyVoxCore/RLECompressor.h | 4 ++-- .../include/PolyVoxCore/RLECompressor.inl | 12 ++++++------ library/PolyVoxCore/source/MinizCompressor.cpp | 4 ++-- 8 files changed, 28 insertions(+), 17 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Compressor.h b/library/PolyVoxCore/include/PolyVoxCore/Compressor.h index 8c00be5e..e85610de 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Compressor.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Compressor.h @@ -76,7 +76,7 @@ namespace PolyVox * \param uDstLength The length of the destination buffer (compression will fail if this isn't big enough). * \return The size of the resulting compressed data. */ - virtual uint32_t compress(void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength) = 0; + virtual uint32_t compress(const void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength) = 0; /** * Decompresses the data. @@ -93,7 +93,7 @@ namespace PolyVox * \param uDstLength The length of the destination buffer (decompression will fail if this isn't big enough). * \return The size of the resulting uncompressed data. */ - virtual uint32_t decompress(void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength) = 0; + virtual uint32_t decompress(const void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength) = 0; }; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h index 2b9893b5..32cb9857 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h @@ -56,6 +56,7 @@ namespace PolyVox { public: CompressedBlock(); + ~CompressedBlock(); const uint8_t* getData(void) const; uint32_t getDataSizeInBytes(void) const; @@ -64,7 +65,7 @@ namespace PolyVox uint32_t calculateSizeInBytes(void); - public: + private: uint8_t* m_pData; uint32_t m_uDataSizeInBytes; }; diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl index 492d829f..b59d6f0a 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl @@ -44,6 +44,13 @@ namespace PolyVox { } + template + CompressedBlock::~CompressedBlock() + { + delete[] m_pData; + m_pData = 0; + } + template const uint8_t* CompressedBlock::getData(void) const { @@ -71,6 +78,9 @@ namespace PolyVox // Copy the data across memcpy(m_pData, pData, uDataSizeInBytes); + + // Flag as modified + m_bDataModified = true; } template diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index ce482006..fdf4bcac 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -641,9 +641,9 @@ namespace PolyVox { UncompressedBlock* pUncompressedBlock = new UncompressedBlock(m_uBlockSideLength); - void* pSrcData = reinterpret_cast(block->m_pData); + const void* pSrcData = reinterpret_cast(block->getData()); void* pDstData = reinterpret_cast(pUncompressedBlock->m_tUncompressedData); - uint32_t uSrcLength = block->m_uDataSizeInBytes; + uint32_t uSrcLength = block->getDataSizeInBytes(); uint32_t uDstLength = m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength * sizeof(VoxelType); //MinizCompressor compressor; diff --git a/library/PolyVoxCore/include/PolyVoxCore/MinizCompressor.h b/library/PolyVoxCore/include/PolyVoxCore/MinizCompressor.h index fb2b2473..7ea8f967 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MinizCompressor.h +++ b/library/PolyVoxCore/include/PolyVoxCore/MinizCompressor.h @@ -25,8 +25,8 @@ namespace PolyVox // API documentation is in base class and gets inherited by Doxygen. uint32_t getMaxCompressedSize(uint32_t uUncompressedInputSize); - uint32_t compress(void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength); - uint32_t decompress(void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength); + uint32_t compress(const void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength); + uint32_t decompress(const void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength); private: unsigned int m_uCompressionFlags; diff --git a/library/PolyVoxCore/include/PolyVoxCore/RLECompressor.h b/library/PolyVoxCore/include/PolyVoxCore/RLECompressor.h index 10b52b90..03fd3318 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RLECompressor.h +++ b/library/PolyVoxCore/include/PolyVoxCore/RLECompressor.h @@ -30,8 +30,8 @@ namespace PolyVox // API documentation is in base class and gets inherited by Doxygen. uint32_t getMaxCompressedSize(uint32_t uUncompressedInputSize); - uint32_t compress(void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength); - uint32_t decompress(void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength); + uint32_t compress(const void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength); + uint32_t decompress(const void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength); }; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/RLECompressor.inl b/library/PolyVoxCore/include/PolyVoxCore/RLECompressor.inl index 0b43a301..cf65bc03 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RLECompressor.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RLECompressor.inl @@ -22,7 +22,7 @@ namespace PolyVox } template - uint32_t RLECompressor::compress(void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength) + uint32_t RLECompressor::compress(const void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength) { if(uSrcLength % sizeof(ValueType) != 0) { @@ -34,11 +34,11 @@ namespace PolyVox uDstLength /= sizeof(Run); // Get data pointers in the appropriate type - ValueType* pSrcDataAsType = reinterpret_cast(pSrcData); + const ValueType* pSrcDataAsType = reinterpret_cast(pSrcData); Run* pDstDataAsRun = reinterpret_cast(pDstData); // Pointers to just past the end of the data - ValueType* pSrcDataEnd = pSrcDataAsType + uSrcLength; + const ValueType* pSrcDataEnd = pSrcDataAsType + uSrcLength; Run* pDstDataEnd = pDstDataAsRun + uDstLength; //Counter for the output length @@ -83,7 +83,7 @@ namespace PolyVox } template - uint32_t RLECompressor::decompress(void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength) + uint32_t RLECompressor::decompress(const void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength) { if(uSrcLength % sizeof(Run) != 0) { @@ -95,11 +95,11 @@ namespace PolyVox uDstLength /= sizeof(ValueType); // Get data pointers in the appropriate type - Run* pSrcDataAsRun = reinterpret_cast(pSrcData); + const Run* pSrcDataAsRun = reinterpret_cast(pSrcData); ValueType* pDstDataAsType = reinterpret_cast(pDstData); // Pointers to just past the end of the data - Run* pSrcDataEnd = pSrcDataAsRun + uSrcLength; + const Run* pSrcDataEnd = pSrcDataAsRun + uSrcLength; ValueType* pDstDataEnd = pDstDataAsType + uDstLength; //Counter for the output length diff --git a/library/PolyVoxCore/source/MinizCompressor.cpp b/library/PolyVoxCore/source/MinizCompressor.cpp index a341ff81..aa35c644 100644 --- a/library/PolyVoxCore/source/MinizCompressor.cpp +++ b/library/PolyVoxCore/source/MinizCompressor.cpp @@ -70,7 +70,7 @@ namespace PolyVox return MZ_MAX(128 + (source_len * 110) / 100, 128 + source_len + ((source_len / (31 * 1024)) + 1) * 5); } - uint32_t MinizCompressor::compress(void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength) + uint32_t MinizCompressor::compress(const void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength) { //Get the deflator tdefl_compressor* pDeflator = reinterpret_cast(m_pDeflator); @@ -103,7 +103,7 @@ namespace PolyVox return ulDstLength; } - uint32_t MinizCompressor::decompress(void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength) + uint32_t MinizCompressor::decompress(const void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength) { // I don't know exactly why this limitation exists but it's an implementation detail of miniz. It shouldn't matter for our purposes // as our detination is a Block and those are always a power of two. If you need to use this class for other purposes then you'll