From 4da1f6149a99bca8d389a7303dcf7a52a8d19b2a Mon Sep 17 00:00:00 2001 From: David Williams Date: Mon, 7 Feb 2011 23:47:48 +0000 Subject: [PATCH] --- examples/Basic/main.cpp | 6 +-- library/PolyVoxCore/include/Volume.h | 7 ++-- library/PolyVoxCore/include/Volume.inl | 53 ++++++-------------------- 3 files changed, 17 insertions(+), 49 deletions(-) diff --git a/examples/Basic/main.cpp b/examples/Basic/main.cpp index ce80aaec..4d359082 100644 --- a/examples/Basic/main.cpp +++ b/examples/Basic/main.cpp @@ -469,7 +469,7 @@ int main(int argc, char *argv[]) openGLWidget.show(); //Create an empty volume and then place a sphere in it - Volume volData(1024, 1024, 1024); + Volume volData(256, 256, 256); //createSphereInVolume(volData, 30); createPerlinVolumeFast(volData); @@ -487,12 +487,12 @@ int main(int argc, char *argv[]) }*/ //Extract the surface - /*SurfaceMesh mesh; + SurfaceMesh mesh; CubicSurfaceExtractorWithNormals surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh); surfaceExtractor.execute(); //Pass the surface to the OpenGL window - openGLWidget.setSurfaceMeshToRender(mesh);*/ + openGLWidget.setSurfaceMeshToRender(mesh); //Run the message pump. return app.exec(); diff --git a/library/PolyVoxCore/include/Volume.h b/library/PolyVoxCore/include/Volume.h index 18fc33a6..94157bb8 100644 --- a/library/PolyVoxCore/include/Volume.h +++ b/library/PolyVoxCore/include/Volume.h @@ -120,7 +120,7 @@ namespace PolyVox public: ///Constructor - Volume(uint16_t uWidth, uint16_t uHeight, uint16_t uDepth, uint16_t uBlockSideLength = 32); + Volume(uint16_t uWidth, uint16_t uHeight, uint16_t uDepth, uint16_t uBlockSideLength = 64); ///Destructor ~Volume(); @@ -152,7 +152,7 @@ namespace PolyVox ///Sets the voxel at a 3D vector position bool setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue); - ///Resises the volume to the specified dimensions + ///Resizes the volume to the specified dimensions void resize(uint16_t uWidth, uint16_t uHeight, uint16_t uDepth, uint16_t uBlockSideLength = 32); public: @@ -160,8 +160,7 @@ namespace PolyVox Block m_pBorderBlock; std::vector< Block > m_pBlocks; - //mutable Block* m_pUncompressedBlock; - mutable std::set*> m_pUncompressedBlocks; + mutable std::vector*> m_pUncompressedBlocks; uint32_t m_uNoOfBlocksInVolume; diff --git a/library/PolyVoxCore/include/Volume.inl b/library/PolyVoxCore/include/Volume.inl index db515b8b..80b67c8f 100644 --- a/library/PolyVoxCore/include/Volume.inl +++ b/library/PolyVoxCore/include/Volume.inl @@ -344,40 +344,6 @@ namespace PolyVox m_fDiagonalLength = sqrtf(static_cast(m_uWidth * m_uWidth + m_uHeight * m_uHeight + m_uDepth * m_uDepth)); } - /*template - Block* Volume::getUncompressedBlock(Block* block) const - { - if(block == m_pUncompressedBlock) - { - return m_pUncompressedBlock; - } - - if(m_pUncompressedBlock) - { - m_pUncompressedBlock->compress(); - } - - m_pUncompressedBlock = block; - m_pUncompressedBlock->uncompress(); - - return m_pUncompressedBlock; - }*/ - - /*template - Block* Volume::getUncompressedBlock(Block* block) const - { - std::set*>::iterator iterBlock = m_pUncompressedBlocks.find(block); - if(iterBlock != m_pUncompressedBlocks.end()) - { - return block; - } - - block->uncompress(); - m_pUncompressedBlocks.insert(block); - - return block; - }*/ - template Block* Volume::getUncompressedBlock(Block* block) const { @@ -391,23 +357,26 @@ namespace PolyVox const uint32_t MaxUncompressedBlocks = 10; if(m_pUncompressedBlocks.size() == MaxUncompressedBlocks) { - Block* pLeastRecentlyUsedBlock = 0; + int32_t leastRecentlyUsedBlockIndex = -1; uint32_t uLeastRecentTimestamp = 1000000000000000; - for(std::set*>::iterator iter = m_pUncompressedBlocks.begin(); iter != m_pUncompressedBlocks.end(); iter++) + for(uint32_t ct = 0; ct < m_pUncompressedBlocks.size(); ct++) { - if((*iter)->m_uTimestamp < uLeastRecentTimestamp) + if(m_pUncompressedBlocks[ct]->m_uTimestamp < uLeastRecentTimestamp) { - uLeastRecentTimestamp = (*iter)->m_uTimestamp; - pLeastRecentlyUsedBlock = *iter; + uLeastRecentTimestamp = m_pUncompressedBlocks[ct]->m_uTimestamp; + leastRecentlyUsedBlockIndex = ct; } } - pLeastRecentlyUsedBlock->compress(); - m_pUncompressedBlocks.erase(pLeastRecentlyUsedBlock); + m_pUncompressedBlocks[leastRecentlyUsedBlockIndex]->compress(); + m_pUncompressedBlocks[leastRecentlyUsedBlockIndex] = block; + } + else + { + m_pUncompressedBlocks.push_back(block); } block->uncompress(); - m_pUncompressedBlocks.insert(block); return block; }