diff --git a/include/Volume.h b/include/Volume.h index 12be1265..0f9eb7fb 100644 --- a/include/Volume.h +++ b/include/Volume.h @@ -36,7 +36,7 @@ namespace PolyVox //Volume interface public: - Volume(); + Volume(boost::uint8_t uSideLengthPower, boost::uint8_t uBlockSideLengthPower); ~Volume(); private: @@ -51,7 +51,11 @@ namespace PolyVox private: Block* getBlock(boost::uint16_t index); - Block* mBlocks[POLYVOX_NO_OF_BLOCKS_IN_VOLUME]; + Block** mBlocks; + boost::uint32_t m_uNoOfBlocksInVolume; + + boost::uint16_t m_uSideLengthPower; + boost::uint16_t m_uSideLength; }; //Some handy typedefs diff --git a/include/Volume.inl b/include/Volume.inl index 6aa6887e..458ccd5c 100644 --- a/include/Volume.inl +++ b/include/Volume.inl @@ -28,11 +28,28 @@ namespace PolyVox { template - Volume::Volume() + Volume::Volume(boost::uint8_t uSideLengthPower, boost::uint8_t uBlockSideLengthPower) { - for(boost::uint16_t i = 0; i < POLYVOX_NO_OF_BLOCKS_IN_VOLUME; ++i) + //Check the volume size is sensible. This corresponds to a side length of 65536 voxels + assert(uSideLengthPower <= 16); + + //Compute the volume side length + m_uSideLengthPower = uSideLengthPower; + m_uSideLength = 0x01 << uSideLengthPower; + + //Compute the block side length + boost::uint16_t uBlockSideLength = 0x01 << uBlockSideLengthPower; + + //Compute the side length in blocks + boost::uint16_t uSideLengthInBlocks = m_uSideLength / uBlockSideLength; + + //Compute number of blocks in the volume + m_uNoOfBlocksInVolume = uSideLengthInBlocks * uSideLengthInBlocks * uSideLengthInBlocks; + + mBlocks = new Block*[m_uNoOfBlocksInVolume]; + for(boost::uint32_t i = 0; i < m_uNoOfBlocksInVolume; ++i) { - mBlocks[i] = new Block(POLYVOX_BLOCK_SIDE_LENGTH_POWER); + mBlocks[i] = new Block(uBlockSideLengthPower); } } @@ -46,7 +63,7 @@ namespace PolyVox template Volume::~Volume() { - for(boost::uint16_t i = 0; i < POLYVOX_NO_OF_BLOCKS_IN_VOLUME; ++i) + for(boost::uint32_t i = 0; i < m_uNoOfBlocksInVolume; ++i) { delete mBlocks[i]; } @@ -67,7 +84,7 @@ namespace PolyVox mBlocks[i] = SharedPtr(new Block); }*/ - for(uint16_t i = 0; i < POLYVOX_NO_OF_BLOCKS_IN_VOLUME; ++i) + for(uint32_t i = 0; i < m_uNoOfBlocksInVolume; ++i) { //I think this is OK... If a block is in the homogeneous array it's ref count will be greater //than 1 as there will be the pointer in the volume and the pointer in the static homogeneous array. @@ -94,9 +111,9 @@ namespace PolyVox template bool Volume::containsPoint(Vector3DFloat pos, float boundary) { - return (pos.x() < POLYVOX_VOLUME_SIDE_LENGTH - 1 - boundary) - && (pos.y() < POLYVOX_VOLUME_SIDE_LENGTH - 1 - boundary) - && (pos.z() < POLYVOX_VOLUME_SIDE_LENGTH - 1 - boundary) + return (pos.x() < m_uSideLength - 1 - boundary) + && (pos.y() < m_uSideLength - 1 - boundary) + && (pos.z() < m_uSideLength - 1 - boundary) && (pos.x() > boundary) && (pos.y() > boundary) && (pos.z() > boundary); @@ -105,9 +122,9 @@ namespace PolyVox template bool Volume::containsPoint(Vector3DInt32 pos, boost::uint16_t boundary) { - return (pos.x() < POLYVOX_VOLUME_SIDE_LENGTH - 1 - boundary) - && (pos.y() < POLYVOX_VOLUME_SIDE_LENGTH - 1 - boundary) - && (pos.z() < POLYVOX_VOLUME_SIDE_LENGTH - 1 - boundary) + return (pos.x() < m_uSideLength - 1 - boundary) + && (pos.y() < m_uSideLength - 1 - boundary) + && (pos.z() < m_uSideLength - 1 - boundary) && (pos.x() > boundary) && (pos.y() > boundary) && (pos.z() > boundary); diff --git a/source/PolyVoxSceneManager.cpp b/source/PolyVoxSceneManager.cpp index 2765b8ce..79479ffc 100644 --- a/source/PolyVoxSceneManager.cpp +++ b/source/PolyVoxSceneManager.cpp @@ -152,7 +152,7 @@ namespace PolyVox void PolyVoxSceneManager::generateLevelVolume(void) { //volumeData = VolumePtr(new Volume); - volumeData = new Volume(); + volumeData = new Volume(POLYVOX_VOLUME_SIDE_LENGTH_POWER, POLYVOX_BLOCK_SIDE_LENGTH_POWER); VolumeIterator volIter(*volumeData); for(uint16_t z = 0; z < POLYVOX_VOLUME_SIDE_LENGTH; ++z) {