Core: Avoid (Some) Global System Accessor
This commit is contained in:
parent
85dee300b5
commit
f09b71582e
|
@ -258,7 +258,7 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_PauseEmulati
|
|||
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_StopEmulation(JNIEnv*, jclass)
|
||||
{
|
||||
HostThreadLock guard;
|
||||
Core::Stop();
|
||||
Core::Stop(Core::System::GetInstance());
|
||||
|
||||
// Kick the waiting event
|
||||
s_update_main_frame_event.Set();
|
||||
|
@ -586,11 +586,11 @@ static void Run(JNIEnv* env, std::unique_ptr<BootParameters>&& boot, bool riivol
|
|||
host_identity_guard.Unlock();
|
||||
s_update_main_frame_event.Wait();
|
||||
host_identity_guard.Lock();
|
||||
Core::HostDispatchJobs();
|
||||
Core::HostDispatchJobs(Core::System::GetInstance());
|
||||
}
|
||||
|
||||
s_game_metadata_is_valid = false;
|
||||
Core::Shutdown();
|
||||
Core::Shutdown(Core::System::GetInstance());
|
||||
host_identity_guard.Unlock();
|
||||
|
||||
env->CallStaticVoidMethod(IDCache::GetNativeLibraryClass(),
|
||||
|
|
|
@ -146,7 +146,7 @@ bool BootCore(Core::System& system, std::unique_ptr<BootParameters> boot,
|
|||
|
||||
system.Initialize();
|
||||
|
||||
Core::UpdateWantDeterminism(/*initial*/ true);
|
||||
Core::UpdateWantDeterminism(system, /*initial*/ true);
|
||||
|
||||
if (system.IsWii())
|
||||
{
|
||||
|
|
|
@ -190,7 +190,7 @@ void SConfig::SetRunningGameMetadata(const std::string& game_id, const std::stri
|
|||
Host_TitleChanged();
|
||||
if (Core::IsRunning())
|
||||
{
|
||||
Core::UpdateTitle();
|
||||
Core::UpdateTitle(system);
|
||||
}
|
||||
|
||||
Config::AddLayer(ConfigLoaders::GenerateGlobalGameConfigLoader(game_id, revision));
|
||||
|
|
|
@ -120,7 +120,7 @@ static std::unique_ptr<MemoryWatcher> s_memory_watcher;
|
|||
|
||||
struct HostJob
|
||||
{
|
||||
std::function<void()> job;
|
||||
std::function<void(Core::System&)> job;
|
||||
bool run_after_stop;
|
||||
};
|
||||
static std::mutex s_host_jobs_lock;
|
||||
|
@ -166,13 +166,13 @@ void FrameUpdateOnCPUThread()
|
|||
NetPlay::NetPlayClient::SendTimeBase();
|
||||
}
|
||||
|
||||
void OnFrameEnd()
|
||||
void OnFrameEnd(Core::System& system)
|
||||
{
|
||||
#ifdef USE_MEMORYWATCHER
|
||||
if (s_memory_watcher)
|
||||
{
|
||||
ASSERT(IsCPUThread());
|
||||
CPUThreadGuard guard(Core::System::GetInstance());
|
||||
const CPUThreadGuard guard(system);
|
||||
|
||||
s_memory_watcher->Step(guard);
|
||||
}
|
||||
|
@ -252,7 +252,7 @@ bool Init(Core::System& system, std::unique_ptr<BootParameters> boot, const Wind
|
|||
}
|
||||
|
||||
// Drain any left over jobs
|
||||
HostDispatchJobs();
|
||||
HostDispatchJobs(system);
|
||||
|
||||
INFO_LOG_FMT(BOOT, "Starting core = {} mode", system.IsWii() ? "Wii" : "GameCube");
|
||||
INFO_LOG_FMT(BOOT, "CPU Thread separate = {}", system.IsDualCoreMode() ? "Yes" : "No");
|
||||
|
@ -284,7 +284,7 @@ static void ResetRumble()
|
|||
}
|
||||
|
||||
// Called from GUI thread
|
||||
void Stop() // - Hammertime!
|
||||
void Stop(Core::System& system) // - Hammertime!
|
||||
{
|
||||
if (GetState() == State::Stopping || GetState() == State::Uninitialized)
|
||||
return;
|
||||
|
@ -299,9 +299,7 @@ void Stop() // - Hammertime!
|
|||
CallOnStateChangedCallbacks(State::Stopping);
|
||||
|
||||
// Dump left over jobs
|
||||
HostDispatchJobs();
|
||||
|
||||
auto& system = Core::System::GetInstance();
|
||||
HostDispatchJobs(system);
|
||||
|
||||
system.GetFifo().EmulatorState(false);
|
||||
|
||||
|
@ -359,7 +357,7 @@ static void CPUSetInitialExecutionState(bool force_paused = false)
|
|||
{
|
||||
// The CPU starts in stepping state, and will wait until a new state is set before executing.
|
||||
// SetState must be called on the host thread, so we defer it for later.
|
||||
QueueHostJob([force_paused]() {
|
||||
QueueHostJob([force_paused](Core::System&) {
|
||||
bool paused = SConfig::GetInstance().bBootToPause || force_paused;
|
||||
SetState(paused ? State::Paused : State::Running);
|
||||
Host_UpdateDisasmDialog();
|
||||
|
@ -663,7 +661,7 @@ static void EmuThread(Core::System& system, std::unique_ptr<BootParameters> boot
|
|||
system.GetPowerPC().SetMode(PowerPC::CoreMode::Interpreter);
|
||||
}
|
||||
|
||||
UpdateTitle();
|
||||
UpdateTitle(system);
|
||||
|
||||
// ENTER THE VIDEO THREAD LOOP
|
||||
if (system.IsDualCoreMode())
|
||||
|
@ -936,13 +934,12 @@ void Callback_NewField(Core::System& system)
|
|||
#endif // USE_RETRO_ACHIEVEMENTS
|
||||
}
|
||||
|
||||
void UpdateTitle()
|
||||
void UpdateTitle(Core::System& system)
|
||||
{
|
||||
// Settings are shown the same for both extended and summary info
|
||||
const std::string SSettings = fmt::format(
|
||||
"{} {} | {} | {}", Core::System::GetInstance().GetPowerPC().GetCPUName(),
|
||||
Core::System::GetInstance().IsDualCoreMode() ? "DC" : "SC", g_video_backend->GetDisplayName(),
|
||||
Config::Get(Config::MAIN_DSP_HLE) ? "HLE" : "LLE");
|
||||
"{} {} | {} | {}", system.GetPowerPC().GetCPUName(), system.IsDualCoreMode() ? "DC" : "SC",
|
||||
g_video_backend->GetDisplayName(), Config::Get(Config::MAIN_DSP_HLE) ? "HLE" : "LLE");
|
||||
|
||||
std::string message = fmt::format("{} | {}", Common::GetScmRevStr(), SSettings);
|
||||
if (Config::Get(Config::MAIN_SHOW_ACTIVE_TITLE))
|
||||
|
@ -955,7 +952,7 @@ void UpdateTitle()
|
|||
Host_UpdateTitle(message);
|
||||
}
|
||||
|
||||
void Shutdown()
|
||||
void Shutdown(Core::System& system)
|
||||
{
|
||||
// During shutdown DXGI expects us to handle some messages on the UI thread.
|
||||
// Therefore we can't immediately block and wait for the emu thread to shut
|
||||
|
@ -967,7 +964,7 @@ void Shutdown()
|
|||
s_emu_thread.join();
|
||||
|
||||
// Make sure there's nothing left over in case we're about to exit.
|
||||
HostDispatchJobs();
|
||||
HostDispatchJobs(system);
|
||||
}
|
||||
|
||||
int AddOnStateChangedCallback(StateChangedCallbackFunc callback)
|
||||
|
@ -1004,12 +1001,11 @@ void CallOnStateChangedCallbacks(Core::State state)
|
|||
}
|
||||
}
|
||||
|
||||
void UpdateWantDeterminism(bool initial)
|
||||
void UpdateWantDeterminism(Core::System& system, bool initial)
|
||||
{
|
||||
// For now, this value is not itself configurable. Instead, individual
|
||||
// settings that depend on it, such as GPU determinism mode. should have
|
||||
// override options for testing,
|
||||
auto& system = Core::System::GetInstance();
|
||||
bool new_want_determinism = system.GetMovie().IsMovieActive() || NetPlay::IsNetPlayRunning();
|
||||
if (new_want_determinism != s_wants_determinism || initial)
|
||||
{
|
||||
|
@ -1030,7 +1026,7 @@ void UpdateWantDeterminism(bool initial)
|
|||
}
|
||||
}
|
||||
|
||||
void QueueHostJob(std::function<void()> job, bool run_during_stop)
|
||||
void QueueHostJob(std::function<void(Core::System&)> job, bool run_during_stop)
|
||||
{
|
||||
if (!job)
|
||||
return;
|
||||
|
@ -1046,7 +1042,7 @@ void QueueHostJob(std::function<void()> job, bool run_during_stop)
|
|||
Host_Message(HostMessageID::WMUserJobDispatch);
|
||||
}
|
||||
|
||||
void HostDispatchJobs()
|
||||
void HostDispatchJobs(Core::System& system)
|
||||
{
|
||||
// WARNING: This should only run on the Host Thread.
|
||||
// NOTE: This function is potentially re-entrant. If a job calls
|
||||
|
@ -1066,7 +1062,7 @@ void HostDispatchJobs()
|
|||
continue;
|
||||
|
||||
guard.unlock();
|
||||
job.job();
|
||||
job.job(system);
|
||||
guard.lock();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -125,8 +125,8 @@ private:
|
|||
};
|
||||
|
||||
bool Init(Core::System& system, std::unique_ptr<BootParameters> boot, const WindowSystemInfo& wsi);
|
||||
void Stop();
|
||||
void Shutdown();
|
||||
void Stop(Core::System& system);
|
||||
void Shutdown(Core::System& system);
|
||||
|
||||
void DeclareAsCPUThread();
|
||||
void UndeclareAsCPUThread();
|
||||
|
@ -157,7 +157,7 @@ void SaveScreenShot(std::string_view name);
|
|||
void DisplayMessage(std::string message, int time_in_ms);
|
||||
|
||||
void FrameUpdateOnCPUThread();
|
||||
void OnFrameEnd();
|
||||
void OnFrameEnd(Core::System& system);
|
||||
|
||||
// Run a function as the CPU thread.
|
||||
//
|
||||
|
@ -181,7 +181,7 @@ bool RemoveOnStateChangedCallback(int* handle);
|
|||
void CallOnStateChangedCallbacks(Core::State state);
|
||||
|
||||
// Run on the Host thread when the factors change. [NOT THREADSAFE]
|
||||
void UpdateWantDeterminism(bool initial = false);
|
||||
void UpdateWantDeterminism(Core::System& system, bool initial = false);
|
||||
|
||||
// Queue an arbitrary function to asynchronously run once on the Host thread later.
|
||||
// Threadsafe. Can be called by any thread, including the Host itself.
|
||||
|
@ -192,16 +192,16 @@ void UpdateWantDeterminism(bool initial = false);
|
|||
// NOTE: Make sure the jobs check the global state instead of assuming everything is
|
||||
// still the same as when the job was queued.
|
||||
// NOTE: Jobs that are not set to run during stop will be discarded instead.
|
||||
void QueueHostJob(std::function<void()> job, bool run_during_stop = false);
|
||||
void QueueHostJob(std::function<void(Core::System&)> job, bool run_during_stop = false);
|
||||
|
||||
// Should be called periodically by the Host to run pending jobs.
|
||||
// WMUserJobDispatch will be sent when something is added to the queue.
|
||||
void HostDispatchJobs();
|
||||
void HostDispatchJobs(Core::System& system);
|
||||
|
||||
void DoFrameStep();
|
||||
|
||||
void UpdateInputGate(bool require_focus, bool require_full_focus = false);
|
||||
|
||||
void UpdateTitle();
|
||||
void UpdateTitle(Core::System& system);
|
||||
|
||||
} // namespace Core
|
||||
|
|
|
@ -841,7 +841,7 @@ void VideoInterfaceManager::EndField(FieldType field, u64 ticks)
|
|||
|
||||
g_perf_metrics.CountVBlank();
|
||||
VIEndFieldEvent::Trigger();
|
||||
Core::OnFrameEnd();
|
||||
Core::OnFrameEnd(m_system);
|
||||
}
|
||||
|
||||
// Purpose: Send VI interrupt when triggered
|
||||
|
|
|
@ -177,7 +177,7 @@ std::optional<IPCReply> BluetoothRealDevice::Open(const OpenRequest& request)
|
|||
"The emulated console will now stop.",
|
||||
m_last_open_error);
|
||||
}
|
||||
Core::QueueHostJob(Core::Stop);
|
||||
Core::QueueHostJob(&Core::Stop);
|
||||
return IPCReply(IPC_ENOENT);
|
||||
}
|
||||
|
||||
|
|
|
@ -572,7 +572,7 @@ bool MovieManager::BeginRecordingInput(const ControllerTypeArray& controllers,
|
|||
Config::AddLayer(ConfigLoaders::GenerateMovieConfigLoader(&header));
|
||||
|
||||
if (Core::IsRunning())
|
||||
Core::UpdateWantDeterminism();
|
||||
Core::UpdateWantDeterminism(m_system);
|
||||
};
|
||||
Core::RunOnCPUThread(start_recording, true);
|
||||
|
||||
|
@ -958,7 +958,7 @@ bool MovieManager::PlayInput(const std::string& movie_path,
|
|||
// Wiimotes cause desync issues if they're not reset before launching the game
|
||||
Wiimote::ResetAllWiimotes();
|
||||
|
||||
Core::UpdateWantDeterminism();
|
||||
Core::UpdateWantDeterminism(m_system);
|
||||
|
||||
m_temp_input.resize(recording_file.GetSize() - 256);
|
||||
recording_file.ReadBytes(m_temp_input.data(), m_temp_input.size());
|
||||
|
@ -1152,7 +1152,7 @@ void MovieManager::LoadInput(const std::string& movie_path)
|
|||
if (m_play_mode != PlayMode::Playing)
|
||||
{
|
||||
m_play_mode = PlayMode::Playing;
|
||||
Core::UpdateWantDeterminism();
|
||||
Core::UpdateWantDeterminism(m_system);
|
||||
Core::DisplayMessage("Switched to playback", 2000);
|
||||
}
|
||||
}
|
||||
|
@ -1161,7 +1161,7 @@ void MovieManager::LoadInput(const std::string& movie_path)
|
|||
if (m_play_mode != PlayMode::Recording)
|
||||
{
|
||||
m_play_mode = PlayMode::Recording;
|
||||
Core::UpdateWantDeterminism();
|
||||
Core::UpdateWantDeterminism(m_system);
|
||||
Core::DisplayMessage("Switched to recording", 2000);
|
||||
}
|
||||
}
|
||||
|
@ -1355,7 +1355,7 @@ void MovieManager::EndPlayInput(bool cont)
|
|||
// delete tmpInput;
|
||||
// tmpInput = nullptr;
|
||||
|
||||
Core::QueueHostJob([=] { Core::UpdateWantDeterminism(); });
|
||||
Core::QueueHostJob([](Core::System& system) { Core::UpdateWantDeterminism(system); });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -316,9 +316,9 @@ int main(int argc, char* argv[])
|
|||
#endif
|
||||
|
||||
s_platform->MainLoop();
|
||||
Core::Stop();
|
||||
Core::Stop(Core::System::GetInstance());
|
||||
|
||||
Core::Shutdown();
|
||||
Core::Shutdown(Core::System::GetInstance());
|
||||
s_platform.reset();
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "Core/ConfigManager.h"
|
||||
#include "Core/Core.h"
|
||||
#include "Core/State.h"
|
||||
#include "Core/System.h"
|
||||
|
||||
#include <climits>
|
||||
#include <cstdio>
|
||||
|
@ -78,7 +79,7 @@ void PlatformFBDev::MainLoop()
|
|||
while (IsRunning())
|
||||
{
|
||||
UpdateRunningFlag();
|
||||
Core::HostDispatchJobs();
|
||||
Core::HostDispatchJobs(Core::System::GetInstance());
|
||||
|
||||
// TODO: Is this sleep appropriate?
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
|
|
|
@ -3,7 +3,9 @@
|
|||
|
||||
#include <cstdio>
|
||||
#include <thread>
|
||||
|
||||
#include "Core/Core.h"
|
||||
#include "Core/System.h"
|
||||
#include "DolphinNoGUI/Platform.h"
|
||||
|
||||
namespace
|
||||
|
@ -27,7 +29,7 @@ void PlatformHeadless::MainLoop()
|
|||
while (m_running.IsSet())
|
||||
{
|
||||
UpdateRunningFlag();
|
||||
Core::HostDispatchJobs();
|
||||
Core::HostDispatchJobs(Core::System::GetInstance());
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "Core/Config/MainSettings.h"
|
||||
#include "Core/Core.h"
|
||||
#include "Core/State.h"
|
||||
#include "Core/System.h"
|
||||
#include "VideoCommon/Present.h"
|
||||
#include "VideoCommon/RenderBase.h"
|
||||
|
||||
|
@ -225,7 +226,7 @@ void PlatformMacOS::MainLoop()
|
|||
while (IsRunning())
|
||||
{
|
||||
UpdateRunningFlag();
|
||||
Core::HostDispatchJobs();
|
||||
Core::HostDispatchJobs(Core::System::GetInstance());
|
||||
ProcessEvents();
|
||||
UpdateWindowPosition();
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "Core/ConfigManager.h"
|
||||
#include "Core/Core.h"
|
||||
#include "Core/State.h"
|
||||
#include "Core/System.h"
|
||||
|
||||
#include <Windows.h>
|
||||
#include <climits>
|
||||
|
@ -123,7 +124,7 @@ void PlatformWin32::MainLoop()
|
|||
while (IsRunning())
|
||||
{
|
||||
UpdateRunningFlag();
|
||||
Core::HostDispatchJobs();
|
||||
Core::HostDispatchJobs(Core::System::GetInstance());
|
||||
ProcessEvents();
|
||||
UpdateWindowPosition();
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ static constexpr auto X_None = None;
|
|||
#include "Core/Config/MainSettings.h"
|
||||
#include "Core/Core.h"
|
||||
#include "Core/State.h"
|
||||
#include "Core/System.h"
|
||||
|
||||
#include <climits>
|
||||
#include <cstdio>
|
||||
|
@ -151,7 +152,7 @@ void PlatformX11::MainLoop()
|
|||
while (IsRunning())
|
||||
{
|
||||
UpdateRunningFlag();
|
||||
Core::HostDispatchJobs();
|
||||
Core::HostDispatchJobs(Core::System::GetInstance());
|
||||
ProcessEvents();
|
||||
UpdateWindowPosition();
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "Core/Config/MainSettings.h"
|
||||
#include "Core/Core.h"
|
||||
#include "Core/DolphinAnalytics.h"
|
||||
#include "Core/System.h"
|
||||
|
||||
#include "DolphinQt/Host.h"
|
||||
#include "DolphinQt/MainWindow.h"
|
||||
|
@ -179,7 +180,7 @@ int main(int argc, char* argv[])
|
|||
// Whenever the event loop is about to go to sleep, dispatch the jobs
|
||||
// queued in the Core first.
|
||||
QObject::connect(QAbstractEventDispatcher::instance(), &QAbstractEventDispatcher::aboutToBlock,
|
||||
&app, &Core::HostDispatchJobs);
|
||||
&app, [] { Core::HostDispatchJobs(Core::System::GetInstance()); });
|
||||
|
||||
std::optional<std::string> save_state_path;
|
||||
if (options.is_set("save_state"))
|
||||
|
@ -293,7 +294,7 @@ int main(int argc, char* argv[])
|
|||
retval = app.exec();
|
||||
}
|
||||
|
||||
Core::Shutdown();
|
||||
Core::Shutdown(Core::System::GetInstance());
|
||||
UICommon::Shutdown();
|
||||
Host::GetInstance()->deleteLater();
|
||||
|
||||
|
|
|
@ -909,7 +909,7 @@ bool MainWindow::RequestStop()
|
|||
{
|
||||
if (!Core::IsRunning())
|
||||
{
|
||||
Core::QueueHostJob([this] { OnStopComplete(); }, true);
|
||||
Core::QueueHostJob([this](Core::System&) { OnStopComplete(); }, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1009,7 +1009,7 @@ bool MainWindow::RequestStop()
|
|||
|
||||
void MainWindow::ForceStop()
|
||||
{
|
||||
Core::Stop();
|
||||
Core::Stop(Core::System::GetInstance());
|
||||
}
|
||||
|
||||
void MainWindow::Reset()
|
||||
|
|
Loading…
Reference in New Issue