demotool/ui-demo.cc

90 lines
2 KiB
C++
Raw Permalink Normal View History

2017-10-02 13:51:08 +02:00
#include "externals.hh"
#include "common.hh"
#include "c-opcomp.hh"
#include "c-sync.hh"
#include "ui.hh"
#include "ui-demo.hh"
#include "ui-opemu.hh"
#include "ui-rendertarget.hh"
#include "ui-sync.hh"
#include <ebcl/Files.hh>
#include <ebcl/SRDText.hh>
2017-10-02 13:51:08 +02:00
2017-11-15 23:09:52 +01:00
bool T_Demo::initialise(
const uint32_t w ,
const uint32_t h )
2017-10-02 13:51:08 +02:00
{
2017-11-15 23:09:52 +01:00
width = w;
height = h;
return program && runInit( *program );
2017-10-02 13:51:08 +02:00
}
bool T_Demo::render( )
2017-10-02 13:51:08 +02:00
{
bool rv = false;
if ( Common::Ops( ).hasNewProgram( ) ) {
auto nProgram{ Common::Ops( ).program( ) };
2017-11-15 23:09:52 +01:00
if ( runInit( *nProgram ) ) {
program = std::move( nProgram );
rv = true;
2017-11-15 23:09:52 +01:00
}
UI::Sync( ).clearMouseDelegate( );
}
UI::Sync( ).updateTime( );
2017-10-07 17:39:38 +02:00
if ( context && !context->aborted ) {
try {
context->run( ops::T_OpContext::R_RENDER ,
Common::Sync( ).time( ) ,
width , height );
} catch ( ops::X_OpFailure const& fail ) {
printf( "FAILED TO RUN FRAME!\n\t%s\n" , fail.what( ) );
context->aborted = true;
}
}
return rv;
2017-10-02 13:51:08 +02:00
}
2017-11-15 23:09:52 +01:00
bool T_Demo::runInit(
ops::T_OpProgram& p )
{
2017-11-15 23:09:52 +01:00
auto nContext{ NewOwned< ops::T_OpContext >( p ) };
try {
2017-11-15 23:09:52 +01:00
nContext->run( ops::T_OpContext::R_INIT , 0 , width , height );
} catch ( ops::X_OpFailure const& fail ) {
printf( "FAILED TO RUN INIT!\n\t%s\n" , fail.what( ) );
2017-11-15 23:09:52 +01:00
nContext.clear( );
}
2017-11-15 23:09:52 +01:00
if ( !nContext ) {
return false;
}
context = std::move( nContext );
Common::Sync( ).clearInputs( );
Common::Sync( ).clearOverrides( );
const auto n( context->initialInputs.size( ) );
2017-11-15 23:09:52 +01:00
assert( n == p.inputs.size( ) );
for ( auto i = 0u ; i < n ; i ++ ) {
Common::Sync( ).addInput( p.inputs[ i ] ,
context->initialInputs[ i ] );
#ifdef INVASIVE_TRACES
2017-11-15 23:09:52 +01:00
printf( "#%d %s pos %d\n" , i , p.inputs[ i ].toOSString( ).data( ) ,
Common::Sync( ).inputPos( p.inputs[ i ] ) );
#endif //INVASIVE_TRACES
}
Common::Sync( ).updateCurveCaches( );
2017-11-15 23:09:52 +01:00
if ( context->installOverrides ) {
Common::Sync( ).mergeOverrides( *( context->installOverrides ) );
context->installOverrides.clear( );
}
2017-11-15 23:09:52 +01:00
return true;
2017-10-02 13:51:08 +02:00
}