Skip to content

Commit

Permalink
Merge pull request #10355 from Pokechu22/fifo-player-config
Browse files Browse the repository at this point in the history
FifoPlayer: Store early memory updates option in the config and allow changing loop option at runtime
  • Loading branch information
leoetlino committed Jan 13, 2022
2 parents 1cea399 + 29df17d commit 21b9e6a
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 18 deletions.
2 changes: 2 additions & 0 deletions Source/Core/Core/Config/MainSettings.cpp
Expand Up @@ -375,6 +375,8 @@ const Info<bool> MAIN_GAMELIST_COLUMN_TAGS{{System::Main, "GameList", "ColumnTag
// Main.FifoPlayer

const Info<bool> MAIN_FIFOPLAYER_LOOP_REPLAY{{System::Main, "FifoPlayer", "LoopReplay"}, true};
const Info<bool> MAIN_FIFOPLAYER_EARLY_MEMORY_UPDATES{
{System::Main, "FifoPlayer", "EarlyMemoryUpdates"}, false};

// Main.AutoUpdate

Expand Down
1 change: 1 addition & 0 deletions Source/Core/Core/Config/MainSettings.h
Expand Up @@ -265,6 +265,7 @@ extern const Info<bool> MAIN_GAMELIST_COLUMN_TAGS;
// Main.FifoPlayer

extern const Info<bool> MAIN_FIFOPLAYER_LOOP_REPLAY;
extern const Info<bool> MAIN_FIFOPLAYER_EARLY_MEMORY_UPDATES;

// Main.AutoUpdate

Expand Down
11 changes: 10 additions & 1 deletion Source/Core/Core/FifoPlayer/FifoPlayer.cpp
Expand Up @@ -163,12 +163,15 @@ void FifoPlaybackAnalyzer::OnCommand(const u8* data, u32 size)

bool IsPlayingBackFifologWithBrokenEFBCopies = false;

FifoPlayer::FifoPlayer() : m_Loop{Config::Get(Config::MAIN_FIFOPLAYER_LOOP_REPLAY)}
FifoPlayer::FifoPlayer()
{
m_config_changed_callback_id = Config::AddConfigChangedCallback([this] { RefreshConfig(); });
RefreshConfig();
}

FifoPlayer::~FifoPlayer()
{
Config::RemoveConfigChangedCallback(m_config_changed_callback_id);
}

bool FifoPlayer::Open(const std::string& filename)
Expand Down Expand Up @@ -298,6 +301,12 @@ std::unique_ptr<CPUCoreBase> FifoPlayer::GetCPUCore()
return std::make_unique<CPUCore>(this);
}

void FifoPlayer::RefreshConfig()
{
m_Loop = Config::Get(Config::MAIN_FIFOPLAYER_LOOP_REPLAY);
m_EarlyMemoryUpdates = Config::Get(Config::MAIN_FIFOPLAYER_EARLY_MEMORY_UPDATES);
}

void FifoPlayer::SetFileLoadedCallback(CallbackFunc callback)
{
m_FileLoadedCb = std::move(callback);
Expand Down
13 changes: 7 additions & 6 deletions Source/Core/Core/FifoPlayer/FifoPlayer.h
Expand Up @@ -122,9 +122,7 @@ class FifoPlayer
void SetObjectRangeStart(u32 start) { m_ObjectRangeStart = start; }
u32 GetObjectRangeEnd() const { return m_ObjectRangeEnd; }
void SetObjectRangeEnd(u32 end) { m_ObjectRangeEnd = end; }
// If enabled then all memory updates happen at once before the first frame
// Default is disabled
void SetEarlyMemoryUpdates(bool enabled) { m_EarlyMemoryUpdates = enabled; }

// Callbacks
void SetFileLoadedCallback(CallbackFunc callback);
void SetFrameWrittenCallback(CallbackFunc callback) { m_FrameWrittenCb = std::move(callback); }
Expand Down Expand Up @@ -172,7 +170,11 @@ class FifoPlayer
static bool IsIdleSet();
static bool IsHighWatermarkSet();

bool m_Loop;
void RefreshConfig();

bool m_Loop = true;
// If enabled then all memory updates happen at once before the first frame
bool m_EarlyMemoryUpdates = false;

u32 m_CurrentFrame = 0;
u32 m_FrameRangeStart = 0;
Expand All @@ -181,14 +183,13 @@ class FifoPlayer
u32 m_ObjectRangeStart = 0;
u32 m_ObjectRangeEnd = 10000;

bool m_EarlyMemoryUpdates = false;

u64 m_CyclesPerFrame = 0;
u32 m_ElapsedCycles = 0;
u32 m_FrameFifoSize = 0;

CallbackFunc m_FileLoadedCb = nullptr;
CallbackFunc m_FrameWrittenCb = nullptr;
size_t m_config_changed_callback_id;

std::unique_ptr<FifoDataFile> m_File;

Expand Down
42 changes: 34 additions & 8 deletions Source/Core/DolphinQt/FIFO/FIFOPlayerWindow.cpp
Expand Up @@ -24,6 +24,7 @@
#include "Core/FifoPlayer/FifoPlayer.h"
#include "Core/FifoPlayer/FifoRecorder.h"

#include "DolphinQt/Config/ToolTipControls/ToolTipCheckBox.h"
#include "DolphinQt/FIFO/FIFOAnalyzer.h"
#include "DolphinQt/QtUtils/DolphinFileDialog.h"
#include "DolphinQt/QtUtils/ModalMessageBox.h"
Expand All @@ -38,6 +39,7 @@ FIFOPlayerWindow::FIFOPlayerWindow(QWidget* parent) : QWidget(parent)

CreateWidgets();
ConnectWidgets();
AddDescriptions();

UpdateInfo();

Expand Down Expand Up @@ -116,11 +118,13 @@ void FIFOPlayerWindow::CreateWidgets()
// Playback Options
auto* playback_group = new QGroupBox(tr("Playback Options"));
auto* playback_layout = new QGridLayout;
m_early_memory_updates = new QCheckBox(tr("Early Memory Updates"));
m_early_memory_updates = new ToolTipCheckBox(tr("Early Memory Updates"));
m_loop = new ToolTipCheckBox(tr("Loop"));

playback_layout->addWidget(object_range_group, 0, 0);
playback_layout->addWidget(frame_range_group, 0, 1);
playback_layout->addWidget(m_early_memory_updates, 1, 0, 1, -1);
playback_layout->addWidget(m_early_memory_updates, 1, 0);
playback_layout->addWidget(m_loop, 1, 1);
playback_group->setLayout(playback_layout);

// Recording Options
Expand Down Expand Up @@ -166,15 +170,22 @@ void FIFOPlayerWindow::CreateWidgets()
setLayout(tab_layout);
}

void FIFOPlayerWindow::LoadSettings()
{
m_early_memory_updates->setChecked(Config::Get(Config::MAIN_FIFOPLAYER_EARLY_MEMORY_UPDATES));
m_loop->setChecked(Config::Get(Config::MAIN_FIFOPLAYER_LOOP_REPLAY));
}

void FIFOPlayerWindow::ConnectWidgets()
{
connect(m_load, &QPushButton::clicked, this, &FIFOPlayerWindow::LoadRecording);
connect(m_save, &QPushButton::clicked, this, &FIFOPlayerWindow::SaveRecording);
connect(m_record, &QPushButton::clicked, this, &FIFOPlayerWindow::StartRecording);
connect(m_stop, &QPushButton::clicked, this, &FIFOPlayerWindow::StopRecording);
connect(m_button_box, &QDialogButtonBox::rejected, this, &FIFOPlayerWindow::hide);
connect(m_early_memory_updates, &QCheckBox::toggled, this,
&FIFOPlayerWindow::OnEarlyMemoryUpdatesChanged);
connect(m_early_memory_updates, &QCheckBox::toggled, this, &FIFOPlayerWindow::OnConfigChanged);
connect(m_loop, &QCheckBox::toggled, this, &FIFOPlayerWindow::OnConfigChanged);

connect(m_frame_range_from, qOverload<int>(&QSpinBox::valueChanged), this,
&FIFOPlayerWindow::OnLimitsChanged);
connect(m_frame_range_to, qOverload<int>(&QSpinBox::valueChanged), this,
Expand All @@ -186,6 +197,21 @@ void FIFOPlayerWindow::ConnectWidgets()
&FIFOPlayerWindow::OnLimitsChanged);
}

void FIFOPlayerWindow::AddDescriptions()
{
static const char TR_MEMORY_UPDATES_DESCRIPTION[] = QT_TR_NOOP(
"If enabled, then all memory updates happen at once before the first frame.<br><br>"
"Causes issues with many fifologs, but can be useful for testing.<br><br>"
"<dolphin_emphasis>If unsure, leave this unchecked.</dolphin_emphasis>");
static const char TR_LOOP_DESCRIPTION[] =
QT_TR_NOOP("If unchecked, then playback of the fifolog stops after the final frame.<br><br>"
"This is generally only useful when a frame-dumping option is enabled.<br><br>"
"<dolphin_emphasis>If unsure, leave this checked.</dolphin_emphasis>");

m_early_memory_updates->SetDescription(tr(TR_MEMORY_UPDATES_DESCRIPTION));
m_loop->SetDescription(tr(TR_LOOP_DESCRIPTION));
}

void FIFOPlayerWindow::LoadRecording()
{
QString path = DolphinFileDialog::getOpenFileName(this, tr("Open FIFO log"), QString(),
Expand Down Expand Up @@ -324,9 +350,11 @@ void FIFOPlayerWindow::OnFIFOLoaded()
m_analyzer->Update();
}

void FIFOPlayerWindow::OnEarlyMemoryUpdatesChanged(bool enabled)
void FIFOPlayerWindow::OnConfigChanged()
{
FifoPlayer::GetInstance().SetEarlyMemoryUpdates(enabled);
Config::SetBase(Config::MAIN_FIFOPLAYER_EARLY_MEMORY_UPDATES,
m_early_memory_updates->isChecked());
Config::SetBase(Config::MAIN_FIFOPLAYER_LOOP_REPLAY, m_loop->isChecked());
}

void FIFOPlayerWindow::OnLimitsChanged()
Expand Down Expand Up @@ -363,8 +391,6 @@ void FIFOPlayerWindow::UpdateControls()
m_object_range_to->setEnabled(is_playing);
m_object_range_to_label->setEnabled(is_playing);

m_early_memory_updates->setEnabled(is_playing);

bool enable_frame_record_count = !is_playing && !is_recording;

m_frame_record_count_label->setEnabled(enable_frame_record_count);
Expand Down
9 changes: 6 additions & 3 deletions Source/Core/DolphinQt/FIFO/FIFOPlayerWindow.h
Expand Up @@ -7,12 +7,12 @@

#include "Core/Core.h"

class QCheckBox;
class QDialogButtonBox;
class QLabel;
class QPushButton;
class QSpinBox;
class QTabWidget;
class ToolTipCheckBox;
class FIFOAnalyzer;

class FIFOPlayerWindow : public QWidget
Expand All @@ -27,7 +27,9 @@ class FIFOPlayerWindow : public QWidget

private:
void CreateWidgets();
void LoadSettings();
void ConnectWidgets();
void AddDescriptions();

void LoadRecording();
void SaveRecording();
Expand All @@ -37,9 +39,9 @@ class FIFOPlayerWindow : public QWidget
void OnEmulationStarted();
void OnEmulationStopped();
void OnLimitsChanged();
void OnEarlyMemoryUpdatesChanged(bool enabled);
void OnRecordingDone();
void OnFIFOLoaded();
void OnConfigChanged();

void UpdateControls();
void UpdateInfo();
Expand All @@ -62,7 +64,8 @@ class FIFOPlayerWindow : public QWidget
QLabel* m_object_range_from_label;
QSpinBox* m_object_range_to;
QLabel* m_object_range_to_label;
QCheckBox* m_early_memory_updates;
ToolTipCheckBox* m_early_memory_updates;
ToolTipCheckBox* m_loop;
QDialogButtonBox* m_button_box;

QWidget* m_main_widget;
Expand Down

0 comments on commit 21b9e6a

Please sign in to comment.