Morph review first wave

This commit is contained in:
german77 2021-10-22 23:04:06 -05:00 committed by Narr the Reg
parent e2e5f1beaf
commit b564f024f0
23 changed files with 117 additions and 136 deletions

View file

@ -6,7 +6,7 @@
#include "core/hid/input_converter.h"
namespace Core::HID {
EmulatedConsole::EmulatedConsole() {}
EmulatedConsole::EmulatedConsole() = default;
EmulatedConsole::~EmulatedConsole() = default;
@ -191,7 +191,7 @@ TouchFingerState EmulatedConsole::GetTouch() const {
}
void EmulatedConsole::TriggerOnChange(ConsoleTriggerType type) {
for (const std::pair<int, ConsoleUpdateCallback> poller_pair : callback_list) {
for (const auto& poller_pair : callback_list) {
const ConsoleUpdateCallback& poller = poller_pair.second;
if (poller.on_change) {
poller.on_change(type);

View file

@ -20,7 +20,7 @@
namespace Core::HID {
struct ConsoleMotionInfo {
Input::MotionStatus raw_status;
Input::MotionStatus raw_status{};
MotionInput emulated{};
};
@ -34,21 +34,21 @@ using ConsoleMotionValues = ConsoleMotionInfo;
using TouchValues = std::array<Input::TouchStatus, 16>;
struct TouchFinger {
u64_le last_touch{};
u64 last_touch{};
Common::Point<float> position{};
u32_le id{};
bool pressed{};
u32 id{};
TouchAttribute attribute{};
bool pressed{};
};
// Contains all motion related data that is used on the services
struct ConsoleMotion {
bool is_at_rest{};
Common::Vec3f accel{};
Common::Vec3f gyro{};
Common::Vec3f rotation{};
std::array<Common::Vec3f, 3> orientation{};
Common::Quaternion<f32> quaternion{};
bool is_at_rest{};
};
using TouchFingerState = std::array<TouchFinger, 16>;

View file

@ -865,10 +865,10 @@ BatteryLevelState EmulatedController::GetBattery() const {
return controller.battery_state;
}
void EmulatedController::TriggerOnChange(ControllerTriggerType type, bool is_service_update) {
for (const std::pair<int, ControllerUpdateCallback> poller_pair : callback_list) {
void EmulatedController::TriggerOnChange(ControllerTriggerType type, bool is_npad_service_update) {
for (const auto& poller_pair : callback_list) {
const ControllerUpdateCallback& poller = poller_pair.second;
if (!is_service_update && poller.is_service) {
if (!is_npad_service_update && poller.is_npad_service) {
continue;
}
if (poller.on_change) {

View file

@ -20,7 +20,7 @@
namespace Core::HID {
struct ControllerMotionInfo {
Input::MotionStatus raw_status;
Input::MotionStatus raw_status{};
MotionInput emulated{};
};
@ -51,28 +51,28 @@ using BatteryValues = std::array<Input::BatteryStatus, 3>;
using VibrationValues = std::array<Input::VibrationStatus, 2>;
struct AnalogSticks {
AnalogStickState left;
AnalogStickState right;
AnalogStickState left{};
AnalogStickState right{};
};
struct ControllerColors {
NpadControllerColor fullkey;
NpadControllerColor left;
NpadControllerColor right;
NpadControllerColor fullkey{};
NpadControllerColor left{};
NpadControllerColor right{};
};
struct BatteryLevelState {
NpadPowerInfo dual;
NpadPowerInfo left;
NpadPowerInfo right;
NpadPowerInfo dual{};
NpadPowerInfo left{};
NpadPowerInfo right{};
};
struct ControllerMotion {
bool is_at_rest;
Common::Vec3f accel{};
Common::Vec3f gyro{};
Common::Vec3f rotation{};
std::array<Common::Vec3f, 3> orientation{};
bool is_at_rest{};
};
using MotionState = std::array<ControllerMotion, 2>;
@ -113,7 +113,7 @@ enum class ControllerTriggerType {
struct ControllerUpdateCallback {
std::function<void(ControllerTriggerType)> on_change;
bool is_service;
bool is_npad_service;
};
class EmulatedController {

View file

@ -9,7 +9,7 @@
namespace Core::HID {
EmulatedDevices::EmulatedDevices() {}
EmulatedDevices::EmulatedDevices() = default;
EmulatedDevices::~EmulatedDevices() = default;
@ -332,7 +332,7 @@ MousePosition EmulatedDevices::GetMousePosition() const {
}
void EmulatedDevices::TriggerOnChange(DeviceTriggerType type) {
for (const std::pair<int, InterfaceUpdateCallback> poller_pair : callback_list) {
for (const auto& poller_pair : callback_list) {
const InterfaceUpdateCallback& poller = poller_pair.second;
if (poller.on_change) {
poller.on_change(type);

View file

@ -113,8 +113,8 @@ NpadStyleTag HIDCore::GetSupportedStyleTag() const {
s8 HIDCore::GetPlayerCount() const {
s8 active_players = 0;
for (std::size_t player_index = 0; player_index < available_controllers -2; player_index++) {
const auto* controller = GetEmulatedControllerByIndex(player_index);
for (std::size_t player_index = 0; player_index < available_controllers - 2; ++player_index) {
const auto* const controller = GetEmulatedControllerByIndex(player_index);
if (controller->IsConnected()) {
active_players++;
}
@ -123,8 +123,8 @@ s8 HIDCore::GetPlayerCount() const {
}
NpadIdType HIDCore::GetFirstNpadId() const {
for (std::size_t player_index = 0; player_index < available_controllers; player_index++) {
const auto* controller = GetEmulatedControllerByIndex(player_index);
for (std::size_t player_index = 0; player_index < available_controllers; ++player_index) {
const auto* const controller = GetEmulatedControllerByIndex(player_index);
if (controller->IsConnected()) {
return controller->GetNpadIdType();
}

View file

@ -100,7 +100,7 @@ enum class NpadType : u8 {
// This is nn::hid::NpadStyleTag
struct NpadStyleTag {
union {
u32_le raw{};
u32 raw{};
BitField<0, 1, u32> fullkey;
BitField<1, 1, u32> handheld;
@ -132,35 +132,35 @@ static_assert(sizeof(TouchAttribute) == 0x4, "TouchAttribute is an invalid size"
// This is nn::hid::TouchState
struct TouchState {
u64_le delta_time;
u64 delta_time;
TouchAttribute attribute;
u32_le finger;
Common::Point<u32_le> position;
u32_le diameter_x;
u32_le diameter_y;
u32_le rotation_angle;
u32 finger;
Common::Point<u32> position;
u32 diameter_x;
u32 diameter_y;
u32 rotation_angle;
};
static_assert(sizeof(TouchState) == 0x28, "Touchstate is an invalid size");
// This is nn::hid::NpadControllerColor
struct NpadControllerColor {
u32_le body;
u32_le button;
u32 body;
u32 button;
};
static_assert(sizeof(NpadControllerColor) == 8, "NpadControllerColor is an invalid size");
// This is nn::hid::AnalogStickState
struct AnalogStickState {
s32_le x;
s32_le y;
s32 x;
s32 y;
};
static_assert(sizeof(AnalogStickState) == 8, "AnalogStickState is an invalid size");
// This is nn::hid::server::NpadGcTriggerState
struct NpadGcTriggerState {
s64_le sampling_number{};
s32_le left{};
s32_le right{};
s64 sampling_number{};
s32 left{};
s32 right{};
};
static_assert(sizeof(NpadGcTriggerState) == 0x10, "NpadGcTriggerState is an invalid size");
@ -286,7 +286,7 @@ static_assert(sizeof(NpadButtonState) == 0x8, "NpadButtonState has incorrect siz
// This is nn::hid::DebugPadButton
struct DebugPadButton {
union {
u32_le raw{};
u32 raw{};
BitField<0, 1, u32> a;
BitField<1, 1, u32> b;
BitField<2, 1, u32> x;
@ -345,7 +345,7 @@ static_assert(sizeof(VibrationDeviceInfo) == 0x8, "VibrationDeviceInfo has incor
// This is nn::hid::KeyboardModifier
struct KeyboardModifier {
union {
u32_le raw{};
u32 raw{};
BitField<0, 1, u32> control;
BitField<1, 1, u32> shift;
BitField<2, 1, u32> left_alt;
@ -383,7 +383,7 @@ static_assert(sizeof(MouseButton) == 0x4, "MouseButton is an invalid size");
// This is nn::hid::MouseAttribute
struct MouseAttribute {
union {
u32_le raw{};
u32 raw{};
BitField<0, 1, u32> transferable;
BitField<1, 1, u32> is_connected;
};
@ -392,13 +392,13 @@ static_assert(sizeof(MouseAttribute) == 0x4, "MouseAttribute is an invalid size"
// This is nn::hid::detail::MouseState
struct MouseState {
s64_le sampling_number;
s32_le x;
s32_le y;
s32_le delta_x;
s32_le delta_y;
s32_le delta_wheel_x;
s32_le delta_wheel_y;
s64 sampling_number;
s32 x;
s32 y;
s32 delta_x;
s32 delta_y;
s32 delta_wheel_x;
s32 delta_wheel_y;
MouseButton button;
MouseAttribute attribute;
};

View file

@ -142,8 +142,8 @@ Input::StickStatus TransformToStick(const Input::CallbackStatus& callback) {
}
SanitizeStick(status.x, status.y, true);
const Input::AnalogProperties& properties_x = status.x.properties;
const Input::AnalogProperties& properties_y = status.y.properties;
const auto& properties_x = status.x.properties;
const auto& properties_y = status.y.properties;
const float x = status.x.value;
const float y = status.y.value;
@ -213,7 +213,7 @@ Input::TriggerStatus TransformToTrigger(const Input::CallbackStatus& callback) {
}
SanitizeAnalog(status.analog, true);
const Input::AnalogProperties& properties = status.analog.properties;
const auto& properties = status.analog.properties;
float& value = status.analog.value;
// Set button status
@ -231,7 +231,7 @@ Input::TriggerStatus TransformToTrigger(const Input::CallbackStatus& callback) {
}
void SanitizeAnalog(Input::AnalogStatus& analog, bool clamp_value) {
const Input::AnalogProperties& properties = analog.properties;
const auto& properties = analog.properties;
float& raw_value = analog.raw_value;
float& value = analog.value;
@ -271,8 +271,8 @@ void SanitizeAnalog(Input::AnalogStatus& analog, bool clamp_value) {
}
void SanitizeStick(Input::AnalogStatus& analog_x, Input::AnalogStatus& analog_y, bool clamp_value) {
const Input::AnalogProperties& properties_x = analog_x.properties;
const Input::AnalogProperties& properties_y = analog_y.properties;
const auto& properties_x = analog_x.properties;
const auto& properties_y = analog_y.properties;
float& raw_x = analog_x.raw_value;
float& raw_y = analog_y.raw_value;
float& x = analog_x.value;