diff --git a/port/include/input.h b/port/include/input.h index fb6c410f1..e3ba604ab 100644 --- a/port/include/input.h +++ b/port/include/input.h @@ -95,17 +95,17 @@ s32 inputControllerConnected(s32 idx); // returns bitmask of connected controllers s32 inputControllerMask(void); -s32 inputControllerGetSticksSwapped(void); -void inputControllerSetSticksSwapped(s32 swapped); +s32 inputControllerGetSticksSwapped(s32 cidx); +void inputControllerSetSticksSwapped(s32 cidx, s32 swapped); -s32 inputControllerGetDualAnalog(void); -void inputControllerSetDualAnalog(s32 enable); +s32 inputControllerGetDualAnalog(s32 cidx); +void inputControllerSetDualAnalog(s32 cidx, s32 enable); -f32 inputControllerGetAxisScale(s32 stick, s32 axis); -void inputControllerSetAxisScale(s32 stick, s32 axis, f32 value); +f32 inputControllerGetAxisScale(s32 cidx, s32 stick, s32 axis); +void inputControllerSetAxisScale(s32 cidx, s32 stick, s32 axis, f32 value); -f32 inputControllerGetAxisDeadzone(s32 stick, s32 axis); -void inputControllerSetAxisDeadzone(s32 stick, s32 axis, f32 value); +f32 inputControllerGetAxisDeadzone(s32 cidx, s32 stick, s32 axis); +void inputControllerSetAxisDeadzone(s32 cidx, s32 stick, s32 axis, f32 value); // vk is a value from the virtkey enum above s32 inputKeyPressed(u32 vk); @@ -134,8 +134,8 @@ const char *inputGetContKeyName(u32 ck); // strength is 0 .. 1; 0 strength turns it off void inputRumble(s32 idx, f32 strength, f32 time); -f32 inputRumbleGetStrength(void); -void inputRumbleSetStrength(f32 val); +f32 inputRumbleGetStrength(s32 cidx); +void inputRumbleSetStrength(s32 cidx, f32 val); // locks the mouse cursor in the window and makes it invisible if argument is true void inputLockMouse(s32 lock); diff --git a/port/src/config.c b/port/src/config.c index 4d2383276..5bce419e1 100644 --- a/port/src/config.c +++ b/port/src/config.c @@ -124,7 +124,7 @@ void configRegisterString(const char *key, char *var, u32 maxstr) static void configSetFromString(const char *key, const char *val) { - struct configentry *cfg = configFindOrAddEntry(key); + struct configentry *cfg = configFindEntry(key); if (!cfg) return; s32 tmp_s32; diff --git a/port/src/input.c b/port/src/input.c index deeb9cf0f..7ee49bd10 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 "utils.h" #include "system.h" #define MAX_BIND_STR 256 @@ -20,9 +21,36 @@ #define WHEEL_DN_MASK SDL_BUTTON(VK_MOUSE_WHEEL_DN - VK_MOUSE_BEGIN + 1) static SDL_GameController *pads[INPUT_MAX_CONTROLLERS]; -static s32 rumbleSupported[INPUT_MAX_CONTROLLERS]; -static u32 binds[MAXCONTROLLERS][CK_TOTAL_COUNT][INPUT_MAX_BINDS]; // [i][CK_][b] = [VK_] +#define CONTROLLERCFG_DEFAULT { \ + .rumbleOn = 0, \ + .rumbleScale = 0.5f, \ + .axisMap = { \ + { SDL_CONTROLLER_AXIS_LEFTX, SDL_CONTROLLER_AXIS_LEFTY }, \ + { SDL_CONTROLLER_AXIS_RIGHTX, SDL_CONTROLLER_AXIS_RIGHTY }, \ + }, \ + .sens = { 1.f, 1.f, 1.f, 1.f }, \ + .deadzone = { DEFAULT_DEADZONE, DEFAULT_DEADZONE, DEFAULT_DEADZONE, DEFAULT_DEADZONE_RY }, \ + .stickCButtons = 0, \ + .swapSticks = 1 \ +} + +static struct controllercfg { + s32 rumbleOn; + f32 rumbleScale; + u32 axisMap[2][2]; + f32 sens[4]; + s32 deadzone[4]; + s32 stickCButtons; + s32 swapSticks; +} padsCfg[INPUT_MAX_CONTROLLERS] = { + CONTROLLERCFG_DEFAULT, + CONTROLLERCFG_DEFAULT, + CONTROLLERCFG_DEFAULT, + CONTROLLERCFG_DEFAULT +}; + +static u32 binds[MAXCONTROLLERS][CK_TOTAL_COUNT][INPUT_MAX_BINDS]; static char bindStrs[MAXCONTROLLERS][CK_TOTAL_COUNT][MAX_BIND_STR]; static s32 fakeControllers = 0; @@ -40,30 +68,8 @@ static s32 mouseWheel = 0; static f32 mouseSensX = 1.5f; static f32 mouseSensY = 1.5f; -static f32 rumbleScale = 0.5f; - static s32 lastKey = 0; -// NOTE: by default this gets inverted for 1.2: "right stick" here means left stick on your controller -static u32 axisMap[2][2] = { - { SDL_CONTROLLER_AXIS_LEFTX, SDL_CONTROLLER_AXIS_LEFTY }, - { SDL_CONTROLLER_AXIS_RIGHTX, SDL_CONTROLLER_AXIS_RIGHTY }, -}; - -static f32 stickSens[4] = { - // index == SDL_CONTROLLER_AXIS_* - 1.f, 1.f, 1.f, 1.f -}; - -static s32 deadzone[4] = { - // index == SDL_CONTROLLER_AXIS_* - DEFAULT_DEADZONE, DEFAULT_DEADZONE, - DEFAULT_DEADZONE, DEFAULT_DEADZONE_RY, -}; - -static s32 stickCButtons = 1; -static s32 swapSticks = 1; - static const char *ckNames[CK_TOTAL_COUNT] = { "R_CBUTTONS", "L_CBUTTONS", @@ -215,15 +221,15 @@ static inline void inputInitController(const s32 cidx) { #if SDL_VERSION_ATLEAST(2, 0, 18) // SDL_GameControllerHasRumble() appeared in 2.0.18 even though SDL_GameControllerRumble() is in 2.0.9 - rumbleSupported[cidx] = SDL_GameControllerHasRumble(pads[cidx]); + padsCfg[cidx].rumbleOn = SDL_GameControllerHasRumble(pads[cidx]); #else // assume that all joysticks with haptic feedback support will support rumble - rumbleSupported[cidx] = SDL_JoystickIsHaptic(SDL_GameControllerGetJoystick(pads[cidx])); - if (!rumbleSupported[cidx]) { + padsCfg[cidx].rumbleOn = SDL_JoystickIsHaptic(SDL_GameControllerGetJoystick(pads[cidx])); + if (!padsCfg[cidx].rumbleOn) { // at least on Windows some controllers will report no haptics, but rumble will still function // just assume it's supported if the controller is of known type const SDL_GameControllerType ctype = SDL_GameControllerGetType(pads[cidx]); - rumbleSupported[cidx] = ctype && (ctype != SDL_CONTROLLER_TYPE_VIRTUAL); + padsCfg[cidx].rumbleOn = ctype && (ctype != SDL_CONTROLLER_TYPE_VIRTUAL); } #endif @@ -237,7 +243,7 @@ static inline void inputCloseController(const s32 cidx) { SDL_GameControllerClose(pads[cidx]); pads[cidx] = NULL; - rumbleSupported[cidx] = 0; + padsCfg[cidx].rumbleOn = 0; if (cidx) { connectedMask &= ~(1 << cidx); } @@ -485,12 +491,10 @@ s32 inputInit(void) inputLockMouse(mouseDefaultLocked); - if (swapSticks) { - // invert axis map - axisMap[0][0] = SDL_CONTROLLER_AXIS_RIGHTX; - axisMap[0][1] = SDL_CONTROLLER_AXIS_RIGHTY; - axisMap[1][0] = SDL_CONTROLLER_AXIS_LEFTX; - axisMap[1][1] = SDL_CONTROLLER_AXIS_LEFTY; + // update the axis maps + // NOTE: by default sticks get swapped for 1.2: "right stick" here means left stick on your controller + for (s32 i = 0; i < INPUT_MAX_CONTROLLERS; ++i) { + inputControllerSetSticksSwapped(i, padsCfg[i].swapSticks); } const s32 overrideMask = (1 << fakeControllers) - 1; @@ -556,15 +560,17 @@ s32 inputReadController(s32 idx, OSContPad *npad) return 0; } - s32 leftX = SDL_GameControllerGetAxis(pads[idx], axisMap[0][0]); - s32 leftY = SDL_GameControllerGetAxis(pads[idx], axisMap[0][1]); - s32 rightX = SDL_GameControllerGetAxis(pads[idx], axisMap[1][0]); - s32 rightY = SDL_GameControllerGetAxis(pads[idx], axisMap[1][1]); + const struct controllercfg *cfg = &padsCfg[idx]; - leftX = inputAxisScale(leftX, deadzone[axisMap[0][0]], stickSens[axisMap[0][0]]); - leftY = inputAxisScale(leftY, deadzone[axisMap[0][1]], stickSens[axisMap[0][1]]); - rightX = inputAxisScale(rightX, deadzone[axisMap[1][0]], stickSens[axisMap[1][0]]); - rightY = inputAxisScale(rightY, deadzone[axisMap[1][1]], stickSens[axisMap[1][1]]); + s32 leftX = SDL_GameControllerGetAxis(pads[idx], cfg->axisMap[0][0]); + s32 leftY = SDL_GameControllerGetAxis(pads[idx], cfg->axisMap[0][1]); + s32 rightX = SDL_GameControllerGetAxis(pads[idx], cfg->axisMap[1][0]); + s32 rightY = SDL_GameControllerGetAxis(pads[idx], cfg->axisMap[1][1]); + + leftX = inputAxisScale(leftX, cfg->deadzone[cfg->axisMap[0][0]], cfg->sens[cfg->axisMap[0][0]]); + leftY = inputAxisScale(leftY, cfg->deadzone[cfg->axisMap[0][1]], cfg->sens[cfg->axisMap[0][1]]); + rightX = inputAxisScale(rightX, cfg->deadzone[cfg->axisMap[1][0]], cfg->sens[cfg->axisMap[1][0]]); + rightY = inputAxisScale(rightY, cfg->deadzone[cfg->axisMap[1][1]], cfg->sens[cfg->axisMap[1][1]]); if (!npad->stick_x && leftX) { npad->stick_x = leftX / 0x100; @@ -575,7 +581,7 @@ s32 inputReadController(s32 idx, OSContPad *npad) npad->stick_y = (stickY == 128) ? 127 : stickY; } - if (stickCButtons) { + if (cfg->stickCButtons) { // rstick emulates C buttons if (rightX < -0x4000) npad->button |= L_CBUTTONS; if (rightX > +0x4000) npad->button |= R_CBUTTONS; @@ -649,7 +655,7 @@ s32 inputRumbleSupported(s32 idx) if (idx < 0 || idx >= INPUT_MAX_CONTROLLERS) { return 0; } - return rumbleSupported[idx]; + return padsCfg[idx].rumbleOn; } void inputRumble(s32 idx, f32 strength, f32 time) @@ -658,8 +664,8 @@ void inputRumble(s32 idx, f32 strength, f32 time) return; } - if (rumbleSupported[idx]) { - strength *= rumbleScale; + if (padsCfg[idx].rumbleOn) { + strength *= padsCfg[idx].rumbleScale; if (strength <= 0.f) { strength = 0.f; time = 0.f; @@ -671,14 +677,14 @@ void inputRumble(s32 idx, f32 strength, f32 time) } } -f32 inputRumbleGetStrength(void) +f32 inputRumbleGetStrength(s32 cidx) { - return rumbleScale; + return padsCfg[cidx].rumbleScale; } -void inputRumbleSetStrength(f32 val) +void inputRumbleSetStrength(s32 cidx, f32 val) { - rumbleScale = val; + padsCfg[cidx].rumbleScale = val; } s32 inputControllerMask(void) @@ -686,55 +692,55 @@ s32 inputControllerMask(void) return connectedMask; } -s32 inputControllerGetSticksSwapped(void) +s32 inputControllerGetSticksSwapped(s32 cidx) { - return swapSticks; + return padsCfg[cidx].swapSticks; } -void inputControllerSetSticksSwapped(s32 swapped) +void inputControllerSetSticksSwapped(s32 cidx, s32 swapped) { - swapSticks = swapped; + padsCfg[cidx].swapSticks = swapped; if (swapped) { - axisMap[0][0] = SDL_CONTROLLER_AXIS_RIGHTX; - axisMap[0][1] = SDL_CONTROLLER_AXIS_RIGHTY; - axisMap[1][0] = SDL_CONTROLLER_AXIS_LEFTX; - axisMap[1][1] = SDL_CONTROLLER_AXIS_LEFTY; + padsCfg[cidx].axisMap[0][0] = SDL_CONTROLLER_AXIS_RIGHTX; + padsCfg[cidx].axisMap[0][1] = SDL_CONTROLLER_AXIS_RIGHTY; + padsCfg[cidx].axisMap[1][0] = SDL_CONTROLLER_AXIS_LEFTX; + padsCfg[cidx].axisMap[1][1] = SDL_CONTROLLER_AXIS_LEFTY; } else { - axisMap[0][0] = SDL_CONTROLLER_AXIS_LEFTX; - axisMap[0][1] = SDL_CONTROLLER_AXIS_LEFTY; - axisMap[1][0] = SDL_CONTROLLER_AXIS_RIGHTX; - axisMap[1][1] = SDL_CONTROLLER_AXIS_RIGHTY; + padsCfg[cidx].axisMap[0][0] = SDL_CONTROLLER_AXIS_LEFTX; + padsCfg[cidx].axisMap[0][1] = SDL_CONTROLLER_AXIS_LEFTY; + padsCfg[cidx].axisMap[1][0] = SDL_CONTROLLER_AXIS_RIGHTX; + padsCfg[cidx].axisMap[1][1] = SDL_CONTROLLER_AXIS_RIGHTY; } } -s32 inputControllerGetDualAnalog(void) +s32 inputControllerGetDualAnalog(s32 cidx) { - return !stickCButtons; + return !padsCfg[cidx].stickCButtons; } -void inputControllerSetDualAnalog(s32 enable) +void inputControllerSetDualAnalog(s32 cidx, s32 enable) { - stickCButtons = !enable; + padsCfg[cidx].stickCButtons = !enable; } -f32 inputControllerGetAxisScale(s32 stick, s32 axis) +f32 inputControllerGetAxisScale(s32 cidx, s32 stick, s32 axis) { - return stickSens[stick * 2 + axis]; + return padsCfg[cidx].sens[stick * 2 + axis]; } -void inputControllerSetAxisScale(s32 stick, s32 axis, f32 value) +void inputControllerSetAxisScale(s32 cidx, s32 stick, s32 axis, f32 value) { - stickSens[stick * 2 + axis] = value; + padsCfg[cidx].sens[stick * 2 + axis] = value; } -f32 inputControllerGetAxisDeadzone(s32 stick, s32 axis) +f32 inputControllerGetAxisDeadzone(s32 cidx, s32 stick, s32 axis) { - return (f32)deadzone[stick * 2 + axis] / 32767.f; + return (f32)padsCfg[cidx].deadzone[stick * 2 + axis] / 32767.f; } -void inputControllerSetAxisDeadzone(s32 stick, s32 axis, f32 value) +void inputControllerSetAxisDeadzone(s32 cidx, s32 stick, s32 axis, f32 value) { - deadzone[stick * 2 + axis] = value * 32767.f; + padsCfg[cidx].deadzone[stick * 2 + axis] = value * 32767.f; } void inputKeyBind(s32 idx, u32 ck, s32 bind, u32 vk) @@ -977,22 +983,6 @@ PD_CONSTRUCTOR static void inputConfigInit(void) configRegisterInt("Input.MouseDefaultLocked", &mouseDefaultLocked, 0, 1); configRegisterFloat("Input.MouseSpeedX", &mouseSensX, -10.f, 10.f); configRegisterFloat("Input.MouseSpeedY", &mouseSensY, -10.f, 10.f); - - configRegisterFloat("Input.RumbleScale", &rumbleScale, 0.f, 1.f); - - configRegisterInt("Input.LStickDeadzoneX", &deadzone[0], 0, 32767); - configRegisterInt("Input.LStickDeadzoneY", &deadzone[1], 0, 32767); - configRegisterInt("Input.RStickDeadzoneX", &deadzone[2], 0, 32767); - configRegisterInt("Input.RStickDeadzoneY", &deadzone[3], 0, 32767); - - configRegisterFloat("Input.LStickScaleX", &stickSens[0], -10.f, 10.f); - configRegisterFloat("Input.LStickScaleY", &stickSens[1], -10.f, 10.f); - configRegisterFloat("Input.RStickScaleX", &stickSens[2], -10.f, 10.f); - configRegisterFloat("Input.RStickScaleY", &stickSens[3], -10.f, 10.f); - - configRegisterInt("Input.StickCButtons", &stickCButtons, 0, 1); - configRegisterInt("Input.SwapSticks", &swapSticks, 0, 1); - configRegisterInt("Input.FakeGamepads", &fakeControllers, 0, 4); configRegisterInt("Input.FirstGamepadNum", &firstController, 0, 3); @@ -1000,6 +990,19 @@ PD_CONSTRUCTOR static void inputConfigInit(void) char keyname[256] = { 0 }; for (s32 c = 0; c < MAXCONTROLLERS; ++c) { secname[12] = '1' + c; + secname[13] = '\0'; + configRegisterFloat(strFmt("%s.RumbleScale", secname), &padsCfg[c].rumbleScale, 0.f, 1.f); + configRegisterInt(strFmt("%s.LStickDeadzoneX", secname), &padsCfg[c].deadzone[0], 0, 32767); + configRegisterInt(strFmt("%s.LStickDeadzoneY", secname), &padsCfg[c].deadzone[1], 0, 32767); + configRegisterInt(strFmt("%s.RStickDeadzoneX", secname), &padsCfg[c].deadzone[2], 0, 32767); + configRegisterInt(strFmt("%s.RStickDeadzoneY", secname), &padsCfg[c].deadzone[3], 0, 32767); + configRegisterFloat(strFmt("%s.LStickScaleX", secname), &padsCfg[c].sens[0], -10.f, 10.f); + configRegisterFloat(strFmt("%s.LStickScaleY", secname), &padsCfg[c].sens[1], -10.f, 10.f); + configRegisterFloat(strFmt("%s.RStickScaleX", secname), &padsCfg[c].sens[2], -10.f, 10.f); + configRegisterFloat(strFmt("%s.RStickScaleY", secname), &padsCfg[c].sens[3], -10.f, 10.f); + configRegisterInt(strFmt("%s.StickCButtons", secname), &padsCfg[c].stickCButtons, 0, 1); + configRegisterInt(strFmt("%s.SwapSticks", secname), &padsCfg[c].swapSticks, 0, 1); + secname[13] = '.'; for (u32 ck = 0; ck < CK_TOTAL_COUNT; ++ck) { snprintf(keyname, sizeof(keyname), "%s.%s", secname, inputGetContKeyName(ck)); configRegisterString(keyname, bindStrs[c][ck], MAX_BIND_STR); diff --git a/port/src/main.c b/port/src/main.c index 9e850c02a..7e6d059f4 100644 --- a/port/src/main.c +++ b/port/src/main.c @@ -16,6 +16,7 @@ #include "config.h" #include "mod.h" #include "system.h" +#include "utils.h" u32 g_OsMemSize = 0; s32 g_OsMemSizeMb = 16; @@ -57,10 +58,15 @@ void bootCreateSched(void) } } -static void gameLoadConfig(void) +static void gameInit(void) { osMemSize = g_OsMemSizeMb * 1024 * 1024; - g_PlayerFovZoomMultiplier = g_PlayerFovAffectsZoom ? g_PlayerDefaultFovY / 60.0f : 1.0f; + + for (s32 i = 0; i < MAX_PLAYERS; ++i) { + struct extplayerconfig *cfg = g_PlayerExtCfg + i; + cfg->fovzoommult = cfg->fovzoom ? cfg->fovy / 60.0f : 1.0f; + } + if (g_HudCenter) { g_HudAlignModeL = G_ASPECT_CENTER_EXT; g_HudAlignModeR = G_ASPECT_CENTER_EXT; @@ -92,7 +98,7 @@ int main(int argc, const char **argv) audioInit(); romdataInit(); - gameLoadConfig(); + gameInit(); if (fsGetModDir()) { modConfigLoad(MOD_CONFIG_FNAME); @@ -127,19 +133,17 @@ int main(int argc, const char **argv) PD_CONSTRUCTOR static void gameConfigInit(void) { configRegisterInt("Game.MemorySize", &g_OsMemSizeMb, 4, 2048); - - configRegisterFloat("Game.FovY", &g_PlayerDefaultFovY, 5.f, 175.f); - configRegisterInt("Game.FovAffectsZoom", &g_PlayerFovAffectsZoom, 0, 1); - - configRegisterInt("Game.MouseAimMode", &g_PlayerMouseAimMode, 0, 1); - configRegisterFloat("Game.MouseAimSpeedX", &g_PlayerMouseAimSpeedX, 0.f, 10.f); - configRegisterFloat("Game.MouseAimSpeedY", &g_PlayerMouseAimSpeedY, 0.f, 10.f); - - configRegisterFloat("Game.RadialMenuSpeed", &g_PlayerRadialMenuSpeed, 0.f, 10.f); - configRegisterFloat("Game.CrosshairSway", &g_PlayerCrosshairSway, 0.f, 10.f); - configRegisterFloat("Game.ScreenShakeIntensity", &g_ViShakeIntensityMult, 0.f, 10.f); - - configRegisterInt("Game.ClassicCrouch", &g_PlayerClassicCrouch, 0, 1); - configRegisterInt("Game.CenterHUD", &g_HudCenter, 0, 1); + configRegisterFloat("Game.ScreenShakeIntensity", &g_ViShakeIntensityMult, 0.f, 10.f); + for (s32 j = 0; j < MAX_PLAYERS; ++j) { + const s32 i = j + 1; + configRegisterFloat(strFmt("Game.Player%d.FovY", i), &g_PlayerExtCfg[j].fovy, 5.f, 175.f); + configRegisterInt(strFmt("Game.Player%d.FovAffectsZoom", i), &g_PlayerExtCfg[j].fovzoom, 0, 1); + configRegisterInt(strFmt("Game.Player%d.MouseAimMode", i), &g_PlayerExtCfg[j].mouseaimmode, 0, 1); + configRegisterFloat(strFmt("Game.Player%d.MouseAimSpeedX", i), &g_PlayerExtCfg[j].mouseaimspeedx, 0.f, 10.f); + configRegisterFloat(strFmt("Game.Player%d.MouseAimSpeedY", i), &g_PlayerExtCfg[j].mouseaimspeedy, 0.f, 10.f); + configRegisterFloat(strFmt("Game.Player%d.RadialMenuSpeed", i), &g_PlayerExtCfg[j].radialmenuspeed, 0.f, 10.f); + configRegisterFloat(strFmt("Game.Player%d.CrosshairSway", i), &g_PlayerExtCfg[j].crosshairsway, 0.f, 10.f); + configRegisterInt(strFmt("Game.Player%d.ClassicCrouch", i), &g_PlayerExtCfg[j].classiccrouch, 0, 1); + } } diff --git a/port/src/optionsmenu.c b/port/src/optionsmenu.c index 250388f5c..4e428071c 100644 --- a/port/src/optionsmenu.c +++ b/port/src/optionsmenu.c @@ -11,10 +11,85 @@ #include "input.h" #include "config.h" -static s32 g_BindsPlayer = 0; +static s32 g_ExtMenuPlayer = 0; +static struct menudialogdef *g_ExtNextDialog = NULL; + static s32 g_BindIndex = 0; static u32 g_BindContKey = 0; -static char g_BindsPlayerText[] = "Player 1 Bindings"; + +static MenuItemHandlerResult menuhandlerSelectPlayer(s32 operation, struct menuitem *item, union handlerdata *data); + +struct menuitem g_ExtendedSelectPlayerMenuItems[] = { + { + MENUITEMTYPE_SELECTABLE, + 0, + MENUITEMFLAG_LITERAL_TEXT, + (uintptr_t)"Player 1\n", + 0, + menuhandlerSelectPlayer, + }, + { + MENUITEMTYPE_SELECTABLE, + 0, + MENUITEMFLAG_LITERAL_TEXT, + (uintptr_t)"Player 2\n", + 0, + menuhandlerSelectPlayer, + }, + { + MENUITEMTYPE_SELECTABLE, + 0, + MENUITEMFLAG_LITERAL_TEXT, + (uintptr_t)"Player 3\n", + 0, + menuhandlerSelectPlayer, + }, + { + MENUITEMTYPE_SELECTABLE, + 0, + MENUITEMFLAG_LITERAL_TEXT, + (uintptr_t)"Player 4\n", + 0, + menuhandlerSelectPlayer, + }, + { + MENUITEMTYPE_SEPARATOR, + 0, + 0, + 0, + 0, + NULL, + }, + { + MENUITEMTYPE_SELECTABLE, + 0, + MENUITEMFLAG_SELECTABLE_CLOSESDIALOG, + L_OPTIONS_213, // "Back" + 0, + NULL, + }, + { MENUITEMTYPE_END }, +}; + +struct menudialogdef g_ExtendedSelectPlayerMenuDialog = { + MENUDIALOGTYPE_DEFAULT, + (uintptr_t)"Select Player", + g_ExtendedSelectPlayerMenuItems, + NULL, + MENUDIALOGFLAG_LITERAL_TEXT, + NULL, +}; + +static MenuItemHandlerResult menuhandlerSelectPlayer(s32 operation, struct menuitem *item, union handlerdata *data) +{ + if (operation == MENUOP_SET) { + g_ExtMenuPlayer = item - g_ExtendedSelectPlayerMenuItems; + ((char *)g_ExtNextDialog->title)[7] = g_ExtMenuPlayer + '1'; + menuPushDialog(g_ExtNextDialog); + } + + return 0; +} static MenuItemHandlerResult menuhandlerMouseEnabled(s32 operation, struct menuitem *item, union handlerdata *data) { @@ -33,9 +108,9 @@ static MenuItemHandlerResult menuhandlerMouseAimLock(s32 operation, struct menui { switch (operation) { case MENUOP_GET: - return g_PlayerMouseAimMode; + return g_PlayerExtCfg[g_ExtMenuPlayer].mouseaimmode; case MENUOP_SET: - g_PlayerMouseAimMode = data->checkbox.value; + g_PlayerExtCfg[g_ExtMenuPlayer].mouseaimmode = data->checkbox.value; break; } @@ -107,16 +182,16 @@ static MenuItemHandlerResult menuhandlerMouseAimSpeedX(s32 operation, struct men { switch (operation) { case MENUOP_GETSLIDER: - if (g_PlayerMouseAimSpeedX < 0.f) { + if (g_PlayerExtCfg[g_ExtMenuPlayer].mouseaimspeedx < 0.f) { data->slider.value = 0; - } else if (g_PlayerMouseAimSpeedX > 10.f) { + } else if (g_PlayerExtCfg[g_ExtMenuPlayer].mouseaimspeedx > 10.f) { data->slider.value = 100; } else { - data->slider.value = g_PlayerMouseAimSpeedX * 10.f + 0.5f; + data->slider.value = g_PlayerExtCfg[g_ExtMenuPlayer].mouseaimspeedx * 10.f + 0.5f; } break; case MENUOP_SET: - g_PlayerMouseAimSpeedX = (f32)data->slider.value / 10.f; + g_PlayerExtCfg[g_ExtMenuPlayer].mouseaimspeedx = (f32)data->slider.value / 10.f; break; } @@ -127,16 +202,16 @@ static MenuItemHandlerResult menuhandlerMouseAimSpeedY(s32 operation, struct men { switch (operation) { case MENUOP_GETSLIDER: - if (g_PlayerMouseAimSpeedY < 0.f) { + if (g_PlayerExtCfg[g_ExtMenuPlayer].mouseaimspeedy < 0.f) { data->slider.value = 0; - } else if (g_PlayerMouseAimSpeedY > 10.f) { + } else if (g_PlayerExtCfg[g_ExtMenuPlayer].mouseaimspeedy > 10.f) { data->slider.value = 100; } else { - data->slider.value = g_PlayerMouseAimSpeedY * 10.f + 0.5f; + data->slider.value = g_PlayerExtCfg[g_ExtMenuPlayer].mouseaimspeedy * 10.f + 0.5f; } break; case MENUOP_SET: - g_PlayerMouseAimSpeedY = (f32)data->slider.value / 10.f; + g_PlayerExtCfg[g_ExtMenuPlayer].mouseaimspeedy = (f32)data->slider.value / 10.f; break; } @@ -147,23 +222,22 @@ static MenuItemHandlerResult menuhandlerRadialMenuSpeed(s32 operation, struct me { switch (operation) { case MENUOP_GETSLIDER: - if (g_PlayerRadialMenuSpeed < 0.f) { + if (g_PlayerExtCfg[0].radialmenuspeed < 0.f) { data->slider.value = 0; - } else if (g_PlayerRadialMenuSpeed> 10.f) { + } else if (g_PlayerExtCfg[0].radialmenuspeed > 10.f) { data->slider.value = 100; } else { - data->slider.value = g_PlayerRadialMenuSpeed * 10.f + 0.5f; + data->slider.value = g_PlayerExtCfg[0].radialmenuspeed * 10.f + 0.5f; } break; case MENUOP_SET: - g_PlayerRadialMenuSpeed = (f32)data->slider.value / 10.f; + g_PlayerExtCfg[0].radialmenuspeed = (f32)data->slider.value / 10.f; break; } return 0; } - struct menuitem g_ExtendedMouseMenuItems[] = { { MENUITEMTYPE_CHECKBOX, @@ -368,10 +442,10 @@ static MenuItemHandlerResult menuhandlerStickSpeed(s32 operation, struct menuite switch (operation) { case MENUOP_GETSLIDER: - data->slider.value = inputControllerGetAxisScale(stick, axis) * 10.f + 0.5f; + data->slider.value = inputControllerGetAxisScale(g_ExtMenuPlayer, stick, axis) * 10.f + 0.5f; break; case MENUOP_SET: - inputControllerSetAxisScale(stick, axis, (f32)data->slider.value / 10.f); + inputControllerSetAxisScale(g_ExtMenuPlayer, stick, axis, (f32)data->slider.value / 10.f); break; } @@ -386,10 +460,10 @@ static MenuItemHandlerResult menuhandlerStickDeadzone(s32 operation, struct menu switch (operation) { case MENUOP_GETSLIDER: - data->slider.value = inputControllerGetAxisDeadzone(stick, axis) * 32.f + 0.5f; + data->slider.value = inputControllerGetAxisDeadzone(g_ExtMenuPlayer, stick, axis) * 32.f + 0.5f; break; case MENUOP_SET: - inputControllerSetAxisDeadzone(stick, axis, (f32)data->slider.value / 32.f); + inputControllerSetAxisDeadzone(g_ExtMenuPlayer, stick, axis, (f32)data->slider.value / 32.f); break; } @@ -409,10 +483,10 @@ static MenuItemHandlerResult menuhandlerVibration(s32 operation, struct menuitem { switch (operation) { case MENUOP_GETSLIDER: - data->slider.value = inputRumbleGetStrength() * 10.f + 0.5f; + data->slider.value = inputRumbleGetStrength(g_ExtMenuPlayer) * 10.f + 0.5f; break; case MENUOP_SET: - inputRumbleSetStrength((f32)data->slider.value / 10.f); + inputRumbleSetStrength(g_ExtMenuPlayer, (f32)data->slider.value / 10.f); break; } @@ -423,9 +497,9 @@ static MenuItemHandlerResult menuhandlerAnalogMovement(s32 operation, struct men { switch (operation) { case MENUOP_GET: - return inputControllerGetDualAnalog(); + return inputControllerGetDualAnalog(g_ExtMenuPlayer); case MENUOP_SET: - inputControllerSetDualAnalog(data->checkbox.value); + inputControllerSetDualAnalog(g_ExtMenuPlayer, data->checkbox.value); break; } @@ -436,9 +510,9 @@ static MenuItemHandlerResult menuhandlerSwapSticks(s32 operation, struct menuite { switch (operation) { case MENUOP_GET: - return inputControllerGetSticksSwapped(); + return inputControllerGetSticksSwapped(g_ExtMenuPlayer); case MENUOP_SET: - inputControllerSetSticksSwapped(data->checkbox.value); + inputControllerSetSticksSwapped(g_ExtMenuPlayer, data->checkbox.value); break; } @@ -497,9 +571,10 @@ struct menuitem g_ExtendedControllerMenuItems[] = { { MENUITEMTYPE_END }, }; +static char g_ExtendedControllerMenuTitle[] = "Player 1 Controller Options"; struct menudialogdef g_ExtendedControllerMenuDialog = { MENUDIALOGTYPE_DEFAULT, - (uintptr_t)"Extended Controller Options", + (uintptr_t)g_ExtendedControllerMenuTitle, g_ExtendedControllerMenuItems, NULL, MENUDIALOGFLAG_LITERAL_TEXT, @@ -565,26 +640,21 @@ static MenuItemHandlerResult menuhandlerCenterHUD(s32 operation, struct menuitem return 0; } -static MenuItemHandlerResult menuhandlerFieldOfView(s32 operation, struct menuitem *item, union handlerdata *data) +static MenuItemHandlerResult menuhandlerScreenShake(s32 operation, struct menuitem *item, union handlerdata *data) { switch (operation) { case MENUOP_GETSLIDER: - data->slider.value = g_PlayerDefaultFovY + 0.5f; + data->slider.value = g_ViShakeIntensityMult * 10.f + 0.5f; break; case MENUOP_SET: - if (data->slider.value >= 15) { - g_PlayerDefaultFovY = data->slider.value; - if (g_PlayerFovAffectsZoom) { - g_PlayerFovZoomMultiplier = g_PlayerDefaultFovY / 60.0f; - } - } + g_ViShakeIntensityMult = (f32)data->slider.value / 10.f; break; } return 0; } -struct menuitem g_ExtendedDisplayMenuItems[] = { +struct menuitem g_ExtendedVideoMenuItems[] = { { MENUITEMTYPE_CHECKBOX, 0, @@ -617,100 +687,6 @@ struct menuitem g_ExtendedDisplayMenuItems[] = { 0, menuhandlerCenterHUD, }, - { - MENUITEMTYPE_SLIDER, - 0, - MENUITEMFLAG_LITERAL_TEXT, - (uintptr_t)"Vert FOV", - 170, - menuhandlerFieldOfView, - }, - { - MENUITEMTYPE_SEPARATOR, - 0, - 0, - 0, - 0, - NULL, - }, - { - MENUITEMTYPE_SELECTABLE, - 0, - MENUITEMFLAG_SELECTABLE_CLOSESDIALOG, - L_OPTIONS_213, // "Back" - 0, - NULL, - }, - { MENUITEMTYPE_END }, -}; - -struct menudialogdef g_ExtendedDisplayMenuDialog = { - MENUDIALOGTYPE_DEFAULT, - (uintptr_t)"Extended Display Options", - g_ExtendedDisplayMenuItems, - NULL, - MENUDIALOGFLAG_LITERAL_TEXT, - NULL, -}; - -static MenuItemHandlerResult menuhandlerClassicCrouch(s32 operation, struct menuitem *item, union handlerdata *data) -{ - switch (operation) { - case MENUOP_GET: - return g_PlayerClassicCrouch; - case MENUOP_SET: - g_PlayerClassicCrouch = data->checkbox.value; - break; - } - - return 0; -} - -static MenuItemHandlerResult menuhandlerCrosshairSway(s32 operation, struct menuitem *item, union handlerdata *data) -{ - switch (operation) { - case MENUOP_GETSLIDER: - data->slider.value = g_PlayerCrosshairSway * 10.f + 0.5f; - break; - case MENUOP_SET: - g_PlayerCrosshairSway = (f32)data->slider.value / 10.f; - break; - } - - return 0; -} - -static MenuItemHandlerResult menuhandlerScreenShake(s32 operation, struct menuitem *item, union handlerdata *data) -{ - switch (operation) { - case MENUOP_GETSLIDER: - data->slider.value = g_ViShakeIntensityMult * 10.f + 0.5f; - break; - case MENUOP_SET: - g_ViShakeIntensityMult = (f32)data->slider.value / 10.f; - break; - } - - return 0; -} - -struct menuitem g_ExtendedGameMenuItems[] = { - { - MENUITEMTYPE_CHECKBOX, - 0, - MENUITEMFLAG_LITERAL_TEXT, - (uintptr_t)"Allow Classic Crouch", - 0, - menuhandlerClassicCrouch, - }, - { - MENUITEMTYPE_SLIDER, - 0, - MENUITEMFLAG_LITERAL_TEXT | MENUITEMFLAG_SLIDER_WIDE, - (uintptr_t)"Crosshair Sway", - 20, - menuhandlerCrosshairSway, - }, { MENUITEMTYPE_SLIDER, 0, @@ -738,9 +714,109 @@ struct menuitem g_ExtendedGameMenuItems[] = { { MENUITEMTYPE_END }, }; +struct menudialogdef g_ExtendedVideoMenuDialog = { + MENUDIALOGTYPE_DEFAULT, + (uintptr_t)"Extended Video Options", + g_ExtendedVideoMenuItems, + NULL, + MENUDIALOGFLAG_LITERAL_TEXT, + NULL, +}; + +static MenuItemHandlerResult menuhandlerFieldOfView(s32 operation, struct menuitem *item, union handlerdata *data) +{ + switch (operation) { + case MENUOP_GETSLIDER: + data->slider.value = g_PlayerExtCfg[g_ExtMenuPlayer].fovy + 0.5f; + break; + case MENUOP_SET: + if (data->slider.value >= 15) { + g_PlayerExtCfg[g_ExtMenuPlayer].fovy = data->slider.value; + if (g_PlayerExtCfg[g_ExtMenuPlayer].fovzoom) { + g_PlayerExtCfg[g_ExtMenuPlayer].fovzoommult = g_PlayerExtCfg[g_ExtMenuPlayer].fovy / 60.f; + } + } + break; + } + + return 0; +} + +static MenuItemHandlerResult menuhandlerClassicCrouch(s32 operation, struct menuitem *item, union handlerdata *data) +{ + switch (operation) { + case MENUOP_GET: + return g_PlayerExtCfg[g_ExtMenuPlayer].classiccrouch; + case MENUOP_SET: + g_PlayerExtCfg[g_ExtMenuPlayer].classiccrouch = data->checkbox.value; + break; + } + + return 0; +} + +static MenuItemHandlerResult menuhandlerCrosshairSway(s32 operation, struct menuitem *item, union handlerdata *data) +{ + switch (operation) { + case MENUOP_GETSLIDER: + data->slider.value = g_PlayerExtCfg[g_ExtMenuPlayer].crosshairsway * 10.f + 0.5f; + break; + case MENUOP_SET: + g_PlayerExtCfg[g_ExtMenuPlayer].crosshairsway = (f32)data->slider.value / 10.f; + break; + } + + return 0; +} + +struct menuitem g_ExtendedGameMenuItems[] = { + { + MENUITEMTYPE_CHECKBOX, + 0, + MENUITEMFLAG_LITERAL_TEXT, + (uintptr_t)"Allow Classic Crouch", + 0, + menuhandlerClassicCrouch, + }, + { + MENUITEMTYPE_SLIDER, + 0, + MENUITEMFLAG_LITERAL_TEXT, + (uintptr_t)"Vert FOV", + 170, + menuhandlerFieldOfView, + }, + { + MENUITEMTYPE_SLIDER, + 0, + MENUITEMFLAG_LITERAL_TEXT | MENUITEMFLAG_SLIDER_WIDE, + (uintptr_t)"Crosshair Sway", + 20, + menuhandlerCrosshairSway, + }, + { + MENUITEMTYPE_SEPARATOR, + 0, + 0, + 0, + 0, + NULL, + }, + { + MENUITEMTYPE_SELECTABLE, + 0, + MENUITEMFLAG_SELECTABLE_CLOSESDIALOG, + L_OPTIONS_213, // "Back" + 0, + NULL, + }, + { MENUITEMTYPE_END }, +}; + +static char g_ExtendedGameMenuTitle[] = "Player 1 Game Options"; struct menudialogdef g_ExtendedGameMenuDialog = { MENUDIALOGTYPE_DEFAULT, - (uintptr_t)"Extended Game Options", + (uintptr_t)g_ExtendedGameMenuTitle, g_ExtendedGameMenuItems, NULL, MENUDIALOGFLAG_LITERAL_TEXT, @@ -891,7 +967,7 @@ static MenuItemHandlerResult menuhandlerDoBind(s32 operation, struct menuitem *i const s32 key = inputGetLastKey(); if (key && key != VK_ESCAPE) { - inputKeyBind(g_BindsPlayer, g_BindContKey, g_BindIndex, (key == VK_DELETE ? 0 : key)); + inputKeyBind(g_ExtMenuPlayer, g_BindContKey, g_BindIndex, (key == VK_DELETE ? 0 : key)); menuPopDialog(); } @@ -915,7 +991,7 @@ static MenuItemHandlerResult menuhandlerBind(s32 operation, struct menuitem *ite data->dropdown.value = INPUT_MAX_BINDS; break; case MENUOP_GETOPTIONTEXT: - binds = inputKeyGetBinds(g_BindsPlayer, menuBinds[idx].ck); + binds = inputKeyGetBinds(g_ExtMenuPlayer, menuBinds[idx].ck); if (binds && binds[data->dropdown.value]) { strncpy(keyname, inputGetKeyName(binds[data->dropdown.value]), sizeof(keyname) - 1); for (char *p = keyname; *p; ++p) { @@ -947,97 +1023,51 @@ static MenuItemHandlerResult menuhandlerResetBinds(s32 operation, struct menuite return 0; } +static char g_ExtendedBindsMenuTitle[] = "Player 1 Bindings"; struct menudialogdef g_ExtendedBindsMenuDialog = { MENUDIALOGTYPE_DEFAULT, - (uintptr_t)g_BindsPlayerText, + (uintptr_t)g_ExtendedBindsMenuTitle, g_ExtendedBindsMenuItems, NULL, MENUDIALOGFLAG_LITERAL_TEXT | MENUDIALOGFLAG_STARTSELECTS | MENUDIALOGFLAG_IGNOREBACK, NULL, }; -static MenuItemHandlerResult menuhandlerOpenBinds(s32 operation, struct menuitem *item, union handlerdata *data); - -struct menuitem g_ExtendedSelectBindsMenuItems[] = { - { - MENUITEMTYPE_SELECTABLE, - 0, - MENUITEMFLAG_LITERAL_TEXT, - (uintptr_t)"Player 1\n", - 0, - menuhandlerOpenBinds, - }, - { - MENUITEMTYPE_SELECTABLE, - 0, - MENUITEMFLAG_LITERAL_TEXT, - (uintptr_t)"Player 2\n", - 0, - menuhandlerOpenBinds, - }, - { - MENUITEMTYPE_SELECTABLE, - 0, - MENUITEMFLAG_LITERAL_TEXT, - (uintptr_t)"Player 3\n", - 0, - menuhandlerOpenBinds, - }, - { - MENUITEMTYPE_SELECTABLE, - 0, - MENUITEMFLAG_LITERAL_TEXT, - (uintptr_t)"Player 4\n", - 0, - menuhandlerOpenBinds, - }, - { - MENUITEMTYPE_SEPARATOR, - 0, - 0, - 0, - 0, - NULL, - }, - { - MENUITEMTYPE_SELECTABLE, - 0, - MENUITEMFLAG_SELECTABLE_CLOSESDIALOG, - L_OPTIONS_213, // "Back" - 0, - NULL, - }, - { MENUITEMTYPE_END }, -}; - -static MenuItemHandlerResult menuhandlerOpenBinds(s32 operation, struct menuitem *item, union handlerdata *data) +static MenuItemHandlerResult menuhandlerOpenControllerMenu(s32 operation, struct menuitem *item, union handlerdata *data) { if (operation == MENUOP_SET) { - g_BindsPlayer = item - g_ExtendedSelectBindsMenuItems; - g_BindsPlayerText[7] = g_BindsPlayer + '1'; - menuPushDialog(&g_ExtendedBindsMenuDialog); + g_ExtNextDialog = &g_ExtendedControllerMenuDialog; + menuPushDialog(&g_ExtendedSelectPlayerMenuDialog); } - return 0; } -struct menudialogdef g_ExtendedSelectBindsMenuDialog = { - MENUDIALOGTYPE_DEFAULT, - (uintptr_t)"Key Bindings", - g_ExtendedSelectBindsMenuItems, - NULL, - MENUDIALOGFLAG_LITERAL_TEXT, - NULL, -}; +static MenuItemHandlerResult menuhandlerOpenGameMenu(s32 operation, struct menuitem *item, union handlerdata *data) +{ + if (operation == MENUOP_SET) { + g_ExtNextDialog = &g_ExtendedGameMenuDialog; + menuPushDialog(&g_ExtendedSelectPlayerMenuDialog); + } + return 0; +} + +static MenuItemHandlerResult menuhandlerOpenBindsMenu(s32 operation, struct menuitem *item, union handlerdata *data) +{ + if (operation == MENUOP_SET) { + g_ExtNextDialog = &g_ExtendedBindsMenuDialog; + menuPushDialog(&g_ExtendedSelectPlayerMenuDialog); + } + return 0; +} struct menuitem g_ExtendedMenuItems[] = { { MENUITEMTYPE_SELECTABLE, 0, MENUITEMFLAG_SELECTABLE_OPENSDIALOG | MENUITEMFLAG_LITERAL_TEXT, - (uintptr_t)"Display\n", + (uintptr_t)"Video\n", 0, - (void *)&g_ExtendedDisplayMenuDialog, + (void *)&g_ExtendedVideoMenuDialog, }, { MENUITEMTYPE_SELECTABLE, @@ -1050,26 +1080,26 @@ struct menuitem g_ExtendedMenuItems[] = { { MENUITEMTYPE_SELECTABLE, 0, - MENUITEMFLAG_SELECTABLE_OPENSDIALOG | MENUITEMFLAG_LITERAL_TEXT, + MENUITEMFLAG_LITERAL_TEXT, (uintptr_t)"Controller\n", 0, - (void *)&g_ExtendedControllerMenuDialog, + menuhandlerOpenControllerMenu, }, { MENUITEMTYPE_SELECTABLE, 0, - MENUITEMFLAG_SELECTABLE_OPENSDIALOG | MENUITEMFLAG_LITERAL_TEXT, + MENUITEMFLAG_LITERAL_TEXT, (uintptr_t)"Game\n", 0, - (void *)&g_ExtendedGameMenuDialog, + menuhandlerOpenGameMenu, }, { MENUITEMTYPE_SELECTABLE, 0, - MENUITEMFLAG_SELECTABLE_OPENSDIALOG | MENUITEMFLAG_LITERAL_TEXT, + MENUITEMFLAG_LITERAL_TEXT, (uintptr_t)"Key Bindings\n", 0, - (void *)&g_ExtendedSelectBindsMenuDialog, + menuhandlerOpenBindsMenu, }, { MENUITEMTYPE_SEPARATOR, diff --git a/src/game/activemenutick.c b/src/game/activemenutick.c index 4424926cc..29d09993b 100644 --- a/src/game/activemenutick.c +++ b/src/game/activemenutick.c @@ -13,6 +13,7 @@ #include "data.h" #include "types.h" #ifndef PLATFORM_N64 +#include "game/player.h" #include "input.h" #endif @@ -80,8 +81,8 @@ void amTick(void) struct activemenu *am = &g_AmMenus[g_AmIndex]; inputMouseGetAbsScaledDelta(&mdx, &mdy); if (mdx || mdy) { - am->mousex += mdx * g_PlayerRadialMenuSpeed; - am->mousey += mdy * g_PlayerRadialMenuSpeed; + am->mousex += mdx * PLAYER_EXTCFG().radialmenuspeed; + am->mousey += mdy * PLAYER_EXTCFG().radialmenuspeed; 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; } diff --git a/src/game/bondgun.c b/src/game/bondgun.c index 44da94a36..c7b3b4048 100644 --- a/src/game/bondgun.c +++ b/src/game/bondgun.c @@ -7516,12 +7516,12 @@ void bgunCreateFx(struct hand *hand, s32 handnum, struct weaponfunc *funcdef, s3 static inline f32 bgunGetFovOffsetZ(void) { - return (g_PlayerDefaultFovY - 60.f) / 3.f; + return (PLAYER_DEFAULT_FOV - 60.f) / 3.f; } static inline f32 bgunGetFovOffsetY(void) { - return (g_PlayerDefaultFovY - 60.f) / (2.75f * 4.f); + return (PLAYER_DEFAULT_FOV - 60.f) / (2.75f * 4.f); } #endif diff --git a/src/game/bondgunreset.c b/src/game/bondgunreset.c index 182cefd75..9e61a70b4 100644 --- a/src/game/bondgunreset.c +++ b/src/game/bondgunreset.c @@ -7,6 +7,9 @@ #include "lib/memp.h" #include "data.h" #include "types.h" +#ifndef PLATFORM_N64 +#include "game/player.h" +#endif extern u32 g_BgunGunMemBaseSize4Mb2P; diff --git a/src/game/bondmove.c b/src/game/bondmove.c index 47e778af6..2bbc9b110 100644 --- a/src/game/bondmove.c +++ b/src/game/bondmove.c @@ -770,7 +770,7 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i #ifndef PLATFORM_N64 if (allowmlook) { inputMouseGetScaledDelta(&movedata.freelookdx, &movedata.freelookdy); - allowmcross = (g_PlayerMouseAimMode == MOUSEAIM_CLASSIC) && + allowmcross = (PLAYER_EXTCFG().mouseaimmode == MOUSEAIM_CLASSIC) && (movedata.freelookdx || movedata.freelookdy || g_Vars.currentplayer->swivelpos[0] || g_Vars.currentplayer->swivelpos[1]); if (movedata.invertpitch) { movedata.freelookdy = -movedata.freelookdy; @@ -1289,7 +1289,7 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i movedata.analoglean = 0.f; } - if (g_PlayerMouseAimMode == MOUSEAIM_LOCKED || bgunGetWeaponNum(HAND_RIGHT) == WEAPON_HORIZONSCANNER) { + if (PLAYER_EXTCFG().mouseaimmode == MOUSEAIM_LOCKED || bgunGetWeaponNum(HAND_RIGHT) == WEAPON_HORIZONSCANNER) { movedata.cannaturalpitch = movedata.cannaturalpitch || (movedata.freelookdy != 0.0f); movedata.cannaturalturn = movedata.cannaturalturn || (movedata.freelookdx != 0.0f); } @@ -1653,7 +1653,7 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i #endif // Handle C-button and analog crouch and uncrouch, if enabled - if (g_PlayerClassicCrouch && allowc1buttons) { + if (PLAYER_EXTCFG().classiccrouch && allowc1buttons) { for (i = 0; i < numsamples; i++) { if (!canmanualzoom && aimonhist[i]) { bool goUp = joyGetButtonsPressedOnSample(i, contpad1, c1allowedbuttons & (U_CBUTTONS)); @@ -1831,11 +1831,7 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i } if (g_Vars.currentplayer->pausemode == PAUSEMODE_UNPAUSED && !g_MainIsEndscreen) { -#ifdef PLATFORM_N64 - zoomfov = 60; -#else - zoomfov = g_PlayerDefaultFovY; -#endif + zoomfov = PLAYER_DEFAULT_FOV; // FarSight in secondary function if (bgunGetWeaponNum(HAND_RIGHT) == WEAPON_FARSIGHT @@ -1844,15 +1840,9 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i && g_Vars.currentplayer->autoeraserdist > 0) { eraserfov = cam0f0b49b8(500.0f / g_Vars.currentplayer->autoeraserdist); -#ifdef PLATFORM_N64 - if (eraserfov > 60) { - eraserfov = 60; + if (eraserfov > PLAYER_DEFAULT_FOV) { + eraserfov = PLAYER_DEFAULT_FOV; } -#else - if (eraserfov > g_PlayerDefaultFovY) { - eraserfov = g_PlayerDefaultFovY; - } -#endif if (eraserfov < ADJUST_ZOOM_FOV(2)) { eraserfov = ADJUST_ZOOM_FOV(2); @@ -1886,15 +1876,9 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i zoomfov = currentPlayerGetGunZoomFov(); } -#ifdef PLATFORM_N64 if (zoomfov <= 0) { - zoomfov = 60; + zoomfov = PLAYER_DEFAULT_FOV; } -#else - if (zoomfov <= 0) { - zoomfov = g_PlayerDefaultFovY; - } -#endif playerTweenFovY(zoomfov); playerUpdateZoom(); @@ -2170,10 +2154,10 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i #else f32 xscale, yscale; if (movedata.freelookdx || movedata.freelookdy) { - xscale = g_PlayerCrosshairSway * 0.20f; - yscale = g_PlayerCrosshairSway * 0.30f; + xscale = PLAYER_EXTCFG().crosshairsway * 0.20f; + yscale = PLAYER_EXTCFG().crosshairsway * 0.30f; } else { - xscale = yscale = g_PlayerCrosshairSway; + xscale = yscale = PLAYER_EXTCFG().crosshairsway; } x = g_Vars.currentplayer->speedtheta * 0.3f * xscale + g_Vars.currentplayer->gunextraaimx; y = -g_Vars.currentplayer->speedverta * 0.1f * yscale + g_Vars.currentplayer->gunextraaimy; @@ -2188,8 +2172,8 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i #ifndef PLATFORM_N64 if (allowmcross) { // joystick is inactive, move crosshair using the mouse - const f32 xscale = g_PlayerMouseAimSpeedX * 320.f / (f32)videoGetWidth(); - const f32 yscale = g_PlayerMouseAimSpeedY * 240.f / (f32)videoGetHeight(); + const f32 xscale = PLAYER_EXTCFG().mouseaimspeedx * 320.f / (f32)videoGetWidth(); + const f32 yscale = PLAYER_EXTCFG().mouseaimspeedy * 240.f / (f32)videoGetHeight(); f32 x = g_Vars.currentplayer->swivelpos[0] + movedata.freelookdx * xscale; f32 y = g_Vars.currentplayer->swivelpos[1] + movedata.freelookdy * yscale; x = (x < -1.f) ? -1.f : ((x > 1.f) ? 1.f : x); diff --git a/src/game/bondview.c b/src/game/bondview.c index 0264567d1..1b6935ce0 100644 --- a/src/game/bondview.c +++ b/src/game/bondview.c @@ -21,6 +21,7 @@ #include "types.h" #include "gbiex.h" #ifndef PLATFORM_N64 +#include "game/player.h" #include "video.h" #endif diff --git a/src/game/hudmsg.c b/src/game/hudmsg.c index aad03591c..fe0b6cfbf 100644 --- a/src/game/hudmsg.c +++ b/src/game/hudmsg.c @@ -269,11 +269,7 @@ Gfx *hudmsgRenderZoomRange(Gfx *gdl, u32 alpha) return gdl; } } else { -#ifdef PLATFORM_N64 - maxzoom = 60.0f / zoomfov; -#else - maxzoom = g_PlayerDefaultFovY / zoomfov; -#endif + maxzoom = PLAYER_DEFAULT_FOV / zoomfov; curzoom = maxzoom - 1.0f / (zoomfov / zoominfovy) + 1; } diff --git a/src/game/mplayer/mplayer.c b/src/game/mplayer/mplayer.c index 879f7ec34..b389e6215 100644 --- a/src/game/mplayer/mplayer.c +++ b/src/game/mplayer/mplayer.c @@ -109,6 +109,29 @@ struct mpweapon g_MpWeapons[NUM_MPWEAPONS] = { /*0x2e*/ { WEAPON_DISABLED }, // 0x25 on N64 }; +#ifndef PLATFORM_N64 + +#define PLAYER_EXT_CFG_DEFAULT { \ + .fovy = 60.f, \ + .fovzoommult = 1.f, \ + .fovzoom = true, \ + .mouseaimmode = MOUSEAIM_CLASSIC, \ + .mouseaimspeedx = 0.7f, \ + .mouseaimspeedy = 0.7f, \ + .radialmenuspeed = 4.f, \ + .crosshairsway = 1.f, \ + .classiccrouch = true, \ +} + +struct extplayerconfig g_PlayerExtCfg[MAX_PLAYERS] = { + PLAYER_EXT_CFG_DEFAULT, + PLAYER_EXT_CFG_DEFAULT, + PLAYER_EXT_CFG_DEFAULT, + PLAYER_EXT_CFG_DEFAULT, +}; + +#endif + /** * Converts the given value into a float on a curved scale from 0.1 to 10. * diff --git a/src/game/player.c b/src/game/player.c index 4b0645428..8bb27558f 100644 --- a/src/game/player.c +++ b/src/game/player.c @@ -202,18 +202,6 @@ s16 g_DeathAnimations[] = { s32 g_NumDeathAnimations = 0; -#ifndef PLATFORM_N64 -f32 g_PlayerDefaultFovY = 60.f; -f32 g_PlayerCrosshairSway = 1.f; -s32 g_PlayerMouseAimMode = MOUSEAIM_CLASSIC; -f32 g_PlayerMouseAimSpeedX = 0.7f; -f32 g_PlayerMouseAimSpeedY = 0.7f; -f32 g_PlayerRadialMenuSpeed = 4.0f; -s32 g_PlayerFovAffectsZoom = 1; -f32 g_PlayerFovZoomMultiplier = 1.0f; -s32 g_PlayerClassicCrouch = true; -#endif - /** * Choose which location to spawn into from the given pads. Write the position * and rooms to the dstpos and dstrooms pointers and return the angle that the @@ -2086,8 +2074,8 @@ void playerTweenFovY(f32 targetfovy) f32 speed = 15.0f / 30.0f; #ifndef PLATFORM_N64 - if (g_PlayerDefaultFovY > 60.0f) { // adjust zoom speed depending on non-default fov setting (higher fov == faster zoom) - speed /= g_PlayerDefaultFovY / 60.0f; + if (PLAYER_DEFAULT_FOV > 60.0f) { // adjust zoom speed depending on non-default fov setting (higher fov == faster zoom) + speed /= PLAYER_DEFAULT_FOV / 60.0f; } #endif @@ -2712,7 +2700,7 @@ Gfx *playerRenderHealthBar(Gfx *gdl) #ifdef PLATFORM_N64 mtx00016ae4(&matrix, 0, 370, 0, 0, 0, 0, 0, 0, -1); #else - f32 fovsc = 60.f / g_PlayerDefaultFovY; + f32 fovsc = 60.f / PLAYER_DEFAULT_FOV; if (fovsc > 1.01f) { fovsc *= 1.1f; } @@ -3167,22 +3155,14 @@ void playerConfigureVi(void) var800800f0jf = 0; #endif -#ifdef PLATFORM_N64 - playermgrSetFovY(60); -#else - playermgrSetFovY(g_PlayerDefaultFovY); -#endif + playermgrSetFovY(PLAYER_DEFAULT_FOV); playermgrSetAspectRatio(ratio); playermgrSetViewSize(playerGetViewportWidth(), playerGetViewportHeight()); playermgrSetViewPosition(playerGetViewportLeft(), playerGetViewportTop()); viSetMode(g_ViModes[g_ViRes].xscale); -#ifdef PLATFORM_N64 - viSetFovAspectAndSize(60, ratio, playerGetViewportWidth(), playerGetViewportHeight()); -#else - viSetFovAspectAndSize(g_PlayerDefaultFovY, ratio, playerGetViewportWidth(), playerGetViewportHeight()); -#endif + viSetFovAspectAndSize(PLAYER_DEFAULT_FOV, ratio, playerGetViewportWidth(), playerGetViewportHeight()); viSetViewPosition(playerGetViewportLeft(), playerGetViewportTop()); viSetSize(playerGetFbWidth(), playerGetFbHeight()); @@ -3245,21 +3225,13 @@ void playerTick(bool arg0) return; } -#ifdef PLATFORM_N64 - playermgrSetFovY(60); -#else - playermgrSetFovY(g_PlayerDefaultFovY); -#endif + playermgrSetFovY(PLAYER_DEFAULT_FOV); playermgrSetAspectRatio(aspectratio); playermgrSetViewSize(playerGetViewportWidth(), playerGetViewportHeight()); playermgrSetViewPosition(playerGetViewportLeft(), playerGetViewportTop()); viSetMode(g_ViModes[g_ViRes].xscale); -#ifdef PLATFORM_N64 - viSetFovAspectAndSize(60, aspectratio, playerGetViewportWidth(), playerGetViewportHeight()); -#else - viSetFovAspectAndSize(g_PlayerDefaultFovY, aspectratio, playerGetViewportWidth(), playerGetViewportHeight()); -#endif + viSetFovAspectAndSize(PLAYER_DEFAULT_FOV, aspectratio, playerGetViewportWidth(), playerGetViewportHeight()); viSetViewPosition(playerGetViewportLeft(), playerGetViewportTop()); viSetSize(playerGetFbWidth(), playerGetFbHeight()); viSetBufSize(playerGetFbWidth(), playerGetFbHeight()); diff --git a/src/include/data.h b/src/include/data.h index e6598f3f6..93c084c8f 100644 --- a/src/include/data.h +++ b/src/include/data.h @@ -531,19 +531,12 @@ extern struct menudialogdef g_HangarListMenuDialog; #ifndef PLATFORM_N64 +extern struct extplayerconfig g_PlayerExtCfg[MAX_PLAYERS]; + extern struct weathercfg g_WeatherConfig[WEATHERCFG_MAX_STAGES]; extern const struct weathercfg g_DefaultWeatherConfig; extern const struct weathercfg *g_CurWeatherConfig; -extern f32 g_PlayerCrosshairSway; -extern f32 g_PlayerDefaultFovY; -extern s32 g_PlayerMouseAimMode; -extern f32 g_PlayerMouseAimSpeedX; -extern f32 g_PlayerMouseAimSpeedY; -extern f32 g_PlayerRadialMenuSpeed; -extern s32 g_PlayerFovAffectsZoom; -extern f32 g_PlayerFovZoomMultiplier; -extern s32 g_PlayerClassicCrouch; extern f32 g_ViShakeIntensityMult; extern u32 g_TexFilter2D; extern s32 g_HudCenter; @@ -552,13 +545,17 @@ extern u32 g_HudAlignModeR; extern s32 g_PrevFrameFb; extern s32 g_PrevFrameCapTimer; +#define PLAYER_EXTCFG() g_PlayerExtCfg[g_Vars.currentplayernum] +#define PLAYER_DEFAULT_FOV (PLAYER_EXTCFG().fovy) + #define TEX_FILTER_2D g_TexFilter2D -#define ADJUST_ZOOM_FOV(x) ((x) * g_PlayerFovZoomMultiplier) +#define ADJUST_ZOOM_FOV(x) ((x) * PLAYER_EXTCFG().fovzoommult) #else // PLATFORM_N64 #define TEX_FILTER_2D G_TF_BILERP #define ADJUST_ZOOM_FOV(x) (x) +#define PLAYER_DEFAULT_FOV 60.f #endif // PLATFORM_N64 diff --git a/src/include/types.h b/src/include/types.h index 71930a240..9917f21f7 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -6123,4 +6123,20 @@ struct xz { f32 z; }; +#ifndef PLATFORM_N64 + +struct extplayerconfig { + f32 fovy; + f32 fovzoommult; + s32 fovzoom; + s32 mouseaimmode; + f32 mouseaimspeedx; + f32 mouseaimspeedy; + s32 classiccrouch; + f32 radialmenuspeed; + f32 crosshairsway; +}; + +#endif + #endif