Qt: Combine EmuThread.cpp and QtHost.cpp

These mostly called back between one another.
This commit is contained in:
Connor McLaughlin 2022-09-07 19:20:50 +10:00 committed by refractionpcsx2
parent e4df563811
commit b667236c92
23 changed files with 1310 additions and 1385 deletions

View File

@ -20,8 +20,6 @@ target_sources(pcsx2-qt PRIVATE
DisplayWidget.cpp
DisplayWidget.h
EarlyHardwareCheck.cpp
EmuThread.cpp
EmuThread.h
MainWindow.cpp
MainWindow.h
MainWindow.ui

View File

@ -20,7 +20,6 @@
#include "pcsx2/Frontend/ImGuiManager.h"
#include "DisplayWidget.h"
#include "EmuThread.h"
#include "MainWindow.h"
#include "QtHost.h"
#include "QtUtils.h"

File diff suppressed because it is too large Load Diff

View File

@ -1,189 +0,0 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2022 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "pcsx2/Host.h"
#include "pcsx2/HostDisplay.h"
#include "pcsx2/Frontend/InputManager.h"
#include <QtCore/QList>
#include <QtCore/QEventLoop>
#include <QtCore/QPair>
#include <QtCore/QString>
#include <QtCore/QSemaphore>
#include <QtCore/QTimer>
#include <QtCore/QThread>
#include <atomic>
#include <memory>
class DisplayWidget;
struct VMBootParameters;
enum class CDVD_SourceType : uint8_t;
class EmuThread : public QThread
{
Q_OBJECT
public:
explicit EmuThread(QThread* ui_thread);
~EmuThread();
static void start();
static void stop();
__fi QEventLoop* getEventLoop() const { return m_event_loop; }
__fi bool isFullscreen() const { return m_is_fullscreen; }
__fi bool isRenderingToMain() const { return m_is_rendering_to_main; }
__fi bool isSurfaceless() const { return m_is_surfaceless; }
__fi bool isRunningFullscreenUI() const { return m_run_fullscreen_ui; }
bool isOnEmuThread() const;
/// Called back from the GS thread when the display state changes (e.g. fullscreen, render to main).
HostDisplay* acquireHostDisplay(HostDisplay::RenderAPI api);
void connectDisplaySignals(DisplayWidget* widget);
void releaseHostDisplay();
void updateDisplay();
void startBackgroundControllerPollTimer();
void stopBackgroundControllerPollTimer();
void updatePerformanceMetrics(bool force);
public Q_SLOTS:
bool confirmMessage(const QString& title, const QString& message);
void startFullscreenUI(bool fullscreen);
void stopFullscreenUI();
void startVM(std::shared_ptr<VMBootParameters> boot_params);
void resetVM();
void setVMPaused(bool paused);
void shutdownVM(bool save_state = true);
void loadState(const QString& filename);
void loadStateFromSlot(qint32 slot);
void saveState(const QString& filename);
void saveStateToSlot(qint32 slot);
void toggleFullscreen();
void setFullscreen(bool fullscreen);
void setSurfaceless(bool surfaceless);
void applySettings();
void reloadGameSettings();
void updateEmuFolders();
void toggleSoftwareRendering();
void switchRenderer(GSRendererType renderer);
void changeDisc(CDVD_SourceType source, const QString& path);
void reloadPatches();
void reloadInputSources();
void reloadInputBindings();
void requestDisplaySize(float scale);
void enumerateInputDevices();
void enumerateVibrationMotors();
void runOnCPUThread(const std::function<void()>& func);
void queueSnapshot(quint32 gsdump_frames);
Q_SIGNALS:
bool messageConfirmed(const QString& title, const QString& message);
DisplayWidget* onCreateDisplayRequested(bool fullscreen, bool render_to_main);
DisplayWidget* onUpdateDisplayRequested(bool fullscreen, bool render_to_main, bool surfaceless);
void onResizeDisplayRequested(qint32 width, qint32 height);
void onDestroyDisplayRequested();
/// Called when the VM is starting initialization, but has not been completed yet.
void onVMStarting();
/// Called when the VM is created.
void onVMStarted();
/// Called when the VM is paused.
void onVMPaused();
/// Called when the VM is resumed after being paused.
void onVMResumed();
/// Called when the VM is shut down or destroyed.
void onVMStopped();
/// Provided by the host; called when the running executable changes.
void onGameChanged(const QString& path, const QString& serial, const QString& name, quint32 crc);
void onInputDevicesEnumerated(const QList<QPair<QString, QString>>& devices);
void onInputDeviceConnected(const QString& identifier, const QString& device_name);
void onInputDeviceDisconnected(const QString& identifier);
void onVibrationMotorsEnumerated(const QList<InputBindingKey>& motors);
/// Called when a save state is loading, before the file is processed.
void onSaveStateLoading(const QString& path);
/// Called after a save state is successfully loaded. If the save state was invalid, was_successful will be false.
void onSaveStateLoaded(const QString& path, bool was_successful);
/// Called when a save state is being created/saved. The compression/write to disk is asynchronous, so this callback
/// just signifies that the save has started, not necessarily completed.
void onSaveStateSaved(const QString& path);
protected:
void run();
private:
/// Interval at which the controllers are polled when the system is not active.
static constexpr u32 BACKGROUND_CONTROLLER_POLLING_INTERVAL = 100;
/// Poll at half the vsync rate for FSUI to reduce the chance of getting a press+release in the same frame.
static constexpr u32 FULLSCREEN_UI_CONTROLLER_POLLING_INTERVAL = 8;
void destroyVM();
void executeVM();
void checkForSettingChanges();
bool shouldRenderToMain() const;
void createBackgroundControllerPollTimer();
void destroyBackgroundControllerPollTimer();
void connectSignals();
void loadOurSettings();
void loadOurInitialSettings();
private Q_SLOTS:
void stopInThread();
void doBackgroundControllerPoll();
void onDisplayWindowResized(int width, int height, float scale);
void onApplicationStateChanged(Qt::ApplicationState state);
void redrawDisplayWindow();
private:
QThread* m_ui_thread;
QSemaphore m_started_semaphore;
QEventLoop* m_event_loop = nullptr;
QTimer* m_background_controller_polling_timer = nullptr;
std::atomic_bool m_shutdown_flag{false};
bool m_verbose_status = false;
bool m_run_fullscreen_ui = false;
bool m_is_rendering_to_main = false;
bool m_is_fullscreen = false;
bool m_is_surfaceless = false;
bool m_save_state_on_shutdown = false;
bool m_pause_on_focus_loss = false;
bool m_was_paused_by_focus_loss = false;
float m_last_speed = 0.0f;
float m_last_game_fps = 0.0f;
float m_last_video_fps = 0.0f;
int m_last_internal_width = 0;
int m_last_internal_height = 0;
GSRendererType m_last_renderer = GSRendererType::Null;
};
extern EmuThread* g_emu_thread;

View File

@ -41,7 +41,6 @@
#include "AboutDialog.h"
#include "AutoUpdaterDialog.h"
#include "DisplayWidget.h"
#include "EmuThread.h"
#include "GameList/GameListRefreshThread.h"
#include "GameList/GameListWidget.h"
#include "MainWindow.h"

File diff suppressed because it is too large Load Diff

View File

@ -14,30 +14,197 @@
*/
#pragma once
#include <atomic>
#include <memory>
#include <functional>
#include <optional>
#include "pcsx2/Host.h"
#include "pcsx2/HostDisplay.h"
#include "pcsx2/HostSettings.h"
#include "pcsx2/Frontend/InputManager.h"
#include "pcsx2/VMManager.h"
#include <QtCore/QList>
#include <QtCore/QEventLoop>
#include <QtCore/QMetaType>
#include <QtCore/QPair>
#include <QtCore/QString>
#include <functional>
#include <memory>
#include <optional>
#include <QtCore/QSemaphore>
#include <QtCore/QString>
#include <QtCore/QTimer>
#include <QtCore/QThread>
class SettingsInterface;
class EmuThread;
class DisplayWidget;
struct VMBootParameters;
enum class CDVD_SourceType : uint8_t;
Q_DECLARE_METATYPE(std::shared_ptr<VMBootParameters>);
Q_DECLARE_METATYPE(std::optional<bool>);
Q_DECLARE_METATYPE(std::function<void()>);
Q_DECLARE_METATYPE(GSRendererType);
Q_DECLARE_METATYPE(InputBindingKey);
Q_DECLARE_METATYPE(CDVD_SourceType);
class EmuThread : public QThread
{
Q_OBJECT
public:
explicit EmuThread(QThread* ui_thread);
~EmuThread();
static void start();
static void stop();
__fi QEventLoop* getEventLoop() const { return m_event_loop; }
__fi bool isFullscreen() const { return m_is_fullscreen; }
__fi bool isRenderingToMain() const { return m_is_rendering_to_main; }
__fi bool isSurfaceless() const { return m_is_surfaceless; }
__fi bool isRunningFullscreenUI() const { return m_run_fullscreen_ui; }
bool isOnEmuThread() const;
/// Called back from the GS thread when the display state changes (e.g. fullscreen, render to main).
HostDisplay* acquireHostDisplay(HostDisplay::RenderAPI api);
void connectDisplaySignals(DisplayWidget* widget);
void releaseHostDisplay();
void updateDisplay();
void startBackgroundControllerPollTimer();
void stopBackgroundControllerPollTimer();
void updatePerformanceMetrics(bool force);
public Q_SLOTS:
bool confirmMessage(const QString& title, const QString& message);
void startFullscreenUI(bool fullscreen);
void stopFullscreenUI();
void startVM(std::shared_ptr<VMBootParameters> boot_params);
void resetVM();
void setVMPaused(bool paused);
void shutdownVM(bool save_state = true);
void loadState(const QString& filename);
void loadStateFromSlot(qint32 slot);
void saveState(const QString& filename);
void saveStateToSlot(qint32 slot);
void toggleFullscreen();
void setFullscreen(bool fullscreen);
void setSurfaceless(bool surfaceless);
void applySettings();
void reloadGameSettings();
void updateEmuFolders();
void toggleSoftwareRendering();
void switchRenderer(GSRendererType renderer);
void changeDisc(CDVD_SourceType source, const QString& path);
void reloadPatches();
void reloadInputSources();
void reloadInputBindings();
void requestDisplaySize(float scale);
void enumerateInputDevices();
void enumerateVibrationMotors();
void runOnCPUThread(const std::function<void()>& func);
void queueSnapshot(quint32 gsdump_frames);
Q_SIGNALS:
bool messageConfirmed(const QString& title, const QString& message);
DisplayWidget* onCreateDisplayRequested(bool fullscreen, bool render_to_main);
DisplayWidget* onUpdateDisplayRequested(bool fullscreen, bool render_to_main, bool surfaceless);
void onResizeDisplayRequested(qint32 width, qint32 height);
void onDestroyDisplayRequested();
/// Called when the VM is starting initialization, but has not been completed yet.
void onVMStarting();
/// Called when the VM is created.
void onVMStarted();
/// Called when the VM is paused.
void onVMPaused();
/// Called when the VM is resumed after being paused.
void onVMResumed();
/// Called when the VM is shut down or destroyed.
void onVMStopped();
/// Provided by the host; called when the running executable changes.
void onGameChanged(const QString& path, const QString& serial, const QString& name, quint32 crc);
void onInputDevicesEnumerated(const QList<QPair<QString, QString>>& devices);
void onInputDeviceConnected(const QString& identifier, const QString& device_name);
void onInputDeviceDisconnected(const QString& identifier);
void onVibrationMotorsEnumerated(const QList<InputBindingKey>& motors);
/// Called when a save state is loading, before the file is processed.
void onSaveStateLoading(const QString& path);
/// Called after a save state is successfully loaded. If the save state was invalid, was_successful will be false.
void onSaveStateLoaded(const QString& path, bool was_successful);
/// Called when a save state is being created/saved. The compression/write to disk is asynchronous, so this callback
/// just signifies that the save has started, not necessarily completed.
void onSaveStateSaved(const QString& path);
protected:
void run();
private:
/// Interval at which the controllers are polled when the system is not active.
static constexpr u32 BACKGROUND_CONTROLLER_POLLING_INTERVAL = 100;
/// Poll at half the vsync rate for FSUI to reduce the chance of getting a press+release in the same frame.
static constexpr u32 FULLSCREEN_UI_CONTROLLER_POLLING_INTERVAL = 8;
void destroyVM();
void executeVM();
void checkForSettingChanges();
bool shouldRenderToMain() const;
void createBackgroundControllerPollTimer();
void destroyBackgroundControllerPollTimer();
void connectSignals();
void loadOurSettings();
void loadOurInitialSettings();
private Q_SLOTS:
void stopInThread();
void doBackgroundControllerPoll();
void onDisplayWindowResized(int width, int height, float scale);
void onApplicationStateChanged(Qt::ApplicationState state);
void redrawDisplayWindow();
private:
QThread* m_ui_thread;
QSemaphore m_started_semaphore;
QEventLoop* m_event_loop = nullptr;
QTimer* m_background_controller_polling_timer = nullptr;
std::atomic_bool m_shutdown_flag{false};
bool m_verbose_status = false;
bool m_run_fullscreen_ui = false;
bool m_is_rendering_to_main = false;
bool m_is_fullscreen = false;
bool m_is_surfaceless = false;
bool m_save_state_on_shutdown = false;
bool m_pause_on_focus_loss = false;
bool m_was_paused_by_focus_loss = false;
float m_last_speed = 0.0f;
float m_last_game_fps = 0.0f;
float m_last_video_fps = 0.0f;
int m_last_internal_width = 0;
int m_last_internal_height = 0;
GSRendererType m_last_renderer = GSRendererType::Null;
};
extern EmuThread* g_emu_thread;
namespace QtHost
{
/// Sets batch mode (exit after game shutdown).

View File

@ -35,7 +35,6 @@
#include "pcsx2/Config.h"
#include "pcsx2/HostSettings.h"
#include "EmuThread.h"
#include "QtHost.h"
#include "QtUtils.h"
#include "Settings/SettingsDialog.h"

View File

@ -19,7 +19,7 @@
#include <algorithm>
#include "AdvancedSystemSettingsWidget.h"
#include "EmuThread.h"
#include "QtHost.h"
#include "QtUtils.h"
#include "SettingWidgetBinder.h"
#include "SettingsDialog.h"

View File

@ -19,7 +19,7 @@
#include <algorithm>
#include "AudioSettingsWidget.h"
#include "EmuThread.h"
#include "QtHost.h"
#include "QtUtils.h"
#include "SettingWidgetBinder.h"
#include "SettingsDialog.h"

View File

@ -24,7 +24,7 @@
#include "Settings/ControllerSettingsDialog.h"
#include "Settings/ControllerSettingWidgetBinder.h"
#include "Settings/SettingsDialog.h"
#include "EmuThread.h"
#include "QtHost.h"
#include "QtUtils.h"
#include "SettingWidgetBinder.h"

View File

@ -29,9 +29,7 @@
#include "pcsx2/HostSettings.h"
#include "EmuThread.h"
#include "QtHost.h"
#include "SettingWidgetBinder.h"
/// This nastyness is required because input profiles aren't overlaid settings like the rest of them, it's

View File

@ -15,7 +15,6 @@
#include "PrecompiledHeader.h"
#include "EmuThread.h"
#include "QtHost.h"
#include "Settings/ControllerSettingsDialog.h"
#include "Settings/ControllerGlobalSettingsWidget.h"

View File

@ -22,7 +22,7 @@
#include "common/StringUtil.h"
#include "DEV9DnsHostDialog.h"
#include "EmuThread.h"
#include "QtHost.h"
#include "QtUtils.h"
#include "SettingWidgetBinder.h"
#include "SettingsDialog.h"

View File

@ -26,7 +26,7 @@
#include "pcsx2/HostSettings.h"
#include "DEV9SettingsWidget.h"
#include "EmuThread.h"
#include "QtHost.h"
#include "QtUtils.h"
#include "SettingWidgetBinder.h"
#include "SettingsDialog.h"

View File

@ -19,7 +19,7 @@
#include <algorithm>
#include "GameFixSettingsWidget.h"
#include "EmuThread.h"
#include "QtHost.h"
#include "QtUtils.h"
#include "SettingWidgetBinder.h"
#include "SettingsDialog.h"

View File

@ -15,7 +15,6 @@
#include "PrecompiledHeader.h"
#include "EmuThread.h"
#include "QtHost.h"
#include "QtUtils.h"
#include "Settings/InputBindingDialog.h"

View File

@ -28,7 +28,6 @@
#include "pcsx2/GS/GSIntrin.h" // _BitScanForward
#include "EmuThread.h"
#include "QtHost.h"
#include "QtUtils.h"
#include "Settings/ControllerSettingsDialog.h"

View File

@ -26,7 +26,7 @@
#include "MemoryCardSettingsWidget.h"
#include "CreateMemoryCardDialog.h"
#include "EmuThread.h"
#include "QtHost.h"
#include "QtUtils.h"
#include "SettingWidgetBinder.h"
#include "SettingsDialog.h"

View File

@ -23,7 +23,6 @@
#include "pcsx2/Frontend/GameList.h"
#include "pcsx2/Frontend/INISettingsInterface.h"
#include "EmuThread.h"
#include "MainWindow.h"
#include "QtHost.h"
#include "QtUtils.h"

View File

@ -20,7 +20,7 @@
#include "pcsx2/HostSettings.h"
#include "EmuThread.h"
#include "QtHost.h"
#include "QtUtils.h"
#include "SettingWidgetBinder.h"
#include "SettingsDialog.h"

View File

@ -171,7 +171,6 @@
<ClCompile Include="PrecompiledHeader.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="EmuThread.cpp" />
<ClCompile Include="QtKeyCodes.cpp" />
<ClCompile Include="QtUtils.cpp" />
</ItemGroup>
@ -207,11 +206,10 @@
<QtMoc Include="Settings\ControllerBindingWidgets.h" />
<QtMoc Include="Settings\ControllerGlobalSettingsWidget.h" />
<ClInclude Include="SettingWidgetBinder.h" />
<ClInclude Include="QtHost.h" />
<QtMoc Include="QtHost.h" />
<ClInclude Include="PrecompiledHeader.h" />
<QtMoc Include="AboutDialog.h" />
<QtMoc Include="AutoUpdaterDialog.h" />
<QtMoc Include="EmuThread.h" />
<QtMoc Include="MainWindow.h" />
<QtMoc Include="DisplayWidget.h" />
</ItemGroup>
@ -250,8 +248,8 @@
<ClCompile Include="$(IntDir)moc_AboutDialog.cpp" />
<ClCompile Include="$(IntDir)moc_AutoUpdaterDialog.cpp" />
<ClCompile Include="$(IntDir)moc_DisplayWidget.cpp" />
<ClCompile Include="$(IntDir)moc_EmuThread.cpp" />
<ClCompile Include="$(IntDir)moc_MainWindow.cpp" />
<ClCompile Include="$(IntDir)moc_QtHost.cpp" />
<ClCompile Include="$(IntDir)Tools\InputRecording\moc_NewInputRecordingDlg.cpp" />
<ClCompile Include="$(IntDir)qrc_resources.cpp">
<PrecompiledHeader>NotUsing</PrecompiledHeader>

View File

@ -42,9 +42,8 @@
<ClCompile Include="$(IntDir)moc_DisplayWidget.cpp">
<Filter>moc</Filter>
</ClCompile>
<ClCompile Include="EmuThread.cpp" />
<ClCompile Include="QtUtils.cpp" />
<ClCompile Include="$(IntDir)moc_EmuThread.cpp">
<ClCompile Include="$(IntDir)moc_QtHost.cpp">
<Filter>moc</Filter>
</ClCompile>
<ClCompile Include="QtKeyCodes.cpp" />
@ -243,7 +242,6 @@
<ItemGroup>
<QtMoc Include="MainWindow.h" />
<QtMoc Include="DisplayWidget.h" />
<QtMoc Include="EmuThread.h" />
<QtMoc Include="Settings\BIOSSettingsWidget.h">
<Filter>Settings</Filter>
</QtMoc>