From 1d0203ac17eeb454ddc53715c508ec226fec5afe Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 5 Aug 2018 16:45:34 +0200 Subject: [PATCH] Abstracted away one-frame-decay values. --- server/TracyDecayValue.hpp | 47 ++++++++++++++++++++ server/TracyView.cpp | 26 +---------- server/TracyView.hpp | 7 ++- standalone/build/win32/Tracy.vcxproj | 1 + standalone/build/win32/Tracy.vcxproj.filters | 3 ++ 5 files changed, 56 insertions(+), 28 deletions(-) create mode 100644 server/TracyDecayValue.hpp diff --git a/server/TracyDecayValue.hpp b/server/TracyDecayValue.hpp new file mode 100644 index 00000000..746a9b65 --- /dev/null +++ b/server/TracyDecayValue.hpp @@ -0,0 +1,47 @@ +#ifndef __TRACYDECAYVALUE_HPP__ +#define __TRACYDECAYVALUE_HPP__ + +#include "../common/TracyForceInline.hpp" + +namespace tracy +{ + +template +class DecayValue +{ +public: + DecayValue( const T& init ) + : m_value( init ) + , m_active( false ) + { + } + + tracy_force_inline operator const T& () const { return m_value; } + + tracy_force_inline DecayValue& operator=( const T& value ) + { + m_value = value; + m_active = true; + return *this; + } + + tracy_force_inline void Decay( const T& value ) + { + if( m_active ) + { + m_active = false; + } + else + { + m_value = value; + } + } + +private: + T m_value; + bool m_active; +}; + +} + +#endif diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 532a04da..91716b6b 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -226,10 +226,8 @@ View::View( const char* addr ) , m_zvScroll( 0 ) , m_zoneInfoWindow( nullptr ) , m_zoneSrcLocHighlight( 0 ) - , m_zoneSrcLocHighlightActive( false ) , m_lockHighlight { -1 } , m_msgHighlight( nullptr ) - , m_msgHighlightActive( false ) , m_gpuInfoWindow( nullptr ) , m_callstackInfoWindow( 0 ) , m_memoryAllocInfoWindow( -1 ) @@ -270,9 +268,7 @@ View::View( FileRead& f ) , m_zvScroll( 0 ) , m_zoneInfoWindow( nullptr ) , m_zoneSrcLocHighlight( 0 ) - , m_zoneSrcLocHighlightActive( false ) , m_msgHighlight( nullptr ) - , m_msgHighlightActive( false ) , m_gpuInfoWindow( nullptr ) , m_callstackInfoWindow( 0 ) , m_memoryAllocInfoWindow( -1 ) @@ -1189,22 +1185,8 @@ bool View::DrawZoneFrames( const FrameData& frames ) void View::DrawZones() { - if( m_msgHighlightActive ) - { - m_msgHighlightActive = false; - } - else - { - m_msgHighlight = nullptr; - } - if( m_zoneSrcLocHighlightActive ) - { - m_zoneSrcLocHighlightActive = false; - } - else - { - m_zoneSrcLocHighlight = 0; - } + m_msgHighlight.Decay( nullptr ); + m_zoneSrcLocHighlight.Decay( 0 ); if( m_zvStart == m_zvEnd ) return; assert( m_zvStart < m_zvEnd ); @@ -1395,7 +1377,6 @@ void View::DrawZones() } ImGui::EndTooltip(); m_msgHighlight = *it; - m_msgHighlightActive = true; } it = next; } @@ -1617,7 +1598,6 @@ int View::DrawZoneLevel( const Vector& vec, bool hover, double pxns, } m_zoneSrcLocHighlight = ev.srcloc; - m_zoneSrcLocHighlightActive = true; } } char tmp[64]; @@ -1723,7 +1703,6 @@ int View::DrawZoneLevel( const Vector& vec, bool hover, double pxns, } m_zoneSrcLocHighlight = ev.srcloc; - m_zoneSrcLocHighlightActive = true; } ++it; @@ -3951,7 +3930,6 @@ void View::DrawMessages() if( ImGui::IsItemHovered() ) { m_msgHighlight = v; - m_msgHighlightActive = true; } ImGui::PopID(); ImGui::NextColumn(); diff --git a/server/TracyView.hpp b/server/TracyView.hpp index 565799e4..951bbebc 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -8,6 +8,7 @@ #include #include +#include "TracyDecayValue.hpp" #include "TracyVector.hpp" #include "TracyWorker.hpp" #include "tracy_flat_hash_map.hpp" @@ -185,11 +186,9 @@ private: const ZoneEvent* m_zoneInfoWindow; const ZoneEvent* m_zoneHighlight; - uint64_t m_zoneSrcLocHighlight; - bool m_zoneSrcLocHighlightActive; + DecayValue m_zoneSrcLocHighlight; LockHighlight m_lockHighlight; - const MessageData* m_msgHighlight; - bool m_msgHighlightActive; + DecayValue m_msgHighlight; const GpuEvent* m_gpuInfoWindow; const GpuEvent* m_gpuHighlight; uint64_t m_gpuInfoWindowThread; diff --git a/standalone/build/win32/Tracy.vcxproj b/standalone/build/win32/Tracy.vcxproj index c5a324aa..095cc03b 100644 --- a/standalone/build/win32/Tracy.vcxproj +++ b/standalone/build/win32/Tracy.vcxproj @@ -131,6 +131,7 @@ + diff --git a/standalone/build/win32/Tracy.vcxproj.filters b/standalone/build/win32/Tracy.vcxproj.filters index 9b336b01..04448419 100644 --- a/standalone/build/win32/Tracy.vcxproj.filters +++ b/standalone/build/win32/Tracy.vcxproj.filters @@ -191,6 +191,9 @@ server + + server +