"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.
This commit is contained in:
Emmanuel BENOîT 2017-12-28 17:15:00 +01:00
parent e8b3188be9
commit 3344f96af0
7 changed files with 66 additions and 22 deletions

View file

@ -84,6 +84,12 @@ class T_ScriptManager : public A_ProjectPathListener
T_ScriptManager( ) noexcept; T_ScriptManager( ) noexcept;
~T_ScriptManager( ); ~T_ScriptManager( );
void enable( ) noexcept;
void disable( ) noexcept
{ enabled_ = false; }
bool enabled( ) const noexcept
{ return enabled_; }
bool hasNewProgram( ) const noexcept bool hasNewProgram( ) const noexcept
{ return bool( output_ ); } { return bool( output_ ); }
@ -94,6 +100,8 @@ class T_ScriptManager : public A_ProjectPathListener
{ return errors_; } { return errors_; }
private: private:
bool enabled_{ false };
T_FSPath path_; T_FSPath path_;
T_WatchedFiles watcher_; T_WatchedFiles watcher_;

View file

@ -46,7 +46,6 @@ T_ScriptManager::T_ScriptManager( ) noexcept
parser_( ) , compiler_( ) parser_( ) , compiler_( )
{ {
Common::Project( ).addListener( this ); Common::Project( ).addListener( this );
projectPathChanged( );
} }
T_ScriptManager::~T_ScriptManager( ) T_ScriptManager::~T_ScriptManager( )
@ -54,12 +53,22 @@ T_ScriptManager::~T_ScriptManager( )
Common::Project( ).removeListener( this ); Common::Project( ).removeListener( this );
} }
void T_ScriptManager::enable( ) noexcept
{
if ( !enabled_ ) {
enabled_ = true;
projectPathChanged( );
}
}
void T_ScriptManager::projectPathChanged( ) noexcept void T_ScriptManager::projectPathChanged( ) noexcept
{ {
path_ = Common::Project( ).pathOf( "demo.srd" ); path_ = Common::Project( ).pathOf( "demo.srd" );
if ( enabled_ ) {
watcher_.clear( ); watcher_.clear( );
watcher_.watch( path_.toString( ) ); watcher_.watch( path_.toString( ) );
loadScript( ); loadScript( );
}
} }
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/

View file

@ -331,7 +331,7 @@ namespace {
struct T_SCIOImpl_ struct T_SCIOImpl_
{ {
T_SCIOImpl_( ) noexcept; 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; T_SRDParserConfig pConfig;
}; };
@ -342,7 +342,7 @@ inline T_SCIOImpl_::T_SCIOImpl_( ) noexcept
{ } { }
inline T_SyncCurvesIO::T_Data T_SCIOImpl_::load( 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 ); T_File file( path , E_FileMode::READ_ONLY );
file.open( ); file.open( );
@ -350,7 +350,7 @@ inline T_SyncCurvesIO::T_Data T_SCIOImpl_::load(
T_FileInputStream fis( file ); T_FileInputStream fis( file );
T_SRDParser parser( pConfig ); T_SRDParser parser( pConfig );
T_SRDTextReader reader( parser ); T_SRDTextReader reader( parser );
reader.read( path , fis ); reader.read( path.components( ).last( ) , fis );
return std::move( *parser.getData< T_SharedPtr< T_ParserOutput_ > >( ) ); 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_SyncCurvesIO::T_Data T_SyncCurvesIO::load(
T_String const& path ) const T_FSPath const& path ) const
{ {
return p< T_SCIOImpl_ >( ).load( path ); 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_SyncCurves const& curves ,
T_SyncTime const& time ) const T_SyncTime const& time ) const
{ {
@ -682,11 +683,7 @@ T_SyncManager::T_SyncManager( ) noexcept
: io_{ } , watcher_{ Common::Watcher( ) , [this](){ curvesChanged_( ); } } , : io_{ } , watcher_{ Common::Watcher( ) , [this](){ curvesChanged_( ); } } ,
soRoot_( "*root*" ) soRoot_( "*root*" )
{ {
auto& p{ Common::Project( ) }; Common::Project( ).addListener( this );
p.addListener( this );
curvesFile_ = p.strPathOf( "curves.srd" );
watcher_.watch( curvesFile_ );
loadCurves( false );
} }
T_SyncManager::~T_SyncManager( ) T_SyncManager::~T_SyncManager( )
@ -694,6 +691,14 @@ T_SyncManager::~T_SyncManager( )
Common::Project( ).removeListener( this ); Common::Project( ).removeListener( this );
} }
void T_SyncManager::enable( ) noexcept
{
if ( !enabled_ ) {
enabled_ = true;
projectPathChanged( );
}
}
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
void T_SyncManager::setDuration( void T_SyncManager::setDuration(
@ -977,8 +982,10 @@ void T_SyncManager::visitOverrides(
void T_SyncManager::projectPathChanged( ) noexcept void T_SyncManager::projectPathChanged( ) noexcept
{ {
curvesFile_ = Common::Project( ).strPathOf( "curves.srd" ); if ( enabled_ ) {
curvesFile_ = Common::Project( ).pathOf( "curves.srd" );
watcher_.clear( ); watcher_.clear( );
watcher_.watch( curvesFile_ ); watcher_.watch( curvesFile_ );
loadCurves( false ); loadCurves( false );
}
} }

View file

@ -157,8 +157,8 @@ struct T_SyncCurvesIO : public ebcl::A_PrivateImplementation
ebcl::T_SRDLocation tLocation; ebcl::T_SRDLocation tLocation;
}; };
T_Data load( T_String const& path ) const; T_Data load( T_FSPath const& path ) const;
void save( T_String const& path , void save( T_FSPath const& path ,
T_SyncCurves const& curves , T_SyncCurves const& curves ,
T_SyncTime const& time ) const; T_SyncTime const& time ) const;
}; };
@ -358,6 +358,12 @@ struct T_SyncManager : public virtual A_ProjectPathListener
T_SyncManager( ) noexcept; T_SyncManager( ) noexcept;
~T_SyncManager( ); ~T_SyncManager( );
void enable( ) noexcept;
void disable( ) noexcept
{ enabled_ = false; }
bool enabled( ) const noexcept
{ return enabled_; }
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// Duration & time controls // Duration & time controls
@ -463,8 +469,9 @@ struct T_SyncManager : public virtual A_ProjectPathListener
// Private data // Private data
private: private:
bool enabled_{ false }; // Interactive mode enabled?
T_SyncCurvesIO io_; // Curves loader/writer 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 T_WatchedFiles watcher_; // Curves file watcher
bool saving_{ false }; // True if file is being saved bool saving_{ false }; // True if file is being saved
bool modified_; // Locally modified bool modified_; // Locally modified

View file

@ -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 T_Project& Common::Project( ) noexcept
{ return M_GET_( project ); } { return M_GET_( project ); }

View file

@ -16,6 +16,8 @@ struct Common
explicit Common( T_FSPath const& path = {} ) noexcept; explicit Common( T_FSPath const& path = {} ) noexcept;
~Common( ) noexcept; ~Common( ) noexcept;
static void SetInteractiveMode( ) noexcept;
static T_Project& Project( ) noexcept; static T_Project& Project( ) noexcept;
static T_FilesWatcher& Watcher( ) noexcept; static T_FilesWatcher& Watcher( ) noexcept;
static T_SyncManager& Sync( ) noexcept; static T_SyncManager& Sync( ) noexcept;

View file

@ -50,6 +50,7 @@ T_Main::T_Main( T_FSPath const& path )
: ui{ path } : ui{ path }
{ {
prevSize = ImVec2( -1 , -1 ); prevSize = ImVec2( -1 , -1 );
Common::SetInteractiveMode( );
} }
void T_Main::mainLoop( ) void T_Main::mainLoop( )