Templatized Block class.
This commit is contained in:
@ -1,91 +0,0 @@
|
||||
/******************************************************************************
|
||||
This file is part of a voxel plugin for OGRE
|
||||
Copyright (C) 2006 David Williams
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
******************************************************************************/
|
||||
|
||||
#include "Block.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
using namespace boost;
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
|
||||
Block::Block()
|
||||
{
|
||||
}
|
||||
|
||||
Block::Block(const Block& rhs)
|
||||
{
|
||||
*this = rhs;
|
||||
}
|
||||
|
||||
Block::~Block()
|
||||
{
|
||||
}
|
||||
|
||||
Block& Block::operator=(const Block& rhs)
|
||||
{
|
||||
if (this == &rhs)
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
memcpy(mData,rhs.mData,POLYVOX_NO_OF_VOXELS_IN_BLOCK);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
uint8_t Block::getVoxelAt(const uint16_t xPosition, const uint16_t yPosition, const uint16_t zPosition) const
|
||||
{
|
||||
return mData
|
||||
[
|
||||
xPosition +
|
||||
yPosition * POLYVOX_BLOCK_SIDE_LENGTH +
|
||||
zPosition * POLYVOX_BLOCK_SIDE_LENGTH * POLYVOX_BLOCK_SIDE_LENGTH
|
||||
];
|
||||
}
|
||||
|
||||
void Block::setVoxelAt(const uint16_t xPosition, const uint16_t yPosition, const uint16_t zPosition, const uint8_t value)
|
||||
{
|
||||
mData
|
||||
[
|
||||
xPosition +
|
||||
yPosition * POLYVOX_BLOCK_SIDE_LENGTH +
|
||||
zPosition * POLYVOX_BLOCK_SIDE_LENGTH * POLYVOX_BLOCK_SIDE_LENGTH
|
||||
] = value;
|
||||
}
|
||||
|
||||
/*void Block::fillWithValue(const uint8_t value)
|
||||
{
|
||||
memset(mData,value,POLYVOX_NO_OF_VOXELS_IN_BLOCK);
|
||||
}*/
|
||||
|
||||
/*bool Block::isHomogeneous(void)
|
||||
{
|
||||
uint8_t uFirstVoxel = mData[0];
|
||||
for(uint32_t ct = 1; ct < POLYVOX_NO_OF_VOXELS_IN_BLOCK; ++ct)
|
||||
{
|
||||
if(mData[ct] != uFirstVoxel)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}*/
|
||||
}
|
@ -34,7 +34,7 @@ namespace PolyVox
|
||||
{
|
||||
for(uint16_t i = 0; i < POLYVOX_NO_OF_BLOCKS_IN_VOLUME; ++i)
|
||||
{
|
||||
mBlocks[i] = new Block;
|
||||
mBlocks[i] = new Block<boost::uint8_t>;
|
||||
}
|
||||
}
|
||||
|
||||
@ -124,7 +124,7 @@ namespace PolyVox
|
||||
block->setVoxelAt(xOffset,yOffset,zOffset, value);
|
||||
}*/
|
||||
|
||||
Block* Volume::getBlock(uint16_t index)
|
||||
Block<boost::uint8_t>* Volume::getBlock(uint16_t index)
|
||||
{
|
||||
return mBlocks[index];
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ namespace PolyVox
|
||||
|
||||
void VolumeIterator::setVoxel(uint8_t value)
|
||||
{
|
||||
Block* currentBlock = mVolume.mBlocks[mBlockIndexInVolume];
|
||||
Block<boost::uint8_t>* currentBlock = mVolume.mBlocks[mBlockIndexInVolume];
|
||||
|
||||
/*if(!currentBlock.unique())
|
||||
{
|
||||
@ -91,7 +91,7 @@ namespace PolyVox
|
||||
const uint16_t yOffset = yPosition - (blockY << POLYVOX_BLOCK_SIDE_LENGTH_POWER);
|
||||
const uint16_t zOffset = zPosition - (blockZ << POLYVOX_BLOCK_SIDE_LENGTH_POWER);
|
||||
|
||||
const Block* block = mVolume.mBlocks
|
||||
const Block<boost::uint8_t>* block = mVolume.mBlocks
|
||||
[
|
||||
blockX +
|
||||
blockY * POLYVOX_VOLUME_SIDE_LENGTH_IN_BLOCKS +
|
||||
@ -135,7 +135,7 @@ namespace PolyVox
|
||||
const uint16_t yOffset = yPosition - (blockY << POLYVOX_BLOCK_SIDE_LENGTH_POWER);
|
||||
const uint16_t zOffset = zPosition - (blockZ << POLYVOX_BLOCK_SIDE_LENGTH_POWER);
|
||||
|
||||
Block* block = mVolume.mBlocks
|
||||
Block<boost::uint8_t>* block = mVolume.mBlocks
|
||||
[
|
||||
blockX +
|
||||
blockY * POLYVOX_VOLUME_SIDE_LENGTH_IN_BLOCKS +
|
||||
@ -324,7 +324,7 @@ namespace PolyVox
|
||||
mBlockIndexInVolume = mXBlock +
|
||||
mYBlock * POLYVOX_VOLUME_SIDE_LENGTH_IN_BLOCKS +
|
||||
mZBlock * POLYVOX_VOLUME_SIDE_LENGTH_IN_BLOCKS * POLYVOX_VOLUME_SIDE_LENGTH_IN_BLOCKS;
|
||||
Block* currentBlock = mVolume.mBlocks[mBlockIndexInVolume];
|
||||
Block<boost::uint8_t>* currentBlock = mVolume.mBlocks[mBlockIndexInVolume];
|
||||
|
||||
mVoxelIndexInBlock = mXPosInBlock +
|
||||
mYPosInBlock * POLYVOX_BLOCK_SIDE_LENGTH +
|
||||
@ -372,7 +372,7 @@ namespace PolyVox
|
||||
mVoxelIndexInBlock = mXPosInBlock +
|
||||
mYPosInBlock * POLYVOX_BLOCK_SIDE_LENGTH +
|
||||
mZPosInBlock * POLYVOX_BLOCK_SIDE_LENGTH * POLYVOX_BLOCK_SIDE_LENGTH;
|
||||
Block* currentBlock = mVolume.mBlocks[mBlockIndexInVolume];
|
||||
Block<boost::uint8_t>* currentBlock = mVolume.mBlocks[mBlockIndexInVolume];
|
||||
mCurrentVoxel = currentBlock->mData + mVoxelIndexInBlock;
|
||||
|
||||
mYPosInBlock++;
|
||||
@ -385,7 +385,7 @@ namespace PolyVox
|
||||
mVoxelIndexInBlock = mXPosInBlock +
|
||||
mYPosInBlock * POLYVOX_BLOCK_SIDE_LENGTH +
|
||||
mZPosInBlock * POLYVOX_BLOCK_SIDE_LENGTH * POLYVOX_BLOCK_SIDE_LENGTH;
|
||||
Block* currentBlock = mVolume.mBlocks[mBlockIndexInVolume];
|
||||
Block<boost::uint8_t>* currentBlock = mVolume.mBlocks[mBlockIndexInVolume];
|
||||
mCurrentVoxel = currentBlock->mData + mVoxelIndexInBlock;
|
||||
|
||||
mZPosInBlock++;
|
||||
@ -424,7 +424,7 @@ namespace PolyVox
|
||||
}
|
||||
}
|
||||
|
||||
Block* currentBlock = mVolume.mBlocks[mBlockIndexInVolume];
|
||||
Block<boost::uint8_t>* currentBlock = mVolume.mBlocks[mBlockIndexInVolume];
|
||||
//mCurrentBlock = mVolume->mBlocks[mBlockIndexInVolume];
|
||||
|
||||
mXPosInVolume = (std::max)(mXRegionFirst,uint16_t(mXBlock * POLYVOX_BLOCK_SIDE_LENGTH));
|
||||
|
Reference in New Issue
Block a user