From fc2ec826d462881f94b324fb6971cc920200f093 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Fri, 5 Jan 2024 09:31:59 +0100 Subject: [PATCH] FifoPlayer: Move instance to System. --- Source/Core/Core/Boot/Boot.cpp | 2 +- Source/Core/Core/Core.cpp | 6 ++-- Source/Core/Core/FifoPlayer/FifoPlayer.cpp | 12 ++----- Source/Core/Core/FifoPlayer/FifoPlayer.h | 17 ++++++--- Source/Core/Core/HW/VideoInterface.cpp | 2 +- Source/Core/Core/System.cpp | 10 +++++- Source/Core/Core/System.h | 2 ++ Source/Core/DolphinQt/FIFO/FIFOAnalyzer.cpp | 26 +++++++------- Source/Core/DolphinQt/FIFO/FIFOAnalyzer.h | 5 ++- .../Core/DolphinQt/FIFO/FIFOPlayerWindow.cpp | 36 +++++++++---------- Source/Core/DolphinQt/FIFO/FIFOPlayerWindow.h | 5 ++- Source/Core/DolphinQt/MainWindow.cpp | 2 +- Source/Core/VideoCommon/BPStructs.cpp | 7 ++-- 13 files changed, 76 insertions(+), 56 deletions(-) diff --git a/Source/Core/Core/Boot/Boot.cpp b/Source/Core/Core/Boot/Boot.cpp index 9ea3d4dcb7..09dbaba403 100644 --- a/Source/Core/Core/Boot/Boot.cpp +++ b/Source/Core/Core/Boot/Boot.cpp @@ -652,7 +652,7 @@ bool CBoot::BootUp(Core::System& system, const Core::CPUThreadGuard& guard, bool operator()(const BootParameters::DFF& dff) const { NOTICE_LOG_FMT(BOOT, "Booting DFF: {}", dff.dff_path); - return FifoPlayer::GetInstance().Open(dff.dff_path); + return system.GetFifoPlayer().Open(dff.dff_path); } private: diff --git a/Source/Core/Core/Core.cpp b/Source/Core/Core/Core.cpp index 85b6e98e19..646fcfec47 100644 --- a/Source/Core/Core/Core.cpp +++ b/Source/Core/Core/Core.cpp @@ -466,7 +466,7 @@ static void FifoPlayerThread(Core::System& system, const std::optional= XFMEM_UNKNOWN_GROUP_3_START && address <= XFMEM_UNKNOWN_GROUP_3_END)); } -bool FifoPlayer::IsIdleSet() +bool FifoPlayer::IsIdleSet() const { CommandProcessor::UCPStatusReg status = Core::System::GetInstance().GetMMU().Read_U16(0xCC000000 | CommandProcessor::STATUS_REGISTER); return status.CommandIdle; } -bool FifoPlayer::IsHighWatermarkSet() +bool FifoPlayer::IsHighWatermarkSet() const { CommandProcessor::UCPStatusReg status = Core::System::GetInstance().GetMMU().Read_U16(0xCC000000 | CommandProcessor::STATUS_REGISTER); diff --git a/Source/Core/Core/FifoPlayer/FifoPlayer.h b/Source/Core/Core/FifoPlayer/FifoPlayer.h index b1cbd7a12d..7482a12aff 100644 --- a/Source/Core/Core/FifoPlayer/FifoPlayer.h +++ b/Source/Core/Core/FifoPlayer/FifoPlayer.h @@ -19,6 +19,10 @@ class FifoDataFile; struct MemoryUpdate; +namespace Core +{ +class System; +} namespace CPU { enum class State; @@ -91,6 +95,11 @@ class FifoPlayer public: using CallbackFunc = std::function; + explicit FifoPlayer(Core::System& system); + FifoPlayer(const FifoPlayer&) = delete; + FifoPlayer(FifoPlayer&&) = delete; + FifoPlayer& operator=(const FifoPlayer&) = delete; + FifoPlayer& operator=(FifoPlayer&&) = delete; ~FifoPlayer(); bool Open(const std::string& filename); @@ -127,13 +136,11 @@ public: // Callbacks void SetFileLoadedCallback(CallbackFunc callback); void SetFrameWrittenCallback(CallbackFunc callback) { m_FrameWrittenCb = std::move(callback); } - static FifoPlayer& GetInstance(); bool IsRunningWithFakeVideoInterfaceUpdates() const; private: class CPUCore; - FifoPlayer(); CPU::State AdvanceFrame(); @@ -168,11 +175,13 @@ private: bool ShouldLoadBP(u8 address); bool ShouldLoadXF(u8 address); - static bool IsIdleSet(); - static bool IsHighWatermarkSet(); + bool IsIdleSet() const; + bool IsHighWatermarkSet() const; void RefreshConfig(); + Core::System& m_system; + bool m_Loop = true; // If enabled then all memory updates happen at once before the first frame bool m_EarlyMemoryUpdates = false; diff --git a/Source/Core/Core/HW/VideoInterface.cpp b/Source/Core/Core/HW/VideoInterface.cpp index 92597776ee..1217b789d9 100644 --- a/Source/Core/Core/HW/VideoInterface.cpp +++ b/Source/Core/Core/HW/VideoInterface.cpp @@ -545,7 +545,7 @@ float VideoInterfaceManager::GetAspectRatio() const // 5. Calculate the final ratio and scale to 4:3 float ratio = horizontal_active_ratio / vertical_active_ratio; - bool running_fifo_log = FifoPlayer::GetInstance().IsRunningWithFakeVideoInterfaceUpdates(); + const bool running_fifo_log = m_system.GetFifoPlayer().IsRunningWithFakeVideoInterfaceUpdates(); if (std::isnormal(ratio) && // Check we have a sane ratio without any infs/nans/zeros !running_fifo_log) // we don't know the correct ratio for fifos return ratio * (4.0f / 3.0f); // Scale to 4:3 diff --git a/Source/Core/Core/System.cpp b/Source/Core/Core/System.cpp index 6767a8154d..7488976ddf 100644 --- a/Source/Core/Core/System.cpp +++ b/Source/Core/Core/System.cpp @@ -8,6 +8,7 @@ #include "AudioCommon/SoundStream.h" #include "Core/Config/MainSettings.h" #include "Core/CoreTiming.h" +#include "Core/FifoPlayer/FifoPlayer.h" #include "Core/HW/AudioInterface.h" #include "Core/HW/CPU.h" #include "Core/HW/DSP.h" @@ -48,7 +49,8 @@ struct System::Impl m_memory(system), m_pixel_engine{system}, m_power_pc(system), m_mmu(system, m_memory, m_power_pc), m_processor_interface(system), m_serial_interface(system), m_system_timers(system), m_video_interface(system), - m_interpreter(system, m_power_pc.GetPPCState(), m_mmu), m_jit_interface(system) + m_interpreter(system, m_power_pc.GetPPCState(), m_mmu), m_jit_interface(system), + m_fifo_player(system) { } @@ -86,6 +88,7 @@ struct System::Impl Interpreter m_interpreter; JitInterface m_jit_interface; VideoCommon::CustomAssetLoader m_custom_asset_loader; + FifoPlayer m_fifo_player; }; System::System() : m_impl{std::make_unique(*this)} @@ -176,6 +179,11 @@ Fifo::FifoManager& System::GetFifo() const return m_impl->m_fifo; } +FifoPlayer& System::GetFifoPlayer() const +{ + return m_impl->m_fifo_player; +} + GeometryShaderManager& System::GetGeometryShaderManager() const { return m_impl->m_geometry_shader_manager; diff --git a/Source/Core/Core/System.h b/Source/Core/Core/System.h index eb46195ecb..8e5d56aeb0 100644 --- a/Source/Core/Core/System.h +++ b/Source/Core/Core/System.h @@ -47,6 +47,7 @@ namespace Fifo { class FifoManager; } +class FifoPlayer; namespace GPFifo { class GPFifoManager; @@ -142,6 +143,7 @@ public: DVD::DVDThread& GetDVDThread() const; ExpansionInterface::ExpansionInterfaceManager& GetExpansionInterface() const; Fifo::FifoManager& GetFifo() const; + FifoPlayer& GetFifoPlayer() const; GeometryShaderManager& GetGeometryShaderManager() const; GPFifo::GPFifoManager& GetGPFifo() const; HSP::HSPManager& GetHSP() const; diff --git a/Source/Core/DolphinQt/FIFO/FIFOAnalyzer.cpp b/Source/Core/DolphinQt/FIFO/FIFOAnalyzer.cpp index bcf0276a02..12838fde31 100644 --- a/Source/Core/DolphinQt/FIFO/FIFOAnalyzer.cpp +++ b/Source/Core/DolphinQt/FIFO/FIFOAnalyzer.cpp @@ -37,7 +37,7 @@ constexpr int PART_START_ROLE = Qt::UserRole + 1; // Values range from 1 to number of parts constexpr int PART_END_ROLE = Qt::UserRole + 2; -FIFOAnalyzer::FIFOAnalyzer() +FIFOAnalyzer::FIFOAnalyzer(FifoPlayer& fifo_player) : m_fifo_player(fifo_player) { CreateWidgets(); ConnectWidgets(); @@ -138,7 +138,7 @@ void FIFOAnalyzer::UpdateTree() { m_tree_widget->clear(); - if (!FifoPlayer::GetInstance().IsPlaying()) + if (!m_fifo_player.IsPlaying()) { m_tree_widget->addTopLevelItem(new QTreeWidgetItem({tr("No recording loaded.")})); return; @@ -148,7 +148,7 @@ void FIFOAnalyzer::UpdateTree() m_tree_widget->addTopLevelItem(recording_item); - auto* file = FifoPlayer::GetInstance().GetFile(); + auto* file = m_fifo_player.GetFile(); const u32 frame_count = file->GetFrameCount(); @@ -158,7 +158,7 @@ void FIFOAnalyzer::UpdateTree() recording_item->addChild(frame_item); - const AnalyzedFrameInfo& frame_info = FifoPlayer::GetInstance().GetAnalyzedFrameInfo(frame); + const AnalyzedFrameInfo& frame_info = m_fifo_player.GetAnalyzedFrameInfo(frame); ASSERT(frame_info.parts.size() != 0); Common::EnumMap part_counts; @@ -339,7 +339,7 @@ void FIFOAnalyzer::UpdateDetails() m_search_previous->setEnabled(false); m_search_label->clear(); - if (!FifoPlayer::GetInstance().IsPlaying()) + if (!m_fifo_player.IsPlaying()) return; const auto items = m_tree_widget->selectedItems(); @@ -351,8 +351,8 @@ void FIFOAnalyzer::UpdateDetails() const u32 start_part_nr = items[0]->data(0, PART_START_ROLE).toUInt(); const u32 end_part_nr = items[0]->data(0, PART_END_ROLE).toUInt(); - const AnalyzedFrameInfo& frame_info = FifoPlayer::GetInstance().GetAnalyzedFrameInfo(frame_nr); - const auto& fifo_frame = FifoPlayer::GetInstance().GetFile()->GetFrame(frame_nr); + const AnalyzedFrameInfo& frame_info = m_fifo_player.GetAnalyzedFrameInfo(frame_nr); + const auto& fifo_frame = m_fifo_player.GetFile()->GetFrame(frame_nr); const u32 object_start = frame_info.parts[start_part_nr].m_start; const u32 object_end = frame_info.parts[end_part_nr].m_end; @@ -386,7 +386,7 @@ void FIFOAnalyzer::BeginSearch() { const QString search_str = m_search_edit->text(); - if (!FifoPlayer::GetInstance().IsPlaying()) + if (!m_fifo_player.IsPlaying()) return; const auto items = m_tree_widget->selectedItems(); @@ -434,8 +434,8 @@ void FIFOAnalyzer::BeginSearch() const u32 start_part_nr = items[0]->data(0, PART_START_ROLE).toUInt(); const u32 end_part_nr = items[0]->data(0, PART_END_ROLE).toUInt(); - const AnalyzedFrameInfo& frame_info = FifoPlayer::GetInstance().GetAnalyzedFrameInfo(frame_nr); - const FifoFrameInfo& fifo_frame = FifoPlayer::GetInstance().GetFile()->GetFrame(frame_nr); + const AnalyzedFrameInfo& frame_info = m_fifo_player.GetAnalyzedFrameInfo(frame_nr); + const FifoFrameInfo& fifo_frame = m_fifo_player.GetFile()->GetFrame(frame_nr); const u32 object_start = frame_info.parts[start_part_nr].m_start; const u32 object_end = frame_info.parts[end_part_nr].m_end; @@ -750,7 +750,7 @@ void FIFOAnalyzer::UpdateDescription() { m_entry_detail_browser->clear(); - if (!FifoPlayer::GetInstance().IsPlaying()) + if (!m_fifo_player.IsPlaying()) return; const auto items = m_tree_widget->selectedItems(); @@ -766,8 +766,8 @@ void FIFOAnalyzer::UpdateDescription() const u32 end_part_nr = items[0]->data(0, PART_END_ROLE).toUInt(); const u32 entry_nr = m_detail_list->currentRow(); - const AnalyzedFrameInfo& frame_info = FifoPlayer::GetInstance().GetAnalyzedFrameInfo(frame_nr); - const FifoFrameInfo& fifo_frame = FifoPlayer::GetInstance().GetFile()->GetFrame(frame_nr); + const AnalyzedFrameInfo& frame_info = m_fifo_player.GetAnalyzedFrameInfo(frame_nr); + const FifoFrameInfo& fifo_frame = m_fifo_player.GetFile()->GetFrame(frame_nr); const u32 object_start = frame_info.parts[start_part_nr].m_start; const u32 object_end = frame_info.parts[end_part_nr].m_end; diff --git a/Source/Core/DolphinQt/FIFO/FIFOAnalyzer.h b/Source/Core/DolphinQt/FIFO/FIFOAnalyzer.h index 222ce8e06b..e17bcb798d 100644 --- a/Source/Core/DolphinQt/FIFO/FIFOAnalyzer.h +++ b/Source/Core/DolphinQt/FIFO/FIFOAnalyzer.h @@ -9,6 +9,7 @@ #include "Common/CommonTypes.h" +class FifoPlayer; class QGroupBox; class QLabel; class QLineEdit; @@ -23,7 +24,7 @@ class FIFOAnalyzer final : public QWidget Q_OBJECT public: - explicit FIFOAnalyzer(); + explicit FIFOAnalyzer(FifoPlayer& fifo_player); ~FIFOAnalyzer(); void Update(); @@ -42,6 +43,8 @@ private: void UpdateDetails(); void UpdateDescription(); + FifoPlayer& m_fifo_player; + QTreeWidget* m_tree_widget; QListWidget* m_detail_list; QTextBrowser* m_entry_detail_browser; diff --git a/Source/Core/DolphinQt/FIFO/FIFOPlayerWindow.cpp b/Source/Core/DolphinQt/FIFO/FIFOPlayerWindow.cpp index d5161640a9..6c108477f5 100644 --- a/Source/Core/DolphinQt/FIFO/FIFOPlayerWindow.cpp +++ b/Source/Core/DolphinQt/FIFO/FIFOPlayerWindow.cpp @@ -32,7 +32,8 @@ #include "DolphinQt/Resources.h" #include "DolphinQt/Settings.h" -FIFOPlayerWindow::FIFOPlayerWindow(QWidget* parent) : QWidget(parent) +FIFOPlayerWindow::FIFOPlayerWindow(FifoPlayer& fifo_player, QWidget* parent) + : QWidget(parent), m_fifo_player(fifo_player) { setWindowTitle(tr("FIFO Player")); setWindowIcon(Resources::GetAppIcon()); @@ -46,9 +47,9 @@ FIFOPlayerWindow::FIFOPlayerWindow(QWidget* parent) : QWidget(parent) UpdateControls(); - FifoPlayer::GetInstance().SetFileLoadedCallback( + m_fifo_player.SetFileLoadedCallback( [this] { QueueOnObject(this, &FIFOPlayerWindow::OnFIFOLoaded); }); - FifoPlayer::GetInstance().SetFrameWrittenCallback([this] { + m_fifo_player.SetFrameWrittenCallback([this] { QueueOnObject(this, [this] { UpdateInfo(); UpdateControls(); @@ -68,8 +69,8 @@ FIFOPlayerWindow::FIFOPlayerWindow(QWidget* parent) : QWidget(parent) FIFOPlayerWindow::~FIFOPlayerWindow() { - FifoPlayer::GetInstance().SetFileLoadedCallback({}); - FifoPlayer::GetInstance().SetFrameWrittenCallback({}); + m_fifo_player.SetFileLoadedCallback({}); + m_fifo_player.SetFrameWrittenCallback({}); } void FIFOPlayerWindow::CreateWidgets() @@ -160,7 +161,7 @@ void FIFOPlayerWindow::CreateWidgets() m_tab_widget = new QTabWidget(this); - m_analyzer = new FIFOAnalyzer; + m_analyzer = new FIFOAnalyzer(m_fifo_player); m_tab_widget->addTab(m_main_widget, tr("Play / Record")); m_tab_widget->addTab(m_analyzer, tr("Analyze")); @@ -262,7 +263,7 @@ void FIFOPlayerWindow::OnEmulationStarted() { UpdateControls(); - if (FifoPlayer::GetInstance().GetFile()) + if (m_fifo_player.GetFile()) OnFIFOLoaded(); } @@ -286,14 +287,13 @@ void FIFOPlayerWindow::OnRecordingDone() void FIFOPlayerWindow::UpdateInfo() { - if (FifoPlayer::GetInstance().IsPlaying()) + if (m_fifo_player.IsPlaying()) { - FifoDataFile* file = FifoPlayer::GetInstance().GetFile(); - m_info_label->setText( - tr("%1 frame(s)\n%2 object(s)\nCurrent Frame: %3") - .arg(QString::number(file->GetFrameCount()), - QString::number(FifoPlayer::GetInstance().GetCurrentFrameObjectCount()), - QString::number(FifoPlayer::GetInstance().GetCurrentFrameNum()))); + FifoDataFile* file = m_fifo_player.GetFile(); + m_info_label->setText(tr("%1 frame(s)\n%2 object(s)\nCurrent Frame: %3") + .arg(QString::number(file->GetFrameCount()), + QString::number(m_fifo_player.GetCurrentFrameObjectCount()), + QString::number(m_fifo_player.GetCurrentFrameNum()))); return; } @@ -327,9 +327,9 @@ void FIFOPlayerWindow::UpdateInfo() void FIFOPlayerWindow::OnFIFOLoaded() { - FifoDataFile* file = FifoPlayer::GetInstance().GetFile(); + FifoDataFile* file = m_fifo_player.GetFile(); - auto object_count = FifoPlayer::GetInstance().GetMaxObjectCount(); + auto object_count = m_fifo_player.GetMaxObjectCount(); auto frame_count = file->GetFrameCount(); m_frame_range_to->setMaximum(frame_count - 1); @@ -356,7 +356,7 @@ void FIFOPlayerWindow::OnConfigChanged() void FIFOPlayerWindow::OnLimitsChanged() { - FifoPlayer& player = FifoPlayer::GetInstance(); + FifoPlayer& player = m_fifo_player; player.SetFrameRangeStart(m_frame_range_from->value()); player.SetFrameRangeEnd(m_frame_range_to->value()); @@ -377,7 +377,7 @@ void FIFOPlayerWindow::UpdateControls() { bool running = Core::IsRunning(); bool is_recording = FifoRecorder::GetInstance().IsRecording(); - bool is_playing = FifoPlayer::GetInstance().IsPlaying(); + bool is_playing = m_fifo_player.IsPlaying(); m_frame_range_from->setEnabled(is_playing); m_frame_range_from_label->setEnabled(is_playing); diff --git a/Source/Core/DolphinQt/FIFO/FIFOPlayerWindow.h b/Source/Core/DolphinQt/FIFO/FIFOPlayerWindow.h index a5e2562c1f..beb549c481 100644 --- a/Source/Core/DolphinQt/FIFO/FIFOPlayerWindow.h +++ b/Source/Core/DolphinQt/FIFO/FIFOPlayerWindow.h @@ -13,13 +13,14 @@ class QPushButton; class QSpinBox; class QTabWidget; class ToolTipCheckBox; +class FifoPlayer; class FIFOAnalyzer; class FIFOPlayerWindow : public QWidget { Q_OBJECT public: - explicit FIFOPlayerWindow(QWidget* parent = nullptr); + explicit FIFOPlayerWindow(FifoPlayer& fifo_player, QWidget* parent = nullptr); ~FIFOPlayerWindow(); signals: @@ -49,6 +50,8 @@ private: bool eventFilter(QObject* object, QEvent* event) final override; + FifoPlayer& m_fifo_player; + QLabel* m_info_label; QPushButton* m_load; QPushButton* m_save; diff --git a/Source/Core/DolphinQt/MainWindow.cpp b/Source/Core/DolphinQt/MainWindow.cpp index ef1bbe7642..45289dbee3 100644 --- a/Source/Core/DolphinQt/MainWindow.cpp +++ b/Source/Core/DolphinQt/MainWindow.cpp @@ -1363,7 +1363,7 @@ void MainWindow::ShowFIFOPlayer() { if (!m_fifo_window) { - m_fifo_window = new FIFOPlayerWindow; + m_fifo_window = new FIFOPlayerWindow(Core::System::GetInstance().GetFifoPlayer()); connect(m_fifo_window, &FIFOPlayerWindow::LoadFIFORequested, this, [this](const QString& path) { StartGame(path, ScanForSecondDisc::No); }); } diff --git a/Source/Core/VideoCommon/BPStructs.cpp b/Source/Core/VideoCommon/BPStructs.cpp index f1dff8fd97..1a8580df8f 100644 --- a/Source/Core/VideoCommon/BPStructs.cpp +++ b/Source/Core/VideoCommon/BPStructs.cpp @@ -355,17 +355,18 @@ static void BPWritten(PixelShaderManager& pixel_shader_manager, XFStateManager& // Might also clean up some issues with games doing XFB copies they don't intend to // display. + auto& system = Core::System::GetInstance(); if (g_ActiveConfig.bImmediateXFB) { // below div two to convert from bytes to pixels - it expects width, not stride - u64 ticks = Core::System::GetInstance().GetCoreTiming().GetTicks(); + u64 ticks = system.GetCoreTiming().GetTicks(); g_presenter->ImmediateSwap(destAddr, destStride / 2, destStride, height, ticks); } else { - if (FifoPlayer::GetInstance().IsRunningWithFakeVideoInterfaceUpdates()) + if (system.GetFifoPlayer().IsRunningWithFakeVideoInterfaceUpdates()) { - auto& vi = Core::System::GetInstance().GetVideoInterface(); + auto& vi = system.GetVideoInterface(); vi.FakeVIUpdate(destAddr, srcRect.GetWidth(), destStride, height); } }