Skip to content

Commit

Permalink
Qt: Attach cheats dialog directly to Snes9x.
Browse files Browse the repository at this point in the history
Update sizing for cheats and shader params dialogs.
  • Loading branch information
bearoso committed Aug 25, 2023
1 parent 34aab85 commit bd41d01
Show file tree
Hide file tree
Showing 14 changed files with 262 additions and 45 deletions.
1 change: 1 addition & 0 deletions cheats.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ int S9xModifyCheatGroup(uint32_t index, const std::string &name, const std::stri
void S9xEnableCheatGroup(uint32_t index);
void S9xDisableCheatGroup(uint32_t index);
void S9xDeleteCheats(void);
std::string S9xCheatGroupToText(const SCheatGroup &g);
std::string S9xCheatGroupToText(uint32_t index);
void S9xDeleteCheatGroup(uint32_t index);
bool8 S9xLoadCheatFile(const std::string &filename);
Expand Down
2 changes: 1 addition & 1 deletion cheats2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ std::string S9xCheatToText(const SCheat &c)
return std::string(output);
}

std::string S9xCheatGroupToText(SCheatGroup &g)
std::string S9xCheatGroupToText(const SCheatGroup &g)
{
std::string text = "";

Expand Down
2 changes: 1 addition & 1 deletion external/SPIRV-Cross
Submodule SPIRV-Cross updated 493 files
2 changes: 1 addition & 1 deletion external/glslang
Submodule glslang updated 94 files
+11 −12 .github/workflows/continuous_integration.yml
+5 −5 Android.mk
+1 −1 BUILD.bazel
+0 −13 CHANGES.md
+19 −2 CMakeLists.txt
+1 −1 OGLCompilersDLL/CMakeLists.txt
+8 −12 SPIRV/CMakeLists.txt
+0 −1 SPIRV/GLSL.ext.EXT.h
+0 −1 SPIRV/GLSL.ext.KHR.h
+1 −1 SPIRV/GLSL.std.450.h
+22 −137 SPIRV/GlslangToSpv.cpp
+2 −2 SPIRV/GlslangToSpv.h
+5 −5 SPIRV/NonSemanticDebugPrintf.h
+5 −5 SPIRV/NonSemanticShaderDebugInfo100.h
+6 −0 SPIRV/SPVRemapper.cpp
+28 −0 SPIRV/SPVRemapper.h
+2 −9 SPIRV/SpvBuilder.cpp
+1 −1 SPIRV/SpvBuilder.h
+1 −1 SPIRV/disassemble.cpp
+10 −37 SPIRV/doc.cpp
+1 −1 SPIRV/doc.h
+13 −0 SPIRV/hex_float.h
+5 −159 SPIRV/spirv.hpp
+1 −3 SPIRV/spvIR.h
+6 −6 StandAlone/CMakeLists.txt
+4 −6 StandAlone/StandAlone.cpp
+2 −0 StandAlone/spirv-remap.cpp
+1 −1 Test/baseResults/440.frag.out
+114 −142 Test/baseResults/rayQuery-allOps.comp.out
+49 −68 Test/baseResults/spv.bufferhandle8.frag.out
+73 −85 Test/baseResults/spv.debuginfo.const_params.glsl.comp.out
+1,051 −1,211 Test/baseResults/spv.debuginfo.glsl.comp.out
+930 −1,090 Test/baseResults/spv.debuginfo.glsl.frag.out
+318 −350 Test/baseResults/spv.debuginfo.glsl.geom.out
+608 −702 Test/baseResults/spv.debuginfo.glsl.tesc.out
+412 −436 Test/baseResults/spv.debuginfo.glsl.tese.out
+475 −532 Test/baseResults/spv.debuginfo.glsl.vert.out
+1,064 −1,218 Test/baseResults/spv.debuginfo.hlsl.comp.out
+973 −1,129 Test/baseResults/spv.debuginfo.hlsl.frag.out
+443 −484 Test/baseResults/spv.debuginfo.hlsl.geom.out
+794 −902 Test/baseResults/spv.debuginfo.hlsl.tesc.out
+576 −613 Test/baseResults/spv.debuginfo.hlsl.tese.out
+564 −632 Test/baseResults/spv.debuginfo.hlsl.vert.out
+31 −46 Test/baseResults/spv.ext.AnyHitShader.rahit.out
+26 −40 Test/baseResults/spv.ext.ClosestHitShader.rchit.out
+0 −38 Test/baseResults/spv.ext.ShaderTileImage.color.frag.out
+0 −56 Test/baseResults/spv.ext.ShaderTileImage.depth_stencil.frag.out
+0 −6 Test/baseResults/spv.ext.ShaderTileImage.overlap.frag.out
+0 −6 Test/baseResults/spv.ext.ShaderTileImage.subpassinput.frag.out
+0 −6 Test/baseResults/spv.ext.ShaderTileImage.typemismatch.frag.out
+0 −9 Test/baseResults/spv.ext.ShaderTileImage.wronglayout.frag.out
+0 −9 Test/rayQuery-allOps.comp
+0 −2 Test/spv.bufferhandle8.frag
+0 −2 Test/spv.ext.AnyHitShader.rahit
+0 −2 Test/spv.ext.ClosestHitShader.rchit
+0 −12 Test/spv.ext.ShaderTileImage.color.frag
+0 −16 Test/spv.ext.ShaderTileImage.depth_stencil.frag
+0 −15 Test/spv.ext.ShaderTileImage.overlap.frag
+0 −13 Test/spv.ext.ShaderTileImage.subpassinput.frag
+0 −13 Test/spv.ext.ShaderTileImage.typemismatch.frag
+0 −13 Test/spv.ext.ShaderTileImage.wronglayout.frag
+35 −18 glslang/CInterface/glslang_c_interface.cpp
+3 −3 glslang/CMakeLists.txt
+0 −4 glslang/Include/BaseTypes.h
+18 −3 glslang/Include/Common.h
+12 −41 glslang/Include/Types.h
+20 −22 glslang/Include/glslang_c_interface.h
+0 −13 glslang/Include/intermediate.h
+1 −39 glslang/MachineIndependent/Initialize.cpp
+5 −64 glslang/MachineIndependent/ParseHelper.cpp
+0 −9 glslang/MachineIndependent/Scan.cpp
+1 −1 glslang/MachineIndependent/SymbolTable.cpp
+1 −4 glslang/MachineIndependent/Versions.cpp
+0 −3 glslang/MachineIndependent/Versions.h
+1 −25 glslang/MachineIndependent/glslang.m4
+1 −25 glslang/MachineIndependent/glslang.y
+4,476 −4,548 glslang/MachineIndependent/glslang_tab.cpp
+132 −136 glslang/MachineIndependent/glslang_tab.cpp.h
+0 −13 glslang/MachineIndependent/intermOut.cpp
+2 −23 glslang/MachineIndependent/linkValidate.cpp
+1 −18 glslang/MachineIndependent/localintermediate.h
+3 −0 glslang/MachineIndependent/preprocessor/PpTokens.cpp
+1 −1 glslang/OSDependent/Unix/CMakeLists.txt
+1 −1 glslang/OSDependent/Windows/CMakeLists.txt
+1 −1 gtests/CMakeLists.txt
+0 −6 gtests/Spv.FromFile.cpp
+4 −6 hlsl/CMakeLists.txt
+2 −2 known_good.json
+0 −1 kokoro/android-ndk-build/build-docker.sh
+7 −7 kokoro/windows-msvc-2015-release-bazel/build.bat
+2 −2 kokoro/windows-msvc-2015-release-bazel/continuous.cfg
+2 −2 kokoro/windows-msvc-2015-release-bazel/presubmit.cfg
+1 −1 ndk_test/Android.mk
+1 −1 ndk_test/jni/Application.mk
5 changes: 3 additions & 2 deletions gtk/src/gtk_cheat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ Snes9xCheats::Snes9xCheats()
get_object<Gtk::Button>("disable_all_button")->signal_clicked().connect(sigc::mem_fun(*this, &Snes9xCheats::disable_all));
get_object<Gtk::Button>("delete_all_cheats_button")->signal_clicked().connect(sigc::mem_fun(*this, &Snes9xCheats::delete_all_cheats));
get_object<Gtk::Button>("cheat_search_button")->signal_clicked().connect(sigc::mem_fun(*this, &Snes9xCheats::search_database));
get_object<Gtk::Button>("update_button")->signal_clicked().connect(sigc::mem_fun(*this, &Snes9xCheats::update_code));

gtk_widget_realize(GTK_WIDGET(window->gobj()));
}
Expand Down Expand Up @@ -288,7 +287,9 @@ void Snes9xCheats::search_database()

for (const auto &dir : { S9xGetDirectory(CHEAT_DIR),
get_config_dir(),
std::string(DATADIR) })
std::string(DATADIR),
"/usr/share/snes9x",
"/usr/local/share/snes9x" })
{
filename = dir + "/cheats.bml";
result = S9xImportCheatsFromDatabase(filename);
Expand Down
227 changes: 201 additions & 26 deletions qt/src/CheatsDialog.cpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,202 @@
#include "CheatsDialog.hpp"

static const auto desired_flags = Qt::ItemFlag::ItemIsUserCheckable |
Qt::ItemFlag::ItemIsEnabled |
Qt::ItemFlag::ItemIsSelectable |
Qt::ItemFlag::ItemIsDragEnabled;

CheatsDialog::CheatsDialog(QWidget *parent, EmuApplication *app_)
: app(app_), QDialog(parent)
{
setupUi(this);
show();

QTreeWidgetItem *item = new QTreeWidgetItem();
item->setFlags(desired_flags);
item->setCheckState(0, Qt::CheckState::Checked);
item->setText(1, "Invincibility");
item->setText(2, "dd32-6dad");

treeWidget_cheats->insertTopLevelItem(0, item);
item = new QTreeWidgetItem();
item->setFlags(desired_flags);
item->setCheckState(0, Qt::CheckState::Checked);
item->setText(1, "Torzx");
item->setText(2, "7e0fff:ff\n7e0ff7:ff");
treeWidget_cheats->insertTopLevelItem(1, item);
#include "CheatsDialog.hpp"
#include "EmuApplication.hpp"
#include "EmuConfig.hpp"
#include "../cheats.h"
#include "fscompat.h"

#include <QMessageBox>
#include <QDir>
#include <QtEvents>

extern SCheatData Cheat;
auto &clist = Cheat.group;

static const auto desired_flags = Qt::ItemFlag::ItemIsUserCheckable |
Qt::ItemFlag::ItemIsEnabled |
Qt::ItemFlag::ItemIsSelectable |
Qt::ItemFlag::ItemIsDragEnabled;

CheatsDialog::CheatsDialog(QWidget *parent, EmuApplication *app_)
: app(app_), QDialog(parent)
{
setupUi(this);

connect(pushButton_add, &QPushButton::clicked, [&] { addCode(); });
connect(pushButton_remove, &QPushButton::clicked, [&] { removeCode(); });
connect(pushButton_remove_all, &QPushButton::clicked, [&] { removeAll(); });
connect(pushButton_check_database, &QPushButton::clicked, [&] { searchDatabase(); });
connect(pushButton_update, &QPushButton::clicked, [&] { updateCurrent(); });

treeWidget_cheats->header()->setSectionResizeMode(QHeaderView::ResizeToContents);

connect(treeWidget_cheats, &QTreeWidget::itemChanged, [&](QTreeWidgetItem *item, int column) {
if (column != 0)
return;

auto index = treeWidget_cheats->indexOfTopLevelItem(item);

app->suspendThread();
if (item->checkState(0) == Qt::Checked)
S9xEnableCheatGroup(index);
else
S9xDisableCheatGroup(index);
app->unsuspendThread();
});

connect(treeWidget_cheats, &QTreeWidget::itemDoubleClicked, [&](QTreeWidgetItem *item, int column) {
lineEdit_description->setText(item->text(1));
lineEdit_code->setText(item->text(2));
});

if (app->config->cheat_dialog_width != 0)
resize(app->config->cheat_dialog_width, app->config->cheat_dialog_height);

show();
}

void CheatsDialog::showEvent(QShowEvent *event)
{
refreshList();
QDialog::showEvent(event);
}

void CheatsDialog::addCode()
{
auto description = lineEdit_description->text().toStdString();
auto code = lineEdit_code->text().toStdString();

if (description.empty())
description = tr("No description").toStdString();

if (S9xAddCheatGroup(description, code) < 0)
{
QMessageBox::information(this, tr("Invalid Cheat"), tr("The cheat you entered was not valid."));
return;
}

refreshList();
treeWidget_cheats->setTreePosition(treeWidget_cheats->topLevelItemCount() - 1);
}

void CheatsDialog::removeCode()
{
if (!treeWidget_cheats->currentIndex().isValid())
return;

auto index = treeWidget_cheats->currentIndex().row();
app->suspendThread();
S9xDeleteCheatGroup(index);
app->unsuspendThread();
auto item = treeWidget_cheats->takeTopLevelItem(index);
if (item)
delete item;
}

void CheatsDialog::disableAll()
{
app->suspendThread();
for (size_t i = 0; i < clist.size(); i++)
S9xDisableCheatGroup(i);
app->unsuspendThread();
refreshList();
}

void CheatsDialog::removeAll()
{
treeWidget_cheats->clear();
app->suspendThread();
S9xDeleteCheats();
app->unsuspendThread();
}

void CheatsDialog::searchDatabase()
{
std::initializer_list<std::string> dirs =
{
EmuConfig::findConfigDir(),
QGuiApplication::applicationDirPath().toStdString(),
S9xGetDirectory(CHEAT_DIR),
"/usr/share/snes9x",
"/usr/local/share/snes9x"
};

bool found = false;

for (auto &path : dirs)
{
auto filename = QDir(QString::fromStdString(path)).absoluteFilePath("cheats.bml").toStdString();
app->suspendThread();
auto result = S9xImportCheatsFromDatabase(filename);
app->unsuspendThread();
if (result == 0)
{
refreshList();
return;
}

if (result == -1)
continue;

if (result == -2)
{
QMessageBox::information(this, tr("No Cheats Found"), tr("No cheats for the current game were found in the database."));
return;
}
}

QMessageBox::information(this, tr("Unable to Open Cheats Database"), tr("cheats.bml was not found."));
}

void CheatsDialog::updateCurrent()
{
if (!treeWidget_cheats->currentIndex().isValid())
return;

auto description = lineEdit_description->text().toStdString();
auto code = lineEdit_code->text().toStdString();
auto index = treeWidget_cheats->currentIndex().row();

if (description.empty())
description = tr("No description").toStdString();

auto validated = S9xCheatValidate(code);
if (validated.empty())
{
QMessageBox::information(this, tr("Invalid Cheat"), tr("The cheat you entered was not valid."));
return;
}

app->suspendThread();
S9xModifyCheatGroup(index, description, validated);
app->unsuspendThread();

treeWidget_cheats->currentItem()->setText(1, lineEdit_description->text());
treeWidget_cheats->currentItem()->setText(2, QString::fromStdString(validated));
}

void CheatsDialog::refreshList()
{
treeWidget_cheats->clear();

QList<QTreeWidgetItem *> items;

app->suspendThread();
for (const auto &c: clist)
{
auto i = new QTreeWidgetItem();
i->setFlags(desired_flags);
i->setCheckState(0, c.enabled ? Qt::Checked : Qt::Unchecked);
i->setText(1, QString::fromStdString(c.name));
i->setText(2, QString::fromStdString(S9xCheatGroupToText(c)));
items.push_back(i);
}
app->unsuspendThread();

treeWidget_cheats->insertTopLevelItems(0, items);
}

void CheatsDialog::resizeEvent(QResizeEvent *event)
{
app->config->cheat_dialog_width = event->size().width();
app->config->cheat_dialog_height = event->size().height();
}
32 changes: 20 additions & 12 deletions qt/src/CheatsDialog.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
#include "ui_CheatsDialog.h"

class EmuApplication;

class CheatsDialog : public QDialog, public Ui_Dialog
{
public:
CheatsDialog(QWidget *parent, EmuApplication *app);

EmuApplication *app;
};

#include "ui_CheatsDialog.h"

class EmuApplication;

class CheatsDialog : public QDialog, public Ui_Dialog
{
public:
CheatsDialog(QWidget *parent, EmuApplication *app);
void addCode();
void removeCode();
void updateCurrent();
void disableAll();
void removeAll();
void searchDatabase();
void refreshList();
void showEvent(QShowEvent *) override;
EmuApplication *app;
void resizeEvent(QResizeEvent *event) override;
};

1 change: 1 addition & 0 deletions qt/src/EmuApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ void EmuApplication::startThread()

bool EmuApplication::openFile(std::string filename)
{
window->gameChanging();
suspendThread();
auto result = core->openFile(filename);
unsuspendThread();
Expand Down
5 changes: 5 additions & 0 deletions qt/src/EmuConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,11 @@ void EmuConfig::config(std::string filename, bool write)
String("LastROMFolder", last_rom_folder);
Int("MainWindowWidth", main_window_width);
Int("MainWindowHeight", main_window_height);
Int("ShaderParametersDialogWidth", shader_parameters_dialog_width);
Int("ShaderParametersDialogHeight", shader_parameters_dialog_height);
Int("CheatDialogWidth", cheat_dialog_width);
Int("CheatDialogHeight", cheat_dialog_height);

int recent_count = recently_used.size();
Int("RecentlyUsedEntries", recent_count);
if (!write)
Expand Down
4 changes: 4 additions & 0 deletions qt/src/EmuConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ struct EmuConfig
std::string last_rom_folder;
int main_window_width = 0;
int main_window_height = 0;
int cheat_dialog_width = 0;
int cheat_dialog_height = 0;
int shader_parameters_dialog_width = 0;
int shader_parameters_dialog_height = 0;
std::vector<std::string> recently_used;

// General
Expand Down
11 changes: 9 additions & 2 deletions qt/src/EmuMainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "EmuCanvasOpenGL.hpp"
#include "EmuCanvasQt.hpp"
#include "CheatsDialog.hpp"
#include "ShaderParametersDialog.hpp"
#undef KeyPress

static EmuSettingsWindow *g_emu_settings_window = nullptr;
Expand Down Expand Up @@ -265,7 +264,9 @@ void EmuMainWindow::createWidgets()

auto cheats_item = emulation_menu->addAction(tr("&Cheats"));
connect(cheats_item, &QAction::triggered, [&] {
auto cheats_dialog = new CheatsDialog(this, app);
if (!cheats_dialog)
cheats_dialog = std::make_unique<CheatsDialog>(this, app);
cheats_dialog->show();
});
core_actions.push_back(cheats_item);

Expand Down Expand Up @@ -662,4 +663,10 @@ void EmuMainWindow::shaderChanged()
if (canvas)
canvas->shaderChanged();
});
}

void EmuMainWindow::gameChanging()
{
if (cheats_dialog)
cheats_dialog->close();
}
4 changes: 4 additions & 0 deletions qt/src/EmuMainWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "EmuCanvas.hpp"

class EmuApplication;
class CheatsDialog;

class EmuMainWindow : public QMainWindow
{
Expand Down Expand Up @@ -35,6 +36,7 @@ class EmuMainWindow : public QMainWindow
bool openFile(std::string filename);
void recreateUIAssets();
void shaderChanged();
void gameChanging();
std::vector<std::string> getDisplayDeviceList();
EmuApplication *app;
EmuCanvas *canvas;
Expand All @@ -46,6 +48,8 @@ class EmuMainWindow : public QMainWindow
static const size_t recent_menu_size = 10;
static const size_t state_items_size = 10;

std::unique_ptr<CheatsDialog> cheats_dialog;

bool manual_pause = false;
bool focus_pause = false;
bool minimized_pause = false;
Expand Down
Loading

0 comments on commit bd41d01

Please sign in to comment.