2017-09-30 10:37:45 +02:00
|
|
|
#include "externals.hh"
|
2017-11-23 23:37:52 +01:00
|
|
|
|
2017-11-23 23:05:14 +01:00
|
|
|
#include "common.hh"
|
2017-11-24 12:11:02 +01:00
|
|
|
#include "c-filewatcher.hh"
|
2017-11-23 23:37:52 +01:00
|
|
|
|
2017-11-23 22:44:20 +01:00
|
|
|
#include "ui.hh"
|
2017-11-23 22:51:50 +01:00
|
|
|
#include "ui-app.hh"
|
2017-11-24 09:51:05 +01:00
|
|
|
#include "ui-demo.hh"
|
2017-11-23 23:31:24 +01:00
|
|
|
#include "ui-odbg.hh"
|
|
|
|
#include "ui-opemu.hh"
|
|
|
|
#include "ui-profiling.hh"
|
|
|
|
#include "ui-rendertarget.hh"
|
2017-11-23 14:21:54 +01:00
|
|
|
#include "ui-sequencer.hh"
|
2017-11-23 23:31:24 +01:00
|
|
|
#include "ui-shaders.hh"
|
2017-11-23 22:44:20 +01:00
|
|
|
#include "ui-sync.hh"
|
2017-11-23 14:43:15 +01:00
|
|
|
#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
|
|
|
|
{
|
2017-10-05 08:45:40 +02:00
|
|
|
static constexpr uint32_t ResizeDelay = 50;
|
|
|
|
|
2017-11-24 14:52:56 +01:00
|
|
|
T_Main( char const* path );
|
2017-09-30 10:37:45 +02:00
|
|
|
~T_Main( );
|
|
|
|
|
|
|
|
void mainLoop( );
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool done = false;
|
|
|
|
|
2017-10-05 08:45:40 +02:00
|
|
|
uint32_t stopResize = 0;
|
|
|
|
ImVec2 prevSize;
|
|
|
|
|
2017-11-03 09:08:19 +01:00
|
|
|
T_Optional< T_Demo > demo;
|
2017-11-20 17:01:09 +01:00
|
|
|
T_Optional< T_SyncView > sequencer;
|
2017-10-02 13:51:08 +02:00
|
|
|
|
|
|
|
void initDemo( );
|
2017-09-30 17:58:48 +02:00
|
|
|
|
2017-09-30 10:37:45 +02:00
|
|
|
void startIteration( );
|
|
|
|
void makeUI( );
|
|
|
|
void render( );
|
|
|
|
};
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
2017-11-24 14:52:56 +01:00
|
|
|
T_Main::T_Main( char const* const path )
|
2017-09-30 10:37:45 +02:00
|
|
|
{
|
2017-11-24 14:52:56 +01:00
|
|
|
UI::Init( path );
|
2017-11-15 23:09:52 +01:00
|
|
|
prevSize = ImVec2( -1 , -1 );
|
2017-09-30 10:37:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void T_Main::mainLoop( )
|
|
|
|
{
|
2017-11-24 09:51:05 +01:00
|
|
|
auto& m( UI::Main( ) );
|
2017-11-23 23:31:24 +01:00
|
|
|
auto& p( UI::Profiler( ) );
|
2017-11-24 09:51:05 +01:00
|
|
|
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 ) {
|
2017-10-05 08:45:40 +02:00
|
|
|
stopResize = ResizeDelay;
|
|
|
|
}
|
|
|
|
}
|
2017-11-15 23:09:52 +01:00
|
|
|
|
2017-11-24 09:51:05 +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 );
|
2017-10-05 08:45:40 +02:00
|
|
|
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( );
|
|
|
|
}
|
2017-11-24 09:51:05 +01:00
|
|
|
|
|
|
|
// Update file watcher and shaders
|
2017-11-23 23:05:14 +01:00
|
|
|
Common::Watcher( ).check( );
|
2017-11-23 22:44:20 +01:00
|
|
|
UI::Shaders( ).update( );
|
2017-10-04 17:29:48 +02:00
|
|
|
|
2017-11-24 09:51:05 +01:00
|
|
|
// Display
|
2017-10-01 12:48:55 +02:00
|
|
|
p.startFrame( );
|
2017-10-04 11:20:27 +02:00
|
|
|
p.start( "Full frame" );
|
2017-11-24 09:51:05 +01:00
|
|
|
m.handleEvents( );
|
|
|
|
|
|
|
|
if ( !m.exiting( ) ) {
|
2017-09-30 10:37:45 +02:00
|
|
|
makeUI( );
|
|
|
|
render( );
|
2017-11-24 09:51:05 +01:00
|
|
|
m.render( );
|
2017-09-30 10:37:45 +02:00
|
|
|
}
|
2017-11-24 09:51:05 +01: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-11-23 22:44:20 +01:00
|
|
|
UI::Shutdown( );
|
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 ) ) {
|
2017-11-23 23:31:24 +01:00
|
|
|
UI::Profiler( ).clear( );
|
2017-10-02 13:51:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-30 10:37:45 +02:00
|
|
|
void T_Main::makeUI( )
|
|
|
|
{
|
2017-11-19 10:21:08 +01:00
|
|
|
using namespace ImGui;
|
2017-11-24 11:59:15 +01:00
|
|
|
auto& main{ UI::Main( ) };
|
2017-11-20 17:01:09 +01:00
|
|
|
bool eSequencer{ sequencer };
|
2017-11-19 10:21:08 +01:00
|
|
|
if ( BeginMainMenuBar( ) ) {
|
|
|
|
if ( BeginMenu( "File" ) ) {
|
2017-11-24 11:59:15 +01:00
|
|
|
main.actionMenu( "Save curves" );
|
|
|
|
main.actionMenu( "Reload curves" );
|
2017-11-22 15:02:54 +01:00
|
|
|
Separator( );
|
2017-11-24 11:59:15 +01:00
|
|
|
main.actionMenu( "Undo" );
|
|
|
|
main.actionMenu( "Redo" );
|
2017-11-22 14:14:49 +01:00
|
|
|
Separator( );
|
2017-11-24 11:59:15 +01:00
|
|
|
main.actionMenu( "Quit" );
|
2017-11-19 10:21:08 +01:00
|
|
|
EndMenu( );
|
2017-10-07 17:39:38 +02:00
|
|
|
}
|
2017-11-19 10:21:08 +01:00
|
|
|
if ( BeginMenu( "Views" ) ) {
|
|
|
|
MenuItemCheckbox( "Input overrides" ,
|
2017-11-23 22:44:20 +01:00
|
|
|
&UI::Sync( ).overridesWindowEnabled( ) );
|
2017-11-19 10:21:08 +01:00
|
|
|
MenuItemCheckbox( "Output debugger" ,
|
2017-11-23 22:44:20 +01:00
|
|
|
&UI::ODbg( ).uiEnabled( ) );
|
2017-11-19 10:21:08 +01:00
|
|
|
MenuItemCheckbox( "Profiler" ,
|
2017-11-23 23:31:24 +01:00
|
|
|
&UI::Profiler( ).uiEnabled( ) );
|
2017-11-20 17:01:09 +01:00
|
|
|
MenuItemCheckbox( "Sequencer" , &eSequencer );
|
2017-11-19 10:21:08 +01:00
|
|
|
MenuItemCheckbox( "Shaders" ,
|
2017-11-23 22:44:20 +01:00
|
|
|
&UI::Shaders( ).uiEnabled( ) );
|
2017-11-19 10:21:08 +01:00
|
|
|
EndMenu( );
|
2017-10-07 17:39:38 +02:00
|
|
|
}
|
2017-11-19 10:21:08 +01:00
|
|
|
EndMainMenuBar( );
|
2017-10-07 17:39:38 +02:00
|
|
|
}
|
|
|
|
|
2017-11-20 17:01:09 +01:00
|
|
|
if ( eSequencer && !sequencer ) {
|
|
|
|
sequencer.setNew( );
|
|
|
|
} else if ( !eSequencer && sequencer ) {
|
|
|
|
sequencer.clear( );
|
|
|
|
}
|
|
|
|
|
2017-11-23 23:31:24 +01:00
|
|
|
UI::Profiler( ).makeUI( );
|
2017-11-23 22:44:20 +01:00
|
|
|
UI::ODbg( ).makeUI( );
|
|
|
|
UI::Shaders( ).makeUI( );
|
|
|
|
UI::Sync( ).makeOverridesWindow( );
|
2017-11-20 17:01:09 +01:00
|
|
|
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( );
|
2017-10-06 14:29:01 +02:00
|
|
|
|
2017-11-23 23:31:24 +01:00
|
|
|
UI::Profiler( ).start( "Debug" );
|
2017-10-06 14:29:01 +02:00
|
|
|
T_Rendertarget::MainOutput( );
|
2017-11-23 22:44:20 +01:00
|
|
|
if ( UI::ODbg( ).isActive( ) ) {
|
|
|
|
UI::ODbg( ).debugOutput( );
|
2017-10-06 14:29:01 +02:00
|
|
|
}
|
2017-12-24 16:02:17 +01:00
|
|
|
UI::Profiler( ).end( "Debug" );
|
2017-10-06 14:29:01 +02:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*============================================================================*/
|
|
|
|
|
2017-11-24 14:52:56 +01:00
|
|
|
int main( int argc , char** argv )
|
2017-09-30 10:37:45 +02:00
|
|
|
{
|
2017-11-24 14:52:56 +01:00
|
|
|
T_Main m{ argc < 2 ? "." : argv[ 1 ] };
|
2017-10-04 11:20:27 +02:00
|
|
|
m.mainLoop( );
|
2017-09-30 10:37:45 +02:00
|
|
|
return 0;
|
|
|
|
}
|