Save/load view state.

This commit is contained in:
Bartosz Taudul 2019-08-28 19:45:22 +02:00
parent dc5444ff0f
commit f37797db44
3 changed files with 38 additions and 0 deletions

View File

@ -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;

View File

@ -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:

View File

@ -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();