diff options
| author | 2020-11-17 22:16:29 -0600 | |
|---|---|---|
| committer | 2020-11-25 23:44:41 -0600 | |
| commit | 2c2b586d86d71bd6c134c32d27b155615230222e (patch) | |
| tree | 8344f77a6a09879bc419dc62cfc3a10ad5632d82 /src/input_common/udp/udp.cpp | |
| parent | Merge pull request #4976 from comex/poll-events (diff) | |
| download | yuzu-2c2b586d86d71bd6c134c32d27b155615230222e.tar.gz yuzu-2c2b586d86d71bd6c134c32d27b155615230222e.tar.xz yuzu-2c2b586d86d71bd6c134c32d27b155615230222e.zip | |
Add multiple udp server support
Diffstat (limited to 'src/input_common/udp/udp.cpp')
| -rw-r--r-- | src/input_common/udp/udp.cpp | 64 |
1 files changed, 30 insertions, 34 deletions
diff --git a/src/input_common/udp/udp.cpp b/src/input_common/udp/udp.cpp index 71a76a7aa..8686a059c 100644 --- a/src/input_common/udp/udp.cpp +++ b/src/input_common/udp/udp.cpp | |||
| @@ -13,17 +13,17 @@ namespace InputCommon { | |||
| 13 | 13 | ||
| 14 | class UDPMotion final : public Input::MotionDevice { | 14 | class UDPMotion final : public Input::MotionDevice { |
| 15 | public: | 15 | public: |
| 16 | explicit UDPMotion(std::string ip_, int port_, u32 pad_, CemuhookUDP::Client* client_) | 16 | explicit UDPMotion(std::string ip_, u16 port_, u16 pad_, CemuhookUDP::Client* client_) |
| 17 | : ip(std::move(ip_)), port(port_), pad(pad_), client(client_) {} | 17 | : ip(std::move(ip_)), port(port_), pad(pad_), client(client_) {} |
| 18 | 18 | ||
| 19 | Input::MotionStatus GetStatus() const override { | 19 | Input::MotionStatus GetStatus() const override { |
| 20 | return client->GetPadState(pad).motion_status; | 20 | return client->GetPadState(ip, port, pad).motion_status; |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | private: | 23 | private: |
| 24 | const std::string ip; | 24 | const std::string ip; |
| 25 | const int port; | 25 | const u16 port; |
| 26 | const u32 pad; | 26 | const u16 pad; |
| 27 | CemuhookUDP::Client* client; | 27 | CemuhookUDP::Client* client; |
| 28 | mutable std::mutex mutex; | 28 | mutable std::mutex mutex; |
| 29 | }; | 29 | }; |
| @@ -39,8 +39,8 @@ UDPMotionFactory::UDPMotionFactory(std::shared_ptr<CemuhookUDP::Client> client_) | |||
| 39 | */ | 39 | */ |
| 40 | std::unique_ptr<Input::MotionDevice> UDPMotionFactory::Create(const Common::ParamPackage& params) { | 40 | std::unique_ptr<Input::MotionDevice> UDPMotionFactory::Create(const Common::ParamPackage& params) { |
| 41 | auto ip = params.Get("ip", "127.0.0.1"); | 41 | auto ip = params.Get("ip", "127.0.0.1"); |
| 42 | const auto port = params.Get("port", 26760); | 42 | const auto port = static_cast<u16>(params.Get("port", 26760)); |
| 43 | const auto pad = static_cast<u32>(params.Get("pad_index", 0)); | 43 | const auto pad = static_cast<u16>(params.Get("pad_index", 0)); |
| 44 | 44 | ||
| 45 | return std::make_unique<UDPMotion>(std::move(ip), port, pad, client.get()); | 45 | return std::make_unique<UDPMotion>(std::move(ip), port, pad, client.get()); |
| 46 | } | 46 | } |
| @@ -59,35 +59,33 @@ Common::ParamPackage UDPMotionFactory::GetNextInput() { | |||
| 59 | Common::ParamPackage params; | 59 | Common::ParamPackage params; |
| 60 | CemuhookUDP::UDPPadStatus pad; | 60 | CemuhookUDP::UDPPadStatus pad; |
| 61 | auto& queue = client->GetPadQueue(); | 61 | auto& queue = client->GetPadQueue(); |
| 62 | for (std::size_t pad_number = 0; pad_number < queue.size(); ++pad_number) { | 62 | while (queue.Pop(pad)) { |
| 63 | while (queue[pad_number].Pop(pad)) { | 63 | if (pad.motion == CemuhookUDP::PadMotion::Undefined || std::abs(pad.motion_value) < 1) { |
| 64 | if (pad.motion == CemuhookUDP::PadMotion::Undefined || std::abs(pad.motion_value) < 1) { | 64 | continue; |
| 65 | continue; | ||
| 66 | } | ||
| 67 | params.Set("engine", "cemuhookudp"); | ||
| 68 | params.Set("ip", "127.0.0.1"); | ||
| 69 | params.Set("port", 26760); | ||
| 70 | params.Set("pad_index", static_cast<int>(pad_number)); | ||
| 71 | params.Set("motion", static_cast<u16>(pad.motion)); | ||
| 72 | return params; | ||
| 73 | } | 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; | ||
| 74 | } | 72 | } |
| 75 | return params; | 73 | return params; |
| 76 | } | 74 | } |
| 77 | 75 | ||
| 78 | class UDPTouch final : public Input::TouchDevice { | 76 | class UDPTouch final : public Input::TouchDevice { |
| 79 | public: | 77 | public: |
| 80 | explicit UDPTouch(std::string ip_, int port_, u32 pad_, CemuhookUDP::Client* client_) | 78 | explicit UDPTouch(std::string ip_, u16 port_, u16 pad_, CemuhookUDP::Client* client_) |
| 81 | : ip(std::move(ip_)), port(port_), pad(pad_), client(client_) {} | 79 | : ip(std::move(ip_)), port(port_), pad(pad_), client(client_) {} |
| 82 | 80 | ||
| 83 | std::tuple<float, float, bool> GetStatus() const override { | 81 | std::tuple<float, float, bool> GetStatus() const override { |
| 84 | return client->GetPadState(pad).touch_status; | 82 | return client->GetPadState(ip, port, pad).touch_status; |
| 85 | } | 83 | } |
| 86 | 84 | ||
| 87 | private: | 85 | private: |
| 88 | const std::string ip; | 86 | const std::string ip; |
| 89 | const int port; | 87 | const u16 port; |
| 90 | const u32 pad; | 88 | const u16 pad; |
| 91 | CemuhookUDP::Client* client; | 89 | CemuhookUDP::Client* client; |
| 92 | mutable std::mutex mutex; | 90 | mutable std::mutex mutex; |
| 93 | }; | 91 | }; |
| @@ -103,8 +101,8 @@ UDPTouchFactory::UDPTouchFactory(std::shared_ptr<CemuhookUDP::Client> client_) | |||
| 103 | */ | 101 | */ |
| 104 | std::unique_ptr<Input::TouchDevice> UDPTouchFactory::Create(const Common::ParamPackage& params) { | 102 | std::unique_ptr<Input::TouchDevice> UDPTouchFactory::Create(const Common::ParamPackage& params) { |
| 105 | auto ip = params.Get("ip", "127.0.0.1"); | 103 | auto ip = params.Get("ip", "127.0.0.1"); |
| 106 | const auto port = params.Get("port", 26760); | 104 | const auto port = static_cast<u16>(params.Get("port", 26760)); |
| 107 | const auto pad = static_cast<u32>(params.Get("pad_index", 0)); | 105 | const auto pad = static_cast<u16>(params.Get("pad_index", 0)); |
| 108 | 106 | ||
| 109 | return std::make_unique<UDPTouch>(std::move(ip), port, pad, client.get()); | 107 | return std::make_unique<UDPTouch>(std::move(ip), port, pad, client.get()); |
| 110 | } | 108 | } |
| @@ -123,18 +121,16 @@ Common::ParamPackage UDPTouchFactory::GetNextInput() { | |||
| 123 | Common::ParamPackage params; | 121 | Common::ParamPackage params; |
| 124 | CemuhookUDP::UDPPadStatus pad; | 122 | CemuhookUDP::UDPPadStatus pad; |
| 125 | auto& queue = client->GetPadQueue(); | 123 | auto& queue = client->GetPadQueue(); |
| 126 | for (std::size_t pad_number = 0; pad_number < queue.size(); ++pad_number) { | 124 | while (queue.Pop(pad)) { |
| 127 | while (queue[pad_number].Pop(pad)) { | 125 | if (pad.touch == CemuhookUDP::PadTouch::Undefined) { |
| 128 | if (pad.touch == CemuhookUDP::PadTouch::Undefined) { | 126 | continue; |
| 129 | continue; | ||
| 130 | } | ||
| 131 | params.Set("engine", "cemuhookudp"); | ||
| 132 | params.Set("ip", "127.0.0.1"); | ||
| 133 | params.Set("port", 26760); | ||
| 134 | params.Set("pad_index", static_cast<int>(pad_number)); | ||
| 135 | params.Set("touch", static_cast<u16>(pad.touch)); | ||
| 136 | return params; | ||
| 137 | } | 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; | ||
| 138 | } | 134 | } |
| 139 | return params; | 135 | return params; |
| 140 | } | 136 | } |