mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-12 09:06:55 -04:00
Wii/GameCube: Input refactor part 1
- Wii/GameCube now use simpler input mode with just A/B when in the launcher, inspired by what the 3DS port does (Thanks Pear for the idea originally) - GameCube now uses secondary control stick for camera input (Thanks GK6475)
This commit is contained in:
parent
d3783eec8b
commit
dd3a39568a
@ -12,6 +12,7 @@
|
|||||||
#include <wiiuse/wpad.h>
|
#include <wiiuse/wpad.h>
|
||||||
#include <wiikeyboard/keyboard.h>
|
#include <wiikeyboard/keyboard.h>
|
||||||
#endif
|
#endif
|
||||||
|
static cc_bool launcherMode;
|
||||||
|
|
||||||
static void* xfb;
|
static void* xfb;
|
||||||
static GXRModeObj* rmode;
|
static GXRModeObj* rmode;
|
||||||
@ -70,36 +71,33 @@ void Window_Init(void) {
|
|||||||
PAD_Init();
|
PAD_Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DoCreateWindow(int _3d) {
|
void Window_Create2D(int width, int height) { launcherMode = true; }
|
||||||
}
|
void Window_Create3D(int width, int height) { launcherMode = false; }
|
||||||
void Window_Create2D(int width, int height) { DoCreateWindow(0); }
|
|
||||||
void Window_Create3D(int width, int height) { DoCreateWindow(1); }
|
|
||||||
|
|
||||||
void Window_SetTitle(const cc_string* title) { }
|
|
||||||
void Clipboard_GetText(cc_string* value) { }
|
|
||||||
void Clipboard_SetText(const cc_string* value) { }
|
|
||||||
|
|
||||||
int Window_GetWindowState(void) { return WINDOW_STATE_FULLSCREEN; }
|
|
||||||
cc_result Window_EnterFullscreen(void) { return 0; }
|
|
||||||
cc_result Window_ExitFullscreen(void) { return 0; }
|
|
||||||
int Window_IsObscured(void) { return 0; }
|
|
||||||
|
|
||||||
void Window_Show(void) { }
|
|
||||||
void Window_SetSize(int width, int height) { }
|
|
||||||
|
|
||||||
void Window_Close(void) {
|
void Window_Close(void) {
|
||||||
/* TODO implement */
|
/* TODO implement */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*########################################################################################################################*
|
||||||
|
*---------------------------------------------GameCube controller processing----------------------------------------------*
|
||||||
|
*#########################################################################################################################*/
|
||||||
|
static void ProcessPAD_Launcher(PADStatus* pad) {
|
||||||
|
int mods = pad->button;
|
||||||
|
|
||||||
static void HandlePADInput(void) {
|
Input_SetNonRepeatable(IPT_ENTER, mods & PAD_BUTTON_A);
|
||||||
PADStatus pads[4];
|
Input_SetNonRepeatable(IPT_ESCAPE, mods & PAD_BUTTON_B);
|
||||||
PAD_Read(pads);
|
// fake tab with down for Launcher
|
||||||
if (pads[0].err) return;
|
//Input_SetNonRepeatable(IPT_TAB, mods & PAD_BUTTON_DOWN);
|
||||||
|
|
||||||
int mods = pads[0].button;
|
Input_SetNonRepeatable(IPT_LEFT, mods & PAD_BUTTON_LEFT);
|
||||||
int dx = pads[0].stickX;
|
Input_SetNonRepeatable(IPT_RIGHT, mods & PAD_BUTTON_RIGHT);
|
||||||
int dy = pads[0].stickY;
|
Input_SetNonRepeatable(IPT_UP, mods & PAD_BUTTON_UP);
|
||||||
|
Input_SetNonRepeatable(IPT_DOWN, mods & PAD_BUTTON_DOWN);
|
||||||
|
}
|
||||||
|
static void ProcessPAD_Game(PADStatus* pad) {
|
||||||
|
int mods = pad->button;
|
||||||
|
int dx = pad->substickX;
|
||||||
|
int dy = pad->substickY;
|
||||||
|
|
||||||
if (Input_RawMode && (Math_AbsI(dx) > 1 || Math_AbsI(dy) > 1)) {
|
if (Input_RawMode && (Math_AbsI(dx) > 1 || Math_AbsI(dy) > 1)) {
|
||||||
Event_RaiseRawMove(&PointerEvents.RawMoved, dx / 32.0f, dy / 32.0f);
|
Event_RaiseRawMove(&PointerEvents.RawMoved, dx / 32.0f, dy / 32.0f);
|
||||||
@ -111,12 +109,10 @@ static void HandlePADInput(void) {
|
|||||||
Input_SetNonRepeatable(KeyBinds[KEYBIND_JUMP], mods & PAD_BUTTON_A);
|
Input_SetNonRepeatable(KeyBinds[KEYBIND_JUMP], mods & PAD_BUTTON_A);
|
||||||
Input_SetNonRepeatable(KeyBinds[KEYBIND_CHAT], mods & PAD_BUTTON_X);
|
Input_SetNonRepeatable(KeyBinds[KEYBIND_CHAT], mods & PAD_BUTTON_X);
|
||||||
Input_SetNonRepeatable(KeyBinds[KEYBIND_INVENTORY], mods & PAD_BUTTON_Y);
|
Input_SetNonRepeatable(KeyBinds[KEYBIND_INVENTORY], mods & PAD_BUTTON_Y);
|
||||||
// PAD_BUTTON_B
|
// TODO PAD_BUTTON_B
|
||||||
|
|
||||||
Input_SetNonRepeatable(IPT_ENTER, mods & PAD_BUTTON_START);
|
Input_SetNonRepeatable(IPT_ENTER, mods & PAD_BUTTON_START);
|
||||||
Input_SetNonRepeatable(IPT_ESCAPE, mods & PAD_TRIGGER_Z);
|
Input_SetNonRepeatable(IPT_ESCAPE, mods & PAD_TRIGGER_Z);
|
||||||
// fake tab with PAD_BUTTON_B for Launcher too
|
|
||||||
Input_SetNonRepeatable(IPT_TAB, mods & PAD_BUTTON_B);
|
|
||||||
|
|
||||||
Input_SetNonRepeatable(KeyBinds[KEYBIND_LEFT], mods & PAD_BUTTON_LEFT);
|
Input_SetNonRepeatable(KeyBinds[KEYBIND_LEFT], mods & PAD_BUTTON_LEFT);
|
||||||
Input_SetNonRepeatable(IPT_LEFT, mods & PAD_BUTTON_LEFT);
|
Input_SetNonRepeatable(IPT_LEFT, mods & PAD_BUTTON_LEFT);
|
||||||
@ -129,15 +125,45 @@ static void HandlePADInput(void) {
|
|||||||
Input_SetNonRepeatable(IPT_DOWN, mods & PAD_BUTTON_DOWN);
|
Input_SetNonRepeatable(IPT_DOWN, mods & PAD_BUTTON_DOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void ProcessPADInput(void) {
|
||||||
|
PADStatus pads[4];
|
||||||
|
PAD_Read(pads);
|
||||||
|
if (pads[0].err) return;
|
||||||
|
|
||||||
|
if (launcherMode) {
|
||||||
|
ProcessPAD_Launcher(&pads[0]);
|
||||||
|
} else {
|
||||||
|
ProcessPAD_Game(&pads[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*########################################################################################################################*
|
||||||
|
*----------------------------------------------------Input processing-----------------------------------------------------*
|
||||||
|
*#########################################################################################################################*/
|
||||||
#if defined HW_RVL
|
#if defined HW_RVL
|
||||||
|
static int dragCursorX;
|
||||||
|
static int dragCursorY;
|
||||||
|
static cc_bool dragOn;
|
||||||
|
static void ProcessWPAD_Launcher(int mods) {
|
||||||
|
Input_SetNonRepeatable(IPT_ENTER, mods & WPAD_BUTTON_A);
|
||||||
|
Input_SetNonRepeatable(IPT_ESCAPE, mods & WPAD_BUTTON_B);
|
||||||
|
|
||||||
int dragCursorX = 0;
|
Input_SetNonRepeatable(IPT_LEFT, mods & WPAD_BUTTON_LEFT);
|
||||||
int dragCursorY = 0;
|
Input_SetNonRepeatable(IPT_RIGHT, mods & WPAD_BUTTON_RIGHT);
|
||||||
cc_bool dragOn = false;
|
Input_SetNonRepeatable(IPT_UP, mods & WPAD_BUTTON_UP);
|
||||||
|
Input_SetNonRepeatable(IPT_DOWN, mods & WPAD_BUTTON_DOWN);
|
||||||
|
}
|
||||||
|
static void ProcessKeyboardInput(void) {
|
||||||
|
keyboard_event ke;
|
||||||
|
int res = KEYBOARD_GetEvent(&ke);
|
||||||
|
|
||||||
#endif
|
if (res && ke.type == KEYBOARD_PRESSED)
|
||||||
|
{
|
||||||
|
//Platform_Log2("KEYCODE: %i (%i)", &ke.keycode, &ke.type);
|
||||||
|
if (ke.symbol) Event_RaiseInt(&InputEvents.Press, ke.symbol);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#if defined HW_RVL
|
|
||||||
void Window_ProcessEvents(double delta) {
|
void Window_ProcessEvents(double delta) {
|
||||||
/* TODO implement */
|
/* TODO implement */
|
||||||
int x, y;
|
int x, y;
|
||||||
@ -149,7 +175,9 @@ void Window_ProcessEvents(double delta) {
|
|||||||
u32 res;
|
u32 res;
|
||||||
WPAD_Probe(0, &res);
|
WPAD_Probe(0, &res);
|
||||||
|
|
||||||
if (res == WPAD_EXP_NUNCHUK) {
|
if (launcherMode) {
|
||||||
|
ProcessWPAD_Launcher(mods);
|
||||||
|
} else if (res == WPAD_EXP_NUNCHUK) {
|
||||||
WPADData *wd = WPAD_Data(0);
|
WPADData *wd = WPAD_Data(0);
|
||||||
joystick_t analog = wd->exp.nunchuk.js;
|
joystick_t analog = wd->exp.nunchuk.js;
|
||||||
|
|
||||||
@ -223,26 +251,13 @@ void Window_ProcessEvents(double delta) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Pointer_SetPosition(0, x, y);
|
Pointer_SetPosition(0, x, y);
|
||||||
HandlePADInput();
|
ProcessPADInput();
|
||||||
|
ProcessKeyboardInput();
|
||||||
keyboard_event ke;
|
|
||||||
res = KEYBOARD_GetEvent(&ke);
|
|
||||||
if (res && ke.type == KEYBOARD_PRESSED)
|
|
||||||
{
|
|
||||||
//Platform_Log2("KEYCODE: %i (%i)", &ke.keycode, &ke.type);
|
|
||||||
if (ke.symbol) Event_RaiseInt(&InputEvents.Press, ke.symbol);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int evctr = 0;
|
|
||||||
static void countevs(int chan, const WPADData *data) {
|
|
||||||
evctr++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Cursor_GetRawPos(int* x, int* y) {
|
static void Cursor_GetRawPos(int* x, int* y) {
|
||||||
u32 type;
|
u32 type;
|
||||||
WPAD_ReadPending(WPAD_CHAN_ALL, countevs);
|
WPAD_ScanPads();
|
||||||
|
|
||||||
int res = WPAD_Probe(0, &type);
|
int res = WPAD_Probe(0, &type);
|
||||||
|
|
||||||
if (res == WPAD_ERR_NONE) {
|
if (res == WPAD_ERR_NONE) {
|
||||||
@ -254,11 +269,10 @@ static void Cursor_GetRawPos(int* x, int* y) {
|
|||||||
*x = 0; *y = 0;
|
*x = 0; *y = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
#elif defined HW_DOL
|
|
||||||
void Window_ProcessEvents(double delta) {
|
void Window_ProcessEvents(double delta) {
|
||||||
/* TODO implement */
|
/* TODO implement */
|
||||||
HandlePADInput();
|
ProcessPADInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Cursor_GetRawPos(int* x, int* y) {
|
static void Cursor_GetRawPos(int* x, int* y) {
|
||||||
@ -275,28 +289,40 @@ static void Cursor_DoSetVisible(cc_bool visible) {
|
|||||||
/* TODO implement */
|
/* TODO implement */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ShowDialogCore(const char* title, const char* msg) {
|
void Window_EnableRawMouse(void) {
|
||||||
|
RegrabMouse();
|
||||||
|
Input_RawMode = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define FACTOR 2
|
||||||
|
void Window_UpdateRawMouse(void) {
|
||||||
|
|
||||||
|
#if defined HW_RVL
|
||||||
|
if (dragOn) {
|
||||||
|
cursorPrevX = (cursorPrevX-dragCursorX)/FACTOR+dragCursorX;
|
||||||
|
cursorPrevY = (cursorPrevY-dragCursorY)/FACTOR+dragCursorY;
|
||||||
|
|
||||||
|
DefaultUpdateRawMouse();
|
||||||
|
}
|
||||||
|
#else
|
||||||
/* TODO implement */
|
/* TODO implement */
|
||||||
Platform_LogConst(title);
|
#endif
|
||||||
Platform_LogConst(msg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result Window_OpenFileDialog(const struct OpenFileDialogArgs* args) {
|
void Window_DisableRawMouse(void) {
|
||||||
return ERR_NOT_SUPPORTED;
|
RegrabMouse();
|
||||||
}
|
Input_RawMode = false;
|
||||||
|
|
||||||
cc_result Window_SaveFileDialog(const struct SaveFileDialogArgs* args) {
|
|
||||||
return ERR_NOT_SUPPORTED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*########################################################################################################################*
|
||||||
|
*------------------------------------------------------Framebuffer--------------------------------------------------------*
|
||||||
|
*#########################################################################################################################*/
|
||||||
static struct Bitmap fb_bmp;
|
static struct Bitmap fb_bmp;
|
||||||
void Window_AllocFramebuffer(struct Bitmap* bmp) {
|
void Window_AllocFramebuffer(struct Bitmap* bmp) {
|
||||||
bmp->scan0 = (BitmapCol*)Mem_Alloc(bmp->width * bmp->height, 4, "window pixels");
|
bmp->scan0 = (BitmapCol*)Mem_Alloc(bmp->width * bmp->height, 4, "window pixels");
|
||||||
fb_bmp = *bmp;
|
fb_bmp = *bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: Get rid of this complexity and use the 3D API instead..
|
// TODO: Get rid of this complexity and use the 3D API instead..
|
||||||
// https://github.com/devkitPro/gamecube-examples/blob/master/graphics/fb/pageflip/source/flip.c
|
// https://github.com/devkitPro/gamecube-examples/blob/master/graphics/fb/pageflip/source/flip.c
|
||||||
static u32 CvtRGB (u8 r1, u8 g1, u8 b1, u8 r2, u8 g2, u8 b2)
|
static u32 CvtRGB (u8 r1, u8 g1, u8 b1, u8 r2, u8 g2, u8 b2)
|
||||||
@ -341,32 +367,36 @@ void Window_FreeFramebuffer(struct Bitmap* bmp) {
|
|||||||
Mem_Free(bmp->scan0);
|
Mem_Free(bmp->scan0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*########################################################################################################################*
|
||||||
|
*-------------------------------------------------------Misc/Other--------------------------------------------------------*
|
||||||
|
*#########################################################################################################################*/
|
||||||
|
void Window_SetTitle(const cc_string* title) { }
|
||||||
|
void Clipboard_GetText(cc_string* value) { }
|
||||||
|
void Clipboard_SetText(const cc_string* value) { }
|
||||||
|
|
||||||
|
int Window_GetWindowState(void) { return WINDOW_STATE_FULLSCREEN; }
|
||||||
|
cc_result Window_EnterFullscreen(void) { return 0; }
|
||||||
|
cc_result Window_ExitFullscreen(void) { return 0; }
|
||||||
|
int Window_IsObscured(void) { return 0; }
|
||||||
|
|
||||||
|
void Window_Show(void) { }
|
||||||
|
void Window_SetSize(int width, int height) { }
|
||||||
|
|
||||||
void Window_OpenKeyboard(struct OpenKeyboardArgs* args) { /* TODO implement */ }
|
void Window_OpenKeyboard(struct OpenKeyboardArgs* args) { /* TODO implement */ }
|
||||||
void Window_SetKeyboardText(const cc_string* text) { }
|
void Window_SetKeyboardText(const cc_string* text) { }
|
||||||
void Window_CloseKeyboard(void) { /* TODO implement */ }
|
void Window_CloseKeyboard(void) { /* TODO implement */ }
|
||||||
|
|
||||||
void Window_EnableRawMouse(void) {
|
static void ShowDialogCore(const char* title, const char* msg) {
|
||||||
RegrabMouse();
|
|
||||||
Input_RawMode = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define FACTOR 2
|
|
||||||
void Window_UpdateRawMouse(void) {
|
|
||||||
|
|
||||||
#if defined HW_RVL
|
|
||||||
if (dragOn) {
|
|
||||||
cursorPrevX = (cursorPrevX-dragCursorX)/FACTOR+dragCursorX;
|
|
||||||
cursorPrevY = (cursorPrevY-dragCursorY)/FACTOR+dragCursorY;
|
|
||||||
|
|
||||||
DefaultUpdateRawMouse();
|
|
||||||
}
|
|
||||||
#elif defined HW_DOL
|
|
||||||
/* TODO implement */
|
/* TODO implement */
|
||||||
#endif
|
Platform_LogConst(title);
|
||||||
|
Platform_LogConst(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window_DisableRawMouse(void) {
|
cc_result Window_OpenFileDialog(const struct OpenFileDialogArgs* args) {
|
||||||
RegrabMouse();
|
return ERR_NOT_SUPPORTED;
|
||||||
Input_RawMode = false;
|
}
|
||||||
|
|
||||||
|
cc_result Window_SaveFileDialog(const struct SaveFileDialogArgs* args) {
|
||||||
|
return ERR_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user