mirror of
https://github.com/wiiu-env/wudd.git
synced 2024-11-22 09:59:16 +01:00
Fix inputs when no gamepad is connected
This commit is contained in:
parent
09df747dcc
commit
15cdd0e089
20
source/input/CombinedInput.h
Normal file
20
source/input/CombinedInput.h
Normal 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;
|
||||
}
|
||||
};
|
@ -11,12 +11,6 @@ public:
|
||||
//!Destructor
|
||||
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 {
|
||||
BUTTON_NONE = 0x0000,
|
||||
VPAD_TOUCH = 0x80000000,
|
||||
@ -63,4 +57,5 @@ public:
|
||||
|
||||
PadData data{};
|
||||
PadData lastData{};
|
||||
|
||||
};
|
||||
|
@ -49,6 +49,8 @@ public:
|
||||
data.y = -(height >> 1) + (int32_t) (float) height - (((float) tpCalib.y / 720.0f) * (float) height);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
data.buttons_h = 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -31,43 +31,43 @@ public:
|
||||
uint32_t remapWiiMoteButtons(uint32_t buttons) {
|
||||
uint32_t conv_buttons = 0;
|
||||
|
||||
if(buttons & WPAD_BUTTON_LEFT)
|
||||
if (buttons & WPAD_BUTTON_LEFT)
|
||||
conv_buttons |= Input::BUTTON_LEFT;
|
||||
|
||||
if(buttons & WPAD_BUTTON_RIGHT)
|
||||
if (buttons & WPAD_BUTTON_RIGHT)
|
||||
conv_buttons |= Input::BUTTON_RIGHT;
|
||||
|
||||
if(buttons & WPAD_BUTTON_DOWN)
|
||||
if (buttons & WPAD_BUTTON_DOWN)
|
||||
conv_buttons |= Input::BUTTON_DOWN;
|
||||
|
||||
if(buttons & WPAD_BUTTON_UP)
|
||||
if (buttons & WPAD_BUTTON_UP)
|
||||
conv_buttons |= Input::BUTTON_UP;
|
||||
|
||||
if(buttons & WPAD_BUTTON_PLUS)
|
||||
if (buttons & WPAD_BUTTON_PLUS)
|
||||
conv_buttons |= Input::BUTTON_PLUS;
|
||||
|
||||
if(buttons & WPAD_BUTTON_2)
|
||||
if (buttons & WPAD_BUTTON_2)
|
||||
conv_buttons |= Input::BUTTON_2;
|
||||
|
||||
if(buttons & WPAD_BUTTON_1)
|
||||
if (buttons & WPAD_BUTTON_1)
|
||||
conv_buttons |= Input::BUTTON_1;
|
||||
|
||||
if(buttons & WPAD_BUTTON_B)
|
||||
if (buttons & WPAD_BUTTON_B)
|
||||
conv_buttons |= Input::BUTTON_B;
|
||||
|
||||
if(buttons & WPAD_BUTTON_A)
|
||||
if (buttons & WPAD_BUTTON_A)
|
||||
conv_buttons |= Input::BUTTON_A;
|
||||
|
||||
if(buttons & WPAD_BUTTON_MINUS)
|
||||
if (buttons & WPAD_BUTTON_MINUS)
|
||||
conv_buttons |= Input::BUTTON_MINUS;
|
||||
|
||||
if(buttons & WPAD_BUTTON_Z)
|
||||
if (buttons & WPAD_BUTTON_Z)
|
||||
conv_buttons |= Input::BUTTON_Z;
|
||||
|
||||
if(buttons & WPAD_BUTTON_C)
|
||||
if (buttons & WPAD_BUTTON_C)
|
||||
conv_buttons |= Input::BUTTON_C;
|
||||
|
||||
if(buttons & WPAD_BUTTON_HOME)
|
||||
if (buttons & WPAD_BUTTON_HOME)
|
||||
conv_buttons |= Input::BUTTON_HOME;
|
||||
|
||||
return conv_buttons;
|
||||
@ -76,63 +76,65 @@ public:
|
||||
uint32_t remapClassicButtons(uint32_t buttons) {
|
||||
uint32_t conv_buttons = 0;
|
||||
|
||||
if(buttons & WPAD_CLASSIC_BUTTON_LEFT)
|
||||
if (buttons & WPAD_CLASSIC_BUTTON_LEFT)
|
||||
conv_buttons |= Input::BUTTON_LEFT;
|
||||
|
||||
if(buttons & WPAD_CLASSIC_BUTTON_RIGHT)
|
||||
if (buttons & WPAD_CLASSIC_BUTTON_RIGHT)
|
||||
conv_buttons |= Input::BUTTON_RIGHT;
|
||||
|
||||
if(buttons & WPAD_CLASSIC_BUTTON_DOWN)
|
||||
if (buttons & WPAD_CLASSIC_BUTTON_DOWN)
|
||||
conv_buttons |= Input::BUTTON_DOWN;
|
||||
|
||||
if(buttons & WPAD_CLASSIC_BUTTON_UP)
|
||||
if (buttons & WPAD_CLASSIC_BUTTON_UP)
|
||||
conv_buttons |= Input::BUTTON_UP;
|
||||
|
||||
if(buttons & WPAD_CLASSIC_BUTTON_PLUS)
|
||||
if (buttons & WPAD_CLASSIC_BUTTON_PLUS)
|
||||
conv_buttons |= Input::BUTTON_PLUS;
|
||||
|
||||
if(buttons & WPAD_CLASSIC_BUTTON_X)
|
||||
if (buttons & WPAD_CLASSIC_BUTTON_X)
|
||||
conv_buttons |= Input::BUTTON_X;
|
||||
|
||||
if(buttons & WPAD_CLASSIC_BUTTON_Y)
|
||||
if (buttons & WPAD_CLASSIC_BUTTON_Y)
|
||||
conv_buttons |= Input::BUTTON_Y;
|
||||
|
||||
if(buttons & WPAD_CLASSIC_BUTTON_B)
|
||||
if (buttons & WPAD_CLASSIC_BUTTON_B)
|
||||
conv_buttons |= Input::BUTTON_B;
|
||||
|
||||
if(buttons & WPAD_CLASSIC_BUTTON_A)
|
||||
if (buttons & WPAD_CLASSIC_BUTTON_A)
|
||||
conv_buttons |= Input::BUTTON_A;
|
||||
|
||||
if(buttons & WPAD_CLASSIC_BUTTON_MINUS)
|
||||
if (buttons & WPAD_CLASSIC_BUTTON_MINUS)
|
||||
conv_buttons |= Input::BUTTON_MINUS;
|
||||
|
||||
if(buttons & WPAD_CLASSIC_BUTTON_HOME)
|
||||
if (buttons & WPAD_CLASSIC_BUTTON_HOME)
|
||||
conv_buttons |= Input::BUTTON_HOME;
|
||||
|
||||
if(buttons & WPAD_CLASSIC_BUTTON_ZR)
|
||||
if (buttons & WPAD_CLASSIC_BUTTON_ZR)
|
||||
conv_buttons |= Input::BUTTON_ZR;
|
||||
|
||||
if(buttons & WPAD_CLASSIC_BUTTON_ZL)
|
||||
if (buttons & WPAD_CLASSIC_BUTTON_ZL)
|
||||
conv_buttons |= Input::BUTTON_ZL;
|
||||
|
||||
if(buttons & WPAD_CLASSIC_BUTTON_R)
|
||||
if (buttons & WPAD_CLASSIC_BUTTON_R)
|
||||
conv_buttons |= Input::BUTTON_R;
|
||||
|
||||
if(buttons & WPAD_CLASSIC_BUTTON_L)
|
||||
if (buttons & WPAD_CLASSIC_BUTTON_L)
|
||||
conv_buttons |= Input::BUTTON_L;
|
||||
|
||||
return conv_buttons;
|
||||
}
|
||||
|
||||
bool update(int32_t width, int32_t height) {
|
||||
lastData = data;
|
||||
WPADExtensionType type;
|
||||
if (WPADProbe(channel, &type) != 0) {
|
||||
data.buttons_h = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
KPADRead(channel, &kpad, 1);
|
||||
|
||||
if(kpad.extensionType == WPAD_EXT_CORE || kpad.extensionType == WPAD_EXT_NUNCHUK) {
|
||||
if (kpad.extensionType == WPAD_EXT_CORE || kpad.extensionType == WPAD_EXT_NUNCHUK) {
|
||||
data.buttons_r = remapWiiMoteButtons(kpad.release);
|
||||
data.buttons_h = remapWiiMoteButtons(kpad.hold);
|
||||
data.buttons_d = remapWiiMoteButtons(kpad.trigger);
|
||||
@ -147,11 +149,11 @@ public:
|
||||
(kpad.pos.y >= -1.0f && kpad.pos.y <= 1.0f);
|
||||
|
||||
//! calculate the screen offsets if pointer is valid else leave old value
|
||||
if(data.validPointer) {
|
||||
if (data.validPointer) {
|
||||
data.x = (width >> 1) * kpad.pos.x;
|
||||
data.y = (height >> 1) * (-kpad.pos.y);
|
||||
|
||||
if(kpad.angle.y > 0.0f) {
|
||||
if (kpad.angle.y > 0.0f) {
|
||||
data.pointerAngle = (-kpad.angle.x + 1.0f) * 0.5f * 180.0f;
|
||||
} else {
|
||||
data.pointerAngle = (kpad.angle.x + 1.0f) * 0.5f * 180.0f - 180.0f;
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <coreinit/energysaver.h>
|
||||
#include <padscore/kpad.h>
|
||||
#include <input/WPADInput.h>
|
||||
#include <input/CombinedInput.h>
|
||||
|
||||
#include "utils/logger.h"
|
||||
#include "utils/WiiUScreen.h"
|
||||
@ -77,6 +78,7 @@ int main(int argc, char **argv) {
|
||||
void main_loop() {
|
||||
DEBUG_FUNCTION_LINE("Creating state");
|
||||
std::unique_ptr<MainApplicationState> state = std::make_unique<MainApplicationState>();
|
||||
CombinedInput baseInput;
|
||||
VPadInput vpadInput;
|
||||
WPADInput wpadInputs[4] = {
|
||||
WPAD_CHAN_0,
|
||||
@ -92,12 +94,17 @@ void main_loop() {
|
||||
|
||||
DEBUG_FUNCTION_LINE("Entering main loop");
|
||||
while (WHBProcIsRunning()) {
|
||||
vpadInput.update(1280, 720);
|
||||
for (auto & wpadInput : wpadInputs) {
|
||||
wpadInput.update(1280, 720);
|
||||
vpadInput.combine(wpadInput);
|
||||
baseInput.reset();
|
||||
if (vpadInput.update(1280, 720)) {
|
||||
baseInput.combine(vpadInput);
|
||||
}
|
||||
state->update(&vpadInput);
|
||||
for (auto &wpadInput: wpadInputs) {
|
||||
if(wpadInput.update(1280, 720)){
|
||||
baseInput.combine(wpadInput);
|
||||
}
|
||||
}
|
||||
baseInput.process();
|
||||
state->update(&baseInput);
|
||||
state->render();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user