mirror of
https://git.suyu.dev/suyu/suyu
synced 2024-12-24 18:32:49 -06:00
Merge pull request #3374 from lioncash/udp
input_common/udp: Minor changes
This commit is contained in:
commit
2cd51fc9fd
6 changed files with 16 additions and 18 deletions
|
@ -41,6 +41,7 @@ void Shutdown() {
|
||||||
Input::UnregisterFactory<Input::MotionDevice>("motion_emu");
|
Input::UnregisterFactory<Input::MotionDevice>("motion_emu");
|
||||||
motion_emu.reset();
|
motion_emu.reset();
|
||||||
sdl.reset();
|
sdl.reset();
|
||||||
|
udp.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
Keyboard* GetKeyboard() {
|
Keyboard* GetKeyboard() {
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
#include "input_common/udp/client.h"
|
#include "input_common/udp/client.h"
|
||||||
#include "input_common/udp/protocol.h"
|
#include "input_common/udp/protocol.h"
|
||||||
|
|
||||||
using boost::asio::ip::address_v4;
|
|
||||||
using boost::asio::ip::udp;
|
using boost::asio::ip::udp;
|
||||||
|
|
||||||
namespace InputCommon::CemuhookUDP {
|
namespace InputCommon::CemuhookUDP {
|
||||||
|
@ -31,10 +30,10 @@ public:
|
||||||
|
|
||||||
explicit Socket(const std::string& host, u16 port, u8 pad_index, u32 client_id,
|
explicit Socket(const std::string& host, u16 port, u8 pad_index, u32 client_id,
|
||||||
SocketCallback callback)
|
SocketCallback callback)
|
||||||
: client_id(client_id), timer(io_service),
|
: callback(std::move(callback)), timer(io_service),
|
||||||
send_endpoint(udp::endpoint(address_v4::from_string(host), port)),
|
socket(io_service, udp::endpoint(udp::v4(), 0)), client_id(client_id),
|
||||||
socket(io_service, udp::endpoint(udp::v4(), 0)), pad_index(pad_index),
|
pad_index(pad_index),
|
||||||
callback(std::move(callback)) {}
|
send_endpoint(udp::endpoint(boost::asio::ip::make_address_v4(host), port)) {}
|
||||||
|
|
||||||
void Stop() {
|
void Stop() {
|
||||||
io_service.stop();
|
io_service.stop();
|
||||||
|
@ -126,7 +125,7 @@ static void SocketLoop(Socket* socket) {
|
||||||
|
|
||||||
Client::Client(std::shared_ptr<DeviceStatus> status, const std::string& host, u16 port,
|
Client::Client(std::shared_ptr<DeviceStatus> status, const std::string& host, u16 port,
|
||||||
u8 pad_index, u32 client_id)
|
u8 pad_index, u32 client_id)
|
||||||
: status(status) {
|
: status(std::move(status)) {
|
||||||
StartCommunication(host, port, pad_index, client_id);
|
StartCommunication(host, port, pad_index, client_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,7 +206,7 @@ void TestCommunication(const std::string& host, u16 port, u8 pad_index, u32 clie
|
||||||
Common::Event success_event;
|
Common::Event success_event;
|
||||||
SocketCallback callback{[](Response::Version version) {}, [](Response::PortInfo info) {},
|
SocketCallback callback{[](Response::Version version) {}, [](Response::PortInfo info) {},
|
||||||
[&](Response::PadData data) { success_event.Set(); }};
|
[&](Response::PadData data) { success_event.Set(); }};
|
||||||
Socket socket{host, port, pad_index, client_id, callback};
|
Socket socket{host, port, pad_index, client_id, std::move(callback)};
|
||||||
std::thread worker_thread{SocketLoop, &socket};
|
std::thread worker_thread{SocketLoop, &socket};
|
||||||
bool result = success_event.WaitFor(std::chrono::seconds(8));
|
bool result = success_event.WaitFor(std::chrono::seconds(8));
|
||||||
socket.Stop();
|
socket.Stop();
|
||||||
|
@ -267,7 +266,7 @@ CalibrationConfigurationJob::CalibrationConfigurationJob(
|
||||||
complete_event.Set();
|
complete_event.Set();
|
||||||
}
|
}
|
||||||
}};
|
}};
|
||||||
Socket socket{host, port, pad_index, client_id, callback};
|
Socket socket{host, port, pad_index, client_id, std::move(callback)};
|
||||||
std::thread worker_thread{SocketLoop, &socket};
|
std::thread worker_thread{SocketLoop, &socket};
|
||||||
complete_event.Wait();
|
complete_event.Wait();
|
||||||
socket.Stop();
|
socket.Stop();
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <vector>
|
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/thread.h"
|
#include "common/thread.h"
|
||||||
#include "common/vector_math.h"
|
#include "common/vector_math.h"
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <vector>
|
|
||||||
#include <boost/crc.hpp>
|
#include <boost/crc.hpp>
|
||||||
#include "common/bit_field.h"
|
#include "common/bit_field.h"
|
||||||
#include "common/swap.h"
|
#include "common/swap.h"
|
||||||
|
|
|
@ -2,7 +2,9 @@
|
||||||
// Licensed under GPLv2 or any later version
|
// Licensed under GPLv2 or any later version
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
#include "common/logging/log.h"
|
#include <mutex>
|
||||||
|
#include <tuple>
|
||||||
|
|
||||||
#include "common/param_package.h"
|
#include "common/param_package.h"
|
||||||
#include "core/frontend/input.h"
|
#include "core/frontend/input.h"
|
||||||
#include "core/settings.h"
|
#include "core/settings.h"
|
||||||
|
@ -14,7 +16,7 @@ namespace InputCommon::CemuhookUDP {
|
||||||
class UDPTouchDevice final : public Input::TouchDevice {
|
class UDPTouchDevice final : public Input::TouchDevice {
|
||||||
public:
|
public:
|
||||||
explicit UDPTouchDevice(std::shared_ptr<DeviceStatus> status_) : status(std::move(status_)) {}
|
explicit UDPTouchDevice(std::shared_ptr<DeviceStatus> status_) : status(std::move(status_)) {}
|
||||||
std::tuple<float, float, bool> GetStatus() const {
|
std::tuple<float, float, bool> GetStatus() const override {
|
||||||
std::lock_guard guard(status->update_mutex);
|
std::lock_guard guard(status->update_mutex);
|
||||||
return status->touch_status;
|
return status->touch_status;
|
||||||
}
|
}
|
||||||
|
@ -26,7 +28,7 @@ private:
|
||||||
class UDPMotionDevice final : public Input::MotionDevice {
|
class UDPMotionDevice final : public Input::MotionDevice {
|
||||||
public:
|
public:
|
||||||
explicit UDPMotionDevice(std::shared_ptr<DeviceStatus> status_) : status(std::move(status_)) {}
|
explicit UDPMotionDevice(std::shared_ptr<DeviceStatus> status_) : status(std::move(status_)) {}
|
||||||
std::tuple<Common::Vec3<float>, Common::Vec3<float>> GetStatus() const {
|
std::tuple<Common::Vec3<float>, Common::Vec3<float>> GetStatus() const override {
|
||||||
std::lock_guard guard(status->update_mutex);
|
std::lock_guard guard(status->update_mutex);
|
||||||
return status->motion_status;
|
return status->motion_status;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,15 +2,13 @@
|
||||||
// Licensed under GPLv2 or any later version
|
// Licensed under GPLv2 or any later version
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <unordered_map>
|
|
||||||
#include "input_common/main.h"
|
|
||||||
#include "input_common/udp/client.h"
|
|
||||||
|
|
||||||
namespace InputCommon::CemuhookUDP {
|
namespace InputCommon::CemuhookUDP {
|
||||||
|
|
||||||
class UDPTouchDevice;
|
class Client;
|
||||||
class UDPMotionDevice;
|
|
||||||
|
|
||||||
class State {
|
class State {
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in a new issue