Skip to content

Commit

Permalink
Qt configs: Make thread-safe, properly update audio enable & renderdo…
Browse files Browse the repository at this point in the history
…c settings
  • Loading branch information
wheremyfoodat committed Dec 1, 2024
1 parent 266e637 commit 87878d3
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 74 deletions.
3 changes: 3 additions & 0 deletions include/emulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ class Emulator {
void setOutputSize(u32 width, u32 height) { gpu.setOutputSize(width, height); }
void deinitGraphicsContext() { gpu.deinitGraphicsContext(); }

// Reloads some settings that require special handling, such as audio enable
void reloadSettings();

EmulatorConfig& getConfig() { return config; }
Cheats& getCheats() { return cheats; }
ServiceManager& getServiceManager() { return kernel.getServiceManager(); }
Expand Down
17 changes: 13 additions & 4 deletions include/panda_qt/config_window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
class ConfigWindow : public QDialog {
Q_OBJECT

private:
private:
using ConfigCallback = std::function<void()>;

enum class Theme : int {
System = 0,
Light = 1,
Expand All @@ -36,13 +38,20 @@ class ConfigWindow : public QDialog {
static constexpr size_t settingWidgetCount = 6;
std::array<QString, settingWidgetCount> helpTexts;

// The config class holds a copy of the emulator config which it edits and sends
// over to the emulator in a thread-safe manner
EmulatorConfig config;
ConfigCallback updateConfig;

void addWidget(QWidget* widget, QString title, QString icon, QString helpText);
void setTheme(Theme theme);

public:
ConfigWindow(Emulator* emu, QWidget* parent = nullptr);
public:
ConfigWindow(ConfigCallback callback, const EmulatorConfig& config, QWidget* parent = nullptr);
~ConfigWindow();

private:
EmulatorConfig& getConfig() { return config; }

private:
Emulator* emu;
};
1 change: 1 addition & 0 deletions include/panda_qt/main_window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class MainWindow : public QMainWindow {
ReleaseTouchscreen,
ReloadUbershader,
SetScreenSize,
UpdateConfig,
};

// Tagged union representing our message queue messages
Expand Down
4 changes: 4 additions & 0 deletions include/renderdoc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ namespace Renderdoc {
// Sets output directory for captures
void setOutputDir(const std::string& path, const std::string& prefix);

// Returns whether Renderdoc has been loaded
bool isLoaded();

// Returns whether we've compiled with Renderdoc support
static constexpr bool isSupported() { return true; }
} // namespace Renderdoc
Expand All @@ -34,6 +37,7 @@ namespace Renderdoc {
static void triggerCapture() { Helpers::panic("Tried to trigger a Renderdoc capture while support for renderdoc is disabled"); }
static void setOutputDir(const std::string& path, const std::string& prefix) {}
static constexpr bool isSupported() { return false; }
static constexpr bool isLoaded() { return false; }
} // namespace Renderdoc
#endif

Expand Down
8 changes: 8 additions & 0 deletions src/emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,3 +444,11 @@ void Emulator::loadRenderdoc() {
Renderdoc::loadRenderdoc();
Renderdoc::setOutputDir(capturePath, "");
}

void Emulator::reloadSettings() {
setAudioEnabled(config.audioEnabled);

if (Renderdoc::isSupported() && config.enableRenderdoc && !Renderdoc::isLoaded()) {
loadRenderdoc();
}
}
Loading

0 comments on commit 87878d3

Please sign in to comment.