Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #10561 from shuffle2/sdl-motion
ControllerInterface: Add support for motion and rumble to SDL backend
  • Loading branch information
JMC47 committed Jul 11, 2022
2 parents 99eef44 + 54b4ad8 commit b2be9b4
Show file tree
Hide file tree
Showing 13 changed files with 737 additions and 64 deletions.
5 changes: 5 additions & 0 deletions .gitmodules
Expand Up @@ -23,3 +23,8 @@
url = https://github.com/KhronosGroup/SPIRV-Cross.git
branch = master
shallow = true
[submodule "SDL"]
path = Externals/SDL/SDL
url = https://github.com/libsdl-org/SDL.git
branch = main
shallow = true
21 changes: 19 additions & 2 deletions CMakeLists.txt
Expand Up @@ -84,8 +84,8 @@ option(OPROFILING "Enable profiling" OFF)
# TODO: Add DSPSpy
option(DSPTOOL "Build dsptool" OFF)

# Enable SDL for default on operating systems that aren't Android, Linux or Windows.
if(NOT ANDROID AND NOT CMAKE_SYSTEM_NAME STREQUAL "Linux" AND NOT MSVC)
# Enable SDL for default on operating systems that aren't Android or Linux.
if(NOT ANDROID AND NOT CMAKE_SYSTEM_NAME STREQUAL "Linux")
option(ENABLE_SDL "Enables SDL as a generic controller backend" ON)
else()
option(ENABLE_SDL "Enables SDL as a generic controller backend" OFF)
Expand Down Expand Up @@ -612,6 +612,23 @@ if(UNIX)
add_definitions(-DUSE_MEMORYWATCHER=1)
endif()

if(ENABLE_SDL)
find_package(SDL2)

if(SDL2_FOUND)
message(STATUS "Using system SDL2")
else()
message(STATUS "Using static SDL2 from Externals")
set(SDL_SHARED OFF)
set(SDL_SHARED_ENABLED_BY_DEFAULT OFF)
set(SDL_STATIC ON)
set(SDL_STATIC_ENABLED_BY_DEFAULT ON)
add_subdirectory(Externals/SDL/SDL)
set(SDL2_FOUND TRUE)
endif()
add_definitions(-DHAVE_SDL2=1)
endif()

if(ENABLE_ANALYTICS)
message(STATUS "Enabling analytics collection (subject to end-user opt-in)")
add_definitions(-DUSE_ANALYTICS=1)
Expand Down
3 changes: 3 additions & 0 deletions Externals/ExternalsReferenceAll.props
Expand Up @@ -94,5 +94,8 @@
<ProjectReference Include="$(ExternalsDir)zstd\zstd.vcxproj">
<Project>{1bea10f3-80ce-4bc4-9331-5769372cdf99}</Project>
</ProjectReference>
<ProjectReference Include="$(ExternalsDir)SDL\SDL2.vcxproj">
<Project>{8DC244EE-A0BD-4038-BAF7-CFAFA5EB2BAA}</Project>
</ProjectReference>
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions Externals/SDL/SDL
Submodule SDL added at cd2dcf
412 changes: 412 additions & 0 deletions Externals/SDL/SDL2.vcxproj

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Source/Core/DolphinLib.props
Expand Up @@ -493,6 +493,7 @@
<ClInclude Include="InputCommon\ControllerInterface\Wiimote\WiimoteController.h" />
<ClInclude Include="InputCommon\ControllerInterface\Win32\Win32.h" />
<ClInclude Include="InputCommon\ControllerInterface\XInput\XInput.h" />
<ClInclude Include="InputCommon\ControllerInterface\SDL\SDL.h" />
<ClInclude Include="InputCommon\ControlReference\ControlReference.h" />
<ClInclude Include="InputCommon\ControlReference\ExpressionParser.h" />
<ClInclude Include="InputCommon\ControlReference\FunctionExpression.h" />
Expand Down Expand Up @@ -1104,6 +1105,7 @@
<ClCompile Include="InputCommon\ControllerInterface\Wiimote\WiimoteController.cpp" />
<ClCompile Include="InputCommon\ControllerInterface\Win32\Win32.cpp" />
<ClCompile Include="InputCommon\ControllerInterface\XInput\XInput.cpp" />
<ClCompile Include="InputCommon\ControllerInterface\SDL\SDL.cpp" />
<ClCompile Include="InputCommon\ControlReference\ControlReference.cpp" />
<ClCompile Include="InputCommon\ControlReference\ExpressionParser.cpp" />
<ClCompile Include="InputCommon\ControlReference\FunctionExpression.cpp" />
Expand Down
32 changes: 6 additions & 26 deletions Source/Core/InputCommon/CMakeLists.txt
Expand Up @@ -174,32 +174,12 @@ if(UNIX)
)
endif()

if(ENABLE_SDL)
find_package(SDL2)
if(SDL2_FOUND)
message(STATUS "Using shared SDL2")
set(SDL_TARGET SDL2::SDL2)
else()
# SDL2 not found, try SDL
find_package(SDL)
if(SDL_FOUND)
message(STATUS "Using shared SDL")
add_library(System_SDL INTERFACE)
target_include_directories(System_SDL INTERFACE ${SDL_INCLUDE_DIR})
target_link_libraries(System_SDL INTERFACE ${SDL_LIBRARY})
set(SDL_TARGET System_SDL)
endif()
endif()
if(SDL_TARGET AND TARGET ${SDL_TARGET})
target_sources(inputcommon PRIVATE
ControllerInterface/SDL/SDL.cpp
ControllerInterface/SDL/SDL.h
)
target_link_libraries(inputcommon PRIVATE ${SDL_TARGET})
target_compile_definitions(inputcommon PRIVATE "CIFACE_USE_SDL=1")
else()
message(STATUS "SDL NOT found, disabling SDL input")
endif()
if(SDL2_FOUND)
target_sources(inputcommon PRIVATE
ControllerInterface/SDL/SDL.cpp
ControllerInterface/SDL/SDL.h
)
target_link_libraries(inputcommon PRIVATE SDL2::SDL2)
endif()

if(MSVC)
Expand Down
Expand Up @@ -30,6 +30,9 @@
#define CIFACE_USE_PIPES
#endif
#define CIFACE_USE_DUALSHOCKUDPCLIENT
#if defined(HAVE_SDL2)
#define CIFACE_USE_SDL
#endif

namespace ciface
{
Expand Down

0 comments on commit b2be9b4

Please sign in to comment.