diff options
| author | 2021-10-30 22:23:10 -0500 | |
|---|---|---|
| committer | 2021-11-24 20:30:26 -0600 | |
| commit | 2b1b0c2a30e242b08ec120e09803ec54d5445703 (patch) | |
| tree | 9a10400a7e4403b288eee3aae8a52f1d5be912de /src/input_common/input_poller.cpp | |
| parent | input_common: Revert deleted TAS functions (diff) | |
| download | yuzu-2b1b0c2a30e242b08ec120e09803ec54d5445703.tar.gz yuzu-2b1b0c2a30e242b08ec120e09803ec54d5445703.tar.xz yuzu-2b1b0c2a30e242b08ec120e09803ec54d5445703.zip | |
kraken: Address comments from review
start lion review
Diffstat (limited to 'src/input_common/input_poller.cpp')
| -rw-r--r-- | src/input_common/input_poller.cpp | 202 |
1 files changed, 105 insertions, 97 deletions
diff --git a/src/input_common/input_poller.cpp b/src/input_common/input_poller.cpp index 6edb8d900..2b3b77938 100644 --- a/src/input_common/input_poller.cpp +++ b/src/input_common/input_poller.cpp | |||
| @@ -10,13 +10,13 @@ | |||
| 10 | 10 | ||
| 11 | namespace InputCommon { | 11 | namespace InputCommon { |
| 12 | 12 | ||
| 13 | class DummyInput final : public Input::InputDevice { | 13 | class DummyInput final : public Common::Input::InputDevice { |
| 14 | public: | 14 | public: |
| 15 | explicit DummyInput() {} | 15 | explicit DummyInput() {} |
| 16 | ~DummyInput() {} | 16 | ~DummyInput() {} |
| 17 | }; | 17 | }; |
| 18 | 18 | ||
| 19 | class InputFromButton final : public Input::InputDevice { | 19 | class InputFromButton final : public Common::Input::InputDevice { |
| 20 | public: | 20 | public: |
| 21 | explicit InputFromButton(PadIdentifier identifier_, u32 button_, bool toggle_, bool inverted_, | 21 | explicit InputFromButton(PadIdentifier identifier_, u32 button_, bool toggle_, bool inverted_, |
| 22 | InputEngine* input_engine_) | 22 | InputEngine* input_engine_) |
| @@ -37,7 +37,7 @@ public: | |||
| 37 | input_engine->DeleteCallback(callback_key); | 37 | input_engine->DeleteCallback(callback_key); |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | Input::ButtonStatus GetStatus() const { | 40 | Common::Input::ButtonStatus GetStatus() const { |
| 41 | return { | 41 | return { |
| 42 | .value = input_engine->GetButton(identifier, button), | 42 | .value = input_engine->GetButton(identifier, button), |
| 43 | .inverted = inverted, | 43 | .inverted = inverted, |
| @@ -46,8 +46,8 @@ public: | |||
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | void ForceUpdate() { | 48 | void ForceUpdate() { |
| 49 | const Input::CallbackStatus status{ | 49 | const Common::Input::CallbackStatus status{ |
| 50 | .type = Input::InputType::Button, | 50 | .type = Common::Input::InputType::Button, |
| 51 | .button_status = GetStatus(), | 51 | .button_status = GetStatus(), |
| 52 | }; | 52 | }; |
| 53 | 53 | ||
| @@ -56,8 +56,8 @@ public: | |||
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | void OnChange() { | 58 | void OnChange() { |
| 59 | const Input::CallbackStatus status{ | 59 | const Common::Input::CallbackStatus status{ |
| 60 | .type = Input::InputType::Button, | 60 | .type = Common::Input::InputType::Button, |
| 61 | .button_status = GetStatus(), | 61 | .button_status = GetStatus(), |
| 62 | }; | 62 | }; |
| 63 | 63 | ||
| @@ -77,7 +77,7 @@ private: | |||
| 77 | InputEngine* input_engine; | 77 | InputEngine* input_engine; |
| 78 | }; | 78 | }; |
| 79 | 79 | ||
| 80 | class InputFromHatButton final : public Input::InputDevice { | 80 | class InputFromHatButton final : public Common::Input::InputDevice { |
| 81 | public: | 81 | public: |
| 82 | explicit InputFromHatButton(PadIdentifier identifier_, u32 button_, u8 direction_, bool toggle_, | 82 | explicit InputFromHatButton(PadIdentifier identifier_, u32 button_, u8 direction_, bool toggle_, |
| 83 | bool inverted_, InputEngine* input_engine_) | 83 | bool inverted_, InputEngine* input_engine_) |
| @@ -98,7 +98,7 @@ public: | |||
| 98 | input_engine->DeleteCallback(callback_key); | 98 | input_engine->DeleteCallback(callback_key); |
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | Input::ButtonStatus GetStatus() const { | 101 | Common::Input::ButtonStatus GetStatus() const { |
| 102 | return { | 102 | return { |
| 103 | .value = input_engine->GetHatButton(identifier, button, direction), | 103 | .value = input_engine->GetHatButton(identifier, button, direction), |
| 104 | .inverted = inverted, | 104 | .inverted = inverted, |
| @@ -107,8 +107,8 @@ public: | |||
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | void ForceUpdate() { | 109 | void ForceUpdate() { |
| 110 | const Input::CallbackStatus status{ | 110 | const Common::Input::CallbackStatus status{ |
| 111 | .type = Input::InputType::Button, | 111 | .type = Common::Input::InputType::Button, |
| 112 | .button_status = GetStatus(), | 112 | .button_status = GetStatus(), |
| 113 | }; | 113 | }; |
| 114 | 114 | ||
| @@ -117,8 +117,8 @@ public: | |||
| 117 | } | 117 | } |
| 118 | 118 | ||
| 119 | void OnChange() { | 119 | void OnChange() { |
| 120 | const Input::CallbackStatus status{ | 120 | const Common::Input::CallbackStatus status{ |
| 121 | .type = Input::InputType::Button, | 121 | .type = Common::Input::InputType::Button, |
| 122 | .button_status = GetStatus(), | 122 | .button_status = GetStatus(), |
| 123 | }; | 123 | }; |
| 124 | 124 | ||
| @@ -139,11 +139,12 @@ private: | |||
| 139 | InputEngine* input_engine; | 139 | InputEngine* input_engine; |
| 140 | }; | 140 | }; |
| 141 | 141 | ||
| 142 | class InputFromStick final : public Input::InputDevice { | 142 | class InputFromStick final : public Common::Input::InputDevice { |
| 143 | public: | 143 | public: |
| 144 | explicit InputFromStick(PadIdentifier identifier_, u32 axis_x_, u32 axis_y_, | 144 | explicit InputFromStick(PadIdentifier identifier_, u32 axis_x_, u32 axis_y_, |
| 145 | Input::AnalogProperties properties_x_, | 145 | Common::Input::AnalogProperties properties_x_, |
| 146 | Input::AnalogProperties properties_y_, InputEngine* input_engine_) | 146 | Common::Input::AnalogProperties properties_y_, |
| 147 | InputEngine* input_engine_) | ||
| 147 | : identifier(identifier_), axis_x(axis_x_), axis_y(axis_y_), properties_x(properties_x_), | 148 | : identifier(identifier_), axis_x(axis_x_), axis_y(axis_y_), properties_x(properties_x_), |
| 148 | properties_y(properties_y_), input_engine(input_engine_) { | 149 | properties_y(properties_y_), input_engine(input_engine_) { |
| 149 | UpdateCallback engine_callback{[this]() { OnChange(); }}; | 150 | UpdateCallback engine_callback{[this]() { OnChange(); }}; |
| @@ -170,8 +171,8 @@ public: | |||
| 170 | input_engine->DeleteCallback(callback_key_y); | 171 | input_engine->DeleteCallback(callback_key_y); |
| 171 | } | 172 | } |
| 172 | 173 | ||
| 173 | Input::StickStatus GetStatus() const { | 174 | Common::Input::StickStatus GetStatus() const { |
| 174 | Input::StickStatus status; | 175 | Common::Input::StickStatus status; |
| 175 | status.x = { | 176 | status.x = { |
| 176 | .raw_value = input_engine->GetAxis(identifier, axis_x), | 177 | .raw_value = input_engine->GetAxis(identifier, axis_x), |
| 177 | .properties = properties_x, | 178 | .properties = properties_x, |
| @@ -184,8 +185,8 @@ public: | |||
| 184 | } | 185 | } |
| 185 | 186 | ||
| 186 | void ForceUpdate() { | 187 | void ForceUpdate() { |
| 187 | const Input::CallbackStatus status{ | 188 | const Common::Input::CallbackStatus status{ |
| 188 | .type = Input::InputType::Stick, | 189 | .type = Common::Input::InputType::Stick, |
| 189 | .stick_status = GetStatus(), | 190 | .stick_status = GetStatus(), |
| 190 | }; | 191 | }; |
| 191 | 192 | ||
| @@ -195,8 +196,8 @@ public: | |||
| 195 | } | 196 | } |
| 196 | 197 | ||
| 197 | void OnChange() { | 198 | void OnChange() { |
| 198 | const Input::CallbackStatus status{ | 199 | const Common::Input::CallbackStatus status{ |
| 199 | .type = Input::InputType::Stick, | 200 | .type = Common::Input::InputType::Stick, |
| 200 | .stick_status = GetStatus(), | 201 | .stick_status = GetStatus(), |
| 201 | }; | 202 | }; |
| 202 | 203 | ||
| @@ -212,8 +213,8 @@ private: | |||
| 212 | const PadIdentifier identifier; | 213 | const PadIdentifier identifier; |
| 213 | const u32 axis_x; | 214 | const u32 axis_x; |
| 214 | const u32 axis_y; | 215 | const u32 axis_y; |
| 215 | const Input::AnalogProperties properties_x; | 216 | const Common::Input::AnalogProperties properties_x; |
| 216 | const Input::AnalogProperties properties_y; | 217 | const Common::Input::AnalogProperties properties_y; |
| 217 | int callback_key_x; | 218 | int callback_key_x; |
| 218 | int callback_key_y; | 219 | int callback_key_y; |
| 219 | float last_axis_x_value; | 220 | float last_axis_x_value; |
| @@ -221,12 +222,13 @@ private: | |||
| 221 | InputEngine* input_engine; | 222 | InputEngine* input_engine; |
| 222 | }; | 223 | }; |
| 223 | 224 | ||
| 224 | class InputFromTouch final : public Input::InputDevice { | 225 | class InputFromTouch final : public Common::Input::InputDevice { |
| 225 | public: | 226 | public: |
| 226 | explicit InputFromTouch(PadIdentifier identifier_, u32 touch_id_, u32 button_, bool toggle_, | 227 | explicit InputFromTouch(PadIdentifier identifier_, u32 touch_id_, u32 button_, bool toggle_, |
| 227 | bool inverted_, u32 axis_x_, u32 axis_y_, | 228 | bool inverted_, u32 axis_x_, u32 axis_y_, |
| 228 | Input::AnalogProperties properties_x_, | 229 | Common::Input::AnalogProperties properties_x_, |
| 229 | Input::AnalogProperties properties_y_, InputEngine* input_engine_) | 230 | Common::Input::AnalogProperties properties_y_, |
| 231 | InputEngine* input_engine_) | ||
| 230 | : identifier(identifier_), touch_id(touch_id_), button(button_), toggle(toggle_), | 232 | : identifier(identifier_), touch_id(touch_id_), button(button_), toggle(toggle_), |
| 231 | inverted(inverted_), axis_x(axis_x_), axis_y(axis_y_), properties_x(properties_x_), | 233 | inverted(inverted_), axis_x(axis_x_), axis_y(axis_y_), properties_x(properties_x_), |
| 232 | properties_y(properties_y_), input_engine(input_engine_) { | 234 | properties_y(properties_y_), input_engine(input_engine_) { |
| @@ -263,8 +265,8 @@ public: | |||
| 263 | input_engine->DeleteCallback(callback_key_y); | 265 | input_engine->DeleteCallback(callback_key_y); |
| 264 | } | 266 | } |
| 265 | 267 | ||
| 266 | Input::TouchStatus GetStatus() const { | 268 | Common::Input::TouchStatus GetStatus() const { |
| 267 | Input::TouchStatus status; | 269 | Common::Input::TouchStatus status; |
| 268 | status.id = touch_id; | 270 | status.id = touch_id; |
| 269 | status.pressed = { | 271 | status.pressed = { |
| 270 | .value = input_engine->GetButton(identifier, button), | 272 | .value = input_engine->GetButton(identifier, button), |
| @@ -283,8 +285,8 @@ public: | |||
| 283 | } | 285 | } |
| 284 | 286 | ||
| 285 | void OnChange() { | 287 | void OnChange() { |
| 286 | const Input::CallbackStatus status{ | 288 | const Common::Input::CallbackStatus status{ |
| 287 | .type = Input::InputType::Touch, | 289 | .type = Common::Input::InputType::Touch, |
| 288 | .touch_status = GetStatus(), | 290 | .touch_status = GetStatus(), |
| 289 | }; | 291 | }; |
| 290 | 292 | ||
| @@ -306,8 +308,8 @@ private: | |||
| 306 | const bool inverted; | 308 | const bool inverted; |
| 307 | const u32 axis_x; | 309 | const u32 axis_x; |
| 308 | const u32 axis_y; | 310 | const u32 axis_y; |
| 309 | const Input::AnalogProperties properties_x; | 311 | const Common::Input::AnalogProperties properties_x; |
| 310 | const Input::AnalogProperties properties_y; | 312 | const Common::Input::AnalogProperties properties_y; |
| 311 | int callback_key_button; | 313 | int callback_key_button; |
| 312 | int callback_key_x; | 314 | int callback_key_x; |
| 313 | int callback_key_y; | 315 | int callback_key_y; |
| @@ -317,10 +319,10 @@ private: | |||
| 317 | InputEngine* input_engine; | 319 | InputEngine* input_engine; |
| 318 | }; | 320 | }; |
| 319 | 321 | ||
| 320 | class InputFromTrigger final : public Input::InputDevice { | 322 | class InputFromTrigger final : public Common::Input::InputDevice { |
| 321 | public: | 323 | public: |
| 322 | explicit InputFromTrigger(PadIdentifier identifier_, u32 button_, bool toggle_, bool inverted_, | 324 | explicit InputFromTrigger(PadIdentifier identifier_, u32 button_, bool toggle_, bool inverted_, |
| 323 | u32 axis_, Input::AnalogProperties properties_, | 325 | u32 axis_, Common::Input::AnalogProperties properties_, |
| 324 | InputEngine* input_engine_) | 326 | InputEngine* input_engine_) |
| 325 | : identifier(identifier_), button(button_), toggle(toggle_), inverted(inverted_), | 327 | : identifier(identifier_), button(button_), toggle(toggle_), inverted(inverted_), |
| 326 | axis(axis_), properties(properties_), input_engine(input_engine_) { | 328 | axis(axis_), properties(properties_), input_engine(input_engine_) { |
| @@ -348,8 +350,8 @@ public: | |||
| 348 | input_engine->DeleteCallback(axis_callback_key); | 350 | input_engine->DeleteCallback(axis_callback_key); |
| 349 | } | 351 | } |
| 350 | 352 | ||
| 351 | Input::TriggerStatus GetStatus() const { | 353 | Common::Input::TriggerStatus GetStatus() const { |
| 352 | const Input::AnalogStatus analog_status{ | 354 | const Common::Input::AnalogStatus analog_status{ |
| 353 | .raw_value = input_engine->GetAxis(identifier, axis), | 355 | .raw_value = input_engine->GetAxis(identifier, axis), |
| 354 | .properties = properties, | 356 | .properties = properties, |
| 355 | }; | 357 | }; |
| @@ -360,8 +362,8 @@ public: | |||
| 360 | } | 362 | } |
| 361 | 363 | ||
| 362 | void OnChange() { | 364 | void OnChange() { |
| 363 | const Input::CallbackStatus status{ | 365 | const Common::Input::CallbackStatus status{ |
| 364 | .type = Input::InputType::Trigger, | 366 | .type = Common::Input::InputType::Trigger, |
| 365 | .trigger_status = GetStatus(), | 367 | .trigger_status = GetStatus(), |
| 366 | }; | 368 | }; |
| 367 | 369 | ||
| @@ -379,7 +381,7 @@ private: | |||
| 379 | const bool toggle; | 381 | const bool toggle; |
| 380 | const bool inverted; | 382 | const bool inverted; |
| 381 | const u32 axis; | 383 | const u32 axis; |
| 382 | const Input::AnalogProperties properties; | 384 | const Common::Input::AnalogProperties properties; |
| 383 | int callback_key_button; | 385 | int callback_key_button; |
| 384 | int axis_callback_key; | 386 | int axis_callback_key; |
| 385 | bool last_button_value; | 387 | bool last_button_value; |
| @@ -387,10 +389,11 @@ private: | |||
| 387 | InputEngine* input_engine; | 389 | InputEngine* input_engine; |
| 388 | }; | 390 | }; |
| 389 | 391 | ||
| 390 | class InputFromAnalog final : public Input::InputDevice { | 392 | class InputFromAnalog final : public Common::Input::InputDevice { |
| 391 | public: | 393 | public: |
| 392 | explicit InputFromAnalog(PadIdentifier identifier_, u32 axis_, | 394 | explicit InputFromAnalog(PadIdentifier identifier_, u32 axis_, |
| 393 | Input::AnalogProperties properties_, InputEngine* input_engine_) | 395 | Common::Input::AnalogProperties properties_, |
| 396 | InputEngine* input_engine_) | ||
| 394 | : identifier(identifier_), axis(axis_), properties(properties_), | 397 | : identifier(identifier_), axis(axis_), properties(properties_), |
| 395 | input_engine(input_engine_) { | 398 | input_engine(input_engine_) { |
| 396 | UpdateCallback engine_callback{[this]() { OnChange(); }}; | 399 | UpdateCallback engine_callback{[this]() { OnChange(); }}; |
| @@ -408,7 +411,7 @@ public: | |||
| 408 | input_engine->DeleteCallback(callback_key); | 411 | input_engine->DeleteCallback(callback_key); |
| 409 | } | 412 | } |
| 410 | 413 | ||
| 411 | Input::AnalogStatus GetStatus() const { | 414 | Common::Input::AnalogStatus GetStatus() const { |
| 412 | return { | 415 | return { |
| 413 | .raw_value = input_engine->GetAxis(identifier, axis), | 416 | .raw_value = input_engine->GetAxis(identifier, axis), |
| 414 | .properties = properties, | 417 | .properties = properties, |
| @@ -416,8 +419,8 @@ public: | |||
| 416 | } | 419 | } |
| 417 | 420 | ||
| 418 | void OnChange() { | 421 | void OnChange() { |
| 419 | const Input::CallbackStatus status{ | 422 | const Common::Input::CallbackStatus status{ |
| 420 | .type = Input::InputType::Analog, | 423 | .type = Common::Input::InputType::Analog, |
| 421 | .analog_status = GetStatus(), | 424 | .analog_status = GetStatus(), |
| 422 | }; | 425 | }; |
| 423 | 426 | ||
| @@ -430,13 +433,13 @@ public: | |||
| 430 | private: | 433 | private: |
| 431 | const PadIdentifier identifier; | 434 | const PadIdentifier identifier; |
| 432 | const u32 axis; | 435 | const u32 axis; |
| 433 | const Input::AnalogProperties properties; | 436 | const Common::Input::AnalogProperties properties; |
| 434 | int callback_key; | 437 | int callback_key; |
| 435 | float last_axis_value; | 438 | float last_axis_value; |
| 436 | InputEngine* input_engine; | 439 | InputEngine* input_engine; |
| 437 | }; | 440 | }; |
| 438 | 441 | ||
| 439 | class InputFromBattery final : public Input::InputDevice { | 442 | class InputFromBattery final : public Common::Input::InputDevice { |
| 440 | public: | 443 | public: |
| 441 | explicit InputFromBattery(PadIdentifier identifier_, InputEngine* input_engine_) | 444 | explicit InputFromBattery(PadIdentifier identifier_, InputEngine* input_engine_) |
| 442 | : identifier(identifier_), input_engine(input_engine_) { | 445 | : identifier(identifier_), input_engine(input_engine_) { |
| @@ -447,7 +450,7 @@ public: | |||
| 447 | .index = 0, | 450 | .index = 0, |
| 448 | .callback = engine_callback, | 451 | .callback = engine_callback, |
| 449 | }; | 452 | }; |
| 450 | last_battery_value = Input::BatteryStatus::Charging; | 453 | last_battery_value = Common::Input::BatteryStatus::Charging; |
| 451 | callback_key = input_engine->SetCallback(input_identifier); | 454 | callback_key = input_engine->SetCallback(input_identifier); |
| 452 | } | 455 | } |
| 453 | 456 | ||
| @@ -455,13 +458,13 @@ public: | |||
| 455 | input_engine->DeleteCallback(callback_key); | 458 | input_engine->DeleteCallback(callback_key); |
| 456 | } | 459 | } |
| 457 | 460 | ||
| 458 | Input::BatteryStatus GetStatus() const { | 461 | Common::Input::BatteryStatus GetStatus() const { |
| 459 | return static_cast<Input::BatteryLevel>(input_engine->GetBattery(identifier)); | 462 | return static_cast<Common::Input::BatteryLevel>(input_engine->GetBattery(identifier)); |
| 460 | } | 463 | } |
| 461 | 464 | ||
| 462 | void ForceUpdate() { | 465 | void ForceUpdate() { |
| 463 | const Input::CallbackStatus status{ | 466 | const Common::Input::CallbackStatus status{ |
| 464 | .type = Input::InputType::Battery, | 467 | .type = Common::Input::InputType::Battery, |
| 465 | .battery_status = GetStatus(), | 468 | .battery_status = GetStatus(), |
| 466 | }; | 469 | }; |
| 467 | 470 | ||
| @@ -470,8 +473,8 @@ public: | |||
| 470 | } | 473 | } |
| 471 | 474 | ||
| 472 | void OnChange() { | 475 | void OnChange() { |
| 473 | const Input::CallbackStatus status{ | 476 | const Common::Input::CallbackStatus status{ |
| 474 | .type = Input::InputType::Battery, | 477 | .type = Common::Input::InputType::Battery, |
| 475 | .battery_status = GetStatus(), | 478 | .battery_status = GetStatus(), |
| 476 | }; | 479 | }; |
| 477 | 480 | ||
| @@ -484,11 +487,11 @@ public: | |||
| 484 | private: | 487 | private: |
| 485 | const PadIdentifier identifier; | 488 | const PadIdentifier identifier; |
| 486 | int callback_key; | 489 | int callback_key; |
| 487 | Input::BatteryStatus last_battery_value; | 490 | Common::Input::BatteryStatus last_battery_value; |
| 488 | InputEngine* input_engine; | 491 | InputEngine* input_engine; |
| 489 | }; | 492 | }; |
| 490 | 493 | ||
| 491 | class InputFromMotion final : public Input::InputDevice { | 494 | class InputFromMotion final : public Common::Input::InputDevice { |
| 492 | public: | 495 | public: |
| 493 | explicit InputFromMotion(PadIdentifier identifier_, u32 motion_sensor_, | 496 | explicit InputFromMotion(PadIdentifier identifier_, u32 motion_sensor_, |
| 494 | InputEngine* input_engine_) | 497 | InputEngine* input_engine_) |
| @@ -507,10 +510,10 @@ public: | |||
| 507 | input_engine->DeleteCallback(callback_key); | 510 | input_engine->DeleteCallback(callback_key); |
| 508 | } | 511 | } |
| 509 | 512 | ||
| 510 | Input::MotionStatus GetStatus() const { | 513 | Common::Input::MotionStatus GetStatus() const { |
| 511 | const auto basic_motion = input_engine->GetMotion(identifier, motion_sensor); | 514 | const auto basic_motion = input_engine->GetMotion(identifier, motion_sensor); |
| 512 | Input::MotionStatus status{}; | 515 | Common::Input::MotionStatus status{}; |
| 513 | const Input::AnalogProperties properties = { | 516 | const Common::Input::AnalogProperties properties = { |
| 514 | .deadzone = 0.001f, | 517 | .deadzone = 0.001f, |
| 515 | .range = 1.0f, | 518 | .range = 1.0f, |
| 516 | .offset = 0.0f, | 519 | .offset = 0.0f, |
| @@ -526,8 +529,8 @@ public: | |||
| 526 | } | 529 | } |
| 527 | 530 | ||
| 528 | void OnChange() { | 531 | void OnChange() { |
| 529 | const Input::CallbackStatus status{ | 532 | const Common::Input::CallbackStatus status{ |
| 530 | .type = Input::InputType::Motion, | 533 | .type = Common::Input::InputType::Motion, |
| 531 | .motion_status = GetStatus(), | 534 | .motion_status = GetStatus(), |
| 532 | }; | 535 | }; |
| 533 | 536 | ||
| @@ -541,12 +544,13 @@ private: | |||
| 541 | InputEngine* input_engine; | 544 | InputEngine* input_engine; |
| 542 | }; | 545 | }; |
| 543 | 546 | ||
| 544 | class InputFromAxisMotion final : public Input::InputDevice { | 547 | class InputFromAxisMotion final : public Common::Input::InputDevice { |
| 545 | public: | 548 | public: |
| 546 | explicit InputFromAxisMotion(PadIdentifier identifier_, u32 axis_x_, u32 axis_y_, u32 axis_z_, | 549 | explicit InputFromAxisMotion(PadIdentifier identifier_, u32 axis_x_, u32 axis_y_, u32 axis_z_, |
| 547 | Input::AnalogProperties properties_x_, | 550 | Common::Input::AnalogProperties properties_x_, |
| 548 | Input::AnalogProperties properties_y_, | 551 | Common::Input::AnalogProperties properties_y_, |
| 549 | Input::AnalogProperties properties_z_, InputEngine* input_engine_) | 552 | Common::Input::AnalogProperties properties_z_, |
| 553 | InputEngine* input_engine_) | ||
| 550 | : identifier(identifier_), axis_x(axis_x_), axis_y(axis_y_), axis_z(axis_z_), | 554 | : identifier(identifier_), axis_x(axis_x_), axis_y(axis_y_), axis_z(axis_z_), |
| 551 | properties_x(properties_x_), properties_y(properties_y_), properties_z(properties_z_), | 555 | properties_x(properties_x_), properties_y(properties_y_), properties_z(properties_z_), |
| 552 | input_engine(input_engine_) { | 556 | input_engine(input_engine_) { |
| @@ -583,8 +587,8 @@ public: | |||
| 583 | input_engine->DeleteCallback(callback_key_z); | 587 | input_engine->DeleteCallback(callback_key_z); |
| 584 | } | 588 | } |
| 585 | 589 | ||
| 586 | Input::MotionStatus GetStatus() const { | 590 | Common::Input::MotionStatus GetStatus() const { |
| 587 | Input::MotionStatus status{}; | 591 | Common::Input::MotionStatus status{}; |
| 588 | status.gyro.x = { | 592 | status.gyro.x = { |
| 589 | .raw_value = input_engine->GetAxis(identifier, axis_x), | 593 | .raw_value = input_engine->GetAxis(identifier, axis_x), |
| 590 | .properties = properties_x, | 594 | .properties = properties_x, |
| @@ -601,8 +605,8 @@ public: | |||
| 601 | } | 605 | } |
| 602 | 606 | ||
| 603 | void ForceUpdate() { | 607 | void ForceUpdate() { |
| 604 | const Input::CallbackStatus status{ | 608 | const Common::Input::CallbackStatus status{ |
| 605 | .type = Input::InputType::Motion, | 609 | .type = Common::Input::InputType::Motion, |
| 606 | .motion_status = GetStatus(), | 610 | .motion_status = GetStatus(), |
| 607 | }; | 611 | }; |
| 608 | 612 | ||
| @@ -613,8 +617,8 @@ public: | |||
| 613 | } | 617 | } |
| 614 | 618 | ||
| 615 | void OnChange() { | 619 | void OnChange() { |
| 616 | const Input::CallbackStatus status{ | 620 | const Common::Input::CallbackStatus status{ |
| 617 | .type = Input::InputType::Motion, | 621 | .type = Common::Input::InputType::Motion, |
| 618 | .motion_status = GetStatus(), | 622 | .motion_status = GetStatus(), |
| 619 | }; | 623 | }; |
| 620 | 624 | ||
| @@ -633,9 +637,9 @@ private: | |||
| 633 | const u32 axis_x; | 637 | const u32 axis_x; |
| 634 | const u32 axis_y; | 638 | const u32 axis_y; |
| 635 | const u32 axis_z; | 639 | const u32 axis_z; |
| 636 | const Input::AnalogProperties properties_x; | 640 | const Common::Input::AnalogProperties properties_x; |
| 637 | const Input::AnalogProperties properties_y; | 641 | const Common::Input::AnalogProperties properties_y; |
| 638 | const Input::AnalogProperties properties_z; | 642 | const Common::Input::AnalogProperties properties_z; |
| 639 | int callback_key_x; | 643 | int callback_key_x; |
| 640 | int callback_key_y; | 644 | int callback_key_y; |
| 641 | int callback_key_z; | 645 | int callback_key_z; |
| @@ -645,20 +649,21 @@ private: | |||
| 645 | InputEngine* input_engine; | 649 | InputEngine* input_engine; |
| 646 | }; | 650 | }; |
| 647 | 651 | ||
| 648 | class OutputFromIdentifier final : public Input::OutputDevice { | 652 | class OutputFromIdentifier final : public Common::Input::OutputDevice { |
| 649 | public: | 653 | public: |
| 650 | explicit OutputFromIdentifier(PadIdentifier identifier_, InputEngine* input_engine_) | 654 | explicit OutputFromIdentifier(PadIdentifier identifier_, InputEngine* input_engine_) |
| 651 | : identifier(identifier_), input_engine(input_engine_) {} | 655 | : identifier(identifier_), input_engine(input_engine_) {} |
| 652 | 656 | ||
| 653 | virtual void SetLED(Input::LedStatus led_status) { | 657 | virtual void SetLED(Common::Input::LedStatus led_status) { |
| 654 | input_engine->SetLeds(identifier, led_status); | 658 | input_engine->SetLeds(identifier, led_status); |
| 655 | } | 659 | } |
| 656 | 660 | ||
| 657 | virtual Input::VibrationError SetVibration(Input::VibrationStatus vibration_status) { | 661 | virtual Common::Input::VibrationError SetVibration( |
| 662 | Common::Input::VibrationStatus vibration_status) { | ||
| 658 | return input_engine->SetRumble(identifier, vibration_status); | 663 | return input_engine->SetRumble(identifier, vibration_status); |
| 659 | } | 664 | } |
| 660 | 665 | ||
| 661 | virtual Input::PollingError SetPollingMode(Input::PollingMode polling_mode) { | 666 | virtual Common::Input::PollingError SetPollingMode(Common::Input::PollingMode polling_mode) { |
| 662 | return input_engine->SetPollingMode(identifier, polling_mode); | 667 | return input_engine->SetPollingMode(identifier, polling_mode); |
| 663 | } | 668 | } |
| 664 | 669 | ||
| @@ -667,7 +672,7 @@ private: | |||
| 667 | InputEngine* input_engine; | 672 | InputEngine* input_engine; |
| 668 | }; | 673 | }; |
| 669 | 674 | ||
| 670 | std::unique_ptr<Input::InputDevice> InputFactory::CreateButtonDevice( | 675 | std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateButtonDevice( |
| 671 | const Common::ParamPackage& params) { | 676 | const Common::ParamPackage& params) { |
| 672 | const PadIdentifier identifier = { | 677 | const PadIdentifier identifier = { |
| 673 | .guid = Common::UUID{params.Get("guid", "")}, | 678 | .guid = Common::UUID{params.Get("guid", "")}, |
| @@ -690,7 +695,7 @@ std::unique_ptr<Input::InputDevice> InputFactory::CreateButtonDevice( | |||
| 690 | input_engine.get()); | 695 | input_engine.get()); |
| 691 | } | 696 | } |
| 692 | 697 | ||
| 693 | std::unique_ptr<Input::InputDevice> InputFactory::CreateHatButtonDevice( | 698 | std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateHatButtonDevice( |
| 694 | const Common::ParamPackage& params) { | 699 | const Common::ParamPackage& params) { |
| 695 | const PadIdentifier identifier = { | 700 | const PadIdentifier identifier = { |
| 696 | .guid = Common::UUID{params.Get("guid", "")}, | 701 | .guid = Common::UUID{params.Get("guid", "")}, |
| @@ -709,7 +714,7 @@ std::unique_ptr<Input::InputDevice> InputFactory::CreateHatButtonDevice( | |||
| 709 | input_engine.get()); | 714 | input_engine.get()); |
| 710 | } | 715 | } |
| 711 | 716 | ||
| 712 | std::unique_ptr<Input::InputDevice> InputFactory::CreateStickDevice( | 717 | std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateStickDevice( |
| 713 | const Common::ParamPackage& params) { | 718 | const Common::ParamPackage& params) { |
| 714 | const auto deadzone = std::clamp(params.Get("deadzone", 0.15f), 0.0f, 1.0f); | 719 | const auto deadzone = std::clamp(params.Get("deadzone", 0.15f), 0.0f, 1.0f); |
| 715 | const auto range = std::clamp(params.Get("range", 1.0f), 0.25f, 1.50f); | 720 | const auto range = std::clamp(params.Get("range", 1.0f), 0.25f, 1.50f); |
| @@ -721,7 +726,7 @@ std::unique_ptr<Input::InputDevice> InputFactory::CreateStickDevice( | |||
| 721 | }; | 726 | }; |
| 722 | 727 | ||
| 723 | const auto axis_x = static_cast<u32>(params.Get("axis_x", 0)); | 728 | const auto axis_x = static_cast<u32>(params.Get("axis_x", 0)); |
| 724 | const Input::AnalogProperties properties_x = { | 729 | const Common::Input::AnalogProperties properties_x = { |
| 725 | .deadzone = deadzone, | 730 | .deadzone = deadzone, |
| 726 | .range = range, | 731 | .range = range, |
| 727 | .threshold = threshold, | 732 | .threshold = threshold, |
| @@ -730,7 +735,7 @@ std::unique_ptr<Input::InputDevice> InputFactory::CreateStickDevice( | |||
| 730 | }; | 735 | }; |
| 731 | 736 | ||
| 732 | const auto axis_y = static_cast<u32>(params.Get("axis_y", 1)); | 737 | const auto axis_y = static_cast<u32>(params.Get("axis_y", 1)); |
| 733 | const Input::AnalogProperties properties_y = { | 738 | const Common::Input::AnalogProperties properties_y = { |
| 734 | .deadzone = deadzone, | 739 | .deadzone = deadzone, |
| 735 | .range = range, | 740 | .range = range, |
| 736 | .threshold = threshold, | 741 | .threshold = threshold, |
| @@ -744,7 +749,7 @@ std::unique_ptr<Input::InputDevice> InputFactory::CreateStickDevice( | |||
| 744 | input_engine.get()); | 749 | input_engine.get()); |
| 745 | } | 750 | } |
| 746 | 751 | ||
| 747 | std::unique_ptr<Input::InputDevice> InputFactory::CreateAnalogDevice( | 752 | std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateAnalogDevice( |
| 748 | const Common::ParamPackage& params) { | 753 | const Common::ParamPackage& params) { |
| 749 | const PadIdentifier identifier = { | 754 | const PadIdentifier identifier = { |
| 750 | .guid = Common::UUID{params.Get("guid", "")}, | 755 | .guid = Common::UUID{params.Get("guid", "")}, |
| @@ -753,7 +758,7 @@ std::unique_ptr<Input::InputDevice> InputFactory::CreateAnalogDevice( | |||
| 753 | }; | 758 | }; |
| 754 | 759 | ||
| 755 | const auto axis = static_cast<u32>(params.Get("axis", 0)); | 760 | const auto axis = static_cast<u32>(params.Get("axis", 0)); |
| 756 | const Input::AnalogProperties properties = { | 761 | const Common::Input::AnalogProperties properties = { |
| 757 | .deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f), | 762 | .deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f), |
| 758 | .range = std::clamp(params.Get("range", 1.0f), 0.25f, 1.50f), | 763 | .range = std::clamp(params.Get("range", 1.0f), 0.25f, 1.50f), |
| 759 | .threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f), | 764 | .threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f), |
| @@ -765,7 +770,7 @@ std::unique_ptr<Input::InputDevice> InputFactory::CreateAnalogDevice( | |||
| 765 | return std::make_unique<InputFromAnalog>(identifier, axis, properties, input_engine.get()); | 770 | return std::make_unique<InputFromAnalog>(identifier, axis, properties, input_engine.get()); |
| 766 | } | 771 | } |
| 767 | 772 | ||
| 768 | std::unique_ptr<Input::InputDevice> InputFactory::CreateTriggerDevice( | 773 | std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateTriggerDevice( |
| 769 | const Common::ParamPackage& params) { | 774 | const Common::ParamPackage& params) { |
| 770 | const PadIdentifier identifier = { | 775 | const PadIdentifier identifier = { |
| 771 | .guid = Common::UUID{params.Get("guid", "")}, | 776 | .guid = Common::UUID{params.Get("guid", "")}, |
| @@ -778,7 +783,7 @@ std::unique_ptr<Input::InputDevice> InputFactory::CreateTriggerDevice( | |||
| 778 | const auto inverted = params.Get("inverted", false); | 783 | const auto inverted = params.Get("inverted", false); |
| 779 | 784 | ||
| 780 | const auto axis = static_cast<u32>(params.Get("axis", 0)); | 785 | const auto axis = static_cast<u32>(params.Get("axis", 0)); |
| 781 | const Input::AnalogProperties properties = { | 786 | const Common::Input::AnalogProperties properties = { |
| 782 | .deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f), | 787 | .deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f), |
| 783 | .range = std::clamp(params.Get("range", 1.0f), 0.25f, 2.50f), | 788 | .range = std::clamp(params.Get("range", 1.0f), 0.25f, 2.50f), |
| 784 | .threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f), | 789 | .threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f), |
| @@ -792,7 +797,7 @@ std::unique_ptr<Input::InputDevice> InputFactory::CreateTriggerDevice( | |||
| 792 | properties, input_engine.get()); | 797 | properties, input_engine.get()); |
| 793 | } | 798 | } |
| 794 | 799 | ||
| 795 | std::unique_ptr<Input::InputDevice> InputFactory::CreateTouchDevice( | 800 | std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateTouchDevice( |
| 796 | const Common::ParamPackage& params) { | 801 | const Common::ParamPackage& params) { |
| 797 | const auto touch_id = params.Get("touch_id", 0); | 802 | const auto touch_id = params.Get("touch_id", 0); |
| 798 | const auto deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f); | 803 | const auto deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f); |
| @@ -809,7 +814,7 @@ std::unique_ptr<Input::InputDevice> InputFactory::CreateTouchDevice( | |||
| 809 | const auto inverted = params.Get("inverted", false); | 814 | const auto inverted = params.Get("inverted", false); |
| 810 | 815 | ||
| 811 | const auto axis_x = static_cast<u32>(params.Get("axis_x", 0)); | 816 | const auto axis_x = static_cast<u32>(params.Get("axis_x", 0)); |
| 812 | const Input::AnalogProperties properties_x = { | 817 | const Common::Input::AnalogProperties properties_x = { |
| 813 | .deadzone = deadzone, | 818 | .deadzone = deadzone, |
| 814 | .range = range, | 819 | .range = range, |
| 815 | .threshold = threshold, | 820 | .threshold = threshold, |
| @@ -818,7 +823,7 @@ std::unique_ptr<Input::InputDevice> InputFactory::CreateTouchDevice( | |||
| 818 | }; | 823 | }; |
| 819 | 824 | ||
| 820 | const auto axis_y = static_cast<u32>(params.Get("axis_y", 1)); | 825 | const auto axis_y = static_cast<u32>(params.Get("axis_y", 1)); |
| 821 | const Input::AnalogProperties properties_y = { | 826 | const Common::Input::AnalogProperties properties_y = { |
| 822 | .deadzone = deadzone, | 827 | .deadzone = deadzone, |
| 823 | .range = range, | 828 | .range = range, |
| 824 | .threshold = threshold, | 829 | .threshold = threshold, |
| @@ -833,7 +838,7 @@ std::unique_ptr<Input::InputDevice> InputFactory::CreateTouchDevice( | |||
| 833 | axis_y, properties_x, properties_y, input_engine.get()); | 838 | axis_y, properties_x, properties_y, input_engine.get()); |
| 834 | } | 839 | } |
| 835 | 840 | ||
| 836 | std::unique_ptr<Input::InputDevice> InputFactory::CreateBatteryDevice( | 841 | std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateBatteryDevice( |
| 837 | const Common::ParamPackage& params) { | 842 | const Common::ParamPackage& params) { |
| 838 | const PadIdentifier identifier = { | 843 | const PadIdentifier identifier = { |
| 839 | .guid = Common::UUID{params.Get("guid", "")}, | 844 | .guid = Common::UUID{params.Get("guid", "")}, |
| @@ -845,7 +850,8 @@ std::unique_ptr<Input::InputDevice> InputFactory::CreateBatteryDevice( | |||
| 845 | return std::make_unique<InputFromBattery>(identifier, input_engine.get()); | 850 | return std::make_unique<InputFromBattery>(identifier, input_engine.get()); |
| 846 | } | 851 | } |
| 847 | 852 | ||
| 848 | std::unique_ptr<Input::InputDevice> InputFactory::CreateMotionDevice(Common::ParamPackage params) { | 853 | std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateMotionDevice( |
| 854 | Common::ParamPackage params) { | ||
| 849 | const PadIdentifier identifier = { | 855 | const PadIdentifier identifier = { |
| 850 | .guid = Common::UUID{params.Get("guid", "")}, | 856 | .guid = Common::UUID{params.Get("guid", "")}, |
| 851 | .port = static_cast<std::size_t>(params.Get("port", 0)), | 857 | .port = static_cast<std::size_t>(params.Get("port", 0)), |
| @@ -864,7 +870,7 @@ std::unique_ptr<Input::InputDevice> InputFactory::CreateMotionDevice(Common::Par | |||
| 864 | const auto threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f); | 870 | const auto threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f); |
| 865 | 871 | ||
| 866 | const auto axis_x = static_cast<u32>(params.Get("axis_x", 0)); | 872 | const auto axis_x = static_cast<u32>(params.Get("axis_x", 0)); |
| 867 | const Input::AnalogProperties properties_x = { | 873 | const Common::Input::AnalogProperties properties_x = { |
| 868 | .deadzone = deadzone, | 874 | .deadzone = deadzone, |
| 869 | .range = range, | 875 | .range = range, |
| 870 | .threshold = threshold, | 876 | .threshold = threshold, |
| @@ -873,7 +879,7 @@ std::unique_ptr<Input::InputDevice> InputFactory::CreateMotionDevice(Common::Par | |||
| 873 | }; | 879 | }; |
| 874 | 880 | ||
| 875 | const auto axis_y = static_cast<u32>(params.Get("axis_y", 1)); | 881 | const auto axis_y = static_cast<u32>(params.Get("axis_y", 1)); |
| 876 | const Input::AnalogProperties properties_y = { | 882 | const Common::Input::AnalogProperties properties_y = { |
| 877 | .deadzone = deadzone, | 883 | .deadzone = deadzone, |
| 878 | .range = range, | 884 | .range = range, |
| 879 | .threshold = threshold, | 885 | .threshold = threshold, |
| @@ -882,7 +888,7 @@ std::unique_ptr<Input::InputDevice> InputFactory::CreateMotionDevice(Common::Par | |||
| 882 | }; | 888 | }; |
| 883 | 889 | ||
| 884 | const auto axis_z = static_cast<u32>(params.Get("axis_z", 1)); | 890 | const auto axis_z = static_cast<u32>(params.Get("axis_z", 1)); |
| 885 | const Input::AnalogProperties properties_z = { | 891 | const Common::Input::AnalogProperties properties_z = { |
| 886 | .deadzone = deadzone, | 892 | .deadzone = deadzone, |
| 887 | .range = range, | 893 | .range = range, |
| 888 | .threshold = threshold, | 894 | .threshold = threshold, |
| @@ -900,7 +906,8 @@ std::unique_ptr<Input::InputDevice> InputFactory::CreateMotionDevice(Common::Par | |||
| 900 | InputFactory::InputFactory(std::shared_ptr<InputEngine> input_engine_) | 906 | InputFactory::InputFactory(std::shared_ptr<InputEngine> input_engine_) |
| 901 | : input_engine(std::move(input_engine_)) {} | 907 | : input_engine(std::move(input_engine_)) {} |
| 902 | 908 | ||
| 903 | std::unique_ptr<Input::InputDevice> InputFactory::Create(const Common::ParamPackage& params) { | 909 | std::unique_ptr<Common::Input::InputDevice> InputFactory::Create( |
| 910 | const Common::ParamPackage& params) { | ||
| 904 | if (params.Has("battery")) { | 911 | if (params.Has("battery")) { |
| 905 | return CreateBatteryDevice(params); | 912 | return CreateBatteryDevice(params); |
| 906 | } | 913 | } |
| @@ -935,7 +942,8 @@ std::unique_ptr<Input::InputDevice> InputFactory::Create(const Common::ParamPack | |||
| 935 | OutputFactory::OutputFactory(std::shared_ptr<InputEngine> input_engine_) | 942 | OutputFactory::OutputFactory(std::shared_ptr<InputEngine> input_engine_) |
| 936 | : input_engine(std::move(input_engine_)) {} | 943 | : input_engine(std::move(input_engine_)) {} |
| 937 | 944 | ||
| 938 | std::unique_ptr<Input::OutputDevice> OutputFactory::Create(const Common::ParamPackage& params) { | 945 | std::unique_ptr<Common::Input::OutputDevice> OutputFactory::Create( |
| 946 | const Common::ParamPackage& params) { | ||
| 939 | const PadIdentifier identifier = { | 947 | const PadIdentifier identifier = { |
| 940 | .guid = Common::UUID{params.Get("guid", "")}, | 948 | .guid = Common::UUID{params.Get("guid", "")}, |
| 941 | .port = static_cast<std::size_t>(params.Get("port", 0)), | 949 | .port = static_cast<std::size_t>(params.Get("port", 0)), |