From 44efb15df1eb586d27b69bb346e979eb1b45ae0a Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 4 Sep 2022 14:46:51 +0200 Subject: [PATCH] Remove VisData. Its functionality is now incorporated into TimelineItem. For purposes of maintaining visibility of frame sets and locks a much simpler ptr -> bool map is now used. --- server/TracyTimelineController.cpp | 41 --------------------------- server/TracyTimelineController.hpp | 25 ---------------- server/TracyView.cpp | 2 +- server/TracyView.hpp | 9 ++++++ server/TracyView_Locks.cpp | 2 +- server/TracyView_NotificationArea.cpp | 4 +-- server/TracyView_Options.cpp | 28 +++++++++--------- server/TracyView_Timeline.cpp | 2 +- 8 files changed, 28 insertions(+), 85 deletions(-) diff --git a/server/TracyTimelineController.cpp b/server/TracyTimelineController.cpp index 6ca8ccb2..2fadf6cd 100644 --- a/server/TracyTimelineController.cpp +++ b/server/TracyTimelineController.cpp @@ -44,45 +44,4 @@ void TimelineController::End( double pxns, int offset, const ImVec2& wpos, bool m_scroll = scrollPos; } -float TimelineController::AdjustThreadPosition( VisData& vis, float wy, int& offset ) -{ - if( vis.offset < offset ) - { - vis.offset = offset; - } - else if( vis.offset > offset ) - { - const auto diff = vis.offset - offset; - const auto move = std::max( 2.0, diff * 10.0 * ImGui::GetIO().DeltaTime ); - offset = vis.offset = int( std::max( vis.offset - move, offset ) ); - } - - return offset + wy; -} - -void TimelineController::AdjustThreadHeight( VisData& vis, int oldOffset, int& offset ) -{ - const auto h = offset - oldOffset; - if( vis.height > h ) - { - vis.height = h; - offset = oldOffset + vis.height; - } - else if( vis.height < h ) - { - if( m_firstFrame ) - { - vis.height = h; - offset = oldOffset + h; - } - else - { - const auto diff = h - vis.height; - const auto move = std::max( 2.0, diff * 10.0 * ImGui::GetIO().DeltaTime ); - vis.height = int( std::min( vis.height + move, h ) ); - offset = oldOffset + vis.height; - } - } -} - } diff --git a/server/TracyTimelineController.hpp b/server/TracyTimelineController.hpp index aa84c02f..e83b9baf 100644 --- a/server/TracyTimelineController.hpp +++ b/server/TracyTimelineController.hpp @@ -13,15 +13,6 @@ namespace tracy class TimelineController { - struct VisData - { - bool visible = true; - bool showFull = true; - bool ghost = false; - int offset = 0; - int height = 0; - }; - public: TimelineController( View& view, Worker& worker ); @@ -38,12 +29,8 @@ public: } float GetHeight() const { return m_height; } - const unordered_flat_map& GetVisData() const { return m_visData; } const unordered_flat_map>& GetItemMap() const { return m_itemMap; } - void AdjustThreadHeight( VisData& vis, int oldOffset, int& offset ); - float AdjustThreadPosition( VisData& vis, float wy, int& offset ); - tracy_force_inline TimelineItem& GetItem( const void* data ) { auto it = m_itemMap.find( data ); @@ -51,22 +38,10 @@ public: return *it->second; } - tracy_force_inline VisData& Vis( const void* ptr ) - { - auto it = m_visData.find( ptr ); - if( it == m_visData.end() ) - { - it = m_visData.emplace( ptr, VisData {} ).first; - } - return it->second; - } - private: std::vector m_items; unordered_flat_map> m_itemMap; - unordered_flat_map m_visData; - float m_height; float m_offset; float m_scroll; diff --git a/server/TracyView.cpp b/server/TracyView.cpp index c06c50eb..caf6f5e7 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -840,7 +840,7 @@ bool View::DrawImpl() if( ImGui::SmallButton( " " ICON_FA_CARET_LEFT " " ) ) ZoomToPrevFrame(); ImGui::SameLine(); { - const auto vis = m_tc.Vis( m_frames ).visible; + const auto vis = Vis( m_frames ); if( !vis ) { ImGui::PushStyleColor( ImGuiCol_Text, GImGui->Style.Colors[ImGuiCol_TextDisabled] ); diff --git a/server/TracyView.hpp b/server/TracyView.hpp index 10e7e815..0be47b75 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -392,6 +392,13 @@ private: static const char* DecodeContextSwitchReason( uint8_t reason ); static const char* DecodeContextSwitchReasonCode( uint8_t reason ); + tracy_force_inline bool& Vis( const void* ptr ) + { + auto it = m_visMap.find( ptr ); + if( it == m_visMap.end() ) it = m_visMap.emplace( ptr, true ).first; + return it->second; + } + Worker m_worker; std::string m_filename, m_filenameStaging; bool m_staticView; @@ -561,6 +568,8 @@ private: unordered_flat_map m_statCache; unordered_flat_map m_gpuStatCache; + unordered_flat_map m_visMap; + void(*m_cbMainThread)(std::function, bool); int m_gpuIdx = 0; diff --git a/server/TracyView_Locks.cpp b/server/TracyView_Locks.cpp index 52126451..83f3371f 100644 --- a/server/TracyView_Locks.cpp +++ b/server/TracyView_Locks.cpp @@ -362,7 +362,7 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos, for( const auto& v : m_worker.GetLockMap() ) { const auto& lockmap = *v.second; - if( !lockmap.valid || !m_tc.Vis( &lockmap ).visible ) continue; + if( !lockmap.valid || !Vis( &lockmap ) ) continue; if( m_vd.onlyContendedLocks && ( lockmap.threadList.size() == 1 || !lockmap.isContended ) && m_lockInfoWindow != v.first ) continue; auto it = lockmap.threadMap.find( tid ); diff --git a/server/TracyView_NotificationArea.cpp b/server/TracyView_NotificationArea.cpp index c3413ca8..c776fbe3 100644 --- a/server/TracyView_NotificationArea.cpp +++ b/server/TracyView_NotificationArea.cpp @@ -189,9 +189,9 @@ void View::DrawNotificationArea() } { bool hidden = false; - for( auto& v : m_tc.GetVisData() ) + for( auto& v : m_visMap ) { - if( !v.second.visible ) + if( !v.second ) { hidden = true; break; diff --git a/server/TracyView_Options.cpp b/server/TracyView_Options.cpp index 352907bd..b7f887d6 100644 --- a/server/TracyView_Options.cpp +++ b/server/TracyView_Options.cpp @@ -283,7 +283,7 @@ void View::DrawOptions() { for( const auto& l : m_worker.GetLockMap() ) { - m_tc.Vis( l.second ).visible = true; + Vis( l.second ) = true; } } ImGui::SameLine(); @@ -291,7 +291,7 @@ void View::DrawOptions() { for( const auto& l : m_worker.GetLockMap() ) { - m_tc.Vis( l.second ).visible = false; + Vis( l.second ) = false; } } ImGui::SameLine(); @@ -307,7 +307,7 @@ void View::DrawOptions() { for( const auto& l : m_worker.GetLockMap() ) { - if( l.second->threadList.size() != 1 && l.second->isContended ) m_tc.Vis( l.second ).visible = true; + if( l.second->threadList.size() != 1 && l.second->isContended ) Vis( l.second ) = true; } } ImGui::SameLine(); @@ -315,7 +315,7 @@ void View::DrawOptions() { for( const auto& l : m_worker.GetLockMap() ) { - if( l.second->threadList.size() != 1 && l.second->isContended ) m_tc.Vis( l.second ).visible = false; + if( l.second->threadList.size() != 1 && l.second->isContended ) Vis( l.second ) = false; } } @@ -335,7 +335,7 @@ void View::DrawOptions() { sprintf( buf, "%" PRIu32 ": %s", l.first, m_worker.GetString( m_worker.GetSourceLocation( l.second->srcloc ).function ) ); } - SmallCheckbox( buf, &m_tc.Vis( l.second ).visible ); + SmallCheckbox( buf, &Vis( l.second ) ); if( ImGui::IsItemHovered() ) { m_lockHoverHighlight = l.first; @@ -385,7 +385,7 @@ void View::DrawOptions() { for( const auto& l : m_worker.GetLockMap() ) { - if( l.second->threadList.size() != 1 && !l.second->isContended ) m_tc.Vis( l.second ).visible = true; + if( l.second->threadList.size() != 1 && !l.second->isContended ) Vis( l.second ) = true; } } ImGui::SameLine(); @@ -393,7 +393,7 @@ void View::DrawOptions() { for( const auto& l : m_worker.GetLockMap() ) { - if( l.second->threadList.size() != 1 && !l.second->isContended ) m_tc.Vis( l.second ).visible = false; + if( l.second->threadList.size() != 1 && !l.second->isContended ) Vis( l.second ) = false; } } @@ -413,7 +413,7 @@ void View::DrawOptions() { sprintf( buf, "%" PRIu32 ": %s", l.first, m_worker.GetString( m_worker.GetSourceLocation( l.second->srcloc ).function ) ); } - SmallCheckbox( buf, &m_tc.Vis( l.second ).visible ); + SmallCheckbox( buf, &Vis( l.second ) ); if( ImGui::IsItemHovered() ) { m_lockHoverHighlight = l.first; @@ -463,7 +463,7 @@ void View::DrawOptions() { for( const auto& l : m_worker.GetLockMap() ) { - if( l.second->threadList.size() == 1 ) m_tc.Vis( l.second ).visible = true; + if( l.second->threadList.size() == 1 ) Vis( l.second ) = true; } } ImGui::SameLine(); @@ -471,7 +471,7 @@ void View::DrawOptions() { for( const auto& l : m_worker.GetLockMap() ) { - if( l.second->threadList.size() == 1 ) m_tc.Vis( l.second ).visible = false; + if( l.second->threadList.size() == 1 ) Vis( l.second ) = false; } } @@ -491,7 +491,7 @@ void View::DrawOptions() { sprintf( buf, "%" PRIu32 ": %s", l.first, m_worker.GetString( m_worker.GetSourceLocation( l.second->srcloc ).function ) ); } - SmallCheckbox( buf, &m_tc.Vis( l.second ).visible ); + SmallCheckbox( buf, &Vis( l.second ) ); if( ImGui::IsItemHovered() ) { m_lockHoverHighlight = l.first; @@ -707,7 +707,7 @@ void View::DrawOptions() { for( const auto& fd : m_worker.GetFrames() ) { - m_tc.Vis( fd ).visible = true; + Vis( fd ) = true; } } ImGui::SameLine(); @@ -715,7 +715,7 @@ void View::DrawOptions() { for( const auto& fd : m_worker.GetFrames() ) { - m_tc.Vis( fd ).visible = false; + Vis( fd ) = false; } } @@ -723,7 +723,7 @@ void View::DrawOptions() for( const auto& fd : m_worker.GetFrames() ) { ImGui::PushID( idx++ ); - SmallCheckbox( GetFrameSetName( *fd ), &m_tc.Vis( fd ).visible ); + SmallCheckbox( GetFrameSetName( *fd ), &Vis( fd ) ); ImGui::PopID(); ImGui::SameLine(); ImGui::TextDisabled( "%s %sframes", RealToString( fd->frames.size() ), fd->continuous ? "" : "discontinuous " ); diff --git a/server/TracyView_Timeline.cpp b/server/TracyView_Timeline.cpp index 41ab3994..998f4d71 100644 --- a/server/TracyView_Timeline.cpp +++ b/server/TracyView_Timeline.cpp @@ -301,7 +301,7 @@ void View::DrawTimeline() auto& frames = m_worker.GetFrames(); for( auto fd : frames ) { - if( m_tc.Vis( fd ).visible ) + if( Vis( fd ) ) { DrawTimelineFrames( *fd ); }