diff options
author | german77 <juangerman-13@hotmail.com> | 2021-03-30 19:42:05 +0200 |
---|---|---|
committer | german77 <juangerman-13@hotmail.com> | 2021-03-31 05:17:08 +0200 |
commit | bb3dce9363c5e805b362b556fa168ffef2c0aca8 (patch) | |
tree | 07621626ea79c084a48631271b3eb43a829af2f2 /src/input_common/udp/client.h | |
parent | Merge pull request #5927 from ameerj/astc-compute (diff) | |
download | yuzu-bb3dce9363c5e805b362b556fa168ffef2c0aca8.tar yuzu-bb3dce9363c5e805b362b556fa168ffef2c0aca8.tar.gz yuzu-bb3dce9363c5e805b362b556fa168ffef2c0aca8.tar.bz2 yuzu-bb3dce9363c5e805b362b556fa168ffef2c0aca8.tar.lz yuzu-bb3dce9363c5e805b362b556fa168ffef2c0aca8.tar.xz yuzu-bb3dce9363c5e805b362b556fa168ffef2c0aca8.tar.zst yuzu-bb3dce9363c5e805b362b556fa168ffef2c0aca8.zip |
Diffstat (limited to 'src/input_common/udp/client.h')
-rw-r--r-- | src/input_common/udp/client.h | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/src/input_common/udp/client.h b/src/input_common/udp/client.h index e9e438e88..a11ea3068 100644 --- a/src/input_common/udp/client.h +++ b/src/input_common/udp/client.h @@ -84,7 +84,7 @@ public: std::vector<Common::ParamPackage> GetInputDevices() const; - bool DeviceConnected(std::size_t client) const; + bool DeviceConnected(std::size_t pad) const; void ReloadSockets(); Common::SPSCQueue<UDPPadStatus>& GetPadQueue(); @@ -97,38 +97,40 @@ public: const Input::TouchStatus& GetTouchState() const; private: - struct ClientData { - ClientData(); - ~ClientData(); - - std::string host{"127.0.0.1"}; - u16 port{26760}; + struct PadData { std::size_t pad_index{}; - std::unique_ptr<Socket> socket; + bool connected{}; DeviceStatus status; - std::thread thread; 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::steady_clock> last_motion_update; + std::chrono::time_point<std::chrono::steady_clock> last_update; + }; + + struct ClientConnection { + ClientConnection(); + ~ClientConnection(); + std::string host{"127.0.0.1"}; + u16 port{26760}; + s8 active{-1}; + std::unique_ptr<Socket> socket; + std::thread thread; }; // 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; + std::size_t GetClientNumber(std::string_view host, u16 port) const; void OnVersion(Response::Version); void OnPortInfo(Response::PortInfo); 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); - void UpdateYuzuSettings(std::size_t client, const Common::Vec3<float>& acc, - const Common::Vec3<float>& gyro); + void StartCommunication(std::size_t client, const std::string& host, u16 port); + void UpdateYuzuSettings(std::size_t client, std::size_t pad_index, + const Common::Vec3<float>& acc, const Common::Vec3<float>& gyro); // Returns an unused finger id, if there is no fingers available std::nullopt will be // returned @@ -140,10 +142,12 @@ private: bool configuring = false; // Allocate clients for 8 udp servers - static constexpr std::size_t MAX_UDP_CLIENTS = 4 * 8; + static constexpr std::size_t MAX_UDP_CLIENTS = 8; + static constexpr std::size_t PADS_PER_CLIENT = 4; // Each client can have up 2 touch inputs static constexpr std::size_t MAX_TOUCH_FINGERS = MAX_UDP_CLIENTS * 2; - std::array<ClientData, MAX_UDP_CLIENTS> clients{}; + std::array<PadData, MAX_UDP_CLIENTS * PADS_PER_CLIENT> pads{}; + std::array<ClientConnection, MAX_UDP_CLIENTS> clients{}; Common::SPSCQueue<UDPPadStatus> pad_queue{}; Input::TouchStatus touch_status{}; std::array<std::size_t, MAX_TOUCH_FINGERS> finger_id{}; @@ -164,7 +168,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, std::size_t pad_index, + explicit CalibrationConfigurationJob(const std::string& host, u16 port, std::function<void(Status)> status_callback, std::function<void(u16, u16, u16, u16)> data_callback); ~CalibrationConfigurationJob(); @@ -174,7 +178,7 @@ private: Common::Event complete_event; }; -void TestCommunication(const std::string& host, u16 port, std::size_t pad_index, +void TestCommunication(const std::string& host, u16 port, const std::function<void()>& success_callback, const std::function<void()>& failure_callback); |