mCurrentVoxel is now zero if the current position is not in the volume. It used to just be set to some invalid address.

This commit is contained in:
Daviw Williams 2012-12-07 15:56:46 +01:00
parent eb0c7e7a9f
commit 4be54c6dd1
4 changed files with 73 additions and 48 deletions

View File

@ -103,6 +103,8 @@ namespace PolyVox
BaseVolume<VoxelType>::template Sampler< LargeVolume<VoxelType> >::setPosition(xPos, yPos, zPos);
// Then we update the voxel pointer
if(this->isCurrentPositionValid())
{
const int32_t uXBlock = this->mXPosInVolume >> this->mVolume->m_uBlockSideLengthPower;
const int32_t uYBlock = this->mYPosInVolume >> this->mVolume->m_uBlockSideLengthPower;
const int32_t uZBlock = this->mZPosInVolume >> this->mVolume->m_uBlockSideLengthPower;
@ -119,6 +121,11 @@ namespace PolyVox
mCurrentVoxel = pUncompressedCurrentBlock->m_tUncompressedData + uVoxelIndexInBlock;
}
else
{
mCurrentVoxel = 0;
}
}
template <typename VoxelType>
bool LargeVolume<VoxelType>::Sampler::setVoxel(VoxelType tValue)
@ -145,7 +152,7 @@ namespace PolyVox
BaseVolume<VoxelType>::template Sampler< LargeVolume<VoxelType> >::movePositiveX();
// Then we update the voxel pointer
if((this->isCurrentPositionValid()) && ((this->mXPosInVolume) % this->mVolume->m_uBlockSideLength != 0))
if((this->isCurrentPositionValid()) && mCurrentVoxel && ((this->mXPosInVolume) % this->mVolume->m_uBlockSideLength != 0))
{
//No need to compute new block.
++mCurrentVoxel;
@ -164,7 +171,7 @@ namespace PolyVox
BaseVolume<VoxelType>::template Sampler< LargeVolume<VoxelType> >::movePositiveY();
// Then we update the voxel pointer
if((this->isCurrentPositionValid()) && ((this->mYPosInVolume) % this->mVolume->m_uBlockSideLength != 0))
if((this->isCurrentPositionValid()) && mCurrentVoxel && ((this->mYPosInVolume) % this->mVolume->m_uBlockSideLength != 0))
{
//No need to compute new block.
mCurrentVoxel += this->mVolume->m_uBlockSideLength;
@ -183,7 +190,7 @@ namespace PolyVox
BaseVolume<VoxelType>::template Sampler< LargeVolume<VoxelType> >::movePositiveZ();
// Then we update the voxel pointer
if((this->isCurrentPositionValid()) && ((this->mZPosInVolume) % this->mVolume->m_uBlockSideLength != 0))
if((this->isCurrentPositionValid()) && mCurrentVoxel && ((this->mZPosInVolume) % this->mVolume->m_uBlockSideLength != 0))
{
//No need to compute new block.
mCurrentVoxel += this->mVolume->m_uBlockSideLength * this->mVolume->m_uBlockSideLength;
@ -202,7 +209,7 @@ namespace PolyVox
BaseVolume<VoxelType>::template Sampler< LargeVolume<VoxelType> >::moveNegativeX();
// Then we update the voxel pointer
if((this->isCurrentPositionValid()) && ((this->mXPosInVolume + 1) % this->mVolume->m_uBlockSideLength != 0))
if((this->isCurrentPositionValid()) && mCurrentVoxel && ((this->mXPosInVolume + 1) % this->mVolume->m_uBlockSideLength != 0))
{
//No need to compute new block.
--mCurrentVoxel;
@ -221,7 +228,7 @@ namespace PolyVox
BaseVolume<VoxelType>::template Sampler< LargeVolume<VoxelType> >::moveNegativeY();
// Then we update the voxel pointer
if((this->isCurrentPositionValid()) && ((this->mYPosInVolume + 1) % this->mVolume->m_uBlockSideLength != 0))
if((this->isCurrentPositionValid()) && mCurrentVoxel && ((this->mYPosInVolume + 1) % this->mVolume->m_uBlockSideLength != 0))
{
//No need to compute new block.
mCurrentVoxel -= this->mVolume->m_uBlockSideLength;
@ -240,7 +247,7 @@ namespace PolyVox
BaseVolume<VoxelType>::template Sampler< LargeVolume<VoxelType> >::moveNegativeZ();
// Then we update the voxel pointer
if((this->isCurrentPositionValid()) && ((this->mZPosInVolume + 1) % this->mVolume->m_uBlockSideLength != 0))
if((this->isCurrentPositionValid()) && mCurrentVoxel && ((this->mZPosInVolume + 1) % this->mVolume->m_uBlockSideLength != 0))
{
//No need to compute new block.
mCurrentVoxel -= this->mVolume->m_uBlockSideLength * this->mVolume->m_uBlockSideLength;

View File

@ -68,6 +68,8 @@ namespace PolyVox
BaseVolume<VoxelType>::template Sampler< RawVolume<VoxelType> >::setPosition(xPos, yPos, zPos);
// Then we update the voxel pointer
if(this->isCurrentPositionValid())
{
const Vector3DInt32& v3dLowerCorner = this->mVolume->m_regValidRegion.getLowerCorner();
int32_t iLocalXPos = xPos - v3dLowerCorner.getX();
int32_t iLocalYPos = yPos - v3dLowerCorner.getY();
@ -79,6 +81,11 @@ namespace PolyVox
mCurrentVoxel = this->mVolume->m_pData + uVoxelIndex;
}
else
{
mCurrentVoxel = 0;
}
}
template <typename VoxelType>
bool RawVolume<VoxelType>::Sampler::setVoxel(VoxelType tValue)
@ -102,7 +109,7 @@ namespace PolyVox
BaseVolume<VoxelType>::template Sampler< RawVolume<VoxelType> >::movePositiveX();
// Then we update the voxel pointer
if(this->isCurrentPositionValid())
if(this->isCurrentPositionValid() && mCurrentVoxel )
{
++mCurrentVoxel;
}
@ -119,7 +126,7 @@ namespace PolyVox
BaseVolume<VoxelType>::template Sampler< RawVolume<VoxelType> >::movePositiveY();
// Then we update the voxel pointer
if(this->isCurrentPositionValid())
if(this->isCurrentPositionValid() && mCurrentVoxel )
{
mCurrentVoxel += this->mVolume->getWidth();
}
@ -136,7 +143,7 @@ namespace PolyVox
BaseVolume<VoxelType>::template Sampler< RawVolume<VoxelType> >::movePositiveZ();
// Then we update the voxel pointer
if(this->isCurrentPositionValid())
if(this->isCurrentPositionValid() && mCurrentVoxel )
{
mCurrentVoxel += this->mVolume->getWidth() * this->mVolume->getHeight();
}
@ -153,7 +160,7 @@ namespace PolyVox
BaseVolume<VoxelType>::template Sampler< RawVolume<VoxelType> >::moveNegativeX();
// Then we update the voxel pointer
if(this->isCurrentPositionValid())
if(this->isCurrentPositionValid() && mCurrentVoxel )
{
--mCurrentVoxel;
}
@ -170,7 +177,7 @@ namespace PolyVox
BaseVolume<VoxelType>::template Sampler< RawVolume<VoxelType> >::moveNegativeY();
// Then we update the voxel pointer
if(this->isCurrentPositionValid())
if(this->isCurrentPositionValid() && mCurrentVoxel )
{
mCurrentVoxel -= this->mVolume->getWidth();
}
@ -187,7 +194,7 @@ namespace PolyVox
BaseVolume<VoxelType>::template Sampler< RawVolume<VoxelType> >::moveNegativeZ();
// Then we update the voxel pointer
if(this->isCurrentPositionValid())
if(this->isCurrentPositionValid() && mCurrentVoxel )
{
mCurrentVoxel -= this->mVolume->getWidth() * this->mVolume->getHeight();
}

View File

@ -306,6 +306,10 @@ namespace PolyVox
uBlockY -= m_regValidRegionInBlocks.getLowerCorner().getY();
uBlockZ -= m_regValidRegionInBlocks.getLowerCorner().getZ();
assert(uBlockX >= 0);
assert(uBlockY >= 0);
assert(uBlockZ >= 0);
//Compute the block index
uint32_t uBlockIndex =
uBlockX +

View File

@ -117,6 +117,8 @@ namespace PolyVox
BaseVolume<VoxelType>::template Sampler< SimpleVolume<VoxelType> >::setPosition(xPos, yPos, zPos);
// Then we update the voxel pointer
if(this->isCurrentPositionValid())
{
const int32_t uXBlock = this->mXPosInVolume >> this->mVolume->m_uBlockSideLengthPower;
const int32_t uYBlock = this->mYPosInVolume >> this->mVolume->m_uBlockSideLengthPower;
const int32_t uZBlock = this->mZPosInVolume >> this->mVolume->m_uBlockSideLengthPower;
@ -133,6 +135,11 @@ namespace PolyVox
mCurrentVoxel = pUncompressedCurrentBlock->m_tUncompressedData + uVoxelIndexInBlock;
}
else
{
mCurrentVoxel = 0;
}
}
/**
* \details
@ -164,7 +171,7 @@ namespace PolyVox
BaseVolume<VoxelType>::template Sampler< SimpleVolume<VoxelType> >::movePositiveX();
// Then we update the voxel pointer
if((this->isCurrentPositionValid()) && ((this->mXPosInVolume) % this->mVolume->m_uBlockSideLength != 0))
if((this->isCurrentPositionValid()) && mCurrentVoxel && ((this->mXPosInVolume) % this->mVolume->m_uBlockSideLength != 0))
{
//No need to compute new block.
++mCurrentVoxel;
@ -183,7 +190,7 @@ namespace PolyVox
BaseVolume<VoxelType>::template Sampler< SimpleVolume<VoxelType> >::movePositiveY();
// Then we update the voxel pointer
if((this->isCurrentPositionValid()) && ((this->mYPosInVolume) % this->mVolume->m_uBlockSideLength != 0))
if((this->isCurrentPositionValid()) && mCurrentVoxel && ((this->mYPosInVolume) % this->mVolume->m_uBlockSideLength != 0))
{
//No need to compute new block.
mCurrentVoxel += this->mVolume->m_uBlockSideLength;
@ -202,7 +209,7 @@ namespace PolyVox
BaseVolume<VoxelType>::template Sampler< SimpleVolume<VoxelType> >::movePositiveZ();
// Then we update the voxel pointer
if((this->isCurrentPositionValid()) && ((this->mZPosInVolume) % this->mVolume->m_uBlockSideLength != 0))
if((this->isCurrentPositionValid()) && mCurrentVoxel && ((this->mZPosInVolume) % this->mVolume->m_uBlockSideLength != 0))
{
//No need to compute new block.
mCurrentVoxel += this->mVolume->m_uBlockSideLength * this->mVolume->m_uBlockSideLength;
@ -221,7 +228,7 @@ namespace PolyVox
BaseVolume<VoxelType>::template Sampler< SimpleVolume<VoxelType> >::moveNegativeX();
// Then we update the voxel pointer
if((this->isCurrentPositionValid()) && ((this->mXPosInVolume + 1) % this->mVolume->m_uBlockSideLength != 0))
if((this->isCurrentPositionValid()) && mCurrentVoxel && ((this->mXPosInVolume + 1) % this->mVolume->m_uBlockSideLength != 0))
{
//No need to compute new block.
--mCurrentVoxel;
@ -240,7 +247,7 @@ namespace PolyVox
BaseVolume<VoxelType>::template Sampler< SimpleVolume<VoxelType> >::moveNegativeY();
// Then we update the voxel pointer
if((this->isCurrentPositionValid()) && ((this->mYPosInVolume + 1) % this->mVolume->m_uBlockSideLength != 0))
if((this->isCurrentPositionValid()) && mCurrentVoxel && ((this->mYPosInVolume + 1) % this->mVolume->m_uBlockSideLength != 0))
{
//No need to compute new block.
mCurrentVoxel -= this->mVolume->m_uBlockSideLength;
@ -259,7 +266,7 @@ namespace PolyVox
BaseVolume<VoxelType>::template Sampler< SimpleVolume<VoxelType> >::moveNegativeZ();
// Then we update the voxel pointer
if((this->isCurrentPositionValid()) && ((this->mZPosInVolume + 1) % this->mVolume->m_uBlockSideLength != 0))
if((this->isCurrentPositionValid()) && mCurrentVoxel && ((this->mZPosInVolume + 1) % this->mVolume->m_uBlockSideLength != 0))
{
//No need to compute new block.
mCurrentVoxel -= this->mVolume->m_uBlockSideLength * this->mVolume->m_uBlockSideLength;