diff --git a/demo.cc b/demo.cc index 47c25a3..bad302b 100644 --- a/demo.cc +++ b/demo.cc @@ -43,6 +43,19 @@ void T_Demo::makeUI( ) void T_Demo::render( ) { + if ( playing ) { + const float time = SDL_GetTicks( ) * 1e-3; + if ( playingPrevious ) { + const float adv = time - lastFrame; + position = std::min( adv + position , sync.duration( ) ); + if ( position >= sync.duration( ) ) { + playing = false; + } + } + lastFrame = time; + } + playingPrevious = playing; + raymarcher->render( ); dof->render( ); bloom->render( ); diff --git a/demo.hh b/demo.hh index da28df3..e3dec2c 100644 --- a/demo.hh +++ b/demo.hh @@ -6,6 +6,7 @@ #include "combine.hh" #include "fxaa.hh" #include "profiling.hh" +#include "sync.hh" struct T_Demo @@ -40,9 +41,17 @@ struct T_Demo const uint32_t width; const uint32_t height; + T_SyncData sync; + float position = 0; + bool playing = false; + std::unique_ptr< T_Raymarcher > raymarcher; std::unique_ptr< T_DoFPass > dof; std::unique_ptr< T_BloomPass > bloom; std::unique_ptr< T_CombinePass > combine; std::unique_ptr< T_FXAAPass > fxaa; + + private: + bool playingPrevious = false; + float lastFrame; }; diff --git a/main.cc b/main.cc index 11e35fe..2137092 100644 --- a/main.cc +++ b/main.cc @@ -29,7 +29,7 @@ struct T_Main uint32_t stopResize = 0; ImVec2 prevSize; - bool demoCtrl_ = true; + bool demoCtrl_ = false; std::unique_ptr< T_Demo > demo; void initDemo( ); @@ -176,10 +176,24 @@ void T_Main::makeUI( ) ImGui::Begin( "Tools" ); ImGui::Checkbox( "Demo controls" , &demoCtrl_ ); - ImGui::Checkbox( "Profiler" , &Globals::Profiler( ).uiEnabled( ) ); ImGui::Checkbox( "Output debugger" , &Globals::ODbg( ).uiEnabled( ) ); + ImGui::Checkbox( "Profiler" , &Globals::Profiler( ).uiEnabled( ) ); ImGui::Checkbox( "Shaders" , &Globals::Shaders( ).uiEnabled( ) ); + if ( demo ) { + ImGui::Separator( ); + const float duration( demo->sync.duration( ) ); + if ( ImGui::SliderFloat( "" , &demo->position , 0 , duration , "%.1fs" ) + && demo->position > duration ) { + demo->position = duration; + demo->playing = false; + } + ImGui::SameLine( ); + if ( ImGui::Button( demo->playing ? "Stop" : "Play" ) ) { + demo->playing = !demo->playing; + } + } + ImGui::End( ); if ( demo && demoCtrl_ ) { diff --git a/sync.cc b/sync.cc index 779dbf2..ebabe65 100644 --- a/sync.cc +++ b/sync.cc @@ -4,6 +4,9 @@ const T_SyncVariable T_SyncData::MissingVariable_{ }; +T_SyncData::T_SyncData( ) + : T_SyncData( 60 * 60 , 1. / 60 ) +{ } T_SyncData::T_SyncData( __rd__ const uint32_t duration , diff --git a/sync.hh b/sync.hh index 7286efc..790ff97 100644 --- a/sync.hh +++ b/sync.hh @@ -25,11 +25,14 @@ using T_SyncVariable = std::vector< T_SyncSegment >; struct T_SyncData { - T_SyncData( ) = delete; + T_SyncData( ); T_SyncData( __rd__ const uint32_t duration , __rd__ const float units ) noexcept; + float duration( ) const noexcept + { return duration_ * units_; } + void setSyncVariable( __rd__ std::string const& name , __rw__ T_SyncVariable&& variable ) noexcept;