mirror of
https://gitlab.com/Mr_Goldberg/goldberg_emulator.git
synced 2024-11-27 14:08:39 +01:00
Don't write stats to disk if value didn't change.
This commit is contained in:
parent
9eb7066098
commit
978a1b81e3
1 changed files with 23 additions and 2 deletions
|
@ -55,6 +55,9 @@ private:
|
||||||
nlohmann::json defined_achievements;
|
nlohmann::json defined_achievements;
|
||||||
nlohmann::json user_achievements;
|
nlohmann::json user_achievements;
|
||||||
std::vector<std::string> sorted_achievement_names;
|
std::vector<std::string> sorted_achievement_names;
|
||||||
|
std::map<std::string, int32> stats_cache_int;
|
||||||
|
std::map<std::string, float> stats_cache_float;
|
||||||
|
|
||||||
|
|
||||||
unsigned int find_leaderboard(std::string name)
|
unsigned int find_leaderboard(std::string name)
|
||||||
{
|
{
|
||||||
|
@ -200,8 +203,17 @@ bool SetStat( const char *pchName, int32 nData )
|
||||||
PRINT_DEBUG("SetStat int32 %s\n", pchName);
|
PRINT_DEBUG("SetStat int32 %s\n", pchName);
|
||||||
if (!pchName) return false;
|
if (!pchName) return false;
|
||||||
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
||||||
|
auto cached_stat = stats_cache_int.find(pchName);
|
||||||
|
if (cached_stat != stats_cache_int.end()) {
|
||||||
|
if (cached_stat->second == nData) return true;
|
||||||
|
}
|
||||||
|
|
||||||
return local_storage->store_data(Local_Storage::stats_storage_folder, pchName, (char* )&nData, sizeof(nData)) == sizeof(nData);
|
if (local_storage->store_data(Local_Storage::stats_storage_folder, pchName, (char* )&nData, sizeof(nData)) == sizeof(nData)) {
|
||||||
|
stats_cache_int[pchName] = nData;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SetStat( const char *pchName, float fData )
|
bool SetStat( const char *pchName, float fData )
|
||||||
|
@ -209,8 +221,17 @@ bool SetStat( const char *pchName, float fData )
|
||||||
PRINT_DEBUG("SetStat float %s\n", pchName);
|
PRINT_DEBUG("SetStat float %s\n", pchName);
|
||||||
if (!pchName) return false;
|
if (!pchName) return false;
|
||||||
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
||||||
|
auto cached_stat = stats_cache_float.find(pchName);
|
||||||
|
if (cached_stat != stats_cache_float.end()) {
|
||||||
|
if (cached_stat->second == fData) return true;
|
||||||
|
}
|
||||||
|
|
||||||
return local_storage->store_data(Local_Storage::stats_storage_folder, pchName, (char* )&fData, sizeof(fData)) == sizeof(fData);
|
if (local_storage->store_data(Local_Storage::stats_storage_folder, pchName, (char* )&fData, sizeof(fData)) == sizeof(fData)) {
|
||||||
|
stats_cache_float[pchName] = fData;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UpdateAvgRateStat( const char *pchName, float flCountThisSession, double dSessionLength )
|
bool UpdateAvgRateStat( const char *pchName, float flCountThisSession, double dSessionLength )
|
||||||
|
|
Loading…
Reference in a new issue