From ab17a995a49d4e819fe445ef57340e5c9dfa1093 Mon Sep 17 00:00:00 2001 From: Raf <> Date: Mon, 28 Aug 2023 04:50:26 +0800 Subject: [PATCH 1/5] enable using mouse on the radial menu --- port/include/input.h | 7 +++++++ port/src/input.c | 18 +++++++++++++++++- src/game/activemenu.c | 7 +++++++ src/game/activemenutick.c | 30 ++++++++++++++++++++++++++++-- 4 files changed, 59 insertions(+), 3 deletions(-) diff --git a/port/include/input.h b/port/include/input.h index a3859c5d3..3b38d9b91 100644 --- a/port/include/input.h +++ b/port/include/input.h @@ -14,6 +14,9 @@ #define CONT_NUM_BUTTONS 16 // not including the stick axes +#define CURDEV_MNK 0x01 +#define CURDEV_CONTR 0x02 + enum virtkey { /* same order as SDL scancodes */ VK_KEYBOARD_BEGIN = 0, @@ -128,4 +131,8 @@ void inputUpdate(void); // call this before configSave() void inputSaveConfig(void); +// returns the current used device (mouse+kb/controller) for the specified player +// TODO: in the future when the input system can differentiate inputs from different players, will need to update this +u8 inputGetCurrentUsedDevice(u8 playerNum); + #endif diff --git a/port/src/input.c b/port/src/input.c index 38bc1f005..65eab168c 100644 --- a/port/src/input.c +++ b/port/src/input.c @@ -8,6 +8,7 @@ #include "input.h" #include "video.h" #include "config.h" +#include "constants.h" #define MAX_BINDS 4 #define TRIG_THRESHOLD (30 * 256) @@ -130,6 +131,8 @@ static const char *vkJoyNames[] = { static char vkNames[VK_TOTAL_COUNT][64]; +static u8 currentUsedDevice[MAX_PLAYERS]; + void inputSetDefaultKeyBinds(void) { // TODO: make VK constants for all these @@ -479,7 +482,8 @@ static inline s32 inputAxisScale(s32 x, const s32 deadzone, const f32 scale) if (abs(x) < deadzone) { return 0; } else { - // rescale to fit the non-deadzone range + // rescale to fit the non-deadzone range + currentUsedDevice[0] = CURDEV_CONTR; if (x < 0) { x += deadzone; } else { @@ -503,6 +507,7 @@ s32 inputReadController(s32 idx, OSContPad *npad) for (u32 i = 0; i < CONT_NUM_BUTTONS; ++i) { if (inputBindPressed(idx, i)) { npad->button |= 1U << i; + currentUsedDevice[0] = CURDEV_CONTR; } } @@ -555,14 +560,18 @@ static inline void inputUpdateMouse(void) if (mouseWheel > 0) { mouseButtons |= WHEEL_UP_MASK; + currentUsedDevice[0] = CURDEV_MNK; } else if (mouseWheel < 0) { mouseButtons |= WHEEL_DN_MASK; + currentUsedDevice[0] = CURDEV_MNK; } mouseWheel = 0; if (mouseLocked) { SDL_GetRelativeMouseState(&mouseDX, &mouseDY); + if (mouseDX || mouseDY) + currentUsedDevice[0] = CURDEV_MNK; } else { mouseDX = mx - mouseX; mouseDY = my - mouseY; @@ -651,8 +660,10 @@ s32 inputKeyPressed(u32 vk) { if (vk >= VK_KEYBOARD_BEGIN && vk < VK_MOUSE_BEGIN) { const u8 *state = SDL_GetKeyboardState(NULL); + currentUsedDevice[0] = CURDEV_MNK; return state[vk - VK_KEYBOARD_BEGIN]; } else if (vk >= VK_MOUSE_BEGIN && vk < VK_JOY_BEGIN) { + currentUsedDevice[0] = CURDEV_MNK; return mouseButtons & SDL_BUTTON(vk - VK_MOUSE_BEGIN + 1); } else if (vk >= VK_JOY_BEGIN && vk < VK_TOTAL_COUNT) { vk -= VK_JOY_BEGIN; @@ -789,3 +800,8 @@ s32 inputGetKeyByName(const char *name) return -1; } + +u8 inputGetCurrentUsedDevice(u8 playerNum) +{ + return currentUsedDevice[playerNum]; +} diff --git a/src/game/activemenu.c b/src/game/activemenu.c index f3f496a2a..980b9a7b1 100644 --- a/src/game/activemenu.c +++ b/src/game/activemenu.c @@ -56,6 +56,9 @@ const u8 g_AmMapping[] = { 2, // unused }; +extern f32 menuMX; +extern f32 menuMY; + struct chrdata *currentPlayerGetCommandingAibot(void) { return g_Vars.currentplayer->commandingaibot; @@ -754,6 +757,10 @@ void amOpen(void) g_AmMenus[g_AmIndex].origscreennum = 0; g_AmMenus[g_AmIndex].prevallbots = 0; g_AmMenus[g_AmIndex].allbots = false; + +#ifndef PLATFORM_N64 + menuMX = menuMY = 0; +#endif } } diff --git a/src/game/activemenutick.c b/src/game/activemenutick.c index 39681565a..a9b79bb61 100644 --- a/src/game/activemenutick.c +++ b/src/game/activemenutick.c @@ -12,6 +12,10 @@ #include "lib/str.h" #include "data.h" #include "types.h" +#include "input.h" + +f32 menuMX; +f32 menuMY; void amTick(void) { @@ -43,8 +47,30 @@ void amTick(void) for (j = 0; j < numsamples; j++) { s8 gotonextscreen = false; - s8 cstickx = joyGetStickXOnSample(j, contpadnum); - s8 csticky = joyGetStickYOnSample(j, contpadnum); + s8 cstickx = joyGetStickXOnSample(j, contpadnum); + s8 csticky = joyGetStickYOnSample(j, contpadnum); + +#ifndef PLATFORM_N64 + if (inputGetCurrentUsedDevice(i) == CURDEV_MNK) { + f32 dx, dy; + inputMouseGetScaledDelta(&dx, &dy); + + menuMX += dx; + menuMY += dy; + + f32 sc = 8.f; + + s8 signx = (menuMX >= 0) ? 1 : -1; + s8 signy = (menuMY >= 0) ? 1 : -1; + + s32 lim = 100; + menuMX = fabsf(menuMX * sc) >= lim ? (menuMX - dx) : menuMX; + menuMY = fabsf(menuMY * sc) >= lim ? (menuMY - dy) : menuMY; + + cstickx = (s8) (menuMX * sc); + csticky = (s8) -(menuMY * sc); + } +#endif s8 absstickx; s8 abssticky; u16 buttonsstate = joyGetButtonsOnSample(j, contpadnum, 0xffff); From 92392da6fee9b6185d4d86ea93c54945415a04a3 Mon Sep 17 00:00:00 2001 From: Raf <> Date: Tue, 29 Aug 2023 02:38:55 +0800 Subject: [PATCH 2/5] enable using mouse on the radial menu: reworked mouse+kb and other input devices are no longer exclusive when using the radial menu --- port/include/input.h | 4 ---- port/src/input.c | 15 ------------ src/game/activemenu.c | 7 ------ src/game/activemenutick.c | 50 ++++++++++++++++++++------------------- src/include/types.h | 5 ++++ 5 files changed, 31 insertions(+), 50 deletions(-) diff --git a/port/include/input.h b/port/include/input.h index 3b38d9b91..c6ac8a315 100644 --- a/port/include/input.h +++ b/port/include/input.h @@ -131,8 +131,4 @@ void inputUpdate(void); // call this before configSave() void inputSaveConfig(void); -// returns the current used device (mouse+kb/controller) for the specified player -// TODO: in the future when the input system can differentiate inputs from different players, will need to update this -u8 inputGetCurrentUsedDevice(u8 playerNum); - #endif diff --git a/port/src/input.c b/port/src/input.c index 65eab168c..d5f247793 100644 --- a/port/src/input.c +++ b/port/src/input.c @@ -131,8 +131,6 @@ static const char *vkJoyNames[] = { static char vkNames[VK_TOTAL_COUNT][64]; -static u8 currentUsedDevice[MAX_PLAYERS]; - void inputSetDefaultKeyBinds(void) { // TODO: make VK constants for all these @@ -483,7 +481,6 @@ static inline s32 inputAxisScale(s32 x, const s32 deadzone, const f32 scale) return 0; } else { // rescale to fit the non-deadzone range - currentUsedDevice[0] = CURDEV_CONTR; if (x < 0) { x += deadzone; } else { @@ -507,7 +504,6 @@ s32 inputReadController(s32 idx, OSContPad *npad) for (u32 i = 0; i < CONT_NUM_BUTTONS; ++i) { if (inputBindPressed(idx, i)) { npad->button |= 1U << i; - currentUsedDevice[0] = CURDEV_CONTR; } } @@ -560,18 +556,14 @@ static inline void inputUpdateMouse(void) if (mouseWheel > 0) { mouseButtons |= WHEEL_UP_MASK; - currentUsedDevice[0] = CURDEV_MNK; } else if (mouseWheel < 0) { mouseButtons |= WHEEL_DN_MASK; - currentUsedDevice[0] = CURDEV_MNK; } mouseWheel = 0; if (mouseLocked) { SDL_GetRelativeMouseState(&mouseDX, &mouseDY); - if (mouseDX || mouseDY) - currentUsedDevice[0] = CURDEV_MNK; } else { mouseDX = mx - mouseX; mouseDY = my - mouseY; @@ -660,10 +652,8 @@ s32 inputKeyPressed(u32 vk) { if (vk >= VK_KEYBOARD_BEGIN && vk < VK_MOUSE_BEGIN) { const u8 *state = SDL_GetKeyboardState(NULL); - currentUsedDevice[0] = CURDEV_MNK; return state[vk - VK_KEYBOARD_BEGIN]; } else if (vk >= VK_MOUSE_BEGIN && vk < VK_JOY_BEGIN) { - currentUsedDevice[0] = CURDEV_MNK; return mouseButtons & SDL_BUTTON(vk - VK_MOUSE_BEGIN + 1); } else if (vk >= VK_JOY_BEGIN && vk < VK_TOTAL_COUNT) { vk -= VK_JOY_BEGIN; @@ -800,8 +790,3 @@ s32 inputGetKeyByName(const char *name) return -1; } - -u8 inputGetCurrentUsedDevice(u8 playerNum) -{ - return currentUsedDevice[playerNum]; -} diff --git a/src/game/activemenu.c b/src/game/activemenu.c index 980b9a7b1..f3f496a2a 100644 --- a/src/game/activemenu.c +++ b/src/game/activemenu.c @@ -56,9 +56,6 @@ const u8 g_AmMapping[] = { 2, // unused }; -extern f32 menuMX; -extern f32 menuMY; - struct chrdata *currentPlayerGetCommandingAibot(void) { return g_Vars.currentplayer->commandingaibot; @@ -757,10 +754,6 @@ void amOpen(void) g_AmMenus[g_AmIndex].origscreennum = 0; g_AmMenus[g_AmIndex].prevallbots = 0; g_AmMenus[g_AmIndex].allbots = false; - -#ifndef PLATFORM_N64 - menuMX = menuMY = 0; -#endif } } diff --git a/src/game/activemenutick.c b/src/game/activemenutick.c index a9b79bb61..37a0f06a5 100644 --- a/src/game/activemenutick.c +++ b/src/game/activemenutick.c @@ -12,10 +12,9 @@ #include "lib/str.h" #include "data.h" #include "types.h" +#ifndef PLATFORM_N64 #include "input.h" - -f32 menuMX; -f32 menuMY; +#endif void amTick(void) { @@ -50,27 +49,6 @@ void amTick(void) s8 cstickx = joyGetStickXOnSample(j, contpadnum); s8 csticky = joyGetStickYOnSample(j, contpadnum); -#ifndef PLATFORM_N64 - if (inputGetCurrentUsedDevice(i) == CURDEV_MNK) { - f32 dx, dy; - inputMouseGetScaledDelta(&dx, &dy); - - menuMX += dx; - menuMY += dy; - - f32 sc = 8.f; - - s8 signx = (menuMX >= 0) ? 1 : -1; - s8 signy = (menuMY >= 0) ? 1 : -1; - - s32 lim = 100; - menuMX = fabsf(menuMX * sc) >= lim ? (menuMX - dx) : menuMX; - menuMY = fabsf(menuMY * sc) >= lim ? (menuMY - dy) : menuMY; - - cstickx = (s8) (menuMX * sc); - csticky = (s8) -(menuMY * sc); - } -#endif s8 absstickx; s8 abssticky; u16 buttonsstate = joyGetButtonsOnSample(j, contpadnum, 0xffff); @@ -89,6 +67,24 @@ void amTick(void) g_AmMenus[g_AmIndex].allbots = false; +#ifndef PLATFORM_N64 + if (j == 0 && g_Vars.currentplayernum == 0 && inputMouseIsLocked()) { + f32 mdx, mdy; + struct activemenu *am = &g_AmMenus[g_AmIndex]; + inputMouseGetScaledDelta(&mdx, &mdy); + if (mdx || mdy) { + am->mousex += mdx * 4.f; + am->mousey += mdy * 4.f; + am->mousex = (am->mousex > 127.f) ? 127.f : (am->mousex < -128.f) ? -128.f : am->mousex; + am->mousey = (am->mousey > 127.f) ? 127.f : (am->mousey < -128.f) ? -128.f : am->mousey; + } + const s32 newstickx = (s32)cstickx + (s32)am->mousex; + const s32 newsticky = (s32)csticky - (s32)am->mousey; + cstickx = (newstickx < -128) ? -128 : (newstickx > 127) ? 127 : newstickx; + csticky = (newsticky < -128) ? -128 : (newsticky > 127) ? 127 : newsticky; + } +#endif + if (g_Vars.currentplayer->activemenumode == AMMODE_EDIT) { buttonsstate = buttonsstate & D_JPAD; cstickx = 0; @@ -363,6 +359,12 @@ void amTick(void) } } } +#ifndef PLATFORM_N64 + else { + g_AmMenus[g_AmIndex].mousex = 0.f; + g_AmMenus[g_AmIndex].mousey = 0.f; + } +#endif if (g_Vars.currentplayer->activemenumode != AMMODE_EDIT) { s16 dist; diff --git a/src/include/types.h b/src/include/types.h index 47fb724d1..5f5e46f6f 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -4306,6 +4306,11 @@ struct activemenu { /*0x32*/ u8 allbots; // when player holds R on the bot command screen /*0x33*/ u8 prevallbots; // used when opening "Pick Target" menu for attack command /*0x34*/ s8 origscreennum; // original screen number before using allbots + +#ifndef PLATFORM_N64 + /* */ f32 mousex; + /* */ f32 mousey; +#endif }; struct briefing { From 9a259acefa9c0fe3e3957b15b13cf8c8ef1c91d6 Mon Sep 17 00:00:00 2001 From: Raf <> Date: Tue, 29 Aug 2023 02:41:11 +0800 Subject: [PATCH 3/5] enable using mouse on the radial menu: removed unused constants --- port/include/input.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/port/include/input.h b/port/include/input.h index c6ac8a315..a3859c5d3 100644 --- a/port/include/input.h +++ b/port/include/input.h @@ -14,9 +14,6 @@ #define CONT_NUM_BUTTONS 16 // not including the stick axes -#define CURDEV_MNK 0x01 -#define CURDEV_CONTR 0x02 - enum virtkey { /* same order as SDL scancodes */ VK_KEYBOARD_BEGIN = 0, From 272b28b6a992f2b9513d84307c978fc516fb5697 Mon Sep 17 00:00:00 2001 From: Raf <> Date: Tue, 29 Aug 2023 02:53:17 +0800 Subject: [PATCH 4/5] attempt to fix whitespace issues --- src/game/activemenutick.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/game/activemenutick.c b/src/game/activemenutick.c index 37a0f06a5..f7ea359ac 100644 --- a/src/game/activemenutick.c +++ b/src/game/activemenutick.c @@ -46,8 +46,8 @@ void amTick(void) for (j = 0; j < numsamples; j++) { s8 gotonextscreen = false; - s8 cstickx = joyGetStickXOnSample(j, contpadnum); - s8 csticky = joyGetStickYOnSample(j, contpadnum); + s8 cstickx = joyGetStickXOnSample(j, contpadnum); + s8 csticky = joyGetStickYOnSample(j, contpadnum); s8 absstickx; s8 abssticky; From 1a7458a2908c7bbf7de97253e9fcf8702ec46e46 Mon Sep 17 00:00:00 2001 From: Raf <> Date: Tue, 29 Aug 2023 16:26:33 +0800 Subject: [PATCH 5/5] fix whitespace issues --- port/src/input.c | 2 +- src/game/activemenutick.c | 38 +++++++++++++++++++------------------- src/include/types.h | 4 ++-- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/port/src/input.c b/port/src/input.c index d5f247793..ddfc7369d 100644 --- a/port/src/input.c +++ b/port/src/input.c @@ -480,7 +480,7 @@ static inline s32 inputAxisScale(s32 x, const s32 deadzone, const f32 scale) if (abs(x) < deadzone) { return 0; } else { - // rescale to fit the non-deadzone range + // rescale to fit the non-deadzone range if (x < 0) { x += deadzone; } else { diff --git a/src/game/activemenutick.c b/src/game/activemenutick.c index f7ea359ac..a7823299c 100644 --- a/src/game/activemenutick.c +++ b/src/game/activemenutick.c @@ -68,21 +68,21 @@ void amTick(void) g_AmMenus[g_AmIndex].allbots = false; #ifndef PLATFORM_N64 - if (j == 0 && g_Vars.currentplayernum == 0 && inputMouseIsLocked()) { - f32 mdx, mdy; - struct activemenu *am = &g_AmMenus[g_AmIndex]; - inputMouseGetScaledDelta(&mdx, &mdy); - if (mdx || mdy) { - am->mousex += mdx * 4.f; - am->mousey += mdy * 4.f; - am->mousex = (am->mousex > 127.f) ? 127.f : (am->mousex < -128.f) ? -128.f : am->mousex; - am->mousey = (am->mousey > 127.f) ? 127.f : (am->mousey < -128.f) ? -128.f : am->mousey; - } - const s32 newstickx = (s32)cstickx + (s32)am->mousex; - const s32 newsticky = (s32)csticky - (s32)am->mousey; - cstickx = (newstickx < -128) ? -128 : (newstickx > 127) ? 127 : newstickx; - csticky = (newsticky < -128) ? -128 : (newsticky > 127) ? 127 : newsticky; - } + if (j == 0 && g_Vars.currentplayernum == 0 && inputMouseIsLocked()) { + f32 mdx, mdy; + struct activemenu *am = &g_AmMenus[g_AmIndex]; + inputMouseGetScaledDelta(&mdx, &mdy); + if (mdx || mdy) { + am->mousex += mdx * 4.f; + am->mousey += mdy * 4.f; + am->mousex = (am->mousex > 127.f) ? 127.f : (am->mousex < -128.f) ? -128.f : am->mousex; + am->mousey = (am->mousey > 127.f) ? 127.f : (am->mousey < -128.f) ? -128.f : am->mousey; + } + const s32 newstickx = (s32)cstickx + (s32)am->mousex; + const s32 newsticky = (s32)csticky - (s32)am->mousey; + cstickx = (newstickx < -128) ? -128 : (newstickx > 127) ? 127 : newstickx; + csticky = (newsticky < -128) ? -128 : (newsticky > 127) ? 127 : newsticky; + } #endif if (g_Vars.currentplayer->activemenumode == AMMODE_EDIT) { @@ -360,10 +360,10 @@ void amTick(void) } } #ifndef PLATFORM_N64 - else { - g_AmMenus[g_AmIndex].mousex = 0.f; - g_AmMenus[g_AmIndex].mousey = 0.f; - } + else { + g_AmMenus[g_AmIndex].mousex = 0.f; + g_AmMenus[g_AmIndex].mousey = 0.f; + } #endif if (g_Vars.currentplayer->activemenumode != AMMODE_EDIT) { diff --git a/src/include/types.h b/src/include/types.h index 5f5e46f6f..8cd8b306e 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -4308,8 +4308,8 @@ struct activemenu { /*0x34*/ s8 origscreennum; // original screen number before using allbots #ifndef PLATFORM_N64 - /* */ f32 mousex; - /* */ f32 mousey; + /* */ f32 mousex; + /* */ f32 mousey; #endif };