Remove some global usages of system (#6688)

This commit is contained in:
Narr the Reg 2023-07-11 22:43:28 -06:00 committed by GitHub
parent 943d5eeddf
commit d702915624
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 57 additions and 35 deletions

View file

@ -151,7 +151,7 @@ static Core::System::ResultStatus RunCitra(const std::string& filepath) {
Camera::RegisterFactory("ndk", std::move(ndk_factory)); Camera::RegisterFactory("ndk", std::move(ndk_factory));
// Register frontend applets // Register frontend applets
Frontend::RegisterDefaultApplets(); Frontend::RegisterDefaultApplets(system);
system.RegisterMiiSelector(std::make_shared<MiiSelector::AndroidMiiSelector>()); system.RegisterMiiSelector(std::make_shared<MiiSelector::AndroidMiiSelector>());
system.RegisterSoftwareKeyboard(std::make_shared<SoftwareKeyboard::AndroidKeyboard>()); system.RegisterSoftwareKeyboard(std::make_shared<SoftwareKeyboard::AndroidKeyboard>());

View file

@ -346,7 +346,7 @@ int main(int argc, char** argv) {
system.ApplySettings(); system.ApplySettings();
// Register frontend applets // Register frontend applets
Frontend::RegisterDefaultApplets(); Frontend::RegisterDefaultApplets(system);
EmuWindow_SDL2::InitializeSDL2(); EmuWindow_SDL2::InitializeSDL2();
@ -354,12 +354,12 @@ int main(int argc, char** argv) {
bool is_secondary) -> std::unique_ptr<EmuWindow_SDL2> { bool is_secondary) -> std::unique_ptr<EmuWindow_SDL2> {
switch (Settings::values.graphics_api.GetValue()) { switch (Settings::values.graphics_api.GetValue()) {
case Settings::GraphicsAPI::OpenGL: case Settings::GraphicsAPI::OpenGL:
return std::make_unique<EmuWindow_SDL2_GL>(fullscreen, is_secondary); return std::make_unique<EmuWindow_SDL2_GL>(system, fullscreen, is_secondary);
case Settings::GraphicsAPI::Software: case Settings::GraphicsAPI::Software:
return std::make_unique<EmuWindow_SDL2_SW>(system, fullscreen, is_secondary); return std::make_unique<EmuWindow_SDL2_SW>(system, fullscreen, is_secondary);
} }
LOG_ERROR(Frontend, "Invalid Graphics API, using OpenGL"); LOG_ERROR(Frontend, "Invalid Graphics API, using OpenGL");
return std::make_unique<EmuWindow_SDL2_GL>(fullscreen, is_secondary); return std::make_unique<EmuWindow_SDL2_GL>(system, fullscreen, is_secondary);
}; };
const auto emu_window{create_emu_window(fullscreen, false)}; const auto emu_window{create_emu_window(fullscreen, false)};

View file

@ -109,7 +109,8 @@ void EmuWindow_SDL2::Fullscreen() {
SDL_MaximizeWindow(render_window); SDL_MaximizeWindow(render_window);
} }
EmuWindow_SDL2::EmuWindow_SDL2(bool is_secondary) : EmuWindow(is_secondary) {} EmuWindow_SDL2::EmuWindow_SDL2(Core::System& system_, bool is_secondary)
: EmuWindow(is_secondary), system(system_) {}
EmuWindow_SDL2::~EmuWindow_SDL2() { EmuWindow_SDL2::~EmuWindow_SDL2() {
SDL_Quit(); SDL_Quit();
@ -202,7 +203,7 @@ void EmuWindow_SDL2::OnMinimalClientAreaChangeRequest(std::pair<u32, u32> minima
void EmuWindow_SDL2::UpdateFramerateCounter() { void EmuWindow_SDL2::UpdateFramerateCounter() {
const u32 current_time = SDL_GetTicks(); const u32 current_time = SDL_GetTicks();
if (current_time > last_time + 2000) { if (current_time > last_time + 2000) {
const auto results = Core::System::GetInstance().GetAndResetPerfStats(); const auto results = system.GetAndResetPerfStats();
const auto title = const auto title =
fmt::format("Citra {} | {}-{} | FPS: {:.0f} ({:.0f}%)", Common::g_build_fullname, fmt::format("Citra {} | {}-{} | FPS: {:.0f} ({:.0f}%)", Common::g_build_fullname,
Common::g_scm_branch, Common::g_scm_desc, results.game_fps, Common::g_scm_branch, Common::g_scm_desc, results.game_fps,

View file

@ -10,9 +10,13 @@
struct SDL_Window; struct SDL_Window;
namespace Core {
class System;
}
class EmuWindow_SDL2 : public Frontend::EmuWindow { class EmuWindow_SDL2 : public Frontend::EmuWindow {
public: public:
explicit EmuWindow_SDL2(bool is_secondary); explicit EmuWindow_SDL2(Core::System& system_, bool is_secondary);
~EmuWindow_SDL2(); ~EmuWindow_SDL2();
/// Initializes SDL2 /// Initializes SDL2
@ -78,4 +82,6 @@ protected:
/// Keeps track of how often to update the title bar during gameplay /// Keeps track of how often to update the title bar during gameplay
u32 last_time = 0; u32 last_time = 0;
Core::System& system;
}; };

View file

@ -42,8 +42,8 @@ private:
SDL_GLContext context; SDL_GLContext context;
}; };
EmuWindow_SDL2_GL::EmuWindow_SDL2_GL(bool fullscreen, bool is_secondary) EmuWindow_SDL2_GL::EmuWindow_SDL2_GL(Core::System& system_, bool fullscreen, bool is_secondary)
: EmuWindow_SDL2{is_secondary} { : EmuWindow_SDL2{system_, is_secondary} {
// Initialize the window // Initialize the window
if (Settings::values.use_gles) { if (Settings::values.use_gles) {
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);

View file

@ -9,9 +9,13 @@
struct SDL_Window; struct SDL_Window;
namespace Core {
class System;
}
class EmuWindow_SDL2_GL : public EmuWindow_SDL2 { class EmuWindow_SDL2_GL : public EmuWindow_SDL2 {
public: public:
explicit EmuWindow_SDL2_GL(bool fullscreen, bool is_secondary); explicit EmuWindow_SDL2_GL(Core::System& system_, bool fullscreen, bool is_secondary);
~EmuWindow_SDL2_GL(); ~EmuWindow_SDL2_GL();
void Present() override; void Present() override;

View file

@ -18,7 +18,7 @@
class DummyContext : public Frontend::GraphicsContext {}; class DummyContext : public Frontend::GraphicsContext {};
EmuWindow_SDL2_SW::EmuWindow_SDL2_SW(Core::System& system_, bool fullscreen, bool is_secondary) EmuWindow_SDL2_SW::EmuWindow_SDL2_SW(Core::System& system_, bool fullscreen, bool is_secondary)
: EmuWindow_SDL2{is_secondary}, system{system_} { : EmuWindow_SDL2{system_, is_secondary}, system{system_} {
std::string window_title = fmt::format("Citra {} | {}-{}", Common::g_build_fullname, std::string window_title = fmt::format("Citra {} | {}-{}", Common::g_build_fullname,
Common::g_scm_branch, Common::g_scm_desc); Common::g_scm_branch, Common::g_scm_desc);
render_window = render_window =

View file

@ -44,7 +44,8 @@
static Frontend::WindowSystemType GetWindowSystemType(); static Frontend::WindowSystemType GetWindowSystemType();
EmuThread::EmuThread(Frontend::GraphicsContext& core_context) : core_context(core_context) {} EmuThread::EmuThread(Core::System& system_, Frontend::GraphicsContext& core_context)
: system{system_}, core_context(core_context) {}
EmuThread::~EmuThread() = default; EmuThread::~EmuThread() = default;
@ -62,7 +63,6 @@ static GMainWindow* GetMainWindow() {
void EmuThread::run() { void EmuThread::run() {
MicroProfileOnThreadCreate("EmuThread"); MicroProfileOnThreadCreate("EmuThread");
const auto scope = core_context.Acquire(); const auto scope = core_context.Acquire();
Core::System& system = Core::System::GetInstance();
if (Settings::values.preload_textures) { if (Settings::values.preload_textures) {
emit LoadProgress(VideoCore::LoadCallbackStage::Preload, 0, 0); emit LoadProgress(VideoCore::LoadCallbackStage::Preload, 0, 0);
@ -107,7 +107,7 @@ void EmuThread::run() {
} }
if (result != Core::System::ResultStatus::Success) { if (result != Core::System::ResultStatus::Success) {
this->SetRunning(false); this->SetRunning(false);
emit ErrorThrown(result, Core::System::GetInstance().GetStatusDetails()); emit ErrorThrown(result, system.GetStatusDetails());
} }
was_active = running || exec_step; was_active = running || exec_step;
@ -248,8 +248,8 @@ public:
#ifdef HAS_OPENGL #ifdef HAS_OPENGL
class OpenGLRenderWidget : public RenderWidget { class OpenGLRenderWidget : public RenderWidget {
public: public:
explicit OpenGLRenderWidget(GRenderWindow* parent, bool is_secondary) explicit OpenGLRenderWidget(GRenderWindow* parent, Core::System& system_, bool is_secondary)
: RenderWidget(parent), is_secondary(is_secondary) { : RenderWidget(parent), system(system_), is_secondary(is_secondary) {
setAttribute(Qt::WA_NativeWindow); setAttribute(Qt::WA_NativeWindow);
setAttribute(Qt::WA_PaintOnScreen); setAttribute(Qt::WA_PaintOnScreen);
if (GetWindowSystemType() == Frontend::WindowSystemType::Wayland) { if (GetWindowSystemType() == Frontend::WindowSystemType::Wayland) {
@ -266,7 +266,7 @@ public:
if (!isVisible()) { if (!isVisible()) {
return; return;
} }
if (!Core::System::GetInstance().IsPoweredOn()) { if (!system.IsPoweredOn()) {
return; return;
} }
context->MakeCurrent(); context->MakeCurrent();
@ -284,6 +284,7 @@ public:
private: private:
std::unique_ptr<Frontend::GraphicsContext> context{}; std::unique_ptr<Frontend::GraphicsContext> context{};
Core::System& system;
bool is_secondary; bool is_secondary;
}; };
#endif #endif
@ -296,7 +297,7 @@ struct SoftwareRenderWidget : public RenderWidget {
if (!isVisible()) { if (!isVisible()) {
return; return;
} }
if (!Core::System::GetInstance().IsPoweredOn()) { if (!system.IsPoweredOn()) {
return; return;
} }
@ -666,7 +667,7 @@ bool GRenderWindow::InitializeOpenGL() {
// TODO: One of these flags might be interesting: WA_OpaquePaintEvent, WA_NoBackground, // TODO: One of these flags might be interesting: WA_OpaquePaintEvent, WA_NoBackground,
// WA_DontShowOnScreen, WA_DeleteOnClose // WA_DontShowOnScreen, WA_DeleteOnClose
auto child = new OpenGLRenderWidget(this, is_secondary); auto child = new OpenGLRenderWidget(this, system, is_secondary);
child_widget = child; child_widget = child;
child_widget->windowHandle()->create(); child_widget->windowHandle()->create();

View file

@ -18,6 +18,10 @@ class QTouchEvent;
class GRenderWindow; class GRenderWindow;
namespace Core {
class System;
}
namespace VideoCore { namespace VideoCore {
enum class LoadCallbackStage; enum class LoadCallbackStage;
} }
@ -26,7 +30,7 @@ class EmuThread final : public QThread {
Q_OBJECT Q_OBJECT
public: public:
explicit EmuThread(Frontend::GraphicsContext& context); explicit EmuThread(Core::System& system_, Frontend::GraphicsContext& context);
~EmuThread() override; ~EmuThread() override;
/** /**
@ -80,6 +84,7 @@ private:
std::mutex running_mutex; std::mutex running_mutex;
std::condition_variable running_cv; std::condition_variable running_cv;
Core::System& system;
Frontend::GraphicsContext& core_context; Frontend::GraphicsContext& core_context;
signals: signals:

View file

@ -11,9 +11,9 @@
#include "core/core.h" #include "core/core.h"
#include "ui_compatdb.h" #include "ui_compatdb.h"
CompatDB::CompatDB(QWidget* parent) CompatDB::CompatDB(Core::TelemetrySession& telemetry_session_, QWidget* parent)
: QWizard(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint | Qt::WindowSystemMenuHint), : QWizard(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint | Qt::WindowSystemMenuHint),
ui{std::make_unique<Ui::CompatDB>()} { ui{std::make_unique<Ui::CompatDB>()}, telemetry_session{telemetry_session_} {
ui->setupUi(this); ui->setupUi(this);
connect(ui->radioButton_Perfect, &QRadioButton::clicked, this, &CompatDB::EnableNext); connect(ui->radioButton_Perfect, &QRadioButton::clicked, this, &CompatDB::EnableNext);
connect(ui->radioButton_Great, &QRadioButton::clicked, this, &CompatDB::EnableNext); connect(ui->radioButton_Great, &QRadioButton::clicked, this, &CompatDB::EnableNext);
@ -51,16 +51,15 @@ void CompatDB::Submit() {
case CompatDBPage::Final: case CompatDBPage::Final:
back(); back();
LOG_DEBUG(Frontend, "Compatibility Rating: {}", compatibility->checkedId()); LOG_DEBUG(Frontend, "Compatibility Rating: {}", compatibility->checkedId());
Core::System::GetInstance().TelemetrySession().AddField( telemetry_session.AddField(Common::Telemetry::FieldType::UserFeedback, "Compatibility",
Common::Telemetry::FieldType::UserFeedback, "Compatibility", compatibility->checkedId());
compatibility->checkedId());
button(NextButton)->setEnabled(false); button(NextButton)->setEnabled(false);
button(NextButton)->setText(tr("Submitting")); button(NextButton)->setText(tr("Submitting"));
button(CancelButton)->setVisible(false); button(CancelButton)->setVisible(false);
testcase_watcher.setFuture(QtConcurrent::run( testcase_watcher.setFuture(
[] { return Core::System::GetInstance().TelemetrySession().SubmitTestcase(); })); QtConcurrent::run([this] { return telemetry_session.SubmitTestcase(); }));
break; break;
default: default:
LOG_ERROR(Frontend, "Unexpected page: {}", currentId()); LOG_ERROR(Frontend, "Unexpected page: {}", currentId());

View file

@ -8,6 +8,10 @@
#include <QFutureWatcher> #include <QFutureWatcher>
#include <QWizard> #include <QWizard>
namespace Core {
class TelemetrySession;
}
namespace Ui { namespace Ui {
class CompatDB; class CompatDB;
} }
@ -16,7 +20,7 @@ class CompatDB : public QWizard {
Q_OBJECT Q_OBJECT
public: public:
explicit CompatDB(QWidget* parent = nullptr); explicit CompatDB(Core::TelemetrySession& telemetry_session_, QWidget* parent = nullptr);
~CompatDB(); ~CompatDB();
private: private:
@ -27,4 +31,6 @@ private:
void Submit(); void Submit();
void OnTestcaseSubmitted(); void OnTestcaseSubmitted();
void EnableNext(); void EnableNext();
Core::TelemetrySession& telemetry_session;
}; };

View file

@ -1223,7 +1223,7 @@ void GMainWindow::BootGame(const QString& filename) {
} }
// Create and start the emulation thread // Create and start the emulation thread
emu_thread = std::make_unique<EmuThread>(*render_window); emu_thread = std::make_unique<EmuThread>(system, *render_window);
emit EmulationStarting(emu_thread.get()); emit EmulationStarting(emu_thread.get());
emu_thread->start(); emu_thread->start();
@ -1814,7 +1814,7 @@ void GMainWindow::OnLoadComplete() {
void GMainWindow::OnMenuReportCompatibility() { void GMainWindow::OnMenuReportCompatibility() {
if (!NetSettings::values.citra_token.empty() && !NetSettings::values.citra_username.empty()) { if (!NetSettings::values.citra_token.empty() && !NetSettings::values.citra_username.empty()) {
CompatDB compatdb{this}; CompatDB compatdb{system.TelemetrySession(), this};
compatdb.exec(); compatdb.exec();
} else { } else {
QMessageBox::critical(this, tr("Missing Citra Account"), QMessageBox::critical(this, tr("Missing Citra Account"),
@ -2931,7 +2931,7 @@ int main(int argc, char* argv[]) {
GMainWindow main_window(system); GMainWindow main_window(system);
// Register frontend applets // Register frontend applets
Frontend::RegisterDefaultApplets(); Frontend::RegisterDefaultApplets(system);
system.RegisterMiiSelector(std::make_shared<QtMiiSelector>(main_window)); system.RegisterMiiSelector(std::make_shared<QtMiiSelector>(main_window));
system.RegisterSoftwareKeyboard(std::make_shared<QtKeyboard>(main_window)); system.RegisterSoftwareKeyboard(std::make_shared<QtKeyboard>(main_window));

View file

@ -8,8 +8,8 @@
#include "core/frontend/applets/swkbd.h" #include "core/frontend/applets/swkbd.h"
namespace Frontend { namespace Frontend {
void RegisterDefaultApplets() { void RegisterDefaultApplets(Core::System& system) {
Core::System::GetInstance().RegisterSoftwareKeyboard(std::make_shared<DefaultKeyboard>()); system.RegisterSoftwareKeyboard(std::make_shared<DefaultKeyboard>());
Core::System::GetInstance().RegisterMiiSelector(std::make_shared<DefaultMiiSelector>()); system.RegisterMiiSelector(std::make_shared<DefaultMiiSelector>());
} }
} // namespace Frontend } // namespace Frontend

View file

@ -9,5 +9,5 @@ namespace Frontend {
* Registers default, frontend-independent applet implementations. * Registers default, frontend-independent applet implementations.
* Will be replaced later if any frontend-specific implementation is available. * Will be replaced later if any frontend-specific implementation is available.
*/ */
void RegisterDefaultApplets(); void RegisterDefaultApplets(Core::System& system);
} // namespace Frontend } // namespace Frontend