From 9f0f3a721800788733fb4de3fa7bfcf990322698 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 16 Jun 2024 12:53:40 +0200 Subject: [PATCH] Save achievements data after each completion. --- profiler/src/profiler/TracyAchievements.cpp | 37 ++++++++++++--------- profiler/src/profiler/TracyAchievements.hpp | 1 + 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/profiler/src/profiler/TracyAchievements.cpp b/profiler/src/profiler/TracyAchievements.cpp index b70965b9..20df41b1 100644 --- a/profiler/src/profiler/TracyAchievements.cpp +++ b/profiler/src/profiler/TracyAchievements.cpp @@ -82,21 +82,7 @@ AchievementsMgr::AchievementsMgr() AchievementsMgr::~AchievementsMgr() { - const auto fn = tracy::GetSavePath( "achievements.ini" ); - FILE* f = fopen( fn, "wb" ); - if( !f ) return; - - for( auto& v : m_map ) - { - auto& it = v.second.item; - fprintf( f, "[%s]\n", it->id ); - fprintf( f, "unlockTime=%" PRIu64 "\n", it->unlockTime ); - fprintf( f, "doneTime=%" PRIu64 "\n", it->doneTime ); - fprintf( f, "hideCompleted=%d\n", it->hideCompleted ? 1 : 0 ); - fprintf( f, "hideNew=%d\n\n", it->hideNew ? 1 : 0 ); - } - - fclose( f ); + Save(); } void AchievementsMgr::Achieve( const char* id ) @@ -129,6 +115,8 @@ void AchievementsMgr::Achieve( const char* id ) c++; } } + + Save(); } data::AchievementCategory** AchievementsMgr::GetCategories() const @@ -200,4 +188,23 @@ void AchievementsMgr::FillMap( data::AchievementItem** items, data::AchievementC } } +void AchievementsMgr::Save() +{ + const auto fn = tracy::GetSavePath( "achievements.ini" ); + FILE* f = fopen( fn, "wb" ); + if( !f ) return; + + for( auto& v : m_map ) + { + auto& it = v.second.item; + fprintf( f, "[%s]\n", it->id ); + fprintf( f, "unlockTime=%" PRIu64 "\n", it->unlockTime ); + fprintf( f, "doneTime=%" PRIu64 "\n", it->doneTime ); + fprintf( f, "hideCompleted=%d\n", it->hideCompleted ? 1 : 0 ); + fprintf( f, "hideNew=%d\n\n", it->hideNew ? 1 : 0 ); + } + + fclose( f ); +} + } diff --git a/profiler/src/profiler/TracyAchievements.hpp b/profiler/src/profiler/TracyAchievements.hpp index 70200188..8ed64363 100644 --- a/profiler/src/profiler/TracyAchievements.hpp +++ b/profiler/src/profiler/TracyAchievements.hpp @@ -71,6 +71,7 @@ public: private: void FillMap( data::AchievementItem** items, data::AchievementCategory* category ); + void Save(); std::vector m_queue; tracy::unordered_flat_map m_map;