From 7bc2befc846ceb935976c732175f2e943b270df6 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 17 Jul 2020 22:09:01 +0200 Subject: [PATCH] - consolidated the finalizing parts of the input code and fully merged most of the bike/boat handlers. Turned out that the only major difference was already split off into subfunctions. --- source/games/duke/src/input.cpp | 91 ++++------- source/games/duke/src/zz_player.cpp | 226 ++++++++-------------------- 2 files changed, 94 insertions(+), 223 deletions(-) diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 55fabfea3..326ea80f3 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -721,27 +721,8 @@ void processCommonInput(ControlInfo &info, bool onVehicle) if (buttonMap.ButtonDown(gamefunc_Fire)) loc.bits |= SKB_FIRE; if (buttonMap.ButtonDown(gamefunc_Open)) loc.bits |= SKB_OPEN; -#if 0 - // todo: handle these with CCMDs instead. - if (buttonMap.ButtonDown(gamefunc_Inventory)) loc.bits |= SKB_INVENTORY; - if (buttonMap.ButtonDown(gamefunc_MedKit)) loc.bits |= SKB_MEDKIT; - if (buttonMap.ButtonDown(gamefunc_Steroids)) loc.bits |= SKB_STEROIDS; - if (buttonMap.ButtonDown(gamefunc_NightVision)) loc.bits |= SKB_NIGHTVISION; - if (buttonMap.ButtonDown(gamefunc_Holo_Duke)) loc.bits |= SKB_HOLODUKE; - if (buttonMap.ButtonDown(gamefunc_Jetpack)) loc.bits |= SKB_JETPACK; - //if (inputState.CheckPause()) loc.bits |= SKB_PAUSE; - if (buttonMap.ButtonDown(gamefunc_Inventory_Left)) loc.bits |= SKB_INV_LEFT; - if (buttonMap.ButtonDown(gamefunc_Inventory_Right)) loc.bits |= SKB_INV_RIGHT; - - /* - loc.bits |= (buttonMap.ButtonDown(gamefunc_Center_View) << SK_CENTER_VIEW); - loc.bits |= buttonMap.ButtonDown(gamefunc_Holster_Weapon) << SK_HOLSTER; - loc.bits |= buttonMap.ButtonDown(gamefunc_TurnAround) << SK_TURNAROUND; - */ - -#else + // These 3 bits are only available when not riding a bike or boat. if (onVehicle) BitsToSend &= ~(SKB_HOLSTER|SKB_TURNAROUND|SKB_CENTER_VIEW); -#endif if (buttonMap.ButtonDown(gamefunc_Dpad_Select)) { @@ -756,17 +737,13 @@ void processCommonInput(ControlInfo &info, bool onVehicle) if (g_gameQuit) loc.bits |= SKB_GAMEQUIT; //if (inputState.GetKeyStatus(sc_Escape)) loc.bits |= SKB_ESCAPE; fixme. This never gets here because the menu eats the escape key. - if (buttonMap.ButtonDown(gamefunc_Dpad_Aiming)) info.dz = 0; } //--------------------------------------------------------------------------- // -// weapon selection bits. -// This should all be remapped to CCMDs, except for the controller check -// For the next and prev weapon functions this is particularly necessary -// due to how the mouse wheel works. +// weapon selection bits. Using CVARs now instead of buttons. // //--------------------------------------------------------------------------- @@ -776,25 +753,6 @@ void processSelectWeapon(input_t& input) WeaponToSend = 0; if (VOLUMEONE && (j >= 7 && j <= 10)) j = 0; -#if 0 // must be removed once the CCMDs are hooked up - if (buttonMap.ButtonPressed(gamefunc_Weapon_1)) j = 1; - if (buttonMap.ButtonPressed(gamefunc_Weapon_2)) j = 2; - if (buttonMap.ButtonPressed(gamefunc_Weapon_3)) j = 3; - if (buttonMap.ButtonPressed(gamefunc_Weapon_4)) j = 4; - if (buttonMap.ButtonPressed(gamefunc_Weapon_5)) j = 5; - if (buttonMap.ButtonPressed(gamefunc_Weapon_6)) j = 6; - - if (!VOLUMEONE) - { - if (buttonMap.ButtonPressed(gamefunc_Weapon_7)) j = 7; - if (buttonMap.ButtonPressed(gamefunc_Weapon_8)) j = 8; - if (buttonMap.ButtonPressed(gamefunc_Weapon_9)) j = 9; - if (buttonMap.ButtonPressed(gamefunc_Weapon_10)) j = 10; - } - if (buttonMap.ButtonPressed(gamefunc_Previous_Weapon)) j = 11; - if (buttonMap.ButtonPressed(gamefunc_Next_Weapon)) j = 12; -#endif - if (buttonMap.ButtonDown(gamefunc_Dpad_Select) && input.fvel < 0) j = 11; if (buttonMap.ButtonDown(gamefunc_Dpad_Select) && input.fvel < 0) j = 12; @@ -963,43 +921,60 @@ static int boatApplyTurn(player_struct *p, int turnl, int turnr, int bike_turn, // //--------------------------------------------------------------------------- -void processBoatInput(player_struct *p, ControlInfo& info, input_t& input, double scaleAdjust) +void processVehicleInput(player_struct *p, ControlInfo& info, input_t& input, double scaleAdjust) { - auto boat_turn = info.mousex + scaleAdjust * info.dyaw * (1. / 32); // originally this was 64, not 32. Why the change? + auto turnspeed = info.mousex + scaleAdjust * info.dyaw * (1. / 32); // originally this was 64, not 32. Why the change? int turnl = buttonMap.ButtonDown(gamefunc_Turn_Left) || buttonMap.ButtonDown(gamefunc_Strafe_Left); int turnr = buttonMap.ButtonDown(gamefunc_Turn_Right) || buttonMap.ButtonDown(gamefunc_Strafe_Right); // Cancel out micro-movement const double turn_threshold = 1 / 65536.; - if (boat_turn < -turn_threshold) + if (turnspeed < -turn_threshold) turnl = 1; - else if (boat_turn > turn_threshold) + else if (turnspeed > turn_threshold) turnr = 1; else - boat_turn = 0; + turnspeed = 0; - if (buttonMap.ButtonDown(gamefunc_Move_Forward) || buttonMap.ButtonDown(gamefunc_Strafe)) - loc.bits |= SKB_JUMP; - if (buttonMap.ButtonDown(gamefunc_Move_Backward)) - loc.bits |= SKB_AIM_UP; - if (buttonMap.ButtonDown(gamefunc_Run)) - loc.bits |= SKB_CROUCH; + if (p->OnBoat || !p->moto_underwater) + { + if (buttonMap.ButtonDown(gamefunc_Move_Forward) || buttonMap.ButtonDown(gamefunc_Strafe)) + loc.bits |= SKB_JUMP; + if (buttonMap.ButtonDown(gamefunc_Move_Backward)) + loc.bits |= SKB_AIM_UP; + if (buttonMap.ButtonDown(gamefunc_Run)) + loc.bits |= SKB_CROUCH; + } if (turnl) loc.bits |= SKB_AIM_DOWN; if (turnr) loc.bits |= SKB_LOOK_LEFT; - double turnvel = boatApplyTurn(p, turnl, turnr, boat_turn != 0, scaleAdjust) * scaleAdjust * 2; + double turnvel; + + if (p->OnMotorcycle) + { + bool moveBack = buttonMap.ButtonDown(gamefunc_Move_Backward) && p->MotoSpeed <= 0; + + turnvel = motoApplyTurn(p, turnl, turnr, turnspeed, moveBack, scaleAdjust); + if (p->moto_underwater) p->MotoSpeed = 0; + } + else + { + turnvel = boatApplyTurn(p, turnl, turnr, turnspeed != 0, scaleAdjust) * scaleAdjust * 2; + + } // What is this? Optimization for playing with a mouse which the original did not have? - if (boat_turn) - turnvel *= clamp(boat_turn * boat_turn, 0., 1.); + if (turnspeed) + turnvel *= clamp(turnspeed * turnspeed, 0., 1.); input.fvel = p->MotoSpeed; input.q16avel = fix16_from_dbl(turnvel); } + //--------------------------------------------------------------------------- // // CCMD based input. The basics are from Randi's ZDuke but this uses dynamic diff --git a/source/games/duke/src/zz_player.cpp b/source/games/duke/src/zz_player.cpp index 349929705..5c435d58e 100644 --- a/source/games/duke/src/zz_player.cpp +++ b/source/games/duke/src/zz_player.cpp @@ -31,7 +31,7 @@ fix16_t GetDeltaQ16Angle(fix16_t ang1, fix16_t ang2); void processCommonInput(ControlInfo& info, bool onVehicle); void processSelectWeapon(input_t& input); int motoApplyTurn(player_struct* p, int turnl, int turnr, int bike_turn, bool goback, double factor); -void processBoatInput(player_struct* p, ControlInfo& info, input_t& input, double scaleAdjust); +void processVehicleInput(player_struct* p, ControlInfo& info, input_t& input, double scaleAdjust); int32_t PHEIGHT = PHEIGHT_DUKE; @@ -88,6 +88,59 @@ static int P_CheckLockedMovement(int const playerNum) return 0; } + +void FinalizeInput(int playerNum, input_t &input, bool vehicle) +{ + auto p = &ps[playerNum]; + int const movementLocked = P_CheckLockedMovement(playerNum); + + if ((ud.scrollmode && ud.overhead_on) || (movementLocked & IL_NOTHING) == IL_NOTHING) + { + if (ud.scrollmode && ud.overhead_on) + { + ud.folfvel = input.fvel; + ud.folavel = fix16_to_int(input.q16avel); + } + + loc.fvel = loc.svel = 0; + loc.q16avel = loc.q16horz = 0; + } + else + { + if (!(movementLocked & IL_NOMOVE)) + { + if (!vehicle) + { + loc.fvel = clamp(loc.fvel + input.fvel, -MAXVEL, MAXVEL); + loc.svel = clamp(loc.svel + input.svel, -MAXSVEL, MAXSVEL); + } + else + loc.fvel = clamp(input.fvel, -(MAXVELMOTO / 8), MAXVELMOTO); + } + + if (!(movementLocked & IL_NOANGLE)) + { + loc.q16avel = fix16_sadd(loc.q16avel, input.q16avel); + if (!synchronized_input) + { + p->q16ang = fix16_sadd(p->q16ang, input.q16avel) & 0x7FFFFFF; + + if (input.q16avel) + { + p->one_eighty_count = 0; + } + } + } + + if (!(movementLocked & IL_NOHORIZ)) + { + loc.q16horz = fix16_clamp(fix16_sadd(loc.q16horz, input.q16horz), F16(-MAXHORIZVEL), F16(MAXHORIZVEL)); + if (!synchronized_input) + p->q16horiz += input.q16horz; // will be clamped below in sethorizon. + } + } +} + double elapsedInputTicks = -1; static double scaleAdjustmentToInterval(double x) @@ -259,48 +312,8 @@ void P_GetInput(int const playerNum) loc.bits |= SKB_LOOK_DOWN; } - int const movementLocked = P_CheckLockedMovement(playerNum); + FinalizeInput(playerNum, input, false); - if ((ud.scrollmode && ud.overhead_on) || (movementLocked & IL_NOTHING) == IL_NOTHING) - { - if (ud.scrollmode && ud.overhead_on) - { - ud.folfvel = input.fvel; - ud.folavel = fix16_to_int(input.q16avel); - } - - loc.fvel = loc.svel = 0; - loc.q16avel = loc.q16horz = 0; - } - else - { - if (!(movementLocked & IL_NOMOVE)) - { - loc.fvel = clamp(loc.fvel + input.fvel, -MAXVEL, MAXVEL); - loc.svel = clamp(loc.svel + input.svel, -MAXSVEL, MAXSVEL); - } - - if (!(movementLocked & IL_NOANGLE)) - { - loc.q16avel = fix16_sadd(loc.q16avel, input.q16avel); - if (!synchronized_input) - { - pPlayer->q16ang = fix16_sadd(pPlayer->q16ang, input.q16avel) & 0x7FFFFFF; - - if (input.q16avel) - { - pPlayer->one_eighty_count = 0; - } - } - } - - if (!(movementLocked & IL_NOHORIZ)) - { - loc.q16horz = fix16_clamp(fix16_sadd(loc.q16horz, input.q16horz), F16(-MAXHORIZVEL), F16(MAXHORIZVEL)); - if (!synchronized_input) - pPlayer->q16horiz += input.q16horz; // will be clamped below in sethorizon. - } - } if (!synchronized_input) { // don't adjust rotscrnang and look_ang if dead. @@ -316,100 +329,9 @@ void P_GetInput(int const playerNum) } -void P_GetInputMotorcycle(int playerNum) +void P_GetInputVehicle(int playerNum) { - auto &thisPlayer = g_player[playerNum]; auto const pPlayer = &ps[playerNum]; - auto const pSprite = &sprite[pPlayer->i]; - ControlInfo info; - double scaleAdjust = elapsedInputTicks * REALGAMETICSPERSEC / 1000.0; - - bool mouseaim = in_mousemode || buttonMap.ButtonDown(gamefunc_Mouse_Aiming); - - CONTROL_GetInput(&info); - - // JBF: Run key behaviour is selectable - int const playerRunning = G_CheckAutorun(buttonMap.ButtonDown(gamefunc_Run)); - int const keyMove = playerRunning ? (NORMALKEYMOVE << 1) : NORMALKEYMOVE; - - input_t input {}; - - pPlayer->crouch_toggle = 0; - processCommonInput(info, true); - - int const turn = input.q16avel / 32; - int turnLeft = buttonMap.ButtonDown(gamefunc_Turn_Left) || buttonMap.ButtonDown(gamefunc_Strafe_Left); - int turnRight = buttonMap.ButtonDown(gamefunc_Turn_Right) || buttonMap.ButtonDown(gamefunc_Strafe_Right); - int avelScale = F16((turnLeft || turnRight) ? 1 : 0); - if (turn) - { - avelScale = fix16_max(avelScale, fix16_clamp(fix16_mul(turn, turn),0,F16(1))); - if (turn < 0) - turnLeft = 1; - else if (turn > 0) - turnRight = 1; - } - - loc.bits |= turnLeft << SK_AIM_DOWN; - loc.bits |= turnRight << SK_LOOK_LEFT; - - int const moveBack = buttonMap.ButtonDown(gamefunc_Move_Backward) && pPlayer->MotoSpeed <= 0; - - // turn is truncated to integer precision to avoid having micro-movement affect the result, which makes a significant difference here. - int turnvel = motoApplyTurn(pPlayer, turnLeft, turnRight, turn >> FRACBITS, moveBack, scaleAdjust); - input.q16avel += int(turnvel * scaleAdjust * FRACUNIT * 2); - - if (pPlayer->moto_underwater) - { - pPlayer->MotoSpeed = 0; - } - else - { - loc.bits |= (buttonMap.ButtonDown(gamefunc_Move_Forward) || buttonMap.ButtonDown(gamefunc_Strafe)) << SK_JUMP; - loc.bits |= buttonMap.ButtonDown(gamefunc_Move_Backward) << SK_AIM_UP; - loc.bits |= buttonMap.ButtonDown(gamefunc_Run) << SK_CROUCH; - } - - input.fvel += pPlayer->MotoSpeed; - input.q16avel = fix16_mul(input.q16avel, avelScale); - - int const movementLocked = P_CheckLockedMovement(playerNum); - - if ((ud.scrollmode && ud.overhead_on) || (movementLocked & IL_NOTHING) == IL_NOTHING) - { - if (ud.scrollmode && ud.overhead_on) - { - ud.folfvel = input.fvel; - ud.folavel = fix16_to_int(input.q16avel); - } - - loc.fvel = loc.svel = 0; - loc.q16avel = loc.q16horz = 0; - } - else - { - if (!(movementLocked & IL_NOMOVE)) - { - loc.fvel = clamp(input.fvel, -(MAXVELMOTO / 8), MAXVELMOTO); - } - - if (!(movementLocked & IL_NOANGLE)) - { - loc.q16avel = fix16_sadd(loc.q16avel, input.q16avel); - if (!synchronized_input) pPlayer->q16ang = fix16_sadd(pPlayer->q16ang, input.q16avel) & 0x7FFFFFF; - } - } - - // don't adjust rotscrnang and look_ang if dead. - if (pSprite->extra > 0 && !synchronized_input) - { - apply_seasick(pPlayer, scaleAdjust); - } -} - -void P_GetInputBoat(int playerNum) -{ - auto const pPlayer = &ps[playerNum]; ControlInfo info; double scaleAdjust = elapsedInputTicks * REALGAMETICSPERSEC / 1000.0; @@ -419,34 +341,9 @@ void P_GetInputBoat(int playerNum) pPlayer->crouch_toggle = 0; processCommonInput(info, true); - processBoatInput(pPlayer, info, input, scaleAdjust); + processVehicleInput(pPlayer, info, input, scaleAdjust); - int const movementLocked = P_CheckLockedMovement(playerNum); - - if ((ud.scrollmode && ud.overhead_on) || (movementLocked & IL_NOTHING) == IL_NOTHING) - { - if (ud.scrollmode && ud.overhead_on) - { - ud.folfvel = input.fvel; - ud.folavel = fix16_to_int(input.q16avel); - } - - loc.fvel = loc.svel = 0; - loc.q16avel = loc.q16horz = 0; - } - else - { - if (!(movementLocked & IL_NOMOVE)) - { - loc.fvel = clamp(input.fvel, -(MAXVELMOTO / 8), MAXVELMOTO); - } - - if (!(movementLocked & IL_NOANGLE)) - { - loc.q16avel = fix16_sadd(loc.q16avel, input.q16avel); - if (!synchronized_input) pPlayer->q16ang = fix16_sadd(pPlayer->q16ang, input.q16avel) & 0x7FFFFFF; - } - } + FinalizeInput(playerNum, input, true); // don't adjust rotscrnang and look_ang if dead. if (sprite[pPlayer->i].extra > 0 && !synchronized_input) @@ -455,6 +352,7 @@ void P_GetInputBoat(int playerNum) } } + void GetInput() { static double lastCheck; @@ -482,10 +380,8 @@ void GetInput() setlocalplayerinput(p); } - if (isRRRA() && p->OnMotorcycle) - P_GetInputMotorcycle(myconnectindex); - else if (isRRRA() && p->OnBoat) - P_GetInputBoat(myconnectindex); + if (isRRRA() && (p->OnMotorcycle || p->OnBoat)) + P_GetInputVehicle(myconnectindex); else P_GetInput(myconnectindex); }