Moved contents of initialize() into constructor.
This commit is contained in:
parent
c804190d84
commit
2c0d9cb9e7
@ -282,11 +282,7 @@ namespace PolyVox
|
|||||||
/// Assignment operator
|
/// Assignment operator
|
||||||
PagedVolume& operator=(const PagedVolume& rhs);
|
PagedVolume& operator=(const PagedVolume& rhs);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// FIXME - We can probably ove this into the constructor
|
|
||||||
void initialise();
|
|
||||||
|
|
||||||
std::shared_ptr<Chunk> getChunk(int32_t uChunkX, int32_t uChunkY, int32_t uChunkZ) const;
|
std::shared_ptr<Chunk> getChunk(int32_t uChunkX, int32_t uChunkY, int32_t uChunkZ) const;
|
||||||
|
|
||||||
void purgeNullPtrsFromAllChunks(void) const;
|
void purgeNullPtrsFromAllChunks(void) const;
|
||||||
@ -310,10 +306,10 @@ namespace PolyVox
|
|||||||
typedef std::unordered_map<Vector3DInt32, std::shared_ptr< Chunk > > SharedPtrChunkMap;
|
typedef std::unordered_map<Vector3DInt32, std::shared_ptr< Chunk > > SharedPtrChunkMap;
|
||||||
mutable SharedPtrChunkMap m_pRecentlyUsedChunks;
|
mutable SharedPtrChunkMap m_pRecentlyUsedChunks;
|
||||||
|
|
||||||
mutable uint32_t m_uTimestamper;
|
mutable uint32_t m_uTimestamper = 0;
|
||||||
mutable Vector3DInt32 m_v3dLastAccessedChunkPos;
|
mutable Vector3DInt32 m_v3dLastAccessedChunkPos = Vector3DInt32(0, 0, 0); //There are no invalid positions, but initially the m_pLastAccessedChunk pointer will be null
|
||||||
mutable std::shared_ptr<Chunk> m_pLastAccessedChunk;
|
mutable std::shared_ptr<Chunk> m_pLastAccessedChunk = nullptr;
|
||||||
uint32_t m_uChunkCountLimit;
|
uint32_t m_uChunkCountLimit = 0;
|
||||||
|
|
||||||
// The size of the volume
|
// The size of the volume
|
||||||
//Region m_regValidRegionInChunks;
|
//Region m_regValidRegionInChunks;
|
||||||
|
@ -42,7 +42,12 @@ namespace PolyVox
|
|||||||
{
|
{
|
||||||
// Validation of parameters
|
// Validation of parameters
|
||||||
POLYVOX_THROW_IF(uTargetMemoryUsageInBytes < 1 * 1024 * 1024, std::invalid_argument, "Target memory usage is too small to be practical");
|
POLYVOX_THROW_IF(uTargetMemoryUsageInBytes < 1 * 1024 * 1024, std::invalid_argument, "Target memory usage is too small to be practical");
|
||||||
POLYVOX_THROW_IF(uChunkSideLength > 256, std::invalid_argument, "Chunk size is too large to be practical");
|
POLYVOX_THROW_IF(m_uChunkSideLength == 0, std::invalid_argument, "Chunk side length cannot be zero.");
|
||||||
|
POLYVOX_THROW_IF(m_uChunkSideLength > 256, std::invalid_argument, "Chunk size is too large to be practical.");
|
||||||
|
POLYVOX_THROW_IF(!isPowerOf2(m_uChunkSideLength), std::invalid_argument, "Chunk side length must be a power of two.");
|
||||||
|
|
||||||
|
// Used to perform multiplications and divisions by bit shifting.
|
||||||
|
m_uChunkSideLengthPower = logBase2(m_uChunkSideLength);
|
||||||
|
|
||||||
// Calculate the number of chunks based on the memory limit and the size of each chunk.
|
// Calculate the number of chunks based on the memory limit and the size of each chunk.
|
||||||
uint32_t uChunkSizeInBytes = PagedVolume<VoxelType>::Chunk::calculateSizeInBytes(m_uChunkSideLength);
|
uint32_t uChunkSizeInBytes = PagedVolume<VoxelType>::Chunk::calculateSizeInBytes(m_uChunkSideLength);
|
||||||
@ -59,8 +64,6 @@ namespace PolyVox
|
|||||||
// Inform the user about the chosen memory configuration.
|
// Inform the user about the chosen memory configuration.
|
||||||
POLYVOX_LOG_DEBUG("Memory usage limit for volume now set to " << (m_uChunkCountLimit * uChunkSizeInBytes) / (1024 * 1024)
|
POLYVOX_LOG_DEBUG("Memory usage limit for volume now set to " << (m_uChunkCountLimit * uChunkSizeInBytes) / (1024 * 1024)
|
||||||
<< "Mb (" << m_uChunkCountLimit << " chunks of " << uChunkSizeInBytes / 1024 << "Kb each).");
|
<< "Mb (" << m_uChunkCountLimit << " chunks of " << uChunkSizeInBytes / 1024 << "Kb each).");
|
||||||
|
|
||||||
initialise();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -73,7 +76,7 @@ namespace PolyVox
|
|||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
PagedVolume<VoxelType>::PagedVolume(const PagedVolume<VoxelType>& /*rhs*/)
|
PagedVolume<VoxelType>::PagedVolume(const PagedVolume<VoxelType>& /*rhs*/)
|
||||||
{
|
{
|
||||||
POLYVOX_THROW(not_implemented, "Volume copy constructor not implemented for performance reasons.");
|
POLYVOX_THROW(not_implemented, "Volume copy constructor not implemented to prevent accidental copying.");
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -265,43 +268,6 @@ namespace PolyVox
|
|||||||
purgeNullPtrsFromAllChunks();
|
purgeNullPtrsFromAllChunks();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// This function should probably be made internal...
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
template <typename VoxelType>
|
|
||||||
void PagedVolume<VoxelType>::initialise()
|
|
||||||
{
|
|
||||||
//Validate parameters
|
|
||||||
if(m_uChunkSideLength == 0)
|
|
||||||
{
|
|
||||||
POLYVOX_THROW(std::invalid_argument, "Chunk side length cannot be zero.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!isPowerOf2(m_uChunkSideLength))
|
|
||||||
{
|
|
||||||
POLYVOX_THROW(std::invalid_argument, "Chunk side length must be a power of two.");
|
|
||||||
}
|
|
||||||
|
|
||||||
m_uTimestamper = 0;
|
|
||||||
m_v3dLastAccessedChunkPos = Vector3DInt32(0,0,0); //There are no invalid positions, but initially the m_pLastAccessedChunk pointer will be null;
|
|
||||||
m_pLastAccessedChunk = nullptr;
|
|
||||||
|
|
||||||
//Compute the chunk side length
|
|
||||||
m_uChunkSideLengthPower = logBase2(m_uChunkSideLength);
|
|
||||||
|
|
||||||
/*m_regValidRegionInChunks.setLowerX(this->m_regValidRegion.getLowerX() >> m_uChunkSideLengthPower);
|
|
||||||
m_regValidRegionInChunks.setLowerY(this->m_regValidRegion.getLowerY() >> m_uChunkSideLengthPower);
|
|
||||||
m_regValidRegionInChunks.setLowerZ(this->m_regValidRegion.getLowerZ() >> m_uChunkSideLengthPower);
|
|
||||||
m_regValidRegionInChunks.setUpperX(this->m_regValidRegion.getUpperX() >> m_uChunkSideLengthPower);
|
|
||||||
m_regValidRegionInChunks.setUpperY(this->m_regValidRegion.getUpperY() >> m_uChunkSideLengthPower);
|
|
||||||
m_regValidRegionInChunks.setUpperZ(this->m_regValidRegion.getUpperZ() >> m_uChunkSideLengthPower);*/
|
|
||||||
|
|
||||||
//setMaxNumberOfChunks(m_uChunkCountLimit);
|
|
||||||
|
|
||||||
//Clear the previous data
|
|
||||||
m_pRecentlyUsedChunks.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
std::shared_ptr<typename PagedVolume<VoxelType>::Chunk> PagedVolume<VoxelType>::getChunk(int32_t uChunkX, int32_t uChunkY, int32_t uChunkZ) const
|
std::shared_ptr<typename PagedVolume<VoxelType>::Chunk> PagedVolume<VoxelType>::getChunk(int32_t uChunkX, int32_t uChunkY, int32_t uChunkZ) const
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user