From 1dd696df1874a3d319d15452c34574bd58fc0fbd Mon Sep 17 00:00:00 2001 From: nukeykt Date: Thu, 31 Oct 2019 02:06:05 +0900 Subject: [PATCH] Initial work on input code improving --- source/exhumed/src/config.cpp | 46 ++++++++++++- source/exhumed/src/exhumed.cpp | 3 +- source/exhumed/src/gun.cpp | 6 +- source/exhumed/src/player.cpp | 120 +++++++++++++++++++++++++++++++-- source/exhumed/src/player.h | 1 + source/exhumed/src/view.cpp | 3 +- 6 files changed, 167 insertions(+), 12 deletions(-) diff --git a/source/exhumed/src/config.cpp b/source/exhumed/src/config.cpp index 992a9d940..b1269c895 100644 --- a/source/exhumed/src/config.cpp +++ b/source/exhumed/src/config.cpp @@ -61,6 +61,50 @@ static const char gamefunctions[kMaxGameFunctions][kMaxGameFuncLen] = }; static const char keydefaults[kMaxGameFunctions * 2][kMaxGameFuncLen] = +{ + "W", "Kpad8", + "S", "Kpad2", + "Left", "Kpad4", + "Right", "KPad6", + "LAlt", "RAlt", + "A", "", + "D", "", + "LShift", "RShift", + "Space", "", + "LCtrl", "", + "RCtrl", "", + "E", "", + "PgUp", "", + "PgDn", "", + "Home", "", + "Insert", "", + "Delete", "", + "T", "", + "1", "", + "2", "", + "3", "", + "4", "", + "5", "", + "6", "", + "7", "", + "/", "", + "Pause", "", + "Tab", "", + "=", "", + "-", "", + "F11", "", + "Escape", "", + "Kpad-", "", + "Kpad+", "", + "Enter", "", + "[", "", + "]", "", + "F7", "", + "F8", "", + "`", "", +}; + +static const char oldkeydefaults[kMaxGameFunctions * 2][kMaxGameFuncLen] = { "Up", "Kpad8", "Down", "Kpad2", @@ -399,7 +443,7 @@ void CONFIG_SetDefaults() mouseaiming = 0; aimmode = 1; - mouseflip = 0; + mouseflip = 1; runkey_mode = 0; auto_run = 1; diff --git a/source/exhumed/src/exhumed.cpp b/source/exhumed/src/exhumed.cpp index fa5457ff1..1e2aff1be 100644 --- a/source/exhumed/src/exhumed.cpp +++ b/source/exhumed/src/exhumed.cpp @@ -2200,12 +2200,13 @@ LOOP3: sPlayerInput[nLocalPlayer].xVel = lPlayerXVel; sPlayerInput[nLocalPlayer].yVel = lPlayerYVel; sPlayerInput[nLocalPlayer].buttons = lLocalButtons | lLocalCodes; - sPlayerInput[nLocalPlayer].nAngle = fix16_from_int(nPlayerDAng)<<2; + sPlayerInput[nLocalPlayer].nAngle = nPlayerDAng; sPlayerInput[nLocalPlayer].nTarget = besttarget; Ra[nLocalPlayer].nTarget = besttarget; lLocalCodes = 0; + nPlayerDAng = 0; sPlayerInput[nLocalPlayer].horizon = nVertPan[nLocalPlayer]; } diff --git a/source/exhumed/src/gun.cpp b/source/exhumed/src/gun.cpp index 84f8483a0..0f4a75ce9 100644 --- a/source/exhumed/src/gun.cpp +++ b/source/exhumed/src/gun.cpp @@ -725,7 +725,7 @@ loc_flag: // loc_27266: case kWeaponSword: { - nHeight += (92 - sPlayerInput[nPlayer].horizon) << 6; + nHeight += (92 - fix16_to_int(sPlayerInput[nPlayer].horizon)) << 6; theZ += nHeight; @@ -828,7 +828,7 @@ loc_flag: } case kWeaponPistol: { - int var_50 = (sPlayerInput[nPlayer].horizon - 92) << 2; + int var_50 = (fix16_to_int(sPlayerInput[nPlayer].horizon) - 92) << 2; nHeight -= var_50; short thetargetthin = sPlayerInput[nPlayer].nTarget; @@ -846,7 +846,7 @@ loc_flag: case kWeaponGrenade: { - ThrowGrenade(nPlayer, ebp, ebx, nHeight - 2560, sPlayerInput[nPlayer].horizon - 92); + ThrowGrenade(nPlayer, ebp, ebx, nHeight - 2560, fix16_to_int(sPlayerInput[nPlayer].horizon) - 92); break; } case kWeaponStaff: diff --git a/source/exhumed/src/player.cpp b/source/exhumed/src/player.cpp index bc6423ff1..fa601e9d7 100644 --- a/source/exhumed/src/player.cpp +++ b/source/exhumed/src/player.cpp @@ -44,9 +44,9 @@ struct PlayerSave short nAngle; }; -int lPlayerXVel = 0; -int lPlayerYVel = 0; -int nPlayerDAng = 0; +fix16_t lPlayerXVel = 0; +fix16_t lPlayerYVel = 0; +fix16_t nPlayerDAng = 0; short bobangle = 0; short bPlayerPan = 0; short bLockPan = 0; @@ -176,10 +176,116 @@ void PlayerInterruptKeys() // JBF: Run key behaviour is selectable int const playerRunning = (runkey_mode) ? (BUTTON(gamefunc_Run) | auto_run) : (auto_run ^ BUTTON(gamefunc_Run)); int const turnAmount = playerRunning ? 12 : 8; + int const keyMove = playerRunning ? 12 : 6; + constexpr int const analogTurnAmount = 12; constexpr int const analogExtent = 32767; // KEEPINSYNC sdlayer.cpp + int fvel = 0, svel = 0; + fix16_t q16avel = 0, q16horz = 0; - int fvel = 0; + if (BUTTON(gamefunc_Strafe)) + { + static int strafeyaw; + svel = -(info.mousex + strafeyaw) >> 6; + strafeyaw = (info.mousex + strafeyaw) % 64; + + svel -= info.dyaw * keyMove / analogExtent; + } + else + { + q16avel = fix16_div(fix16_from_int(info.mousex), F16(32)); + q16avel += fix16_from_int(info.dyaw) / analogExtent * (analogTurnAmount << 1); + } + + if (aimmode) + q16horz = fix16_div(fix16_from_int(info.mousey), F16(64)); + else + fvel = -(info.mousey >> 6); + + if (mouseflip) q16horz = -q16horz; + + q16horz -= fix16_from_int(info.dpitch) / analogExtent * analogTurnAmount; + svel -= info.dx * keyMove / analogExtent; + fvel -= info.dz * keyMove / analogExtent; + + if (BUTTON(gamefunc_Strafe)) + { + if (BUTTON(gamefunc_Turn_Left)) + svel -= -keyMove; + + if (BUTTON(gamefunc_Turn_Right)) + svel -= keyMove; + } + else + { + static int turn = 0; + static int counter = 0; + // normal, non strafing movement + if (BUTTON(gamefunc_Turn_Left)) + { + turn -= 2; + + if (turn < -turnAmount) + turn = -turnAmount; + } + else if (BUTTON(gamefunc_Turn_Right)) + { + turn += 2; + + if (turn > turnAmount) + turn = turnAmount; + } + + if (turn < 0) + { + turn++; + if (turn > 0) + turn = 0; + } + + if (turn > 0) + { + turn--; + if (turn < 0) + turn = 0; + } + + if ((counter++) % 4 == 0) + q16avel += fix16_from_int(turn<<2); + } + + if (BUTTON(gamefunc_Strafe_Left)) + svel += keyMove; + + if (BUTTON(gamefunc_Strafe_Right)) + svel += -keyMove; + + if (BUTTON(gamefunc_Move_Forward)) + fvel += keyMove; + + if (BUTTON(gamefunc_Move_Backward)) + fvel += -keyMove; + + fvel = clamp(fvel, -12, 12); + svel = clamp(svel, -12, 12); + + nPlayerDAng += q16avel; + + inita &= kAngleMask; + + lPlayerXVel += fvel * Cos(inita) + svel * Sin(inita); + lPlayerYVel += fvel * Sin(inita) - svel * Cos(inita); + + lPlayerXVel -= (lPlayerXVel >> 5) + (lPlayerXVel >> 6); + lPlayerYVel -= (lPlayerYVel >> 5) + (lPlayerYVel >> 6); + + // A horiz diff of 128 equal 45 degrees, + // so we convert horiz to 1024 angle units + + float horizAngle = atan2f(nVertPan[nLocalPlayer] - F16(92), F16(128)) * (512.f / fPI) + fix16_to_float(q16horz); + nVertPan[nLocalPlayer] = fix16_clamp(F16(92) + Blrintf(F16(128) * tanf(horizAngle * (fPI / 512.f))), F16(0), F16(184)); + +#if 0 info.dyaw *= (lMouseSens >> 1) + 1; int nXVel, nYVel; @@ -370,6 +476,7 @@ void PlayerInterruptKeys() lPlayerXVel -= (lPlayerXVel >> 5) + (lPlayerXVel >> 6); lPlayerYVel -= (lPlayerYVel >> 5) + (lPlayerYVel >> 6); +#endif } void RestoreSavePoint(int nPlayer, int *x, int *y, int *z, short *nSector, short *nAngle) @@ -668,7 +775,7 @@ void RestartPlayer(short nPlayer) nYDamage[nPlayer] = 0; nXDamage[nPlayer] = 0; - nVertPan[nPlayer] = F16(92); + PlayerList[nPlayer].q16horiz = nVertPan[nPlayer] = F16(92); nDestVertPan[nPlayer] = F16(92); nBreathTimer[nPlayer] = 90; @@ -770,7 +877,7 @@ void StartDeathSeq(int nPlayer, int nVal) StopFiringWeapon(nPlayer); - nVertPan[nPlayer] = F16(92); + PlayerList[nPlayer].q16horiz = nVertPan[nPlayer] = F16(92); eyelevel[nPlayer] = -14080; nPlayerInvisible[nPlayer] = 0; dVertPan[nPlayer] = 15; @@ -1148,6 +1255,7 @@ void FuncPlayer(int pA, int nDamage, int nRun) // loc_1A494: PlayerList[nPlayer].q16angle = (PlayerList[nPlayer].q16angle + sPlayerInput[nPlayer].nAngle) & 0x7FFFFFF; + PlayerList[nPlayer].q16horiz = sPlayerInput[nPlayer].horizon; sprite[nPlayerSprite].ang = fix16_to_int(PlayerList[nPlayer].q16angle); // sprite[nPlayerSprite].zvel is modified within Gravity() diff --git a/source/exhumed/src/player.h b/source/exhumed/src/player.h index e8f266229..c6a36b451 100644 --- a/source/exhumed/src/player.h +++ b/source/exhumed/src/player.h @@ -54,6 +54,7 @@ struct Player short nRun; fix16_t q16angle; + fix16_t q16horiz; }; extern short PlayerCount; diff --git a/source/exhumed/src/view.cpp b/source/exhumed/src/view.cpp index 0ab1c5885..2bd1d031a 100644 --- a/source/exhumed/src/view.cpp +++ b/source/exhumed/src/view.cpp @@ -355,7 +355,8 @@ void DrawView() viewz = playerZ + nQuake[nLocalPlayer]; int floorZ = sector[sprite[nPlayerSprite].sectnum].floorz; - pan = nVertPan[nLocalPlayer]; + // pan = nVertPan[nLocalPlayer]; + pan = PlayerList[nLocalPlayer].q16horiz; if (viewz > floorZ) viewz = floorZ;