mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-11-30 06:34:16 +01:00
Address feedback regarding increments, const vars, and general cleanup
This commit is contained in:
parent
dfdf87d844
commit
a76e11e7f0
@ -45,13 +45,13 @@ GCPadStatus Adapter::GetPadStatus(int port, const std::array<u8, 37>& adapter_pa
|
|||||||
const u8 b1 = adapter_payload[1 + (9 * port) + 1];
|
const u8 b1 = adapter_payload[1 + (9 * port) + 1];
|
||||||
const u8 b2 = adapter_payload[1 + (9 * port) + 2];
|
const u8 b2 = adapter_payload[1 + (9 * port) + 2];
|
||||||
|
|
||||||
for (int i = 0; i < b1_buttons.size(); i++) {
|
for (std::size_t i = 0; i < b1_buttons.size(); ++i) {
|
||||||
if (b1 & (1 << i)) {
|
if (b1 & (1 << i)) {
|
||||||
pad.button |= static_cast<u16>(b1_buttons[i]);
|
pad.button |= static_cast<u16>(b1_buttons[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int j = 0; j < b2_buttons.size(); j++) {
|
for (std::size_t j = 0; j < b2_buttons.size(); ++j) {
|
||||||
if (b2 & (1 << j)) {
|
if (b2 & (1 << j)) {
|
||||||
pad.button |= static_cast<u16>(b2_buttons[j]);
|
pad.button |= static_cast<u16>(b2_buttons[j]);
|
||||||
}
|
}
|
||||||
@ -73,7 +73,7 @@ GCPadStatus Adapter::GetPadStatus(int port, const std::array<u8, 37>& adapter_pa
|
|||||||
|
|
||||||
void Adapter::PadToState(const GCPadStatus& pad, GCState& state) {
|
void Adapter::PadToState(const GCPadStatus& pad, GCState& state) {
|
||||||
for (const auto& button : PadButtonArray) {
|
for (const auto& button : PadButtonArray) {
|
||||||
u16 button_value = static_cast<u16>(button);
|
const u16 button_value = static_cast<u16>(button);
|
||||||
state.buttons.insert_or_assign(button_value, pad.button & button_value);
|
state.buttons.insert_or_assign(button_value, pad.button & button_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ void Adapter::PadToState(const GCPadStatus& pad, GCState& state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Adapter::Read() {
|
void Adapter::Read() {
|
||||||
LOG_INFO(Input, "GC Adapter Read() thread started");
|
LOG_DEBUG(Input, "GC Adapter Read() thread started");
|
||||||
|
|
||||||
int payload_size_in, payload_size_copy;
|
int payload_size_in, payload_size_copy;
|
||||||
std::array<u8, 37> adapter_payload;
|
std::array<u8, 37> adapter_payload;
|
||||||
@ -109,12 +109,10 @@ void Adapter::Read() {
|
|||||||
LOG_ERROR(Input, "error reading payload (size: %d, type: %02x)", payload_size_copy,
|
LOG_ERROR(Input, "error reading payload (size: %d, type: %02x)", payload_size_copy,
|
||||||
adapter_payload_copy[0]);
|
adapter_payload_copy[0]);
|
||||||
adapter_thread_running = false; // error reading from adapter, stop reading.
|
adapter_thread_running = false; // error reading from adapter, stop reading.
|
||||||
} else {
|
break;
|
||||||
for (int port = 0; port < pads.size(); port++) {
|
|
||||||
pads[port] = GetPadStatus(port, adapter_payload_copy);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for (int port = 0; port < pads.size(); port++) {
|
for (std::size_t port = 0; port < pads.size(); ++port) {
|
||||||
|
pads[port] = GetPadStatus(port, adapter_payload_copy);
|
||||||
if (DeviceConnected(port) && configuring) {
|
if (DeviceConnected(port) && configuring) {
|
||||||
if (pads[port].button != PAD_GET_ORIGIN) {
|
if (pads[port].button != PAD_GET_ORIGIN) {
|
||||||
pad_queue[port].Push(pads[port]);
|
pad_queue[port].Push(pads[port]);
|
||||||
@ -189,14 +187,16 @@ void Adapter::Setup() {
|
|||||||
|
|
||||||
adapter_controllers_status.fill(ControllerTypes::None);
|
adapter_controllers_status.fill(ControllerTypes::None);
|
||||||
|
|
||||||
libusb_device** devs; // pointer to list of connected usb devices
|
// pointer to list of connected usb devices
|
||||||
|
libusb_device** devices;
|
||||||
|
|
||||||
const std::size_t cnt = libusb_get_device_list(libusb_ctx, &devs); // get the list of devices
|
// populate the list of devices, get the count
|
||||||
|
const std::size_t device_count = libusb_get_device_list(libusb_ctx, &devices);
|
||||||
|
|
||||||
for (int i = 0; i < cnt; i++) {
|
for (std::size_t index = 0; index < device_count; ++index) {
|
||||||
if (CheckDeviceAccess(devs[i])) {
|
if (CheckDeviceAccess(devices[index])) {
|
||||||
// GC Adapter found and accessible, registering it
|
// GC Adapter found and accessible, registering it
|
||||||
GetGCEndpoint(devs[i]);
|
GetGCEndpoint(devices[index]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,9 +39,9 @@ public:
|
|||||||
bool GetStatus() const override {
|
bool GetStatus() const override {
|
||||||
const float axis_value = (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 128.0f;
|
const float axis_value = (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 128.0f;
|
||||||
if (trigger_if_greater) {
|
if (trigger_if_greater) {
|
||||||
return axis_value > 0.10f; // TODO(ameerj) : Fix threshold.
|
return axis_value > threshold; // TODO(ameerj) : Fix threshold.
|
||||||
}
|
}
|
||||||
return axis_value < -0.10f;
|
return axis_value < -threshold;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -87,16 +87,13 @@ Common::ParamPackage GCButtonFactory::GetNextInput() {
|
|||||||
Common::ParamPackage params;
|
Common::ParamPackage params;
|
||||||
GCAdapter::GCPadStatus pad;
|
GCAdapter::GCPadStatus pad;
|
||||||
auto& queue = adapter->GetPadQueue();
|
auto& queue = adapter->GetPadQueue();
|
||||||
for (int port = 0; port < queue.size(); port++) {
|
for (std::size_t port = 0; port < queue.size(); ++port) {
|
||||||
while (queue[port].Pop(pad)) {
|
while (queue[port].Pop(pad)) {
|
||||||
// This while loop will break on the earliest detected button
|
// This while loop will break on the earliest detected button
|
||||||
params.Set("engine", "gcpad");
|
params.Set("engine", "gcpad");
|
||||||
params.Set("port", port);
|
params.Set("port", static_cast<int>(port));
|
||||||
// I was debating whether to keep these verbose for ease of reading
|
for (const auto& button : GCAdapter::PadButtonArray) {
|
||||||
// or to use a while loop shifting the bits to test and set the value.
|
const u16 button_value = static_cast<u16>(button);
|
||||||
|
|
||||||
for (auto button : GCAdapter::PadButtonArray) {
|
|
||||||
u16 button_value = static_cast<u16>(button);
|
|
||||||
if (pad.button & button_value) {
|
if (pad.button & button_value) {
|
||||||
params.Set("button", button_value);
|
params.Set("button", button_value);
|
||||||
break;
|
break;
|
||||||
@ -228,7 +225,7 @@ void GCAnalogFactory::EndConfiguration() {
|
|||||||
Common::ParamPackage GCAnalogFactory::GetNextInput() {
|
Common::ParamPackage GCAnalogFactory::GetNextInput() {
|
||||||
GCAdapter::GCPadStatus pad;
|
GCAdapter::GCPadStatus pad;
|
||||||
auto& queue = adapter->GetPadQueue();
|
auto& queue = adapter->GetPadQueue();
|
||||||
for (int port = 0; port < queue.size(); port++) {
|
for (std::size_t port = 0; port < queue.size(); ++port) {
|
||||||
while (queue[port].Pop(pad)) {
|
while (queue[port].Pop(pad)) {
|
||||||
if (pad.axis == GCAdapter::PadAxes::Undefined ||
|
if (pad.axis == GCAdapter::PadAxes::Undefined ||
|
||||||
std::abs((pad.axis_value - 128.0f) / 128.0f) < 0.1) {
|
std::abs((pad.axis_value - 128.0f) / 128.0f) < 0.1) {
|
||||||
|
Loading…
Reference in New Issue
Block a user