From f4f85551c6179a1b8bb50feaaee4a6bf9b270629 Mon Sep 17 00:00:00 2001 From: David Williams Date: Thu, 25 Jul 2013 15:51:30 +0200 Subject: [PATCH] Starting some refactoring of the LargeVolume such that the uncompressed blocks are the 'main' representation, rather than the compressed block being the main version and the uncompressed blocks simply being a cached version. I hope this simplifies and improves the code. --- .../include/PolyVoxCore/LargeVolume.inl | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index ad67d849..65bbbed3 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -713,13 +713,39 @@ namespace PolyVox //the time stamp. If we updated it everytime then that would be every time we touched //a voxel, which would overflow a uint32_t and require us to use a uint64_t instead. //This check should also provide a significant speed boost as usually it is true. - if((v3dBlockPos == m_v3dLastAccessedBlockPos) && (m_pLastAccessedBlock != 0)) + /*if((v3dBlockPos == m_v3dLastAccessedBlockPos) && (m_pLastAccessedBlock != 0)) { return m_pLastAccessedBlock; + }*/ + + UncompressedBlock* pUncompressedBlock = 0; + + typename UncompressedBlockMap::iterator itUncompressedBlock = m_pUncompressedBlockCache.find(v3dBlockPos); + // check whether the block is already loaded + if(itUncompressedBlock != m_pUncompressedBlockCache.end()) + { + pUncompressedBlock = itUncompressedBlock->second; + + } + //else if(check compressed list...) + //{ + //} + else + { + // At this point we just create a new block. + pUncompressedBlock = new UncompressedBlock(m_uBlockSideLength); + + m_pUncompressedBlockCache.insert(std::make_pair(v3dBlockPos, pUncompressedBlock)); + + // Our block cache may now have grown too large. Flush some entries is necessary. + // FIXME - Watch out for flushing the block we just created! + //flushExcessiveCacheEntries(); } + pUncompressedBlock->m_uBlockLastAccessed = ++m_uTimestamper; + //Gets the block and marks that we accessed it - CompressedBlock* block = getCompressedBlock(uBlockX, uBlockY, uBlockZ); + /*CompressedBlock* block = getCompressedBlock(uBlockX, uBlockY, uBlockZ); typename UncompressedBlockMap::iterator itUncompressedBlock = m_pUncompressedBlockCache.find(v3dBlockPos); // check whether the block is already loaded @@ -743,9 +769,9 @@ namespace PolyVox // Our block cache may now have grown too large. Fluch some entries is necessary. flushExcessiveCacheEntries(); - } + }*/ - m_pLastAccessedBlock = (*itUncompressedBlock).second; + m_pLastAccessedBlock = pUncompressedBlock; m_v3dLastAccessedBlockPos = v3dBlockPos; return m_pLastAccessedBlock;