From f32616d5a9f20807b9189bed2879e7e2c619deed Mon Sep 17 00:00:00 2001 From: David Williams Date: Thu, 10 Jul 2008 21:43:24 +0000 Subject: [PATCH] Work on generating surface patches on demand. --- .../include/PolyVoxCore/IndexedSurfacePatch.h | 2 ++ library/include/PolyVoxCore/Region.h | 2 ++ .../include/PolyVoxUtil/VolumeChangeTracker.h | 6 ++++ .../PolyVoxCore/IndexedSurfacePatch.cpp | 1 + library/source/PolyVoxCore/Region.cpp | 10 ++++++ .../PolyVoxUtil/VolumeChangeTracker.cpp | 32 +++++++++++++++++++ 6 files changed, 53 insertions(+) diff --git a/library/include/PolyVoxCore/IndexedSurfacePatch.h b/library/include/PolyVoxCore/IndexedSurfacePatch.h index b40ad4ae..359ae690 100644 --- a/library/include/PolyVoxCore/IndexedSurfacePatch.h +++ b/library/include/PolyVoxCore/IndexedSurfacePatch.h @@ -53,6 +53,8 @@ namespace PolyVox const bool isEmpty(void) const; Vector3DInt32 m_v3dRegionPosition; //FIXME - remove this? + + int32 m_iTimeStamp; private: std::vector m_vecTriangleIndices; diff --git a/library/include/PolyVoxCore/Region.h b/library/include/PolyVoxCore/Region.h index 91150166..2579f16a 100644 --- a/library/include/PolyVoxCore/Region.h +++ b/library/include/PolyVoxCore/Region.h @@ -45,6 +45,8 @@ namespace PolyVox bool containsPoint(const Vector3DInt32& pos, uint8 boundary) const; void cropTo(const Region& other); void shift(const Vector3DInt32& amount); + void shiftLowerCorner(const Vector3DInt32& amount); + void shiftUpperCorner(const Vector3DInt32& amount); private: Vector3DInt32 m_v3dLowerCorner; diff --git a/library/include/PolyVoxUtil/VolumeChangeTracker.h b/library/include/PolyVoxUtil/VolumeChangeTracker.h index 8fdb263e..f21eb4d9 100644 --- a/library/include/PolyVoxUtil/VolumeChangeTracker.h +++ b/library/include/PolyVoxUtil/VolumeChangeTracker.h @@ -41,13 +41,16 @@ namespace PolyVox //Getters void getChangedRegions(std::list& listToFill) const; + int32 getCurrentTime(void) const; Region getEnclosingRegion(void) const; + int32 getLastModifiedTimeForRegion(uint16 uX, uint16 uY, uint16 uZ); uint16 getSideLength(void); BlockVolume* getVolumeData(void) const; uint8 getVoxelAt(const Vector3DUint16& pos); uint8 getVoxelAt(uint16 uX, uint16 uY, uint16 uZ); //Setters + void setAllRegionsModified(void); void setAllRegionsUpToDate(bool newUpToDateValue); void setLockedVoxelAt(uint16 x, uint16 y, uint16 z, uint8 value); void setVolumeData(BlockVolume* volumeDataToSet); @@ -63,6 +66,9 @@ namespace PolyVox Region m_regLastLocked; BlockVolume* volumeData; LinearVolume* volRegionUpToDate; + LinearVolume* volRegionLastModified; + + static int32 m_iCurrentTime; }; } diff --git a/library/source/PolyVoxCore/IndexedSurfacePatch.cpp b/library/source/PolyVoxCore/IndexedSurfacePatch.cpp index d901e616..b6fba1f3 100644 --- a/library/source/PolyVoxCore/IndexedSurfacePatch.cpp +++ b/library/source/PolyVoxCore/IndexedSurfacePatch.cpp @@ -27,6 +27,7 @@ namespace PolyVox { IndexedSurfacePatch::IndexedSurfacePatch() { + m_iTimeStamp = -1; } IndexedSurfacePatch::~IndexedSurfacePatch() diff --git a/library/source/PolyVoxCore/Region.cpp b/library/source/PolyVoxCore/Region.cpp index 202e1e3d..5468d85c 100644 --- a/library/source/PolyVoxCore/Region.cpp +++ b/library/source/PolyVoxCore/Region.cpp @@ -69,4 +69,14 @@ namespace PolyVox m_v3dLowerCorner += amount; m_v3dUpperCorner += amount; } + + void Region::shiftLowerCorner(const Vector3DInt32& amount) + { + m_v3dLowerCorner += amount; + } + + void Region::shiftUpperCorner(const Vector3DInt32& amount) + { + m_v3dUpperCorner += amount; + } } diff --git a/library/source/PolyVoxUtil/VolumeChangeTracker.cpp b/library/source/PolyVoxUtil/VolumeChangeTracker.cpp index a239330b..3f79d473 100644 --- a/library/source/PolyVoxUtil/VolumeChangeTracker.cpp +++ b/library/source/PolyVoxUtil/VolumeChangeTracker.cpp @@ -36,6 +36,7 @@ using namespace std; namespace PolyVox { + int32 VolumeChangeTracker::m_iCurrentTime = 0; ////////////////////////////////////////////////////////////////////////// // VolumeChangeTracker @@ -54,6 +55,7 @@ namespace PolyVox { volumeData = volumeDataToSet; volRegionUpToDate = new LinearVolume(PolyVox::logBase2(POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS)); + volRegionLastModified = new LinearVolume(PolyVox::logBase2(POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS)); } @@ -106,6 +108,26 @@ namespace PolyVox } } + void VolumeChangeTracker::setAllRegionsModified(void) + { + 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) + { + volRegionLastModified->setVoxelAt(blockX, blockY, blockZ, m_iCurrentTime); + ++m_iCurrentTime; + } + } + } + } + + int32 VolumeChangeTracker::getCurrentTime(void) const + { + return m_iCurrentTime; + } + uint16 VolumeChangeTracker::getSideLength(void) { return volumeData->getSideLength(); @@ -116,6 +138,11 @@ namespace PolyVox return volumeData->getEnclosingRegion(); } + int32 VolumeChangeTracker::getLastModifiedTimeForRegion(uint16 uX, uint16 uY, uint16 uZ) + { + return volRegionLastModified->getVoxelAt(uX, uY, uZ); + } + uint8 VolumeChangeTracker::getVoxelAt(const Vector3DUint16& pos) { return getVoxelAt(pos.getX(), pos.getY(), pos.getZ()); @@ -153,6 +180,7 @@ namespace PolyVox (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 { @@ -175,10 +203,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; } void VolumeChangeTracker::setLockedVoxelAt(uint16 x, uint16 y, uint16 z, uint8 value) @@ -224,10 +254,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_bIsLocked = false; } }