Time value, play button, playing

This commit is contained in:
Emmanuel BENOîT 2017-10-07 17:39:38 +02:00
parent d61158fa9e
commit 58e3c35ea4
5 changed files with 45 additions and 3 deletions

13
demo.cc
View file

@ -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( );

View file

@ -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;
};

18
main.cc
View file

@ -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_ ) {

View file

@ -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 ,

View file

@ -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;