From a1c465baafbaa998572e6715ee5e3d49f1b23eb4 Mon Sep 17 00:00:00 2001 From: Daniel Simpkins Date: Sun, 22 Jan 2023 11:14:04 -0500 Subject: [PATCH] Use rom hash for playtime identifier. Fixed issue with double counting time when switching to fullscreen mode. --- Source/Project64-core/RomList/RomList.cpp | 12 ++++++++---- Source/Project64-core/RomList/RomList.h | 4 ++-- Source/Project64/UserInterface/MainWindow.cpp | 13 ++++++++----- Source/Project64/UserInterface/MainWindow.h | 2 +- Source/Project64/UserInterface/RomBrowser.cpp | 3 ++- 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/Source/Project64-core/RomList/RomList.cpp b/Source/Project64-core/RomList/RomList.cpp index 6cfcb4d1a..b98154c08 100644 --- a/Source/Project64-core/RomList/RomList.cpp +++ b/Source/Project64-core/RomList/RomList.cpp @@ -90,14 +90,18 @@ CRomList::~CRomList() WriteTrace(TraceRomList, TraceVerbose, "Done"); } -uint32_t CRomList::LoadPlaytime(const std::string & ApplicationName) +uint32_t CRomList::LoadPlaytime(const std::string & RomIniKey) { - return m_PlaytimeFile->GetNumber(ApplicationName.c_str(), "Playtime", 0); + return m_PlaytimeFile->GetNumber(RomIniKey.c_str(), "Playtime", 0); } -void CRomList::SavePlaytime(const std::string & ApplicationName, uint32_t Playtime) +void CRomList::SavePlaytime(uint32_t ElapsedPlaytime) { - m_PlaytimeFile->SaveNumber(ApplicationName.c_str(), "Playtime", Playtime); + auto RomIniKey = g_Settings->LoadStringVal(Game_IniKey); + auto CurrentPlaytime = LoadPlaytime(RomIniKey); + auto RomGoodName = g_Settings->LoadStringVal(Rdb_GoodName); + m_PlaytimeFile->SaveString(RomIniKey.c_str(), "Name", RomGoodName.c_str()); + m_PlaytimeFile->SaveNumber(RomIniKey.c_str(), "Playtime", CurrentPlaytime + ElapsedPlaytime); } void CRomList::RefreshRomList(void) diff --git a/Source/Project64-core/RomList/RomList.h b/Source/Project64-core/RomList/RomList.h index aeb856029..82764af1d 100644 --- a/Source/Project64-core/RomList/RomList.h +++ b/Source/Project64-core/RomList/RomList.h @@ -54,8 +54,8 @@ public: void RefreshRomList(void); void LoadRomList(void); - uint32_t LoadPlaytime(const std::string & ApplicationName); - void SavePlaytime(const std::string & ApplicationName, uint32_t Playtime); + uint32_t LoadPlaytime(const std::string & RomIniKey); + void SavePlaytime(uint32_t ElapsedPlaytime); protected: typedef std::vector ROMINFO_LIST; diff --git a/Source/Project64/UserInterface/MainWindow.cpp b/Source/Project64/UserInterface/MainWindow.cpp index e1c8e09ee..0a7726558 100644 --- a/Source/Project64/UserInterface/MainWindow.cpp +++ b/Source/Project64/UserInterface/MainWindow.cpp @@ -229,17 +229,20 @@ void CMainGui::GamePaused(CMainGui * Gui) void CMainGui::SavePlaytime() { - auto Now = std::chrono::steady_clock::now(); - uint32_t Elapsed = std::chrono::duration_cast(Now - m_CurrentPlaytime).count(); - auto PastPlaytime = CRomList::LoadPlaytime(g_Settings->LoadStringVal(Rdb_GoodName)); - CRomList::SavePlaytime(g_Settings->LoadStringVal(Rdb_GoodName), PastPlaytime + Elapsed); + if (m_CurrentPlaytime.second) + { + auto Now = std::chrono::steady_clock::now(); + auto ElapsedPlaytime = std::chrono::duration_cast(Now - m_CurrentPlaytime.first).count(); + CRomList::SavePlaytime(static_cast(ElapsedPlaytime)); + m_CurrentPlaytime.second = false; + } } void CMainGui::GameCpuRunning(CMainGui * Gui) { if (g_Settings->LoadBool(GameRunning_CPU_Running)) { - Gui->m_CurrentPlaytime = std::chrono::steady_clock::now(); + Gui->m_CurrentPlaytime = {std::chrono::steady_clock::now(), true}; Gui->MakeWindowOnTop(UISettingsLoadBool(UserInterface_AlwaysOnTop)); Gui->HideRomList(); if (UISettingsLoadBool(Setting_AutoFullscreen)) diff --git a/Source/Project64/UserInterface/MainWindow.h b/Source/Project64/UserInterface/MainWindow.h index ce95936e0..3fdf571f0 100644 --- a/Source/Project64/UserInterface/MainWindow.h +++ b/Source/Project64/UserInterface/MainWindow.h @@ -159,5 +159,5 @@ private: LONG m_SaveRomBrowserTop; LONG m_SaveRomBrowserLeft; - std::chrono::steady_clock::time_point m_CurrentPlaytime; + std::pair m_CurrentPlaytime; }; diff --git a/Source/Project64/UserInterface/RomBrowser.cpp b/Source/Project64/UserInterface/RomBrowser.cpp index 427a80017..9c8f1263e 100644 --- a/Source/Project64/UserInterface/RomBrowser.cpp +++ b/Source/Project64/UserInterface/RomBrowser.cpp @@ -848,7 +848,8 @@ void CRomBrowser::RomList_GetDispInfo(uint32_t pnmh) break; case RB_Playtime: { - auto Playtime = LoadPlaytime(stdstr(pRomInfo->GoodName)); + auto RomIdent = stdstr_f("%08X-%08X-C:%X", pRomInfo->CRC1, pRomInfo->CRC2, pRomInfo->Country); + auto Playtime = LoadPlaytime(RomIdent); swprintf(lpdi->item.pszText, lpdi->item.cchTextMax / sizeof(wchar_t), L"%02d:%02d:%02d", Playtime / 3600, (Playtime / 60) % 60, Playtime % 60); break; }