From 8ab6d73f0af7f1dbd13060d83980fffa92b750c5 Mon Sep 17 00:00:00 2001 From: David Williams Date: Tue, 25 Jun 2013 23:34:58 +0200 Subject: [PATCH] Work on LargeVolume refactoring - getting FilePager working. --- examples/Basic/main.cpp | 4 ++-- .../PolyVoxCore/include/PolyVoxCore/FilePager.h | 2 ++ .../include/PolyVoxCore/Impl/Block.inl | 5 ++++- .../include/PolyVoxCore/LargeVolume.inl | 16 +++++++++++----- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/examples/Basic/main.cpp b/examples/Basic/main.cpp index 40bf0058..444e71fb 100644 --- a/examples/Basic/main.cpp +++ b/examples/Basic/main.cpp @@ -85,8 +85,8 @@ int main(int argc, char *argv[]) FilePager* pFilePager = new FilePager("D:/temp/voldata/"); LargeVolume volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(63, 63, 63)), pCompressor, pFilePager, 32); - //volData.setMaxNumberOfUncompressedBlocks(6); - //volData.setMaxNumberOfBlocksInMemory(7); + volData.setMaxNumberOfUncompressedBlocks(6); + volData.setMaxNumberOfBlocksInMemory(7); createSphereInVolume(volData, 30); diff --git a/library/PolyVoxCore/include/PolyVoxCore/FilePager.h b/library/PolyVoxCore/include/PolyVoxCore/FilePager.h index 07dc94e1..5d8d97ed 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/FilePager.h +++ b/library/PolyVoxCore/include/PolyVoxCore/FilePager.h @@ -54,6 +54,7 @@ namespace PolyVox virtual void pageIn(const Region& region, Block* pBlockData) { POLYVOX_ASSERT(pBlockData, "Attempting to page in NULL block"); + POLYVOX_ASSERT(pBlockData->hasUncompressedData() == false, "Block should not have uncompressed data"); std::stringstream ss; ss << region.getLowerX() << "_" << region.getLowerY() << "_" << region.getLowerZ() << "_" @@ -94,6 +95,7 @@ namespace PolyVox virtual void pageOut(const Region& region, Block* pBlockData) { POLYVOX_ASSERT(pBlockData, "Attempting to page out NULL block"); + POLYVOX_ASSERT(pBlockData->hasUncompressedData() == false, "Block should not have uncompressed data"); logTrace() << "Paging out data for " << region; diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl index cf103eaa..3076d2bb 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl @@ -64,11 +64,14 @@ namespace PolyVox m_uSideLength = uSideLength; m_uSideLengthPower = logBase2(uSideLength); - //Create the block data + //Temporarily create the block data. This is just so we can compress it an discard it. + // FIXME - this is a temporary solution. const uint32_t uNoOfVoxels = m_uSideLength * m_uSideLength * m_uSideLength; m_tUncompressedData = new VoxelType[uNoOfVoxels]; std::fill(m_tUncompressedData, m_tUncompressedData + uNoOfVoxels, VoxelType()); m_bIsUncompressedDataModified = true; + + destroyUncompressedData(); } template diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index 8f9e6085..dccaa4cd 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -540,9 +540,11 @@ namespace PolyVox Vector3DInt32 v3dUpper = v3dLower + Vector3DInt32(m_uBlockSideLength-1, m_uBlockSideLength-1, m_uBlockSideLength-1); Region reg(v3dLower, v3dUpper); - ConstVolumeProxy ConstVolumeProxy(*this, reg); + /*ConstVolumeProxy ConstVolumeProxy(*this, reg); - m_pPager->dataOverflowHandler(ConstVolumeProxy, reg); + m_pPager->dataOverflowHandler(ConstVolumeProxy, reg);*/ + + m_pPager->pageOut(reg, &(itBlock->second)); } for(uint32_t ct = 0; ct < m_vecBlocksWithUncompressedData.size(); ct++) @@ -631,7 +633,9 @@ namespace PolyVox // create the new block Block newBlock(m_uBlockSideLength, m_pCompressor); - itBlock = m_pBlocks.insert(std::make_pair(v3dBlockPos, newBlock)).first; + auto retVal = m_pBlocks.insert(std::make_pair(v3dBlockPos, newBlock)); + itBlock = retVal.first; + POLYVOX_ASSERT(retVal.second == true, "Element was not supposed to exist!"); //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. @@ -645,8 +649,10 @@ namespace PolyVox 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); Region reg(v3dLower, v3dUpper); - ConstVolumeProxy ConstVolumeProxy(*this, reg); - m_pPager->dataRequiredHandler(ConstVolumeProxy, reg); + /*ConstVolumeProxy ConstVolumeProxy(*this, reg); + m_pPager->dataRequiredHandler(ConstVolumeProxy, reg);*/ + + m_pPager->pageIn(reg, &(itBlock->second)); } } }