Skip to content

Commit

Permalink
fix: drill down system as needed and use GetInstance when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
NikhilNarayana committed Nov 5, 2024
1 parent 340a8df commit e6032f1
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 34 deletions.
6 changes: 3 additions & 3 deletions Source/Core/Core/HW/EXI/EXI_DeviceSlippi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2569,7 +2569,7 @@ void CEXISlippi::prepareFileLength(u8* payload)
std::string file_name((char*)&payload[0]);

std::string contents;
u32 size = game_file_loader->LoadFile(file_name, contents);
u32 size = game_file_loader->LoadFile(this->m_system, file_name, contents);

INFO_LOG_FMT(SLIPPI, "Getting file size for: {} -> {}", file_name.c_str(), size);

Expand All @@ -2584,7 +2584,7 @@ void CEXISlippi::prepareFileLoad(u8* payload)
std::string file_name((char*)&payload[0]);

std::string contents;
u32 size = game_file_loader->LoadFile(file_name, contents);
u32 size = game_file_loader->LoadFile(this->m_system, file_name, contents);
std::vector<u8> buf(contents.begin(), contents.end());

INFO_LOG_FMT(SLIPPI, "Writing file contents: {} -> {}", file_name.c_str(), size);
Expand Down Expand Up @@ -3078,7 +3078,7 @@ void CEXISlippi::DMAWrite(u32 _uAddr, u32 _uSize)
{
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
u8* mem_ptr = memory.GetPointer(_uAddr);
u8* mem_ptr = memory.GetPointerForRange(_uAddr, _uSize);

u32 buf_loc = 0;

Expand Down
4 changes: 2 additions & 2 deletions Source/Core/Core/Slippi/SlippiGameFileLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ std::string getFilePath(std::string file_name)
return "";
}

u32 SlippiGameFileLoader::LoadFile(std::string file_name, std::string& data)
u32 SlippiGameFileLoader::LoadFile(Core::System& system, std::string file_name, std::string& data)
{
if (file_cache.count(file_name))
{
Expand All @@ -53,7 +53,7 @@ u32 SlippiGameFileLoader::LoadFile(std::string file_name, std::string& data)
// If the file was a diff file and the game is running, load the main file from ISO and apply
// patch
if (game_file_path.substr(game_file_path.length() - 5) == ".diff" &&
Core::GetState() == Core::State::Running)
Core::GetState(system) == Core::State::Running)
{
std::vector<u8> buf;
INFO_LOG_FMT(SLIPPI, "Will process diff");
Expand Down
3 changes: 2 additions & 1 deletion Source/Core/Core/Slippi/SlippiGameFileLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
#include <unordered_map>
#include <vector>
#include "Common/CommonTypes.h"
#include "Core/System.h"

class SlippiGameFileLoader
{
public:
u32 LoadFile(std::string file_name, std::string& contents);
u32 LoadFile(Core::System& system, std::string file_name, std::string& contents);

protected:
std::unordered_map<std::string, std::string> file_cache;
Expand Down
38 changes: 20 additions & 18 deletions Source/Core/Core/Slippi/SlippiPlayback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "Core/HW/EXI/EXI_DeviceSlippi.h"
#include "Core/NetPlayClient.h"
#include "Core/State.h"
#include "Core/System.h"
#include "SlippiPlayback.h"

#define FRAME_INTERVAL 900
Expand Down Expand Up @@ -124,14 +125,14 @@ void SlippiPlaybackStatus::resetPlayback()
in_slippi_playback = false;
}

void SlippiPlaybackStatus::processInitialState()
void SlippiPlaybackStatus::processInitialState(Core::System& system)
{
INFO_LOG_FMT(SLIPPI, "saving initial_state");
State::SaveToBuffer(initial_state);
State::SaveToBuffer(system, initial_state);
// The initial save to curr_state causes a stutter of about 5-10 frames
// Doing it here to get it out of the way and prevent stutters later
// Subsequent calls to SaveToBuffer for curr_state take ~1 frame
State::SaveToBuffer(curr_state);
State::SaveToBuffer(system, curr_state);
if (Config::Get(Config::SLIPPI_ENABLE_SEEK))
{
Config::SetCurrent(Config::MAIN_SHOW_CURSOR, Config::ShowCursor::Constantly);
Expand All @@ -140,6 +141,7 @@ void SlippiPlaybackStatus::processInitialState()

void SlippiPlaybackStatus::SavestateThread()
{
Core::System& system = Core::System::GetInstance();
Common::SetCurrentThreadName("Savestate thread");
std::unique_lock<std::mutex> interval_lock(mtx);

Expand All @@ -165,14 +167,14 @@ void SlippiPlaybackStatus::SavestateThread()

if (!in_slippi_playback && is_start_frame)
{
processInitialState();
processInitialState(system);
in_slippi_playback = true;
}
else if (Config::Get(Config::SLIPPI_ENABLE_SEEK) && !has_state_been_processed &&
!is_start_frame)
{
INFO_LOG_FMT(SLIPPI, "saving diff at frame: {}", fixed_frame_num);
State::SaveToBuffer(curr_state);
State::SaveToBuffer(system, curr_state);

future_diffs[fixed_frame_num] = std::async(processDiff, initial_state, curr_state);
}
Expand All @@ -182,7 +184,7 @@ void SlippiPlaybackStatus::SavestateThread()
INFO_LOG_FMT(SLIPPI, "Exiting savestate thread");
}

void SlippiPlaybackStatus::seekToFrame()
void SlippiPlaybackStatus::seekToFrame(Core::System& system)
{
if (seek_mtx.try_lock())
{
Expand All @@ -199,9 +201,9 @@ void SlippiPlaybackStatus::seekToFrame()
if (replay_comm_settings.mode == "queue")
updateWatchSettingsStartEnd();

auto prev_state = Core::GetState();
auto prev_state = Core::GetState(system);
if (prev_state != Core::State::Paused)
Core::SetState(Core::State::Paused);
Core::SetState(system, Core::State::Paused);

s32 closest_state_frame =
target_frame_num - emod(target_frame_num - Slippi::PLAYBACK_FIRST_SAVE, FRAME_INTERVAL);
Expand All @@ -212,22 +214,22 @@ void SlippiPlaybackStatus::seekToFrame()
{
if (closest_state_frame <= Slippi::PLAYBACK_FIRST_SAVE)
{
State::LoadFromBuffer(initial_state);
State::LoadFromBuffer(system, initial_state);
}
else
{
// If this diff exists, load it
if (future_diffs.count(closest_state_frame) > 0)
{
loadState(closest_state_frame);
loadState(system, closest_state_frame);
}
else if (target_frame_num < current_playback_frame)
{
s32 closest_actual_state_frame = closest_state_frame - FRAME_INTERVAL;
while (closest_actual_state_frame > Slippi::PLAYBACK_FIRST_SAVE &&
future_diffs.count(closest_actual_state_frame) == 0)
closest_actual_state_frame -= FRAME_INTERVAL;
loadState(closest_actual_state_frame);
loadState(system, closest_actual_state_frame);
}
else if (target_frame_num > current_playback_frame)
{
Expand All @@ -239,7 +241,7 @@ void SlippiPlaybackStatus::seekToFrame()
// only load a savestate if we find one past our current frame since we are seeking
// forwards
if (closest_actual_state_frame > current_playback_frame)
loadState(closest_actual_state_frame);
loadState(system, closest_actual_state_frame);
}
}
}
Expand All @@ -248,17 +250,17 @@ void SlippiPlaybackStatus::seekToFrame()
if (target_frame_num != closest_state_frame && target_frame_num != last_frame)
{
setHardFFW(true);
Core::SetState(Core::State::Running);
Core::SetState(system, Core::State::Running);
cv_waiting_for_target_frame.wait(ffw_lock);
Core::SetState(Core::State::Paused);
Core::SetState(system, Core::State::Paused);
setHardFFW(false);
}

// We've reached the frame we want. Reset target_frame_num and release mutex so another seek can
// be performed
g_playback_status->current_playback_frame = target_frame_num;
target_frame_num = INT_MAX;
Core::SetState(prev_state);
Core::SetState(system, prev_state);
seek_mtx.unlock();
}
else
Expand All @@ -284,17 +286,17 @@ void SlippiPlaybackStatus::setHardFFW(bool enable)
is_hard_FFW = enable;
}

void SlippiPlaybackStatus::loadState(s32 closest_state_frame)
void SlippiPlaybackStatus::loadState(Core::System& system, s32 closest_state_frame)
{
if (closest_state_frame == Slippi::PLAYBACK_FIRST_SAVE)
State::LoadFromBuffer(initial_state);
State::LoadFromBuffer(system, initial_state);
else
{
std::string state_string;
decoder.Decode((char*)initial_state.data(), initial_state.size(),
future_diffs[closest_state_frame].get(), &state_string);
std::vector<u8> state_to_load(state_string.begin(), state_string.end());
State::LoadFromBuffer(state_to_load);
State::LoadFromBuffer(system, state_to_load);
}
}

Expand Down
10 changes: 5 additions & 5 deletions Source/Core/Core/Slippi/SlippiPlayback.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ class SlippiPlaybackStatus

std::thread m_savestate_thread;

void startThreads(void);
void startThreads();
void resetPlayback(void);
bool shouldFFWFrame(s32 frame_idx) const;
void prepareSlippiPlayback(s32& frame_idx);
void setHardFFW(bool enable);
std::unordered_map<u32, bool> getDenylist();
std::vector<u8> getLegacyCodelist();
void seekToFrame();
void seekToFrame(Core::System& system);

private:
void SavestateThread(void);
void loadState(s32 closest_state_frame);
void processInitialState();
void SavestateThread();
void loadState(Core::System& system, s32 closest_state_frame);
void processInitialState(Core::System& system);
void updateWatchSettingsStartEnd();
void generateDenylist();
void generateLegacyCodelist();
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinQt/Config/Graphics/GeneralWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void GeneralWidget::CreateWidgets()
m_video_layout = new QGridLayout();

m_backend_combo = new ToolTipComboBox();
m_aspect_combo = new ConfigChoice({tr("Auto"), tr("Force 16:9"), tr("Force 4:3"), tr("Force 73:60 (Melee)")
m_aspect_combo = new ConfigChoice({tr("Auto"), tr("Force 16:9"), tr("Force 4:3"), tr("Force 73:60 (Melee)"),
tr("Stretch to Window"), tr("Custom"), tr("Custom (Stretch)")},
Config::GFX_ASPECT_RATIO);
m_custom_aspect_label = new QLabel(tr("Custom Aspect Ratio:"));
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinQt/RenderWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,5 +611,5 @@ void RenderWidget::Exit()

void RenderWidget::PlaybackSeek()
{
g_playback_status->seekToFrame();
g_playback_status->seekToFrame(Core::System::GetInstance());
}
2 changes: 1 addition & 1 deletion Source/Core/DolphinQt/Settings/AudioPane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ void AudioPane::OnVolumeChanged(int volume)
m_volume_indicator->setText(tr("%1%").arg(volume));

#ifndef IS_PLAYBACK
if (Core::GetState() == Core::State::Running)
if (Core::GetState(Core::System::GetInstance()) == Core::State::Running)
{
auto& system = Core::System::GetInstance();
auto& exi_manager = system.GetExpansionInterface();
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/DolphinQt/Settings/SlippiPane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ void SlippiPane::ToggleJukebox(bool checked)
Config::SetBase(Config::SLIPPI_ENABLE_JUKEBOX, checked);
m_music_volume_slider->setDisabled(!checked);

if (Core::GetState() == Core::State::Running)
if (Core::GetState(Core::System::GetInstance()) == Core::State::Running)
{
auto& system = Core::System::GetInstance();
auto& exi_manager = system.GetExpansionInterface();
Expand All @@ -301,7 +301,7 @@ void SlippiPane::OnMusicVolumeUpdate(int volume)
{
Config::SetBase(Config::SLIPPI_JUKEBOX_VOLUME, volume);
m_music_volume_percent->setText(tr(" %1%").arg(volume));
if (Core::GetState() == Core::State::Running)
if (Core::GetState(Core::System::GetInstance()) == Core::State::Running)
{
auto& system = Core::System::GetInstance();
auto& exi_manager = system.GetExpansionInterface();
Expand Down

0 comments on commit e6032f1

Please sign in to comment.