From e6032f1eb9980c6fb2f36af8a0665aff87f5799c Mon Sep 17 00:00:00 2001 From: Nikhil Narayana Date: Tue, 5 Nov 2024 09:51:46 -0800 Subject: [PATCH] fix: drill down system as needed and use GetInstance when necessary --- Source/Core/Core/HW/EXI/EXI_DeviceSlippi.cpp | 6 +-- .../Core/Core/Slippi/SlippiGameFileLoader.cpp | 4 +- .../Core/Core/Slippi/SlippiGameFileLoader.h | 3 +- Source/Core/Core/Slippi/SlippiPlayback.cpp | 38 ++++++++++--------- Source/Core/Core/Slippi/SlippiPlayback.h | 10 ++--- .../Config/Graphics/GeneralWidget.cpp | 2 +- Source/Core/DolphinQt/RenderWidget.cpp | 2 +- Source/Core/DolphinQt/Settings/AudioPane.cpp | 2 +- Source/Core/DolphinQt/Settings/SlippiPane.cpp | 4 +- 9 files changed, 37 insertions(+), 34 deletions(-) diff --git a/Source/Core/Core/HW/EXI/EXI_DeviceSlippi.cpp b/Source/Core/Core/HW/EXI/EXI_DeviceSlippi.cpp index 51b84e717c..6c20ce557c 100644 --- a/Source/Core/Core/HW/EXI/EXI_DeviceSlippi.cpp +++ b/Source/Core/Core/HW/EXI/EXI_DeviceSlippi.cpp @@ -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); @@ -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 buf(contents.begin(), contents.end()); INFO_LOG_FMT(SLIPPI, "Writing file contents: {} -> {}", file_name.c_str(), size); @@ -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; diff --git a/Source/Core/Core/Slippi/SlippiGameFileLoader.cpp b/Source/Core/Core/Slippi/SlippiGameFileLoader.cpp index 1d06c7c4cd..15273eb2e9 100644 --- a/Source/Core/Core/Slippi/SlippiGameFileLoader.cpp +++ b/Source/Core/Core/Slippi/SlippiGameFileLoader.cpp @@ -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)) { @@ -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 buf; INFO_LOG_FMT(SLIPPI, "Will process diff"); diff --git a/Source/Core/Core/Slippi/SlippiGameFileLoader.h b/Source/Core/Core/Slippi/SlippiGameFileLoader.h index 4e16faf8d8..9949b7cd65 100644 --- a/Source/Core/Core/Slippi/SlippiGameFileLoader.h +++ b/Source/Core/Core/Slippi/SlippiGameFileLoader.h @@ -5,11 +5,12 @@ #include #include #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 file_cache; diff --git a/Source/Core/Core/Slippi/SlippiPlayback.cpp b/Source/Core/Core/Slippi/SlippiPlayback.cpp index caeec1761e..f8fb360921 100644 --- a/Source/Core/Core/Slippi/SlippiPlayback.cpp +++ b/Source/Core/Core/Slippi/SlippiPlayback.cpp @@ -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 @@ -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); @@ -140,6 +141,7 @@ void SlippiPlaybackStatus::processInitialState() void SlippiPlaybackStatus::SavestateThread() { + Core::System& system = Core::System::GetInstance(); Common::SetCurrentThreadName("Savestate thread"); std::unique_lock interval_lock(mtx); @@ -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); } @@ -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()) { @@ -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); @@ -212,14 +214,14 @@ 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) { @@ -227,7 +229,7 @@ void SlippiPlaybackStatus::seekToFrame() 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) { @@ -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); } } } @@ -248,9 +250,9 @@ 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); } @@ -258,7 +260,7 @@ void SlippiPlaybackStatus::seekToFrame() // 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 @@ -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 state_to_load(state_string.begin(), state_string.end()); - State::LoadFromBuffer(state_to_load); + State::LoadFromBuffer(system, state_to_load); } } diff --git a/Source/Core/Core/Slippi/SlippiPlayback.h b/Source/Core/Core/Slippi/SlippiPlayback.h index 78bb504a2e..4e25e12e46 100644 --- a/Source/Core/Core/Slippi/SlippiPlayback.h +++ b/Source/Core/Core/Slippi/SlippiPlayback.h @@ -34,19 +34,19 @@ public: 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 getDenylist(); std::vector 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(); diff --git a/Source/Core/DolphinQt/Config/Graphics/GeneralWidget.cpp b/Source/Core/DolphinQt/Config/Graphics/GeneralWidget.cpp index ee896f60cf..3787843a3a 100644 --- a/Source/Core/DolphinQt/Config/Graphics/GeneralWidget.cpp +++ b/Source/Core/DolphinQt/Config/Graphics/GeneralWidget.cpp @@ -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:")); diff --git a/Source/Core/DolphinQt/RenderWidget.cpp b/Source/Core/DolphinQt/RenderWidget.cpp index 801bed7673..115488ee85 100644 --- a/Source/Core/DolphinQt/RenderWidget.cpp +++ b/Source/Core/DolphinQt/RenderWidget.cpp @@ -611,5 +611,5 @@ void RenderWidget::Exit() void RenderWidget::PlaybackSeek() { - g_playback_status->seekToFrame(); + g_playback_status->seekToFrame(Core::System::GetInstance()); } diff --git a/Source/Core/DolphinQt/Settings/AudioPane.cpp b/Source/Core/DolphinQt/Settings/AudioPane.cpp index 6e4b436e3a..0b21befe98 100644 --- a/Source/Core/DolphinQt/Settings/AudioPane.cpp +++ b/Source/Core/DolphinQt/Settings/AudioPane.cpp @@ -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(); diff --git a/Source/Core/DolphinQt/Settings/SlippiPane.cpp b/Source/Core/DolphinQt/Settings/SlippiPane.cpp index 0c7b8269cc..2ea1cb57aa 100644 --- a/Source/Core/DolphinQt/Settings/SlippiPane.cpp +++ b/Source/Core/DolphinQt/Settings/SlippiPane.cpp @@ -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(); @@ -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();