chore: make yuzu REUSE compliant
[REUSE] is a specification that aims at making file copyright
information consistent, so that it can be both human and machine
readable. It basically requires that all files have a header containing
copyright and licensing information. When this isn't possible, like
when dealing with binary assets, generated files or embedded third-party
dependencies, it is permitted to insert copyright information in the
`.reuse/dep5` file.
Oh, and it also requires that all the licenses used in the project are
present in the `LICENSES` folder, that's why the diff is so huge.
This can be done automatically with `reuse download --all`.
The `reuse` tool also contains a handy subcommand that analyzes the
project and tells whether or not the project is (still) compliant,
`reuse lint`.
Following REUSE has a few advantages over the current approach:
- Copyright information is easy to access for users / downstream
- Files like `dist/license.md` do not need to exist anymore, as
`.reuse/dep5` is used instead
- `reuse lint` makes it easy to ensure that copyright information of
files like binary assets / images is always accurate and up to date
To add copyright information of files that didn't have it I looked up
who committed what and when, for each file. As yuzu contributors do not
have to sign a CLA or similar I couldn't assume that copyright ownership
was of the "yuzu Emulator Project", so I used the name and/or email of
the commit author instead.
[REUSE]: https://reuse.software
Follow-up to 01cf05bc75b1e47beb08937439f3ed9339e7b254
2022-05-15 00:06:02 +00:00
|
|
|
// SPDX-FileCopyrightText: 2017 Citra Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2017-01-21 11:04:00 +00:00
|
|
|
|
2020-11-07 15:48:11 +00:00
|
|
|
#include <chrono>
|
|
|
|
#include <cmath>
|
|
|
|
#include "common/math_util.h"
|
2021-04-14 23:07:40 +00:00
|
|
|
#include "common/settings.h"
|
2021-09-20 21:57:55 +00:00
|
|
|
#include "input_common/helpers/stick_from_buttons.h"
|
2017-01-21 11:04:00 +00:00
|
|
|
|
|
|
|
namespace InputCommon {
|
|
|
|
|
2021-10-31 03:23:10 +00:00
|
|
|
class Stick final : public Common::Input::InputDevice {
|
2017-01-21 11:04:00 +00:00
|
|
|
public:
|
2023-01-25 19:16:52 +00:00
|
|
|
// Some games such as EARTH DEFENSE FORCE: WORLD BROTHERS
|
|
|
|
// do not play nicely with the theoretical maximum range.
|
|
|
|
// Using a value one lower from the maximum emulates real stick behavior.
|
|
|
|
static constexpr float MAX_RANGE = 32766.0f / 32767.0f;
|
2023-02-02 15:51:23 +00:00
|
|
|
static constexpr float TAU = Common::PI * 2.0f;
|
|
|
|
// Use wider angle to ease the transition.
|
|
|
|
static constexpr float APERTURE = TAU * 0.15f;
|
2023-01-25 19:16:52 +00:00
|
|
|
|
2021-10-31 03:23:10 +00:00
|
|
|
using Button = std::unique_ptr<Common::Input::InputDevice>;
|
2017-01-21 11:04:00 +00:00
|
|
|
|
2023-01-06 01:16:55 +00:00
|
|
|
Stick(Button up_, Button down_, Button left_, Button right_, Button modifier_, Button updater_,
|
2021-09-20 21:57:55 +00:00
|
|
|
float modifier_scale_, float modifier_angle_)
|
2017-01-21 11:04:00 +00:00
|
|
|
: up(std::move(up_)), down(std::move(down_)), left(std::move(left_)),
|
2023-01-06 01:16:55 +00:00
|
|
|
right(std::move(right_)), modifier(std::move(modifier_)), updater(std::move(updater_)),
|
|
|
|
modifier_scale(modifier_scale_), modifier_angle(modifier_angle_) {
|
2021-12-14 02:09:28 +00:00
|
|
|
up->SetCallback({
|
|
|
|
.on_change =
|
|
|
|
[this](const Common::Input::CallbackStatus& callback_) {
|
|
|
|
UpdateUpButtonStatus(callback_);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
down->SetCallback({
|
|
|
|
.on_change =
|
|
|
|
[this](const Common::Input::CallbackStatus& callback_) {
|
|
|
|
UpdateDownButtonStatus(callback_);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
left->SetCallback({
|
|
|
|
.on_change =
|
|
|
|
[this](const Common::Input::CallbackStatus& callback_) {
|
|
|
|
UpdateLeftButtonStatus(callback_);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
right->SetCallback({
|
|
|
|
.on_change =
|
|
|
|
[this](const Common::Input::CallbackStatus& callback_) {
|
|
|
|
UpdateRightButtonStatus(callback_);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
modifier->SetCallback({
|
|
|
|
.on_change =
|
|
|
|
[this](const Common::Input::CallbackStatus& callback_) {
|
|
|
|
UpdateModButtonStatus(callback_);
|
|
|
|
},
|
|
|
|
});
|
2023-01-06 01:16:55 +00:00
|
|
|
updater->SetCallback({
|
|
|
|
.on_change = [this](const Common::Input::CallbackStatus& callback_) { SoftUpdate(); },
|
|
|
|
});
|
2021-11-02 01:49:14 +00:00
|
|
|
last_x_axis_value = 0.0f;
|
|
|
|
last_y_axis_value = 0.0f;
|
2020-11-07 15:48:11 +00:00
|
|
|
}
|
2017-01-21 11:04:00 +00:00
|
|
|
|
2021-05-30 04:35:46 +00:00
|
|
|
bool IsAngleGreater(float old_angle, float new_angle) const {
|
2023-02-02 15:51:23 +00:00
|
|
|
const float top_limit = new_angle + APERTURE;
|
2021-05-30 04:35:46 +00:00
|
|
|
return (old_angle > new_angle && old_angle <= top_limit) ||
|
|
|
|
(old_angle + TAU > new_angle && old_angle + TAU <= top_limit);
|
2020-11-07 15:48:11 +00:00
|
|
|
}
|
|
|
|
|
2021-05-30 04:35:46 +00:00
|
|
|
bool IsAngleSmaller(float old_angle, float new_angle) const {
|
2023-02-02 15:51:23 +00:00
|
|
|
const float bottom_limit = new_angle - APERTURE;
|
2021-05-30 04:35:46 +00:00
|
|
|
return (old_angle >= bottom_limit && old_angle < new_angle) ||
|
|
|
|
(old_angle - TAU >= bottom_limit && old_angle - TAU < new_angle);
|
|
|
|
}
|
|
|
|
|
|
|
|
float GetAngle(std::chrono::time_point<std::chrono::steady_clock> now) const {
|
|
|
|
float new_angle = angle;
|
|
|
|
|
|
|
|
auto time_difference = static_cast<float>(
|
2023-02-02 15:51:23 +00:00
|
|
|
std::chrono::duration_cast<std::chrono::milliseconds>(now - last_update).count());
|
|
|
|
time_difference /= 1000.0f;
|
2021-05-30 04:35:46 +00:00
|
|
|
if (time_difference > 0.5f) {
|
|
|
|
time_difference = 0.5f;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsAngleGreater(new_angle, goal_angle)) {
|
|
|
|
new_angle -= modifier_angle * time_difference;
|
|
|
|
if (new_angle < 0) {
|
|
|
|
new_angle += TAU;
|
|
|
|
}
|
|
|
|
if (!IsAngleGreater(new_angle, goal_angle)) {
|
|
|
|
return goal_angle;
|
2020-11-07 15:48:11 +00:00
|
|
|
}
|
2021-05-30 04:35:46 +00:00
|
|
|
} else if (IsAngleSmaller(new_angle, goal_angle)) {
|
|
|
|
new_angle += modifier_angle * time_difference;
|
|
|
|
if (new_angle >= TAU) {
|
|
|
|
new_angle -= TAU;
|
|
|
|
}
|
|
|
|
if (!IsAngleSmaller(new_angle, goal_angle)) {
|
|
|
|
return goal_angle;
|
2020-11-07 15:48:11 +00:00
|
|
|
}
|
|
|
|
} else {
|
2021-05-30 04:35:46 +00:00
|
|
|
return goal_angle;
|
2020-10-14 06:51:14 +00:00
|
|
|
}
|
2021-05-30 04:35:46 +00:00
|
|
|
return new_angle;
|
2020-11-07 15:48:11 +00:00
|
|
|
}
|
|
|
|
|
2021-05-30 04:35:46 +00:00
|
|
|
void SetGoalAngle(bool r, bool l, bool u, bool d) {
|
|
|
|
// Move to the right
|
|
|
|
if (r && !u && !d) {
|
|
|
|
goal_angle = 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Move to the upper right
|
|
|
|
if (r && u && !d) {
|
|
|
|
goal_angle = Common::PI * 0.25f;
|
|
|
|
}
|
2020-11-07 15:48:11 +00:00
|
|
|
|
2021-05-30 04:35:46 +00:00
|
|
|
// Move up
|
|
|
|
if (u && !l && !r) {
|
|
|
|
goal_angle = Common::PI * 0.5f;
|
|
|
|
}
|
2020-11-07 15:48:11 +00:00
|
|
|
|
2021-05-30 04:35:46 +00:00
|
|
|
// Move to the upper left
|
|
|
|
if (l && u && !d) {
|
|
|
|
goal_angle = Common::PI * 0.75f;
|
|
|
|
}
|
2020-11-07 15:48:11 +00:00
|
|
|
|
2021-05-30 04:35:46 +00:00
|
|
|
// Move to the left
|
|
|
|
if (l && !u && !d) {
|
|
|
|
goal_angle = Common::PI;
|
|
|
|
}
|
2020-11-07 15:48:11 +00:00
|
|
|
|
2021-05-30 04:35:46 +00:00
|
|
|
// Move to the bottom left
|
|
|
|
if (l && !u && d) {
|
|
|
|
goal_angle = Common::PI * 1.25f;
|
|
|
|
}
|
2020-11-07 15:48:11 +00:00
|
|
|
|
2021-05-30 04:35:46 +00:00
|
|
|
// Move down
|
|
|
|
if (d && !l && !r) {
|
|
|
|
goal_angle = Common::PI * 1.5f;
|
|
|
|
}
|
2020-11-07 15:48:11 +00:00
|
|
|
|
2021-05-30 04:35:46 +00:00
|
|
|
// Move to the bottom right
|
|
|
|
if (r && !u && d) {
|
|
|
|
goal_angle = Common::PI * 1.75f;
|
|
|
|
}
|
|
|
|
}
|
2020-11-07 15:48:11 +00:00
|
|
|
|
2021-12-14 02:09:28 +00:00
|
|
|
void UpdateUpButtonStatus(const Common::Input::CallbackStatus& button_callback) {
|
2021-09-20 21:57:55 +00:00
|
|
|
up_status = button_callback.button_status.value;
|
|
|
|
UpdateStatus();
|
|
|
|
}
|
|
|
|
|
2021-12-14 02:09:28 +00:00
|
|
|
void UpdateDownButtonStatus(const Common::Input::CallbackStatus& button_callback) {
|
2021-09-20 21:57:55 +00:00
|
|
|
down_status = button_callback.button_status.value;
|
|
|
|
UpdateStatus();
|
|
|
|
}
|
|
|
|
|
2021-12-14 02:09:28 +00:00
|
|
|
void UpdateLeftButtonStatus(const Common::Input::CallbackStatus& button_callback) {
|
2021-09-20 21:57:55 +00:00
|
|
|
left_status = button_callback.button_status.value;
|
|
|
|
UpdateStatus();
|
|
|
|
}
|
|
|
|
|
2021-12-14 02:09:28 +00:00
|
|
|
void UpdateRightButtonStatus(const Common::Input::CallbackStatus& button_callback) {
|
2021-09-20 21:57:55 +00:00
|
|
|
right_status = button_callback.button_status.value;
|
|
|
|
UpdateStatus();
|
|
|
|
}
|
|
|
|
|
2021-12-14 02:09:28 +00:00
|
|
|
void UpdateModButtonStatus(const Common::Input::CallbackStatus& button_callback) {
|
2022-01-31 04:42:26 +00:00
|
|
|
const auto& new_status = button_callback.button_status;
|
|
|
|
const bool new_button_value = new_status.inverted ? !new_status.value : new_status.value;
|
|
|
|
modifier_status.toggle = new_status.toggle;
|
|
|
|
|
|
|
|
// Update button status with current
|
|
|
|
if (!modifier_status.toggle) {
|
|
|
|
modifier_status.locked = false;
|
|
|
|
if (modifier_status.value != new_button_value) {
|
|
|
|
modifier_status.value = new_button_value;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Toggle button and lock status
|
|
|
|
if (new_button_value && !modifier_status.locked) {
|
|
|
|
modifier_status.locked = true;
|
|
|
|
modifier_status.value = !modifier_status.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unlock button ready for next press
|
|
|
|
if (!new_button_value && modifier_status.locked) {
|
|
|
|
modifier_status.locked = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-20 21:57:55 +00:00
|
|
|
UpdateStatus();
|
|
|
|
}
|
|
|
|
|
2021-05-30 04:35:46 +00:00
|
|
|
void UpdateStatus() {
|
2021-09-20 21:57:55 +00:00
|
|
|
bool r = right_status;
|
|
|
|
bool l = left_status;
|
|
|
|
bool u = up_status;
|
|
|
|
bool d = down_status;
|
2020-11-07 15:48:11 +00:00
|
|
|
|
2021-05-30 04:35:46 +00:00
|
|
|
// Eliminate contradictory movements
|
|
|
|
if (r && l) {
|
|
|
|
r = false;
|
|
|
|
l = false;
|
|
|
|
}
|
|
|
|
if (u && d) {
|
|
|
|
u = false;
|
|
|
|
d = false;
|
|
|
|
}
|
2020-11-07 15:48:11 +00:00
|
|
|
|
2021-05-30 04:35:46 +00:00
|
|
|
// Move if a key is pressed
|
|
|
|
if (r || l || u || d) {
|
2023-02-02 15:51:23 +00:00
|
|
|
amplitude = modifier_status.value ? modifier_scale : MAX_RANGE;
|
2021-05-30 04:35:46 +00:00
|
|
|
} else {
|
|
|
|
amplitude = 0;
|
2020-10-14 06:51:14 +00:00
|
|
|
}
|
2021-05-30 04:35:46 +00:00
|
|
|
|
|
|
|
const auto now = std::chrono::steady_clock::now();
|
|
|
|
const auto time_difference = static_cast<u64>(
|
|
|
|
std::chrono::duration_cast<std::chrono::milliseconds>(now - last_update).count());
|
|
|
|
|
|
|
|
if (time_difference < 10) {
|
|
|
|
// Disable analog mode if inputs are too fast
|
|
|
|
SetGoalAngle(r, l, u, d);
|
|
|
|
angle = goal_angle;
|
|
|
|
} else {
|
|
|
|
angle = GetAngle(now);
|
|
|
|
SetGoalAngle(r, l, u, d);
|
|
|
|
}
|
|
|
|
|
|
|
|
last_update = now;
|
2021-10-31 03:23:10 +00:00
|
|
|
Common::Input::CallbackStatus status{
|
|
|
|
.type = Common::Input::InputType::Stick,
|
2021-09-20 21:57:55 +00:00
|
|
|
.stick_status = GetStatus(),
|
|
|
|
};
|
2021-11-02 01:49:14 +00:00
|
|
|
last_x_axis_value = status.stick_status.x.raw_value;
|
|
|
|
last_y_axis_value = status.stick_status.y.raw_value;
|
2021-09-20 21:57:55 +00:00
|
|
|
TriggerOnChange(status);
|
2020-11-07 15:48:11 +00:00
|
|
|
}
|
2017-01-21 11:04:00 +00:00
|
|
|
|
2021-10-25 04:23:54 +00:00
|
|
|
void ForceUpdate() override {
|
2021-10-25 01:28:54 +00:00
|
|
|
up->ForceUpdate();
|
|
|
|
down->ForceUpdate();
|
|
|
|
left->ForceUpdate();
|
|
|
|
right->ForceUpdate();
|
|
|
|
modifier->ForceUpdate();
|
|
|
|
}
|
|
|
|
|
2023-01-06 01:16:55 +00:00
|
|
|
void SoftUpdate() {
|
2021-10-31 03:23:10 +00:00
|
|
|
Common::Input::CallbackStatus status{
|
|
|
|
.type = Common::Input::InputType::Stick,
|
2021-10-25 01:28:54 +00:00
|
|
|
.stick_status = GetStatus(),
|
|
|
|
};
|
2021-11-02 01:49:14 +00:00
|
|
|
if (last_x_axis_value == status.stick_status.x.raw_value &&
|
|
|
|
last_y_axis_value == status.stick_status.y.raw_value) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
last_x_axis_value = status.stick_status.x.raw_value;
|
|
|
|
last_y_axis_value = status.stick_status.y.raw_value;
|
2021-10-25 01:28:54 +00:00
|
|
|
TriggerOnChange(status);
|
|
|
|
}
|
|
|
|
|
2021-10-31 03:23:10 +00:00
|
|
|
Common::Input::StickStatus GetStatus() const {
|
|
|
|
Common::Input::StickStatus status{};
|
2021-09-20 21:57:55 +00:00
|
|
|
status.x.properties = properties;
|
|
|
|
status.y.properties = properties;
|
2023-02-02 15:51:23 +00:00
|
|
|
|
2020-11-27 02:56:06 +00:00
|
|
|
if (Settings::values.emulate_analog_keyboard) {
|
2021-05-30 04:35:46 +00:00
|
|
|
const auto now = std::chrono::steady_clock::now();
|
2023-02-02 15:51:23 +00:00
|
|
|
const float angle_ = GetAngle(now);
|
2021-09-20 21:57:55 +00:00
|
|
|
status.x.raw_value = std::cos(angle_) * amplitude;
|
|
|
|
status.y.raw_value = std::sin(angle_) * amplitude;
|
|
|
|
return status;
|
2020-11-27 02:56:06 +00:00
|
|
|
}
|
2023-02-02 15:51:23 +00:00
|
|
|
|
|
|
|
status.x.raw_value = std::cos(goal_angle) * amplitude;
|
|
|
|
status.y.raw_value = std::sin(goal_angle) * amplitude;
|
2021-09-20 21:57:55 +00:00
|
|
|
return status;
|
2020-02-18 05:45:37 +00:00
|
|
|
}
|
|
|
|
|
2017-01-21 11:04:00 +00:00
|
|
|
private:
|
2022-11-28 15:08:50 +00:00
|
|
|
static constexpr Common::Input::AnalogProperties properties{
|
|
|
|
.deadzone = 0.0f,
|
|
|
|
.range = 1.0f,
|
|
|
|
.threshold = 0.5f,
|
|
|
|
.offset = 0.0f,
|
|
|
|
.inverted = false,
|
|
|
|
.toggle = false,
|
|
|
|
};
|
|
|
|
|
2017-01-21 11:04:00 +00:00
|
|
|
Button up;
|
|
|
|
Button down;
|
|
|
|
Button left;
|
|
|
|
Button right;
|
|
|
|
Button modifier;
|
2023-01-06 01:16:55 +00:00
|
|
|
Button updater;
|
2021-12-14 02:09:28 +00:00
|
|
|
float modifier_scale{};
|
|
|
|
float modifier_angle{};
|
2020-11-07 15:48:11 +00:00
|
|
|
float angle{};
|
2021-05-30 04:35:46 +00:00
|
|
|
float goal_angle{};
|
2020-11-07 15:48:11 +00:00
|
|
|
float amplitude{};
|
2021-12-14 02:09:28 +00:00
|
|
|
bool up_status{};
|
|
|
|
bool down_status{};
|
|
|
|
bool left_status{};
|
|
|
|
bool right_status{};
|
|
|
|
float last_x_axis_value{};
|
|
|
|
float last_y_axis_value{};
|
2022-01-31 04:42:26 +00:00
|
|
|
Common::Input::ButtonStatus modifier_status{};
|
2021-05-30 04:35:46 +00:00
|
|
|
std::chrono::time_point<std::chrono::steady_clock> last_update;
|
2017-01-21 11:04:00 +00:00
|
|
|
};
|
|
|
|
|
2021-10-31 03:23:10 +00:00
|
|
|
std::unique_ptr<Common::Input::InputDevice> StickFromButton::Create(
|
|
|
|
const Common::ParamPackage& params) {
|
2017-01-21 11:04:00 +00:00
|
|
|
const std::string null_engine = Common::ParamPackage{{"engine", "null"}}.Serialize();
|
2022-11-28 14:19:01 +00:00
|
|
|
auto up = Common::Input::CreateInputDeviceFromString(params.Get("up", null_engine));
|
|
|
|
auto down = Common::Input::CreateInputDeviceFromString(params.Get("down", null_engine));
|
|
|
|
auto left = Common::Input::CreateInputDeviceFromString(params.Get("left", null_engine));
|
|
|
|
auto right = Common::Input::CreateInputDeviceFromString(params.Get("right", null_engine));
|
|
|
|
auto modifier = Common::Input::CreateInputDeviceFromString(params.Get("modifier", null_engine));
|
2023-01-06 01:16:55 +00:00
|
|
|
auto updater = Common::Input::CreateInputDeviceFromString("engine:updater,button:0");
|
2017-01-21 11:04:00 +00:00
|
|
|
auto modifier_scale = params.Get("modifier_scale", 0.5f);
|
2021-05-30 04:35:46 +00:00
|
|
|
auto modifier_angle = params.Get("modifier_angle", 5.5f);
|
2021-09-20 21:57:55 +00:00
|
|
|
return std::make_unique<Stick>(std::move(up), std::move(down), std::move(left),
|
2023-01-06 01:16:55 +00:00
|
|
|
std::move(right), std::move(modifier), std::move(updater),
|
|
|
|
modifier_scale, modifier_angle);
|
2017-01-21 11:04:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace InputCommon
|