Merge branch 'port' into port-net

This commit is contained in:
fgsfds committed 2024-05-14 20:33:50 +02:00
commit 948a3e0c51
11 files changed
+281 -103

No files matched your search

+80 -78
View File
@@ -17,88 +17,88 @@
#define CONT_NUM_BUTTONS 32 // not including the stick axes
enum virtkey {
/* same order as SDL scancodes */
VK_KEYBOARD_BEGIN = 0,
VK_A = 4,
VK_Z = 29,
VK_1 = 30,
VK_9 = 38,
VK_0 = 39,
VK_RETURN = 40,
VK_ESCAPE = 41,
VK_BACKSPACE = 42,
VK_SPACE = 44,
VK_MINUS = 45,
VK_LEFTBRACKET = 47,
VK_RIGHTBRACKET = 48,
VK_SEMICOLON = 51,
VK_GRAVE = 53,
VK_COMMA = 54,
VK_PERIOD = 55,
VK_F1 = 58,
VK_F9 = 66,
VK_DELETE = 76,
VK_LCTRL = 224,
VK_LSHIFT = 225,
VK_RCTRL = 228,
VK_RSHIFT = 229,
/* same order as SDL scancodes */
VK_KEYBOARD_BEGIN = 0,
VK_A = 4,
VK_Z = 29,
VK_1 = 30,
VK_9 = 38,
VK_0 = 39,
VK_RETURN = 40,
VK_ESCAPE = 41,
VK_BACKSPACE = 42,
VK_SPACE = 44,
VK_MINUS = 45,
VK_LEFTBRACKET = 47,
VK_RIGHTBRACKET = 48,
VK_SEMICOLON = 51,
VK_GRAVE = 53,
VK_COMMA = 54,
VK_PERIOD = 55,
VK_F1 = 58,
VK_F9 = 66,
VK_DELETE = 76,
VK_LCTRL = 224,
VK_LSHIFT = 225,
VK_RCTRL = 228,
VK_RSHIFT = 229,
/* same order as SDL mouse buttons */
VK_MOUSE_BEGIN = 512,
VK_MOUSE_LEFT = VK_MOUSE_BEGIN,
VK_MOUSE_MIDDLE,
VK_MOUSE_RIGHT,
VK_MOUSE_X1,
VK_MOUSE_X2,
VK_MOUSE_WHEEL_UP,
VK_MOUSE_WHEEL_DN,
/* same order as SDL mouse buttons */
VK_MOUSE_BEGIN = 512,
VK_MOUSE_LEFT = VK_MOUSE_BEGIN,
VK_MOUSE_MIDDLE,
VK_MOUSE_RIGHT,
VK_MOUSE_X1,
VK_MOUSE_X2,
VK_MOUSE_WHEEL_UP,
VK_MOUSE_WHEEL_DN,
/* same order as SDL gamecontroller buttons plus two buttons for triggers */
VK_JOY_BEGIN,
VK_JOY1_BEGIN = VK_JOY_BEGIN,
VK_JOY1_LTRIG = VK_JOY1_BEGIN + 30,
VK_JOY1_RTRIG = VK_JOY1_BEGIN + 31,
VK_JOY2_BEGIN = VK_JOY1_BEGIN + INPUT_MAX_CONTROLLER_BUTTONS,
VK_JOY3_BEGIN = VK_JOY2_BEGIN + INPUT_MAX_CONTROLLER_BUTTONS,
VK_JOY4_BEGIN = VK_JOY3_BEGIN + INPUT_MAX_CONTROLLER_BUTTONS,
/* same order as SDL gamecontroller buttons plus two buttons for triggers */
VK_JOY_BEGIN,
VK_JOY1_BEGIN = VK_JOY_BEGIN,
VK_JOY1_LTRIG = VK_JOY1_BEGIN + 30,
VK_JOY1_RTRIG = VK_JOY1_BEGIN + 31,
VK_JOY2_BEGIN = VK_JOY1_BEGIN + INPUT_MAX_CONTROLLER_BUTTONS,
VK_JOY3_BEGIN = VK_JOY2_BEGIN + INPUT_MAX_CONTROLLER_BUTTONS,
VK_JOY4_BEGIN = VK_JOY3_BEGIN + INPUT_MAX_CONTROLLER_BUTTONS,
VK_TOTAL_COUNT = VK_JOY_BEGIN + INPUT_MAX_CONTROLLERS * INPUT_MAX_CONTROLLER_BUTTONS,
VK_TOTAL_COUNT = VK_JOY_BEGIN + INPUT_MAX_CONTROLLERS * INPUT_MAX_CONTROLLER_BUTTONS,
};
enum contkey {
CK_C_R,
CK_C_L,
CK_C_D,
CK_C_U,
CK_RTRIG,
CK_LTRIG,
CK_X, // gap in CONT_
CK_Y, // gap in CONT_
CK_DPAD_R,
CK_DPAD_L,
CK_DPAD_D,
CK_DPAD_U,
CK_START,
CK_ZTRIG,
CK_B,
CK_A,
CK_STICK_XNEG,
CK_STICK_XPOS,
CK_STICK_YNEG,
CK_STICK_YPOS,
CK_0010,
CK_0020,
CK_0040,
CK_0080,
CK_0100,
CK_0200,
CK_0400,
CK_0800,
CK_1000,
CK_2000,
CK_4000,
CK_8000,
CK_TOTAL_COUNT
CK_C_R,
CK_C_L,
CK_C_D,
CK_C_U,
CK_RTRIG,
CK_LTRIG,
CK_X, // gap in CONT_
CK_Y, // gap in CONT_
CK_DPAD_R,
CK_DPAD_L,
CK_DPAD_D,
CK_DPAD_U,
CK_START,
CK_ZTRIG,
CK_B,
CK_A,
CK_STICK_XNEG,
CK_STICK_XPOS,
CK_STICK_YNEG,
CK_STICK_YPOS,
CK_0010,
CK_0020,
CK_0040,
CK_0080,
CK_0100,
CK_0200,
CK_0400,
CK_0800,
CK_1000,
CK_2000,
CK_4000,
CK_8000,
CK_TOTAL_COUNT
};
// returns bitmask of connected controllers or -1 if failed
@@ -152,6 +152,7 @@ s32 inputAssignController(s32 cidx, s32 id);
// vk is a value from the virtkey enum above
s32 inputKeyPressed(u32 vk);
s32 inputKeyJustPressed(u32 vk);
// idx is controller index, contbtn is one of the CONT_ constants
s32 inputButtonPressed(s32 idx, u32 contbtn);
@@ -186,8 +187,9 @@ void inputLockMouse(s32 lock);
// returns the current state of the above
s32 inputMouseIsLocked(void);
// returns mouse position in native viewport coordinates (ie, 320x240 most of the time)
void inputMouseGetPosition(s32 *x, s32 *y);
// sets x, y to mouse position in native viewport coordinates (ie, 320x240 most of the time)
// returns true if mouse has moved this input frame
s32 inputMouseGetPosition(s32 *x, s32 *y);
// returns changes in mouse position since last frame, in window coordinates
void inputMouseGetRawDelta(s32 *dx, s32 *dy);
+21 -13
View File
@@ -173,6 +173,8 @@ static const char *vkJoyNames[] = {
static char vkNames[VK_TOTAL_COUNT][64];
static s8 vkPrevState[VK_TOTAL_COUNT];
void inputSetDefaultKeyBinds(s32 cidx, s32 n64mode)
{
// TODO: make VK constants for all these
@@ -817,12 +819,6 @@ static inline void inputUpdateMouse(void)
mouseX = mx;
mouseY = my;
if (!mouseLocked && (mouseButtons & SDL_BUTTON_LMASK)) {
inputLockMouse(1);
} else if (mouseLocked && inputKeyPressed(VK_ESCAPE)) {
inputLockMouse(0);
}
}
void inputUpdate(void)
@@ -1069,9 +1065,13 @@ s32 inputKeyPressed(u32 vk)
if (vk >= VK_KEYBOARD_BEGIN && vk < VK_MOUSE_BEGIN) {
const u8 *state = SDL_GetKeyboardState(NULL);
return state[vk - VK_KEYBOARD_BEGIN];
} else if (vk >= VK_MOUSE_BEGIN && vk < VK_JOY_BEGIN) {
return mouseButtons & SDL_BUTTON(vk - VK_MOUSE_BEGIN + 1);
} else if (vk >= VK_JOY_BEGIN && vk < VK_TOTAL_COUNT) {
}
if (vk >= VK_MOUSE_BEGIN && vk < VK_JOY_BEGIN) {
return (mouseButtons & SDL_BUTTON(vk - VK_MOUSE_BEGIN + 1)) != 0;
}
if (vk >= VK_JOY_BEGIN && vk < VK_TOTAL_COUNT) {
vk -= VK_JOY_BEGIN;
const s32 idx = vk / INPUT_MAX_CONTROLLER_BUTTONS;
if (idx < 0 || idx >= INPUT_MAX_CONTROLLERS || !pads[idx]) {
@@ -1085,9 +1085,18 @@ s32 inputKeyPressed(u32 vk)
}
return SDL_GameControllerGetButton(pads[idx], vk);
}
return 0;
}
s32 inputKeyJustPressed(u32 vk)
{
const s8 pressed = inputKeyPressed(vk);
const s32 result = pressed && !vkPrevState[vk];
vkPrevState[vk] = pressed;
return result;
}
static inline u32 inputContToContKey(const u32 cont)
{
if (cont == 0) {
@@ -1117,10 +1126,11 @@ s32 inputMouseIsLocked(void)
return mouseLocked;
}
void inputMouseGetPosition(s32 *x, s32 *y)
s32 inputMouseGetPosition(s32 *x, s32 *y)
{
if (x) *x = mouseX * videoGetNativeWidth() / videoGetWidth();
if (y) *y = mouseY * videoGetNativeHeight() / videoGetHeight();
return (mouseDX != 0 || mouseDY != 0);
}
void inputMouseGetRawDelta(s32 *dx, s32 *dy)
@@ -1190,9 +1200,7 @@ s32 inputGetMouseDefaultLocked(void)
void inputSetMouseDefaultLocked(s32 defaultLocked)
{
mouseDefaultLocked = !!defaultLocked;
if (mouseEnabled) {
inputLockMouse(mouseDefaultLocked);
}
inputLockMouse(mouseDefaultLocked);
}
const char *inputGetContKeyName(u32 ck)
+1
View File
@@ -174,6 +174,7 @@ PD_CONSTRUCTOR static void gameConfigInit(void)
{
configRegisterInt("Game.MemorySize", &g_OsMemSizeMb, 4, 2048);
configRegisterInt("Game.CenterHUD", &g_HudCenter, 0, 2);
configRegisterInt("Game.MenuMouseControl", &g_MenuMouseControl, 0, 1);
configRegisterFloat("Game.ScreenShakeIntensity", &g_ViShakeIntensityMult, 0.f, 10.f);
configRegisterInt("Game.TickRateDivisor", &g_TickRateDiv, 0, 10);
configRegisterInt("Game.ExtraSleep", &g_TickExtraSleep, 0, 1);
+6
View File
@@ -978,6 +978,12 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i
movedata.freelookdy = -movedata.freelookdy;
}
}
// always pause with ESC
if (allowc1buttons && g_Vars.currentplayer->isdead == false && g_Vars.currentplayer->pausemode == PAUSEMODE_UNPAUSED) {
if (inputKeyJustPressed(VK_ESCAPE)) {
c1buttonsthisframe |= START_BUTTON;
}
}
#endif
// Pausing
+129 -11
View File
@@ -50,6 +50,7 @@
#include "types.h"
#ifndef PLATFORM_N64
#include "video.h"
#include "input.h"
#include "net/net.h"
#define BLUR_OFS 10
#else
@@ -137,6 +138,10 @@ char *g_StringPointer2 = &g_CheatMarqueeString[VERSION >= VERSION_PAL_FINAL ? 15
s32 g_MpPlayerNum = 0;
#ifndef PLATFORM_N64
s32 g_MenuMouseControl = true;
#endif
void menuPlaySound(s32 menusound)
{
s32 sound = -1;
@@ -1348,20 +1353,68 @@ s32 dialogChangeItemFocusHorizontally(struct menudialog *dialog, s32 leftright)
return swipedir;
}
s32 dialogChangeItemFocus(struct menudialog *dialog, s32 leftright, s32 updown)
#ifndef PLATFORM_N64
bool dialogChangeItemFocusWithMouse(struct menudialog *dialog, s32 mx, s32 my)
{
struct menu *menu = &g_Menus[g_MpPlayerNum];
s32 col, row;
s32 curx, cury;
s32 colwidth = 0;
// only allow mouse control of player 1 menus
if (menu->playernum != 0) {
return false;
}
curx = dialog->x;
for (col = 0; col < dialog->numcols; col++, curx += colwidth) {
s32 colindex = dialog->colstart + col;
colwidth = menu->cols[colindex].width;
if (mx <= curx || mx >= curx + colwidth) {
continue;
}
cury = dialog->y + LINEHEIGHT + 1 + dialog->scroll;
for (row = 0; row < menu->cols[colindex].numrows; row++) {
s32 rowindex = menu->cols[colindex].rowstart + row;
s32 rowheight = menu->rows[rowindex].height;
struct menuitem *item = &dialog->definition->items[menu->rows[rowindex].itemindex];
if (my > cury && my < cury + rowheight &&
item != dialog->focuseditem && menuIsItemFocusable(item, dialog, 0)) {
dialog->focuseditem = item;
return true;
}
cury += rowheight;
}
}
return false;
}
#endif
s32 dialogChangeItemFocus(struct menudialog *dialog, struct menuinputs *inputs)
{
s32 swipedir = 0;
if (leftright == 0 && updown == 0) {
if (inputs->leftright == 0 && inputs->updown == 0) {
#ifndef PLATFORM_N64
if (!dialogChangeItemFocusWithMouse(dialog, inputs->mousex, inputs->mousey)) {
return 0;
}
#else
return 0;
#endif
}
if (updown != 0) {
dialogChangeItemFocusVertically(dialog, updown);
if (inputs->updown != 0) {
dialogChangeItemFocusVertically(dialog, inputs->updown);
}
if (leftright != 0) {
swipedir = dialogChangeItemFocusHorizontally(dialog, leftright);
if (inputs->leftright != 0) {
swipedir = dialogChangeItemFocusHorizontally(dialog, inputs->leftright);
}
if (dialog->focuseditem != 0) {
@@ -1449,6 +1502,10 @@ void menuOpenDialog(struct menudialogdef *dialogdef, struct menudialog *dialog,
dialog->y = dialog->dsty;
dialog->width = dialog->dstwidth;
dialog->height = dialog->dstheight;
#ifndef PLATFORM_N64
dialog->usingmouse = false;
#endif
}
void menuPushDialog(struct menudialogdef *dialogdef)
@@ -3419,6 +3476,12 @@ void menuClose(void)
g_Menus[g_MpPlayerNum].curdialog = NULL;
g_Menus[g_MpPlayerNum].openinhibit = 10;
#ifndef PLATFORM_N64
if (inputMouseIsEnabled()) {
inputLockMouse(true);
}
#endif
if (g_MenuData.root == MENUROOT_MPPAUSE) {
g_PlayersWithControl[g_Menus[g_MpPlayerNum].playernum] = true;
}
@@ -3526,6 +3589,12 @@ void menuPushRootDialog(struct menudialogdef *dialogdef, s32 root)
g_PlayersWithControl[g_Menus[g_MpPlayerNum].playernum] = false;
#ifndef PLATFORM_N64
if (inputMouseIsEnabled()) {
inputLockMouse(false);
}
#endif
func0f0f1494();
g_MenuData.count++;
@@ -4387,14 +4456,14 @@ void dialogTick(struct menudialog *dialog, struct menuinputs *inputs, u32 tickfl
if (layer->numsiblings <= 1) {
struct menuitem *prevfocuseditem = dialog->focuseditem;
dialogChangeItemFocus(dialog, inputs->leftright, inputs->updown);
dialogChangeItemFocus(dialog, inputs);
if (dialog->focuseditem != prevfocuseditem) {
menuPlaySound(MENUSOUND_FOCUS);
}
} else {
struct menuitem *prevfocuseditem = dialog->focuseditem;
s32 swipedir = dialogChangeItemFocus(dialog, inputs->leftright, inputs->updown);
s32 swipedir = dialogChangeItemFocus(dialog, inputs);
if (swipedir != 0) {
menuSwipe(swipedir);
@@ -4439,8 +4508,15 @@ void dialogTick(struct menudialog *dialog, struct menuinputs *inputs, u32 tickfl
s32 y = dialogFindItem(dialog, dialog->focuseditem, &rowindex, &colindex);
if ((dialog->focuseditem->flags & MENUITEMFLAG_00010000) == 0) {
itemy = y + menu->rows[rowindex].height / 2;
dstscroll = (dialog->height - LINEHEIGHT - 1) / 2 - itemy;
#ifndef PLATFORM_N64
if (dialog->usingmouse) {
dstscroll = dialog->dstscroll - inputs->mousescroll * LINEHEIGHT;
} else
#endif
{
itemy = y + menu->rows[rowindex].height / 2;
dstscroll = (dialog->height - LINEHEIGHT - 1) / 2 - itemy;
}
if (dstscroll > 0) {
dstscroll = 0;
@@ -4588,6 +4664,28 @@ void menuProcessInput(void)
inputs.shoulder = 0;
inputs.back2 = 0;
#ifndef PLATFORM_N64
inputs.mousemoved = false;
inputs.mousescroll = 0;
inputs.mousex = 0;
inputs.mousey = 0;
// only allow mouse controls for player 1 menus
if (menu->playernum == 0) {
// ESC always acts as back
inputs.back = inputKeyJustPressed(VK_ESCAPE);
if (inputMouseIsEnabled() && !inputMouseIsLocked() && g_MenuMouseControl) {
inputs.mousemoved = inputMouseGetPosition(&inputs.mousex, &inputs.mousey);
inputs.mousescroll = inputKeyPressed(VK_MOUSE_WHEEL_DN) - inputKeyPressed(VK_MOUSE_WHEEL_UP);
// aspect correct the X
const f32 cx = ((f32)inputs.mousex - (f32)(SCREEN_WIDTH_LO / 2)) * (videoGetAspect() / SCREEN_ASPECT);
inputs.mousex = (f32)(SCREEN_WIDTH_LO / 2) + cx;
}
if (dialog && inputs.mousemoved) {
dialog->usingmouse = true;
}
}
#endif
if (g_Menus[g_MpPlayerNum].curdialog) {
stickx = 0;
sticky = 0;
@@ -4649,7 +4747,8 @@ void menuProcessInput(void)
inputs.select = 1;
}
if (buttonsnow & BUTTON_WPNBACK) {
// don't back out on weapon back when using mouse because it's likely bound to wheel
if (!dialog->usingmouse && (buttonsnow & BUTTON_WPNBACK)) {
inputs.back = 1;
}
#endif
@@ -4992,6 +5091,25 @@ void menuProcessInput(void)
inputs.unk14 = 0;
inputs.start = starttap ? true : false;
#ifndef PLATFORM_N64
// if we haven't been using the mouse but we have been keyboard scrolling disable the mouse
if (!inputs.mousemoved && (inputs.leftright || inputs.updown || inputs.leftrightheld || inputs.updownheld)) {
dialog->usingmouse = false;
}
// otherwise rotate left/right by clicking on the side of the menu
if (dialog->usingmouse && inputs.select && !inputs.leftright && !inputs.leftrightheld) {
if (inputs.mousey > dialog->y && inputs.mousey < dialog->y + dialog->height) {
if (inputs.mousex < dialog->x) {
inputs.leftright = -1;
inputs.select = 0;
} else if (inputs.mousex > dialog->x + dialog->width) {
inputs.leftright = 1;
inputs.select = 0;
}
}
}
#endif
// Handle dialogs that allow pressing start to select,
// and handle pressing start on a list item.
if (g_Menus[g_MpPlayerNum].curdialog && starttap) {
+6
View File
@@ -732,9 +732,15 @@ bool menuitemListTick(struct menuitem *item, struct menuinputs *inputs, u32 tick
data->list.targetoffsety = menuitemListGetOffsetY(data->list.index, item);
}
#ifdef PLATFORM_N64
if (inputs->updown) {
prev2 = data->list.index;
data->list.index += inputs->updown;
#else
if (inputs->updown || inputs->mousescroll) {
prev2 = data->list.index;
data->list.index += inputs->updown + inputs->mousescroll;
#endif
if (data->list.index < 0) {
data->list.index = handlerdata.list.value - 1;
+9
View File
@@ -26,9 +26,18 @@
#include "lib/snd.h"
#include "data.h"
#include "types.h"
#ifndef PLATFORM_N64
#include "input.h"
#endif
void menuStop(void)
{
#ifndef PLATFORM_N64
if (inputMouseIsEnabled()) {
inputLockMouse(true);
}
#endif
if (var80062944) {
var80062944 = 0;
var80062948 = 0;
+18
View File
@@ -2050,6 +2050,12 @@ void playerTickCutscene(bool arg0)
g_CutsceneCurTotalFrame60f += g_Vars.lvupdate60freal;
}
#ifndef PLATFORM_N64
if (arg0 && inputKeyJustPressed(VK_ESCAPE)) {
buttons |= START_BUTTON;
}
#endif
#if VERSION >= VERSION_NTSC_1_0
if (g_CutsceneCurTotalFrame60f > 30 && (buttons & 0xffffffff)) {
g_CutsceneSkipRequested = true;
@@ -3323,6 +3329,12 @@ void playerTick(bool arg0)
s8 contpad1 = optionsGetContpadNum1(g_Vars.currentplayerstats->mpindex);
u32 buttons = arg0 ? joyGetButtons(contpad1, 0xffffffff) : 0;
#ifndef PLATFORM_N64
if (arg0 && inputKeyJustPressed(VK_ESCAPE)) {
buttons |= START_BUTTON;
}
#endif
if (g_Vars.currentplayer->isdead == false
&& g_Vars.currentplayer->pausemode == PAUSEMODE_UNPAUSED
&& (buttons & START_BUTTON)) {
@@ -3608,6 +3620,12 @@ void playerTick(bool arg0)
}
}
#ifndef PLATFORM_N64
if (g_PlayersWithControl[g_Vars.currentplayernum] && inputKeyJustPressed(VK_ESCAPE)) {
pause = true;
}
#endif
if (pause) {
if (g_Vars.mplayerisrunning == false) {
playerPause(MENUROOT_MAINMENU);
+1
View File
@@ -543,6 +543,7 @@ extern const struct weathercfg *g_CurWeatherConfig;
extern f32 g_ViShakeIntensityMult;
extern u32 g_TexFilter2D;
extern s32 g_HudCenter;
extern s32 g_MenuMouseControl;
extern u32 g_HudAlignModeL;
extern u32 g_HudAlignModeR;
extern s32 g_PrevFrameFb;
+1 -1
View File
@@ -46,7 +46,7 @@ struct menuitem *dialogFindFirstItem(struct menudialog *dialog);
struct menuitem *dialogFindFirstItemRight(struct menudialog *dialog);
void dialogChangeItemFocusVertically(struct menudialog *dialog, s32 updown);
s32 dialogChangeItemFocusHorizontally(struct menudialog *dialog, s32 leftright);
s32 dialogChangeItemFocus(struct menudialog *dialog, s32 leftright, s32 updown);
s32 dialogChangeItemFocus(struct menudialog *dialog, struct menuinputs *inputs);
void menuOpenDialog(struct menudialogdef *dialogdef, struct menudialog *arg1, struct menu *menu);
void menuPushDialog(struct menudialogdef *dialogdef);
+9
View File
@@ -3745,6 +3745,9 @@ struct menudialog {
/*0x6c*/ u8 unk6c;
/*0x6d*/ s8 swipedir;
/*0x6e*/ u8 unk6e;
#ifndef PLATFORM_N64
/*0x6f*/ u8 usingmouse;
#endif
};
struct menudfc {
@@ -5006,6 +5009,12 @@ struct menuinputs {
/*0x0c*/ s32 unk0c;
/*0x10*/ s32 unk10;
/*0x14*/ u8 unk14;
#ifndef PLATFORM_N64
/*0x15*/ u8 mousemoved;
/*0x16*/ s8 mousescroll;
/*0x18*/ s32 mousex;
/*0x1c*/ s32 mousey;
#endif
};
struct mpconfigsim {