diff --git a/library/PolyVoxUtil/include/Serialization.h b/library/PolyVoxUtil/include/Serialization.h index dd9d6858..847cc22d 100644 --- a/library/PolyVoxUtil/include/Serialization.h +++ b/library/PolyVoxUtil/include/Serialization.h @@ -33,7 +33,7 @@ namespace PolyVox POLYVOXUTIL_API Volume* loadVolumeRaw(std::istream& stream); POLYVOXUTIL_API void saveVolumeRaw(std::ostream& stream, Volume& volume); - POLYVOXUTIL_API Volume* loadVolumeRle(std::istream& stream); + POLYVOXUTIL_API Volume* loadVolumeRle(std::istream& stream, void (*pCallback)(float) = 0); POLYVOXUTIL_API void saveVolumeRle(std::ostream& stream, Volume& volume); } diff --git a/library/PolyVoxUtil/source/Serialization.cpp b/library/PolyVoxUtil/source/Serialization.cpp index 651c4bdb..b67416e7 100644 --- a/library/PolyVoxUtil/source/Serialization.cpp +++ b/library/PolyVoxUtil/source/Serialization.cpp @@ -78,7 +78,7 @@ namespace PolyVox //Note: we don't do much error handling in here - exceptions will simply be propergated up to the caller. //FIXME - think about pointer ownership issues. Or could return volume by value if the copy constructor is shallow - Volume* loadVolumeRle(istream& stream) + Volume* loadVolumeRle(istream& stream, void (*pCallback)(float)) { //Read volume dimensions uint8_t volumeWidthPower = 0; @@ -103,6 +103,13 @@ namespace PolyVox stream.read(reinterpret_cast(&runLength), sizeof(runLength)); for(uint16_t z = 0; z < volumeDepth; ++z) { + //Update progress once per slice. + if(pCallback) + { + float fProgress = static_cast(z) / static_cast(volumeDepth); + pCallback(fProgress); + } + for(uint16_t y = 0; y < volumeHeight; ++y) { for(uint16_t x = 0; x < volumeWidth; ++x) @@ -121,9 +128,14 @@ namespace PolyVox runLength--; } } - } + } } + //Finished + if(pCallback) + { + pCallback(1.0f); + } return volume; }