mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-08 07:05:40 +12:00
Qt configs: Make thread-safe, properly update audio enable & renderdoc settings
This commit is contained in:
parent
266e637790
commit
87878d3cba
8 changed files with 116 additions and 74 deletions
|
@ -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(); }
|
||||
|
|
|
@ -20,6 +20,8 @@ class ConfigWindow : public QDialog {
|
|||
Q_OBJECT
|
||||
|
||||
private:
|
||||
using ConfigCallback = std::function<void()>;
|
||||
|
||||
enum class Theme : int {
|
||||
System = 0,
|
||||
Light = 1,
|
||||
|
@ -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);
|
||||
ConfigWindow(ConfigCallback callback, const EmulatorConfig& config, QWidget* parent = nullptr);
|
||||
~ConfigWindow();
|
||||
|
||||
EmulatorConfig& getConfig() { return config; }
|
||||
|
||||
private:
|
||||
Emulator* emu;
|
||||
};
|
||||
|
|
|
@ -51,6 +51,7 @@ class MainWindow : public QMainWindow {
|
|||
ReleaseTouchscreen,
|
||||
ReloadUbershader,
|
||||
SetScreenSize,
|
||||
UpdateConfig,
|
||||
};
|
||||
|
||||
// Tagged union representing our message queue messages
|
||||
|
|
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -1,9 +1,8 @@
|
|||
#include "panda_qt/config_window.hpp"
|
||||
|
||||
ConfigWindow::ConfigWindow(Emulator* emu, QWidget* parent) : QDialog(parent), emu(emu) {
|
||||
ConfigWindow::ConfigWindow(ConfigCallback callback, const EmulatorConfig& emuConfig, QWidget* parent) : QDialog(parent), config(emuConfig) {
|
||||
setWindowTitle(tr("Configuration"));
|
||||
|
||||
EmulatorConfig& config = emu->getConfig();
|
||||
updateConfig = std::move(callback);
|
||||
|
||||
// Set up theme selection
|
||||
setTheme(Theme::Dark);
|
||||
|
@ -65,7 +64,7 @@ ConfigWindow::ConfigWindow(Emulator* emu, QWidget* parent) : QDialog(parent), em
|
|||
showAppVersion->setChecked(config.windowSettings.showAppVersion);
|
||||
connect(showAppVersion, &QCheckBox::toggled, this, [&](bool checked) {
|
||||
config.windowSettings.showAppVersion = checked;
|
||||
config.save();
|
||||
updateConfig();
|
||||
});
|
||||
guiLayout->addRow(showAppVersion);
|
||||
|
||||
|
@ -73,7 +72,7 @@ ConfigWindow::ConfigWindow(Emulator* emu, QWidget* parent) : QDialog(parent), em
|
|||
rememberPosition->setChecked(config.windowSettings.rememberPosition);
|
||||
connect(rememberPosition, &QCheckBox::toggled, this, [&](bool checked) {
|
||||
config.windowSettings.rememberPosition = checked;
|
||||
config.save();
|
||||
updateConfig();
|
||||
});
|
||||
guiLayout->addRow(rememberPosition);
|
||||
|
||||
|
@ -87,7 +86,7 @@ ConfigWindow::ConfigWindow(Emulator* emu, QWidget* parent) : QDialog(parent), em
|
|||
defaultRomPath->setText(QString::fromStdU16String(config.defaultRomPath.u16string()));
|
||||
connect(defaultRomPath, &QLineEdit::textChanged, this, [&](const QString &text) {
|
||||
config.defaultRomPath = text.toStdString();
|
||||
config.save();
|
||||
updateConfig();
|
||||
});
|
||||
QPushButton* browseRomPath = new QPushButton(tr("Browse..."));
|
||||
browseRomPath->setAutoDefault(false);
|
||||
|
@ -110,7 +109,7 @@ ConfigWindow::ConfigWindow(Emulator* emu, QWidget* parent) : QDialog(parent), em
|
|||
discordRpcEnabled->setChecked(config.discordRpcEnabled);
|
||||
connect(discordRpcEnabled, &QCheckBox::toggled, this, [&](bool checked) {
|
||||
config.discordRpcEnabled = checked;
|
||||
config.save();
|
||||
updateConfig();
|
||||
});
|
||||
genLayout->addRow(discordRpcEnabled);
|
||||
|
||||
|
@ -118,7 +117,7 @@ ConfigWindow::ConfigWindow(Emulator* emu, QWidget* parent) : QDialog(parent), em
|
|||
usePortableBuild->setChecked(config.usePortableBuild);
|
||||
connect(usePortableBuild, &QCheckBox::toggled, this, [&](bool checked) {
|
||||
config.usePortableBuild = checked;
|
||||
config.save();
|
||||
updateConfig();
|
||||
});
|
||||
genLayout->addRow(usePortableBuild);
|
||||
|
||||
|
@ -126,7 +125,7 @@ ConfigWindow::ConfigWindow(Emulator* emu, QWidget* parent) : QDialog(parent), em
|
|||
printAppVersion->setChecked(config.printAppVersion);
|
||||
connect(printAppVersion, &QCheckBox::toggled, this, [&](bool checked) {
|
||||
config.printAppVersion = checked;
|
||||
config.save();
|
||||
updateConfig();
|
||||
});
|
||||
genLayout->addRow(printAppVersion);
|
||||
|
||||
|
@ -143,7 +142,7 @@ ConfigWindow::ConfigWindow(Emulator* emu, QWidget* parent) : QDialog(parent), em
|
|||
rendererType->setCurrentIndex(static_cast<int>(config.rendererType));
|
||||
connect(rendererType, &QComboBox::currentIndexChanged, this, [&](int index) {
|
||||
config.rendererType = static_cast<RendererType>(index);
|
||||
config.save();
|
||||
updateConfig();
|
||||
});
|
||||
gpuLayout->addRow(tr("GPU renderer"), rendererType);
|
||||
|
||||
|
@ -151,7 +150,7 @@ ConfigWindow::ConfigWindow(Emulator* emu, QWidget* parent) : QDialog(parent), em
|
|||
enableRenderdoc->setChecked(config.enableRenderdoc);
|
||||
connect(enableRenderdoc, &QCheckBox::toggled, this, [&](bool checked) {
|
||||
config.enableRenderdoc = checked;
|
||||
config.save();
|
||||
updateConfig();
|
||||
});
|
||||
gpuLayout->addRow(enableRenderdoc);
|
||||
|
||||
|
@ -159,7 +158,7 @@ ConfigWindow::ConfigWindow(Emulator* emu, QWidget* parent) : QDialog(parent), em
|
|||
shaderJitEnabled->setChecked(config.shaderJitEnabled);
|
||||
connect(shaderJitEnabled, &QCheckBox::toggled, this, [&](bool checked) {
|
||||
config.shaderJitEnabled = checked;
|
||||
config.save();
|
||||
updateConfig();
|
||||
});
|
||||
gpuLayout->addRow(shaderJitEnabled);
|
||||
|
||||
|
@ -167,7 +166,7 @@ ConfigWindow::ConfigWindow(Emulator* emu, QWidget* parent) : QDialog(parent), em
|
|||
vsyncEnabled->setChecked(config.vsyncEnabled);
|
||||
connect(vsyncEnabled, &QCheckBox::toggled, this, [&](bool checked) {
|
||||
config.vsyncEnabled = checked;
|
||||
config.save();
|
||||
updateConfig();
|
||||
});
|
||||
gpuLayout->addRow(vsyncEnabled);
|
||||
|
||||
|
@ -175,7 +174,7 @@ ConfigWindow::ConfigWindow(Emulator* emu, QWidget* parent) : QDialog(parent), em
|
|||
useUbershaders->setChecked(config.useUbershaders);
|
||||
connect(useUbershaders, &QCheckBox::toggled, this, [&](bool checked) {
|
||||
config.useUbershaders = checked;
|
||||
config.save();
|
||||
updateConfig();
|
||||
});
|
||||
gpuLayout->addRow(useUbershaders);
|
||||
|
||||
|
@ -183,7 +182,7 @@ ConfigWindow::ConfigWindow(Emulator* emu, QWidget* parent) : QDialog(parent), em
|
|||
accurateShaderMul->setChecked(config.accurateShaderMul);
|
||||
connect(accurateShaderMul, &QCheckBox::toggled, this, [&](bool checked) {
|
||||
config.accurateShaderMul = checked;
|
||||
config.save();
|
||||
updateConfig();
|
||||
});
|
||||
gpuLayout->addRow(accurateShaderMul);
|
||||
|
||||
|
@ -191,14 +190,14 @@ ConfigWindow::ConfigWindow(Emulator* emu, QWidget* parent) : QDialog(parent), em
|
|||
accelerateShaders->setChecked(config.accelerateShaders);
|
||||
connect(accelerateShaders, &QCheckBox::toggled, this, [&](bool checked) {
|
||||
config.accelerateShaders = checked;
|
||||
config.save();
|
||||
updateConfig();
|
||||
});
|
||||
gpuLayout->addRow(accelerateShaders);
|
||||
|
||||
QCheckBox* forceShadergenForLights = new QCheckBox(tr("Force shadergen when rendering lights"));
|
||||
connect(forceShadergenForLights, &QCheckBox::toggled, this, [&](bool checked) {
|
||||
config.forceShadergenForLights = checked;
|
||||
config.save();
|
||||
updateConfig();
|
||||
});
|
||||
gpuLayout->addRow(forceShadergenForLights);
|
||||
|
||||
|
@ -207,7 +206,7 @@ ConfigWindow::ConfigWindow(Emulator* emu, QWidget* parent) : QDialog(parent), em
|
|||
lightShadergenThreshold->setValue(config.lightShadergenThreshold);
|
||||
connect(lightShadergenThreshold, &QSpinBox::valueChanged, this, [&](int value) {
|
||||
config.lightShadergenThreshold = static_cast<int>(value);
|
||||
config.save();
|
||||
updateConfig();
|
||||
});
|
||||
gpuLayout->addRow(tr("Light threshold for forcing shadergen"), lightShadergenThreshold);
|
||||
|
||||
|
@ -224,7 +223,7 @@ ConfigWindow::ConfigWindow(Emulator* emu, QWidget* parent) : QDialog(parent), em
|
|||
dspType->setCurrentIndex(static_cast<int>(config.dspType));
|
||||
connect(dspType, &QComboBox::currentIndexChanged, this, [&](int index) {
|
||||
config.dspType = static_cast<Audio::DSPCore::Type>(index);
|
||||
config.save();
|
||||
updateConfig();
|
||||
});
|
||||
spuLayout->addRow(tr("DSP emulation"), dspType);
|
||||
|
||||
|
@ -232,7 +231,7 @@ ConfigWindow::ConfigWindow(Emulator* emu, QWidget* parent) : QDialog(parent), em
|
|||
audioEnabled->setChecked(config.audioEnabled);
|
||||
connect(audioEnabled, &QCheckBox::toggled, this, [&](bool checked) {
|
||||
config.audioEnabled = checked;
|
||||
config.save();
|
||||
updateConfig();
|
||||
});
|
||||
spuLayout->addRow(audioEnabled);
|
||||
|
||||
|
@ -240,7 +239,7 @@ ConfigWindow::ConfigWindow(Emulator* emu, QWidget* parent) : QDialog(parent), em
|
|||
aacEnabled->setChecked(config.aacEnabled);
|
||||
connect(aacEnabled, &QCheckBox::toggled, this, [&](bool checked) {
|
||||
config.aacEnabled = checked;
|
||||
config.save();
|
||||
updateConfig();
|
||||
});
|
||||
spuLayout->addRow(aacEnabled);
|
||||
|
||||
|
@ -248,7 +247,7 @@ ConfigWindow::ConfigWindow(Emulator* emu, QWidget* parent) : QDialog(parent), em
|
|||
printDSPFirmware->setChecked(config.printDSPFirmware);
|
||||
connect(printDSPFirmware, &QCheckBox::toggled, this, [&](bool checked) {
|
||||
config.printDSPFirmware = checked;
|
||||
config.save();
|
||||
updateConfig();
|
||||
});
|
||||
spuLayout->addRow(printDSPFirmware);
|
||||
|
||||
|
@ -256,7 +255,7 @@ ConfigWindow::ConfigWindow(Emulator* emu, QWidget* parent) : QDialog(parent), em
|
|||
muteAudio->setChecked(config.audioDeviceConfig.muteAudio);
|
||||
connect(muteAudio, &QCheckBox::toggled, this, [&](bool checked) {
|
||||
config.audioDeviceConfig.muteAudio = checked;
|
||||
config.save();
|
||||
updateConfig();
|
||||
});
|
||||
spuLayout->addRow(muteAudio);
|
||||
|
||||
|
@ -265,7 +264,7 @@ ConfigWindow::ConfigWindow(Emulator* emu, QWidget* parent) : QDialog(parent), em
|
|||
volumeRaw->setValue(config.audioDeviceConfig.volumeRaw* 100);
|
||||
connect(volumeRaw, &QSpinBox::valueChanged, this, [&](int value) {
|
||||
config.audioDeviceConfig.volumeRaw = static_cast<float>(value) / 100.0f;
|
||||
config.save();
|
||||
updateConfig();
|
||||
});
|
||||
spuLayout->addRow(tr("Audio device volume"), volumeRaw);
|
||||
|
||||
|
@ -280,7 +279,7 @@ ConfigWindow::ConfigWindow(Emulator* emu, QWidget* parent) : QDialog(parent), em
|
|||
batteryPercentage->setValue(config.batteryPercentage);
|
||||
connect(batteryPercentage, &QSpinBox::valueChanged, this, [&](int value) {
|
||||
config.batteryPercentage = static_cast<int>(value);
|
||||
config.save();
|
||||
updateConfig();
|
||||
});
|
||||
batLayout->addRow(tr("Battery percentage"), batteryPercentage);
|
||||
|
||||
|
@ -288,7 +287,7 @@ ConfigWindow::ConfigWindow(Emulator* emu, QWidget* parent) : QDialog(parent), em
|
|||
chargerPlugged->setChecked(config.chargerPlugged);
|
||||
connect(chargerPlugged, &QCheckBox::toggled, this, [&](bool checked) {
|
||||
config.chargerPlugged = checked;
|
||||
config.save();
|
||||
updateConfig();
|
||||
});
|
||||
batLayout->addRow(chargerPlugged);
|
||||
|
||||
|
@ -302,7 +301,7 @@ ConfigWindow::ConfigWindow(Emulator* emu, QWidget* parent) : QDialog(parent), em
|
|||
sdCardInserted->setChecked(config.sdCardInserted);
|
||||
connect(sdCardInserted, &QCheckBox::toggled, this, [&](bool checked) {
|
||||
config.sdCardInserted = checked;
|
||||
config.save();
|
||||
updateConfig();
|
||||
});
|
||||
sdcLayout->addRow(sdCardInserted);
|
||||
|
||||
|
@ -310,7 +309,7 @@ ConfigWindow::ConfigWindow(Emulator* emu, QWidget* parent) : QDialog(parent), em
|
|||
sdWriteProtected->setChecked(config.sdWriteProtected);
|
||||
connect(sdWriteProtected, &QCheckBox::toggled, this, [&](bool checked) {
|
||||
config.sdWriteProtected = checked;
|
||||
config.save();
|
||||
updateConfig();
|
||||
});
|
||||
sdcLayout->addRow(sdWriteProtected);
|
||||
|
||||
|
|
|
@ -81,7 +81,6 @@ MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent)
|
|||
|
||||
// Set up misc objects
|
||||
aboutWindow = new AboutWindow(nullptr);
|
||||
configWindow = new ConfigWindow(emu, this);
|
||||
cheatsEditor = new CheatsWindow(emu, {}, this);
|
||||
patchWindow = new PatchWindow(this);
|
||||
luaEditor = new TextEditorWindow(this, "script.lua", "");
|
||||
|
@ -92,6 +91,14 @@ MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent)
|
|||
shaderEditor->setText(emu->getRenderer()->getUbershader());
|
||||
}
|
||||
|
||||
configWindow = new ConfigWindow(
|
||||
[&]() {
|
||||
EmulatorMessage message{.type = MessageType::UpdateConfig};
|
||||
sendMessage(message);
|
||||
},
|
||||
emu->getConfig(), this
|
||||
);
|
||||
|
||||
auto args = QCoreApplication::arguments();
|
||||
if (args.size() > 1) {
|
||||
auto romPath = std::filesystem::current_path() / args.at(1).toStdU16String();
|
||||
|
@ -410,6 +417,11 @@ void MainWindow::dispatchMessage(const EmulatorMessage& message) {
|
|||
screen->resizeSurface(width, height);
|
||||
break;
|
||||
}
|
||||
|
||||
case MessageType::UpdateConfig:
|
||||
emu->getConfig() = configWindow->getConfig();
|
||||
emu->reloadSettings();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,8 @@ namespace Renderdoc {
|
|||
};
|
||||
|
||||
static CaptureState captureState{CaptureState::Idle};
|
||||
static bool renderdocLoaded{false};
|
||||
|
||||
RENDERDOC_API_1_6_0* rdocAPI{};
|
||||
|
||||
void loadRenderdoc() {
|
||||
|
@ -73,6 +75,8 @@ namespace Renderdoc {
|
|||
}
|
||||
#endif
|
||||
if (rdocAPI) {
|
||||
renderdocLoaded = true;
|
||||
|
||||
// Disable default capture keys as they suppose to trigger present-to-present capturing
|
||||
// and it is not what we want
|
||||
rdocAPI->SetCaptureKeys(nullptr, 0);
|
||||
|
@ -115,5 +119,7 @@ namespace Renderdoc {
|
|||
rdocAPI->SetCaptureFilePathTemplate((path + '\\' + prefix).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
bool isLoaded() { return renderdocLoaded; }
|
||||
} // namespace Renderdoc
|
||||
#endif
|
Loading…
Add table
Reference in a new issue