Pulling out timestamps and last accessed block from SimpleVolume.
This commit is contained in:
		| @@ -41,19 +41,8 @@ namespace PolyVox | |||||||
| 	public: | 	public: | ||||||
| 		class Block | 		class Block | ||||||
| 		{ | 		{ | ||||||
| 			template <typename LengthType> |  | ||||||
| 			struct RunlengthEntry |  | ||||||
| 			{ |  | ||||||
| 				LengthType length; |  | ||||||
| 				VoxelType value; |  | ||||||
|  |  | ||||||
| 				//We can parametise the length on anything up to uint32_t. |  | ||||||
| 				//This lets us experiment with the optimal size in the future. |  | ||||||
| 				static uint32_t maxRunlength(void) {return (std::numeric_limits<LengthType>::max)();} |  | ||||||
| 			}; |  | ||||||
|  |  | ||||||
| 			//Make Sampler a friend | 			//Make Sampler a friend | ||||||
| 			friend class LargeVolume<VoxelType>::Sampler; | 			friend class SimpleVolume<VoxelType>::Sampler; | ||||||
| 		public: | 		public: | ||||||
| 			Block(uint16_t uSideLength = 0); | 			Block(uint16_t uSideLength = 0); | ||||||
|  |  | ||||||
| @@ -69,12 +58,9 @@ namespace PolyVox | |||||||
| 			uint32_t calculateSizeInBytes(void); | 			uint32_t calculateSizeInBytes(void); | ||||||
|  |  | ||||||
| 		public: | 		public: | ||||||
| 			std::vector< RunlengthEntry<uint16_t> > m_vecCompressedData; |  | ||||||
| 			VoxelType* m_tUncompressedData; | 			VoxelType* m_tUncompressedData; | ||||||
| 			uint16_t m_uSideLength; | 			uint16_t m_uSideLength; | ||||||
| 			uint8_t m_uSideLengthPower;	 | 			uint8_t m_uSideLengthPower;	 | ||||||
| 			bool m_bIsCompressed; |  | ||||||
| 			bool m_bIsUncompressedDataModified; |  | ||||||
| 		}; | 		}; | ||||||
|  |  | ||||||
| 		class Sampler | 		class Sampler | ||||||
| @@ -147,19 +133,6 @@ namespace PolyVox | |||||||
| 			VoxelType* mCurrentVoxel; | 			VoxelType* mCurrentVoxel; | ||||||
| 		}; | 		}; | ||||||
|  |  | ||||||
| 		struct LoadedBlock |  | ||||||
| 		{ |  | ||||||
| 		public: |  | ||||||
| 			LoadedBlock(uint16_t uSideLength = 0) |  | ||||||
| 				:block(uSideLength) |  | ||||||
| 				,timestamp(0) |  | ||||||
| 			{ |  | ||||||
| 			} |  | ||||||
|  |  | ||||||
| 			Block block; |  | ||||||
| 			uint32_t timestamp; |  | ||||||
| 		}; |  | ||||||
|  |  | ||||||
| 	public: | 	public: | ||||||
| 		/// Constructor for creating a fixed size volume. | 		/// Constructor for creating a fixed size volume. | ||||||
| 		SimpleVolume | 		SimpleVolume | ||||||
| @@ -225,14 +198,12 @@ private: | |||||||
| 		polyvox_function<void(const ConstVolumeProxy<VoxelType>&, const Region&)> m_funcDataOverflowHandler; | 		polyvox_function<void(const ConstVolumeProxy<VoxelType>&, const Region&)> m_funcDataOverflowHandler; | ||||||
| 	 | 	 | ||||||
| 		Block* getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const; | 		Block* getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const; | ||||||
| 		void eraseBlock(typename std::map<Vector3DInt32, LoadedBlock >::iterator itBlock) const; |  | ||||||
| 		/// this function can be called by m_funcDataRequiredHandler without causing any weird effects | 		/// 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; | 		bool setVoxelAtConst(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue) const; | ||||||
|  |  | ||||||
| 		//The block data | 		//The block data | ||||||
| 		mutable std::map<Vector3DInt32, LoadedBlock > m_pBlocks; | 		mutable std::map<Vector3DInt32, Block > m_pBlocks; | ||||||
|  |  | ||||||
| 		mutable uint32_t m_uTimestamper; |  | ||||||
| 		mutable Vector3DInt32 m_v3dLastAccessedBlockPos; | 		mutable Vector3DInt32 m_v3dLastAccessedBlockPos; | ||||||
| 		mutable Block* m_pLastAccessedBlock; | 		mutable Block* m_pLastAccessedBlock; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -284,11 +284,8 @@ namespace PolyVox | |||||||
| 			throw std::invalid_argument("Block side length must be a power of two."); | 			throw std::invalid_argument("Block side length must be a power of two."); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		m_uTimestamper = 0; |  | ||||||
| 		m_uBlockSideLength = uBlockSideLength; | 		m_uBlockSideLength = uBlockSideLength; | ||||||
| 		m_pUncompressedBorderData = 0; | 		m_pUncompressedBorderData = 0; | ||||||
| 		m_v3dLastAccessedBlockPos = Vector3DInt32(0,0,0); //There are no invalid positions, but initially the m_pLastAccessedBlock pointer will be null; |  | ||||||
| 		m_pLastAccessedBlock = 0; |  | ||||||
|  |  | ||||||
| 		m_regValidRegion = regValidRegion; | 		m_regValidRegion = regValidRegion; | ||||||
|  |  | ||||||
| @@ -315,12 +312,6 @@ namespace PolyVox | |||||||
| 		m_fDiagonalLength = sqrtf(static_cast<float>(getWidth() * getWidth() + getHeight() * getHeight() + getDepth() * getDepth())); | 		m_fDiagonalLength = sqrtf(static_cast<float>(getWidth() * getWidth() + getHeight() * getHeight() + getDepth() * getDepth())); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	template <typename VoxelType> |  | ||||||
| 	void SimpleVolume<VoxelType>::eraseBlock(typename std::map<Vector3DInt32, LoadedBlock >::iterator itBlock) const |  | ||||||
| 	{ |  | ||||||
| 		m_pBlocks.erase(itBlock); |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	template <typename VoxelType> | 	template <typename VoxelType> | ||||||
| 	bool SimpleVolume<VoxelType>::setVoxelAtConst(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue) const | 	bool SimpleVolume<VoxelType>::setVoxelAtConst(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue) const | ||||||
| 	{ | 	{ | ||||||
| @@ -350,32 +341,17 @@ namespace PolyVox | |||||||
| 	{ | 	{ | ||||||
| 		Vector3DInt32 v3dBlockPos(uBlockX, uBlockY, uBlockZ);		 | 		Vector3DInt32 v3dBlockPos(uBlockX, uBlockY, uBlockZ);		 | ||||||
|  |  | ||||||
| 		typename std::map<Vector3DInt32, LoadedBlock >::iterator itBlock = m_pBlocks.find(v3dBlockPos); | 		typename std::map<Vector3DInt32, Block >::iterator itBlock = m_pBlocks.find(v3dBlockPos); | ||||||
| 		// check whether the block is already loaded | 		// check whether the block is already loaded | ||||||
| 		if(itBlock == m_pBlocks.end()) | 		if(itBlock == m_pBlocks.end()) | ||||||
| 		{			 | 		{			 | ||||||
| 			// create the new block | 			// create the new block | ||||||
| 			LoadedBlock newBlock(m_uBlockSideLength); | 			Block newBlock(m_uBlockSideLength); | ||||||
| 			itBlock = m_pBlocks.insert(std::make_pair(v3dBlockPos, newBlock)).first; | 			itBlock = m_pBlocks.insert(std::make_pair(v3dBlockPos, newBlock)).first; | ||||||
| 		}		 | 		}		 | ||||||
|  |  | ||||||
| 		//Get the block and mark that we accessed it | 		Block& block = itBlock->second; | ||||||
| 		LoadedBlock& loadedBlock = itBlock->second; | 		return █ | ||||||
| 		loadedBlock.timestamp = ++m_uTimestamper; |  | ||||||
| 		m_v3dLastAccessedBlockPos = v3dBlockPos; |  | ||||||
| 		m_pLastAccessedBlock = &(loadedBlock.block); |  | ||||||
|  |  | ||||||
| 		if(loadedBlock.block.m_bIsCompressed == false) |  | ||||||
| 		{ 			 |  | ||||||
| 			assert(m_pLastAccessedBlock->m_tUncompressedData); |  | ||||||
| 			return m_pLastAccessedBlock; |  | ||||||
| 		} |  | ||||||
| 		 |  | ||||||
| 		//loadedBlock.block.uncompress(); |  | ||||||
|  |  | ||||||
| 		m_pLastAccessedBlock = &(loadedBlock.block); |  | ||||||
| 		assert(m_pLastAccessedBlock->m_tUncompressedData); |  | ||||||
| 		return m_pLastAccessedBlock; |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	//////////////////////////////////////////////////////////////////////////////// | 	//////////////////////////////////////////////////////////////////////////////// | ||||||
|   | |||||||
| @@ -36,8 +36,6 @@ namespace PolyVox | |||||||
| 		:m_uSideLength(0) | 		:m_uSideLength(0) | ||||||
| 		,m_uSideLengthPower(0) | 		,m_uSideLengthPower(0) | ||||||
| 		,m_tUncompressedData(0) | 		,m_tUncompressedData(0) | ||||||
| 		,m_bIsCompressed(true) |  | ||||||
| 		,m_bIsUncompressedDataModified(true) |  | ||||||
| 	{ | 	{ | ||||||
| 		if(uSideLength != 0) | 		if(uSideLength != 0) | ||||||
| 		{ | 		{ | ||||||
| @@ -89,8 +87,6 @@ namespace PolyVox | |||||||
| 			uYPos * m_uSideLength +  | 			uYPos * m_uSideLength +  | ||||||
| 			uZPos * m_uSideLength * m_uSideLength | 			uZPos * m_uSideLength * m_uSideLength | ||||||
| 		] = tValue; | 		] = tValue; | ||||||
|  |  | ||||||
| 		m_bIsUncompressedDataModified = true; |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	template <typename VoxelType> | 	template <typename VoxelType> | ||||||
| @@ -102,12 +98,8 @@ namespace PolyVox | |||||||
| 	template <typename VoxelType> | 	template <typename VoxelType> | ||||||
| 	void SimpleVolume<VoxelType>::Block::fill(VoxelType tValue) | 	void SimpleVolume<VoxelType>::Block::fill(VoxelType tValue) | ||||||
| 	{ | 	{ | ||||||
| 			//The memset *may* be faster than the std::fill(), but it doesn't compile nicely |  | ||||||
| 			//in 64-bit mode as casting the pointer to an int causes a loss of precision. |  | ||||||
| 		const uint32_t uNoOfVoxels = m_uSideLength * m_uSideLength * m_uSideLength; | 		const uint32_t uNoOfVoxels = m_uSideLength * m_uSideLength * m_uSideLength; | ||||||
| 		std::fill(m_tUncompressedData, m_tUncompressedData + uNoOfVoxels, tValue); | 		std::fill(m_tUncompressedData, m_tUncompressedData + uNoOfVoxels, tValue); | ||||||
|  |  | ||||||
| 			m_bIsUncompressedDataModified = true; |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	template <typename VoxelType> | 	template <typename VoxelType> | ||||||
| @@ -135,7 +127,7 @@ namespace PolyVox | |||||||
| 	uint32_t SimpleVolume<VoxelType>::Block::calculateSizeInBytes(void) | 	uint32_t SimpleVolume<VoxelType>::Block::calculateSizeInBytes(void) | ||||||
| 	{ | 	{ | ||||||
| 		uint32_t uSizeInBytes = sizeof(Block<VoxelType>); | 		uint32_t uSizeInBytes = sizeof(Block<VoxelType>); | ||||||
| 		uSizeInBytes += m_vecCompressedData.capacity() * sizeof(RunlengthEntry<uint16_t>); | 		uSizeInBytes += sizeof(VoxelType) * m_uSideLength * m_uSideLength * m_uSideLength; | ||||||
| 		return  uSizeInBytes; | 		return  uSizeInBytes; | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user