mirror of
https://github.com/open-goal/jak-project
synced 2026-08-31 09:41:05 -04:00
1f6438e517
This PR updates to SDL3, and with it, adds a handful of new features. Everything seems to work but I'm going to look over the code once last time before merging, some of the API changes are hard to spot. Fixes #2773 ### Pressure sensitivity support for DS3 Controllers SDL3 adds pressure sensitivity support for DS3 controllers on windows. I have not tested on linux. The option is disabled by default. On windows you will need https://docs.nefarius.at/projects/DsHidMini/ and to be using SXS mode. ### DualSense and Xbox One Trigger Effects If enabled, Jak 2 will have certain trigger effects. They are: - xbox1: - small vibrate when collecting dark eco - big vibrate when changing to dark jak - vibrate when shooting gun, proportional to gun type - ps5: - resistance when changing to dark jak - different gun shooting effects - red (resistance) - yellow (weapon trigger) - blue (vibrates) - purple (less resistance) > **Gun Shooting effects are only enabled if the new "Swap R1 and R2" option is enabled** There are more effects that could be used in `dualsense_effects.cpp`, but I only exposed the ones I needed to OpenGOAL. If a modder wants to use some of the others and wires them up end-to-end, please consider contributing that upstream. ### New ImGUI Menu Added new imgui options for selecting the active controller, for those people that struggle to select the initial controller.  ### Testing The highlights of what I tested successfully: - display - [x] all mode switch permutations - [x] launch with all modes saved - [x] switch monitors / unplug monitor that was active, how does it handle it - [x] load with alternate monitor saved and all modes - [x] allowing hidpi doesnt break macos - controls - [x] keyboard and mouse still work - [x] pressure sensitivity on linux
112 lines
3.0 KiB
C++
112 lines
3.0 KiB
C++
#include "sdl_util.h"
|
|
|
|
#include "common/log/log.h"
|
|
|
|
#include "third-party/SDL/include/SDL3/SDL.h"
|
|
|
|
namespace sdl_util {
|
|
void log_error(const std::string& msg) {
|
|
std::string sdl_cause = SDL_GetError();
|
|
lg::error("SDL Error: {} - Cause: {}", msg, sdl_cause.empty() ? "n/a" : sdl_cause);
|
|
}
|
|
|
|
std::string log_and_return_error(const std::string& msg) {
|
|
std::string sdl_cause = SDL_GetError();
|
|
lg::error("SDL Error: {} - Cause: {}", msg, sdl_cause.empty() ? "n/a" : sdl_cause);
|
|
return sdl_cause;
|
|
}
|
|
|
|
bool is_any_event_type(uint32_t event_type, const std::vector<uint32_t>& allowed_types) {
|
|
for (const auto& allowed_type : allowed_types) {
|
|
if (allowed_type == event_type) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool is_SDL_GUID_zero(SDL_GUID guid) {
|
|
for (int i = 0; i < 16; i++) {
|
|
if (guid.data[i] != 0) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
std::vector<std::string> get_modifier_strings(InputModifiers modifiers) {
|
|
std::vector<std::string> result = {};
|
|
if (modifiers.need_ctrl) {
|
|
result.push_back("ctrl");
|
|
}
|
|
if (modifiers.need_shift) {
|
|
result.push_back("shift");
|
|
}
|
|
if (modifiers.need_alt) {
|
|
result.push_back("alt");
|
|
}
|
|
if (modifiers.need_meta) {
|
|
result.push_back("meta");
|
|
}
|
|
return result;
|
|
}
|
|
std::string get_mouse_button_name(const int sdl_mouse_button_id, InputModifiers modifiers) {
|
|
std::string result = "";
|
|
switch (sdl_mouse_button_id) {
|
|
case SDL_BUTTON_LEFT:
|
|
result = "LEFT MOUSE";
|
|
break;
|
|
case SDL_BUTTON_MIDDLE:
|
|
result = "MIDDLE MOUSE";
|
|
break;
|
|
case SDL_BUTTON_RIGHT:
|
|
result = "RIGHT MOUSE";
|
|
break;
|
|
case SDL_BUTTON_X1:
|
|
result = "MOUSE 4";
|
|
break;
|
|
case SDL_BUTTON_X2:
|
|
result = "MOUSE 5";
|
|
break;
|
|
default:
|
|
result = "";
|
|
}
|
|
if (result.empty()) {
|
|
return "unknown";
|
|
}
|
|
auto tokens = get_modifier_strings(modifiers);
|
|
tokens.push_back(result);
|
|
return fmt::to_string(fmt::join(tokens, " + "));
|
|
}
|
|
|
|
std::string get_keyboard_button_name(const int sdl_key_code, InputModifiers modifiers) {
|
|
const auto result = SDL_GetKeyName((SDL_Keycode)sdl_key_code);
|
|
if (!result) {
|
|
return "Unknown";
|
|
}
|
|
auto tokens = get_modifier_strings(modifiers);
|
|
tokens.push_back(result);
|
|
return fmt::to_string(fmt::join(tokens, " + "));
|
|
}
|
|
std::string get_controller_button_name(const int sdl_button_id) {
|
|
const auto result = SDL_GetGamepadStringForButton((SDL_GamepadButton)sdl_button_id);
|
|
if (!result) {
|
|
return "Unknown";
|
|
}
|
|
return result;
|
|
}
|
|
std::string get_controller_axis_name(const int sdl_axis_id) {
|
|
const auto result = SDL_GetGamepadStringForAxis((SDL_GamepadAxis)sdl_axis_id);
|
|
if (!result) {
|
|
return "Unknown";
|
|
}
|
|
return result;
|
|
}
|
|
|
|
bool is_modifier_key(const SDL_Keycode key_code) {
|
|
return key_code == SDLK_LSHIFT || key_code == SDLK_RSHIFT || key_code == SDLK_LALT ||
|
|
key_code == SDLK_RALT || key_code == SDLK_LCTRL || key_code == SDLK_RCTRL ||
|
|
key_code == SDLK_LGUI || key_code == SDLK_RGUI;
|
|
}
|
|
} // namespace sdl_util
|