Skip to content

Commit

Permalink
Merge pull request #11302 from tellowkrinkle/SDL226
Browse files Browse the repository at this point in the history
Update SDL to 2.26
  • Loading branch information
lioncash committed Nov 24, 2022
2 parents 7be4c90 + db8f08b commit 032f54d
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Externals/SDL/SDL
Submodule SDL updated 488 files
2 changes: 2 additions & 0 deletions Externals/SDL/SDL2.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,9 @@
<ClCompile Include="SDL\src\joystick\hidapi\SDL_hidapi_rumble.c" />
<ClCompile Include="SDL\src\joystick\hidapi\SDL_hidapi_shield.c" />
<ClCompile Include="SDL\src\joystick\hidapi\SDL_hidapi_stadia.c" />
<ClCompile Include="SDL\src\joystick\hidapi\SDL_hidapi_steam.c" />
<ClCompile Include="SDL\src\joystick\hidapi\SDL_hidapi_switch.c" />
<ClCompile Include="SDL\src\joystick\hidapi\SDL_hidapi_wii.c" />
<ClCompile Include="SDL\src\joystick\hidapi\SDL_hidapi_xbox360.c" />
<ClCompile Include="SDL\src\joystick\hidapi\SDL_hidapi_xbox360w.c" />
<ClCompile Include="SDL\src\joystick\hidapi\SDL_hidapi_xboxone.c" />
Expand Down
64 changes: 41 additions & 23 deletions Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,27 @@ void InputBackend::PopulateDevices()
#endif
}

struct SDLMotionAxis
{
std::string_view name;
int index;
ControlState scale;
};
using SDLMotionAxisList = std::array<SDLMotionAxis, 6>;

// clang-format off
static constexpr SDLMotionAxisList SDL_AXES_ACCELEROMETER = {{
{"Up", 1, 1}, {"Down", 1, -1},
{"Left", 0, -1}, {"Right", 0, 1},
{"Forward", 2, -1}, {"Backward", 2, 1},
}};
static constexpr SDLMotionAxisList SDL_AXES_GYRO = {{
{"Pitch Up", 0, 1}, {"Pitch Down", 0, -1},
{"Roll Left", 2, 1}, {"Roll Right", 2, -1},
{"Yaw Left", 1, 1}, {"Yaw Right", 1, -1},
}};
// clang-format on

Joystick::Joystick(SDL_Joystick* const joystick, const int sdl_index)
: m_joystick(joystick), m_name(StripWhitespace(GetJoystickName(sdl_index)))
{
Expand Down Expand Up @@ -398,29 +419,26 @@ Joystick::Joystick(SDL_Joystick* const joystick, const int sdl_index)
m_controller = SDL_GameControllerOpen(sdl_index);
if (m_controller)
{
if (SDL_GameControllerSetSensorEnabled(m_controller, SDL_SENSOR_ACCEL, SDL_TRUE) == 0)
{
AddInput(new MotionInput("Accel Up", m_controller, SDL_SENSOR_ACCEL, 1, 1));
AddInput(new MotionInput("Accel Down", m_controller, SDL_SENSOR_ACCEL, 1, -1));

AddInput(new MotionInput("Accel Left", m_controller, SDL_SENSOR_ACCEL, 0, -1));
AddInput(new MotionInput("Accel Right", m_controller, SDL_SENSOR_ACCEL, 0, 1));

AddInput(new MotionInput("Accel Forward", m_controller, SDL_SENSOR_ACCEL, 2, -1));
AddInput(new MotionInput("Accel Backward", m_controller, SDL_SENSOR_ACCEL, 2, 1));
}

if (SDL_GameControllerSetSensorEnabled(m_controller, SDL_SENSOR_GYRO, SDL_TRUE) == 0)
{
AddInput(new MotionInput("Gyro Pitch Up", m_controller, SDL_SENSOR_GYRO, 0, 1));
AddInput(new MotionInput("Gyro Pitch Down", m_controller, SDL_SENSOR_GYRO, 0, -1));

AddInput(new MotionInput("Gyro Roll Left", m_controller, SDL_SENSOR_GYRO, 2, 1));
AddInput(new MotionInput("Gyro Roll Right", m_controller, SDL_SENSOR_GYRO, 2, -1));

AddInput(new MotionInput("Gyro Yaw Left", m_controller, SDL_SENSOR_GYRO, 1, 1));
AddInput(new MotionInput("Gyro Yaw Right", m_controller, SDL_SENSOR_GYRO, 1, -1));
}
auto AddSensor = [this](SDL_SensorType type, std::string_view name,
const SDLMotionAxisList& axes) {
if (SDL_GameControllerSetSensorEnabled(m_controller, type, SDL_TRUE) == 0)
{
for (const SDLMotionAxis& axis : axes)
{
AddInput(new MotionInput(fmt::format("{} {}", name, axis.name), m_controller, type,
axis.index, axis.scale));
}
}
};

AddSensor(SDL_SENSOR_ACCEL, "Accel", SDL_AXES_ACCELEROMETER);
AddSensor(SDL_SENSOR_GYRO, "Gyro", SDL_AXES_GYRO);
#if SDL_VERSION_ATLEAST(2, 26, 0)
AddSensor(SDL_SENSOR_ACCEL_L, "Accel L", SDL_AXES_ACCELEROMETER);
AddSensor(SDL_SENSOR_GYRO_L, "Gyro L", SDL_AXES_GYRO);
AddSensor(SDL_SENSOR_ACCEL_R, "Accel R", SDL_AXES_ACCELEROMETER);
AddSensor(SDL_SENSOR_GYRO_R, "Gyro R", SDL_AXES_GYRO);
#endif
}
}
#endif
Expand Down
6 changes: 3 additions & 3 deletions Source/Core/InputCommon/ControllerInterface/SDL/SDL.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,16 @@ class Joystick : public Core::Device
class MotionInput : public Input
{
public:
MotionInput(const char* name, SDL_GameController* gc, SDL_SensorType type, int index,
MotionInput(std::string name, SDL_GameController* gc, SDL_SensorType type, int index,
ControlState scale)
: m_name(name), m_gc(gc), m_type(type), m_index(index), m_scale(scale){};
: m_name(std::move(name)), m_gc(gc), m_type(type), m_index(index), m_scale(scale){};

std::string GetName() const override { return m_name; };
bool IsDetectable() const override { return false; };
ControlState GetState() const override;

private:
const char* m_name;
std::string m_name;

SDL_GameController* const m_gc;
SDL_SensorType const m_type;
Expand Down

0 comments on commit 032f54d

Please sign in to comment.