"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( );
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_;

View file

@ -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" );
if ( enabled_ ) {
watcher_.clear( );
watcher_.watch( path_.toString( ) );
loadScript( );
}
}
/*----------------------------------------------------------------------------*/

View file

@ -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" );
if ( enabled_ ) {
curvesFile_ = Common::Project( ).pathOf( "curves.srd" );
watcher_.clear( );
watcher_.watch( curvesFile_ );
loadCurves( false );
}
}

View file

@ -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

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
{ return M_GET_( project ); }

View file

@ -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;

View file

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