Sync - Curves file also stores duration
This commit is contained in:
parent
bd8eb2ff02
commit
7ef4bedfa6
4 changed files with 77 additions and 33 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
(duration 0.016667 3600)
|
||||||
|
|
||||||
(dof-sharp-distance
|
(dof-sharp-distance
|
||||||
(segment smooth
|
(segment smooth
|
||||||
(values 35 100 35)
|
(values 35 100 35)
|
||||||
|
|
11
main.cc
11
main.cc
|
@ -82,7 +82,6 @@ void T_Main::mainLoop( )
|
||||||
|
|
||||||
Globals::Watcher( ).check( );
|
Globals::Watcher( ).check( );
|
||||||
Globals::Shaders( ).update( );
|
Globals::Shaders( ).update( );
|
||||||
Globals::Sync( ).checkCurveFile( );
|
|
||||||
|
|
||||||
glFinish( );
|
glFinish( );
|
||||||
p.startFrame( );
|
p.startFrame( );
|
||||||
|
@ -205,9 +204,17 @@ void T_Main::makeUI( )
|
||||||
{
|
{
|
||||||
using namespace ImGui;
|
using namespace ImGui;
|
||||||
auto& undo( Globals::Undo( ) );
|
auto& undo( Globals::Undo( ) );
|
||||||
|
auto& sync( Globals::Sync( ) );
|
||||||
bool eSequencer{ sequencer };
|
bool eSequencer{ sequencer };
|
||||||
if ( BeginMainMenuBar( ) ) {
|
if ( BeginMainMenuBar( ) ) {
|
||||||
if ( BeginMenu( "File" ) ) {
|
if ( BeginMenu( "File" ) ) {
|
||||||
|
if ( MenuItem( "Save curves" , "C-s" , false , sync.curvesModified( ) ) ) {
|
||||||
|
}
|
||||||
|
if ( MenuItem( "Reload curves" , "C-R" , false , sync.curvesModified( ) ) ) {
|
||||||
|
// FIXME: confirmation dialog
|
||||||
|
sync.loadCurves( );
|
||||||
|
}
|
||||||
|
Separator( );
|
||||||
if ( MenuItem( "Undo" , "C-z" , false , undo.canUndo( ) ) ) {
|
if ( MenuItem( "Undo" , "C-z" , false , undo.canUndo( ) ) ) {
|
||||||
undo.undo( );
|
undo.undo( );
|
||||||
}
|
}
|
||||||
|
@ -222,7 +229,7 @@ void T_Main::makeUI( )
|
||||||
}
|
}
|
||||||
if ( BeginMenu( "Views" ) ) {
|
if ( BeginMenu( "Views" ) ) {
|
||||||
MenuItemCheckbox( "Input overrides" ,
|
MenuItemCheckbox( "Input overrides" ,
|
||||||
&Globals::Sync( ).overridesWindowEnabled( ) );
|
&sync.overridesWindowEnabled( ) );
|
||||||
MenuItemCheckbox( "Output debugger" ,
|
MenuItemCheckbox( "Output debugger" ,
|
||||||
&Globals::ODbg( ).uiEnabled( ) );
|
&Globals::ODbg( ).uiEnabled( ) );
|
||||||
MenuItemCheckbox( "Profiler" ,
|
MenuItemCheckbox( "Profiler" ,
|
||||||
|
|
84
sync.cc
84
sync.cc
|
@ -25,6 +25,13 @@ const std::map< std::string , T_SyncSegment::E_SegmentType > SegmentTypes_( ([]
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
struct T_ParserOutput_
|
||||||
|
{
|
||||||
|
T_SyncCurves curves;
|
||||||
|
T_Optional< T_SyncTime > time;
|
||||||
|
ebcl::T_SRDLocation tLocation;
|
||||||
|
};
|
||||||
|
|
||||||
using namespace ebcl;
|
using namespace ebcl;
|
||||||
|
|
||||||
bool CPEnterCurve_( T_SRDParserData const& data )
|
bool CPEnterCurve_( T_SRDParserData const& data )
|
||||||
|
@ -35,8 +42,8 @@ bool CPEnterCurve_( T_SRDParserData const& data )
|
||||||
|
|
||||||
bool CPExitCurve_( T_SRDParserData const& data )
|
bool CPExitCurve_( T_SRDParserData const& data )
|
||||||
{
|
{
|
||||||
T_SyncCurve& curve( data.currentData->value< T_SyncCurve >( ) );
|
auto& curve( data.currentData->value< T_SyncCurve >( ) );
|
||||||
T_SyncCurves& curves( *( data.targetData->value< T_SharedPtr< T_SyncCurves > >( ) ) );
|
auto& po( *( data.targetData->value< T_SharedPtr< T_ParserOutput_ > >( ) ) );
|
||||||
|
|
||||||
if ( curve.segments.empty( ) ) {
|
if ( curve.segments.empty( ) ) {
|
||||||
T_StringBuilder sb;
|
T_StringBuilder sb;
|
||||||
|
@ -44,12 +51,12 @@ bool CPExitCurve_( T_SRDParserData const& data )
|
||||||
data.errors.add( std::move( sb ) , (*data.input)[ 0 ] );
|
data.errors.add( std::move( sb ) , (*data.input)[ 0 ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( curves.curves.contains( curve.name ) ) {
|
if ( po.curves.curves.contains( curve.name ) ) {
|
||||||
T_StringBuilder sb;
|
T_StringBuilder sb;
|
||||||
sb << "duplicate curve '" << curve.name << "'";
|
sb << "duplicate curve '" << curve.name << "'";
|
||||||
data.errors.add( std::move( sb ) , (*data.input)[ 0 ] );
|
data.errors.add( std::move( sb ) , (*data.input)[ 0 ] );
|
||||||
} else {
|
} else {
|
||||||
curves.setCurve( std::move( curve ) );
|
po.curves.setCurve( std::move( curve ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -118,13 +125,30 @@ bool CPSegmentDV_( T_SRDParserData const& data )
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CPSetDuration_( T_SRDParserData const& data )
|
||||||
|
{
|
||||||
|
auto const& input( *data.input );
|
||||||
|
auto& po( *( data.currentData->value< T_SharedPtr< T_ParserOutput_ > >( ) ) );
|
||||||
|
if ( po.time ) {
|
||||||
|
T_StringBuilder eb;
|
||||||
|
eb << "duplicate duration specification; previous: "
|
||||||
|
<< po.tLocation;
|
||||||
|
data.errors.add( std::move( eb ) , input[ 0 ].location( ) );
|
||||||
|
} else {
|
||||||
|
po.time = T_SyncTime( );
|
||||||
|
po.time->uDuration = std::min( 2. , std::max( 1. / 60. , input[ 1 ].floatValue( ) ) );
|
||||||
|
po.time->iDuration = std::max( 1l , input[ 2 ].longValue( ) );
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
T_SRDParserConfig MakeCurvesParser_( )
|
T_SRDParserConfig MakeCurvesParser_( )
|
||||||
{
|
{
|
||||||
using namespace ebcl::SRD;
|
using namespace ebcl::SRD;
|
||||||
|
|
||||||
T_SRDParserDefs defs( "default" );
|
T_SRDParserDefs defs( "default" );
|
||||||
defs << OnStart( []( T_SRDParserData const& data ) -> bool {
|
defs << OnStart( []( T_SRDParserData const& data ) -> bool {
|
||||||
*( data.currentData ) = NewShared< T_SyncCurves >( );
|
*( data.currentData ) = NewShared< T_ParserOutput_ >( );
|
||||||
return true;
|
return true;
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
@ -133,7 +157,9 @@ T_SRDParserConfig MakeCurvesParser_( )
|
||||||
|
|
||||||
defs.context( "default" )
|
defs.context( "default" )
|
||||||
<< ( Rule( ) << Text( ) << EnterContext( "segments" )
|
<< ( Rule( ) << Text( ) << EnterContext( "segments" )
|
||||||
<< OnEnter( CPEnterCurve_ ) << OnExit( CPExitCurve_ ) );
|
<< OnEnter( CPEnterCurve_ ) << OnExit( CPExitCurve_ ) )
|
||||||
|
<< ( Rule( ) << "duration" << Float( ) << Int32( )
|
||||||
|
<< CPSetDuration_ );
|
||||||
defs.context( "segments" )
|
defs.context( "segments" )
|
||||||
<< ( Rule( ) << "segment" << Enum( "segment-type" )
|
<< ( Rule( ) << "segment" << Enum( "segment-type" )
|
||||||
<< ( List( ) << "values" << ( AtLeast( 2 ) << Numeric( ) ) )
|
<< ( List( ) << "values" << ( AtLeast( 2 ) << Numeric( ) ) )
|
||||||
|
@ -516,8 +542,12 @@ T_SyncOverrideVisitor::T_OpElement T_SyncOverrideVisitor::nodeBrowser(
|
||||||
|
|
||||||
T_SyncManager::T_SyncManager( )
|
T_SyncManager::T_SyncManager( )
|
||||||
: pConfig_( MakeCurvesParser_( ) ) ,
|
: pConfig_( MakeCurvesParser_( ) ) ,
|
||||||
|
watcher_{ Globals::Watcher( ) , [this](){ curvesChanged_( ); } } ,
|
||||||
soRoot_( "*root*" )
|
soRoot_( "*root*" )
|
||||||
{ }
|
{
|
||||||
|
watcher_.watch( "curves.srd" );
|
||||||
|
loadCurves( );
|
||||||
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
@ -559,24 +589,11 @@ void T_SyncManager::clearInputs( ) noexcept
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void T_SyncManager::checkCurveFile( )
|
|
||||||
{
|
|
||||||
if ( watcher_ ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
watcher_ = NewOwned< T_WatchedFiles >(
|
|
||||||
Globals::Watcher( ) ,
|
|
||||||
[this] { curvesChanged_( ); } );
|
|
||||||
watcher_->watch( "curves.srd" );
|
|
||||||
bool missing;
|
|
||||||
loadCurves_( missing );
|
|
||||||
}
|
|
||||||
|
|
||||||
void T_SyncManager::clearCurves( )
|
void T_SyncManager::clearCurves( )
|
||||||
{
|
{
|
||||||
curves_.clear( );
|
curves_.clear( );
|
||||||
updateCurveCaches( );
|
updateCurveCaches( );
|
||||||
|
modified_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void T_SyncManager::setCurve(
|
void T_SyncManager::setCurve(
|
||||||
|
@ -584,6 +601,7 @@ void T_SyncManager::setCurve(
|
||||||
{
|
{
|
||||||
curves_.setCurve( curve );
|
curves_.setCurve( curve );
|
||||||
updateCurveCaches( );
|
updateCurveCaches( );
|
||||||
|
modified_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void T_SyncManager::removeCurve(
|
void T_SyncManager::removeCurve(
|
||||||
|
@ -591,33 +609,42 @@ void T_SyncManager::removeCurve(
|
||||||
{
|
{
|
||||||
if ( curves_.removeCurve( curve ) ) {
|
if ( curves_.removeCurve( curve ) ) {
|
||||||
updateCurveCaches( );
|
updateCurveCaches( );
|
||||||
|
modified_ = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void T_SyncManager::curvesChanged_( )
|
void T_SyncManager::curvesChanged_( )
|
||||||
{
|
{
|
||||||
bool missing;
|
if ( modified_ ) {
|
||||||
loadCurves_( missing );
|
fileChanged_ = true;
|
||||||
|
} else {
|
||||||
|
loadCurves( );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool T_SyncManager::loadCurves_(
|
bool T_SyncManager::loadCurves( )
|
||||||
bool& missing )
|
|
||||||
{
|
{
|
||||||
printf( "Loading curves data\n" );
|
printf( "Loading curves data\n" );
|
||||||
missing = true;
|
|
||||||
try {
|
try {
|
||||||
using namespace ebcl;
|
using namespace ebcl;
|
||||||
const T_SRDParserConfig cfg( MakeCurvesParser_( ) );
|
const T_SRDParserConfig cfg( MakeCurvesParser_( ) );
|
||||||
T_File file( "curves.srd" , E_FileMode::READ_ONLY );
|
T_File file( "curves.srd" , E_FileMode::READ_ONLY );
|
||||||
file.open( );
|
file.open( );
|
||||||
missing = false;
|
|
||||||
|
|
||||||
T_FileInputStream fis( file );
|
T_FileInputStream fis( file );
|
||||||
T_SRDParser parser( cfg );
|
T_SRDParser parser( cfg );
|
||||||
T_SRDTextReader reader( parser );
|
T_SRDTextReader reader( parser );
|
||||||
reader.read( "curves.srd" , fis );
|
reader.read( "curves.srd" , fis );
|
||||||
|
|
||||||
curves_ = std::move( *parser.getData< T_SharedPtr< T_SyncCurves > >( ) );
|
auto p( parser.getData< T_SharedPtr< T_ParserOutput_ > >( ) );
|
||||||
|
curves_ = std::move( p->curves );
|
||||||
|
if ( p->time ) {
|
||||||
|
time_.iDuration = p->time->iDuration;
|
||||||
|
time_.uDuration = p->time->uDuration;
|
||||||
|
} else {
|
||||||
|
time_.iDuration = 3600;
|
||||||
|
time_.uDuration = 1.f / 60.f;
|
||||||
|
}
|
||||||
} catch ( ebcl::X_StreamError const& e ) {
|
} catch ( ebcl::X_StreamError const& e ) {
|
||||||
printf( "... ERR %s\n" , e.what( ) );
|
printf( "... ERR %s\n" , e.what( ) );
|
||||||
return false;
|
return false;
|
||||||
|
@ -636,6 +663,7 @@ bool T_SyncManager::loadCurves_(
|
||||||
printf( "... success\n" );
|
printf( "... success\n" );
|
||||||
|
|
||||||
updateCurveCaches( );
|
updateCurveCaches( );
|
||||||
|
modified_ = fileChanged_ = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
13
sync.hh
13
sync.hh
|
@ -343,7 +343,6 @@ struct T_SyncManager : public virtual A_MouseCtrl
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Curves
|
// Curves
|
||||||
|
|
||||||
void checkCurveFile( );
|
|
||||||
void clearCurves( );
|
void clearCurves( );
|
||||||
void setCurve( T_SyncCurve curve );
|
void setCurve( T_SyncCurve curve );
|
||||||
void removeCurve( T_String const& curve ) noexcept;
|
void removeCurve( T_String const& curve ) noexcept;
|
||||||
|
@ -351,9 +350,15 @@ struct T_SyncManager : public virtual A_MouseCtrl
|
||||||
T_Array< T_SyncCurve > const& curves( ) const noexcept
|
T_Array< T_SyncCurve > const& curves( ) const noexcept
|
||||||
{ return curves_.curves.values( ); }
|
{ return curves_.curves.values( ); }
|
||||||
|
|
||||||
|
bool curvesModified( ) const noexcept
|
||||||
|
{ return modified_; }
|
||||||
|
bool curvesFileChanged( ) const noexcept
|
||||||
|
{ return fileChanged_; }
|
||||||
|
|
||||||
|
bool loadCurves( );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void curvesChanged_( );
|
void curvesChanged_( );
|
||||||
bool loadCurves_( bool& missing );
|
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
@ -407,7 +412,9 @@ struct T_SyncManager : public virtual A_MouseCtrl
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ebcl::T_SRDParserConfig pConfig_; // Parser config for curves
|
ebcl::T_SRDParserConfig pConfig_; // Parser config for curves
|
||||||
P_WatchedFiles watcher_; // Curves file watcher
|
T_WatchedFiles watcher_; // Curves file watcher
|
||||||
|
bool modified_; // Locally modified
|
||||||
|
bool fileChanged_; // File modified
|
||||||
|
|
||||||
T_SyncTime time_; // Duration/time information
|
T_SyncTime time_; // Duration/time information
|
||||||
bool playing_{ false }; // Is it playing?
|
bool playing_{ false }; // Is it playing?
|
||||||
|
|
Loading…
Reference in a new issue