diff options
| author | 2021-09-20 19:43:16 -0500 | |
|---|---|---|
| committer | 2021-11-24 20:30:23 -0600 | |
| commit | c3f54ff2329d79bdbb273678b5123cf0b1cd090c (patch) | |
| tree | 671542346e2f692b2cef8dc4da6ccdb0b9e21dc2 /src/core/hid/emulated_console.h | |
| parent | yuzu_cmd: Use new input (diff) | |
| download | yuzu-c3f54ff2329d79bdbb273678b5123cf0b1cd090c.tar.gz yuzu-c3f54ff2329d79bdbb273678b5123cf0b1cd090c.tar.xz yuzu-c3f54ff2329d79bdbb273678b5123cf0b1cd090c.zip | |
core/hid: Add emulated controllers
Diffstat (limited to 'src/core/hid/emulated_console.h')
| -rw-r--r-- | src/core/hid/emulated_console.h | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/src/core/hid/emulated_console.h b/src/core/hid/emulated_console.h new file mode 100644 index 000000000..d9e275042 --- /dev/null +++ b/src/core/hid/emulated_console.h | |||
| @@ -0,0 +1,142 @@ | |||
| 1 | // Copyright 2021 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <functional> | ||
| 8 | #include <mutex> | ||
| 9 | #include <unordered_map> | ||
| 10 | |||
| 11 | #include "common/input.h" | ||
| 12 | #include "common/param_package.h" | ||
| 13 | #include "common/point.h" | ||
| 14 | #include "common/quaternion.h" | ||
| 15 | #include "common/settings.h" | ||
| 16 | #include "common/vector_math.h" | ||
| 17 | #include "core/hid/hid_types.h" | ||
| 18 | #include "core/hid/motion_input.h" | ||
| 19 | |||
| 20 | namespace Core::HID { | ||
| 21 | |||
| 22 | struct ConsoleMotionInfo { | ||
| 23 | Input::MotionStatus raw_status; | ||
| 24 | MotionInput emulated{}; | ||
| 25 | }; | ||
| 26 | |||
| 27 | using ConsoleMotionDevices = std::unique_ptr<Input::InputDevice>; | ||
| 28 | using TouchDevices = std::array<std::unique_ptr<Input::InputDevice>, 16>; | ||
| 29 | |||
| 30 | using ConsoleMotionParams = Common::ParamPackage; | ||
| 31 | using TouchParams = std::array<Common::ParamPackage, 16>; | ||
| 32 | |||
| 33 | using ConsoleMotionValues = ConsoleMotionInfo; | ||
| 34 | using TouchValues = std::array<Input::TouchStatus, 16>; | ||
| 35 | |||
| 36 | struct TouchFinger { | ||
| 37 | u64_le last_touch{}; | ||
| 38 | Common::Point<float> position{}; | ||
| 39 | u32_le id{}; | ||
| 40 | bool pressed{}; | ||
| 41 | Core::HID::TouchAttribute attribute{}; | ||
| 42 | }; | ||
| 43 | |||
| 44 | struct ConsoleMotion { | ||
| 45 | bool is_at_rest{}; | ||
| 46 | Common::Vec3f accel{}; | ||
| 47 | Common::Vec3f gyro{}; | ||
| 48 | Common::Vec3f rotation{}; | ||
| 49 | std::array<Common::Vec3f, 3> orientation{}; | ||
| 50 | Common::Quaternion<f32> quaternion{}; | ||
| 51 | }; | ||
| 52 | |||
| 53 | using TouchFingerState = std::array<TouchFinger, 16>; | ||
| 54 | |||
| 55 | struct ConsoleStatus { | ||
| 56 | // Data from input_common | ||
| 57 | ConsoleMotionValues motion_values{}; | ||
| 58 | TouchValues touch_values{}; | ||
| 59 | |||
| 60 | // Data for Nintendo devices; | ||
| 61 | ConsoleMotion motion_state{}; | ||
| 62 | TouchFingerState touch_state{}; | ||
| 63 | }; | ||
| 64 | |||
| 65 | enum class ConsoleTriggerType { | ||
| 66 | Motion, | ||
| 67 | Touch, | ||
| 68 | All, | ||
| 69 | }; | ||
| 70 | |||
| 71 | struct ConsoleUpdateCallback { | ||
| 72 | std::function<void(ConsoleTriggerType)> on_change; | ||
| 73 | }; | ||
| 74 | |||
| 75 | class EmulatedConsole { | ||
| 76 | public: | ||
| 77 | /** | ||
| 78 | * TODO: Write description | ||
| 79 | * | ||
| 80 | * @param npad_id_type | ||
| 81 | */ | ||
| 82 | explicit EmulatedConsole(); | ||
| 83 | ~EmulatedConsole(); | ||
| 84 | |||
| 85 | YUZU_NON_COPYABLE(EmulatedConsole); | ||
| 86 | YUZU_NON_MOVEABLE(EmulatedConsole); | ||
| 87 | |||
| 88 | void ReloadFromSettings(); | ||
| 89 | void ReloadInput(); | ||
| 90 | void UnloadInput(); | ||
| 91 | |||
| 92 | void EnableConfiguration(); | ||
| 93 | void DisableConfiguration(); | ||
| 94 | bool IsConfiguring() const; | ||
| 95 | void SaveCurrentConfig(); | ||
| 96 | void RestoreConfig(); | ||
| 97 | |||
| 98 | Common::ParamPackage GetMotionParam() const; | ||
| 99 | |||
| 100 | void SetMotionParam(Common::ParamPackage param); | ||
| 101 | |||
| 102 | ConsoleMotionValues GetMotionValues() const; | ||
| 103 | TouchValues GetTouchValues() const; | ||
| 104 | |||
| 105 | ConsoleMotion GetMotion() const; | ||
| 106 | TouchFingerState GetTouch() const; | ||
| 107 | |||
| 108 | int SetCallback(ConsoleUpdateCallback update_callback); | ||
| 109 | void DeleteCallback(int key); | ||
| 110 | |||
| 111 | private: | ||
| 112 | /** | ||
| 113 | * Sets the status of a button. Applies toggle properties to the output. | ||
| 114 | * | ||
| 115 | * @param A CallbackStatus and a button index number | ||
| 116 | */ | ||
| 117 | void SetMotion(Input::CallbackStatus callback); | ||
| 118 | void SetTouch(Input::CallbackStatus callback, std::size_t index); | ||
| 119 | |||
| 120 | /** | ||
| 121 | * Triggers a callback that something has changed | ||
| 122 | * | ||
| 123 | * @param Input type of the trigger | ||
| 124 | */ | ||
| 125 | void TriggerOnChange(ConsoleTriggerType type); | ||
| 126 | |||
| 127 | bool is_configuring{false}; | ||
| 128 | f32 motion_sensitivity{0.01f}; | ||
| 129 | |||
| 130 | ConsoleMotionParams motion_params; | ||
| 131 | TouchParams touch_params; | ||
| 132 | |||
| 133 | ConsoleMotionDevices motion_devices; | ||
| 134 | TouchDevices touch_devices; | ||
| 135 | |||
| 136 | mutable std::mutex mutex; | ||
| 137 | std::unordered_map<int, ConsoleUpdateCallback> callback_list; | ||
| 138 | int last_callback_key = 0; | ||
| 139 | ConsoleStatus console; | ||
| 140 | }; | ||
| 141 | |||
| 142 | } // namespace Core::HID | ||