diff options
author | Levi <L3ehunin@gmail.com> | 2021-01-11 06:09:56 +0100 |
---|---|---|
committer | Levi <L3ehunin@gmail.com> | 2021-01-11 06:09:56 +0100 |
commit | 7a3c884e39fccfbb498b855080bffabc9ce2e7f1 (patch) | |
tree | 5056f9406dec188439cb0deb87603498243a9412 /src/input_common/udp/client.h | |
parent | More forgetting... duh (diff) | |
parent | Merge pull request #5229 from Morph1984/fullscreen-opt (diff) | |
download | yuzu-7a3c884e39fccfbb498b855080bffabc9ce2e7f1.tar yuzu-7a3c884e39fccfbb498b855080bffabc9ce2e7f1.tar.gz yuzu-7a3c884e39fccfbb498b855080bffabc9ce2e7f1.tar.bz2 yuzu-7a3c884e39fccfbb498b855080bffabc9ce2e7f1.tar.lz yuzu-7a3c884e39fccfbb498b855080bffabc9ce2e7f1.tar.xz yuzu-7a3c884e39fccfbb498b855080bffabc9ce2e7f1.tar.zst yuzu-7a3c884e39fccfbb498b855080bffabc9ce2e7f1.zip |
Diffstat (limited to 'src/input_common/udp/client.h')
-rw-r--r-- | src/input_common/udp/client.h | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/src/input_common/udp/client.h b/src/input_common/udp/client.h index 523dc6a7a..00c8b09f5 100644 --- a/src/input_common/udp/client.h +++ b/src/input_common/udp/client.h @@ -21,8 +21,7 @@ namespace InputCommon::CemuhookUDP { -constexpr u16 DEFAULT_PORT = 26760; -constexpr char DEFAULT_ADDR[] = "127.0.0.1"; +constexpr char DEFAULT_SRV[] = "127.0.0.1:26760"; class Socket; @@ -48,6 +47,9 @@ enum class PadTouch { }; struct UDPPadStatus { + std::string host{"127.0.0.1"}; + u16 port{26760}; + std::size_t pad_index{}; PadTouch touch{PadTouch::Undefined}; PadMotion motion{PadMotion::Undefined}; f32 motion_value{0.0f}; @@ -82,46 +84,52 @@ public: std::vector<Common::ParamPackage> GetInputDevices() const; - bool DeviceConnected(std::size_t pad) const; - void ReloadUDPClient(); - void ReloadSocket(const std::string& host = "127.0.0.1", u16 port = 26760, u8 pad_index = 0, - u32 client_id = 24872); + bool DeviceConnected(std::size_t client) const; + void ReloadSockets(); - std::array<Common::SPSCQueue<UDPPadStatus>, 4>& GetPadQueue(); - const std::array<Common::SPSCQueue<UDPPadStatus>, 4>& GetPadQueue() const; + Common::SPSCQueue<UDPPadStatus>& GetPadQueue(); + const Common::SPSCQueue<UDPPadStatus>& GetPadQueue() const; - DeviceStatus& GetPadState(std::size_t pad); - const DeviceStatus& GetPadState(std::size_t pad) const; + DeviceStatus& GetPadState(const std::string& host, u16 port, std::size_t pad); + const DeviceStatus& GetPadState(const std::string& host, u16 port, std::size_t pad) const; private: struct ClientData { + std::string host{"127.0.0.1"}; + u16 port{26760}; + std::size_t pad_index{}; std::unique_ptr<Socket> socket; DeviceStatus status; std::thread thread; - u64 packet_sequence = 0; - u8 active; + u64 packet_sequence{}; + s8 active{-1}; // Realtime values // motion is initalized with PID values for drift correction on joycons InputCommon::MotionInput motion{0.3f, 0.005f, 0.0f}; - std::chrono::time_point<std::chrono::system_clock> last_motion_update; + std::chrono::time_point<std::chrono::steady_clock> last_motion_update; }; // For shutting down, clear all data, join all threads, release usb void Reset(); + // Translates configuration to client number + std::size_t GetClientNumber(std::string_view host, u16 port, std::size_t pad) const; + void OnVersion(Response::Version); void OnPortInfo(Response::PortInfo); - void OnPadData(Response::PadData); - void StartCommunication(std::size_t client, const std::string& host, u16 port, u8 pad_index, - u32 client_id); + void OnPadData(Response::PadData, std::size_t client); + void StartCommunication(std::size_t client, const std::string& host, u16 port, + std::size_t pad_index, u32 client_id); void UpdateYuzuSettings(std::size_t client, const Common::Vec3<float>& acc, const Common::Vec3<float>& gyro, bool touch); bool configuring = false; - std::array<ClientData, 4> clients; - std::array<Common::SPSCQueue<UDPPadStatus>, 4> pad_queue; + // Allocate clients for 8 udp servers + const std::size_t max_udp_clients = 32; + std::array<ClientData, 4 * 8> clients; + Common::SPSCQueue<UDPPadStatus> pad_queue; }; /// An async job allowing configuration of the touchpad calibration. @@ -139,7 +147,7 @@ public: * @param status_callback Callback for job status updates * @param data_callback Called when calibration data is ready */ - explicit CalibrationConfigurationJob(const std::string& host, u16 port, u8 pad_index, + explicit CalibrationConfigurationJob(const std::string& host, u16 port, std::size_t pad_index, u32 client_id, std::function<void(Status)> status_callback, std::function<void(u16, u16, u16, u16)> data_callback); ~CalibrationConfigurationJob(); @@ -149,8 +157,8 @@ private: Common::Event complete_event; }; -void TestCommunication(const std::string& host, u16 port, u8 pad_index, u32 client_id, - std::function<void()> success_callback, - std::function<void()> failure_callback); +void TestCommunication(const std::string& host, u16 port, std::size_t pad_index, u32 client_id, + const std::function<void()>& success_callback, + const std::function<void()>& failure_callback); } // namespace InputCommon::CemuhookUDP |