diff --git a/source/blood/src/blood.cpp b/source/blood/src/blood.cpp index 8428e798f..c7cd9e6a0 100644 --- a/source/blood/src/blood.cpp +++ b/source/blood/src/blood.cpp @@ -526,11 +526,9 @@ void ProcessFrame(void) { auto& inp = gPlayer[i].input; auto oldactions = inp.actions; - auto oldflags = inp.syncFlags.value; inp = gFifoInput[gNetFifoTail & 255][i]; inp.actions |= oldactions & ~(SB_BUTTON_MASK|SB_RUN|SB_WEAPONMASK_BITS); // should be everything non-button and non-weapon - inp.syncFlags.value |= oldflags & ~flag_buttonmask; int newweap = inp.getNewWeapon(); if (newweap > 0 && newweap < WeaponSel_MaxBlood) gPlayer[i].newWeapon = newweap; diff --git a/source/blood/src/controls.cpp b/source/blood/src/controls.cpp index 2f32494ba..9dbbee9de 100644 --- a/source/blood/src/controls.cpp +++ b/source/blood/src/controls.cpp @@ -127,9 +127,6 @@ void ctrlGetInput(void) InputPacket input = {}; - bool mouseaim = in_mousemode || buttonMap.ButtonDown(gamefunc_Mouse_Aiming); - if (!mouseaim) gInput.actions |= SB_CENTERVIEW; - if (numplayers == 1) { gProfile[myconnectindex].nAutoAim = cl_autoaim; @@ -140,6 +137,9 @@ void ctrlGetInput(void) ApplyGlobalInput(gInput, &info); + bool mouseaim = !!(gInput.actions & SB_AIMMODE); + if (!mouseaim) gInput.actions |= SB_CENTERVIEW; + if (buttonMap.ButtonDown(gamefunc_Shrink_Screen)) { if (automapMode != am_off) @@ -168,16 +168,8 @@ void ctrlGetInput(void) cl_showweapon = (cl_showweapon + 1) & 3; } - gInput.syncFlags.lookUp |= buttonMap.ButtonDown(gamefunc_Look_Up); - gInput.syncFlags.lookDown |= buttonMap.ButtonDown(gamefunc_Look_Down); - - if (buttonMap.ButtonDown(gamefunc_Look_Up) || buttonMap.ButtonDown(gamefunc_Look_Down)) + if (gInput.actions & (SB_LOOK_UP|SB_LOOK_DOWN)) gInput.actions |= SB_CENTERVIEW; - else - { - gInput.syncFlags.lookUp |= buttonMap.ButtonDown(gamefunc_Aim_Up); - gInput.syncFlags.lookDown |= buttonMap.ButtonDown(gamefunc_Aim_Down); - } int const run = !!(gInput.actions & SB_RUN); int const keyMove = (1 + run) << 10; diff --git a/source/blood/src/player.cpp b/source/blood/src/player.cpp index 8193e745c..03c72f3a0 100644 --- a/source/blood/src/player.cpp +++ b/source/blood/src/player.cpp @@ -765,7 +765,6 @@ void playerStart(int nPlayer, int bNewLevel) xvel[pSprite->index] = yvel[pSprite->index] = zvel[pSprite->index] = 0; pInput->q16avel = 0; pInput->actions = 0; - pInput->syncFlags.value = 0; pInput->fvel = 0; pInput->svel = 0; pInput->q16horz = 0; @@ -1333,7 +1332,7 @@ void ProcessInput(PLAYER *pPlayer) } pPlayer->isRunning = !!(pInput->actions & SB_RUN); - if ((pInput->syncFlags.value & flag_buttonmask_norun) || (pInput->actions & SB_BUTTON_MASK) || pInput->fvel || pInput->svel || pInput->q16avel) + if ((pInput->actions & SB_BUTTON_MASK) || pInput->fvel || pInput->svel || pInput->q16avel) pPlayer->restTime = 0; else if (pPlayer->restTime >= 0) pPlayer->restTime += 4; @@ -1563,7 +1562,7 @@ void ProcessInput(PLAYER *pPlayer) } if (bVanilla) { - if ((pInput->actions & SB_CENTERVIEW) && !pInput->syncFlags.lookUp && !pInput->syncFlags.lookDown) + if ((pInput->actions & SB_CENTERVIEW) && !pInput->actions & (SB_LOOK_UP|SB_LOOK_DOWN)) { if (pPlayer->q16look < 0) pPlayer->q16look = fix16_min(pPlayer->q16look+fix16_from_int(4), fix16_from_int(0)); @@ -1574,9 +1573,9 @@ void ProcessInput(PLAYER *pPlayer) } else { - if (pInput->syncFlags.lookUp) + if (pInput->actions & (SB_LOOK_UP|SB_AIM_UP)) pPlayer->q16look = fix16_min(pPlayer->q16look+fix16_from_int(4), fix16_from_int(60)); - if (pInput->syncFlags.lookDown) + if (pInput->actions & (SB_LOOK_DOWN|SB_AIM_DOWN)) pPlayer->q16look = fix16_max(pPlayer->q16look-fix16_from_int(4), fix16_from_int(-60)); } pPlayer->q16look = fix16_clamp(pPlayer->q16look+pInput->q16horz, fix16_from_int(-60), fix16_from_int(60)); @@ -1593,7 +1592,7 @@ void ProcessInput(PLAYER *pPlayer) int downAngle = -347; double lookStepUp = 4.0*upAngle/60.0; double lookStepDown = -4.0*downAngle/60.0; - if ((pInput->actions & SB_CENTERVIEW) && !pInput->syncFlags.lookUp && !pInput->syncFlags.lookDown) + if ((pInput->actions & SB_CENTERVIEW) && !pInput->actions & (SB_LOOK_UP | SB_LOOK_DOWN)) { if (pPlayer->q16look < 0) pPlayer->q16look = fix16_min(pPlayer->q16look+fix16_from_dbl(lookStepDown), fix16_from_int(0)); @@ -1604,22 +1603,22 @@ void ProcessInput(PLAYER *pPlayer) } else { - if (pInput->syncFlags.lookUp) + if (pInput->actions & (SB_LOOK_UP | SB_AIM_UP)) pPlayer->q16look = fix16_min(pPlayer->q16look+fix16_from_dbl(lookStepUp), fix16_from_int(upAngle)); - if (pInput->syncFlags.lookDown) + if (pInput->actions & (SB_LOOK_DOWN | SB_AIM_DOWN)) pPlayer->q16look = fix16_max(pPlayer->q16look-fix16_from_dbl(lookStepDown), fix16_from_int(downAngle)); } if (pPlayer == gMe && numplayers == 1) { - if (pInput->syncFlags.lookUp) + if (pInput->actions & (SB_LOOK_UP | SB_AIM_UP)) { gViewLookAdjust += float(lookStepUp); } - if (pInput->syncFlags.lookDown) + if (pInput->actions & (SB_LOOK_DOWN | SB_AIM_DOWN)) { gViewLookAdjust -= float(lookStepDown); } - gViewLookRecenter = (pInput->actions & SB_CENTERVIEW) && !pInput->syncFlags.lookUp && !pInput->syncFlags.lookDown; + gViewLookRecenter = ((pInput->actions & SB_CENTERVIEW) && !pInput->actions & (SB_LOOK_UP | SB_LOOK_DOWN)); } pPlayer->q16look = fix16_clamp(pPlayer->q16look+(pInput->q16horz<<3), fix16_from_int(downAngle), fix16_from_int(upAngle)); pPlayer->q16horiz = fix16_from_float(100.f*tanf(fix16_to_float(pPlayer->q16look)*fPI/1024.f)); diff --git a/source/blood/src/prediction.cpp b/source/blood/src/prediction.cpp index 2d8e94f79..735acde05 100644 --- a/source/blood/src/prediction.cpp +++ b/source/blood/src/prediction.cpp @@ -262,7 +262,7 @@ static void fakeProcessInput(PLAYER *pPlayer, InputPacket *pInput) int downAngle = -347; double lookStepUp = 4.0*upAngle/60.0; double lookStepDown = -4.0*downAngle/60.0; - if (predict.at6e && !pInput->syncFlags.lookUp && !pInput->syncFlags.lookDown) + if (predict.at6e && !pInput->actions & (SB_LOOK_UP | SB_LOOK_DOWN)) { if (predict.at20 < 0) predict.at20 = fix16_min(predict.at20+fix16_from_dbl(lookStepDown), fix16_from_int(0)); @@ -273,22 +273,22 @@ static void fakeProcessInput(PLAYER *pPlayer, InputPacket *pInput) } else { - if (pInput->syncFlags.lookUp) + if (pInput->actions & (SB_LOOK_UP | SB_AIM_UP)) predict.at20 = fix16_min(predict.at20+fix16_from_dbl(lookStepUp), fix16_from_int(upAngle)); - if (pInput->syncFlags.lookDown) + if (pInput->actions & (SB_LOOK_DOWN | SB_AIM_DOWN)) predict.at20 = fix16_max(predict.at20-fix16_from_dbl(lookStepDown), fix16_from_int(downAngle)); } if (numplayers > 1 && gPrediction) { - if (pInput->syncFlags.lookUp) + if (pInput->actions & (SB_LOOK_UP | SB_AIM_UP)) { gViewLookAdjust += float(lookStepUp); } - if (pInput->syncFlags.lookDown) + if (pInput->actions & (SB_LOOK_DOWN | SB_AIM_DOWN)) { gViewLookAdjust -= float(lookStepDown); } - gViewLookRecenter = predict.at6e && !pInput->syncFlags.lookUp && !pInput->syncFlags.lookDown; + gViewLookRecenter = predict.at6e && !pInput->actions & (SB_LOOK_UP | SB_LOOK_DOWN); } predict.at20 = fix16_clamp(predict.at20+(pInput->q16horz<<3), fix16_from_int(downAngle), fix16_from_int(upAngle)); predict.at24 = fix16_from_float(100.f*tanf(fix16_to_float(predict.at20)*fPI/1024.f)); diff --git a/source/core/gamecvars.h b/source/core/gamecvars.h index 173a77c6b..aaecae826 100644 --- a/source/core/gamecvars.h +++ b/source/core/gamecvars.h @@ -88,7 +88,6 @@ EXTERN_CVAR(Int, gl_ssao) EXTERN_CVAR(Bool, use_joystick) EXTERN_CVAR(Int, in_mousebias) EXTERN_CVAR(Bool, in_mouseflip) -EXTERN_CVAR(Bool, in_mousemode) EXTERN_CVAR(Bool, in_mousesmoothing) EXTERN_CVAR(Float, in_mousesensitivity) EXTERN_CVAR(Float, in_mousescalex) diff --git a/source/core/inputstate.cpp b/source/core/inputstate.cpp index 2c1a0270e..8d5ba3a0e 100644 --- a/source/core/inputstate.cpp +++ b/source/core/inputstate.cpp @@ -329,6 +329,11 @@ CCMD(holsterweapon) ActionsToSend |= SB_HOLSTER; } +CCMD(backoff) +{ + ActionsToSend |= SB_ESCAPE; +} + CCMD(pause) { sendPause = true; @@ -362,6 +367,15 @@ void ApplyGlobalInput(InputPacket& input, ControlInfo *info) input.actions |= ActionsToSend; ActionsToSend = 0; + if (buttonMap.ButtonDown(gamefunc_Aim_Up) || (buttonMap.ButtonDown(gamefunc_Dpad_Aiming) && info->dz > 0)) + input.actions |= SB_AIM_UP; + + if ((buttonMap.ButtonDown(gamefunc_Aim_Down) || (buttonMap.ButtonDown(gamefunc_Dpad_Aiming) && info->dz < 0))) + input.actions |= SB_AIM_DOWN; + + if (buttonMap.ButtonDown(gamefunc_Dpad_Aiming)) + info->dz = 0; + if (buttonMap.ButtonDown(gamefunc_Jump)) input.actions |= SB_JUMP; @@ -382,10 +396,20 @@ void ApplyGlobalInput(InputPacket& input, ControlInfo *info) if (G_CheckAutorun(buttonMap.ButtonDown(gamefunc_Run))) input.actions |= SB_RUN; + if (in_mousemode || buttonMap.ButtonDown(gamefunc_Mouse_Aiming)) + input.actions |= SB_AIMMODE; + + if (buttonMap.ButtonDown(gamefunc_Look_Up)) + input.actions |= SB_LOOK_UP; + + if (buttonMap.ButtonDown(gamefunc_Look_Down)) + input.actions |= SB_LOOK_DOWN; + + if (buttonMap.ButtonDown(gamefunc_Look_Left)) + input.actions |= SB_LOOK_LEFT; + + if (buttonMap.ButtonDown(gamefunc_Look_Right)) + input.actions |= SB_LOOK_RIGHT; + } -#if 0 - - C_RegisterFunction("backoff", nullptr, [](CCmdFuncPtr)->int { BitsToSend |= SKB_ESCAPE; return CCMD_OK; }); - -#endif diff --git a/source/core/packet.h b/source/core/packet.h index 0097f5df1..7b4308f09 100644 --- a/source/core/packet.h +++ b/source/core/packet.h @@ -23,6 +23,18 @@ enum ESyncBits_ : uint32_t SB_HOLSTER = 1 << 16, SB_OPEN = 1 << 17, + SB_AIMMODE = 1 << 18, + + SB_AIM_UP = 1 << 19, + SB_AIM_DOWN = 1 << 20, + SB_LOOK_LEFT = 1 << 21, + SB_LOOK_RIGHT = 1 << 22, + SB_QUICK_KICK = 1 << 23, // Duke only. + SB_CROUCH_LOCK = 1 << 23, // SW only. + SB_ESCAPE = 1 << 24, + + SB_LOOK_UP = 1 << 25, + SB_LOOK_DOWN = 1 << 26, SB_RUN = 1 << 27, SB_JUMP = 1 << 28, SB_CROUCH = 1 << 29, @@ -33,7 +45,7 @@ enum ESyncBits_ : uint32_t SB_ITEMUSE_BITS = (127u * SB_ITEM_BIT_1), SB_BUTTON_MASK = SB_ALTFIRE|SB_FIRE|SB_CROUCH|SB_JUMP, // all input from buttons (i.e. active while held) - SB_INTERFACE_MASK = (SB_INVPREV|SB_INVNEXT|SB_INVUSE|SB_CENTERVIEW|SB_TURNAROUND|SB_HOLSTER|SB_OPEN), // all input from CCMDs + SB_INTERFACE_MASK = (SB_INVPREV|SB_INVNEXT|SB_INVUSE|SB_CENTERVIEW|SB_TURNAROUND|SB_HOLSTER|SB_OPEN|SB_ESCAPE|SB_QUICK_KICK), // all input from CCMDs SB_INTERFACE_BITS = (SB_WEAPONMASK_BITS | SB_ITEMUSE_BITS | SB_INTERFACE_MASK), SB_ALL = ~0u }; @@ -43,14 +55,6 @@ using ESyncBits = TFlags; DEFINE_TFLAGS_OPERATORS(ESyncBits) -// Blood flags -enum -{ - flag_buttonmask = 127, - flag_buttonmask_norun = 126 -}; - - enum { // The maximum valid weapons for the respective games. @@ -65,67 +69,6 @@ enum WeaponSel_Alt = 15 }; -enum EDukeSyncBits_ : uint32_t -{ - SKB_AIM_UP = 1 << 3, - SKB_AIM_DOWN = 1 << 4, - SKB_LOOK_LEFT = 1 << 6, - SKB_LOOK_RIGHT = 1 << 7, - SKB_LOOK_UP = 1 << 13, - SKB_LOOK_DOWN = 1 << 14, - SKB_QUICK_KICK = 1 << 22, - SKB_AIMMODE = 1 << 23, - SKB_ESCAPE = 1u << 31, - - SKB_INTERFACE_BITS = (SKB_QUICK_KICK | \ - SKB_ESCAPE), - - SKB_NONE = 0, - SKB_ALL = ~0u - -}; - -// enforce type safe operations on the input bits. -using EDukeSyncBits = TFlags; -DEFINE_TFLAGS_OPERATORS(EDukeSyncBits) - -union SYNCFLAGS -{ - uint32_t value; - struct - { - unsigned int _run : 1; - unsigned int _jump : 1; - unsigned int _crouch : 1; - unsigned int _shoot : 1; - unsigned int _shoot2 : 1; - unsigned int lookUp : 1; - unsigned int lookDown : 1; - - - unsigned int lookLeft : 1; - unsigned int lookRight : 1; - }; -}; - -// SW - -// -// NETWORK - REDEFINABLE SHARED (SYNC) KEYS BIT POSITIONS -// - - -#define SK_LOOK_UP 12 -#define SK_LOOK_DOWN 13 -#define SK_CRAWL_LOCK 14 -#define SK_FLY 15 - -#define SK_AIM_UP 21 -#define SK_AIM_DOWN 22 - -#define SK_SPACE_BAR 31 - - struct InputPacket { int16_t svel; @@ -136,18 +79,6 @@ struct InputPacket fix16_t q16ang; // only used by SW ESyncBits actions; - // Making this a union lets some constructs fail. Since these names are transitional only the added memory use doesn't really matter. - // for Duke - EDukeSyncBits sbits; - - // for SW - int32_t bits; - - // for Blood - SYNCFLAGS syncFlags; - - // For Exhumed - uint16_t buttons; int getNewWeapon() const { diff --git a/source/exhumed/src/input.cpp b/source/exhumed/src/input.cpp index 0c04a6db9..ed84b54d4 100644 --- a/source/exhumed/src/input.cpp +++ b/source/exhumed/src/input.cpp @@ -31,8 +31,6 @@ BEGIN_PS_NS extern short bPlayerPan; extern short bLockPan; -bool g_MyAimMode; - short nInputStack = 0; short bStackNode[kMaxPlayers]; @@ -158,12 +156,12 @@ void PlayerInterruptKeys(bool after) if (paused) return; - localInput = {}; - InputPacket input{}; + InputPacket tempinput{}; fix16_t input_angle = 0; if (PlayerList[nLocalPlayer].nHealth == 0) { + localInput = {}; lPlayerYVel = 0; lPlayerXVel = 0; nPlayerDAng = 0; @@ -172,6 +170,7 @@ void PlayerInterruptKeys(bool after) if (!after) { + localInput = {}; ApplyGlobalInput(localInput, &info); if (PlayerList[nLocalPlayer].nHealth == 0) localInput.actions &= ~(SB_FIRE | SB_JUMP | SB_CROUCH); } @@ -184,8 +183,8 @@ void PlayerInterruptKeys(bool after) if (buttonMap.ButtonDown(gamefunc_Strafe)) { - input.svel -= info.mousex * 4.f; - input.svel -= info.dyaw * keyMove; + tempinput.svel -= info.mousex * 4.f; + tempinput.svel -= info.dyaw * keyMove; } else { @@ -193,26 +192,26 @@ void PlayerInterruptKeys(bool after) input_angle = fix16_sadd(input_angle, fix16_from_dbl(scaleAdjustmentToInterval(info.dyaw))); } - g_MyAimMode = in_mousemode || buttonMap.ButtonDown(gamefunc_Mouse_Aiming); + bool mouseaim = !!(localInput.actions & SB_AIMMODE); - if (g_MyAimMode) - input.q16horz = fix16_sadd(input.q16horz, fix16_from_float(info.mousey)); + if (mouseaim) + tempinput.q16horz = fix16_sadd(tempinput.q16horz, fix16_from_float(info.mousey)); else - input.fvel -= info.mousey * 8.f; + tempinput.fvel -= info.mousey * 8.f; - if (!in_mouseflip) input.q16horz = -input.q16horz; + if (!in_mouseflip) tempinput.q16horz = -tempinput.q16horz; - input.q16horz = fix16_ssub(input.q16horz, fix16_from_dbl(scaleAdjustmentToInterval(info.dpitch))); - input.svel -= info.dx * keyMove; - input.fvel -= info.dz * keyMove; + tempinput.q16horz = fix16_ssub(tempinput.q16horz, fix16_from_dbl(scaleAdjustmentToInterval(info.dpitch))); + tempinput.svel -= info.dx * keyMove; + tempinput.fvel -= info.dz * keyMove; if (buttonMap.ButtonDown(gamefunc_Strafe)) { if (buttonMap.ButtonDown(gamefunc_Turn_Left)) - input.svel -= -keyMove; + tempinput.svel -= -keyMove; if (buttonMap.ButtonDown(gamefunc_Turn_Right)) - input.svel -= keyMove; + tempinput.svel -= keyMove; } else { @@ -254,19 +253,19 @@ void PlayerInterruptKeys(bool after) } if (buttonMap.ButtonDown(gamefunc_Strafe_Left)) - input.svel += keyMove; + tempinput.svel += keyMove; if (buttonMap.ButtonDown(gamefunc_Strafe_Right)) - input.svel += -keyMove; + tempinput.svel += -keyMove; if (buttonMap.ButtonDown(gamefunc_Move_Forward)) - input.fvel += keyMove; + tempinput.fvel += keyMove; if (buttonMap.ButtonDown(gamefunc_Move_Backward)) - input.fvel += -keyMove; + tempinput.fvel += -keyMove; - localInput.fvel = clamp(localInput.fvel + input.fvel, -12, 12); - localInput.svel = clamp(localInput.svel + input.svel, -12, 12); + localInput.fvel = clamp(localInput.fvel + tempinput.fvel, -12, 12); + localInput.svel = clamp(localInput.svel + tempinput.svel, -12, 12); localInput.q16avel = fix16_sadd(localInput.q16avel, input_angle); @@ -277,11 +276,11 @@ void PlayerInterruptKeys(bool after) // A horiz diff of 128 equal 45 degrees, // so we convert horiz to 1024 angle units - float const horizAngle = clamp(atan2f(PlayerList[nLocalPlayer].q16horiz - fix16_from_int(92), fix16_from_int(128)) * (512.f / fPI) + fix16_to_float(input.q16horz), -255.f, 255.f); + float const horizAngle = clamp(atan2f(PlayerList[nLocalPlayer].q16horiz - fix16_from_int(92), fix16_from_int(128)) * (512.f / fPI) + fix16_to_float(tempinput.q16horz), -255.f, 255.f); PlayerList[nLocalPlayer].q16horiz = fix16_from_int(92) + Blrintf(fix16_from_int(128) * tanf(horizAngle * (fPI / 512.f))); // Look/aim up/down functions. - if (buttonMap.ButtonDown(gamefunc_Look_Up) || buttonMap.ButtonDown(gamefunc_Aim_Up)) + if (localInput.actions & (SB_LOOK_UP|SB_AIM_UP)) { bLockPan = false; if (PlayerList[nLocalPlayer].q16horiz < fix16_from_int(180)) { @@ -291,7 +290,7 @@ void PlayerInterruptKeys(bool after) bPlayerPan = true; nDestVertPan[nLocalPlayer] = PlayerList[nLocalPlayer].q16horiz; } - else if (buttonMap.ButtonDown(gamefunc_Look_Down) || buttonMap.ButtonDown(gamefunc_Aim_Down)) + else if (localInput.actions & (SB_LOOK_DOWN|SB_AIM_DOWN)) { bLockPan = false; if (PlayerList[nLocalPlayer].q16horiz > fix16_from_int(4)) { @@ -308,13 +307,13 @@ void PlayerInterruptKeys(bool after) bPlayerPan = false; } - if (g_MyAimMode) + if (mouseaim) bLockPan = true; // loc_1C05E fix16_t ecx = nDestVertPan[nLocalPlayer] - PlayerList[nLocalPlayer].q16horiz; - if (g_MyAimMode) + if (mouseaim) { ecx = 0; } diff --git a/source/games/duke/src/funct.h b/source/games/duke/src/funct.h index 5621a1127..5cb8e16bf 100644 --- a/source/games/duke/src/funct.h +++ b/source/games/duke/src/funct.h @@ -110,12 +110,12 @@ int makepainsounds(int snum, int type); void playerCrouch(int snum); void playerJump(int snum, int fz, int cz); void applylook(int snum, double factor, fixed_t adjustment); -void checklook(int snum, int sb_snum); +void checklook(int snum, ESyncBits actions); void playerCenterView(int snum); -void playerLookUp(int snum, ESyncBits sb_snum); -void playerLookDown(int snum, ESyncBits sb_snum); -void playerAimUp(int snum, ESyncBits sb_snum); -void playerAimDown(int snum, ESyncBits sb_snum); +void playerLookUp(int snum, ESyncBits actions); +void playerLookDown(int snum, ESyncBits actions); +void playerAimUp(int snum, ESyncBits actions); +void playerAimDown(int snum, ESyncBits actions); bool view(struct player_struct* pp, int* vx, int* vy, int* vz, short* vsectnum, int ang, int horiz); void tracers(int x1, int y1, int z1, int x2, int y2, int z2, int n); int hits(int i); @@ -232,7 +232,7 @@ void PlayerColorChanged(void); void nonsharedkeys(void); void apply_seasick(player_struct* p, double scalefactor); void calcviewpitch(player_struct* p, double factor); -void sethorizon(int snum, int sb_snum, double factor, fixed_t adjustment); +void sethorizon(int snum, ESyncBits actions, double factor, fixed_t adjustment); bool movementBlocked(int snum); void GetInput(); void startmainmenu(); diff --git a/source/games/duke/src/inlines.h b/source/games/duke/src/inlines.h index ec03613aa..a4f8fae52 100644 --- a/source/games/duke/src/inlines.h +++ b/source/games/duke/src/inlines.h @@ -116,26 +116,6 @@ inline bool isIn(int value, const std::initializer_list& list) // these are mainly here to avoid directly accessing the input data so that it can be more easily refactored later. -inline bool PlayerInput(int pl, EDukeSyncBits bit) -{ - return (!!((sync[pl].sbits) & bit)); -} - -inline void PlayerSetInput(int pl, EDukeSyncBits bit) -{ - sync[pl].sbits |= bit; -} - -inline void PlayerClearInput(int pl, EDukeSyncBits bit) -{ - sync[pl].sbits &= ~bit; -} - -inline EDukeSyncBits PlayerInputBits(int pl, EDukeSyncBits bits) -{ - return (sync[pl].sbits & bits); -} - inline bool PlayerInput(int pl, ESyncBits bit) { return (!!((sync[pl].actions) & bit)); diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 760b98d42..ef50282bb 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -150,7 +150,7 @@ void hud_input(int snum) p = &ps[snum]; i = p->aim_mode; - p->aim_mode = PlayerInput(snum, SKB_AIMMODE); + p->aim_mode = PlayerInput(snum, SB_AIMMODE); if (p->aim_mode < i) p->return_to_center = 9; @@ -159,7 +159,7 @@ void hud_input(int snum) if (isRR()) { - if (PlayerInput(snum, SKB_QUICK_KICK) && p->last_pissed_time == 0) + if (PlayerInput(snum, SB_QUICK_KICK) && p->last_pissed_time == 0) { if (!isRRRA() || sprite[p->i].extra > 0) { @@ -177,7 +177,7 @@ void hud_input(int snum) } else { - if (PlayerInput(snum, SKB_QUICK_KICK) && p->quick_kick == 0 && (p->curr_weapon != KNEE_WEAPON || p->kickback_pic == 0)) + if (PlayerInput(snum, SB_QUICK_KICK) && p->quick_kick == 0 && (p->curr_weapon != KNEE_WEAPON || p->kickback_pic == 0)) { SetGameVarID(g_iReturnVarID, 0, -1, snum); OnEvent(EVENT_QUICKKICK, -1, snum, -1); @@ -189,9 +189,9 @@ void hud_input(int snum) } } } - if (!PlayerInput(snum, SKB_QUICK_KICK)) p->quick_kick_msg = false; + if (!PlayerInput(snum, SB_QUICK_KICK)) p->quick_kick_msg = false; - if (!PlayerInputBits(snum, SKB_INTERFACE_BITS) && ! PlayerInputBits(snum, SB_INTERFACE_BITS)) + if (!PlayerInputBits(snum, SB_INTERFACE_BITS)) p->interface_toggle_flag = 0; else if (p->interface_toggle_flag == 0) { @@ -606,38 +606,27 @@ enum static void processInputBits(player_struct *p, ControlInfo &info) { - bool onVehicle = p->OnMotorcycle || p->OnBoat; + ApplyGlobalInput(loc, &info); + if (isRR() && (loc.actions & SB_CROUCH)) loc.actions &= ~SB_JUMP; - if (!onVehicle) + if (p->OnMotorcycle || p->OnBoat) { + // mask out all actions not compatible with vehicles. + loc.actions &= ~(SB_WEAPONMASK_BITS | SB_TURNAROUND | SB_CENTERVIEW | SB_HOLSTER | SB_JUMP | SB_CROUCH | SB_RUN | + SB_AIM_UP | SB_AIM_DOWN | SB_AIMMODE | SB_LOOK_UP | SB_LOOK_DOWN | SB_LOOK_LEFT | SB_LOOK_RIGHT); + } + else + { + if (buttonMap.ButtonDown(gamefunc_Quick_Kick)) // this shares a bit with another function so cannot be in the common code. + loc.actions |= SB_QUICK_KICK; + if (buttonMap.ButtonDown(gamefunc_Toggle_Crouch) || p->crouch_toggle) { loc.actions |= SB_CROUCH; } - if (buttonMap.ButtonDown(gamefunc_Aim_Up) || (buttonMap.ButtonDown(gamefunc_Dpad_Aiming) && info.dz > 0)) loc.sbits |= SKB_AIM_UP; - if ((buttonMap.ButtonDown(gamefunc_Aim_Down) || (buttonMap.ButtonDown(gamefunc_Dpad_Aiming) && info.dz < 0))) loc.sbits |= SKB_AIM_DOWN; - if (buttonMap.ButtonDown(gamefunc_Look_Left)) loc.sbits |= SKB_LOOK_LEFT; - if (buttonMap.ButtonDown(gamefunc_Look_Right)) loc.sbits |= SKB_LOOK_RIGHT; - if (buttonMap.ButtonDown(gamefunc_Look_Up)) loc.sbits |= SKB_LOOK_UP; - if (buttonMap.ButtonDown(gamefunc_Look_Down)) loc.sbits |= SKB_LOOK_DOWN; - if (buttonMap.ButtonDown(gamefunc_Quick_Kick)) loc.sbits |= SKB_QUICK_KICK; - if (in_mousemode || buttonMap.ButtonDown(gamefunc_Mouse_Aiming)) loc.sbits |= SKB_AIMMODE; - - if ((isRR() && p->drink_amt > 88)) loc.sbits |= SKB_LOOK_LEFT; - if ((isRR() && p->drink_amt > 99)) loc.sbits |= SKB_LOOK_DOWN; - + if ((isRR() && p->drink_amt > 88)) loc.actions |= SB_LOOK_LEFT; + if ((isRR() && p->drink_amt > 99)) loc.actions |= SB_LOOK_DOWN; } - ApplyGlobalInput(loc, &info); - if (isRR() && (loc.actions & SB_CROUCH)) loc.actions &= ~SB_JUMP; - - if (onVehicle) - { - // mask out all actions not compatible with vehicles. - loc.actions &= ~(SB_WEAPONMASK_BITS | SB_TURNAROUND | SB_CENTERVIEW | SB_HOLSTER | SB_JUMP | SB_CROUCH | SB_RUN); - } - - if (buttonMap.ButtonDown(gamefunc_Dpad_Aiming)) - info.dz = 0; } //--------------------------------------------------------------------------- @@ -684,7 +673,7 @@ int getticssincelastupdate() static void processMovement(player_struct *p, InputPacket &input, ControlInfo &info, double scaleFactor) { - bool mouseaim = in_mousemode || buttonMap.ButtonDown(gamefunc_Mouse_Aiming); + bool mouseaim = !!(loc.actions & SB_AIMMODE); // JBF: Run key behaviour is selectable int running = !!(loc.actions & SB_RUN); @@ -980,15 +969,15 @@ static void processVehicleInput(player_struct *p, ControlInfo& info, InputPacket if (buttonMap.ButtonDown(gamefunc_Move_Forward) || buttonMap.ButtonDown(gamefunc_Strafe)) loc.actions |= SB_JUMP; if (buttonMap.ButtonDown(gamefunc_Move_Backward)) - loc.sbits |= SKB_AIM_UP; - if (loc.buttons & SB_RUN) + loc.actions |= SB_AIM_UP; + if (loc.actions & SB_RUN) loc.actions |= SB_CROUCH; } if (turnl) - loc.sbits |= SKB_AIM_DOWN; + loc.actions |= SB_AIM_DOWN; if (turnr) - loc.sbits |= SKB_LOOK_LEFT; + loc.actions |= SB_LOOK_LEFT; double turnvel; @@ -1136,7 +1125,7 @@ void GetInput() // Do these in the same order as the old code. calcviewpitch(p, scaleAdjust); applylook(myconnectindex, scaleAdjust, input.q16avel); - sethorizon(myconnectindex, loc.sbits, scaleAdjust, input.q16horz); + sethorizon(myconnectindex, loc.actions, scaleAdjust, input.q16horz); } } diff --git a/source/games/duke/src/player.cpp b/source/games/duke/src/player.cpp index 3d26c81f1..a10df4c78 100644 --- a/source/games/duke/src/player.cpp +++ b/source/games/duke/src/player.cpp @@ -968,13 +968,13 @@ void playerweaponsway(player_struct* p, spritetype* s) // //--------------------------------------------------------------------------- -void checklook(int snum, int sb_snum) +void checklook(int snum, ESyncBits actions) { auto p = &ps[snum]; p->lookLeft = false; p->lookRight = false; - if ((sb_snum & SKB_LOOK_LEFT) && !p->OnMotorcycle) + if ((actions & SB_LOOK_LEFT) && !p->OnMotorcycle) { SetGameVarID(g_iReturnVarID, 0, p->i, snum); OnEvent(EVENT_LOOKLEFT, p->i, snum, -1); @@ -984,7 +984,7 @@ void checklook(int snum, int sb_snum) } } - if ((sb_snum & SKB_LOOK_RIGHT) && !p->OnMotorcycle) + if ((actions & SB_LOOK_RIGHT) && !p->OnMotorcycle) { SetGameVarID(g_iReturnVarID, 0, p->i, snum); OnEvent(EVENT_LOOKRIGHT, p->i, snum, -1); @@ -1002,14 +1002,14 @@ void checklook(int snum, int sb_snum) // //--------------------------------------------------------------------------- -void sethorizon(int snum, int sb_snum, double factor, fixed_t adjustment) +void sethorizon(int snum, ESyncBits actions, double factor, fixed_t adjustment) { auto p = &ps[snum]; // Calculate adjustment as true pitch (Fixed point math really sucks...) double horizAngle = clamp2(atan2(p->q16horiz - F16(100), F16(128)) * (512. / pi::pi()) + (factor * p->pitchAdjust) + (adjustment / 65536.), -180, 180); - if (p->return_to_center > 0 && (sb_snum & (SKB_LOOK_UP | SKB_LOOK_DOWN)) == 0) // only snap back if no relevant button is pressed. + if (p->return_to_center > 0 && (actions & (SB_LOOK_UP | SB_LOOK_DOWN)) == 0) // only snap back if no relevant button is pressed. { p->return_to_center += -factor * (p->return_to_center / 2); horizAngle += -factor * (horizAngle / 2); diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index 8d44d5b7b..79a952f8c 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -41,7 +41,7 @@ source as it is released. BEGIN_DUKE_NS void fireweapon_ww(int snum); -void operateweapon_ww(int snum, ESyncBits actions, EDukeSyncBits sb_snum, int psect); +void operateweapon_ww(int snum, ESyncBits actions, int psect); //--------------------------------------------------------------------------- // @@ -2073,7 +2073,7 @@ static void fireweapon(int snum) // //--------------------------------------------------------------------------- -static void operateweapon(int snum, ESyncBits actions, EDukeSyncBits sb_snum, int psect) +static void operateweapon(int snum, ESyncBits actions, int psect) { auto p = &ps[snum]; int pi = p->i; @@ -2529,7 +2529,7 @@ static void operateweapon(int snum, ESyncBits actions, EDukeSyncBits sb_snum, in // //--------------------------------------------------------------------------- -static void processweapon(int snum, ESyncBits actions, EDukeSyncBits sb_snum, int psect) +static void processweapon(int snum, ESyncBits actions, int psect) { auto p = &ps[snum]; int pi = p->i; @@ -2600,8 +2600,8 @@ static void processweapon(int snum, ESyncBits actions, EDukeSyncBits sb_snum, in } else if (p->kickback_pic) { - if (!isWW2GI()) operateweapon(snum, actions, sb_snum, psect); - else operateweapon_ww(snum, actions, sb_snum, psect); + if (!isWW2GI()) operateweapon(snum, actions, psect); + else operateweapon_ww(snum, actions, psect); } } //--------------------------------------------------------------------------- @@ -2614,7 +2614,6 @@ void processinput_d(int snum) { int j, i, k, doubvel, fz, cz, hz, lz, truefdist; char shrunk; - EDukeSyncBits sb_snum; ESyncBits actions; short psect, psectlotag, pi; struct player_struct* p; @@ -2626,7 +2625,6 @@ void processinput_d(int snum) resetinputhelpers(p); - sb_snum = PlayerInputBits(snum, SKB_ALL); actions = PlayerInputBits(snum, SB_ALL); auto sb_fvel = PlayerInputForwardVel(snum); @@ -2750,14 +2748,14 @@ void processinput_d(int snum) fi.doincrements(p); - if (isWW2GI() && aplWeaponWorksLike[p->curr_weapon][snum] == HANDREMOTE_WEAPON) processweapon(snum, actions, sb_snum, psect); - if (!isWW2GI() && p->curr_weapon == HANDREMOTE_WEAPON) processweapon(snum, actions, sb_snum, psect); + if (isWW2GI() && aplWeaponWorksLike[p->curr_weapon][snum] == HANDREMOTE_WEAPON) processweapon(snum, actions, psect); + if (!isWW2GI() && p->curr_weapon == HANDREMOTE_WEAPON) processweapon(snum, actions, psect); return; } doubvel = TICSPERFRAME; - checklook(snum,sb_snum); + checklook(snum,actions); if (p->on_crane >= 0) goto HORIZONLY; @@ -3016,26 +3014,26 @@ HORIZONLY: { playerCenterView(snum); } - else if (sb_snum & SKB_LOOK_UP) + else if (actions & SB_LOOK_UP) { playerLookUp(snum, actions); } - else if (sb_snum & SKB_LOOK_DOWN) + else if (actions & SB_LOOK_DOWN) { playerLookDown(snum, actions); } - else if (sb_snum & SKB_AIM_UP) + else if (actions & SB_AIM_UP) { playerAimUp(snum, actions); } - else if (sb_snum & SKB_AIM_DOWN) + else if (actions & SB_AIM_DOWN) { // aim_down playerAimDown(snum, actions); } if (cl_syncinput) { - sethorizon(snum, sb_snum, 1, sync[snum].q16horz); + sethorizon(snum, actions, 1, sync[snum].q16horz); } checkhardlanding(p); @@ -3077,7 +3075,7 @@ HORIZONLY: } // HACKS - processweapon(snum, actions, sb_snum, psect); + processweapon(snum, actions, psect); } void processmove_d(int snum, ESyncBits actions, int psect, int fz, int cz, int shrunk, int truefdist) diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index ebe7d4748..c3ae51519 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -1542,7 +1542,7 @@ void checkweapons_r(struct player_struct* p) // //--------------------------------------------------------------------------- -static void onMotorcycle(int snum, ESyncBits &actions, EDukeSyncBits &sb_snum) +static void onMotorcycle(int snum, ESyncBits &actions) { auto p = &ps[snum]; auto pi = p->i; @@ -1605,29 +1605,29 @@ static void onMotorcycle(int snum, ESyncBits &actions, EDukeSyncBits &sb_snum) if (!S_CheckActorSoundPlaying(pi, 189) && !S_CheckActorSoundPlaying(pi, 187)) S_PlayActorSound(187, pi); } - if (sb_snum & SKB_AIM_UP) + if (actions & SB_AIM_UP) { var6c = 1; - sb_snum &= ~SKB_AIM_UP; + actions &= ~SB_AIM_UP; } else var6c = 0; - if (sb_snum & SKB_AIM_DOWN) + if (actions & SB_AIM_DOWN) { var70 = 1; var74 = 1; - sb_snum &= ~SKB_AIM_DOWN; + actions &= ~SB_AIM_DOWN; } else { var70 = 0; var74 = 0; } - if (sb_snum & SKB_LOOK_LEFT) + if (actions & SB_LOOK_LEFT) { var78 = 1; var7c = 1; - sb_snum &= ~SKB_LOOK_LEFT; + actions &= ~SB_LOOK_LEFT; } else { @@ -1835,7 +1835,7 @@ static void onMotorcycle(int snum, ESyncBits &actions, EDukeSyncBits &sb_snum) // //--------------------------------------------------------------------------- -static void onBoat(int snum, ESyncBits &actions, EDukeSyncBits& sb_snum) +static void onBoat(int snum, ESyncBits &actions) { auto p = &ps[snum]; auto pi = p->i; @@ -1908,17 +1908,17 @@ static void onBoat(int snum, ESyncBits &actions, EDukeSyncBits& sb_snum) } else varb0 = 0; - if (sb_snum & SKB_AIM_UP) + if (actions & SB_AIM_UP) { varb4 = 1; - sb_snum &= ~SKB_AIM_UP; + actions &= ~SB_AIM_UP; } else varb4 = 0; - if (sb_snum & SKB_AIM_DOWN) + if (actions & SB_AIM_DOWN) { varb8 = 1; varbc = 1; - sb_snum &= ~SKB_AIM_DOWN; + actions &= ~SB_AIM_DOWN; if (!S_CheckActorSoundPlaying(pi, 91) && p->MotoSpeed > 30 && !p->NotOnWater) S_PlayActorSound(91, pi); } @@ -1927,11 +1927,11 @@ static void onBoat(int snum, ESyncBits &actions, EDukeSyncBits& sb_snum) varb8 = 0; varbc = 0; } - if (sb_snum & SKB_LOOK_LEFT) + if (actions & SB_LOOK_LEFT) { varc0 = 1; varc4 = 1; - sb_snum &= ~SKB_LOOK_LEFT; + actions &= ~SB_LOOK_LEFT; if (!S_CheckActorSoundPlaying(pi, 91) && p->MotoSpeed > 30 && !p->NotOnWater) S_PlayActorSound(91, pi); } @@ -2119,7 +2119,7 @@ static void onBoat(int snum, ESyncBits &actions, EDukeSyncBits& sb_snum) // //--------------------------------------------------------------------------- -static void movement(int snum, ESyncBits actions, EDukeSyncBits sb_snum, int psect, int fz, int cz, int shrunk, int truefdist, int psectlotag) +static void movement(int snum, ESyncBits actions, int psect, int fz, int cz, int shrunk, int truefdist, int psectlotag) { auto p = &ps[snum]; auto pi = p->i; @@ -2349,7 +2349,7 @@ static void movement(int snum, ESyncBits actions, EDukeSyncBits sb_snum, int pse // //--------------------------------------------------------------------------- -static void underwater(int snum, ESyncBits actions, EDukeSyncBits sb_snum, int psect, int fz, int cz) +static void underwater(int snum, ESyncBits actions, int psect, int fz, int cz) { int j; auto p = &ps[snum]; @@ -2773,7 +2773,7 @@ static void fireweapon(int snum) // //--------------------------------------------------------------------------- -static void operateweapon(int snum, ESyncBits actions, EDukeSyncBits sb_snum, int psect) +static void operateweapon(int snum, ESyncBits actions, int psect) { auto p = &ps[snum]; int pi = p->i; @@ -3365,7 +3365,7 @@ static void operateweapon(int snum, ESyncBits actions, EDukeSyncBits sb_snum, in // //--------------------------------------------------------------------------- -static void processweapon(int snum, ESyncBits actions, EDukeSyncBits sb_snum, int psect) +static void processweapon(int snum, ESyncBits actions, int psect) { auto p = &ps[snum]; int pi = p->i; @@ -3416,7 +3416,7 @@ static void processweapon(int snum, ESyncBits actions, EDukeSyncBits sb_snum, in } else if (p->kickback_pic) { - operateweapon(snum, actions, sb_snum, psect); + operateweapon(snum, actions, psect); } } @@ -3430,7 +3430,6 @@ void processinput_r(int snum) { int j, i, k, doubvel, fz, cz, hz, lz, truefdist, var60; char shrunk; - EDukeSyncBits sb_snum; ESyncBits actions; short psect, psectlotag, pi; struct player_struct* p; @@ -3442,7 +3441,6 @@ void processinput_r(int snum) resetinputhelpers(p); - sb_snum = PlayerInputBits(snum, SKB_ALL); actions = PlayerInputBits(snum, SB_ALL); auto sb_fvel = PlayerInputForwardVel(snum); @@ -3452,11 +3450,11 @@ void processinput_r(int snum) psect = p->cursectnum; if (p->OnMotorcycle && s->extra > 0) { - onMotorcycle(snum, actions, sb_snum); + onMotorcycle(snum, actions); } else if (p->OnBoat && s->extra > 0) { - onBoat(snum, actions, sb_snum); + onBoat(snum, actions); } if (psect == -1) { @@ -3663,13 +3661,13 @@ void processinput_r(int snum) fi.doincrements(p); - if (p->curr_weapon == THROWINGDYNAMITE_WEAPON) processweapon(snum, actions, sb_snum, psect); + if (p->curr_weapon == THROWINGDYNAMITE_WEAPON) processweapon(snum, actions, psect); return; } doubvel = TICSPERFRAME; - checklook(snum, sb_snum); + checklook(snum, actions); if (p->on_crane >= 0) goto HORIZONLY; @@ -3709,11 +3707,11 @@ void processinput_r(int snum) if (psectlotag == ST_2_UNDERWATER) { - underwater(snum, actions, sb_snum, psect, fz, cz); + underwater(snum, actions, psect, fz, cz); } else { - movement(snum, actions, sb_snum, psect, fz, cz, shrunk, truefdist, psectlotag); + movement(snum, actions, psect, fz, cz, shrunk, truefdist, psectlotag); } p->psectlotag = psectlotag; @@ -4060,19 +4058,19 @@ HORIZONLY: { playerCenterView(snum); } - else if (sb_snum & SKB_LOOK_UP) + else if (actions & SB_LOOK_UP) { playerLookUp(snum, actions); } - else if (sb_snum & SKB_LOOK_DOWN) + else if (actions & SB_LOOK_DOWN) { playerLookDown(snum, actions); } - else if ((sb_snum & SKB_AIM_UP) && !p->OnMotorcycle) + else if ((actions & SB_AIM_UP) && !p->OnMotorcycle) { playerAimUp(snum, actions); } - else if ((sb_snum & SKB_AIM_DOWN) && !p->OnMotorcycle) + else if ((actions & SB_AIM_DOWN) && !p->OnMotorcycle) { playerAimDown(snum, actions); } @@ -4087,7 +4085,7 @@ HORIZONLY: if (cl_syncinput) { - sethorizon(snum, sb_snum, 1, sync[snum].q16horz); + sethorizon(snum, actions, 1, sync[snum].q16horz); } checkhardlanding(p); @@ -4123,7 +4121,7 @@ HORIZONLY: else p->weapon_pos--; } - processweapon(snum, actions, sb_snum, psect); + processweapon(snum, actions, psect); } //--------------------------------------------------------------------------- @@ -4132,17 +4130,17 @@ HORIZONLY: // //--------------------------------------------------------------------------- -void processmove_r(int snum, ESyncBits actions, EDukeSyncBits sb_snum, int psect, int fz, int cz, int shrunk, int truefdist) +void processmove_r(int snum, ESyncBits actions, int psect, int fz, int cz, int shrunk, int truefdist) { int psectlotag = sector[psect].lotag; auto p = &ps[snum]; if (psectlotag == ST_2_UNDERWATER) { - underwater(snum, actions, sb_snum, psect, fz, cz); + underwater(snum, actions, psect, fz, cz); } else { - movement(snum, actions, sb_snum, psect, fz, cz, shrunk, truefdist, psectlotag); + movement(snum, actions, psect, fz, cz, shrunk, truefdist, psectlotag); } } diff --git a/source/games/duke/src/player_w.cpp b/source/games/duke/src/player_w.cpp index 031334a14..08e7beed0 100644 --- a/source/games/duke/src/player_w.cpp +++ b/source/games/duke/src/player_w.cpp @@ -306,7 +306,7 @@ void fireweapon_ww(int snum) // //--------------------------------------------------------------------------- -void operateweapon_ww(int snum, ESyncBits actions, EDukeSyncBits sb_snum, int psect) +void operateweapon_ww(int snum, ESyncBits actions, int psect) { auto p = &ps[snum]; int pi = p->i; diff --git a/source/games/duke/src/prediction.cpp b/source/games/duke/src/prediction.cpp index c96fa5431..48b8ff00b 100644 --- a/source/games/duke/src/prediction.cpp +++ b/source/games/duke/src/prediction.cpp @@ -98,14 +98,15 @@ void fakedomovethingscorrect(void) } +// This still needs fixing for the magic numbers in the input bits void fakedomovethings(void) { input *syn; struct player_struct *p; int i, j, k, doubvel, fz, cz, hz, lz, x, y; - EDukeSyncBits sb_snum; short psect, psectlotag, tempsect, backcstat; uint8_t shrunk, spritebridge; + ESyncBits actions; syn = (input *)&inputfifo[fakemovefifoplc&(MOVEFIFOSIZ-1)][myconnectindex]; @@ -114,7 +115,7 @@ void fakedomovethings(void) backcstat = sprite[p->i].cstat; sprite[p->i].cstat &= ~257; - sb_snum = syn->bits; + actions = syn->actions; psect = mycursectnum; psectlotag = sector[psect].lotag; diff --git a/source/games/duke/src/sectors_d.cpp b/source/games/duke/src/sectors_d.cpp index d03d3fda7..d7cc97477 100644 --- a/source/games/duke/src/sectors_d.cpp +++ b/source/games/duke/src/sectors_d.cpp @@ -1532,13 +1532,13 @@ void checksectors_d(int snum) } } - if (!(PlayerInput(snum, SB_OPEN)) && !PlayerInput(snum, SKB_ESCAPE)) + if (!(PlayerInput(snum, SB_OPEN))) p->toggle_key_flag = 0; else if (!p->toggle_key_flag) { - if (PlayerInput(snum, SKB_ESCAPE)) + if (PlayerInput(snum, SB_ESCAPE)) { if (p->newowner >= 0) { diff --git a/source/games/duke/src/sectors_r.cpp b/source/games/duke/src/sectors_r.cpp index 7430e9bfa..42ec2f645 100644 --- a/source/games/duke/src/sectors_r.cpp +++ b/source/games/duke/src/sectors_r.cpp @@ -2488,7 +2488,7 @@ void checksectors_r(int snum) fi.lotsofmoney(&sprite[p->i], 2); - if (!(PlayerInput(snum, SB_OPEN)) && !PlayerInput(snum, SKB_ESCAPE)) + if (!(PlayerInput(snum, SB_OPEN))) p->toggle_key_flag = 0; else if (!p->toggle_key_flag) diff --git a/source/sw/src/eel.cpp b/source/sw/src/eel.cpp index 6fdfe6acb..a93787e83 100644 --- a/source/sw/src/eel.cpp +++ b/source/sw/src/eel.cpp @@ -616,9 +616,6 @@ int DoEelMove(short SpriteNum) else (*u->ActorActionFunc)(SpriteNum); - //if (TEST_SYNC_KEY((Player+myconnectindex), SK_OPERATE)) - // CON_Message("Stop"); - DoEelMatchPlayerZ(SpriteNum); DoActorSectorDamage(SpriteNum); diff --git a/source/sw/src/game.h b/source/sw/src/game.h index 8f68ac82e..7b44571cf 100644 --- a/source/sw/src/game.h +++ b/source/sw/src/game.h @@ -255,17 +255,6 @@ extern SWBOOL MenuInputMode; #define SectorIsDiveArea(sect) (TEST(sector[sect].extra, SECTFX_DIVE_AREA) ? TRUE : FALSE) #define SectorIsUnderwaterArea(sect) (TEST(sector[sect].extra, SECTFX_UNDERWATER|SECTFX_UNDERWATER2) ? TRUE : FALSE) -// Key Press Flags macros -#define FLAG_KEY_PRESSED(pp,sync_key) TEST(pp->KeyPressFlags,1<KeyPressFlags,1<KeyPressFlags,1<input.bits, ((!!(key_test)) << (sync_num))) -#define TEST_SYNC_KEY(player, sync_num) TEST((player)->input.bits, (1 << (sync_num))) -#define RESET_SYNC_KEY(player, sync_num) RESET((player)->input.bits, (1 << (sync_num))) - #define TRAVERSE_SPRITE_SECT(l, o, n) for ((o) = (l); (n) = (o) == -1 ? -1 : nextspritesect[o], (o) != -1; (o) = (n)) #define TRAVERSE_SPRITE_STAT(l, o, n) for ((o) = (l); (n) = (o) == -1 ? -1 : nextspritestat[o], (o) != -1; (o) = (n)) #define TRAVERSE_CONNECT(i) for (i = connecthead; i != -1; i = connectpoint2[i]) @@ -916,6 +905,7 @@ struct PLAYERstruct // variables that do not fit into sprite structure int hvel,tilt,tilt_dest; + bool centering; fix16_t q16horiz, q16horizbase, q16horizoff, q16ang; fix16_t camq16horiz, camq16ang; short recoil_amt; @@ -967,7 +957,6 @@ struct PLAYERstruct PLAYER_ACTION_FUNCp DoPlayerAction; int Flags, Flags2; ESyncBits KeyPressBits; - int KeyPressFlags; SECTOR_OBJECTp sop_control; // sector object pointer SECTOR_OBJECTp sop_riding; // sector object pointer diff --git a/source/sw/src/input.cpp b/source/sw/src/input.cpp index 1848cadc6..fcb3caac9 100644 --- a/source/sw/src/input.cpp +++ b/source/sw/src/input.cpp @@ -113,7 +113,37 @@ getinput(InputPacket *loc, SWBOOL tied) lastInputTicks = currentHiTicks; - bool mouseaim = in_mousemode || buttonMap.ButtonDown(gamefunc_Mouse_Aiming); + ControlInfo info; + CONTROL_GetInput(&info); + + if (paused) + return; + + // If in 2D follow mode, scroll around using glob vars + // Tried calling this in domovethings, but key response it too poor, skips key presses + // Note: this get called only during follow mode + if (!tied && automapFollow && automapMode != am_off && pp == Player + myconnectindex && !Prediction) + MoveScrollMode2D(Player + myconnectindex); + + // !JIM! Added M_Active() so that you don't move at all while using menus + if (M_Active() || automapFollow) + return; + + int32_t turnamount; + int32_t keymove; + + // The function DoPlayerTurn() scales the player's q16angvel by 1.40625, so store as constant + // and use to scale back player's aim and ang values for a consistent feel between games. + float const angvelScale = 1.40625f; + float const aimvelScale = 1.203125f; + + // Shadow Warrior has a ticrate of 40, 25% more than the other games, so store below constant + // for dividing controller input to match speed input speed of other games. + float const ticrateScale = 0.75f; + + ApplyGlobalInput(*loc, &info); + + bool mouseaim = !!(loc->actions & SB_AIMMODE); if (!CommEnabled) { @@ -131,37 +161,10 @@ getinput(InputPacket *loc, SWBOOL tied) RESET(Player[myconnectindex].Flags, PF_AUTO_AIM); } - ControlInfo info; - CONTROL_GetInput(&info); - if (paused) - return; - // If in 2D follow mode, scroll around using glob vars - // Tried calling this in domovethings, but key response it too poor, skips key presses - // Note: this get called only during follow mode - if (!tied && automapFollow && automapMode != am_off && pp == Player + myconnectindex && !Prediction) - MoveScrollMode2D(Player + myconnectindex); - - // !JIM! Added M_Active() so that you don't move at all while using menus - if (M_Active() || automapFollow) - return; - - SET_LOC_KEY(loc->bits, SK_SPACE_BAR, buttonMap.ButtonDown(gamefunc_Open)); - - int32_t turnamount; - int32_t keymove; - - // The function DoPlayerTurn() scales the player's q16angvel by 1.40625, so store as constant - // and use to scale back player's aim and ang values for a consistent feel between games. - float const angvelScale = 1.40625f; - float const aimvelScale = 1.203125f; - - // Shadow Warrior has a ticrate of 40, 25% more than the other games, so store below constant - // for dividing controller input to match speed input speed of other games. - float const ticrateScale = 0.75f; - - ApplyGlobalInput(*loc, &info); + if (buttonMap.ButtonDown(gamefunc_Toggle_Crouch)) // this shares a bit with another function so cannot be in the common code. + loc->actions |= SB_CROUCH_LOCK; if (loc->actions & SB_RUN) @@ -310,14 +313,6 @@ getinput(InputPacket *loc, SWBOOL tied) loc->q16horz += q16horz; - // actually snap - SET_LOC_KEY(loc->bits, SK_AIM_UP, buttonMap.ButtonDown(gamefunc_Aim_Up)); - SET_LOC_KEY(loc->bits, SK_AIM_DOWN, buttonMap.ButtonDown(gamefunc_Aim_Down)); - - // actually just look - SET_LOC_KEY(loc->bits, SK_LOOK_UP, buttonMap.ButtonDown(gamefunc_Look_Up)); - SET_LOC_KEY(loc->bits, SK_LOOK_DOWN, buttonMap.ButtonDown(gamefunc_Look_Down)); - if (loc->getNewWeapon() == WeaponSel_Next) { USERp u = User[pp->PlayerSprite]; @@ -394,9 +389,6 @@ getinput(InputPacket *loc, SWBOOL tied) loc->setNewWeapon(which_weapon); } - // need BUTTON - SET_LOC_KEY(loc->bits, SK_CRAWL_LOCK, buttonMap.ButtonDown(gamefunc_Toggle_Crouch)); - if (gNet.MultiGameType == MULTI_GAME_COOPERATIVE) { if (buttonMap.ButtonDown(gamefunc_See_Coop_View)) diff --git a/source/sw/src/network.cpp b/source/sw/src/network.cpp index 632ee2555..63afbcc87 100644 --- a/source/sw/src/network.cpp +++ b/source/sw/src/network.cpp @@ -82,7 +82,6 @@ typedef struct fix16_t q16horz; fix16_t q16ang; fix16_t q16horiz; - int32_t bits; ESyncBits actions; } SW_AVERAGE_PACKET; @@ -203,7 +202,6 @@ UpdateInputs(void) AveragePacket.q16horz += loc.q16horz; AveragePacket.q16ang = Player[myconnectindex].camq16ang; AveragePacket.q16horiz = Player[myconnectindex].camq16horiz; - SET(AveragePacket.bits, loc.bits); SET(AveragePacket.actions, loc.actions); // The above would or the weapon numbers together. Undo that now. The last one should win. AveragePacket.actions &= ~SB_WEAPONMASK_BITS; @@ -229,7 +227,6 @@ UpdateInputs(void) loc.q16horz = fix16_div(AveragePacket.q16horz, fix16_from_int(MovesPerPacket)); loc.q16ang = AveragePacket.q16ang; loc.q16horiz = AveragePacket.q16horiz; - loc.bits = AveragePacket.bits; loc.actions = AveragePacket.actions; memset(&AveragePacket, 0, sizeof(AveragePacket)); diff --git a/source/sw/src/panel.cpp b/source/sw/src/panel.cpp index 4cc12b940..829f22606 100644 --- a/source/sw/src/panel.cpp +++ b/source/sw/src/panel.cpp @@ -6509,10 +6509,8 @@ pFistRest(PANEL_SPRITEp psp) // Reset move to default psp->PlayerP->WpnKungFuMove = 0; - //if ((psp->PlayerP->input.actions & SB_FIRE) || force || TEST_SYNC_KEY(psp->PlayerP, SK_OPERATE)) if ((psp->PlayerP->input.actions & SB_FIRE) || force) { - //if ((psp->PlayerP->KeyPressBits & SB_FIRE) || force || FLAG_KEY_PRESSED(psp->PlayerP, SK_OPERATE)) if ((psp->PlayerP->KeyPressBits & SB_FIRE) || force) { RESET(psp->flags, PANF_UNHIDE_SHOOT); diff --git a/source/sw/src/player.cpp b/source/sw/src/player.cpp index a0f817c8e..c49f87bc2 100644 --- a/source/sw/src/player.cpp +++ b/source/sw/src/player.cpp @@ -1938,7 +1938,7 @@ DoPlayerHorizon(PLAYERp pp, fix16_t *pq16horiz, fix16_t q16horz) SET(pp->Flags, PF_LOCK_HORIZ | PF_LOOKING); } - if (pp->input.actions & SB_CENTERVIEW) + if ((pp->input.actions & SB_CENTERVIEW) || pp->centering) { if (PedanticMode) pp->q16horizbase = fix16_from_int(100); @@ -1952,18 +1952,19 @@ DoPlayerHorizon(PLAYERp pp, fix16_t *pq16horiz, fix16_t q16horz) pp->q16horizbase = fix16_sadd(pp->q16horizbase, fix16_from_float(scaleAdjustmentToInterval((HORIZ_SPEED*6)))); pp->q16horizbase = fix16_min(pp->q16horizbase, fix16_from_int(100)); } + pp->centering = pp->q16horizbase != fix16_from_int(100); *pq16horiz = pp->q16horizbase; pp->q16horizoff = 0; } // this is the locked type - if (TEST_SYNC_KEY(pp, SK_AIM_UP) || TEST_SYNC_KEY(pp, SK_AIM_DOWN)) + if (pp->input.actions & (SB_AIM_UP|SB_AIM_DOWN)) { // set looking because player is manually looking SET(pp->Flags, PF_LOCK_HORIZ | PF_LOOKING); // adjust *pq16horiz negative - if (TEST_SYNC_KEY(pp, SK_AIM_DOWN)) + if (pp->input.actions & SB_AIM_DOWN) { if (PedanticMode) pp->q16horizbase -= fix16_from_int((HORIZ_SPEED/2)); @@ -1972,23 +1973,24 @@ DoPlayerHorizon(PLAYERp pp, fix16_t *pq16horiz, fix16_t q16horz) } // adjust *pq16horiz positive - if (TEST_SYNC_KEY(pp, SK_AIM_UP)) + if (pp->input.actions & SB_AIM_UP) { if (PedanticMode) pp->q16horizbase += fix16_from_int((HORIZ_SPEED/2)); else pp->q16horizbase = fix16_sadd(pp->q16horizbase, fix16_from_float(scaleAdjustmentToInterval((HORIZ_SPEED/2)))); } + pp->centering = false; } // this is the unlocked type - if (TEST_SYNC_KEY(pp, SK_LOOK_UP) || TEST_SYNC_KEY(pp, SK_LOOK_DOWN)) + if (pp->input.actions & (SB_LOOK_UP|SB_LOOK_DOWN)) { RESET(pp->Flags, PF_LOCK_HORIZ); SET(pp->Flags, PF_LOOKING); // adjust *pq16horiz negative - if (TEST_SYNC_KEY(pp, SK_LOOK_DOWN)) + if (pp->input.actions & SB_LOOK_DOWN) { if (PedanticMode) pp->q16horizbase -= fix16_from_int(HORIZ_SPEED); @@ -1997,18 +1999,19 @@ DoPlayerHorizon(PLAYERp pp, fix16_t *pq16horiz, fix16_t q16horz) } // adjust *pq16horiz positive - if (TEST_SYNC_KEY(pp, SK_LOOK_UP)) + if (pp->input.actions & SB_LOOK_UP) { if (PedanticMode) pp->q16horizbase += fix16_from_int(HORIZ_SPEED); else pp->q16horizbase = fix16_sadd(pp->q16horizbase, fix16_from_float(scaleAdjustmentToInterval(HORIZ_SPEED))); } + pp->centering = false; } if (!TEST(pp->Flags, PF_LOCK_HORIZ)) { - if (!(TEST_SYNC_KEY(pp, SK_LOOK_UP) || TEST_SYNC_KEY(pp, SK_LOOK_DOWN))) + if (!(pp->input.actions & (SB_LOOK_UP|SB_LOOK_DOWN))) { // not pressing the *pq16horiz keys if (pp->q16horizbase != fix16_from_int(100)) @@ -2043,9 +2046,6 @@ DoPlayerHorizon(PLAYERp pp, fix16_t *pq16horiz, fix16_t q16horz) else if (pp->q16horizbase + pp->q16horizoff > fix16_from_int(PLAYER_HORIZ_MAX)) pp->q16horizoff = fix16_from_int(PLAYER_HORIZ_MAX) - pp->q16horizbase; - ////DSPRINTF(ds,"base %d, off %d, base + off %d",fix16_to_int(pp->q16horizbase), fix16_to_int(pp->q16horizoff), fix16_to_int(pp->q16horizbase + pp->q16horizoff)); - //MONO_PRINT(ds); - // add base and offsets *pq16horiz = pp->q16horizbase + pp->q16horizoff; #else @@ -4148,14 +4148,14 @@ DoPlayerCrawl(PLAYERp pp) if (TEST(pp->Flags, PF_LOCK_CRAWL)) { - if (TEST_SYNC_KEY(pp, SK_CRAWL_LOCK)) + if (pp->input.actions & SB_CROUCH_LOCK) { - if (FLAG_KEY_PRESSED(pp, SK_CRAWL_LOCK)) + if (pp->KeyPressBits & SB_CROUCH_LOCK) { //if (pp->hiz < PLAYER_STANDING_ROOM(pp)) if (labs(pp->loz - pp->hiz) >= PLAYER_STANDING_ROOM) { - FLAG_KEY_RELEASE(pp, SK_CRAWL_LOCK); + pp->KeyPressBits&= ~SB_CROUCH_LOCK; RESET(pp->Flags, PF_CRAWLING); DoPlayerBeginRun(pp); @@ -4165,7 +4165,7 @@ DoPlayerCrawl(PLAYERp pp) } else { - FLAG_KEY_RESET(pp, SK_CRAWL_LOCK); + pp->KeyPressBits |= SB_CROUCH_LOCK; } // Jump to get up @@ -6040,7 +6040,6 @@ DoPlayerOperateTank(PLAYERp pp) { short save_sectnum; - //ASSERT(!TEST_SYNC_KEY(pp, SK_OPERATE)); if (pp->input.actions & SB_OPEN) { if (pp->KeyPressBits & SB_OPEN) @@ -6618,8 +6617,7 @@ void DoPlayerDeathCheckKeys(PLAYERp pp) SPRITEp sp = pp->SpriteP; USERp u = User[pp->PlayerSprite]; - //if (pp->input.actions & SB_OPEN) - if (TEST_SYNC_KEY(pp, SK_SPACE_BAR)) + if (pp->input.actions & SB_OPEN) { // Spawn a dead LoWang body for non-head deaths // Hey Frank, if you think of a better check, go ahead and put it in. @@ -7149,11 +7147,11 @@ DoPlayerRun(PLAYERp pp) } // Crawl lock - if (TEST_SYNC_KEY(pp, SK_CRAWL_LOCK)) + if (pp->input.actions & SB_CROUCH_LOCK) { - if (FLAG_KEY_PRESSED(pp, SK_CRAWL_LOCK)) + if (pp->KeyPressBits & SB_CROUCH_LOCK) { - FLAG_KEY_RELEASE(pp, SK_CRAWL_LOCK); + pp->KeyPressBits &= ~SB_CROUCH_LOCK; SET(pp->Flags, PF_LOCK_CRAWL); DoPlayerBeginCrawl(pp); return; @@ -7161,7 +7159,7 @@ DoPlayerRun(PLAYERp pp) } else { - FLAG_KEY_RESET(pp, SK_CRAWL_LOCK); + pp->KeyPressBits |= SB_CROUCH_LOCK; } if (PlayerFlyKey()) @@ -7407,8 +7405,8 @@ void ChopsCheck(PLAYERp pp) { if (!M_Active() && !TEST(pp->Flags, PF_DEAD) && !pp->sop_riding && numplayers <= 1) { - if ((pp->input.bits|pp->input.fvel|pp->input.svel|pp->input.q16avel|pp->input.q16horz) || - TEST(pp->Flags, PF_CLIMBING|PF_FALLING|PF_DIVING)) + if (pp->input.actions || pp->input.fvel || pp->input.svel || pp->input.q16avel || pp->input.q16horz || + TEST(pp->Flags, PF_CLIMBING | PF_FALLING | PF_DIVING)) { // Hit a input key or other reason to stop chops //if (pp->Chops && pp->Chops->State != pp->Chops->State->RetractState) @@ -7788,7 +7786,6 @@ InitAllPlayers(void) pp->WpnGotOnceFlags = 0; pp->DoPlayerAction = DoPlayerBeginRun; pp->KeyPressBits = ESyncBits::FromInt(0xFFFFFFFF); - pp->KeyPressFlags = 0xFFFFFFFF; memset(pp->KilledPlayer,0,sizeof(pp->KilledPlayer)); if (NewGame)