Replaced std::functions with Pager class for paging.

This commit is contained in:
David Williams
2013-06-16 19:48:14 +02:00
parent 414a012230
commit a14de4a72e
6 changed files with 33 additions and 33 deletions

View File

@ -27,6 +27,7 @@ freely, subject to the following restrictions:
#include "PolyVoxCore/BaseVolume.h"
#include "Impl/Block.h"
#include "PolyVoxCore/Compressor.h"
#include "PolyVoxCore/Pager.h"
#include "PolyVoxCore/Region.h"
#include "PolyVoxCore/Vector.h"
@ -249,18 +250,15 @@ namespace PolyVox
LargeVolume
(
Compressor* pCompressor,
polyvox_function<void(const ConstVolumeProxy<VoxelType>&, const Region&)> dataRequiredHandler,
polyvox_function<void(const ConstVolumeProxy<VoxelType>&, const Region&)> dataOverflowHandler,
Pager<VoxelType>* pPager,
uint16_t uBlockSideLength = 32
);
/// Constructor for creating a fixed size volume.
LargeVolume
(
const Region& regValid,
Compressor* pCompressor = 0,
polyvox_function<void(const ConstVolumeProxy<VoxelType>&, const Region&)> dataRequiredHandler = 0,
polyvox_function<void(const ConstVolumeProxy<VoxelType>&, const Region&)> dataOverflowHandler = 0,
bool bPagingEnabled = false,
Compressor* pCompressor,
Pager<VoxelType>* pPager,
uint16_t uBlockSideLength = 32
);
/// Destructor
@ -346,12 +344,12 @@ namespace PolyVox
/// gets called when a new region is allocated and needs to be filled
/// NOTE: accessing ANY voxels outside this region during the process of this function
/// is absolutely unsafe
polyvox_function<void(const ConstVolumeProxy<VoxelType>&, const Region&)> m_funcDataRequiredHandler;
//polyvox_function<void(const ConstVolumeProxy<VoxelType>&, const Region&)> m_funcDataRequiredHandler;
/// gets called when a Region needs to be stored by the user, because LargeVolume will erase it right after
/// this function returns
/// NOTE: accessing ANY voxels outside this region during the process of this function
/// is absolutely unsafe
polyvox_function<void(const ConstVolumeProxy<VoxelType>&, const Region&)> m_funcDataOverflowHandler;
//polyvox_function<void(const ConstVolumeProxy<VoxelType>&, const Region&)> m_funcDataOverflowHandler;
Block<VoxelType>* getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const;
void eraseBlock(typename std::map<Vector3DInt32, LoadedBlock, BlockPositionCompare>::iterator itBlock) const;
@ -381,8 +379,7 @@ namespace PolyVox
//The compressor used by the Blocks to compress their data if required.
Compressor* m_pCompressor;
bool m_bPagingEnabled;
Pager<VoxelType>* m_pPager;
};
}

View File

@ -38,16 +38,13 @@ namespace PolyVox
LargeVolume<VoxelType>::LargeVolume
(
Compressor* pCompressor,
polyvox_function<void(const ConstVolumeProxy<VoxelType>&, const Region&)> dataRequiredHandler,
polyvox_function<void(const ConstVolumeProxy<VoxelType>&, const Region&)> dataOverflowHandler,
Pager<VoxelType>* pPager,
uint16_t uBlockSideLength
)
:BaseVolume<VoxelType>(Region::MaxRegion)
,m_pCompressor(pCompressor)
{
m_funcDataRequiredHandler = dataRequiredHandler;
m_funcDataOverflowHandler = dataOverflowHandler;
m_bPagingEnabled = true;
m_pPager = pPager;
//Create a volume of the right size.
initialise(Region::MaxRegion,uBlockSideLength);
}
@ -66,17 +63,13 @@ namespace PolyVox
(
const Region& regValid,
Compressor* pCompressor,
polyvox_function<void(const ConstVolumeProxy<VoxelType>&, const Region&)> dataRequiredHandler,
polyvox_function<void(const ConstVolumeProxy<VoxelType>&, const Region&)> dataOverflowHandler,
bool bPagingEnabled,
Pager<VoxelType>* pPager,
uint16_t uBlockSideLength
)
:BaseVolume<VoxelType>(regValid)
,m_pCompressor(pCompressor)
{
m_funcDataRequiredHandler = dataRequiredHandler;
m_funcDataOverflowHandler = dataOverflowHandler;
m_bPagingEnabled = bPagingEnabled;
m_pPager = pPager;
//Create a volume of the right size.
initialise(regValid,uBlockSideLength);
@ -540,7 +533,7 @@ namespace PolyVox
template <typename VoxelType>
void LargeVolume<VoxelType>::eraseBlock(typename std::map<Vector3DInt32, LoadedBlock, BlockPositionCompare>::iterator itBlock) const
{
if(m_funcDataOverflowHandler)
//if(m_funcDataOverflowHandler)
{
Vector3DInt32 v3dPos = itBlock->first;
Vector3DInt32 v3dLower(v3dPos.getX() << m_uBlockSideLengthPower, v3dPos.getY() << m_uBlockSideLengthPower, v3dPos.getZ() << m_uBlockSideLengthPower);
@ -549,7 +542,7 @@ namespace PolyVox
Region reg(v3dLower, v3dUpper);
ConstVolumeProxy<VoxelType> ConstVolumeProxy(*this, reg);
m_funcDataOverflowHandler(ConstVolumeProxy, reg);
m_pPager->dataOverflowHandler(ConstVolumeProxy, reg);
}
if(m_pCompressor)
{
@ -617,7 +610,7 @@ namespace PolyVox
//The block is not in the map, so we will have to create a new block and add it.
//Before we do so, we might want to dump some existing data to make space. We
//Only do this if paging is enabled.
if(m_bPagingEnabled)
if(m_pPager)
{
// check wether another block needs to be unloaded before this one can be loaded
if(m_pBlocks.size() == m_uMaxNumberOfBlocksInMemory)
@ -648,9 +641,9 @@ namespace PolyVox
//We have created the new block. If paging is enabled it should be used to
//fill in the required data. Otherwise it is just left in the default state.
if(m_bPagingEnabled)
if(m_pPager)
{
if(m_funcDataRequiredHandler)
//if(m_funcDataRequiredHandler)
{
// "load" will actually call setVoxel, which will in turn call this function again but the block will be found
// so this if(itBlock == m_pBlocks.end()) never is entered
@ -659,7 +652,7 @@ namespace PolyVox
Vector3DInt32 v3dUpper = v3dLower + Vector3DInt32(m_uBlockSideLength-1, m_uBlockSideLength-1, m_uBlockSideLength-1);
Region reg(v3dLower, v3dUpper);
ConstVolumeProxy<VoxelType> ConstVolumeProxy(*this, reg);
m_funcDataRequiredHandler(ConstVolumeProxy, reg);
m_pPager->dataRequiredHandler(ConstVolumeProxy, reg);
}
}
}

View File

@ -42,8 +42,15 @@ namespace PolyVox
/// Destructor
virtual ~Pager() {};
virtual void dataRequiredHandler(const ConstVolumeProxy<VoxelType>& volumeProxy, const Region& region);
virtual void dataOverflowHandler(const ConstVolumeProxy<VoxelType>& volumeProxy, const Region& region);
virtual void dataRequiredHandler(const ConstVolumeProxy<VoxelType>& volumeProxy, const Region& region)
{
POLYVOX_ASSERT(false, "NOT IMPLEMENTED");
}
virtual void dataOverflowHandler(const ConstVolumeProxy<VoxelType>& volumeProxy, const Region& region)
{
POLYVOX_ASSERT(false, "NOT IMPLEMENTED");
}
};
}