diff options
| author | JMC47 <JMC4789@gmail.com> | 2022-07-11 16:28:30 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-11 16:28:30 -0400 |
| commit | b2be9b40ccdd3ab6b71fc5f124404148fb16a5f4 (patch) | |
| tree | 176104c39c1d4e9ba9416ea6ad08d1d468669edd | |
| parent | 99eef447651d40ed1954ccd5a83557478546face (diff) | |
| parent | 54b4ad8f559d6fa16bf0ca15f91de4e7d103996f (diff) | |
Merge pull request #10561 from shuffle2/sdl-motion
ControllerInterface: Add support for motion and rumble to SDL backend
| -rw-r--r-- | .gitmodules | 5 | ||||
| -rw-r--r-- | CMakeLists.txt | 21 | ||||
| -rw-r--r-- | Externals/ExternalsReferenceAll.props | 3 | ||||
| m--------- | Externals/SDL/SDL | 0 | ||||
| -rw-r--r-- | Externals/SDL/SDL2.vcxproj | 412 | ||||
| -rw-r--r-- | Source/Core/DolphinLib.props | 2 | ||||
| -rw-r--r-- | Source/Core/InputCommon/CMakeLists.txt | 32 | ||||
| -rw-r--r-- | Source/Core/InputCommon/ControllerInterface/ControllerInterface.h | 3 | ||||
| -rw-r--r-- | Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp | 253 | ||||
| -rw-r--r-- | Source/Core/InputCommon/ControllerInterface/SDL/SDL.h | 50 | ||||
| -rw-r--r-- | Source/Core/InputCommon/ControllerInterface/Win32/Win32.cpp | 6 | ||||
| -rw-r--r-- | Source/VSProps/Base.props | 2 | ||||
| -rw-r--r-- | Source/dolphin-emu.sln | 11 |
13 files changed, 736 insertions, 64 deletions
diff --git a/.gitmodules b/.gitmodules index 01e2ced8b6..d27084a9a6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index ae835b0f39..e3602d8bc5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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) diff --git a/Externals/ExternalsReferenceAll.props b/Externals/ExternalsReferenceAll.props index f3a19282e4..2566a4a4a0 100644 --- a/Externals/ExternalsReferenceAll.props +++ b/Externals/ExternalsReferenceAll.props @@ -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> diff --git a/Externals/SDL/SDL b/Externals/SDL/SDL new file mode 160000 +Subproject cd2dcf54afaa6d640abf8b83855f6c4b5cda457 diff --git a/Externals/SDL/SDL2.vcxproj b/Externals/SDL/SDL2.vcxproj new file mode 100644 index 0000000000..ebc599029a --- /dev/null +++ b/Externals/SDL/SDL2.vcxproj @@ -0,0 +1,412 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project> + <Import Project="..\..\Source\VSProps\Base.Macros.props" /> + <Import Project="$(VSPropsDir)Base.Targets.props" /> + <PropertyGroup Label="Globals"> + <ProjectGuid>{8DC244EE-A0BD-4038-BAF7-CFAFA5EB2BAA}</ProjectGuid> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <Import Project="$(VSPropsDir)Configuration.StaticLibrary.props" /> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <ImportGroup Label="ExtensionSettings" /> + <ImportGroup Label="PropertySheets"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + <Import Project="$(VSPropsDir)Base.props" /> + <Import Project="$(VSPropsDir)ClDisableAllWarnings.props" /> + </ImportGroup> + <PropertyGroup Label="UserMacros" /> + <ItemDefinitionGroup> + <ClCompile> + <AdditionalIncludeDirectories>SDL\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <PreprocessorDefinitions>HAVE_LIBC=1;%(PreprocessorDefinitions)</PreprocessorDefinitions> + </ClCompile> + </ItemDefinitionGroup> + <ItemGroup> + <ClInclude Include="SDL\include\begin_code.h" /> + <ClInclude Include="SDL\include\close_code.h" /> + <ClInclude Include="SDL\include\SDL_assert.h" /> + <ClInclude Include="SDL\include\SDL_atomic.h" /> + <ClInclude Include="SDL\include\SDL_audio.h" /> + <ClInclude Include="SDL\include\SDL_bits.h" /> + <ClInclude Include="SDL\include\SDL_blendmode.h" /> + <ClInclude Include="SDL\include\SDL_clipboard.h" /> + <ClInclude Include="SDL\include\SDL_config_windows.h" /> + <ClInclude Include="SDL\include\SDL_config.h" /> + <ClInclude Include="SDL\include\SDL_copying.h" /> + <ClInclude Include="SDL\include\SDL_cpuinfo.h" /> + <ClInclude Include="SDL\include\SDL_egl.h" /> + <ClInclude Include="SDL\include\SDL_endian.h" /> + <ClInclude Include="SDL\include\SDL_error.h" /> + <ClInclude Include="SDL\include\SDL_events.h" /> + <ClInclude Include="SDL\include\SDL_filesystem.h" /> + <ClInclude Include="SDL\include\SDL_gamecontroller.h" /> + <ClInclude Include="SDL\include\SDL_gesture.h" /> + <ClInclude Include="SDL\include\SDL_guid.h" /> + <ClInclude Include="SDL\include\SDL_haptic.h" /> + <ClInclude Include="SDL\include\SDL_hidapi.h" /> + <ClInclude Include="SDL\include\SDL_hints.h" /> + <ClInclude Include="SDL\include\SDL_joystick.h" /> + <ClInclude Include="SDL\include\SDL_keyboard.h" /> + <ClInclude Include="SDL\include\SDL_keycode.h" /> + <ClInclude Include="SDL\include\SDL_loadso.h" /> + <ClInclude Include="SDL\include\SDL_locale.h" /> + <ClInclude Include="SDL\include\SDL_log.h" /> + <ClInclude Include="SDL\include\SDL_main.h" /> + <ClInclude Include="SDL\include\SDL_messagebox.h" /> + <ClInclude Include="SDL\include\SDL_metal.h" /> + <ClInclude Include="SDL\include\SDL_misc.h" /> + <ClInclude Include="SDL\include\SDL_mouse.h" /> + <ClInclude Include="SDL\include\SDL_mutex.h" /> + <ClInclude Include="SDL\include\SDL_name.h" /> + <ClInclude Include="SDL\include\SDL_opengl_glext.h" /> + <ClInclude Include="SDL\include\SDL_opengl.h" /> + <ClInclude Include="SDL\include\SDL_opengles.h" /> + <ClInclude Include="SDL\include\SDL_opengles2_gl2.h" /> + <ClInclude Include="SDL\include\SDL_opengles2_gl2ext.h" /> + <ClInclude Include="SDL\include\SDL_opengles2_gl2platform.h" /> + <ClInclude Include="SDL\include\SDL_opengles2_khrplatform.h" /> + <ClInclude Include="SDL\include\SDL_opengles2.h" /> + <ClInclude Include="SDL\include\SDL_pixels.h" /> + <ClInclude Include="SDL\include\SDL_platform.h" /> + <ClInclude Include="SDL\include\SDL_power.h" /> + <ClInclude Include="SDL\include\SDL_quit.h" /> + <ClInclude Include="SDL\include\SDL_rect.h" /> + <ClInclude Include="SDL\include\SDL_render.h" /> + <ClInclude Include="SDL\include\SDL_revision.h" /> + <ClInclude Include="SDL\include\SDL_rwops.h" /> + <ClInclude Include="SDL\include\SDL_scancode.h" /> + <ClInclude Include="SDL\include\SDL_sensor.h" /> + <ClInclude Include="SDL\include\SDL_shape.h" /> + <ClInclude Include="SDL\include\SDL_stdinc.h" /> + <ClInclude Include="SDL\include\SDL_surface.h" /> + <ClInclude Include="SDL\include\SDL_system.h" /> + <ClInclude Include="SDL\include\SDL_syswm.h" /> + <ClInclude Include="SDL\include\SDL_test_assert.h" /> + <ClInclude Include="SDL\include\SDL_test_common.h" /> + <ClInclude Include="SDL\include\SDL_test_compare.h" /> + <ClInclude Include="SDL\include\SDL_test_crc32.h" /> + <ClInclude Include="SDL\include\SDL_test_font.h" /> + <ClInclude Include="SDL\include\SDL_test_fuzzer.h" /> + <ClInclude Include="SDL\include\SDL_test_harness.h" /> + <ClInclude Include="SDL\include\SDL_test_images.h" /> + <ClInclude Include="SDL\include\SDL_test_log.h" /> + <ClInclude Include="SDL\include\SDL_test_md5.h" /> + <ClInclude Include="SDL\include\SDL_test_memory.h" /> + <ClInclude Include="SDL\include\SDL_test_random.h" /> + <ClInclude Include="SDL\include\SDL_test.h" /> + <ClInclude Include="SDL\include\SDL_thread.h" /> + <ClInclude Include="SDL\include\SDL_timer.h" /> + <ClInclude Include="SDL\include\SDL_touch.h" /> + <ClInclude Include="SDL\include\SDL_types.h" /> + <ClInclude Include="SDL\include\SDL_version.h" /> + <ClInclude Include="SDL\include\SDL_video.h" /> + <ClInclude Include="SDL\include\SDL_vulkan.h" /> + <ClInclude Include="SDL\include\SDL.h" /> + <ClInclude Include="SDL\src\audio\directsound\SDL_directsound.h" /> + <ClInclude Include="SDL\src\audio\disk\SDL_diskaudio.h" /> + <ClInclude Include="SDL\src\audio\dummy\SDL_dummyaudio.h" /> + <ClInclude Include="SDL\src\audio\SDL_audio_c.h" /> + <ClInclude Include="SDL\src\audio\SDL_audio_resampler_filter.h" /> + <ClInclude Include="SDL\src\audio\SDL_audiodev_c.h" /> + <ClInclude Include="SDL\src\audio\SDL_sysaudio.h" /> + <ClInclude Include="SDL\src\audio\SDL_wave.h" /> + <ClInclude Include="SDL\src\audio\wasapi\SDL_wasapi.h" /> + <ClInclude Include="SDL\src\audio\winmm\SDL_winmm.h" /> + <ClInclude Include="SDL\src\core\windows\SDL_directx.h" /> + <ClInclude Include="SDL\src\core\windows\SDL_hid.h" /> + <ClInclude Include="SDL\src\core\windows\SDL_windows.h" /> + <ClInclude Include="SDL\src\core\windows\SDL_xinput.h" /> + <ClInclude Include="SDL\src\dynapi\SDL_dynapi_overrides.h" /> + <ClInclude Include="SDL\src\dynapi\SDL_dynapi_procs.h" /> + <ClInclude Include="SDL\src\dynapi\SDL_dynapi.h" /> + <ClInclude Include="SDL\src\events\blank_cursor.h" /> + <ClInclude Include="SDL\src\events\default_cursor.h" /> + <ClInclude Include="SDL\src\events\scancodes_ascii.h" /> + <ClInclude Include="SDL\src\events\scancodes_windows.h" /> + <ClInclude Include="SDL\src\events\SDL_clipboardevents_c.h" /> + <ClInclude Include="SDL\src\events\SDL_displayevents_c.h" /> + <ClInclude Include="SDL\src\events\SDL_dropevents_c.h" /> + <ClInclude Include="SDL\src\events\SDL_events_c.h" /> + <ClInclude Include="SDL\src\events\SDL_gesture_c.h" /> + <ClInclude Include="SDL\src\events\SDL_keyboard_c.h" /> + <ClInclude Include="SDL\src\events\SDL_log.h" /> + <ClInclude Include="SDL\src\events\SDL_mouse_c.h" /> + <ClInclude Include="SDL\src\events\SDL_touch_c.h" /> + <ClInclude Include="SDL\src\events\SDL_windowevents_c.h" /> + <ClInclude Include="SDL\src\haptic\SDL_haptic_c.h" /> + <ClInclude Include="SDL\src\haptic\SDL_syshaptic.h" /> + <ClInclude Include="SDL\src\haptic\windows\SDL_dinputhaptic_c.h" /> + <ClInclude Include="SDL\src\haptic\windows\SDL_windowshaptic_c.h" /> + <ClInclude Include="SDL\src\haptic\windows\SDL_xinputhaptic_c.h" /> + <ClInclude Include="SDL\src\hidapi\hidapi\hidapi.h" /> + <ClInclude Include="SDL\src\hidapi\SDL_hidapi_c.h" /> + <ClInclude Include="SDL\src\joystick\controller_type.h" /> + <ClInclude Include="SDL\src\joystick\hidapi\SDL_hidapi_rumble.h" /> + <ClInclude Include="SDL\src\joystick\hidapi\SDL_hidapijoystick_c.h" /> + <ClInclude Include="SDL\src\joystick\SDL_gamecontrollerdb.h" /> + <ClInclude Include="SDL\src\joystick\SDL_joystick_c.h" /> + <ClInclude Include="SDL\src\joystick\SDL_sysjoystick.h" /> + <ClInclude Include="SDL\src\joystick\usb_ids.h" /> + <ClInclude Include="SDL\src\joystick\virtual\SDL_virtualjoystick_c.h" /> + <ClInclude Include="SDL\src\joystick\windows\SDL_dinputjoystick_c.h" /> + <ClInclude Include="SDL\src\joystick\windows\SDL_rawinputjoystick_c.h" /> + <ClInclude Include="SDL\src\joystick\windows\SDL_windowsjoystick_c.h" /> + <ClInclude Include="SDL\src\joystick\windows\SDL_xinputjoystick_c.h" /> + <ClInclude Include="SDL\src\locale\SDL_syslocale.h" /> + <ClInclude Include="SDL\src\misc\SDL_sysurl.h" /> + <ClInclude Include="SDL\src\power\SDL_syspower.h" /> + <ClInclude Include="SDL\src\render\direct3d\SDL_shaders_d3d.h" /> + <ClInclude Include="SDL\src\render\direct3d11\SDL_shaders_d3d11.h" /> + <ClInclude Include="SDL\src\render\direct3d12\SDL_render_d3d12_xbox.h" /> + <ClInclude Include="SDL\src\render\direct3d12\SDL_shaders_d3d12.h" /> + <ClInclude Include="SDL\src\render\opengl\SDL_glfuncs.h" /> + <ClInclude Include="SDL\src\render\opengl\SDL_shaders_gl.h" /> + <ClInclude Include="SDL\src\render\opengles2\SDL_gles2funcs.h" /> + <ClInclude Include="SDL\src\render\opengles2\SDL_shaders_gles2.h" /> + <ClInclude Include="SDL\src\render\SDL_d3dmath.h" /> + <ClInclude Include="SDL\src\render\SDL_sysrender.h" /> + <ClInclude Include="SDL\src\render\SDL_yuv_sw_c.h" /> + <ClInclude Include="SDL\src\render\software\SDL_blendfillrect.h" /> + <ClInclude Include="SDL\src\render\software\SDL_blendline.h" /> + <ClInclude Include="SDL\src\render\software\SDL_blendpoint.h" /> + <ClInclude Include="SDL\src\render\software\SDL_draw.h" /> + <ClInclude Include="SDL\src\render\software\SDL_drawline.h" /> + <ClInclude Include="SDL\src\render\software\SDL_drawpoint.h" /> + <ClInclude Include="SDL\src\render\software\SDL_render_sw_c.h" /> + <ClInclude Include="SDL\src\render\software\SDL_rotate.h" /> + <ClInclude Include="SDL\src\render\software\SDL_triangle.h" /> + <ClInclude Include="SDL\src\SDL_assert_c.h" /> + <ClInclude Include="SDL\src\SDL_dataqueue.h" /> + <ClInclude Include="SDL\src\SDL_error_c.h" /> + <ClInclude Include="SDL\src\SDL_hints_c.h" /> + <ClInclude Include="SDL\src\SDL_internal.h" /> + <ClInclude Include="SDL\src\SDL_list.h" /> + <ClInclude Include="SDL\src\sensor\dummy\SDL_dummysensor.h" /> + <ClInclude Include="SDL\src\sensor\SDL_sensor_c.h" /> + <ClInclude Include="SDL\src\sensor\SDL_syssensor.h" /> + <ClInclude Include="SDL\src\sensor\windows\SDL_windowssensor.h" /> + <ClInclude Include="SDL\src\stdlib\SDL_vacopy.h" /> + <ClInclude Include="SDL\src\thread\generic\SDL_syscond_c.h" /> + <ClInclude Include="SDL\src\thread\SDL_systhread.h" /> + <ClInclude Include="SDL\src\thread\SDL_thread_c.h" /> + <ClInclude Include="SDL\src\thread\windows\SDL_sysmutex_c.h" /> + <ClInclude Include="SDL\src\thread\windows\SDL_systhread_c.h" /> + <ClInclude Include="SDL\src\timer\SDL_timer_c.h" /> + <ClInclude Include="SDL\src\video\dummy\SDL_nullevents_c.h" /> + <ClInclude Include="SDL\src\video\dummy\SDL_nullframebuffer_c.h" /> + <ClInclude Include="SDL\src\video\dummy\SDL_nullvideo.h" /> + <ClInclude Include="SDL\src\video\khronos\vulkan\vk_icd.h" /> + <ClInclude Include="SDL\src\video\khronos\vulkan\vk_layer.h" /> + <ClInclude Include="SDL\src\video\khronos\vulkan\vk_platform.h" /> + <ClInclude Include="SDL\src\video\khronos\vulkan\vk_sdk_platform.h" /> + <ClInclude Include="SDL\src\video\khronos\vulkan\vulkan_android.h" /> + <ClInclude Include="SDL\src\video\khronos\vulkan\vulkan_beta.h" /> + <ClInclude Include="SDL\src\video\khronos\vulkan\vulkan_core.h" /> + <ClInclude Include="SDL\src\video\khronos\vulkan\vulkan_directfb.h" /> + <ClInclude Include="SDL\src\video\khronos\vulkan\vulkan_fuchsia.h" /> + <ClInclude Include="SDL\src\video\khronos\vulkan\vulkan_ggp.h" /> + <ClInclude Include="SDL\src\video\khronos\vulkan\vulkan_ios.h" /> + <ClInclude Include="SDL\src\video\khronos\vulkan\vulkan_macos.h" /> + <ClInclude Include="SDL\src\video\khronos\vulkan\vulkan_metal.h" /> + <ClInclude Include="SDL\src\video\khronos\vulkan\vulkan_vi.h" /> + <ClInclude Include="SDL\src\video\khronos\vulkan\vulkan_wayland.h" /> + <ClInclude Include="SDL\src\video\khronos\vulkan\vulkan_win32.h" /> + <ClInclude Include="SDL\src\video\khronos\vulkan\vulkan_xcb.h" /> + <ClInclude Include="SDL\src\video\khronos\vulkan\vulkan_xlib_xrandr.h" /> + <ClInclude Include="SDL\src\video\khronos\vulkan\vulkan_xlib.h" /> + <ClInclude Include="SDL\src\video\khronos\vulkan\vulkan.h" /> + <ClInclude Include="SDL\src\video\khronos\vulkan\vulkan.hpp" /> + <ClInclude Include="SDL\src\video\SDL_blit_auto.h" /> + <ClInclude Include="SDL\src\video\SDL_blit_copy.h" /> + <ClInclude Include="SDL\src\video\SDL_blit_slow.h" /> + <ClInclude Include="SDL\src\video\SDL_blit.h" /> + <ClInclude Include="SDL\src\video\SDL_egl_c.h" /> + <ClInclude Include="SDL\src\video\SDL_pixels_c.h" /> + <ClInclude Include="SDL\src\video\SDL_rect_c.h" /> + <ClInclude Include="SDL\src\video\SDL_RLEaccel_c.h" /> + <ClInclude Include="SDL\src\video\SDL_shape_internals.h" /> + <ClInclude Include="SDL\src\video\SDL_sysvideo.h" /> + <ClInclude Include="SDL\src\video\SDL_vulkan_internal.h" /> + <ClInclude Include="SDL\src\video\SDL_yuv_c.h" /> + <ClInclude Include="SDL\src\video\windows\SDL_msctf.h" /> + <ClInclude Include="SDL\src\video\windows\SDL_vkeys.h" /> + <ClInclude Include="SDL\src\video\windows\SDL_windowsclipboard.h" /> + <ClInclude Include="SDL\src\video\windows\SDL_windowsevents.h" /> + <ClInclude Include="SDL\src\video\windows\SDL_windowsframebuffer.h" /> + <ClInclude Include="SDL\src\video\windows\SDL_windowskeyboard.h" /> + <ClInclude Include="SDL\src\video\windows\SDL_windowsmessagebox.h" /> + <ClInclude Include="SDL\src\video\windows\SDL_windowsmodes.h" /> + <ClInclude Include="SDL\src\video\windows\SDL_windowsmouse.h" /> + <ClInclude Include="SDL\src\video\windows\SDL_windowsopengl.h" /> + <ClInclude Include="SDL\src\video\windows\SDL_windowsopengles.h" /> + <ClInclude Include="SDL\src\video\windows\SDL_windowsshape.h" /> + <ClInclude Include="SDL\src\video\windows\SDL_windowstaskdialog.h" /> + <ClInclude Include="SDL\src\video\windows\SDL_windowsvideo.h" /> + <ClInclude Include="SDL\src\video\windows\SDL_windowsvulkan.h" /> + <ClInclude Include="SDL\src\video\windows\SDL_windowswindow.h" /> + <ClInclude Include="SDL\src\video\windows\wmmsg.h" /> + <ClInclude Include="SDL\src\video\yuv2rgb\yuv_rgb_sse_func.h" /> + <ClInclude Include="SDL\src\video\yuv2rgb\yuv_rgb_std_func.h" /> + <ClInclude Include="SDL\src\video\yuv2rgb\yuv_rgb.h" /> + </ItemGroup> + <ItemGroup> + <ClCompile Include="SDL\src\atomic\SDL_atomic.c" /> + <ClCompile Include="SDL\src\atomic\SDL_spinlock.c" /> + <ClCompile Include="SDL\src\audio\directsound\SDL_directsound.c" /> + <ClCompile Include="SDL\src\audio\disk\SDL_diskaudio.c" /> + <ClCompile Include="SDL\src\audio\dummy\SDL_dummyaudio.c" /> + <ClCompile Include="SDL\src\audio\SDL_audio.c" /> + <ClCompile Include="SDL\src\audio\SDL_audiocvt.c" /> + <ClCompile Include="SDL\src\audio\SDL_audiodev.c" /> + <ClCompile Include="SDL\src\audio\SDL_audiotypecvt.c" /> + <ClCompile Include="SDL\src\audio\SDL_mixer.c" /> + <ClCompile Include="SDL\src\audio\SDL_wave.c" /> + <ClCompile Include="SDL\src\audio\wasapi\SDL_wasapi_win32.c" /> + <ClCompile Include="SDL\src\audio\wasapi\SDL_wasapi.c" /> + <ClCompile Include="SDL\src\audio\winmm\SDL_winmm.c" /> + <ClCompile Include="SDL\src\core\windows\SDL_hid.c" /> + <ClCompile Include="SDL\src\core\windows\SDL_windows.c" /> + <ClCompile Include="SDL\src\core\windows\SDL_xinput.c" /> + <ClCompile Include="SDL\src\cpuinfo\SDL_cpuinfo.c" /> + <ClCompile Include="SDL\src\dynapi\SDL_dynapi.c" /> + <ClCompile Include="SDL\src\events\SDL_clipboardevents.c" /> + <ClCompile Include="SDL\src\events\SDL_displayevents.c" /> + <ClCompile Include="SDL\src\events\SDL_dropevents.c" /> + <ClCompile Include="SDL\src\events\SDL_events.c" /> + <ClCompile Include="SDL\src\events\SDL_gesture.c" /> + <ClCompile Include="SDL\src\events\SDL_keyboard.c" /> + <ClCompile Include="SDL\src\events\SDL_mouse.c" /> + <ClCompile Include="SDL\src\events\SDL_quit.c" /> + <ClCompile Include="SDL\src\events\SDL_touch.c" /> + <ClCompile Include="SDL\src\events\SDL_windowevents.c" /> + <ClCompile Include="SDL\src\file\SDL_rwops.c" /> + <ClCompile Include="SDL\src\filesystem\windows\SDL_sysfilesystem.c" /> + <ClCompile Include="SDL\src\haptic\dummy\SDL_syshaptic.c" /> + <ClCompile Include="SDL\src\haptic\SDL_haptic.c" /> + <ClCompile Include="SDL\src\haptic\windows\SDL_dinputhaptic.c" /> + <ClCompile Include="SDL\src\haptic\windows\SDL_windowshaptic.c" /> + <ClCompile Include="SDL\src\haptic\windows\SDL_xinputhaptic.c" /> + <ClCompile Include="SDL\src\hidapi\SDL_hidapi.c" /> + <ClCompile Include="SDL\src\joystick\controller_type.c" /> + <ClCompile Include="SDL\src\joystick\dummy\SDL_sysjoystick.c" /> + <ClCompile Include="SDL\src\joystick\hidapi\SDL_hidapi_gamecube.c" /> + <ClCompile Include="SDL\src\joystick\hidapi\SDL_hidapi_luna.c" /> + <ClCompile Include="SDL\src\joystick\hidapi\SDL_hidapi_ps4.c" /> + <ClCompile Include="SDL\src\joystick\hidapi\SDL_hidapi_ps5.c" /> + <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_switch.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" /> + <ClCompile Include="SDL\src\joystick\hidapi\SDL_hidapijoystick.c" /> + <ClCompile Include="SDL\src\joystick\SDL_gamecontroller.c" /> + <ClCompile Include="SDL\src\joystick\SDL_joystick.c" /> + <ClCompile Include="SDL\src\joystick\virtual\SDL_virtualjoystick.c" /> + <ClCompile Include="SDL\src\joystick\windows\SDL_dinputjoystick.c" /> + <ClCompile Include="SDL\src\joystick\windows\SDL_rawinputjoystick.c" /> + <ClCompile Include="SDL\src\joystick\windows\SDL_windows_gaming_input.c" /> + <ClCompile Include="SDL\src\joystick\windows\SDL_windowsjoystick.c" /> + <ClCompile Include="SDL\src\joystick\windows\SDL_xinputjoystick.c" /> + <ClCompile Include="SDL\src\loadso\windows\SDL_sysloadso.c" /> + <ClCompile Include="SDL\src\locale\SDL_locale.c" /> + <ClCompile Include="SDL\src\locale\windows\SDL_syslocale.c" /> + <ClCompile Include="SDL\src\misc\SDL_url.c" /> + <ClCompile Include="SDL\src\misc\windows\SDL_sysurl.c" /> + <ClCompile Include="SDL\src\power\SDL_power.c" /> + <ClCompile Include="SDL\src\power\windows\SDL_syspower.c" /> + <ClCompile Include="SDL\src\render\direct3d\SDL_render_d3d.c" /> + <ClCompile Include="SDL\src\render\direct3d\SDL_shaders_d3d.c" /> + <ClCompile Include="SDL\src\render\direct3d11\SDL_render_d3d11.c" /> + <ClCompile Include="SDL\src\render\direct3d11\SDL_shaders_d3d11.c" /> + <ClCompile Include="SDL\src\render\direct3d12\SDL_render_d3d12.c" /> + <ClCompile Include="SDL\src\render\direct3d12\SDL_shaders_d3d12.c" /> + <ClCompile Include="SDL\src\render\opengl\SDL_render_gl.c" /> + <ClCompile Include="SDL\src\render\opengl\SDL_shaders_gl.c" /> + <ClCompile Include="SDL\src\render\opengles2\SDL_render_gles2.c" /> + <ClCompile Include="SDL\src\render\opengles2\SDL_shaders_gles2.c" /> + <ClCompile Include="SDL\src\render\SDL_d3dmath.c" /> + <ClCompile Include="SDL\src\render\SDL_render.c" /> + <ClCompile Include="SDL\src\render\SDL_yuv_sw.c" /> + <ClCompile Include="SDL\src\render\software\SDL_blendfillrect.c" /> + <ClCompile Include="SDL\src\render\software\SDL_blendline.c" /> + <ClCompile Include="SDL\src\render\software\SDL_blendpoint.c" /> + <ClCompile Include="SDL\src\render\software\SDL_drawline.c" /> + <ClCompile Include="SDL\src\render\software\SDL_drawpoint.c" /> + <ClCompile Include="SDL\src\render\software\SDL_render_sw.c" /> + <ClCompile Include="SDL\src\render\software\SDL_rotate.c" /> + <ClCompile Include="SDL\src\render\software\SDL_triangle.c" /> + <ClCompile Include="SDL\src\SDL_assert.c" /> + <ClCompile Include="SDL\src\SDL_dataqueue.c" /> + <ClCompile Include="SDL\src\SDL_error.c" /> + <ClCompile Include="SDL\src\SDL_guid.c" /> + <ClCompile Include="SDL\src\SDL_hints.c" /> + <ClCompile Include="SDL\src\SDL_list.c" /> + <ClCompile Include="SDL\src\SDL_log.c" /> + <ClCompile Include="SDL\src\SDL.c" /> + <ClCompile Include="SDL\src\sensor\dummy\SDL_dummysensor.c" /> + <ClCompile Include="SDL\src\sensor\SDL_sensor.c" /> + <ClCompile Include="SDL\src\sensor\windows\SDL_windowssensor.c" /> + <ClCompile Include="SDL\src\stdlib\SDL_crc32.c" /> + <ClCompile Include="SDL\src\stdlib\SDL_getenv.c" /> + <ClCompile Include="SDL\src\stdlib\SDL_iconv.c" /> + <ClCompile Include="SDL\src\stdlib\SDL_malloc.c" /> + <ClCompile Include="SDL\src\stdlib\SDL_memcpy.c" /> + <ClCompile Include="SDL\src\stdlib\SDL_memset.c" /> + <ClCompile Include="SDL\src\stdlib\SDL_qsort.c" /> + <ClCompile Include="SDL\src\stdlib\SDL_stdlib.c" /> + <ClCompile Include="SDL\src\stdlib\SDL_string.c" /> + <ClCompile Include="SDL\src\stdlib\SDL_strtokr.c" /> + <ClCompile Include="SDL\src\thread\generic\SDL_syscond.c" /> + <ClCompile Include="SDL\src\thread\SDL_thread.c" /> + <ClCompile Include="SDL\src\thread\windows\SDL_syscond_cv.c" /> + <ClCompile Include="SDL\src\thread\windows\SDL_sysmutex.c" /> + <ClCompile Include="SDL\src\thread\windows\SDL_syssem.c" /> + <ClCompile Include="SDL\src\thread\windows\SDL_systhread.c" /> + <ClCompile Include="SDL\src\thread\windows\SDL_systls.c" /> + <ClCompile Include="SDL\src\timer\SDL_timer.c" /> + <ClCompile Include="SDL\src\timer\windows\SDL_systimer.c" /> + <ClCompile Include="SDL\src\video\dummy\SDL_nullevents.c" /> + <ClCompile Include="SDL\src\video\dummy\SDL_nullframebuffer.c" /> + <ClCompile Include="SDL\src\video\dummy\SDL_nullvideo.c" /> + <ClCompile Include="SDL\src\video\SDL_blit_0.c" /> + <ClCompile Include="SDL\src\video\SDL_blit_1.c" /> + <ClCompile Include="SDL\src\video\SDL_blit_A.c" /> + <ClCompile Include="SDL\src\video\SDL_blit_auto.c" /> + <ClCompile Include="SDL\src\video\SDL_blit_copy.c" /> + <ClCompile Include="SDL\src\video\SDL_blit_N.c" /> + <ClCompile Include="SDL\src\video\SDL_blit_slow.c" /> + <ClCompile Include="SDL\src\video\SDL_blit.c" /> + <ClCompile Include="SDL\src\video\SDL_bmp.c" /> + <ClCompile Include="SDL\src\video\SDL_clipboard.c" /> + <ClCompile Include="SDL\src\video\SDL_egl.c" /> + <ClCompile Include="SDL\src\video\SDL_fillrect.c" /> + <ClCompile Include="SDL\src\video\SDL_pixels.c" /> + <ClCompile Include="SDL\src\video\SDL_rect.c" /> + <ClCompile Include="SDL\src\video\SDL_RLEaccel.c" /> + <ClCompile Include="SDL\src\video\SDL_shape.c" /> + <ClCompile Include="SDL\src\video\SDL_stretch.c" /> + <ClCompile Include="SDL\src\video\SDL_surface.c" /> + <ClCompile Include="SDL\src\video\SDL_video.c" /> + <ClCompile Include="SDL\src\video\SDL_vulkan_utils.c" /> + <ClCompile Include="SDL\src\video\SDL_yuv.c" /> + <ClCompile Include="SDL\src\video\windows\SDL_windowsclipboard.c" /> + <ClCompile Include="SDL\src\video\windows\SDL_windowsevents.c" /> + <ClCompile Include="SDL\src\video\windows\SDL_windowsframebuffer.c" /> + <ClCompile Include="SDL\src\video\windows\SDL_windowskeyboard.c" /> + <ClCompile Include="SDL\src\video\windows\SDL_windowsmessagebox.c" /> + <ClCompile Include="SDL\src\video\windows\SDL_windowsmodes.c" /> + <ClCompile Include="SDL\src\video\windows\SDL_windowsmouse.c" /> + <ClCompile Include="SDL\src\video\windows\SDL_windowsopengl.c" /> + <ClCompile Include="SDL\src\video\windows\SDL_windowsopengles.c" /> + <ClCompile Include="SDL\src\video\windows\SDL_windowsshape.c" /> + <ClCompile Include="SDL\src\video\windows\SDL_windowsvideo.c" /> + <ClCompile Include="SDL\src\video\windows\SDL_windowsvulkan.c" /> + <ClCompile Include="SDL\src\video\windows\SDL_windowswindow.c" /> + <ClCompile Include="SDL\src\video\yuv2rgb\yuv_rgb.c" /> + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + </ImportGroup> +</Project>
\ No newline at end of file diff --git a/Source/Core/DolphinLib.props b/Source/Core/DolphinLib.props index 8cb5919edf..2e7e546c78 100644 --- a/Source/Core/DolphinLib.props +++ b/Source/Core/DolphinLib.props @@ -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" /> @@ -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" /> diff --git a/Source/Core/InputCommon/CMakeLists.txt b/Source/Core/InputCommon/CMakeLists.txt index 06f959a91a..9cca78b65d 100644 --- a/Source/Core/InputCommon/CMakeLists.txt +++ b/Source/Core/InputCommon/CMakeLists.txt @@ -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) diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h index 7a5ee0ad26..2f43cacc42 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h @@ -30,6 +30,9 @@ #define CIFACE_USE_PIPES #endif #define CIFACE_USE_DUALSHOCKUDPCLIENT +#if defined(HAVE_SDL2) +#define CIFACE_USE_SDL +#endif namespace ciface { diff --git a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp index a2e6893801..6dec6003fd 100644 --- a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp +++ b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp @@ -15,6 +15,8 @@ #include "InputCommon/ControllerInterface/ControllerInterface.h" #ifdef _WIN32 +#include <Windows.h> + #pragma comment(lib, "SDL2.lib") #endif @@ -56,8 +58,9 @@ static bool HandleEventAndContinue(const SDL_Event& e) else if (e.type == SDL_JOYDEVICEREMOVED) { g_controller_interface.RemoveDevice([&e](const auto* device) { - const Joystick* joystick = dynamic_cast<const Joystick*>(device); - return joystick && SDL_JoystickInstanceID(joystick->GetSDLJoystick()) == e.jdevice.which; + return device->GetSource() == "SDL" && + SDL_JoystickInstanceID(static_cast<const Joystick*>(device)->GetSDLJoystick()) == + e.jdevice.which; }); } else if (e.type == s_populate_event_type) @@ -76,10 +79,77 @@ static bool HandleEventAndContinue(const SDL_Event& e) } #endif +static void EnableSDLLogging() +{ + SDL_LogSetAllPriority(SDL_LOG_PRIORITY_VERBOSE); + SDL_LogSetOutputFunction( + [](void*, int category, SDL_LogPriority priority, const char* message) { + std::string category_name; + switch (category) + { + case SDL_LOG_CATEGORY_APPLICATION: + category_name = "app"; + break; + case SDL_LOG_CATEGORY_ERROR: + category_name = "error"; + break; + case SDL_LOG_CATEGORY_ASSERT: + category_name = "assert"; + break; + case SDL_LOG_CATEGORY_SYSTEM: + category_name = "system"; + break; + case SDL_LOG_CATEGORY_AUDIO: + category_name = "audio"; + break; + case SDL_LOG_CATEGORY_VIDEO: + category_name = "video"; + break; + case SDL_LOG_CATEGORY_RENDER: + category_name = "render"; + break; + case SDL_LOG_CATEGORY_INPUT: + category_name = "input"; + break; + case SDL_LOG_CATEGORY_TEST: + category_name = "test"; + break; + default: + category_name = fmt::format("unknown({})", category); + break; + } + + auto log_level = Common::Log::LogLevel::LNOTICE; + switch (priority) + { + case SDL_LOG_PRIORITY_VERBOSE: + case SDL_LOG_PRIORITY_DEBUG: + log_level = Common::Log::LogLevel::LDEBUG; + break; + case SDL_LOG_PRIORITY_INFO: + log_level = Common::Log::LogLevel::LINFO; + break; + case SDL_LOG_PRIORITY_WARN: + log_level = Common::Log::LogLevel::LWARNING; + break; + case SDL_LOG_PRIORITY_ERROR: + log_level = Common::Log::LogLevel::LERROR; + break; + case SDL_LOG_PRIORITY_CRITICAL: + log_level = Common::Log::LogLevel::LNOTICE; + break; + } + + GENERIC_LOG_FMT(Common::Log::LogType::CONTROLLERINTERFACE, log_level, "{}: {}", + category_name, message); + }, + nullptr); +} + void Init() { #if !SDL_VERSION_ATLEAST(2, 0, 0) - if (SDL_Init(SDL_INIT_JOYSTICK) != 0) + if (SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC) != 0) ERROR_LOG_FMT(CONTROLLERINTERFACE, "SDL failed to initialize"); return; #else @@ -88,16 +158,27 @@ void Init() SDL_InitSubSystem(SDL_INIT_JOYSTICK); SDL_QuitSubSystem(SDL_INIT_JOYSTICK); #endif + + EnableSDLLogging(); + +#if SDL_VERSION_ATLEAST(2, 0, 14) + // This is required on windows so that SDL's joystick code properly pumps window messages + SDL_SetHint(SDL_HINT_JOYSTICK_THREAD, "1"); +#endif + +#if SDL_VERSION_ATLEAST(2, 0, 9) + SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE, "1"); +#endif + s_hotplug_thread = std::thread([] { Common::ScopeGuard quit_guard([] { // TODO: there seems to be some sort of memory leak with SDL, quit isn't freeing everything up SDL_Quit(); }); - { Common::ScopeGuard init_guard([] { s_init_event.Set(); }); - if (SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC) != 0) + if (SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER) != 0) { ERROR_LOG_FMT(CONTROLLERINTERFACE, "SDL failed to initialize"); return; @@ -125,11 +206,34 @@ void Init() } } +#ifdef _WIN32 + // This is a hack to workaround SDL_hidapi using window messages to detect device + // removal/arrival, yet no part of SDL pumps messages for it. It can hopefully be removed in the + // future when SDL fixes the issue. Note this is a separate issue from SDL_HINT_JOYSTICK_THREAD. + // Also note that SDL_WaitEvent may block while device detection window messages get queued up, + // causing some noticible stutter. This is just another reason it should be fixed properly by + // SDL... + const auto window_handle = + FindWindowEx(HWND_MESSAGE, nullptr, TEXT("SDL_HIDAPI_DEVICE_DETECTION"), nullptr); +#endif + SDL_Event e; while (SDL_WaitEvent(&e) != 0) { if (!HandleEventAndContinue(e)) return; + +#ifdef _WIN32 + MSG msg; + while (window_handle && PeekMessage(&msg, window_handle, 0, 0, PM_NOREMOVE)) + { + if (GetMessageA(&msg, window_handle, 0, 0) != 0) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } +#endif } }); @@ -172,10 +276,13 @@ void PopulateDevices() Joystick::Joystick(SDL_Joystick* const joystick, const int sdl_index) : m_joystick(joystick), m_name(StripSpaces(GetJoystickName(sdl_index))) { -// really bad HACKS: -// to not use SDL for an XInput device -// too many people on the forums pick the SDL device and ask: -// "why don't my 360 gamepad triggers/rumble work correctly" + // really bad HACKS: + // to not use SDL for an XInput device + // too many people on the forums pick the SDL device and ask: + // "why don't my 360 gamepad triggers/rumble work correctly" + // XXX x360 controllers _should_ work on modern SDL2, so it's unclear why they're + // still broken. Perhaps it's because we're not pumping window messages, which SDL seems to + // expect. #ifdef _WIN32 // checking the name is probably good (and hacky) enough // but I'll double check with the num of buttons/axes @@ -183,7 +290,7 @@ Joystick::Joystick(SDL_Joystick* const joystick, const int sdl_index) Common::ToLower(&lcasename); if ((std::string::npos != lcasename.find("xbox 360")) && - (10 == SDL_JoystickNumButtons(joystick)) && (5 == SDL_JoystickNumAxes(joystick)) && + (11 == SDL_JoystickNumButtons(joystick)) && (6 == SDL_JoystickNumAxes(joystick)) && (1 == SDL_JoystickNumHats(joystick)) && (0 == SDL_JoystickNumBalls(joystick))) { // this device won't be used @@ -220,53 +327,110 @@ Joystick::Joystick(SDL_Joystick* const joystick, const int sdl_index) } #ifdef USE_SDL_HAPTIC - m_haptic = SDL_HapticOpenFromJoystick(m_joystick); - if (!m_haptic) - return; + if (SDL_JoystickIsHaptic(m_joystick)) + { + m_haptic = SDL_HapticOpenFromJoystick(m_joystick); + if (m_haptic) + { + const unsigned int supported_effects = SDL_HapticQuery(m_haptic); - const unsigned int supported_effects = SDL_HapticQuery(m_haptic); + // Disable autocenter: + if (supported_effects & SDL_HAPTIC_AUTOCENTER) + SDL_HapticSetAutocenter(m_haptic, 0); - // Disable autocenter: - if (supported_effects & SDL_HAPTIC_AUTOCENTER) - SDL_HapticSetAutocenter(m_haptic, 0); + // Constant + if (supported_effects & SDL_HAPTIC_CONSTANT) + AddOutput(new ConstantEffect(m_haptic)); - // Constant - if (supported_effects & SDL_HAPTIC_CONSTANT) - AddOutput(new ConstantEffect(m_haptic)); + // Ramp + if (supported_effects & SDL_HAPTIC_RAMP) + AddOutput(new RampEffect(m_haptic)); - // Ramp - if (supported_effects & SDL_HAPTIC_RAMP) - AddOutput(new RampEffect(m_haptic)); + // Periodic + for (auto waveform : + {SDL_HAPTIC_SINE, SDL_HAPTIC_TRIANGLE, SDL_HAPTIC_SAWTOOTHUP, SDL_HAPTIC_SAWTOOTHDOWN}) + { + if (supported_effects & waveform) + AddOutput(new PeriodicEffect(m_haptic, waveform)); + } - // Periodic - for (auto waveform : - {SDL_HAPTIC_SINE, SDL_HAPTIC_TRIANGLE, SDL_HAPTIC_SAWTOOTHUP, SDL_HAPTIC_SAWTOOTHDOWN}) + // LeftRight + if (supported_effects & SDL_HAPTIC_LEFTRIGHT) + { + AddOutput(new LeftRightEffect(m_haptic, LeftRightEffect::Motor::Strong)); + AddOutput(new LeftRightEffect(m_haptic, LeftRightEffect::Motor::Weak)); + } + } + } +#endif + +#if SDL_VERSION_ATLEAST(2, 0, 9) + if (!m_haptic) { - if (supported_effects & waveform) - AddOutput(new PeriodicEffect(m_haptic, waveform)); + AddOutput(new Motor(m_joystick)); } +#endif - // LeftRight - if (supported_effects & SDL_HAPTIC_LEFTRIGHT) +#ifdef USE_SDL_GAMECONTROLLER + if (SDL_IsGameController(sdl_index)) { - AddOutput(new LeftRightEffect(m_haptic, LeftRightEffect::Motor::Strong)); - AddOutput(new LeftRightEffect(m_haptic, LeftRightEffect::Motor::Weak)); + 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)); + } + } } #endif } Joystick::~Joystick() { +#ifdef USE_SDL_GAMECONTROLLER + if (m_controller) + { + SDL_GameControllerClose(m_controller); + m_controller = nullptr; + } +#endif + #ifdef USE_SDL_HAPTIC if (m_haptic) { // stop/destroy all effects SDL_HapticStopAll(m_haptic); - // close haptic first + // close haptic before joystick SDL_HapticClose(m_haptic); + m_haptic = nullptr; } #endif +#if SDL_VERSION_ATLEAST(2, 0, 9) + // stop all rumble + SDL_JoystickRumble(m_joystick, 0, 0, 0); +#endif + // close joystick SDL_JoystickClose(m_joystick); } @@ -442,6 +606,19 @@ bool Joystick::LeftRightEffect::UpdateParameters(s16 value) } #endif +#if SDL_VERSION_ATLEAST(2, 0, 9) +std::string Joystick::Motor::GetName() const +{ + return "Motor"; +} + +void Joystick::Motor::SetState(ControlState state) +{ + Uint16 rumble = state * std::numeric_limits<Uint16>::max(); + SDL_JoystickRumble(m_js, rumble, rumble, std::numeric_limits<Uint32>::max()); +} +#endif + void Joystick::UpdateInput() { // TODO: Don't call this for every Joystick, only once per ControllerInterface::UpdateInput() @@ -492,4 +669,14 @@ ControlState Joystick::Hat::GetState() const { return (SDL_JoystickGetHat(m_js, m_index) & (1 << m_direction)) > 0; } +#ifdef USE_SDL_GAMECONTROLLER + +ControlState Joystick::MotionInput::GetState() const +{ + std::array<float, 3> data{}; + SDL_GameControllerGetSensorData(m_gc, m_type, data.data(), (int)data.size()); + return m_scale * data[m_index]; +} + +#endif } // namespace ciface::SDL diff --git a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.h b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.h index 7fbf7cf23e..f789c8846a 100644 --- a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.h +++ b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.h @@ -9,10 +9,18 @@ #define USE_SDL_HAPTIC #endif +#if SDL_VERSION_ATLEAST(2, 0, 14) +#define USE_SDL_GAMECONTROLLER +#endif + #ifdef USE_SDL_HAPTIC #include <SDL_haptic.h> #endif +#ifdef USE_SDL_GAMECONTROLLER +#include <SDL_gamecontroller.h> +#endif + #include "InputCommon/ControllerInterface/CoreDevice.h" namespace ciface::SDL @@ -137,6 +145,42 @@ private: }; #endif +#if SDL_VERSION_ATLEAST(2, 0, 9) + class Motor : public Output + { + public: + explicit Motor(SDL_Joystick* js) : m_js(js){}; + std::string GetName() const override; + void SetState(ControlState state) override; + + private: + SDL_Joystick* const m_js; + }; +#endif + +#ifdef USE_SDL_GAMECONTROLLER + class MotionInput : public Input + { + public: + MotionInput(const char* 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){}; + + std::string GetName() const override { return m_name; }; + bool IsDetectable() const override { return false; }; + ControlState GetState() const override; + + private: + const char* m_name; + + SDL_GameController* const m_gc; + SDL_SensorType const m_type; + int const m_index; + + ControlState const m_scale; + }; +#endif + public: void UpdateInput() override; @@ -152,7 +196,11 @@ private: std::string m_name; #ifdef USE_SDL_HAPTIC - SDL_Haptic* m_haptic; + SDL_Haptic* m_haptic = nullptr; +#endif + +#ifdef USE_SDL_GAMECONTROLLER + SDL_GameController* m_controller = nullptr; #endif }; } // namespace ciface::SDL diff --git a/Source/Core/InputCommon/ControllerInterface/Win32/Win32.cpp b/Source/Core/InputCommon/ControllerInterface/Win32/Win32.cpp index a9c28efdc0..42aa12a141 100644 --- a/Source/Core/InputCommon/ControllerInterface/Win32/Win32.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Win32/Win32.cpp @@ -73,11 +73,13 @@ void ciface::Win32::Init(void* hwnd) } Common::ScopeGuard uninit([] { CoUninitialize(); }); + const auto window_name = TEXT("DolphinWin32ControllerInterface"); + WNDCLASSEX window_class_info{}; window_class_info.cbSize = sizeof(window_class_info); window_class_info.lpfnWndProc = WindowProc; window_class_info.hInstance = GetModuleHandle(nullptr); - window_class_info.lpszClassName = L"Message"; + window_class_info.lpszClassName = window_name; ATOM window_class = RegisterClassEx(&window_class_info); if (!window_class) @@ -92,7 +94,7 @@ void ciface::Win32::Init(void* hwnd) Common::HRWrap(GetLastError())); }); - message_window = CreateWindowEx(0, L"Message", nullptr, 0, 0, 0, 0, 0, HWND_MESSAGE, nullptr, + message_window = CreateWindowEx(0, window_name, nullptr, 0, 0, 0, 0, 0, HWND_MESSAGE, nullptr, nullptr, nullptr); promise_guard.Exit(); if (!message_window) diff --git a/Source/VSProps/Base.props b/Source/VSProps/Base.props index 49f546d39f..ae821339cc 100644 --- a/Source/VSProps/Base.props +++ b/Source/VSProps/Base.props @@ -52,6 +52,7 @@ <AdditionalIncludeDirectories>$(ExternalsDir)picojson;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(ExternalsDir)pugixml;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(ExternalsDir)rangeset\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories>$(ExternalsDir)SDL\SDL\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(ExternalsDir)SFML\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(ExternalsDir)soundtouch;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(ExternalsDir)Vulkan\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> @@ -91,6 +92,7 @@ <PreprocessorDefinitions>HAS_LIBMGBA;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>AUTOUPDATE=1;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PreprocessorDefinitions>HAVE_SDL2=1;%(PreprocessorDefinitions)</PreprocessorDefinitions> <!-- Make sure we include a clean version of windows.h. --> diff --git a/Source/dolphin-emu.sln b/Source/dolphin-emu.sln index 89df520d9b..b289f27548 100644 --- a/Source/dolphin-emu.sln +++ b/Source/dolphin-emu.sln @@ -81,6 +81,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fmt", "..\Externals\fmt\fmt EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "spirv_cross", "..\Externals\spirv_cross\spirv_cross.vcxproj", "{3d780617-ec8c-4721-b9fd-dfc9bb658c7c}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SDL2", "..\Externals\SDL\SDL2.vcxproj", "{8DC244EE-A0BD-4038-BAF7-CFAFA5EB2BAA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|ARM64 = Debug|ARM64 @@ -389,6 +391,14 @@ Global {3D780617-EC8C-4721-B9FD-DFC9BB658C7C}.Release|ARM64.Build.0 = Release|ARM64 {3D780617-EC8C-4721-B9FD-DFC9BB658C7C}.Release|x64.ActiveCfg = Release|x64 {3D780617-EC8C-4721-B9FD-DFC9BB658C7C}.Release|x64.Build.0 = Release|x64 + {8DC244EE-A0BD-4038-BAF7-CFAFA5EB2BAA}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {8DC244EE-A0BD-4038-BAF7-CFAFA5EB2BAA}.Debug|ARM64.Build.0 = Debug|ARM64 + {8DC244EE-A0BD-4038-BAF7-CFAFA5EB2BAA}.Debug|x64.ActiveCfg = Debug|x64 + {8DC244EE-A0BD-4038-BAF7-CFAFA5EB2BAA}.Debug|x64.Build.0 = Debug|x64 + {8DC244EE-A0BD-4038-BAF7-CFAFA5EB2BAA}.Release|ARM64.ActiveCfg = Release|ARM64 + {8DC244EE-A0BD-4038-BAF7-CFAFA5EB2BAA}.Release|ARM64.Build.0 = Release|ARM64 + {8DC244EE-A0BD-4038-BAF7-CFAFA5EB2BAA}.Release|x64.ActiveCfg = Release|x64 + {8DC244EE-A0BD-4038-BAF7-CFAFA5EB2BAA}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -422,6 +432,7 @@ Global {864C4C8E-296D-3DBC-AD83-F1D5CB6E8EC6} = {87ADDFF9-5768-4DA2-A33B-2477593D6677} {4BC5A148-0AB3-440F-A980-A29B4B999190} = {87ADDFF9-5768-4DA2-A33B-2477593D6677} {3D780617-EC8C-4721-B9FD-DFC9BB658C7C} = {87ADDFF9-5768-4DA2-A33B-2477593D6677} + {8DC244EE-A0BD-4038-BAF7-CFAFA5EB2BAA} = {87ADDFF9-5768-4DA2-A33B-2477593D6677} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {64B0A343-3B94-4522-9C24-6937FE5EFB22} |
