diff --git a/examples/OpenGL/OpenGLWidget.h b/examples/OpenGL/OpenGLWidget.h index 35d67b19..f61a43ad 100644 --- a/examples/OpenGL/OpenGLWidget.h +++ b/examples/OpenGL/OpenGLWidget.h @@ -39,6 +39,22 @@ freely, subject to the following restrictions: const int32_t g_uVolumeSideLength = 128; +struct Vector3DUint8Compare +{ + bool operator() (const PolyVox::Vector3DUint8& a, const PolyVox::Vector3DUint8& b) + { + const uint32_t size = 3; + for(uint32_t ct = 0; ct < size; ++ct) + { + if (a.getElement(ct) < b.getElement(ct)) + return true; + if (b.getElement(ct) < a.getElement(ct)) + return false; + } + return false; + } +}; + class OpenGLWidget : public QGLWidget { @@ -71,8 +87,8 @@ class OpenGLWidget : public QGLWidget PolyVox::LargeVolume* m_volData; //Rather than storing one big mesh, the volume is broken into regions and a mesh is stored for each region - std::map m_mapOpenGLSurfaceMeshes; - std::map > > m_mapSurfaceMeshes; + std::map m_mapOpenGLSurfaceMeshes; + std::map >, Vector3DUint8Compare> m_mapSurfaceMeshes; unsigned int m_uRegionSideLength; unsigned int m_uVolumeWidthInRegions; diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h index 9c92e5ea..c0764527 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h @@ -307,6 +307,22 @@ namespace PolyVox LargeVolume& operator=(const LargeVolume& rhs); private: + + struct BlockPositionCompare + { + bool operator() (const PolyVox::Vector3DInt32& a, const PolyVox::Vector3DInt32& b) + { + const uint32_t size = 3; + for(uint32_t ct = 0; ct < size; ++ct) + { + if (a.getElement(ct) < b.getElement(ct)) + return true; + if (b.getElement(ct) < a.getElement(ct)) + return false; + } + return false; + } + }; void initialise(const Region& regValidRegion, uint16_t uBlockSideLength); /// gets called when a new region is allocated and needs to be filled @@ -320,12 +336,12 @@ namespace PolyVox polyvox_function&, const Region&)> m_funcDataOverflowHandler; Block* getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const; - void eraseBlock(typename std::map::iterator itBlock) const; + void eraseBlock(typename std::map::iterator itBlock) const; /// this function can be called by m_funcDataRequiredHandler without causing any weird effects bool setVoxelAtConst(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue) const; //The block data - mutable std::map m_pBlocks; + mutable std::map m_pBlocks; //The cache of uncompressed blocks. The uncompressed block data and the timestamps are stored here rather //than in the Block class. This is so that in the future each VolumeIterator might to maintain its own cache diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index 54df09c5..81d53a3f 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -297,7 +297,7 @@ namespace PolyVox for(int32_t z = v3dStart.getZ(); z <= v3dEnd.getZ(); z++) { Vector3DInt32 pos(x,y,z); - typename std::map::iterator itBlock = m_pBlocks.find(pos); + typename std::map::iterator itBlock = m_pBlocks.find(pos); if(itBlock != m_pBlocks.end()) { @@ -328,7 +328,7 @@ namespace PolyVox template void LargeVolume::flushAll() { - typename std::map::iterator i; + typename std::map::iterator i; //Replaced the for loop here as the call to //eraseBlock was invalidating the iterator. while(m_pBlocks.size() > 0) @@ -362,7 +362,7 @@ namespace PolyVox for(int32_t z = v3dStart.getZ(); z <= v3dEnd.getZ(); z++) { Vector3DInt32 pos(x,y,z); - typename std::map::iterator itBlock = m_pBlocks.find(pos); + typename std::map::iterator itBlock = m_pBlocks.find(pos); if(itBlock == m_pBlocks.end()) { // not loaded, not unloading @@ -448,7 +448,7 @@ namespace PolyVox } template - void LargeVolume::eraseBlock(typename std::map::iterator itBlock) const + void LargeVolume::eraseBlock(typename std::map::iterator itBlock) const { if(m_funcDataOverflowHandler) { @@ -519,7 +519,7 @@ namespace PolyVox return m_pLastAccessedBlock; } - typename std::map::iterator itBlock = m_pBlocks.find(v3dBlockPos); + typename std::map::iterator itBlock = m_pBlocks.find(v3dBlockPos); // check whether the block is already loaded if(itBlock == m_pBlocks.end()) { @@ -532,8 +532,8 @@ namespace PolyVox if(m_pBlocks.size() == m_uMaxNumberOfBlocksInMemory) { // find the least recently used block - typename std::map::iterator i; - typename std::map::iterator itUnloadBlock = m_pBlocks.begin(); + typename std::map::iterator i; + typename std::map::iterator itUnloadBlock = m_pBlocks.begin(); for(i = m_pBlocks.begin(); i != m_pBlocks.end(); i++) { if(i->second.timestamp < itUnloadBlock->second.timestamp) @@ -636,7 +636,7 @@ namespace PolyVox uint32_t uSizeInBytes = sizeof(LargeVolume); //Memory used by the blocks - typename std::map::iterator i; + typename std::map::iterator i; for(i = m_pBlocks.begin(); i != m_pBlocks.end(); i++) { //Inaccurate - account for rest of loaded block.