diff --git a/lib/app/include/app/core/renderer/renderer_system.hpp b/lib/app/include/app/core/renderer/renderer_system.hpp index 3cb680e8e..0d4b7d5f6 100644 --- a/lib/app/include/app/core/renderer/renderer_system.hpp +++ b/lib/app/include/app/core/renderer/renderer_system.hpp @@ -13,6 +13,8 @@ namespace VTX::App::Core::Renderer inline static FilePath SHADER_DIR = Util::Filesystem::getExecutableDir(); RendererSystem() : VTX::Renderer::Facade( 1, 1, SHADER_DIR ) {} + + inline static void init( const FilePath & p_shaderPath ) { SHADER_DIR = p_shaderPath; } }; } // namespace VTX::App::Core::Renderer diff --git a/lib/app/src/app/core/action/action_system.cpp b/lib/app/src/app/core/action/action_system.cpp index 1262075fc..936441b20 100644 --- a/lib/app/src/app/core/action/action_system.cpp +++ b/lib/app/src/app/core/action/action_system.cpp @@ -1,7 +1,9 @@ #include "app/core/action/action_system.hpp" #include #include +#include #include +#include namespace VTX::App::Core::Action { @@ -12,20 +14,12 @@ namespace VTX::App::Core::Action VTX_DEBUG( "ActionSystem::execute( {} )", typeid( *p_actionPtr ).name() ); try { - p_actionPtr->execute(); - // VTX_EVENT( ACTION_EXECUTED_EVENT, *actionPtr ); - // // Signal catched and managed by ScenePathData component - // switch ( p_action->getTag() ) - //{ - // case ACTION_TAG::MODIFY_SCENE: - // if ( isActionUndonable ) - // App::Old::APP::getScenePathData().incrementSceneModifications(); - // else // if the action is not undoable, it make a permanent modification on scene - // App::Old::APP::getScenePathData().forceSceneModifications(); - // break; - // case ACTION_TAG::NONE: - // default: break; - //} + auto duration = Util::CHRONO_CPU( [ &p_actionPtr ]() { p_actionPtr->execute(); } ); + VTX_DEBUG( + "ActionSystem::execute( {} ) - done ({})", + typeid( *p_actionPtr ).name(), + Util::String::durationToStr( duration ) + ); } catch ( const std::exception & p_e ) { @@ -33,25 +27,18 @@ namespace VTX::App::Core::Action return; } } + void ActionSystem::execute( std::unique_ptr & p_actionPtr ) { VTX_DEBUG( "ActionSystem::execute( {} )", typeid( *p_actionPtr ).name() ); try { - p_actionPtr->execute(); - // VTX_EVENT( ACTION_EXECUTED_EVENT, *actionPtr ); - // // Signal catched and managed by ScenePathData component - // switch ( p_action->getTag() ) - //{ - // case ACTION_TAG::MODIFY_SCENE: - // if ( isActionUndonable ) - // App::Old::APP::getScenePathData().incrementSceneModifications(); - // else // if the action is not undoable, it make a permanent modification on scene - // App::Old::APP::getScenePathData().forceSceneModifications(); - // break; - // case ACTION_TAG::NONE: - // default: break; - //} + auto duration = Util::CHRONO_CPU( [ &p_actionPtr ]() { p_actionPtr->execute(); } ); + VTX_DEBUG( + "ActionSystem::execute( {} ) - done ({})", + typeid( *p_actionPtr ).name(), + Util::String::durationToStr( duration ) + ); } catch ( const std::exception & p_e ) { diff --git a/lib/app/src/app/serialization/io/reader/molecule_loader.cpp b/lib/app/src/app/serialization/io/reader/molecule_loader.cpp index c316b04d5..4e3c9fad1 100644 --- a/lib/app/src/app/serialization/io/reader/molecule_loader.cpp +++ b/lib/app/src/app/serialization/io/reader/molecule_loader.cpp @@ -16,6 +16,7 @@ #include #include #include +#include namespace VTX::App::Serialization::IO::Reader { @@ -32,7 +33,7 @@ namespace VTX::App::Serialization::IO::Reader chrono.start(); p_molecule.setMoleculeStruct( moleculeStruct ); chrono.stop(); - VTX_INFO( "Build Molecule convenient structure : {}", chrono.elapsedTimeStr() ); + VTX_INFO( "Build Molecule convenient structure : {}", Util::String::durationToStr( chrono.elapsedTime() ) ); } void MoleculeLoader::readBuffer( diff --git a/lib/app/src/app/vtx_app.cpp b/lib/app/src/app/vtx_app.cpp index cd82e02f5..3a66b585e 100644 --- a/lib/app/src/app/vtx_app.cpp +++ b/lib/app/src/app/vtx_app.cpp @@ -40,7 +40,7 @@ namespace VTX::App Settings::initSettings(); // Init renderer. - Core::Renderer::RendererSystem::SHADER_DIR = Filesystem::getShadersDir(); + Core::Renderer::RendererSystem::init( Filesystem::getShadersDir() ); // Setup entity creation routines (add components, setup components, etc.). Internal::ECS::setupEntityDirector(); diff --git a/lib/io/src/io/reader/chemfiles.cpp b/lib/io/src/io/reader/chemfiles.cpp index 5b69769f5..52be0a600 100644 --- a/lib/io/src/io/reader/chemfiles.cpp +++ b/lib/io/src/io/reader/chemfiles.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #pragma warning( push, 0 ) #include @@ -108,7 +109,7 @@ namespace VTX::IO::Reader std::unique_ptr chemfilesReader = std::make_unique( p_path ); chrono.stop(); - VTX_INFO( "readFile : {}", chrono.elapsedTimeStr() ); + VTX_INFO( "readFile : {}", Util::String::durationToStr( chrono.elapsedTime() ) ); return chemfilesReader; } @@ -123,7 +124,7 @@ namespace VTX::IO::Reader std::unique_ptr chemfilesReader = std::make_unique( p_buffer, p_path ); chrono.stop(); - VTX_INFO( "readBuffer : {}", chrono.elapsedTimeStr() ); + VTX_INFO( "readBuffer : {}", Util::String::durationToStr( chrono.elapsedTime() ) ); return chemfilesReader; } @@ -154,18 +155,18 @@ namespace VTX::IO::Reader chrono.start(); _preRead(); chrono.stop(); - VTX_INFO( "_preRead: {}", chrono.elapsedTimeStr() ); + VTX_INFO( "_preRead: {}", Util::String::durationToStr( chrono.elapsedTime() ) ); chrono.start(); chemfiles::Frame frame; _read(); chrono.stop(); - VTX_INFO( "Trajectory read in: {}", chrono.elapsedTimeStr() ); + VTX_INFO( "Trajectory read in: {}", Util::String::durationToStr( chrono.elapsedTime() ) ); chrono.start(); _postRead(); chrono.stop(); - VTX_INFO( "_postRead: {}", chrono.elapsedTimeStr() ); + VTX_INFO( "_postRead: {}", Util::String::durationToStr( chrono.elapsedTime() ) ); } void Chemfiles::_preRead() diff --git a/lib/ui/qt/src/ui/qt/dock_widget/options.cpp b/lib/ui/qt/src/ui/qt/dock_widget/options.cpp index 27df0318d..0efd864fb 100644 --- a/lib/ui/qt/src/ui/qt/dock_widget/options.cpp +++ b/lib/ui/qt/src/ui/qt/dock_widget/options.cpp @@ -25,9 +25,10 @@ namespace VTX::UI::QT::DockWidget groupCacheBox->setLayout( groupCacheLayout ); - auto * buttonCacheLayout = new QHBoxLayout( this ); - auto * buttonOpenCache = new QPushButton( "Open", this ); - auto * buttonClearCache = new QPushButton( "Clear", this ); + auto * buttonCacheLayout = new QHBoxLayout( this ); + auto * buttonOpenCache = new QPushButton( "Open", this ); + auto * buttonClearCache = new QPushButton( "Clear", this ); + auto * buttonRefreshCache = new QPushButton( "Refresh", this ); const FilePath cachePath = App::Filesystem::getCacheDir(); connect( @@ -47,6 +48,8 @@ namespace VTX::UI::QT::DockWidget } ); + connect( buttonRefreshCache, &QPushButton::clicked, [ this ]() { _refreshCacheInfos(); } ); + _labelCacheCount = new QLabel( this ); _labelCacheSize = new QLabel( this ); @@ -54,6 +57,7 @@ namespace VTX::UI::QT::DockWidget groupCacheLayout->addWidget( _labelCacheSize ); buttonCacheLayout->addWidget( buttonOpenCache ); buttonCacheLayout->addWidget( buttonClearCache ); + buttonCacheLayout->addWidget( buttonRefreshCache ); groupCacheLayout->addLayout( buttonCacheLayout ); layout->addWidget( groupCacheBox ); diff --git a/lib/util/include/util/chrono.hpp b/lib/util/include/util/chrono.hpp index 38dd5a0d2..03fe5bf6e 100644 --- a/lib/util/include/util/chrono.hpp +++ b/lib/util/include/util/chrono.hpp @@ -15,11 +15,10 @@ namespace VTX::Util static long long getTimestamp(); - void start(); - void stop(); - float elapsedTime() const; - std::string elapsedTimeStr() const; - float intervalTime(); + void start(); + void stop(); + float elapsedTime() const; + float intervalTime(); private: using SystemClock = std::chrono::system_clock; diff --git a/lib/util/include/util/string.hpp b/lib/util/include/util/string.hpp index c3f70c583..2c74bf5ad 100644 --- a/lib/util/include/util/string.hpp +++ b/lib/util/include/util/string.hpp @@ -27,6 +27,8 @@ namespace VTX::Util::String std::string toUpper( const std::string & p_str ); // Memory size to string. std::string memSizeToStr( const size_t p_size ); + // Duration to string. + std::string durationToStr( const float p_durationInSeconds ); } // namespace VTX::Util::String diff --git a/lib/util/src/util/chrono.cpp b/lib/util/src/util/chrono.cpp index bd8c6a358..4c8c2d7a4 100644 --- a/lib/util/src/util/chrono.cpp +++ b/lib/util/src/util/chrono.cpp @@ -18,8 +18,6 @@ namespace VTX::Util return ( std::chrono::duration_cast( Clock::now() - _begin ) ).count(); } - std::string Chrono::elapsedTimeStr() const { return std::to_string( elapsedTime() ) + 's'; } - float Chrono::intervalTime() { Duration intervalTime = std::chrono::duration_cast( Clock::now() - _interval ); diff --git a/lib/util/src/util/string.cpp b/lib/util/src/util/string.cpp index ca9d430b3..9841763af 100644 --- a/lib/util/src/util/string.cpp +++ b/lib/util/src/util/string.cpp @@ -102,4 +102,38 @@ namespace VTX::Util::String return oss.str(); } + std::string durationToStr( const float p_durationInSeconds ) + { + std::ostringstream oss; + int totalMilliseconds = static_cast( p_durationInSeconds * 1000 ); + + int hours = totalMilliseconds / 3600000; + totalMilliseconds %= 3600000; + + int minutes = totalMilliseconds / 60000; + totalMilliseconds %= 60000; + + int seconds = totalMilliseconds / 1000; + int milliseconds = totalMilliseconds % 1000; + + if ( hours > 0 ) + { + oss << hours << " h "; + } + if ( minutes > 0 || hours > 0 ) + { + oss << minutes << " min "; + } + if ( seconds > 0 || minutes > 0 || hours > 0 ) + { + oss << seconds << " s "; + } + if ( milliseconds > 0 || ( hours == 0 && minutes == 0 && seconds == 0 ) ) + { + oss << milliseconds << " ms"; + } + + return oss.str(); + } + } // namespace VTX::Util::String