Compare commits

...

3 Commits

Author SHA1 Message Date
Daniel Simpkins da1ce99ff6
Merge a1c465baaf into 290040d945 2024-02-28 22:56:20 -07:00
Daniel Simpkins a1c465baaf Use rom hash for playtime identifier.
Fixed issue with double counting time when switching to fullscreen mode.
2023-01-23 21:43:28 -05:00
Daniel Simpkins a2c356f16e Core: Added playtime counter on a per ROM basis. 2023-01-21 18:18:38 -05:00
10 changed files with 54 additions and 0 deletions

View File

@ -195,6 +195,7 @@ enum LanguageStringID
RB_FORCE_FEEDBACK = 318,
RB_FILE_FORMAT = 319,
RB_NAME = 321,
RB_PLAYTIME = 3114,
// Select ROM
SELECT_ROM_DIR = 320,

View File

@ -145,6 +145,7 @@ void CLanguage::LoadDefaultStrings(void)
DEF_STR(RB_FORCE_FEEDBACK, "Force Feedback");
DEF_STR(RB_FILE_FORMAT, "File Format");
DEF_STR(RB_NAME, "Name");
DEF_STR(RB_PLAYTIME, "Playtime");
// Select ROM
DEF_STR(SELECT_ROM_DIR, "Select current ROM directory");

View File

@ -44,6 +44,7 @@ CRomList::CRomList() :
m_NotesIniFile = new CIniFile(g_Settings->LoadStringVal(SupportFile_Notes).c_str());
m_ExtIniFile = new CIniFile(g_Settings->LoadStringVal(SupportFile_ExtInfo).c_str());
m_RomIniFile = new CIniFile(g_Settings->LoadStringVal(SupportFile_RomDatabase).c_str());
m_PlaytimeFile = std::make_unique<CIniFile>(g_Settings->LoadStringVal(SupportFile_Playtime).c_str());
#ifdef _WIN32
m_ZipIniFile = new CIniFile(g_Settings->LoadStringVal(RomList_7zipCache).c_str());
#endif
@ -89,6 +90,20 @@ CRomList::~CRomList()
WriteTrace(TraceRomList, TraceVerbose, "Done");
}
uint32_t CRomList::LoadPlaytime(const std::string & RomIniKey)
{
return m_PlaytimeFile->GetNumber(RomIniKey.c_str(), "Playtime", 0);
}
void CRomList::SavePlaytime(uint32_t ElapsedPlaytime)
{
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)
{
if (m_RefreshThread.isRunning())

View File

@ -1,10 +1,13 @@
#pragma once
#include <Common/IniFile.h>
#include <Common/StdString.h>
#include <Common/Thread.h>
#include <Common/md5.h>
#include <Common/path.h>
#include <Project64-core/N64System/N64Types.h>
#include <memory>
#include <string>
class CRomList
{
@ -51,6 +54,9 @@ public:
void RefreshRomList(void);
void LoadRomList(void);
uint32_t LoadPlaytime(const std::string & RomIniKey);
void SavePlaytime(uint32_t ElapsedPlaytime);
protected:
typedef std::vector<ROM_INFO> ROMINFO_LIST;
@ -87,6 +93,7 @@ private:
CIniFile * m_NotesIniFile;
CIniFile * m_ExtIniFile;
CIniFile * m_RomIniFile;
std::unique_ptr<CIniFile> m_PlaytimeFile;
#ifdef _WIN32
CIniFile * m_ZipIniFile;
#endif

View File

@ -80,6 +80,8 @@ void CSettings::AddHowToHandleSetting(const char * BaseDirectory)
AddHandler(Cmd_ComboDiskFile, new CSettingTypeTempString(""));
// Support files
AddHandler(SupportFile_Playtime, new CSettingTypeApplicationPath("Settings", "Playtime", SupportFile_PlaytimeDefault));
AddHandler(SupportFile_PlaytimeDefault, new CSettingTypeRelativePath("Config", "Playtime.rdn"));
AddHandler(SupportFile_SettingsDirectory, new CSettingTypeTempString(""));
AddHandler(SupportFile_Settings, new CSettingTypeApplicationPath("Settings", "ConfigFile", SupportFile_SettingsDefault));
AddHandler(SupportFile_SettingsDefault, new CSettingTypeRelativePath("Config", "Project64.cfg"));

View File

@ -18,6 +18,8 @@ enum SettingID
Cmd_ShowHelp,
// Support files
SupportFile_Playtime,
SupportFile_PlaytimeDefault,
SupportFile_SettingsDirectory,
SupportFile_Settings,
SupportFile_SettingsDefault,

View File

@ -227,10 +227,22 @@ void CMainGui::GamePaused(CMainGui * Gui)
Gui->RefreshMenu();
}
void CMainGui::SavePlaytime()
{
if (m_CurrentPlaytime.second)
{
auto Now = std::chrono::steady_clock::now();
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)
{
if (g_Settings->LoadBool(GameRunning_CPU_Running))
{
Gui->m_CurrentPlaytime = {std::chrono::steady_clock::now(), true};
Gui->MakeWindowOnTop(UISettingsLoadBool(UserInterface_AlwaysOnTop));
Gui->HideRomList();
if (UISettingsLoadBool(Setting_AutoFullscreen))
@ -251,6 +263,7 @@ void CMainGui::GameCpuRunning(CMainGui * Gui)
}
else
{
Gui->SavePlaytime();
if (Gui->m_CheatsUI.m_hWnd != nullptr)
{
Gui->m_CheatsUI.SendMessage(WM_COMMAND, MAKELONG(IDCANCEL, 0));

View File

@ -7,6 +7,7 @@
#include <Project64/UserInterface/EnhancementUI.h>
#include <Project64/UserInterface/ProjectSupport.h>
#include <Project64/UserInterface/RomBrowser.h>
#include <chrono>
class CGfxPlugin; // Plugin that controls the rendering
class CAudioPlugin; // Plugin for audio, need the hwnd
@ -119,6 +120,7 @@ private:
void AddRecentRom(const char * ImagePath);
void SetWindowCaption(const wchar_t * Caption);
void ShowRomBrowser(void);
void SavePlaytime(void);
static LRESULT CALLBACK MainGui_Proc(HWND, DWORD, WPARAM, LPARAM);
@ -156,4 +158,6 @@ private:
bool m_SaveRomBrowserPos;
LONG m_SaveRomBrowserTop;
LONG m_SaveRomBrowserLeft;
std::pair<std::chrono::steady_clock::time_point, bool> m_CurrentPlaytime;
};

View File

@ -59,6 +59,7 @@ void CRomBrowser::GetFieldInfo(ROMBROWSER_FIELDS_LIST & Fields, bool UseDefault
AddField(Fields, "Players", -1, RB_Players, 100, RB_PLAYERS, UseDefault);
AddField(Fields, "Force Feedback", -1, RB_ForceFeedback, 100, RB_FORCE_FEEDBACK, UseDefault);
AddField(Fields, "File Format", -1, RB_FileFormat, 100, RB_FILE_FORMAT, UseDefault);
AddField(Fields, "Playtime", -1, RB_Playtime, 200, RB_PLAYTIME, UseDefault);
}
int32_t CRomBrowser::CalcSortPosition(uint32_t lParam)
@ -845,6 +846,13 @@ void CRomBrowser::RomList_GetDispInfo(LPARAM pnmh)
default: swprintf(lpdi->item.pszText, lpdi->item.cchTextMax / sizeof(wchar_t), L"Unknown (%X)", pRomInfo->FileFormat); break;
}
break;
case RB_Playtime:
{
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;
}
default: wcsncpy(lpdi->item.pszText, L" ", lpdi->item.cchTextMax);
}
if (lpdi->item.pszText == nullptr || wcslen(lpdi->item.pszText) == 0)

View File

@ -146,6 +146,7 @@ private:
RB_Players = 18,
RB_ForceFeedback = 19,
RB_FileFormat = 20,
RB_Playtime = 21,
};
enum