Misc: Initial SDL3 port

Migrates build system to use SDL3
Run automated rename scripts, along with additional manual fixups
This commit is contained in:
TheTechnician27 2025-02-05 18:17:23 -06:00 committed by TheLastRar
parent 0f13cd5cf3
commit 23af1c776c
10 changed files with 200 additions and 196 deletions

View File

@ -17,7 +17,7 @@ find_package(ZLIB REQUIRED) # v1.3, but Mac uses the SDK version.
find_package(Zstd 1.5.5 REQUIRED)
find_package(LZ4 REQUIRED)
find_package(WebP REQUIRED) # v1.3.2, spews an error on Linux because no pkg-config.
find_package(SDL2 2.30.4 REQUIRED)
find_package(SDL3 3.2.6 REQUIRED)
find_package(Freetype 2.11.1 REQUIRED)
if(USE_VULKAN)

View File

@ -4,7 +4,7 @@
<ItemDefinitionGroup>
<Link>
<AdditionalLibraryDirectories>$(DepsLibDir);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>%(AdditionalDependencies);freetype.lib;libjpeg.lib;libpng16.lib;libwebp.lib;lz4.lib;SDL2.lib;zlib.lib;zstd.lib</AdditionalDependencies>
<AdditionalDependencies>%(AdditionalDependencies);freetype.lib;libjpeg.lib;libpng16.lib;libwebp.lib;lz4.lib;SDL3.lib;zlib.lib;zstd.lib</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
@ -15,7 +15,7 @@
<DepsDLLs Include="$(DepsBinDir)libsharpyuv.dll" />
<DepsDLLs Include="$(DepsBinDir)libwebp.dll" />
<DepsDLLs Include="$(DepsBinDir)lz4.dll" />
<DepsDLLs Include="$(DepsBinDir)SDL2.dll" />
<DepsDLLs Include="$(DepsBinDir)SDL3.dll" />
<DepsDLLs Include="$(DepsBinDir)shaderc_shared.dll" />
<DepsDLLs Include="$(DepsBinDir)zlib1.dll" />
<DepsDLLs Include="$(DepsBinDir)zstd.dll" />

View File

@ -36,7 +36,7 @@
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DepsIncludeDir)\SDL2</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DepsIncludeDir)\SDL3</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SolutionDir)3rdparty\fmt\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SolutionDir)3rdparty\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SolutionDir)3rdparty\lzma\include</AdditionalIncludeDirectories>

View File

@ -1146,7 +1146,7 @@ target_link_libraries(PCSX2_FLAGS INTERFACE
discord-rpc
simpleini
freesurround
SDL2::SDL2
SDL3::SDL3
ZLIB::ZLIB
LZ4::LZ4
SoundTouch::SoundTouch
@ -1282,7 +1282,7 @@ function(setup_main_executable target)
# Copy dependency libraries.
set(DEPS_BINDIR "${CMAKE_SOURCE_DIR}/deps/bin")
set(DEPS_TO_COPY freetype.dll harfbuzz.dll libjpeg.dll libpng16.dll libsharpyuv.dll libwebp.dll lz4.dll SDL2.dll shaderc_shared.dll zlib1.dll zstd.dll)
set(DEPS_TO_COPY freetype.dll harfbuzz.dll libjpeg.dll libpng16.dll libsharpyuv.dll libwebp.dll lz4.dll SDL3.dll shaderc_shared.dll zlib1.dll zstd.dll)
foreach(DEP_TO_COPY ${DEPS_TO_COPY})
install(FILES "${DEPS_BINDIR}/${DEP_TO_COPY}" DESTINATION "${CMAKE_SOURCE_DIR}/bin")
endforeach()

View File

@ -7,7 +7,7 @@
#include "common/Console.h"
#include "common/Error.h"
#include <SDL.h>
#include <SDL3/SDL.h>
namespace
{
@ -105,7 +105,7 @@ bool SDLAudioStream::OpenDevice(bool stretch_enabled, Error* error)
SDL_AudioSpec spec = {};
spec.freq = m_sample_rate;
spec.channels = m_output_channels;
spec.format = AUDIO_S16;
spec.format = SDL_AUDIO_S16LE;
spec.samples = static_cast<Uint16>(GetBufferSizeForMS(
m_sample_rate, (m_parameters.minimal_output_latency) ? m_parameters.buffer_ms : m_parameters.output_latency_ms));
spec.callback = AudioCallback;
@ -122,7 +122,7 @@ bool SDLAudioStream::OpenDevice(bool stretch_enabled, Error* error)
DEV_LOG("Requested {} frame buffer, got {} frame buffer", spec.samples, obtained_spec.samples);
BaseInitialize(sample_readers[static_cast<size_t>(m_parameters.expansion_mode)], stretch_enabled);
SDL_PauseAudioDevice(m_device_id, 0);
SDL_ResumeAudioDevice(m_device_id);
return true;
}
@ -131,8 +131,12 @@ void SDLAudioStream::SetPaused(bool paused)
{
if (m_paused == paused)
return;
if (paused)
SDL_PauseAudioDevice(m_device_id);
else
SDL_ResumeAudioDevice(m_device_id);
SDL_PauseAudioDevice(m_device_id, paused ? 1 : 0);
m_paused = paused;
}

View File

@ -21,92 +21,92 @@
static constexpr const char* CONTROLLER_DB_FILENAME = "game_controller_db.txt";
static constexpr const char* s_sdl_axis_names[] = {
"LeftX", // SDL_CONTROLLER_AXIS_LEFTX
"LeftY", // SDL_CONTROLLER_AXIS_LEFTY
"RightX", // SDL_CONTROLLER_AXIS_RIGHTX
"RightY", // SDL_CONTROLLER_AXIS_RIGHTY
"LeftTrigger", // SDL_CONTROLLER_AXIS_TRIGGERLEFT
"RightTrigger", // SDL_CONTROLLER_AXIS_TRIGGERRIGHT
"LeftX", // SDL_GAMEPAD_AXIS_LEFTX
"LeftY", // SDL_GAMEPAD_AXIS_LEFTY
"RightX", // SDL_GAMEPAD_AXIS_RIGHTX
"RightY", // SDL_GAMEPAD_AXIS_RIGHTY
"LeftTrigger", // SDL_GAMEPAD_AXIS_LEFT_TRIGGER
"RightTrigger", // SDL_GAMEPAD_AXIS_RIGHT_TRIGGER
};
static constexpr const char* s_sdl_axis_icons[][2] = {
{ICON_PF_LEFT_ANALOG_LEFT, ICON_PF_LEFT_ANALOG_RIGHT}, // SDL_CONTROLLER_AXIS_LEFTX
{ICON_PF_LEFT_ANALOG_UP, ICON_PF_LEFT_ANALOG_DOWN}, // SDL_CONTROLLER_AXIS_LEFTY
{ICON_PF_RIGHT_ANALOG_LEFT, ICON_PF_RIGHT_ANALOG_RIGHT}, // SDL_CONTROLLER_AXIS_RIGHTX
{ICON_PF_RIGHT_ANALOG_UP, ICON_PF_RIGHT_ANALOG_DOWN}, // SDL_CONTROLLER_AXIS_RIGHTY
{nullptr, ICON_PF_LEFT_TRIGGER_PULL}, // SDL_CONTROLLER_AXIS_TRIGGERLEFT
{nullptr, ICON_PF_RIGHT_TRIGGER_PULL}, // SDL_CONTROLLER_AXIS_TRIGGERRIGHT
{ICON_PF_LEFT_ANALOG_LEFT, ICON_PF_LEFT_ANALOG_RIGHT}, // SDL_GAMEPAD_AXIS_LEFTX
{ICON_PF_LEFT_ANALOG_UP, ICON_PF_LEFT_ANALOG_DOWN}, // SDL_GAMEPAD_AXIS_LEFTY
{ICON_PF_RIGHT_ANALOG_LEFT, ICON_PF_RIGHT_ANALOG_RIGHT}, // SDL_GAMEPAD_AXIS_RIGHTX
{ICON_PF_RIGHT_ANALOG_UP, ICON_PF_RIGHT_ANALOG_DOWN}, // SDL_GAMEPAD_AXIS_RIGHTY
{nullptr, ICON_PF_LEFT_TRIGGER_PULL}, // SDL_GAMEPAD_AXIS_LEFT_TRIGGER
{nullptr, ICON_PF_RIGHT_TRIGGER_PULL}, // SDL_GAMEPAD_AXIS_RIGHT_TRIGGER
};
static constexpr const GenericInputBinding s_sdl_generic_binding_axis_mapping[][2] = {
{GenericInputBinding::LeftStickLeft, GenericInputBinding::LeftStickRight}, // SDL_CONTROLLER_AXIS_LEFTX
{GenericInputBinding::LeftStickUp, GenericInputBinding::LeftStickDown}, // SDL_CONTROLLER_AXIS_LEFTY
{GenericInputBinding::RightStickLeft, GenericInputBinding::RightStickRight}, // SDL_CONTROLLER_AXIS_RIGHTX
{GenericInputBinding::RightStickUp, GenericInputBinding::RightStickDown}, // SDL_CONTROLLER_AXIS_RIGHTY
{GenericInputBinding::Unknown, GenericInputBinding::L2}, // SDL_CONTROLLER_AXIS_TRIGGERLEFT
{GenericInputBinding::Unknown, GenericInputBinding::R2}, // SDL_CONTROLLER_AXIS_TRIGGERRIGHT
{GenericInputBinding::LeftStickLeft, GenericInputBinding::LeftStickRight}, // SDL_GAMEPAD_AXIS_LEFTX
{GenericInputBinding::LeftStickUp, GenericInputBinding::LeftStickDown}, // SDL_GAMEPAD_AXIS_LEFTY
{GenericInputBinding::RightStickLeft, GenericInputBinding::RightStickRight}, // SDL_GAMEPAD_AXIS_RIGHTX
{GenericInputBinding::RightStickUp, GenericInputBinding::RightStickDown}, // SDL_GAMEPAD_AXIS_RIGHTY
{GenericInputBinding::Unknown, GenericInputBinding::L2}, // SDL_GAMEPAD_AXIS_LEFT_TRIGGER
{GenericInputBinding::Unknown, GenericInputBinding::R2}, // SDL_GAMEPAD_AXIS_RIGHT_TRIGGER
};
static constexpr const char* s_sdl_button_names[] = {
"A", // SDL_CONTROLLER_BUTTON_A
"B", // SDL_CONTROLLER_BUTTON_B
"X", // SDL_CONTROLLER_BUTTON_X
"Y", // SDL_CONTROLLER_BUTTON_Y
"Back", // SDL_CONTROLLER_BUTTON_BACK
"Guide", // SDL_CONTROLLER_BUTTON_GUIDE
"Start", // SDL_CONTROLLER_BUTTON_START
"LeftStick", // SDL_CONTROLLER_BUTTON_LEFTSTICK
"RightStick", // SDL_CONTROLLER_BUTTON_RIGHTSTICK
"LeftShoulder", // SDL_CONTROLLER_BUTTON_LEFTSHOULDER
"RightShoulder", // SDL_CONTROLLER_BUTTON_RIGHTSHOULDER
"DPadUp", // SDL_CONTROLLER_BUTTON_DPAD_UP
"DPadDown", // SDL_CONTROLLER_BUTTON_DPAD_DOWN
"DPadLeft", // SDL_CONTROLLER_BUTTON_DPAD_LEFT
"DPadRight", // SDL_CONTROLLER_BUTTON_DPAD_RIGHT
"Misc1", // SDL_CONTROLLER_BUTTON_MISC1
"Paddle1", // SDL_CONTROLLER_BUTTON_PADDLE1
"Paddle2", // SDL_CONTROLLER_BUTTON_PADDLE2
"Paddle3", // SDL_CONTROLLER_BUTTON_PADDLE3
"Paddle4", // SDL_CONTROLLER_BUTTON_PADDLE4
"Touchpad", // SDL_CONTROLLER_BUTTON_TOUCHPAD
"A", // SDL_GAMEPAD_BUTTON_SOUTH
"B", // SDL_GAMEPAD_BUTTON_EAST
"X", // SDL_GAMEPAD_BUTTON_WEST
"Y", // SDL_GAMEPAD_BUTTON_NORTH
"Back", // SDL_GAMEPAD_BUTTON_BACK
"Guide", // SDL_GAMEPAD_BUTTON_GUIDE
"Start", // SDL_GAMEPAD_BUTTON_START
"LeftStick", // SDL_GAMEPAD_BUTTON_LEFT_STICK
"RightStick", // SDL_GAMEPAD_BUTTON_RIGHT_STICK
"LeftShoulder", // SDL_GAMEPAD_BUTTON_LEFT_SHOULDER
"RightShoulder", // SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER
"DPadUp", // SDL_GAMEPAD_BUTTON_DPAD_UP
"DPadDown", // SDL_GAMEPAD_BUTTON_DPAD_DOWN
"DPadLeft", // SDL_GAMEPAD_BUTTON_DPAD_LEFT
"DPadRight", // SDL_GAMEPAD_BUTTON_DPAD_RIGHT
"Misc1", // SDL_GAMEPAD_BUTTON_MISC1
"Paddle1", // SDL_GAMEPAD_BUTTON_RIGHT_PADDLE1
"Paddle2", // SDL_GAMEPAD_BUTTON_LEFT_PADDLE1
"Paddle3", // SDL_GAMEPAD_BUTTON_RIGHT_PADDLE2
"Paddle4", // SDL_GAMEPAD_BUTTON_LEFT_PADDLE2
"Touchpad", // SDL_GAMEPAD_BUTTON_TOUCHPAD
};
static constexpr const char* s_sdl_button_icons[] = {
ICON_PF_BUTTON_A, // SDL_CONTROLLER_BUTTON_A
ICON_PF_BUTTON_B, // SDL_CONTROLLER_BUTTON_B
ICON_PF_BUTTON_X, // SDL_CONTROLLER_BUTTON_X
ICON_PF_BUTTON_Y, // SDL_CONTROLLER_BUTTON_Y
ICON_PF_SHARE_CAPTURE, // SDL_CONTROLLER_BUTTON_BACK
ICON_PF_XBOX, // SDL_CONTROLLER_BUTTON_GUIDE
ICON_PF_BURGER_MENU, // SDL_CONTROLLER_BUTTON_START
ICON_PF_LEFT_ANALOG_CLICK, // SDL_CONTROLLER_BUTTON_LEFTSTICK
ICON_PF_RIGHT_ANALOG_CLICK, // SDL_CONTROLLER_BUTTON_RIGHTSTICK
ICON_PF_LEFT_SHOULDER_LB, // SDL_CONTROLLER_BUTTON_LEFTSHOULDER
ICON_PF_RIGHT_SHOULDER_RB, // SDL_CONTROLLER_BUTTON_RIGHTSHOULDER
ICON_PF_XBOX_DPAD_UP, // SDL_CONTROLLER_BUTTON_DPAD_UP
ICON_PF_XBOX_DPAD_DOWN, // SDL_CONTROLLER_BUTTON_DPAD_DOWN
ICON_PF_XBOX_DPAD_LEFT, // SDL_CONTROLLER_BUTTON_DPAD_LEFT
ICON_PF_XBOX_DPAD_RIGHT, // SDL_CONTROLLER_BUTTON_DPAD_RIGHT
ICON_PF_BUTTON_A, // SDL_GAMEPAD_BUTTON_SOUTH
ICON_PF_BUTTON_B, // SDL_GAMEPAD_BUTTON_EAST
ICON_PF_BUTTON_X, // SDL_GAMEPAD_BUTTON_WEST
ICON_PF_BUTTON_Y, // SDL_GAMEPAD_BUTTON_NORTH
ICON_PF_SHARE_CAPTURE, // SDL_GAMEPAD_BUTTON_BACK
ICON_PF_XBOX, // SDL_GAMEPAD_BUTTON_GUIDE
ICON_PF_BURGER_MENU, // SDL_GAMEPAD_BUTTON_START
ICON_PF_LEFT_ANALOG_CLICK, // SDL_GAMEPAD_BUTTON_LEFT_STICK
ICON_PF_RIGHT_ANALOG_CLICK, // SDL_GAMEPAD_BUTTON_RIGHT_STICK
ICON_PF_LEFT_SHOULDER_LB, // SDL_GAMEPAD_BUTTON_LEFT_SHOULDER
ICON_PF_RIGHT_SHOULDER_RB, // SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER
ICON_PF_XBOX_DPAD_UP, // SDL_GAMEPAD_BUTTON_DPAD_UP
ICON_PF_XBOX_DPAD_DOWN, // SDL_GAMEPAD_BUTTON_DPAD_DOWN
ICON_PF_XBOX_DPAD_LEFT, // SDL_GAMEPAD_BUTTON_DPAD_LEFT
ICON_PF_XBOX_DPAD_RIGHT, // SDL_GAMEPAD_BUTTON_DPAD_RIGHT
};
static constexpr const GenericInputBinding s_sdl_generic_binding_button_mapping[] = {
GenericInputBinding::Cross, // SDL_CONTROLLER_BUTTON_A
GenericInputBinding::Circle, // SDL_CONTROLLER_BUTTON_B
GenericInputBinding::Square, // SDL_CONTROLLER_BUTTON_X
GenericInputBinding::Triangle, // SDL_CONTROLLER_BUTTON_Y
GenericInputBinding::Select, // SDL_CONTROLLER_BUTTON_BACK
GenericInputBinding::System, // SDL_CONTROLLER_BUTTON_GUIDE
GenericInputBinding::Start, // SDL_CONTROLLER_BUTTON_START
GenericInputBinding::L3, // SDL_CONTROLLER_BUTTON_LEFTSTICK
GenericInputBinding::R3, // SDL_CONTROLLER_BUTTON_RIGHTSTICK
GenericInputBinding::L1, // SDL_CONTROLLER_BUTTON_LEFTSHOULDER
GenericInputBinding::R1, // SDL_CONTROLLER_BUTTON_RIGHTSHOULDER
GenericInputBinding::DPadUp, // SDL_CONTROLLER_BUTTON_DPAD_UP
GenericInputBinding::DPadDown, // SDL_CONTROLLER_BUTTON_DPAD_DOWN
GenericInputBinding::DPadLeft, // SDL_CONTROLLER_BUTTON_DPAD_LEFT
GenericInputBinding::DPadRight, // SDL_CONTROLLER_BUTTON_DPAD_RIGHT
GenericInputBinding::Unknown, // SDL_CONTROLLER_BUTTON_MISC1
GenericInputBinding::Unknown, // SDL_CONTROLLER_BUTTON_PADDLE1
GenericInputBinding::Unknown, // SDL_CONTROLLER_BUTTON_PADDLE2
GenericInputBinding::Unknown, // SDL_CONTROLLER_BUTTON_PADDLE3
GenericInputBinding::Unknown, // SDL_CONTROLLER_BUTTON_PADDLE4
GenericInputBinding::Unknown, // SDL_CONTROLLER_BUTTON_TOUCHPAD
GenericInputBinding::Cross, // SDL_GAMEPAD_BUTTON_SOUTH
GenericInputBinding::Circle, // SDL_GAMEPAD_BUTTON_EAST
GenericInputBinding::Square, // SDL_GAMEPAD_BUTTON_WEST
GenericInputBinding::Triangle, // SDL_GAMEPAD_BUTTON_NORTH
GenericInputBinding::Select, // SDL_GAMEPAD_BUTTON_BACK
GenericInputBinding::System, // SDL_GAMEPAD_BUTTON_GUIDE
GenericInputBinding::Start, // SDL_GAMEPAD_BUTTON_START
GenericInputBinding::L3, // SDL_GAMEPAD_BUTTON_LEFT_STICK
GenericInputBinding::R3, // SDL_GAMEPAD_BUTTON_RIGHT_STICK
GenericInputBinding::L1, // SDL_GAMEPAD_BUTTON_LEFT_SHOULDER
GenericInputBinding::R1, // SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER
GenericInputBinding::DPadUp, // SDL_GAMEPAD_BUTTON_DPAD_UP
GenericInputBinding::DPadDown, // SDL_GAMEPAD_BUTTON_DPAD_DOWN
GenericInputBinding::DPadLeft, // SDL_GAMEPAD_BUTTON_DPAD_LEFT
GenericInputBinding::DPadRight, // SDL_GAMEPAD_BUTTON_DPAD_RIGHT
GenericInputBinding::Unknown, // SDL_GAMEPAD_BUTTON_MISC1
GenericInputBinding::Unknown, // SDL_GAMEPAD_BUTTON_RIGHT_PADDLE1
GenericInputBinding::Unknown, // SDL_GAMEPAD_BUTTON_LEFT_PADDLE1
GenericInputBinding::Unknown, // SDL_GAMEPAD_BUTTON_RIGHT_PADDLE2
GenericInputBinding::Unknown, // SDL_GAMEPAD_BUTTON_LEFT_PADDLE2
GenericInputBinding::Unknown, // SDL_GAMEPAD_BUTTON_TOUCHPAD
};
static constexpr const char* s_sdl_hat_direction_names[] = {
@ -125,9 +125,9 @@ static constexpr const char* s_sdl_default_led_colors[] = {
"808000", // SDL-3
};
static void SetControllerRGBLED(SDL_GameController* gc, u32 color)
static void SetControllerRGBLED(SDL_Gamepad* gc, u32 color)
{
SDL_GameControllerSetLED(gc, (color >> 16) & 0xff, (color >> 8) & 0xff, color & 0xff);
SDL_SetGamepadLED(gc, (color >> 16) & 0xff, (color >> 8) & 0xff, color & 0xff);
}
static void SDLLogCallback(void* userdata, int category, SDL_LogPriority priority, const char* message)
@ -273,8 +273,8 @@ void SDLInputSource::SetHints()
}
SDL_SetHint(SDL_HINT_JOYSTICK_RAWINPUT, m_controller_raw_mode ? "1" : "0");
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE, m_controller_enhanced_mode ? "1" : "0");
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE, m_controller_enhanced_mode ? "1" : "0");
SDL_SetHint(SDL_HINT_JOYSTICK_ENHANCED_REPORTS, m_controller_enhanced_mode ? "1" : "0");
SDL_SetHint(SDL_HINT_JOYSTICK_ENHANCED_REPORTS, m_controller_enhanced_mode ? "1" : "0");
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS5_PLAYER_LED, m_controller_ps5_player_led ? "1" : "0");
// Enable Wii U Pro Controller support
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_WII, "1");
@ -296,17 +296,17 @@ void SDLInputSource::SetHints()
bool SDLInputSource::InitializeSubsystem()
{
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC) < 0)
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_GAMEPAD | SDL_INIT_HAPTIC) < 0)
{
Console.Error("SDL_InitSubSystem(SDL_INIT_JOYSTICK |SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC) failed");
Console.Error("SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_GAMEPAD | SDL_INIT_HAPTIC) failed");
return false;
}
SDL_LogSetOutputFunction(SDLLogCallback, nullptr);
SDL_SetLogOutputFunction(SDLLogCallback, nullptr);
#ifdef PCSX2_DEVBUILD
SDL_LogSetAllPriority(SDL_LOG_PRIORITY_VERBOSE);
SDL_SetLogPriorities(SDL_LOG_PRIORITY_VERBOSE);
#else
SDL_LogSetAllPriority(SDL_LOG_PRIORITY_INFO);
SDL_SetLogPriorities(SDL_LOG_PRIORITY_INFO);
#endif
// we should open the controllers as the connected events come in, so no need to do any more here
@ -322,7 +322,7 @@ void SDLInputSource::ShutdownSubsystem()
if (m_sdl_subsystem_initialized)
{
SDL_QuitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC);
SDL_QuitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_GAMEPAD | SDL_INIT_HAPTIC);
m_sdl_subsystem_initialized = false;
}
}
@ -347,7 +347,7 @@ std::vector<std::pair<std::string, std::string>> SDLInputSource::EnumerateDevice
{
std::string id(StringUtil::StdStringFromFormat("SDL-%d", cd.player_id));
const char* name = cd.game_controller ? SDL_GameControllerName(cd.game_controller) : SDL_JoystickName(cd.joystick);
const char* name = cd.game_controller ? SDL_GetGamepadName(cd.game_controller) : SDL_GetJoystickName(cd.joystick);
if (name)
ret.emplace_back(std::move(id), name);
else
@ -546,24 +546,24 @@ bool SDLInputSource::ProcessSDLEvent(const SDL_Event* event)
{
switch (event->type)
{
case SDL_CONTROLLERDEVICEADDED:
case SDL_EVENT_GAMEPAD_ADDED:
{
Console.WriteLn("SDLInputSource: Controller %d inserted", event->cdevice.which);
OpenDevice(event->cdevice.which, true);
return true;
}
case SDL_CONTROLLERDEVICEREMOVED:
case SDL_EVENT_GAMEPAD_REMOVED:
{
Console.WriteLn("SDLInputSource: Controller %d removed", event->cdevice.which);
CloseDevice(event->cdevice.which);
return true;
}
case SDL_JOYDEVICEADDED:
case SDL_EVENT_JOYSTICK_ADDED:
{
// Let game controller handle.. well.. game controllers.
if (SDL_IsGameController(event->jdevice.which))
if (SDL_IsGamepad(event->jdevice.which))
return false;
Console.WriteLn("SDLInputSource: Joystick %d inserted", event->jdevice.which);
@ -572,7 +572,7 @@ bool SDLInputSource::ProcessSDLEvent(const SDL_Event* event)
}
break;
case SDL_JOYDEVICEREMOVED:
case SDL_EVENT_JOYSTICK_REMOVED:
{
if (auto it = GetControllerDataForJoystickId(event->cdevice.which); it != m_controllers.end() && it->game_controller)
return false;
@ -582,21 +582,21 @@ bool SDLInputSource::ProcessSDLEvent(const SDL_Event* event)
return true;
}
case SDL_CONTROLLERAXISMOTION:
return HandleControllerAxisEvent(&event->caxis);
case SDL_EVENT_GAMEPAD_AXIS_MOTION:
return HandleControllerAxisEvent(&event->gaxis);
case SDL_CONTROLLERBUTTONDOWN:
case SDL_CONTROLLERBUTTONUP:
return HandleControllerButtonEvent(&event->cbutton);
case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
case SDL_EVENT_GAMEPAD_BUTTON_UP:
return HandleControllerButtonEvent(&event->gbutton);
case SDL_JOYAXISMOTION:
case SDL_EVENT_JOYSTICK_AXIS_MOTION:
return HandleJoystickAxisEvent(&event->jaxis);
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
case SDL_EVENT_JOYSTICK_BUTTON_DOWN:
case SDL_EVENT_JOYSTICK_BUTTON_UP:
return HandleJoystickButtonEvent(&event->jbutton);
case SDL_JOYHATMOTION:
case SDL_EVENT_JOYSTICK_HAT_MOTION:
return HandleJoystickHatEvent(&event->jhat);
default:
@ -649,18 +649,18 @@ int SDLInputSource::GetFreePlayerId() const
bool SDLInputSource::OpenDevice(int index, bool is_gamecontroller)
{
SDL_GameController* gcontroller;
SDL_Gamepad* gcontroller;
SDL_Joystick* joystick;
if (is_gamecontroller)
{
gcontroller = SDL_GameControllerOpen(index);
joystick = gcontroller ? SDL_GameControllerGetJoystick(gcontroller) : nullptr;
gcontroller = SDL_OpenGamepad(index);
joystick = gcontroller ? SDL_GetGamepadJoystick(gcontroller) : nullptr;
}
else
{
gcontroller = nullptr;
joystick = SDL_JoystickOpen(index);
joystick = SDL_OpenJoystick(index);
}
if (!gcontroller && !joystick)
@ -669,17 +669,17 @@ bool SDLInputSource::OpenDevice(int index, bool is_gamecontroller)
return false;
}
const int joystick_id = SDL_JoystickInstanceID(joystick);
int player_id = gcontroller ? SDL_GameControllerGetPlayerIndex(gcontroller) : SDL_JoystickGetPlayerIndex(joystick);
const int joystick_id = SDL_GetJoystickID(joystick);
int player_id = gcontroller ? SDL_GetGamepadPlayerIndex(gcontroller) : SDL_GetJoystickPlayerIndex(joystick);
for (auto it = m_controllers.begin(); it != m_controllers.end(); ++it)
{
if (it->joystick_id == joystick_id)
{
ERROR_LOG("SDLInputSource: Controller {}, instance {}, player {} already connected, ignoring.", index, joystick_id, player_id);
if (gcontroller)
SDL_GameControllerClose(gcontroller);
SDL_CloseGamepad(gcontroller);
else
SDL_JoystickClose(joystick);
SDL_CloseJoystick(joystick);
return false;
}
@ -694,7 +694,7 @@ bool SDLInputSource::OpenDevice(int index, bool is_gamecontroller)
player_id = free_player_id;
}
const char* name = gcontroller ? SDL_GameControllerName(gcontroller) : SDL_JoystickName(joystick);
const char* name = gcontroller ? SDL_GetGamepadName(gcontroller) : SDL_GetJoystickName(joystick);
if (!name)
name = "Unknown Device";
@ -710,49 +710,49 @@ bool SDLInputSource::OpenDevice(int index, bool is_gamecontroller)
if (gcontroller)
{
const int num_axes = SDL_JoystickNumAxes(joystick);
const int num_buttons = SDL_JoystickNumButtons(joystick);
const int num_axes = SDL_GetNumJoystickAxes(joystick);
const int num_buttons = SDL_GetNumJoystickButtons(joystick);
cd.joy_axis_used_in_gc.resize(num_axes, false);
cd.joy_button_used_in_gc.resize(num_buttons, false);
auto mark_bind = [&](SDL_GameControllerButtonBind bind) {
if (bind.bindType == SDL_CONTROLLER_BINDTYPE_AXIS && bind.value.axis < num_axes)
if (bind.bindType == SDL_GAMEPAD_BINDTYPE_AXIS && bind.value.axis < num_axes)
cd.joy_axis_used_in_gc[bind.value.axis] = true;
if (bind.bindType == SDL_CONTROLLER_BINDTYPE_BUTTON && bind.value.button < num_buttons)
if (bind.bindType == SDL_GAMEPAD_BINDTYPE_BUTTON && bind.value.button < num_buttons)
cd.joy_button_used_in_gc[bind.value.button] = true;
};
for (size_t i = 0; i < std::size(s_sdl_axis_names); i++)
mark_bind(SDL_GameControllerGetBindForAxis(gcontroller, static_cast<SDL_GameControllerAxis>(i)));
mark_bind(SDL_GetGamepadBindings(gcontroller, static_cast<SDL_GamepadAxis>(i)));
for (size_t i = 0; i < std::size(s_sdl_button_names); i++)
mark_bind(SDL_GameControllerGetBindForButton(gcontroller, static_cast<SDL_GameControllerButton>(i)));
mark_bind(SDL_GameControllerGetBindForButton(gcontroller, static_cast<SDL_GamepadButton>(i)));
INFO_LOG("SDLInputSource: Controller {} has {} axes and {} buttons", player_id, num_axes, num_buttons);
}
else
{
// GC doesn't have the concept of hats, so we only need to do this for joysticks.
const int num_hats = SDL_JoystickNumHats(joystick);
const int num_hats = SDL_GetNumJoystickHats(joystick);
if (num_hats > 0)
cd.last_hat_state.resize(static_cast<size_t>(num_hats), u8(0));
INFO_LOG("SDLInputSource: Joystick {} has {} axes, {} buttons and {} hats", player_id,
SDL_JoystickNumAxes(joystick), SDL_JoystickNumButtons(joystick), num_hats);
SDL_GetNumJoystickAxes(joystick), SDL_GetNumJoystickButtons(joystick), num_hats);
}
cd.use_game_controller_rumble = (gcontroller && SDL_GameControllerRumble(gcontroller, 0, 0, 0) == 0);
cd.use_game_controller_rumble = (gcontroller && SDL_RumbleGamepad(gcontroller, 0, 0, 0) == 0);
if (cd.use_game_controller_rumble)
{
INFO_LOG("SDLInputSource: Rumble is supported on '{}' via gamecontroller", name);
}
else
{
SDL_Haptic* haptic = SDL_HapticOpenFromJoystick(joystick);
SDL_Haptic* haptic = SDL_OpenHapticFromJoystick(joystick);
if (haptic)
{
SDL_HapticEffect ef = {};
ef.leftright.type = SDL_HAPTIC_LEFTRIGHT;
ef.leftright.length = 1000;
int ef_id = SDL_HapticNewEffect(haptic, &ef);
int ef_id = SDL_CreateHapticEffect(haptic, &ef);
if (ef_id >= 0)
{
cd.haptic = haptic;
@ -761,14 +761,14 @@ bool SDLInputSource::OpenDevice(int index, bool is_gamecontroller)
else
{
ERROR_LOG("SDLInputSource: Failed to create haptic left/right effect: {}", SDL_GetError());
if (SDL_HapticRumbleSupported(haptic) && SDL_HapticRumbleInit(haptic) != 0)
if (SDL_HapticRumbleSupported(haptic) && SDL_InitHapticRumble(haptic) != 0)
{
cd.haptic = haptic;
}
else
{
ERROR_LOG("SDLInputSource: No haptic rumble supported: {}", SDL_GetError());
SDL_HapticClose(haptic);
SDL_CloseHaptic(haptic);
}
}
}
@ -802,12 +802,12 @@ bool SDLInputSource::CloseDevice(int joystick_index)
fmt::format("SDL-{}", it->player_id));
if (it->haptic)
SDL_HapticClose(it->haptic);
SDL_CloseHaptic(it->haptic);
if (it->game_controller)
SDL_GameControllerClose(it->game_controller);
SDL_CloseGamepad(it->game_controller);
else
SDL_JoystickClose(it->joystick);
SDL_CloseJoystick(it->joystick);
m_controllers.erase(it);
return true;
@ -818,7 +818,7 @@ static float NormalizeS16(s16 value)
return static_cast<float>(value) / (value < 0 ? 32768.0f : 32767.0f);
}
bool SDLInputSource::HandleControllerAxisEvent(const SDL_ControllerAxisEvent* ev)
bool SDLInputSource::HandleControllerAxisEvent(const SDL_GamepadAxisEvent* ev)
{
auto it = GetControllerDataForJoystickId(ev->which);
if (it == m_controllers.end())
@ -829,7 +829,7 @@ bool SDLInputSource::HandleControllerAxisEvent(const SDL_ControllerAxisEvent* ev
return true;
}
bool SDLInputSource::HandleControllerButtonEvent(const SDL_ControllerButtonEvent* ev)
bool SDLInputSource::HandleControllerButtonEvent(const SDL_GamepadButtonEvent* ev)
{
auto it = GetControllerDataForJoystickId(ev->which);
if (it == m_controllers.end())
@ -839,7 +839,7 @@ bool SDLInputSource::HandleControllerButtonEvent(const SDL_ControllerButtonEvent
const GenericInputBinding generic_key = (ev->button < std::size(s_sdl_generic_binding_button_mapping)) ?
s_sdl_generic_binding_button_mapping[ev->button] :
GenericInputBinding::Unknown;
InputManager::InvokeEvents(key, (ev->state == SDL_PRESSED) ? 1.0f : 0.0f, generic_key);
InputManager::InvokeEvents(key, static_cast<float>(ev->down), generic_key);
return true;
}
@ -865,7 +865,7 @@ bool SDLInputSource::HandleJoystickButtonEvent(const SDL_JoyButtonEvent* ev)
return false; // Will get handled by GC event
const u32 button = ev->button + std::size(s_sdl_button_names); // Ensure we don't conflict with GC buttons
const InputBindingKey key(MakeGenericControllerButtonKey(InputSourceType::SDL, it->player_id, button));
InputManager::InvokeEvents(key, (ev->state == SDL_PRESSED) ? 1.0f : 0.0f);
InputManager::InvokeEvents(key, static_cast<float>(ev->down));
return true;
}
@ -1019,7 +1019,7 @@ void SDLInputSource::SendRumbleUpdate(ControllerData* cd)
if (cd->use_game_controller_rumble)
{
SDL_GameControllerRumble(cd->game_controller, cd->rumble_intensity[0], cd->rumble_intensity[1], DURATION);
SDL_RumbleGamepad(cd->game_controller, cd->rumble_intensity[0], cd->rumble_intensity[1], DURATION);
return;
}
@ -1032,20 +1032,20 @@ void SDLInputSource::SendRumbleUpdate(ControllerData* cd)
ef.leftright.large_magnitude = cd->rumble_intensity[0];
ef.leftright.small_magnitude = cd->rumble_intensity[1];
ef.leftright.length = DURATION;
SDL_HapticUpdateEffect(cd->haptic, cd->haptic_left_right_effect, &ef);
SDL_HapticRunEffect(cd->haptic, cd->haptic_left_right_effect, SDL_HAPTIC_INFINITY);
SDL_UpdateHapticEffect(cd->haptic, cd->haptic_left_right_effect, &ef);
SDL_RunHapticEffect(cd->haptic, cd->haptic_left_right_effect, SDL_HAPTIC_INFINITY);
}
else
{
SDL_HapticStopEffect(cd->haptic, cd->haptic_left_right_effect);
SDL_StopHapticEffect(cd->haptic, cd->haptic_left_right_effect);
}
}
else
{
const float strength = static_cast<float>(std::max(cd->rumble_intensity[0], cd->rumble_intensity[1])) * (1.0f / 65535.0f);
if (strength > 0.0f)
SDL_HapticRumblePlay(cd->haptic, strength, DURATION);
SDL_PlayHapticRumble(cd->haptic, strength, DURATION);
else
SDL_HapticRumbleStop(cd->haptic);
SDL_StopHapticRumble(cd->haptic);
}
}

View File

@ -5,7 +5,7 @@
#include "Input/InputSource.h"
#include <SDL.h>
#include <SDL3/SDL.h>
#include <array>
#include <functional>
@ -50,7 +50,7 @@ private:
struct ControllerData
{
SDL_Haptic* haptic;
SDL_GameController* game_controller;
SDL_Gamepad* game_controller;
SDL_Joystick* joystick;
u16 rumble_intensity[2];
int haptic_left_right_effect;
@ -79,8 +79,8 @@ private:
bool OpenDevice(int index, bool is_gamecontroller);
bool CloseDevice(int joystick_index);
bool HandleControllerAxisEvent(const SDL_ControllerAxisEvent* ev);
bool HandleControllerButtonEvent(const SDL_ControllerButtonEvent* ev);
bool HandleControllerAxisEvent(const SDL_GamepadAxisEvent* ev);
bool HandleControllerButtonEvent(const SDL_GamepadButtonEvent* ev);
bool HandleJoystickAxisEvent(const SDL_JoyAxisEvent* ev);
bool HandleJoystickButtonEvent(const SDL_JoyButtonEvent* ev);
bool HandleJoystickHatEvent(const SDL_JoyHatEvent* ev);

View File

@ -27,7 +27,7 @@ namespace usb_pad
{
DestroyEffects();
SDL_HapticClose(m_haptic);
SDL_CloseHaptic(m_haptic);
m_haptic = nullptr;
}
}
@ -45,7 +45,7 @@ namespace usb_pad
return nullptr;
}
SDL_Haptic* haptic = SDL_HapticOpenFromJoystick(joystick);
SDL_Haptic* haptic = SDL_OpenHapticFromJoystick(joystick);
if (!haptic)
{
Console.Error(fmt::format("Haptic is not supported on {}.", device));
@ -77,16 +77,16 @@ namespace usb_pad
// - Simagic Alpha Mini: Does NOT implement infinite durations (stops after some time, seeking hard numbers)
constexpr u32 length = SDL_HAPTIC_INFINITY;
const unsigned int supported = SDL_HapticQuery(m_haptic);
const unsigned int supported = SDL_GetHapticFeatures(m_haptic);
if (supported & SDL_HAPTIC_CONSTANT)
{
m_constant_effect.type = SDL_HAPTIC_CONSTANT;
m_constant_effect.constant.direction.type = SDL_HAPTIC_STEERING_AXIS;
m_constant_effect.constant.length = length;
m_constant_effect_id = SDL_HapticNewEffect(m_haptic, &m_constant_effect);
m_constant_effect_id = SDL_CreateHapticEffect(m_haptic, &m_constant_effect);
if (m_constant_effect_id < 0)
Console.Error("SDL_HapticNewEffect() for constant failed: %s", SDL_GetError());
Console.Error("SDL_CreateHapticEffect() for constant failed: %s", SDL_GetError());
}
else
{
@ -99,9 +99,9 @@ namespace usb_pad
m_spring_effect.condition.direction.type = SDL_HAPTIC_STEERING_AXIS;
m_spring_effect.condition.length = length;
m_spring_effect_id = SDL_HapticNewEffect(m_haptic, &m_spring_effect);
m_spring_effect_id = SDL_CreateHapticEffect(m_haptic, &m_spring_effect);
if (m_spring_effect_id < 0)
Console.Error("SDL_HapticNewEffect() for spring failed: %s", SDL_GetError());
Console.Error("SDL_CreateHapticEffect() for spring failed: %s", SDL_GetError());
}
else
{
@ -114,9 +114,9 @@ namespace usb_pad
m_damper_effect.condition.direction.type = SDL_HAPTIC_STEERING_AXIS;
m_damper_effect.condition.length = length;
m_damper_effect_id = SDL_HapticNewEffect(m_haptic, &m_damper_effect);
m_damper_effect_id = SDL_CreateHapticEffect(m_haptic, &m_damper_effect);
if (m_damper_effect_id < 0)
Console.Error("SDL_HapticNewEffect() for damper failed: %s", SDL_GetError());
Console.Error("SDL_CreateHapticEffect() for damper failed: %s", SDL_GetError());
}
else
{
@ -129,9 +129,9 @@ namespace usb_pad
m_friction_effect.condition.direction.type = SDL_HAPTIC_STEERING_AXIS;
m_friction_effect.condition.length = length;
m_friction_effect_id = SDL_HapticNewEffect(m_haptic, &m_friction_effect);
m_friction_effect_id = SDL_CreateHapticEffect(m_haptic, &m_friction_effect);
if (m_friction_effect_id < 0)
Console.Error("SDL_HapticNewEffect() for friction failed: %s", SDL_GetError());
Console.Error("SDL_CreateHapticEffect() for friction failed: %s", SDL_GetError());
}
else
{
@ -149,10 +149,10 @@ namespace usb_pad
{
if (m_friction_effect_running)
{
SDL_HapticStopEffect(m_haptic, m_friction_effect_id);
SDL_StopHapticEffect(m_haptic, m_friction_effect_id);
m_friction_effect_running = false;
}
SDL_HapticDestroyEffect(m_haptic, m_friction_effect_id);
SDL_DestroyHapticEffect(m_haptic, m_friction_effect_id);
m_friction_effect_id = -1;
}
@ -160,10 +160,10 @@ namespace usb_pad
{
if (m_damper_effect_running)
{
SDL_HapticStopEffect(m_haptic, m_damper_effect_id);
SDL_StopHapticEffect(m_haptic, m_damper_effect_id);
m_damper_effect_running = false;
}
SDL_HapticDestroyEffect(m_haptic, m_damper_effect_id);
SDL_DestroyHapticEffect(m_haptic, m_damper_effect_id);
m_damper_effect_id = -1;
}
@ -171,10 +171,10 @@ namespace usb_pad
{
if (m_spring_effect_running)
{
SDL_HapticStopEffect(m_haptic, m_spring_effect_id);
SDL_StopHapticEffect(m_haptic, m_spring_effect_id);
m_spring_effect_running = false;
}
SDL_HapticDestroyEffect(m_haptic, m_spring_effect_id);
SDL_DestroyHapticEffect(m_haptic, m_spring_effect_id);
m_spring_effect_id = -1;
}
@ -182,10 +182,10 @@ namespace usb_pad
{
if (m_constant_effect_running)
{
SDL_HapticStopEffect(m_haptic, m_constant_effect_id);
SDL_StopHapticEffect(m_haptic, m_constant_effect_id);
m_constant_effect_running = false;
}
SDL_HapticDestroyEffect(m_haptic, m_constant_effect_id);
SDL_DestroyHapticEffect(m_haptic, m_constant_effect_id);
m_constant_effect_id = -1;
}
}
@ -199,8 +199,8 @@ namespace usb_pad
if (m_constant_effect.constant.level != new_level)
{
m_constant_effect.constant.level = new_level;
if (SDL_HapticUpdateEffect(m_haptic, m_constant_effect_id, &m_constant_effect) != 0)
Console.Warning("SDL_HapticUpdateEffect() for constant failed: %s", SDL_GetError());
if (SDL_UpdateHapticEffect(m_haptic, m_constant_effect_id, &m_constant_effect) != 0)
Console.Warning("SDL_UpdateHapticEffect() for constant failed: %s", SDL_GetError());
}
// Avoid re-running already-running effects by default. Re-running a running effect
@ -217,10 +217,10 @@ namespace usb_pad
// This is the reason for use_ffb_dropout_workaround.
if (!m_constant_effect_running || use_ffb_dropout_workaround)
{
if (SDL_HapticRunEffect(m_haptic, m_constant_effect_id, SDL_HAPTIC_INFINITY) == 0)
if (SDL_RunHapticEffect(m_haptic, m_constant_effect_id, SDL_HAPTIC_INFINITY) == 0)
m_constant_effect_running = true;
else
Console.Error("SDL_HapticRunEffect() for constant failed: %s", SDL_GetError());
Console.Error("SDL_RunHapticEffect() for constant failed: %s", SDL_GetError());
}
}
@ -248,15 +248,15 @@ namespace usb_pad
m_spring_effect.condition.deadband[0] = ClampU16(ff.u.condition.deadband);
m_spring_effect.condition.center[0] = ClampS16(ff.u.condition.center);
if (SDL_HapticUpdateEffect(m_haptic, m_spring_effect_id, &m_spring_effect) != 0)
Console.Warning("SDL_HapticUpdateEffect() for spring failed: %s", SDL_GetError());
if (SDL_UpdateHapticEffect(m_haptic, m_spring_effect_id, &m_spring_effect) != 0)
Console.Warning("SDL_UpdateHapticEffect() for spring failed: %s", SDL_GetError());
if (!m_spring_effect_running)
{
if (SDL_HapticRunEffect(m_haptic, m_spring_effect_id, SDL_HAPTIC_INFINITY) == 0)
if (SDL_RunHapticEffect(m_haptic, m_spring_effect_id, SDL_HAPTIC_INFINITY) == 0)
m_spring_effect_running = true;
else
Console.Error("SDL_HapticRunEffect() for spring failed: %s", SDL_GetError());
Console.Error("SDL_RunHapticEffect() for spring failed: %s", SDL_GetError());
}
}
@ -272,15 +272,15 @@ namespace usb_pad
m_damper_effect.condition.deadband[0] = ClampU16(ff.u.condition.deadband);
m_damper_effect.condition.center[0] = ClampS16(ff.u.condition.center);
if (SDL_HapticUpdateEffect(m_haptic, m_damper_effect_id, &m_damper_effect) != 0)
Console.Warning("SDL_HapticUpdateEffect() for damper failed: %s", SDL_GetError());
if (SDL_UpdateHapticEffect(m_haptic, m_damper_effect_id, &m_damper_effect) != 0)
Console.Warning("SDL_UpdateHapticEffect() for damper failed: %s", SDL_GetError());
if (!m_damper_effect_running)
{
if (SDL_HapticRunEffect(m_haptic, m_damper_effect_id, SDL_HAPTIC_INFINITY) == 0)
if (SDL_RunHapticEffect(m_haptic, m_damper_effect_id, SDL_HAPTIC_INFINITY) == 0)
m_damper_effect_running = true;
else
Console.Error("SDL_HapticRunEffect() for damper failed: %s", SDL_GetError());
Console.Error("SDL_RunHapticEffect() for damper failed: %s", SDL_GetError());
}
}
@ -296,12 +296,12 @@ namespace usb_pad
m_friction_effect.condition.deadband[0] = ClampU16(ff.u.condition.deadband);
m_friction_effect.condition.center[0] = ClampS16(ff.u.condition.center);
if (SDL_HapticUpdateEffect(m_haptic, m_friction_effect_id, &m_friction_effect) != 0)
if (SDL_UpdateHapticEffect(m_haptic, m_friction_effect_id, &m_friction_effect) != 0)
{
if (!m_friction_effect_running && SDL_HapticRunEffect(m_haptic, m_friction_effect_id, SDL_HAPTIC_INFINITY) == 0)
if (!m_friction_effect_running && SDL_RunHapticEffect(m_haptic, m_friction_effect_id, SDL_HAPTIC_INFINITY) == 0)
m_friction_effect_running = true;
else
Console.Error("SDL_HapticUpdateEffect() for friction failed: %s", SDL_GetError());
Console.Error("SDL_UpdateHapticEffect() for friction failed: %s", SDL_GetError());
}
}
@ -309,8 +309,8 @@ namespace usb_pad
{
if (m_autocenter_supported)
{
if (SDL_HapticSetAutocenter(m_haptic, value) != 0)
Console.Warning("SDL_HapticSetAutocenter() failed: %s", SDL_GetError());
if (SDL_SetHapticAutocenter(m_haptic, value) != 0)
Console.Warning("SDL_SetHapticAutocenter() failed: %s", SDL_GetError());
}
}
@ -322,7 +322,7 @@ namespace usb_pad
{
if (m_constant_effect_running)
{
SDL_HapticStopEffect(m_haptic, m_constant_effect_id);
SDL_StopHapticEffect(m_haptic, m_constant_effect_id);
m_constant_effect_running = false;
}
}
@ -332,7 +332,7 @@ namespace usb_pad
{
if (m_spring_effect_running)
{
SDL_HapticStopEffect(m_haptic, m_spring_effect_id);
SDL_StopHapticEffect(m_haptic, m_spring_effect_id);
m_spring_effect_running = false;
}
}
@ -342,7 +342,7 @@ namespace usb_pad
{
if (m_damper_effect_running)
{
SDL_HapticStopEffect(m_haptic, m_damper_effect_id);
SDL_StopHapticEffect(m_haptic, m_damper_effect_id);
m_damper_effect_running = false;
}
}
@ -352,7 +352,7 @@ namespace usb_pad
{
if (m_friction_effect_running)
{
SDL_HapticStopEffect(m_haptic, m_friction_effect_id);
SDL_StopHapticEffect(m_haptic, m_friction_effect_id);
m_friction_effect_running = false;
}
}

View File

@ -31,7 +31,7 @@
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DepsIncludeDir)\SDL2</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DepsIncludeDir)\SDL3</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SolutionDir)3rdparty\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SolutionDir)3rdparty\fmt\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SolutionDir)3rdparty\winwil\include</AdditionalIncludeDirectories>

View File

@ -60,16 +60,16 @@ else()
target_sources(core_test PRIVATE ${multi_isa_sources})
endif()
if(WIN32 AND TARGET SDL2::SDL2)
# Copy SDL2 DLL to binary directory.
if(WIN32 AND TARGET SDL3::SDL3)
# Copy SDL3 DLL to binary directory.
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
get_property(SDL2_DLL_PATH TARGET SDL2::SDL2 PROPERTY IMPORTED_LOCATION_DEBUG)
get_property(SDL3_DLL_PATH TARGET SDL3::SDL3 PROPERTY IMPORTED_LOCATION_DEBUG)
else()
get_property(SDL2_DLL_PATH TARGET SDL2::SDL2 PROPERTY IMPORTED_LOCATION_RELEASE)
get_property(SDL3_DLL_PATH TARGET SDL3::SDL3 PROPERTY IMPORTED_LOCATION_RELEASE)
endif()
if(SDL2_DLL_PATH)
if(SDL3_DLL_PATH)
add_custom_command(TARGET core_test POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E make_directory "$<TARGET_FILE_DIR:core_test>"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${SDL2_DLL_PATH}" "$<TARGET_FILE_DIR:core_test>")
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${SDL3_DLL_PATH}" "$<TARGET_FILE_DIR:core_test>")
endif()
endif()