diff --git a/demo.cc b/demo.cc index a65169d..f381bea 100644 --- a/demo.cc +++ b/demo.cc @@ -97,29 +97,10 @@ bool T_Demo::runInit( } Globals::Sync( ).updateCurveCaches( ); -#warning silly test here - T_OwnPtr< sov::T_Float > ov{ NewOwned< sov::T_Float >( - "dof-sharp-distance" , "Sharp distance" ) }; - ov->setMin( 0 ); - ov->setMax( 1000 ); - ov->setStep( .1 ); -// ov->setSlider( true ); - ov->setup( ); - - T_SyncOverrideSection sos( "" ); - sos.subsections.add( NewOwned< T_SyncOverrideSection >( "Testing" ) ); - sos.subsections[ 0 ]->subsections.add( NewOwned< T_SyncOverrideSection >( "Yeah really" ) ); - sos.subsections[ 0 ]->subsections[ 0 ]->overrides.add( std::move( ov ) ); - - auto ov2{ NewOwned< sov::T_Float4 >( - "bloom-bw0" , "bloom-bw1" , "bloom-bw2" , "bloom-bw3" , - "Blur weights" ) }; - ov2->setMax( 1 ); - ov2->setSlider( ); - ov2->setup( ); - sos.subsections[ 0 ]->overrides.add( std::move( ov2 ) ); - - Globals::Sync( ).mergeOverrides( sos ); + if ( context->installOverrides ) { + Globals::Sync( ).mergeOverrides( *( context->installOverrides ) ); + context->installOverrides.clear( ); + } return true; } diff --git a/opast.hh b/opast.hh index 3c89fbc..52381ba 100644 --- a/opast.hh +++ b/opast.hh @@ -968,6 +968,9 @@ class T_OverridesInstrNode : public A_InstructionNode T_SyncOverrideSection& root( ) const noexcept { return *overrides_; } + + T_OwnPtr< T_SyncOverrideSection > extractRoot( ) noexcept + { return std::move( overrides_ ); } }; // Profiling instruction diff --git a/opcomp.cc b/opcomp.cc index 7d02c3a..5167d1f 100644 --- a/opcomp.cc +++ b/opcomp.cc @@ -667,6 +667,14 @@ bool T_CompilerImpl_::compileNode( } break; + case A_Node::OP_OVERRIDES: + if ( exit ) { + auto& n{ (T_OverridesInstrNode&) node }; + const auto idx{ output->overrides.add( n.extractRoot( ) ) }; + addInstruction( OP_UI_INPUT_OVR , idx , node.location( ) ); + } + break; + //- EXPRESSIONS - ARGUMENTS ----------------------------------------------------------- diff --git a/opparser.cc b/opparser.cc index dd69551..07ae11e 100644 --- a/opparser.cc +++ b/opparser.cc @@ -169,6 +169,7 @@ struct T_ParserImpl_ } return {}; } }; + T_SyncOverrideVisitor ovVisitor; T_ParserImpl_( T_Array< T_SRDError >* errors , T_OwnPtr< T_OpsParserOutput >* root ) noexcept; @@ -772,6 +773,28 @@ bool T_ParserImpl_::checkIdentifiers( ) noexcept return false; } + case A_Node::OP_OVERRIDES: + { + auto& ov{ dynamic_cast< T_OverridesInstrNode& >( n ) }; + ovVisitor.visitor.visit( &ov.root( ) , + [&]( T_SyncOverrideVisitor::T_Element element , bool exit ) -> bool { + if ( exit || element.hasType< T_SyncOverrideSection* >( ) ) { + return true; + } + + auto& ovr( *element.value< A_SyncOverride* >( ) ); + auto const& in( ovr.inputNames( ) ); + const auto nin( in.size( ) ); + for ( auto i = 0u ; i < nin ; i ++ ) { + checkIdentifier( in[ i ] , ovr.location( ) , + cfi , E_DataType::INPUT ); + } + return false; + } + ); + return false; + } + default: return true; } diff --git a/ops.cc b/ops.cc index 49a5dfa..84bea88 100644 --- a/ops.cc +++ b/ops.cc @@ -146,6 +146,7 @@ static T_KeyValueTable< E_OpType , T_OpInfo > OpInfoTable_{ ([]() { infos.add( E_OpType::OP_UI_PENTER , T_OpInfo{ "ui-prof-enter" , 1 } ); infos.add( E_OpType::OP_UI_PEXIT , T_OpInfo{ "ui-prof-exit" } ); infos.add( E_OpType::OP_UI_INPUT_DFT , T_OpInfo{ "ui-input-default" , 2 } ); + infos.add( E_OpType::OP_UI_INPUT_OVR , T_OpInfo{ "ui-overrides" , 1 } ); infos.add( E_OpType::OP_UI_ODBG , T_OpInfo{ "ui-odbg" , 2 , OpStackMain{ -1 } } ); return infos; @@ -281,6 +282,7 @@ void T_OpContext::run( stack.clear( ); stack.add( 0xffffffff ); + installOverrides.clear( ); while ( !stack.empty( ) ) { auto const& instr{ program.ops[ instrPtr ] }; @@ -884,6 +886,13 @@ void T_OpContext::run( initialInputs[ instr.args[ 0 ] ] = values[ instr.args[ 1 ] ].f; break; + case OP_UI_INPUT_OVR: + if ( !installOverrides ) { + installOverrides = NewOwned< T_SyncOverrideSection >( "*" ); + } + installOverrides->merge( *( program.overrides[ instr.args[ 0 ] ] ) ); + break; + case OP_UI_ODBG: { ensureStack( instr , 1 ); diff --git a/ops.hh b/ops.hh index 10376b2..1ce4b3d 100644 --- a/ops.hh +++ b/ops.hh @@ -73,6 +73,7 @@ enum E_OpType OP_UI_PENTER , OP_UI_PEXIT , OP_UI_INPUT_DFT , + OP_UI_INPUT_OVR , OP_UI_ODBG , }; @@ -142,6 +143,8 @@ struct T_OpProgram T_Array< T_String > progNames; // GLSL program files T_Array< T_String > uiStrings; // UI strings for profiling, etc. + T_Array< P_SyncOverrideSection > overrides; + // Override definitions for the UI }; using P_OpProgram = T_OwnPtr< T_OpProgram >; @@ -161,6 +164,8 @@ struct T_OpContext double x87stack[ 8 ]; // x87 FPU emulation stack uint32_t x87sp; // x87 FPU emulation stack pointer + P_SyncOverrideSection installOverrides; // Install UI overrides + // Allocated resources T_Array< T_OwnPtr< T_Rendertarget > > framebuffers; T_Array< T_OwnPtr< T_ShaderProgram > > programs; diff --git a/sync.cc b/sync.cc index 920f631..fe81d1f 100644 --- a/sync.cc +++ b/sync.cc @@ -481,6 +481,28 @@ T_SyncOverrideSection const* T_SyncOverrideSection::section( } +/*= T_SyncOverrideVisitor ====================================================*/ + +T_SyncOverrideVisitor::T_OpElement T_SyncOverrideVisitor::nodeBrowser( + const T_Element element , + const uint32_t child ) +{ + if ( element.hasType< A_SyncOverride* >( ) ) { + return {}; + } + + auto& section( *element.value< T_SyncOverrideSection* >( ) ); + const auto nss( section.subsections.size( ) ); + if ( child < nss ) { + return T_OpElement{ section.subsections[ child ].get( ) }; + } + if ( child - nss < section.overrides.size( ) ) { + return T_OpElement{ section.overrides[ child - nss ].get( ) }; + } + return {}; +} + + /*= T_SyncManager ============================================================*/ T_SyncManager::T_SyncManager( ) @@ -635,6 +657,18 @@ void T_SyncManager::mergeOverrides( { assert( overrides.overrides.empty( ) ); soRoot_.merge( overrides ); + + T_SyncOverrideVisitor v; + v.visitor.visit( &soRoot_ , + []( T_SyncOverrideVisitor::T_Element node , bool exit ) -> bool { + if ( exit || node.hasType< T_SyncOverrideSection* >( ) ) { + return true; + } + auto& ovr( *node.value< A_SyncOverride* >( ) ); + ovr.setup( ); + return false; + } + ); } void T_SyncManager::makeOverridesWindow( ) diff --git a/sync.hh b/sync.hh index 8f1d8bc..83e6c6d 100644 --- a/sync.hh +++ b/sync.hh @@ -5,6 +5,7 @@ #include #include +#include // Duration and current playing time @@ -235,6 +236,21 @@ struct T_SyncOverrideSection T_String const& name ) const noexcept; }; +/*----------------------------------------------------------------------------*/ + +struct T_SyncOverrideVisitor +{ + public: + using T_Element = ebcl::T_Union< + T_SyncOverrideSection* , + A_SyncOverride* >; + using T_OpElement = T_Optional< T_Element >; + + static T_OpElement nodeBrowser( T_Element element , uint32_t child ); + + ebcl::T_Visitor< T_Element , T_Element > visitor{ nodeBrowser }; +}; + /*============================================================================*/ // Synchronisation manager; handles all the synchronization data and makes it diff --git a/syncoverrides.cc b/syncoverrides.cc index 0ac4fe8..8e1ccdd 100644 --- a/syncoverrides.cc +++ b/syncoverrides.cc @@ -48,8 +48,8 @@ using SP_Float = T_SharedPtr< A_Float >; bool EnterFloat1_( T_SRDParserData const& data ) { auto const& input( *( data.input ) ); - SP_Float ptr{ NewShared< T_Float >( - input[ 1 ].stringValue( ) , input[ 2 ].stringValue( ) ) }; + SP_Float ptr{ NewShared< T_Float >( input[ 2 ].stringValue( ) , + input[ 1 ].stringValue( ) ) }; ptr->location( ) = input[ 0 ].location( ); *( data.targetData ) = std::move( ptr ); return true; @@ -59,8 +59,8 @@ bool EnterFloat2_( T_SRDParserData const& data ) { auto const& input( *( data.input ) ); SP_Float ptr{ NewShared< T_Float2 >( - input[ 1 ].stringValue( ) , input[ 2 ].stringValue( ) , - input[ 3 ].stringValue( ) ) }; + input[ 2 ].stringValue( ) , input[ 3 ].stringValue( ) , + input[ 1 ].stringValue( ) ) }; ptr->location( ) = input[ 0 ].location( ); *( data.targetData ) = std::move( ptr ); return true; @@ -70,8 +70,9 @@ bool EnterFloat3_( T_SRDParserData const& data ) { auto const& input( *( data.input ) ); SP_Float ptr{ NewShared< T_Float3 >( - input[ 1 ].stringValue( ) , input[ 2 ].stringValue( ) , - input[ 3 ].stringValue( ) , input[ 4 ].stringValue( ) ) }; + input[ 2 ].stringValue( ) , input[ 3 ].stringValue( ) , + input[ 4 ].stringValue( ) , + input[ 1 ].stringValue( ) ) }; ptr->location( ) = input[ 0 ].location( ); *( data.targetData ) = std::move( ptr ); return true; @@ -81,9 +82,9 @@ bool EnterFloat4_( T_SRDParserData const& data ) { auto const& input( *( data.input ) ); SP_Float ptr{ NewShared< T_Float4 >( - input[ 1 ].stringValue( ) , input[ 2 ].stringValue( ) , - input[ 3 ].stringValue( ) , input[ 4 ].stringValue( ) , - input[ 5 ].stringValue( ) ) }; + input[ 2 ].stringValue( ) , input[ 3 ].stringValue( ) , + input[ 4 ].stringValue( ) , input[ 5 ].stringValue( ) , + input[ 1 ].stringValue( ) ) }; ptr->location( ) = input[ 0 ].location( ); *( data.targetData ) = std::move( ptr ); return true;