From 0e27b2fb50453da7e8564eafee16a8fd959beaad Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 30 Apr 2011 12:16:33 +0100 Subject: [PATCH] Swapped std::map for array in SimpleVolume. --- library/PolyVoxCore/include/SimpleVolume.h | 4 ++- library/PolyVoxCore/include/SimpleVolume.inl | 34 ++++++++++++++++---- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/library/PolyVoxCore/include/SimpleVolume.h b/library/PolyVoxCore/include/SimpleVolume.h index e8c1f98d..eab6844e 100644 --- a/library/PolyVoxCore/include/SimpleVolume.h +++ b/library/PolyVoxCore/include/SimpleVolume.h @@ -186,7 +186,9 @@ private: Block* getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const; //The block data - mutable std::map m_pBlocks; + //mutable std::map m_pBlocks; + + Block* m_pBlocks; //We don't store an actual Block for the border, just the uncompressed data. This is partly because the border //block does not have a position (so can't be passed to getUncompressedBlock()) and partly because there's a diff --git a/library/PolyVoxCore/include/SimpleVolume.inl b/library/PolyVoxCore/include/SimpleVolume.inl index eb4ff2fa..610826c2 100644 --- a/library/PolyVoxCore/include/SimpleVolume.inl +++ b/library/PolyVoxCore/include/SimpleVolume.inl @@ -284,15 +284,21 @@ namespace PolyVox m_regValidRegionInBlocks.setLowerCorner(m_regValidRegion.getLowerCorner() / static_cast(uBlockSideLength)); m_regValidRegionInBlocks.setUpperCorner(m_regValidRegion.getUpperCorner() / static_cast(uBlockSideLength)); - //Clear the previous data - m_pBlocks.clear(); - //Compute the block side length m_uBlockSideLength = uBlockSideLength; m_uBlockSideLengthPower = logBase2(m_uBlockSideLength); //Clear the previous data - m_pBlocks.clear(); + //m_pBlocks.clear(); + //delete[] m_pBlocks; + //Allocate the new data + + Vector3DInt32 uDimensionsInBlocks = m_regValidRegionInBlocks.getUpperCorner() - m_regValidRegionInBlocks.getLowerCorner() + Vector3DInt32(1,1,1); + m_pBlocks = new Block[uDimensionsInBlocks.getX() * uDimensionsInBlocks.getY() * uDimensionsInBlocks.getZ()]; + for(uint32_t i = 0; i < uDimensionsInBlocks.getX() * uDimensionsInBlocks.getY() * uDimensionsInBlocks.getZ(); ++i) + { + m_pBlocks[i].initialise(m_uBlockSideLength); + } //Create the border block m_pUncompressedBorderData = new VoxelType[m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength]; @@ -307,9 +313,23 @@ namespace PolyVox template typename SimpleVolume::Block* SimpleVolume::getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const { - Vector3DInt32 v3dBlockPos(uBlockX, uBlockY, uBlockZ); + Vector3DInt32 v3dBlockPos(uBlockX, uBlockY, uBlockZ); - typename std::map::iterator itBlock = m_pBlocks.find(v3dBlockPos); + Vector3DInt32 uDimensionsInBlocks = m_regValidRegionInBlocks.getUpperCorner() - m_regValidRegionInBlocks.getLowerCorner() + Vector3DInt32(1,1,1); + + uint32_t uBlockIndex = + uBlockX + + uBlockY * uDimensionsInBlocks.getX() + + uBlockZ * uDimensionsInBlocks.getX() * uDimensionsInBlocks.getY(); + + //Get the block + Block* block = &(m_pBlocks[uBlockIndex]); + + return block; + + //Block& block = m_pBlocks[] + + /*typename std::map::iterator itBlock = m_pBlocks.find(v3dBlockPos); // check whether the block is already loaded if(itBlock == m_pBlocks.end()) { @@ -319,7 +339,7 @@ namespace PolyVox } Block& block = itBlock->second; - return █ + return █*/ } ////////////////////////////////////////////////////////////////////////////////