Implement new ConfigAPI and new Config Menu

This commit is contained in:
Maschell
2023-12-16 17:36:57 +01:00
parent b991d6e329
commit 921b5ce157
40 changed files with 2578 additions and 1319 deletions

View File

@@ -0,0 +1,27 @@
#pragma once
#include "Input.h"
class CombinedInput : public Input {
public:
void combine(const Input &b) {
data.buttons_h |= b.data.buttons_h;
if (!data.touched) {
data.touched = b.data.touched;
}
if (!data.validPointer) {
data.validPointer = b.data.validPointer;
data.pointerAngle = b.data.pointerAngle;
data.x = b.data.x;
data.y = b.data.y;
}
}
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 = {};
}
};

View File

@@ -0,0 +1,62 @@
#pragma once
#include <cstdint>
#include <cstring>
class Input {
public:
//!Constructor
Input() = default;
//!Destructor
virtual ~Input() = default;
enum eButtons {
BUTTON_NONE = 0x0000,
VPAD_TOUCH = 0x80000000,
BUTTON_STICK_L = 0x80000,
BUTTON_STICK_R = 0x40000,
BUTTON_Z = 0x20000,
BUTTON_C = 0x10000,
BUTTON_A = 0x8000,
BUTTON_B = 0x4000,
BUTTON_X = 0x2000,
BUTTON_Y = 0x1000,
BUTTON_1 = BUTTON_Y,
BUTTON_2 = BUTTON_X,
BUTTON_LEFT = 0x0800,
BUTTON_RIGHT = 0x0400,
BUTTON_UP = 0x0200,
BUTTON_DOWN = 0x0100,
BUTTON_ZL = 0x0080,
BUTTON_ZR = 0x0040,
BUTTON_L = 0x0020,
BUTTON_R = 0x0010,
BUTTON_PLUS = 0x0008,
BUTTON_MINUS = 0x0004,
BUTTON_HOME = 0x0002,
BUTTON_SYNC = 0x0001,
STICK_R_LEFT = 0x04000000,
STICK_R_RIGHT = 0x02000000,
STICK_R_UP = 0x01000000,
STICK_R_DOWN = 0x00800000,
STICK_L_LEFT = 0x40000000,
STICK_L_RIGHT = 0x20000000,
STICK_L_UP = 0x10000000,
STICK_L_DOWN = 0x08000000
};
typedef struct {
uint32_t buttons_h;
uint32_t buttons_d;
uint32_t buttons_r;
bool validPointer;
bool touched;
float pointerAngle;
int32_t x;
int32_t y;
} PadData;
PadData data{};
PadData lastData{};
};

View File

@@ -0,0 +1,57 @@
#pragma once
/****************************************************************************
* Copyright (C) 2015 Dimok
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include "Input.h"
#include <vpad/input.h>
class VPadInput : public Input {
public:
//!Constructor
VPadInput() = default;
//!Destructor
~VPadInput() override = default;
bool update(int32_t width, int32_t height) {
lastData = data;
data = {};
vpadError = VPAD_READ_NO_SAMPLES;
if (VPADRead(VPAD_CHAN_0, &vpad, 1, &vpadError) > 0 && vpadError == VPAD_READ_SUCCESS) {
data.buttons_r = vpad.release;
data.buttons_h = vpad.hold;
data.buttons_d = vpad.trigger;
data.validPointer = !vpad.tpNormal.validity;
data.touched = vpad.tpNormal.touched;
VPADGetTPCalibratedPoint(VPAD_CHAN_0, &tpCalib, &vpad.tpFiltered1);
//! calculate the screen offsets
data.x = -(width >> 1) + (int32_t) (((float) tpCalib.x / 1280.0f) * (float) width);
data.y = -(height >> 1) + (int32_t) (float) height - (((float) tpCalib.y / 720.0f) * (float) height);
return true;
}
return false;
}
VPADStatus vpad = {};
VPADReadError vpadError = {};
VPADTouchData tpCalib = {};
};

View File

@@ -0,0 +1,187 @@
#pragma once
/****************************************************************************
* Copyright (C) 2015 Dimok
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include "Input.h"
#include <padscore/kpad.h>
#include <padscore/wpad.h>
class WPADInput : public Input {
public:
WPADInput(KPADChan channel) {
this->channel = channel;
}
~WPADInput() override {}
uint32_t remapWiiMoteButtons(uint32_t buttons) {
uint32_t conv_buttons = 0;
if (buttons & WPAD_BUTTON_LEFT)
conv_buttons |= Input::BUTTON_LEFT;
if (buttons & WPAD_BUTTON_RIGHT)
conv_buttons |= Input::BUTTON_RIGHT;
if (buttons & WPAD_BUTTON_DOWN)
conv_buttons |= Input::BUTTON_DOWN;
if (buttons & WPAD_BUTTON_UP)
conv_buttons |= Input::BUTTON_UP;
if (buttons & WPAD_BUTTON_PLUS)
conv_buttons |= Input::BUTTON_PLUS;
if (buttons & WPAD_BUTTON_2)
conv_buttons |= Input::BUTTON_2;
if (buttons & WPAD_BUTTON_1)
conv_buttons |= Input::BUTTON_1;
if (buttons & WPAD_BUTTON_B)
conv_buttons |= Input::BUTTON_B;
if (buttons & WPAD_BUTTON_A)
conv_buttons |= Input::BUTTON_A;
if (buttons & WPAD_BUTTON_MINUS)
conv_buttons |= Input::BUTTON_MINUS;
if (buttons & WPAD_BUTTON_Z)
conv_buttons |= Input::BUTTON_Z;
if (buttons & WPAD_BUTTON_C)
conv_buttons |= Input::BUTTON_C;
if (buttons & WPAD_BUTTON_HOME)
conv_buttons |= Input::BUTTON_HOME;
return conv_buttons;
}
uint32_t remapClassicButtons(uint32_t buttons) {
uint32_t conv_buttons = 0;
if (buttons & WPAD_CLASSIC_BUTTON_LEFT)
conv_buttons |= Input::BUTTON_LEFT;
if (buttons & WPAD_CLASSIC_BUTTON_RIGHT)
conv_buttons |= Input::BUTTON_RIGHT;
if (buttons & WPAD_CLASSIC_BUTTON_DOWN)
conv_buttons |= Input::BUTTON_DOWN;
if (buttons & WPAD_CLASSIC_BUTTON_UP)
conv_buttons |= Input::BUTTON_UP;
if (buttons & WPAD_CLASSIC_BUTTON_PLUS)
conv_buttons |= Input::BUTTON_PLUS;
if (buttons & WPAD_CLASSIC_BUTTON_X)
conv_buttons |= Input::BUTTON_X;
if (buttons & WPAD_CLASSIC_BUTTON_Y)
conv_buttons |= Input::BUTTON_Y;
if (buttons & WPAD_CLASSIC_BUTTON_B)
conv_buttons |= Input::BUTTON_B;
if (buttons & WPAD_CLASSIC_BUTTON_A)
conv_buttons |= Input::BUTTON_A;
if (buttons & WPAD_CLASSIC_BUTTON_MINUS)
conv_buttons |= Input::BUTTON_MINUS;
if (buttons & WPAD_CLASSIC_BUTTON_HOME)
conv_buttons |= Input::BUTTON_HOME;
if (buttons & WPAD_CLASSIC_BUTTON_ZR)
conv_buttons |= Input::BUTTON_ZR;
if (buttons & WPAD_CLASSIC_BUTTON_ZL)
conv_buttons |= Input::BUTTON_ZL;
if (buttons & WPAD_CLASSIC_BUTTON_R)
conv_buttons |= Input::BUTTON_R;
if (buttons & WPAD_CLASSIC_BUTTON_L)
conv_buttons |= Input::BUTTON_L;
return conv_buttons;
}
bool update(int32_t width, int32_t height) {
lastData = data;
kpadError = KPAD_ERROR_UNINITIALIZED;
data = {};
WPADExtensionType type;
if (WPADProbe(channel, &type) != 0) {
data.buttons_h = 0;
return false;
}
if (KPADReadEx(channel, &kpad, 1, &kpadError) <= 0) {
return false;
}
if (kpadError != KPAD_ERROR_OK || kpad.extensionType == 0xFF) {
return false;
}
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);
} else {
data.buttons_r = remapClassicButtons(kpad.classic.release);
data.buttons_h = remapClassicButtons(kpad.classic.hold);
data.buttons_d = remapClassicButtons(kpad.classic.trigger);
}
data.validPointer = (kpad.posValid == 1 || kpad.posValid == 2) &&
(kpad.pos.x >= -1.0f && kpad.pos.x <= 1.0f) &&
(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) {
data.x = (width >> 1) * kpad.pos.x;
data.y = (height >> 1) * (-kpad.pos.y);
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;
}
}
return true;
}
static void init() {
KPADInit();
WPADEnableURCC(1);
}
static void close() {
}
KPADStatus kpad = {};
KPADError kpadError = KPAD_ERROR_UNINITIALIZED;
KPADChan channel;
};