Skip to content

Commit

Permalink
input: add SDL_GameControllerDB
Browse files Browse the repository at this point in the history
  • Loading branch information
Megamouse committed Aug 29, 2023
1 parent d105b0b commit 452a465
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .ci/deploy-windows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ ARTIFACT_DIR="$BUILD_ARTIFACTSTAGINGDIRECTORY"
rm -f ./bin/rpcs3.exp ./bin/rpcs3.lib ./bin/rpcs3.pdb ./bin/vc_redist.x64.exe
rm -rf ./bin/git

# Prepare compatibility database for packaging, as well as
# Prepare compatibility and SDL database for packaging, as well as
# certificate for ssl (auto-updater)
mkdir ./bin/config
mkdir ./bin/config/input_configs
curl -fsSL 'https://raw.githubusercontent.com/gabomdq/SDL_GameControllerDB/master/gamecontrollerdb.txt' 1> ./bin/config/input_configs/gamecontrollerdb.txt
curl -fsSL 'https://rpcs3.net/compatibility?api=v1&export' | iconv -t UTF-8 1> ./bin/GuiConfigs/compat_database.dat
curl -fsSL 'https://curl.haxx.se/ca/cacert.pem' 1> ./bin/cacert.pem

Expand Down
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,4 @@
[submodule "3rdparty/rtmidi/rtmidi"]
path = 3rdparty/rtmidi/rtmidi
url = ../../thestk/rtmidi
ignore = dirty
1 change: 1 addition & 0 deletions rpcs3/Emu/system_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ struct cfg_root : cfg::node
cfg::_bool show_move_cursor{this, "Show move cursor", false, true};
cfg::_bool lock_overlay_input_to_player_one{this, "Lock overlay input to player one", false, true};
cfg::string midi_devices{ this, "Emulated Midi devices", "ßßß@@@ßßß@@@ßßß@@@" };
cfg::_bool load_sdl_mappings{ this, "Load SDL GameController Mappings", true };
} io{ this };

struct node_sys : cfg::node
Expand Down
20 changes: 20 additions & 0 deletions rpcs3/Input/sdl_pad_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "stdafx.h"
#include "sdl_pad_handler.h"
#include "Emu/system_utils.hpp"
#include "Emu/system_config.h"

LOG_CHANNEL(sdl_log, "SDL");

Expand Down Expand Up @@ -217,6 +219,24 @@ bool sdl_pad_handler::Init()
}
}, nullptr);

if (g_cfg.io.load_sdl_mappings)
{
const std::string db_path = rpcs3::utils::get_input_config_root() + "gamecontrollerdb.txt";
sdl_log.notice("Adding mappings from file '%s'", db_path);

if (fs::is_file(db_path))
{
if (SDL_GameControllerAddMappingsFromFile(db_path.c_str()) < 0)
{
sdl_log.error("Could not add mappings from file '%s'! SDL Error: %s", db_path, SDL_GetError());
}
}
else
{
sdl_log.error("Could not add mappings from file '%s'! File does not exist!", db_path);
}
}

m_is_init = true;
enumerate_devices();

Expand Down
2 changes: 2 additions & 0 deletions rpcs3/rpcs3qt/emu_settings_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ enum class emu_settings_type
Turntable,
GHLtar,
MidiDevices,
SDLMappings,

// Misc
ExitRPCS3OnFinish,
Expand Down Expand Up @@ -341,6 +342,7 @@ inline static const QMap<emu_settings_type, cfg_location> settings_location =
{ emu_settings_type::Turntable, { "Input/Output", "Turntable emulated controller" }},
{ emu_settings_type::GHLtar, { "Input/Output", "GHLtar emulated controller" }},
{ emu_settings_type::MidiDevices, { "Input/Output", "Emulated Midi devices" }},
{ emu_settings_type::SDLMappings, { "Input/Output", "Load SDL GameController Mappings" }},

// Misc
{ emu_settings_type::ExitRPCS3OnFinish, { "Miscellaneous", "Exit RPCS3 when process finishes" }},
Expand Down
7 changes: 7 additions & 0 deletions rpcs3/rpcs3qt/settings_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,13 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
m_emu_settings->EnhanceCheckBox(ui->lockOverlayInputToPlayerOne, emu_settings_type::LockOvlIptToP1);
SubscribeTooltip(ui->lockOverlayInputToPlayerOne, tooltips.settings.lock_overlay_input_to_player_one);

#if HAVE_SDL2
m_emu_settings->EnhanceCheckBox(ui->loadSdlMappings, emu_settings_type::SDLMappings);
SubscribeTooltip(ui->loadSdlMappings, tooltips.settings.sdl_mappings);
#else
ui->loadSdlMappings->setVisible(false);
#endif

// Midi
const QString midi_none = m_emu_settings->m_midi_creator.get_none();
const midi_device def_midi_device{ .type = midi_device_type::keyboard, .name = midi_none.toStdString() };
Expand Down
7 changes: 7 additions & 0 deletions rpcs3/rpcs3qt/settings_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1810,6 +1810,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="loadSdlMappings">
<property name="text">
<string>Use SDL GameController Database</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacerIoAdditionalSettings">
<property name="orientation">
Expand Down
1 change: 1 addition & 0 deletions rpcs3/rpcs3qt/tooltips.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ class Tooltips : public QObject
const QString background_input = tr("Allows pad and keyboard input while the game window is unfocused.");
const QString show_move_cursor = tr("Shows the raw position of the PS Move input.\nThis can be very helpful during calibration screens.");
const QString midi_devices = tr("Select up to 3 emulated MIDI devices and their types.");
const QString sdl_mappings = tr("Loads the SDL GameController database for improved gamepad compatibility. Only used in the SDL pad handler.");

const QString lock_overlay_input_to_player_one = tr("Locks the native overlay input to the first player.");

Expand Down

0 comments on commit 452a465

Please sign in to comment.