From 3344f96af011644257cb7e83c711d61244f64b8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Thu, 28 Dec 2017 17:15:00 +0100 Subject: [PATCH] "Interactive mode" for common code This prevents the script manager and sync manager from watching/loading their files unless they're explicitely started using Common::SetInteractiveMode() This will avoid having the whole thing loaded twice when running the builder. --- c-opcomp.hh | 8 ++++++++ c-opmgr.cc | 17 +++++++++++++---- c-sync.cc | 35 +++++++++++++++++++++-------------- c-sync.hh | 13 ++++++++++--- common.cc | 12 +++++++++++- common.hh | 2 ++ m-tool.cc | 1 + 7 files changed, 66 insertions(+), 22 deletions(-) diff --git a/c-opcomp.hh b/c-opcomp.hh index 6009093..481bcbb 100644 --- a/c-opcomp.hh +++ b/c-opcomp.hh @@ -84,6 +84,12 @@ class T_ScriptManager : public A_ProjectPathListener T_ScriptManager( ) noexcept; ~T_ScriptManager( ); + void enable( ) noexcept; + void disable( ) noexcept + { enabled_ = false; } + bool enabled( ) const noexcept + { return enabled_; } + bool hasNewProgram( ) const noexcept { return bool( output_ ); } @@ -94,6 +100,8 @@ class T_ScriptManager : public A_ProjectPathListener { return errors_; } private: + bool enabled_{ false }; + T_FSPath path_; T_WatchedFiles watcher_; diff --git a/c-opmgr.cc b/c-opmgr.cc index d2c8a6a..da558ff 100644 --- a/c-opmgr.cc +++ b/c-opmgr.cc @@ -46,7 +46,6 @@ T_ScriptManager::T_ScriptManager( ) noexcept parser_( ) , compiler_( ) { Common::Project( ).addListener( this ); - projectPathChanged( ); } T_ScriptManager::~T_ScriptManager( ) @@ -54,12 +53,22 @@ T_ScriptManager::~T_ScriptManager( ) Common::Project( ).removeListener( this ); } +void T_ScriptManager::enable( ) noexcept +{ + if ( !enabled_ ) { + enabled_ = true; + projectPathChanged( ); + } +} + void T_ScriptManager::projectPathChanged( ) noexcept { path_ = Common::Project( ).pathOf( "demo.srd" ); - watcher_.clear( ); - watcher_.watch( path_.toString( ) ); - loadScript( ); + if ( enabled_ ) { + watcher_.clear( ); + watcher_.watch( path_.toString( ) ); + loadScript( ); + } } /*----------------------------------------------------------------------------*/ diff --git a/c-sync.cc b/c-sync.cc index cca0ad8..ed16f04 100644 --- a/c-sync.cc +++ b/c-sync.cc @@ -331,7 +331,7 @@ namespace { struct T_SCIOImpl_ { T_SCIOImpl_( ) noexcept; - T_SyncCurvesIO::T_Data load( T_String const& path ) const; + T_SyncCurvesIO::T_Data load( T_FSPath const& path ) const; T_SRDParserConfig pConfig; }; @@ -342,7 +342,7 @@ inline T_SCIOImpl_::T_SCIOImpl_( ) noexcept { } inline T_SyncCurvesIO::T_Data T_SCIOImpl_::load( - T_String const& path ) const + T_FSPath const& path ) const { T_File file( path , E_FileMode::READ_ONLY ); file.open( ); @@ -350,7 +350,7 @@ inline T_SyncCurvesIO::T_Data T_SCIOImpl_::load( T_FileInputStream fis( file ); T_SRDParser parser( pConfig ); T_SRDTextReader reader( parser ); - reader.read( path , fis ); + reader.read( path.components( ).last( ) , fis ); return std::move( *parser.getData< T_SharedPtr< T_ParserOutput_ > >( ) ); } @@ -365,12 +365,13 @@ T_SyncCurvesIO::T_SyncCurvesIO( ) noexcept T_SyncCurvesIO::T_Data T_SyncCurvesIO::load( - T_String const& path ) const + T_FSPath const& path ) const { return p< T_SCIOImpl_ >( ).load( path ); } -void T_SyncCurvesIO::save( T_String const& path , +void T_SyncCurvesIO::save( + T_FSPath const& path , T_SyncCurves const& curves , T_SyncTime const& time ) const { @@ -682,11 +683,7 @@ T_SyncManager::T_SyncManager( ) noexcept : io_{ } , watcher_{ Common::Watcher( ) , [this](){ curvesChanged_( ); } } , soRoot_( "*root*" ) { - auto& p{ Common::Project( ) }; - p.addListener( this ); - curvesFile_ = p.strPathOf( "curves.srd" ); - watcher_.watch( curvesFile_ ); - loadCurves( false ); + Common::Project( ).addListener( this ); } T_SyncManager::~T_SyncManager( ) @@ -694,6 +691,14 @@ T_SyncManager::~T_SyncManager( ) Common::Project( ).removeListener( this ); } +void T_SyncManager::enable( ) noexcept +{ + if ( !enabled_ ) { + enabled_ = true; + projectPathChanged( ); + } +} + /*----------------------------------------------------------------------------*/ void T_SyncManager::setDuration( @@ -977,8 +982,10 @@ void T_SyncManager::visitOverrides( void T_SyncManager::projectPathChanged( ) noexcept { - curvesFile_ = Common::Project( ).strPathOf( "curves.srd" ); - watcher_.clear( ); - watcher_.watch( curvesFile_ ); - loadCurves( false ); + if ( enabled_ ) { + curvesFile_ = Common::Project( ).pathOf( "curves.srd" ); + watcher_.clear( ); + watcher_.watch( curvesFile_ ); + loadCurves( false ); + } } diff --git a/c-sync.hh b/c-sync.hh index 098c83e..ccafa49 100644 --- a/c-sync.hh +++ b/c-sync.hh @@ -157,8 +157,8 @@ struct T_SyncCurvesIO : public ebcl::A_PrivateImplementation ebcl::T_SRDLocation tLocation; }; - T_Data load( T_String const& path ) const; - void save( T_String const& path , + T_Data load( T_FSPath const& path ) const; + void save( T_FSPath const& path , T_SyncCurves const& curves , T_SyncTime const& time ) const; }; @@ -358,6 +358,12 @@ struct T_SyncManager : public virtual A_ProjectPathListener T_SyncManager( ) noexcept; ~T_SyncManager( ); + void enable( ) noexcept; + void disable( ) noexcept + { enabled_ = false; } + bool enabled( ) const noexcept + { return enabled_; } + // --------------------------------------------------------------------- // Duration & time controls @@ -463,8 +469,9 @@ struct T_SyncManager : public virtual A_ProjectPathListener // Private data private: + bool enabled_{ false }; // Interactive mode enabled? T_SyncCurvesIO io_; // Curves loader/writer - T_String curvesFile_; // Path to the curves file + T_FSPath curvesFile_; // Path to the curves file T_WatchedFiles watcher_; // Curves file watcher bool saving_{ false }; // True if file is being saved bool modified_; // Locally modified diff --git a/common.cc b/common.cc index 264fe9f..2aafe8d 100644 --- a/common.cc +++ b/common.cc @@ -49,7 +49,17 @@ Common::~Common( ) noexcept /*----------------------------------------------------------------------------*/ -#define M_GET_( P ) ((CommonData_*)(char*)&Instance_)->P +#define M_ACCESS_() ((CommonData_*)(char*)&Instance_) +#define M_GET_( P ) M_ACCESS_()->P + +void Common::SetInteractiveMode( ) noexcept +{ + auto* d{ M_ACCESS_( ) }; + d->sync.enable( ); + d->ops.enable( ); +} + +/*----------------------------------------------------------------------------*/ T_Project& Common::Project( ) noexcept { return M_GET_( project ); } diff --git a/common.hh b/common.hh index 2cc2f16..3f6089b 100644 --- a/common.hh +++ b/common.hh @@ -16,6 +16,8 @@ struct Common explicit Common( T_FSPath const& path = {} ) noexcept; ~Common( ) noexcept; + static void SetInteractiveMode( ) noexcept; + static T_Project& Project( ) noexcept; static T_FilesWatcher& Watcher( ) noexcept; static T_SyncManager& Sync( ) noexcept; diff --git a/m-tool.cc b/m-tool.cc index 7ed1452..9446270 100644 --- a/m-tool.cc +++ b/m-tool.cc @@ -50,6 +50,7 @@ T_Main::T_Main( T_FSPath const& path ) : ui{ path } { prevSize = ImVec2( -1 , -1 ); + Common::SetInteractiveMode( ); } void T_Main::mainLoop( )