diff --git a/server/TracyUserData.cpp b/server/TracyUserData.cpp index 86eff760..712b2223 100644 --- a/server/TracyUserData.cpp +++ b/server/TracyUserData.cpp @@ -3,11 +3,15 @@ #include "TracyStorage.hpp" #include "TracyUserData.hpp" +#include "TracyViewData.hpp" namespace tracy { constexpr auto FileDescription = "description"; +constexpr auto FileTimeline = "timeline"; + +enum : uint32_t { VersionTimeline = 0 }; UserData::UserData() : m_preserveState( false ) @@ -53,6 +57,34 @@ bool UserData::SetDescription( const char* description ) return true; } +void UserData::LoadState( ViewData& data ) +{ + assert( Valid() ); + FILE* f = OpenFile( FileTimeline, false ); + if( !f ) return; + uint32_t ver; + fread( &ver, 1, sizeof( ver ), f ); + if( ver == VersionTimeline ) + { + fread( &data.zvStart, 1, sizeof( data.zvStart ), f ); + fread( &data.zvEnd, 1, sizeof( data.zvEnd ), f ); + } + fclose( f ); +} + +void UserData::SaveState( const ViewData& data ) +{ + if( !m_preserveState ) return; + assert( Valid() ); + FILE* f = OpenFile( FileTimeline, true ); + if( !f ) return; + uint32_t ver = VersionTimeline; + fwrite( &ver, 1, sizeof( ver ), f ); + fwrite( &data.zvStart, 1, sizeof( data.zvStart ), f ); + fwrite( &data.zvEnd, 1, sizeof( data.zvEnd ), f ); + fclose( f ); +} + void UserData::StateShouldBePreserved() { m_preserveState = true; diff --git a/server/TracyUserData.hpp b/server/TracyUserData.hpp index 3bc07943..8e8450e6 100644 --- a/server/TracyUserData.hpp +++ b/server/TracyUserData.hpp @@ -8,6 +8,8 @@ namespace tracy { +struct ViewData; + class UserData { public: @@ -20,6 +22,8 @@ public: const std::string& GetDescription() const { return m_description; } bool SetDescription( const char* description ); + void LoadState( ViewData& data ); + void SaveState( const ViewData& data ); void StateShouldBePreserved(); private: diff --git a/server/TracyView.cpp b/server/TracyView.cpp index c0b9fa77..14b59a49 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -149,11 +149,13 @@ View::View( FileRead& f, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, InitTextEditor(); SetViewToLastFrames(); m_userData.StateShouldBePreserved(); + m_userData.LoadState( m_vd ); } View::~View() { m_worker.Shutdown(); + m_userData.SaveState( m_vd ); if( m_compare.loadThread.joinable() ) m_compare.loadThread.join(); if( m_saveThread.joinable() ) m_saveThread.join();