diff --git a/examples/Paging/main.cpp b/examples/Paging/main.cpp index f10c2331..55e08b75 100644 --- a/examples/Paging/main.cpp +++ b/examples/Paging/main.cpp @@ -37,129 +37,6 @@ freely, subject to the following restrictions: //Use the PolyVox namespace using namespace PolyVox; -void createPerlinVolumeSlow(LargeVolume& volData) -{ - Perlin perlin(2,8,1,234); - - for(int z = 1; z < 256-1; z++) - { - std::cout << z << std::endl; - for(int y = 1; y < 256-1; y++) - { - for(int x = 1; x < 256-1; x++) - { - float perlinVal = perlin.Get3D(x /static_cast(256-1), (y) / static_cast(256-1), z / static_cast(256-1)); - - perlinVal += 1.0f; - perlinVal *= 0.5f; - perlinVal *= MaterialDensityPair44::getMaxDensity(); - - MaterialDensityPair44 voxel; - - voxel.setMaterial(245); - voxel.setDensity(perlinVal); - - /*if(perlinVal < 0.0f) - { - voxel.setMaterial(245); - voxel.setDensity(MaterialDensityPair44::getMaxDensity()); - } - else - { - voxel.setMaterial(0); - voxel.setDensity(MaterialDensityPair44::getMinDensity()); - }*/ - - volData.setVoxelAt(x, y, z, voxel); - } - } - } -} - -/*void createPerlinVolumeFast(LargeVolume& volData) -{ - Perlin perlin(2,8,1,234); - - for(int blockZ = 0; blockZ < volData.m_uDepthInBlocks; blockZ++) - { - std::cout << blockZ << std::endl; - for(int blockY = 0; blockY < volData.m_uHeightInBlocks; blockY++) - { - for(int blockX = 0; blockX < volData.m_uWidthInBlocks; blockX++) - { - for(int offsetz = 0; offsetz < volData.m_uBlockSideLength; offsetz++) - { - for(int offsety = 0; offsety < volData.m_uBlockSideLength; offsety++) - { - for(int offsetx = 0; offsetx < volData.m_uBlockSideLength; offsetx++) - { - int x = blockX * volData.m_uBlockSideLength + offsetx; - int y = blockY * volData.m_uBlockSideLength + offsety; - int z = blockZ * volData.m_uBlockSideLength + offsetz; - - if((x == 0) || (x == volData.getWidth()-1)) continue; - if((y == 0) || (y == volData.getHeight()-1)) continue; - if((z == 0) || (z == volData.getDepth()-1)) continue; - - float perlinVal = perlin.Get3D(x /static_cast(volData.getWidth()-1), (y) / static_cast(volData.getHeight()-1), z / static_cast(volData.getDepth()-1)); - - MaterialDensityPair44 voxel; - if(perlinVal < 0.0f) - { - voxel.setMaterial(245); - voxel.setDensity(MaterialDensityPair44::getMaxDensity()); - } - else - { - voxel.setMaterial(0); - voxel.setDensity(MaterialDensityPair44::getMinDensity()); - } - - volData.setVoxelAt(x, y, z, voxel); - } - } - } - } - } - } -}*/ - -void createPerlinTerrain(LargeVolume& volData) -{ - Perlin perlin(2,2,1,234); - - for(int x = 1; x < 255-1; x++) - { - if(x%(255/100) == 0) { - std::cout << "." << std::flush; - } - for(int y = 1; y < 255-1; y++) - { - float perlinVal = perlin.Get(x / static_cast(255-1), y / static_cast(255-1)); - perlinVal += 1.0f; - perlinVal *= 0.5f; - perlinVal *= 255; - for(int z = 1; z < 255-1; z++) - { - MaterialDensityPair44 voxel; - if(z < perlinVal) - { - voxel.setMaterial(245); - voxel.setDensity(MaterialDensityPair44::getMaxDensity()); - } - else - { - voxel.setMaterial(0); - voxel.setDensity(MaterialDensityPair44::getMinDensity()); - } - - volData.setVoxelAt(x, y, z, voxel); - } - } - } - std::cout << std::endl; -} - void createSphereInVolume(LargeVolume& volData, Vector3DFloat v3dVolCenter, float fRadius) { //This vector hold the position of the center of the volume @@ -251,12 +128,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. pBlockData->setVoxelAt(x - region.getLowerX(), y - region.getLowerY(), z - region.getLowerZ(), voxel); } } } - - pBlockData->destroyUncompressedData(); } virtual void pageOut(const Region& region, Block* pBlockData) diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index ef8dbb40..ab6f4b46 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -586,7 +586,7 @@ namespace PolyVox //This check should also provide a significant speed boost as usually it is true. if((v3dBlockPos == m_v3dLastAccessedBlockPos) && (m_pLastAccessedBlock != 0)) { - POLYVOX_ASSERT(m_pLastAccessedBlock->m_tUncompressedData, "Block has no uncompressed data"); + POLYVOX_ASSERT(m_pLastAccessedBlock->hasUncompressedData(), "Last accessed block has no uncompressed data."); return m_pLastAccessedBlock; } @@ -649,7 +649,6 @@ namespace PolyVox if(block.hasUncompressedData()) { - POLYVOX_ASSERT(m_pLastAccessedBlock->m_tUncompressedData, "Block has no uncompressed data"); return m_pLastAccessedBlock; }