Removed redundant stuff from Volume and VolumeIterator.

Fixed bug with scenery not disappearing.
This commit is contained in:
David Williams
2009-05-21 22:01:40 +00:00
parent 542ad104cc
commit 0888948138
4 changed files with 1 additions and 217 deletions

View File

@@ -228,187 +228,16 @@ namespace PolyVox
mCurrentVoxel = currentBlock->m_tData + mVoxelIndexInBlock;
}
template <typename VoxelType>
void VolumeIterator<VoxelType>::setValidRegion(const Region& region)
{
setValidRegion(region.getLowerCorner().getX(),region.getLowerCorner().getY(),region.getLowerCorner().getZ(),region.getUpperCorner().getX(),region.getUpperCorner().getY(),region.getUpperCorner().getZ());
}
template <typename VoxelType>
void VolumeIterator<VoxelType>::setValidRegion(uint16_t xFirst, uint16_t yFirst, uint16_t zFirst, uint16_t xLast, uint16_t yLast, uint16_t zLast)
{
mXRegionFirst = xFirst;
mYRegionFirst = yFirst;
mZRegionFirst = zFirst;
mXRegionLast = xLast;
mYRegionLast = yLast;
mZRegionLast = zLast;
mXRegionFirstBlock = mXRegionFirst >> mVolume.m_uBlockSideLengthPower;
mYRegionFirstBlock = mYRegionFirst >> mVolume.m_uBlockSideLengthPower;
mZRegionFirstBlock = mZRegionFirst >> mVolume.m_uBlockSideLengthPower;
mXRegionLastBlock = mXRegionLast >> mVolume.m_uBlockSideLengthPower;
mYRegionLastBlock = mYRegionLast >> mVolume.m_uBlockSideLengthPower;
mZRegionLastBlock = mZRegionLast >> mVolume.m_uBlockSideLengthPower;
}
#pragma endregion
#pragma region Other
template <typename VoxelType>
bool VolumeIterator<VoxelType>::isValidForRegion(void) const
{
return mIsValidForRegion;
}
template <typename VoxelType>
void VolumeIterator<VoxelType>::moveForwardInRegionXYZFast(void)
{
mXPosInBlock++;
mCurrentVoxel++;
mXPosInVolume++;
if((mXPosInBlock == mVolume.m_uBlockSideLength) || (mXPosInVolume > mXRegionLast))
{
mXPosInVolume = (std::max)(mXRegionFirst,uint16_t(mXBlock * mVolume.m_uBlockSideLength));
mXPosInBlock = mXPosInVolume - (mXBlock << mVolume.m_uBlockSideLengthPower);
mVoxelIndexInBlock = mXPosInBlock +
mYPosInBlock * mVolume.m_uBlockSideLength +
mZPosInBlock * mVolume.m_uBlockSideLength * mVolume.m_uBlockSideLength;
POLYVOX_SHARED_PTR< Block<VoxelType> > currentBlock = mVolume.m_pBlocks[mBlockIndexInVolume];
mCurrentVoxel = currentBlock->m_tData + mVoxelIndexInBlock;
mYPosInBlock++;
mYPosInVolume++;
mCurrentVoxel += mVolume.m_uBlockSideLength;
if((mYPosInBlock == mVolume.m_uBlockSideLength) || (mYPosInVolume > mYRegionLast))
{
mYPosInVolume = (std::max)(mYRegionFirst,uint16_t(mYBlock * mVolume.m_uBlockSideLength));
mYPosInBlock = mYPosInVolume - (mYBlock << mVolume.m_uBlockSideLengthPower);
mVoxelIndexInBlock = mXPosInBlock +
mYPosInBlock * mVolume.m_uBlockSideLength +
mZPosInBlock * mVolume.m_uBlockSideLength * mVolume.m_uBlockSideLength;
Block<VoxelType>* currentBlock = mVolume.m_pBlocks[mBlockIndexInVolume];
mCurrentVoxel = currentBlock->m_tData + mVoxelIndexInBlock;
mZPosInBlock++;
mZPosInVolume++;
mCurrentVoxel += mVolume.m_uBlockSideLength * mVolume.m_uBlockSideLength;
if((mZPosInBlock == mVolume.m_uBlockSideLength) || (mZPosInVolume > mZRegionLast))
{
//At this point we've left the current block. Find a new one...
++mXBlock;
++mBlockIndexInVolume;
if(mXBlock > mXRegionLastBlock)
{
mXBlock = mXRegionFirstBlock;
mBlockIndexInVolume = mXBlock +
mYBlock * mVolume.m_uWidthInBlocks +
mZBlock * mVolume.m_uWidthInBlocks * mVolume.m_uHeightInBlocks;
++mYBlock;
mBlockIndexInVolume += mVolume.m_uWidthInBlocks;
if(mYBlock > mYRegionLastBlock)
{
mYBlock = mYRegionFirstBlock;
mBlockIndexInVolume = mXBlock +
mYBlock * mVolume.m_uSideLengthInBlocks +
mZBlock * mVolume.m_uSideLengthInBlocks * mVolume.m_uSideLengthInBlocks;
++mZBlock;
mBlockIndexInVolume += mVolume.m_uWidthInBlocks * mVolume.m_uHeightInBlocks;
if(mZBlock > mZRegionLastBlock)
{
mIsValidForRegion = false;
return;
}
}
}
Block<VoxelType>* currentBlock = mVolume.m_pBlocks[mBlockIndexInVolume];
//mCurrentBlock = mVolume->m_pBlocks[mBlockIndexInVolume];
mXPosInVolume = (std::max)(mXRegionFirst,uint16_t(mXBlock * mVolume.m_uBlockSideLength));
mYPosInVolume = (std::max)(mYRegionFirst,uint16_t(mYBlock * mVolume.m_uBlockSideLength));
mZPosInVolume = (std::max)(mZRegionFirst,uint16_t(mZBlock * mVolume.m_uBlockSideLength));
mXPosInBlock = mXPosInVolume - (mXBlock << mVolume.m_uBlockSideLengthPower);
mYPosInBlock = mYPosInVolume - (mYBlock << mVolume.m_uBlockSideLengthPower);
mZPosInBlock = mZPosInVolume - (mZBlock << mVolume.m_uBlockSideLengthPower);
mVoxelIndexInBlock = mXPosInBlock +
mYPosInBlock * mVolume.m_uBlockSideLength +
mZPosInBlock * mVolume.m_uBlockSideLength * mVolume.m_uBlockSideLength;
mCurrentVoxel = currentBlock->m_tData + mVoxelIndexInBlock;
}
}
}
}
template <typename VoxelType>
bool VolumeIterator<VoxelType>::moveForwardInRegionXYZ(void)
{
if(mXPosInVolume < mXRegionLast)
{
++mXPosInVolume;
if(mXPosInVolume % mVolume.m_uBlockSideLength != 0)
{
//No need to compute new block.
++mVoxelIndexInBlock;
++mCurrentVoxel;
}
else
{
//A more complex situation. Just call setPosition().
setPosition(mXPosInVolume, mYPosInVolume, mZPosInVolume);
}
}
else
{
mXPosInVolume = mXRegionFirst;
if(mYPosInVolume < mYRegionLast)
{
++mYPosInVolume;
//In the case of 'X' we used a trick to avoid calling this evey time. It's hard to use the same
//trick here because the x position has been reset and so is likely to be in a different block.
setPosition(mXPosInVolume, mYPosInVolume, mZPosInVolume);
}
else
{
mYPosInVolume = mYRegionFirst;
if(mZPosInVolume < mZRegionLast)
{
++mZPosInVolume;
//In the case of 'X' we used a trick to avoid calling this evey time. It's hard to use the same
//trick here because the x position has been reset and so is likely to be in a different block.
setPosition(mXPosInVolume, mYPosInVolume, mZPosInVolume);
}
else
{
//We've hit the end of the region. Reset x and y positions to where they were.
mXPosInVolume = mXRegionLast;
mYPosInVolume = mYRegionLast;
//Return false to indicate we failed to move forward.
return false;
}
}
}
return true;
}
template <typename VoxelType>
void VolumeIterator<VoxelType>::movePositiveX(void)
{
++mXPosInVolume;
if(mXPosInVolume % mVolume.m_uBlockSideLength == 0)
{
//We've hit the block boundary. Just calling setPosition() is the easiest weay to resolve this.
//We've hit the block boundary. Just calling setPosition() is the easiest way to resolve this.
setPosition(mXPosInVolume, mYPosInVolume, mZPosInVolume);
}
else