mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-11-30 10:24:20 +01:00
std::array and const reference passing of non-trivial objects
This commit is contained in:
parent
8ccc8cb252
commit
fcc23139f6
@ -21,7 +21,7 @@ Adapter::Adapter() {
|
|||||||
StartScanThread();
|
StartScanThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
GCPadStatus Adapter::CheckStatus(int port, u8 adapter_payload[37]) {
|
GCPadStatus Adapter::CheckStatus(int port, const std::array<u8, 37>& adapter_payload) {
|
||||||
GCPadStatus pad = {};
|
GCPadStatus pad = {};
|
||||||
bool get_origin = false;
|
bool get_origin = false;
|
||||||
|
|
||||||
@ -88,7 +88,7 @@ GCPadStatus Adapter::CheckStatus(int port, u8 adapter_payload[37]) {
|
|||||||
return pad;
|
return pad;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Adapter::PadToState(GCPadStatus pad, GCState& state) {
|
void Adapter::PadToState(const GCPadStatus& pad, GCState& state) {
|
||||||
state.buttons.insert_or_assign(PAD_BUTTON_A, pad.button & PAD_BUTTON_A);
|
state.buttons.insert_or_assign(PAD_BUTTON_A, pad.button & PAD_BUTTON_A);
|
||||||
state.buttons.insert_or_assign(PAD_BUTTON_B, pad.button & PAD_BUTTON_B);
|
state.buttons.insert_or_assign(PAD_BUTTON_B, pad.button & PAD_BUTTON_B);
|
||||||
state.buttons.insert_or_assign(PAD_BUTTON_X, pad.button & PAD_BUTTON_X);
|
state.buttons.insert_or_assign(PAD_BUTTON_X, pad.button & PAD_BUTTON_X);
|
||||||
@ -112,15 +112,15 @@ void Adapter::PadToState(GCPadStatus pad, GCState& state) {
|
|||||||
void Adapter::Read() {
|
void Adapter::Read() {
|
||||||
LOG_INFO(Input, "GC Adapter Read() thread started");
|
LOG_INFO(Input, "GC Adapter Read() thread started");
|
||||||
|
|
||||||
int payload_size_in;
|
int payload_size_in, payload_size;
|
||||||
u8 adapter_payload[37];
|
std::array<u8, 37> adapter_payload;
|
||||||
|
std::array<u8, 37> controller_payload_copy;
|
||||||
|
std::array<GCPadStatus, 4> pad;
|
||||||
|
|
||||||
while (adapter_thread_running) {
|
while (adapter_thread_running) {
|
||||||
libusb_interrupt_transfer(usb_adapter_handle, input_endpoint, adapter_payload,
|
libusb_interrupt_transfer(usb_adapter_handle, input_endpoint, adapter_payload.data(),
|
||||||
sizeof(adapter_payload), &payload_size_in, 32);
|
sizeof(adapter_payload), &payload_size_in, 32);
|
||||||
|
payload_size = 0;
|
||||||
int payload_size = 0;
|
|
||||||
u8 controller_payload_copy[37];
|
|
||||||
|
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lk(s_mutex);
|
std::lock_guard<std::mutex> lk(s_mutex);
|
||||||
std::copy(std::begin(adapter_payload), std::end(adapter_payload),
|
std::copy(std::begin(adapter_payload), std::end(adapter_payload),
|
||||||
@ -128,7 +128,6 @@ void Adapter::Read() {
|
|||||||
payload_size = payload_size_in;
|
payload_size = payload_size_in;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::array<GCPadStatus, 4> pad;
|
|
||||||
if (payload_size != sizeof(controller_payload_copy) ||
|
if (payload_size != sizeof(controller_payload_copy) ||
|
||||||
controller_payload_copy[0] != LIBUSB_DT_HID) {
|
controller_payload_copy[0] != LIBUSB_DT_HID) {
|
||||||
LOG_ERROR(Input, "error reading payload (size: %d, type: %02x)", payload_size,
|
LOG_ERROR(Input, "error reading payload (size: %d, type: %02x)", payload_size,
|
||||||
@ -365,4 +364,4 @@ const std::array<GCState, 4>& Adapter::GetPadState() const {
|
|||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end of namespace GCAdapter
|
} // namespace GCAdapter
|
||||||
|
@ -101,9 +101,9 @@ public:
|
|||||||
const std::array<GCState, 4>& GetPadState() const;
|
const std::array<GCState, 4>& GetPadState() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GCPadStatus CheckStatus(int port, u8 adapter_payload[37]);
|
GCPadStatus CheckStatus(int port, const std::array<u8, 37>& adapter_payload);
|
||||||
|
|
||||||
void PadToState(GCPadStatus pad, GCState& state);
|
void PadToState(const GCPadStatus& pad, GCState& state);
|
||||||
|
|
||||||
void Read();
|
void Read();
|
||||||
void ScanThreadFunc();
|
void ScanThreadFunc();
|
||||||
@ -154,4 +154,4 @@ private:
|
|||||||
std::array<GCState, 4> state;
|
std::array<GCState, 4> state;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end of namespace GCAdapter
|
} // namespace GCAdapter
|
||||||
|
Loading…
Reference in New Issue
Block a user