Use rom hash for playtime identifier.
Fixed issue with double counting time when switching to fullscreen mode.
This commit is contained in:
parent
a2c356f16e
commit
a1c465baaf
|
@ -90,14 +90,18 @@ CRomList::~CRomList()
|
||||||
WriteTrace(TraceRomList, TraceVerbose, "Done");
|
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)
|
void CRomList::RefreshRomList(void)
|
||||||
|
|
|
@ -54,8 +54,8 @@ public:
|
||||||
void RefreshRomList(void);
|
void RefreshRomList(void);
|
||||||
void LoadRomList(void);
|
void LoadRomList(void);
|
||||||
|
|
||||||
uint32_t LoadPlaytime(const std::string & ApplicationName);
|
uint32_t LoadPlaytime(const std::string & RomIniKey);
|
||||||
void SavePlaytime(const std::string & ApplicationName, uint32_t Playtime);
|
void SavePlaytime(uint32_t ElapsedPlaytime);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
typedef std::vector<ROM_INFO> ROMINFO_LIST;
|
typedef std::vector<ROM_INFO> ROMINFO_LIST;
|
||||||
|
|
|
@ -229,17 +229,20 @@ void CMainGui::GamePaused(CMainGui * Gui)
|
||||||
|
|
||||||
void CMainGui::SavePlaytime()
|
void CMainGui::SavePlaytime()
|
||||||
{
|
{
|
||||||
auto Now = std::chrono::steady_clock::now();
|
if (m_CurrentPlaytime.second)
|
||||||
uint32_t Elapsed = std::chrono::duration_cast<std::chrono::seconds>(Now - m_CurrentPlaytime).count();
|
{
|
||||||
auto PastPlaytime = CRomList::LoadPlaytime(g_Settings->LoadStringVal(Rdb_GoodName));
|
auto Now = std::chrono::steady_clock::now();
|
||||||
CRomList::SavePlaytime(g_Settings->LoadStringVal(Rdb_GoodName), PastPlaytime + Elapsed);
|
auto ElapsedPlaytime = std::chrono::duration_cast<std::chrono::seconds>(Now - m_CurrentPlaytime.first).count();
|
||||||
|
CRomList::SavePlaytime(static_cast<uint32_t>(ElapsedPlaytime));
|
||||||
|
m_CurrentPlaytime.second = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMainGui::GameCpuRunning(CMainGui * Gui)
|
void CMainGui::GameCpuRunning(CMainGui * Gui)
|
||||||
{
|
{
|
||||||
if (g_Settings->LoadBool(GameRunning_CPU_Running))
|
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->MakeWindowOnTop(UISettingsLoadBool(UserInterface_AlwaysOnTop));
|
||||||
Gui->HideRomList();
|
Gui->HideRomList();
|
||||||
if (UISettingsLoadBool(Setting_AutoFullscreen))
|
if (UISettingsLoadBool(Setting_AutoFullscreen))
|
||||||
|
|
|
@ -159,5 +159,5 @@ private:
|
||||||
LONG m_SaveRomBrowserTop;
|
LONG m_SaveRomBrowserTop;
|
||||||
LONG m_SaveRomBrowserLeft;
|
LONG m_SaveRomBrowserLeft;
|
||||||
|
|
||||||
std::chrono::steady_clock::time_point m_CurrentPlaytime;
|
std::pair<std::chrono::steady_clock::time_point, bool> m_CurrentPlaytime;
|
||||||
};
|
};
|
||||||
|
|
|
@ -848,7 +848,8 @@ void CRomBrowser::RomList_GetDispInfo(uint32_t pnmh)
|
||||||
break;
|
break;
|
||||||
case RB_Playtime:
|
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);
|
swprintf(lpdi->item.pszText, lpdi->item.cchTextMax / sizeof(wchar_t), L"%02d:%02d:%02d", Playtime / 3600, (Playtime / 60) % 60, Playtime % 60);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue