Optimised code for setting the flag states.

This commit is contained in:
David Williams 2012-12-01 00:47:50 +01:00
parent ba827d446b
commit 7b6fd11a06

View File

@ -545,23 +545,36 @@ namespace PolyVox
int32_t yPos = this->mYPosInVolume; int32_t yPos = this->mYPosInVolume;
int32_t zPos = this->mZPosInVolume; int32_t zPos = this->mZPosInVolume;
//FIXME - Can we speed this up?
if(this->mVolume->getEnclosingRegion().containsPoint(xPos, yPos, zPos, 1)) if(this->mVolume->getEnclosingRegion().containsPoint(xPos, yPos, zPos, 1))
{ {
//We're well inside the region so all flags can be set. // This is the most common case, where the position being set is well within the volume. We can just set all the flags to true.
m_uValidFlags = Current | PositiveX | NegativeX | PositiveY | NegativeY | PositiveZ | NegativeZ; m_uValidFlags = Current | PositiveX | NegativeX | PositiveY | NegativeY | PositiveZ | NegativeZ;
} }
else else
{ {
m_uValidFlags = 0; // We're not well inside the volume, so we could be on the edge of we could be outside. Determine which it is.
//FIXME - replace with versions which don't build Vector3DInt32. m_uValidFlags[CurrentShift] = this->mVolume->getEnclosingRegion().containsPoint(xPos, yPos, zPos, 0);
if(this->mVolume->getEnclosingRegion().containsPoint(xPos, yPos, zPos, 0)) m_uValidFlags |= Current;
if(this->mVolume->getEnclosingRegion().containsPoint(xPos+1, yPos, zPos, 0)) m_uValidFlags |= PositiveX; if(m_uValidFlags[Current])
if(this->mVolume->getEnclosingRegion().containsPoint(xPos-1, yPos, zPos, 0)) m_uValidFlags |= NegativeX; {
if(this->mVolume->getEnclosingRegion().containsPoint(xPos, yPos+1, zPos, 0)) m_uValidFlags |= PositiveY; // If we're on the edge then we can simplify the logic by only checking one bound as we know current position is valid.
if(this->mVolume->getEnclosingRegion().containsPoint(xPos, yPos-1, zPos, 0)) m_uValidFlags |= NegativeY; m_uValidFlags[PositiveXShift] = xPos < this->mVolume->getEnclosingRegion().getUpperX();
if(this->mVolume->getEnclosingRegion().containsPoint(xPos, yPos, zPos+1, 0)) m_uValidFlags |= PositiveZ; m_uValidFlags[PositiveYShift] = yPos < this->mVolume->getEnclosingRegion().getUpperY();
if(this->mVolume->getEnclosingRegion().containsPoint(xPos, yPos, zPos-1, 0)) m_uValidFlags |= NegativeZ; m_uValidFlags[PositiveZShift] = zPos < this->mVolume->getEnclosingRegion().getUpperZ();
m_uValidFlags[NegativeXShift] = xPos > this->mVolume->getEnclosingRegion().getLowerX();
m_uValidFlags[NegativeYShift] = yPos > this->mVolume->getEnclosingRegion().getLowerY();
m_uValidFlags[NegativeZShift] = zPos > this->mVolume->getEnclosingRegion().getLowerZ();
}
else
{
// We're outside the volume... hard to optimise for this (uncommon) case so do the full calculations for each position.
m_uValidFlags[PositiveXShift] = this->mVolume->getEnclosingRegion().containsPoint(xPos+1, yPos, zPos, 0);
m_uValidFlags[PositiveYShift] = this->mVolume->getEnclosingRegion().containsPoint(xPos, yPos+1, zPos, 0);
m_uValidFlags[PositiveZShift] = this->mVolume->getEnclosingRegion().containsPoint(xPos, yPos, zPos+1, 0);
m_uValidFlags[NegativeXShift] = this->mVolume->getEnclosingRegion().containsPoint(xPos-1, yPos, zPos, 0);
m_uValidFlags[NegativeYShift] = this->mVolume->getEnclosingRegion().containsPoint(xPos, yPos-1, zPos, 0);
m_uValidFlags[NegativeZShift] = this->mVolume->getEnclosingRegion().containsPoint(xPos, yPos, zPos-1, 0);
}
} }
} }
} }