Removed homogeneous value from Block class.
This commit is contained in:
		| @@ -34,7 +34,6 @@ namespace PolyVox | |||||||
| 	{ | 	{ | ||||||
| 	public: | 	public: | ||||||
| 		POLYVOX_SHARED_PTR< BlockData<VoxelType> > m_pBlockData; | 		POLYVOX_SHARED_PTR< BlockData<VoxelType> > m_pBlockData; | ||||||
| 		VoxelType m_pHomogenousValue; |  | ||||||
| 		bool m_bIsShared; | 		bool m_bIsShared; | ||||||
| 		bool m_bIsPotentiallySharable; | 		bool m_bIsPotentiallySharable; | ||||||
| 	}; | 	}; | ||||||
|   | |||||||
| @@ -77,9 +77,14 @@ namespace PolyVox | |||||||
| 			return *this; | 			return *this; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | 		//If this fails an exception will be thrown. Memory is not    | ||||||
|  | 		//allocated and there is nothing else in this class to clean up | ||||||
|  | 		m_tData = new VoxelType[rhs.m_uSideLength * rhs.m_uSideLength * rhs.m_uSideLength]; | ||||||
|  |  | ||||||
|  | 		//Copy the data | ||||||
| 		m_uSideLength = rhs.m_uSideLength; | 		m_uSideLength = rhs.m_uSideLength; | ||||||
| 		m_uSideLengthPower = rhs.m_uSideLengthPower;		 | 		m_uSideLengthPower = rhs.m_uSideLengthPower;		 | ||||||
| 		memcpy(m_tData, rhs.m_tData, m_uSideLength * m_uSideLength * m_uSideLength); | 		memcpy(m_tData, rhs.m_tData, m_uSideLength * m_uSideLength * m_uSideLength * sizeof(VoxelType)); | ||||||
|  |  | ||||||
| 		return *this; | 		return *this; | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -78,7 +78,6 @@ namespace PolyVox | |||||||
| 			m_pBlocks[i].m_pBlockData = getHomogenousBlockData(0); | 			m_pBlocks[i].m_pBlockData = getHomogenousBlockData(0); | ||||||
| 			m_pBlocks[i].m_bIsShared = true; | 			m_pBlocks[i].m_bIsShared = true; | ||||||
| 			m_pBlocks[i].m_bIsPotentiallySharable = false; | 			m_pBlocks[i].m_bIsPotentiallySharable = false; | ||||||
| 			m_pBlocks[i].m_pHomogenousValue = 0; |  | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -171,25 +170,26 @@ namespace PolyVox | |||||||
| 				blockZ * m_uSideLengthInBlocks * m_uSideLengthInBlocks | 				blockZ * m_uSideLengthInBlocks * m_uSideLengthInBlocks | ||||||
| 			]; | 			]; | ||||||
|  |  | ||||||
| 		if(block.m_bIsShared) | 		//It's quite possible that the user might attempt to set a voxel to it's current value. | ||||||
|  | 		//We test for this case firstly because it could help performance, but more importantly | ||||||
|  | 		//because it lets us avoid unsharing blocks unnecessarily. | ||||||
|  | 		if(block.m_pBlockData->getVoxelAt(xOffset, yOffset, zOffset) != tValue) | ||||||
| 		{ | 		{ | ||||||
| 			const VoxelType tHomogenousValue = block.m_pHomogenousValue; | 			if(block.m_bIsShared) | ||||||
| 			if(tHomogenousValue != tValue) |  | ||||||
| 			{ | 			{ | ||||||
| 				POLYVOX_SHARED_PTR< BlockData<VoxelType> > pNewBlockData(new BlockData<VoxelType>(m_uBlockSideLength)); | 				POLYVOX_SHARED_PTR< BlockData<VoxelType> > pNewBlockData(new BlockData<VoxelType>(*(block.m_pBlockData))); | ||||||
| 				block.m_pBlockData = pNewBlockData; | 				block.m_pBlockData = pNewBlockData; | ||||||
| 				block.m_bIsShared = false; | 				block.m_bIsShared = false; | ||||||
| 				block.m_bIsPotentiallySharable = false; | 				block.m_bIsPotentiallySharable = false; | ||||||
| 				block.m_pBlockData->fill(tHomogenousValue); |  | ||||||
| 				block.m_pBlockData->setVoxelAt(xOffset,yOffset,zOffset, tValue); | 				block.m_pBlockData->setVoxelAt(xOffset,yOffset,zOffset, tValue); | ||||||
| 			} | 			} | ||||||
| 		} | 			else | ||||||
| 		else | 			{			 | ||||||
| 		{			 | 				block.m_pBlockData->setVoxelAt(xOffset,yOffset,zOffset, tValue); | ||||||
| 			block.m_pBlockData->setVoxelAt(xOffset,yOffset,zOffset, tValue); | 				//There is a chance that setting this voxel makes the block homogenous and therefore shareable. But checking | ||||||
| 			//There is a chance that setting this voxel makes the block homogenous and therefore shareable. But checking | 				//this will take some time, so for now just set a flag. | ||||||
| 			//this will take some time, so for now just set a flag. | 				block.m_bIsPotentiallySharable = true; | ||||||
| 			block.m_bIsPotentiallySharable = true; | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -221,7 +221,6 @@ namespace PolyVox | |||||||
| 					delete block.m_pBlockData; | 					delete block.m_pBlockData; | ||||||
|  |  | ||||||
| 					block.m_pBlockData = getHomogenousBlockData(homogeneousValue); | 					block.m_pBlockData = getHomogenousBlockData(homogeneousValue); | ||||||
| 					block.m_pHomogenousValue = homogeneousValue; |  | ||||||
| 					block.m_bIsShared = true; | 					block.m_bIsShared = true; | ||||||
| 				} | 				} | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user