diff --git a/library/PolyVoxCore/CMakeLists.txt b/library/PolyVoxCore/CMakeLists.txt index 5f2d49b3..bb28c01e 100644 --- a/library/PolyVoxCore/CMakeLists.txt +++ b/library/PolyVoxCore/CMakeLists.txt @@ -49,8 +49,9 @@ SET(CORE_INC_FILES include/PolyVoxCore/BaseVolume.inl include/PolyVoxCore/BaseVolumeSampler.inl include/PolyVoxCore/Block.h - include/PolyVoxCore/Block.inl include/PolyVoxCore/BlockCompressor.h + include/PolyVoxCore/CompressedBlock.h + include/PolyVoxCore/CompressedBlock.inl include/PolyVoxCore/Compressor.h include/PolyVoxCore/CubicSurfaceExtractor.h include/PolyVoxCore/CubicSurfaceExtractor.inl @@ -95,6 +96,8 @@ SET(CORE_INC_FILES include/PolyVoxCore/SimpleVolumeSampler.inl include/PolyVoxCore/SurfaceMesh.h include/PolyVoxCore/SurfaceMesh.inl + include/PolyVoxCore/UncompressedBlock.h + include/PolyVoxCore/UncompressedBlock.inl include/PolyVoxCore/Vector.h include/PolyVoxCore/Vector.inl include/PolyVoxCore/VertexTypes.h diff --git a/library/PolyVoxCore/include/PolyVoxCore/Block.h b/library/PolyVoxCore/include/PolyVoxCore/Block.h index a1567552..e2bb16cb 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Block.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Block.h @@ -1,5 +1,5 @@ /******************************************************************************* -Copyright (c) 2005-2009 David Williams +Copyright (c) 2005-2013 David Williams and Matthew Williams This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages @@ -61,71 +61,6 @@ namespace PolyVox /// Private assignment operator to prevent accisdental copying Block& operator=(const Block& /*rhs*/) {}; }; - - template - class CompressedBlock : public Block - { - friend class LargeVolume; - - public: - CompressedBlock(); - ~CompressedBlock(); - - const uint8_t* getData(void) const; - uint32_t getDataSizeInBytes(void) const; - - void setData(const uint8_t* const pData, uint32_t uDataSizeInBytes); - - private: - /// Private copy constructor to prevent accisdental copying - CompressedBlock(const CompressedBlock& /*rhs*/) {}; - - /// Private assignment operator to prevent accisdental copying - CompressedBlock& operator=(const CompressedBlock& /*rhs*/) {}; - - // Made this private to avoid any confusion with getDataSizeInBytes(). - // Users shouldn't really need this for CompressedBlock anyway. - uint32_t calculateSizeInBytes(void); - - uint8_t* m_pData; - uint32_t m_uDataSizeInBytes; - }; - - template - class UncompressedBlock : public Block - { - friend class LargeVolume; - - public: - UncompressedBlock(uint16_t uSideLength); - ~UncompressedBlock(); - - VoxelType* getData(void) const; - uint32_t getDataSizeInBytes(void) const; - - VoxelType getVoxel(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const; - VoxelType getVoxel(const Vector3DUint16& v3dPos) const; - - void setVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos, VoxelType tValue); - void setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue); - - private: - /// Private copy constructor to prevent accisdental copying - UncompressedBlock(const UncompressedBlock& /*rhs*/) {}; - - /// Private assignment operator to prevent accisdental copying - UncompressedBlock& operator=(const UncompressedBlock& /*rhs*/) {}; - - // Made this private for consistancy with CompressedBlock. - // Users shouldn't really need this for UncompressedBlock anyway. - uint32_t calculateSizeInBytes(void); - - VoxelType* m_tData; - uint16_t m_uSideLength; - uint8_t m_uSideLengthPower; - }; } -#include "PolyVoxCore/Block.inl" - #endif diff --git a/library/PolyVoxCore/include/PolyVoxCore/BlockCompressor.h b/library/PolyVoxCore/include/PolyVoxCore/BlockCompressor.h index 2646e94c..5af6dbfb 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/BlockCompressor.h +++ b/library/PolyVoxCore/include/PolyVoxCore/BlockCompressor.h @@ -25,7 +25,8 @@ freely, subject to the following restrictions: #define __PolyVox_BlockCompressor_H__ #include "PolyVoxCore/PolyVoxForwardDeclarations.h" -#include "PolyVoxCore/Block.h" +#include "PolyVoxCore/CompressedBlock.h" +#include "PolyVoxCore/UncompressedBlock.h" namespace PolyVox { diff --git a/library/PolyVoxCore/include/PolyVoxCore/CompressedBlock.h b/library/PolyVoxCore/include/PolyVoxCore/CompressedBlock.h new file mode 100644 index 00000000..5a8ba89a --- /dev/null +++ b/library/PolyVoxCore/include/PolyVoxCore/CompressedBlock.h @@ -0,0 +1,63 @@ +/******************************************************************************* +Copyright (c) 2005-2013 David Williams and Matthew Williams + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. +*******************************************************************************/ + +#ifndef __PolyVox_CompressedBlock_H__ +#define __PolyVox_CompressedBlock_H__ + +#include "PolyVoxCore/Block.h" + +namespace PolyVox +{ + template + class CompressedBlock : public Block + { + friend class LargeVolume; + + public: + CompressedBlock(); + ~CompressedBlock(); + + const uint8_t* getData(void) const; + uint32_t getDataSizeInBytes(void) const; + + void setData(const uint8_t* const pData, uint32_t uDataSizeInBytes); + + private: + /// Private copy constructor to prevent accisdental copying + CompressedBlock(const CompressedBlock& /*rhs*/) {}; + + /// Private assignment operator to prevent accisdental copying + CompressedBlock& operator=(const CompressedBlock& /*rhs*/) {}; + + // Made this private to avoid any confusion with getDataSizeInBytes(). + // Users shouldn't really need this for CompressedBlock anyway. + uint32_t calculateSizeInBytes(void); + + uint8_t* m_pData; + uint32_t m_uDataSizeInBytes; + }; +} + +#include "PolyVoxCore/CompressedBlock.inl" + +#endif diff --git a/library/PolyVoxCore/include/PolyVoxCore/CompressedBlock.inl b/library/PolyVoxCore/include/PolyVoxCore/CompressedBlock.inl new file mode 100644 index 00000000..e98df8e3 --- /dev/null +++ b/library/PolyVoxCore/include/PolyVoxCore/CompressedBlock.inl @@ -0,0 +1,79 @@ +/******************************************************************************* +Copyright (c) 2005-2013 David Williams and Matthew Williams + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. +*******************************************************************************/ + +namespace PolyVox +{ + template + CompressedBlock::CompressedBlock() + :m_pData(0) + ,m_uDataSizeInBytes(0) + { + } + + template + CompressedBlock::~CompressedBlock() + { + delete[] m_pData; + m_pData = 0; + } + + template + const uint8_t* CompressedBlock::getData(void) const + { + return m_pData; + } + + template + uint32_t CompressedBlock::getDataSizeInBytes(void) const + { + return m_uDataSizeInBytes; + } + + template + void CompressedBlock::setData(const uint8_t* const pData, uint32_t uDataSizeInBytes) + { + POLYVOX_THROW_IF(pData == 0, std::invalid_argument, "Pointer to data cannot be null"); + POLYVOX_THROW_IF(m_pData == pData, std::invalid_argument, "Attempting to copy data onto itself"); + + // Delete any existing data + delete[] m_pData; + + // Allocate new data + m_uDataSizeInBytes = uDataSizeInBytes; + m_pData = new uint8_t[uDataSizeInBytes]; + + // Copy the data across + memcpy(m_pData, pData, uDataSizeInBytes); + + // Flag as modified + this->m_bDataModified = true; + } + + template + uint32_t CompressedBlock::calculateSizeInBytes(void) + { + // Returns the size of this class plus the size of the compressed data. + uint32_t uSizeInBytes = sizeof(CompressedBlock) + m_uDataSizeInBytes; + return uSizeInBytes; + } +} diff --git a/library/PolyVoxCore/include/PolyVoxCore/Pager.h b/library/PolyVoxCore/include/PolyVoxCore/Pager.h index 6189566a..eb37e4f7 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Pager.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Pager.h @@ -24,7 +24,7 @@ freely, subject to the following restrictions: #ifndef __PolyVox_Pager_H__ #define __PolyVox_Pager_H__ -#include "PolyVoxCore/Block.h" +#include "PolyVoxCore/CompressedBlock.h" #include "PolyVoxCore/Impl/TypeDef.h" namespace PolyVox diff --git a/library/PolyVoxCore/include/PolyVoxCore/UncompressedBlock.h b/library/PolyVoxCore/include/PolyVoxCore/UncompressedBlock.h new file mode 100644 index 00000000..54a1aacb --- /dev/null +++ b/library/PolyVoxCore/include/PolyVoxCore/UncompressedBlock.h @@ -0,0 +1,68 @@ +/******************************************************************************* +Copyright (c) 2005-2013 David Williams and Matthew Williams + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. +*******************************************************************************/ + +#ifndef __PolyVox_UncompressedBlock_H__ +#define __PolyVox_UncompressedBlock_H__ + +#include "PolyVoxCore/Block.h" + +namespace PolyVox +{ + template + class UncompressedBlock : public Block + { + friend class LargeVolume; + + public: + UncompressedBlock(uint16_t uSideLength); + ~UncompressedBlock(); + + VoxelType* getData(void) const; + uint32_t getDataSizeInBytes(void) const; + + VoxelType getVoxel(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const; + VoxelType getVoxel(const Vector3DUint16& v3dPos) const; + + void setVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos, VoxelType tValue); + void setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue); + + private: + /// Private copy constructor to prevent accisdental copying + UncompressedBlock(const UncompressedBlock& /*rhs*/) {}; + + /// Private assignment operator to prevent accisdental copying + UncompressedBlock& operator=(const UncompressedBlock& /*rhs*/) {}; + + // Made this private for consistancy with CompressedBlock. + // Users shouldn't really need this for UncompressedBlock anyway. + uint32_t calculateSizeInBytes(void); + + VoxelType* m_tData; + uint16_t m_uSideLength; + uint8_t m_uSideLengthPower; + }; +} + +#include "PolyVoxCore/UncompressedBlock.inl" + +#endif diff --git a/library/PolyVoxCore/include/PolyVoxCore/Block.inl b/library/PolyVoxCore/include/PolyVoxCore/UncompressedBlock.inl similarity index 62% rename from library/PolyVoxCore/include/PolyVoxCore/Block.inl rename to library/PolyVoxCore/include/PolyVoxCore/UncompressedBlock.inl index 279dbf0e..4d506d74 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Block.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/UncompressedBlock.inl @@ -1,5 +1,5 @@ /******************************************************************************* -Copyright (c) 2005-2009 David Williams +Copyright (c) 2005-2013 David Williams and Matthew Williams This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages @@ -9,90 +9,20 @@ Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: -1. The origin of this software must not be misrepresented; you must not -claim that you wrote the original software. If you use this software -in a product, an acknowledgment in the product documentation would be -appreciated but is not required. + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be -misrepresented as being the original software. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. -3. This notice may not be removed or altered from any source -distribution. + 3. This notice may not be removed or altered from any source + distribution. *******************************************************************************/ -#include "PolyVoxCore/Impl/ErrorHandling.h" -#include "PolyVoxCore/Impl/Utility.h" - -#include "PolyVoxCore/Compressor.h" -#include "PolyVoxCore/Vector.h" - -#include "PolyVoxCore/Impl/ErrorHandling.h" - -#include //For memcpy -#include -#include //for std::invalid_argument - namespace PolyVox { - //////////////////////////////////////////////////////////////////////////////// - - template - CompressedBlock::CompressedBlock() - :m_pData(0) - ,m_uDataSizeInBytes(0) - { - } - - template - CompressedBlock::~CompressedBlock() - { - delete[] m_pData; - m_pData = 0; - } - - template - const uint8_t* CompressedBlock::getData(void) const - { - return m_pData; - } - - template - uint32_t CompressedBlock::getDataSizeInBytes(void) const - { - return m_uDataSizeInBytes; - } - - template - void CompressedBlock::setData(const uint8_t* const pData, uint32_t uDataSizeInBytes) - { - POLYVOX_THROW_IF(pData == 0, std::invalid_argument, "Pointer to data cannot be null"); - POLYVOX_THROW_IF(m_pData == pData, std::invalid_argument, "Attempting to copy data onto itself"); - - // Delete any existing data - delete[] m_pData; - - // Allocate new data - m_uDataSizeInBytes = uDataSizeInBytes; - m_pData = new uint8_t[uDataSizeInBytes]; - - // Copy the data across - memcpy(m_pData, pData, uDataSizeInBytes); - - // Flag as modified - this->m_bDataModified = true; - } - - template - uint32_t CompressedBlock::calculateSizeInBytes(void) - { - // Returns the size of this class plus the size of the compressed data. - uint32_t uSizeInBytes = sizeof(CompressedBlock) + m_uDataSizeInBytes; - return uSizeInBytes; - } - - //////////////////////////////////////////////////////////////////////////////// - template UncompressedBlock::UncompressedBlock(uint16_t uSideLength) :m_tData(0)