Making use of shared_ptr to track blocks.
This commit is contained in:
		| @@ -69,7 +69,7 @@ namespace PolyVox | ||||
| 			m_vecCreatedFiles.clear(); | ||||
| 		} | ||||
|  | ||||
| 		virtual void pageIn(const Region& region, UncompressedBlock<VoxelType>* pBlockData) | ||||
| 		virtual void pageIn(const Region& region, std::shared_ptr< UncompressedBlock<VoxelType> > pBlockData) | ||||
| 		{ | ||||
| 			POLYVOX_ASSERT(pBlockData, "Attempting to page in NULL block"); | ||||
| 			//POLYVOX_ASSERT(pBlockData->hasUncompressedData() == false, "Block should not have uncompressed data"); | ||||
| @@ -113,7 +113,7 @@ namespace PolyVox | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		virtual void pageOut(const Region& region, UncompressedBlock<VoxelType>* pBlockData) | ||||
| 		virtual void pageOut(const Region& region, std::shared_ptr< UncompressedBlock<VoxelType> > pBlockData) | ||||
| 		{ | ||||
| 			POLYVOX_ASSERT(pBlockData, "Attempting to page out NULL block"); | ||||
| 			//POLYVOX_ASSERT(pBlockData->hasUncompressedData() == false, "Block should not have uncompressed data"); | ||||
|   | ||||
| @@ -300,7 +300,7 @@ namespace PolyVox | ||||
| 			} | ||||
| 		};	 | ||||
|  | ||||
| 		typedef std::map<Vector3DInt32, UncompressedBlock<VoxelType>*, BlockPositionCompare> UncompressedBlockMap; | ||||
| 		typedef std::map<Vector3DInt32, std::shared_ptr< UncompressedBlock<VoxelType> >, BlockPositionCompare> UncompressedBlockMap; | ||||
|  | ||||
| 		void ensureUncompressedBlockMapHasFreeSpace(void) const; | ||||
|  | ||||
| @@ -314,7 +314,7 @@ namespace PolyVox | ||||
| 		VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType<WrapModes::Border>, VoxelType tBorder) const; | ||||
| 		VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType<WrapModes::AssumeValid>, VoxelType tBorder) const; | ||||
| 	 | ||||
| 		UncompressedBlock<VoxelType>* getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const; | ||||
| 		std::shared_ptr< UncompressedBlock<VoxelType> > getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const; | ||||
|  | ||||
| 		void eraseBlock(typename UncompressedBlockMap::iterator itUncompressedBlock) const; | ||||
|  | ||||
| @@ -323,7 +323,7 @@ namespace PolyVox | ||||
|  | ||||
| 		mutable uint32_t m_uTimestamper; | ||||
| 		mutable Vector3DInt32 m_v3dLastAccessedBlockPos; | ||||
| 		mutable UncompressedBlock<VoxelType>* m_pLastAccessedBlock; | ||||
| 		mutable std::shared_ptr< UncompressedBlock<VoxelType> > m_pLastAccessedBlock; | ||||
| 		uint32_t m_uMaxNumberOfUncompressedBlocks; | ||||
|  | ||||
| 		// The size of the volume | ||||
|   | ||||
| @@ -186,7 +186,7 @@ namespace PolyVox | ||||
| 			const uint16_t yOffset = static_cast<uint16_t>(uYPos - (blockY << m_uBlockSideLengthPower)); | ||||
| 			const uint16_t zOffset = static_cast<uint16_t>(uZPos - (blockZ << m_uBlockSideLengthPower)); | ||||
|  | ||||
| 			const UncompressedBlock<VoxelType>* pUncompressedBlock = getUncompressedBlock(blockX, blockY, blockZ); | ||||
| 			auto pUncompressedBlock = getUncompressedBlock(blockX, blockY, blockZ); | ||||
|  | ||||
| 			return pUncompressedBlock->getVoxel(xOffset, yOffset, zOffset); | ||||
| 		} | ||||
| @@ -262,7 +262,7 @@ namespace PolyVox | ||||
| 		const uint16_t yOffset = static_cast<uint16_t>(uYPos - (blockY << m_uBlockSideLengthPower)); | ||||
| 		const uint16_t zOffset = static_cast<uint16_t>(uZPos - (blockZ << m_uBlockSideLengthPower)); | ||||
|  | ||||
| 		UncompressedBlock<VoxelType>* pUncompressedBlock = getUncompressedBlock(blockX, blockY, blockZ); | ||||
| 		auto pUncompressedBlock = getUncompressedBlock(blockX, blockY, blockZ); | ||||
| 		pUncompressedBlock->setVoxelAt(xOffset, yOffset, zOffset, tValue); | ||||
| 	} | ||||
|  | ||||
| @@ -299,7 +299,7 @@ namespace PolyVox | ||||
| 		const uint16_t yOffset = static_cast<uint16_t>(uYPos - (blockY << m_uBlockSideLengthPower)); | ||||
| 		const uint16_t zOffset = static_cast<uint16_t>(uZPos - (blockZ << m_uBlockSideLengthPower)); | ||||
|  | ||||
| 		UncompressedBlock<VoxelType>* pUncompressedBlock = getUncompressedBlock(blockX, blockY, blockZ); | ||||
| 		auto pUncompressedBlock = getUncompressedBlock(blockX, blockY, blockZ); | ||||
|  | ||||
| 		pUncompressedBlock->setVoxelAt(xOffset, yOffset, zOffset, tValue); | ||||
|  | ||||
| @@ -486,7 +486,7 @@ namespace PolyVox | ||||
| 	template <typename VoxelType> | ||||
| 	void LargeVolume<VoxelType>::eraseBlock(typename UncompressedBlockMap::iterator itUncompressedBlock) const | ||||
| 	{ | ||||
| 		UncompressedBlock<VoxelType>* pUncompressedBlock = itUncompressedBlock->second; | ||||
| 		std::shared_ptr< UncompressedBlock<VoxelType> > pUncompressedBlock = itUncompressedBlock->second; | ||||
|  | ||||
| 		// This should never happen as blocks are deleted based on being least recently used. | ||||
| 		// I the case that we are flushing we delete all blocks, but the flush function will | ||||
| @@ -511,14 +511,14 @@ namespace PolyVox | ||||
| 			pUncompressedBlock->m_bDataModified = false; | ||||
| 		} | ||||
|  | ||||
| 		delete itUncompressedBlock->second; | ||||
| 		//delete itUncompressedBlock->second; | ||||
|  | ||||
| 		// We can now remove the block data from memory. | ||||
| 		m_pBlocks.erase(itUncompressedBlock); | ||||
| 	} | ||||
|  | ||||
| 	template <typename VoxelType> | ||||
| 	UncompressedBlock<VoxelType>* LargeVolume<VoxelType>::getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const | ||||
| 	std::shared_ptr< UncompressedBlock<VoxelType> > LargeVolume<VoxelType>::getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const | ||||
| 	{ | ||||
| 		Vector3DInt32 v3dBlockPos(uBlockX, uBlockY, uBlockZ); | ||||
|  | ||||
| @@ -531,7 +531,7 @@ namespace PolyVox | ||||
| 			return m_pLastAccessedBlock; | ||||
| 		} | ||||
|  | ||||
| 		UncompressedBlock<VoxelType>* pUncompressedBlock = 0; | ||||
| 		std::shared_ptr< UncompressedBlock<VoxelType> > pUncompressedBlock = nullptr; | ||||
|  | ||||
| 		typename UncompressedBlockMap::iterator itUncompressedBlock = m_pBlocks.find(v3dBlockPos); | ||||
| 		// check whether the block is already loaded | ||||
| @@ -546,7 +546,8 @@ namespace PolyVox | ||||
| 			ensureUncompressedBlockMapHasFreeSpace(); | ||||
|  | ||||
| 			// We can now create a new block. | ||||
| 			pUncompressedBlock = new UncompressedBlock<VoxelType>(m_uBlockSideLength); | ||||
| 			//pUncompressedBlock = new UncompressedBlock<VoxelType>(m_uBlockSideLength); | ||||
| 			pUncompressedBlock = std::make_shared< UncompressedBlock<VoxelType> >(m_uBlockSideLength); | ||||
|  | ||||
| 			// An uncompressed bock is always backed by a compressed one, and this is created by getCompressedBlock() if it doesn't  | ||||
| 			// already exist. If it does already exist and has data then we bring this across into the ucompressed version. | ||||
| @@ -677,7 +678,7 @@ namespace PolyVox | ||||
| 		const uint16_t yOffset = static_cast<uint16_t>(uYPos - (blockY << m_uBlockSideLengthPower)); | ||||
| 		const uint16_t zOffset = static_cast<uint16_t>(uZPos - (blockZ << m_uBlockSideLengthPower)); | ||||
|  | ||||
| 		UncompressedBlock<VoxelType>* pUncompressedBlock = getUncompressedBlock(blockX, blockY, blockZ); | ||||
| 		auto pUncompressedBlock = getUncompressedBlock(blockX, blockY, blockZ); | ||||
| 		return pUncompressedBlock->getVoxel(xOffset, yOffset, zOffset); | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -119,7 +119,7 @@ namespace PolyVox | ||||
| 					uYPosInBlock * this->mVolume->m_uBlockSideLength +  | ||||
| 					uZPosInBlock * this->mVolume->m_uBlockSideLength * this->mVolume->m_uBlockSideLength; | ||||
|  | ||||
| 			UncompressedBlock<VoxelType>* pUncompressedCurrentBlock = this->mVolume->getUncompressedBlock(uXBlock, uYBlock, uZBlock); | ||||
| 			auto pUncompressedCurrentBlock = this->mVolume->getUncompressedBlock(uXBlock, uYBlock, uZBlock); | ||||
|  | ||||
| 			mCurrentVoxel = pUncompressedCurrentBlock->m_tData + uVoxelIndexInBlock; | ||||
| 		} | ||||
|   | ||||
| @@ -27,6 +27,8 @@ freely, subject to the following restrictions: | ||||
| #include "PolyVoxCore/UncompressedBlock.h" | ||||
| #include "PolyVoxCore/Impl/TypeDef.h" | ||||
|  | ||||
| #include <memory> | ||||
|  | ||||
| namespace PolyVox | ||||
| { | ||||
| 	/** | ||||
| @@ -41,8 +43,8 @@ namespace PolyVox | ||||
| 		/// Destructor | ||||
| 		virtual ~Pager() {}; | ||||
|  | ||||
| 		virtual void pageIn(const Region& region, UncompressedBlock<VoxelType>* pBlockData) = 0; | ||||
| 		virtual void pageOut(const Region& region, UncompressedBlock<VoxelType>* pBlockData) = 0; | ||||
| 		virtual void pageIn(const Region& region, std::shared_ptr< UncompressedBlock<VoxelType> > pBlockData) = 0; | ||||
| 		virtual void pageOut(const Region& region, std::shared_ptr< UncompressedBlock<VoxelType> > pBlockData) = 0; | ||||
| 	}; | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user