2017-09-30 10:37:45 +02:00
|
|
|
#include "externals.hh"
|
|
|
|
#include "imgui_impl_sdl.h"
|
2017-10-02 13:51:08 +02:00
|
|
|
#include "demo.hh"
|
2017-10-04 11:20:27 +02:00
|
|
|
#include "globals.hh"
|
2017-10-01 11:37:04 +02:00
|
|
|
#include "profiling.hh"
|
2017-10-04 11:20:27 +02:00
|
|
|
#include "window.hh"
|
|
|
|
#include "shaders.hh"
|
2017-10-06 14:29:01 +02:00
|
|
|
#include "odbg.hh"
|
2017-11-23 14:21:54 +01:00
|
|
|
#include "opemu.hh"
|
2017-11-14 22:04:00 +01:00
|
|
|
#include "rendertarget.hh"
|
2017-11-15 23:09:52 +01:00
|
|
|
#include "sync.hh"
|
2017-11-23 14:21:54 +01:00
|
|
|
#include "ui-sequencer.hh"
|
2017-11-22 14:14:49 +01:00
|
|
|
#include "undo.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-09-30 10:37:45 +02:00
|
|
|
T_Main( );
|
|
|
|
~T_Main( );
|
|
|
|
|
|
|
|
void mainLoop( );
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool done = false;
|
|
|
|
bool capture = false;
|
|
|
|
ImVec2 mouseInitial;
|
|
|
|
ImVec2 mouseMove;
|
|
|
|
|
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 handleCapture( );
|
|
|
|
void makeUI( );
|
|
|
|
void render( );
|
|
|
|
};
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
T_Main::T_Main( )
|
|
|
|
{
|
2017-10-04 11:20:27 +02:00
|
|
|
Globals::Init( );
|
2017-11-15 23:09:52 +01:00
|
|
|
prevSize = ImVec2( -1 , -1 );
|
2017-11-23 13:54:27 +01:00
|
|
|
|
|
|
|
// FIXME: should be somewhere else
|
|
|
|
T_UIAction saveCurves{ "Save curves" , []() {
|
|
|
|
if ( Globals::Sync( ).curvesFileChanged( ) ) {
|
|
|
|
Globals::Window( ).msgbox(
|
|
|
|
"Curves file changed" ,
|
|
|
|
"The file containing the curves has been modified "
|
|
|
|
"on the disk. These changes will be overwritten. "
|
|
|
|
"Do you want to continue?" ,
|
|
|
|
[]( auto b ) {
|
|
|
|
if ( b == T_MessageBox::BT_YES ) {
|
|
|
|
Globals::Sync( ).saveCurves( );
|
|
|
|
}
|
|
|
|
} , { T_MessageBox::BT_YES , T_MessageBox::BT_NO } );
|
|
|
|
} else {
|
|
|
|
Globals::Sync( ).saveCurves( );
|
|
|
|
}
|
|
|
|
} };
|
|
|
|
saveCurves.setEnabledCheck( []() { return Globals::Sync( ).curvesModified( ); } )
|
|
|
|
.setIcon( ICON_FA_FLOPPY_O )
|
|
|
|
.setShortcut( T_KeyboardShortcut{ 's' , E_KeyboardModifier::CTRL } );
|
|
|
|
Globals::Window( ).addAction( std::move( saveCurves ) );
|
|
|
|
|
|
|
|
T_UIAction reloadCurves{ "Reload curves" , []() {
|
|
|
|
Globals::Window( ).msgbox(
|
|
|
|
"Reload curves?" ,
|
|
|
|
"Changes you made to the curves will be lost. Do you "
|
|
|
|
"want to continue?" ,
|
|
|
|
[]( auto b ) {
|
|
|
|
if ( b == T_MessageBox::BT_YES ) {
|
|
|
|
Globals::Sync( ).loadCurves( );
|
|
|
|
}
|
|
|
|
} , { T_MessageBox::BT_YES , T_MessageBox::BT_NO } );
|
|
|
|
} };
|
|
|
|
reloadCurves.setEnabledCheck( []() { return Globals::Sync( ).curvesModified( ); } )
|
|
|
|
.setIcon( ICON_FA_DOWNLOAD )
|
|
|
|
.setShortcut( T_KeyboardShortcut{ 'r' ,
|
|
|
|
{ E_KeyboardModifier::CTRL , E_KeyboardModifier::SHIFT } } );
|
|
|
|
Globals::Window( ).addAction( std::move( reloadCurves ) );
|
2017-09-30 10:37:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void T_Main::mainLoop( )
|
|
|
|
{
|
2017-10-04 11:20:27 +02:00
|
|
|
auto& p( Globals::Profiler( ) );
|
2017-09-30 10:37:45 +02:00
|
|
|
while ( !done ) {
|
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
|
|
|
|
|
|
|
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-20 21:54:46 +01:00
|
|
|
#warning FIXME remove this
|
|
|
|
if ( !sequencer ) {
|
|
|
|
sequencer.setNew( );
|
|
|
|
}
|
2017-10-02 13:51:08 +02:00
|
|
|
|
2017-10-04 17:29:48 +02:00
|
|
|
Globals::Watcher( ).check( );
|
|
|
|
Globals::Shaders( ).update( );
|
|
|
|
|
2017-10-03 09:56:37 +02:00
|
|
|
glFinish( );
|
2017-10-01 12:48:55 +02:00
|
|
|
p.startFrame( );
|
2017-10-04 11:20:27 +02:00
|
|
|
p.start( "Full frame" );
|
2017-09-30 10:37:45 +02:00
|
|
|
startIteration( );
|
|
|
|
if ( !done ) {
|
|
|
|
handleCapture( );
|
|
|
|
makeUI( );
|
|
|
|
render( );
|
2017-10-04 11:20:27 +02:00
|
|
|
p.end( "Full frame" );
|
|
|
|
Globals::Window( ).swap( );
|
2017-10-01 12:48:55 +02:00
|
|
|
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-10-04 11:20:27 +02:00
|
|
|
Globals::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-10-04 11:20:27 +02:00
|
|
|
Globals::Profiler( ).clear( );
|
2017-10-02 13:51:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-30 10:37:45 +02:00
|
|
|
void T_Main::startIteration( )
|
|
|
|
{
|
|
|
|
SDL_Event event;
|
|
|
|
mouseMove = ImVec2( );
|
|
|
|
while ( SDL_PollEvent( &event ) ) {
|
|
|
|
ImGui_ImplSdl_ProcessEvent( &event );
|
|
|
|
if ( event.type == SDL_QUIT ) {
|
|
|
|
done = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( capture && event.type == SDL_MOUSEMOTION ) {
|
|
|
|
mouseMove.x += event.motion.xrel;
|
|
|
|
mouseMove.y += event.motion.yrel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-04 11:20:27 +02:00
|
|
|
Globals::Window( ).startFrame( capture , mouseInitial );
|
2017-09-30 10:37:45 +02:00
|
|
|
ImGui::GetIO( ).MouseDrawCursor = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void T_Main::handleCapture( )
|
|
|
|
{
|
2017-11-20 14:32:53 +01:00
|
|
|
using namespace ImGui;
|
|
|
|
auto const& io( GetIO( ) );
|
|
|
|
const T_MouseButtons mb( ([]() {;
|
|
|
|
T_MouseButtons mb;
|
|
|
|
if ( IsMouseDown( 0 ) ) {
|
|
|
|
mb |= E_MouseButton::LEFT;
|
|
|
|
}
|
|
|
|
if ( IsMouseDown( 1 ) ) {
|
|
|
|
mb |= E_MouseButton::RIGHT;
|
|
|
|
}
|
|
|
|
if ( IsMouseDown( 2 ) ) {
|
|
|
|
mb |= E_MouseButton::MIDDLE;
|
|
|
|
}
|
|
|
|
return mb;
|
|
|
|
})() );
|
|
|
|
const T_KeyboardModifiers kb( ([&io]() {
|
|
|
|
T_KeyboardModifiers kb;
|
|
|
|
if ( io.KeyCtrl ) {
|
|
|
|
kb |= E_KeyboardModifier::CTRL;
|
|
|
|
}
|
|
|
|
if ( io.KeyShift ) {
|
|
|
|
kb |= E_KeyboardModifier::SHIFT;
|
|
|
|
}
|
|
|
|
if ( io.KeyAlt ) {
|
|
|
|
kb |= E_KeyboardModifier::ALT;
|
|
|
|
}
|
|
|
|
return kb;
|
|
|
|
})() );
|
2017-09-30 10:37:45 +02:00
|
|
|
const bool appCanGrab( !( ImGui::IsMouseHoveringAnyWindow( )
|
|
|
|
|| io.WantCaptureMouse
|
|
|
|
|| io.WantCaptureKeyboard ) );
|
|
|
|
|
|
|
|
if ( capture && !mb ) {
|
|
|
|
capture = false;
|
2017-11-20 14:32:53 +01:00
|
|
|
CaptureMouseFromApp( false );
|
2017-09-30 10:37:45 +02:00
|
|
|
SDL_SetRelativeMouseMode( SDL_FALSE );
|
2017-10-04 11:20:27 +02:00
|
|
|
Globals::Window( ).warpMouse( mouseInitial );
|
2017-11-20 14:32:53 +01:00
|
|
|
SetMouseCursor( ImGuiMouseCursor_Arrow );
|
2017-09-30 10:37:45 +02:00
|
|
|
} else if ( capture ) {
|
2017-11-20 14:32:53 +01:00
|
|
|
SetMouseCursor( ImGuiMouseCursor_Move );
|
|
|
|
Globals::Sync( ).handleDragAndDrop( mouseMove , kb , mb );
|
2017-09-30 10:37:45 +02:00
|
|
|
} else if ( appCanGrab && mb ) {
|
|
|
|
capture = true;
|
2017-11-20 14:32:53 +01:00
|
|
|
mouseInitial = GetMousePos( );
|
|
|
|
CaptureMouseFromApp( true );
|
2017-09-30 10:37:45 +02:00
|
|
|
SDL_SetRelativeMouseMode( SDL_TRUE );
|
2017-11-20 14:32:53 +01:00
|
|
|
SetMouseCursor( ImGuiMouseCursor_Move );
|
2017-09-30 10:37:45 +02:00
|
|
|
}
|
|
|
|
|
2017-11-20 14:32:53 +01:00
|
|
|
if ( ( appCanGrab || capture ) && io.MouseWheel ) {
|
|
|
|
Globals::Sync( ).handleWheel( io.MouseWheel , kb , mb );
|
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-22 14:14:49 +01:00
|
|
|
auto& undo( Globals::Undo( ) );
|
2017-11-22 15:02:54 +01:00
|
|
|
auto& sync( Globals::Sync( ) );
|
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-23 13:54:27 +01:00
|
|
|
Globals::Window( ).actionMenu( "Save curves" );
|
|
|
|
Globals::Window( ).actionMenu( "Reload curves" );
|
2017-11-22 15:02:54 +01:00
|
|
|
Separator( );
|
2017-11-22 14:14:49 +01:00
|
|
|
if ( MenuItem( "Undo" , "C-z" , false , undo.canUndo( ) ) ) {
|
|
|
|
undo.undo( );
|
|
|
|
}
|
|
|
|
if ( MenuItem( "Redo" , "C-Z" , false , undo.canRedo( ) ) ) {
|
|
|
|
undo.redo( );
|
|
|
|
}
|
|
|
|
Separator( );
|
2017-11-19 10:21:08 +01:00
|
|
|
if ( MenuItem( "Quit" ) ) {
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
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-22 15:02:54 +01:00
|
|
|
&sync.overridesWindowEnabled( ) );
|
2017-11-19 10:21:08 +01:00
|
|
|
MenuItemCheckbox( "Output debugger" ,
|
|
|
|
&Globals::ODbg( ).uiEnabled( ) );
|
|
|
|
MenuItemCheckbox( "Profiler" ,
|
|
|
|
&Globals::Profiler( ).uiEnabled( ) );
|
2017-11-20 17:01:09 +01:00
|
|
|
MenuItemCheckbox( "Sequencer" , &eSequencer );
|
2017-11-19 10:21:08 +01:00
|
|
|
MenuItemCheckbox( "Shaders" ,
|
|
|
|
&Globals::Shaders( ).uiEnabled( ) );
|
|
|
|
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-10-04 11:20:27 +02:00
|
|
|
Globals::Profiler( ).makeUI( );
|
2017-10-06 14:29:01 +02:00
|
|
|
Globals::ODbg( ).makeUI( );
|
2017-10-06 18:42:51 +02:00
|
|
|
Globals::Shaders( ).makeUI( );
|
2017-11-19 10:21:08 +01:00
|
|
|
Globals::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
|
|
|
|
|
|
|
Globals::Profiler( ).start( "Debug" );
|
|
|
|
T_Rendertarget::MainOutput( );
|
|
|
|
if ( Globals::ODbg( ).isActive( ) ) {
|
|
|
|
Globals::ODbg( ).debugOutput( );
|
|
|
|
}
|
|
|
|
glFinish( ); Globals::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-10-06 14:29:01 +02:00
|
|
|
|
2017-11-22 14:13:02 +01:00
|
|
|
Globals::Window( ).handleDialogs( );
|
2017-09-30 10:37:45 +02:00
|
|
|
glUseProgram( 0 );
|
2017-10-04 17:37:55 +02:00
|
|
|
glBindProgramPipeline( 0 );
|
2017-10-04 11:20:27 +02:00
|
|
|
Globals::Textures( ).reset( );
|
2017-10-05 18:35:35 +02:00
|
|
|
glClearColor( 0 , 0 , 0 , 1 );
|
2017-09-30 10:37:45 +02:00
|
|
|
ImGui::Render( );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*============================================================================*/
|
|
|
|
|
|
|
|
int main( int , char** )
|
|
|
|
{
|
|
|
|
T_Main m;
|
2017-10-04 11:20:27 +02:00
|
|
|
m.mainLoop( );
|
2017-09-30 10:37:45 +02:00
|
|
|
return 0;
|
|
|
|
}
|