summaryrefslogtreecommitdiff
path: root/src/input_common/gcadapter/gc_poller.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common/gcadapter/gc_poller.cpp')
-rw-r--r--src/input_common/gcadapter/gc_poller.cpp74
1 files changed, 18 insertions, 56 deletions
diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp
index be7c600a2..977261884 100644
--- a/src/input_common/gcadapter/gc_poller.cpp
+++ b/src/input_common/gcadapter/gc_poller.cpp
@@ -58,8 +58,8 @@ GCButtonFactory::GCButtonFactory(std::shared_ptr<GCAdapter::Adapter> adapter_)
58GCButton::~GCButton() = default; 58GCButton::~GCButton() = default;
59 59
60std::unique_ptr<Input::ButtonDevice> GCButtonFactory::Create(const Common::ParamPackage& params) { 60std::unique_ptr<Input::ButtonDevice> GCButtonFactory::Create(const Common::ParamPackage& params) {
61 int button_id = params.Get("button", 0); 61 const int button_id = params.Get("button", 0);
62 int port = params.Get("port", 0); 62 const int port = params.Get("port", 0);
63 // For Axis buttons, used by the binary sticks. 63 // For Axis buttons, used by the binary sticks.
64 if (params.Has("axis")) { 64 if (params.Has("axis")) {
65 const int axis = params.Get("axis", 0); 65 const int axis = params.Get("axis", 0);
@@ -86,61 +86,22 @@ std::unique_ptr<Input::ButtonDevice> GCButtonFactory::Create(const Common::Param
86Common::ParamPackage GCButtonFactory::GetNextInput() { 86Common::ParamPackage GCButtonFactory::GetNextInput() {
87 Common::ParamPackage params; 87 Common::ParamPackage params;
88 GCAdapter::GCPadStatus pad; 88 GCAdapter::GCPadStatus pad;
89 for (int i = 0; i < 4; i++) { 89 auto& queue = adapter->GetPadQueue();
90 while (adapter->GetPadQueue()[i].Pop(pad)) { 90 for (int port = 0; port < queue.size(); port++) {
91 while (queue[port].Pop(pad)) {
91 // This while loop will break on the earliest detected button 92 // This while loop will break on the earliest detected button
92 params.Set("engine", "gcpad"); 93 params.Set("engine", "gcpad");
93 params.Set("port", i); 94 params.Set("port", port);
94 // I was debating whether to keep these verbose for ease of reading 95 // I was debating whether to keep these verbose for ease of reading
95 // or to use a while loop shifting the bits to test and set the value. 96 // or to use a while loop shifting the bits to test and set the value.
96 if (pad.button & GCAdapter::PAD_BUTTON_A) { 97
97 params.Set("button", GCAdapter::PAD_BUTTON_A); 98 for (auto button : GCAdapter::PadButtonArray) {
98 break; 99 if (pad.button & button) {
99 } 100 params.Set("button", button);
100 if (pad.button & GCAdapter::PAD_BUTTON_B) { 101 break;
101 params.Set("button", GCAdapter::PAD_BUTTON_B); 102 }
102 break;
103 }
104 if (pad.button & GCAdapter::PAD_BUTTON_X) {
105 params.Set("button", GCAdapter::PAD_BUTTON_X);
106 break;
107 }
108 if (pad.button & GCAdapter::PAD_BUTTON_Y) {
109 params.Set("button", GCAdapter::PAD_BUTTON_Y);
110 break;
111 }
112 if (pad.button & GCAdapter::PAD_BUTTON_DOWN) {
113 params.Set("button", GCAdapter::PAD_BUTTON_DOWN);
114 break;
115 }
116 if (pad.button & GCAdapter::PAD_BUTTON_LEFT) {
117 params.Set("button", GCAdapter::PAD_BUTTON_LEFT);
118 break;
119 }
120 if (pad.button & GCAdapter::PAD_BUTTON_RIGHT) {
121 params.Set("button", GCAdapter::PAD_BUTTON_RIGHT);
122 break;
123 }
124 if (pad.button & GCAdapter::PAD_BUTTON_UP) {
125 params.Set("button", GCAdapter::PAD_BUTTON_UP);
126 break;
127 }
128 if (pad.button & GCAdapter::PAD_TRIGGER_L) {
129 params.Set("button", GCAdapter::PAD_TRIGGER_L);
130 break;
131 }
132 if (pad.button & GCAdapter::PAD_TRIGGER_R) {
133 params.Set("button", GCAdapter::PAD_TRIGGER_R);
134 break;
135 }
136 if (pad.button & GCAdapter::PAD_TRIGGER_Z) {
137 params.Set("button", GCAdapter::PAD_TRIGGER_Z);
138 break;
139 }
140 if (pad.button & GCAdapter::PAD_BUTTON_START) {
141 params.Set("button", GCAdapter::PAD_BUTTON_START);
142 break;
143 } 103 }
104
144 // For Axis button implementation 105 // For Axis button implementation
145 if (pad.axis != GCAdapter::PadAxes::Undefined) { 106 if (pad.axis != GCAdapter::PadAxes::Undefined) {
146 params.Set("axis", static_cast<u8>(pad.axis)); 107 params.Set("axis", static_cast<u8>(pad.axis));
@@ -265,8 +226,9 @@ void GCAnalogFactory::EndConfiguration() {
265 226
266Common::ParamPackage GCAnalogFactory::GetNextInput() { 227Common::ParamPackage GCAnalogFactory::GetNextInput() {
267 GCAdapter::GCPadStatus pad; 228 GCAdapter::GCPadStatus pad;
268 for (int i = 0; i < 4; i++) { 229 auto& queue = adapter->GetPadQueue();
269 while (adapter->GetPadQueue()[i].Pop(pad)) { 230 for (int port = 0; port < queue.size(); port++) {
231 while (queue[port].Pop(pad)) {
270 if (pad.axis == GCAdapter::PadAxes::Undefined || 232 if (pad.axis == GCAdapter::PadAxes::Undefined ||
271 std::abs((pad.axis_value - 128.0f) / 128.0f) < 0.1) { 233 std::abs((pad.axis_value - 128.0f) / 128.0f) < 0.1) {
272 continue; 234 continue;
@@ -276,8 +238,8 @@ Common::ParamPackage GCAnalogFactory::GetNextInput() {
276 const u8 axis = static_cast<u8>(pad.axis); 238 const u8 axis = static_cast<u8>(pad.axis);
277 if (analog_x_axis == -1) { 239 if (analog_x_axis == -1) {
278 analog_x_axis = axis; 240 analog_x_axis = axis;
279 controller_number = i; 241 controller_number = port;
280 } else if (analog_y_axis == -1 && analog_x_axis != axis && controller_number == i) { 242 } else if (analog_y_axis == -1 && analog_x_axis != axis && controller_number == port) {
281 analog_y_axis = axis; 243 analog_y_axis = axis;
282 } 244 }
283 } 245 }