From 2459b9988635a2e48ef8ff0fd34593b13a257358 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sun, 13 Jul 2008 09:14:20 +0000 Subject: [PATCH] Work on level of detail including refactoring. --- TODO.txt | 1 + .../include/PolyVoxUtil/VolumeChangeTracker.h | 3 - library/source/PolyVoxCore/Region.cpp | 2 +- .../PolyVoxUtil/VolumeChangeTracker.cpp | 61 ++----------------- 4 files changed, 7 insertions(+), 60 deletions(-) diff --git a/TODO.txt b/TODO.txt index 65efdcec..72c80888 100644 --- a/TODO.txt +++ b/TODO.txt @@ -19,6 +19,7 @@ Use of LinearVolume instead of arrays. Add API docs Add manual Finish OpenGL sample. +VolumeChangeTracker can be more conservitive regarding when neighbouring regions are modified. For Version 2.0 =============== diff --git a/library/include/PolyVoxUtil/VolumeChangeTracker.h b/library/include/PolyVoxUtil/VolumeChangeTracker.h index f21eb4d9..0a7afbc7 100644 --- a/library/include/PolyVoxUtil/VolumeChangeTracker.h +++ b/library/include/PolyVoxUtil/VolumeChangeTracker.h @@ -40,7 +40,6 @@ namespace PolyVox ~VolumeChangeTracker(); //Getters - void getChangedRegions(std::list& listToFill) const; int32 getCurrentTime(void) const; Region getEnclosingRegion(void) const; int32 getLastModifiedTimeForRegion(uint16 uX, uint16 uY, uint16 uZ); @@ -51,7 +50,6 @@ namespace PolyVox //Setters void setAllRegionsModified(void); - void setAllRegionsUpToDate(bool newUpToDateValue); void setLockedVoxelAt(uint16 x, uint16 y, uint16 z, uint8 value); void setVolumeData(BlockVolume* volumeDataToSet); void setVoxelAt(uint16 x, uint16 y, uint16 z, uint8 value); @@ -65,7 +63,6 @@ namespace PolyVox bool m_bIsLocked; Region m_regLastLocked; BlockVolume* volumeData; - LinearVolume* volRegionUpToDate; LinearVolume* volRegionLastModified; static int32 m_iCurrentTime; diff --git a/library/source/PolyVoxCore/Region.cpp b/library/source/PolyVoxCore/Region.cpp index 5468d85c..c4f12238 100644 --- a/library/source/PolyVoxCore/Region.cpp +++ b/library/source/PolyVoxCore/Region.cpp @@ -37,7 +37,7 @@ namespace PolyVox bool Region::containsPoint(const Vector3DFloat& pos, float boundary) const { return (pos.getX() <= m_v3dUpperCorner.getX() - boundary) - && (pos.getY() <= m_v3dUpperCorner.getY() - boundary) + && (pos.getY() <= m_v3dUpperCorner.getY() - boundary) && (pos.getZ() <= m_v3dUpperCorner.getZ() - boundary) && (pos.getX() >= m_v3dLowerCorner.getX() + boundary) && (pos.getY() >= m_v3dLowerCorner.getY() + boundary) diff --git a/library/source/PolyVoxUtil/VolumeChangeTracker.cpp b/library/source/PolyVoxUtil/VolumeChangeTracker.cpp index 3f79d473..9b622773 100644 --- a/library/source/PolyVoxUtil/VolumeChangeTracker.cpp +++ b/library/source/PolyVoxUtil/VolumeChangeTracker.cpp @@ -54,60 +54,9 @@ namespace PolyVox void VolumeChangeTracker::setVolumeData(BlockVolume* volumeDataToSet) { volumeData = volumeDataToSet; - volRegionUpToDate = new LinearVolume(PolyVox::logBase2(POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS)); volRegionLastModified = new LinearVolume(PolyVox::logBase2(POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS)); } - - //Return changed regions - cropped to volume - void VolumeChangeTracker::getChangedRegions(std::list& listToFill) const - { - //Clear the list - listToFill.clear(); - - //Regenerate meshes. - for(uint16 regionZ = 0; regionZ < POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS; ++regionZ) - //for(uint16 regionZ = 0; regionZ < 1; ++regionZ) - { - for(uint16 regionY = 0; regionY < POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS; ++regionY) - //for(uint16 regionY = 0; regionY < 2; ++regionY) - { - for(uint16 regionX = 0; regionX < POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS; ++regionX) - //for(uint16 regionX = 0; regionX < 2; ++regionX) - { - if(volRegionUpToDate->getVoxelAt(regionX, regionY, regionZ) == false) - { - const uint16 firstX = regionX * POLYVOX_REGION_SIDE_LENGTH; - const uint16 firstY = regionY * POLYVOX_REGION_SIDE_LENGTH; - const uint16 firstZ = regionZ * POLYVOX_REGION_SIDE_LENGTH; - const uint16 lastX = firstX + POLYVOX_REGION_SIDE_LENGTH; - const uint16 lastY = firstY + POLYVOX_REGION_SIDE_LENGTH; - const uint16 lastZ = firstZ + POLYVOX_REGION_SIDE_LENGTH; - - Region region(Vector3DInt32(firstX, firstY, firstZ), Vector3DInt32(lastX, lastY, lastZ)); - region.cropTo(volumeData->getEnclosingRegion()); - - listToFill.push_back(region); - } - } - } - } - } - - void VolumeChangeTracker::setAllRegionsUpToDate(bool newUpToDateValue) - { - for(uint16 blockZ = 0; blockZ < POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS; ++blockZ) - { - for(uint16 blockY = 0; blockY < POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS; ++blockY) - { - for(uint16 blockX = 0; blockX < POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS; ++blockX) - { - volRegionUpToDate->setVoxelAt(blockX, blockY, blockZ, newUpToDateValue); - } - } - } - } - void VolumeChangeTracker::setAllRegionsModified(void) { for(uint16 blockZ = 0; blockZ < POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS; ++blockZ) @@ -164,8 +113,10 @@ namespace PolyVox return volumeData; } + //NOTE - Document the fact that the time stamp is incremented at the start, not the end. void VolumeChangeTracker::setVoxelAt(uint16 x, uint16 y, uint16 z, uint8 value) { + ++m_iCurrentTime; //FIXME - rather than creating a iterator each time we should have one stored BlockVolumeIterator iterVol(*volumeData); iterVol.setPosition(x,y,z); @@ -179,7 +130,6 @@ namespace PolyVox (z % POLYVOX_REGION_SIDE_LENGTH != 0) && (z % POLYVOX_REGION_SIDE_LENGTH != POLYVOX_REGION_SIDE_LENGTH-1)) { - volRegionUpToDate->setVoxelAt(x >> POLYVOX_REGION_SIDE_LENGTH_POWER, y >> POLYVOX_REGION_SIDE_LENGTH_POWER, z >> POLYVOX_REGION_SIDE_LENGTH_POWER, false); volRegionLastModified->setVoxelAt(x >> POLYVOX_REGION_SIDE_LENGTH_POWER, y >> POLYVOX_REGION_SIDE_LENGTH_POWER, z >> POLYVOX_REGION_SIDE_LENGTH_POWER, m_iCurrentTime); } else //Mark surrounding regions as well @@ -202,13 +152,12 @@ namespace PolyVox { for(uint16 xCt = minRegionX; xCt <= maxRegionX; xCt++) { - volRegionUpToDate->setVoxelAt(xCt,yCt,zCt,false); volRegionLastModified->setVoxelAt(xCt,yCt,zCt,m_iCurrentTime); } } } } - ++m_iCurrentTime; + //++m_iCurrentTime; } void VolumeChangeTracker::setLockedVoxelAt(uint16 x, uint16 y, uint16 z, uint8 value) @@ -234,6 +183,7 @@ namespace PolyVox void VolumeChangeTracker::unlockRegion(void) { + ++m_iCurrentTime; if(!m_bIsLocked) { throw std::logic_error("No region is locked. You must lock a region before you can unlock it."); @@ -253,13 +203,12 @@ namespace PolyVox { for(uint16 xCt = firstRegionX; xCt <= lastRegionX; xCt++) { - volRegionUpToDate->setVoxelAt(xCt,yCt,zCt,false); volRegionLastModified->setVoxelAt(xCt,yCt,zCt,m_iCurrentTime); } } } - ++m_iCurrentTime; + //++m_iCurrentTime; m_bIsLocked = false; } }