diff --git a/src/core/host_interface.cpp b/src/core/host_interface.cpp index 4083bd828..fc369dedb 100644 --- a/src/core/host_interface.cpp +++ b/src/core/host_interface.cpp @@ -438,7 +438,7 @@ void HostInterface::UpdateSpeedLimiterState() void HostInterface::OnPerformanceCountersUpdated() {} -void HostInterface::OnRunningGameChanged(const char* path, const char* game_code, const char* game_title) {} +void HostInterface::OnRunningGameChanged() {} void HostInterface::SetUserDirectory() { @@ -540,31 +540,3 @@ void HostInterface::ResetPerformanceCounters() m_worst_frame_time_accumulator = 0.0f; m_fps_timer.Reset(); } - -void HostInterface::UpdateRunningGame(const char* path, CDImage* image) -{ - if (!path || std::strlen(path) == 0) - { - OnRunningGameChanged("", "", ""); - return; - } - - const GameListEntry* list_entry = m_game_list->GetEntryForPath(path); - if (list_entry) - { - OnRunningGameChanged(path, list_entry->code.c_str(), list_entry->title.c_str()); - return; - } - - const std::string game_code = image ? GameList::GetGameCodeForImage(image) : std::string(); - const GameListDatabaseEntry* db_entry = - (!game_code.empty()) ? m_game_list->GetDatabaseEntryForCode(game_code) : nullptr; - if (!db_entry) - { - const std::string game_title(GameList::GetTitleForPath(path)); - OnRunningGameChanged(path, game_code.c_str(), game_title.c_str()); - return; - } - - OnRunningGameChanged(path, db_entry->code.c_str(), db_entry->title.c_str()); -} diff --git a/src/core/host_interface.h b/src/core/host_interface.h index f300e5cb8..64cdfdf2a 100644 --- a/src/core/host_interface.h +++ b/src/core/host_interface.h @@ -86,7 +86,7 @@ protected: }; virtual void OnPerformanceCountersUpdated(); - virtual void OnRunningGameChanged(const char* path, const char* game_code, const char* game_title); + virtual void OnRunningGameChanged(); void SetUserDirectory(); @@ -108,8 +108,6 @@ protected: void UpdatePerformanceCounters(); void ResetPerformanceCounters(); - void UpdateRunningGame(const char* path, CDImage* image); - std::unique_ptr m_display; std::unique_ptr m_audio_stream; std::unique_ptr m_system; diff --git a/src/core/system.cpp b/src/core/system.cpp index 5a7e41b93..95acf7948 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -155,7 +155,7 @@ bool System::Boot(const char* filename) } // Notify change of disc. - m_host_interface->UpdateRunningGame(filename, media.get()); + UpdateRunningGame(filename, media.get()); // Insert CD, and apply fastboot patch if enabled. m_cdrom->InsertMedia(std::move(media)); @@ -251,7 +251,7 @@ bool System::DoState(StateWrapper& sw) Log_ErrorPrintf("Failed to open CD image from save state: '%s'", media_filename.c_str()); } - m_host_interface->UpdateRunningGame(media_filename.c_str(), media.get()); + UpdateRunningGame(media_filename.c_str(), media.get()); if (media) m_cdrom->InsertMedia(std::move(media)); else @@ -516,6 +516,7 @@ bool System::InsertMedia(const char* path) if (!image) return false; + UpdateRunningGame(path, image.get()); m_cdrom->InsertMedia(std::move(image)); return true; } @@ -524,3 +525,37 @@ void System::RemoveMedia() { m_cdrom->RemoveMedia(); } + +void System::UpdateRunningGame(const char* path, CDImage* image) +{ + m_running_game_path.clear(); + m_running_game_code.clear(); + m_running_game_title.clear(); + + if (path && std::strlen(path) > 0) + { + m_running_game_path = path; + + const GameListEntry* list_entry = m_host_interface->GetGameList()->GetEntryForPath(path); + if (list_entry) + { + m_running_game_code = list_entry->code; + m_running_game_title = list_entry->title; + } + else + { + if (image) + m_running_game_code = GameList::GetGameCodeForImage(image); + + const GameListDatabaseEntry* db_entry = + (!m_running_game_code.empty()) ? m_host_interface->GetGameList()->GetDatabaseEntryForCode(m_running_game_code) : + nullptr; + if (db_entry) + m_running_game_title = db_entry->title; + else + m_running_game_title = GameList::GetTitleForPath(path); + } + } + + m_host_interface->OnRunningGameChanged(); +} diff --git a/src/core/system.h b/src/core/system.h index 1f78664c4..2b193f6cb 100644 --- a/src/core/system.h +++ b/src/core/system.h @@ -1,8 +1,9 @@ #pragma once -#include "types.h" #include "host_interface.h" +#include "types.h" #include #include +#include class ByteStream; class CDImage; @@ -11,7 +12,7 @@ class StateWrapper; namespace CPU { class Core; class CodeCache; -} +} // namespace CPU class Bus; class DMA; @@ -56,6 +57,10 @@ public: const Settings& GetSettings() { return m_host_interface->GetSettings(); } + const std::string& GetRunningPath() const { return m_running_game_path; } + const std::string& GetRunningCode() const { return m_running_game_code; } + const std::string& GetRunningTitle() const { return m_running_game_title; } + bool Boot(const char* filename); void Reset(); @@ -94,6 +99,8 @@ private: void InitializeComponents(); + void UpdateRunningGame(const char* path, CDImage* image); + HostInterface* m_host_interface; std::unique_ptr m_cpu; std::unique_ptr m_cpu_code_cache; @@ -112,4 +119,8 @@ private: u32 m_frame_number = 1; u32 m_internal_frame_number = 1; u32 m_global_tick_counter = 0; + + std::string m_running_game_path; + std::string m_running_game_code; + std::string m_running_game_title; }; diff --git a/src/duckstation-qt/qthostinterface.cpp b/src/duckstation-qt/qthostinterface.cpp index 225fc3c14..ee3ad17b9 100644 --- a/src/duckstation-qt/qthostinterface.cpp +++ b/src/duckstation-qt/qthostinterface.cpp @@ -247,11 +247,20 @@ void QtHostInterface::OnPerformanceCountersUpdated() emit performanceCountersUpdated(m_speed, m_fps, m_vps, m_average_frame_time, m_worst_frame_time); } -void QtHostInterface::OnRunningGameChanged(const char* path, const char* game_code, const char* game_title) +void QtHostInterface::OnRunningGameChanged() { - HostInterface::OnRunningGameChanged(path, game_code, game_title); + HostInterface::OnRunningGameChanged(); - emit runningGameChanged(QString::fromUtf8(path), QString::fromUtf8(game_code), QString::fromUtf8(game_title)); + if (m_system) + { + emit runningGameChanged(QString::fromStdString(m_system->GetRunningPath()), + QString::fromStdString(m_system->GetRunningCode()), + QString::fromStdString(m_system->GetRunningTitle())); + } + else + { + emit runningGameChanged(QString(), QString(), QString()); + } } void QtHostInterface::updateInputMap() diff --git a/src/duckstation-qt/qthostinterface.h b/src/duckstation-qt/qthostinterface.h index ddb91e15e..1e616216c 100644 --- a/src/duckstation-qt/qthostinterface.h +++ b/src/duckstation-qt/qthostinterface.h @@ -88,7 +88,7 @@ private Q_SLOTS: protected: void OnPerformanceCountersUpdated() override; - void OnRunningGameChanged(const char* path, const char* game_code, const char* game_title) override; + void OnRunningGameChanged() override; private: using InputButtonHandler = std::function;