Moved Pager to be a nested class of PagedVolume.

This commit is contained in:
David Williams 2014-09-21 11:42:12 +02:00
parent db9a74fdb4
commit d6a7b83698
7 changed files with 30 additions and 67 deletions

View File

@ -27,9 +27,8 @@ freely, subject to the following restrictions:
#include "PolyVoxCore/MaterialDensityPair.h" #include "PolyVoxCore/MaterialDensityPair.h"
#include "PolyVoxCore/CubicSurfaceExtractor.h" #include "PolyVoxCore/CubicSurfaceExtractor.h"
#include "PolyVoxCore/MarchingCubesSurfaceExtractor.h" #include "PolyVoxCore/MarchingCubesSurfaceExtractor.h"
#include "PolyVoxCore/Pager.h"
#include "PolyVoxCore/Mesh.h" #include "PolyVoxCore/Mesh.h"
#include "PolyVoxCore/LargeVolume.h" #include "PolyVoxCore/PagedVolume.h"
#include <QApplication> #include <QApplication>
@ -78,12 +77,12 @@ void createSphereInVolume(LargeVolume<MaterialDensityPair44>& volData, Vector3DF
/** /**
* Generates data using Perlin noise. * Generates data using Perlin noise.
*/ */
class PerlinNoisePager : public PolyVox::Pager<MaterialDensityPair44> class PerlinNoisePager : public PolyVox::PagedVolume<MaterialDensityPair44>::Pager
{ {
public: public:
/// Constructor /// Constructor
PerlinNoisePager() PerlinNoisePager()
:Pager<MaterialDensityPair44>() :PagedVolume<MaterialDensityPair44>::Pager()
{ {
} }

View File

@ -62,7 +62,6 @@ SET(CORE_INC_FILES
include/PolyVoxCore/PagedVolume.inl include/PolyVoxCore/PagedVolume.inl
include/PolyVoxCore/PagedVolumeChunk.inl include/PolyVoxCore/PagedVolumeChunk.inl
include/PolyVoxCore/PagedVolumeSampler.inl include/PolyVoxCore/PagedVolumeSampler.inl
include/PolyVoxCore/Pager.h
include/PolyVoxCore/PolyVoxForwardDeclarations.h include/PolyVoxCore/PolyVoxForwardDeclarations.h
include/PolyVoxCore/Picking.h include/PolyVoxCore/Picking.h
include/PolyVoxCore/Picking.inl include/PolyVoxCore/Picking.inl

View File

@ -26,7 +26,7 @@ freely, subject to the following restrictions:
#include "PolyVoxCore/Impl/TypeDef.h" #include "PolyVoxCore/Impl/TypeDef.h"
#include "PolyVoxCore/Pager.h" #include "PolyVoxCore/PagedVolume.h"
#include "PolyVoxCore/Region.h" #include "PolyVoxCore/Region.h"
#include <cstdlib> #include <cstdlib>
@ -42,12 +42,12 @@ namespace PolyVox
* Provides an interface for performing paging of data. * Provides an interface for performing paging of data.
*/ */
template <typename VoxelType> template <typename VoxelType>
class FilePager : public Pager<VoxelType> class FilePager : public PagedVolume<VoxelType>::Pager
{ {
public: public:
/// Constructor /// Constructor
FilePager(const std::string& strFolderName = ".") FilePager(const std::string& strFolderName = ".")
:Pager<VoxelType>() :PagedVolume<VoxelType>::Pager()
,m_strFolderName(strFolderName) ,m_strFolderName(strFolderName)
{ {
// Add the trailing slash, assuming the user dind't already do it. // Add the trailing slash, assuming the user dind't already do it.

View File

@ -25,7 +25,6 @@ freely, subject to the following restrictions:
#define __PolyVox_PagedVolume_H__ #define __PolyVox_PagedVolume_H__
#include "PolyVoxCore/BaseVolume.h" #include "PolyVoxCore/BaseVolume.h"
#include "PolyVoxCore/Pager.h"
#include "PolyVoxCore/Region.h" #include "PolyVoxCore/Region.h"
#include "PolyVoxCore/Vector.h" #include "PolyVoxCore/Vector.h"
@ -156,11 +155,13 @@ namespace PolyVox
class PagedVolume : public BaseVolume<VoxelType> class PagedVolume : public BaseVolume<VoxelType>
{ {
public: public:
class Chunk;
class Pager;
class Chunk class Chunk
{ {
public: public:
Chunk(Vector3DInt32 v3dPosition, uint16_t uSideLength, Pager<VoxelType>* pPager = nullptr); Chunk(Vector3DInt32 v3dPosition, uint16_t uSideLength, typename PagedVolume<VoxelType>::Pager* pPager = nullptr);
~Chunk(); ~Chunk();
VoxelType* getData(void) const; VoxelType* getData(void) const;
@ -192,10 +193,25 @@ namespace PolyVox
VoxelType* m_tData; VoxelType* m_tData;
uint16_t m_uSideLength; uint16_t m_uSideLength;
uint8_t m_uSideLengthPower; uint8_t m_uSideLengthPower;
Pager<VoxelType>* m_pPager; typename PagedVolume<VoxelType>::Pager* m_pPager;
Vector3DInt32 m_v3dChunkSpacePosition; Vector3DInt32 m_v3dChunkSpacePosition;
}; };
/**
* Provides an interface for performing paging of data.
*/
class Pager
{
public:
/// Constructor
Pager() {};
/// Destructor
virtual ~Pager() {};
virtual void pageIn(const Region& region, typename PagedVolume<VoxelType>::Chunk* pChunk) = 0;
virtual void pageOut(const Region& region, typename PagedVolume<VoxelType>::Chunk* pChunk) = 0;
};
//There seems to be some descrepency between Visual Studio and GCC about how the following class should be declared. //There seems to be some descrepency between Visual Studio and GCC about how the following class should be declared.
//There is a work around (see also See http://goo.gl/qu1wn) given below which appears to work on VS2010 and GCC, but //There is a work around (see also See http://goo.gl/qu1wn) given below which appears to work on VS2010 and GCC, but
//which seems to cause internal compiler errors on VS2008 when building with the /Gm 'Enable Minimal Rebuild' compiler //which seems to cause internal compiler errors on VS2008 when building with the /Gm 'Enable Minimal Rebuild' compiler
@ -272,7 +288,7 @@ namespace PolyVox
PagedVolume PagedVolume
( (
const Region& regValid, const Region& regValid,
Pager<VoxelType>* pPager = nullptr, typename PagedVolume<VoxelType>::Pager* pPager = nullptr,
uint16_t uChunkSideLength = 32 uint16_t uChunkSideLength = 32
); );
/// Destructor /// Destructor
@ -357,11 +373,11 @@ namespace PolyVox
uint16_t m_uChunkSideLength; uint16_t m_uChunkSideLength;
uint8_t m_uChunkSideLengthPower; uint8_t m_uChunkSideLengthPower;
Pager<VoxelType>* m_pPager; typename PagedVolume<VoxelType>::Pager* m_pPager;
// Enough to make sure a chunks and it's neighbours can be loaded, with a few to spare. // Enough to make sure a chunks and it's neighbours can be loaded, with a few to spare.
static const uint32_t uMinPracticalNoOfChunks = 32; static const uint32_t uMinPracticalNoOfChunks = 32;
// Should preent multi-gigabyte volumes with reasonable chunk sizes. // Should prevent multi-gigabyte volumes when chunk sizes are reasonable.
static const uint32_t uMaxPracticalNoOfChunks = 32768; static const uint32_t uMaxPracticalNoOfChunks = 32768;
}; };
} }

View File

@ -40,7 +40,7 @@ namespace PolyVox
PagedVolume<VoxelType>::PagedVolume PagedVolume<VoxelType>::PagedVolume
( (
const Region& regValid, const Region& regValid,
Pager<VoxelType>* pPager, typename PagedVolume<VoxelType>::Pager* pPager,
uint16_t uChunkSideLength uint16_t uChunkSideLength
) )
:BaseVolume<VoxelType>(regValid) :BaseVolume<VoxelType>(regValid)

View File

@ -26,7 +26,7 @@ freely, subject to the following restrictions:
namespace PolyVox namespace PolyVox
{ {
template <typename VoxelType> template <typename VoxelType>
PagedVolume<VoxelType>::Chunk::Chunk(Vector3DInt32 v3dPosition, uint16_t uSideLength, Pager<VoxelType>* pPager) PagedVolume<VoxelType>::Chunk::Chunk(Vector3DInt32 v3dPosition, uint16_t uSideLength, typename PagedVolume<VoxelType>::Pager* pPager)
:m_uChunkLastAccessed(0) :m_uChunkLastAccessed(0)
,m_bDataModified(true) ,m_bDataModified(true)
,m_tData(0) ,m_tData(0)

View File

@ -1,51 +0,0 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_Pager_H__
#define __PolyVox_Pager_H__
#include "PolyVoxCore/PagedVolume.h"
#include "PolyVoxCore/Impl/TypeDef.h"
#include <memory>
namespace PolyVox
{
/**
* Provides an interface for performing paging of data.
*/
template <typename VoxelType>
class Pager
{
public:
/// Constructor
Pager() {};
/// Destructor
virtual ~Pager() {};
virtual void pageIn(const Region& region, typename PagedVolume<VoxelType>::Chunk* pChunk) = 0;
virtual void pageOut(const Region& region, typename PagedVolume<VoxelType>::Chunk* pChunk) = 0;
};
}
#endif //__PolyVox_Pager_H__