From dfe1f03e5b392aa877c1760e63dd0c0171a63131 Mon Sep 17 00:00:00 2001 From: Gargaj Date: Mon, 4 Aug 2014 23:57:08 +0200 Subject: [PATCH 1/8] Split off postprocessing progress --- code/Importer.cpp | 3 ++- include/assimp/ProgressHandler.hpp | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/code/Importer.cpp b/code/Importer.cpp index c6b9daf67..50ce016d5 100644 --- a/code/Importer.cpp +++ b/code/Importer.cpp @@ -768,6 +768,7 @@ const aiScene* Importer::ApplyPostProcessing(unsigned int pFlags) for( unsigned int a = 0; a < pimpl->mPostProcessingSteps.size(); a++) { BaseProcess* process = pimpl->mPostProcessingSteps[a]; + pimpl->mProgressHandler->UpdatePostProcess( a, pimpl->mPostProcessingSteps.size() ); if( process->IsActive( pFlags)) { if (profiler) { @@ -775,7 +776,6 @@ const aiScene* Importer::ApplyPostProcessing(unsigned int pFlags) } process->ExecuteOnScene ( this ); - pimpl->mProgressHandler->Update(); if (profiler) { profiler->EndRegion("postprocess"); @@ -803,6 +803,7 @@ const aiScene* Importer::ApplyPostProcessing(unsigned int pFlags) } #endif // ! DEBUG } + pimpl->mProgressHandler->UpdatePostProcess( pimpl->mPostProcessingSteps.size(), pimpl->mPostProcessingSteps.size() ); // update private scene flags if( pimpl->mScene ) diff --git a/include/assimp/ProgressHandler.hpp b/include/assimp/ProgressHandler.hpp index 31c746c59..7a4cec84f 100644 --- a/include/assimp/ProgressHandler.hpp +++ b/include/assimp/ProgressHandler.hpp @@ -88,6 +88,19 @@ public: virtual bool Update(float percentage = -1.f) = 0; + // ------------------------------------------------------------------- + /** @brief Progress callback for post-processing steps + * @param numberOfSteps The number of total post-processing + * steps + * @param currentStep The index of the current post-processing + * step that will run, or equal to numberOfSteps if all of + * them has finished. This number is always strictly monotone + * increasing, although not necessarily linearly. + * */ + virtual void UpdatePostProcess(int currentStep /*= 0*/, int numberOfSteps /*= 0*/) { + float f = currentStep / (float)numberOfSteps; + Update( f * 0.5f + 0.5f ); + }; }; // !class ProgressHandler // ------------------------------------------------------------------------------------ From dbc553343ce52211aab14227929fe5202cf2b2e9 Mon Sep 17 00:00:00 2001 From: Gargaj Date: Tue, 5 Aug 2014 00:05:18 +0200 Subject: [PATCH 2/8] Granulate file loading too --- code/Importer.cpp | 4 ++-- include/assimp/ProgressHandler.hpp | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/code/Importer.cpp b/code/Importer.cpp index 50ce016d5..49cfeffa6 100644 --- a/code/Importer.cpp +++ b/code/Importer.cpp @@ -642,14 +642,14 @@ const aiScene* Importer::ReadFile( const char* _pFile, unsigned int pFlags) // Dispatch the reading to the worker class for this format DefaultLogger::get()->info("Found a matching importer for this file format"); - pimpl->mProgressHandler->Update(); + pimpl->mProgressHandler->UpdateFileRead( 0, 1 ); if (profiler) { profiler->BeginRegion("import"); } pimpl->mScene = imp->ReadFile( this, pFile, pimpl->mIOHandler); - pimpl->mProgressHandler->Update(); + pimpl->mProgressHandler->UpdateFileRead( 1, 1 ); if (profiler) { profiler->EndRegion("import"); diff --git a/include/assimp/ProgressHandler.hpp b/include/assimp/ProgressHandler.hpp index 7a4cec84f..8aaa99276 100644 --- a/include/assimp/ProgressHandler.hpp +++ b/include/assimp/ProgressHandler.hpp @@ -81,12 +81,25 @@ public: * all needed cleanup tasks prior to returning control to the * caller). If the loading is aborted, #Importer::ReadFile() * returns always NULL. - * - * @note Currently, percentage is always -1.f because there is - * no reliable way to compute it. * */ virtual bool Update(float percentage = -1.f) = 0; + // ------------------------------------------------------------------- + /** @brief Progress callback for file loading steps + * @param numberOfSteps The number of total post-processing + * steps + * @param currentStep The index of the current post-processing + * step that will run, or equal to numberOfSteps if all of + * them has finished. This number is always strictly monotone + * increasing, although not necessarily linearly. + * + * @note This is currently only used at the start and the end + * of the file parsing. + * */ + virtual void UpdateFileRead(int currentStep /*= 0*/, int numberOfSteps /*= 0*/) { + float f = currentStep / (float)numberOfSteps; + Update( f * 0.5f ); + }; // ------------------------------------------------------------------- /** @brief Progress callback for post-processing steps From 6b8cbe5c834ef99ca2f330b97068b7af7d312b01 Mon Sep 17 00:00:00 2001 From: Gargaj Date: Tue, 5 Aug 2014 00:10:23 +0200 Subject: [PATCH 3/8] this isn't needed anymore --- code/Importer.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/code/Importer.cpp b/code/Importer.cpp index 49cfeffa6..0a817476a 100644 --- a/code/Importer.cpp +++ b/code/Importer.cpp @@ -678,7 +678,6 @@ const aiScene* Importer::ReadFile( const char* _pFile, unsigned int pFlags) ScenePreprocessor pre(pimpl->mScene); pre.ProcessScene(); - pimpl->mProgressHandler->Update(); if (profiler) { profiler->EndRegion("preprocess"); } From 8f960f0ed2ea073017e8f8672f3575c8de273a29 Mon Sep 17 00:00:00 2001 From: Gargaj Date: Tue, 5 Aug 2014 19:36:18 +0200 Subject: [PATCH 4/8] avoid division by zero --- include/assimp/ProgressHandler.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/assimp/ProgressHandler.hpp b/include/assimp/ProgressHandler.hpp index 8aaa99276..3ab1e489b 100644 --- a/include/assimp/ProgressHandler.hpp +++ b/include/assimp/ProgressHandler.hpp @@ -97,7 +97,7 @@ public: * of the file parsing. * */ virtual void UpdateFileRead(int currentStep /*= 0*/, int numberOfSteps /*= 0*/) { - float f = currentStep / (float)numberOfSteps; + float f = numberOfSteps ? currentStep / (float)numberOfSteps : 1.0f; Update( f * 0.5f ); }; @@ -111,7 +111,7 @@ public: * increasing, although not necessarily linearly. * */ virtual void UpdatePostProcess(int currentStep /*= 0*/, int numberOfSteps /*= 0*/) { - float f = currentStep / (float)numberOfSteps; + float f = numberOfSteps ? currentStep / (float)numberOfSteps : 1.0f; Update( f * 0.5f + 0.5f ); }; From 523d87bbe7c76ffbdc74ee49b5977a66055bea0d Mon Sep 17 00:00:00 2001 From: Gargaj Date: Thu, 7 Aug 2014 08:22:47 +0200 Subject: [PATCH 5/8] use 0..fileSize as progress metric (easier for loaders) --- code/Importer.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/code/Importer.cpp b/code/Importer.cpp index 0a817476a..9cfb5be46 100644 --- a/code/Importer.cpp +++ b/code/Importer.cpp @@ -640,16 +640,21 @@ const aiScene* Importer::ReadFile( const char* _pFile, unsigned int pFlags) } } + // Get file size for progress handler + IOStream * fileIO = pimpl->mIOHandler->Open( pFile ); + uint32_t fileSize = fileIO->FileSize(); + pimpl->mIOHandler->Close( fileIO ); + // Dispatch the reading to the worker class for this format DefaultLogger::get()->info("Found a matching importer for this file format"); - pimpl->mProgressHandler->UpdateFileRead( 0, 1 ); + pimpl->mProgressHandler->UpdateFileRead( 0, fileSize ); if (profiler) { profiler->BeginRegion("import"); } pimpl->mScene = imp->ReadFile( this, pFile, pimpl->mIOHandler); - pimpl->mProgressHandler->UpdateFileRead( 1, 1 ); + pimpl->mProgressHandler->UpdateFileRead( fileSize, fileSize ); if (profiler) { profiler->EndRegion("import"); From 7925dcadba2778d8e8a4308aacf252ef19ace689 Mon Sep 17 00:00:00 2001 From: Gargaj Date: Thu, 7 Aug 2014 08:25:10 +0200 Subject: [PATCH 6/8] avoid NULL, just in case (loader might just probably crash anyway) --- code/Importer.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/code/Importer.cpp b/code/Importer.cpp index 9cfb5be46..c22b76057 100644 --- a/code/Importer.cpp +++ b/code/Importer.cpp @@ -642,8 +642,11 @@ const aiScene* Importer::ReadFile( const char* _pFile, unsigned int pFlags) // Get file size for progress handler IOStream * fileIO = pimpl->mIOHandler->Open( pFile ); - uint32_t fileSize = fileIO->FileSize(); - pimpl->mIOHandler->Close( fileIO ); + if (fileIO) + { + uint32_t fileSize = fileIO->FileSize(); + pimpl->mIOHandler->Close( fileIO ); + } // Dispatch the reading to the worker class for this format DefaultLogger::get()->info("Found a matching importer for this file format"); From aa5c1a1a23eb69af3e721e5d59fd2c7f08d12ce1 Mon Sep 17 00:00:00 2001 From: Gargaj Date: Thu, 7 Aug 2014 08:26:04 +0200 Subject: [PATCH 7/8] syntax --- code/Importer.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/code/Importer.cpp b/code/Importer.cpp index c22b76057..01f853a05 100644 --- a/code/Importer.cpp +++ b/code/Importer.cpp @@ -642,9 +642,10 @@ const aiScene* Importer::ReadFile( const char* _pFile, unsigned int pFlags) // Get file size for progress handler IOStream * fileIO = pimpl->mIOHandler->Open( pFile ); + uint32_t fileSize = 0; if (fileIO) { - uint32_t fileSize = fileIO->FileSize(); + fileSize = fileIO->FileSize(); pimpl->mIOHandler->Close( fileIO ); } From df4b17d145530403b507f528de28ff59b2df3bf0 Mon Sep 17 00:00:00 2001 From: Gargaj Date: Thu, 7 Aug 2014 08:26:34 +0200 Subject: [PATCH 8/8] code style --- code/Importer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/Importer.cpp b/code/Importer.cpp index 01f853a05..a9173cddc 100644 --- a/code/Importer.cpp +++ b/code/Importer.cpp @@ -642,7 +642,7 @@ const aiScene* Importer::ReadFile( const char* _pFile, unsigned int pFlags) // Get file size for progress handler IOStream * fileIO = pimpl->mIOHandler->Open( pFile ); - uint32_t fileSize = 0; + uint32_t fileSize = 0; if (fileIO) { fileSize = fileIO->FileSize();