Replaced std::functions with Pager class for paging.
This commit is contained in:
parent
414a012230
commit
a14de4a72e
@ -25,6 +25,7 @@ freely, subject to the following restrictions:
|
|||||||
#include "PolyVoxCore/LargeVolume.h"
|
#include "PolyVoxCore/LargeVolume.h"
|
||||||
#include "PolyVoxCore/LowPassFilter.h"
|
#include "PolyVoxCore/LowPassFilter.h"
|
||||||
#include "PolyVoxCore/RawVolume.h"
|
#include "PolyVoxCore/RawVolume.h"
|
||||||
|
#include "PolyVoxCore/RLECompressor.h"
|
||||||
#include "PolyVoxCore/SurfaceMesh.h"
|
#include "PolyVoxCore/SurfaceMesh.h"
|
||||||
#include "PolyVoxCore/Impl/Utility.h"
|
#include "PolyVoxCore/Impl/Utility.h"
|
||||||
|
|
||||||
@ -48,7 +49,8 @@ using namespace std;
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
LargeVolume<MaterialDensityPair44> volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(g_uVolumeSideLength-1, g_uVolumeSideLength-1, g_uVolumeSideLength-1)));
|
RLECompressor<MaterialDensityPair44, uint16_t>* compressor = new RLECompressor<MaterialDensityPair44, uint16_t>();
|
||||||
|
LargeVolume<MaterialDensityPair44> volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(g_uVolumeSideLength-1, g_uVolumeSideLength-1, g_uVolumeSideLength-1)), compressor, 0);
|
||||||
|
|
||||||
//Make our volume contain a sphere in the center.
|
//Make our volume contain a sphere in the center.
|
||||||
int32_t minPos = 0;
|
int32_t minPos = 0;
|
||||||
|
@ -314,12 +314,13 @@ int main(int argc, char *argv[])
|
|||||||
OpenGLWidget openGLWidget(0);
|
OpenGLWidget openGLWidget(0);
|
||||||
openGLWidget.show();
|
openGLWidget.show();
|
||||||
|
|
||||||
RLECompressor<MaterialDensityPair44, uint16_t>* compressor = new RLECompressor<MaterialDensityPair44, uint16_t>();
|
RLECompressor<MaterialDensityPair44, uint16_t>* compressor = new RLECompressor<MaterialDensityPair44, uint16_t>();
|
||||||
|
PerlinNoisePager* pager = new PerlinNoisePager();
|
||||||
|
|
||||||
//If these lines don't compile, please try commenting them out and using the two lines after
|
//If these lines don't compile, please try commenting them out and using the two lines after
|
||||||
//(you will need Boost for this). If you have to do this then please let us know in the forums as
|
//(you will need Boost for this). If you have to do this then please let us know in the forums as
|
||||||
//we rely on community feedback to keep the Boost version running.
|
//we rely on community feedback to keep the Boost version running.
|
||||||
LargeVolume<MaterialDensityPair44> volData(compressor, &load, &unload, 64);
|
LargeVolume<MaterialDensityPair44> volData(compressor, pager, 64);
|
||||||
//LargeVolume<MaterialDensityPair44> volData(polyvox_bind(&load, polyvox_placeholder_1, polyvox_placeholder_2),
|
//LargeVolume<MaterialDensityPair44> volData(polyvox_bind(&load, polyvox_placeholder_1, polyvox_placeholder_2),
|
||||||
// polyvox_bind(&unload, polyvox_placeholder_1, polyvox_placeholder_2), 256);
|
// polyvox_bind(&unload, polyvox_placeholder_1, polyvox_placeholder_2), 256);
|
||||||
volData.setMaxNumberOfBlocksInMemory(4096);
|
volData.setMaxNumberOfBlocksInMemory(4096);
|
||||||
|
@ -27,6 +27,7 @@ freely, subject to the following restrictions:
|
|||||||
#include "PolyVoxCore/BaseVolume.h"
|
#include "PolyVoxCore/BaseVolume.h"
|
||||||
#include "Impl/Block.h"
|
#include "Impl/Block.h"
|
||||||
#include "PolyVoxCore/Compressor.h"
|
#include "PolyVoxCore/Compressor.h"
|
||||||
|
#include "PolyVoxCore/Pager.h"
|
||||||
#include "PolyVoxCore/Region.h"
|
#include "PolyVoxCore/Region.h"
|
||||||
#include "PolyVoxCore/Vector.h"
|
#include "PolyVoxCore/Vector.h"
|
||||||
|
|
||||||
@ -249,18 +250,15 @@ namespace PolyVox
|
|||||||
LargeVolume
|
LargeVolume
|
||||||
(
|
(
|
||||||
Compressor* pCompressor,
|
Compressor* pCompressor,
|
||||||
polyvox_function<void(const ConstVolumeProxy<VoxelType>&, const Region&)> dataRequiredHandler,
|
Pager<VoxelType>* pPager,
|
||||||
polyvox_function<void(const ConstVolumeProxy<VoxelType>&, const Region&)> dataOverflowHandler,
|
|
||||||
uint16_t uBlockSideLength = 32
|
uint16_t uBlockSideLength = 32
|
||||||
);
|
);
|
||||||
/// Constructor for creating a fixed size volume.
|
/// Constructor for creating a fixed size volume.
|
||||||
LargeVolume
|
LargeVolume
|
||||||
(
|
(
|
||||||
const Region& regValid,
|
const Region& regValid,
|
||||||
Compressor* pCompressor = 0,
|
Compressor* pCompressor,
|
||||||
polyvox_function<void(const ConstVolumeProxy<VoxelType>&, const Region&)> dataRequiredHandler = 0,
|
Pager<VoxelType>* pPager,
|
||||||
polyvox_function<void(const ConstVolumeProxy<VoxelType>&, const Region&)> dataOverflowHandler = 0,
|
|
||||||
bool bPagingEnabled = false,
|
|
||||||
uint16_t uBlockSideLength = 32
|
uint16_t uBlockSideLength = 32
|
||||||
);
|
);
|
||||||
/// Destructor
|
/// Destructor
|
||||||
@ -346,12 +344,12 @@ namespace PolyVox
|
|||||||
/// gets called when a new region is allocated and needs to be filled
|
/// 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
|
/// NOTE: accessing ANY voxels outside this region during the process of this function
|
||||||
/// is absolutely unsafe
|
/// 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
|
/// gets called when a Region needs to be stored by the user, because LargeVolume will erase it right after
|
||||||
/// this function returns
|
/// this function returns
|
||||||
/// NOTE: accessing ANY voxels outside this region during the process of this function
|
/// NOTE: accessing ANY voxels outside this region during the process of this function
|
||||||
/// is absolutely unsafe
|
/// 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;
|
Block<VoxelType>* getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const;
|
||||||
void eraseBlock(typename std::map<Vector3DInt32, LoadedBlock, BlockPositionCompare>::iterator itBlock) 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.
|
//The compressor used by the Blocks to compress their data if required.
|
||||||
Compressor* m_pCompressor;
|
Compressor* m_pCompressor;
|
||||||
|
Pager<VoxelType>* m_pPager;
|
||||||
bool m_bPagingEnabled;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,16 +38,13 @@ namespace PolyVox
|
|||||||
LargeVolume<VoxelType>::LargeVolume
|
LargeVolume<VoxelType>::LargeVolume
|
||||||
(
|
(
|
||||||
Compressor* pCompressor,
|
Compressor* pCompressor,
|
||||||
polyvox_function<void(const ConstVolumeProxy<VoxelType>&, const Region&)> dataRequiredHandler,
|
Pager<VoxelType>* pPager,
|
||||||
polyvox_function<void(const ConstVolumeProxy<VoxelType>&, const Region&)> dataOverflowHandler,
|
|
||||||
uint16_t uBlockSideLength
|
uint16_t uBlockSideLength
|
||||||
)
|
)
|
||||||
:BaseVolume<VoxelType>(Region::MaxRegion)
|
:BaseVolume<VoxelType>(Region::MaxRegion)
|
||||||
,m_pCompressor(pCompressor)
|
,m_pCompressor(pCompressor)
|
||||||
{
|
{
|
||||||
m_funcDataRequiredHandler = dataRequiredHandler;
|
m_pPager = pPager;
|
||||||
m_funcDataOverflowHandler = dataOverflowHandler;
|
|
||||||
m_bPagingEnabled = true;
|
|
||||||
//Create a volume of the right size.
|
//Create a volume of the right size.
|
||||||
initialise(Region::MaxRegion,uBlockSideLength);
|
initialise(Region::MaxRegion,uBlockSideLength);
|
||||||
}
|
}
|
||||||
@ -66,17 +63,13 @@ namespace PolyVox
|
|||||||
(
|
(
|
||||||
const Region& regValid,
|
const Region& regValid,
|
||||||
Compressor* pCompressor,
|
Compressor* pCompressor,
|
||||||
polyvox_function<void(const ConstVolumeProxy<VoxelType>&, const Region&)> dataRequiredHandler,
|
Pager<VoxelType>* pPager,
|
||||||
polyvox_function<void(const ConstVolumeProxy<VoxelType>&, const Region&)> dataOverflowHandler,
|
|
||||||
bool bPagingEnabled,
|
|
||||||
uint16_t uBlockSideLength
|
uint16_t uBlockSideLength
|
||||||
)
|
)
|
||||||
:BaseVolume<VoxelType>(regValid)
|
:BaseVolume<VoxelType>(regValid)
|
||||||
,m_pCompressor(pCompressor)
|
,m_pCompressor(pCompressor)
|
||||||
{
|
{
|
||||||
m_funcDataRequiredHandler = dataRequiredHandler;
|
m_pPager = pPager;
|
||||||
m_funcDataOverflowHandler = dataOverflowHandler;
|
|
||||||
m_bPagingEnabled = bPagingEnabled;
|
|
||||||
|
|
||||||
//Create a volume of the right size.
|
//Create a volume of the right size.
|
||||||
initialise(regValid,uBlockSideLength);
|
initialise(regValid,uBlockSideLength);
|
||||||
@ -540,7 +533,7 @@ namespace PolyVox
|
|||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
void LargeVolume<VoxelType>::eraseBlock(typename std::map<Vector3DInt32, LoadedBlock, BlockPositionCompare>::iterator itBlock) const
|
void LargeVolume<VoxelType>::eraseBlock(typename std::map<Vector3DInt32, LoadedBlock, BlockPositionCompare>::iterator itBlock) const
|
||||||
{
|
{
|
||||||
if(m_funcDataOverflowHandler)
|
//if(m_funcDataOverflowHandler)
|
||||||
{
|
{
|
||||||
Vector3DInt32 v3dPos = itBlock->first;
|
Vector3DInt32 v3dPos = itBlock->first;
|
||||||
Vector3DInt32 v3dLower(v3dPos.getX() << m_uBlockSideLengthPower, v3dPos.getY() << m_uBlockSideLengthPower, v3dPos.getZ() << m_uBlockSideLengthPower);
|
Vector3DInt32 v3dLower(v3dPos.getX() << m_uBlockSideLengthPower, v3dPos.getY() << m_uBlockSideLengthPower, v3dPos.getZ() << m_uBlockSideLengthPower);
|
||||||
@ -549,7 +542,7 @@ namespace PolyVox
|
|||||||
Region reg(v3dLower, v3dUpper);
|
Region reg(v3dLower, v3dUpper);
|
||||||
ConstVolumeProxy<VoxelType> ConstVolumeProxy(*this, reg);
|
ConstVolumeProxy<VoxelType> ConstVolumeProxy(*this, reg);
|
||||||
|
|
||||||
m_funcDataOverflowHandler(ConstVolumeProxy, reg);
|
m_pPager->dataOverflowHandler(ConstVolumeProxy, reg);
|
||||||
}
|
}
|
||||||
if(m_pCompressor)
|
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.
|
//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
|
//Before we do so, we might want to dump some existing data to make space. We
|
||||||
//Only do this if paging is enabled.
|
//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
|
// check wether another block needs to be unloaded before this one can be loaded
|
||||||
if(m_pBlocks.size() == m_uMaxNumberOfBlocksInMemory)
|
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
|
//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.
|
//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
|
// "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
|
// 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);
|
Vector3DInt32 v3dUpper = v3dLower + Vector3DInt32(m_uBlockSideLength-1, m_uBlockSideLength-1, m_uBlockSideLength-1);
|
||||||
Region reg(v3dLower, v3dUpper);
|
Region reg(v3dLower, v3dUpper);
|
||||||
ConstVolumeProxy<VoxelType> ConstVolumeProxy(*this, reg);
|
ConstVolumeProxy<VoxelType> ConstVolumeProxy(*this, reg);
|
||||||
m_funcDataRequiredHandler(ConstVolumeProxy, reg);
|
m_pPager->dataRequiredHandler(ConstVolumeProxy, reg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,8 +42,15 @@ namespace PolyVox
|
|||||||
/// Destructor
|
/// Destructor
|
||||||
virtual ~Pager() {};
|
virtual ~Pager() {};
|
||||||
|
|
||||||
virtual void dataRequiredHandler(const ConstVolumeProxy<VoxelType>& volumeProxy, const Region& region);
|
virtual void dataRequiredHandler(const ConstVolumeProxy<VoxelType>& volumeProxy, const Region& region)
|
||||||
virtual void dataOverflowHandler(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");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,7 +277,7 @@ TestVolume::TestVolume()
|
|||||||
//Create the volumes
|
//Create the volumes
|
||||||
m_pRawVolume = new RawVolume<int32_t>(region);
|
m_pRawVolume = new RawVolume<int32_t>(region);
|
||||||
m_pSimpleVolume = new SimpleVolume<int32_t>(region);
|
m_pSimpleVolume = new SimpleVolume<int32_t>(region);
|
||||||
m_pLargeVolume = new LargeVolume<int32_t>(region, m_pCompressor);
|
m_pLargeVolume = new LargeVolume<int32_t>(region, m_pCompressor, 0, 32);
|
||||||
|
|
||||||
// LargeVolume currently fails a test if compression is enabled. It
|
// LargeVolume currently fails a test if compression is enabled. It
|
||||||
// may be related to accessing the data through more than one sampler?
|
// may be related to accessing the data through more than one sampler?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user