diff options
| -rw-r--r-- | .ci/templates/build-msvc.yml | 2 | ||||
| -rw-r--r-- | CMakeLists.txt | 76 | ||||
| -rw-r--r-- | src/input_common/sdl/sdl_impl.cpp | 26 | ||||
| -rw-r--r-- | src/input_common/sdl/sdl_impl.h | 4 |
4 files changed, 61 insertions, 47 deletions
diff --git a/.ci/templates/build-msvc.yml b/.ci/templates/build-msvc.yml index 097367018..74e688c12 100644 --- a/.ci/templates/build-msvc.yml +++ b/.ci/templates/build-msvc.yml | |||
| @@ -8,7 +8,7 @@ steps: | |||
| 8 | displayName: 'Install vulkan-sdk' | 8 | displayName: 'Install vulkan-sdk' |
| 9 | - script: python -m pip install --upgrade pip conan | 9 | - script: python -m pip install --upgrade pip conan |
| 10 | displayName: 'Install conan' | 10 | displayName: 'Install conan' |
| 11 | - script: refreshenv && mkdir build && cd build && cmake -G "Visual Studio 16 2019" -A x64 -DYUZU_USE_BUNDLED_QT=1 -DYUZU_USE_QT_WEB_ENGINE=ON -DENABLE_COMPATIBILITY_LIST_DOWNLOAD=ON -DYUZU_ENABLE_COMPATIBILITY_REPORTING=${COMPAT} -DUSE_DISCORD_PRESENCE=ON -DENABLE_QT_TRANSLATION=ON -DDISPLAY_VERSION=${{ parameters['version'] }} .. && cmake --install . --config Release && cd .. | 11 | - script: refreshenv && mkdir build && cd build && cmake -G "Visual Studio 16 2019" -A x64 -DYUZU_USE_BUNDLED_QT=1 -DYUZU_USE_BUNDLED_SDL2=1 -DYUZU_USE_QT_WEB_ENGINE=ON -DENABLE_COMPATIBILITY_LIST_DOWNLOAD=ON -DYUZU_ENABLE_COMPATIBILITY_REPORTING=${COMPAT} -DUSE_DISCORD_PRESENCE=ON -DENABLE_QT_TRANSLATION=ON -DDISPLAY_VERSION=${{ parameters['version'] }} .. && cmake --install . --config Release && cd .. |
| 12 | displayName: 'Configure CMake' | 12 | displayName: 'Configure CMake' |
| 13 | - task: MSBuild@1 | 13 | - task: MSBuild@1 |
| 14 | displayName: 'Build' | 14 | displayName: 'Build' |
diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ea6c650e..a4a6da2e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
| @@ -11,6 +11,7 @@ project(yuzu) | |||
| 11 | # Set bundled sdl2/qt as dependent options. | 11 | # Set bundled sdl2/qt as dependent options. |
| 12 | # OFF by default, but if ENABLE_SDL2 and MSVC are true then ON | 12 | # OFF by default, but if ENABLE_SDL2 and MSVC are true then ON |
| 13 | option(ENABLE_SDL2 "Enable the SDL2 frontend" ON) | 13 | option(ENABLE_SDL2 "Enable the SDL2 frontend" ON) |
| 14 | CMAKE_DEPENDENT_OPTION(YUZU_USE_BUNDLED_SDL2 "Download bundled SDL2 binaries" ON "ENABLE_SDL2;MSVC" OFF) | ||
| 14 | 15 | ||
| 15 | option(ENABLE_QT "Enable the Qt frontend" ON) | 16 | option(ENABLE_QT "Enable the Qt frontend" ON) |
| 16 | option(ENABLE_QT_TRANSLATION "Enable translations for the Qt frontend" OFF) | 17 | option(ENABLE_QT_TRANSLATION "Enable translations for the Qt frontend" OFF) |
| @@ -166,8 +167,6 @@ macro(yuzu_find_packages) | |||
| 166 | # Cmake Pkg Prefix Version Conan Pkg | 167 | # Cmake Pkg Prefix Version Conan Pkg |
| 167 | "Catch2 2.13 catch2/2.13.0" | 168 | "Catch2 2.13 catch2/2.13.0" |
| 168 | "fmt 7.1 fmt/7.1.2" | 169 | "fmt 7.1 fmt/7.1.2" |
| 169 | # can't use until https://github.com/bincrafters/community/issues/1173 | ||
| 170 | #"libzip 1.5 libzip/1.5.2@bincrafters/stable" | ||
| 171 | "lz4 1.8 lz4/1.9.2" | 170 | "lz4 1.8 lz4/1.9.2" |
| 172 | "nlohmann_json 3.8 nlohmann_json/3.8.0" | 171 | "nlohmann_json 3.8 nlohmann_json/3.8.0" |
| 173 | "ZLIB 1.2 zlib/1.2.11" | 172 | "ZLIB 1.2 zlib/1.2.11" |
| @@ -251,22 +250,44 @@ if(ENABLE_QT) | |||
| 251 | if (ENABLE_QT_TRANSLATION) | 250 | if (ENABLE_QT_TRANSLATION) |
| 252 | find_package(Qt5 REQUIRED COMPONENTS LinguistTools ${QT_PREFIX_HINT}) | 251 | find_package(Qt5 REQUIRED COMPONENTS LinguistTools ${QT_PREFIX_HINT}) |
| 253 | endif() | 252 | endif() |
| 254 | if (NOT Qt5_FOUND) | ||
| 255 | list(APPEND CONAN_REQUIRED_LIBS "qt/5.14.1@bincrafters/stable") | ||
| 256 | endif() | ||
| 257 | endif() | 253 | endif() |
| 258 | # find SDL2 exports a bunch of variables that are needed, so its easier to do this outside of the yuzu_find_package | 254 | # find SDL2 exports a bunch of variables that are needed, so its easier to do this outside of the yuzu_find_package |
| 259 | if(ENABLE_SDL2) | 255 | if (ENABLE_SDL2) |
| 260 | if(EXISTS ${CMAKE_BINARY_DIR}/sdl2Config.cmake) | 256 | if (YUZU_USE_BUNDLED_SDL2) |
| 261 | include(${CMAKE_BINARY_DIR}/sdl2Config.cmake) | 257 | # Detect toolchain and platform |
| 262 | list(APPEND CMAKE_MODULE_PATH "${CONAN_SDL2_ROOT_RELEASE}") | 258 | if ((MSVC_VERSION GREATER_EQUAL 1910 AND MSVC_VERSION LESS 1930) AND ARCHITECTURE_x86_64) |
| 263 | list(APPEND CMAKE_PREFIX_PATH "${CONAN_SDL2_ROOT_RELEASE}") | 259 | set(SDL2_VER "SDL2-2.0.14") |
| 264 | endif() | 260 | else() |
| 265 | find_package(SDL2) | 261 | message(FATAL_ERROR "No bundled SDL2 binaries for your toolchain. Disable YUZU_USE_BUNDLED_SDL2 and provide your own.") |
| 266 | if (NOT SDL2_FOUND) | 262 | endif() |
| 267 | # otherwise add this to the list of libraries to install | 263 | |
| 268 | list(APPEND CONAN_REQUIRED_LIBS "sdl2/2.0.14@bincrafters/stable") | 264 | if (DEFINED SDL2_VER) |
| 265 | download_bundled_external("sdl2/" ${SDL2_VER} SDL2_PREFIX) | ||
| 266 | endif() | ||
| 267 | |||
| 268 | set(SDL2_FOUND YES) | ||
| 269 | set(SDL2_INCLUDE_DIR "${SDL2_PREFIX}/include" CACHE PATH "Path to SDL2 headers") | ||
| 270 | set(SDL2_LIBRARY "${SDL2_PREFIX}/lib/x64/SDL2.lib" CACHE PATH "Path to SDL2 library") | ||
| 271 | set(SDL2_DLL_DIR "${SDL2_PREFIX}/lib/x64/" CACHE PATH "Path to SDL2.dll") | ||
| 272 | |||
| 273 | add_library(SDL2 INTERFACE) | ||
| 274 | target_link_libraries(SDL2 INTERFACE "${SDL2_LIBRARY}") | ||
| 275 | target_include_directories(SDL2 INTERFACE "${SDL2_INCLUDE_DIR}") | ||
| 276 | else() | ||
| 277 | find_package(SDL2 REQUIRED) | ||
| 278 | |||
| 279 | # Some installations don't set SDL2_LIBRARIES | ||
| 280 | if("${SDL2_LIBRARIES}" STREQUAL "") | ||
| 281 | message(WARNING "SDL2_LIBRARIES wasn't set, manually setting to SDL2::SDL2") | ||
| 282 | set(SDL2_LIBRARIES "SDL2::SDL2") | ||
| 283 | endif() | ||
| 284 | |||
| 285 | include_directories(SYSTEM ${SDL2_INCLUDE_DIRS}) | ||
| 286 | add_library(SDL2 INTERFACE) | ||
| 287 | target_link_libraries(SDL2 INTERFACE "${SDL2_LIBRARIES}") | ||
| 269 | endif() | 288 | endif() |
| 289 | else() | ||
| 290 | set(SDL2_FOUND NO) | ||
| 270 | endif() | 291 | endif() |
| 271 | 292 | ||
| 272 | # Install any missing dependencies with conan install | 293 | # Install any missing dependencies with conan install |
| @@ -287,9 +308,6 @@ if (CONAN_REQUIRED_LIBS) | |||
| 287 | ) | 308 | ) |
| 288 | 309 | ||
| 289 | conan_check(VERSION 1.24.0 REQUIRED) | 310 | conan_check(VERSION 1.24.0 REQUIRED) |
| 290 | # Add the bincrafters remote | ||
| 291 | conan_add_remote(NAME bincrafters | ||
| 292 | URL https://api.bintray.com/conan/bincrafters/public-conan) | ||
| 293 | 311 | ||
| 294 | # Manually add iconv to fix a dep conflict between qt and sdl2 | 312 | # Manually add iconv to fix a dep conflict between qt and sdl2 |
| 295 | # We don't need to add it through find_package or anything since the other two can find it just fine | 313 | # We don't need to add it through find_package or anything since the other two can find it just fine |
| @@ -340,11 +358,6 @@ if (CONAN_REQUIRED_LIBS) | |||
| 340 | find_package(Qt5 REQUIRED COMPONENTS WebEngineCore WebEngineWidgets) | 358 | find_package(Qt5 REQUIRED COMPONENTS WebEngineCore WebEngineWidgets) |
| 341 | endif() | 359 | endif() |
| 342 | endif() | 360 | endif() |
| 343 | if(ENABLE_SDL2) | ||
| 344 | list(APPEND CMAKE_MODULE_PATH "${CONAN_SDL2_ROOT_RELEASE}") | ||
| 345 | list(APPEND CMAKE_PREFIX_PATH "${CONAN_SDL2_ROOT_RELEASE}") | ||
| 346 | find_package(SDL2 REQUIRED) | ||
| 347 | endif() | ||
| 348 | 361 | ||
| 349 | endif() | 362 | endif() |
| 350 | 363 | ||
| @@ -360,23 +373,6 @@ elseif (TARGET Boost::boost) | |||
| 360 | add_library(boost ALIAS Boost::boost) | 373 | add_library(boost ALIAS Boost::boost) |
| 361 | endif() | 374 | endif() |
| 362 | 375 | ||
| 363 | if (TARGET sdl2::sdl2) | ||
| 364 | # imported from the conan generated sdl2Config.cmake | ||
| 365 | set_target_properties(sdl2::sdl2 PROPERTIES IMPORTED_GLOBAL TRUE) | ||
| 366 | add_library(SDL2 ALIAS sdl2::sdl2) | ||
| 367 | elseif(SDL2_FOUND) | ||
| 368 | # found through the system package manager | ||
| 369 | # Some installations don't set SDL2_LIBRARIES | ||
| 370 | if("${SDL2_LIBRARIES}" STREQUAL "") | ||
| 371 | message(WARNING "SDL2_LIBRARIES wasn't set, manually setting to SDL2::SDL2") | ||
| 372 | set(SDL2_LIBRARIES "SDL2::SDL2") | ||
| 373 | endif() | ||
| 374 | |||
| 375 | include_directories(SYSTEM ${SDL2_INCLUDE_DIRS}) | ||
| 376 | add_library(SDL2 INTERFACE) | ||
| 377 | target_link_libraries(SDL2 INTERFACE "${SDL2_LIBRARIES}") | ||
| 378 | endif() | ||
| 379 | |||
| 380 | # Ensure libusb is properly configured (based on dolphin libusb include) | 376 | # Ensure libusb is properly configured (based on dolphin libusb include) |
| 381 | if(NOT APPLE) | 377 | if(NOT APPLE) |
| 382 | include(FindPkgConfig) | 378 | include(FindPkgConfig) |
diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp index 8bca71731..9418e78fa 100644 --- a/src/input_common/sdl/sdl_impl.cpp +++ b/src/input_common/sdl/sdl_impl.cpp | |||
| @@ -761,7 +761,7 @@ std::vector<Common::ParamPackage> SDLState::GetInputDevices() { | |||
| 761 | for (const auto& joystick : value) { | 761 | for (const auto& joystick : value) { |
| 762 | if (auto* const controller = joystick->GetSDLGameController()) { | 762 | if (auto* const controller = joystick->GetSDLGameController()) { |
| 763 | std::string name = | 763 | std::string name = |
| 764 | fmt::format("{} {}", SDL_GameControllerName(controller), joystick->GetPort()); | 764 | fmt::format("{} {}", GetControllerName(controller), joystick->GetPort()); |
| 765 | devices.emplace_back(Common::ParamPackage{ | 765 | devices.emplace_back(Common::ParamPackage{ |
| 766 | {"class", "sdl"}, | 766 | {"class", "sdl"}, |
| 767 | {"display", std::move(name)}, | 767 | {"display", std::move(name)}, |
| @@ -782,6 +782,17 @@ std::vector<Common::ParamPackage> SDLState::GetInputDevices() { | |||
| 782 | return devices; | 782 | return devices; |
| 783 | } | 783 | } |
| 784 | 784 | ||
| 785 | std::string SDLState::GetControllerName(SDL_GameController* controller) const { | ||
| 786 | switch (SDL_GameControllerGetType(controller)) { | ||
| 787 | case SDL_CONTROLLER_TYPE_XBOX360: | ||
| 788 | return "XBox 360 Controller"; | ||
| 789 | case SDL_CONTROLLER_TYPE_XBOXONE: | ||
| 790 | return "XBox One Controller"; | ||
| 791 | default: | ||
| 792 | return SDL_GameControllerName(controller); | ||
| 793 | } | ||
| 794 | } | ||
| 795 | |||
| 785 | namespace { | 796 | namespace { |
| 786 | Common::ParamPackage BuildAnalogParamPackageForButton(int port, std::string guid, s32 axis, | 797 | Common::ParamPackage BuildAnalogParamPackageForButton(int port, std::string guid, s32 axis, |
| 787 | float value = 0.1f) { | 798 | float value = 0.1f) { |
| @@ -930,16 +941,19 @@ ButtonMapping SDLState::GetButtonMappingForDevice(const Common::ParamPackage& pa | |||
| 930 | return {}; | 941 | return {}; |
| 931 | } | 942 | } |
| 932 | 943 | ||
| 944 | const bool invert = | ||
| 945 | SDL_GameControllerGetType(controller) != SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO; | ||
| 946 | |||
| 933 | // This list is missing ZL/ZR since those are not considered buttons in SDL GameController. | 947 | // This list is missing ZL/ZR since those are not considered buttons in SDL GameController. |
| 934 | // We will add those afterwards | 948 | // We will add those afterwards |
| 935 | // This list also excludes Screenshot since theres not really a mapping for that | 949 | // This list also excludes Screenshot since theres not really a mapping for that |
| 936 | using ButtonBindings = | 950 | using ButtonBindings = |
| 937 | std::array<std::pair<Settings::NativeButton::Values, SDL_GameControllerButton>, 17>; | 951 | std::array<std::pair<Settings::NativeButton::Values, SDL_GameControllerButton>, 17>; |
| 938 | static constexpr ButtonBindings switch_to_sdl_button{{ | 952 | const ButtonBindings switch_to_sdl_button{{ |
| 939 | {Settings::NativeButton::A, SDL_CONTROLLER_BUTTON_B}, | 953 | {Settings::NativeButton::A, invert ? SDL_CONTROLLER_BUTTON_B : SDL_CONTROLLER_BUTTON_A}, |
| 940 | {Settings::NativeButton::B, SDL_CONTROLLER_BUTTON_A}, | 954 | {Settings::NativeButton::B, invert ? SDL_CONTROLLER_BUTTON_A : SDL_CONTROLLER_BUTTON_B}, |
| 941 | {Settings::NativeButton::X, SDL_CONTROLLER_BUTTON_Y}, | 955 | {Settings::NativeButton::X, invert ? SDL_CONTROLLER_BUTTON_Y : SDL_CONTROLLER_BUTTON_X}, |
| 942 | {Settings::NativeButton::Y, SDL_CONTROLLER_BUTTON_X}, | 956 | {Settings::NativeButton::Y, invert ? SDL_CONTROLLER_BUTTON_X : SDL_CONTROLLER_BUTTON_Y}, |
| 943 | {Settings::NativeButton::LStick, SDL_CONTROLLER_BUTTON_LEFTSTICK}, | 957 | {Settings::NativeButton::LStick, SDL_CONTROLLER_BUTTON_LEFTSTICK}, |
| 944 | {Settings::NativeButton::RStick, SDL_CONTROLLER_BUTTON_RIGHTSTICK}, | 958 | {Settings::NativeButton::RStick, SDL_CONTROLLER_BUTTON_RIGHTSTICK}, |
| 945 | {Settings::NativeButton::L, SDL_CONTROLLER_BUTTON_LEFTSHOULDER}, | 959 | {Settings::NativeButton::L, SDL_CONTROLLER_BUTTON_LEFTSHOULDER}, |
diff --git a/src/input_common/sdl/sdl_impl.h b/src/input_common/sdl/sdl_impl.h index 08044b00d..8b7363f56 100644 --- a/src/input_common/sdl/sdl_impl.h +++ b/src/input_common/sdl/sdl_impl.h | |||
| @@ -14,6 +14,7 @@ | |||
| 14 | #include "input_common/sdl/sdl.h" | 14 | #include "input_common/sdl/sdl.h" |
| 15 | 15 | ||
| 16 | union SDL_Event; | 16 | union SDL_Event; |
| 17 | using SDL_GameController = struct _SDL_GameController; | ||
| 17 | using SDL_Joystick = struct _SDL_Joystick; | 18 | using SDL_Joystick = struct _SDL_Joystick; |
| 18 | using SDL_JoystickID = s32; | 19 | using SDL_JoystickID = s32; |
| 19 | 20 | ||
| @@ -64,6 +65,9 @@ private: | |||
| 64 | /// Needs to be called before SDL_QuitSubSystem. | 65 | /// Needs to be called before SDL_QuitSubSystem. |
| 65 | void CloseJoysticks(); | 66 | void CloseJoysticks(); |
| 66 | 67 | ||
| 68 | /// Returns a custom name for specific controllers because the default name is not correct | ||
| 69 | std::string GetControllerName(SDL_GameController* controller) const; | ||
| 70 | |||
| 67 | // Set to true if SDL supports game controller subsystem | 71 | // Set to true if SDL supports game controller subsystem |
| 68 | bool has_gamecontroller = false; | 72 | bool has_gamecontroller = false; |
| 69 | 73 | ||