From b9d9dc3c7109dec9b529a34be8eed644bd76e722 Mon Sep 17 00:00:00 2001 From: pineappleEA Date: Sun, 25 Feb 2024 00:30:13 +0100 Subject: [PATCH] early-access version 4167 --- README.md | 2 +- src/core/hle/service/glue/time/worker.cpp | 7 ++----- .../service/set/system_settings_server.cpp | 13 +++++++----- .../hle/service/set/system_settings_server.h | 21 ++++++++----------- src/hid_core/frontend/emulated_controller.cpp | 17 +++++++++++++++ src/hid_core/frontend/emulated_controller.h | 1 + src/hid_core/hid_types.h | 6 +++++- src/hid_core/resources/npad/npad.cpp | 1 - 8 files changed, 43 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index d097f9fe2..c7ded9519 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ yuzu emulator early access ============= -This is the source code for early-access 4166. +This is the source code for early-access 4167. ## Legal Notice diff --git a/src/core/hle/service/glue/time/worker.cpp b/src/core/hle/service/glue/time/worker.cpp index b28569b68..b6bbd7965 100755 --- a/src/core/hle/service/glue/time/worker.cpp +++ b/src/core/hle/service/glue/time/worker.cpp @@ -26,12 +26,9 @@ Service::PSC::Time::SystemClockContext g_report_ephemeral_clock_context{}; template T GetSettingsItemValue(std::shared_ptr& set_sys, const char* category, const char* name) { - std::vector interval_buf; - auto res = set_sys->GetSettingsItemValueImpl(interval_buf, category, name); - ASSERT(res == ResultSuccess); - T v{}; - std::memcpy(&v, interval_buf.data(), sizeof(T)); + auto res = set_sys->GetSettingsItemValueImpl(v, category, name); + ASSERT(res == ResultSuccess); return v; } diff --git a/src/core/hle/service/set/system_settings_server.cpp b/src/core/hle/service/set/system_settings_server.cpp index 6a7ea83fd..900d5408f 100755 --- a/src/core/hle/service/set/system_settings_server.cpp +++ b/src/core/hle/service/set/system_settings_server.cpp @@ -308,7 +308,7 @@ ISystemSettingsServer::ISystemSettingsServer(Core::System& system_) SetupSettings(); m_system_settings.region_code = - static_cast(Settings::values.region_index.GetValue()); + static_cast(::Settings::values.region_index.GetValue()); // TODO: Remove this when starter applet is fully functional EulaVersion eula_version{ @@ -715,7 +715,7 @@ Result ISystemSettingsServer::GetSettingsItemValueSize( } Result ISystemSettingsServer::GetSettingsItemValue( - OutBuffer out_data, + Out out_size, OutBuffer out_data, InLargeData setting_category_buffer, InLargeData setting_name_buffer) { const std::string setting_category{Common::StringFromBuffer(*setting_category_buffer)}; @@ -723,7 +723,7 @@ Result ISystemSettingsServer::GetSettingsItemValue( LOG_INFO(Service_SET, "called, category={}, name={}", setting_category, setting_name); - R_RETURN(GetSettingsItemValueImpl(out_data, setting_category, setting_name)); + R_RETURN(GetSettingsItemValueImpl(out_data, *out_size, setting_category, setting_name)); } Result ISystemSettingsServer::GetTvSettings(Out out_tv_settings) { @@ -1363,13 +1363,16 @@ void ISystemSettingsServer::SetSaveNeeded() { m_save_needed = true; } -Result ISystemSettingsServer::GetSettingsItemValueImpl(std::vector& out_value, +Result ISystemSettingsServer::GetSettingsItemValueImpl(std::span out_value, u64& out_size, const std::string& category, const std::string& name) { auto settings{GetSettings()}; R_UNLESS(settings.contains(category) && settings[category].contains(name), ResultUnknown); - out_value = settings[category][name]; + ASSERT_MSG(out_value.size() >= settings[category][name].size(), + "Stored type is bigger than requested type"); + out_size = std::min(settings[category][name].size(), out_value.size()); + std::memcpy(out_value.data(), settings[category][name].data(), out_size); R_SUCCEED(); } diff --git a/src/core/hle/service/set/system_settings_server.h b/src/core/hle/service/set/system_settings_server.h index 46e06c8ea..9a1154ad6 100755 --- a/src/core/hle/service/set/system_settings_server.h +++ b/src/core/hle/service/set/system_settings_server.h @@ -34,20 +34,17 @@ public: explicit ISystemSettingsServer(Core::System& system_); ~ISystemSettingsServer() override; - Result GetSettingsItemValueImpl(std::vector& out_value, const std::string& category, - const std::string& name); + Result GetSettingsItemValueImpl(std::span out_value, u64& out_size, + const std::string& category, const std::string& name); template - Result GetSettingsItemValueImpl(T& value, const std::string& category, + Result GetSettingsItemValueImpl(T& out_value, const std::string& category, const std::string& name) { - std::vector data; - const auto result = GetSettingsItemValueImpl(data, category, name); - if (result.IsError()) { - return result; - } - ASSERT(data.size() >= sizeof(T)); - std::memcpy(&value, data.data(), sizeof(T)); - return result; + u64 data_size{}; + std::vector data(sizeof(T)); + R_TRY(GetSettingsItemValueImpl(data, data_size, category, name)); + std::memcpy(&out_value, data.data(), data_size); + R_SUCCEED(); } public: @@ -84,7 +81,7 @@ public: InLargeData setting_category_buffer, InLargeData setting_name_buf); Result GetSettingsItemValue( - OutBuffer out_data, + Out out_size, OutBuffer out_data, InLargeData setting_category_buffer, InLargeData setting_name_buffer); Result GetTvSettings(Out out_tv_settings); diff --git a/src/hid_core/frontend/emulated_controller.cpp b/src/hid_core/frontend/emulated_controller.cpp index 5cd26819c..7664341bd 100755 --- a/src/hid_core/frontend/emulated_controller.cpp +++ b/src/hid_core/frontend/emulated_controller.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include +#include #include #include "common/polyfill_ranges.h" @@ -1287,6 +1288,22 @@ bool EmulatedController::SetVibration(DeviceIndex device_index, const VibrationV return false; } + if (!Settings::values.enable_accurate_vibrations.GetValue()) { + using std::chrono::duration_cast; + using std::chrono::milliseconds; + using std::chrono::steady_clock; + + const auto now = steady_clock::now(); + + // Filter out non-zero vibrations that are within 15ms of each other. + if ((vibration.low_amplitude != 0.0f || vibration.high_amplitude != 0.0f) && + duration_cast(now - last_vibration_timepoint[index]) < milliseconds(15)) { + return false; + } + + last_vibration_timepoint[index] = now; + } + // Exponential amplification is too strong at low amplitudes. Switch to a linear // amplification if strength is set below 0.7f const Common::Input::VibrationAmplificationType type = diff --git a/src/hid_core/frontend/emulated_controller.h b/src/hid_core/frontend/emulated_controller.h index ab3c6fcd3..17ad6069e 100755 --- a/src/hid_core/frontend/emulated_controller.h +++ b/src/hid_core/frontend/emulated_controller.h @@ -583,6 +583,7 @@ private: std::size_t nfc_handles{0}; std::array last_vibration_value{DEFAULT_VIBRATION_VALUE, DEFAULT_VIBRATION_VALUE}; + std::array last_vibration_timepoint{}; // Temporary values to avoid doing changes while the controller is in configuring mode NpadStyleIndex tmp_npad_type{NpadStyleIndex::None}; diff --git a/src/hid_core/hid_types.h b/src/hid_core/hid_types.h index 1b2fc6295..38888fdd1 100755 --- a/src/hid_core/hid_types.h +++ b/src/hid_core/hid_types.h @@ -638,7 +638,11 @@ struct VibrationValue { if (low_amplitude != b.low_amplitude || high_amplitude != b.high_amplitude) { return false; } - if (low_frequency != b.low_amplitude || high_frequency != b.high_frequency) { + // Changes in frequency without amplitude don't have any effect + if (low_amplitude == 0 && high_amplitude == 0) { + return true; + } + if (low_frequency != b.low_frequency || high_frequency != b.high_frequency) { return false; } return true; diff --git a/src/hid_core/resources/npad/npad.cpp b/src/hid_core/resources/npad/npad.cpp index e10e97e1c..ca1ccd659 100755 --- a/src/hid_core/resources/npad/npad.cpp +++ b/src/hid_core/resources/npad/npad.cpp @@ -3,7 +3,6 @@ #include #include -#include #include #include "common/assert.h"