diff --git a/port/include/input.h b/port/include/input.h index 6171c26961..452439f4d0 100644 --- a/port/include/input.h +++ b/port/include/input.h @@ -222,6 +222,9 @@ void inputMouseGetRawDelta(s32 *dx, s32 *dy); // returns 0, 0 when the mouse is not locked into the window void inputMouseGetScaledDelta(f32 *dx, f32 *dy); +// returns changes in mouse position since last frame, scaled by sensitivity and crosshair size +void inputMouseGetScaledDeltaCrosshair(f32* dx, f32* dy); + // returns changes in mouse position since last frame, scaled by absolute sensitivity // returns 0, 0 when the mouse is not locked into the window void inputMouseGetAbsScaledDelta(f32 *dx, f32 *dy); @@ -229,6 +232,9 @@ void inputMouseGetAbsScaledDelta(f32 *dx, f32 *dy); void inputMouseGetSpeed(f32 *x, f32 *y); void inputMouseSetSpeed(f32 x, f32 y); +void inputMouseGetAimSpeed(f32* x, f32* y); +void inputMouseSetAimSpeed(f32 x, f32 y); + s32 inputMouseIsEnabled(void); void inputMouseEnable(s32 enabled); diff --git a/port/src/input.c b/port/src/input.c index 41e0fa0387..24e5bcbbbe 100644 --- a/port/src/input.c +++ b/port/src/input.c @@ -11,6 +11,7 @@ #include "utils.h" #include "system.h" #include "fs.h" +#include "data.h" #if !SDL_VERSION_ATLEAST(2, 0, 14) // this was added in 2.0.14 @@ -1273,6 +1274,29 @@ void inputMouseSetSpeed(f32 x, f32 y) mouseSensY = y; } +void inputMouseGetScaledDeltaCrosshair(f32* dx, f32* dy) +{ + f32 mdx = 0.f, mdy = 0.f; + if (mouseLocked) { + mdx = mouseDX * (0.022f / 20.0f) * g_PlayerExtCfg[0].mouseaimsensx; + mdy = mouseDY * (0.022f / 20.0f) * g_PlayerExtCfg[0].mouseaimsensy; + } + if (dx) *dx = mdx; + if (dy) *dy = mdy; +} + +void inputMouseGetAimSpeed(f32* x, f32* y) +{ + if (x) *x = g_PlayerExtCfg[0].mouseaimsensx; + if (y) *y = g_PlayerExtCfg[0].mouseaimsensy; +} + +void inputMouseSetAimSpeed(f32 x, f32 y) +{ + g_PlayerExtCfg[0].mouseaimsensx = x; + g_PlayerExtCfg[0].mouseaimsensy = y; +} + s32 inputMouseIsEnabled(void) { return mouseEnabled; diff --git a/port/src/main.c b/port/src/main.c index 4b86d300c0..6738501d16 100644 --- a/port/src/main.c +++ b/port/src/main.c @@ -175,8 +175,8 @@ PD_CONSTRUCTOR static void gameConfigInit(void) 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.MouseAimSensX", i), &g_PlayerExtCfg[j].mouseaimsensx, 0.f, 10.f); + configRegisterFloat(strFmt("Game.Player%d.MouseAimSensY", i), &g_PlayerExtCfg[j].mouseaimsensy, 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.CrouchMode", i), &g_PlayerExtCfg[j].crouchmode, 0, CROUCHMODE_TOGGLE_ANALOG); diff --git a/port/src/optionsmenu.c b/port/src/optionsmenu.c index 5632153346..f736280523 100644 --- a/port/src/optionsmenu.c +++ b/port/src/optionsmenu.c @@ -213,45 +213,51 @@ static MenuItemHandlerResult menuhandlerMouseSpeedY(s32 operation, struct menuit static MenuItemHandlerResult menuhandlerMouseAimSpeedX(s32 operation, struct menuitem *item, union handlerdata *data) { + f32 x, y; switch (operation) { case MENUOP_GETSLIDER: - if (g_PlayerExtCfg[g_ExtMenuPlayer].mouseaimspeedx < 0.f) { + inputMouseGetAimSpeed(&x, &y); + if (x < 0.f) { data->slider.value = 0; - } else if (g_PlayerExtCfg[g_ExtMenuPlayer].mouseaimspeedx > 10.f) { + } else if (x > 10.f) { data->slider.value = 1000; } else { - data->slider.value = g_PlayerExtCfg[g_ExtMenuPlayer].mouseaimspeedx * 100.f + 0.5f; + data->slider.value = x * 100.f + 0.5f; } break; case MENUOP_SET: - g_PlayerExtCfg[g_ExtMenuPlayer].mouseaimspeedx = (f32)data->slider.value / 100.f; + inputMouseGetAimSpeed(&x, &y); + inputMouseSetAimSpeed((f32)data->slider.value / 100.f, y); break; case MENUOP_GETSLIDERLABEL: sprintf(data->slider.label, "%.2f", (f32)data->slider.value / 100.f); + break; } - return 0; } static MenuItemHandlerResult menuhandlerMouseAimSpeedY(s32 operation, struct menuitem *item, union handlerdata *data) { + f32 x, y; switch (operation) { case MENUOP_GETSLIDER: - if (g_PlayerExtCfg[g_ExtMenuPlayer].mouseaimspeedy < 0.f) { + inputMouseGetAimSpeed(&x, &y); + if (y < 0.f) { data->slider.value = 0; - } else if (g_PlayerExtCfg[g_ExtMenuPlayer].mouseaimspeedy > 10.f) { + } else if (y > 10.f) { data->slider.value = 1000; } else { - data->slider.value = g_PlayerExtCfg[g_ExtMenuPlayer].mouseaimspeedy * 100.f + 0.5f; + data->slider.value = y * 100.f + 0.5f; } break; case MENUOP_SET: - g_PlayerExtCfg[g_ExtMenuPlayer].mouseaimspeedy = (f32)data->slider.value / 100.f; + inputMouseGetAimSpeed(&x, &y); + inputMouseSetAimSpeed(x, (f32)data->slider.value / 100.f); break; case MENUOP_GETSLIDERLABEL: sprintf(data->slider.label, "%.2f", (f32)data->slider.value / 100.f); + break; } - return 0; } diff --git a/src/game/bondmove.c b/src/game/bondmove.c index 64e6dee604..108708d509 100644 --- a/src/game/bondmove.c +++ b/src/game/bondmove.c @@ -436,6 +436,24 @@ void bmoveUpdateSpeedThetaControl(f32 value) } } +/** + * Apply crosshair movement with scaling and clamping + */ +static void bmoveApplyCrosshairMovement(f32 aimspeedx, f32 aimspeedy, f32 dx, f32 dy) +{ + const f32 xcoeff = 320.f / 1080.f; + const f32 ycoeff = 240.f / 1080.f; + const f32 xscale = (aimspeedx * xcoeff) / g_Vars.currentplayer->aspect; + const f32 yscale = aimspeedy * ycoeff; + f32 x = g_Vars.currentplayer->swivelpos[0] + (dx * xscale); + f32 y = g_Vars.currentplayer->swivelpos[1] + (dy * yscale); + x = (x < -1.f) ? -1.f : ((x > 1.f) ? 1.f : x); + y = (y < -1.f) ? -1.f : ((y > 1.f) ? 1.f : y); + g_Vars.currentplayer->swivelpos[0] = x; + g_Vars.currentplayer->swivelpos[1] = y; + bgunSwivelWithDamp(x, y, 0.01f); +} + /** * Calculate the lookahead angle. * @@ -2204,21 +2222,14 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i // when holding aim and moving stick bgunSetAimType(0); #ifndef PLATFORM_N64 - if (allowmcross) { - // joystick is inactive, move crosshair using the mouse - const f32 xcoeff = 320.f / 1080.f; - const f32 ycoeff = 240.f / 1080.f; - const f32 xscale = (PLAYER_EXTCFG().mouseaimspeedx * xcoeff) / g_Vars.currentplayer->aspect; - const f32 yscale = PLAYER_EXTCFG().mouseaimspeedy * ycoeff; - 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); - y = (y < -1.f) ? -1.f : ((y > 1.f) ? 1.f : y); - g_Vars.currentplayer->swivelpos[0] = x; - g_Vars.currentplayer->swivelpos[1] = y; - bgunSwivelWithDamp(x, y, 0.01f); - return; - } + if (allowmcross) { + // joystick is inactive, move crosshair using the mouse + f32 dx, dy; + inputMouseGetScaledDeltaCrosshair(&dx, &dy); + const f32 norm = g_Vars.lvupdate60freal; + bmoveApplyCrosshairMovement(PLAYER_EXTCFG().mouseaimsensx, PLAYER_EXTCFG().mouseaimsensy, dx, dy); + return; + } #endif bgunSwivelWithoutDamp((movedata.c1stickxraw * 0.65f) / 80.0f, (movedata.c1stickyraw * 0.65f) / 80.0f); } diff --git a/src/game/mplayer/mplayer.c b/src/game/mplayer/mplayer.c index f3a8b20cd1..f1c3d5e060 100644 --- a/src/game/mplayer/mplayer.c +++ b/src/game/mplayer/mplayer.c @@ -131,8 +131,8 @@ struct mpweapon g_MpWeapons[NUM_MPWEAPONS] = { .fovzoommult = 1.f, \ .fovzoom = true, \ .mouseaimmode = MOUSEAIM_CLASSIC, \ - .mouseaimspeedx = 0.7f, \ - .mouseaimspeedy = 0.7f, \ + .mouseaimsensx = 2.5f, \ + .mouseaimsensy = 2.5f, \ .radialmenuspeed = 4.f, \ .crosshairsway = 1.f, \ .crouchmode = CROUCHMODE_TOGGLE_ANALOG, \ diff --git a/src/include/types.h b/src/include/types.h index 5dbe003e5e..96e08c6e6c 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -6150,8 +6150,8 @@ struct extplayerconfig { f32 fovzoommult; s32 fovzoom; s32 mouseaimmode; - f32 mouseaimspeedx; - f32 mouseaimspeedy; + f32 mouseaimsensx; + f32 mouseaimsensy; s32 crouchmode; f32 radialmenuspeed; f32 crosshairsway;