Changes to support non-C++0x compilers.

This commit is contained in:
David Williams 2010-09-01 22:01:52 +00:00
parent 40d26b4361
commit 7f2518e6c8
14 changed files with 49 additions and 39 deletions

View File

@ -26,8 +26,6 @@ freely, subject to the following restrictions:
#include "SurfaceMesh.h"
#include <cstdint>
using namespace PolyVox;
using namespace std;

View File

@ -89,7 +89,7 @@ void OpenGLWidget::setVolume(PolyVox::Volume<MaterialDensityPair44>* volData)
//Extract the surface for this region
//extractSurface(m_volData, 0, PolyVox::Region(regLowerCorner, regUpperCorner), meshCurrent);
shared_ptr<SurfaceMesh> mesh(new SurfaceMesh);
polyvox_shared_ptr<SurfaceMesh> mesh(new SurfaceMesh);
SurfaceExtractor<MaterialDensityPair44> surfaceExtractor(volData, PolyVox::Region(regLowerCorner, regUpperCorner), mesh.get());
surfaceExtractor.execute();
@ -229,7 +229,7 @@ void OpenGLWidget::paintGL()
Vector3DUint8 v3dRegPos(uRegionX,uRegionY,uRegionZ);
if(m_mapSurfaceMeshes.find(v3dRegPos) != m_mapSurfaceMeshes.end())
{
shared_ptr<SurfaceMesh> meshCurrent = m_mapSurfaceMeshes[v3dRegPos];
polyvox_shared_ptr<SurfaceMesh> meshCurrent = m_mapSurfaceMeshes[v3dRegPos];
unsigned int uLodLevel = 0; //meshCurrent->m_vecLodRecords.size() - 1;
if(m_bUseOpenGLVertexBufferObjects)
{

View File

@ -73,7 +73,7 @@ class OpenGLWidget : public QGLWidget
//Rather than storing one big mesh, the volume is broken into regions and a mesh is stored for each region
std::map<PolyVox::Vector3DUint8, OpenGLSurfaceMesh> m_mapOpenGLSurfaceMeshes;
std::map<PolyVox::Vector3DUint8, std::shared_ptr<PolyVox::SurfaceMesh> > m_mapSurfaceMeshes;
std::map<PolyVox::Vector3DUint8, polyvox_shared_ptr<PolyVox::SurfaceMesh> > m_mapSurfaceMeshes;
unsigned int m_uRegionSideLength;
unsigned int m_uVolumeWidthInRegions;

View File

@ -26,7 +26,7 @@ freely, subject to the following restrictions:
#ifndef __PolyVox_ForwardDeclarations_H__
#define __PolyVox_ForwardDeclarations_H__
#include <cstdint>
#include "PolyVoxImpl/TypeDef.h"
namespace PolyVox
{

View File

@ -27,7 +27,7 @@ distribution.
#define __PolyVox_ArraySizesImpl_H__
#pragma region Headers
#include <cstdint>
#include "typedef.h"
#pragma endregion
namespace PolyVox

View File

@ -26,6 +26,7 @@ freely, subject to the following restrictions:
#ifndef __PolyVox_TypeDef_H__
#define __PolyVox_TypeDef_H__
//Definitions needed to make library functions accessable
#ifdef _MSC_VER
//We are using a Microsoft compiler.
#ifdef POLYVOXCORE_EXPORT
@ -38,14 +39,26 @@ freely, subject to the following restrictions:
#define POLYVOXCORE_API __attribute__ ((visibility("default")))
#endif
// To support non-C++0x compilers we use boost to replace the std::shared_ptr
// and potentially other C++0x features. To use this capability you will need
// to make sure you have boost installed on your system.
#ifdef _MSC_VER
#if _MSC_VER < 1600 // Older than VS 2010
#include <boost/shared_ptr>
#define std::shared_ptr boost::shared_ptr
#endif
//Check which compiler we are using and work around unsupported features as necessary.
#if defined(_MSC_VER) && (_MSC_VER < 1600)
//To support old Microsoft compilers we use boost to replace the std::shared_ptr
//and potentially other C++0x features. To use this capability you will need to
//make sure you have boost installed on your system.
#include "boost/smart_ptr.hpp"
#define polyvox_shared_ptr boost::shared_ptr
//We also need to define these types as cstdint isn't available
typedef char int8_t;
typedef short int16_t;
typedef long int32_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned long uint32_t;
#else
//We have a decent compiler - use real C++0x features
#include <cstdint>
#include <memory>
#define polyvox_shared_ptr std::shared_ptr
#endif
#endif

View File

@ -29,7 +29,6 @@ freely, subject to the following restrictions:
#include "TypeDef.h"
#include <cassert>
#include <cstdint>
namespace PolyVox
{

View File

@ -66,7 +66,7 @@ namespace PolyVox
void smoothPositions(float fAmount, bool bIncludeGeometryEdgeVertices = false);
void sumNearbyNormals(bool bNormaliseResult = true);
std::shared_ptr<SurfaceMesh> extractSubset(std::set<uint8_t> setMaterials);
polyvox_shared_ptr<SurfaceMesh> extractSubset(std::set<uint8_t> setMaterials);
void generateAveragedFaceNormals(bool bNormalise, bool bIncludeEdgeVertices = false);

View File

@ -159,10 +159,10 @@ namespace PolyVox
void tidyUpMemory(uint32_t uNoOfBlocksToProcess = (std::numeric_limits<uint32_t>::max)());
private:
std::shared_ptr< Block<VoxelType> > getHomogenousBlock(VoxelType tHomogenousValue);
polyvox_shared_ptr< Block<VoxelType> > getHomogenousBlock(VoxelType tHomogenousValue);
std::shared_ptr< Block<VoxelType> > m_pBorderBlock;
std::vector< std::shared_ptr< Block<VoxelType> > > m_pBlocks;
polyvox_shared_ptr< Block<VoxelType> > m_pBorderBlock;
std::vector< polyvox_shared_ptr< Block<VoxelType> > > m_pBlocks;
std::vector<bool> m_vecBlockIsPotentiallyHomogenous;
//Note: We were once storing weak_ptr's in this map, so that the blocks would be deleted once they
@ -170,7 +170,7 @@ namespace PolyVox
//shared. A call to shared_ptr::unique() from within setVoxel was not sufficient as weak_ptr's did
//not contribute to the reference count. Instead we store shared_ptr's here, and check if they
//are used by anyone else (i.e are non-unique) when we tidy the volume.
std::map<VoxelType, std::shared_ptr< Block<VoxelType> > > m_pHomogenousBlock;
std::map<VoxelType, polyvox_shared_ptr< Block<VoxelType> > > m_pHomogenousBlock;
uint32_t m_uNoOfBlocksInVolume;

View File

@ -121,7 +121,7 @@ namespace PolyVox
}
//Create the border block
std::shared_ptr< Block<VoxelType> > pTempBlock(new Block<VoxelType>(m_uBlockSideLength));
polyvox_shared_ptr< Block<VoxelType> > pTempBlock(new Block<VoxelType>(m_uBlockSideLength));
pTempBlock->fill(VoxelType());
m_pBorderBlock = pTempBlock;
@ -253,7 +253,7 @@ namespace PolyVox
const uint16_t yOffset = uYPos - (blockY << m_uBlockSideLengthPower);
const uint16_t zOffset = uZPos - (blockZ << m_uBlockSideLengthPower);
const std::shared_ptr< Block< VoxelType > >& block = m_pBlocks
const polyvox_shared_ptr< Block< VoxelType > >& block = m_pBlocks
[
blockX +
blockY * m_uWidthInBlocks +
@ -316,7 +316,7 @@ namespace PolyVox
blockY * m_uWidthInBlocks +
blockZ * m_uWidthInBlocks * m_uHeightInBlocks;
std::shared_ptr< Block<VoxelType> >& block = m_pBlocks[uBlockIndex];
polyvox_shared_ptr< Block<VoxelType> >& block = m_pBlocks[uBlockIndex];
//It's quite possible that the user might attempt to set a voxel to it's current value.
//We test for this case firstly because it could help performance, but more importantly
@ -332,7 +332,7 @@ namespace PolyVox
}
else
{
std::shared_ptr< Block<VoxelType> > pNewBlock(new Block<VoxelType>(*(block)));
polyvox_shared_ptr< Block<VoxelType> > pNewBlock(new Block<VoxelType>(*(block)));
block = pNewBlock;
m_vecBlockIsPotentiallyHomogenous[uBlockIndex] = false;
block->setVoxelAt(xOffset,yOffset,zOffset, tValue);
@ -407,7 +407,7 @@ namespace PolyVox
}
//Identify and remove any homogeneous blocks which are not actually in use.
typename std::map<VoxelType, std::shared_ptr< Block<VoxelType> > >::iterator iter = m_pHomogenousBlock.begin();
typename std::map<VoxelType, polyvox_shared_ptr< Block<VoxelType> > >::iterator iter = m_pHomogenousBlock.begin();
while(iter != m_pHomogenousBlock.end())
{
if(iter->second.unique())
@ -424,13 +424,13 @@ namespace PolyVox
#pragma region Private Implementation
template <typename VoxelType>
std::shared_ptr< Block<VoxelType> > Volume<VoxelType>::getHomogenousBlock(VoxelType tHomogenousValue)
polyvox_shared_ptr< Block<VoxelType> > Volume<VoxelType>::getHomogenousBlock(VoxelType tHomogenousValue)
{
typename std::map<VoxelType, std::shared_ptr< Block<VoxelType> > >::iterator iterResult = m_pHomogenousBlock.find(tHomogenousValue);
typename std::map<VoxelType, polyvox_shared_ptr< Block<VoxelType> > >::iterator iterResult = m_pHomogenousBlock.find(tHomogenousValue);
if(iterResult == m_pHomogenousBlock.end())
{
//Block<VoxelType> block;
std::shared_ptr< Block<VoxelType> > pHomogeneousBlock(new Block<VoxelType>(m_uBlockSideLength));
polyvox_shared_ptr< Block<VoxelType> > pHomogeneousBlock(new Block<VoxelType>(m_uBlockSideLength));
//block.m_pBlock = temp;
//block.m_uReferenceCount++;
pHomogeneousBlock->fill(tHomogenousValue);
@ -440,7 +440,7 @@ namespace PolyVox
else
{
//iterResult->second.m_uReferenceCount++;
//std::shared_ptr< Block<VoxelType> > result(iterResult->second);
//polyvox_shared_ptr< Block<VoxelType> > result(iterResult->second);
return iterResult->second;
}
}

View File

@ -165,7 +165,7 @@ namespace PolyVox
const uint32_t uBlockIndexInVolume = uXBlock +
uYBlock * mVolume->m_uWidthInBlocks +
uZBlock * mVolume->m_uWidthInBlocks * mVolume->m_uHeightInBlocks;
const std::shared_ptr< Block<VoxelType> >& currentBlock = mVolume->m_pBlocks[uBlockIndexInVolume];
const polyvox_shared_ptr< Block<VoxelType> >& currentBlock = mVolume->m_pBlocks[uBlockIndexInVolume];
mCurrentVoxel = currentBlock->m_tData + uVoxelIndexInBlock;
}

View File

@ -349,9 +349,9 @@ namespace PolyVox
}
}
shared_ptr<SurfaceMesh> SurfaceMesh::extractSubset(std::set<uint8_t> setMaterials)
polyvox_shared_ptr<SurfaceMesh> SurfaceMesh::extractSubset(std::set<uint8_t> setMaterials)
{
shared_ptr<SurfaceMesh> result(new SurfaceMesh);
polyvox_shared_ptr<SurfaceMesh> result(new SurfaceMesh);
if(m_vecVertices.size() == 0) //FIXME - I don't think we should need this test, but I have seen crashes otherwise...
{

View File

@ -42,12 +42,12 @@ namespace PolyVox
};
template <typename VoxelType>
std::shared_ptr< Volume<VoxelType> > loadVolumeRaw(std::istream& stream, VolumeSerializationProgressListener* progressListener = 0);
polyvox_shared_ptr< Volume<VoxelType> > loadVolumeRaw(std::istream& stream, VolumeSerializationProgressListener* progressListener = 0);
template <typename VoxelType>
void saveVolumeRaw(std::ostream& stream, Volume<VoxelType>& volume, VolumeSerializationProgressListener* progressListener = 0);
template <typename VoxelType>
std::shared_ptr< Volume<VoxelType> > loadVolumeRle(std::istream& stream, VolumeSerializationProgressListener* progressListener = 0);
polyvox_shared_ptr< Volume<VoxelType> > loadVolumeRle(std::istream& stream, VolumeSerializationProgressListener* progressListener = 0);
template <typename VoxelType>
void saveVolumeRle(std::ostream& stream, Volume<VoxelType>& volume, VolumeSerializationProgressListener* progressListener = 0);
}

View File

@ -30,7 +30,7 @@ namespace PolyVox
//Note: we don't do much error handling in here - exceptions will simply be propergated up to the caller.
//FIXME - think about pointer ownership issues. Or could return volume by value if the copy constructor is shallow
template <typename VoxelType>
std::shared_ptr< Volume<VoxelType> > loadVolumeRaw(std::istream& stream, VolumeSerializationProgressListener* progressListener)
polyvox_shared_ptr< Volume<VoxelType> > loadVolumeRaw(std::istream& stream, VolumeSerializationProgressListener* progressListener)
{
//Read volume dimensions
uint8_t volumeWidthPower = 0;
@ -45,7 +45,7 @@ namespace PolyVox
uint16_t volumeDepth = 0x0001 << volumeDepthPower;
//FIXME - need to support non cubic volumes
std::shared_ptr< Volume<VoxelType> > volume(new Volume<VoxelType>(volumeWidth, volumeHeight, volumeDepth));
polyvox_shared_ptr< Volume<VoxelType> > volume(new Volume<VoxelType>(volumeWidth, volumeHeight, volumeDepth));
//Read data
for(uint16_t z = 0; z < volumeDepth; ++z)
@ -126,7 +126,7 @@ namespace PolyVox
//Note: we don't do much error handling in here - exceptions will simply be propergated up to the caller.
//FIXME - think about pointer ownership issues. Or could return volume by value if the copy constructor is shallow
template <typename VoxelType>
std::shared_ptr< Volume<VoxelType> > loadVolumeRle(std::istream& stream, VolumeSerializationProgressListener* progressListener)
polyvox_shared_ptr< Volume<VoxelType> > loadVolumeRle(std::istream& stream, VolumeSerializationProgressListener* progressListener)
{
//Read volume dimensions
uint8_t volumeWidthPower = 0;
@ -141,7 +141,7 @@ namespace PolyVox
uint16_t volumeDepth = 0x0001 << volumeDepthPower;
//FIXME - need to support non cubic volumes
std::shared_ptr< Volume<VoxelType> > volume(new Volume<VoxelType>(volumeWidth, volumeHeight, volumeDepth));
polyvox_shared_ptr< Volume<VoxelType> > volume(new Volume<VoxelType>(volumeWidth, volumeHeight, volumeDepth));
//Read data
bool firstTime = true;