Skip to content

Commit

Permalink
FifoPlayer: Move instance to System.
Browse files Browse the repository at this point in the history
  • Loading branch information
AdmiralCurtiss committed Jan 5, 2024
1 parent 2f7f7af commit fc2ec82
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 56 deletions.
2 changes: 1 addition & 1 deletion Source/Core/Core/Boot/Boot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions Source/Core/Core/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ static void FifoPlayerThread(Core::System& system, const std::optional<std::stri
Common::SetCurrentThreadName("FIFO-GPU thread");

// Enter CPU run loop. When we leave it - we are done.
if (auto cpu_core = FifoPlayer::GetInstance().GetCPUCore())
if (auto cpu_core = system.GetFifoPlayer().GetCPUCore())
{
system.GetPowerPC().InjectExternalCPUCore(cpu_core.get());
s_is_started = true;
Expand All @@ -476,13 +476,13 @@ static void FifoPlayerThread(Core::System& system, const std::optional<std::stri

s_is_started = false;
system.GetPowerPC().InjectExternalCPUCore(nullptr);
FifoPlayer::GetInstance().Close();
system.GetFifoPlayer().Close();
}
else
{
// FIFO log does not contain any frames, cannot continue.
PanicAlertFmt("FIFO file is invalid, cannot playback.");
FifoPlayer::GetInstance().Close();
system.GetFifoPlayer().Close();
return;
}
}
Expand Down
12 changes: 3 additions & 9 deletions Source/Core/Core/FifoPlayer/FifoPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ void FifoPlaybackAnalyzer::OnCommand(const u8* data, u32 size)

bool IsPlayingBackFifologWithBrokenEFBCopies = false;

FifoPlayer::FifoPlayer()
FifoPlayer::FifoPlayer(Core::System& system) : m_system(system)
{
m_config_changed_callback_id = Config::AddConfigChangedCallback([this] { RefreshConfig(); });
RefreshConfig();
Expand Down Expand Up @@ -401,12 +401,6 @@ void FifoPlayer::SetFrameRangeEnd(u32 end)
}
}

FifoPlayer& FifoPlayer::GetInstance()
{
static FifoPlayer instance;
return instance;
}

void FifoPlayer::WriteFrame(const FifoFrameInfo& frame, const AnalyzedFrameInfo& info)
{
// Core timing information
Expand Down Expand Up @@ -821,14 +815,14 @@ bool FifoPlayer::ShouldLoadXF(u8 reg)
(address >= 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);
Expand Down
17 changes: 13 additions & 4 deletions Source/Core/Core/FifoPlayer/FifoPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
class FifoDataFile;
struct MemoryUpdate;

namespace Core
{
class System;
}
namespace CPU
{
enum class State;
Expand Down Expand Up @@ -91,6 +95,11 @@ class FifoPlayer
public:
using CallbackFunc = std::function<void()>;

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);
Expand Down Expand Up @@ -127,13 +136,11 @@ class FifoPlayer
// 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();

Expand Down Expand Up @@ -168,11 +175,13 @@ class FifoPlayer
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;
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/HW/VideoInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion Source/Core/Core/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
{
}

Expand Down Expand Up @@ -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<Impl>(*this)}
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/Core/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ namespace Fifo
{
class FifoManager;
}
class FifoPlayer;
namespace GPFifo
{
class GPFifoManager;
Expand Down Expand Up @@ -142,6 +143,7 @@ class System
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;
Expand Down
26 changes: 13 additions & 13 deletions Source/Core/DolphinQt/FIFO/FIFOAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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();

Expand All @@ -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<u32, FramePartType::EFBCopy> part_counts;
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion Source/Core/DolphinQt/FIFO/FIFOAnalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "Common/CommonTypes.h"

class FifoPlayer;
class QGroupBox;
class QLabel;
class QLineEdit;
Expand All @@ -23,7 +24,7 @@ class FIFOAnalyzer final : public QWidget
Q_OBJECT

public:
explicit FIFOAnalyzer();
explicit FIFOAnalyzer(FifoPlayer& fifo_player);
~FIFOAnalyzer();

void Update();
Expand All @@ -42,6 +43,8 @@ class FIFOAnalyzer final : public QWidget
void UpdateDetails();
void UpdateDescription();

FifoPlayer& m_fifo_player;

QTreeWidget* m_tree_widget;
QListWidget* m_detail_list;
QTextBrowser* m_entry_detail_browser;
Expand Down

0 comments on commit fc2ec82

Please sign in to comment.