From 3e4d3efbdb2897965f6a634627bfd1db13bedff1 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Mon, 26 Aug 2019 19:01:51 +0200 Subject: [PATCH] Extract frame number getter. --- server/TracyView.cpp | 33 +++++++++++++++++++++++++++------ server/TracyView.hpp | 1 + 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index a41ac8a5..7292cdad 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -998,6 +998,7 @@ void View::DrawFrames() } else { + const auto fnum = GetFrameNumber( *m_frames, sel, m_worker.GetFrameOffset() ); m_frameHover = sel; if( m_frames->name == 0 ) { @@ -1012,7 +1013,7 @@ void View::DrawFrames() { TextDisabledUnformatted( "Frame:" ); ImGui::SameLine(); - ImGui::TextUnformatted( RealToString( sel, true ) ); + ImGui::TextUnformatted( RealToString( fnum, true ) ); ImGui::Separator(); const auto frameTime = m_worker.GetFrameTime( *m_frames, sel ); TextFocused( "Frame time:", TimeToString( frameTime ) ); @@ -1029,7 +1030,7 @@ void View::DrawFrames() { TextDisabledUnformatted( "Frame:" ); ImGui::SameLine(); - ImGui::TextUnformatted( RealToString( sel + offset - 1, true ) ); + ImGui::TextUnformatted( RealToString( fnum, true ) ); ImGui::Separator(); const auto frameTime = m_worker.GetFrameTime( *m_frames, sel ); TextFocused( "Frame time:", TimeToString( frameTime ) ); @@ -1041,7 +1042,7 @@ void View::DrawFrames() { ImGui::TextDisabled( "%s:", m_worker.GetString( m_frames->name ) ); ImGui::SameLine(); - ImGui::TextUnformatted( RealToString( sel + 1, true ) ); + ImGui::TextUnformatted( RealToString( fnum, true ) ); ImGui::Separator(); const auto frameTime = m_worker.GetFrameTime( *m_frames, sel ); TextFocused( "Frame time:", TimeToString( frameTime ) ); @@ -1269,8 +1270,28 @@ void View::HandleZoneViewMouse( int64_t timespan, const ImVec2& wpos, float w, d } } +uint64_t View::GetFrameNumber( const FrameData& fd, int i, uint64_t offset ) const +{ + if( fd.name == 0 ) + { + if( offset == 0 ) + { + return i; + } + else + { + return i + offset - 1; + } + } + else + { + return i + 1; + } +} + const char* View::GetFrameText( const FrameData& fd, int i, uint64_t ftime, uint64_t offset ) const { + const auto fnum = GetFrameNumber( fd, i, offset ); static char buf[1024]; if( fd.name == 0 ) { @@ -1280,7 +1301,7 @@ const char* View::GetFrameText( const FrameData& fd, int i, uint64_t ftime, uint } else if( offset == 0 ) { - sprintf( buf, "Frame %s (%s)", RealToString( i, true ), TimeToString( ftime ) ); + sprintf( buf, "Frame %s (%s)", RealToString( fnum, true ), TimeToString( ftime ) ); } else if( i == 1 ) { @@ -1288,12 +1309,12 @@ const char* View::GetFrameText( const FrameData& fd, int i, uint64_t ftime, uint } else { - sprintf( buf, "Frame %s (%s)", RealToString( i + offset - 1, true ), TimeToString( ftime ) ); + sprintf( buf, "Frame %s (%s)", RealToString( fnum, true ), TimeToString( ftime ) ); } } else { - sprintf( buf, "%s %s (%s)", m_worker.GetString( fd.name ), RealToString( i + 1, true ), TimeToString( ftime ) ); + sprintf( buf, "%s %s (%s)", m_worker.GetString( fd.name ), RealToString( fnum, true ), TimeToString( ftime ) ); } return buf; } diff --git a/server/TracyView.hpp b/server/TracyView.hpp index 2c7d107b..595fdde2 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -181,6 +181,7 @@ private: uint64_t GetZoneThread( const GpuEvent& zone ) const; const GpuCtxData* GetZoneCtx( const GpuEvent& zone ) const; const ZoneEvent* FindZoneAtTime( uint64_t thread, int64_t time ) const; + uint64_t GetFrameNumber( const FrameData& fd, int i, uint64_t offset ) const; const char* GetFrameText( const FrameData& fd, int i, uint64_t ftime, uint64_t offset ) const; #ifndef TRACY_NO_STATISTICS