Fix inputs when no gamepad is connected

This commit is contained in:
Maschell 2021-10-17 15:09:53 +02:00
parent 09df747dcc
commit 15cdd0e089
5 changed files with 68 additions and 42 deletions

View File

@ -0,0 +1,20 @@
#pragma once
class CombinedInput : public Input {
public:
void combine(const Input &b) {
data.buttons_h |= b.data.buttons_h;
}
void process() {
data.buttons_d |= (data.buttons_h & (~lastData.buttons_h));
data.buttons_r |= (lastData.buttons_h & (~data.buttons_h));
lastData.buttons_h = data.buttons_h;
}
void reset() {
data.buttons_h = 0;
data.buttons_d = 0;
data.buttons_r = 0;
}
};

View File

@ -11,12 +11,6 @@ public:
//!Destructor //!Destructor
virtual ~Input() = default; virtual ~Input() = default;
void combine(const Input &b) {
data.buttons_d |= b.data.buttons_d;
data.buttons_h |= b.data.buttons_h;
data.buttons_r |= b.data.buttons_r;
}
enum eButtons { enum eButtons {
BUTTON_NONE = 0x0000, BUTTON_NONE = 0x0000,
VPAD_TOUCH = 0x80000000, VPAD_TOUCH = 0x80000000,
@ -63,4 +57,5 @@ public:
PadData data{}; PadData data{};
PadData lastData{}; PadData lastData{};
}; };

View File

@ -49,6 +49,8 @@ public:
data.y = -(height >> 1) + (int32_t) (float) height - (((float) tpCalib.y / 720.0f) * (float) height); data.y = -(height >> 1) + (int32_t) (float) height - (((float) tpCalib.y / 720.0f) * (float) height);
return true; return true;
} else {
data.buttons_h = 0;
} }
return false; return false;
} }

View File

@ -125,8 +125,10 @@ public:
} }
bool update(int32_t width, int32_t height) { bool update(int32_t width, int32_t height) {
lastData = data;
WPADExtensionType type; WPADExtensionType type;
if (WPADProbe(channel, &type) != 0) { if (WPADProbe(channel, &type) != 0) {
data.buttons_h = 0;
return false; return false;
} }

View File

@ -10,6 +10,7 @@
#include <coreinit/energysaver.h> #include <coreinit/energysaver.h>
#include <padscore/kpad.h> #include <padscore/kpad.h>
#include <input/WPADInput.h> #include <input/WPADInput.h>
#include <input/CombinedInput.h>
#include "utils/logger.h" #include "utils/logger.h"
#include "utils/WiiUScreen.h" #include "utils/WiiUScreen.h"
@ -77,6 +78,7 @@ int main(int argc, char **argv) {
void main_loop() { void main_loop() {
DEBUG_FUNCTION_LINE("Creating state"); DEBUG_FUNCTION_LINE("Creating state");
std::unique_ptr<MainApplicationState> state = std::make_unique<MainApplicationState>(); std::unique_ptr<MainApplicationState> state = std::make_unique<MainApplicationState>();
CombinedInput baseInput;
VPadInput vpadInput; VPadInput vpadInput;
WPADInput wpadInputs[4] = { WPADInput wpadInputs[4] = {
WPAD_CHAN_0, WPAD_CHAN_0,
@ -92,12 +94,17 @@ void main_loop() {
DEBUG_FUNCTION_LINE("Entering main loop"); DEBUG_FUNCTION_LINE("Entering main loop");
while (WHBProcIsRunning()) { while (WHBProcIsRunning()) {
vpadInput.update(1280, 720); baseInput.reset();
for (auto & wpadInput : wpadInputs) { if (vpadInput.update(1280, 720)) {
wpadInput.update(1280, 720); baseInput.combine(vpadInput);
vpadInput.combine(wpadInput);
} }
state->update(&vpadInput); for (auto &wpadInput: wpadInputs) {
if(wpadInput.update(1280, 720)){
baseInput.combine(wpadInput);
}
}
baseInput.process();
state->update(&baseInput);
state->render(); state->render();
} }
} }