Pulling out timestamps and last accessed block from SimpleVolume.
This commit is contained in:
		| @@ -41,19 +41,8 @@ namespace PolyVox | ||||
| 	public: | ||||
| 		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 | ||||
| 			friend class LargeVolume<VoxelType>::Sampler; | ||||
| 			friend class SimpleVolume<VoxelType>::Sampler; | ||||
| 		public: | ||||
| 			Block(uint16_t uSideLength = 0); | ||||
|  | ||||
| @@ -69,12 +58,9 @@ namespace PolyVox | ||||
| 			uint32_t calculateSizeInBytes(void); | ||||
|  | ||||
| 		public: | ||||
| 			std::vector< RunlengthEntry<uint16_t> > m_vecCompressedData; | ||||
| 			VoxelType* m_tUncompressedData; | ||||
| 			uint16_t m_uSideLength; | ||||
| 			uint8_t m_uSideLengthPower;	 | ||||
| 			bool m_bIsCompressed; | ||||
| 			bool m_bIsUncompressedDataModified; | ||||
| 		}; | ||||
|  | ||||
| 		class Sampler | ||||
| @@ -147,19 +133,6 @@ namespace PolyVox | ||||
| 			VoxelType* mCurrentVoxel; | ||||
| 		}; | ||||
|  | ||||
| 		struct LoadedBlock | ||||
| 		{ | ||||
| 		public: | ||||
| 			LoadedBlock(uint16_t uSideLength = 0) | ||||
| 				:block(uSideLength) | ||||
| 				,timestamp(0) | ||||
| 			{ | ||||
| 			} | ||||
|  | ||||
| 			Block block; | ||||
| 			uint32_t timestamp; | ||||
| 		}; | ||||
|  | ||||
| 	public: | ||||
| 		/// Constructor for creating a fixed size volume. | ||||
| 		SimpleVolume | ||||
| @@ -225,14 +198,12 @@ private: | ||||
| 		polyvox_function<void(const ConstVolumeProxy<VoxelType>&, const Region&)> m_funcDataOverflowHandler; | ||||
| 	 | ||||
| 		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 | ||||
| 		bool setVoxelAtConst(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue) const; | ||||
|  | ||||
| 		//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 Block* m_pLastAccessedBlock; | ||||
|  | ||||
|   | ||||
| @@ -284,11 +284,8 @@ namespace PolyVox | ||||
| 			throw std::invalid_argument("Block side length must be a power of two."); | ||||
| 		} | ||||
|  | ||||
| 		m_uTimestamper = 0; | ||||
| 		m_uBlockSideLength = uBlockSideLength; | ||||
| 		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; | ||||
|  | ||||
| @@ -315,12 +312,6 @@ namespace PolyVox | ||||
| 		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> | ||||
| 	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);		 | ||||
|  | ||||
| 		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 | ||||
| 		if(itBlock == m_pBlocks.end()) | ||||
| 		{			 | ||||
| 			// create the new block | ||||
| 			LoadedBlock newBlock(m_uBlockSideLength); | ||||
| 			Block newBlock(m_uBlockSideLength); | ||||
| 			itBlock = m_pBlocks.insert(std::make_pair(v3dBlockPos, newBlock)).first; | ||||
| 		}		 | ||||
|  | ||||
| 		//Get the block and mark that we accessed it | ||||
| 		LoadedBlock& loadedBlock = itBlock->second; | ||||
| 		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; | ||||
| 		Block& block = itBlock->second; | ||||
| 		return █ | ||||
| 	} | ||||
|  | ||||
| 	//////////////////////////////////////////////////////////////////////////////// | ||||
|   | ||||
| @@ -36,8 +36,6 @@ namespace PolyVox | ||||
| 		:m_uSideLength(0) | ||||
| 		,m_uSideLengthPower(0) | ||||
| 		,m_tUncompressedData(0) | ||||
| 		,m_bIsCompressed(true) | ||||
| 		,m_bIsUncompressedDataModified(true) | ||||
| 	{ | ||||
| 		if(uSideLength != 0) | ||||
| 		{ | ||||
| @@ -89,8 +87,6 @@ namespace PolyVox | ||||
| 			uYPos * m_uSideLength +  | ||||
| 			uZPos * m_uSideLength * m_uSideLength | ||||
| 		] = tValue; | ||||
|  | ||||
| 		m_bIsUncompressedDataModified = true; | ||||
| 	} | ||||
|  | ||||
| 	template <typename VoxelType> | ||||
| @@ -102,12 +98,8 @@ namespace PolyVox | ||||
| 	template <typename VoxelType> | ||||
| 	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; | ||||
| 		std::fill(m_tUncompressedData, m_tUncompressedData + uNoOfVoxels, tValue); | ||||
|  | ||||
| 			m_bIsUncompressedDataModified = true; | ||||
| 	} | ||||
|  | ||||
| 	template <typename VoxelType> | ||||
| @@ -135,7 +127,7 @@ namespace PolyVox | ||||
| 	uint32_t SimpleVolume<VoxelType>::Block::calculateSizeInBytes(void) | ||||
| 	{ | ||||
| 		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; | ||||
| 	} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user