From 687682cab07f02e4d7bc419d3e697570be15d47b Mon Sep 17 00:00:00 2001 From: fgsfds Date: Wed, 30 Aug 2023 16:09:56 +0200 Subject: [PATCH] port: fix gamepad aiming with MOUSEAIM_CLASSIC also uninvert Y when moving the camera with it --- src/game/bondgun.c | 5 ---- src/game/bondmove.c | 59 +++++++++++++++++++++++---------------------- 2 files changed, 30 insertions(+), 34 deletions(-) diff --git a/src/game/bondgun.c b/src/game/bondgun.c index f46e06e01..a61a2c087 100644 --- a/src/game/bondgun.c +++ b/src/game/bondgun.c @@ -5040,11 +5040,6 @@ void bgunSwivel(f32 screenx, f32 screeny, f32 crossdamp, f32 aimdamp) struct coord sp94; f32 sp8c[2]; -#ifndef PLATFORM_N64 - player->swivelpos[0] = screenx; - player->swivelpos[1] = screeny; -#endif - x[HAND_RIGHT] = x[HAND_LEFT] = screenx; y[HAND_RIGHT] = y[HAND_LEFT] = screeny; diff --git a/src/game/bondmove.c b/src/game/bondmove.c index 648359b9c..541c680e0 100644 --- a/src/game/bondmove.c +++ b/src/game/bondmove.c @@ -648,6 +648,7 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i f32 newverta; #ifndef PLATFORM_N64 const bool allowmlook = (g_Vars.currentplayernum == 0) && (allowc1x || allowc1y); + bool allowmcross = false; #endif controlmode = optionsGetControlMode(g_Vars.currentplayerstats->mpindex); @@ -703,6 +704,8 @@ 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) && + (movedata.freelookdx || movedata.freelookdy || g_Vars.currentplayer->swivelpos[0] || g_Vars.currentplayer->swivelpos[1]); } #endif @@ -1284,25 +1287,23 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i #ifndef PLATFORM_N64 // Handle turning and looking up/down via mouselook when aiming - if (allowmlook && g_Vars.currentplayer->insightaimmode && g_PlayerMouseAimMode == MOUSEAIM_CLASSIC) { - if (!movedata.c1stickxraw && !movedata.c1stickyraw) { - if (g_Vars.currentplayer->swivelpos[0] > 0.9f) { - movedata.aimturnrightspeed = (g_Vars.currentplayer->swivelpos[0] - 0.9f) / 0.1f; - movedata.aimturnleftspeed = 0.f; - } else if (g_Vars.currentplayer->swivelpos[0] < -0.9f) { - movedata.aimturnleftspeed = (g_Vars.currentplayer->swivelpos[0] - -0.9f) / -0.1f; - movedata.aimturnrightspeed = 0.f; - } - if (g_Vars.currentplayer->swivelpos[1] > 0.9f) { - movedata.speedvertadown = (g_Vars.currentplayer->swivelpos[1] - 0.9f) / 0.1f; - movedata.speedvertaup = 0.f; - } else if (g_Vars.currentplayer->swivelpos[1] < -0.9f) { - movedata.speedvertaup = (g_Vars.currentplayer->swivelpos[1] - -0.9f) / -0.1f; - movedata.speedvertadown = 0.f; - } + if (g_Vars.currentplayer->insightaimmode && allowmcross) { + if (g_Vars.currentplayer->swivelpos[0] > 0.9f) { + movedata.aimturnrightspeed = (g_Vars.currentplayer->swivelpos[0] - 0.9f) / 0.1f; + movedata.aimturnleftspeed = 0.f; + } else if (g_Vars.currentplayer->swivelpos[0] < -0.9f) { + movedata.aimturnleftspeed = (g_Vars.currentplayer->swivelpos[0] - -0.9f) / -0.1f; + movedata.aimturnrightspeed = 0.f; + } + if (g_Vars.currentplayer->swivelpos[1] > 0.9f) { + movedata.speedvertaup = (g_Vars.currentplayer->swivelpos[1] - 0.9f) / 0.1f; + movedata.speedvertadown = 0.f; + } else if (g_Vars.currentplayer->swivelpos[1] < -0.9f) { + movedata.speedvertadown = (g_Vars.currentplayer->swivelpos[1] - -0.9f) / -0.1f; + movedata.speedvertaup = 0.f; } } else { - // Reset mouse position when not mouse aiming + // Reset mouse aim position when not mouse aiming g_Vars.currentplayer->swivelpos[0] = 0.f; g_Vars.currentplayer->swivelpos[1] = 0.f; } @@ -2037,18 +2038,18 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i // when holding aim and moving stick bgunSetAimType(0); #ifndef PLATFORM_N64 - if (allowmlook && g_PlayerMouseAimMode == MOUSEAIM_CLASSIC) { - if (!movedata.c1stickxraw && !movedata.c1stickyraw) { - // joystick is inactive, move crosshair using the mouse - const f32 xscale = 320.f / (f32)videoGetWidth(); - const f32 yscale = 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); - y = (y < -1.f) ? -1.f : ((y > 1.f) ? 1.f : y); - bgunSwivelWithDamp(x, y, 0.01f); - return; - } + if (allowmcross) { + // joystick is inactive, move crosshair using the mouse + const f32 xscale = 320.f / (f32)videoGetWidth(); + const f32 yscale = 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); + 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; } #endif bgunSwivelWithoutDamp((movedata.c1stickxraw * 0.65f) / 80.0f, (movedata.c1stickyraw * 0.65f) / 80.0f);