mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-30 01:04:36 +00:00
Save/load annotations.
This commit is contained in:
parent
c2f38d0db7
commit
e462335f83
@ -11,9 +11,11 @@ namespace tracy
|
||||
constexpr auto FileDescription = "description";
|
||||
constexpr auto FileTimeline = "timeline";
|
||||
constexpr auto FileOptions = "options";
|
||||
constexpr auto FileAnnotations = "annotations";
|
||||
|
||||
enum : uint32_t { VersionTimeline = 0 };
|
||||
enum : uint32_t { VersionOptions = 2 };
|
||||
enum : uint32_t { VersionAnnotations = 0 };
|
||||
|
||||
UserData::UserData()
|
||||
: m_preserveState( false )
|
||||
@ -143,6 +145,74 @@ void UserData::StateShouldBePreserved()
|
||||
m_preserveState = true;
|
||||
}
|
||||
|
||||
void UserData::LoadAnnotations( std::vector<std::unique_ptr<Annotation>>& data )
|
||||
{
|
||||
assert( Valid() );
|
||||
FILE* f = OpenFile( FileAnnotations, false );
|
||||
if( f )
|
||||
{
|
||||
uint32_t ver;
|
||||
fread( &ver, 1, sizeof( ver ), f );
|
||||
if( ver == VersionAnnotations )
|
||||
{
|
||||
uint32_t sz;
|
||||
fread( &sz, 1, sizeof( sz ), f );
|
||||
for( uint32_t i=0; i<sz; i++ )
|
||||
{
|
||||
auto ann = std::make_unique<Annotation>();
|
||||
|
||||
uint32_t tsz;
|
||||
fread( &tsz, 1, sizeof( tsz ), f );
|
||||
if( tsz != 0 )
|
||||
{
|
||||
char buf[1024];
|
||||
assert( tsz < 1024 );
|
||||
fread( buf, 1, tsz, f );
|
||||
ann->text.assign( buf, tsz );
|
||||
}
|
||||
fread( &ann->start, 1, sizeof( ann->start ), f );
|
||||
fread( &ann->end, 1, sizeof( ann->end ), f );
|
||||
fread( &ann->color, 1, sizeof( ann->color ), f );
|
||||
|
||||
data.emplace_back( std::move( ann ) );
|
||||
}
|
||||
}
|
||||
fclose( f );
|
||||
}
|
||||
}
|
||||
|
||||
void UserData::SaveAnnotations( const std::vector<std::unique_ptr<Annotation>>& data )
|
||||
{
|
||||
if( !m_preserveState ) return;
|
||||
if( data.empty() )
|
||||
{
|
||||
Remove( FileAnnotations );
|
||||
return;
|
||||
}
|
||||
assert( Valid() );
|
||||
FILE* f = OpenFile( FileAnnotations, true );
|
||||
if( f )
|
||||
{
|
||||
uint32_t ver = VersionAnnotations;
|
||||
fwrite( &ver, 1, sizeof( ver ), f );
|
||||
uint32_t sz = uint32_t( data.size() );
|
||||
fwrite( &sz, 1, sizeof( sz ), f );
|
||||
for( auto& ann : data )
|
||||
{
|
||||
sz = uint32_t( ann->text.size() );
|
||||
fwrite( &sz, 1, sizeof( sz ), f );
|
||||
if( sz != 0 )
|
||||
{
|
||||
fwrite( ann->text.c_str(), 1, sz, f );
|
||||
}
|
||||
fwrite( &ann->start, 1, sizeof( ann->start ), f );
|
||||
fwrite( &ann->end, 1, sizeof( ann->end ), f );
|
||||
fwrite( &ann->color, 1, sizeof( ann->color ), f );
|
||||
}
|
||||
fclose( f );
|
||||
}
|
||||
}
|
||||
|
||||
FILE* UserData::OpenFile( const char* filename, bool write )
|
||||
{
|
||||
const auto path = GetSavePath( m_program.c_str(), m_time, filename, write );
|
||||
|
@ -1,13 +1,16 @@
|
||||
#ifndef __TRACYUSERDATA_HPP__
|
||||
#define __TRACYUSERDATA_HPP__
|
||||
|
||||
#include <memory>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
struct Annotation;
|
||||
struct ViewData;
|
||||
|
||||
class UserData
|
||||
@ -26,6 +29,9 @@ public:
|
||||
void SaveState( const ViewData& data );
|
||||
void StateShouldBePreserved();
|
||||
|
||||
void LoadAnnotations( std::vector<std::unique_ptr<Annotation>>& data );
|
||||
void SaveAnnotations( const std::vector<std::unique_ptr<Annotation>>& data );
|
||||
|
||||
private:
|
||||
FILE* OpenFile( const char* filename, bool write );
|
||||
void Remove( const char* filename );
|
||||
|
@ -151,12 +151,14 @@ View::View( FileRead& f, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont,
|
||||
SetViewToLastFrames();
|
||||
m_userData.StateShouldBePreserved();
|
||||
m_userData.LoadState( m_vd );
|
||||
m_userData.LoadAnnotations( m_annotations );
|
||||
}
|
||||
|
||||
View::~View()
|
||||
{
|
||||
m_worker.Shutdown();
|
||||
m_userData.SaveState( m_vd );
|
||||
m_userData.SaveAnnotations( m_annotations );
|
||||
|
||||
if( m_compare.loadThread.joinable() ) m_compare.loadThread.join();
|
||||
if( m_saveThread.joinable() ) m_saveThread.join();
|
||||
|
Loading…
Reference in New Issue
Block a user