More work on SimpleVolume.
This commit is contained in:
parent
0e27b2fb50
commit
87d97436ea
@ -28,10 +28,7 @@ freely, subject to the following restrictions:
|
|||||||
#include "PolyVoxForwardDeclarations.h"
|
#include "PolyVoxForwardDeclarations.h"
|
||||||
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <map>
|
|
||||||
#include <set>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace PolyVox
|
namespace PolyVox
|
||||||
{
|
{
|
||||||
@ -186,8 +183,6 @@ private:
|
|||||||
Block* getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const;
|
Block* getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const;
|
||||||
|
|
||||||
//The block data
|
//The block data
|
||||||
//mutable std::map<Vector3DInt32, Block > m_pBlocks;
|
|
||||||
|
|
||||||
Block* 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
|
//We don't store an actual Block for the border, just the uncompressed data. This is partly because the border
|
||||||
@ -200,6 +195,12 @@ private:
|
|||||||
Region m_regValidRegion;
|
Region m_regValidRegion;
|
||||||
Region m_regValidRegionInBlocks;
|
Region m_regValidRegionInBlocks;
|
||||||
|
|
||||||
|
//Volume size measured in blocks.
|
||||||
|
uint32_t m_uNoOfBlocksInVolume;
|
||||||
|
uint16_t m_uWidthInBlocks;
|
||||||
|
uint16_t m_uHeightInBlocks;
|
||||||
|
uint16_t m_uDepthInBlocks;
|
||||||
|
|
||||||
//The size of the blocks
|
//The size of the blocks
|
||||||
uint16_t m_uBlockSideLength;
|
uint16_t m_uBlockSideLength;
|
||||||
uint8_t m_uBlockSideLengthPower;
|
uint8_t m_uBlockSideLengthPower;
|
||||||
|
@ -30,8 +30,6 @@ freely, subject to the following restrictions:
|
|||||||
#include <limits>
|
#include <limits>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstdlib> //For abort()
|
#include <cstdlib> //For abort()
|
||||||
#include <cstring> //For memcpy
|
|
||||||
#include <list>
|
|
||||||
#include <stdexcept> //For invalid_argument
|
#include <stdexcept> //For invalid_argument
|
||||||
|
|
||||||
namespace PolyVox
|
namespace PolyVox
|
||||||
@ -82,6 +80,8 @@ namespace PolyVox
|
|||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
SimpleVolume<VoxelType>::~SimpleVolume()
|
SimpleVolume<VoxelType>::~SimpleVolume()
|
||||||
{
|
{
|
||||||
|
delete[] m_pBlocks;
|
||||||
|
m_pBlocks = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -288,14 +288,15 @@ namespace PolyVox
|
|||||||
m_uBlockSideLength = uBlockSideLength;
|
m_uBlockSideLength = uBlockSideLength;
|
||||||
m_uBlockSideLengthPower = logBase2(m_uBlockSideLength);
|
m_uBlockSideLengthPower = logBase2(m_uBlockSideLength);
|
||||||
|
|
||||||
//Clear the previous data
|
//Compute the size of the volume in blocks (and note +1 at the end)
|
||||||
//m_pBlocks.clear();
|
m_uWidthInBlocks = m_regValidRegionInBlocks.getUpperCorner().getX() - m_regValidRegionInBlocks.getLowerCorner().getX() + 1;
|
||||||
//delete[] m_pBlocks;
|
m_uHeightInBlocks = m_regValidRegionInBlocks.getUpperCorner().getY() - m_regValidRegionInBlocks.getLowerCorner().getY() + 1;
|
||||||
//Allocate the new data
|
m_uDepthInBlocks = m_regValidRegionInBlocks.getUpperCorner().getZ() - m_regValidRegionInBlocks.getLowerCorner().getZ() + 1;
|
||||||
|
m_uNoOfBlocksInVolume = m_uWidthInBlocks * m_uHeightInBlocks * m_uDepthInBlocks;
|
||||||
|
|
||||||
Vector3DInt32 uDimensionsInBlocks = m_regValidRegionInBlocks.getUpperCorner() - m_regValidRegionInBlocks.getLowerCorner() + Vector3DInt32(1,1,1);
|
//Allocate the data
|
||||||
m_pBlocks = new Block[uDimensionsInBlocks.getX() * uDimensionsInBlocks.getY() * uDimensionsInBlocks.getZ()];
|
m_pBlocks = new Block[m_uNoOfBlocksInVolume];
|
||||||
for(uint32_t i = 0; i < uDimensionsInBlocks.getX() * uDimensionsInBlocks.getY() * uDimensionsInBlocks.getZ(); ++i)
|
for(uint32_t i = 0; i < m_uNoOfBlocksInVolume; ++i)
|
||||||
{
|
{
|
||||||
m_pBlocks[i].initialise(m_uBlockSideLength);
|
m_pBlocks[i].initialise(m_uBlockSideLength);
|
||||||
}
|
}
|
||||||
@ -313,33 +314,20 @@ namespace PolyVox
|
|||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
typename SimpleVolume<VoxelType>::Block* SimpleVolume<VoxelType>::getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const
|
typename SimpleVolume<VoxelType>::Block* SimpleVolume<VoxelType>::getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const
|
||||||
{
|
{
|
||||||
Vector3DInt32 v3dBlockPos(uBlockX, uBlockY, uBlockZ);
|
//The lower left corner of the volume could be
|
||||||
|
//anywhere, but array indices need to start at zero.
|
||||||
Vector3DInt32 uDimensionsInBlocks = m_regValidRegionInBlocks.getUpperCorner() - m_regValidRegionInBlocks.getLowerCorner() + Vector3DInt32(1,1,1);
|
uBlockX -= m_regValidRegionInBlocks.getLowerCorner().getX();
|
||||||
|
uBlockY -= m_regValidRegionInBlocks.getLowerCorner().getY();
|
||||||
|
uBlockZ -= m_regValidRegionInBlocks.getLowerCorner().getZ();
|
||||||
|
|
||||||
|
//Compute the block index
|
||||||
uint32_t uBlockIndex =
|
uint32_t uBlockIndex =
|
||||||
uBlockX +
|
uBlockX +
|
||||||
uBlockY * uDimensionsInBlocks.getX() +
|
uBlockY * m_uWidthInBlocks +
|
||||||
uBlockZ * uDimensionsInBlocks.getX() * uDimensionsInBlocks.getY();
|
uBlockZ * m_uWidthInBlocks * m_uHeightInBlocks;
|
||||||
|
|
||||||
//Get the block
|
//Return the block
|
||||||
Block* block = &(m_pBlocks[uBlockIndex]);
|
return &(m_pBlocks[uBlockIndex]);
|
||||||
|
|
||||||
return block;
|
|
||||||
|
|
||||||
//Block& block = m_pBlocks[]
|
|
||||||
|
|
||||||
/*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
|
|
||||||
Block newBlock(m_uBlockSideLength);
|
|
||||||
itBlock = m_pBlocks.insert(std::make_pair(v3dBlockPos, newBlock)).first;
|
|
||||||
}
|
|
||||||
|
|
||||||
Block& block = itBlock->second;
|
|
||||||
return █*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
Loading…
x
Reference in New Issue
Block a user