mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 14:19:46 -06:00
Merge pull request #13507 from JosJuice/time-played-game-id
Core: Don't store game ID inside TimePlayed
This commit is contained in:
@ -78,17 +78,17 @@ void CPUManager::StartTimePlayedTimer()
|
|||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
const std::string game_id = SConfig::GetInstance().GetGameID();
|
TimePlayed time_played;
|
||||||
TimePlayed time_played(game_id);
|
|
||||||
auto curr_time = timer.now();
|
auto curr_time = timer.now();
|
||||||
|
|
||||||
// Check that emulation is not paused
|
// Check that emulation is not paused
|
||||||
// If the emulation is paused, wait for SetStepping() to reactivate
|
// If the emulation is paused, wait for SetStepping() to reactivate
|
||||||
if (m_state == State::Running)
|
if (m_state == State::Running)
|
||||||
{
|
{
|
||||||
|
const std::string game_id = SConfig::GetInstance().GetGameID();
|
||||||
const auto diff_time =
|
const auto diff_time =
|
||||||
std::chrono::duration_cast<std::chrono::milliseconds>(curr_time - prev_time);
|
std::chrono::duration_cast<std::chrono::milliseconds>(curr_time - prev_time);
|
||||||
time_played.AddTime(diff_time);
|
time_played.AddTime(game_id, diff_time);
|
||||||
}
|
}
|
||||||
else if (m_state == State::Stepping)
|
else if (m_state == State::Stepping)
|
||||||
{
|
{
|
||||||
|
@ -11,47 +11,23 @@
|
|||||||
#include "Common/IniFile.h"
|
#include "Common/IniFile.h"
|
||||||
#include "Common/NandPaths.h"
|
#include "Common/NandPaths.h"
|
||||||
|
|
||||||
TimePlayed::TimePlayed()
|
TimePlayed::TimePlayed() : m_ini_path(File::GetUserPath(D_CONFIG_IDX) + "TimePlayed.ini")
|
||||||
: m_game_id(""), m_ini_path(File::GetUserPath(D_CONFIG_IDX) + "TimePlayed.ini")
|
|
||||||
{
|
|
||||||
Reload();
|
|
||||||
}
|
|
||||||
|
|
||||||
TimePlayed::TimePlayed(std::string game_id)
|
|
||||||
: m_game_id(Common::EscapeFileName(game_id)), // filter for unsafe characters
|
|
||||||
m_ini_path(File::GetUserPath(D_CONFIG_IDX) + "TimePlayed.ini")
|
|
||||||
{
|
{
|
||||||
Reload();
|
Reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
TimePlayed::~TimePlayed() = default;
|
TimePlayed::~TimePlayed() = default;
|
||||||
|
|
||||||
void TimePlayed::AddTime(std::chrono::milliseconds time_emulated)
|
void TimePlayed::AddTime(const std::string& game_id, std::chrono::milliseconds time_emulated)
|
||||||
{
|
{
|
||||||
if (m_game_id == "")
|
std::string filtered_game_id = Common::EscapeFileName(game_id);
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
u64 previous_time;
|
u64 previous_time;
|
||||||
m_time_list->Get(m_game_id, &previous_time);
|
m_time_list->Get(filtered_game_id, &previous_time);
|
||||||
m_time_list->Set(m_game_id, previous_time + static_cast<u64>(time_emulated.count()));
|
m_time_list->Set(filtered_game_id, previous_time + static_cast<u64>(time_emulated.count()));
|
||||||
m_ini.Save(m_ini_path);
|
m_ini.Save(m_ini_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::chrono::milliseconds TimePlayed::GetTimePlayed() const
|
std::chrono::milliseconds TimePlayed::GetTimePlayed(const std::string& game_id) const
|
||||||
{
|
|
||||||
if (m_game_id == "")
|
|
||||||
{
|
|
||||||
return std::chrono::milliseconds(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
u64 previous_time;
|
|
||||||
m_time_list->Get(m_game_id, &previous_time);
|
|
||||||
return std::chrono::milliseconds(previous_time);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::chrono::milliseconds TimePlayed::GetTimePlayed(std::string game_id) const
|
|
||||||
{
|
{
|
||||||
std::string filtered_game_id = Common::EscapeFileName(game_id);
|
std::string filtered_game_id = Common::EscapeFileName(game_id);
|
||||||
u64 previous_time;
|
u64 previous_time;
|
||||||
|
@ -12,11 +12,8 @@
|
|||||||
class TimePlayed
|
class TimePlayed
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// used for QT interface - general access to time played for games
|
|
||||||
TimePlayed();
|
TimePlayed();
|
||||||
|
|
||||||
TimePlayed(std::string game_id);
|
|
||||||
|
|
||||||
// not copyable due to the stored section pointer
|
// not copyable due to the stored section pointer
|
||||||
TimePlayed(const TimePlayed& other) = delete;
|
TimePlayed(const TimePlayed& other) = delete;
|
||||||
TimePlayed(TimePlayed&& other) = delete;
|
TimePlayed(TimePlayed&& other) = delete;
|
||||||
@ -25,15 +22,13 @@ public:
|
|||||||
|
|
||||||
~TimePlayed();
|
~TimePlayed();
|
||||||
|
|
||||||
void AddTime(std::chrono::milliseconds time_emulated);
|
void AddTime(const std::string& game_id, std::chrono::milliseconds time_emulated);
|
||||||
|
|
||||||
std::chrono::milliseconds GetTimePlayed() const;
|
std::chrono::milliseconds GetTimePlayed(const std::string& game_id) const;
|
||||||
std::chrono::milliseconds GetTimePlayed(std::string game_id) const;
|
|
||||||
|
|
||||||
void Reload();
|
void Reload();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_game_id;
|
|
||||||
std::string m_ini_path;
|
std::string m_ini_path;
|
||||||
Common::IniFile m_ini;
|
Common::IniFile m_ini;
|
||||||
Common::IniFile::Section* m_time_list;
|
Common::IniFile::Section* m_time_list;
|
||||||
|
Reference in New Issue
Block a user