Const fixes.

This commit is contained in:
David Williams 2013-07-16 16:09:57 +02:00
parent 3904c9aa8f
commit b5d930062b
8 changed files with 28 additions and 17 deletions

View File

@ -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;
};
}

View File

@ -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;
};

View File

@ -44,6 +44,13 @@ namespace PolyVox
{
}
template <typename VoxelType>
CompressedBlock<VoxelType>::~CompressedBlock()
{
delete[] m_pData;
m_pData = 0;
}
template <typename VoxelType>
const uint8_t* CompressedBlock<VoxelType>::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 <typename VoxelType>

View File

@ -641,9 +641,9 @@ namespace PolyVox
{
UncompressedBlock<VoxelType>* pUncompressedBlock = new UncompressedBlock<VoxelType>(m_uBlockSideLength);
void* pSrcData = reinterpret_cast<void*>(block->m_pData);
const void* pSrcData = reinterpret_cast<const void*>(block->getData());
void* pDstData = reinterpret_cast<void*>(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;

View File

@ -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;

View File

@ -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);
};
}

View File

@ -22,7 +22,7 @@ namespace PolyVox
}
template<typename ValueType, typename LengthType>
uint32_t RLECompressor<ValueType, LengthType>::compress(void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength)
uint32_t RLECompressor<ValueType, LengthType>::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<ValueType*>(pSrcData);
const ValueType* pSrcDataAsType = reinterpret_cast<const ValueType*>(pSrcData);
Run* pDstDataAsRun = reinterpret_cast<Run*>(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<typename ValueType, typename LengthType>
uint32_t RLECompressor<ValueType, LengthType>::decompress(void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength)
uint32_t RLECompressor<ValueType, LengthType>::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<Run*>(pSrcData);
const Run* pSrcDataAsRun = reinterpret_cast<const Run*>(pSrcData);
ValueType* pDstDataAsType = reinterpret_cast<ValueType*>(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

View File

@ -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<tdefl_compressor*>(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