Renamed UncompressedBlock to Chunk.

This commit is contained in:
David Williams 2014-09-20 17:26:57 +02:00
parent 880dcd8645
commit ede35435a0
9 changed files with 74 additions and 74 deletions

View File

@ -90,11 +90,11 @@ public:
/// Destructor
virtual ~PerlinNoisePager() {};
virtual void pageIn(const PolyVox::Region& region, UncompressedBlock<MaterialDensityPair44>* pBlockData)
virtual void pageIn(const PolyVox::Region& region, Chunk<MaterialDensityPair44>* pBlockData)
{
// FIXME - this isn't a great example... it's a shame we have to hard clode the block size and also create/destroy
// a compressor each time. These could at least be moved outside somewhere if we can't fix it in a better way...
//UncompressedBlock<MaterialDensityPair44> block(256);
//Chunk<MaterialDensityPair44> block(256);
Perlin perlin(2,2,1,234);
@ -143,7 +143,7 @@ public:
//delete compressor;
}
virtual void pageOut(const PolyVox::Region& region, UncompressedBlock<MaterialDensityPair44>* /*pBlockData*/)
virtual void pageOut(const PolyVox::Region& region, Chunk<MaterialDensityPair44>* /*pBlockData*/)
{
std::cout << "warning unloading region: " << region.getLowerCorner() << " -> " << region.getUpperCorner() << std::endl;
}

View File

@ -38,6 +38,8 @@ SET(CORE_INC_FILES
include/PolyVoxCore/BaseVolume.h
include/PolyVoxCore/BaseVolume.inl
include/PolyVoxCore/BaseVolumeSampler.inl
include/PolyVoxCore/Chunk.h
include/PolyVoxCore/Chunk.inl
include/PolyVoxCore/CubicSurfaceExtractor.h
include/PolyVoxCore/CubicSurfaceExtractor.inl
include/PolyVoxCore/DefaultIsQuadNeeded.h
@ -72,8 +74,6 @@ SET(CORE_INC_FILES
include/PolyVoxCore/Raycast.inl
include/PolyVoxCore/Region.h
include/PolyVoxCore/SimpleVolume.h
include/PolyVoxCore/UncompressedBlock.h
include/PolyVoxCore/UncompressedBlock.inl
include/PolyVoxCore/Vector.h
include/PolyVoxCore/Vector.inl
include/PolyVoxCore/Vertex.h

View File

@ -21,8 +21,8 @@ freely, subject to the following restrictions:
distribution.
*******************************************************************************/
#ifndef __PolyVox_UncompressedBlock_H__
#define __PolyVox_UncompressedBlock_H__
#ifndef __PolyVox_Chunk_H__
#define __PolyVox_Chunk_H__
#include "PolyVoxCore/PolyVoxForwardDeclarations.h"
#include "PolyVoxCore/Vector.h"
@ -30,13 +30,13 @@ freely, subject to the following restrictions:
namespace PolyVox
{
template <typename VoxelType>
class UncompressedBlock
class Chunk
{
friend class PagedVolume<VoxelType>;
public:
UncompressedBlock(Vector3DInt32 v3dPosition, uint16_t uSideLength, Pager<VoxelType>* pPager = nullptr);
~UncompressedBlock();
Chunk(Vector3DInt32 v3dPosition, uint16_t uSideLength, Pager<VoxelType>* pPager = nullptr);
~Chunk();
VoxelType* getData(void) const;
uint32_t getDataSizeInBytes(void) const;
@ -49,10 +49,10 @@ namespace PolyVox
private:
/// Private copy constructor to prevent accisdental copying
UncompressedBlock(const UncompressedBlock& /*rhs*/) {};
Chunk(const Chunk& /*rhs*/) {};
/// Private assignment operator to prevent accisdental copying
UncompressedBlock& operator=(const UncompressedBlock& /*rhs*/) {};
Chunk& operator=(const Chunk& /*rhs*/) {};
// This is updated by the PagedVolume and used to discard the least recently used blocks.
uint32_t m_uBlockLastAccessed;
@ -62,7 +62,7 @@ namespace PolyVox
bool m_bDataModified;
// Made this private for consistancy with CompressedBlock.
// Users shouldn't really need this for UncompressedBlock anyway.
// Users shouldn't really need this for Chunk anyway.
uint32_t calculateSizeInBytes(void);
static uint32_t calculateSizeInBytes(uint32_t uSideLength);
@ -74,6 +74,6 @@ namespace PolyVox
};
}
#include "PolyVoxCore/UncompressedBlock.inl"
#include "PolyVoxCore/Chunk.inl"
#endif

View File

@ -26,7 +26,7 @@ freely, subject to the following restrictions:
namespace PolyVox
{
template <typename VoxelType>
UncompressedBlock<VoxelType>::UncompressedBlock(Vector3DInt32 v3dPosition, uint16_t uSideLength, Pager<VoxelType>* pPager)
Chunk<VoxelType>::Chunk(Vector3DInt32 v3dPosition, uint16_t uSideLength, Pager<VoxelType>* pPager)
:m_uBlockLastAccessed(0)
,m_bDataModified(true)
,m_tData(0)
@ -65,7 +65,7 @@ namespace PolyVox
}
template <typename VoxelType>
UncompressedBlock<VoxelType>::~UncompressedBlock()
Chunk<VoxelType>::~Chunk()
{
if (m_pPager && m_bDataModified)
{
@ -82,19 +82,19 @@ namespace PolyVox
}
template <typename VoxelType>
VoxelType* UncompressedBlock<VoxelType>::getData(void) const
VoxelType* Chunk<VoxelType>::getData(void) const
{
return m_tData;
}
template <typename VoxelType>
uint32_t UncompressedBlock<VoxelType>::getDataSizeInBytes(void) const
uint32_t Chunk<VoxelType>::getDataSizeInBytes(void) const
{
return m_uSideLength * m_uSideLength * m_uSideLength * sizeof(VoxelType);
}
template <typename VoxelType>
VoxelType UncompressedBlock<VoxelType>::getVoxel(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const
VoxelType Chunk<VoxelType>::getVoxel(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const
{
// This code is not usually expected to be called by the user, with the exception of when implementing paging
// of uncompressed data. It's a performance critical code path so we use asserts rather than exceptions.
@ -112,13 +112,13 @@ namespace PolyVox
}
template <typename VoxelType>
VoxelType UncompressedBlock<VoxelType>::getVoxel(const Vector3DUint16& v3dPos) const
VoxelType Chunk<VoxelType>::getVoxel(const Vector3DUint16& v3dPos) const
{
return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ());
}
template <typename VoxelType>
void UncompressedBlock<VoxelType>::setVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos, VoxelType tValue)
void Chunk<VoxelType>::setVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos, VoxelType tValue)
{
// This code is not usually expected to be called by the user, with the exception of when implementing paging
// of uncompressed data. It's a performance critical code path so we use asserts rather than exceptions.
@ -138,20 +138,20 @@ namespace PolyVox
}
template <typename VoxelType>
void UncompressedBlock<VoxelType>::setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue)
void Chunk<VoxelType>::setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue)
{
setVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue);
}
template <typename VoxelType>
uint32_t UncompressedBlock<VoxelType>::calculateSizeInBytes(void)
uint32_t Chunk<VoxelType>::calculateSizeInBytes(void)
{
// Call through to the static version
return calculateSizeInBytes(m_uSideLength);
}
template <typename VoxelType>
uint32_t UncompressedBlock<VoxelType>::calculateSizeInBytes(uint32_t uSideLength)
uint32_t Chunk<VoxelType>::calculateSizeInBytes(uint32_t uSideLength)
{
// Note: We disregard the size of the other class members as they are likely to be very small compared to the size of the
// allocated voxel data. This also keeps the reported size as a power of two, which makes other memory calculations easier.

View File

@ -76,7 +76,7 @@ namespace PolyVox
m_vecCreatedFiles.clear();
}
virtual void pageIn(const Region& region, UncompressedBlock<VoxelType>* pBlockData)
virtual void pageIn(const Region& region, Chunk<VoxelType>* pBlockData)
{
POLYVOX_ASSERT(pBlockData, "Attempting to page in NULL block");
//POLYVOX_ASSERT(pBlockData->hasUncompressedData() == false, "Block should not have uncompressed data");
@ -120,7 +120,7 @@ namespace PolyVox
}
}
virtual void pageOut(const Region& region, UncompressedBlock<VoxelType>* pBlockData)
virtual void pageOut(const Region& region, Chunk<VoxelType>* pBlockData)
{
POLYVOX_ASSERT(pBlockData, "Attempting to page out NULL block");
//POLYVOX_ASSERT(pBlockData->hasUncompressedData() == false, "Block should not have uncompressed data");

View File

@ -27,7 +27,7 @@ freely, subject to the following restrictions:
#include "PolyVoxCore/BaseVolume.h"
#include "PolyVoxCore/Pager.h"
#include "PolyVoxCore/Region.h"
#include "PolyVoxCore/UncompressedBlock.h"
#include "PolyVoxCore/Chunk.h"
#include "PolyVoxCore/Vector.h"
#include <limits>
@ -285,8 +285,8 @@ namespace PolyVox
private:
typedef std::unordered_map<Vector3DInt32, std::shared_ptr< UncompressedBlock<VoxelType> > > SharedPtrBlockMap;
typedef std::unordered_map<Vector3DInt32, std::weak_ptr< UncompressedBlock<VoxelType> > > WeakPtrBlockMap;
typedef std::unordered_map<Vector3DInt32, std::shared_ptr< Chunk<VoxelType> > > SharedPtrBlockMap;
typedef std::unordered_map<Vector3DInt32, std::weak_ptr< Chunk<VoxelType> > > WeakPtrBlockMap;
void initialise();
@ -298,7 +298,7 @@ namespace PolyVox
VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType<WrapModes::Border>, VoxelType tBorder) const;
VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType<WrapModes::AssumeValid>, VoxelType tBorder) const;
std::shared_ptr< UncompressedBlock<VoxelType> > getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const;
std::shared_ptr< Chunk<VoxelType> > getChunk(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const;
void purgeNullPtrsFromAllBlocks(void) const;
@ -308,7 +308,7 @@ namespace PolyVox
mutable uint32_t m_uTimestamper;
mutable Vector3DInt32 m_v3dLastAccessedBlockPos;
mutable std::shared_ptr< UncompressedBlock<VoxelType> > m_pLastAccessedBlock;
mutable std::shared_ptr< Chunk<VoxelType> > m_pLastAccessedBlock;
uint32_t m_uBlockCountLimit;
// The size of the volume

View File

@ -82,9 +82,9 @@ namespace PolyVox
m_uBlockCountLimit = (std::max)(m_uBlockCountLimit, uMinPracticalNoOfBlocks);
m_uBlockCountLimit = (std::min)(m_uBlockCountLimit, uMaxPracticalNoOfBlocks);
uint32_t uUncompressedBlockSizeInBytes = UncompressedBlock<VoxelType>::calculateSizeInBytes(m_uBlockSideLength);
POLYVOX_LOG_DEBUG("Memory usage limit for volume initially set to " << (m_uBlockCountLimit * uUncompressedBlockSizeInBytes) / (1024 * 1024)
<< "Mb (" << m_uBlockCountLimit << " blocks of " << uUncompressedBlockSizeInBytes / 1024 << "Kb each).");
uint32_t uChunkSizeInBytes = Chunk<VoxelType>::calculateSizeInBytes(m_uBlockSideLength);
POLYVOX_LOG_DEBUG("Memory usage limit for volume initially set to " << (m_uBlockCountLimit * uChunkSizeInBytes) / (1024 * 1024)
<< "Mb (" << m_uBlockCountLimit << " blocks of " << uChunkSizeInBytes / 1024 << "Kb each).");
initialise();
}
@ -223,9 +223,9 @@ namespace PolyVox
const uint16_t yOffset = static_cast<uint16_t>(uYPos - (blockY << m_uBlockSideLengthPower));
const uint16_t zOffset = static_cast<uint16_t>(uZPos - (blockZ << m_uBlockSideLengthPower));
auto pUncompressedBlock = getUncompressedBlock(blockX, blockY, blockZ);
auto pChunk = getChunk(blockX, blockY, blockZ);
return pUncompressedBlock->getVoxel(xOffset, yOffset, zOffset);
return pChunk->getVoxel(xOffset, yOffset, zOffset);
}
else
{
@ -247,7 +247,7 @@ namespace PolyVox
/// Increasing the size of the block cache will increase memory but may improve performance.
/// You may want to set this to a large value (e.g. 1024) when you are first loading your
/// volume data and then set it to a smaller value (e.g.64) for general processing.
/// \param uMaxNumberOfUncompressedBlocks The number of blocks for which uncompressed data can be cached.
/// \param uMaxNumberOfChunks The number of blocks for which uncompressed data can be cached.
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
void PagedVolume<VoxelType>::setMemoryUsageLimit(uint32_t uMemoryUsageInBytes)
@ -255,8 +255,8 @@ namespace PolyVox
POLYVOX_THROW_IF(!m_pPager, invalid_operation, "You cannot limit the memory usage of the volume because it was created without a pager attached.");
// Calculate the number of blocks based on the memory limit and the size of each block.
uint32_t uUncompressedBlockSizeInBytes = UncompressedBlock<VoxelType>::calculateSizeInBytes(m_uBlockSideLength);
m_uBlockCountLimit = uMemoryUsageInBytes / uUncompressedBlockSizeInBytes;
uint32_t uChunkSizeInBytes = Chunk<VoxelType>::calculateSizeInBytes(m_uBlockSideLength);
m_uBlockCountLimit = uMemoryUsageInBytes / uChunkSizeInBytes;
// We need at least a few blocks available to avoid thrashing, and in pratice there will probably be hundreds.
POLYVOX_LOG_WARNING_IF(m_uBlockCountLimit < uMinPracticalNoOfBlocks, "Requested memory usage limit of "
@ -270,8 +270,8 @@ namespace PolyVox
flushAll();
}
POLYVOX_LOG_DEBUG("Memory usage limit for volume now set to " << (m_uBlockCountLimit * uUncompressedBlockSizeInBytes) / (1024 * 1024)
<< "Mb (" << m_uBlockCountLimit << " blocks of " << uUncompressedBlockSizeInBytes / 1024 << "Kb each).");
POLYVOX_LOG_DEBUG("Memory usage limit for volume now set to " << (m_uBlockCountLimit * uChunkSizeInBytes) / (1024 * 1024)
<< "Mb (" << m_uBlockCountLimit << " blocks of " << uChunkSizeInBytes / 1024 << "Kb each).");
}
////////////////////////////////////////////////////////////////////////////////
@ -307,8 +307,8 @@ namespace PolyVox
const uint16_t yOffset = static_cast<uint16_t>(uYPos - (blockY << m_uBlockSideLengthPower));
const uint16_t zOffset = static_cast<uint16_t>(uZPos - (blockZ << m_uBlockSideLengthPower));
auto pUncompressedBlock = getUncompressedBlock(blockX, blockY, blockZ);
pUncompressedBlock->setVoxelAt(xOffset, yOffset, zOffset, tValue);
auto pChunk = getChunk(blockX, blockY, blockZ);
pChunk->setVoxelAt(xOffset, yOffset, zOffset, tValue);
}
////////////////////////////////////////////////////////////////////////////////
@ -344,9 +344,9 @@ namespace PolyVox
const uint16_t yOffset = static_cast<uint16_t>(uYPos - (blockY << m_uBlockSideLengthPower));
const uint16_t zOffset = static_cast<uint16_t>(uZPos - (blockZ << m_uBlockSideLengthPower));
auto pUncompressedBlock = getUncompressedBlock(blockX, blockY, blockZ);
auto pChunk = getChunk(blockX, blockY, blockZ);
pUncompressedBlock->setVoxelAt(xOffset, yOffset, zOffset, tValue);
pChunk->setVoxelAt(xOffset, yOffset, zOffset, tValue);
//Return true to indicate that we modified a voxel.
return true;
@ -397,7 +397,7 @@ namespace PolyVox
{
for(int32_t z = v3dStart.getZ(); z <= v3dEnd.getZ(); z++)
{
getUncompressedBlock(x,y,z);
getChunk(x,y,z);
}
}
}
@ -497,7 +497,7 @@ namespace PolyVox
m_regValidRegionInBlocks.setUpperY(this->m_regValidRegion.getUpperY() >> m_uBlockSideLengthPower);
m_regValidRegionInBlocks.setUpperZ(this->m_regValidRegion.getUpperZ() >> m_uBlockSideLengthPower);
//setMaxNumberOfUncompressedBlocks(m_uBlockCountLimit);
//setMaxNumberOfChunks(m_uBlockCountLimit);
//Clear the previous data
m_pRecentlyUsedBlocks.clear();
@ -509,7 +509,7 @@ namespace PolyVox
}
template <typename VoxelType>
std::shared_ptr< UncompressedBlock<VoxelType> > PagedVolume<VoxelType>::getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const
std::shared_ptr< Chunk<VoxelType> > PagedVolume<VoxelType>::getChunk(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const
{
Vector3DInt32 v3dBlockPos(uBlockX, uBlockY, uBlockZ);
@ -523,45 +523,45 @@ namespace PolyVox
}
// The block was not the same as last time, but we can now hope it is in the set of most recently used blocks.
std::shared_ptr< UncompressedBlock<VoxelType> > pUncompressedBlock = nullptr;
typename SharedPtrBlockMap::iterator itUncompressedBlock = m_pRecentlyUsedBlocks.find(v3dBlockPos);
std::shared_ptr< Chunk<VoxelType> > pChunk = nullptr;
typename SharedPtrBlockMap::iterator itChunk = m_pRecentlyUsedBlocks.find(v3dBlockPos);
// Check whether the block was found.
if ((itUncompressedBlock) != m_pRecentlyUsedBlocks.end())
if ((itChunk) != m_pRecentlyUsedBlocks.end())
{
// The block was found so we can use it.
pUncompressedBlock = itUncompressedBlock->second;
POLYVOX_ASSERT(pUncompressedBlock, "Recent block list shold never contain a null pointer.");
pChunk = itChunk->second;
POLYVOX_ASSERT(pChunk, "Recent block list shold never contain a null pointer.");
}
if (!pUncompressedBlock)
if (!pChunk)
{
// Although it's not in our recently use blocks, there's some (slim) chance that it
// exists in the list of all loaded blocks, because a sampler may be holding on to it.
typename WeakPtrBlockMap::iterator itWeakUncompressedBlock = m_pAllBlocks.find(v3dBlockPos);
if (itWeakUncompressedBlock != m_pAllBlocks.end())
typename WeakPtrBlockMap::iterator itWeakChunk = m_pAllBlocks.find(v3dBlockPos);
if (itWeakChunk != m_pAllBlocks.end())
{
// We've found an entry in the 'all blocks' list, but it can be null. This happens if a sampler was the
// last thing to be keeping it alive and then the sampler let it go. In this case we remove it from the
// list, and it will get added again soon when we page it in and fill it with valid data.
if (itWeakUncompressedBlock->second.expired())
if (itWeakChunk->second.expired())
{
m_pAllBlocks.erase(itWeakUncompressedBlock);
m_pAllBlocks.erase(itWeakChunk);
}
else
{
// The block is valid. We know it's not in the recently used list (we checked earlier) so it should be added.
pUncompressedBlock = std::shared_ptr< UncompressedBlock<VoxelType> >(itWeakUncompressedBlock->second);
m_pRecentlyUsedBlocks.insert(std::make_pair(v3dBlockPos, pUncompressedBlock));
pChunk = std::shared_ptr< Chunk<VoxelType> >(itWeakChunk->second);
m_pRecentlyUsedBlocks.insert(std::make_pair(v3dBlockPos, pChunk));
}
}
}
// If we still haven't found the block then it's time to create a new one and page it in from disk.
if (!pUncompressedBlock)
if (!pChunk)
{
// The block was not found so we will create a new one.
pUncompressedBlock = std::make_shared< UncompressedBlock<VoxelType> >(v3dBlockPos, m_uBlockSideLength, m_pPager);
pChunk = std::make_shared< Chunk<VoxelType> >(v3dBlockPos, m_uBlockSideLength, m_pPager);
// As we are loading a new block we should try to ensure we don't go over our target memory usage.
bool erasedBlock = false;
@ -594,15 +594,15 @@ namespace PolyVox
}
// Add our new block to the maps.
m_pAllBlocks.insert(std::make_pair(v3dBlockPos, pUncompressedBlock));
m_pRecentlyUsedBlocks.insert(std::make_pair(v3dBlockPos, pUncompressedBlock));
m_pAllBlocks.insert(std::make_pair(v3dBlockPos, pChunk));
m_pRecentlyUsedBlocks.insert(std::make_pair(v3dBlockPos, pChunk));
}
pUncompressedBlock->m_uBlockLastAccessed = ++m_uTimestamper;
m_pLastAccessedBlock = pUncompressedBlock;
pChunk->m_uBlockLastAccessed = ++m_uTimestamper;
m_pLastAccessedBlock = pChunk;
m_v3dLastAccessedBlockPos = v3dBlockPos;
return pUncompressedBlock;
return pChunk;
}
////////////////////////////////////////////////////////////////////////////////
@ -616,7 +616,7 @@ namespace PolyVox
// Note: We disregard the size of the other class members as they are likely to be very small compared to the size of the
// allocated voxel data. This also keeps the reported size as a power of two, which makes other memory calculations easier.
return UncompressedBlock<VoxelType>::calculateSizeInBytes(m_uBlockSideLength) * m_pAllBlocks.size();
return Chunk<VoxelType>::calculateSizeInBytes(m_uBlockSideLength) * m_pAllBlocks.size();
}
template <typename VoxelType>
@ -692,8 +692,8 @@ namespace PolyVox
const uint16_t yOffset = static_cast<uint16_t>(uYPos - (blockY << m_uBlockSideLengthPower));
const uint16_t zOffset = static_cast<uint16_t>(uZPos - (blockZ << m_uBlockSideLengthPower));
auto pUncompressedBlock = getUncompressedBlock(blockX, blockY, blockZ);
return pUncompressedBlock->getVoxel(xOffset, yOffset, zOffset);
auto pChunk = getChunk(blockX, blockY, blockZ);
return pChunk->getVoxel(xOffset, yOffset, zOffset);
}
}

View File

@ -119,7 +119,7 @@ namespace PolyVox
uYPosInBlock * this->mVolume->m_uBlockSideLength +
uZPosInBlock * this->mVolume->m_uBlockSideLength * this->mVolume->m_uBlockSideLength;
auto pUncompressedCurrentBlock = this->mVolume->getUncompressedBlock(uXBlock, uYBlock, uZBlock);
auto pUncompressedCurrentBlock = this->mVolume->getChunk(uXBlock, uYBlock, uZBlock);
mCurrentVoxel = pUncompressedCurrentBlock->m_tData + uVoxelIndexInBlock;
}

View File

@ -24,7 +24,7 @@ freely, subject to the following restrictions:
#ifndef __PolyVox_Pager_H__
#define __PolyVox_Pager_H__
#include "PolyVoxCore/UncompressedBlock.h"
#include "PolyVoxCore/Chunk.h"
#include "PolyVoxCore/Impl/TypeDef.h"
#include <memory>
@ -43,8 +43,8 @@ namespace PolyVox
/// Destructor
virtual ~Pager() {};
virtual void pageIn(const Region& region, UncompressedBlock<VoxelType>* pBlockData) = 0;
virtual void pageOut(const Region& region, UncompressedBlock<VoxelType>* pBlockData) = 0;
virtual void pageIn(const Region& region, Chunk<VoxelType>* pBlockData) = 0;
virtual void pageOut(const Region& region, Chunk<VoxelType>* pBlockData) = 0;
};
}