From 0ab7f27f0f5b55873482b4522f4821d133d48565 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 20 Sep 2014 21:27:26 +0200 Subject: [PATCH] More renaming of block to chunk. --- examples/Paging/main.cpp | 15 +-- .../PolyVoxCore/include/PolyVoxCore/Chunk.h | 8 +- .../PolyVoxCore/include/PolyVoxCore/Chunk.inl | 10 +- .../include/PolyVoxCore/FilePager.h | 14 +-- .../include/PolyVoxCore/PagedVolume.h | 32 +++---- .../include/PolyVoxCore/PagedVolume.inl | 96 +++++++++---------- .../PolyVoxCore/PagedVolumeSampler.inl | 24 ++--- .../include/PolyVoxCore/RawVolume.h | 2 +- 8 files changed, 95 insertions(+), 106 deletions(-) diff --git a/examples/Paging/main.cpp b/examples/Paging/main.cpp index b111a6bf..6d140e2f 100644 --- a/examples/Paging/main.cpp +++ b/examples/Paging/main.cpp @@ -92,10 +92,6 @@ public: virtual void pageIn(const PolyVox::Region& region, Chunk* pChunk) { - // 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... - //Chunk block(256); - Perlin perlin(2,2,1,234); for(int x = region.getLowerX(); x <= region.getUpperX(); x++) @@ -129,18 +125,13 @@ public: voxel.setDensity(MaterialDensityPair44::getMinDensity()); } - // Voxel position within a block always start from zero. So if a block represents region (4, 8, 12) to (11, 19, 15) - // then the valid block voxels are from (0, 0, 0) to (7, 11, 3). Hence we subtract the lower corner position of the - // region from the volume space position in order to get the block space position. + // Voxel position within a chunk always start from zero. So if a chunk represents region (4, 8, 12) to (11, 19, 15) + // then the valid chunk voxels are from (0, 0, 0) to (7, 11, 3). Hence we subtract the lower corner position of the + // region from the volume space position in order to get the chunk space position. pChunk->setVoxelAt(x - region.getLowerX(), y - region.getLowerY(), z - region.getLowerZ(), voxel); } } } - - // Now compress the computed data into the provided block. - //RLEBlockCompressor* compressor = new RLEBlockCompressor(); - //compressor->compress(&block, pChunk); - //delete compressor; } virtual void pageOut(const PolyVox::Region& region, Chunk* /*pChunk*/) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Chunk.h b/library/PolyVoxCore/include/PolyVoxCore/Chunk.h index 69df02b3..1eeec066 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Chunk.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Chunk.h @@ -54,15 +54,13 @@ namespace PolyVox /// Private assignment operator to prevent accisdental copying Chunk& operator=(const Chunk& /*rhs*/) {}; - // This is updated by the PagedVolume and used to discard the least recently used blocks. + // This is updated by the PagedVolume and used to discard the least recently used chunks. uint32_t m_uChunkLastAccessed; - // This is so we can tell whether a uncompressed block has to be recompressed and whether - // a compressed block has to be paged back to disk, or whether they can just be discarded. + // This is so we can tell whether a uncompressed chunk has to be recompressed and whether + // a compressed chunk has to be paged back to disk, or whether they can just be discarded. bool m_bDataModified; - // Made this private for consistancy with CompressedBlock. - // Users shouldn't really need this for Chunk anyway. uint32_t calculateSizeInBytes(void); static uint32_t calculateSizeInBytes(uint32_t uSideLength); diff --git a/library/PolyVoxCore/include/PolyVoxCore/Chunk.inl b/library/PolyVoxCore/include/PolyVoxCore/Chunk.inl index 16440c7b..49d25aeb 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Chunk.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Chunk.inl @@ -43,10 +43,10 @@ namespace PolyVox const uint32_t uNoOfVoxels = m_uSideLength * m_uSideLength * m_uSideLength; m_tData = new VoxelType[uNoOfVoxels]; - // Pass the block to the Pager to give it a chance to initialise it with any data + // Pass the chunk to the Pager to give it a chance to initialise it with any data if (m_pPager) { - // From the coordinates of the block we deduce the coordinates of the contained voxels. + // From the coordinates of the chunk we deduce the coordinates of the contained voxels. Vector3DInt32 v3dLower = m_v3dChunkSpacePosition * static_cast(m_uSideLength); Vector3DInt32 v3dUpper = v3dLower + Vector3DInt32(m_uSideLength - 1, m_uSideLength - 1, m_uSideLength - 1); Region reg(v3dLower, v3dUpper); @@ -69,7 +69,7 @@ namespace PolyVox { if (m_pPager && m_bDataModified) { - // From the coordinates of the block we deduce the coordinates of the contained voxels. + // From the coordinates of the chunk we deduce the coordinates of the contained voxels. Vector3DInt32 v3dLower = m_v3dChunkSpacePosition * static_cast(m_uSideLength); Vector3DInt32 v3dUpper = v3dLower + Vector3DInt32(m_uSideLength - 1, m_uSideLength - 1, m_uSideLength - 1); @@ -101,7 +101,7 @@ namespace PolyVox POLYVOX_ASSERT(uXPos < m_uSideLength, "Supplied position is outside of the chunk"); POLYVOX_ASSERT(uYPos < m_uSideLength, "Supplied position is outside of the chunk"); POLYVOX_ASSERT(uZPos < m_uSideLength, "Supplied position is outside of the chunk"); - POLYVOX_ASSERT(m_tData, "No uncompressed data - block must be decompressed before accessing voxels."); + POLYVOX_ASSERT(m_tData, "No uncompressed data - chunk must be decompressed before accessing voxels."); return m_tData [ @@ -125,7 +125,7 @@ namespace PolyVox POLYVOX_ASSERT(uXPos < m_uSideLength, "Supplied position is outside of the chunk"); POLYVOX_ASSERT(uYPos < m_uSideLength, "Supplied position is outside of the chunk"); POLYVOX_ASSERT(uZPos < m_uSideLength, "Supplied position is outside of the chunk"); - POLYVOX_ASSERT(m_tData, "No uncompressed data - block must be decompressed before accessing voxels."); + POLYVOX_ASSERT(m_tData, "No uncompressed data - chunk must be decompressed before accessing voxels."); m_tData [ diff --git a/library/PolyVoxCore/include/PolyVoxCore/FilePager.h b/library/PolyVoxCore/include/PolyVoxCore/FilePager.h index 671023cc..26f20c21 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/FilePager.h +++ b/library/PolyVoxCore/include/PolyVoxCore/FilePager.h @@ -78,8 +78,8 @@ namespace PolyVox virtual void pageIn(const Region& region, Chunk* pChunk) { - POLYVOX_ASSERT(pChunk, "Attempting to page in NULL block"); - //POLYVOX_ASSERT(pChunk->hasUncompressedData() == false, "Block should not have uncompressed data"); + POLYVOX_ASSERT(pChunk, "Attempting to page in NULL chunk"); + POLYVOX_ASSERT(pChunk->getData() == false, "Chunk must have valid data"); std::stringstream ssFilename; ssFilename << m_strFolderName << "/" << m_strRandomPrefix << "-" @@ -109,7 +109,7 @@ namespace PolyVox if(ferror(pFile)) { - POLYVOX_THROW(std::runtime_error, "Error reading in block data, even though a file exists."); + POLYVOX_THROW(std::runtime_error, "Error reading in chunk data, even though a file exists."); } fclose(pFile); @@ -122,8 +122,8 @@ namespace PolyVox virtual void pageOut(const Region& region, Chunk* pChunk) { - POLYVOX_ASSERT(pChunk, "Attempting to page out NULL block"); - //POLYVOX_ASSERT(pChunk->hasUncompressedData() == false, "Block should not have uncompressed data"); + POLYVOX_ASSERT(pChunk, "Attempting to page out NULL chunk"); + POLYVOX_ASSERT(pChunk->getData() == false, "Chunk must have valid data"); POLYVOX_LOG_TRACE("Paging out data for " << region); @@ -140,7 +140,7 @@ namespace PolyVox FILE* pFile = fopen(filename.c_str(), "wb"); if(!pFile) { - POLYVOX_THROW(std::runtime_error, "Unable to open file to write out block data."); + POLYVOX_THROW(std::runtime_error, "Unable to open file to write out chunk data."); } //The file has been created, so add it to the list to delete on shutdown. @@ -150,7 +150,7 @@ namespace PolyVox if(ferror(pFile)) { - POLYVOX_THROW(std::runtime_error, "Error writing out block data."); + POLYVOX_THROW(std::runtime_error, "Error writing out chunk data."); } fclose(pFile); diff --git a/library/PolyVoxCore/include/PolyVoxCore/PagedVolume.h b/library/PolyVoxCore/include/PolyVoxCore/PagedVolume.h index de85418e..bc5ebb3e 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/PagedVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/PagedVolume.h @@ -80,14 +80,14 @@ namespace PolyVox /// 1 byte per voxel will require 1GB of memory if stored in an uncompressed form. Natuarally our PagedVolume class is much more efficient /// than this and it is worth understanding (at least at a high level) the approach which is used. /// - /// Essentially, the PagedVolume class stores its data as a collection of blocks. Each of these block is much smaller than the whole volume, + /// Essentially, the PagedVolume class stores its data as a collection of chunks. Each of these chunk is much smaller than the whole volume, /// for example a typical size might be 32x32x32 voxels (though is is configurable by the user). In this case, a 256x512x1024 volume - /// would contain 8x16x32 = 4096 blocks. The data for each block is stored in a compressed form, which uses only a small amout of - /// memory but it is hard to modify the data. Therefore, before any given voxel can be modified, its corresponding block must be uncompressed. + /// would contain 8x16x32 = 4096 chunks. The data for each chunk is stored in a compressed form, which uses only a small amout of + /// memory but it is hard to modify the data. Therefore, before any given voxel can be modified, its corresponding chunk must be uncompressed. /// - /// The compression and decompression of block is a relatively slow process and so we aim to do this as rarely as possible. In order - /// to achive this, the volume class stores a cache of recently used blocks and their associated uncompressed data. Each time a voxel - /// is touched a timestamp is updated on the corresponding block. When the cache becomes full the block with the oldest timestamp is + /// The compression and decompression of chunk is a relatively slow process and so we aim to do this as rarely as possible. In order + /// to achive this, the volume class stores a cache of recently used chunks and their associated uncompressed data. Each time a voxel + /// is touched a timestamp is updated on the corresponding chunk. When the cache becomes full the chunk with the oldest timestamp is /// recompressed and moved out of the cache. /// /// Achieving high compression rates @@ -136,11 +136,11 @@ namespace PolyVox /// Cache-aware traversal /// --------------------- /// You might be suprised at just how many cache misses can occur when you traverse the volume in a naive manner. Consider a 1024x1024x1024 volume - /// with blocks of size 32x32x32. And imagine you iterate over this volume with a simple three-level for loop which iterates over x, the y, then z. + /// with chunks of size 32x32x32. And imagine you iterate over this volume with a simple three-level for loop which iterates over x, the y, then z. /// If you start at position (0,0,0) then ny the time you reach position (1023,0,0) you have touched 1024 voxels along one edge of the volume and - /// have pulled 32 blocks into the cache. By the time you reach (1023,1023,0) you have hit 1024x1024 voxels and pulled 32x32 blocks into the cache. - /// You are now ready to touch voxel (0,0,1) which is right nect to where you started, but unless your cache is at least 32x32 blocks large then this - /// initial block has already been cleared from the cache. + /// have pulled 32 chunks into the cache. By the time you reach (1023,1023,0) you have hit 1024x1024 voxels and pulled 32x32 chunks into the cache. + /// You are now ready to touch voxel (0,0,1) which is right nect to where you started, but unless your cache is at least 32x32 chunks large then this + /// initial chunk has already been cleared from the cache. /// /// Ensuring you have a large enough cache size can obviously help the above situation, but you might also consider iterating over the voxels in a /// different order. For example, if you replace your three-level loop with a six-level loop then you can first process all the voxels between (0,0,0) @@ -151,7 +151,7 @@ namespace PolyVox /// --------- /// The PagedVolume class does not make any guarentees about thread safety. You should ensure that all accesses are performed from the same thread. /// This is true even if you are only reading data from the volume, as concurrently reading from different threads can invalidate the contents - /// of the block cache (amoung other problems). + /// of the chunk cache (amoung other problems). //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// template class PagedVolume : public BaseVolume @@ -256,7 +256,7 @@ namespace PolyVox /// Gets a voxel at the position given by a 3D vector POLYVOX_DEPRECATED VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const; - /// Sets the number of blocks for which uncompressed data is stored + /// Sets the number of chunks for which uncompressed data is stored void setMemoryUsageLimit(uint32_t uMemoryUsageInBytes); /// Sets the voxel at the position given by x,y,z coordinates void setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, WrapMode eWrapMode = WrapModes::Validate); @@ -302,7 +302,7 @@ namespace PolyVox void purgeNullPtrsFromAllChunks(void) const; - // The block data + // The chunk data mutable WeakPtrChunkMap m_pAllChunks; mutable SharedPtrChunkMap m_pRecentlyUsedChunks; @@ -314,15 +314,15 @@ namespace PolyVox // The size of the volume Region m_regValidRegionInBlocks; - // The size of the blocks + // The size of the chunks uint16_t m_uChunkSideLength; uint8_t m_uChunkSideLengthPower; Pager* m_pPager; - // Enough to make sure a blocks and it's neighbours can be loaded, with a few to spare. + // Enough to make sure a chunks and it's neighbours can be loaded, with a few to spare. static const uint32_t uMinPracticalNoOfBlocks = 32; - // Should preent multi-gigabyte volumes with reasonable block sizes. + // Should preent multi-gigabyte volumes with reasonable chunk sizes. static const uint32_t uMaxPracticalNoOfBlocks = 32768; }; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/PagedVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/PagedVolume.inl index 8db258d7..cd8654c8 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/PagedVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/PagedVolume.inl @@ -34,7 +34,7 @@ namespace PolyVox /// \param dataRequiredHandler The callback function which will be called when PolyVox tries to use data which is not currently in momory. /// \param dataOverflowHandler The callback function which will be called when PolyVox has too much data and needs to remove some from memory. /// \param bPagingEnabled Controls whether or not paging is enabled for this PagedVolume. - /// \param uChunkSideLength The size of the blocks making up the volume. Small blocks will compress/decompress faster, but there will also be more of them meaning voxel access could be slower. + /// \param uChunkSideLength The size of the chunks making up the volume. Small chunks will compress/decompress faster, but there will also be more of them meaning voxel access could be slower. //////////////////////////////////////////////////////////////////////////////// template PagedVolume::PagedVolume @@ -51,15 +51,15 @@ namespace PolyVox if (m_pPager) { // If the user is creating a vast (almost infinite) volume then we can bet they will be - // expecting a high memory usage and will want a fair number of blocks to play around with. + // expecting a high memory usage and will want a fair number of chunks to play around with. if (regValid == Region::MaxRegion) { m_uBlockCountLimit = 1024; } else { - // Otherwise we try to choose a block count to avoid too much thrashing, particularly when iterating - // over the whole volume. This means at least enough blocks to cover one edge of the volume, and ideally + // Otherwise we try to choose a chunk count to avoid too much thrashing, particularly when iterating + // over the whole volume. This means at least enough chunks to cover one edge of the volume, and ideally // enough for a whole face. Which face? Longest edge by shortest edge seems like a reasonable guess. uint32_t longestSide = (std::max)(regValid.getWidthInVoxels(), (std::max)(regValid.getHeightInVoxels(), regValid.getDepthInVoxels())); uint32_t shortestSide = (std::min)(regValid.getWidthInVoxels(), (std::min)(regValid.getHeightInVoxels(), regValid.getDepthInVoxels())); @@ -72,18 +72,18 @@ namespace PolyVox } else { - // If there is no pager provided then we set the block limit to the maximum - // value to ensure the system never attempts to page blocks out of memory. + // If there is no pager provided then we set the chunk limit to the maximum + // value to ensure the system never attempts to page chunks out of memory. m_uBlockCountLimit = (std::numeric_limits::max)(); } - // Make sure the calculated block limit is within practical bounds + // Make sure the calculated chunk limit is within practical bounds m_uBlockCountLimit = (std::max)(m_uBlockCountLimit, uMinPracticalNoOfBlocks); m_uBlockCountLimit = (std::min)(m_uBlockCountLimit, uMaxPracticalNoOfBlocks); uint32_t uChunkSizeInBytes = Chunk::calculateSizeInBytes(m_uChunkSideLength); 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)."); + << "Mb (" << m_uBlockCountLimit << " chunks of " << uChunkSizeInBytes / 1024 << "Kb each)."); initialise(); } @@ -243,34 +243,34 @@ namespace PolyVox } //////////////////////////////////////////////////////////////////////////////// - /// Increasing the size of the block cache will increase memory but may improve performance. + /// Increasing the size of the chunk 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 uMaxNumberOfChunks The number of blocks for which uncompressed data can be cached. + /// \param uMaxNumberOfChunks The number of chunks for which uncompressed data can be cached. //////////////////////////////////////////////////////////////////////////////// template void PagedVolume::setMemoryUsageLimit(uint32_t uMemoryUsageInBytes) { 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. + // Calculate the number of chunks based on the memory limit and the size of each chunk. uint32_t uChunkSizeInBytes = Chunk::calculateSizeInBytes(m_uChunkSideLength); m_uBlockCountLimit = uMemoryUsageInBytes / uChunkSizeInBytes; - // We need at least a few blocks available to avoid thrashing, and in pratice there will probably be hundreds. + // We need at least a few chunks available to avoid thrashing, and in pratice there will probably be hundreds. POLYVOX_LOG_WARNING_IF(m_uBlockCountLimit < uMinPracticalNoOfBlocks, "Requested memory usage limit of " << uMemoryUsageInBytes / (1024 * 1024) << "Mb is too low and cannot be adhered to."); m_uBlockCountLimit = (std::max)(m_uBlockCountLimit, uMinPracticalNoOfBlocks); m_uBlockCountLimit = (std::min)(m_uBlockCountLimit, uMaxPracticalNoOfBlocks); - // If the new limit is less than the number of blocks already loaded then the easiest solution is to flush and start loading again. + // If the new limit is less than the number of chunks already loaded then the easiest solution is to flush and start loading again. if (m_pRecentlyUsedChunks.size() > m_uBlockCountLimit) { flushAll(); } 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)."); + << "Mb (" << m_uBlockCountLimit << " chunks of " << uChunkSizeInBytes / 1024 << "Kb each)."); } //////////////////////////////////////////////////////////////////////////////// @@ -370,7 +370,7 @@ namespace PolyVox template void PagedVolume::prefetch(Region regPrefetch) { - // Convert the start and end positions into block space coordinates + // Convert the start and end positions into chunk space coordinates Vector3DInt32 v3dStart; for(int i = 0; i < 3; i++) { @@ -383,13 +383,13 @@ namespace PolyVox v3dEnd.setElement(i, regPrefetch.getUpperCorner().getElement(i) >> m_uChunkSideLengthPower); } - // Ensure we don't page in more blocks than the volume can hold. + // Ensure we don't page in more chunks than the volume can hold. Region region(v3dStart, v3dEnd); uint32_t uNoOfBlocks = static_cast(region.getWidthInVoxels() * region.getHeightInVoxels() * region.getDepthInVoxels()); - POLYVOX_LOG_WARNING_IF(uNoOfBlocks > m_uBlockCountLimit, "Attempting to prefetch more than the maximum number of blocks."); + POLYVOX_LOG_WARNING_IF(uNoOfBlocks > m_uBlockCountLimit, "Attempting to prefetch more than the maximum number of chunks."); uNoOfBlocks = (std::min)(uNoOfBlocks, m_uBlockCountLimit); - // Loops over the specified positions and touch the corresponding blocks. + // Loops over the specified positions and touch the corresponding chunks. for(int32_t x = v3dStart.getX(); x <= v3dEnd.getX(); x++) { for(int32_t y = v3dStart.getY(); y <= v3dEnd.getY(); y++) @@ -410,16 +410,16 @@ namespace PolyVox { POLYVOX_LOG_WARNING_IF(!m_pPager, "Data discarded by flush operation as no pager is attached."); - // Clear this pointer so it doesn't hang on to any blocks. + // Clear this pointer so it doesn't hang on to any chunks. m_pLastAccessedChunk = nullptr; - // Erase all the most recently used blocks. + // Erase all the most recently used chunks. m_pRecentlyUsedChunks.clear(); - // Remove deleted blocks from the list of all loaded blocks. + // Remove deleted chunks from the list of all loaded chunks. purgeNullPtrsFromAllChunks(); - // If there are still some blocks left then this is a cause for concern. Perhaps samplers are holding on to them? + // If there are still some chunks left then this is a cause for concern. Perhaps samplers are holding on to them? POLYVOX_LOG_WARNING_IF(m_pAllChunks.size() > 0, "Blocks still exist after performing flushAll()! Perhaps you have samplers attached?"); } @@ -431,10 +431,10 @@ namespace PolyVox { POLYVOX_LOG_WARNING_IF(!m_pPager, "Data discarded by flush operation as no pager is attached."); - // Clear this pointer so it doesn't hang on to any blocks. + // Clear this pointer so it doesn't hang on to any chunks. m_pLastAccessedChunk = nullptr; - // Convert the start and end positions into block space coordinates + // Convert the start and end positions into chunk space coordinates Vector3DInt32 v3dStart; for(int i = 0; i < 3; i++) { @@ -447,7 +447,7 @@ namespace PolyVox v3dEnd.setElement(i, regFlush.getUpperCorner().getElement(i) >> m_uChunkSideLengthPower); } - // Loops over the specified positions and delete the corresponding blocks. + // Loops over the specified positions and delete the corresponding chunks. for(int32_t x = v3dStart.getX(); x <= v3dEnd.getX(); x++) { for(int32_t y = v3dStart.getY(); y <= v3dEnd.getY(); y++) @@ -459,7 +459,7 @@ namespace PolyVox } } - // We might now have so null pointers in the 'all blocks' list so clean them up. + // We might now have so null pointers in the 'all chunks' list so clean them up. purgeNullPtrsFromAllChunks(); } @@ -486,7 +486,7 @@ namespace PolyVox m_v3dLastAccessedChunkPos = Vector3DInt32(0,0,0); //There are no invalid positions, but initially the m_pLastAccessedChunk pointer will be null; m_pLastAccessedChunk = 0; - //Compute the block side length + //Compute the chunk side length m_uChunkSideLengthPower = logBase2(m_uChunkSideLength); m_regValidRegionInBlocks.setLowerX(this->m_regValidRegion.getLowerX() >> m_uChunkSideLengthPower); @@ -512,7 +512,7 @@ namespace PolyVox { Vector3DInt32 v3dBlockPos(uBlockX, uBlockY, uBlockZ); - //Check if we have the same block as last time, if so there's no need to even update + //Check if we have the same chunk as last time, if so there's no need to even update //the time stamp. If we updated it everytime then that would be every time we touched //a voxel, which would overflow a uint32_t and require us to use a uint64_t instead. //This check should also provide a significant speed boost as usually it is true. @@ -521,26 +521,26 @@ namespace PolyVox return m_pLastAccessedChunk; } - // The block was not the same as last time, but we can now hope it is in the set of most recently used blocks. + // The chunk was not the same as last time, but we can now hope it is in the set of most recently used chunks. std::shared_ptr< Chunk > pChunk = nullptr; typename SharedPtrChunkMap::iterator itChunk = m_pRecentlyUsedChunks.find(v3dBlockPos); - // Check whether the block was found. + // Check whether the chunk was found. if ((itChunk) != m_pRecentlyUsedChunks.end()) { - // The block was found so we can use it. + // The chunk was found so we can use it. pChunk = itChunk->second; - POLYVOX_ASSERT(pChunk, "Recent block list shold never contain a null pointer."); + POLYVOX_ASSERT(pChunk, "Recent chunk list shold never contain a null pointer."); } 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. + // Although it's not in our recently use chunks, there's some (slim) chance that it + // exists in the list of all loaded chunks, because a sampler may be holding on to it. typename WeakPtrChunkMap::iterator itWeakChunk = m_pAllChunks.find(v3dBlockPos); if (itWeakChunk != m_pAllChunks.end()) { - // We've found an entry in the 'all blocks' list, but it can be null. This happens if a sampler was the + // We've found an entry in the 'all chunks' 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 (itWeakChunk->second.expired()) @@ -549,28 +549,28 @@ namespace PolyVox } else { - // The block is valid. We know it's not in the recently used list (we checked earlier) so it should be added. + // The chunk is valid. We know it's not in the recently used list (we checked earlier) so it should be added. pChunk = std::shared_ptr< Chunk >(itWeakChunk->second); m_pRecentlyUsedChunks.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 we still haven't found the chunk then it's time to create a new one and page it in from disk. if (!pChunk) { - // The block was not found so we will create a new one. + // The chunk was not found so we will create a new one. pChunk = std::make_shared< Chunk >(v3dBlockPos, m_uChunkSideLength, m_pPager); - // As we are loading a new block we should try to ensure we don't go over our target memory usage. + // As we are loading a new chunk we should try to ensure we don't go over our target memory usage. bool erasedBlock = false; - while (m_pRecentlyUsedChunks.size() + 1 > m_uBlockCountLimit) // +1 ready for new block we will add next. + while (m_pRecentlyUsedChunks.size() + 1 > m_uBlockCountLimit) // +1 ready for new chunk we will add next. { // This should never hit, because it should not have been possible for - // the user to limit the number of blocks if they did not provide a pager. - POLYVOX_ASSERT(m_pPager, "A valid pager is required to limit number of blocks"); + // the user to limit the number of chunks if they did not provide a pager. + POLYVOX_ASSERT(m_pPager, "A valid pager is required to limit number of chunks"); - // Find the least recently used block. Hopefully this isn't too slow. + // Find the least recently used chunk. Hopefully this isn't too slow. typename SharedPtrChunkMap::iterator itUnloadBlock = m_pRecentlyUsedChunks.begin(); for (typename SharedPtrChunkMap::iterator i = m_pRecentlyUsedChunks.begin(); i != m_pRecentlyUsedChunks.end(); i++) { @@ -580,19 +580,19 @@ namespace PolyVox } } - // Erase the least recently used block + // Erase the least recently used chunk m_pRecentlyUsedChunks.erase(itUnloadBlock); erasedBlock = true; } - // If we've deleted any blocks from the recently used list then this - // seems like a good place to purge the 'all blocks' list as well. + // If we've deleted any chunks from the recently used list then this + // seems like a good place to purge the 'all chunks' list as well. if (erasedBlock) { purgeNullPtrsFromAllChunks(); } - // Add our new block to the maps. + // Add our new chunk to the maps. m_pAllChunks.insert(std::make_pair(v3dBlockPos, pChunk)); m_pRecentlyUsedChunks.insert(std::make_pair(v3dBlockPos, pChunk)); } @@ -610,7 +610,7 @@ namespace PolyVox template uint32_t PagedVolume::calculateSizeInBytes(void) { - // Purge null blocks so we know that all blocks are used. + // Purge null chunks so we know that all chunks are used. purgeNullPtrsFromAllChunks(); // Note: We disregard the size of the other class members as they are likely to be very small compared to the size of the diff --git a/library/PolyVoxCore/include/PolyVoxCore/PagedVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/PagedVolumeSampler.inl index bd7b8d7f..d325b01d 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/PagedVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/PagedVolumeSampler.inl @@ -159,12 +159,12 @@ namespace PolyVox // Then we update the voxel pointer if((this->isCurrentPositionValid()) && bIsOldPositionValid && ((this->mXPosInVolume) % this->mVolume->m_uChunkSideLength != 0)) { - //No need to compute new block. + //No need to compute new chunk. ++mCurrentVoxel; } else { - //We've hit the block boundary. Just calling setPosition() is the easiest way to resolve this. + //We've hit the chunk boundary. Just calling setPosition() is the easiest way to resolve this. setPosition(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume); } } @@ -181,12 +181,12 @@ namespace PolyVox // Then we update the voxel pointer if((this->isCurrentPositionValid()) && bIsOldPositionValid && ((this->mYPosInVolume) % this->mVolume->m_uChunkSideLength != 0)) { - //No need to compute new block. + //No need to compute new chunk. mCurrentVoxel += this->mVolume->m_uChunkSideLength; } else { - //We've hit the block boundary. Just calling setPosition() is the easiest way to resolve this. + //We've hit the chunk boundary. Just calling setPosition() is the easiest way to resolve this. setPosition(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume); } } @@ -203,12 +203,12 @@ namespace PolyVox // Then we update the voxel pointer if((this->isCurrentPositionValid()) && bIsOldPositionValid && ((this->mZPosInVolume) % this->mVolume->m_uChunkSideLength != 0)) { - //No need to compute new block. + //No need to compute new chunk. mCurrentVoxel += this->mVolume->m_uChunkSideLength * this->mVolume->m_uChunkSideLength; } else { - //We've hit the block boundary. Just calling setPosition() is the easiest way to resolve this. + //We've hit the chunk boundary. Just calling setPosition() is the easiest way to resolve this. setPosition(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume); } } @@ -225,12 +225,12 @@ namespace PolyVox // Then we update the voxel pointer if((this->isCurrentPositionValid()) && bIsOldPositionValid && ((this->mXPosInVolume + 1) % this->mVolume->m_uChunkSideLength != 0)) { - //No need to compute new block. + //No need to compute new chunk. --mCurrentVoxel; } else { - //We've hit the block boundary. Just calling setPosition() is the easiest way to resolve this. + //We've hit the chunk boundary. Just calling setPosition() is the easiest way to resolve this. setPosition(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume); } } @@ -247,12 +247,12 @@ namespace PolyVox // Then we update the voxel pointer if((this->isCurrentPositionValid()) && bIsOldPositionValid && ((this->mYPosInVolume + 1) % this->mVolume->m_uChunkSideLength != 0)) { - //No need to compute new block. + //No need to compute new chunk. mCurrentVoxel -= this->mVolume->m_uChunkSideLength; } else { - //We've hit the block boundary. Just calling setPosition() is the easiest way to resolve this. + //We've hit the chunk boundary. Just calling setPosition() is the easiest way to resolve this. setPosition(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume); } } @@ -269,12 +269,12 @@ namespace PolyVox // Then we update the voxel pointer if((this->isCurrentPositionValid()) && bIsOldPositionValid && ((this->mZPosInVolume + 1) % this->mVolume->m_uChunkSideLength != 0)) { - //No need to compute new block. + //No need to compute new chunk. mCurrentVoxel -= this->mVolume->m_uChunkSideLength * this->mVolume->m_uChunkSideLength; } else { - //We've hit the block boundary. Just calling setPosition() is the easiest way to resolve this. + //We've hit the chunk boundary. Just calling setPosition() is the easiest way to resolve this. setPosition(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume); } } diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h index 71f2be01..7c24e023 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h @@ -162,7 +162,7 @@ namespace PolyVox VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; - //The block data + //The voxel data VoxelType* m_pData; }; }