demotool/m-tool.cc

216 lines
4.3 KiB
C++
Raw Normal View History

2017-09-30 10:37:45 +02:00
#include "externals.hh"
#include "common.hh"
2017-11-24 12:11:02 +01:00
#include "c-filewatcher.hh"
#include "ui.hh"
#include "ui-app.hh"
#include "ui-demo.hh"
#include "ui-odbg.hh"
#include "ui-opemu.hh"
#include "ui-profiling.hh"
#include "ui-rendertarget.hh"
#include "ui-sequencer.hh"
#include "ui-shaders.hh"
#include "ui-sync.hh"
#include "ui-utilities.hh"
2017-11-03 09:08:19 +01:00
2017-09-30 10:37:45 +02:00
/*= T_Main ===================================================================*/
struct T_Main
{
static constexpr uint32_t ResizeDelay = 50;
2017-12-27 14:15:49 +01:00
explicit T_Main( T_FSPath const& path );
2017-09-30 10:37:45 +02:00
~T_Main( );
void mainLoop( );
private:
bool done = false;
uint32_t stopResize = 0;
ImVec2 prevSize;
2017-12-28 10:27:23 +01:00
UI ui;
2017-11-03 09:08:19 +01:00
T_Optional< T_Demo > demo;
T_Optional< T_SyncView > sequencer;
2017-10-02 13:51:08 +02:00
void initDemo( );
2017-09-30 10:37:45 +02:00
void startIteration( );
void makeUI( );
void render( );
};
/*----------------------------------------------------------------------------*/
2017-12-27 14:15:49 +01:00
T_Main::T_Main( T_FSPath const& path )
2017-12-28 10:27:23 +01:00
: ui{ path }
2017-09-30 10:37:45 +02:00
{
2017-11-15 23:09:52 +01:00
prevSize = ImVec2( -1 , -1 );
Common::SetInteractiveMode( );
2017-09-30 10:37:45 +02:00
}
void T_Main::mainLoop( )
{
auto& m( UI::Main( ) );
auto& p( UI::Profiler( ) );
while ( !m.exiting( ) ) {
// Check whether there's a resize in progress
2017-11-15 23:09:52 +01:00
auto const& dspSize( ImGui::GetIO( ).DisplaySize );
if ( prevSize.x != dspSize.x || prevSize.y != dspSize.y ) {
const auto doit( prevSize.x > 0 );
prevSize = dspSize;
if ( doit ) {
stopResize = ResizeDelay;
}
}
2017-11-15 23:09:52 +01:00
// If there was a resize and some time has passed,
// re-initialise the demo.
2017-11-15 23:09:52 +01:00
bool needInit( !demo );
if ( stopResize > 0 ) {
stopResize --;
if ( stopResize == 0 ) {
2017-11-15 23:09:52 +01:00
needInit = true;
2017-10-02 13:51:08 +02:00
}
}
2017-11-15 23:09:52 +01:00
if ( needInit ) {
2017-10-02 13:51:08 +02:00
initDemo( );
}
// Update file watcher and shaders
Common::Watcher( ).check( );
UI::Shaders( ).update( );
// Display
2017-10-01 12:48:55 +02:00
p.startFrame( );
p.start( "Full frame" );
m.handleEvents( );
if ( !m.exiting( ) ) {
2017-09-30 10:37:45 +02:00
makeUI( );
render( );
m.render( );
2017-09-30 10:37:45 +02:00
}
p.end( "Full frame" );
m.swap( );
p.endFrame( );
2017-09-30 10:37:45 +02:00
}
}
T_Main::~T_Main( )
{
2017-11-03 09:08:19 +01:00
demo.clear( );
2017-09-30 10:37:45 +02:00
}
/*----------------------------------------------------------------------------*/
2017-10-02 13:51:08 +02:00
void T_Main::initDemo( )
{
auto const& dspSize( ImGui::GetIO( ).DisplaySize );
if ( dspSize.x < 0 || dspSize.y < 0 ) {
return;
}
2017-11-15 23:09:52 +01:00
if ( !demo ) {
demo.setNew( );
}
2017-10-02 13:51:08 +02:00
printf( "init w/ dspsize %dx%d\n" , int( dspSize.x ) , int( dspSize.y ) );
2017-11-15 23:09:52 +01:00
if ( demo->initialise( (uint32_t) dspSize.x , (uint32_t) dspSize.y ) ) {
UI::Profiler( ).clear( );
2017-10-02 13:51:08 +02:00
}
}
2017-09-30 10:37:45 +02:00
void T_Main::makeUI( )
{
using namespace ImGui;
auto& main{ UI::Main( ) };
bool eSequencer{ sequencer };
if ( BeginMainMenuBar( ) ) {
if ( BeginMenu( "File" ) ) {
main.actionMenu( "Save curves" );
main.actionMenu( "Reload curves" );
Separator( );
main.actionMenu( "Undo" );
main.actionMenu( "Redo" );
2017-11-22 14:14:49 +01:00
Separator( );
main.actionMenu( "Quit" );
EndMenu( );
2017-10-07 17:39:38 +02:00
}
if ( BeginMenu( "Views" ) ) {
MenuItemCheckbox( "Input overrides" ,
&UI::Sync( ).overridesWindowEnabled( ) );
MenuItemCheckbox( "Output debugger" ,
&UI::ODbg( ).uiEnabled( ) );
MenuItemCheckbox( "Profiler" ,
&UI::Profiler( ).uiEnabled( ) );
MenuItemCheckbox( "Sequencer" , &eSequencer );
MenuItemCheckbox( "Shaders" ,
&UI::Shaders( ).uiEnabled( ) );
EndMenu( );
2017-10-07 17:39:38 +02:00
}
EndMainMenuBar( );
2017-10-07 17:39:38 +02:00
}
if ( eSequencer && !sequencer ) {
sequencer.setNew( );
} else if ( !eSequencer && sequencer ) {
sequencer.clear( );
}
UI::Profiler( ).makeUI( );
UI::ODbg( ).makeUI( );
UI::Shaders( ).makeUI( );
UI::Sync( ).makeOverridesWindow( );
if ( sequencer && !sequencer->display( ) ) {
sequencer.clear( );
}
2017-09-30 10:37:45 +02:00
}
void T_Main::render( )
{
2017-11-08 09:09:21 +01:00
if ( demo ) {
demo->render( );
UI::Profiler( ).start( "Debug" );
T_Rendertarget::MainOutput( );
if ( UI::ODbg( ).isActive( ) ) {
UI::ODbg( ).debugOutput( );
}
UI::Profiler( ).end( "Debug" );
2017-10-05 18:35:35 +02:00
} else {
T_Rendertarget::MainOutput( );
glClearColor( 0 , 0 , 0 , 1 );
glClear( GL_COLOR_BUFFER_BIT );
2017-10-02 13:51:08 +02:00
}
2017-09-30 10:37:45 +02:00
}
/*============================================================================*/
int main( int argc , char** argv )
2017-09-30 10:37:45 +02:00
{
2017-12-27 11:32:49 +01:00
const T_FSPath cwd{ Filesystem::Cwd( ) };
T_FSPath pp;
if ( argc >= 2 ) {
pp = T_String{ argv[ 1 ] };
if ( !pp.isValid( ) ) {
fprintf( stderr , "Invalid path '%s'\n" , argv[ 1 ] );
return 1;
}
} else {
pp = T_String{ "." };
}
const T_FSPath rpp{ ( pp.isRelative( ) ? ( cwd + pp ) : pp ).canonical( ) };
2017-12-27 14:15:49 +01:00
T_Main m{ rpp };
m.mainLoop( );
2017-09-30 10:37:45 +02:00
return 0;
}