Removed redundant stuff from Volume and VolumeIterator.
Fixed bug with scenery not disappearing.
This commit is contained in:
parent
542ad104cc
commit
0888948138
@ -138,7 +138,6 @@ namespace PolyVox
|
||||
void setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue);
|
||||
|
||||
void tidyUpMemory(uint32_t uNoOfBlocksToProcess = (std::numeric_limits<uint32_t>::max)());
|
||||
bool isRegionHomogenous(const Region& region);
|
||||
|
||||
private:
|
||||
POLYVOX_SHARED_PTR< Block<VoxelType> > getHomogenousBlock(VoxelType tHomogenousValue) const;
|
||||
|
@ -372,28 +372,6 @@ namespace PolyVox
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
bool Volume<VoxelType>::isRegionHomogenous(const Region& region)
|
||||
{
|
||||
VolumeIterator<VoxelType> iter(*this);
|
||||
iter.setValidRegion(region);
|
||||
iter.setPosition(static_cast<Vector3DInt16>(region.getLowerCorner()));
|
||||
|
||||
VoxelType tFirst = iter.getVoxel();
|
||||
iter.moveForwardInRegionXYZ();
|
||||
|
||||
do
|
||||
{
|
||||
VoxelType tCurrent = iter.getVoxel();
|
||||
if(tCurrent != tFirst)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}while(iter.moveForwardInRegionXYZ());
|
||||
|
||||
return true;
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Private Implementation
|
||||
|
@ -53,12 +53,6 @@ namespace PolyVox
|
||||
|
||||
void setPosition(const Vector3DInt16& v3dNewPos);
|
||||
void setPosition(uint16_t xPos, uint16_t yPos, uint16_t zPos);
|
||||
void setValidRegion(const Region& region);
|
||||
void setValidRegion(uint16_t xFirst, uint16_t yFirst, uint16_t zFirst, uint16_t xLast, uint16_t yLast, uint16_t zLast);
|
||||
|
||||
bool isValidForRegion(void) const;
|
||||
bool moveForwardInRegionXYZ(void);
|
||||
void moveForwardInRegionXYZFast(void);
|
||||
|
||||
void movePositiveX(void);
|
||||
|
||||
@ -116,22 +110,6 @@ namespace PolyVox
|
||||
VoxelType* mCurrentVoxel;
|
||||
uint32_t mBlockIndexInVolume;
|
||||
uint32_t mVoxelIndexInBlock;
|
||||
|
||||
uint16_t mXRegionFirst;
|
||||
uint16_t mYRegionFirst;
|
||||
uint16_t mZRegionFirst;
|
||||
uint16_t mXRegionLast;
|
||||
uint16_t mYRegionLast;
|
||||
uint16_t mZRegionLast;
|
||||
|
||||
uint16_t mXRegionFirstBlock;
|
||||
uint16_t mYRegionFirstBlock;
|
||||
uint16_t mZRegionFirstBlock;
|
||||
uint16_t mXRegionLastBlock;
|
||||
uint16_t mYRegionLastBlock;
|
||||
uint16_t mZRegionLastBlock;
|
||||
|
||||
bool mIsValidForRegion;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user