Tidying up Block and FilePager.
This commit is contained in:
@ -54,7 +54,7 @@ namespace PolyVox
|
||||
virtual void pageIn(const Region& region, Block<VoxelType>* pBlockData)
|
||||
{
|
||||
POLYVOX_ASSERT(pBlockData, "Attempting to page in NULL block");
|
||||
POLYVOX_ASSERT(pBlockData->m_bIsCompressed, "Attempting to page in uncompressed block");
|
||||
POLYVOX_ASSERT(pBlockData->isCompressed(), "Attempting to page in uncompressed block");
|
||||
|
||||
std::stringstream ss;
|
||||
ss << region.getLowerX() << "_" << region.getLowerY() << "_" << region.getLowerZ() << "_"
|
||||
@ -71,13 +71,13 @@ namespace PolyVox
|
||||
logTrace() << "Paging in data for " << region;
|
||||
|
||||
fseek(pFile, 0L, SEEK_END);
|
||||
pBlockData->m_uCompressedDataLength = ftell(pFile);
|
||||
size_t fileSizeInBytes = ftell(pFile);
|
||||
fseek(pFile, 0L, SEEK_SET);
|
||||
|
||||
delete[] pBlockData->m_pCompressedData;
|
||||
pBlockData->m_pCompressedData = new uint8_t[pBlockData->m_uCompressedDataLength];
|
||||
|
||||
fread(pBlockData->m_pCompressedData, sizeof(uint8_t), pBlockData->m_uCompressedDataLength, pFile);
|
||||
|
||||
uint8_t* buffer = new uint8_t[fileSizeInBytes];
|
||||
fread(buffer, sizeof(uint8_t), fileSizeInBytes, pFile);
|
||||
pBlockData->setCompressedData(buffer, fileSizeInBytes);
|
||||
delete[] buffer;
|
||||
|
||||
if(ferror(pFile))
|
||||
{
|
||||
@ -95,7 +95,7 @@ namespace PolyVox
|
||||
virtual void pageOut(const Region& region, Block<VoxelType>* pBlockData)
|
||||
{
|
||||
POLYVOX_ASSERT(pBlockData, "Attempting to page out NULL block");
|
||||
POLYVOX_ASSERT(pBlockData->m_bIsCompressed, "Attempting to page out uncompressed block");
|
||||
POLYVOX_ASSERT(pBlockData->isCompressed(), "Attempting to page out uncompressed block");
|
||||
|
||||
logTrace() << "Paging out data for " << region;
|
||||
|
||||
@ -114,7 +114,7 @@ namespace PolyVox
|
||||
POLYVOX_THROW(std::runtime_error, "Unable to open file to write out block data.");
|
||||
}
|
||||
|
||||
fwrite(pBlockData->m_pCompressedData, sizeof(uint8_t), pBlockData->m_uCompressedDataLength, pFile);
|
||||
fwrite(pBlockData->getCompressedData(), sizeof(uint8_t), pBlockData->getCompressedDataLength(), pFile);
|
||||
|
||||
if(ferror(pFile))
|
||||
{
|
||||
|
@ -51,12 +51,14 @@ namespace PolyVox
|
||||
public:
|
||||
Block(uint16_t uSideLength = 0);
|
||||
|
||||
const uint8_t* getCompressedData(void) const;
|
||||
const uint8_t* const getCompressedData(void) const;
|
||||
const uint32_t getCompressedDataLength(void) const;
|
||||
uint16_t getSideLength(void) const;
|
||||
VoxelType getVoxel(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const;
|
||||
VoxelType getVoxel(const Vector3DUint16& v3dPos) const;
|
||||
|
||||
bool isCompressed(void);
|
||||
|
||||
void setCompressedData(const uint8_t* const data, uint32_t dataLength);
|
||||
void setVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos, VoxelType tValue);
|
||||
void setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue);
|
||||
|
@ -52,7 +52,7 @@ namespace PolyVox
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
const uint8_t* Block<VoxelType>::getCompressedData(void) const
|
||||
const uint8_t* const Block<VoxelType>::getCompressedData(void) const
|
||||
{
|
||||
POLYVOX_ASSERT(m_bIsCompressed, "You cannot call getCompressedData() when the block is not compressed");
|
||||
POLYVOX_ASSERT(m_pCompressedData, "Compressed data is NULL");
|
||||
@ -99,6 +99,12 @@ namespace PolyVox
|
||||
return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ());
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
bool Block<VoxelType>::isCompressed(void)
|
||||
{
|
||||
return m_bIsCompressed;
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
void Block<VoxelType>::setCompressedData(const uint8_t* const data, uint32_t dataLength)
|
||||
{
|
||||
|
Reference in New Issue
Block a user