diff options
| author | 2021-01-10 22:09:56 -0700 | |
|---|---|---|
| committer | 2021-01-10 22:09:56 -0700 | |
| commit | 7a3c884e39fccfbb498b855080bffabc9ce2e7f1 (patch) | |
| tree | 5056f9406dec188439cb0deb87603498243a9412 /src/input_common/udp/udp.cpp | |
| parent | More forgetting... duh (diff) | |
| parent | Merge pull request #5229 from Morph1984/fullscreen-opt (diff) | |
| download | yuzu-7a3c884e39fccfbb498b855080bffabc9ce2e7f1.tar.gz yuzu-7a3c884e39fccfbb498b855080bffabc9ce2e7f1.tar.xz yuzu-7a3c884e39fccfbb498b855080bffabc9ce2e7f1.zip | |
Merge remote-tracking branch 'upstream/master' into int-flags
Diffstat (limited to 'src/input_common/udp/udp.cpp')
| -rw-r--r-- | src/input_common/udp/udp.cpp | 84 |
1 files changed, 39 insertions, 45 deletions
diff --git a/src/input_common/udp/udp.cpp b/src/input_common/udp/udp.cpp index eba077a36..c5da27a38 100644 --- a/src/input_common/udp/udp.cpp +++ b/src/input_common/udp/udp.cpp | |||
| @@ -2,8 +2,6 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <atomic> | ||
| 6 | #include <list> | ||
| 7 | #include <mutex> | 5 | #include <mutex> |
| 8 | #include <utility> | 6 | #include <utility> |
| 9 | #include "common/assert.h" | 7 | #include "common/assert.h" |
| @@ -15,36 +13,36 @@ namespace InputCommon { | |||
| 15 | 13 | ||
| 16 | class UDPMotion final : public Input::MotionDevice { | 14 | class UDPMotion final : public Input::MotionDevice { |
| 17 | public: | 15 | public: |
| 18 | UDPMotion(std::string ip_, int port_, int pad_, CemuhookUDP::Client* client_) | 16 | explicit UDPMotion(std::string ip_, u16 port_, u16 pad_, CemuhookUDP::Client* client_) |
| 19 | : ip(ip_), port(port_), pad(pad_), client(client_) {} | 17 | : ip(std::move(ip_)), port(port_), pad(pad_), client(client_) {} |
| 20 | 18 | ||
| 21 | Input::MotionStatus GetStatus() const override { | 19 | Input::MotionStatus GetStatus() const override { |
| 22 | return client->GetPadState(pad).motion_status; | 20 | return client->GetPadState(ip, port, pad).motion_status; |
| 23 | } | 21 | } |
| 24 | 22 | ||
| 25 | private: | 23 | private: |
| 26 | const std::string ip; | 24 | const std::string ip; |
| 27 | const int port; | 25 | const u16 port; |
| 28 | const int pad; | 26 | const u16 pad; |
| 29 | CemuhookUDP::Client* client; | 27 | CemuhookUDP::Client* client; |
| 30 | mutable std::mutex mutex; | 28 | mutable std::mutex mutex; |
| 31 | }; | 29 | }; |
| 32 | 30 | ||
| 33 | /// A motion device factory that creates motion devices from JC Adapter | 31 | /// A motion device factory that creates motion devices from a UDP client |
| 34 | UDPMotionFactory::UDPMotionFactory(std::shared_ptr<CemuhookUDP::Client> client_) | 32 | UDPMotionFactory::UDPMotionFactory(std::shared_ptr<CemuhookUDP::Client> client_) |
| 35 | : client(std::move(client_)) {} | 33 | : client(std::move(client_)) {} |
| 36 | 34 | ||
| 37 | /** | 35 | /** |
| 38 | * Creates motion device | 36 | * Creates motion device |
| 39 | * @param params contains parameters for creating the device: | 37 | * @param params contains parameters for creating the device: |
| 40 | * - "port": the nth jcpad on the adapter | 38 | * - "port": the UDP port number |
| 41 | */ | 39 | */ |
| 42 | std::unique_ptr<Input::MotionDevice> UDPMotionFactory::Create(const Common::ParamPackage& params) { | 40 | std::unique_ptr<Input::MotionDevice> UDPMotionFactory::Create(const Common::ParamPackage& params) { |
| 43 | const std::string ip = params.Get("ip", "127.0.0.1"); | 41 | auto ip = params.Get("ip", "127.0.0.1"); |
| 44 | const int port = params.Get("port", 26760); | 42 | const auto port = static_cast<u16>(params.Get("port", 26760)); |
| 45 | const int pad = params.Get("pad_index", 0); | 43 | const auto pad = static_cast<u16>(params.Get("pad_index", 0)); |
| 46 | 44 | ||
| 47 | return std::make_unique<UDPMotion>(ip, port, pad, client.get()); | 45 | return std::make_unique<UDPMotion>(std::move(ip), port, pad, client.get()); |
| 48 | } | 46 | } |
| 49 | 47 | ||
| 50 | void UDPMotionFactory::BeginConfiguration() { | 48 | void UDPMotionFactory::BeginConfiguration() { |
| @@ -61,54 +59,52 @@ Common::ParamPackage UDPMotionFactory::GetNextInput() { | |||
| 61 | Common::ParamPackage params; | 59 | Common::ParamPackage params; |
| 62 | CemuhookUDP::UDPPadStatus pad; | 60 | CemuhookUDP::UDPPadStatus pad; |
| 63 | auto& queue = client->GetPadQueue(); | 61 | auto& queue = client->GetPadQueue(); |
| 64 | for (std::size_t pad_number = 0; pad_number < queue.size(); ++pad_number) { | 62 | while (queue.Pop(pad)) { |
| 65 | while (queue[pad_number].Pop(pad)) { | 63 | if (pad.motion == CemuhookUDP::PadMotion::Undefined || std::abs(pad.motion_value) < 1) { |
| 66 | if (pad.motion == CemuhookUDP::PadMotion::Undefined || std::abs(pad.motion_value) < 1) { | 64 | continue; |
| 67 | continue; | ||
| 68 | } | ||
| 69 | params.Set("engine", "cemuhookudp"); | ||
| 70 | params.Set("ip", "127.0.0.1"); | ||
| 71 | params.Set("port", 26760); | ||
| 72 | params.Set("pad_index", static_cast<int>(pad_number)); | ||
| 73 | params.Set("motion", static_cast<u16>(pad.motion)); | ||
| 74 | return params; | ||
| 75 | } | 65 | } |
| 66 | params.Set("engine", "cemuhookudp"); | ||
| 67 | params.Set("ip", pad.host); | ||
| 68 | params.Set("port", static_cast<u16>(pad.port)); | ||
| 69 | params.Set("pad_index", static_cast<u16>(pad.pad_index)); | ||
| 70 | params.Set("motion", static_cast<u16>(pad.motion)); | ||
| 71 | return params; | ||
| 76 | } | 72 | } |
| 77 | return params; | 73 | return params; |
| 78 | } | 74 | } |
| 79 | 75 | ||
| 80 | class UDPTouch final : public Input::TouchDevice { | 76 | class UDPTouch final : public Input::TouchDevice { |
| 81 | public: | 77 | public: |
| 82 | UDPTouch(std::string ip_, int port_, int pad_, CemuhookUDP::Client* client_) | 78 | explicit UDPTouch(std::string ip_, u16 port_, u16 pad_, CemuhookUDP::Client* client_) |
| 83 | : ip(std::move(ip_)), port(port_), pad(pad_), client(client_) {} | 79 | : ip(std::move(ip_)), port(port_), pad(pad_), client(client_) {} |
| 84 | 80 | ||
| 85 | std::tuple<float, float, bool> GetStatus() const override { | 81 | std::tuple<float, float, bool> GetStatus() const override { |
| 86 | return client->GetPadState(pad).touch_status; | 82 | return client->GetPadState(ip, port, pad).touch_status; |
| 87 | } | 83 | } |
| 88 | 84 | ||
| 89 | private: | 85 | private: |
| 90 | const std::string ip; | 86 | const std::string ip; |
| 91 | const int port; | 87 | const u16 port; |
| 92 | const int pad; | 88 | const u16 pad; |
| 93 | CemuhookUDP::Client* client; | 89 | CemuhookUDP::Client* client; |
| 94 | mutable std::mutex mutex; | 90 | mutable std::mutex mutex; |
| 95 | }; | 91 | }; |
| 96 | 92 | ||
| 97 | /// A motion device factory that creates motion devices from JC Adapter | 93 | /// A motion device factory that creates motion devices from a UDP client |
| 98 | UDPTouchFactory::UDPTouchFactory(std::shared_ptr<CemuhookUDP::Client> client_) | 94 | UDPTouchFactory::UDPTouchFactory(std::shared_ptr<CemuhookUDP::Client> client_) |
| 99 | : client(std::move(client_)) {} | 95 | : client(std::move(client_)) {} |
| 100 | 96 | ||
| 101 | /** | 97 | /** |
| 102 | * Creates motion device | 98 | * Creates motion device |
| 103 | * @param params contains parameters for creating the device: | 99 | * @param params contains parameters for creating the device: |
| 104 | * - "port": the nth jcpad on the adapter | 100 | * - "port": the UDP port number |
| 105 | */ | 101 | */ |
| 106 | std::unique_ptr<Input::TouchDevice> UDPTouchFactory::Create(const Common::ParamPackage& params) { | 102 | std::unique_ptr<Input::TouchDevice> UDPTouchFactory::Create(const Common::ParamPackage& params) { |
| 107 | const std::string ip = params.Get("ip", "127.0.0.1"); | 103 | auto ip = params.Get("ip", "127.0.0.1"); |
| 108 | const int port = params.Get("port", 26760); | 104 | const auto port = static_cast<u16>(params.Get("port", 26760)); |
| 109 | const int pad = params.Get("pad_index", 0); | 105 | const auto pad = static_cast<u16>(params.Get("pad_index", 0)); |
| 110 | 106 | ||
| 111 | return std::make_unique<UDPTouch>(ip, port, pad, client.get()); | 107 | return std::make_unique<UDPTouch>(std::move(ip), port, pad, client.get()); |
| 112 | } | 108 | } |
| 113 | 109 | ||
| 114 | void UDPTouchFactory::BeginConfiguration() { | 110 | void UDPTouchFactory::BeginConfiguration() { |
| @@ -125,18 +121,16 @@ Common::ParamPackage UDPTouchFactory::GetNextInput() { | |||
| 125 | Common::ParamPackage params; | 121 | Common::ParamPackage params; |
| 126 | CemuhookUDP::UDPPadStatus pad; | 122 | CemuhookUDP::UDPPadStatus pad; |
| 127 | auto& queue = client->GetPadQueue(); | 123 | auto& queue = client->GetPadQueue(); |
| 128 | for (std::size_t pad_number = 0; pad_number < queue.size(); ++pad_number) { | 124 | while (queue.Pop(pad)) { |
| 129 | while (queue[pad_number].Pop(pad)) { | 125 | if (pad.touch == CemuhookUDP::PadTouch::Undefined) { |
| 130 | if (pad.touch == CemuhookUDP::PadTouch::Undefined) { | 126 | continue; |
| 131 | continue; | ||
| 132 | } | ||
| 133 | params.Set("engine", "cemuhookudp"); | ||
| 134 | params.Set("ip", "127.0.0.1"); | ||
| 135 | params.Set("port", 26760); | ||
| 136 | params.Set("pad_index", static_cast<int>(pad_number)); | ||
| 137 | params.Set("touch", static_cast<u16>(pad.touch)); | ||
| 138 | return params; | ||
| 139 | } | 127 | } |
| 128 | params.Set("engine", "cemuhookudp"); | ||
| 129 | params.Set("ip", pad.host); | ||
| 130 | params.Set("port", static_cast<u16>(pad.port)); | ||
| 131 | params.Set("pad_index", static_cast<u16>(pad.pad_index)); | ||
| 132 | params.Set("touch", static_cast<u16>(pad.touch)); | ||
| 133 | return params; | ||
| 140 | } | 134 | } |
| 141 | return params; | 135 | return params; |
| 142 | } | 136 | } |