Commited refactoring changes made on the train.

This commit is contained in:
David Williams
2008-05-13 19:49:03 +00:00
parent 2107128f7c
commit b48b869eb2
10 changed files with 244 additions and 109 deletions

View File

@ -19,9 +19,6 @@ namespace PolyVox
const boost::uint32_t POLYVOX_REGION_SIDE_LENGTH_POWER = 4;
const boost::uint32_t POLYVOX_REGION_SIDE_LENGTH = (0x0001 << POLYVOX_REGION_SIDE_LENGTH_POWER);
const boost::uint32_t POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS = (POLYVOX_VOLUME_SIDE_LENGTH >> POLYVOX_REGION_SIDE_LENGTH_POWER);
const boost::uint32_t POLYVOX_NO_OF_REGIONS_IN_VOLUME = (POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS * POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS * POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS);
const boost::uint32_t POLYVOX_MAX_VOXELS_TO_BURN_PER_FRAME = 1000;
}
#endif

64
include/LinearVolume.h Normal file
View File

@ -0,0 +1,64 @@
#pragma region License
/******************************************************************************
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.
******************************************************************************/
#pragma endregion
#ifndef __PolyVox_LinearVolume_H__
#define __PolyVox_LinearVolume_H__
#pragma region Headers
#include "Constants.h"
#include "PolyVoxForwardDeclarations.h"
#include "TypeDef.h"
#include "boost/cstdint.hpp"
#pragma endregion
namespace PolyVox
{
template <typename VoxelType>
class LinearVolume
{
public:
LinearVolume(boost::uint8_t uSideLengthPower);
LinearVolume(const LinearVolume& rhs);
~LinearVolume();
LinearVolume& operator=(const LinearVolume& rhs);
//bool isHomogeneous(void);
boost::uint16_t getSideLength(void);
VoxelType getVoxelAt(const boost::uint16_t xPosition, const boost::uint16_t yPosition, const boost::uint16_t zPosition) const;
void setVoxelAt(const boost::uint16_t xPosition, const boost::uint16_t yPosition, const boost::uint16_t zPosition, const VoxelType value);
//void fillWithValue(const VoxelType value);
private:
boost::uint32_t getNoOfVoxels(void);
boost::uint8_t m_uSideLengthPower;
boost::uint16_t m_uSideLength;
VoxelType* m_tData;
};
}
#include "LinearVolume.inl"
#endif

100
include/LinearVolume.inl Normal file
View File

@ -0,0 +1,100 @@
/******************************************************************************
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 <cstring>
namespace PolyVox
{
template <typename VoxelType>
LinearVolume<VoxelType>::LinearVolume(boost::uint8_t uSideLengthPower)
:m_tData(0)
{
//Check the block size is sensible. This corresponds to a side length of 256 voxels
assert(uSideLengthPower <= 8);
//Compute the side length
m_uSideLengthPower = uSideLengthPower;
m_uSideLength = 0x01 << uSideLengthPower;
//If this fails an exception will be thrown. Memory is not
//allocated and there is nothing else in this class to clean up
m_tData = new VoxelType[getNoOfVoxels()];
}
template <typename VoxelType>
LinearVolume<VoxelType>::LinearVolume(const LinearVolume<VoxelType>& rhs)
{
*this = rhs;
}
template <typename VoxelType>
LinearVolume<VoxelType>::~LinearVolume()
{
delete[] m_tData;
m_tData = 0;
}
template <typename VoxelType>
LinearVolume<VoxelType>& LinearVolume<VoxelType>::operator=(const LinearVolume<VoxelType>& rhs)
{
if (this == &rhs)
{
return *this;
}
memcpy(m_tData,rhs.m_tData,getNoOfVoxels());
return *this;
}
template <typename VoxelType>
VoxelType LinearVolume<VoxelType>::getVoxelAt(const boost::uint16_t xPosition, const boost::uint16_t yPosition, const boost::uint16_t zPosition) const
{
return m_tData
[
xPosition +
yPosition * m_uSideLength +
zPosition * m_uSideLength * m_uSideLength
];
}
template <typename VoxelType>
void LinearVolume<VoxelType>::setVoxelAt(const boost::uint16_t xPosition, const boost::uint16_t yPosition, const boost::uint16_t zPosition, const VoxelType value)
{
m_tData
[
xPosition +
yPosition * m_uSideLength +
zPosition * m_uSideLength * m_uSideLength
] = value;
}
template <typename VoxelType>
boost::uint16_t LinearVolume<VoxelType>::getSideLength(void)
{
return m_uSideLength;
}
template <typename VoxelType>
boost::uint32_t LinearVolume<VoxelType>::getNoOfVoxels(void)
{
return m_uSideLength * m_uSideLength * m_uSideLength;
}
}

View File

@ -8,6 +8,7 @@ namespace PolyVox
template <typename VoxelType> class Block;
class IndexedSurfacePatch;
class IntegrealVector3;
template <typename VoxelType> class LinearVolume;
class PolyVoxSceneManager;
class RegionGeometry;
class SurfaceVertex;

View File

@ -51,6 +51,7 @@ namespace PolyVox
//Setters
void setVolumeData(Volume<boost::uint8_t>* volumeDataToSet);
void setNormalGenerationMethod(NormalGenerationMethod method);
//void _findVisibleObjects(Camera* cam, VisibleObjectsBoundsInfo * visibleBounds, bool onlyShadowCasters);
@ -61,15 +62,13 @@ namespace PolyVox
//void generateLevelVolume(void);
void generateMeshDataForRegion(boost::uint16_t regionX,boost:: uint16_t regionY, boost::uint16_t regionZ, IndexedSurfacePatch* singleMaterialPatch, IndexedSurfacePatch* multiMaterialPatch) const;
void generateMeshDataForRegion(boost::uint16_t regionX, boost::uint16_t regionY, boost::uint16_t regionZ, IndexedSurfacePatch* singleMaterialPatch, IndexedSurfacePatch* multiMaterialPatch) const;
bool containsPoint(Vector3DFloat pos, float boundary);
bool containsPoint(Vector3DInt32 pos, boost::uint16_t boundary);
bool surfaceUpToDate[POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS][POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS][POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS];
bool regionIsHomogenous[POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS][POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS][POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS];
LinearVolume<bool>* volSurfaceUpToDate;
Vector3DFloat computeNormal(const Vector3DFloat& position, NormalGenerationMethod normalGenerationMethod) const;
@ -85,7 +84,7 @@ namespace PolyVox
NormalGenerationMethod m_normalGenerationMethod;
private:
Volume<boost::uint8_t>* volumeData;
bool m_bHaveGeneratedMeshes;

14
include/Utility.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef __PolyVox_Utility_H__
#define __PolyVox_Utility_H__
#include "Typedef.h"
#include "boost/cstdint.hpp"
namespace PolyVox
{
POLYVOX_API boost::uint8_t logBase2(boost::uint32_t uInput);
POLYVOX_API bool isPowerOf2(boost::uint32_t uInput);
}
#endif

View File

@ -186,14 +186,6 @@ namespace PolyVox
mYRegionLast = yLast;
mZRegionLast = zLast;
/*mXRegionFirst = (std::max)(0,xFirst);
mYRegionFirst = (std::max)(0,yFirst);
mZRegionFirst = (std::max)(0,zFirst);
mXRegionLast = (std::min)(POLYVOX_VOLUME_SIDE_LENGTH-1, xLast);
mYRegionLast = (std::min)(POLYVOX_VOLUME_SIDE_LENGTH-1, yLast);
mZRegionLast = (std::min)(POLYVOX_VOLUME_SIDE_LENGTH-1, zLast);*/
mXRegionFirstBlock = mXRegionFirst >> mVolume.getBlockSideLengthPower();
mYRegionFirstBlock = mYRegionFirst >> mVolume.getBlockSideLengthPower();
mZRegionFirstBlock = mZRegionFirst >> mVolume.getBlockSideLengthPower();