Moved paging code into block constructor/destructor.
This commit is contained in:
parent
2b47c959a5
commit
5b59bc2d8c
@ -90,7 +90,7 @@ public:
|
|||||||
/// Destructor
|
/// Destructor
|
||||||
virtual ~PerlinNoisePager() {};
|
virtual ~PerlinNoisePager() {};
|
||||||
|
|
||||||
virtual void pageIn(const PolyVox::Region& region, std::shared_ptr< UncompressedBlock<MaterialDensityPair44> > pBlockData)
|
virtual void pageIn(const PolyVox::Region& region, UncompressedBlock<MaterialDensityPair44>* pBlockData)
|
||||||
{
|
{
|
||||||
// FIXME - this isn't a great example... it's a shame we have to hard clode the block size and also create/destroy
|
// FIXME - this isn't a great example... it's a shame we have to hard clode the block size and also create/destroy
|
||||||
// a compressor each time. These could at least be moved outside somewhere if we can't fix it in a better way...
|
// a compressor each time. These could at least be moved outside somewhere if we can't fix it in a better way...
|
||||||
@ -143,7 +143,7 @@ public:
|
|||||||
//delete compressor;
|
//delete compressor;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void pageOut(const PolyVox::Region& region, std::shared_ptr< UncompressedBlock<MaterialDensityPair44> > /*pBlockData*/)
|
virtual void pageOut(const PolyVox::Region& region, UncompressedBlock<MaterialDensityPair44>* /*pBlockData*/)
|
||||||
{
|
{
|
||||||
std::cout << "warning unloading region: " << region.getLowerCorner() << " -> " << region.getUpperCorner() << std::endl;
|
std::cout << "warning unloading region: " << region.getLowerCorner() << " -> " << region.getUpperCorner() << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ namespace PolyVox
|
|||||||
m_vecCreatedFiles.clear();
|
m_vecCreatedFiles.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void pageIn(const Region& region, std::shared_ptr< UncompressedBlock<VoxelType> > pBlockData)
|
virtual void pageIn(const Region& region, UncompressedBlock<VoxelType>* pBlockData)
|
||||||
{
|
{
|
||||||
POLYVOX_ASSERT(pBlockData, "Attempting to page in NULL block");
|
POLYVOX_ASSERT(pBlockData, "Attempting to page in NULL block");
|
||||||
//POLYVOX_ASSERT(pBlockData->hasUncompressedData() == false, "Block should not have uncompressed data");
|
//POLYVOX_ASSERT(pBlockData->hasUncompressedData() == false, "Block should not have uncompressed data");
|
||||||
@ -113,7 +113,7 @@ namespace PolyVox
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void pageOut(const Region& region, std::shared_ptr< UncompressedBlock<VoxelType> > pBlockData)
|
virtual void pageOut(const Region& region, UncompressedBlock<VoxelType>* pBlockData)
|
||||||
{
|
{
|
||||||
POLYVOX_ASSERT(pBlockData, "Attempting to page out NULL block");
|
POLYVOX_ASSERT(pBlockData, "Attempting to page out NULL block");
|
||||||
//POLYVOX_ASSERT(pBlockData->hasUncompressedData() == false, "Block should not have uncompressed data");
|
//POLYVOX_ASSERT(pBlockData->hasUncompressedData() == false, "Block should not have uncompressed data");
|
||||||
|
@ -515,21 +515,7 @@ namespace PolyVox
|
|||||||
|
|
||||||
// Before deleting the block we may need to recompress its data. We
|
// Before deleting the block we may need to recompress its data. We
|
||||||
// only do this if the data has been modified since it was decompressed.
|
// only do this if the data has been modified since it was decompressed.
|
||||||
if(pUncompressedBlock->m_bDataModified)
|
|
||||||
{
|
|
||||||
// Get the compressed block which we will copy the data back in to.
|
|
||||||
Vector3DInt32 v3dBlockPos = itUncompressedBlock->first;
|
|
||||||
|
|
||||||
// From the coordinates of the block we deduce the coordinates of the contained voxels.
|
|
||||||
Vector3DInt32 v3dLower(v3dBlockPos.getX() << m_uBlockSideLengthPower, v3dBlockPos.getY() << m_uBlockSideLengthPower, v3dBlockPos.getZ() << m_uBlockSideLengthPower);
|
|
||||||
Vector3DInt32 v3dUpper = v3dLower + Vector3DInt32(m_uBlockSideLength - 1, m_uBlockSideLength - 1, m_uBlockSideLength - 1);
|
|
||||||
|
|
||||||
// Page the data out
|
|
||||||
m_pPager->pageOut(Region(v3dLower, v3dUpper), itUncompressedBlock->second);
|
|
||||||
|
|
||||||
// The compressed data has been updated, so the uncompressed data is no longer modified with respect to it.
|
|
||||||
pUncompressedBlock->m_bDataModified = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//delete itUncompressedBlock->second;
|
//delete itUncompressedBlock->second;
|
||||||
|
|
||||||
@ -564,16 +550,7 @@ namespace PolyVox
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// The blcok was not found so we will create a new one.
|
// The blcok was not found so we will create a new one.
|
||||||
pUncompressedBlock = std::make_shared< UncompressedBlock<VoxelType> >(m_uBlockSideLength);
|
pUncompressedBlock = std::make_shared< UncompressedBlock<VoxelType> >(v3dBlockPos, m_uBlockSideLength, m_pPager);
|
||||||
|
|
||||||
// Pass the block to the Pager to give it a chance to initialise it with any data
|
|
||||||
if (m_pPager)
|
|
||||||
{
|
|
||||||
Vector3DInt32 v3dLower(uBlockX << m_uBlockSideLengthPower, uBlockY << m_uBlockSideLengthPower, uBlockZ << m_uBlockSideLengthPower);
|
|
||||||
Vector3DInt32 v3dUpper = v3dLower + Vector3DInt32(m_uBlockSideLength - 1, m_uBlockSideLength - 1, m_uBlockSideLength - 1);
|
|
||||||
Region reg(v3dLower, v3dUpper);
|
|
||||||
m_pPager->pageIn(reg, pUncompressedBlock);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (m_pBlocks.size() + 1 > m_uMaxNumberOfUncompressedBlocks) // +1 ready for new block we will add next.
|
while (m_pBlocks.size() + 1 > m_uMaxNumberOfUncompressedBlocks) // +1 ready for new block we will add next.
|
||||||
{
|
{
|
||||||
|
@ -43,8 +43,8 @@ namespace PolyVox
|
|||||||
/// Destructor
|
/// Destructor
|
||||||
virtual ~Pager() {};
|
virtual ~Pager() {};
|
||||||
|
|
||||||
virtual void pageIn(const Region& region, std::shared_ptr< UncompressedBlock<VoxelType> > pBlockData) = 0;
|
virtual void pageIn(const Region& region, UncompressedBlock<VoxelType>* pBlockData) = 0;
|
||||||
virtual void pageOut(const Region& region, std::shared_ptr< UncompressedBlock<VoxelType> > pBlockData) = 0;
|
virtual void pageOut(const Region& region, UncompressedBlock<VoxelType>* pBlockData) = 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ namespace PolyVox
|
|||||||
friend class LargeVolume<VoxelType>;
|
friend class LargeVolume<VoxelType>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UncompressedBlock(uint16_t uSideLength);
|
UncompressedBlock(Vector3DInt32 v3dPosition, uint16_t uSideLength, Pager<VoxelType>* pPager = nullptr);
|
||||||
~UncompressedBlock();
|
~UncompressedBlock();
|
||||||
|
|
||||||
VoxelType* getData(void) const;
|
VoxelType* getData(void) const;
|
||||||
@ -68,6 +68,8 @@ 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;
|
||||||
|
Vector3DInt32 m_v3dBlockSpacePosition;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,12 +26,14 @@ freely, subject to the following restrictions:
|
|||||||
namespace PolyVox
|
namespace PolyVox
|
||||||
{
|
{
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
UncompressedBlock<VoxelType>::UncompressedBlock(uint16_t uSideLength)
|
UncompressedBlock<VoxelType>::UncompressedBlock(Vector3DInt32 v3dPosition, uint16_t uSideLength, Pager<VoxelType>* pPager)
|
||||||
:m_uBlockLastAccessed(0)
|
:m_uBlockLastAccessed(0)
|
||||||
,m_bDataModified(true)
|
,m_bDataModified(true)
|
||||||
,m_tData(0)
|
,m_tData(0)
|
||||||
,m_uSideLength(0)
|
,m_uSideLength(0)
|
||||||
,m_uSideLengthPower(0)
|
,m_uSideLengthPower(0)
|
||||||
|
,m_pPager(pPager)
|
||||||
|
,m_v3dBlockSpacePosition(v3dPosition)
|
||||||
{
|
{
|
||||||
// Compute the side length
|
// Compute the side length
|
||||||
m_uSideLength = uSideLength;
|
m_uSideLength = uSideLength;
|
||||||
@ -40,11 +42,36 @@ namespace PolyVox
|
|||||||
// Allocate the data
|
// Allocate the data
|
||||||
const uint32_t uNoOfVoxels = m_uSideLength * m_uSideLength * m_uSideLength;
|
const uint32_t uNoOfVoxels = m_uSideLength * m_uSideLength * m_uSideLength;
|
||||||
m_tData = new VoxelType[uNoOfVoxels];
|
m_tData = new VoxelType[uNoOfVoxels];
|
||||||
|
|
||||||
|
// Pass the block to the Pager to give it a chance to initialise it with any data
|
||||||
|
if (m_pPager)
|
||||||
|
{
|
||||||
|
// From the coordinates of the block we deduce the coordinates of the contained voxels.
|
||||||
|
Vector3DInt32 v3dLower = m_v3dBlockSpacePosition * static_cast<int32_t>(m_uSideLength);
|
||||||
|
Vector3DInt32 v3dUpper = v3dLower + Vector3DInt32(m_uSideLength - 1, m_uSideLength - 1, m_uSideLength - 1);
|
||||||
|
Region reg(v3dLower, v3dUpper);
|
||||||
|
|
||||||
|
// Page the data in
|
||||||
|
m_pPager->pageIn(reg, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// We'll use this later to decide if data needs to be paged out again.
|
||||||
|
m_bDataModified = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
UncompressedBlock<VoxelType>::~UncompressedBlock()
|
UncompressedBlock<VoxelType>::~UncompressedBlock()
|
||||||
{
|
{
|
||||||
|
if (m_pPager && m_bDataModified)
|
||||||
|
{
|
||||||
|
// From the coordinates of the block we deduce the coordinates of the contained voxels.
|
||||||
|
Vector3DInt32 v3dLower = m_v3dBlockSpacePosition * static_cast<int32_t>(m_uSideLength);
|
||||||
|
Vector3DInt32 v3dUpper = v3dLower + Vector3DInt32(m_uSideLength - 1, m_uSideLength - 1, m_uSideLength - 1);
|
||||||
|
|
||||||
|
// Page the data out
|
||||||
|
m_pPager->pageOut(Region(v3dLower, v3dUpper), this);
|
||||||
|
}
|
||||||
|
|
||||||
delete[] m_tData;
|
delete[] m_tData;
|
||||||
m_tData = 0;
|
m_tData = 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user