From e5865cb23e9997c07c1144a2571fef9e0a82f0e6 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sat, 28 Oct 2017 12:37:34 +0200 Subject: [PATCH] Optimize drawing messages. --- server/TracyView.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 1915c308..95279056 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -1839,7 +1839,7 @@ void View::DrawZones() ImGui::InvisibleButton( "##zones", ImVec2( w, h ) ); bool hover = ImGui::IsItemHovered(); - auto timespan = m_zvEnd - m_zvStart; + const auto timespan = m_zvEnd - m_zvStart; auto pxns = w / double( timespan ); if( hover ) @@ -1848,6 +1848,8 @@ void View::DrawZones() HandleZoneViewMouse( timespan, wpos, w, pxns ); } + const auto nspx = 1.0 / pxns; + // zones LockHighlight nextLockHighlight { -1 }; const auto ty = ImGui::GetFontSize(); @@ -1870,17 +1872,31 @@ void View::DrawZones() while( it < end ) { + const auto next = std::upper_bound( it, v->messages.end(), (*it)->time + MinVisSize * nspx, [] ( const auto& lhs, const auto& rhs ) { return lhs < rhs->time; } ); + const auto dist = std::distance( it, next ); + const auto px = ( (*it)->time - m_zvStart ) * pxns; + if( dist > 1 ) + { + draw->AddTriangleFilled( wpos + ImVec2( px - (ty - to) * 0.5, offset + to ), wpos + ImVec2( px + (ty - to) * 0.5, offset + to ), wpos + ImVec2( px, offset + to + th ), 0xFFDDDDDD ); + } draw->AddTriangle( wpos + ImVec2( px - (ty - to) * 0.5, offset + to ), wpos + ImVec2( px + (ty - to) * 0.5, offset + to ), wpos + ImVec2( px, offset + to + th ), 0xFFDDDDDD ); if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( px - (ty - to) * 0.5 - 1, offset ), wpos + ImVec2( px + (ty - to) * 0.5 + 1, offset + ty ) ) ) { ImGui::BeginTooltip(); - ImGui::Text( "%s", TimeToString( (*it)->time - m_frames[0] ) ); - ImGui::Text( "%s", (*it)->literal ? GetString( (*it)->str ) : (*it)->txt ); + if( dist > 1 ) + { + ImGui::Text( "%i messages", (int)dist ); + } + else + { + ImGui::Text( "%s", TimeToString( (*it)->time - m_frames[0] ) ); + ImGui::Text( "%s", (*it)->literal ? GetString( (*it)->str ) : (*it)->txt ); + } ImGui::EndTooltip(); m_msgHighlight = *it; } - ++it; + it = next; } } else