mirror of
https://git.eden-emu.dev/eden-emu/eden.git
synced 2026-09-05 20:04:13 +00:00
@@ -4,17 +4,16 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include <fmt/ranges.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "common/param_package.h"
|
||||
#include "common/settings.h"
|
||||
#include "common/thread.h"
|
||||
#include "common/steady_clock.h"
|
||||
#include "input_common/drivers/mouse.h"
|
||||
|
||||
namespace InputCommon {
|
||||
constexpr int update_time = 10;
|
||||
constexpr float default_panning_sensitivity = 0.0010f;
|
||||
constexpr float default_stick_sensitivity = 0.0006f;
|
||||
constexpr float default_deadzone_counterweight = 0.01f;
|
||||
@@ -74,7 +73,7 @@ Mouse::Mouse(std::string input_engine_) : InputEngine(std::move(input_engine_))
|
||||
last_motion_change = {};
|
||||
}
|
||||
|
||||
void Mouse::UpdateStickInput() {
|
||||
void Mouse::UpdateStickInput(Common::SteadyClock::time_point timestamp) {
|
||||
if (!IsMousePanningEnabled()) {
|
||||
return;
|
||||
}
|
||||
@@ -100,12 +99,9 @@ void Mouse::UpdateStickInput() {
|
||||
last_mouse_change *= clamped_decay;
|
||||
}
|
||||
|
||||
void Mouse::UpdateMotionInput() {
|
||||
const float sensitivity =
|
||||
IsMousePanningEnabled() ? default_motion_panning_sensitivity : default_motion_sensitivity;
|
||||
|
||||
const float rotation_velocity = std::sqrt(last_motion_change.x * last_motion_change.x +
|
||||
last_motion_change.y * last_motion_change.y);
|
||||
void Mouse::UpdateMotionInput(Common::SteadyClock::time_point timestamp) {
|
||||
const float sensitivity = IsMousePanningEnabled() ? default_motion_panning_sensitivity : default_motion_sensitivity;
|
||||
const float rotation_velocity = std::sqrt(last_motion_change.x * last_motion_change.x + last_motion_change.y * last_motion_change.y);
|
||||
|
||||
// Clamp rotation speed
|
||||
if (rotation_velocity > maximum_rotation_speed / sensitivity) {
|
||||
@@ -121,7 +117,7 @@ void Mouse::UpdateMotionInput() {
|
||||
.accel_x = 0,
|
||||
.accel_y = 0,
|
||||
.accel_z = 0,
|
||||
.delta_timestamp = update_time * 1000,
|
||||
.delta_timestamp = u64(std::chrono::duration_cast<std::chrono::microseconds>(timestamp - last_notify_timestamp).count()),
|
||||
};
|
||||
|
||||
if (IsMousePanningEnabled()) {
|
||||
@@ -177,8 +173,10 @@ void Mouse::Move(int x, int y, int center_x, int center_y) {
|
||||
}
|
||||
|
||||
void Mouse::NotifyChanged() {
|
||||
UpdateStickInput();
|
||||
UpdateMotionInput();
|
||||
auto const timestamp = Common::SteadyClock::Now();
|
||||
UpdateStickInput(timestamp);
|
||||
UpdateMotionInput(timestamp);
|
||||
last_notify_timestamp = Common::SteadyClock::Now();
|
||||
}
|
||||
|
||||
void Mouse::MouseMove(f32 touch_x, f32 touch_y) {
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
#include "common/steady_clock.h"
|
||||
#include "common/polyfill_thread.h"
|
||||
#include "common/vector_math.h"
|
||||
#include "input_common/input_engine.h"
|
||||
@@ -101,17 +103,18 @@ public:
|
||||
Common::Input::ButtonNames GetUIName(const Common::ParamPackage& params) const override;
|
||||
|
||||
private:
|
||||
void UpdateStickInput();
|
||||
void UpdateMotionInput();
|
||||
void UpdateStickInput(Common::SteadyClock::time_point timestamp);
|
||||
void UpdateMotionInput(Common::SteadyClock::time_point timestamp);
|
||||
bool IsMousePanningEnabled();
|
||||
|
||||
Common::Input::ButtonNames GetUIButtonName(const Common::ParamPackage& params) const;
|
||||
|
||||
Common::Vec2<int> mouse_origin;
|
||||
Common::Vec2<int> last_mouse_position;
|
||||
Common::Vec2<float> last_mouse_change;
|
||||
Common::Vec3<float> last_motion_change;
|
||||
Common::Vec2<int> wheel_position;
|
||||
Common::Vec2<int> mouse_origin{};
|
||||
Common::Vec2<int> last_mouse_position{};
|
||||
Common::Vec2<float> last_mouse_change{};
|
||||
Common::Vec3<float> last_motion_change{};
|
||||
Common::Vec2<int> wheel_position{};
|
||||
Common::SteadyClock::time_point last_notify_timestamp{};
|
||||
bool button_pressed = false;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user