diff options
Diffstat (limited to 'src')
61 files changed, 601 insertions, 411 deletions
diff --git a/src/audio_core/CMakeLists.txt b/src/audio_core/CMakeLists.txt index 6a7075f73..54940a034 100644 --- a/src/audio_core/CMakeLists.txt +++ b/src/audio_core/CMakeLists.txt | |||
| @@ -46,10 +46,13 @@ create_target_directory_groups(audio_core) | |||
| 46 | 46 | ||
| 47 | if (NOT MSVC) | 47 | if (NOT MSVC) |
| 48 | target_compile_options(audio_core PRIVATE | 48 | target_compile_options(audio_core PRIVATE |
| 49 | -Werror=conversion | ||
| 49 | -Werror=ignored-qualifiers | 50 | -Werror=ignored-qualifiers |
| 50 | -Werror=implicit-fallthrough | 51 | -Werror=implicit-fallthrough |
| 51 | -Werror=reorder | 52 | -Werror=reorder |
| 52 | -Werror=sign-compare | 53 | -Werror=sign-compare |
| 54 | -Werror=unused-but-set-parameter | ||
| 55 | -Werror=unused-but-set-variable | ||
| 53 | -Werror=unused-variable | 56 | -Werror=unused-variable |
| 54 | ) | 57 | ) |
| 55 | endif() | 58 | endif() |
diff --git a/src/audio_core/algorithm/filter.cpp b/src/audio_core/algorithm/filter.cpp index f65bf64f7..f34a5b9f3 100644 --- a/src/audio_core/algorithm/filter.cpp +++ b/src/audio_core/algorithm/filter.cpp | |||
| @@ -55,7 +55,8 @@ void Filter::Process(std::vector<s16>& signal) { | |||
| 55 | /// @param total_count The total number of biquads to be cascaded. | 55 | /// @param total_count The total number of biquads to be cascaded. |
| 56 | /// @param index 0-index of the biquad to calculate the Q value for. | 56 | /// @param index 0-index of the biquad to calculate the Q value for. |
| 57 | static double CascadingBiquadQ(std::size_t total_count, std::size_t index) { | 57 | static double CascadingBiquadQ(std::size_t total_count, std::size_t index) { |
| 58 | const double pole = M_PI * (2 * index + 1) / (4.0 * total_count); | 58 | const auto pole = |
| 59 | M_PI * static_cast<double>(2 * index + 1) / (4.0 * static_cast<double>(total_count)); | ||
| 59 | return 1.0 / (2.0 * std::cos(pole)); | 60 | return 1.0 / (2.0 * std::cos(pole)); |
| 60 | } | 61 | } |
| 61 | 62 | ||
diff --git a/src/audio_core/algorithm/interpolate.cpp b/src/audio_core/algorithm/interpolate.cpp index 689a54508..699fcb84c 100644 --- a/src/audio_core/algorithm/interpolate.cpp +++ b/src/audio_core/algorithm/interpolate.cpp | |||
| @@ -146,7 +146,7 @@ std::vector<s16> Interpolate(InterpolationState& state, std::vector<s16> input, | |||
| 146 | return {}; | 146 | return {}; |
| 147 | 147 | ||
| 148 | if (ratio <= 0) { | 148 | if (ratio <= 0) { |
| 149 | LOG_CRITICAL(Audio, "Nonsensical interpolation ratio {}", ratio); | 149 | LOG_ERROR(Audio, "Nonsensical interpolation ratio {}", ratio); |
| 150 | return input; | 150 | return input; |
| 151 | } | 151 | } |
| 152 | 152 | ||
| @@ -164,7 +164,8 @@ std::vector<s16> Interpolate(InterpolationState& state, std::vector<s16> input, | |||
| 164 | const std::size_t num_frames{input.size() / 2}; | 164 | const std::size_t num_frames{input.size() / 2}; |
| 165 | 165 | ||
| 166 | std::vector<s16> output; | 166 | std::vector<s16> output; |
| 167 | output.reserve(static_cast<std::size_t>(input.size() / ratio + InterpolationState::taps)); | 167 | output.reserve(static_cast<std::size_t>(static_cast<double>(input.size()) / ratio + |
| 168 | InterpolationState::taps)); | ||
| 168 | 169 | ||
| 169 | for (std::size_t frame{}; frame < num_frames; ++frame) { | 170 | for (std::size_t frame{}; frame < num_frames; ++frame) { |
| 170 | const std::size_t lut_index{(state.fraction >> 8) * InterpolationState::taps}; | 171 | const std::size_t lut_index{(state.fraction >> 8) * InterpolationState::taps}; |
diff --git a/src/audio_core/command_generator.cpp b/src/audio_core/command_generator.cpp index bba40d13d..fb8700ccf 100644 --- a/src/audio_core/command_generator.cpp +++ b/src/audio_core/command_generator.cpp | |||
| @@ -793,7 +793,6 @@ s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_s | |||
| 793 | // Decode entire frame | 793 | // Decode entire frame |
| 794 | if (remaining_samples >= static_cast<int>(SAMPLES_PER_FRAME)) { | 794 | if (remaining_samples >= static_cast<int>(SAMPLES_PER_FRAME)) { |
| 795 | for (std::size_t i = 0; i < SAMPLES_PER_FRAME / 2; i++) { | 795 | for (std::size_t i = 0; i < SAMPLES_PER_FRAME / 2; i++) { |
| 796 | |||
| 797 | // Sample 1 | 796 | // Sample 1 |
| 798 | const s32 s0 = SIGNED_NIBBLES[buffer[buffer_offset] >> 4]; | 797 | const s32 s0 = SIGNED_NIBBLES[buffer[buffer_offset] >> 4]; |
| 799 | const s32 s1 = SIGNED_NIBBLES[buffer[buffer_offset++] & 0xf]; | 798 | const s32 s1 = SIGNED_NIBBLES[buffer[buffer_offset++] & 0xf]; |
| @@ -802,7 +801,7 @@ s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_s | |||
| 802 | sample_buffer[cur_mix_offset++] = sample_1; | 801 | sample_buffer[cur_mix_offset++] = sample_1; |
| 803 | sample_buffer[cur_mix_offset++] = sample_2; | 802 | sample_buffer[cur_mix_offset++] = sample_2; |
| 804 | } | 803 | } |
| 805 | remaining_samples -= SAMPLES_PER_FRAME; | 804 | remaining_samples -= static_cast<int>(SAMPLES_PER_FRAME); |
| 806 | position_in_frame += SAMPLES_PER_FRAME; | 805 | position_in_frame += SAMPLES_PER_FRAME; |
| 807 | continue; | 806 | continue; |
| 808 | } | 807 | } |
diff --git a/src/audio_core/cubeb_sink.cpp b/src/audio_core/cubeb_sink.cpp index eb82791f6..6eaa60815 100644 --- a/src/audio_core/cubeb_sink.cpp +++ b/src/audio_core/cubeb_sink.cpp | |||
| @@ -93,8 +93,10 @@ public: | |||
| 93 | constexpr s32 clev{707}; // center mixing level coefficient | 93 | constexpr s32 clev{707}; // center mixing level coefficient |
| 94 | constexpr s32 slev{707}; // surround mixing level coefficient | 94 | constexpr s32 slev{707}; // surround mixing level coefficient |
| 95 | 95 | ||
| 96 | buf.push_back(left + (clev * center / 1000) + (slev * surround_left / 1000)); | 96 | buf.push_back(static_cast<s16>(left + (clev * center / 1000) + |
| 97 | buf.push_back(right + (clev * center / 1000) + (slev * surround_right / 1000)); | 97 | (slev * surround_left / 1000))); |
| 98 | buf.push_back(static_cast<s16>(right + (clev * center / 1000) + | ||
| 99 | (slev * surround_right / 1000))); | ||
| 98 | } | 100 | } |
| 99 | queue.Push(buf); | 101 | queue.Push(buf); |
| 100 | return; | 102 | return; |
diff --git a/src/audio_core/voice_context.cpp b/src/audio_core/voice_context.cpp index 863ac9267..c46ee55f1 100644 --- a/src/audio_core/voice_context.cpp +++ b/src/audio_core/voice_context.cpp | |||
| @@ -128,7 +128,10 @@ void ServerVoiceInfo::UpdateParameters(const VoiceInfo::InParams& voice_in, | |||
| 128 | in_params.wave_buffer_count = voice_in.wave_buffer_count; | 128 | in_params.wave_buffer_count = voice_in.wave_buffer_count; |
| 129 | in_params.wave_bufffer_head = voice_in.wave_buffer_head; | 129 | in_params.wave_bufffer_head = voice_in.wave_buffer_head; |
| 130 | if (behavior_info.IsFlushVoiceWaveBuffersSupported()) { | 130 | if (behavior_info.IsFlushVoiceWaveBuffersSupported()) { |
| 131 | in_params.wave_buffer_flush_request_count += voice_in.wave_buffer_flush_request_count; | 131 | const auto in_request_count = in_params.wave_buffer_flush_request_count; |
| 132 | const auto voice_request_count = voice_in.wave_buffer_flush_request_count; | ||
| 133 | in_params.wave_buffer_flush_request_count = | ||
| 134 | static_cast<u8>(in_request_count + voice_request_count); | ||
| 132 | } | 135 | } |
| 133 | in_params.mix_id = voice_in.mix_id; | 136 | in_params.mix_id = voice_in.mix_id; |
| 134 | if (behavior_info.IsSplitterSupported()) { | 137 | if (behavior_info.IsSplitterSupported()) { |
diff --git a/src/common/hex_util.h b/src/common/hex_util.h index 120f1a5e6..a8d414fb8 100644 --- a/src/common/hex_util.h +++ b/src/common/hex_util.h | |||
| @@ -16,14 +16,14 @@ namespace Common { | |||
| 16 | 16 | ||
| 17 | [[nodiscard]] constexpr u8 ToHexNibble(char c) { | 17 | [[nodiscard]] constexpr u8 ToHexNibble(char c) { |
| 18 | if (c >= 65 && c <= 70) { | 18 | if (c >= 65 && c <= 70) { |
| 19 | return c - 55; | 19 | return static_cast<u8>(c - 55); |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | if (c >= 97 && c <= 102) { | 22 | if (c >= 97 && c <= 102) { |
| 23 | return c - 87; | 23 | return static_cast<u8>(c - 87); |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | return c - 48; | 26 | return static_cast<u8>(c - 48); |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | [[nodiscard]] std::vector<u8> HexStringToVector(std::string_view str, bool little_endian); | 29 | [[nodiscard]] std::vector<u8> HexStringToVector(std::string_view str, bool little_endian); |
| @@ -33,11 +33,11 @@ template <std::size_t Size, bool le = false> | |||
| 33 | std::array<u8, Size> out{}; | 33 | std::array<u8, Size> out{}; |
| 34 | if constexpr (le) { | 34 | if constexpr (le) { |
| 35 | for (std::size_t i = 2 * Size - 2; i <= 2 * Size; i -= 2) { | 35 | for (std::size_t i = 2 * Size - 2; i <= 2 * Size; i -= 2) { |
| 36 | out[i / 2] = (ToHexNibble(str[i]) << 4) | ToHexNibble(str[i + 1]); | 36 | out[i / 2] = static_cast<u8>((ToHexNibble(str[i]) << 4) | ToHexNibble(str[i + 1])); |
| 37 | } | 37 | } |
| 38 | } else { | 38 | } else { |
| 39 | for (std::size_t i = 0; i < 2 * Size; i += 2) { | 39 | for (std::size_t i = 0; i < 2 * Size; i += 2) { |
| 40 | out[i / 2] = (ToHexNibble(str[i]) << 4) | ToHexNibble(str[i + 1]); | 40 | out[i / 2] = static_cast<u8>((ToHexNibble(str[i]) << 4) | ToHexNibble(str[i + 1])); |
| 41 | } | 41 | } |
| 42 | } | 42 | } |
| 43 | return out; | 43 | return out; |
diff --git a/src/common/math_util.h b/src/common/math_util.h index b35ad8507..7cec80d57 100644 --- a/src/common/math_util.h +++ b/src/common/math_util.h | |||
| @@ -20,8 +20,8 @@ struct Rectangle { | |||
| 20 | 20 | ||
| 21 | constexpr Rectangle() = default; | 21 | constexpr Rectangle() = default; |
| 22 | 22 | ||
| 23 | constexpr Rectangle(T left, T top, T right, T bottom) | 23 | constexpr Rectangle(T left_, T top_, T right_, T bottom_) |
| 24 | : left(left), top(top), right(right), bottom(bottom) {} | 24 | : left(left_), top(top_), right(right_), bottom(bottom_) {} |
| 25 | 25 | ||
| 26 | [[nodiscard]] T GetWidth() const { | 26 | [[nodiscard]] T GetWidth() const { |
| 27 | if constexpr (std::is_floating_point_v<T>) { | 27 | if constexpr (std::is_floating_point_v<T>) { |
diff --git a/src/common/vector_math.h b/src/common/vector_math.h index 2a0fcf541..22dba3c2d 100644 --- a/src/common/vector_math.h +++ b/src/common/vector_math.h | |||
| @@ -87,7 +87,13 @@ public: | |||
| 87 | 87 | ||
| 88 | template <typename V> | 88 | template <typename V> |
| 89 | [[nodiscard]] constexpr Vec2<decltype(T{} * V{})> operator*(const V& f) const { | 89 | [[nodiscard]] constexpr Vec2<decltype(T{} * V{})> operator*(const V& f) const { |
| 90 | return {x * f, y * f}; | 90 | using TV = decltype(T{} * V{}); |
| 91 | using C = std::common_type_t<T, V>; | ||
| 92 | |||
| 93 | return { | ||
| 94 | static_cast<TV>(static_cast<C>(x) * static_cast<C>(f)), | ||
| 95 | static_cast<TV>(static_cast<C>(y) * static_cast<C>(f)), | ||
| 96 | }; | ||
| 91 | } | 97 | } |
| 92 | 98 | ||
| 93 | template <typename V> | 99 | template <typename V> |
| @@ -98,7 +104,13 @@ public: | |||
| 98 | 104 | ||
| 99 | template <typename V> | 105 | template <typename V> |
| 100 | [[nodiscard]] constexpr Vec2<decltype(T{} / V{})> operator/(const V& f) const { | 106 | [[nodiscard]] constexpr Vec2<decltype(T{} / V{})> operator/(const V& f) const { |
| 101 | return {x / f, y / f}; | 107 | using TV = decltype(T{} / V{}); |
| 108 | using C = std::common_type_t<T, V>; | ||
| 109 | |||
| 110 | return { | ||
| 111 | static_cast<TV>(static_cast<C>(x) / static_cast<C>(f)), | ||
| 112 | static_cast<TV>(static_cast<C>(y) / static_cast<C>(f)), | ||
| 113 | }; | ||
| 102 | } | 114 | } |
| 103 | 115 | ||
| 104 | template <typename V> | 116 | template <typename V> |
| @@ -168,7 +180,10 @@ public: | |||
| 168 | 180 | ||
| 169 | template <typename T, typename V> | 181 | template <typename T, typename V> |
| 170 | [[nodiscard]] constexpr Vec2<T> operator*(const V& f, const Vec2<T>& vec) { | 182 | [[nodiscard]] constexpr Vec2<T> operator*(const V& f, const Vec2<T>& vec) { |
| 171 | return Vec2<T>(f * vec.x, f * vec.y); | 183 | using C = std::common_type_t<T, V>; |
| 184 | |||
| 185 | return Vec2<T>(static_cast<T>(static_cast<C>(f) * static_cast<C>(vec.x)), | ||
| 186 | static_cast<T>(static_cast<C>(f) * static_cast<C>(vec.y))); | ||
| 172 | } | 187 | } |
| 173 | 188 | ||
| 174 | using Vec2f = Vec2<float>; | 189 | using Vec2f = Vec2<float>; |
| @@ -237,7 +252,14 @@ public: | |||
| 237 | 252 | ||
| 238 | template <typename V> | 253 | template <typename V> |
| 239 | [[nodiscard]] constexpr Vec3<decltype(T{} * V{})> operator*(const V& f) const { | 254 | [[nodiscard]] constexpr Vec3<decltype(T{} * V{})> operator*(const V& f) const { |
| 240 | return {x * f, y * f, z * f}; | 255 | using TV = decltype(T{} * V{}); |
| 256 | using C = std::common_type_t<T, V>; | ||
| 257 | |||
| 258 | return { | ||
| 259 | static_cast<TV>(static_cast<C>(x) * static_cast<C>(f)), | ||
| 260 | static_cast<TV>(static_cast<C>(y) * static_cast<C>(f)), | ||
| 261 | static_cast<TV>(static_cast<C>(z) * static_cast<C>(f)), | ||
| 262 | }; | ||
| 241 | } | 263 | } |
| 242 | 264 | ||
| 243 | template <typename V> | 265 | template <typename V> |
| @@ -247,7 +269,14 @@ public: | |||
| 247 | } | 269 | } |
| 248 | template <typename V> | 270 | template <typename V> |
| 249 | [[nodiscard]] constexpr Vec3<decltype(T{} / V{})> operator/(const V& f) const { | 271 | [[nodiscard]] constexpr Vec3<decltype(T{} / V{})> operator/(const V& f) const { |
| 250 | return {x / f, y / f, z / f}; | 272 | using TV = decltype(T{} / V{}); |
| 273 | using C = std::common_type_t<T, V>; | ||
| 274 | |||
| 275 | return { | ||
| 276 | static_cast<TV>(static_cast<C>(x) / static_cast<C>(f)), | ||
| 277 | static_cast<TV>(static_cast<C>(y) / static_cast<C>(f)), | ||
| 278 | static_cast<TV>(static_cast<C>(z) / static_cast<C>(f)), | ||
| 279 | }; | ||
| 251 | } | 280 | } |
| 252 | 281 | ||
| 253 | template <typename V> | 282 | template <typename V> |
| @@ -367,7 +396,11 @@ public: | |||
| 367 | 396 | ||
| 368 | template <typename T, typename V> | 397 | template <typename T, typename V> |
| 369 | [[nodiscard]] constexpr Vec3<T> operator*(const V& f, const Vec3<T>& vec) { | 398 | [[nodiscard]] constexpr Vec3<T> operator*(const V& f, const Vec3<T>& vec) { |
| 370 | return Vec3<T>(f * vec.x, f * vec.y, f * vec.z); | 399 | using C = std::common_type_t<T, V>; |
| 400 | |||
| 401 | return Vec3<T>(static_cast<T>(static_cast<C>(f) * static_cast<C>(vec.x)), | ||
| 402 | static_cast<T>(static_cast<C>(f) * static_cast<C>(vec.y)), | ||
| 403 | static_cast<T>(static_cast<C>(f) * static_cast<C>(vec.z))); | ||
| 371 | } | 404 | } |
| 372 | 405 | ||
| 373 | template <> | 406 | template <> |
| @@ -446,7 +479,15 @@ public: | |||
| 446 | 479 | ||
| 447 | template <typename V> | 480 | template <typename V> |
| 448 | [[nodiscard]] constexpr Vec4<decltype(T{} * V{})> operator*(const V& f) const { | 481 | [[nodiscard]] constexpr Vec4<decltype(T{} * V{})> operator*(const V& f) const { |
| 449 | return {x * f, y * f, z * f, w * f}; | 482 | using TV = decltype(T{} * V{}); |
| 483 | using C = std::common_type_t<T, V>; | ||
| 484 | |||
| 485 | return { | ||
| 486 | static_cast<TV>(static_cast<C>(x) * static_cast<C>(f)), | ||
| 487 | static_cast<TV>(static_cast<C>(y) * static_cast<C>(f)), | ||
| 488 | static_cast<TV>(static_cast<C>(z) * static_cast<C>(f)), | ||
| 489 | static_cast<TV>(static_cast<C>(w) * static_cast<C>(f)), | ||
| 490 | }; | ||
| 450 | } | 491 | } |
| 451 | 492 | ||
| 452 | template <typename V> | 493 | template <typename V> |
| @@ -457,7 +498,15 @@ public: | |||
| 457 | 498 | ||
| 458 | template <typename V> | 499 | template <typename V> |
| 459 | [[nodiscard]] constexpr Vec4<decltype(T{} / V{})> operator/(const V& f) const { | 500 | [[nodiscard]] constexpr Vec4<decltype(T{} / V{})> operator/(const V& f) const { |
| 460 | return {x / f, y / f, z / f, w / f}; | 501 | using TV = decltype(T{} / V{}); |
| 502 | using C = std::common_type_t<T, V>; | ||
| 503 | |||
| 504 | return { | ||
| 505 | static_cast<TV>(static_cast<C>(x) / static_cast<C>(f)), | ||
| 506 | static_cast<TV>(static_cast<C>(y) / static_cast<C>(f)), | ||
| 507 | static_cast<TV>(static_cast<C>(z) / static_cast<C>(f)), | ||
| 508 | static_cast<TV>(static_cast<C>(w) / static_cast<C>(f)), | ||
| 509 | }; | ||
| 461 | } | 510 | } |
| 462 | 511 | ||
| 463 | template <typename V> | 512 | template <typename V> |
| @@ -582,7 +631,15 @@ public: | |||
| 582 | 631 | ||
| 583 | template <typename T, typename V> | 632 | template <typename T, typename V> |
| 584 | [[nodiscard]] constexpr Vec4<decltype(V{} * T{})> operator*(const V& f, const Vec4<T>& vec) { | 633 | [[nodiscard]] constexpr Vec4<decltype(V{} * T{})> operator*(const V& f, const Vec4<T>& vec) { |
| 585 | return {f * vec.x, f * vec.y, f * vec.z, f * vec.w}; | 634 | using TV = decltype(V{} * T{}); |
| 635 | using C = std::common_type_t<T, V>; | ||
| 636 | |||
| 637 | return { | ||
| 638 | static_cast<TV>(static_cast<C>(f) * static_cast<C>(vec.x)), | ||
| 639 | static_cast<TV>(static_cast<C>(f) * static_cast<C>(vec.y)), | ||
| 640 | static_cast<TV>(static_cast<C>(f) * static_cast<C>(vec.z)), | ||
| 641 | static_cast<TV>(static_cast<C>(f) * static_cast<C>(vec.w)), | ||
| 642 | }; | ||
| 586 | } | 643 | } |
| 587 | 644 | ||
| 588 | using Vec4f = Vec4<float>; | 645 | using Vec4f = Vec4<float>; |
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index d0c405ec7..9760be4e4 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -623,6 +623,17 @@ if (MSVC) | |||
| 623 | # 'context' : truncation from 'type1' to 'type2' | 623 | # 'context' : truncation from 'type1' to 'type2' |
| 624 | /we4305 | 624 | /we4305 |
| 625 | ) | 625 | ) |
| 626 | else() | ||
| 627 | target_compile_options(core PRIVATE | ||
| 628 | -Werror=conversion | ||
| 629 | -Werror=ignored-qualifiers | ||
| 630 | -Werror=implicit-fallthrough | ||
| 631 | -Werror=reorder | ||
| 632 | -Werror=sign-compare | ||
| 633 | -Werror=unused-but-set-parameter | ||
| 634 | -Werror=unused-but-set-variable | ||
| 635 | -Werror=unused-variable | ||
| 636 | ) | ||
| 626 | endif() | 637 | endif() |
| 627 | 638 | ||
| 628 | create_target_directory_groups(core) | 639 | create_target_directory_groups(core) |
diff --git a/src/core/crypto/key_manager.cpp b/src/core/crypto/key_manager.cpp index 65d246050..da15f764a 100644 --- a/src/core/crypto/key_manager.cpp +++ b/src/core/crypto/key_manager.cpp | |||
| @@ -411,7 +411,7 @@ Loader::ResultStatus DeriveSDKeys(std::array<Key256, 2>& sd_keys, KeyManager& ke | |||
| 411 | // Combine sources and seed | 411 | // Combine sources and seed |
| 412 | for (auto& source : sd_key_sources) { | 412 | for (auto& source : sd_key_sources) { |
| 413 | for (std::size_t i = 0; i < source.size(); ++i) { | 413 | for (std::size_t i = 0; i < source.size(); ++i) { |
| 414 | source[i] ^= sd_seed[i & 0xF]; | 414 | source[i] = static_cast<u8>(source[i] ^ sd_seed[i & 0xF]); |
| 415 | } | 415 | } |
| 416 | } | 416 | } |
| 417 | 417 | ||
diff --git a/src/core/file_sys/fsmitm_romfsbuild.cpp b/src/core/file_sys/fsmitm_romfsbuild.cpp index 2aff2708a..c52fafb6f 100644 --- a/src/core/file_sys/fsmitm_romfsbuild.cpp +++ b/src/core/file_sys/fsmitm_romfsbuild.cpp | |||
| @@ -266,8 +266,9 @@ std::multimap<u64, VirtualFile> RomFSBuildContext::Build() { | |||
| 266 | cur_file->offset = file_partition_size; | 266 | cur_file->offset = file_partition_size; |
| 267 | file_partition_size += cur_file->size; | 267 | file_partition_size += cur_file->size; |
| 268 | cur_file->entry_offset = entry_offset; | 268 | cur_file->entry_offset = entry_offset; |
| 269 | entry_offset += sizeof(RomFSFileEntry) + | 269 | entry_offset += |
| 270 | Common::AlignUp(cur_file->path_len - cur_file->cur_path_ofs, 4); | 270 | static_cast<u32>(sizeof(RomFSFileEntry) + |
| 271 | Common::AlignUp(cur_file->path_len - cur_file->cur_path_ofs, 4)); | ||
| 271 | prev_file = cur_file; | 272 | prev_file = cur_file; |
| 272 | } | 273 | } |
| 273 | // Assign deferred parent/sibling ownership. | 274 | // Assign deferred parent/sibling ownership. |
| @@ -284,8 +285,9 @@ std::multimap<u64, VirtualFile> RomFSBuildContext::Build() { | |||
| 284 | for (const auto& it : directories) { | 285 | for (const auto& it : directories) { |
| 285 | cur_dir = it.second; | 286 | cur_dir = it.second; |
| 286 | cur_dir->entry_offset = entry_offset; | 287 | cur_dir->entry_offset = entry_offset; |
| 287 | entry_offset += sizeof(RomFSDirectoryEntry) + | 288 | entry_offset += |
| 288 | Common::AlignUp(cur_dir->path_len - cur_dir->cur_path_ofs, 4); | 289 | static_cast<u32>(sizeof(RomFSDirectoryEntry) + |
| 290 | Common::AlignUp(cur_dir->path_len - cur_dir->cur_path_ofs, 4)); | ||
| 289 | } | 291 | } |
| 290 | // Assign deferred parent/sibling ownership. | 292 | // Assign deferred parent/sibling ownership. |
| 291 | for (auto it = directories.rbegin(); it->second != root; ++it) { | 293 | for (auto it = directories.rbegin(); it->second != root; ++it) { |
diff --git a/src/core/file_sys/ips_layer.cpp b/src/core/file_sys/ips_layer.cpp index dd779310f..a6101f1c0 100644 --- a/src/core/file_sys/ips_layer.cpp +++ b/src/core/file_sys/ips_layer.cpp | |||
| @@ -299,7 +299,7 @@ void IPSwitchCompiler::Parse() { | |||
| 299 | patch_text->GetName(), offset, Common::HexToString(replace)); | 299 | patch_text->GetName(), offset, Common::HexToString(replace)); |
| 300 | } | 300 | } |
| 301 | 301 | ||
| 302 | patch.records.insert_or_assign(offset, std::move(replace)); | 302 | patch.records.insert_or_assign(static_cast<u32>(offset), std::move(replace)); |
| 303 | } | 303 | } |
| 304 | 304 | ||
| 305 | patches.push_back(std::move(patch)); | 305 | patches.push_back(std::move(patch)); |
diff --git a/src/core/file_sys/nca_metadata.cpp b/src/core/file_sys/nca_metadata.cpp index 2d1476e3a..3596541b2 100644 --- a/src/core/file_sys/nca_metadata.cpp +++ b/src/core/file_sys/nca_metadata.cpp | |||
| @@ -108,7 +108,7 @@ std::vector<u8> CNMT::Serialize() const { | |||
| 108 | memcpy(out.data() + sizeof(CNMTHeader), &opt_header, sizeof(OptionalHeader)); | 108 | memcpy(out.data() + sizeof(CNMTHeader), &opt_header, sizeof(OptionalHeader)); |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | auto offset = header.table_offset; | 111 | u64_le offset = header.table_offset; |
| 112 | 112 | ||
| 113 | for (const auto& rec : content_records) { | 113 | for (const auto& rec : content_records) { |
| 114 | memcpy(out.data() + offset + sizeof(CNMTHeader), &rec, sizeof(ContentRecord)); | 114 | memcpy(out.data() + offset + sizeof(CNMTHeader), &rec, sizeof(ContentRecord)); |
diff --git a/src/core/file_sys/patch_manager.cpp b/src/core/file_sys/patch_manager.cpp index b9c09b456..807b05821 100644 --- a/src/core/file_sys/patch_manager.cpp +++ b/src/core/file_sys/patch_manager.cpp | |||
| @@ -29,7 +29,7 @@ | |||
| 29 | namespace FileSys { | 29 | namespace FileSys { |
| 30 | namespace { | 30 | namespace { |
| 31 | 31 | ||
| 32 | constexpr u64 SINGLE_BYTE_MODULUS = 0x100; | 32 | constexpr u32 SINGLE_BYTE_MODULUS = 0x100; |
| 33 | constexpr u64 DLC_BASE_TITLE_ID_MASK = 0xFFFFFFFFFFFFE000; | 33 | constexpr u64 DLC_BASE_TITLE_ID_MASK = 0xFFFFFFFFFFFFE000; |
| 34 | 34 | ||
| 35 | constexpr std::array<const char*, 14> EXEFS_FILE_NAMES{ | 35 | constexpr std::array<const char*, 14> EXEFS_FILE_NAMES{ |
diff --git a/src/core/file_sys/submission_package.cpp b/src/core/file_sys/submission_package.cpp index 07ae90819..90641d23b 100644 --- a/src/core/file_sys/submission_package.cpp +++ b/src/core/file_sys/submission_package.cpp | |||
| @@ -19,38 +19,6 @@ | |||
| 19 | #include "core/loader/loader.h" | 19 | #include "core/loader/loader.h" |
| 20 | 20 | ||
| 21 | namespace FileSys { | 21 | namespace FileSys { |
| 22 | namespace { | ||
| 23 | void SetTicketKeys(const std::vector<VirtualFile>& files) { | ||
| 24 | auto& keys = Core::Crypto::KeyManager::Instance(); | ||
| 25 | |||
| 26 | for (const auto& ticket_file : files) { | ||
| 27 | if (ticket_file == nullptr) { | ||
| 28 | continue; | ||
| 29 | } | ||
| 30 | |||
| 31 | if (ticket_file->GetExtension() != "tik") { | ||
| 32 | continue; | ||
| 33 | } | ||
| 34 | |||
| 35 | if (ticket_file->GetSize() < | ||
| 36 | Core::Crypto::TICKET_FILE_TITLEKEY_OFFSET + sizeof(Core::Crypto::Key128)) { | ||
| 37 | continue; | ||
| 38 | } | ||
| 39 | |||
| 40 | Core::Crypto::Key128 key{}; | ||
| 41 | ticket_file->Read(key.data(), key.size(), Core::Crypto::TICKET_FILE_TITLEKEY_OFFSET); | ||
| 42 | |||
| 43 | // We get the name without the extension in order to create the rights ID. | ||
| 44 | std::string name_only(ticket_file->GetName()); | ||
| 45 | name_only.erase(name_only.size() - 4); | ||
| 46 | |||
| 47 | const auto rights_id_raw = Common::HexStringToArray<16>(name_only); | ||
| 48 | u128 rights_id; | ||
| 49 | std::memcpy(rights_id.data(), rights_id_raw.data(), sizeof(u128)); | ||
| 50 | keys.SetKey(Core::Crypto::S128KeyType::Titlekey, key, rights_id[1], rights_id[0]); | ||
| 51 | } | ||
| 52 | } | ||
| 53 | } // Anonymous namespace | ||
| 54 | 22 | ||
| 55 | NSP::NSP(VirtualFile file_) | 23 | NSP::NSP(VirtualFile file_) |
| 56 | : file(std::move(file_)), status{Loader::ResultStatus::Success}, | 24 | : file(std::move(file_)), status{Loader::ResultStatus::Success}, |
| @@ -232,6 +200,35 @@ VirtualDir NSP::GetParentDirectory() const { | |||
| 232 | return file->GetContainingDirectory(); | 200 | return file->GetContainingDirectory(); |
| 233 | } | 201 | } |
| 234 | 202 | ||
| 203 | void NSP::SetTicketKeys(const std::vector<VirtualFile>& files) { | ||
| 204 | for (const auto& ticket_file : files) { | ||
| 205 | if (ticket_file == nullptr) { | ||
| 206 | continue; | ||
| 207 | } | ||
| 208 | |||
| 209 | if (ticket_file->GetExtension() != "tik") { | ||
| 210 | continue; | ||
| 211 | } | ||
| 212 | |||
| 213 | if (ticket_file->GetSize() < | ||
| 214 | Core::Crypto::TICKET_FILE_TITLEKEY_OFFSET + sizeof(Core::Crypto::Key128)) { | ||
| 215 | continue; | ||
| 216 | } | ||
| 217 | |||
| 218 | Core::Crypto::Key128 key{}; | ||
| 219 | ticket_file->Read(key.data(), key.size(), Core::Crypto::TICKET_FILE_TITLEKEY_OFFSET); | ||
| 220 | |||
| 221 | // We get the name without the extension in order to create the rights ID. | ||
| 222 | std::string name_only(ticket_file->GetName()); | ||
| 223 | name_only.erase(name_only.size() - 4); | ||
| 224 | |||
| 225 | const auto rights_id_raw = Common::HexStringToArray<16>(name_only); | ||
| 226 | u128 rights_id; | ||
| 227 | std::memcpy(rights_id.data(), rights_id_raw.data(), sizeof(u128)); | ||
| 228 | keys.SetKey(Core::Crypto::S128KeyType::Titlekey, key, rights_id[1], rights_id[0]); | ||
| 229 | } | ||
| 230 | } | ||
| 231 | |||
| 235 | void NSP::InitializeExeFSAndRomFS(const std::vector<VirtualFile>& files) { | 232 | void NSP::InitializeExeFSAndRomFS(const std::vector<VirtualFile>& files) { |
| 236 | exefs = pfs; | 233 | exefs = pfs; |
| 237 | 234 | ||
diff --git a/src/core/file_sys/submission_package.h b/src/core/file_sys/submission_package.h index 2db5e46b8..c70a11b5b 100644 --- a/src/core/file_sys/submission_package.h +++ b/src/core/file_sys/submission_package.h | |||
| @@ -63,6 +63,7 @@ public: | |||
| 63 | VirtualDir GetParentDirectory() const override; | 63 | VirtualDir GetParentDirectory() const override; |
| 64 | 64 | ||
| 65 | private: | 65 | private: |
| 66 | void SetTicketKeys(const std::vector<VirtualFile>& files); | ||
| 66 | void InitializeExeFSAndRomFS(const std::vector<VirtualFile>& files); | 67 | void InitializeExeFSAndRomFS(const std::vector<VirtualFile>& files); |
| 67 | void ReadNCAs(const std::vector<VirtualFile>& files); | 68 | void ReadNCAs(const std::vector<VirtualFile>& files); |
| 68 | 69 | ||
diff --git a/src/core/frontend/emu_window.cpp b/src/core/frontend/emu_window.cpp index 9a081fbd4..8c1193894 100644 --- a/src/core/frontend/emu_window.cpp +++ b/src/core/frontend/emu_window.cpp | |||
| @@ -84,10 +84,12 @@ void EmuWindow::TouchPressed(unsigned framebuffer_x, unsigned framebuffer_y) { | |||
| 84 | return; | 84 | return; |
| 85 | 85 | ||
| 86 | std::lock_guard guard{touch_state->mutex}; | 86 | std::lock_guard guard{touch_state->mutex}; |
| 87 | touch_state->touch_x = static_cast<float>(framebuffer_x - framebuffer_layout.screen.left) / | 87 | touch_state->touch_x = |
| 88 | (framebuffer_layout.screen.right - framebuffer_layout.screen.left); | 88 | static_cast<float>(framebuffer_x - framebuffer_layout.screen.left) / |
| 89 | touch_state->touch_y = static_cast<float>(framebuffer_y - framebuffer_layout.screen.top) / | 89 | static_cast<float>(framebuffer_layout.screen.right - framebuffer_layout.screen.left); |
| 90 | (framebuffer_layout.screen.bottom - framebuffer_layout.screen.top); | 90 | touch_state->touch_y = |
| 91 | static_cast<float>(framebuffer_y - framebuffer_layout.screen.top) / | ||
| 92 | static_cast<float>(framebuffer_layout.screen.bottom - framebuffer_layout.screen.top); | ||
| 91 | 93 | ||
| 92 | touch_state->touch_pressed = true; | 94 | touch_state->touch_pressed = true; |
| 93 | } | 95 | } |
diff --git a/src/core/frontend/framebuffer_layout.cpp b/src/core/frontend/framebuffer_layout.cpp index c1fbc235b..1acc82497 100644 --- a/src/core/frontend/framebuffer_layout.cpp +++ b/src/core/frontend/framebuffer_layout.cpp | |||
| @@ -14,8 +14,8 @@ namespace Layout { | |||
| 14 | template <class T> | 14 | template <class T> |
| 15 | static Common::Rectangle<T> MaxRectangle(Common::Rectangle<T> window_area, | 15 | static Common::Rectangle<T> MaxRectangle(Common::Rectangle<T> window_area, |
| 16 | float screen_aspect_ratio) { | 16 | float screen_aspect_ratio) { |
| 17 | float scale = std::min(static_cast<float>(window_area.GetWidth()), | 17 | const float scale = std::min(static_cast<float>(window_area.GetWidth()), |
| 18 | window_area.GetHeight() / screen_aspect_ratio); | 18 | static_cast<float>(window_area.GetHeight()) / screen_aspect_ratio); |
| 19 | return Common::Rectangle<T>{0, 0, static_cast<T>(std::round(scale)), | 19 | return Common::Rectangle<T>{0, 0, static_cast<T>(std::round(scale)), |
| 20 | static_cast<T>(std::round(scale * screen_aspect_ratio))}; | 20 | static_cast<T>(std::round(scale * screen_aspect_ratio))}; |
| 21 | } | 21 | } |
| @@ -27,7 +27,7 @@ FramebufferLayout DefaultFrameLayout(u32 width, u32 height) { | |||
| 27 | // so just calculate them both even if the other isn't showing. | 27 | // so just calculate them both even if the other isn't showing. |
| 28 | FramebufferLayout res{width, height, false, {}}; | 28 | FramebufferLayout res{width, height, false, {}}; |
| 29 | 29 | ||
| 30 | const float window_aspect_ratio = static_cast<float>(height) / width; | 30 | const float window_aspect_ratio = static_cast<float>(height) / static_cast<float>(width); |
| 31 | const float emulation_aspect_ratio = EmulationAspectRatio( | 31 | const float emulation_aspect_ratio = EmulationAspectRatio( |
| 32 | static_cast<AspectRatio>(Settings::values.aspect_ratio.GetValue()), window_aspect_ratio); | 32 | static_cast<AspectRatio>(Settings::values.aspect_ratio.GetValue()), window_aspect_ratio); |
| 33 | 33 | ||
diff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cpp index 79f22a403..97ee65464 100644 --- a/src/core/gdbstub/gdbstub.cpp +++ b/src/core/gdbstub/gdbstub.cpp | |||
| @@ -291,11 +291,11 @@ static void FpuWrite(std::size_t id, u128 val, Kernel::Thread* thread = nullptr) | |||
| 291 | */ | 291 | */ |
| 292 | static u8 HexCharToValue(u8 hex) { | 292 | static u8 HexCharToValue(u8 hex) { |
| 293 | if (hex >= '0' && hex <= '9') { | 293 | if (hex >= '0' && hex <= '9') { |
| 294 | return hex - '0'; | 294 | return static_cast<u8>(hex - '0'); |
| 295 | } else if (hex >= 'a' && hex <= 'f') { | 295 | } else if (hex >= 'a' && hex <= 'f') { |
| 296 | return hex - 'a' + 0xA; | 296 | return static_cast<u8>(hex - 'a' + 0xA); |
| 297 | } else if (hex >= 'A' && hex <= 'F') { | 297 | } else if (hex >= 'A' && hex <= 'F') { |
| 298 | return hex - 'A' + 0xA; | 298 | return static_cast<u8>(hex - 'A' + 0xA); |
| 299 | } | 299 | } |
| 300 | 300 | ||
| 301 | LOG_ERROR(Debug_GDBStub, "Invalid nibble: {} ({:02X})", hex, hex); | 301 | LOG_ERROR(Debug_GDBStub, "Invalid nibble: {} ({:02X})", hex, hex); |
| @@ -310,9 +310,9 @@ static u8 HexCharToValue(u8 hex) { | |||
| 310 | static u8 NibbleToHex(u8 n) { | 310 | static u8 NibbleToHex(u8 n) { |
| 311 | n &= 0xF; | 311 | n &= 0xF; |
| 312 | if (n < 0xA) { | 312 | if (n < 0xA) { |
| 313 | return '0' + n; | 313 | return static_cast<u8>('0' + n); |
| 314 | } else { | 314 | } else { |
| 315 | return 'a' + n - 0xA; | 315 | return static_cast<u8>('a' + n - 0xA); |
| 316 | } | 316 | } |
| 317 | } | 317 | } |
| 318 | 318 | ||
| @@ -355,8 +355,8 @@ static u64 HexToLong(const u8* src, std::size_t len) { | |||
| 355 | */ | 355 | */ |
| 356 | static void MemToGdbHex(u8* dest, const u8* src, std::size_t len) { | 356 | static void MemToGdbHex(u8* dest, const u8* src, std::size_t len) { |
| 357 | while (len-- > 0) { | 357 | while (len-- > 0) { |
| 358 | u8 tmp = *src++; | 358 | const u8 tmp = *src++; |
| 359 | *dest++ = NibbleToHex(tmp >> 4); | 359 | *dest++ = NibbleToHex(static_cast<u8>(tmp >> 4)); |
| 360 | *dest++ = NibbleToHex(tmp); | 360 | *dest++ = NibbleToHex(tmp); |
| 361 | } | 361 | } |
| 362 | } | 362 | } |
| @@ -370,7 +370,7 @@ static void MemToGdbHex(u8* dest, const u8* src, std::size_t len) { | |||
| 370 | */ | 370 | */ |
| 371 | static void GdbHexToMem(u8* dest, const u8* src, std::size_t len) { | 371 | static void GdbHexToMem(u8* dest, const u8* src, std::size_t len) { |
| 372 | while (len-- > 0) { | 372 | while (len-- > 0) { |
| 373 | *dest++ = (HexCharToValue(src[0]) << 4) | HexCharToValue(src[1]); | 373 | *dest++ = static_cast<u8>((HexCharToValue(src[0]) << 4) | HexCharToValue(src[1])); |
| 374 | src += 2; | 374 | src += 2; |
| 375 | } | 375 | } |
| 376 | } | 376 | } |
| @@ -602,22 +602,22 @@ static void SendReply(const char* reply) { | |||
| 602 | 602 | ||
| 603 | memcpy(command_buffer + 1, reply, command_length); | 603 | memcpy(command_buffer + 1, reply, command_length); |
| 604 | 604 | ||
| 605 | u8 checksum = CalculateChecksum(command_buffer, command_length + 1); | 605 | const u8 checksum = CalculateChecksum(command_buffer, command_length + 1); |
| 606 | command_buffer[0] = GDB_STUB_START; | 606 | command_buffer[0] = GDB_STUB_START; |
| 607 | command_buffer[command_length + 1] = GDB_STUB_END; | 607 | command_buffer[command_length + 1] = GDB_STUB_END; |
| 608 | command_buffer[command_length + 2] = NibbleToHex(checksum >> 4); | 608 | command_buffer[command_length + 2] = NibbleToHex(static_cast<u8>(checksum >> 4)); |
| 609 | command_buffer[command_length + 3] = NibbleToHex(checksum); | 609 | command_buffer[command_length + 3] = NibbleToHex(checksum); |
| 610 | 610 | ||
| 611 | u8* ptr = command_buffer; | 611 | u8* ptr = command_buffer; |
| 612 | u32 left = command_length + 4; | 612 | u32 left = command_length + 4; |
| 613 | while (left > 0) { | 613 | while (left > 0) { |
| 614 | int sent_size = send(gdbserver_socket, reinterpret_cast<char*>(ptr), left, 0); | 614 | const auto sent_size = send(gdbserver_socket, reinterpret_cast<char*>(ptr), left, 0); |
| 615 | if (sent_size < 0) { | 615 | if (sent_size < 0) { |
| 616 | LOG_ERROR(Debug_GDBStub, "gdb: send failed"); | 616 | LOG_ERROR(Debug_GDBStub, "gdb: send failed"); |
| 617 | return Shutdown(); | 617 | return Shutdown(); |
| 618 | } | 618 | } |
| 619 | 619 | ||
| 620 | left -= sent_size; | 620 | left -= static_cast<u32>(sent_size); |
| 621 | ptr += sent_size; | 621 | ptr += sent_size; |
| 622 | } | 622 | } |
| 623 | } | 623 | } |
| @@ -777,10 +777,10 @@ static void ReadCommand() { | |||
| 777 | command_buffer[command_length++] = c; | 777 | command_buffer[command_length++] = c; |
| 778 | } | 778 | } |
| 779 | 779 | ||
| 780 | u8 checksum_received = HexCharToValue(ReadByte()) << 4; | 780 | auto checksum_received = static_cast<u32>(HexCharToValue(ReadByte()) << 4); |
| 781 | checksum_received |= HexCharToValue(ReadByte()); | 781 | checksum_received |= static_cast<u32>(HexCharToValue(ReadByte())); |
| 782 | 782 | ||
| 783 | u8 checksum_calculated = CalculateChecksum(command_buffer, command_length); | 783 | const u32 checksum_calculated = CalculateChecksum(command_buffer, command_length); |
| 784 | 784 | ||
| 785 | if (checksum_received != checksum_calculated) { | 785 | if (checksum_received != checksum_calculated) { |
| 786 | LOG_ERROR(Debug_GDBStub, | 786 | LOG_ERROR(Debug_GDBStub, |
diff --git a/src/core/hle/ipc_helpers.h b/src/core/hle/ipc_helpers.h index 1b503331f..1c354037d 100644 --- a/src/core/hle/ipc_helpers.h +++ b/src/core/hle/ipc_helpers.h | |||
| @@ -38,10 +38,11 @@ public: | |||
| 38 | explicit RequestHelperBase(Kernel::HLERequestContext& context) | 38 | explicit RequestHelperBase(Kernel::HLERequestContext& context) |
| 39 | : context(&context), cmdbuf(context.CommandBuffer()) {} | 39 | : context(&context), cmdbuf(context.CommandBuffer()) {} |
| 40 | 40 | ||
| 41 | void Skip(unsigned size_in_words, bool set_to_null) { | 41 | void Skip(u32 size_in_words, bool set_to_null) { |
| 42 | if (set_to_null) | 42 | if (set_to_null) { |
| 43 | memset(cmdbuf + index, 0, size_in_words * sizeof(u32)); | 43 | memset(cmdbuf + index, 0, size_in_words * sizeof(u32)); |
| 44 | index += size_in_words; | 44 | } |
| 45 | index += static_cast<ptrdiff_t>(size_in_words); | ||
| 45 | } | 46 | } |
| 46 | 47 | ||
| 47 | /** | 48 | /** |
| @@ -49,15 +50,15 @@ public: | |||
| 49 | */ | 50 | */ |
| 50 | void AlignWithPadding() { | 51 | void AlignWithPadding() { |
| 51 | if (index & 3) { | 52 | if (index & 3) { |
| 52 | Skip(4 - (index & 3), true); | 53 | Skip(static_cast<u32>(4 - (index & 3)), true); |
| 53 | } | 54 | } |
| 54 | } | 55 | } |
| 55 | 56 | ||
| 56 | unsigned GetCurrentOffset() const { | 57 | u32 GetCurrentOffset() const { |
| 57 | return static_cast<unsigned>(index); | 58 | return static_cast<u32>(index); |
| 58 | } | 59 | } |
| 59 | 60 | ||
| 60 | void SetCurrentOffset(unsigned offset) { | 61 | void SetCurrentOffset(u32 offset) { |
| 61 | index = static_cast<ptrdiff_t>(offset); | 62 | index = static_cast<ptrdiff_t>(offset); |
| 62 | } | 63 | } |
| 63 | }; | 64 | }; |
| @@ -89,7 +90,7 @@ public: | |||
| 89 | 90 | ||
| 90 | // The entire size of the raw data section in u32 units, including the 16 bytes of mandatory | 91 | // The entire size of the raw data section in u32 units, including the 16 bytes of mandatory |
| 91 | // padding. | 92 | // padding. |
| 92 | u32 raw_data_size = sizeof(IPC::DataPayloadHeader) / 4 + 4 + normal_params_size; | 93 | u64 raw_data_size = sizeof(IPC::DataPayloadHeader) / 4 + 4 + normal_params_size; |
| 93 | 94 | ||
| 94 | u32 num_handles_to_move{}; | 95 | u32 num_handles_to_move{}; |
| 95 | u32 num_domain_objects{}; | 96 | u32 num_domain_objects{}; |
| @@ -105,7 +106,7 @@ public: | |||
| 105 | raw_data_size += sizeof(DomainMessageHeader) / 4 + num_domain_objects; | 106 | raw_data_size += sizeof(DomainMessageHeader) / 4 + num_domain_objects; |
| 106 | } | 107 | } |
| 107 | 108 | ||
| 108 | header.data_size.Assign(raw_data_size); | 109 | header.data_size.Assign(static_cast<u32>(raw_data_size)); |
| 109 | if (num_handles_to_copy || num_handles_to_move) { | 110 | if (num_handles_to_copy || num_handles_to_move) { |
| 110 | header.enable_handle_descriptor.Assign(1); | 111 | header.enable_handle_descriptor.Assign(1); |
| 111 | } | 112 | } |
diff --git a/src/core/hle/kernel/handle_table.cpp b/src/core/hle/kernel/handle_table.cpp index fb30b6f8b..3e745c18b 100644 --- a/src/core/hle/kernel/handle_table.cpp +++ b/src/core/hle/kernel/handle_table.cpp | |||
| @@ -118,7 +118,7 @@ std::shared_ptr<Object> HandleTable::GetGeneric(Handle handle) const { | |||
| 118 | 118 | ||
| 119 | void HandleTable::Clear() { | 119 | void HandleTable::Clear() { |
| 120 | for (u16 i = 0; i < table_size; ++i) { | 120 | for (u16 i = 0; i < table_size; ++i) { |
| 121 | generations[i] = i + 1; | 121 | generations[i] = static_cast<u16>(i + 1); |
| 122 | objects[i] = nullptr; | 122 | objects[i] = nullptr; |
| 123 | } | 123 | } |
| 124 | next_free_slot = 0; | 124 | next_free_slot = 0; |
diff --git a/src/core/hle/kernel/scheduler.cpp b/src/core/hle/kernel/scheduler.cpp index 5cbd3b912..6b7db5372 100644 --- a/src/core/hle/kernel/scheduler.cpp +++ b/src/core/hle/kernel/scheduler.cpp | |||
| @@ -72,7 +72,7 @@ u32 GlobalScheduler::SelectThreads() { | |||
| 72 | if (top_thread != nullptr) { | 72 | if (top_thread != nullptr) { |
| 73 | // TODO(Blinkhawk): Implement Thread Pinning | 73 | // TODO(Blinkhawk): Implement Thread Pinning |
| 74 | } else { | 74 | } else { |
| 75 | idle_cores |= (1ul << core); | 75 | idle_cores |= (1U << core); |
| 76 | } | 76 | } |
| 77 | top_threads[core] = top_thread; | 77 | top_threads[core] = top_thread; |
| 78 | } | 78 | } |
| @@ -126,7 +126,7 @@ u32 GlobalScheduler::SelectThreads() { | |||
| 126 | top_threads[core_id] = suggested; | 126 | top_threads[core_id] = suggested; |
| 127 | } | 127 | } |
| 128 | 128 | ||
| 129 | idle_cores &= ~(1ul << core_id); | 129 | idle_cores &= ~(1U << core_id); |
| 130 | } | 130 | } |
| 131 | u32 cores_needing_context_switch{}; | 131 | u32 cores_needing_context_switch{}; |
| 132 | for (u32 core = 0; core < Core::Hardware::NUM_CPU_CORES; core++) { | 132 | for (u32 core = 0; core < Core::Hardware::NUM_CPU_CORES; core++) { |
| @@ -134,7 +134,7 @@ u32 GlobalScheduler::SelectThreads() { | |||
| 134 | ASSERT(top_threads[core] == nullptr || | 134 | ASSERT(top_threads[core] == nullptr || |
| 135 | static_cast<u32>(top_threads[core]->GetProcessorID()) == core); | 135 | static_cast<u32>(top_threads[core]->GetProcessorID()) == core); |
| 136 | if (update_thread(top_threads[core], sched)) { | 136 | if (update_thread(top_threads[core], sched)) { |
| 137 | cores_needing_context_switch |= (1ul << core); | 137 | cores_needing_context_switch |= (1U << core); |
| 138 | } | 138 | } |
| 139 | } | 139 | } |
| 140 | return cores_needing_context_switch; | 140 | return cores_needing_context_switch; |
| @@ -364,7 +364,7 @@ void GlobalScheduler::EnableInterruptAndSchedule(u32 cores_pending_reschedule, | |||
| 364 | } else { | 364 | } else { |
| 365 | must_context_switch = true; | 365 | must_context_switch = true; |
| 366 | } | 366 | } |
| 367 | cores_pending_reschedule &= ~(1ul << core); | 367 | cores_pending_reschedule &= ~(1U << core); |
| 368 | } | 368 | } |
| 369 | if (must_context_switch) { | 369 | if (must_context_switch) { |
| 370 | auto& core_scheduler = kernel.CurrentScheduler(); | 370 | auto& core_scheduler = kernel.CurrentScheduler(); |
| @@ -767,7 +767,7 @@ void Scheduler::SwitchToCurrent() { | |||
| 767 | current_thread->context_guard.unlock(); | 767 | current_thread->context_guard.unlock(); |
| 768 | break; | 768 | break; |
| 769 | } | 769 | } |
| 770 | if (current_thread->GetProcessorID() != core_id) { | 770 | if (static_cast<u32>(current_thread->GetProcessorID()) != core_id) { |
| 771 | current_thread->context_guard.unlock(); | 771 | current_thread->context_guard.unlock(); |
| 772 | break; | 772 | break; |
| 773 | } | 773 | } |
diff --git a/src/core/hle/service/acc/acc.cpp b/src/core/hle/service/acc/acc.cpp index 6b1613510..2850dd805 100644 --- a/src/core/hle/service/acc/acc.cpp +++ b/src/core/hle/service/acc/acc.cpp | |||
| @@ -496,7 +496,7 @@ public: | |||
| 496 | {3, nullptr, "LoadIdTokenCache"}, | 496 | {3, nullptr, "LoadIdTokenCache"}, |
| 497 | {130, nullptr, "GetNintendoAccountUserResourceCacheForApplication"}, | 497 | {130, nullptr, "GetNintendoAccountUserResourceCacheForApplication"}, |
| 498 | {150, nullptr, "CreateAuthorizationRequest"}, | 498 | {150, nullptr, "CreateAuthorizationRequest"}, |
| 499 | {160, nullptr, "StoreOpenContext"}, | 499 | {160, &IManagerForApplication::StoreOpenContext, "StoreOpenContext"}, |
| 500 | {170, nullptr, "LoadNetworkServiceLicenseKindAsync"}, | 500 | {170, nullptr, "LoadNetworkServiceLicenseKindAsync"}, |
| 501 | }; | 501 | }; |
| 502 | // clang-format on | 502 | // clang-format on |
| @@ -520,6 +520,12 @@ private: | |||
| 520 | rb.PushRaw<u64>(user_id.GetNintendoID()); | 520 | rb.PushRaw<u64>(user_id.GetNintendoID()); |
| 521 | } | 521 | } |
| 522 | 522 | ||
| 523 | void StoreOpenContext(Kernel::HLERequestContext& ctx) { | ||
| 524 | LOG_WARNING(Service_ACC, "(STUBBED) called"); | ||
| 525 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 526 | rb.Push(RESULT_SUCCESS); | ||
| 527 | } | ||
| 528 | |||
| 523 | Common::UUID user_id; | 529 | Common::UUID user_id; |
| 524 | }; | 530 | }; |
| 525 | 531 | ||
diff --git a/src/core/hle/service/bcat/backend/boxcat.cpp b/src/core/hle/service/bcat/backend/boxcat.cpp index ca021a99f..3b6f7498e 100644 --- a/src/core/hle/service/bcat/backend/boxcat.cpp +++ b/src/core/hle/service/bcat/backend/boxcat.cpp | |||
| @@ -196,7 +196,9 @@ private: | |||
| 196 | const std::string& content_type_name) { | 196 | const std::string& content_type_name) { |
| 197 | if (client == nullptr) { | 197 | if (client == nullptr) { |
| 198 | client = std::make_unique<httplib::SSLClient>(BOXCAT_HOSTNAME, PORT); | 198 | client = std::make_unique<httplib::SSLClient>(BOXCAT_HOSTNAME, PORT); |
| 199 | client->set_timeout_sec(timeout_seconds); | 199 | client->set_connection_timeout(timeout_seconds); |
| 200 | client->set_read_timeout(timeout_seconds); | ||
| 201 | client->set_write_timeout(timeout_seconds); | ||
| 200 | } | 202 | } |
| 201 | 203 | ||
| 202 | httplib::Headers headers{ | 204 | httplib::Headers headers{ |
| @@ -255,7 +257,7 @@ private: | |||
| 255 | return out; | 257 | return out; |
| 256 | } | 258 | } |
| 257 | 259 | ||
| 258 | std::unique_ptr<httplib::Client> client; | 260 | std::unique_ptr<httplib::SSLClient> client; |
| 259 | std::string path; | 261 | std::string path; |
| 260 | u64 title_id; | 262 | u64 title_id; |
| 261 | u64 build_id; | 263 | u64 build_id; |
| @@ -443,13 +445,25 @@ std::optional<std::vector<u8>> Boxcat::GetLaunchParameter(TitleIDVersion title) | |||
| 443 | Boxcat::StatusResult Boxcat::GetStatus(std::optional<std::string>& global, | 445 | Boxcat::StatusResult Boxcat::GetStatus(std::optional<std::string>& global, |
| 444 | std::map<std::string, EventStatus>& games) { | 446 | std::map<std::string, EventStatus>& games) { |
| 445 | httplib::SSLClient client{BOXCAT_HOSTNAME, static_cast<int>(PORT)}; | 447 | httplib::SSLClient client{BOXCAT_HOSTNAME, static_cast<int>(PORT)}; |
| 446 | client.set_timeout_sec(static_cast<int>(TIMEOUT_SECONDS)); | 448 | client.set_connection_timeout(static_cast<int>(TIMEOUT_SECONDS)); |
| 449 | client.set_read_timeout(static_cast<int>(TIMEOUT_SECONDS)); | ||
| 450 | client.set_write_timeout(static_cast<int>(TIMEOUT_SECONDS)); | ||
| 447 | 451 | ||
| 448 | httplib::Headers headers{ | 452 | httplib::Headers headers{ |
| 449 | {std::string("Game-Assets-API-Version"), std::string(BOXCAT_API_VERSION)}, | 453 | {std::string("Game-Assets-API-Version"), std::string(BOXCAT_API_VERSION)}, |
| 450 | {std::string("Boxcat-Client-Type"), std::string(BOXCAT_CLIENT_TYPE)}, | 454 | {std::string("Boxcat-Client-Type"), std::string(BOXCAT_CLIENT_TYPE)}, |
| 451 | }; | 455 | }; |
| 452 | 456 | ||
| 457 | if (!client.is_valid()) { | ||
| 458 | LOG_ERROR(Service_BCAT, "Client is invalid, going offline!"); | ||
| 459 | return StatusResult::Offline; | ||
| 460 | } | ||
| 461 | |||
| 462 | if (!client.is_socket_open()) { | ||
| 463 | LOG_ERROR(Service_BCAT, "Failed to open socket, going offline!"); | ||
| 464 | return StatusResult::Offline; | ||
| 465 | } | ||
| 466 | |||
| 453 | const auto response = client.Get(BOXCAT_PATHNAME_EVENTS, headers); | 467 | const auto response = client.Get(BOXCAT_PATHNAME_EVENTS, headers); |
| 454 | if (response == nullptr) | 468 | if (response == nullptr) |
| 455 | return StatusResult::Offline; | 469 | return StatusResult::Offline; |
diff --git a/src/core/hle/service/hid/controllers/keyboard.cpp b/src/core/hle/service/hid/controllers/keyboard.cpp index 0b896d5ad..59b694cd4 100644 --- a/src/core/hle/service/hid/controllers/keyboard.cpp +++ b/src/core/hle/service/hid/controllers/keyboard.cpp | |||
| @@ -42,8 +42,8 @@ void Controller_Keyboard::OnUpdate(const Core::Timing::CoreTiming& core_timing, | |||
| 42 | cur_entry.modifier = 0; | 42 | cur_entry.modifier = 0; |
| 43 | if (Settings::values.keyboard_enabled) { | 43 | if (Settings::values.keyboard_enabled) { |
| 44 | for (std::size_t i = 0; i < keyboard_keys.size(); ++i) { | 44 | for (std::size_t i = 0; i < keyboard_keys.size(); ++i) { |
| 45 | cur_entry.key[i / KEYS_PER_BYTE] |= | 45 | auto& entry = cur_entry.key[i / KEYS_PER_BYTE]; |
| 46 | (keyboard_keys[i]->GetStatus() << (i % KEYS_PER_BYTE)); | 46 | entry = static_cast<u8>(entry | (keyboard_keys[i]->GetStatus() << (i % KEYS_PER_BYTE))); |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | for (std::size_t i = 0; i < keyboard_mods.size(); ++i) { | 49 | for (std::size_t i = 0; i < keyboard_mods.size(); ++i) { |
diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp index 2de4ed348..e311bc18c 100644 --- a/src/core/hle/service/hid/controllers/npad.cpp +++ b/src/core/hle/service/hid/controllers/npad.cpp | |||
| @@ -269,7 +269,6 @@ void Controller_NPad::RequestPadStateUpdate(u32 npad_id) { | |||
| 269 | auto& rstick_entry = npad_pad_states[controller_idx].r_stick; | 269 | auto& rstick_entry = npad_pad_states[controller_idx].r_stick; |
| 270 | const auto& button_state = buttons[controller_idx]; | 270 | const auto& button_state = buttons[controller_idx]; |
| 271 | const auto& analog_state = sticks[controller_idx]; | 271 | const auto& analog_state = sticks[controller_idx]; |
| 272 | const auto& motion_state = motions[controller_idx]; | ||
| 273 | const auto [stick_l_x_f, stick_l_y_f] = | 272 | const auto [stick_l_x_f, stick_l_y_f] = |
| 274 | analog_state[static_cast<std::size_t>(JoystickId::Joystick_Left)]->GetStatus(); | 273 | analog_state[static_cast<std::size_t>(JoystickId::Joystick_Left)]->GetStatus(); |
| 275 | const auto [stick_r_x_f, stick_r_y_f] = | 274 | const auto [stick_r_x_f, stick_r_y_f] = |
| @@ -391,18 +390,6 @@ void Controller_NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* | |||
| 391 | 390 | ||
| 392 | libnx_entry.connection_status.raw = 0; | 391 | libnx_entry.connection_status.raw = 0; |
| 393 | libnx_entry.connection_status.IsConnected.Assign(1); | 392 | libnx_entry.connection_status.IsConnected.Assign(1); |
| 394 | auto& full_sixaxis_entry = | ||
| 395 | npad.sixaxis_full.sixaxis[npad.sixaxis_full.common.last_entry_index]; | ||
| 396 | auto& handheld_sixaxis_entry = | ||
| 397 | npad.sixaxis_handheld.sixaxis[npad.sixaxis_handheld.common.last_entry_index]; | ||
| 398 | auto& dual_left_sixaxis_entry = | ||
| 399 | npad.sixaxis_dual_left.sixaxis[npad.sixaxis_dual_left.common.last_entry_index]; | ||
| 400 | auto& dual_right_sixaxis_entry = | ||
| 401 | npad.sixaxis_dual_right.sixaxis[npad.sixaxis_dual_right.common.last_entry_index]; | ||
| 402 | auto& left_sixaxis_entry = | ||
| 403 | npad.sixaxis_left.sixaxis[npad.sixaxis_left.common.last_entry_index]; | ||
| 404 | auto& right_sixaxis_entry = | ||
| 405 | npad.sixaxis_right.sixaxis[npad.sixaxis_right.common.last_entry_index]; | ||
| 406 | 393 | ||
| 407 | switch (controller_type) { | 394 | switch (controller_type) { |
| 408 | case NPadControllerType::None: | 395 | case NPadControllerType::None: |
| @@ -541,18 +528,6 @@ void Controller_NPad::OnMotionUpdate(const Core::Timing::CoreTiming& core_timing | |||
| 541 | } | 528 | } |
| 542 | } | 529 | } |
| 543 | 530 | ||
| 544 | auto& main_controller = | ||
| 545 | npad.main_controller_states.npad[npad.main_controller_states.common.last_entry_index]; | ||
| 546 | auto& handheld_entry = | ||
| 547 | npad.handheld_states.npad[npad.handheld_states.common.last_entry_index]; | ||
| 548 | auto& dual_entry = npad.dual_states.npad[npad.dual_states.common.last_entry_index]; | ||
| 549 | auto& left_entry = npad.left_joy_states.npad[npad.left_joy_states.common.last_entry_index]; | ||
| 550 | auto& right_entry = | ||
| 551 | npad.right_joy_states.npad[npad.right_joy_states.common.last_entry_index]; | ||
| 552 | auto& pokeball_entry = | ||
| 553 | npad.pokeball_states.npad[npad.pokeball_states.common.last_entry_index]; | ||
| 554 | auto& libnx_entry = npad.libnx.npad[npad.libnx.common.last_entry_index]; | ||
| 555 | |||
| 556 | auto& full_sixaxis_entry = | 531 | auto& full_sixaxis_entry = |
| 557 | npad.sixaxis_full.sixaxis[npad.sixaxis_full.common.last_entry_index]; | 532 | npad.sixaxis_full.sixaxis[npad.sixaxis_full.common.last_entry_index]; |
| 558 | auto& handheld_sixaxis_entry = | 533 | auto& handheld_sixaxis_entry = |
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index 71dbaba7f..8918946a1 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp | |||
| @@ -475,7 +475,7 @@ void Hid::StopSixAxisSensor(Kernel::HLERequestContext& ctx) { | |||
| 475 | 475 | ||
| 476 | void Hid::EnableSixAxisSensorFusion(Kernel::HLERequestContext& ctx) { | 476 | void Hid::EnableSixAxisSensorFusion(Kernel::HLERequestContext& ctx) { |
| 477 | IPC::RequestParser rp{ctx}; | 477 | IPC::RequestParser rp{ctx}; |
| 478 | const auto enable{rp.Pop<bool>()}; | 478 | [[maybe_unused]] const auto enable{rp.Pop<bool>()}; |
| 479 | const auto handle{rp.Pop<u32>()}; | 479 | const auto handle{rp.Pop<u32>()}; |
| 480 | const auto applet_resource_user_id{rp.Pop<u64>()}; | 480 | const auto applet_resource_user_id{rp.Pop<u64>()}; |
| 481 | 481 | ||
diff --git a/src/core/hle/service/mii/manager.cpp b/src/core/hle/service/mii/manager.cpp index 4730070cb..8e433eb41 100644 --- a/src/core/hle/service/mii/manager.cpp +++ b/src/core/hle/service/mii/manager.cpp | |||
| @@ -428,7 +428,7 @@ bool MiiManager::IsFullDatabase() const { | |||
| 428 | } | 428 | } |
| 429 | 429 | ||
| 430 | u32 MiiManager::GetCount(SourceFlag source_flag) const { | 430 | u32 MiiManager::GetCount(SourceFlag source_flag) const { |
| 431 | u32 count{}; | 431 | std::size_t count{}; |
| 432 | if ((source_flag & SourceFlag::Database) != SourceFlag::None) { | 432 | if ((source_flag & SourceFlag::Database) != SourceFlag::None) { |
| 433 | // TODO(bunnei): We don't implement the Mii database, but when we do, update this | 433 | // TODO(bunnei): We don't implement the Mii database, but when we do, update this |
| 434 | count += 0; | 434 | count += 0; |
| @@ -436,7 +436,7 @@ u32 MiiManager::GetCount(SourceFlag source_flag) const { | |||
| 436 | if ((source_flag & SourceFlag::Default) != SourceFlag::None) { | 436 | if ((source_flag & SourceFlag::Default) != SourceFlag::None) { |
| 437 | count += DefaultMiiCount; | 437 | count += DefaultMiiCount; |
| 438 | } | 438 | } |
| 439 | return count; | 439 | return static_cast<u32>(count); |
| 440 | } | 440 | } |
| 441 | 441 | ||
| 442 | ResultVal<MiiInfo> MiiManager::UpdateLatest([[maybe_unused]] const MiiInfo& info, | 442 | ResultVal<MiiInfo> MiiManager::UpdateLatest([[maybe_unused]] const MiiInfo& info, |
diff --git a/src/core/hle/service/nvflinger/buffer_queue.cpp b/src/core/hle/service/nvflinger/buffer_queue.cpp index 637b310d7..4f1e210b1 100644 --- a/src/core/hle/service/nvflinger/buffer_queue.cpp +++ b/src/core/hle/service/nvflinger/buffer_queue.cpp | |||
| @@ -99,6 +99,20 @@ void BufferQueue::QueueBuffer(u32 slot, BufferTransformFlags transform, | |||
| 99 | queue_sequence.push_back(slot); | 99 | queue_sequence.push_back(slot); |
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | void BufferQueue::CancelBuffer(u32 slot, const Service::Nvidia::MultiFence& multi_fence) { | ||
| 103 | const auto itr = std::find_if(queue.begin(), queue.end(), | ||
| 104 | [slot](const Buffer& buffer) { return buffer.slot == slot; }); | ||
| 105 | ASSERT(itr != queue.end()); | ||
| 106 | ASSERT(itr->status != Buffer::Status::Free); | ||
| 107 | itr->status = Buffer::Status::Free; | ||
| 108 | itr->multi_fence = multi_fence; | ||
| 109 | itr->swap_interval = 0; | ||
| 110 | |||
| 111 | free_buffers.push_back(slot); | ||
| 112 | |||
| 113 | buffer_wait_event.writable->Signal(); | ||
| 114 | } | ||
| 115 | |||
| 102 | std::optional<std::reference_wrapper<const BufferQueue::Buffer>> BufferQueue::AcquireBuffer() { | 116 | std::optional<std::reference_wrapper<const BufferQueue::Buffer>> BufferQueue::AcquireBuffer() { |
| 103 | auto itr = queue.end(); | 117 | auto itr = queue.end(); |
| 104 | // Iterate to find a queued buffer matching the requested slot. | 118 | // Iterate to find a queued buffer matching the requested slot. |
diff --git a/src/core/hle/service/nvflinger/buffer_queue.h b/src/core/hle/service/nvflinger/buffer_queue.h index 8a837e5aa..e7517c7e1 100644 --- a/src/core/hle/service/nvflinger/buffer_queue.h +++ b/src/core/hle/service/nvflinger/buffer_queue.h | |||
| @@ -95,6 +95,7 @@ public: | |||
| 95 | void QueueBuffer(u32 slot, BufferTransformFlags transform, | 95 | void QueueBuffer(u32 slot, BufferTransformFlags transform, |
| 96 | const Common::Rectangle<int>& crop_rect, u32 swap_interval, | 96 | const Common::Rectangle<int>& crop_rect, u32 swap_interval, |
| 97 | Service::Nvidia::MultiFence& multi_fence); | 97 | Service::Nvidia::MultiFence& multi_fence); |
| 98 | void CancelBuffer(u32 slot, const Service::Nvidia::MultiFence& multi_fence); | ||
| 98 | std::optional<std::reference_wrapper<const Buffer>> AcquireBuffer(); | 99 | std::optional<std::reference_wrapper<const Buffer>> AcquireBuffer(); |
| 99 | void ReleaseBuffer(u32 slot); | 100 | void ReleaseBuffer(u32 slot); |
| 100 | void Disconnect(); | 101 | void Disconnect(); |
diff --git a/src/core/hle/service/sockets/sockets_translate.cpp b/src/core/hle/service/sockets/sockets_translate.cpp index 139743e1d..2e626fd86 100644 --- a/src/core/hle/service/sockets/sockets_translate.cpp +++ b/src/core/hle/service/sockets/sockets_translate.cpp | |||
| @@ -89,9 +89,9 @@ Network::Protocol Translate(Type type, Protocol protocol) { | |||
| 89 | } | 89 | } |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | u16 TranslatePollEventsToHost(u16 flags) { | 92 | u16 TranslatePollEventsToHost(u32 flags) { |
| 93 | u16 result = 0; | 93 | u32 result = 0; |
| 94 | const auto translate = [&result, &flags](u16 from, u16 to) { | 94 | const auto translate = [&result, &flags](u32 from, u32 to) { |
| 95 | if ((flags & from) != 0) { | 95 | if ((flags & from) != 0) { |
| 96 | flags &= ~from; | 96 | flags &= ~from; |
| 97 | result |= to; | 97 | result |= to; |
| @@ -105,12 +105,12 @@ u16 TranslatePollEventsToHost(u16 flags) { | |||
| 105 | translate(POLL_NVAL, Network::POLL_NVAL); | 105 | translate(POLL_NVAL, Network::POLL_NVAL); |
| 106 | 106 | ||
| 107 | UNIMPLEMENTED_IF_MSG(flags != 0, "Unimplemented flags={}", flags); | 107 | UNIMPLEMENTED_IF_MSG(flags != 0, "Unimplemented flags={}", flags); |
| 108 | return result; | 108 | return static_cast<u16>(result); |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | u16 TranslatePollEventsToGuest(u16 flags) { | 111 | u16 TranslatePollEventsToGuest(u32 flags) { |
| 112 | u16 result = 0; | 112 | u32 result = 0; |
| 113 | const auto translate = [&result, &flags](u16 from, u16 to) { | 113 | const auto translate = [&result, &flags](u32 from, u32 to) { |
| 114 | if ((flags & from) != 0) { | 114 | if ((flags & from) != 0) { |
| 115 | flags &= ~from; | 115 | flags &= ~from; |
| 116 | result |= to; | 116 | result |= to; |
| @@ -125,7 +125,7 @@ u16 TranslatePollEventsToGuest(u16 flags) { | |||
| 125 | translate(Network::POLL_NVAL, POLL_NVAL); | 125 | translate(Network::POLL_NVAL, POLL_NVAL); |
| 126 | 126 | ||
| 127 | UNIMPLEMENTED_IF_MSG(flags != 0, "Unimplemented flags={}", flags); | 127 | UNIMPLEMENTED_IF_MSG(flags != 0, "Unimplemented flags={}", flags); |
| 128 | return result; | 128 | return static_cast<u16>(result); |
| 129 | } | 129 | } |
| 130 | 130 | ||
| 131 | Network::SockAddrIn Translate(SockAddrIn value) { | 131 | Network::SockAddrIn Translate(SockAddrIn value) { |
diff --git a/src/core/hle/service/sockets/sockets_translate.h b/src/core/hle/service/sockets/sockets_translate.h index 8ed041e31..e498913d4 100644 --- a/src/core/hle/service/sockets/sockets_translate.h +++ b/src/core/hle/service/sockets/sockets_translate.h | |||
| @@ -31,10 +31,10 @@ Network::Type Translate(Type type); | |||
| 31 | Network::Protocol Translate(Type type, Protocol protocol); | 31 | Network::Protocol Translate(Type type, Protocol protocol); |
| 32 | 32 | ||
| 33 | /// Translate abstract poll event flags to guest poll event flags | 33 | /// Translate abstract poll event flags to guest poll event flags |
| 34 | u16 TranslatePollEventsToHost(u16 flags); | 34 | u16 TranslatePollEventsToHost(u32 flags); |
| 35 | 35 | ||
| 36 | /// Translate guest poll event flags to abstract poll event flags | 36 | /// Translate guest poll event flags to abstract poll event flags |
| 37 | u16 TranslatePollEventsToGuest(u16 flags); | 37 | u16 TranslatePollEventsToGuest(u32 flags); |
| 38 | 38 | ||
| 39 | /// Translate guest socket address structure to abstract socket address structure | 39 | /// Translate guest socket address structure to abstract socket address structure |
| 40 | Network::SockAddrIn Translate(SockAddrIn value); | 40 | Network::SockAddrIn Translate(SockAddrIn value); |
diff --git a/src/core/hle/service/time/time_zone_manager.cpp b/src/core/hle/service/time/time_zone_manager.cpp index 69152d0ac..bdf0439f2 100644 --- a/src/core/hle/service/time/time_zone_manager.cpp +++ b/src/core/hle/service/time/time_zone_manager.cpp | |||
| @@ -820,7 +820,10 @@ static ResultCode ToCalendarTimeImpl(const TimeZoneRule& rules, s64 time, Calend | |||
| 820 | const ResultCode result{ | 820 | const ResultCode result{ |
| 821 | ToCalendarTimeInternal(rules, time, calendar_time, calendar.additiona_info)}; | 821 | ToCalendarTimeInternal(rules, time, calendar_time, calendar.additiona_info)}; |
| 822 | calendar.time.year = static_cast<s16>(calendar_time.year); | 822 | calendar.time.year = static_cast<s16>(calendar_time.year); |
| 823 | calendar.time.month = calendar_time.month + 1; // Internal impl. uses 0-indexed month | 823 | |
| 824 | // Internal impl. uses 0-indexed month | ||
| 825 | calendar.time.month = static_cast<s8>(calendar_time.month + 1); | ||
| 826 | |||
| 824 | calendar.time.day = calendar_time.day; | 827 | calendar.time.day = calendar_time.day; |
| 825 | calendar.time.hour = calendar_time.hour; | 828 | calendar.time.hour = calendar_time.hour; |
| 826 | calendar.time.minute = calendar_time.minute; | 829 | calendar.time.minute = calendar_time.minute; |
| @@ -872,13 +875,15 @@ ResultCode TimeZoneManager::ToPosixTime(const TimeZoneRule& rules, | |||
| 872 | const CalendarTime& calendar_time, s64& posix_time) const { | 875 | const CalendarTime& calendar_time, s64& posix_time) const { |
| 873 | posix_time = 0; | 876 | posix_time = 0; |
| 874 | 877 | ||
| 875 | CalendarTimeInternal internal_time{}; | 878 | CalendarTimeInternal internal_time{ |
| 876 | internal_time.year = calendar_time.year; | 879 | .year = calendar_time.year, |
| 877 | internal_time.month = calendar_time.month - 1; // Internal impl. uses 0-indexed month | 880 | // Internal impl. uses 0-indexed month |
| 878 | internal_time.day = calendar_time.day; | 881 | .month = static_cast<s8>(calendar_time.month - 1), |
| 879 | internal_time.hour = calendar_time.hour; | 882 | .day = calendar_time.day, |
| 880 | internal_time.minute = calendar_time.minute; | 883 | .hour = calendar_time.hour, |
| 881 | internal_time.second = calendar_time.second; | 884 | .minute = calendar_time.minute, |
| 885 | .second = calendar_time.second, | ||
| 886 | }; | ||
| 882 | 887 | ||
| 883 | s32 hour{internal_time.hour}; | 888 | s32 hour{internal_time.hour}; |
| 884 | s32 minute{internal_time.minute}; | 889 | s32 minute{internal_time.minute}; |
diff --git a/src/core/hle/service/vi/vi.cpp b/src/core/hle/service/vi/vi.cpp index 480d34725..5b0e371fe 100644 --- a/src/core/hle/service/vi/vi.cpp +++ b/src/core/hle/service/vi/vi.cpp | |||
| @@ -159,7 +159,7 @@ public: | |||
| 159 | header.data_size = static_cast<u32_le>(write_index - sizeof(Header)); | 159 | header.data_size = static_cast<u32_le>(write_index - sizeof(Header)); |
| 160 | header.data_offset = sizeof(Header); | 160 | header.data_offset = sizeof(Header); |
| 161 | header.objects_size = 4; | 161 | header.objects_size = 4; |
| 162 | header.objects_offset = sizeof(Header) + header.data_size; | 162 | header.objects_offset = static_cast<u32>(sizeof(Header) + header.data_size); |
| 163 | std::memcpy(buffer.data(), &header, sizeof(Header)); | 163 | std::memcpy(buffer.data(), &header, sizeof(Header)); |
| 164 | 164 | ||
| 165 | return buffer; | 165 | return buffer; |
| @@ -215,10 +215,9 @@ public: | |||
| 215 | explicit IGBPConnectRequestParcel(std::vector<u8> buffer) : Parcel(std::move(buffer)) { | 215 | explicit IGBPConnectRequestParcel(std::vector<u8> buffer) : Parcel(std::move(buffer)) { |
| 216 | Deserialize(); | 216 | Deserialize(); |
| 217 | } | 217 | } |
| 218 | ~IGBPConnectRequestParcel() override = default; | ||
| 219 | 218 | ||
| 220 | void DeserializeData() override { | 219 | void DeserializeData() override { |
| 221 | std::u16string token = ReadInterfaceToken(); | 220 | [[maybe_unused]] const std::u16string token = ReadInterfaceToken(); |
| 222 | data = Read<Data>(); | 221 | data = Read<Data>(); |
| 223 | } | 222 | } |
| 224 | 223 | ||
| @@ -279,10 +278,9 @@ public: | |||
| 279 | : Parcel(std::move(buffer)) { | 278 | : Parcel(std::move(buffer)) { |
| 280 | Deserialize(); | 279 | Deserialize(); |
| 281 | } | 280 | } |
| 282 | ~IGBPSetPreallocatedBufferRequestParcel() override = default; | ||
| 283 | 281 | ||
| 284 | void DeserializeData() override { | 282 | void DeserializeData() override { |
| 285 | std::u16string token = ReadInterfaceToken(); | 283 | [[maybe_unused]] const std::u16string token = ReadInterfaceToken(); |
| 286 | data = Read<Data>(); | 284 | data = Read<Data>(); |
| 287 | buffer = Read<NVFlinger::IGBPBuffer>(); | 285 | buffer = Read<NVFlinger::IGBPBuffer>(); |
| 288 | } | 286 | } |
| @@ -306,15 +304,40 @@ protected: | |||
| 306 | } | 304 | } |
| 307 | }; | 305 | }; |
| 308 | 306 | ||
| 307 | class IGBPCancelBufferRequestParcel : public Parcel { | ||
| 308 | public: | ||
| 309 | explicit IGBPCancelBufferRequestParcel(std::vector<u8> buffer) : Parcel(std::move(buffer)) { | ||
| 310 | Deserialize(); | ||
| 311 | } | ||
| 312 | |||
| 313 | void DeserializeData() override { | ||
| 314 | [[maybe_unused]] const std::u16string token = ReadInterfaceToken(); | ||
| 315 | data = Read<Data>(); | ||
| 316 | } | ||
| 317 | |||
| 318 | struct Data { | ||
| 319 | u32_le slot; | ||
| 320 | Service::Nvidia::MultiFence multi_fence; | ||
| 321 | }; | ||
| 322 | |||
| 323 | Data data; | ||
| 324 | }; | ||
| 325 | |||
| 326 | class IGBPCancelBufferResponseParcel : public Parcel { | ||
| 327 | protected: | ||
| 328 | void SerializeData() override { | ||
| 329 | Write<u32>(0); // Success | ||
| 330 | } | ||
| 331 | }; | ||
| 332 | |||
| 309 | class IGBPDequeueBufferRequestParcel : public Parcel { | 333 | class IGBPDequeueBufferRequestParcel : public Parcel { |
| 310 | public: | 334 | public: |
| 311 | explicit IGBPDequeueBufferRequestParcel(std::vector<u8> buffer) : Parcel(std::move(buffer)) { | 335 | explicit IGBPDequeueBufferRequestParcel(std::vector<u8> buffer) : Parcel(std::move(buffer)) { |
| 312 | Deserialize(); | 336 | Deserialize(); |
| 313 | } | 337 | } |
| 314 | ~IGBPDequeueBufferRequestParcel() override = default; | ||
| 315 | 338 | ||
| 316 | void DeserializeData() override { | 339 | void DeserializeData() override { |
| 317 | std::u16string token = ReadInterfaceToken(); | 340 | [[maybe_unused]] const std::u16string token = ReadInterfaceToken(); |
| 318 | data = Read<Data>(); | 341 | data = Read<Data>(); |
| 319 | } | 342 | } |
| 320 | 343 | ||
| @@ -333,7 +356,6 @@ class IGBPDequeueBufferResponseParcel : public Parcel { | |||
| 333 | public: | 356 | public: |
| 334 | explicit IGBPDequeueBufferResponseParcel(u32 slot, Service::Nvidia::MultiFence& multi_fence) | 357 | explicit IGBPDequeueBufferResponseParcel(u32 slot, Service::Nvidia::MultiFence& multi_fence) |
| 335 | : slot(slot), multi_fence(multi_fence) {} | 358 | : slot(slot), multi_fence(multi_fence) {} |
| 336 | ~IGBPDequeueBufferResponseParcel() override = default; | ||
| 337 | 359 | ||
| 338 | protected: | 360 | protected: |
| 339 | void SerializeData() override { | 361 | void SerializeData() override { |
| @@ -352,10 +374,9 @@ public: | |||
| 352 | explicit IGBPRequestBufferRequestParcel(std::vector<u8> buffer) : Parcel(std::move(buffer)) { | 374 | explicit IGBPRequestBufferRequestParcel(std::vector<u8> buffer) : Parcel(std::move(buffer)) { |
| 353 | Deserialize(); | 375 | Deserialize(); |
| 354 | } | 376 | } |
| 355 | ~IGBPRequestBufferRequestParcel() override = default; | ||
| 356 | 377 | ||
| 357 | void DeserializeData() override { | 378 | void DeserializeData() override { |
| 358 | std::u16string token = ReadInterfaceToken(); | 379 | [[maybe_unused]] const std::u16string token = ReadInterfaceToken(); |
| 359 | slot = Read<u32_le>(); | 380 | slot = Read<u32_le>(); |
| 360 | } | 381 | } |
| 361 | 382 | ||
| @@ -384,10 +405,9 @@ public: | |||
| 384 | explicit IGBPQueueBufferRequestParcel(std::vector<u8> buffer) : Parcel(std::move(buffer)) { | 405 | explicit IGBPQueueBufferRequestParcel(std::vector<u8> buffer) : Parcel(std::move(buffer)) { |
| 385 | Deserialize(); | 406 | Deserialize(); |
| 386 | } | 407 | } |
| 387 | ~IGBPQueueBufferRequestParcel() override = default; | ||
| 388 | 408 | ||
| 389 | void DeserializeData() override { | 409 | void DeserializeData() override { |
| 390 | std::u16string token = ReadInterfaceToken(); | 410 | [[maybe_unused]] const std::u16string token = ReadInterfaceToken(); |
| 391 | data = Read<Data>(); | 411 | data = Read<Data>(); |
| 392 | } | 412 | } |
| 393 | 413 | ||
| @@ -447,10 +467,9 @@ public: | |||
| 447 | explicit IGBPQueryRequestParcel(std::vector<u8> buffer) : Parcel(std::move(buffer)) { | 467 | explicit IGBPQueryRequestParcel(std::vector<u8> buffer) : Parcel(std::move(buffer)) { |
| 448 | Deserialize(); | 468 | Deserialize(); |
| 449 | } | 469 | } |
| 450 | ~IGBPQueryRequestParcel() override = default; | ||
| 451 | 470 | ||
| 452 | void DeserializeData() override { | 471 | void DeserializeData() override { |
| 453 | std::u16string token = ReadInterfaceToken(); | 472 | [[maybe_unused]] const std::u16string token = ReadInterfaceToken(); |
| 454 | type = Read<u32_le>(); | 473 | type = Read<u32_le>(); |
| 455 | } | 474 | } |
| 456 | 475 | ||
| @@ -596,7 +615,12 @@ private: | |||
| 596 | break; | 615 | break; |
| 597 | } | 616 | } |
| 598 | case TransactionId::CancelBuffer: { | 617 | case TransactionId::CancelBuffer: { |
| 599 | LOG_CRITICAL(Service_VI, "(STUBBED) called, transaction=CancelBuffer"); | 618 | IGBPCancelBufferRequestParcel request{ctx.ReadBuffer()}; |
| 619 | |||
| 620 | buffer_queue.CancelBuffer(request.data.slot, request.data.multi_fence); | ||
| 621 | |||
| 622 | IGBPCancelBufferResponseParcel response{}; | ||
| 623 | ctx.WriteBuffer(response.Serialize()); | ||
| 600 | break; | 624 | break; |
| 601 | } | 625 | } |
| 602 | case TransactionId::Disconnect: { | 626 | case TransactionId::Disconnect: { |
diff --git a/src/core/loader/kip.cpp b/src/core/loader/kip.cpp index 5981bcd21..2a905d3e4 100644 --- a/src/core/loader/kip.cpp +++ b/src/core/loader/kip.cpp | |||
| @@ -16,7 +16,7 @@ namespace Loader { | |||
| 16 | 16 | ||
| 17 | namespace { | 17 | namespace { |
| 18 | constexpr u32 PageAlignSize(u32 size) { | 18 | constexpr u32 PageAlignSize(u32 size) { |
| 19 | return (size + Core::Memory::PAGE_MASK) & ~Core::Memory::PAGE_MASK; | 19 | return static_cast<u32>((size + Core::Memory::PAGE_MASK) & ~Core::Memory::PAGE_MASK); |
| 20 | } | 20 | } |
| 21 | } // Anonymous namespace | 21 | } // Anonymous namespace |
| 22 | 22 | ||
diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp index 9fb5eddad..5f4b3104b 100644 --- a/src/core/loader/nro.cpp +++ b/src/core/loader/nro.cpp | |||
| @@ -127,7 +127,7 @@ FileType AppLoader_NRO::IdentifyType(const FileSys::VirtualFile& file) { | |||
| 127 | } | 127 | } |
| 128 | 128 | ||
| 129 | static constexpr u32 PageAlignSize(u32 size) { | 129 | static constexpr u32 PageAlignSize(u32 size) { |
| 130 | return (size + Core::Memory::PAGE_MASK) & ~Core::Memory::PAGE_MASK; | 130 | return static_cast<u32>((size + Core::Memory::PAGE_MASK) & ~Core::Memory::PAGE_MASK); |
| 131 | } | 131 | } |
| 132 | 132 | ||
| 133 | static bool LoadNroImpl(Kernel::Process& process, const std::vector<u8>& data, | 133 | static bool LoadNroImpl(Kernel::Process& process, const std::vector<u8>& data, |
diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp index 1e70f6e11..497f438a1 100644 --- a/src/core/loader/nso.cpp +++ b/src/core/loader/nso.cpp | |||
| @@ -47,7 +47,7 @@ std::vector<u8> DecompressSegment(const std::vector<u8>& compressed_data, | |||
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | constexpr u32 PageAlignSize(u32 size) { | 49 | constexpr u32 PageAlignSize(u32 size) { |
| 50 | return (size + Core::Memory::PAGE_MASK) & ~Core::Memory::PAGE_MASK; | 50 | return static_cast<u32>((size + Core::Memory::PAGE_MASK) & ~Core::Memory::PAGE_MASK); |
| 51 | } | 51 | } |
| 52 | } // Anonymous namespace | 52 | } // Anonymous namespace |
| 53 | 53 | ||
diff --git a/src/core/loader/nso.h b/src/core/loader/nso.h index 4bd47787d..d331096ae 100644 --- a/src/core/loader/nso.h +++ b/src/core/loader/nso.h | |||
| @@ -59,7 +59,7 @@ struct NSOHeader { | |||
| 59 | static_assert(sizeof(NSOHeader) == 0x100, "NSOHeader has incorrect size."); | 59 | static_assert(sizeof(NSOHeader) == 0x100, "NSOHeader has incorrect size."); |
| 60 | static_assert(std::is_trivially_copyable_v<NSOHeader>, "NSOHeader must be trivially copyable."); | 60 | static_assert(std::is_trivially_copyable_v<NSOHeader>, "NSOHeader must be trivially copyable."); |
| 61 | 61 | ||
| 62 | constexpr u64 NSO_ARGUMENT_DATA_ALLOCATION_SIZE = 0x9000; | 62 | constexpr u32 NSO_ARGUMENT_DATA_ALLOCATION_SIZE = 0x9000; |
| 63 | 63 | ||
| 64 | struct NSOArgumentHeader { | 64 | struct NSOArgumentHeader { |
| 65 | u32_le allocated_size; | 65 | u32_le allocated_size; |
diff --git a/src/core/memory.cpp b/src/core/memory.cpp index c3f4829d7..b88aa5c40 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp | |||
| @@ -120,9 +120,9 @@ struct Memory::Impl { | |||
| 120 | if ((addr & 1) == 0) { | 120 | if ((addr & 1) == 0) { |
| 121 | return Read<u16_le>(addr); | 121 | return Read<u16_le>(addr); |
| 122 | } else { | 122 | } else { |
| 123 | const u8 a{Read<u8>(addr)}; | 123 | const u32 a{Read<u8>(addr)}; |
| 124 | const u8 b{Read<u8>(addr + sizeof(u8))}; | 124 | const u32 b{Read<u8>(addr + sizeof(u8))}; |
| 125 | return (static_cast<u16>(b) << 8) | a; | 125 | return static_cast<u16>((b << 8) | a); |
| 126 | } | 126 | } |
| 127 | } | 127 | } |
| 128 | 128 | ||
| @@ -130,9 +130,9 @@ struct Memory::Impl { | |||
| 130 | if ((addr & 3) == 0) { | 130 | if ((addr & 3) == 0) { |
| 131 | return Read<u32_le>(addr); | 131 | return Read<u32_le>(addr); |
| 132 | } else { | 132 | } else { |
| 133 | const u16 a{Read16(addr)}; | 133 | const u32 a{Read16(addr)}; |
| 134 | const u16 b{Read16(addr + sizeof(u16))}; | 134 | const u32 b{Read16(addr + sizeof(u16))}; |
| 135 | return (static_cast<u32>(b) << 16) | a; | 135 | return (b << 16) | a; |
| 136 | } | 136 | } |
| 137 | } | 137 | } |
| 138 | 138 | ||
diff --git a/src/core/memory/cheat_engine.cpp b/src/core/memory/cheat_engine.cpp index 29284a42d..2dd0eb0f8 100644 --- a/src/core/memory/cheat_engine.cpp +++ b/src/core/memory/cheat_engine.cpp | |||
| @@ -153,8 +153,9 @@ std::vector<CheatEntry> TextCheatParser::Parse(std::string_view data) const { | |||
| 153 | return {}; | 153 | return {}; |
| 154 | } | 154 | } |
| 155 | 155 | ||
| 156 | const auto value = static_cast<u32>(std::stoul(hex, nullptr, 0x10)); | ||
| 156 | out[*current_entry].definition.opcodes[out[*current_entry].definition.num_opcodes++] = | 157 | out[*current_entry].definition.opcodes[out[*current_entry].definition.num_opcodes++] = |
| 157 | std::stoul(hex, nullptr, 0x10); | 158 | value; |
| 158 | 159 | ||
| 159 | i += 8; | 160 | i += 8; |
| 160 | } else { | 161 | } else { |
diff --git a/src/core/network/network.cpp b/src/core/network/network.cpp index 56d173b5e..4b3bb4366 100644 --- a/src/core/network/network.cpp +++ b/src/core/network/network.cpp | |||
| @@ -238,14 +238,14 @@ SockAddrIn TranslateToSockAddrIn(sockaddr input_) { | |||
| 238 | return result; | 238 | return result; |
| 239 | } | 239 | } |
| 240 | 240 | ||
| 241 | u16 TranslatePollEvents(u16 events) { | 241 | u16 TranslatePollEvents(u32 events) { |
| 242 | u16 result = 0; | 242 | u32 result = 0; |
| 243 | 243 | ||
| 244 | if (events & POLL_IN) { | 244 | if ((events & POLL_IN) != 0) { |
| 245 | events &= ~POLL_IN; | 245 | events &= ~POLL_IN; |
| 246 | result |= POLLIN; | 246 | result |= POLLIN; |
| 247 | } | 247 | } |
| 248 | if (events & POLL_PRI) { | 248 | if ((events & POLL_PRI) != 0) { |
| 249 | events &= ~POLL_PRI; | 249 | events &= ~POLL_PRI; |
| 250 | #ifdef _WIN32 | 250 | #ifdef _WIN32 |
| 251 | LOG_WARNING(Service, "Winsock doesn't support POLLPRI"); | 251 | LOG_WARNING(Service, "Winsock doesn't support POLLPRI"); |
| @@ -253,20 +253,20 @@ u16 TranslatePollEvents(u16 events) { | |||
| 253 | result |= POLL_PRI; | 253 | result |= POLL_PRI; |
| 254 | #endif | 254 | #endif |
| 255 | } | 255 | } |
| 256 | if (events & POLL_OUT) { | 256 | if ((events & POLL_OUT) != 0) { |
| 257 | events &= ~POLL_OUT; | 257 | events &= ~POLL_OUT; |
| 258 | result |= POLLOUT; | 258 | result |= POLLOUT; |
| 259 | } | 259 | } |
| 260 | 260 | ||
| 261 | UNIMPLEMENTED_IF_MSG(events != 0, "Unhandled guest events=0x{:x}", events); | 261 | UNIMPLEMENTED_IF_MSG(events != 0, "Unhandled guest events=0x{:x}", events); |
| 262 | 262 | ||
| 263 | return result; | 263 | return static_cast<u16>(result); |
| 264 | } | 264 | } |
| 265 | 265 | ||
| 266 | u16 TranslatePollRevents(u16 revents) { | 266 | u16 TranslatePollRevents(u32 revents) { |
| 267 | u16 result = 0; | 267 | u32 result = 0; |
| 268 | const auto translate = [&result, &revents](int host, unsigned guest) { | 268 | const auto translate = [&result, &revents](u32 host, u32 guest) { |
| 269 | if (revents & host) { | 269 | if ((revents & host) != 0) { |
| 270 | revents &= ~host; | 270 | revents &= ~host; |
| 271 | result |= guest; | 271 | result |= guest; |
| 272 | } | 272 | } |
| @@ -280,7 +280,7 @@ u16 TranslatePollRevents(u16 revents) { | |||
| 280 | 280 | ||
| 281 | UNIMPLEMENTED_IF_MSG(revents != 0, "Unhandled host revents=0x{:x}", revents); | 281 | UNIMPLEMENTED_IF_MSG(revents != 0, "Unhandled host revents=0x{:x}", revents); |
| 282 | 282 | ||
| 283 | return result; | 283 | return static_cast<u16>(result); |
| 284 | } | 284 | } |
| 285 | 285 | ||
| 286 | template <typename T> | 286 | template <typename T> |
| @@ -350,7 +350,7 @@ std::pair<s32, Errno> Poll(std::vector<PollFD>& pollfds, s32 timeout) { | |||
| 350 | } | 350 | } |
| 351 | 351 | ||
| 352 | for (size_t i = 0; i < num; ++i) { | 352 | for (size_t i = 0; i < num; ++i) { |
| 353 | pollfds[i].revents = TranslatePollRevents(host_pollfds[i].revents); | 353 | pollfds[i].revents = TranslatePollRevents(static_cast<u32>(host_pollfds[i].revents)); |
| 354 | } | 354 | } |
| 355 | 355 | ||
| 356 | if (result > 0) { | 356 | if (result > 0) { |
| @@ -408,7 +408,7 @@ std::pair<Socket::AcceptResult, Errno> Socket::Accept() { | |||
| 408 | 408 | ||
| 409 | Errno Socket::Connect(SockAddrIn addr_in) { | 409 | Errno Socket::Connect(SockAddrIn addr_in) { |
| 410 | const sockaddr host_addr_in = TranslateFromSockAddrIn(addr_in); | 410 | const sockaddr host_addr_in = TranslateFromSockAddrIn(addr_in); |
| 411 | if (connect(fd, &host_addr_in, sizeof(host_addr_in)) != INVALID_SOCKET) { | 411 | if (connect(fd, &host_addr_in, sizeof(host_addr_in)) != SOCKET_ERROR) { |
| 412 | return Errno::SUCCESS; | 412 | return Errno::SUCCESS; |
| 413 | } | 413 | } |
| 414 | 414 | ||
| @@ -503,10 +503,10 @@ std::pair<s32, Errno> Socket::Recv(int flags, std::vector<u8>& message) { | |||
| 503 | ASSERT(flags == 0); | 503 | ASSERT(flags == 0); |
| 504 | ASSERT(message.size() < static_cast<size_t>(std::numeric_limits<int>::max())); | 504 | ASSERT(message.size() < static_cast<size_t>(std::numeric_limits<int>::max())); |
| 505 | 505 | ||
| 506 | const int result = | 506 | const auto result = |
| 507 | recv(fd, reinterpret_cast<char*>(message.data()), static_cast<int>(message.size()), 0); | 507 | recv(fd, reinterpret_cast<char*>(message.data()), static_cast<int>(message.size()), 0); |
| 508 | if (result != SOCKET_ERROR) { | 508 | if (result != SOCKET_ERROR) { |
| 509 | return {result, Errno::SUCCESS}; | 509 | return {static_cast<s32>(result), Errno::SUCCESS}; |
| 510 | } | 510 | } |
| 511 | 511 | ||
| 512 | switch (const int ec = LastError()) { | 512 | switch (const int ec = LastError()) { |
| @@ -531,14 +531,14 @@ std::pair<s32, Errno> Socket::RecvFrom(int flags, std::vector<u8>& message, Sock | |||
| 531 | socklen_t* const p_addrlen = addr ? &addrlen : nullptr; | 531 | socklen_t* const p_addrlen = addr ? &addrlen : nullptr; |
| 532 | sockaddr* const p_addr_in = addr ? &addr_in : nullptr; | 532 | sockaddr* const p_addr_in = addr ? &addr_in : nullptr; |
| 533 | 533 | ||
| 534 | const int result = recvfrom(fd, reinterpret_cast<char*>(message.data()), | 534 | const auto result = recvfrom(fd, reinterpret_cast<char*>(message.data()), |
| 535 | static_cast<int>(message.size()), 0, p_addr_in, p_addrlen); | 535 | static_cast<int>(message.size()), 0, p_addr_in, p_addrlen); |
| 536 | if (result != SOCKET_ERROR) { | 536 | if (result != SOCKET_ERROR) { |
| 537 | if (addr) { | 537 | if (addr) { |
| 538 | ASSERT(addrlen == sizeof(addr_in)); | 538 | ASSERT(addrlen == sizeof(addr_in)); |
| 539 | *addr = TranslateToSockAddrIn(addr_in); | 539 | *addr = TranslateToSockAddrIn(addr_in); |
| 540 | } | 540 | } |
| 541 | return {result, Errno::SUCCESS}; | 541 | return {static_cast<s32>(result), Errno::SUCCESS}; |
| 542 | } | 542 | } |
| 543 | 543 | ||
| 544 | switch (const int ec = LastError()) { | 544 | switch (const int ec = LastError()) { |
| @@ -558,10 +558,10 @@ std::pair<s32, Errno> Socket::Send(const std::vector<u8>& message, int flags) { | |||
| 558 | ASSERT(message.size() < static_cast<size_t>(std::numeric_limits<int>::max())); | 558 | ASSERT(message.size() < static_cast<size_t>(std::numeric_limits<int>::max())); |
| 559 | ASSERT(flags == 0); | 559 | ASSERT(flags == 0); |
| 560 | 560 | ||
| 561 | const int result = send(fd, reinterpret_cast<const char*>(message.data()), | 561 | const auto result = send(fd, reinterpret_cast<const char*>(message.data()), |
| 562 | static_cast<int>(message.size()), 0); | 562 | static_cast<int>(message.size()), 0); |
| 563 | if (result != SOCKET_ERROR) { | 563 | if (result != SOCKET_ERROR) { |
| 564 | return {result, Errno::SUCCESS}; | 564 | return {static_cast<s32>(result), Errno::SUCCESS}; |
| 565 | } | 565 | } |
| 566 | 566 | ||
| 567 | const int ec = LastError(); | 567 | const int ec = LastError(); |
| @@ -591,10 +591,10 @@ std::pair<s32, Errno> Socket::SendTo(u32 flags, const std::vector<u8>& message, | |||
| 591 | to = &host_addr_in; | 591 | to = &host_addr_in; |
| 592 | } | 592 | } |
| 593 | 593 | ||
| 594 | const int result = sendto(fd, reinterpret_cast<const char*>(message.data()), | 594 | const auto result = sendto(fd, reinterpret_cast<const char*>(message.data()), |
| 595 | static_cast<int>(message.size()), 0, to, tolen); | 595 | static_cast<int>(message.size()), 0, to, tolen); |
| 596 | if (result != SOCKET_ERROR) { | 596 | if (result != SOCKET_ERROR) { |
| 597 | return {result, Errno::SUCCESS}; | 597 | return {static_cast<s32>(result), Errno::SUCCESS}; |
| 598 | } | 598 | } |
| 599 | 599 | ||
| 600 | const int ec = LastError(); | 600 | const int ec = LastError(); |
diff --git a/src/input_common/CMakeLists.txt b/src/input_common/CMakeLists.txt index c84685214..7b39a38c1 100644 --- a/src/input_common/CMakeLists.txt +++ b/src/input_common/CMakeLists.txt | |||
| @@ -29,6 +29,35 @@ add_library(input_common STATIC | |||
| 29 | udp/udp.h | 29 | udp/udp.h |
| 30 | ) | 30 | ) |
| 31 | 31 | ||
| 32 | if (MSVC) | ||
| 33 | target_compile_options(input_common PRIVATE | ||
| 34 | # 'expression' : signed/unsigned mismatch | ||
| 35 | /we4018 | ||
| 36 | # 'argument' : conversion from 'type1' to 'type2', possible loss of data (floating-point) | ||
| 37 | /we4244 | ||
| 38 | # 'conversion' : conversion from 'type1' to 'type2', signed/unsigned mismatch | ||
| 39 | /we4245 | ||
| 40 | # 'operator': conversion from 'type1:field_bits' to 'type2:field_bits', possible loss of data | ||
| 41 | /we4254 | ||
| 42 | # 'var' : conversion from 'size_t' to 'type', possible loss of data | ||
| 43 | /we4267 | ||
| 44 | # 'context' : truncation from 'type1' to 'type2' | ||
| 45 | /we4305 | ||
| 46 | ) | ||
| 47 | else() | ||
| 48 | target_compile_options(input_common PRIVATE | ||
| 49 | -Werror=conversion | ||
| 50 | -Werror=ignored-qualifiers | ||
| 51 | -Werror=implicit-fallthrough | ||
| 52 | -Werror=reorder | ||
| 53 | -Werror=shadow | ||
| 54 | -Werror=sign-compare | ||
| 55 | -Werror=unused-but-set-parameter | ||
| 56 | -Werror=unused-but-set-variable | ||
| 57 | -Werror=unused-variable | ||
| 58 | ) | ||
| 59 | endif() | ||
| 60 | |||
| 32 | if(SDL2_FOUND) | 61 | if(SDL2_FOUND) |
| 33 | target_sources(input_common PRIVATE | 62 | target_sources(input_common PRIVATE |
| 34 | sdl/sdl_impl.cpp | 63 | sdl/sdl_impl.cpp |
diff --git a/src/input_common/analog_from_button.cpp b/src/input_common/analog_from_button.cpp index 6cabdaa3c..74744d7f3 100755 --- a/src/input_common/analog_from_button.cpp +++ b/src/input_common/analog_from_button.cpp | |||
| @@ -20,18 +20,22 @@ public: | |||
| 20 | constexpr float SQRT_HALF = 0.707106781f; | 20 | constexpr float SQRT_HALF = 0.707106781f; |
| 21 | int x = 0, y = 0; | 21 | int x = 0, y = 0; |
| 22 | 22 | ||
| 23 | if (right->GetStatus()) | 23 | if (right->GetStatus()) { |
| 24 | ++x; | 24 | ++x; |
| 25 | if (left->GetStatus()) | 25 | } |
| 26 | if (left->GetStatus()) { | ||
| 26 | --x; | 27 | --x; |
| 27 | if (up->GetStatus()) | 28 | } |
| 29 | if (up->GetStatus()) { | ||
| 28 | ++y; | 30 | ++y; |
| 29 | if (down->GetStatus()) | 31 | } |
| 32 | if (down->GetStatus()) { | ||
| 30 | --y; | 33 | --y; |
| 34 | } | ||
| 31 | 35 | ||
| 32 | float coef = modifier->GetStatus() ? modifier_scale : 1.0f; | 36 | const float coef = modifier->GetStatus() ? modifier_scale : 1.0f; |
| 33 | return std::make_tuple(x * coef * (y == 0 ? 1.0f : SQRT_HALF), | 37 | return std::make_tuple(static_cast<float>(x) * coef * (y == 0 ? 1.0f : SQRT_HALF), |
| 34 | y * coef * (x == 0 ? 1.0f : SQRT_HALF)); | 38 | static_cast<float>(y) * coef * (x == 0 ? 1.0f : SQRT_HALF)); |
| 35 | } | 39 | } |
| 36 | 40 | ||
| 37 | bool GetAnalogDirectionStatus(Input::AnalogDirection direction) const override { | 41 | bool GetAnalogDirectionStatus(Input::AnalogDirection direction) const override { |
diff --git a/src/input_common/gcadapter/gc_adapter.cpp b/src/input_common/gcadapter/gc_adapter.cpp index 89c148aba..c95feb0d7 100644 --- a/src/input_common/gcadapter/gc_adapter.cpp +++ b/src/input_common/gcadapter/gc_adapter.cpp | |||
| @@ -21,7 +21,7 @@ | |||
| 21 | 21 | ||
| 22 | namespace GCAdapter { | 22 | namespace GCAdapter { |
| 23 | 23 | ||
| 24 | /// Used to loop through and assign button in poller | 24 | // Used to loop through and assign button in poller |
| 25 | constexpr std::array<PadButton, 12> PadButtonArray{ | 25 | constexpr std::array<PadButton, 12> PadButtonArray{ |
| 26 | PadButton::PAD_BUTTON_LEFT, PadButton::PAD_BUTTON_RIGHT, PadButton::PAD_BUTTON_DOWN, | 26 | PadButton::PAD_BUTTON_LEFT, PadButton::PAD_BUTTON_RIGHT, PadButton::PAD_BUTTON_DOWN, |
| 27 | PadButton::PAD_BUTTON_UP, PadButton::PAD_TRIGGER_Z, PadButton::PAD_TRIGGER_R, | 27 | PadButton::PAD_BUTTON_UP, PadButton::PAD_TRIGGER_Z, PadButton::PAD_TRIGGER_R, |
| @@ -29,6 +29,18 @@ constexpr std::array<PadButton, 12> PadButtonArray{ | |||
| 29 | PadButton::PAD_BUTTON_X, PadButton::PAD_BUTTON_Y, PadButton::PAD_BUTTON_START, | 29 | PadButton::PAD_BUTTON_X, PadButton::PAD_BUTTON_Y, PadButton::PAD_BUTTON_START, |
| 30 | }; | 30 | }; |
| 31 | 31 | ||
| 32 | static void PadToState(const GCPadStatus& pad, GCState& out_state) { | ||
| 33 | for (const auto& button : PadButtonArray) { | ||
| 34 | const auto button_key = static_cast<u16>(button); | ||
| 35 | const auto button_value = (pad.button & button_key) != 0; | ||
| 36 | out_state.buttons.insert_or_assign(static_cast<s32>(button_key), button_value); | ||
| 37 | } | ||
| 38 | |||
| 39 | for (std::size_t i = 0; i < pad.axis_values.size(); ++i) { | ||
| 40 | out_state.axes.insert_or_assign(static_cast<u32>(i), pad.axis_values[i]); | ||
| 41 | } | ||
| 42 | } | ||
| 43 | |||
| 32 | Adapter::Adapter() { | 44 | Adapter::Adapter() { |
| 33 | if (usb_adapter_handle != nullptr) { | 45 | if (usb_adapter_handle != nullptr) { |
| 34 | return; | 46 | return; |
| @@ -78,17 +90,17 @@ GCPadStatus Adapter::GetPadStatus(std::size_t port, const std::array<u8, 37>& ad | |||
| 78 | 90 | ||
| 79 | for (std::size_t i = 0; i < b1_buttons.size(); ++i) { | 91 | for (std::size_t i = 0; i < b1_buttons.size(); ++i) { |
| 80 | if ((b1 & (1U << i)) != 0) { | 92 | if ((b1 & (1U << i)) != 0) { |
| 81 | pad.button |= static_cast<u16>(b1_buttons[i]); | 93 | pad.button = static_cast<u16>(pad.button | static_cast<u16>(b1_buttons[i])); |
| 82 | } | 94 | } |
| 83 | } | 95 | } |
| 84 | 96 | ||
| 85 | for (std::size_t j = 0; j < b2_buttons.size(); ++j) { | 97 | for (std::size_t j = 0; j < b2_buttons.size(); ++j) { |
| 86 | if ((b2 & (1U << j)) != 0) { | 98 | if ((b2 & (1U << j)) != 0) { |
| 87 | pad.button |= static_cast<u16>(b2_buttons[j]); | 99 | pad.button = static_cast<u16>(pad.button | static_cast<u16>(b2_buttons[j])); |
| 88 | } | 100 | } |
| 89 | } | 101 | } |
| 90 | for (PadAxes axis : axes) { | 102 | for (PadAxes axis : axes) { |
| 91 | const std::size_t index = static_cast<std::size_t>(axis); | 103 | const auto index = static_cast<std::size_t>(axis); |
| 92 | pad.axis_values[index] = adapter_payload[offset + 3 + index]; | 104 | pad.axis_values[index] = adapter_payload[offset + 3 + index]; |
| 93 | } | 105 | } |
| 94 | 106 | ||
| @@ -100,17 +112,6 @@ GCPadStatus Adapter::GetPadStatus(std::size_t port, const std::array<u8, 37>& ad | |||
| 100 | return pad; | 112 | return pad; |
| 101 | } | 113 | } |
| 102 | 114 | ||
| 103 | void Adapter::PadToState(const GCPadStatus& pad, GCState& state) { | ||
| 104 | for (const auto& button : PadButtonArray) { | ||
| 105 | const u16 button_value = static_cast<u16>(button); | ||
| 106 | state.buttons.insert_or_assign(button_value, pad.button & button_value); | ||
| 107 | } | ||
| 108 | |||
| 109 | for (size_t i = 0; i < pad.axis_values.size(); ++i) { | ||
| 110 | state.axes.insert_or_assign(static_cast<u8>(i), pad.axis_values[i]); | ||
| 111 | } | ||
| 112 | } | ||
| 113 | |||
| 114 | void Adapter::Read() { | 115 | void Adapter::Read() { |
| 115 | LOG_DEBUG(Input, "GC Adapter Read() thread started"); | 116 | LOG_DEBUG(Input, "GC Adapter Read() thread started"); |
| 116 | 117 | ||
| @@ -250,7 +251,7 @@ void Adapter::GetGCEndpoint(libusb_device* device) { | |||
| 250 | const libusb_interface_descriptor* interface = &interfaceContainer->altsetting[i]; | 251 | const libusb_interface_descriptor* interface = &interfaceContainer->altsetting[i]; |
| 251 | for (u8 e = 0; e < interface->bNumEndpoints; e++) { | 252 | for (u8 e = 0; e < interface->bNumEndpoints; e++) { |
| 252 | const libusb_endpoint_descriptor* endpoint = &interface->endpoint[e]; | 253 | const libusb_endpoint_descriptor* endpoint = &interface->endpoint[e]; |
| 253 | if (endpoint->bEndpointAddress & LIBUSB_ENDPOINT_IN) { | 254 | if ((endpoint->bEndpointAddress & LIBUSB_ENDPOINT_IN) != 0) { |
| 254 | input_endpoint = endpoint->bEndpointAddress; | 255 | input_endpoint = endpoint->bEndpointAddress; |
| 255 | } else { | 256 | } else { |
| 256 | output_endpoint = endpoint->bEndpointAddress; | 257 | output_endpoint = endpoint->bEndpointAddress; |
| @@ -419,7 +420,7 @@ const std::array<GCState, 4>& Adapter::GetPadState() const { | |||
| 419 | return state; | 420 | return state; |
| 420 | } | 421 | } |
| 421 | 422 | ||
| 422 | int Adapter::GetOriginValue(int port, int axis) const { | 423 | int Adapter::GetOriginValue(u32 port, u32 axis) const { |
| 423 | return origin_status[port].axis_values[axis]; | 424 | return origin_status[port].axis_values[axis]; |
| 424 | } | 425 | } |
| 425 | 426 | ||
diff --git a/src/input_common/gcadapter/gc_adapter.h b/src/input_common/gcadapter/gc_adapter.h index 75bf9fe74..4f5f3de8e 100644 --- a/src/input_common/gcadapter/gc_adapter.h +++ b/src/input_common/gcadapter/gc_adapter.h | |||
| @@ -60,7 +60,7 @@ struct GCPadStatus { | |||
| 60 | 60 | ||
| 61 | struct GCState { | 61 | struct GCState { |
| 62 | std::unordered_map<int, bool> buttons; | 62 | std::unordered_map<int, bool> buttons; |
| 63 | std::unordered_map<int, u16> axes; | 63 | std::unordered_map<u32, u16> axes; |
| 64 | }; | 64 | }; |
| 65 | 65 | ||
| 66 | enum class ControllerTypes { None, Wired, Wireless }; | 66 | enum class ControllerTypes { None, Wired, Wireless }; |
| @@ -89,13 +89,11 @@ public: | |||
| 89 | std::array<GCState, 4>& GetPadState(); | 89 | std::array<GCState, 4>& GetPadState(); |
| 90 | const std::array<GCState, 4>& GetPadState() const; | 90 | const std::array<GCState, 4>& GetPadState() const; |
| 91 | 91 | ||
| 92 | int GetOriginValue(int port, int axis) const; | 92 | int GetOriginValue(u32 port, u32 axis) const; |
| 93 | 93 | ||
| 94 | private: | 94 | private: |
| 95 | GCPadStatus GetPadStatus(std::size_t port, const std::array<u8, 37>& adapter_payload); | 95 | GCPadStatus GetPadStatus(std::size_t port, const std::array<u8, 37>& adapter_payload); |
| 96 | 96 | ||
| 97 | void PadToState(const GCPadStatus& pad, GCState& state); | ||
| 98 | |||
| 99 | void Read(); | 97 | void Read(); |
| 100 | 98 | ||
| 101 | /// Resets status of device connected to port | 99 | /// Resets status of device connected to port |
diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp index 92e9e8e89..893556916 100644 --- a/src/input_common/gcadapter/gc_poller.cpp +++ b/src/input_common/gcadapter/gc_poller.cpp | |||
| @@ -15,7 +15,7 @@ namespace InputCommon { | |||
| 15 | 15 | ||
| 16 | class GCButton final : public Input::ButtonDevice { | 16 | class GCButton final : public Input::ButtonDevice { |
| 17 | public: | 17 | public: |
| 18 | explicit GCButton(int port_, int button_, const GCAdapter::Adapter* adapter) | 18 | explicit GCButton(u32 port_, int button_, const GCAdapter::Adapter* adapter) |
| 19 | : port(port_), button(button_), gcadapter(adapter) {} | 19 | : port(port_), button(button_), gcadapter(adapter) {} |
| 20 | 20 | ||
| 21 | ~GCButton() override; | 21 | ~GCButton() override; |
| @@ -28,14 +28,14 @@ public: | |||
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | private: | 30 | private: |
| 31 | const int port; | 31 | const u32 port; |
| 32 | const int button; | 32 | const int button; |
| 33 | const GCAdapter::Adapter* gcadapter; | 33 | const GCAdapter::Adapter* gcadapter; |
| 34 | }; | 34 | }; |
| 35 | 35 | ||
| 36 | class GCAxisButton final : public Input::ButtonDevice { | 36 | class GCAxisButton final : public Input::ButtonDevice { |
| 37 | public: | 37 | public: |
| 38 | explicit GCAxisButton(int port_, int axis_, float threshold_, bool trigger_if_greater_, | 38 | explicit GCAxisButton(u32 port_, u32 axis_, float threshold_, bool trigger_if_greater_, |
| 39 | const GCAdapter::Adapter* adapter) | 39 | const GCAdapter::Adapter* adapter) |
| 40 | : port(port_), axis(axis_), threshold(threshold_), trigger_if_greater(trigger_if_greater_), | 40 | : port(port_), axis(axis_), threshold(threshold_), trigger_if_greater(trigger_if_greater_), |
| 41 | gcadapter(adapter), | 41 | gcadapter(adapter), |
| @@ -56,8 +56,8 @@ public: | |||
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | private: | 58 | private: |
| 59 | const int port; | 59 | const u32 port; |
| 60 | const int axis; | 60 | const u32 axis; |
| 61 | float threshold; | 61 | float threshold; |
| 62 | bool trigger_if_greater; | 62 | bool trigger_if_greater; |
| 63 | const GCAdapter::Adapter* gcadapter; | 63 | const GCAdapter::Adapter* gcadapter; |
| @@ -70,8 +70,8 @@ GCButtonFactory::GCButtonFactory(std::shared_ptr<GCAdapter::Adapter> adapter_) | |||
| 70 | GCButton::~GCButton() = default; | 70 | GCButton::~GCButton() = default; |
| 71 | 71 | ||
| 72 | std::unique_ptr<Input::ButtonDevice> GCButtonFactory::Create(const Common::ParamPackage& params) { | 72 | std::unique_ptr<Input::ButtonDevice> GCButtonFactory::Create(const Common::ParamPackage& params) { |
| 73 | const int button_id = params.Get("button", 0); | 73 | const auto button_id = params.Get("button", 0); |
| 74 | const int port = params.Get("port", 0); | 74 | const auto port = static_cast<u32>(params.Get("port", 0)); |
| 75 | 75 | ||
| 76 | constexpr int PAD_STICK_ID = static_cast<u16>(GCAdapter::PadButton::PAD_STICK); | 76 | constexpr int PAD_STICK_ID = static_cast<u16>(GCAdapter::PadButton::PAD_STICK); |
| 77 | 77 | ||
| @@ -149,25 +149,27 @@ void GCButtonFactory::EndConfiguration() { | |||
| 149 | 149 | ||
| 150 | class GCAnalog final : public Input::AnalogDevice { | 150 | class GCAnalog final : public Input::AnalogDevice { |
| 151 | public: | 151 | public: |
| 152 | GCAnalog(int port_, int axis_x_, int axis_y_, float deadzone_, | 152 | explicit GCAnalog(u32 port_, u32 axis_x_, u32 axis_y_, float deadzone_, |
| 153 | const GCAdapter::Adapter* adapter, float range_) | 153 | const GCAdapter::Adapter* adapter, float range_) |
| 154 | : port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_), gcadapter(adapter), | 154 | : port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_), gcadapter(adapter), |
| 155 | origin_value_x(static_cast<float>(adapter->GetOriginValue(port_, axis_x_))), | 155 | origin_value_x(static_cast<float>(adapter->GetOriginValue(port_, axis_x_))), |
| 156 | origin_value_y(static_cast<float>(adapter->GetOriginValue(port_, axis_y_))), | 156 | origin_value_y(static_cast<float>(adapter->GetOriginValue(port_, axis_y_))), |
| 157 | range(range_) {} | 157 | range(range_) {} |
| 158 | 158 | ||
| 159 | float GetAxis(int axis) const { | 159 | float GetAxis(u32 axis) const { |
| 160 | if (gcadapter->DeviceConnected(port)) { | 160 | if (gcadapter->DeviceConnected(port)) { |
| 161 | std::lock_guard lock{mutex}; | 161 | std::lock_guard lock{mutex}; |
| 162 | const auto origin_value = axis % 2 == 0 ? origin_value_x : origin_value_y; | 162 | const auto origin_value = axis % 2 == 0 ? origin_value_x : origin_value_y; |
| 163 | return (gcadapter->GetPadState()[port].axes.at(axis) - origin_value) / (100.0f * range); | 163 | const auto axis_value = |
| 164 | static_cast<float>(gcadapter->GetPadState()[port].axes.at(axis)); | ||
| 165 | return (axis_value - origin_value) / (100.0f * range); | ||
| 164 | } | 166 | } |
| 165 | return 0.0f; | 167 | return 0.0f; |
| 166 | } | 168 | } |
| 167 | 169 | ||
| 168 | std::pair<float, float> GetAnalog(int axis_x, int axis_y) const { | 170 | std::pair<float, float> GetAnalog(u32 analog_axis_x, u32 analog_axis_y) const { |
| 169 | float x = GetAxis(axis_x); | 171 | float x = GetAxis(analog_axis_x); |
| 170 | float y = GetAxis(axis_y); | 172 | float y = GetAxis(analog_axis_y); |
| 171 | 173 | ||
| 172 | // Make sure the coordinates are in the unit circle, | 174 | // Make sure the coordinates are in the unit circle, |
| 173 | // otherwise normalize it. | 175 | // otherwise normalize it. |
| @@ -208,9 +210,9 @@ public: | |||
| 208 | } | 210 | } |
| 209 | 211 | ||
| 210 | private: | 212 | private: |
| 211 | const int port; | 213 | const u32 port; |
| 212 | const int axis_x; | 214 | const u32 axis_x; |
| 213 | const int axis_y; | 215 | const u32 axis_y; |
| 214 | const float deadzone; | 216 | const float deadzone; |
| 215 | const GCAdapter::Adapter* gcadapter; | 217 | const GCAdapter::Adapter* gcadapter; |
| 216 | const float origin_value_x; | 218 | const float origin_value_x; |
| @@ -231,11 +233,11 @@ GCAnalogFactory::GCAnalogFactory(std::shared_ptr<GCAdapter::Adapter> adapter_) | |||
| 231 | * - "axis_y": the index of the axis to be bind as y-axis | 233 | * - "axis_y": the index of the axis to be bind as y-axis |
| 232 | */ | 234 | */ |
| 233 | std::unique_ptr<Input::AnalogDevice> GCAnalogFactory::Create(const Common::ParamPackage& params) { | 235 | std::unique_ptr<Input::AnalogDevice> GCAnalogFactory::Create(const Common::ParamPackage& params) { |
| 234 | const int port = params.Get("port", 0); | 236 | const auto port = static_cast<u32>(params.Get("port", 0)); |
| 235 | const int axis_x = params.Get("axis_x", 0); | 237 | const auto axis_x = static_cast<u32>(params.Get("axis_x", 0)); |
| 236 | const int axis_y = params.Get("axis_y", 1); | 238 | const auto axis_y = static_cast<u32>(params.Get("axis_y", 1)); |
| 237 | const float deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f); | 239 | const auto deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f); |
| 238 | const float range = std::clamp(params.Get("range", 1.0f), 0.50f, 1.50f); | 240 | const auto range = std::clamp(params.Get("range", 1.0f), 0.50f, 1.50f); |
| 239 | 241 | ||
| 240 | return std::make_unique<GCAnalog>(port, axis_x, axis_y, deadzone, adapter.get(), range); | 242 | return std::make_unique<GCAnalog>(port, axis_x, axis_y, deadzone, adapter.get(), range); |
| 241 | } | 243 | } |
| @@ -256,7 +258,7 @@ Common::ParamPackage GCAnalogFactory::GetNextInput() { | |||
| 256 | for (std::size_t port = 0; port < queue.size(); ++port) { | 258 | for (std::size_t port = 0; port < queue.size(); ++port) { |
| 257 | while (queue[port].Pop(pad)) { | 259 | while (queue[port].Pop(pad)) { |
| 258 | if (pad.axis == GCAdapter::PadAxes::Undefined || | 260 | if (pad.axis == GCAdapter::PadAxes::Undefined || |
| 259 | std::abs((pad.axis_value - 128.0f) / 128.0f) < 0.1) { | 261 | std::abs((static_cast<float>(pad.axis_value) - 128.0f) / 128.0f) < 0.1f) { |
| 260 | continue; | 262 | continue; |
| 261 | } | 263 | } |
| 262 | // An analog device needs two axes, so we need to store the axis for later and wait for | 264 | // An analog device needs two axes, so we need to store the axis for later and wait for |
diff --git a/src/input_common/keyboard.cpp b/src/input_common/keyboard.cpp index afb8e6612..24a6f7a33 100644 --- a/src/input_common/keyboard.cpp +++ b/src/input_common/keyboard.cpp | |||
| @@ -49,8 +49,9 @@ public: | |||
| 49 | void ChangeKeyStatus(int key_code, bool pressed) { | 49 | void ChangeKeyStatus(int key_code, bool pressed) { |
| 50 | std::lock_guard guard{mutex}; | 50 | std::lock_guard guard{mutex}; |
| 51 | for (const KeyButtonPair& pair : list) { | 51 | for (const KeyButtonPair& pair : list) { |
| 52 | if (pair.key_code == key_code) | 52 | if (pair.key_code == key_code) { |
| 53 | pair.key_button->status.store(pressed); | 53 | pair.key_button->status.store(pressed); |
| 54 | } | ||
| 54 | } | 55 | } |
| 55 | } | 56 | } |
| 56 | 57 | ||
| @@ -73,7 +74,7 @@ KeyButton::~KeyButton() { | |||
| 73 | } | 74 | } |
| 74 | 75 | ||
| 75 | std::unique_ptr<Input::ButtonDevice> Keyboard::Create(const Common::ParamPackage& params) { | 76 | std::unique_ptr<Input::ButtonDevice> Keyboard::Create(const Common::ParamPackage& params) { |
| 76 | int key_code = params.Get("code", 0); | 77 | const int key_code = params.Get("code", 0); |
| 77 | std::unique_ptr<KeyButton> button = std::make_unique<KeyButton>(key_button_list); | 78 | std::unique_ptr<KeyButton> button = std::make_unique<KeyButton>(key_button_list); |
| 78 | key_button_list->AddKeyButton(key_code, button.get()); | 79 | key_button_list->AddKeyButton(key_code, button.get()); |
| 79 | return button; | 80 | return button; |
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index 3d97d95f7..d32fd8b81 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp | |||
| @@ -196,6 +196,10 @@ ButtonMapping InputSubsystem::GetButtonMappingForDevice(const Common::ParamPacka | |||
| 196 | return impl->GetButtonMappingForDevice(device); | 196 | return impl->GetButtonMappingForDevice(device); |
| 197 | } | 197 | } |
| 198 | 198 | ||
| 199 | MotionMapping InputSubsystem::GetMotionMappingForDevice(const Common::ParamPackage& device) const { | ||
| 200 | return impl->GetMotionMappingForDevice(device); | ||
| 201 | } | ||
| 202 | |||
| 199 | GCAnalogFactory* InputSubsystem::GetGCAnalogs() { | 203 | GCAnalogFactory* InputSubsystem::GetGCAnalogs() { |
| 200 | return impl->gcanalog.get(); | 204 | return impl->gcanalog.get(); |
| 201 | } | 205 | } |
diff --git a/src/input_common/motion_emu.cpp b/src/input_common/motion_emu.cpp index 69fd3c1d2..d4da5596b 100644 --- a/src/input_common/motion_emu.cpp +++ b/src/input_common/motion_emu.cpp | |||
| @@ -18,11 +18,11 @@ namespace InputCommon { | |||
| 18 | // Implementation class of the motion emulation device | 18 | // Implementation class of the motion emulation device |
| 19 | class MotionEmuDevice { | 19 | class MotionEmuDevice { |
| 20 | public: | 20 | public: |
| 21 | MotionEmuDevice(int update_millisecond, float sensitivity) | 21 | explicit MotionEmuDevice(int update_millisecond_, float sensitivity_) |
| 22 | : update_millisecond(update_millisecond), | 22 | : update_millisecond(update_millisecond_), |
| 23 | update_duration(std::chrono::duration_cast<std::chrono::steady_clock::duration>( | 23 | update_duration(std::chrono::duration_cast<std::chrono::steady_clock::duration>( |
| 24 | std::chrono::milliseconds(update_millisecond))), | 24 | std::chrono::milliseconds(update_millisecond))), |
| 25 | sensitivity(sensitivity), motion_emu_thread(&MotionEmuDevice::MotionEmuThread, this) {} | 25 | sensitivity(sensitivity_), motion_emu_thread(&MotionEmuDevice::MotionEmuThread, this) {} |
| 26 | 26 | ||
| 27 | ~MotionEmuDevice() { | 27 | ~MotionEmuDevice() { |
| 28 | if (motion_emu_thread.joinable()) { | 28 | if (motion_emu_thread.joinable()) { |
| @@ -37,16 +37,18 @@ public: | |||
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | void Tilt(int x, int y) { | 39 | void Tilt(int x, int y) { |
| 40 | auto mouse_move = Common::MakeVec(x, y) - mouse_origin; | 40 | if (!is_tilting) { |
| 41 | if (is_tilting) { | 41 | return; |
| 42 | std::lock_guard guard{tilt_mutex}; | 42 | } |
| 43 | if (mouse_move.x == 0 && mouse_move.y == 0) { | 43 | |
| 44 | tilt_angle = 0; | 44 | std::lock_guard guard{tilt_mutex}; |
| 45 | } else { | 45 | const auto mouse_move = Common::MakeVec(x, y) - mouse_origin; |
| 46 | tilt_direction = mouse_move.Cast<float>(); | 46 | if (mouse_move.x == 0 && mouse_move.y == 0) { |
| 47 | tilt_angle = | 47 | tilt_angle = 0; |
| 48 | std::clamp(tilt_direction.Normalize() * sensitivity, 0.0f, Common::PI * 0.5f); | 48 | } else { |
| 49 | } | 49 | tilt_direction = mouse_move.Cast<float>(); |
| 50 | tilt_angle = | ||
| 51 | std::clamp(tilt_direction.Normalize() * sensitivity, 0.0f, Common::PI * 0.5f); | ||
| 50 | } | 52 | } |
| 51 | } | 53 | } |
| 52 | 54 | ||
| @@ -86,11 +88,10 @@ private: | |||
| 86 | void MotionEmuThread() { | 88 | void MotionEmuThread() { |
| 87 | auto update_time = std::chrono::steady_clock::now(); | 89 | auto update_time = std::chrono::steady_clock::now(); |
| 88 | Common::Quaternion<float> q = Common::MakeQuaternion(Common::Vec3<float>(), 0); | 90 | Common::Quaternion<float> q = Common::MakeQuaternion(Common::Vec3<float>(), 0); |
| 89 | Common::Quaternion<float> old_q; | ||
| 90 | 91 | ||
| 91 | while (!shutdown_event.WaitUntil(update_time)) { | 92 | while (!shutdown_event.WaitUntil(update_time)) { |
| 92 | update_time += update_duration; | 93 | update_time += update_duration; |
| 93 | old_q = q; | 94 | const Common::Quaternion<float> old_q = q; |
| 94 | 95 | ||
| 95 | { | 96 | { |
| 96 | std::lock_guard guard{tilt_mutex}; | 97 | std::lock_guard guard{tilt_mutex}; |
| @@ -100,14 +101,14 @@ private: | |||
| 100 | Common::MakeVec(-tilt_direction.y, 0.0f, tilt_direction.x), tilt_angle); | 101 | Common::MakeVec(-tilt_direction.y, 0.0f, tilt_direction.x), tilt_angle); |
| 101 | } | 102 | } |
| 102 | 103 | ||
| 103 | auto inv_q = q.Inverse(); | 104 | const auto inv_q = q.Inverse(); |
| 104 | 105 | ||
| 105 | // Set the gravity vector in world space | 106 | // Set the gravity vector in world space |
| 106 | auto gravity = Common::MakeVec(0.0f, -1.0f, 0.0f); | 107 | auto gravity = Common::MakeVec(0.0f, -1.0f, 0.0f); |
| 107 | 108 | ||
| 108 | // Find the angular rate vector in world space | 109 | // Find the angular rate vector in world space |
| 109 | auto angular_rate = ((q - old_q) * inv_q).xyz * 2; | 110 | auto angular_rate = ((q - old_q) * inv_q).xyz * 2; |
| 110 | angular_rate *= 1000 / update_millisecond / Common::PI * 180; | 111 | angular_rate *= static_cast<float>(1000 / update_millisecond) / Common::PI * 180.0f; |
| 111 | 112 | ||
| 112 | // Transform the two vectors from world space to 3DS space | 113 | // Transform the two vectors from world space to 3DS space |
| 113 | gravity = QuaternionRotate(inv_q, gravity); | 114 | gravity = QuaternionRotate(inv_q, gravity); |
| @@ -136,7 +137,7 @@ private: | |||
| 136 | // can forward all the inputs to the implementation only when it is valid. | 137 | // can forward all the inputs to the implementation only when it is valid. |
| 137 | class MotionEmuDeviceWrapper : public Input::MotionDevice { | 138 | class MotionEmuDeviceWrapper : public Input::MotionDevice { |
| 138 | public: | 139 | public: |
| 139 | MotionEmuDeviceWrapper(int update_millisecond, float sensitivity) { | 140 | explicit MotionEmuDeviceWrapper(int update_millisecond, float sensitivity) { |
| 140 | device = std::make_shared<MotionEmuDevice>(update_millisecond, sensitivity); | 141 | device = std::make_shared<MotionEmuDevice>(update_millisecond, sensitivity); |
| 141 | } | 142 | } |
| 142 | 143 | ||
| @@ -148,8 +149,8 @@ public: | |||
| 148 | }; | 149 | }; |
| 149 | 150 | ||
| 150 | std::unique_ptr<Input::MotionDevice> MotionEmu::Create(const Common::ParamPackage& params) { | 151 | std::unique_ptr<Input::MotionDevice> MotionEmu::Create(const Common::ParamPackage& params) { |
| 151 | int update_period = params.Get("update_period", 100); | 152 | const int update_period = params.Get("update_period", 100); |
| 152 | float sensitivity = params.Get("sensitivity", 0.01f); | 153 | const float sensitivity = params.Get("sensitivity", 0.01f); |
| 153 | auto device_wrapper = std::make_unique<MotionEmuDeviceWrapper>(update_period, sensitivity); | 154 | auto device_wrapper = std::make_unique<MotionEmuDeviceWrapper>(update_period, sensitivity); |
| 154 | // Previously created device is disconnected here. Having two motion devices for 3DS is not | 155 | // Previously created device is disconnected here. Having two motion devices for 3DS is not |
| 155 | // expected. | 156 | // expected. |
diff --git a/src/input_common/motion_from_button.cpp b/src/input_common/motion_from_button.cpp index 9d459f963..29045a673 100644 --- a/src/input_common/motion_from_button.cpp +++ b/src/input_common/motion_from_button.cpp | |||
| @@ -11,7 +11,7 @@ class MotionKey final : public Input::MotionDevice { | |||
| 11 | public: | 11 | public: |
| 12 | using Button = std::unique_ptr<Input::ButtonDevice>; | 12 | using Button = std::unique_ptr<Input::ButtonDevice>; |
| 13 | 13 | ||
| 14 | MotionKey(Button key_) : key(std::move(key_)) {} | 14 | explicit MotionKey(Button key_) : key(std::move(key_)) {} |
| 15 | 15 | ||
| 16 | Input::MotionStatus GetStatus() const override { | 16 | Input::MotionStatus GetStatus() const override { |
| 17 | 17 | ||
diff --git a/src/input_common/motion_input.cpp b/src/input_common/motion_input.cpp index e89019723..f77ba535d 100644 --- a/src/input_common/motion_input.cpp +++ b/src/input_common/motion_input.cpp | |||
| @@ -8,8 +8,7 @@ | |||
| 8 | 8 | ||
| 9 | namespace InputCommon { | 9 | namespace InputCommon { |
| 10 | 10 | ||
| 11 | MotionInput::MotionInput(f32 new_kp, f32 new_ki, f32 new_kd) | 11 | MotionInput::MotionInput(f32 new_kp, f32 new_ki, f32 new_kd) : kp(new_kp), ki(new_ki), kd(new_kd) {} |
| 12 | : kp(new_kp), ki(new_ki), kd(new_kd), quat{{0, 0, -1}, 0} {} | ||
| 13 | 12 | ||
| 14 | void MotionInput::SetAcceleration(const Common::Vec3f& acceleration) { | 13 | void MotionInput::SetAcceleration(const Common::Vec3f& acceleration) { |
| 15 | accel = acceleration; | 14 | accel = acceleration; |
| @@ -59,7 +58,7 @@ bool MotionInput::IsCalibrated(f32 sensitivity) const { | |||
| 59 | } | 58 | } |
| 60 | 59 | ||
| 61 | void MotionInput::UpdateRotation(u64 elapsed_time) { | 60 | void MotionInput::UpdateRotation(u64 elapsed_time) { |
| 62 | const f32 sample_period = elapsed_time / 1000000.0f; | 61 | const auto sample_period = static_cast<f32>(elapsed_time) / 1000000.0f; |
| 63 | if (sample_period > 0.1f) { | 62 | if (sample_period > 0.1f) { |
| 64 | return; | 63 | return; |
| 65 | } | 64 | } |
| @@ -75,7 +74,7 @@ void MotionInput::UpdateOrientation(u64 elapsed_time) { | |||
| 75 | f32 q2 = quat.xyz[0]; | 74 | f32 q2 = quat.xyz[0]; |
| 76 | f32 q3 = quat.xyz[1]; | 75 | f32 q3 = quat.xyz[1]; |
| 77 | f32 q4 = quat.xyz[2]; | 76 | f32 q4 = quat.xyz[2]; |
| 78 | const f32 sample_period = elapsed_time / 1000000.0f; | 77 | const auto sample_period = static_cast<f32>(elapsed_time) / 1000000.0f; |
| 79 | 78 | ||
| 80 | // Ignore invalid elapsed time | 79 | // Ignore invalid elapsed time |
| 81 | if (sample_period > 0.1f) { | 80 | if (sample_period > 0.1f) { |
| @@ -203,21 +202,21 @@ Input::MotionStatus MotionInput::GetRandomMotion(int accel_magnitude, int gyro_m | |||
| 203 | std::random_device device; | 202 | std::random_device device; |
| 204 | std::mt19937 gen(device()); | 203 | std::mt19937 gen(device()); |
| 205 | std::uniform_int_distribution<s16> distribution(-1000, 1000); | 204 | std::uniform_int_distribution<s16> distribution(-1000, 1000); |
| 206 | const Common::Vec3f gyroscope = { | 205 | const Common::Vec3f gyroscope{ |
| 207 | distribution(gen) * 0.001f, | 206 | static_cast<f32>(distribution(gen)) * 0.001f, |
| 208 | distribution(gen) * 0.001f, | 207 | static_cast<f32>(distribution(gen)) * 0.001f, |
| 209 | distribution(gen) * 0.001f, | 208 | static_cast<f32>(distribution(gen)) * 0.001f, |
| 210 | }; | 209 | }; |
| 211 | const Common::Vec3f accelerometer = { | 210 | const Common::Vec3f accelerometer{ |
| 212 | distribution(gen) * 0.001f, | 211 | static_cast<f32>(distribution(gen)) * 0.001f, |
| 213 | distribution(gen) * 0.001f, | 212 | static_cast<f32>(distribution(gen)) * 0.001f, |
| 214 | distribution(gen) * 0.001f, | 213 | static_cast<f32>(distribution(gen)) * 0.001f, |
| 215 | }; | 214 | }; |
| 216 | const Common::Vec3f rotation = {}; | 215 | constexpr Common::Vec3f rotation; |
| 217 | const std::array<Common::Vec3f, 3> orientation = { | 216 | constexpr std::array orientation{ |
| 218 | Common::Vec3f{1.0f, 0, 0}, | 217 | Common::Vec3f{1.0f, 0.0f, 0.0f}, |
| 219 | Common::Vec3f{0, 1.0f, 0}, | 218 | Common::Vec3f{0.0f, 1.0f, 0.0f}, |
| 220 | Common::Vec3f{0, 0, 1.0f}, | 219 | Common::Vec3f{0.0f, 0.0f, 1.0f}, |
| 221 | }; | 220 | }; |
| 222 | return {accelerometer * accel_magnitude, gyroscope * gyro_magnitude, rotation, orientation}; | 221 | return {accelerometer * accel_magnitude, gyroscope * gyro_magnitude, rotation, orientation}; |
| 223 | } | 222 | } |
| @@ -247,9 +246,6 @@ void MotionInput::SetOrientationFromAccelerometer() { | |||
| 247 | const f32 sample_period = 0.015f; | 246 | const f32 sample_period = 0.015f; |
| 248 | 247 | ||
| 249 | const auto normal_accel = accel.Normalized(); | 248 | const auto normal_accel = accel.Normalized(); |
| 250 | const f32 ax = -normal_accel.x; | ||
| 251 | const f32 ay = normal_accel.y; | ||
| 252 | const f32 az = -normal_accel.z; | ||
| 253 | 249 | ||
| 254 | while (!IsCalibrated(0.01f) && ++iterations < 100) { | 250 | while (!IsCalibrated(0.01f) && ++iterations < 100) { |
| 255 | // Short name local variable for readability | 251 | // Short name local variable for readability |
| @@ -258,7 +254,7 @@ void MotionInput::SetOrientationFromAccelerometer() { | |||
| 258 | f32 q3 = quat.xyz[1]; | 254 | f32 q3 = quat.xyz[1]; |
| 259 | f32 q4 = quat.xyz[2]; | 255 | f32 q4 = quat.xyz[2]; |
| 260 | 256 | ||
| 261 | Common::Vec3f rad_gyro = {}; | 257 | Common::Vec3f rad_gyro; |
| 262 | const f32 ax = -normal_accel.x; | 258 | const f32 ax = -normal_accel.x; |
| 263 | const f32 ay = normal_accel.y; | 259 | const f32 ay = normal_accel.y; |
| 264 | const f32 az = -normal_accel.z; | 260 | const f32 az = -normal_accel.z; |
diff --git a/src/input_common/motion_input.h b/src/input_common/motion_input.h index 6342d0318..abb957f04 100644 --- a/src/input_common/motion_input.h +++ b/src/input_common/motion_input.h | |||
| @@ -22,7 +22,7 @@ public: | |||
| 22 | MotionInput& operator=(MotionInput&&) = default; | 22 | MotionInput& operator=(MotionInput&&) = default; |
| 23 | 23 | ||
| 24 | void SetAcceleration(const Common::Vec3f& acceleration); | 24 | void SetAcceleration(const Common::Vec3f& acceleration); |
| 25 | void SetGyroscope(const Common::Vec3f& acceleration); | 25 | void SetGyroscope(const Common::Vec3f& gyroscope); |
| 26 | void SetQuaternion(const Common::Quaternion<f32>& quaternion); | 26 | void SetQuaternion(const Common::Quaternion<f32>& quaternion); |
| 27 | void SetGyroDrift(const Common::Vec3f& drift); | 27 | void SetGyroDrift(const Common::Vec3f& drift); |
| 28 | void SetGyroThreshold(f32 threshold); | 28 | void SetGyroThreshold(f32 threshold); |
| @@ -49,16 +49,16 @@ private: | |||
| 49 | void SetOrientationFromAccelerometer(); | 49 | void SetOrientationFromAccelerometer(); |
| 50 | 50 | ||
| 51 | // PID constants | 51 | // PID constants |
| 52 | const f32 kp; | 52 | f32 kp; |
| 53 | const f32 ki; | 53 | f32 ki; |
| 54 | const f32 kd; | 54 | f32 kd; |
| 55 | 55 | ||
| 56 | // PID errors | 56 | // PID errors |
| 57 | Common::Vec3f real_error; | 57 | Common::Vec3f real_error; |
| 58 | Common::Vec3f integral_error; | 58 | Common::Vec3f integral_error; |
| 59 | Common::Vec3f derivative_error; | 59 | Common::Vec3f derivative_error; |
| 60 | 60 | ||
| 61 | Common::Quaternion<f32> quat; | 61 | Common::Quaternion<f32> quat{{0.0f, 0.0f, -1.0f}, 0.0f}; |
| 62 | Common::Vec3f rotations; | 62 | Common::Vec3f rotations; |
| 63 | Common::Vec3f accel; | 63 | Common::Vec3f accel; |
| 64 | Common::Vec3f gyro; | 64 | Common::Vec3f gyro; |
diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp index bd480570a..8c2cef35d 100644 --- a/src/input_common/sdl/sdl_impl.cpp +++ b/src/input_common/sdl/sdl_impl.cpp | |||
| @@ -56,9 +56,9 @@ static int SDLEventWatcher(void* user_data, SDL_Event* event) { | |||
| 56 | class SDLJoystick { | 56 | class SDLJoystick { |
| 57 | public: | 57 | public: |
| 58 | SDLJoystick(std::string guid_, int port_, SDL_Joystick* joystick, | 58 | SDLJoystick(std::string guid_, int port_, SDL_Joystick* joystick, |
| 59 | SDL_GameController* gamecontroller) | 59 | SDL_GameController* game_controller) |
| 60 | : guid{std::move(guid_)}, port{port_}, sdl_joystick{joystick, &SDL_JoystickClose}, | 60 | : guid{std::move(guid_)}, port{port_}, sdl_joystick{joystick, &SDL_JoystickClose}, |
| 61 | sdl_controller{gamecontroller, &SDL_GameControllerClose} {} | 61 | sdl_controller{game_controller, &SDL_GameControllerClose} {} |
| 62 | 62 | ||
| 63 | void SetButton(int button, bool value) { | 63 | void SetButton(int button, bool value) { |
| 64 | std::lock_guard lock{mutex}; | 64 | std::lock_guard lock{mutex}; |
| @@ -77,10 +77,10 @@ public: | |||
| 77 | 77 | ||
| 78 | float GetAxis(int axis, float range) const { | 78 | float GetAxis(int axis, float range) const { |
| 79 | std::lock_guard lock{mutex}; | 79 | std::lock_guard lock{mutex}; |
| 80 | return state.axes.at(axis) / (32767.0f * range); | 80 | return static_cast<float>(state.axes.at(axis)) / (32767.0f * range); |
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | bool RumblePlay(f32 amp_low, f32 amp_high, int time) { | 83 | bool RumblePlay(f32 amp_low, f32 amp_high, u32 time) { |
| 84 | const u16 raw_amp_low = static_cast<u16>(amp_low * 0xFFFF); | 84 | const u16 raw_amp_low = static_cast<u16>(amp_low * 0xFFFF); |
| 85 | const u16 raw_amp_high = static_cast<u16>(amp_high * 0xFFFF); | 85 | const u16 raw_amp_high = static_cast<u16>(amp_high * 0xFFFF); |
| 86 | // Lower drastically the number of state changes | 86 | // Lower drastically the number of state changes |
| @@ -124,7 +124,7 @@ public: | |||
| 124 | return std::make_tuple(x, y); | 124 | return std::make_tuple(x, y); |
| 125 | } | 125 | } |
| 126 | 126 | ||
| 127 | const InputCommon::MotionInput& GetMotion() const { | 127 | const MotionInput& GetMotion() const { |
| 128 | return motion; | 128 | return motion; |
| 129 | } | 129 | } |
| 130 | 130 | ||
| @@ -172,15 +172,15 @@ private: | |||
| 172 | } state; | 172 | } state; |
| 173 | std::string guid; | 173 | std::string guid; |
| 174 | int port; | 174 | int port; |
| 175 | u16 last_state_rumble_high; | 175 | u16 last_state_rumble_high = 0; |
| 176 | u16 last_state_rumble_low; | 176 | u16 last_state_rumble_low = 0; |
| 177 | std::chrono::time_point<std::chrono::system_clock> last_vibration; | 177 | std::chrono::time_point<std::chrono::system_clock> last_vibration; |
| 178 | std::unique_ptr<SDL_Joystick, decltype(&SDL_JoystickClose)> sdl_joystick; | 178 | std::unique_ptr<SDL_Joystick, decltype(&SDL_JoystickClose)> sdl_joystick; |
| 179 | std::unique_ptr<SDL_GameController, decltype(&SDL_GameControllerClose)> sdl_controller; | 179 | std::unique_ptr<SDL_GameController, decltype(&SDL_GameControllerClose)> sdl_controller; |
| 180 | mutable std::mutex mutex; | 180 | mutable std::mutex mutex; |
| 181 | 181 | ||
| 182 | // motion is initalized without PID values as motion input is not aviable for SDL2 | 182 | // Motion is initialized without PID values as motion input is not aviable for SDL2 |
| 183 | InputCommon::MotionInput motion{0.0f, 0.0f, 0.0f}; | 183 | MotionInput motion{0.0f, 0.0f, 0.0f}; |
| 184 | }; | 184 | }; |
| 185 | 185 | ||
| 186 | std::shared_ptr<SDLJoystick> SDLState::GetSDLJoystickByGUID(const std::string& guid, int port) { | 186 | std::shared_ptr<SDLJoystick> SDLState::GetSDLJoystickByGUID(const std::string& guid, int port) { |
| @@ -192,7 +192,7 @@ std::shared_ptr<SDLJoystick> SDLState::GetSDLJoystickByGUID(const std::string& g | |||
| 192 | nullptr, nullptr); | 192 | nullptr, nullptr); |
| 193 | it->second.emplace_back(std::move(joystick)); | 193 | it->second.emplace_back(std::move(joystick)); |
| 194 | } | 194 | } |
| 195 | return it->second[port]; | 195 | return it->second[static_cast<std::size_t>(port)]; |
| 196 | } | 196 | } |
| 197 | auto joystick = std::make_shared<SDLJoystick>(guid, 0, nullptr, nullptr); | 197 | auto joystick = std::make_shared<SDLJoystick>(guid, 0, nullptr, nullptr); |
| 198 | return joystick_map[guid].emplace_back(std::move(joystick)); | 198 | return joystick_map[guid].emplace_back(std::move(joystick)); |
| @@ -212,7 +212,7 @@ std::shared_ptr<SDLJoystick> SDLState::GetSDLJoystickBySDLID(SDL_JoystickID sdl_ | |||
| 212 | return sdl_joystick == joystick->GetSDLJoystick(); | 212 | return sdl_joystick == joystick->GetSDLJoystick(); |
| 213 | }); | 213 | }); |
| 214 | if (vec_it != map_it->second.end()) { | 214 | if (vec_it != map_it->second.end()) { |
| 215 | // This is the common case: There is already an existing SDL_Joystick maped to a | 215 | // This is the common case: There is already an existing SDL_Joystick mapped to a |
| 216 | // SDLJoystick. return the SDLJoystick | 216 | // SDLJoystick. return the SDLJoystick |
| 217 | return *vec_it; | 217 | return *vec_it; |
| 218 | } | 218 | } |
| @@ -220,7 +220,7 @@ std::shared_ptr<SDLJoystick> SDLState::GetSDLJoystickBySDLID(SDL_JoystickID sdl_ | |||
| 220 | // Search for a SDLJoystick without a mapped SDL_Joystick... | 220 | // Search for a SDLJoystick without a mapped SDL_Joystick... |
| 221 | const auto nullptr_it = std::find_if(map_it->second.begin(), map_it->second.end(), | 221 | const auto nullptr_it = std::find_if(map_it->second.begin(), map_it->second.end(), |
| 222 | [](const std::shared_ptr<SDLJoystick>& joystick) { | 222 | [](const std::shared_ptr<SDLJoystick>& joystick) { |
| 223 | return !joystick->GetSDLJoystick(); | 223 | return joystick->GetSDLJoystick() == nullptr; |
| 224 | }); | 224 | }); |
| 225 | if (nullptr_it != map_it->second.end()) { | 225 | if (nullptr_it != map_it->second.end()) { |
| 226 | // ... and map it | 226 | // ... and map it |
| @@ -273,22 +273,21 @@ void SDLState::InitJoystick(int joystick_index) { | |||
| 273 | void SDLState::CloseJoystick(SDL_Joystick* sdl_joystick) { | 273 | void SDLState::CloseJoystick(SDL_Joystick* sdl_joystick) { |
| 274 | const std::string guid = GetGUID(sdl_joystick); | 274 | const std::string guid = GetGUID(sdl_joystick); |
| 275 | 275 | ||
| 276 | std::shared_ptr<SDLJoystick> joystick; | 276 | std::shared_ptr<SDLJoystick> found_joystick; |
| 277 | { | 277 | { |
| 278 | std::lock_guard lock{joystick_map_mutex}; | 278 | std::lock_guard lock{joystick_map_mutex}; |
| 279 | // This call to guid is safe since the joystick is guaranteed to be in the map | 279 | // This call to guid is safe since the joystick is guaranteed to be in the map |
| 280 | const auto& joystick_guid_list = joystick_map[guid]; | 280 | const auto& joystick_guid_list = joystick_map[guid]; |
| 281 | const auto joystick_it = | 281 | const auto joystick_it = std::find_if(joystick_guid_list.begin(), joystick_guid_list.end(), |
| 282 | std::find_if(joystick_guid_list.begin(), joystick_guid_list.end(), | 282 | [&sdl_joystick](const auto& joystick) { |
| 283 | [&sdl_joystick](const std::shared_ptr<SDLJoystick>& joystick) { | 283 | return joystick->GetSDLJoystick() == sdl_joystick; |
| 284 | return joystick->GetSDLJoystick() == sdl_joystick; | 284 | }); |
| 285 | }); | 285 | found_joystick = *joystick_it; |
| 286 | joystick = *joystick_it; | ||
| 287 | } | 286 | } |
| 288 | 287 | ||
| 289 | // Destruct SDL_Joystick outside the lock guard because SDL can internally call the | 288 | // Destruct SDL_Joystick outside the lock guard because SDL can internally call the |
| 290 | // event callback which locks the mutex again. | 289 | // event callback which locks the mutex again. |
| 291 | joystick->SetSDLJoystick(nullptr, nullptr); | 290 | found_joystick->SetSDLJoystick(nullptr, nullptr); |
| 292 | } | 291 | } |
| 293 | 292 | ||
| 294 | void SDLState::HandleGameControllerEvent(const SDL_Event& event) { | 293 | void SDLState::HandleGameControllerEvent(const SDL_Event& event) { |
| @@ -392,8 +391,8 @@ private: | |||
| 392 | 391 | ||
| 393 | class SDLAnalog final : public Input::AnalogDevice { | 392 | class SDLAnalog final : public Input::AnalogDevice { |
| 394 | public: | 393 | public: |
| 395 | SDLAnalog(std::shared_ptr<SDLJoystick> joystick_, int axis_x_, int axis_y_, float deadzone_, | 394 | explicit SDLAnalog(std::shared_ptr<SDLJoystick> joystick_, int axis_x_, int axis_y_, |
| 396 | float range_) | 395 | float deadzone_, float range_) |
| 397 | : joystick(std::move(joystick_)), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_), | 396 | : joystick(std::move(joystick_)), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_), |
| 398 | range(range_) {} | 397 | range(range_) {} |
| 399 | 398 | ||
| @@ -672,13 +671,13 @@ SDLState::SDLState() { | |||
| 672 | RegisterFactory<ButtonDevice>("sdl", button_factory); | 671 | RegisterFactory<ButtonDevice>("sdl", button_factory); |
| 673 | RegisterFactory<MotionDevice>("sdl", motion_factory); | 672 | RegisterFactory<MotionDevice>("sdl", motion_factory); |
| 674 | 673 | ||
| 675 | // If the frontend is going to manage the event loop, then we dont start one here | 674 | // If the frontend is going to manage the event loop, then we don't start one here |
| 676 | start_thread = !SDL_WasInit(SDL_INIT_JOYSTICK); | 675 | start_thread = SDL_WasInit(SDL_INIT_JOYSTICK) == 0; |
| 677 | if (start_thread && SDL_Init(SDL_INIT_JOYSTICK) < 0) { | 676 | if (start_thread && SDL_Init(SDL_INIT_JOYSTICK) < 0) { |
| 678 | LOG_CRITICAL(Input, "SDL_Init(SDL_INIT_JOYSTICK) failed with: {}", SDL_GetError()); | 677 | LOG_CRITICAL(Input, "SDL_Init(SDL_INIT_JOYSTICK) failed with: {}", SDL_GetError()); |
| 679 | return; | 678 | return; |
| 680 | } | 679 | } |
| 681 | has_gamecontroller = SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER); | 680 | has_gamecontroller = SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) != 0; |
| 682 | if (SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1") == SDL_FALSE) { | 681 | if (SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1") == SDL_FALSE) { |
| 683 | LOG_ERROR(Input, "Failed to set hint for background events with: {}", SDL_GetError()); | 682 | LOG_ERROR(Input, "Failed to set hint for background events with: {}", SDL_GetError()); |
| 684 | } | 683 | } |
| @@ -723,8 +722,8 @@ std::vector<Common::ParamPackage> SDLState::GetInputDevices() { | |||
| 723 | std::vector<Common::ParamPackage> devices; | 722 | std::vector<Common::ParamPackage> devices; |
| 724 | for (const auto& [key, value] : joystick_map) { | 723 | for (const auto& [key, value] : joystick_map) { |
| 725 | for (const auto& joystick : value) { | 724 | for (const auto& joystick : value) { |
| 726 | auto joy = joystick->GetSDLJoystick(); | 725 | auto* joy = joystick->GetSDLJoystick(); |
| 727 | if (auto controller = joystick->GetSDLGameController()) { | 726 | if (auto* controller = joystick->GetSDLGameController()) { |
| 728 | std::string name = | 727 | std::string name = |
| 729 | fmt::format("{} {}", SDL_GameControllerName(controller), joystick->GetPort()); | 728 | fmt::format("{} {}", SDL_GameControllerName(controller), joystick->GetPort()); |
| 730 | devices.emplace_back(Common::ParamPackage{ | 729 | devices.emplace_back(Common::ParamPackage{ |
| @@ -748,7 +747,7 @@ std::vector<Common::ParamPackage> SDLState::GetInputDevices() { | |||
| 748 | } | 747 | } |
| 749 | 748 | ||
| 750 | namespace { | 749 | namespace { |
| 751 | Common::ParamPackage BuildAnalogParamPackageForButton(int port, std::string guid, u8 axis, | 750 | Common::ParamPackage BuildAnalogParamPackageForButton(int port, std::string guid, s32 axis, |
| 752 | float value = 0.1f) { | 751 | float value = 0.1f) { |
| 753 | Common::ParamPackage params({{"engine", "sdl"}}); | 752 | Common::ParamPackage params({{"engine", "sdl"}}); |
| 754 | params.Set("port", port); | 753 | params.Set("port", port); |
| @@ -764,7 +763,7 @@ Common::ParamPackage BuildAnalogParamPackageForButton(int port, std::string guid | |||
| 764 | return params; | 763 | return params; |
| 765 | } | 764 | } |
| 766 | 765 | ||
| 767 | Common::ParamPackage BuildButtonParamPackageForButton(int port, std::string guid, u8 button) { | 766 | Common::ParamPackage BuildButtonParamPackageForButton(int port, std::string guid, s32 button) { |
| 768 | Common::ParamPackage params({{"engine", "sdl"}}); | 767 | Common::ParamPackage params({{"engine", "sdl"}}); |
| 769 | params.Set("port", port); | 768 | params.Set("port", port); |
| 770 | params.Set("guid", std::move(guid)); | 769 | params.Set("guid", std::move(guid)); |
| @@ -772,7 +771,7 @@ Common::ParamPackage BuildButtonParamPackageForButton(int port, std::string guid | |||
| 772 | return params; | 771 | return params; |
| 773 | } | 772 | } |
| 774 | 773 | ||
| 775 | Common::ParamPackage BuildHatParamPackageForButton(int port, std::string guid, u8 hat, u8 value) { | 774 | Common::ParamPackage BuildHatParamPackageForButton(int port, std::string guid, s32 hat, s32 value) { |
| 776 | Common::ParamPackage params({{"engine", "sdl"}}); | 775 | Common::ParamPackage params({{"engine", "sdl"}}); |
| 777 | 776 | ||
| 778 | params.Set("port", port); | 777 | params.Set("port", port); |
| @@ -802,17 +801,19 @@ Common::ParamPackage SDLEventToButtonParamPackage(SDLState& state, const SDL_Eve | |||
| 802 | case SDL_JOYAXISMOTION: { | 801 | case SDL_JOYAXISMOTION: { |
| 803 | const auto joystick = state.GetSDLJoystickBySDLID(event.jaxis.which); | 802 | const auto joystick = state.GetSDLJoystickBySDLID(event.jaxis.which); |
| 804 | return BuildAnalogParamPackageForButton(joystick->GetPort(), joystick->GetGUID(), | 803 | return BuildAnalogParamPackageForButton(joystick->GetPort(), joystick->GetGUID(), |
| 805 | event.jaxis.axis, event.jaxis.value); | 804 | static_cast<s32>(event.jaxis.axis), |
| 805 | event.jaxis.value); | ||
| 806 | } | 806 | } |
| 807 | case SDL_JOYBUTTONUP: { | 807 | case SDL_JOYBUTTONUP: { |
| 808 | const auto joystick = state.GetSDLJoystickBySDLID(event.jbutton.which); | 808 | const auto joystick = state.GetSDLJoystickBySDLID(event.jbutton.which); |
| 809 | return BuildButtonParamPackageForButton(joystick->GetPort(), joystick->GetGUID(), | 809 | return BuildButtonParamPackageForButton(joystick->GetPort(), joystick->GetGUID(), |
| 810 | event.jbutton.button); | 810 | static_cast<s32>(event.jbutton.button)); |
| 811 | } | 811 | } |
| 812 | case SDL_JOYHATMOTION: { | 812 | case SDL_JOYHATMOTION: { |
| 813 | const auto joystick = state.GetSDLJoystickBySDLID(event.jhat.which); | 813 | const auto joystick = state.GetSDLJoystickBySDLID(event.jhat.which); |
| 814 | return BuildHatParamPackageForButton(joystick->GetPort(), joystick->GetGUID(), | 814 | return BuildHatParamPackageForButton(joystick->GetPort(), joystick->GetGUID(), |
| 815 | event.jhat.hat, event.jhat.value); | 815 | static_cast<s32>(event.jhat.hat), |
| 816 | static_cast<s32>(event.jhat.value)); | ||
| 816 | } | 817 | } |
| 817 | } | 818 | } |
| 818 | return {}; | 819 | return {}; |
| @@ -823,17 +824,19 @@ Common::ParamPackage SDLEventToMotionParamPackage(SDLState& state, const SDL_Eve | |||
| 823 | case SDL_JOYAXISMOTION: { | 824 | case SDL_JOYAXISMOTION: { |
| 824 | const auto joystick = state.GetSDLJoystickBySDLID(event.jaxis.which); | 825 | const auto joystick = state.GetSDLJoystickBySDLID(event.jaxis.which); |
| 825 | return BuildAnalogParamPackageForButton(joystick->GetPort(), joystick->GetGUID(), | 826 | return BuildAnalogParamPackageForButton(joystick->GetPort(), joystick->GetGUID(), |
| 826 | event.jaxis.axis, event.jaxis.value); | 827 | static_cast<s32>(event.jaxis.axis), |
| 828 | event.jaxis.value); | ||
| 827 | } | 829 | } |
| 828 | case SDL_JOYBUTTONUP: { | 830 | case SDL_JOYBUTTONUP: { |
| 829 | const auto joystick = state.GetSDLJoystickBySDLID(event.jbutton.which); | 831 | const auto joystick = state.GetSDLJoystickBySDLID(event.jbutton.which); |
| 830 | return BuildButtonParamPackageForButton(joystick->GetPort(), joystick->GetGUID(), | 832 | return BuildButtonParamPackageForButton(joystick->GetPort(), joystick->GetGUID(), |
| 831 | event.jbutton.button); | 833 | static_cast<s32>(event.jbutton.button)); |
| 832 | } | 834 | } |
| 833 | case SDL_JOYHATMOTION: { | 835 | case SDL_JOYHATMOTION: { |
| 834 | const auto joystick = state.GetSDLJoystickBySDLID(event.jhat.which); | 836 | const auto joystick = state.GetSDLJoystickBySDLID(event.jhat.which); |
| 835 | return BuildHatParamPackageForButton(joystick->GetPort(), joystick->GetGUID(), | 837 | return BuildHatParamPackageForButton(joystick->GetPort(), joystick->GetGUID(), |
| 836 | event.jhat.hat, event.jhat.value); | 838 | static_cast<s32>(event.jhat.hat), |
| 839 | static_cast<s32>(event.jhat.value)); | ||
| 837 | } | 840 | } |
| 838 | } | 841 | } |
| 839 | return {}; | 842 | return {}; |
| @@ -1062,7 +1065,7 @@ public: | |||
| 1062 | if (event.type == SDL_JOYAXISMOTION) { | 1065 | if (event.type == SDL_JOYAXISMOTION) { |
| 1063 | const auto axis = event.jaxis.axis; | 1066 | const auto axis = event.jaxis.axis; |
| 1064 | const auto joystick = state.GetSDLJoystickBySDLID(event.jaxis.which); | 1067 | const auto joystick = state.GetSDLJoystickBySDLID(event.jaxis.which); |
| 1065 | const auto controller = joystick->GetSDLGameController(); | 1068 | auto* const controller = joystick->GetSDLGameController(); |
| 1066 | if (controller) { | 1069 | if (controller) { |
| 1067 | const auto axis_left_x = | 1070 | const auto axis_left_x = |
| 1068 | SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_LEFTX) | 1071 | SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_LEFTX) |
diff --git a/src/input_common/touch_from_button.cpp b/src/input_common/touch_from_button.cpp index 98da0ef1a..c37716aae 100644 --- a/src/input_common/touch_from_button.cpp +++ b/src/input_common/touch_from_button.cpp | |||
| @@ -11,9 +11,11 @@ namespace InputCommon { | |||
| 11 | class TouchFromButtonDevice final : public Input::TouchDevice { | 11 | class TouchFromButtonDevice final : public Input::TouchDevice { |
| 12 | public: | 12 | public: |
| 13 | TouchFromButtonDevice() { | 13 | TouchFromButtonDevice() { |
| 14 | for (const auto& config_entry : | 14 | const auto button_index = |
| 15 | Settings::values.touch_from_button_maps[Settings::values.touch_from_button_map_index] | 15 | static_cast<std::size_t>(Settings::values.touch_from_button_map_index); |
| 16 | .buttons) { | 16 | const auto& buttons = Settings::values.touch_from_button_maps[button_index].buttons; |
| 17 | |||
| 18 | for (const auto& config_entry : buttons) { | ||
| 17 | const Common::ParamPackage package{config_entry}; | 19 | const Common::ParamPackage package{config_entry}; |
| 18 | map.emplace_back( | 20 | map.emplace_back( |
| 19 | Input::CreateDevice<Input::ButtonDevice>(config_entry), | 21 | Input::CreateDevice<Input::ButtonDevice>(config_entry), |
diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp index 9d0b9f31d..7039d6fc3 100644 --- a/src/input_common/udp/client.cpp +++ b/src/input_common/udp/client.cpp | |||
| @@ -26,11 +26,11 @@ class Socket { | |||
| 26 | public: | 26 | public: |
| 27 | using clock = std::chrono::system_clock; | 27 | using clock = std::chrono::system_clock; |
| 28 | 28 | ||
| 29 | explicit Socket(const std::string& host, u16 port, u8 pad_index, u32 client_id, | 29 | explicit Socket(const std::string& host, u16 port, std::size_t pad_index_, u32 client_id_, |
| 30 | SocketCallback callback) | 30 | SocketCallback callback_) |
| 31 | : callback(std::move(callback)), timer(io_service), | 31 | : callback(std::move(callback_)), timer(io_service), |
| 32 | socket(io_service, udp::endpoint(udp::v4(), 0)), client_id(client_id), | 32 | socket(io_service, udp::endpoint(udp::v4(), 0)), client_id(client_id_), |
| 33 | pad_index(pad_index) { | 33 | pad_index(pad_index_) { |
| 34 | boost::system::error_code ec{}; | 34 | boost::system::error_code ec{}; |
| 35 | auto ipv4 = boost::asio::ip::make_address_v4(host, ec); | 35 | auto ipv4 = boost::asio::ip::make_address_v4(host, ec); |
| 36 | if (ec.value() != boost::system::errc::success) { | 36 | if (ec.value() != boost::system::errc::success) { |
| @@ -93,13 +93,17 @@ private: | |||
| 93 | void HandleSend(const boost::system::error_code& error) { | 93 | void HandleSend(const boost::system::error_code& error) { |
| 94 | boost::system::error_code _ignored{}; | 94 | boost::system::error_code _ignored{}; |
| 95 | // Send a request for getting port info for the pad | 95 | // Send a request for getting port info for the pad |
| 96 | Request::PortInfo port_info{1, {pad_index, 0, 0, 0}}; | 96 | const Request::PortInfo port_info{1, {static_cast<u8>(pad_index), 0, 0, 0}}; |
| 97 | const auto port_message = Request::Create(port_info, client_id); | 97 | const auto port_message = Request::Create(port_info, client_id); |
| 98 | std::memcpy(&send_buffer1, &port_message, PORT_INFO_SIZE); | 98 | std::memcpy(&send_buffer1, &port_message, PORT_INFO_SIZE); |
| 99 | socket.send_to(boost::asio::buffer(send_buffer1), send_endpoint, {}, _ignored); | 99 | socket.send_to(boost::asio::buffer(send_buffer1), send_endpoint, {}, _ignored); |
| 100 | 100 | ||
| 101 | // Send a request for getting pad data for the pad | 101 | // Send a request for getting pad data for the pad |
| 102 | Request::PadData pad_data{Request::PadData::Flags::Id, pad_index, EMPTY_MAC_ADDRESS}; | 102 | const Request::PadData pad_data{ |
| 103 | Request::PadData::Flags::Id, | ||
| 104 | static_cast<u8>(pad_index), | ||
| 105 | EMPTY_MAC_ADDRESS, | ||
| 106 | }; | ||
| 103 | const auto pad_message = Request::Create(pad_data, client_id); | 107 | const auto pad_message = Request::Create(pad_data, client_id); |
| 104 | std::memcpy(send_buffer2.data(), &pad_message, PAD_DATA_SIZE); | 108 | std::memcpy(send_buffer2.data(), &pad_message, PAD_DATA_SIZE); |
| 105 | socket.send_to(boost::asio::buffer(send_buffer2), send_endpoint, {}, _ignored); | 109 | socket.send_to(boost::asio::buffer(send_buffer2), send_endpoint, {}, _ignored); |
| @@ -112,7 +116,7 @@ private: | |||
| 112 | udp::socket socket; | 116 | udp::socket socket; |
| 113 | 117 | ||
| 114 | u32 client_id{}; | 118 | u32 client_id{}; |
| 115 | u8 pad_index{}; | 119 | std::size_t pad_index{}; |
| 116 | 120 | ||
| 117 | static constexpr std::size_t PORT_INFO_SIZE = sizeof(Message<Request::PortInfo>); | 121 | static constexpr std::size_t PORT_INFO_SIZE = sizeof(Message<Request::PortInfo>); |
| 118 | static constexpr std::size_t PAD_DATA_SIZE = sizeof(Message<Request::PadData>); | 122 | static constexpr std::size_t PAD_DATA_SIZE = sizeof(Message<Request::PadData>); |
| @@ -133,7 +137,7 @@ static void SocketLoop(Socket* socket) { | |||
| 133 | Client::Client() { | 137 | Client::Client() { |
| 134 | LOG_INFO(Input, "Udp Initialization started"); | 138 | LOG_INFO(Input, "Udp Initialization started"); |
| 135 | for (std::size_t client = 0; client < clients.size(); client++) { | 139 | for (std::size_t client = 0; client < clients.size(); client++) { |
| 136 | u8 pad = client % 4; | 140 | const auto pad = client % 4; |
| 137 | StartCommunication(client, Settings::values.udp_input_address, | 141 | StartCommunication(client, Settings::values.udp_input_address, |
| 138 | Settings::values.udp_input_port, pad, 24872); | 142 | Settings::values.udp_input_port, pad, 24872); |
| 139 | // Set motion parameters | 143 | // Set motion parameters |
| @@ -166,9 +170,9 @@ std::vector<Common::ParamPackage> Client::GetInputDevices() const { | |||
| 166 | bool Client::DeviceConnected(std::size_t pad) const { | 170 | bool Client::DeviceConnected(std::size_t pad) const { |
| 167 | // Use last timestamp to detect if the socket has stopped sending data | 171 | // Use last timestamp to detect if the socket has stopped sending data |
| 168 | const auto now = std::chrono::system_clock::now(); | 172 | const auto now = std::chrono::system_clock::now(); |
| 169 | u64 time_difference = | 173 | const auto time_difference = static_cast<u64>( |
| 170 | std::chrono::duration_cast<std::chrono::milliseconds>(now - clients[pad].last_motion_update) | 174 | std::chrono::duration_cast<std::chrono::milliseconds>(now - clients[pad].last_motion_update) |
| 171 | .count(); | 175 | .count()); |
| 172 | return time_difference < 1000 && clients[pad].active == 1; | 176 | return time_difference < 1000 && clients[pad].active == 1; |
| 173 | } | 177 | } |
| 174 | 178 | ||
| @@ -177,9 +181,9 @@ void Client::ReloadUDPClient() { | |||
| 177 | ReloadSocket(Settings::values.udp_input_address, Settings::values.udp_input_port, client); | 181 | ReloadSocket(Settings::values.udp_input_address, Settings::values.udp_input_port, client); |
| 178 | } | 182 | } |
| 179 | } | 183 | } |
| 180 | void Client::ReloadSocket(const std::string& host, u16 port, u8 pad_index, u32 client_id) { | 184 | void Client::ReloadSocket(const std::string& host, u16 port, std::size_t pad_index, u32 client_id) { |
| 181 | // client number must be determined from host / port and pad index | 185 | // client number must be determined from host / port and pad index |
| 182 | std::size_t client = pad_index; | 186 | const std::size_t client = pad_index; |
| 183 | clients[client].socket->Stop(); | 187 | clients[client].socket->Stop(); |
| 184 | clients[client].thread.join(); | 188 | clients[client].thread.join(); |
| 185 | StartCommunication(client, host, port, pad_index, client_id); | 189 | StartCommunication(client, host, port, pad_index, client_id); |
| @@ -194,8 +198,8 @@ void Client::OnPortInfo(Response::PortInfo data) { | |||
| 194 | } | 198 | } |
| 195 | 199 | ||
| 196 | void Client::OnPadData(Response::PadData data) { | 200 | void Client::OnPadData(Response::PadData data) { |
| 197 | // client number must be determined from host / port and pad index | 201 | // Client number must be determined from host / port and pad index |
| 198 | std::size_t client = data.info.id; | 202 | const std::size_t client = data.info.id; |
| 199 | LOG_TRACE(Input, "PadData packet received"); | 203 | LOG_TRACE(Input, "PadData packet received"); |
| 200 | if (data.packet_counter == clients[client].packet_sequence) { | 204 | if (data.packet_counter == clients[client].packet_sequence) { |
| 201 | LOG_WARNING( | 205 | LOG_WARNING( |
| @@ -207,11 +211,12 @@ void Client::OnPadData(Response::PadData data) { | |||
| 207 | clients[client].active = data.info.is_pad_active; | 211 | clients[client].active = data.info.is_pad_active; |
| 208 | clients[client].packet_sequence = data.packet_counter; | 212 | clients[client].packet_sequence = data.packet_counter; |
| 209 | const auto now = std::chrono::system_clock::now(); | 213 | const auto now = std::chrono::system_clock::now(); |
| 210 | u64 time_difference = std::chrono::duration_cast<std::chrono::microseconds>( | 214 | const auto time_difference = |
| 211 | now - clients[client].last_motion_update) | 215 | static_cast<u64>(std::chrono::duration_cast<std::chrono::microseconds>( |
| 212 | .count(); | 216 | now - clients[client].last_motion_update) |
| 217 | .count()); | ||
| 213 | clients[client].last_motion_update = now; | 218 | clients[client].last_motion_update = now; |
| 214 | Common::Vec3f raw_gyroscope = {data.gyro.pitch, data.gyro.roll, -data.gyro.yaw}; | 219 | const Common::Vec3f raw_gyroscope = {data.gyro.pitch, data.gyro.roll, -data.gyro.yaw}; |
| 215 | clients[client].motion.SetAcceleration({data.accel.x, -data.accel.z, data.accel.y}); | 220 | clients[client].motion.SetAcceleration({data.accel.x, -data.accel.z, data.accel.y}); |
| 216 | // Gyroscope values are not it the correct scale from better joy. | 221 | // Gyroscope values are not it the correct scale from better joy. |
| 217 | // Dividing by 312 allows us to make one full turn = 1 turn | 222 | // Dividing by 312 allows us to make one full turn = 1 turn |
| @@ -237,9 +242,11 @@ void Client::OnPadData(Response::PadData data) { | |||
| 237 | const u16 min_y = clients[client].status.touch_calibration->min_y; | 242 | const u16 min_y = clients[client].status.touch_calibration->min_y; |
| 238 | const u16 max_y = clients[client].status.touch_calibration->max_y; | 243 | const u16 max_y = clients[client].status.touch_calibration->max_y; |
| 239 | 244 | ||
| 240 | x = (std::clamp(static_cast<u16>(data.touch_1.x), min_x, max_x) - min_x) / | 245 | x = static_cast<float>(std::clamp(static_cast<u16>(data.touch_1.x), min_x, max_x) - |
| 246 | min_x) / | ||
| 241 | static_cast<float>(max_x - min_x); | 247 | static_cast<float>(max_x - min_x); |
| 242 | y = (std::clamp(static_cast<u16>(data.touch_1.y), min_y, max_y) - min_y) / | 248 | y = static_cast<float>(std::clamp(static_cast<u16>(data.touch_1.y), min_y, max_y) - |
| 249 | min_y) / | ||
| 243 | static_cast<float>(max_y - min_y); | 250 | static_cast<float>(max_y - min_y); |
| 244 | } | 251 | } |
| 245 | 252 | ||
| @@ -253,8 +260,8 @@ void Client::OnPadData(Response::PadData data) { | |||
| 253 | } | 260 | } |
| 254 | } | 261 | } |
| 255 | 262 | ||
| 256 | void Client::StartCommunication(std::size_t client, const std::string& host, u16 port, u8 pad_index, | 263 | void Client::StartCommunication(std::size_t client, const std::string& host, u16 port, |
| 257 | u32 client_id) { | 264 | std::size_t pad_index, u32 client_id) { |
| 258 | SocketCallback callback{[this](Response::Version version) { OnVersion(version); }, | 265 | SocketCallback callback{[this](Response::Version version) { OnVersion(version); }, |
| 259 | [this](Response::PortInfo info) { OnPortInfo(info); }, | 266 | [this](Response::PortInfo info) { OnPortInfo(info); }, |
| 260 | [this](Response::PadData data) { OnPadData(data); }}; | 267 | [this](Response::PadData data) { OnPadData(data); }}; |
| @@ -264,9 +271,9 @@ void Client::StartCommunication(std::size_t client, const std::string& host, u16 | |||
| 264 | } | 271 | } |
| 265 | 272 | ||
| 266 | void Client::Reset() { | 273 | void Client::Reset() { |
| 267 | for (std::size_t client = 0; client < clients.size(); client++) { | 274 | for (auto& client : clients) { |
| 268 | clients[client].socket->Stop(); | 275 | client.socket->Stop(); |
| 269 | clients[client].thread.join(); | 276 | client.thread.join(); |
| 270 | } | 277 | } |
| 271 | } | 278 | } |
| 272 | 279 | ||
| @@ -325,16 +332,19 @@ const std::array<Common::SPSCQueue<UDPPadStatus>, 4>& Client::GetPadQueue() cons | |||
| 325 | return pad_queue; | 332 | return pad_queue; |
| 326 | } | 333 | } |
| 327 | 334 | ||
| 328 | void TestCommunication(const std::string& host, u16 port, u8 pad_index, u32 client_id, | 335 | void TestCommunication(const std::string& host, u16 port, std::size_t pad_index, u32 client_id, |
| 329 | std::function<void()> success_callback, | 336 | const std::function<void()>& success_callback, |
| 330 | std::function<void()> failure_callback) { | 337 | const std::function<void()>& failure_callback) { |
| 331 | std::thread([=] { | 338 | std::thread([=] { |
| 332 | Common::Event success_event; | 339 | Common::Event success_event; |
| 333 | SocketCallback callback{[](Response::Version version) {}, [](Response::PortInfo info) {}, | 340 | SocketCallback callback{ |
| 334 | [&](Response::PadData data) { success_event.Set(); }}; | 341 | .version = [](Response::Version) {}, |
| 342 | .port_info = [](Response::PortInfo) {}, | ||
| 343 | .pad_data = [&](Response::PadData) { success_event.Set(); }, | ||
| 344 | }; | ||
| 335 | Socket socket{host, port, pad_index, client_id, std::move(callback)}; | 345 | Socket socket{host, port, pad_index, client_id, std::move(callback)}; |
| 336 | std::thread worker_thread{SocketLoop, &socket}; | 346 | std::thread worker_thread{SocketLoop, &socket}; |
| 337 | bool result = success_event.WaitFor(std::chrono::seconds(8)); | 347 | const bool result = success_event.WaitFor(std::chrono::seconds(8)); |
| 338 | socket.Stop(); | 348 | socket.Stop(); |
| 339 | worker_thread.join(); | 349 | worker_thread.join(); |
| 340 | if (result) { | 350 | if (result) { |
| @@ -346,7 +356,7 @@ void TestCommunication(const std::string& host, u16 port, u8 pad_index, u32 clie | |||
| 346 | } | 356 | } |
| 347 | 357 | ||
| 348 | CalibrationConfigurationJob::CalibrationConfigurationJob( | 358 | CalibrationConfigurationJob::CalibrationConfigurationJob( |
| 349 | const std::string& host, u16 port, u8 pad_index, u32 client_id, | 359 | const std::string& host, u16 port, std::size_t pad_index, u32 client_id, |
| 350 | std::function<void(Status)> status_callback, | 360 | std::function<void(Status)> status_callback, |
| 351 | std::function<void(u16, u16, u16, u16)> data_callback) { | 361 | std::function<void(u16, u16, u16, u16)> data_callback) { |
| 352 | 362 | ||
| @@ -366,7 +376,7 @@ CalibrationConfigurationJob::CalibrationConfigurationJob( | |||
| 366 | current_status = Status::Ready; | 376 | current_status = Status::Ready; |
| 367 | status_callback(current_status); | 377 | status_callback(current_status); |
| 368 | } | 378 | } |
| 369 | if (!data.touch_1.is_active) { | 379 | if (data.touch_1.is_active == 0) { |
| 370 | return; | 380 | return; |
| 371 | } | 381 | } |
| 372 | LOG_DEBUG(Input, "Current touch: {} {}", data.touch_1.x, | 382 | LOG_DEBUG(Input, "Current touch: {} {}", data.touch_1.x, |
diff --git a/src/input_common/udp/client.h b/src/input_common/udp/client.h index 523dc6a7a..747e0c0a2 100644 --- a/src/input_common/udp/client.h +++ b/src/input_common/udp/client.h | |||
| @@ -84,8 +84,8 @@ public: | |||
| 84 | 84 | ||
| 85 | bool DeviceConnected(std::size_t pad) const; | 85 | bool DeviceConnected(std::size_t pad) const; |
| 86 | void ReloadUDPClient(); | 86 | void ReloadUDPClient(); |
| 87 | void ReloadSocket(const std::string& host = "127.0.0.1", u16 port = 26760, u8 pad_index = 0, | 87 | void ReloadSocket(const std::string& host = "127.0.0.1", u16 port = 26760, |
| 88 | u32 client_id = 24872); | 88 | std::size_t pad_index = 0, u32 client_id = 24872); |
| 89 | 89 | ||
| 90 | std::array<Common::SPSCQueue<UDPPadStatus>, 4>& GetPadQueue(); | 90 | std::array<Common::SPSCQueue<UDPPadStatus>, 4>& GetPadQueue(); |
| 91 | const std::array<Common::SPSCQueue<UDPPadStatus>, 4>& GetPadQueue() const; | 91 | const std::array<Common::SPSCQueue<UDPPadStatus>, 4>& GetPadQueue() const; |
| @@ -99,7 +99,7 @@ private: | |||
| 99 | DeviceStatus status; | 99 | DeviceStatus status; |
| 100 | std::thread thread; | 100 | std::thread thread; |
| 101 | u64 packet_sequence = 0; | 101 | u64 packet_sequence = 0; |
| 102 | u8 active; | 102 | u8 active = 0; |
| 103 | 103 | ||
| 104 | // Realtime values | 104 | // Realtime values |
| 105 | // motion is initalized with PID values for drift correction on joycons | 105 | // motion is initalized with PID values for drift correction on joycons |
| @@ -113,8 +113,8 @@ private: | |||
| 113 | void OnVersion(Response::Version); | 113 | void OnVersion(Response::Version); |
| 114 | void OnPortInfo(Response::PortInfo); | 114 | void OnPortInfo(Response::PortInfo); |
| 115 | void OnPadData(Response::PadData); | 115 | void OnPadData(Response::PadData); |
| 116 | void StartCommunication(std::size_t client, const std::string& host, u16 port, u8 pad_index, | 116 | void StartCommunication(std::size_t client, const std::string& host, u16 port, |
| 117 | u32 client_id); | 117 | std::size_t pad_index, u32 client_id); |
| 118 | void UpdateYuzuSettings(std::size_t client, const Common::Vec3<float>& acc, | 118 | void UpdateYuzuSettings(std::size_t client, const Common::Vec3<float>& acc, |
| 119 | const Common::Vec3<float>& gyro, bool touch); | 119 | const Common::Vec3<float>& gyro, bool touch); |
| 120 | 120 | ||
| @@ -139,7 +139,7 @@ public: | |||
| 139 | * @param status_callback Callback for job status updates | 139 | * @param status_callback Callback for job status updates |
| 140 | * @param data_callback Called when calibration data is ready | 140 | * @param data_callback Called when calibration data is ready |
| 141 | */ | 141 | */ |
| 142 | explicit CalibrationConfigurationJob(const std::string& host, u16 port, u8 pad_index, | 142 | explicit CalibrationConfigurationJob(const std::string& host, u16 port, std::size_t pad_index, |
| 143 | u32 client_id, std::function<void(Status)> status_callback, | 143 | u32 client_id, std::function<void(Status)> status_callback, |
| 144 | std::function<void(u16, u16, u16, u16)> data_callback); | 144 | std::function<void(u16, u16, u16, u16)> data_callback); |
| 145 | ~CalibrationConfigurationJob(); | 145 | ~CalibrationConfigurationJob(); |
| @@ -149,8 +149,8 @@ private: | |||
| 149 | Common::Event complete_event; | 149 | Common::Event complete_event; |
| 150 | }; | 150 | }; |
| 151 | 151 | ||
| 152 | void TestCommunication(const std::string& host, u16 port, u8 pad_index, u32 client_id, | 152 | void TestCommunication(const std::string& host, u16 port, std::size_t pad_index, u32 client_id, |
| 153 | std::function<void()> success_callback, | 153 | const std::function<void()>& success_callback, |
| 154 | std::function<void()> failure_callback); | 154 | const std::function<void()>& failure_callback); |
| 155 | 155 | ||
| 156 | } // namespace InputCommon::CemuhookUDP | 156 | } // namespace InputCommon::CemuhookUDP |
diff --git a/src/input_common/udp/udp.cpp b/src/input_common/udp/udp.cpp index eba077a36..71a76a7aa 100644 --- a/src/input_common/udp/udp.cpp +++ b/src/input_common/udp/udp.cpp | |||
| @@ -2,8 +2,6 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <atomic> | ||
| 6 | #include <list> | ||
| 7 | #include <mutex> | 5 | #include <mutex> |
| 8 | #include <utility> | 6 | #include <utility> |
| 9 | #include "common/assert.h" | 7 | #include "common/assert.h" |
| @@ -15,8 +13,8 @@ namespace InputCommon { | |||
| 15 | 13 | ||
| 16 | class UDPMotion final : public Input::MotionDevice { | 14 | class UDPMotion final : public Input::MotionDevice { |
| 17 | public: | 15 | public: |
| 18 | UDPMotion(std::string ip_, int port_, int pad_, CemuhookUDP::Client* client_) | 16 | explicit UDPMotion(std::string ip_, int port_, u32 pad_, CemuhookUDP::Client* client_) |
| 19 | : ip(ip_), port(port_), pad(pad_), client(client_) {} | 17 | : ip(std::move(ip_)), port(port_), pad(pad_), client(client_) {} |
| 20 | 18 | ||
| 21 | Input::MotionStatus GetStatus() const override { | 19 | Input::MotionStatus GetStatus() const override { |
| 22 | return client->GetPadState(pad).motion_status; | 20 | return client->GetPadState(pad).motion_status; |
| @@ -25,7 +23,7 @@ public: | |||
| 25 | private: | 23 | private: |
| 26 | const std::string ip; | 24 | const std::string ip; |
| 27 | const int port; | 25 | const int port; |
| 28 | const int pad; | 26 | const u32 pad; |
| 29 | CemuhookUDP::Client* client; | 27 | CemuhookUDP::Client* client; |
| 30 | mutable std::mutex mutex; | 28 | mutable std::mutex mutex; |
| 31 | }; | 29 | }; |
| @@ -40,11 +38,11 @@ UDPMotionFactory::UDPMotionFactory(std::shared_ptr<CemuhookUDP::Client> client_) | |||
| 40 | * - "port": the nth jcpad on the adapter | 38 | * - "port": the nth jcpad on the adapter |
| 41 | */ | 39 | */ |
| 42 | std::unique_ptr<Input::MotionDevice> UDPMotionFactory::Create(const Common::ParamPackage& params) { | 40 | std::unique_ptr<Input::MotionDevice> UDPMotionFactory::Create(const Common::ParamPackage& params) { |
| 43 | const std::string ip = params.Get("ip", "127.0.0.1"); | 41 | auto ip = params.Get("ip", "127.0.0.1"); |
| 44 | const int port = params.Get("port", 26760); | 42 | const auto port = params.Get("port", 26760); |
| 45 | const int pad = params.Get("pad_index", 0); | 43 | const auto pad = static_cast<u32>(params.Get("pad_index", 0)); |
| 46 | 44 | ||
| 47 | return std::make_unique<UDPMotion>(ip, port, pad, client.get()); | 45 | return std::make_unique<UDPMotion>(std::move(ip), port, pad, client.get()); |
| 48 | } | 46 | } |
| 49 | 47 | ||
| 50 | void UDPMotionFactory::BeginConfiguration() { | 48 | void UDPMotionFactory::BeginConfiguration() { |
| @@ -79,7 +77,7 @@ Common::ParamPackage UDPMotionFactory::GetNextInput() { | |||
| 79 | 77 | ||
| 80 | class UDPTouch final : public Input::TouchDevice { | 78 | class UDPTouch final : public Input::TouchDevice { |
| 81 | public: | 79 | public: |
| 82 | UDPTouch(std::string ip_, int port_, int pad_, CemuhookUDP::Client* client_) | 80 | explicit UDPTouch(std::string ip_, int port_, u32 pad_, CemuhookUDP::Client* client_) |
| 83 | : ip(std::move(ip_)), port(port_), pad(pad_), client(client_) {} | 81 | : ip(std::move(ip_)), port(port_), pad(pad_), client(client_) {} |
| 84 | 82 | ||
| 85 | std::tuple<float, float, bool> GetStatus() const override { | 83 | std::tuple<float, float, bool> GetStatus() const override { |
| @@ -89,7 +87,7 @@ public: | |||
| 89 | private: | 87 | private: |
| 90 | const std::string ip; | 88 | const std::string ip; |
| 91 | const int port; | 89 | const int port; |
| 92 | const int pad; | 90 | const u32 pad; |
| 93 | CemuhookUDP::Client* client; | 91 | CemuhookUDP::Client* client; |
| 94 | mutable std::mutex mutex; | 92 | mutable std::mutex mutex; |
| 95 | }; | 93 | }; |
| @@ -104,11 +102,11 @@ UDPTouchFactory::UDPTouchFactory(std::shared_ptr<CemuhookUDP::Client> client_) | |||
| 104 | * - "port": the nth jcpad on the adapter | 102 | * - "port": the nth jcpad on the adapter |
| 105 | */ | 103 | */ |
| 106 | std::unique_ptr<Input::TouchDevice> UDPTouchFactory::Create(const Common::ParamPackage& params) { | 104 | std::unique_ptr<Input::TouchDevice> UDPTouchFactory::Create(const Common::ParamPackage& params) { |
| 107 | const std::string ip = params.Get("ip", "127.0.0.1"); | 105 | auto ip = params.Get("ip", "127.0.0.1"); |
| 108 | const int port = params.Get("port", 26760); | 106 | const auto port = params.Get("port", 26760); |
| 109 | const int pad = params.Get("pad_index", 0); | 107 | const auto pad = static_cast<u32>(params.Get("pad_index", 0)); |
| 110 | 108 | ||
| 111 | return std::make_unique<UDPTouch>(ip, port, pad, client.get()); | 109 | return std::make_unique<UDPTouch>(std::move(ip), port, pad, client.get()); |
| 112 | } | 110 | } |
| 113 | 111 | ||
| 114 | void UDPTouchFactory::BeginConfiguration() { | 112 | void UDPTouchFactory::BeginConfiguration() { |
diff --git a/src/video_core/renderer_vulkan/vk_device.cpp b/src/video_core/renderer_vulkan/vk_device.cpp index 3d8d3213d..1f057b43b 100644 --- a/src/video_core/renderer_vulkan/vk_device.cpp +++ b/src/video_core/renderer_vulkan/vk_device.cpp | |||
| @@ -79,6 +79,21 @@ VkFormatFeatureFlags GetFormatFeatures(VkFormatProperties properties, FormatType | |||
| 79 | } | 79 | } |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | [[nodiscard]] bool IsRDNA(std::string_view device_name, VkDriverIdKHR driver_id) { | ||
| 83 | static constexpr std::array RDNA_DEVICES{ | ||
| 84 | "5700", | ||
| 85 | "5600", | ||
| 86 | "5500", | ||
| 87 | "5300", | ||
| 88 | }; | ||
| 89 | if (driver_id != VK_DRIVER_ID_AMD_PROPRIETARY_KHR) { | ||
| 90 | return false; | ||
| 91 | } | ||
| 92 | return std::any_of(RDNA_DEVICES.begin(), RDNA_DEVICES.end(), [device_name](const char* name) { | ||
| 93 | return device_name.find(name) != std::string_view::npos; | ||
| 94 | }); | ||
| 95 | } | ||
| 96 | |||
| 82 | std::unordered_map<VkFormat, VkFormatProperties> GetFormatProperties( | 97 | std::unordered_map<VkFormat, VkFormatProperties> GetFormatProperties( |
| 83 | vk::PhysicalDevice physical, const vk::InstanceDispatch& dld) { | 98 | vk::PhysicalDevice physical, const vk::InstanceDispatch& dld) { |
| 84 | static constexpr std::array formats{ | 99 | static constexpr std::array formats{ |
| @@ -388,6 +403,15 @@ bool VKDevice::Create() { | |||
| 388 | 403 | ||
| 389 | CollectTelemetryParameters(); | 404 | CollectTelemetryParameters(); |
| 390 | 405 | ||
| 406 | if (ext_extended_dynamic_state && IsRDNA(properties.deviceName, driver_id)) { | ||
| 407 | // AMD's proprietary driver supports VK_EXT_extended_dynamic_state but on RDNA devices it | ||
| 408 | // seems to cause stability issues | ||
| 409 | LOG_WARNING( | ||
| 410 | Render_Vulkan, | ||
| 411 | "Blacklisting AMD proprietary on RDNA devices from VK_EXT_extended_dynamic_state"); | ||
| 412 | ext_extended_dynamic_state = false; | ||
| 413 | } | ||
| 414 | |||
| 391 | graphics_queue = logical.GetQueue(graphics_family); | 415 | graphics_queue = logical.GetQueue(graphics_family); |
| 392 | present_queue = logical.GetQueue(present_family); | 416 | present_queue = logical.GetQueue(present_family); |
| 393 | 417 | ||
diff --git a/src/web_service/web_backend.cpp b/src/web_service/web_backend.cpp index 74e287045..534960d09 100644 --- a/src/web_service/web_backend.cpp +++ b/src/web_service/web_backend.cpp | |||
| @@ -67,28 +67,25 @@ struct Client::Impl { | |||
| 67 | const std::string& jwt = "", const std::string& username = "", | 67 | const std::string& jwt = "", const std::string& username = "", |
| 68 | const std::string& token = "") { | 68 | const std::string& token = "") { |
| 69 | if (cli == nullptr) { | 69 | if (cli == nullptr) { |
| 70 | auto parsedUrl = LUrlParser::clParseURL::ParseURL(host); | 70 | const auto parsedUrl = LUrlParser::clParseURL::ParseURL(host); |
| 71 | int port; | 71 | int port{}; |
| 72 | if (parsedUrl.m_Scheme == "http") { | 72 | if (parsedUrl.m_Scheme == "http") { |
| 73 | if (!parsedUrl.GetPort(&port)) { | 73 | if (!parsedUrl.GetPort(&port)) { |
| 74 | port = HTTP_PORT; | 74 | port = HTTP_PORT; |
| 75 | } | 75 | } |
| 76 | cli = std::make_unique<httplib::Client>(parsedUrl.m_Host.c_str(), port); | ||
| 77 | } else if (parsedUrl.m_Scheme == "https") { | 76 | } else if (parsedUrl.m_Scheme == "https") { |
| 78 | if (!parsedUrl.GetPort(&port)) { | 77 | if (!parsedUrl.GetPort(&port)) { |
| 79 | port = HTTPS_PORT; | 78 | port = HTTPS_PORT; |
| 80 | } | 79 | } |
| 81 | cli = std::make_unique<httplib::SSLClient>(parsedUrl.m_Host.c_str(), port); | ||
| 82 | } else { | 80 | } else { |
| 83 | LOG_ERROR(WebService, "Bad URL scheme {}", parsedUrl.m_Scheme); | 81 | LOG_ERROR(WebService, "Bad URL scheme {}", parsedUrl.m_Scheme); |
| 84 | return WebResult{WebResult::Code::InvalidURL, "Bad URL scheme", ""}; | 82 | return WebResult{WebResult::Code::InvalidURL, "Bad URL scheme", ""}; |
| 85 | } | 83 | } |
| 84 | cli = std::make_unique<httplib::Client>(parsedUrl.m_Host.c_str(), port); | ||
| 86 | } | 85 | } |
| 87 | if (cli == nullptr) { | 86 | cli->set_connection_timeout(TIMEOUT_SECONDS); |
| 88 | LOG_ERROR(WebService, "Invalid URL {}", host + path); | 87 | cli->set_read_timeout(TIMEOUT_SECONDS); |
| 89 | return WebResult{WebResult::Code::InvalidURL, "Invalid URL", ""}; | 88 | cli->set_write_timeout(TIMEOUT_SECONDS); |
| 90 | } | ||
| 91 | cli->set_timeout_sec(TIMEOUT_SECONDS); | ||
| 92 | 89 | ||
| 93 | httplib::Headers params; | 90 | httplib::Headers params; |
| 94 | if (!jwt.empty()) { | 91 | if (!jwt.empty()) { |
diff --git a/src/yuzu/configuration/configure_motion_touch.cpp b/src/yuzu/configuration/configure_motion_touch.cpp index c7d085151..170574d9b 100644 --- a/src/yuzu/configuration/configure_motion_touch.cpp +++ b/src/yuzu/configuration/configure_motion_touch.cpp | |||
| @@ -193,7 +193,7 @@ void ConfigureMotionTouch::OnCemuhookUDPTest() { | |||
| 193 | udp_test_in_progress = true; | 193 | udp_test_in_progress = true; |
| 194 | InputCommon::CemuhookUDP::TestCommunication( | 194 | InputCommon::CemuhookUDP::TestCommunication( |
| 195 | ui->udp_server->text().toStdString(), static_cast<u16>(ui->udp_port->text().toInt()), | 195 | ui->udp_server->text().toStdString(), static_cast<u16>(ui->udp_port->text().toInt()), |
| 196 | static_cast<u8>(ui->udp_pad_index->currentIndex()), 24872, | 196 | static_cast<u32>(ui->udp_pad_index->currentIndex()), 24872, |
| 197 | [this] { | 197 | [this] { |
| 198 | LOG_INFO(Frontend, "UDP input test success"); | 198 | LOG_INFO(Frontend, "UDP input test success"); |
| 199 | QMetaObject::invokeMethod(this, "ShowUDPTestResult", Q_ARG(bool, true)); | 199 | QMetaObject::invokeMethod(this, "ShowUDPTestResult", Q_ARG(bool, true)); |