From 18ef460a99242d02ac5fde5a2cefb0b4fcbe1b4d Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Mon, 13 Mar 2023 21:17:33 +1100 Subject: [PATCH 01/67] - Tidy up interface for `PlayerAngles::doViewPitch()` since we have internal access to the player's actor. --- source/core/gameinput.cpp | 17 +++++++++-------- source/core/gameinput.h | 2 +- source/games/blood/src/player.cpp | 17 ++--------------- source/games/duke/src/inlines.h | 3 +-- source/games/sw/src/player.cpp | 4 ++-- 5 files changed, 15 insertions(+), 28 deletions(-) diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index c73f990a5..a3fc34094 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -240,30 +240,31 @@ void PlayerAngles::doYawKeys(ESyncBits* actions) // //--------------------------------------------------------------------------- -void PlayerAngles::doViewPitch(const DVector2& pos, DAngle const ang, bool const aimmode, bool const canslopetilt, sectortype* const cursectnum, bool const climbing) +void PlayerAngles::doViewPitch(const bool canslopetilt, const bool climbing) { - if (cl_slopetilting && cursectnum != nullptr) + if (cl_slopetilting) { - if (aimmode && canslopetilt) // If the floor is sloped + const auto actorsect = pActor->sector(); + if (actorsect && (actorsect->floorstat & CSTAT_SECTOR_SLOPE) && canslopetilt) // If the floor is sloped { // Get a point, 512 (64 for Blood) units ahead of player's position - auto rotpt = pos + ang.ToVector() * (!isBlood() ? 32 : 4); - auto tempsect = cursectnum; + const auto rotpt = pActor->spr.pos.XY() + pActor->spr.Angles.Yaw.ToVector() * (!isBlood() ? 32 : 4); + auto tempsect = actorsect; updatesector(rotpt, &tempsect); if (tempsect != nullptr) // If the new point is inside a valid sector... { // Get the floorz as if the new (x,y) point was still in // your sector, unless it's Blood. - double const j = getflorzofslopeptr(cursectnum, pos); - double const k = getflorzofslopeptr(!isBlood() ? cursectnum : tempsect, rotpt); + const double j = getflorzofslopeptr(actorsect, pActor->spr.pos.XY()); + const double k = getflorzofslopeptr(!isBlood() ? actorsect : tempsect, rotpt); // If extended point is in same sector as you or the slopes // of the sector of the extended point and your sector match // closely (to avoid accidently looking straight out when // you're at the edge of a sector line) then adjust horizon // accordingly - if (cursectnum == tempsect || (!isBlood() && abs(getflorzofslopeptr(tempsect, rotpt) - k) <= 4)) + if (actorsect == tempsect || (!isBlood() && abs(getflorzofslopeptr(tempsect, rotpt) - k) <= 4)) { ViewAngles.Pitch -= maphoriz((j - k) * (!isBlood() ? 0.625 : 5.5)); } diff --git a/source/core/gameinput.h b/source/core/gameinput.h index 9973dab7d..d7a4e2164 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -22,7 +22,7 @@ struct PlayerAngles // Prototypes. void doPitchKeys(ESyncBits* actions, const bool stopcentering); void doYawKeys(ESyncBits* actions); - void doViewPitch(const DVector2& pos, DAngle const ang, bool const aimmode, bool const canslopetilt, sectortype* const cursectnum, bool const climbing = false); + void doViewPitch(const bool canslopetilt, const bool climbing = false); void doViewYaw(const ESyncBits actions); // General methods. diff --git a/source/games/blood/src/player.cpp b/source/games/blood/src/player.cpp index 8081cec34..0394fa357 100644 --- a/source/games/blood/src/player.cpp +++ b/source/games/blood/src/player.cpp @@ -1493,20 +1493,6 @@ int ActionScan(PLAYER* pPlayer, HitInfo* out) return -1; } -//--------------------------------------------------------------------------- -// -// Player's slope tilting wrapper function function, called in ProcessInput() or from gi->GetInput() as required. -// -//--------------------------------------------------------------------------- - -void doslopetilting(PLAYER* pPlayer) -{ - auto plActor = pPlayer->actor; - int const florhit = pPlayer->actor->hit.florhit.type; - bool const va = plActor->xspr.height < 16 && (florhit == kHitSector || florhit == 0) ? 1 : 0; - pPlayer->Angles.doViewPitch(plActor->spr.pos.XY(), plActor->spr.Angles.Yaw, va, plActor->sector()->floorstat & CSTAT_SECTOR_SLOPE, plActor->sector()); -} - //--------------------------------------------------------------------------- // // @@ -1717,8 +1703,9 @@ void ProcessInput(PLAYER* pPlayer) pPlayer->actor->spr.Angles.Pitch += DAngle::fromDeg(pInput->horz); } + const int florhit = pPlayer->actor->hit.florhit.type; + pPlayer->Angles.doViewPitch(actor->xspr.height < 16 && (florhit == kHitSector || florhit == 0)); pPlayer->Angles.doPitchKeys(&pInput->actions, pInput->horz); - doslopetilting(pPlayer); pPlayer->slope = pPlayer->actor->spr.Angles.Pitch.Tan(); if (pInput->actions & SB_INVPREV) diff --git a/source/games/duke/src/inlines.h b/source/games/duke/src/inlines.h index e7eacdfe9..5648de43d 100644 --- a/source/games/duke/src/inlines.h +++ b/source/games/duke/src/inlines.h @@ -234,8 +234,7 @@ inline bool playrunning() inline void doslopetilting(player_struct* p) { - bool const canslopetilt = p->on_ground && p->insector() && p->cursector->lotag != ST_2_UNDERWATER && (p->cursector->floorstat & CSTAT_SECTOR_SLOPE); - p->Angles.doViewPitch(p->GetActor()->spr.pos.XY(), p->GetActor()->spr.Angles.Yaw, p->aim_mode == 0, canslopetilt, p->cursector); + p->Angles.doViewPitch(p->aim_mode == 0 && p->on_ground && p->cursector->lotag != ST_2_UNDERWATER); } //--------------------------------------------------------------------------- diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index 40b3176d9..7abc652c7 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -1663,8 +1663,8 @@ void SlipSlope(PLAYER* pp) void DoPlayerSlopeTilting(PLAYER* pp) { - bool const canslopetilt = !(pp->Flags & (PF_FLYING|PF_SWIMMING|PF_DIVING|PF_CLIMBING|PF_JUMPING|PF_FALLING)) && pp->cursector && (pp->cursector->floorstat & CSTAT_SECTOR_SLOPE); - pp->Angles.doViewPitch(pp->actor->spr.pos.XY(), pp->actor->spr.Angles.Yaw, pp->input.actions & SB_AIMMODE, canslopetilt, pp->cursector, (pp->Flags & PF_CLIMBING)); + const bool canslopetilt = (pp->input.actions & SB_AIMMODE) && !(pp->Flags & (PF_FLYING|PF_SWIMMING|PF_DIVING|PF_CLIMBING|PF_JUMPING|PF_FALLING)); + pp->Angles.doViewPitch(canslopetilt, pp->Flags & PF_CLIMBING); } //--------------------------------------------------------------------------- From c1f52b1137714231c26b9da8dc7b2fb9ff0ba46f Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Mon, 13 Mar 2023 21:30:39 +1100 Subject: [PATCH 02/67] - Adjust `PlayerAngles::doViewPitch()` so that view pitch always resets to 0 upon enabling mouse aiming. --- source/core/gameinput.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index a3fc34094..cf45b90d7 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -270,22 +270,22 @@ void PlayerAngles::doViewPitch(const bool canslopetilt, const bool climbing) } } } - - if (climbing) - { - // tilt when climbing but you can't even really tell it. - if (ViewAngles.Pitch > PITCH_HORIZOFFCLIMB) - ViewAngles.Pitch += getscaledangle(deltaangle(ViewAngles.Pitch, PITCH_HORIZOFFCLIMB), PITCH_HORIZOFFSPEED, PITCH_HORIZOFFPUSH); - } - else - { - // Make horizoff grow towards 0 since horizoff is not modified when you're not on a slope. - scaletozero(ViewAngles.Pitch, PITCH_HORIZOFFSPEED, PITCH_HORIZOFFPUSH); - } - - // Clamp off against the maximum allowed pitch. - ViewAngles.Pitch = ClampViewPitch(ViewAngles.Pitch); } + + if (cl_slopetilting && climbing) + { + // tilt when climbing but you can't even really tell it. + if (ViewAngles.Pitch > PITCH_HORIZOFFCLIMB) + ViewAngles.Pitch += getscaledangle(deltaangle(ViewAngles.Pitch, PITCH_HORIZOFFCLIMB), PITCH_HORIZOFFSPEED, PITCH_HORIZOFFPUSH); + } + else + { + // Make horizoff grow towards 0 since horizoff is not modified when you're not on a slope. + scaletozero(ViewAngles.Pitch, PITCH_HORIZOFFSPEED, PITCH_HORIZOFFPUSH); + } + + // Clamp off against the maximum allowed pitch. + ViewAngles.Pitch = ClampViewPitch(ViewAngles.Pitch); } From c73ee5f84852f3facae9288f6b007f696bfcef59 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Mon, 13 Mar 2023 20:10:47 +1100 Subject: [PATCH 03/67] - Exhumed: Move `PlayerInput::pTarget` to `Player` struct. --- source/games/exhumed/src/exhumed.cpp | 5 +---- source/games/exhumed/src/gun.cpp | 4 ++-- source/games/exhumed/src/input.cpp | 9 --------- source/games/exhumed/src/input.h | 1 - source/games/exhumed/src/player.cpp | 3 ++- source/games/exhumed/src/player.h | 1 + source/games/exhumed/src/ra.cpp | 2 +- source/games/exhumed/src/snake.cpp | 4 ++-- 8 files changed, 9 insertions(+), 20 deletions(-) diff --git a/source/games/exhumed/src/exhumed.cpp b/source/games/exhumed/src/exhumed.cpp index 29ab58fcc..3353cfb68 100644 --- a/source/games/exhumed/src/exhumed.cpp +++ b/source/games/exhumed/src/exhumed.cpp @@ -63,7 +63,6 @@ IMPLEMENT_POINTERS_END size_t MarkMove(); size_t MarkBullets(); -size_t MarkInput(); size_t MarkItems(); size_t MarkLighting(); size_t MarkObjects(); @@ -77,7 +76,6 @@ size_t MarkRunlist(); static void markgcroots() { MarkBullets(); - MarkInput(); MarkItems(); MarkLighting(); MarkObjects(); @@ -484,11 +482,10 @@ void GameInterface::Ticker() if (oldactions & SB_CENTERVIEW) sPlayerInput[nLocalPlayer].actions |= SB_CENTERVIEW; sPlayerInput[nLocalPlayer].buttons = lLocalCodes; - sPlayerInput[nLocalPlayer].pTarget = bestTarget; sPlayerInput[nLocalPlayer].nAngle = localInput.avel; sPlayerInput[nLocalPlayer].pan = localInput.horz; - Ra[nLocalPlayer].pTarget = bestTarget; + PlayerList[nLocalPlayer].pTarget = Ra[nLocalPlayer].pTarget = bestTarget; lLocalCodes = 0; diff --git a/source/games/exhumed/src/gun.cpp b/source/games/exhumed/src/gun.cpp index 66c24dcc3..09b92fbda 100644 --- a/source/games/exhumed/src/gun.cpp +++ b/source/games/exhumed/src/gun.cpp @@ -838,9 +838,9 @@ loc_flag: nHeight += h; DExhumedActor* target = nullptr; - if (sPlayerInput[nPlayer].pTarget != nullptr && Autoaim(nPlayer)) + if (PlayerList[nPlayer].pTarget != nullptr && Autoaim(nPlayer)) { - DExhumedActor* t = sPlayerInput[nPlayer].pTarget; + DExhumedActor* t = PlayerList[nPlayer].pTarget; // only autoaim if target is in front of the player. assert(t->sector()); DAngle angletotarget = (t->spr.pos - pPlayerActor->spr.pos).Angle(); diff --git a/source/games/exhumed/src/input.cpp b/source/games/exhumed/src/input.cpp index 3cfcc1c99..988eba81f 100644 --- a/source/games/exhumed/src/input.cpp +++ b/source/games/exhumed/src/input.cpp @@ -33,15 +33,6 @@ PlayerInput sPlayerInput[kMaxPlayers]; // //--------------------------------------------------------------------------- -size_t MarkInput() -{ - for (auto& p : sPlayerInput) - { - GC::Mark(p.pTarget); - } - return kMaxPlayers; -} - void ClearSpaceBar(int nPlayer) { sPlayerInput[nPlayer].actions &= SB_OPEN; diff --git a/source/games/exhumed/src/input.h b/source/games/exhumed/src/input.h index 1934ced84..5a3d11d50 100644 --- a/source/games/exhumed/src/input.h +++ b/source/games/exhumed/src/input.h @@ -32,7 +32,6 @@ enum { // 32 bytes struct PlayerInput { - TObjPtr pTarget; DVector2 vel; uint16_t buttons; float nAngle; diff --git a/source/games/exhumed/src/player.cpp b/source/games/exhumed/src/player.cpp index 7a3a8115a..28898942f 100644 --- a/source/games/exhumed/src/player.cpp +++ b/source/games/exhumed/src/player.cpp @@ -100,9 +100,10 @@ size_t MarkPlayers() GC::Mark(p.pDoppleSprite); GC::Mark(p.pPlayerFloorSprite); GC::Mark(p.pPlayerGrenade); + GC::Mark(p.pTarget); } GC::MarkArray(nNetStartSprite, kMaxPlayers); - return 5 * kMaxPlayers; + return 6 * kMaxPlayers; } //--------------------------------------------------------------------------- diff --git a/source/games/exhumed/src/player.h b/source/games/exhumed/src/player.h index d7480b149..149a7f35f 100644 --- a/source/games/exhumed/src/player.h +++ b/source/games/exhumed/src/player.h @@ -101,6 +101,7 @@ struct Player TObjPtr pPlayerGrenade; TObjPtr pPlayerFloorSprite; TObjPtr pDoppleSprite; + TObjPtr pTarget; }; diff --git a/source/games/exhumed/src/ra.cpp b/source/games/exhumed/src/ra.cpp index 9b58331ba..b6d2ef290 100644 --- a/source/games/exhumed/src/ra.cpp +++ b/source/games/exhumed/src/ra.cpp @@ -216,7 +216,7 @@ void AIRa::Tick(RunListEvent* ev) bool bVal = false; - Ra[nPlayer].pTarget = sPlayerInput[nPlayer].pTarget; + Ra[nPlayer].pTarget = PlayerList[nPlayer].pTarget; pActor->spr.picnum = seq_GetSeqPicnum2(nSeq, Ra[nPlayer].nFrame); if (Ra[nPlayer].nAction) diff --git a/source/games/exhumed/src/snake.cpp b/source/games/exhumed/src/snake.cpp index b962c915a..27ca006e4 100644 --- a/source/games/exhumed/src/snake.cpp +++ b/source/games/exhumed/src/snake.cpp @@ -191,9 +191,9 @@ void BuildSnake(int nPlayer, double zVal) if (hitactor && hitactor->spr.statnum >= 90 && hitactor->spr.statnum <= 199) { pTarget = hitactor; } - else if (sPlayerInput[nPlayer].pTarget != nullptr) + else if (PlayerList[nPlayer].pTarget != nullptr) { - pTarget = sPlayerInput[nPlayer].pTarget; + pTarget = PlayerList[nPlayer].pTarget; } int nSnake = GrabSnake(); From f77b1007be6febf9b65a7f0f1210a9996e091a8e Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Mon, 13 Mar 2023 20:12:31 +1100 Subject: [PATCH 04/67] - Exhumed: Remove unused `PlayerInput::buttons` --- source/games/exhumed/src/exhumed.cpp | 5 ----- source/games/exhumed/src/input.h | 2 -- 2 files changed, 7 deletions(-) diff --git a/source/games/exhumed/src/exhumed.cpp b/source/games/exhumed/src/exhumed.cpp index 3353cfb68..5c698221b 100644 --- a/source/games/exhumed/src/exhumed.cpp +++ b/source/games/exhumed/src/exhumed.cpp @@ -146,8 +146,6 @@ int nEnergyTowers = 0; int nCfgNetPlayers = 0; -int lLocalCodes = 0; - bool bCoordinates = false; int nNetTime = -1; @@ -481,14 +479,11 @@ void GameInterface::Ticker() sPlayerInput[nLocalPlayer].actions = localInput.actions; if (oldactions & SB_CENTERVIEW) sPlayerInput[nLocalPlayer].actions |= SB_CENTERVIEW; - sPlayerInput[nLocalPlayer].buttons = lLocalCodes; sPlayerInput[nLocalPlayer].nAngle = localInput.avel; sPlayerInput[nLocalPlayer].pan = localInput.horz; PlayerList[nLocalPlayer].pTarget = Ra[nLocalPlayer].pTarget = bestTarget; - lLocalCodes = 0; - PlayClock += 4; if (PlayClock == 8) gameaction = ga_autosave; // let the game run for 1 frame before saving. GameMove(); diff --git a/source/games/exhumed/src/input.h b/source/games/exhumed/src/input.h index 5a3d11d50..1954398db 100644 --- a/source/games/exhumed/src/input.h +++ b/source/games/exhumed/src/input.h @@ -33,7 +33,6 @@ enum { struct PlayerInput { DVector2 vel; - uint16_t buttons; float nAngle; float pan; int8_t nItem; @@ -57,7 +56,6 @@ int GetLocalInput(); extern PlayerInput sPlayerInput[]; extern InputPacket localInput; -extern int lLocalCodes; END_PS_NS From 73acffac2c57b397ed8f230dbc0540a2d66b398d Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Mon, 13 Mar 2023 20:29:04 +1100 Subject: [PATCH 05/67] - Exhumed: Move `PlayerInput::nItem` to `Player` struct as `Player::nCurrentItem`. --- source/games/exhumed/src/exhumed.cpp | 2 +- source/games/exhumed/src/input.h | 1 - source/games/exhumed/src/player.cpp | 8 ++++---- source/games/exhumed/src/player.h | 1 + 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/source/games/exhumed/src/exhumed.cpp b/source/games/exhumed/src/exhumed.cpp index 5c698221b..734e0a2ce 100644 --- a/source/games/exhumed/src/exhumed.cpp +++ b/source/games/exhumed/src/exhumed.cpp @@ -438,7 +438,7 @@ void GameInterface::Ticker() { if (nItemMagic[i] <= PlayerList[nLocalPlayer].nMagic) { - sPlayerInput[nLocalPlayer].nItem = i; + PlayerList[nLocalPlayer].nCurrentItem = i; break; } } diff --git a/source/games/exhumed/src/input.h b/source/games/exhumed/src/input.h index 1954398db..6467df723 100644 --- a/source/games/exhumed/src/input.h +++ b/source/games/exhumed/src/input.h @@ -35,7 +35,6 @@ struct PlayerInput DVector2 vel; float nAngle; float pan; - int8_t nItem; ESyncBits actions; int getNewWeapon() const diff --git a/source/games/exhumed/src/player.cpp b/source/games/exhumed/src/player.cpp index 28898942f..9377a5330 100644 --- a/source/games/exhumed/src/player.cpp +++ b/source/games/exhumed/src/player.cpp @@ -433,7 +433,7 @@ void RestartPlayer(int nPlayer) plr->ototalvel = plr->totalvel = 0; memset(&sPlayerInput[nPlayer], 0, sizeof(PlayerInput)); - sPlayerInput[nPlayer].nItem = -1; + PlayerList[nPlayer].nCurrentItem = -1; plr->nDeathType = 0; nQuake[nPlayer] = 0; @@ -908,10 +908,10 @@ void AIPlayer::Tick(RunListEvent* ev) pPlayerActor->vel.XY() = sPlayerInput[nPlayer].vel; - if (sPlayerInput[nPlayer].nItem > -1) + if (PlayerList[nPlayer].nCurrentItem > -1) { - UseItem(nPlayer, sPlayerInput[nPlayer].nItem); - sPlayerInput[nPlayer].nItem = -1; + UseItem(nPlayer, PlayerList[nPlayer].nCurrentItem); + PlayerList[nPlayer].nCurrentItem = -1; } pPlayerActor->spr.picnum = seq_GetSeqPicnum(PlayerList[nPlayer].nSeq, PlayerSeq[nHeightTemplate[nAction]].a, PlayerList[nPlayer].nSeqSize); diff --git a/source/games/exhumed/src/player.h b/source/games/exhumed/src/player.h index 149a7f35f..c755e898a 100644 --- a/source/games/exhumed/src/player.h +++ b/source/games/exhumed/src/player.h @@ -65,6 +65,7 @@ struct Player uint16_t keys; int16_t nMagic; int16_t nItem; + int8_t nCurrentItem; uint8_t items[8]; int16_t nAmmo[7]; // TODO - kMaxWeapons? From 67c7dd65f94f9340d28ac9729be141377d9478e2 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Mon, 13 Mar 2023 20:42:37 +1100 Subject: [PATCH 06/67] - Exhumed: Remove `PlayerInput::vel` in favour of just using actor's velocity. --- source/games/exhumed/src/exhumed.cpp | 2 +- source/games/exhumed/src/input.cpp | 4 ++-- source/games/exhumed/src/input.h | 1 - source/games/exhumed/src/player.cpp | 7 ++----- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/source/games/exhumed/src/exhumed.cpp b/source/games/exhumed/src/exhumed.cpp index 734e0a2ce..9f42345a9 100644 --- a/source/games/exhumed/src/exhumed.cpp +++ b/source/games/exhumed/src/exhumed.cpp @@ -375,7 +375,7 @@ void GameInterface::Ticker() // disable synchronised input if set by game. resetForcedSyncInput(); - auto& lPlayerVel = sPlayerInput[nLocalPlayer].vel; + auto& lPlayerVel = PlayerList[nLocalPlayer].pActor->vel.XY(); auto inputvect = DVector2(localInput.fvel, localInput.svel).Rotated(inita) * 0.375; diff --git a/source/games/exhumed/src/input.cpp b/source/games/exhumed/src/input.cpp index 988eba81f..479aa5b7c 100644 --- a/source/games/exhumed/src/input.cpp +++ b/source/games/exhumed/src/input.cpp @@ -68,9 +68,9 @@ void GameInterface::GetInput(ControlInfo* const hidInput, double const scaleAdju { processMovement(&input, &localInput, hidInput, scaleAdjust); } - else + else if (pPlayer->pActor) { - sPlayerInput[nLocalPlayer].vel.Zero(); + pPlayer->pActor->vel.Zero(); } if (!SyncInput() && gamestate == GS_LEVEL && !nFreeze) diff --git a/source/games/exhumed/src/input.h b/source/games/exhumed/src/input.h index 6467df723..75e17b46f 100644 --- a/source/games/exhumed/src/input.h +++ b/source/games/exhumed/src/input.h @@ -32,7 +32,6 @@ enum { // 32 bytes struct PlayerInput { - DVector2 vel; float nAngle; float pan; ESyncBits actions; diff --git a/source/games/exhumed/src/player.cpp b/source/games/exhumed/src/player.cpp index 9377a5330..a982cfe13 100644 --- a/source/games/exhumed/src/player.cpp +++ b/source/games/exhumed/src/player.cpp @@ -855,7 +855,7 @@ bool CheckMovingBlocks(int nPlayer, Collision& nMove, DVector3& spr_pos, sectort { PlayerList[nPlayer].pPlayerPushSect = sect; - DVector2 vel = sPlayerInput[nPlayer].vel; + DVector2 vel = PlayerList[nPlayer].pActor->vel.XY(); auto nMyAngle = vel.Angle().Normalized360(); setsectinterpolate(sect); @@ -906,8 +906,6 @@ void AIPlayer::Tick(RunListEvent* ev) int nAction = PlayerList[nPlayer].nAction; int nActionB = PlayerList[nPlayer].nAction; - pPlayerActor->vel.XY() = sPlayerInput[nPlayer].vel; - if (PlayerList[nPlayer].nCurrentItem > -1) { UseItem(nPlayer, PlayerList[nPlayer].nCurrentItem); @@ -1006,7 +1004,7 @@ void AIPlayer::Tick(RunListEvent* ev) auto playerPos = pPlayerActor->spr.pos.XY(); - DVector2 vect = sPlayerInput[nPlayer].vel; + DVector2 vect = pPlayerActor->vel.XY(); double zz = pPlayerActor->vel.Z; if (pPlayerActor->vel.Z > 32) @@ -1074,7 +1072,6 @@ void AIPlayer::Tick(RunListEvent* ev) pPlayerActor->spr.Angles = DRotator(nullAngle, GetAngleToSprite(pPlayerActor, pSpiritSprite), nullAngle); pPlayerActor->backupang(); - sPlayerInput[nPlayer].vel.Zero(); pPlayerActor->vel.Zero(); if (nFreeze < 1) From 9ffc65fa48bbe348ca8bba28121559cc5c38271a Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Mon, 13 Mar 2023 21:08:11 +1100 Subject: [PATCH 07/67] - Exhumed: Eliminate `PlayerInput` struct in favour of `InputPacket` object `PlayerList::input`. --- source/games/exhumed/src/exhumed.cpp | 38 +++++++++++++--------------- source/games/exhumed/src/input.cpp | 4 +-- source/games/exhumed/src/input.h | 24 ------------------ source/games/exhumed/src/player.cpp | 13 +++++----- source/games/exhumed/src/player.h | 1 + source/games/exhumed/src/ramses.cpp | 2 +- 6 files changed, 27 insertions(+), 55 deletions(-) diff --git a/source/games/exhumed/src/exhumed.cpp b/source/games/exhumed/src/exhumed.cpp index 9f42345a9..5446915f9 100644 --- a/source/games/exhumed/src/exhumed.cpp +++ b/source/games/exhumed/src/exhumed.cpp @@ -98,8 +98,6 @@ void InitCheats(); int EndLevel = 0; -InputPacket localInput; - //////// void ResetEngine() @@ -375,9 +373,14 @@ void GameInterface::Ticker() // disable synchronised input if set by game. resetForcedSyncInput(); + // set new player input, factoring in previous view centering. + auto oldactions = PlayerList[nLocalPlayer].input.actions; + PlayerList[nLocalPlayer].input = playercmds[nLocalPlayer].ucmd; + if (oldactions & SB_CENTERVIEW) PlayerList[nLocalPlayer].input.actions |= SB_CENTERVIEW; + auto& lPlayerVel = PlayerList[nLocalPlayer].pActor->vel.XY(); - auto inputvect = DVector2(localInput.fvel, localInput.svel).Rotated(inita) * 0.375; + auto inputvect = DVector2(PlayerList[nLocalPlayer].input.fvel, PlayerList[nLocalPlayer].input.svel).Rotated(inita) * 0.375; for (int i = 0; i < 4; i++) { @@ -387,7 +390,7 @@ void GameInterface::Ticker() } UpdateInterpolations(); - if (localInput.actions & SB_INVPREV) + if (PlayerList[nLocalPlayer].input.actions & SB_INVPREV) { int nItem = PlayerList[nLocalPlayer].nItem; @@ -404,7 +407,7 @@ void GameInterface::Ticker() if (i > 0) PlayerList[nLocalPlayer].nItem = nItem; } - if (localInput.actions & SB_INVNEXT) + if (PlayerList[nLocalPlayer].input.actions & SB_INVNEXT) { int nItem = PlayerList[nLocalPlayer].nItem; @@ -421,19 +424,19 @@ void GameInterface::Ticker() if (i > 0) PlayerList[nLocalPlayer].nItem = nItem; } - if (localInput.actions & SB_INVUSE) + if (PlayerList[nLocalPlayer].input.actions & SB_INVUSE) { if (PlayerList[nLocalPlayer].nItem != -1) { - localInput.setItemUsed(PlayerList[nLocalPlayer].nItem); + PlayerList[nLocalPlayer].input.setItemUsed(PlayerList[nLocalPlayer].nItem); } } for (int i = 0; i < 6; i++) { - if (localInput.isItemUsed(i)) + if (PlayerList[nLocalPlayer].input.isItemUsed(i)) { - localInput.clearItemUsed(i); + PlayerList[nLocalPlayer].input.clearItemUsed(i); if (PlayerList[nLocalPlayer].items[i] > 0) { if (nItemMagic[i] <= PlayerList[nLocalPlayer].nMagic) @@ -446,7 +449,7 @@ void GameInterface::Ticker() } auto currWeap = PlayerList[nLocalPlayer].nCurrentWeapon; - int weap2 = localInput.getNewWeapon(); + int weap2 = PlayerList[nLocalPlayer].input.getNewWeapon(); if (weap2 == WeaponSel_Next) { auto newWeap = currWeap == 6 ? 0 : currWeap + 1; @@ -455,7 +458,7 @@ void GameInterface::Ticker() newWeap++; if (newWeap > 6) newWeap = 0; } - localInput.setNewWeapon(newWeap + 1); + PlayerList[nLocalPlayer].input.setNewWeapon(newWeap + 1); } else if (weap2 == WeaponSel_Prev) { @@ -464,7 +467,7 @@ void GameInterface::Ticker() { newWeap--; } - localInput.setNewWeapon(newWeap + 1); + PlayerList[nLocalPlayer].input.setNewWeapon(newWeap + 1); } else if (weap2 == WeaponSel_Alt) { @@ -472,15 +475,8 @@ void GameInterface::Ticker() } // make weapon selection persist until it gets used up. - int weap = sPlayerInput[nLocalPlayer].getNewWeapon(); - if (weap2 <= 0 || weap2 > 7) sPlayerInput[nLocalPlayer].SetNewWeapon(weap); - - auto oldactions = sPlayerInput[nLocalPlayer].actions; - sPlayerInput[nLocalPlayer].actions = localInput.actions; - if (oldactions & SB_CENTERVIEW) sPlayerInput[nLocalPlayer].actions |= SB_CENTERVIEW; - - sPlayerInput[nLocalPlayer].nAngle = localInput.avel; - sPlayerInput[nLocalPlayer].pan = localInput.horz; + int weap = PlayerList[nLocalPlayer].input.getNewWeapon(); + if (weap2 <= 0 || weap2 > 7) PlayerList[nLocalPlayer].input.setNewWeapon(weap); PlayerList[nLocalPlayer].pTarget = Ra[nLocalPlayer].pTarget = bestTarget; diff --git a/source/games/exhumed/src/input.cpp b/source/games/exhumed/src/input.cpp index 479aa5b7c..5e95ba0d8 100644 --- a/source/games/exhumed/src/input.cpp +++ b/source/games/exhumed/src/input.cpp @@ -25,7 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. BEGIN_PS_NS -PlayerInput sPlayerInput[kMaxPlayers]; +static InputPacket localInput; //--------------------------------------------------------------------------- // @@ -35,7 +35,7 @@ PlayerInput sPlayerInput[kMaxPlayers]; void ClearSpaceBar(int nPlayer) { - sPlayerInput[nPlayer].actions &= SB_OPEN; + PlayerList[nPlayer].input.actions &= SB_OPEN; buttonMap.ClearButton(gamefunc_Open); } diff --git a/source/games/exhumed/src/input.h b/source/games/exhumed/src/input.h index 75e17b46f..5b445ad24 100644 --- a/source/games/exhumed/src/input.h +++ b/source/games/exhumed/src/input.h @@ -29,31 +29,7 @@ enum { kButtonCheatItems = 0x100, }; -// 32 bytes -struct PlayerInput -{ - float nAngle; - float pan; - ESyncBits actions; - - int getNewWeapon() const - { - return (actions & SB_WEAPONMASK_BITS).GetValue(); - } - - void SetNewWeapon(int weap) - { - actions = (actions & ~SB_WEAPONMASK_BITS) | (ESyncBits::FromInt(weap) & SB_WEAPONMASK_BITS); - } - -}; - void ClearSpaceBar(int nPlayer); -int GetLocalInput(); - -extern PlayerInput sPlayerInput[]; -extern InputPacket localInput; - END_PS_NS diff --git a/source/games/exhumed/src/player.cpp b/source/games/exhumed/src/player.cpp index a982cfe13..b95217738 100644 --- a/source/games/exhumed/src/player.cpp +++ b/source/games/exhumed/src/player.cpp @@ -432,7 +432,6 @@ void RestartPlayer(int nPlayer) plr->ototalvel = plr->totalvel = 0; - memset(&sPlayerInput[nPlayer], 0, sizeof(PlayerInput)); PlayerList[nPlayer].nCurrentItem = -1; plr->nDeathType = 0; @@ -982,7 +981,7 @@ void AIPlayer::Tick(RunListEvent* ev) // loc_1A494: if (SyncInput()) { - PlayerList[nPlayer].pActor->spr.Angles.Yaw += DAngle::fromDeg(sPlayerInput[nPlayer].nAngle); + PlayerList[nPlayer].pActor->spr.Angles.Yaw += DAngle::fromDeg(PlayerList[nPlayer].input.avel); } PlayerList[nPlayer].Angles.doYawKeys(&sPlayerInput[nLocalPlayer].actions); @@ -1215,7 +1214,7 @@ sectdone: int var_5C = pViewSect->Flag & kSectUnderwater; - auto actions = sPlayerInput[nPlayer].actions; + auto actions = PlayerList[nPlayer].input.actions; // loc_1AEF5: if (PlayerList[nPlayer].nHealth > 0) @@ -2425,7 +2424,7 @@ sectdone: // loc_1BE70: // Handle player pressing number keys to change weapon - uint8_t var_90 = sPlayerInput[nPlayer].getNewWeapon(); + uint8_t var_90 = PlayerList[nPlayer].input.getNewWeapon(); if (var_90) { @@ -2469,12 +2468,12 @@ sectdone: if (SyncInput()) { - pPlayer->pActor->spr.Angles.Pitch += DAngle::fromDeg(sPlayerInput[nPlayer].pan); + pPlayer->pActor->spr.Angles.Pitch += DAngle::fromDeg(PlayerList[nPlayer].input.horz); } - pPlayer->Angles.doPitchKeys(&sPlayerInput[nLocalPlayer].actions, sPlayerInput[nPlayer].pan); + pPlayer->Angles.doPitchKeys(&PlayerList[nLocalPlayer].input.actions, PlayerList[nPlayer].input.pan); - if (actions & (SB_AIM_UP | SB_AIM_DOWN) || sPlayerInput[nPlayer].pan) + if (actions & (SB_AIM_UP | SB_AIM_DOWN) || PlayerList[nPlayer].input.horz) { pPlayer->nDestVertPan = pPlayer->pActor->spr.Angles.Pitch; pPlayer->bPlayerPan = pPlayer->bLockPan = true; diff --git a/source/games/exhumed/src/player.h b/source/games/exhumed/src/player.h index c755e898a..f099f5436 100644 --- a/source/games/exhumed/src/player.h +++ b/source/games/exhumed/src/player.h @@ -79,6 +79,7 @@ struct Player bool bPlayerPan, bLockPan; DAngle nDestVertPan; + InputPacket input; PlayerAngles Angles; sectortype* pPlayerPushSect; sectortype* pPlayerViewSect; diff --git a/source/games/exhumed/src/ramses.cpp b/source/games/exhumed/src/ramses.cpp index a274620f1..3a84319bc 100644 --- a/source/games/exhumed/src/ramses.cpp +++ b/source/games/exhumed/src/ramses.cpp @@ -196,7 +196,7 @@ void DoSpiritHead() static int dimSectCount = 0; auto pSpiritSpr = pSpiritSprite; - sPlayerInput[0].actions |= SB_CENTERVIEW; + PlayerList[0].input.actions |= SB_CENTERVIEW; switch (nHeadStage) { From 62561d863ee5e32cc3f91d3a761248ae0e8be039 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Mon, 13 Mar 2023 21:17:53 +1100 Subject: [PATCH 08/67] - Tidy up `PlayerAngles::doPitchKeys()` interface by passing the whole sync packet through. --- source/core/gameinput.cpp | 21 +++++++++++---------- source/core/gameinput.h | 2 +- source/games/blood/src/player.cpp | 2 +- source/games/duke/src/player_d.cpp | 2 +- source/games/duke/src/player_r.cpp | 2 +- source/games/exhumed/src/player.cpp | 2 +- source/games/sw/src/player.cpp | 8 ++++---- 7 files changed, 20 insertions(+), 19 deletions(-) diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index cf45b90d7..0dc32701a 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -167,30 +167,31 @@ void processMovement(InputPacket* const currInput, InputPacket* const inputBuffe // //--------------------------------------------------------------------------- -void PlayerAngles::doPitchKeys(ESyncBits* actions, const bool stopcentering) +void PlayerAngles::doPitchKeys(InputPacket* const input) { // Cancel return to center if conditions met. - if (stopcentering) *actions &= ~SB_CENTERVIEW; + if (input->horz) + input->actions &= ~SB_CENTERVIEW; // Process keyboard input. - if (auto aiming = !!(*actions & SB_AIM_DOWN) - !!(*actions & SB_AIM_UP)) + if (const auto aiming = !!(input->actions & SB_AIM_DOWN) - !!(input->actions & SB_AIM_UP)) { - pActor->spr.Angles.Pitch += DAngle::fromDeg(getTicrateScale(PITCH_AIMSPEED)) * aiming; - *actions &= ~SB_CENTERVIEW; + pActor->spr.Angles.Pitch += DAngle::fromDeg(getTicrateScale(PITCH_AIMSPEED) * aiming); + input->actions &= ~SB_CENTERVIEW; } - if (auto looking = !!(*actions & SB_LOOK_DOWN) - !!(*actions & SB_LOOK_UP)) + if (const auto looking = !!(input->actions & SB_LOOK_DOWN) - !!(input->actions & SB_LOOK_UP)) { - pActor->spr.Angles.Pitch += DAngle::fromDeg(getTicrateScale(PITCH_LOOKSPEED)) * looking; - *actions |= SB_CENTERVIEW; + pActor->spr.Angles.Pitch += DAngle::fromDeg(getTicrateScale(PITCH_LOOKSPEED) * looking); + input->actions |= SB_CENTERVIEW; } // Do return to centre. - if ((*actions & SB_CENTERVIEW) && !(*actions & (SB_LOOK_UP|SB_LOOK_DOWN))) + if ((input->actions & SB_CENTERVIEW) && !(input->actions & (SB_LOOK_UP|SB_LOOK_DOWN))) { const auto pitch = abs(pActor->spr.Angles.Pitch); const auto scale = pitch > PITCH_CNTRSINEOFFSET ? (pitch - PITCH_CNTRSINEOFFSET).Cos() : 1.; if (scaletozero(pActor->spr.Angles.Pitch, PITCH_CENTERSPEED * scale)) - *actions &= ~SB_CENTERVIEW; + input->actions &= ~SB_CENTERVIEW; } // clamp before we finish, factoring in the player's view pitch offset. diff --git a/source/core/gameinput.h b/source/core/gameinput.h index d7a4e2164..c8951476b 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -20,7 +20,7 @@ struct PlayerAngles friend FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngles& w, PlayerAngles* def); // Prototypes. - void doPitchKeys(ESyncBits* actions, const bool stopcentering); + void doPitchKeys(InputPacket* const input); void doYawKeys(ESyncBits* actions); void doViewPitch(const bool canslopetilt, const bool climbing = false); void doViewYaw(const ESyncBits actions); diff --git a/source/games/blood/src/player.cpp b/source/games/blood/src/player.cpp index 0394fa357..829d565d0 100644 --- a/source/games/blood/src/player.cpp +++ b/source/games/blood/src/player.cpp @@ -1705,7 +1705,7 @@ void ProcessInput(PLAYER* pPlayer) const int florhit = pPlayer->actor->hit.florhit.type; pPlayer->Angles.doViewPitch(actor->xspr.height < 16 && (florhit == kHitSector || florhit == 0)); - pPlayer->Angles.doPitchKeys(&pInput->actions, pInput->horz); + pPlayer->Angles.doPitchKeys(pInput); pPlayer->slope = pPlayer->actor->spr.Angles.Pitch.Tan(); if (pInput->actions & SB_INVPREV) diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index f7d6e972f..67b6b7fe3 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -2988,7 +2988,7 @@ HORIZONLY: p->GetActor()->spr.Angles.Pitch += GetPlayerHorizon(snum); } - p->Angles.doPitchKeys(&actions, GetPlayerHorizon(snum).Sgn()); + p->Angles.doPitchKeys(&p->sync); p->checkhardlanding(); diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index 6575a524c..a2664a379 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -3802,7 +3802,7 @@ HORIZONLY: p->GetActor()->spr.Angles.Pitch += GetPlayerHorizon(snum); } - p->Angles.doPitchKeys(&actions, GetPlayerHorizon(snum).Sgn()); + p->Angles.doPitchKeys(&p->sync); p->checkhardlanding(); diff --git a/source/games/exhumed/src/player.cpp b/source/games/exhumed/src/player.cpp index b95217738..ce0cd3b32 100644 --- a/source/games/exhumed/src/player.cpp +++ b/source/games/exhumed/src/player.cpp @@ -2471,7 +2471,7 @@ sectdone: pPlayer->pActor->spr.Angles.Pitch += DAngle::fromDeg(PlayerList[nPlayer].input.horz); } - pPlayer->Angles.doPitchKeys(&PlayerList[nLocalPlayer].input.actions, PlayerList[nPlayer].input.pan); + pPlayer->Angles.doPitchKeys(&PlayerList[nLocalPlayer].input); if (actions & (SB_AIM_UP | SB_AIM_DOWN) || PlayerList[nPlayer].input.horz) { diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index 7abc652c7..8d7a23779 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -2163,7 +2163,7 @@ void DoPlayerMove(PLAYER* pp) pp->actor->spr.Angles.Pitch += DAngle::fromDeg(pp->input.horz); } - pp->Angles.doPitchKeys(&pp->input.actions, pp->input.horz); + pp->Angles.doPitchKeys(&pp->input); DoPlayerSlopeTilting(pp); @@ -2750,7 +2750,7 @@ void DoPlayerMoveVehicle(PLAYER* pp) pp->actor->spr.Angles.Pitch += DAngle::fromDeg(pp->input.horz); } - pp->Angles.doPitchKeys(&pp->input.actions, pp->input.horz); + pp->Angles.doPitchKeys(&pp->input); DoPlayerSlopeTilting(pp); @@ -2796,7 +2796,7 @@ void DoPlayerMoveTurret(PLAYER* pp) pp->actor->spr.Angles.Pitch += DAngle::fromDeg(pp->input.horz); } - pp->Angles.doPitchKeys(&pp->input.actions, pp->input.horz); + pp->Angles.doPitchKeys(&pp->input); DoPlayerSlopeTilting(pp); } @@ -3398,7 +3398,7 @@ void DoPlayerClimb(PLAYER* pp) pp->actor->spr.Angles.Pitch += DAngle::fromDeg(pp->input.horz); } - pp->Angles.doPitchKeys(&pp->input.actions, pp->input.horz); + pp->Angles.doPitchKeys(&pp->input); DoPlayerSlopeTilting(pp); From a90665732c7e983b686638ae9489f8856521b78f Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Mon, 13 Mar 2023 21:33:37 +1100 Subject: [PATCH 09/67] - Clean up other PlayerAngles interfaces for consistency. --- source/core/gameinput.cpp | 42 +++++++++++++---------------- source/core/gameinput.h | 13 ++++----- source/games/blood/src/player.cpp | 4 +-- source/games/duke/src/player_d.cpp | 4 +-- source/games/duke/src/player_r.cpp | 4 +-- source/games/exhumed/src/player.cpp | 4 +-- source/games/sw/src/player.cpp | 4 +-- 7 files changed, 34 insertions(+), 41 deletions(-) diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index 0dc32701a..133ce4c40 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -21,11 +21,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ //------------------------------------------------------------------------- -#include "gamecontrol.h" #include "gameinput.h" -#include "gamestruct.h" -#include "serializer.h" -#include "gamefuncs.h" //--------------------------------------------------------------------------- // @@ -73,7 +69,7 @@ static inline DAngle getscaledangle(const DAngle angle, const double scale, cons static inline bool scaletozero(DAngle& angle, const double scale, const DAngle push = DAngle::fromDeg(32. / 465.)) { - auto sgn = angle.Sgn(); + const auto sgn = angle.Sgn(); if (!sgn || sgn != (angle -= getscaledangle(angle, scale, push * sgn)).Sgn()) { @@ -92,7 +88,7 @@ static inline bool scaletozero(DAngle& angle, const double scale, const DAngle p static double turnheldtime; -void updateTurnHeldAmt(double const scaleAdjust) +void updateTurnHeldAmt(const double scaleAdjust) { turnheldtime += getTicrateScale(BUILDTICRATE) * scaleAdjust; } @@ -114,23 +110,23 @@ void resetTurnHeldAmt() // //--------------------------------------------------------------------------- -void processMovement(InputPacket* const currInput, InputPacket* const inputBuffer, ControlInfo* const hidInput, double const scaleAdjust, int const drink_amt, bool const allowstrafe, double const turnscale) +void processMovement(InputPacket* const currInput, InputPacket* const inputBuffer, ControlInfo* const hidInput, const double scaleAdjust, const int drink_amt, const bool allowstrafe, const double turnscale) { // set up variables. - int const keymove = 1 << int(!!(inputBuffer->actions & SB_RUN)); - float const hidspeed = float(getTicrateScale(YAW_TURNSPEEDS[2]) * turnscale); - float const scaleAdjustf = float(scaleAdjust); + const int keymove = 1 << int(!!(inputBuffer->actions & SB_RUN)); + const float hidspeed = float(getTicrateScale(YAW_TURNSPEEDS[2]) * turnscale); + const float scaleAdjustf = float(scaleAdjust); // determine player input. - auto const turning = buttonMap.ButtonDown(gamefunc_Turn_Right) - buttonMap.ButtonDown(gamefunc_Turn_Left); - auto const moving = buttonMap.ButtonDown(gamefunc_Move_Forward) - buttonMap.ButtonDown(gamefunc_Move_Backward) + hidInput->dz * scaleAdjustf; - auto const strafing = buttonMap.ButtonDown(gamefunc_Strafe_Right) - buttonMap.ButtonDown(gamefunc_Strafe_Left) - hidInput->dx * scaleAdjustf; + const auto turning = buttonMap.ButtonDown(gamefunc_Turn_Right) - buttonMap.ButtonDown(gamefunc_Turn_Left); + const auto moving = buttonMap.ButtonDown(gamefunc_Move_Forward) - buttonMap.ButtonDown(gamefunc_Move_Backward) + hidInput->dz * scaleAdjustf; + const auto strafing = buttonMap.ButtonDown(gamefunc_Strafe_Right) - buttonMap.ButtonDown(gamefunc_Strafe_Left) - hidInput->dx * scaleAdjustf; // process player angle input. if (!(buttonMap.ButtonDown(gamefunc_Strafe) && allowstrafe)) { - float const turndir = clamp(turning + strafing * !allowstrafe, -1.f, 1.f); - float const turnspeed = float(getTicrateScale(YAW_TURNSPEEDS[keymove]) * turnscale * (isTurboTurnTime() ? 1. : YAW_PREAMBLESCALE)); + const float turndir = clamp(turning + strafing * !allowstrafe, -1.f, 1.f); + const float turnspeed = float(getTicrateScale(YAW_TURNSPEEDS[keymove]) * turnscale * (isTurboTurnTime() ? 1. : YAW_PREAMBLESCALE)); currInput->avel += hidInput->mouseturnx + (hidInput->dyaw * hidspeed + turndir * turnspeed) * scaleAdjustf; if (turndir) updateTurnHeldAmt(scaleAdjust); else resetTurnHeldAmt(); } @@ -207,22 +203,22 @@ void PlayerAngles::doPitchKeys(InputPacket* const input) // //--------------------------------------------------------------------------- -void PlayerAngles::doYawKeys(ESyncBits* actions) +void PlayerAngles::doYawKeys(InputPacket* const input) { - if (*actions & SB_TURNAROUND) + if (input->actions & SB_TURNAROUND) { if (YawSpin == nullAngle) { // currently not spinning, so start a spin YawSpin = -DAngle180; } - *actions &= ~SB_TURNAROUND; + input->actions &= ~SB_TURNAROUND; } if (YawSpin < nullAngle) { // return spin to 0 - DAngle add = DAngle::fromDeg(getTicrateScale(!(*actions & SB_CROUCH) ? YAW_SPINSTAND : YAW_SPINCROUCH)); + DAngle add = DAngle::fromDeg(getTicrateScale(!(input->actions & SB_CROUCH) ? YAW_SPINSTAND : YAW_SPINCROUCH)); YawSpin += add; if (YawSpin > nullAngle) { @@ -296,17 +292,17 @@ void PlayerAngles::doViewPitch(const bool canslopetilt, const bool climbing) // //--------------------------------------------------------------------------- -void PlayerAngles::doViewYaw(const ESyncBits actions) +void PlayerAngles::doViewYaw(InputPacket* const input) { // Process angle return to zeros. scaletozero(ViewAngles.Yaw, YAW_LOOKRETURN); scaletozero(ViewAngles.Roll, YAW_LOOKRETURN); // Process keyboard input. - if (auto looking = !!(actions & SB_LOOK_RIGHT) - !!(actions & SB_LOOK_LEFT)) + if (const auto looking = !!(input->actions & SB_LOOK_RIGHT) - !!(input->actions & SB_LOOK_LEFT)) { - ViewAngles.Yaw += DAngle::fromDeg(getTicrateScale(YAW_LOOKINGSPEED)) * looking; - ViewAngles.Roll += DAngle::fromDeg(getTicrateScale(YAW_ROTATESPEED)) * looking; + ViewAngles.Yaw += DAngle::fromDeg(getTicrateScale(YAW_LOOKINGSPEED) * looking); + ViewAngles.Roll += DAngle::fromDeg(getTicrateScale(YAW_ROTATESPEED) * looking); } } diff --git a/source/core/gameinput.h b/source/core/gameinput.h index c8951476b..edc26c054 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -1,10 +1,7 @@ #pragma once -#include "m_fixed.h" -#include "gamecvars.h" -#include "gamestruct.h" +#include "serializer.h" #include "gamefuncs.h" -#include "packet.h" struct PlayerAngles { @@ -21,9 +18,9 @@ struct PlayerAngles // Prototypes. void doPitchKeys(InputPacket* const input); - void doYawKeys(ESyncBits* actions); + void doYawKeys(InputPacket* const input); void doViewPitch(const bool canslopetilt, const bool climbing = false); - void doViewYaw(const ESyncBits actions); + void doViewYaw(InputPacket* const input); // General methods. void initialize(DCoreActor* const actor, const DAngle viewyaw = nullAngle) @@ -83,7 +80,7 @@ class FSerializer; FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngles& w, PlayerAngles* def); -void updateTurnHeldAmt(double const scaleAdjust); +void updateTurnHeldAmt(const double scaleAdjust); bool isTurboTurnTime(); void resetTurnHeldAmt(); -void processMovement(InputPacket* const currInput, InputPacket* const inputBuffer, ControlInfo* const hidInput, double const scaleAdjust, int const drink_amt = 0, bool const allowstrafe = true, double const turnscale = 1); +void processMovement(InputPacket* const currInput, InputPacket* const inputBuffer, ControlInfo* const hidInput, const double scaleAdjust, const int drink_amt = 0, const bool allowstrafe = true, const double turnscale = 1); diff --git a/source/games/blood/src/player.cpp b/source/games/blood/src/player.cpp index 829d565d0..6ff6d4b75 100644 --- a/source/games/blood/src/player.cpp +++ b/source/games/blood/src/player.cpp @@ -1569,14 +1569,14 @@ void ProcessInput(PLAYER* pPlayer) actor->vel.XY() += DVector2(pInput->fvel * fvAccel, pInput->svel * svAccel).Rotated(actor->spr.Angles.Yaw) * speed; } - pPlayer->Angles.doViewYaw(pInput->actions); + pPlayer->Angles.doViewYaw(pInput); if (SyncInput()) { pPlayer->actor->spr.Angles.Yaw += DAngle::fromDeg(pInput->avel); } - pPlayer->Angles.doYawKeys(&pInput->actions); + pPlayer->Angles.doYawKeys(pInput); if (!(pInput->actions & SB_JUMP)) pPlayer->cantJump = 0; diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index 67b6b7fe3..335e0e750 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -2756,7 +2756,7 @@ void processinput_d(int snum) p->psectlotag = psectlotag; //Do the quick lefts and rights - p->Angles.doViewYaw(actions); + p->Angles.doViewYaw(&p->sync); if (movementBlocked(p)) { @@ -2773,7 +2773,7 @@ void processinput_d(int snum) p->GetActor()->spr.Angles.Yaw += p->adjustavel(PlayerInputAngVel(snum)); } - p->Angles.doYawKeys(&actions); + p->Angles.doYawKeys(&p->sync); purplelavacheck(p); if (p->spritebridge == 0 && pact->insector()) diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index a2664a379..59a0da549 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -3442,7 +3442,7 @@ void processinput_r(int snum) p->psectlotag = psectlotag; //Do the quick lefts and rights - p->Angles.doViewYaw(actions); + p->Angles.doViewYaw(&p->sync); if (movementBlocked(p)) { @@ -3459,7 +3459,7 @@ void processinput_r(int snum) p->GetActor()->spr.Angles.Yaw += p->adjustavel(PlayerInputAngVel(snum)); } - p->Angles.doYawKeys(&actions); + p->Angles.doYawKeys(&p->sync); purplelavacheck(p); if (p->spritebridge == 0 && pact->insector()) diff --git a/source/games/exhumed/src/player.cpp b/source/games/exhumed/src/player.cpp index ce0cd3b32..56ef4ef50 100644 --- a/source/games/exhumed/src/player.cpp +++ b/source/games/exhumed/src/player.cpp @@ -976,7 +976,7 @@ void AIPlayer::Tick(RunListEvent* ev) } } - PlayerList[nPlayer].Angles.doViewYaw(sPlayerInput[nLocalPlayer].actions); + PlayerList[nPlayer].Angles.doViewYaw(&PlayerList[nLocalPlayer].input); // loc_1A494: if (SyncInput()) @@ -984,7 +984,7 @@ void AIPlayer::Tick(RunListEvent* ev) PlayerList[nPlayer].pActor->spr.Angles.Yaw += DAngle::fromDeg(PlayerList[nPlayer].input.avel); } - PlayerList[nPlayer].Angles.doYawKeys(&sPlayerInput[nLocalPlayer].actions); + PlayerList[nPlayer].Angles.doYawKeys(&PlayerList[nLocalPlayer].input); UpdatePlayerSpriteAngle(&PlayerList[nPlayer]); // player.zvel is modified within Gravity() diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index 8d7a23779..42b47e65d 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -2024,7 +2024,7 @@ void DoPlayerMove(PLAYER* pp) SlipSlope(pp); - pp->Angles.doViewYaw(pp->input.actions); + pp->Angles.doViewYaw(&pp->input); if (!SyncInput()) { @@ -2035,7 +2035,7 @@ void DoPlayerMove(PLAYER* pp) pp->actor->spr.Angles.Yaw += DAngle::fromDeg(pp->input.avel); } - pp->Angles.doYawKeys(&pp->input.actions); + pp->Angles.doYawKeys(&pp->input); UpdatePlayerSpriteAngle(pp); pp->lastcursector = pp->cursector; From 016016b7ab9a7f5d3b4c788c7ce35cd4ca32b36e Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Tue, 14 Mar 2023 20:13:47 +1100 Subject: [PATCH 10/67] - Blood: Fix max weapons slot test preventing `slot 12` from being called. * Fixes #891. --- source/games/blood/src/blood.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/games/blood/src/blood.cpp b/source/games/blood/src/blood.cpp index 18e2b5ae3..c0ca75a03 100644 --- a/source/games/blood/src/blood.cpp +++ b/source/games/blood/src/blood.cpp @@ -421,7 +421,7 @@ void GameInterface::Ticker() inp.actions |= oldactions & ~(SB_BUTTON_MASK | SB_RUN | SB_WEAPONMASK_BITS); // should be everything non-button and non-weapon int newweap = inp.getNewWeapon(); - if (newweap > 0 && newweap < WeaponSel_MaxBlood) gPlayer[i].newWeapon = newweap; + if (newweap > 0 && newweap <= WeaponSel_MaxBlood) gPlayer[i].newWeapon = newweap; } BloodSpriteIterator it; From 2162e5142458c393037b6c80e71731c3c72c144e Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Tue, 14 Mar 2023 21:44:28 +1100 Subject: [PATCH 11/67] - Blood: Amend how QAVs process when game is paused. * Repair of initial implementation in ebdc9c31f29e25a315c524061cdc5fd7a27704e5. * Fixes #883. --- source/games/blood/src/qav.cpp | 46 ++++++++++++++++------------------ 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/source/games/blood/src/qav.cpp b/source/games/blood/src/qav.cpp index a6917648a..5450a0b20 100644 --- a/source/games/blood/src/qav.cpp +++ b/source/games/blood/src/qav.cpp @@ -309,9 +309,8 @@ void qavProcessTicker(QAV* const pQAV, int* duration, int* lastTick) { if (*duration > 0) { - auto thisTick = I_GetTime(pQAV->ticrate); - auto numTicks = thisTick - (*lastTick); - if (numTicks) + const auto thisTick = I_GetTime(pQAV->ticrate); + if (const auto numTicks = thisTick - (*lastTick)) { *lastTick = thisTick; *duration -= pQAV->ticksPerFrame * numTicks; @@ -328,35 +327,34 @@ void qavProcessTicker(QAV* const pQAV, int* duration, int* lastTick) void qavProcessTimer(PLAYER* const pPlayer, QAV* const pQAV, int* duration, double* interpfrac, bool const fixedduration, bool const ignoreWeaponTimer) { - // Process if not paused. + // Process clock based on QAV's ticrate and last tick value. if (!paused) { - // Process clock based on QAV's ticrate and last tick value. qavProcessTicker(pQAV, &pPlayer->qavTimer, &pPlayer->qavLastTick); - - if (pPlayer->weaponTimer == 0 && pPlayer->qavTimer == 0 && !ignoreWeaponTimer) - { - // Check if we're playing an idle QAV as per the ticker's weapon timer. - *duration = fixedduration ? pQAV->duration - 1 : I_GetBuildTime() % pQAV->duration; - *interpfrac = 1.; - } - else if (pPlayer->qavTimer == 0) - { - // If qavTimer is 0, play the last frame uninterpolated. Sometimes the timer can be just ahead of weaponTimer. - *duration = pQAV->duration - 1; - *interpfrac = 1.; - } - else - { - // Apply normal values. - *duration = pQAV->duration - pPlayer->qavTimer; - *interpfrac = !cl_interpolate || cl_capfps ? 1. : I_GetTimeFrac(pQAV->ticrate); - } } else { + pPlayer->qavLastTick = I_GetTime(pQAV->ticrate); + } + + if (pPlayer->weaponTimer == 0 && pPlayer->qavTimer == 0 && !ignoreWeaponTimer) + { + // Check if we're playing an idle QAV as per the ticker's weapon timer. + *duration = fixedduration ? pQAV->duration - 1 : I_GetBuildTime() % pQAV->duration; *interpfrac = 1.; } + else if (pPlayer->qavTimer == 0) + { + // If qavTimer is 0, play the last frame uninterpolated. Sometimes the timer can be just ahead of weaponTimer. + *duration = pQAV->duration - 1; + *interpfrac = 1.; + } + else + { + // Apply normal values. + *duration = pQAV->duration - pPlayer->qavTimer; + *interpfrac = !cl_interpolate || cl_capfps || paused ? 1. : I_GetTimeFrac(pQAV->ticrate); + } } From 0dba1af7c0fb3f14ed3e9d33118cae93c625b0a0 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Wed, 15 Mar 2023 16:36:56 +1100 Subject: [PATCH 12/67] - Move `canslopetilt` test for `PlayerAngles::doViewPitch()`. --- source/core/gameinput.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index 133ce4c40..f96ac64db 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -239,10 +239,10 @@ void PlayerAngles::doYawKeys(InputPacket* const input) void PlayerAngles::doViewPitch(const bool canslopetilt, const bool climbing) { - if (cl_slopetilting) + if (cl_slopetilting && canslopetilt) { const auto actorsect = pActor->sector(); - if (actorsect && (actorsect->floorstat & CSTAT_SECTOR_SLOPE) && canslopetilt) // If the floor is sloped + if (actorsect && (actorsect->floorstat & CSTAT_SECTOR_SLOPE)) // If the floor is sloped { // Get a point, 512 (64 for Blood) units ahead of player's position const auto rotpt = pActor->spr.pos.XY() + pActor->spr.Angles.Yaw.ToVector() * (!isBlood() ? 32 : 4); From fb97e3c6cae49d9ff34f43668593b9c089b7a02d Mon Sep 17 00:00:00 2001 From: sirlemonhead Date: Thu, 19 May 2022 21:28:41 +0100 Subject: [PATCH 13/67] PCExhumed: Fixed Ignited sprite anim issue that could cause invalid array access. * Fixes #638. --- source/games/exhumed/src/aistuff.h | 8 +++++++- source/games/exhumed/src/anims.cpp | 30 ++++++++++++++++++++++++++++ source/games/exhumed/src/exhumed.cpp | 2 ++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/source/games/exhumed/src/aistuff.h b/source/games/exhumed/src/aistuff.h index 882c24f13..3932be1fb 100644 --- a/source/games/exhumed/src/aistuff.h +++ b/source/games/exhumed/src/aistuff.h @@ -27,10 +27,16 @@ BEGIN_PS_NS // anims +enum +{ + kAnimFlag1 = (1 << 2), + kAnimLoop = (1 << 4) +}; + void InitAnims(); void DestroyAnim(DExhumedActor* nAnim); DExhumedActor* BuildAnim(DExhumedActor* actor, int val, int val2, const DVector3& pos, sectortype* pSector, double nScale, int nFlag); - +void UnlinkIgnitedAnim(DExhumedActor* pActor); void FuncAnim(int, int, int, int); void BuildExplosion(DExhumedActor* actor); void BuildSplash(DExhumedActor* actor, sectortype* pSector); diff --git a/source/games/exhumed/src/anims.cpp b/source/games/exhumed/src/anims.cpp index bba736b96..c7ad69a39 100644 --- a/source/games/exhumed/src/anims.cpp +++ b/source/games/exhumed/src/anims.cpp @@ -54,6 +54,36 @@ void InitAnims() nSavePointSeq = SeqOffsets[kSeqItems] + 12; } +/* + Use when deleting an ignited sprite to check if any anims reference it. + Will remove the Anim's loop flag and set the source (the ignited sprite's) sprite reference to -1. + FuncAnim() will then delete the anim on next call for this anim. + + Without this, the anim will hold reference to a sprite which will eventually be reused, but the anim code + will continue to manipulate its hitag value. This can break runlist records for things like LavaDude + limbs that store these in the sprite hitag. + + Specifically needed for IgniteSprite() anims which can become orphaned from the source sprite (e.g a bullet) + when the bullet sprite is deleted. +*/ +void UnlinkIgnitedAnim(DExhumedActor* pActor) +{ + // scan the active anims (that aren't in the 'free' section of AnimsFree[]) + ExhumedStatIterator it(500); + while (auto itActor = it.Next()) + { + if (itActor->spr.statnum == kStatIgnited) + { + // .hitag holds the sprite number of the source 'sprite that's on fire' sprite + if (pActor == itActor->pTarget) + { + itActor->nAction &= ~kAnimLoop; // clear the animation loop flag + itActor->pTarget = nullptr; // set the sprite reference to -1 + } + } + } +} + void DestroyAnim(DExhumedActor* pActor) { if (pActor) diff --git a/source/games/exhumed/src/exhumed.cpp b/source/games/exhumed/src/exhumed.cpp index 5446915f9..4d1c753ce 100644 --- a/source/games/exhumed/src/exhumed.cpp +++ b/source/games/exhumed/src/exhumed.cpp @@ -18,6 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "ns.h" #include "engine.h" #include "exhumed.h" +#include "aistuff.h" #include "sequence.h" #include "names.h" #include "player.h" @@ -603,6 +604,7 @@ void DeleteActor(DExhumedActor* actor) bestTarget = nullptr; } + UnlinkIgnitedAnim(actor); actor->Destroy(); } From 39624da3909395f1862326e1169407e25d004280 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Wed, 15 Mar 2023 18:24:01 +1100 Subject: [PATCH 14/67] - SW: Remove `getViewHeightDiff()` call in player sprite draw code. * I added this when removing the player's pos vector in lieu of the sprite vector to further smooth out the sprite's Z in chase cam mode, but it just doesn't look good. --- source/games/sw/src/draw.cpp | 2 +- source/games/sw/src/game.h | 5 ----- source/games/sw/src/player.cpp | 2 +- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/source/games/sw/src/draw.cpp b/source/games/sw/src/draw.cpp index 1d5e7d45b..088f10fe2 100644 --- a/source/games/sw/src/draw.cpp +++ b/source/games/sw/src/draw.cpp @@ -781,7 +781,7 @@ static void analyzesprites(tspriteArray& tsprites, const DVector3& viewpos, doub if (pp->Flags & (PF_VIEW_FROM_OUTSIDE)) tsp->cstat |= (CSTAT_SPRITE_TRANSLUCENT); - auto pos = pp->si.plusZ(tsp->pos.Z + pp->getViewHeightDiff()); + auto pos = pp->si.plusZ(tsp->pos.Z); if (pp->Flags & (PF_CLIMBING)) { diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index ea2e276d7..805a0883c 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -1892,11 +1892,6 @@ struct PLAYER uint8_t WpnReloadState; - double getViewHeightDiff() - { - return actor->viewzoffset + height; - } - void posZset(const double val) { actor->spr.pos.Z = val - actor->viewzoffset; diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index 42b47e65d..cdabe1e3f 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -1485,7 +1485,7 @@ void DoPlayerSetWadeDepth(PLAYER* pp) void DoPlayerViewOffset(PLAYER* pp) { - pp->actor->viewzoffset -= pp->getViewHeightDiff() * 0.375; + pp->actor->viewzoffset -= (pp->actor->viewzoffset + pp->height) * 0.375; } void DoPlayerHeight(PLAYER* pp) From 7da3c62ea8bf12b3b21c342c08a66e677f697408 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Wed, 15 Mar 2023 19:40:42 +1100 Subject: [PATCH 15/67] - Blood: Repair velocity scaling in `ConcussSprite()`. * Issue originates back from 645c606e396b1a757319070511699735f76f864c. * During initial floatification, the velocity addition was changed a mulscale of 16 to 12, quadrupling the amplification. * A lot's changed since then, but we can restore the size of the velocity by simply dividing the size value by 4x. * Turned into a reciprocal as well to avoid division. * Fixes #860. --- source/games/blood/src/actor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/games/blood/src/actor.cpp b/source/games/blood/src/actor.cpp index 017ff11d6..dcbba241b 100644 --- a/source/games/blood/src/actor.cpp +++ b/source/games/blood/src/actor.cpp @@ -2574,7 +2574,7 @@ static void ConcussSprite(DBloodActor* source, DBloodActor* actor, const DVector if (mass > 0) { auto tex = TexMan.GetGameTexture(actor->spr.spritetexture()); - double size = (tex->GetDisplayWidth() * actor->spr.scale.X * tex->GetDisplayHeight() * actor->spr.scale.Y) / 0x20000; + double size = tex->GetDisplayWidth() * actor->spr.scale.X * tex->GetDisplayHeight() * actor->spr.scale.Y * (1. / 0x100000); actor->vel += vect * Scale(damage, size, mass); } } From a4bca328bc3c19ee5c433a694769ba359af09257 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Wed, 15 Mar 2023 19:57:45 +1100 Subject: [PATCH 16/67] - SW: Remove `Player::siang` since we have the same data in --- source/games/sw/src/draw.cpp | 3 +-- source/games/sw/src/game.h | 1 - source/games/sw/src/player.cpp | 1 - source/games/sw/src/save.cpp | 1 - wadsrc/static/zscript/games/sw/swgame.zs | 1 - 5 files changed, 1 insertion(+), 6 deletions(-) diff --git a/source/games/sw/src/draw.cpp b/source/games/sw/src/draw.cpp index 088f10fe2..fcc785b58 100644 --- a/source/games/sw/src/draw.cpp +++ b/source/games/sw/src/draw.cpp @@ -800,7 +800,7 @@ static void analyzesprites(tspriteArray& tsprites, const DVector3& viewpos, doub } tsp->pos = pos; - tsp->Angles.Yaw = pp->siang; + tsp->Angles.Yaw = pp->Angles.RenderAngles.Yaw; //continue; } else @@ -1260,7 +1260,6 @@ void drawscreen(PLAYER* pp, double interpfrac, bool sceneonly) } pp->si = tpos.plusZ(-pp->actor->getOffsetZ()); - pp->siang = tangles.Yaw; QuakeViewChange(camerapp, tpos, tangles.Yaw); int vis = g_visibility; diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index 805a0883c..fff107c4d 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -1744,7 +1744,6 @@ struct PLAYER double circle_camera_dist; DVector3 si; // save player interp position for PlayerSprite - DAngle siang; DVector2 vect, ovect, slide_vect; // these need floatification, but must be done together. vect is in 14.18 format! diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index cdabe1e3f..ab1ae57cc 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -7464,7 +7464,6 @@ DEFINE_FIELD_X(SWPlayer, PLAYER, circle_camera_dist) //DEFINE_FIELD_X(SWPlayer, PLAYER, six) //DEFINE_FIELD_X(SWPlayer, PLAYER, siy) //DEFINE_FIELD_X(SWPlayer, PLAYER, siz) -DEFINE_FIELD_X(SWPlayer, PLAYER, siang) //DEFINE_FIELD_X(SWPlayer, PLAYER, xvect) //DEFINE_FIELD_X(SWPlayer, PLAYER, yvect) //DEFINE_FIELD_X(SWPlayer, PLAYER, oxvect) diff --git a/source/games/sw/src/save.cpp b/source/games/sw/src/save.cpp index 8e9ceaac0..d1b87182c 100644 --- a/source/games/sw/src/save.cpp +++ b/source/games/sw/src/save.cpp @@ -460,7 +460,6 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, PLAYER& w, PLAYER* ("six", w.si.X) ("siy", w.si.Y) ("siz", w.si.Z) - ("siang", w.siang) ("xvect", w.vect.X) ("yvect", w.vect.Y) ("friction", w.friction) diff --git a/wadsrc/static/zscript/games/sw/swgame.zs b/wadsrc/static/zscript/games/sw/swgame.zs index 8556bd136..4d4ccc286 100644 --- a/wadsrc/static/zscript/games/sw/swgame.zs +++ b/wadsrc/static/zscript/games/sw/swgame.zs @@ -198,7 +198,6 @@ struct SWPlayer native native double hiz,loz; native double p_ceiling_dist,p_floor_dist; native double circle_camera_dist; - native double siang; native int friction; native int16 slide_ang; From e8f2f98473de15807fd92bc76d4b4a23e0ead449 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Wed, 15 Mar 2023 20:42:24 +1100 Subject: [PATCH 17/67] - Repair voxel 2D vector adjustment. * Originates from a6fb8318941b08c6fdde49f78f25738e96c59dea. * Division taken off, probably mixing up x/yrepeat and x/yoffset. * Fixes #869. --- source/core/rendering/scene/hw_sprites.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/core/rendering/scene/hw_sprites.cpp b/source/core/rendering/scene/hw_sprites.cpp index d45a2e3a5..369168d17 100644 --- a/source/core/rendering/scene/hw_sprites.cpp +++ b/source/core/rendering/scene/hw_sprites.cpp @@ -487,8 +487,8 @@ bool HWSprite::ProcessVoxel(HWDrawInfo* di, voxmodel_t* vox, tspritetype* spr, s { sprxscale *= 1.25f; auto rvec = ownerActor->sprext.rot.Yaw.ToVector(); - translatevec.Y -= spr->xoffset * rvec.X; - translatevec.X += spr->xoffset * rvec.Y; + translatevec.Y -= spr->xoffset * rvec.X / 64; + translatevec.X += spr->xoffset * rvec.Y / 64; } if (spr->cstat & CSTAT_SPRITE_YFLIP) From 30f9ec5fd857edfb641a7bc88d722570d9f98082 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Wed, 15 Mar 2023 21:30:44 +1100 Subject: [PATCH 18/67] - Blood: Fix shotgun ammo display when player fires a shell, switches weapons, then switches back. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Such a circumstance reloads the weapon off screen. * While the "right" fix would be to stop that, some fanatics will probably be relying on such a mechanism. * As such, just fudge the printout on the screen instead 🙃. * Fixes #877. --- wadsrc/static/zscript/games/blood/ui/sbar.zs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/wadsrc/static/zscript/games/blood/ui/sbar.zs b/wadsrc/static/zscript/games/blood/ui/sbar.zs index bb31ca484..c4af37a27 100644 --- a/wadsrc/static/zscript/games/blood/ui/sbar.zs +++ b/wadsrc/static/zscript/games/blood/ui/sbar.zs @@ -688,6 +688,9 @@ class BloodStatusBar : RazeStatusBar } else { + bool stateNeedsEvenAmt = pPlayer.weaponState == 3 || pPlayer.weaponState == 1; + bool stateNeedsOddAmt = pPlayer.weaponState == 2; + num += stateNeedsEvenAmt && (num % 2) || stateNeedsOddAmt && !(num % 2); int clip = CalcMagazineAmount(num, 2, pPlayer.weaponState == 1); int total = num - clip; String format = String.Format("%d/%d", clip, num - clip); From 07a82508fae3dcc683d24f12803e5767051ea04f Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Wed, 15 Mar 2023 22:22:52 +1100 Subject: [PATCH 19/67] - Blood: Fix palette of actor sprite on 2D automap. * Fixes #846. --- source/games/blood/src/view.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/games/blood/src/view.cpp b/source/games/blood/src/view.cpp index a1194c1f5..6cfe0a881 100644 --- a/source/games/blood/src/view.cpp +++ b/source/games/blood/src/view.cpp @@ -800,7 +800,7 @@ bool GameInterface::DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos, auto vect = OutAutomapVector(mxy - cpos, cangvect, czoom, xydim); DrawTexture(twod, tileGetTexture(actor->spr.picnum, true), vect.X, vect.Y, DTA_ClipLeft, viewport3d.Left(), DTA_ClipTop, viewport3d.Top(), DTA_ScaleX, czoom * (2. / 3.), DTA_ScaleY, czoom * (2. / 3.), DTA_CenterOffset, true, - DTA_ClipRight, viewport3d.Right(), DTA_ClipBottom, viewport3d.Bottom(), DTA_Alpha, (actor->spr.cstat & CSTAT_SPRITE_TRANSLUCENT ? 0.5 : 1.), TAG_DONE); + DTA_ClipRight, viewport3d.Right(), DTA_ClipBottom, viewport3d.Bottom(), DTA_Alpha, (actor->spr.cstat & CSTAT_SPRITE_TRANSLUCENT ? 0.5 : 1.), DTA_TranslationIndex, TRANSLATION(Translation_Remap, actor->spr.pal), TAG_DONE); } } return true; From 0d62e6befeb31842388478ca12f5d90a16df5c64 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Wed, 15 Mar 2023 22:52:14 +1100 Subject: [PATCH 20/67] - Exhumed: Optimise `UnlinkIgnitedAnim()` from fb97e3c6cae49d9ff34f43668593b9c089b7a02d a bit. * Bad cherry pick caused a stat iteration over the wrong stat number. * Cleaned up commentary to reflect that we have actors and not so much sprites or an anim array anymore. --- source/games/exhumed/src/anims.cpp | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/source/games/exhumed/src/anims.cpp b/source/games/exhumed/src/anims.cpp index c7ad69a39..7b20f1a3c 100644 --- a/source/games/exhumed/src/anims.cpp +++ b/source/games/exhumed/src/anims.cpp @@ -55,31 +55,25 @@ void InitAnims() } /* - Use when deleting an ignited sprite to check if any anims reference it. - Will remove the Anim's loop flag and set the source (the ignited sprite's) sprite reference to -1. - FuncAnim() will then delete the anim on next call for this anim. + Use when deleting an ignited actor to check if any actors reference it. + Will remove the actor's anim loop flag and set the source (the ignited actor's) actor target to null. + FuncAnim() will then delete the actor on next call for this actor. - Without this, the anim will hold reference to a sprite which will eventually be reused, but the anim code - will continue to manipulate its hitag value. This can break runlist records for things like LavaDude - limbs that store these in the sprite hitag. + Without this, the actor will hold reference to an actor which will prevent the GC from deleting it properly. Specifically needed for IgniteSprite() anims which can become orphaned from the source sprite (e.g a bullet) when the bullet sprite is deleted. */ void UnlinkIgnitedAnim(DExhumedActor* pActor) { - // scan the active anims (that aren't in the 'free' section of AnimsFree[]) - ExhumedStatIterator it(500); + ExhumedStatIterator it(kStatIgnited); while (auto itActor = it.Next()) { - if (itActor->spr.statnum == kStatIgnited) + // .pTarget holds the actor pointer of the source 'actor that's on fire' actor + if (pActor == itActor->pTarget) { - // .hitag holds the sprite number of the source 'sprite that's on fire' sprite - if (pActor == itActor->pTarget) - { - itActor->nAction &= ~kAnimLoop; // clear the animation loop flag - itActor->pTarget = nullptr; // set the sprite reference to -1 - } + itActor->nAction &= ~kAnimLoop; // clear the animation loop flag + itActor->pTarget = nullptr; // set the actor target to null } } } From b42b9de2a26de4710cb55e4949985ddaccf36bfa Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Thu, 16 Mar 2023 11:23:05 +1100 Subject: [PATCH 21/67] Revert "- SW: Tune shadow drawing code so that it by default uses the sector's interpolated floorz when possible." This reverts commit 3271c2011ee97291312fd88a36ac7a338b23bf44. * Fixes #884 * Fixes #892 --- source/games/sw/src/draw.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/source/games/sw/src/draw.cpp b/source/games/sw/src/draw.cpp index fcc785b58..77285d94b 100644 --- a/source/games/sw/src/draw.cpp +++ b/source/games/sw/src/draw.cpp @@ -312,10 +312,13 @@ void DoShadows(tspriteArray& tsprites, tspritetype* tsp, double viewz) scale = tsp->scale; } - loz = DoShadowFindGroundPoint(tsp); - if (ownerActor->user.lowActor && (ownerActor->user.lowActor->spr.cstat & (CSTAT_SPRITE_ALIGNMENT_WALL | CSTAT_SPRITE_ALIGNMENT_FLOOR))) + loz = ownerActor->user.loz; + if (ownerActor->user.lowActor) { - loz = ownerActor->user.loz; + if (!(ownerActor->user.lowActor->spr.cstat & (CSTAT_SPRITE_ALIGNMENT_WALL | CSTAT_SPRITE_ALIGNMENT_FLOOR))) + { + loz = DoShadowFindGroundPoint(tsp); + } } // need to find the ground here From 3d6f1e1a04956c4903143c0b291a13539202645e Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Thu, 16 Mar 2023 12:17:42 +1100 Subject: [PATCH 22/67] - Exhumed: Store dedicated player velocity in Player struct. * Changes implementation in 67c7dd65f94f9340d28ac9729be141377d9478e2. * Cannot rely on the actor's velocity alone as parts of the game modify this, such as getting hit by lava dudes, but game nullifies this at the start of the player's tic. --- source/games/exhumed/src/exhumed.cpp | 2 +- source/games/exhumed/src/input.cpp | 4 ++-- source/games/exhumed/src/player.cpp | 7 +++++-- source/games/exhumed/src/player.h | 1 + 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/source/games/exhumed/src/exhumed.cpp b/source/games/exhumed/src/exhumed.cpp index 4d1c753ce..1a7025224 100644 --- a/source/games/exhumed/src/exhumed.cpp +++ b/source/games/exhumed/src/exhumed.cpp @@ -379,7 +379,7 @@ void GameInterface::Ticker() PlayerList[nLocalPlayer].input = playercmds[nLocalPlayer].ucmd; if (oldactions & SB_CENTERVIEW) PlayerList[nLocalPlayer].input.actions |= SB_CENTERVIEW; - auto& lPlayerVel = PlayerList[nLocalPlayer].pActor->vel.XY(); + auto& lPlayerVel = PlayerList[nLocalPlayer].vel; auto inputvect = DVector2(PlayerList[nLocalPlayer].input.fvel, PlayerList[nLocalPlayer].input.svel).Rotated(inita) * 0.375; diff --git a/source/games/exhumed/src/input.cpp b/source/games/exhumed/src/input.cpp index 5e95ba0d8..f227503dd 100644 --- a/source/games/exhumed/src/input.cpp +++ b/source/games/exhumed/src/input.cpp @@ -68,9 +68,9 @@ void GameInterface::GetInput(ControlInfo* const hidInput, double const scaleAdju { processMovement(&input, &localInput, hidInput, scaleAdjust); } - else if (pPlayer->pActor) + else { - pPlayer->pActor->vel.Zero(); + pPlayer->vel.Zero(); } if (!SyncInput() && gamestate == GS_LEVEL && !nFreeze) diff --git a/source/games/exhumed/src/player.cpp b/source/games/exhumed/src/player.cpp index 56ef4ef50..1bf4923d2 100644 --- a/source/games/exhumed/src/player.cpp +++ b/source/games/exhumed/src/player.cpp @@ -854,7 +854,7 @@ bool CheckMovingBlocks(int nPlayer, Collision& nMove, DVector3& spr_pos, sectort { PlayerList[nPlayer].pPlayerPushSect = sect; - DVector2 vel = PlayerList[nPlayer].pActor->vel.XY(); + DVector2 vel = PlayerList[nPlayer].vel; auto nMyAngle = vel.Angle().Normalized360(); setsectinterpolate(sect); @@ -905,6 +905,8 @@ void AIPlayer::Tick(RunListEvent* ev) int nAction = PlayerList[nPlayer].nAction; int nActionB = PlayerList[nPlayer].nAction; + pPlayerActor->vel.XY() = PlayerList[nPlayer].vel; + if (PlayerList[nPlayer].nCurrentItem > -1) { UseItem(nPlayer, PlayerList[nPlayer].nCurrentItem); @@ -1003,7 +1005,7 @@ void AIPlayer::Tick(RunListEvent* ev) auto playerPos = pPlayerActor->spr.pos.XY(); - DVector2 vect = pPlayerActor->vel.XY(); + DVector2 vect = PlayerList[nPlayer].vel; double zz = pPlayerActor->vel.Z; if (pPlayerActor->vel.Z > 32) @@ -1071,6 +1073,7 @@ void AIPlayer::Tick(RunListEvent* ev) pPlayerActor->spr.Angles = DRotator(nullAngle, GetAngleToSprite(pPlayerActor, pSpiritSprite), nullAngle); pPlayerActor->backupang(); + PlayerList[nPlayer].vel.Zero(); pPlayerActor->vel.Zero(); if (nFreeze < 1) diff --git a/source/games/exhumed/src/player.h b/source/games/exhumed/src/player.h index f099f5436..1363c6b4b 100644 --- a/source/games/exhumed/src/player.h +++ b/source/games/exhumed/src/player.h @@ -81,6 +81,7 @@ struct Player InputPacket input; PlayerAngles Angles; + DVector2 vel; sectortype* pPlayerPushSect; sectortype* pPlayerViewSect; From cb1e4e7a34784cc68f8a2e55fadfce609d2d5fca Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Thu, 16 Mar 2023 13:05:22 +1100 Subject: [PATCH 23/67] - Exhumed: Ensure `Player::items[]` is signed. * Change originates from b71c725e3ebbf0cfb72c711d72dfccc00758f55c. * Matches PCExhumed and GDX. * Logic in game requires this variable to be signed. * Fixes #415. * Fixes #888. --- source/games/exhumed/src/player.h | 2 +- wadsrc/static/zscript/games/exhumed/exhumedgame.zs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/games/exhumed/src/player.h b/source/games/exhumed/src/player.h index 1363c6b4b..dceddcb9f 100644 --- a/source/games/exhumed/src/player.h +++ b/source/games/exhumed/src/player.h @@ -66,7 +66,7 @@ struct Player int16_t nMagic; int16_t nItem; int8_t nCurrentItem; - uint8_t items[8]; + int8_t items[8]; int16_t nAmmo[7]; // TODO - kMaxWeapons? int16_t nCurrentWeapon; diff --git a/wadsrc/static/zscript/games/exhumed/exhumedgame.zs b/wadsrc/static/zscript/games/exhumed/exhumedgame.zs index 0b4a5fa2e..947856800 100644 --- a/wadsrc/static/zscript/games/exhumed/exhumedgame.zs +++ b/wadsrc/static/zscript/games/exhumed/exhumedgame.zs @@ -50,7 +50,7 @@ struct ExhumedPlayer native native uint16 keys; native int16 nMagic; native int16 nItem; - native uint8 items[8]; + native int8 items[8]; native int16 nAmmo[7]; // TODO - kMaxWeapons? native int16 nPlayerWeapons; From 528eb0ea9aaf07eef08984ea1d018c097399ee90 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Thu, 16 Mar 2023 15:50:52 +1100 Subject: [PATCH 24/67] - Blood: Fix state checks when using TNT while diving underwater. * A mess of bloody proportions... * Originates from d30c94c70998417422f201b2e5c3b536a075538b. * Fixes #878. --- source/games/blood/src/weapon.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/games/blood/src/weapon.cpp b/source/games/blood/src/weapon.cpp index efcd8d968..16786f05e 100644 --- a/source/games/blood/src/weapon.cpp +++ b/source/games/blood/src/weapon.cpp @@ -862,6 +862,7 @@ void WeaponLower(PLAYER* pPlayer) } else { + pPlayer->weaponState = 1; StartQAV(pPlayer, kQAVBUNDOWN2); } break; @@ -2400,7 +2401,7 @@ void WeaponProcess(PLAYER* pPlayer) { { pPlayer->fuseTime = pPlayer->weaponTimer; DropBundle(1, pPlayer); - pPlayer->weaponState = 1; + pPlayer->weaponState = 3; } } WeaponLower(pPlayer); From 8bcbc1b892031eecba7ad78651bf00582e8efcda Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Thu, 16 Mar 2023 16:34:31 +1100 Subject: [PATCH 25/67] - Null the roll angle used for weapon drawing when looking left/right and with Blood's delirium for now. * Intended to make the look left/right keys better, but doesn't work properly for weapons made up of layered parts of varying sizes. * Fixes #879. --- source/core/gameinput.h | 4 ++-- source/games/blood/src/hudsprites.cpp | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/source/core/gameinput.h b/source/core/gameinput.h index edc26c054..8a5cdc605 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -65,8 +65,8 @@ struct PlayerAngles } auto getWeaponOffsets(const double interpfrac) { - // Push the Y down a bit since the weapon is at the edge of the screen. - auto offsets = getCrosshairOffsets(interpfrac); offsets.first.Y *= 4.; + // Push the Y down a bit since the weapon is at the edge of the screen. Also null roll for now. + auto offsets = getCrosshairOffsets(interpfrac); offsets.first.Y *= 4.; offsets.second = nullAngle; return offsets; } diff --git a/source/games/blood/src/hudsprites.cpp b/source/games/blood/src/hudsprites.cpp index 0e3f41f75..3a079d4d1 100644 --- a/source/games/blood/src/hudsprites.cpp +++ b/source/games/blood/src/hudsprites.cpp @@ -112,6 +112,9 @@ void hudDraw(PLAYER* pPlayer, sectortype* pSector, double bobx, double boby, dou { if (gViewPos == 0) { + // Nullify incoming roll angle for now as it doesn't draw weapons made up of parts correctly. + angle = nullAngle; + auto cXY = DVector2(160, 220) + pPlayer->Angles.getWeaponOffsets(interpfrac).first; if (cl_weaponsway) From 9a17d335793546e53d4da385b95beb9e92eec85c Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Thu, 16 Mar 2023 22:15:11 +1100 Subject: [PATCH 26/67] - Duke: Ensure spawned player actor has view height baked in up until the first `getzrange()` call. * The original game spawning the player's sprite/actor would set the sprite's pos with the Z matching the player's, which had a height offset already applied. * This baked in height offset was carried through up until the `SetActor()` call in `processinput()`, where the original game would then strip off `gs.playerheight`. * This baked in height offset within the actor is critical on the first tic for pre-activated elevators on level spawn to function right, such as E1L2 and E2L3. * Properly setting the player actor's Z immediately after the initial `getzrange()` call, but before other functions like `movement()`, etc further down in `processinput()` is the best spot. * Fixes #870. --- source/games/duke/src/player_d.cpp | 9 ++++++++- source/games/duke/src/player_r.cpp | 16 ++++++++++------ source/games/duke/src/premap.cpp | 3 +-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index 335e0e750..9a3969f30 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -2620,6 +2620,13 @@ void processinput_d(int snum) shrunk = (pact->spr.scale.Y < 0.5); getzrange(p->GetActor()->getPosWithOffsetZ(), psectp, &ceilingz, chz, &floorz, clz, 10.1875, CLIPMASK0); + if (!PlayClock) + { + pact->spr.pos.Z += gs.playerheight; + pact->opos.Z += gs.playerheight; + pact->oviewzoffset = pact->viewzoffset = -gs.playerheight; + } + p->truefz = getflorzofslopeptr(psectp, p->GetActor()->getPosWithOffsetZ()); p->truecz = getceilzofslopeptr(psectp, p->GetActor()->getPosWithOffsetZ()); @@ -2910,7 +2917,7 @@ HORIZONLY: } // RBG*** - SetActor(pact, p->GetActor()->spr.pos); + SetActor(pact, pact->spr.pos); if (psectlotag < 3) { diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index 59a0da549..d678c3bf7 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -3235,22 +3235,26 @@ void processinput_r(int snum) p->spritebridge = 0; shrunk = (pact->spr.scale.Y < 0.125); - double tempfz; if (pact->clipdist == 16) { getzrange(p->GetActor()->getPosWithOffsetZ(), psectp, &ceilingz, chz, &floorz, clz, 10.1875, CLIPMASK0); - tempfz = getflorzofslopeptr(psectp, p->GetActor()->getPosWithOffsetZ()); } else { getzrange(p->GetActor()->getPosWithOffsetZ(), psectp, &ceilingz, chz, &floorz, clz, 0.25, CLIPMASK0); - tempfz = getflorzofslopeptr(psectp, p->GetActor()->getPosWithOffsetZ()); } - p->truefz = tempfz; + if (!PlayClock) + { + pact->spr.pos.Z += gs.playerheight; + pact->opos.Z += gs.playerheight; + pact->oviewzoffset = pact->viewzoffset = -gs.playerheight; + } + + p->truefz = getflorzofslopeptr(psectp, p->GetActor()->getPosWithOffsetZ()); p->truecz = getceilzofslopeptr(psectp, p->GetActor()->getPosWithOffsetZ()); - double truefdist = abs(p->GetActor()->getOffsetZ() - tempfz); + double truefdist = abs(p->GetActor()->getOffsetZ() - p->truefz); if (clz.type == kHitSector && psectlotag == 1 && truefdist > gs.playerheight + 16) psectlotag = 0; @@ -3700,7 +3704,7 @@ HORIZONLY: } // RBG*** - SetActor(pact, p->GetActor()->spr.pos); + SetActor(pact, pact->spr.pos); if (psectlotag == 800 && (!isRRRA() || !p->lotag800kill)) { diff --git a/source/games/duke/src/premap.cpp b/source/games/duke/src/premap.cpp index 91051c6d8..cf7b6d72f 100644 --- a/source/games/duke/src/premap.cpp +++ b/source/games/duke/src/premap.cpp @@ -503,11 +503,10 @@ void resetpspritevars(int g, const DVector3& startpos, const DAngle startang) int aimmode[MAXPLAYERS]; STATUSBARTYPE tsbar[MAXPLAYERS]; - auto newActor = CreateActor(ps[0].cursector, startpos.plusZ(gs.playerheight), + auto newActor = CreateActor(ps[0].cursector, startpos, TILE_APLAYER, 0, DVector2(0, 0), startang, 0., 0., nullptr, 10); newActor->spr.Angles.Pitch = DAngle::fromDeg(-17.354); - newActor->viewzoffset = -gs.playerheight; newActor->backuploc(); if (ud.recstat != 2) for (i = 0; i < MAXPLAYERS; i++) From c4041affb116a1bf31fdbf08f7c50eb3a91a5811 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Thu, 16 Mar 2023 22:24:34 +1100 Subject: [PATCH 27/67] - Duke: Reduce boilerplate from previous commit. --- source/games/duke/src/inlines.h | 10 ++++++++++ source/games/duke/src/player_d.cpp | 7 +------ source/games/duke/src/player_r.cpp | 7 +------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/source/games/duke/src/inlines.h b/source/games/duke/src/inlines.h index 5648de43d..a0f4e4ae8 100644 --- a/source/games/duke/src/inlines.h +++ b/source/games/duke/src/inlines.h @@ -353,4 +353,14 @@ inline void processinputvel(int snum) p->sync.svel = (float)velvect.Y; } +inline void setPlayerActorViewZOffset(DDukeActor* const pact) +{ + if (!PlayClock) + { + pact->spr.pos.Z += gs.playerheight; + pact->opos.Z += gs.playerheight; + pact->oviewzoffset = pact->viewzoffset = -gs.playerheight; + } +} + END_DUKE_NS diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index 9a3969f30..4c49e6bd3 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -2620,12 +2620,7 @@ void processinput_d(int snum) shrunk = (pact->spr.scale.Y < 0.5); getzrange(p->GetActor()->getPosWithOffsetZ(), psectp, &ceilingz, chz, &floorz, clz, 10.1875, CLIPMASK0); - if (!PlayClock) - { - pact->spr.pos.Z += gs.playerheight; - pact->opos.Z += gs.playerheight; - pact->oviewzoffset = pact->viewzoffset = -gs.playerheight; - } + setPlayerActorViewZOffset(pact); p->truefz = getflorzofslopeptr(psectp, p->GetActor()->getPosWithOffsetZ()); p->truecz = getceilzofslopeptr(psectp, p->GetActor()->getPosWithOffsetZ()); diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index d678c3bf7..fa1f1b375 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -3244,12 +3244,7 @@ void processinput_r(int snum) getzrange(p->GetActor()->getPosWithOffsetZ(), psectp, &ceilingz, chz, &floorz, clz, 0.25, CLIPMASK0); } - if (!PlayClock) - { - pact->spr.pos.Z += gs.playerheight; - pact->opos.Z += gs.playerheight; - pact->oviewzoffset = pact->viewzoffset = -gs.playerheight; - } + setPlayerActorViewZOffset(pact); p->truefz = getflorzofslopeptr(psectp, p->GetActor()->getPosWithOffsetZ()); p->truecz = getceilzofslopeptr(psectp, p->GetActor()->getPosWithOffsetZ()); From d17650f8858ffe4ef5fa1a4ba40ef4e9ffcbce1e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 16 Mar 2023 17:49:50 +0100 Subject: [PATCH 28/67] - removed the ValidateTarget call from HackSeqCallback. The original function does not validate its target, it just uses undefined memory instead when this case happens. --- source/games/blood/src/aizomba.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/games/blood/src/aizomba.cpp b/source/games/blood/src/aizomba.cpp index ac0f8ef46..aa6d012ee 100644 --- a/source/games/blood/src/aizomba.cpp +++ b/source/games/blood/src/aizomba.cpp @@ -60,8 +60,8 @@ AISTATE zombie13AC2C = { kAiStateOther, 11, nStandClient, 0, entryEZombie, NULL, void HackSeqCallback(int, DBloodActor* actor) { - if (!actor->ValidateTarget(__FUNCTION__)) return; auto target = actor->GetTarget(); + if (!target) return; DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type); DUDEINFO* pDudeInfoT = getDudeInfo(target->spr.type); DVector3 dv; From d6b68dec5e1b6c54600a797f377a6dae32a355a4 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Fri, 17 Mar 2023 12:29:37 +1100 Subject: [PATCH 29/67] - Duke: Remove `player_struct::resurrected` flag I added in 2021 and fix issue properly. * The check for `player_struct::dead_flag` in `FinalizeInput()` was overzealous and is not checked in the original code in this instance. --- source/games/duke/src/cheats.cpp | 1 - source/games/duke/src/gameexec.cpp | 1 - source/games/duke/src/input.cpp | 3 +-- source/games/duke/src/player.cpp | 2 +- source/games/duke/src/premap.cpp | 1 - source/games/duke/src/savegame.cpp | 1 - source/games/duke/src/types.h | 2 -- source/games/duke/src/vmexports.cpp | 1 - wadsrc/static/zscript/games/duke/dukegame.zs | 2 -- 9 files changed, 2 insertions(+), 12 deletions(-) diff --git a/source/games/duke/src/cheats.cpp b/source/games/duke/src/cheats.cpp index 3f12c6127..1aab5e643 100644 --- a/source/games/duke/src/cheats.cpp +++ b/source/games/duke/src/cheats.cpp @@ -66,7 +66,6 @@ static const char *cheatGod(int myconnectindex, int state) auto* p = &ps[myconnectindex]; auto act = p->GetActor(); - p->resurrected = true; act->spr.extra = gs.max_player_health; act->hitextra = 0; if (ud.god) diff --git a/source/games/duke/src/gameexec.cpp b/source/games/duke/src/gameexec.cpp index 272fbee0c..dbe99c024 100644 --- a/source/games/duke/src/gameexec.cpp +++ b/source/games/duke/src/gameexec.cpp @@ -2268,7 +2268,6 @@ int ParseState::parse(void) ps[g_p].wackedbyactor = nullptr; ps[g_p].shield_amount = gs.max_armour_amount; ps[g_p].dead_flag = 0; - ps[g_p].resurrected = false; ps[g_p].pals.a = 0; ps[g_p].footprintcount = 0; ps[g_p].weapreccnt = 0; diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 0a177e00f..32c9b7dab 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -85,7 +85,6 @@ void hud_input(int plnum) { p->GetActor()->spr.extra += 2; p->last_extra = p->GetActor()->spr.extra; - p->resurrected = true; } else if (p->GetActor()->spr.extra < gs.max_player_health) p->GetActor()->spr.extra = gs.max_player_health; @@ -771,7 +770,7 @@ static void processVehicleInput(player_struct *p, ControlInfo* const hidInput, I static void FinalizeInput(player_struct *p, InputPacket& input) { - if (gamestate != GS_LEVEL || movementBlocked(p) || p->GetActor()->spr.extra <= 0 || (p->dead_flag && !ud.god && !p->resurrected)) + if (gamestate != GS_LEVEL || movementBlocked(p) || p->GetActor()->spr.extra <= 0) { // neutralize all movement when not in a game, blocked or in automap follow mode loc.fvel = loc.svel = 0; diff --git a/source/games/duke/src/player.cpp b/source/games/duke/src/player.cpp index 68a975c05..87b2a32bc 100644 --- a/source/games/duke/src/player.cpp +++ b/source/games/duke/src/player.cpp @@ -726,7 +726,7 @@ void playerJump(int snum, double floorz, double ceilingz) void player_struct::apply_seasick() { - if (isRRRA() && SeaSick && (dead_flag == 0 || (dead_flag && resurrected))) + if (isRRRA() && SeaSick && (dead_flag == 0)) { if (SeaSick < 250) { diff --git a/source/games/duke/src/premap.cpp b/source/games/duke/src/premap.cpp index cf7b6d72f..580570d77 100644 --- a/source/games/duke/src/premap.cpp +++ b/source/games/duke/src/premap.cpp @@ -91,7 +91,6 @@ void resetplayerstats(int snum) gFullMap = 0; p->dead_flag = 0; - p->resurrected = false; p->wackedbyactor = nullptr; p->falling_counter = 0; p->quick_kick = 0; diff --git a/source/games/duke/src/savegame.cpp b/source/games/duke/src/savegame.cpp index b0836c790..d5bec5b84 100644 --- a/source/games/duke/src/savegame.cpp +++ b/source/games/duke/src/savegame.cpp @@ -151,7 +151,6 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, player_struct& w, .Array("weaprecs", w.weaprecs, w.weapreccnt) ("interface_toggle_flag", w.interface_toggle_flag) ("dead_flag", w.dead_flag) - ("resurrected", w.resurrected) ("show_empty_weapon", w.show_empty_weapon) ("scuba_amount", w.scuba_amount) ("jetpack_amount", w.jetpack_amount) diff --git a/source/games/duke/src/types.h b/source/games/duke/src/types.h index 4aa549d3b..368134a08 100644 --- a/source/games/duke/src/types.h +++ b/source/games/duke/src/types.h @@ -276,8 +276,6 @@ struct player_struct int max_secret_rooms, secret_rooms, max_actors_killed, actors_killed; - bool resurrected; - // Redneck Rampage additions. Those which did not have names in the reconstructed source got one from either RedneckGDX or RedNukem. // Items were reordered by size. int stairs; diff --git a/source/games/duke/src/vmexports.cpp b/source/games/duke/src/vmexports.cpp index 64800e332..89ce890e4 100644 --- a/source/games/duke/src/vmexports.cpp +++ b/source/games/duke/src/vmexports.cpp @@ -898,7 +898,6 @@ DEFINE_FIELD_X(DukePlayer, player_struct, max_secret_rooms) DEFINE_FIELD_X(DukePlayer, player_struct, secret_rooms) DEFINE_FIELD_X(DukePlayer, player_struct, max_actors_killed) DEFINE_FIELD_X(DukePlayer, player_struct, actors_killed) -DEFINE_FIELD_X(DukePlayer, player_struct, resurrected) DEFINE_FIELD_X(DukePlayer, player_struct, stairs) DEFINE_FIELD_X(DukePlayer, player_struct, detonate_count) //DEFINE_FIELD_X(DukePlayer, player_struct, noise.X) diff --git a/wadsrc/static/zscript/games/duke/dukegame.zs b/wadsrc/static/zscript/games/duke/dukegame.zs index aeb545fb6..c6d6dd8f0 100644 --- a/wadsrc/static/zscript/games/duke/dukegame.zs +++ b/wadsrc/static/zscript/games/duke/dukegame.zs @@ -303,8 +303,6 @@ struct DukePlayer native native int max_secret_rooms, secret_rooms, max_actors_killed, actors_killed; - native bool resurrected; - // Redneck Rampage additions. Those which did not have names in the reconstructed source got one from either RedneckGDX or RedNukem. // Items were reordered by size. native int stairs; From 0fca5b14a2eb3c4d27c11280aba49dbce701f784 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Fri, 17 Mar 2023 13:45:29 +1100 Subject: [PATCH 30/67] - SW: Ensure automap uses untouched interpolated actor position. * Using chase cam while the automap was on was drawing the player sprite incorrectly. --- source/games/sw/src/draw.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/games/sw/src/draw.cpp b/source/games/sw/src/draw.cpp index 77285d94b..a61514e45 100644 --- a/source/games/sw/src/draw.cpp +++ b/source/games/sw/src/draw.cpp @@ -1246,6 +1246,7 @@ void drawscreen(PLAYER* pp, double interpfrac, bool sceneonly) // Get initial player position, interpolating if required. DVector3 tpos = camerapp->actor->getRenderPos(interpfrac); + DVector2 ampos = tpos.XY(); DRotator tangles = camerapp->Angles.getRenderAngles(interpfrac); sectortype* tsect = camerapp->cursector; @@ -1333,7 +1334,7 @@ void drawscreen(PLAYER* pp, double interpfrac, bool sceneonly) } } } - DrawOverheadMap(tpos.XY(), tangles.Yaw, interpfrac); + DrawOverheadMap(ampos, tangles.Yaw, interpfrac); } SWSpriteIterator it; From 742a2e5c9aae837d67d32a5c373e90ec53ffb987 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Fri, 17 Mar 2023 14:11:27 +1100 Subject: [PATCH 31/67] - Exhumed: Ensure automap uses untouched interpolated actor position. * Using chase cam while the automap was on was drawing the player sprite incorrectly. --- source/games/exhumed/src/view.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/games/exhumed/src/view.cpp b/source/games/exhumed/src/view.cpp index 7ce9fcc10..0aa842aa7 100644 --- a/source/games/exhumed/src/view.cpp +++ b/source/games/exhumed/src/view.cpp @@ -250,6 +250,8 @@ void DrawView(double interpfrac, bool sceneonly) } } + const auto ampos = nCamerapos.XY(); + if (nSnakeCam >= 0 && !sceneonly) { nCameraangles.Pitch = nullAngle; @@ -379,7 +381,7 @@ void DrawView(double interpfrac, bool sceneonly) } } - DrawMap(nCamerapos.XY(), nCameraangles.Yaw, interpfrac); + DrawMap(ampos, nCameraangles.Yaw, interpfrac); } } else From d3293281918dc02b6ff31d097f69ce2fb54fad50 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Fri, 17 Mar 2023 14:20:36 +1100 Subject: [PATCH 32/67] - Rename `PlayerAngles::RenderAngles` to `CameraAngles`. * Better conveys what it is and separates it from the already established `getRender*()` methods around the place. * Sorry Simon! --- source/core/gameinput.cpp | 2 +- source/core/gameinput.h | 16 ++++++++-------- source/games/blood/src/blood.cpp | 2 +- source/games/blood/src/controls.cpp | 4 ++-- source/games/blood/src/view.cpp | 2 +- source/games/duke/src/game_misc.cpp | 2 +- source/games/duke/src/gameloop.cpp | 2 +- source/games/duke/src/input.cpp | 4 ++-- source/games/duke/src/render.cpp | 2 +- source/games/exhumed/src/exhumed.cpp | 2 +- source/games/exhumed/src/input.cpp | 4 ++-- source/games/exhumed/src/view.cpp | 2 +- source/games/sw/src/draw.cpp | 6 +++--- source/games/sw/src/input.cpp | 8 ++++---- source/games/sw/src/player.cpp | 2 +- 15 files changed, 30 insertions(+), 30 deletions(-) diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index f96ac64db..170233cd2 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -324,7 +324,7 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngles& w, P if (arc.isReading()) { - w.resetRenderAngles(); + w.resetCameraAngles(); } } return arc; diff --git a/source/core/gameinput.h b/source/core/gameinput.h index 8a5cdc605..e58c553f7 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -9,7 +9,7 @@ struct PlayerAngles DRotator PrevViewAngles, ViewAngles; // Player camera angles, not for direct manipulation within the playsim. - DRotator RenderAngles; + DRotator CameraAngles; // Holder of current yaw spin state for the 180 degree turn. DAngle YawSpin; @@ -25,7 +25,7 @@ struct PlayerAngles // General methods. void initialize(DCoreActor* const actor, const DAngle viewyaw = nullAngle) { - if (pActor = actor) RenderAngles = PrevLerpAngles = pActor->spr.Angles; + if (pActor = actor) CameraAngles = PrevLerpAngles = pActor->spr.Angles; PrevViewAngles.Yaw = ViewAngles.Yaw = viewyaw; } DAngle getPitchWithView() @@ -37,22 +37,22 @@ struct PlayerAngles DRotator getRenderAngles(const double interpfrac) { // Get angles and return with clamped off pitch. - auto angles = RenderAngles + interpolatedvalue(PrevViewAngles, ViewAngles, interpfrac); + auto angles = CameraAngles + interpolatedvalue(PrevViewAngles, ViewAngles, interpfrac); angles.Pitch = ClampViewPitch(angles.Pitch); return angles; } - void updateRenderAngles(const double interpfrac) + void updateCameraAngles(const double interpfrac) { // Apply the current interpolated angle state to the render angles. const auto lerpAngles = interpolatedvalue(pActor->PrevAngles, pActor->spr.Angles, interpfrac); - RenderAngles += lerpAngles - PrevLerpAngles; + CameraAngles += lerpAngles - PrevLerpAngles; PrevLerpAngles = lerpAngles; } - void resetRenderAngles() + void resetCameraAngles() { // Apply any last remaining ticrate angle updates and reset variables. - RenderAngles += pActor->spr.Angles - PrevLerpAngles; - PrevLerpAngles = pActor->spr.Angles = RenderAngles; + CameraAngles += pActor->spr.Angles - PrevLerpAngles; + PrevLerpAngles = pActor->spr.Angles = CameraAngles; PrevViewAngles = ViewAngles; } diff --git a/source/games/blood/src/blood.cpp b/source/games/blood/src/blood.cpp index c0ca75a03..266e6cc47 100644 --- a/source/games/blood/src/blood.cpp +++ b/source/games/blood/src/blood.cpp @@ -438,7 +438,7 @@ void GameInterface::Ticker() PLAYER* pPlayer = &gPlayer[myconnectindex]; // this must be done before the view is backed up. - pPlayer->Angles.resetRenderAngles(); + pPlayer->Angles.resetCameraAngles(); // disable synchronised input if set by game. resetForcedSyncInput(); diff --git a/source/games/blood/src/controls.cpp b/source/games/blood/src/controls.cpp index f28dfde8a..5829e7eb3 100644 --- a/source/games/blood/src/controls.cpp +++ b/source/games/blood/src/controls.cpp @@ -57,8 +57,8 @@ void GameInterface::GetInput(ControlInfo* const hidInput, double const scaleAdju // Perform unsynchronised angle/horizon if not dead. if (!SyncInput() && gamestate == GS_LEVEL && pPlayer->actor->xspr.health != 0) { - pPlayer->Angles.RenderAngles.Yaw += DAngle::fromDeg(input.avel); - pPlayer->Angles.RenderAngles.Pitch += DAngle::fromDeg(input.horz); + pPlayer->Angles.CameraAngles.Yaw += DAngle::fromDeg(input.avel); + pPlayer->Angles.CameraAngles.Pitch += DAngle::fromDeg(input.horz); } if (packet) diff --git a/source/games/blood/src/view.cpp b/source/games/blood/src/view.cpp index 6cfe0a881..bf7ce28cd 100644 --- a/source/games/blood/src/view.cpp +++ b/source/games/blood/src/view.cpp @@ -582,7 +582,7 @@ void viewDrawScreen(bool sceneonly) else interpfrac = 1.; // update render angles. - pPlayer->Angles.updateRenderAngles(interpfrac); + pPlayer->Angles.updateCameraAngles(interpfrac); if (cl_interpolate) { diff --git a/source/games/duke/src/game_misc.cpp b/source/games/duke/src/game_misc.cpp index 3e86a78e2..eca805b6e 100644 --- a/source/games/duke/src/game_misc.cpp +++ b/source/games/duke/src/game_misc.cpp @@ -426,7 +426,7 @@ bool GameInterface::DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos, double j = clamp(czoom * act->spr.scale.Y + abs(pp.truefz - act->getOffsetZ()) * REPEAT_SCALE, (1. / 3.), 2.); auto const vec = OutAutomapVector(mxy - cpos, cangvect, czoom, xydim); - auto const daang = -(pp.Angles.RenderAngles.Yaw - cang).Normalized360().Degrees(); + auto const daang = -(pp.Angles.CameraAngles.Yaw - cang).Normalized360().Degrees(); DrawTexture(twod, tileGetTexture(i), vec.X, vec.Y, DTA_TranslationIndex, TRANSLATION(Translation_Remap + setpal(&pp), act->spr.pal), DTA_CenterOffset, true, DTA_Rotate, daang, DTA_Color, shadeToLight(act->spr.shade), DTA_ScaleX, j, DTA_ScaleY, j, TAG_DONE); diff --git a/source/games/duke/src/gameloop.cpp b/source/games/duke/src/gameloop.cpp index b53f266fb..a4f9f80e1 100644 --- a/source/games/duke/src/gameloop.cpp +++ b/source/games/duke/src/gameloop.cpp @@ -70,7 +70,7 @@ void GameInterface::Ticker() everyothertime++; // this must be done before the view is backed up. - ps[myconnectindex].Angles.resetRenderAngles(); + ps[myconnectindex].Angles.resetCameraAngles(); // disable synchronised input if set by game. resetForcedSyncInput(); diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 32c9b7dab..b2b4970c4 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -830,8 +830,8 @@ void GameInterface::GetInput(ControlInfo* const hidInput, double const scaleAdju if (!SyncInput() && p->GetActor()->spr.extra > 0) { - p->Angles.RenderAngles.Yaw += p->adjustavel(input.avel); - p->Angles.RenderAngles.Pitch += DAngle::fromDeg(input.horz); + p->Angles.CameraAngles.Yaw += p->adjustavel(input.avel); + p->Angles.CameraAngles.Pitch += DAngle::fromDeg(input.horz); } if (packet) diff --git a/source/games/duke/src/render.cpp b/source/games/duke/src/render.cpp index d27992e9b..19a40d524 100644 --- a/source/games/duke/src/render.cpp +++ b/source/games/duke/src/render.cpp @@ -221,7 +221,7 @@ void displayrooms(int snum, double interpfrac, bool sceneonly) player_struct* p = &ps[snum]; // update render angles. - p->Angles.updateRenderAngles(interpfrac); + p->Angles.updateCameraAngles(interpfrac); if (automapMode == am_full || !p->insector()) return; diff --git a/source/games/exhumed/src/exhumed.cpp b/source/games/exhumed/src/exhumed.cpp index 1a7025224..60c5e60e0 100644 --- a/source/games/exhumed/src/exhumed.cpp +++ b/source/games/exhumed/src/exhumed.cpp @@ -368,7 +368,7 @@ void GameInterface::Ticker() else if (EndLevel == 0) { // this must be done before the view is backed up. - PlayerList[nLocalPlayer].Angles.resetRenderAngles(); + PlayerList[nLocalPlayer].Angles.resetCameraAngles(); UpdatePlayerSpriteAngle(&PlayerList[nLocalPlayer]); // disable synchronised input if set by game. diff --git a/source/games/exhumed/src/input.cpp b/source/games/exhumed/src/input.cpp index f227503dd..461c08d59 100644 --- a/source/games/exhumed/src/input.cpp +++ b/source/games/exhumed/src/input.cpp @@ -75,8 +75,8 @@ void GameInterface::GetInput(ControlInfo* const hidInput, double const scaleAdju if (!SyncInput() && gamestate == GS_LEVEL && !nFreeze) { - pPlayer->Angles.RenderAngles.Yaw += DAngle::fromDeg(input.avel); - pPlayer->Angles.RenderAngles.Pitch += DAngle::fromDeg(input.horz); + pPlayer->Angles.CameraAngles.Yaw += DAngle::fromDeg(input.avel); + pPlayer->Angles.CameraAngles.Pitch += DAngle::fromDeg(input.horz); if (input.horz) { diff --git a/source/games/exhumed/src/view.cpp b/source/games/exhumed/src/view.cpp index 0aa842aa7..835a82400 100644 --- a/source/games/exhumed/src/view.cpp +++ b/source/games/exhumed/src/view.cpp @@ -203,7 +203,7 @@ void DrawView(double interpfrac, bool sceneonly) auto nDoppleOldCstat = pDop->spr.cstat; // update render angles. - pPlayer->Angles.updateRenderAngles(interpfrac); + pPlayer->Angles.updateCameraAngles(interpfrac); UpdatePlayerSpriteAngle(pPlayer); if (nSnakeCam >= 0 && !sceneonly) diff --git a/source/games/sw/src/draw.cpp b/source/games/sw/src/draw.cpp index a61514e45..5f9898b00 100644 --- a/source/games/sw/src/draw.cpp +++ b/source/games/sw/src/draw.cpp @@ -803,7 +803,7 @@ static void analyzesprites(tspriteArray& tsprites, const DVector3& viewpos, doub } tsp->pos = pos; - tsp->Angles.Yaw = pp->Angles.RenderAngles.Yaw; + tsp->Angles.Yaw = pp->Angles.CameraAngles.Yaw; //continue; } else @@ -1242,7 +1242,7 @@ void drawscreen(PLAYER* pp, double interpfrac, bool sceneonly) } // update render angles. - pp->Angles.updateRenderAngles(interpfrac); + pp->Angles.updateCameraAngles(interpfrac); // Get initial player position, interpolating if required. DVector3 tpos = camerapp->actor->getRenderPos(interpfrac); @@ -1458,7 +1458,7 @@ bool GameInterface::DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos, if (spnum >= 0) { - const auto daang = -(pp->Angles.RenderAngles.Yaw - cang).Normalized360().Degrees(); + const auto daang = -(pp->Angles.CameraAngles.Yaw - cang).Normalized360().Degrees(); auto vect = OutAutomapVector(mxy - cpos, cangvect, czoom, xydim); // This repeat scale is correct. diff --git a/source/games/sw/src/input.cpp b/source/games/sw/src/input.cpp index b1516e375..0b7e69ccc 100644 --- a/source/games/sw/src/input.cpp +++ b/source/games/sw/src/input.cpp @@ -180,22 +180,22 @@ void GameInterface::GetInput(ControlInfo* const hidInput, double const scaleAdju { if ((pp->Flags2 & PF2_INPUT_CAN_AIM)) { - pp->Angles.RenderAngles.Pitch += DAngle::fromDeg(input.horz); + pp->Angles.CameraAngles.Pitch += DAngle::fromDeg(input.horz); } if ((pp->Flags2 & PF2_INPUT_CAN_TURN_GENERAL)) { - pp->Angles.RenderAngles.Yaw += DAngle::fromDeg(input.avel); + pp->Angles.CameraAngles.Yaw += DAngle::fromDeg(input.avel); } if ((pp->Flags2 & PF2_INPUT_CAN_TURN_VEHICLE)) { - DoPlayerTurnVehicle(pp, pp->Angles.RenderAngles.Yaw, input.avel, pp->actor->getOffsetZ() + 10, abs(pp->actor->getOffsetZ() + 10 - pp->sop->floor_loz)); + DoPlayerTurnVehicle(pp, pp->Angles.CameraAngles.Yaw, input.avel, pp->actor->getOffsetZ() + 10, abs(pp->actor->getOffsetZ() + 10 - pp->sop->floor_loz)); } if ((pp->Flags2 & PF2_INPUT_CAN_TURN_TURRET)) { - DoPlayerTurnTurret(pp, pp->Angles.RenderAngles.Yaw, input.avel); + DoPlayerTurnTurret(pp, pp->Angles.CameraAngles.Yaw, input.avel); } } diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index ab1ae57cc..26c5e2813 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -6705,7 +6705,7 @@ void MoveSkipSavePos(void) MoveSkip2 ^= 1; // this must be done before the view is backed up. - Player[myconnectindex].Angles.resetRenderAngles(); + Player[myconnectindex].Angles.resetCameraAngles(); // Save off player TRAVERSE_CONNECT(pnum) From 130c5315e97aac666b4c42c9895589f0f24d310f Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Fri, 17 Mar 2023 14:40:18 +1100 Subject: [PATCH 33/67] - Call `PlayerAngles::resetCameraAngles()` from within the player loop of each game. * I was only thinking of the console player initially but since each game can draw the view of other players in network games, each game will need to update and reset the camera angles for all players. --- source/games/blood/src/blood.cpp | 4 +--- source/games/duke/src/gameloop.cpp | 5 ++++- source/games/sw/src/player.cpp | 4 +--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/source/games/blood/src/blood.cpp b/source/games/blood/src/blood.cpp index 266e6cc47..086f589e8 100644 --- a/source/games/blood/src/blood.cpp +++ b/source/games/blood/src/blood.cpp @@ -437,14 +437,12 @@ void GameInterface::Ticker() PLAYER* pPlayer = &gPlayer[myconnectindex]; - // this must be done before the view is backed up. - pPlayer->Angles.resetCameraAngles(); - // disable synchronised input if set by game. resetForcedSyncInput(); for (int i = connecthead; i >= 0; i = connectpoint2[i]) { + gPlayer[i].Angles.resetCameraAngles(); viewBackupView(i); playerProcess(&gPlayer[i]); } diff --git a/source/games/duke/src/gameloop.cpp b/source/games/duke/src/gameloop.cpp index a4f9f80e1..881b71a86 100644 --- a/source/games/duke/src/gameloop.cpp +++ b/source/games/duke/src/gameloop.cpp @@ -70,7 +70,10 @@ void GameInterface::Ticker() everyothertime++; // this must be done before the view is backed up. - ps[myconnectindex].Angles.resetCameraAngles(); + for (int i = connecthead; i >= 0; i = connectpoint2[i]) + { + ps[i].Angles.resetCameraAngles(); + } // disable synchronised input if set by game. resetForcedSyncInput(); diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index 26c5e2813..a391e64a5 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -6704,14 +6704,12 @@ void MoveSkipSavePos(void) MoveSkip4 = (MoveSkip4 + 1) & 3; MoveSkip2 ^= 1; - // this must be done before the view is backed up. - Player[myconnectindex].Angles.resetCameraAngles(); - // Save off player TRAVERSE_CONNECT(pnum) { pp = Player + pnum; + pp->Angles.resetCameraAngles(); pp->actor->backuploc(); pp->obob_z = pp->bob_z; pp->opbob_amt = pp->pbob_amt; From e6cffbaefbe07f98edb1aea2832dcb909607a9a9 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Fri, 17 Mar 2023 14:41:17 +1100 Subject: [PATCH 34/67] - Duke: Remove unnecessary `playrunning()` test within a loop. --- source/games/duke/src/gameloop.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/source/games/duke/src/gameloop.cpp b/source/games/duke/src/gameloop.cpp index 881b71a86..3159c64e3 100644 --- a/source/games/duke/src/gameloop.cpp +++ b/source/games/duke/src/gameloop.cpp @@ -90,17 +90,14 @@ void GameInterface::Ticker() for (int i = connecthead; i >= 0; i = connectpoint2[i]) { - if (playrunning()) - { - auto p = &ps[i]; - if (p->pals.a > 0) - p->pals.a--; + auto p = &ps[i]; + if (p->pals.a > 0) + p->pals.a--; - hud_input(i); - processinputvel(i); - fi.processinput(i); - fi.checksectors(i); - } + hud_input(i); + processinputvel(i); + fi.processinput(i); + fi.checksectors(i); } fi.think(); From 3c4b4e448330097b743f86776fe5736d24a49c94 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Fri, 17 Mar 2023 17:28:04 +1100 Subject: [PATCH 35/67] - Tidy up `warptocoords` CCMD since everything is in an actor now. * Now accepts floating point inputs. * Restores lost pitch capability. --- source/core/gamestruct.h | 2 +- source/core/inputstate.cpp | 22 ++++++++-------------- source/games/blood/src/blood.h | 2 +- source/games/blood/src/osdcmd.cpp | 13 ++----------- source/games/duke/src/ccmds.cpp | 15 ++------------- source/games/duke/src/duke3d.h | 2 +- source/games/exhumed/src/exhumed.h | 2 +- source/games/exhumed/src/osdcmds.cpp | 12 ++---------- source/games/sw/src/game.h | 2 +- source/games/sw/src/osdcmds.cpp | 16 ++-------------- 10 files changed, 21 insertions(+), 67 deletions(-) diff --git a/source/core/gamestruct.h b/source/core/gamestruct.h index a271bcd99..cf99196e5 100644 --- a/source/core/gamestruct.h +++ b/source/core/gamestruct.h @@ -105,7 +105,7 @@ struct GameInterface virtual bool DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos, const DAngle cang, const DVector2& xydim, const double czoom, double const interpfrac) { return false; } virtual DAngle playerPitchMin() { return DAngle::fromDeg(57.375); } virtual DAngle playerPitchMax() { return DAngle::fromDeg(-57.375); } - virtual void WarpToCoords(double x, double y, double z, DAngle a) {} + virtual DCoreActor* getConsoleActor() = 0; virtual void ToggleThirdPerson() { } virtual void SwitchCoopView() { Printf("Unsupported command\n"); } virtual void ToggleShowWeapon() { Printf("Unsupported command\n"); } diff --git a/source/core/inputstate.cpp b/source/core/inputstate.cpp index aa55b505d..e340ada4b 100644 --- a/source/core/inputstate.cpp +++ b/source/core/inputstate.cpp @@ -365,7 +365,7 @@ CCMD(warptocoords) } if (argv.argc() < 4) { - Printf("warptocoords [x] [y] [z] [ang] (optional) [horiz] (optional): warps the player to the specified coordinates\n"); + Printf("warptocoords [x] [y] [z] [yaw] (optional) [pitch] (optional): warps the player to the specified coordinates\n"); return; } if (gamestate != GS_LEVEL) @@ -373,20 +373,14 @@ CCMD(warptocoords) Printf("warptocoords: must be in a level\n"); return; } - int x = atoi(argv[1]); - int y = atoi(argv[2]); - int z = atoi(argv[3]); - int ang = INT_MIN, horiz = INT_MIN; - if (argv.argc() > 4) - { - ang = atoi(argv[4]); - } - if (argv.argc() > 5) - { - horiz = atoi(argv[5]); - } - gi->WarpToCoords(x, y, z, DAngle::fromDeg(ang)); + if (const auto pActor = gi->getConsoleActor()) + { + pActor->spr.pos = DVector3(atof(argv[1]), atof(argv[2]), atof(argv[3])); + if (argv.argc() > 4) pActor->spr.Angles.Yaw = DAngle::fromDeg(atof(argv[4])); + if (argv.argc() > 5) pActor->spr.Angles.Pitch = DAngle::fromDeg(atof(argv[5])); + pActor->backuploc(); + } } CCMD(third_person_view) diff --git a/source/games/blood/src/blood.h b/source/games/blood/src/blood.h index c69363ee8..5fcde103f 100644 --- a/source/games/blood/src/blood.h +++ b/source/games/blood/src/blood.h @@ -133,7 +133,7 @@ struct GameInterface : public ::GameInterface bool DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos, const DAngle cang, const DVector2& xydim, const double czoom, double const interpfrac) override; DAngle playerPitchMin() override { return DAngle::fromDeg(54.575); } DAngle playerPitchMax() override { return DAngle::fromDeg(-43.15); } - void WarpToCoords(double x, double y, double z, DAngle a) override; + DCoreActor* getConsoleActor() override; void ToggleThirdPerson() override; void SwitchCoopView() override; void ToggleShowWeapon() override; diff --git a/source/games/blood/src/osdcmd.cpp b/source/games/blood/src/osdcmd.cpp index e9856a38a..9ecf2429a 100644 --- a/source/games/blood/src/osdcmd.cpp +++ b/source/games/blood/src/osdcmd.cpp @@ -31,18 +31,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. BEGIN_BLD_NS -void GameInterface::WarpToCoords(double x, double y, double z, DAngle ang) +DCoreActor* GameInterface::getConsoleActor() { - PLAYER* pPlayer = &gPlayer[myconnectindex]; - - pPlayer->actor->spr.pos = { x, y, z }; - playerResetInertia(pPlayer); - - if (ang != DAngle::fromDeg(INT_MIN)) - { - pPlayer->actor->spr.Angles.Yaw = ang; - pPlayer->actor->backupang(); - } + return gPlayer[myconnectindex].actor; } void GameInterface::ToggleThirdPerson() diff --git a/source/games/duke/src/ccmds.cpp b/source/games/duke/src/ccmds.cpp index 3b495465e..0cbfc875c 100644 --- a/source/games/duke/src/ccmds.cpp +++ b/source/games/duke/src/ccmds.cpp @@ -118,20 +118,9 @@ static int ccmd_spawn(CCmdFuncPtr parm) return CCMD_OK; } -void GameInterface::WarpToCoords(double x, double y, double z, DAngle ang) +DCoreActor* GameInterface::getConsoleActor() { - player_struct* p = &ps[myconnectindex]; - auto pActor = p->GetActor(); - - if (!pActor) return; - - pActor->spr.pos = DVector3(x, y, z); - pActor->backuppos(); - - if (ang != DAngle::fromDeg(INT_MIN)) - { - p->GetActor()->PrevAngles.Yaw = p->GetActor()->spr.Angles.Yaw = ang; - } + return ps[myconnectindex].GetActor(); } void GameInterface::ToggleThirdPerson() diff --git a/source/games/duke/src/duke3d.h b/source/games/duke/src/duke3d.h index 0f1eb44d8..e472ab0a5 100644 --- a/source/games/duke/src/duke3d.h +++ b/source/games/duke/src/duke3d.h @@ -51,7 +51,7 @@ struct GameInterface : public ::GameInterface void NewGame(MapRecord* map, int skill, bool) override; void LevelCompleted(MapRecord* map, int skill) override; bool DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos, const DAngle cang, const DVector2& xydim, const double czoom, double const interpfrac) override; - void WarpToCoords(double x, double y, double z, DAngle ang) override; + DCoreActor* getConsoleActor() override; void ToggleThirdPerson() override; void SwitchCoopView() override; void ToggleShowWeapon() override; diff --git a/source/games/exhumed/src/exhumed.h b/source/games/exhumed/src/exhumed.h index fd34ceb70..0670d4d90 100644 --- a/source/games/exhumed/src/exhumed.h +++ b/source/games/exhumed/src/exhumed.h @@ -234,7 +234,7 @@ struct GameInterface : public ::GameInterface bool DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos, const DAngle cang, const DVector2& xydim, const double czoom, double const interpfrac) override; DAngle playerPitchMin() override { return DAngle::fromDeg(49.5); } DAngle playerPitchMax() override { return DAngle::fromDeg(-49.5); } - void WarpToCoords(double x, double y, double z, DAngle ang) override; + DCoreActor* getConsoleActor() override; void ToggleThirdPerson() override; void processSprites(tspriteArray& tsprites, const DVector3& view, DAngle viewang, double interpfrac) override; int GetCurrentSkill() override; diff --git a/source/games/exhumed/src/osdcmds.cpp b/source/games/exhumed/src/osdcmds.cpp index 45a18fa47..3d795cf5c 100644 --- a/source/games/exhumed/src/osdcmds.cpp +++ b/source/games/exhumed/src/osdcmds.cpp @@ -39,17 +39,9 @@ BEGIN_PS_NS // //--------------------------------------------------------------------------- -void GameInterface::WarpToCoords(double x, double y, double z, DAngle ang) +DCoreActor* GameInterface::getConsoleActor() { - Player *nPlayer = &PlayerList[nLocalPlayer]; - - nPlayer->pActor->spr.pos = DVector3(x, y, z); - nPlayer->pActor->backuppos(); - - if (ang != DAngle::fromDeg(INT_MIN)) - { - nPlayer->pActor->PrevAngles.Yaw = nPlayer->pActor->spr.Angles.Yaw = ang; - } + return PlayerList[nLocalPlayer].pActor; } //--------------------------------------------------------------------------- diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index fff107c4d..50cc2e452 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -1694,7 +1694,7 @@ struct GameInterface : public ::GameInterface void NextLevel(MapRecord *map, int skill) override; void NewGame(MapRecord *map, int skill, bool) override; bool DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos, const DAngle cang, const DVector2& xydim, const double czoom, double const interpfrac) override; - void WarpToCoords(double x, double y, double z, DAngle ang) override; + DCoreActor* getConsoleActor() override; void ToggleThirdPerson() override; void SwitchCoopView() override; void processSprites(tspriteArray& tsprites, const DVector3& view, DAngle viewang, double smoothRatio) override; diff --git a/source/games/sw/src/osdcmds.cpp b/source/games/sw/src/osdcmds.cpp index e5ab2b8f5..e2720b157 100644 --- a/source/games/sw/src/osdcmds.cpp +++ b/source/games/sw/src/osdcmds.cpp @@ -54,21 +54,9 @@ BEGIN_SW_NS // //--------------------------------------------------------------------------- -void GameInterface::WarpToCoords(double x, double y, double z, DAngle ang) +DCoreActor* GameInterface::getConsoleActor() { - auto pp = &Player[myconnectindex]; - auto ppActor = pp->actor; - - if (!ppActor) return; - - ppActor->spr.pos = DVector3(x,y,z); - - if (ang != DAngle::fromDeg(INT_MIN)) - { - Player->actor->spr.Angles.Yaw = ang; - } - - ppActor->backuploc(); + return Player[myconnectindex].actor; } //--------------------------------------------------------------------------- From 81caf74721bf2ad5f48ad233131be7d515f5a401 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Fri, 17 Mar 2023 17:28:26 +1100 Subject: [PATCH 36/67] - Tidy up `coord` stat to use `gi->getConsoleActor()` and also print pitch. --- source/core/gamecvars.cpp | 13 +++++++------ source/core/gamestruct.h | 1 - source/games/blood/src/blood.h | 1 - source/games/blood/src/view.cpp | 7 ------- source/games/duke/src/duke3d.h | 1 - source/games/duke/src/game_misc.cpp | 7 ------- source/games/exhumed/src/exhumed.cpp | 7 ------- source/games/exhumed/src/exhumed.h | 1 - source/games/sw/src/draw.cpp | 13 ------------- source/games/sw/src/game.h | 1 - 10 files changed, 7 insertions(+), 45 deletions(-) diff --git a/source/core/gamecvars.cpp b/source/core/gamecvars.cpp index ff5aebe02..5e1b75d96 100644 --- a/source/core/gamecvars.cpp +++ b/source/core/gamecvars.cpp @@ -46,6 +46,7 @@ #include "quotemgr.h" #include "gamestruct.h" #include "statusbar.h" +#include "coreactor.h" CVARD(Bool, cl_crosshair, true, CVAR_ARCHIVE, "enable/disable crosshair"); CVARD(Bool, cl_automsg, false, CVAR_ARCHIVE, "enable/disable automatically sending messages to all players") // Not implemented for Blood @@ -235,14 +236,14 @@ ADD_STAT(fps) ADD_STAT(coord) { - auto coord = gi->GetCoordinates(); FString out; - if (coord.first.X < DBL_MAX) + if (const auto pActor = gi->getConsoleActor()) { - out.AppendFormat("X: %f ", coord.first.X); - out.AppendFormat("Y: %f ", coord.first.Y); - out.AppendFormat("Z: %f ", coord.first.Z); - out.AppendFormat("Angle: %f\n", coord.second.Degrees()); + out.AppendFormat("X: %.4f ", pActor->spr.pos.X); + out.AppendFormat("Y: %.4f ", pActor->spr.pos.Y); + out.AppendFormat("Z: %.4f ", pActor->spr.pos.Z); + out.AppendFormat("Yaw: %.4f ", pActor->spr.Angles.Yaw.Degrees()); + out.AppendFormat("Pitch: %.4f\n", pActor->spr.Angles.Pitch.Degrees()); } return out; } diff --git a/source/core/gamestruct.h b/source/core/gamestruct.h index cf99196e5..af0ee818d 100644 --- a/source/core/gamestruct.h +++ b/source/core/gamestruct.h @@ -87,7 +87,6 @@ struct GameInterface virtual void SerializeGameState(FSerializer& arc) {} virtual void DrawPlayerSprite(const DVector2& origin, bool onteam) {} virtual void SetAmbience(bool on) {} - virtual std::pair GetCoordinates() { return {}; } virtual void ExitFromMenu() { throw CExitEvent(0); } virtual void GetInput(ControlInfo* const hidInput, double const scaleAdjust, InputPacket* packet = nullptr) {} virtual void UpdateSounds() {} diff --git a/source/games/blood/src/blood.h b/source/games/blood/src/blood.h index 5fcde103f..070d6ee1b 100644 --- a/source/games/blood/src/blood.h +++ b/source/games/blood/src/blood.h @@ -119,7 +119,6 @@ struct GameInterface : public ::GameInterface void MenuOpened() override; void MenuClosed() override; bool CanSave() override; - std::pair GetCoordinates() override; void UpdateSounds() override; void GetInput(ControlInfo* const hidInput, double const scaleAdjust, InputPacket* packet = nullptr) override; void Ticker() override; diff --git a/source/games/blood/src/view.cpp b/source/games/blood/src/view.cpp index bf7ce28cd..456f5c022 100644 --- a/source/games/blood/src/view.cpp +++ b/source/games/blood/src/view.cpp @@ -774,13 +774,6 @@ bool GameInterface::GenerateSavePic() return true; } -std::pair GameInterface::GetCoordinates() -{ - PLAYER* pPlayer = &gPlayer[myconnectindex]; - if (!pPlayer->actor) return std::make_pair(DVector3(DBL_MAX, 0, 0), nullAngle); - return std::make_pair(pPlayer->actor->spr.pos, pPlayer->actor->spr.Angles.Yaw); -} - //--------------------------------------------------------------------------- // diff --git a/source/games/duke/src/duke3d.h b/source/games/duke/src/duke3d.h index e472ab0a5..7e0b60c5d 100644 --- a/source/games/duke/src/duke3d.h +++ b/source/games/duke/src/duke3d.h @@ -36,7 +36,6 @@ struct GameInterface : public ::GameInterface FSavegameInfo GetSaveSig() override; double SmallFontScale() override { return isRR() ? 0.5 : 1.; } void SerializeGameState(FSerializer& arc) override; - std::pair GetCoordinates() override; void ExitFromMenu() override; void DrawPlayerSprite(const DVector2& origin, bool onteam) override; void GetInput(ControlInfo* const hidInput, double const scaleAdjust, InputPacket* packet = nullptr) override; diff --git a/source/games/duke/src/game_misc.cpp b/source/games/duke/src/game_misc.cpp index eca805b6e..fe6dd8159 100644 --- a/source/games/duke/src/game_misc.cpp +++ b/source/games/duke/src/game_misc.cpp @@ -55,13 +55,6 @@ BEGIN_DUKE_NS // //--------------------------------------------------------------------------- -std::pair GameInterface::GetCoordinates() -{ - auto pActor = ps[screenpeek].GetActor(); - if (!pActor) return std::make_pair(DVector3(DBL_MAX, 0, 0), nullAngle); - return std::make_pair(pActor->spr.pos, pActor->spr.Angles.Yaw); -} - GameStats GameInterface::getStats() { player_struct* p = &ps[myconnectindex]; diff --git a/source/games/exhumed/src/exhumed.cpp b/source/games/exhumed/src/exhumed.cpp index 60c5e60e0..0bb0d9963 100644 --- a/source/games/exhumed/src/exhumed.cpp +++ b/source/games/exhumed/src/exhumed.cpp @@ -679,13 +679,6 @@ bool GameInterface::CanSave() return new GameInterface; } -std::pair GameInterface::GetCoordinates() -{ - auto pPlayerActor = PlayerList[nLocalPlayer].pActor; - if (!pPlayerActor) return std::make_pair(DVector3(DBL_MAX, 0, 0), nullAngle); - return std::make_pair(pPlayerActor->spr.pos, pPlayerActor->spr.Angles.Yaw); -} - //--------------------------------------------------------------------------- // diff --git a/source/games/exhumed/src/exhumed.h b/source/games/exhumed/src/exhumed.h index 0670d4d90..06960c93c 100644 --- a/source/games/exhumed/src/exhumed.h +++ b/source/games/exhumed/src/exhumed.h @@ -238,7 +238,6 @@ struct GameInterface : public ::GameInterface void ToggleThirdPerson() override; void processSprites(tspriteArray& tsprites, const DVector3& view, DAngle viewang, double interpfrac) override; int GetCurrentSkill() override; - std::pair GetCoordinates() override; void StartSoundEngine() override; ::GameStats getStats() override; diff --git a/source/games/sw/src/draw.cpp b/source/games/sw/src/draw.cpp index 5f9898b00..7d0ca917e 100644 --- a/source/games/sw/src/draw.cpp +++ b/source/games/sw/src/draw.cpp @@ -967,19 +967,6 @@ void post_analyzesprites(tspriteArray& tsprites) // //--------------------------------------------------------------------------- -std::pair GameInterface::GetCoordinates() -{ - auto ppActor = Player[myconnectindex].actor; - if (!ppActor) return std::make_pair(DVector3(DBL_MAX, 0, 0), nullAngle); - return std::make_pair(ppActor->spr.pos, ppActor->spr.Angles.Yaw); -} - -//--------------------------------------------------------------------------- -// -// -// -//--------------------------------------------------------------------------- - void PrintSpriteInfo(PLAYER* pp) { const int Y_STEP = 7; diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index 50cc2e452..3e37d9fe8 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -1679,7 +1679,6 @@ struct GameInterface : public ::GameInterface FSavegameInfo GetSaveSig() override; void SerializeGameState(FSerializer& arc); void SetAmbience(bool on) override { if (on) StartAmbientSound(); else StopAmbientSound(); } - std::pair GetCoordinates() override; void UpdateSounds() override; void ErrorCleanup() override; void GetInput(ControlInfo* const hidInput, double const scaleAdjust, InputPacket* input = nullptr) override; From 7f79ee9801d42f8df251c942691d6510a63feb94 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Fri, 17 Mar 2023 19:17:18 +1100 Subject: [PATCH 37/67] - Exhumed: Repair missing negation affecting death sequence. * Pitch negation strike's back! --- source/games/exhumed/src/player.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/games/exhumed/src/player.cpp b/source/games/exhumed/src/player.cpp index 1bf4923d2..442a17a96 100644 --- a/source/games/exhumed/src/player.cpp +++ b/source/games/exhumed/src/player.cpp @@ -2623,7 +2623,7 @@ sectdone: { PlayerList[nPlayer].pActor->spr.Angles.Pitch -= maphoriz(dVertPan[nPlayer]); - if (PlayerList[nPlayer].pActor->spr.Angles.Pitch.Degrees() <= 38) + if (PlayerList[nPlayer].pActor->spr.Angles.Pitch.Degrees() <= -38) { PlayerList[nPlayer].pActor->spr.Angles.Pitch = DAngle::fromDeg(-37.72); } From 686bec566472ad2872e2d90a7710995a80d9e4cc Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Fri, 17 Mar 2023 19:40:36 +1100 Subject: [PATCH 38/67] - Duke: Make vehicle input functions work on floats and not doubles and FAngles. * It's what's natively needed at the end of the day. --- source/games/duke/src/input.cpp | 35 +++++++++++++++++---------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index b2b4970c4..d6508ff76 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -513,9 +513,10 @@ enum enum { MAXVELMOTO = 120, - VEHICLETURN = 20 }; +static constexpr float VEHICLETURN = (20.f * 360.f / 2048.f); + //--------------------------------------------------------------------------- // // handles the input bits @@ -554,9 +555,9 @@ static void processInputBits(player_struct *p, ControlInfo* const hidInput) // //--------------------------------------------------------------------------- -static FAngle motoApplyTurn(player_struct* p, ControlInfo* const hidInput, bool const kbdLeft, bool const kbdRight, double const factor) +static float motoApplyTurn(player_struct* p, ControlInfo* const hidInput, bool const kbdLeft, bool const kbdRight, const float factor) { - double turnvel = 0; + float turnvel = 0; p->oTiltStatus = p->TiltStatus; if (p->MotoSpeed == 0 || !p->on_ground) @@ -580,8 +581,8 @@ static FAngle motoApplyTurn(player_struct* p, ControlInfo* const hidInput, bool { if (kbdLeft || kbdRight || p->moto_drink || hidInput->mouseturnx || hidInput->dyaw) { - double const velScale = 3. / 10; - auto const baseVel = (buttonMap.ButtonDown(gamefunc_Move_Backward) || hidInput->dz < 0) && p->MotoSpeed <= 0 ? -VEHICLETURN : VEHICLETURN; + constexpr float velScale = (3.f / 10.f); + const float baseVel = (buttonMap.ButtonDown(gamefunc_Move_Backward) || hidInput->dz < 0) && p->MotoSpeed <= 0 ? -VEHICLETURN : VEHICLETURN; if (kbdLeft || p->moto_drink < 0 || hidInput->mouseturnx < 0 || hidInput->dyaw < 0) { @@ -594,7 +595,7 @@ static FAngle motoApplyTurn(player_struct* p, ControlInfo* const hidInput, bool turnvel -= isTurboTurnTime() && p->MotoSpeed > 0 ? baseVel : baseVel * velScale; if (hidInput->mouseturnx < 0) - turnvel -= Sgn(baseVel) * sqrt((p->MotoSpeed > 0 ? abs(baseVel) : abs(baseVel) * velScale) * -(hidInput->mouseturnx / factor) * 2.); + turnvel -= Sgn(baseVel) * sqrtf(abs(p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * -(hidInput->mouseturnx / factor) * (7.f / 20.f)); if (hidInput->dyaw < 0) turnvel += (p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * hidInput->dyaw; @@ -613,7 +614,7 @@ static FAngle motoApplyTurn(player_struct* p, ControlInfo* const hidInput, bool turnvel += isTurboTurnTime() && p->MotoSpeed > 0 ? baseVel : baseVel * velScale; if (hidInput->mouseturnx > 0) - turnvel += Sgn(baseVel) * sqrt((p->MotoSpeed > 0 ? abs(baseVel) : abs(baseVel) * velScale) * (hidInput->mouseturnx / factor) * 2.); + turnvel += Sgn(baseVel) * sqrtf(abs(p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * (hidInput->mouseturnx / factor) * (7.f / 20.f)); if (hidInput->dyaw > 0) turnvel += (p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * hidInput->dyaw; @@ -635,7 +636,7 @@ static FAngle motoApplyTurn(player_struct* p, ControlInfo* const hidInput, bool if (fabs(p->TiltStatus) < factor) p->TiltStatus = 0; - return FAngle::fromBuild(turnvel * factor); + return turnvel * factor; } //--------------------------------------------------------------------------- @@ -644,17 +645,17 @@ static FAngle motoApplyTurn(player_struct* p, ControlInfo* const hidInput, bool // //--------------------------------------------------------------------------- -static FAngle boatApplyTurn(player_struct *p, ControlInfo* const hidInput, bool const kbdLeft, bool const kbdRight, double const factor) +static float boatApplyTurn(player_struct *p, ControlInfo* const hidInput, bool const kbdLeft, bool const kbdRight, const float factor) { - double turnvel = 0; + float turnvel = 0; p->oTiltStatus = p->TiltStatus; if (p->MotoSpeed) { if (kbdLeft || kbdRight || p->moto_drink || hidInput->mouseturnx || hidInput->dyaw) { - double const velScale = !p->NotOnWater? 1. : 6. / 19.; - auto const baseVel = +VEHICLETURN * velScale; + const float velScale = !p->NotOnWater? 1.f : (6.f / 19.f); + const float baseVel = VEHICLETURN * velScale; if (kbdLeft || p->moto_drink < 0 || hidInput->mouseturnx < 0 || hidInput->dyaw < 0) { @@ -669,7 +670,7 @@ static FAngle boatApplyTurn(player_struct *p, ControlInfo* const hidInput, bool turnvel -= isTurboTurnTime() ? baseVel : baseVel * velScale; if (hidInput->mouseturnx < 0) - turnvel -= Sgn(baseVel) * sqrt(abs(baseVel) * -(hidInput->mouseturnx / factor) * 2.); + turnvel -= Sgn(baseVel) * sqrtf(abs(baseVel) * -(hidInput->mouseturnx / factor) * (7.f / 20.f)); if (hidInput->dyaw < 0) turnvel += baseVel * hidInput->dyaw; @@ -690,7 +691,7 @@ static FAngle boatApplyTurn(player_struct *p, ControlInfo* const hidInput, bool turnvel += isTurboTurnTime() ? baseVel : baseVel * velScale; if (hidInput->mouseturnx > 0) - turnvel += Sgn(baseVel) * sqrt(abs(baseVel) * (hidInput->mouseturnx / factor) * 2.); + turnvel += Sgn(baseVel) * sqrtf(abs(baseVel) * (hidInput->mouseturnx / factor) * (7.f / 20.f)); if (hidInput->dyaw > 0) turnvel += baseVel * hidInput->dyaw; @@ -721,7 +722,7 @@ static FAngle boatApplyTurn(player_struct *p, ControlInfo* const hidInput, bool if (fabs(p->TiltStatus) < factor) p->TiltStatus = 0; - return FAngle::fromBuild(turnvel * factor); + return turnvel * factor; } //--------------------------------------------------------------------------- @@ -750,12 +751,12 @@ static void processVehicleInput(player_struct *p, ControlInfo* const hidInput, I if (p->OnMotorcycle) { - input.avel = motoApplyTurn(p, hidInput, kbdLeft, kbdRight, scaleAdjust).Degrees(); + input.avel = motoApplyTurn(p, hidInput, kbdLeft, kbdRight, (float)scaleAdjust); if (p->moto_underwater) p->MotoSpeed = 0; } else { - input.avel = boatApplyTurn(p, hidInput, kbdLeft, kbdRight, scaleAdjust).Degrees(); + input.avel = boatApplyTurn(p, hidInput, kbdLeft, kbdRight, (float)scaleAdjust); } loc.fvel = clamp((float)p->MotoSpeed, -(MAXVELMOTO >> 3), MAXVELMOTO) * (1.f / 40.f); From 1f97e73501955dc5f692ab00d1bc438c8402113f Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Fri, 17 Mar 2023 20:16:58 +1100 Subject: [PATCH 39/67] - Rename ControlInfo joystick variables to names matching backend. --- source/core/gameinput.cpp | 4 ++-- source/core/inputstate.cpp | 22 +++++++++++----------- source/core/inputstate.h | 6 +++--- source/games/duke/src/input.cpp | 6 +++--- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index 170233cd2..9cd87b092 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -119,8 +119,8 @@ void processMovement(InputPacket* const currInput, InputPacket* const inputBuffe // determine player input. const auto turning = buttonMap.ButtonDown(gamefunc_Turn_Right) - buttonMap.ButtonDown(gamefunc_Turn_Left); - const auto moving = buttonMap.ButtonDown(gamefunc_Move_Forward) - buttonMap.ButtonDown(gamefunc_Move_Backward) + hidInput->dz * scaleAdjustf; - const auto strafing = buttonMap.ButtonDown(gamefunc_Strafe_Right) - buttonMap.ButtonDown(gamefunc_Strafe_Left) - hidInput->dx * scaleAdjustf; + const auto moving = buttonMap.ButtonDown(gamefunc_Move_Forward) - buttonMap.ButtonDown(gamefunc_Move_Backward) + hidInput->dforward * scaleAdjustf; + const auto strafing = buttonMap.ButtonDown(gamefunc_Strafe_Right) - buttonMap.ButtonDown(gamefunc_Strafe_Left) - hidInput->dside * scaleAdjustf; // process player angle input. if (!(buttonMap.ButtonDown(gamefunc_Strafe) && allowstrafe)) diff --git a/source/core/inputstate.cpp b/source/core/inputstate.cpp index e340ada4b..b548311fe 100644 --- a/source/core/inputstate.cpp +++ b/source/core/inputstate.cpp @@ -215,9 +215,9 @@ ControlInfo CONTROL_GetInput() I_GetAxes(joyaxes); hidInput.dyaw += -joyaxes[JOYAXIS_Yaw]; - hidInput.dx += joyaxes[JOYAXIS_Side] * .5f; - hidInput.dz += joyaxes[JOYAXIS_Forward] * .5f; hidInput.dpitch += -joyaxes[JOYAXIS_Pitch]; + hidInput.dforward += joyaxes[JOYAXIS_Forward] * .5f; + hidInput.dside += joyaxes[JOYAXIS_Side] * .5f; } return hidInput; @@ -405,18 +405,18 @@ void ApplyGlobalInput(InputPacket& input, ControlInfo* hidInput, bool const crou if (hidInput && buttonMap.ButtonDown(gamefunc_Dpad_Select)) { // These buttons should not autorepeat. The game handlers are not really equipped for that. - if (hidInput->dz > 0 && !(dpad_lock & 1)) { dpad_lock |= 1; input.setNewWeapon(WeaponSel_Prev); } + if (hidInput->dforward > 0 && !(dpad_lock & 1)) { dpad_lock |= 1; input.setNewWeapon(WeaponSel_Prev); } else dpad_lock &= ~1; - if (hidInput->dz < 0 && !(dpad_lock & 2)) { dpad_lock |= 2; input.setNewWeapon(WeaponSel_Next); } + if (hidInput->dforward < 0 && !(dpad_lock & 2)) { dpad_lock |= 2; input.setNewWeapon(WeaponSel_Next); } else dpad_lock &= ~2; - if ((hidInput->dx < 0 || hidInput->dyaw < 0) && !(dpad_lock & 4)) { dpad_lock |= 4; input.actions |= SB_INVPREV; } + if ((hidInput->dside < 0 || hidInput->dyaw < 0) && !(dpad_lock & 4)) { dpad_lock |= 4; input.actions |= SB_INVPREV; } else dpad_lock &= ~4; - if ((hidInput->dx > 0 || hidInput->dyaw > 0) && !(dpad_lock & 8)) { dpad_lock |= 8; input.actions |= SB_INVNEXT; } + if ((hidInput->dside > 0 || hidInput->dyaw > 0) && !(dpad_lock & 8)) { dpad_lock |= 8; input.actions |= SB_INVNEXT; } else dpad_lock &= ~8; // This eats the controller input for regular use - hidInput->dx = 0; - hidInput->dz = 0; + hidInput->dside = 0; + hidInput->dforward = 0; hidInput->dyaw = 0; } else dpad_lock = 0; @@ -424,14 +424,14 @@ void ApplyGlobalInput(InputPacket& input, ControlInfo* hidInput, bool const crou input.actions |= ActionsToSend; ActionsToSend = 0; - if (buttonMap.ButtonDown(gamefunc_Aim_Up) || (buttonMap.ButtonDown(gamefunc_Dpad_Aiming) && hidInput->dz > 0)) + if (buttonMap.ButtonDown(gamefunc_Aim_Up) || (buttonMap.ButtonDown(gamefunc_Dpad_Aiming) && hidInput->dforward > 0)) input.actions |= SB_AIM_UP; - if ((buttonMap.ButtonDown(gamefunc_Aim_Down) || (buttonMap.ButtonDown(gamefunc_Dpad_Aiming) && hidInput->dz < 0))) + if ((buttonMap.ButtonDown(gamefunc_Aim_Down) || (buttonMap.ButtonDown(gamefunc_Dpad_Aiming) && hidInput->dforward < 0))) input.actions |= SB_AIM_DOWN; if (buttonMap.ButtonDown(gamefunc_Dpad_Aiming)) - hidInput->dz = 0; + hidInput->dforward = 0; if (buttonMap.ButtonDown(gamefunc_Jump)) input.actions |= SB_JUMP; diff --git a/source/core/inputstate.h b/source/core/inputstate.h index 4782fb79f..568acdf6c 100644 --- a/source/core/inputstate.h +++ b/source/core/inputstate.h @@ -16,9 +16,9 @@ struct ControlInfo { - float dx; - float dy; - float dz; + float dside; + float dup; + float dforward; float dyaw; float dpitch; float droll; diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index d6508ff76..758bbd27a 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -582,7 +582,7 @@ static float motoApplyTurn(player_struct* p, ControlInfo* const hidInput, bool c if (kbdLeft || kbdRight || p->moto_drink || hidInput->mouseturnx || hidInput->dyaw) { constexpr float velScale = (3.f / 10.f); - const float baseVel = (buttonMap.ButtonDown(gamefunc_Move_Backward) || hidInput->dz < 0) && p->MotoSpeed <= 0 ? -VEHICLETURN : VEHICLETURN; + const float baseVel = (buttonMap.ButtonDown(gamefunc_Move_Backward) || hidInput->dforward < 0) && p->MotoSpeed <= 0 ? -VEHICLETURN : VEHICLETURN; if (kbdLeft || p->moto_drink < 0 || hidInput->mouseturnx < 0 || hidInput->dyaw < 0) { @@ -744,8 +744,8 @@ static void processVehicleInput(player_struct *p, ControlInfo* const hidInput, I if (p->OnBoat || !p->moto_underwater) { - p->vehForwardScale = min((buttonMap.ButtonDown(gamefunc_Move_Forward) || buttonMap.ButtonDown(gamefunc_Strafe)) + hidInput->dz, 1.f); - p->vehReverseScale = min(buttonMap.ButtonDown(gamefunc_Move_Backward) + -hidInput->dz, 1.f); + p->vehForwardScale = min((buttonMap.ButtonDown(gamefunc_Move_Forward) || buttonMap.ButtonDown(gamefunc_Strafe)) + hidInput->dforward, 1.f); + p->vehReverseScale = min(buttonMap.ButtonDown(gamefunc_Move_Backward) + -hidInput->dforward, 1.f); p->vehBraking = buttonMap.ButtonDown(gamefunc_Run); } From 446218dd7b799e44a2255f55919c6b293b61a1b5 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Fri, 17 Mar 2023 20:58:11 +1100 Subject: [PATCH 40/67] - Get mouse/controller input by pointed variable and not copy on return. --- source/core/gameinput.cpp | 2 +- source/core/gameinput.h | 2 +- source/core/gamestruct.h | 2 +- source/core/inputstate.cpp | 20 ++++++++------------ source/core/inputstate.h | 8 ++++---- source/core/mainloop.cpp | 6 ++---- source/games/blood/src/blood.h | 2 +- source/games/blood/src/controls.cpp | 9 ++++++--- source/games/duke/src/duke3d.h | 2 +- source/games/duke/src/input.cpp | 19 +++++++++++-------- source/games/exhumed/src/exhumed.h | 2 +- source/games/exhumed/src/input.cpp | 9 ++++++--- source/games/sw/src/game.h | 2 +- source/games/sw/src/input.cpp | 9 ++++++--- source/games/sw/src/player.h | 2 +- 15 files changed, 51 insertions(+), 45 deletions(-) diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index 9cd87b092..7913857db 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -110,7 +110,7 @@ void resetTurnHeldAmt() // //--------------------------------------------------------------------------- -void processMovement(InputPacket* const currInput, InputPacket* const inputBuffer, ControlInfo* const hidInput, const double scaleAdjust, const int drink_amt, const bool allowstrafe, const double turnscale) +void processMovement(InputPacket* const currInput, InputPacket* const inputBuffer, HIDInput* const hidInput, const double scaleAdjust, const int drink_amt, const bool allowstrafe, const double turnscale) { // set up variables. const int keymove = 1 << int(!!(inputBuffer->actions & SB_RUN)); diff --git a/source/core/gameinput.h b/source/core/gameinput.h index e58c553f7..378ca98ae 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -83,4 +83,4 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngles& w, P void updateTurnHeldAmt(const double scaleAdjust); bool isTurboTurnTime(); void resetTurnHeldAmt(); -void processMovement(InputPacket* const currInput, InputPacket* const inputBuffer, ControlInfo* const hidInput, const double scaleAdjust, const int drink_amt = 0, const bool allowstrafe = true, const double turnscale = 1); +void processMovement(InputPacket* const currInput, InputPacket* const inputBuffer, HIDInput* const hidInput, const double scaleAdjust, const int drink_amt = 0, const bool allowstrafe = true, const double turnscale = 1); diff --git a/source/core/gamestruct.h b/source/core/gamestruct.h index af0ee818d..9f1e3cb9c 100644 --- a/source/core/gamestruct.h +++ b/source/core/gamestruct.h @@ -88,7 +88,7 @@ struct GameInterface virtual void DrawPlayerSprite(const DVector2& origin, bool onteam) {} virtual void SetAmbience(bool on) {} virtual void ExitFromMenu() { throw CExitEvent(0); } - virtual void GetInput(ControlInfo* const hidInput, double const scaleAdjust, InputPacket* packet = nullptr) {} + virtual void GetInput(const double scaleAdjust, InputPacket* packet = nullptr) {} virtual void UpdateSounds() {} virtual void ErrorCleanup() {} virtual void Startup() {} diff --git a/source/core/inputstate.cpp b/source/core/inputstate.cpp index b548311fe..b4c59fb12 100644 --- a/source/core/inputstate.cpp +++ b/source/core/inputstate.cpp @@ -65,7 +65,7 @@ CVARD(Bool, invertmouse, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG, "invert vertic // //========================================================================== -void InputState::GetMouseDelta(ControlInfo * hidInput) +void InputState::GetMouseDelta(HIDInput * hidInput) { g_mousePos *= backendinputscale(); @@ -201,11 +201,9 @@ int32_t handleevents(void) // //========================================================================== -ControlInfo CONTROL_GetInput() +void getHidInput(HIDInput* const hidInput) { - ControlInfo hidInput {}; - - inputState.GetMouseDelta(&hidInput); + inputState.GetMouseDelta(hidInput); if (use_joystick) { @@ -214,13 +212,11 @@ ControlInfo CONTROL_GetInput() I_GetAxes(joyaxes); - hidInput.dyaw += -joyaxes[JOYAXIS_Yaw]; - hidInput.dpitch += -joyaxes[JOYAXIS_Pitch]; - hidInput.dforward += joyaxes[JOYAXIS_Forward] * .5f; - hidInput.dside += joyaxes[JOYAXIS_Side] * .5f; + hidInput->dyaw += -joyaxes[JOYAXIS_Yaw]; + hidInput->dpitch += -joyaxes[JOYAXIS_Pitch]; + hidInput->dforward += joyaxes[JOYAXIS_Forward] * .5f; + hidInput->dside += joyaxes[JOYAXIS_Side] * .5f; } - - return hidInput; } //--------------------------------------------------------------------------- @@ -398,7 +394,7 @@ CCMD(show_weapon) gi->ToggleShowWeapon(); } -void ApplyGlobalInput(InputPacket& input, ControlInfo* hidInput, bool const crouchable, bool const disableToggle) +void ApplyGlobalInput(InputPacket& input, HIDInput* hidInput, bool const crouchable, bool const disableToggle) { if (WeaponToSend != 0) input.setNewWeapon(WeaponToSend); WeaponToSend = 0; diff --git a/source/core/inputstate.h b/source/core/inputstate.h index 568acdf6c..52a0740a3 100644 --- a/source/core/inputstate.h +++ b/source/core/inputstate.h @@ -14,7 +14,7 @@ #include "vectors.h" -struct ControlInfo +struct HIDInput { float dside; float dup; @@ -50,7 +50,7 @@ public: g_mousePos.Y += y; } - void GetMouseDelta(ControlInfo* hidInput); + void GetMouseDelta(HIDInput* hidInput); void ClearAllInput(); bool CheckAllInput() @@ -63,7 +63,7 @@ public: extern InputState inputState; -ControlInfo CONTROL_GetInput(); +void getHidInput(HIDInput* const hidInput); int32_t handleevents(void); enum GameFunction_t @@ -102,7 +102,7 @@ enum GameFunction_t }; void SetupGameButtons(); -void ApplyGlobalInput(InputPacket& input, ControlInfo* const hidInput, bool const crouchable = true, bool const disableToggle = false); +void ApplyGlobalInput(InputPacket& input, HIDInput* const hidInput, bool const crouchable = true, bool const disableToggle = false); extern ESyncBits ActionsToSend; extern bool gamesetinput; diff --git a/source/core/mainloop.cpp b/source/core/mainloop.cpp index 75d96fbce..196ea891e 100644 --- a/source/core/mainloop.cpp +++ b/source/core/mainloop.cpp @@ -136,8 +136,7 @@ void G_BuildTiccmd(ticcmd_t* cmd) } cmd->ucmd = {}; I_GetEvent(); - auto input = CONTROL_GetInput(); - gi->GetInput(&input, inputScale, &cmd->ucmd); + gi->GetInput(inputScale, &cmd->ucmd); cmd->consistency = consistency[myconnectindex][(maketic / ticdup) % BACKUPTICS]; } @@ -615,8 +614,7 @@ void TryRunTics (void) if (!SyncInput()) { I_GetEvent(); - auto input = CONTROL_GetInput(); - gi->GetInput(&input, inputScale); + gi->GetInput(inputScale); } return; } diff --git a/source/games/blood/src/blood.h b/source/games/blood/src/blood.h index 070d6ee1b..4994f2682 100644 --- a/source/games/blood/src/blood.h +++ b/source/games/blood/src/blood.h @@ -120,7 +120,7 @@ struct GameInterface : public ::GameInterface void MenuClosed() override; bool CanSave() override; void UpdateSounds() override; - void GetInput(ControlInfo* const hidInput, double const scaleAdjust, InputPacket* packet = nullptr) override; + void GetInput(const double scaleAdjust, InputPacket* packet = nullptr) override; void Ticker() override; void DrawBackground() override; void Startup() override; diff --git a/source/games/blood/src/controls.cpp b/source/games/blood/src/controls.cpp index 5829e7eb3..36d2d1f79 100644 --- a/source/games/blood/src/controls.cpp +++ b/source/games/blood/src/controls.cpp @@ -40,7 +40,7 @@ static InputPacket gInput; // //--------------------------------------------------------------------------- -void GameInterface::GetInput(ControlInfo* const hidInput, double const scaleAdjust, InputPacket* packet) +void GameInterface::GetInput(const double scaleAdjust, InputPacket* packet) { if (paused || M_Active()) { @@ -48,11 +48,14 @@ void GameInterface::GetInput(ControlInfo* const hidInput, double const scaleAdju return; } + HIDInput hidInput; + getHidInput(&hidInput); + PLAYER* pPlayer = &gPlayer[myconnectindex]; InputPacket input{}; - ApplyGlobalInput(gInput, hidInput); - processMovement(&input, &gInput, hidInput, scaleAdjust); + ApplyGlobalInput(gInput, &hidInput); + processMovement(&input, &gInput, &hidInput, scaleAdjust); // Perform unsynchronised angle/horizon if not dead. if (!SyncInput() && gamestate == GS_LEVEL && pPlayer->actor->xspr.health != 0) diff --git a/source/games/duke/src/duke3d.h b/source/games/duke/src/duke3d.h index 7e0b60c5d..430abe230 100644 --- a/source/games/duke/src/duke3d.h +++ b/source/games/duke/src/duke3d.h @@ -38,7 +38,7 @@ struct GameInterface : public ::GameInterface void SerializeGameState(FSerializer& arc) override; void ExitFromMenu() override; void DrawPlayerSprite(const DVector2& origin, bool onteam) override; - void GetInput(ControlInfo* const hidInput, double const scaleAdjust, InputPacket* packet = nullptr) override; + void GetInput(const double scaleAdjust, InputPacket* packet = nullptr) override; void UpdateSounds() override; void Startup() override; void DrawBackground() override; diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 758bbd27a..892c2eb81 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -523,7 +523,7 @@ static constexpr float VEHICLETURN = (20.f * 360.f / 2048.f); // //--------------------------------------------------------------------------- -static void processInputBits(player_struct *p, ControlInfo* const hidInput) +static void processInputBits(player_struct *p, HIDInput* const hidInput) { // Set-up crouch bools. int const sectorLotag = p->insector() ? p->cursector->lotag : 0; @@ -555,7 +555,7 @@ static void processInputBits(player_struct *p, ControlInfo* const hidInput) // //--------------------------------------------------------------------------- -static float motoApplyTurn(player_struct* p, ControlInfo* const hidInput, bool const kbdLeft, bool const kbdRight, const float factor) +static float motoApplyTurn(player_struct* p, HIDInput* const hidInput, bool const kbdLeft, bool const kbdRight, const float factor) { float turnvel = 0; p->oTiltStatus = p->TiltStatus; @@ -645,7 +645,7 @@ static float motoApplyTurn(player_struct* p, ControlInfo* const hidInput, bool c // //--------------------------------------------------------------------------- -static float boatApplyTurn(player_struct *p, ControlInfo* const hidInput, bool const kbdLeft, bool const kbdRight, const float factor) +static float boatApplyTurn(player_struct *p, HIDInput* const hidInput, bool const kbdLeft, bool const kbdRight, const float factor) { float turnvel = 0; p->oTiltStatus = p->TiltStatus; @@ -731,7 +731,7 @@ static float boatApplyTurn(player_struct *p, ControlInfo* const hidInput, bool c // //--------------------------------------------------------------------------- -static void processVehicleInput(player_struct *p, ControlInfo* const hidInput, InputPacket& input, double const scaleAdjust) +static void processVehicleInput(player_struct *p, HIDInput* const hidInput, InputPacket& input, double const scaleAdjust) { bool const kbdLeft = buttonMap.ButtonDown(gamefunc_Turn_Left) || buttonMap.ButtonDown(gamefunc_Strafe_Left); bool const kbdRight = buttonMap.ButtonDown(gamefunc_Turn_Right) || buttonMap.ButtonDown(gamefunc_Strafe_Right); @@ -805,7 +805,7 @@ static void FinalizeInput(player_struct *p, InputPacket& input) // //--------------------------------------------------------------------------- -void GameInterface::GetInput(ControlInfo* const hidInput, double const scaleAdjust, InputPacket* packet) +void GameInterface::GetInput(const double scaleAdjust, InputPacket* packet) { if (paused || gamestate != GS_LEVEL) { @@ -813,18 +813,21 @@ void GameInterface::GetInput(ControlInfo* const hidInput, double const scaleAdju return; } + HIDInput hidInput; + getHidInput(&hidInput); + auto const p = &ps[myconnectindex]; InputPacket input{}; - processInputBits(p, hidInput); + processInputBits(p, &hidInput); if (isRRRA() && (p->OnMotorcycle || p->OnBoat)) { - processVehicleInput(p, hidInput, input, scaleAdjust); + processVehicleInput(p, &hidInput, input, scaleAdjust); } else { - processMovement(&input, &loc, hidInput, scaleAdjust, p->drink_amt); + processMovement(&input, &loc, &hidInput, scaleAdjust, p->drink_amt); } FinalizeInput(p, input); diff --git a/source/games/exhumed/src/exhumed.h b/source/games/exhumed/src/exhumed.h index 06960c93c..c89973a50 100644 --- a/source/games/exhumed/src/exhumed.h +++ b/source/games/exhumed/src/exhumed.h @@ -225,7 +225,7 @@ struct GameInterface : public ::GameInterface void DrawBackground() override; void Render() override; //void DrawWeapons() override; - void GetInput(ControlInfo* const hidInput, double const scaleAdjust, InputPacket* packet = nullptr) override; + void GetInput(const double scaleAdjust, InputPacket* packet = nullptr) override; void Startup() override; const char* GenericCheat(int player, int cheat) override; void NewGame(MapRecord *map, int skill, bool) override; diff --git a/source/games/exhumed/src/input.cpp b/source/games/exhumed/src/input.cpp index 461c08d59..275be4165 100644 --- a/source/games/exhumed/src/input.cpp +++ b/source/games/exhumed/src/input.cpp @@ -46,7 +46,7 @@ void ClearSpaceBar(int nPlayer) // //--------------------------------------------------------------------------- -void GameInterface::GetInput(ControlInfo* const hidInput, double const scaleAdjust, InputPacket* packet) +void GameInterface::GetInput(const double scaleAdjust, InputPacket* packet) { if (paused || M_Active()) { @@ -54,10 +54,13 @@ void GameInterface::GetInput(ControlInfo* const hidInput, double const scaleAdju return; } + HIDInput hidInput; + getHidInput(&hidInput); + if (packet != nullptr) { localInput = {}; - ApplyGlobalInput(localInput, hidInput); + ApplyGlobalInput(localInput, &hidInput); if (PlayerList[nLocalPlayer].nHealth == 0) localInput.actions &= SB_OPEN; } @@ -66,7 +69,7 @@ void GameInterface::GetInput(ControlInfo* const hidInput, double const scaleAdju if (PlayerList[nLocalPlayer].nHealth != 0) { - processMovement(&input, &localInput, hidInput, scaleAdjust); + processMovement(&input, &localInput, &hidInput, scaleAdjust); } else { diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index 3e37d9fe8..801578132 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -1681,7 +1681,7 @@ struct GameInterface : public ::GameInterface void SetAmbience(bool on) override { if (on) StartAmbientSound(); else StopAmbientSound(); } void UpdateSounds() override; void ErrorCleanup() override; - void GetInput(ControlInfo* const hidInput, double const scaleAdjust, InputPacket* input = nullptr) override; + void GetInput(const double scaleAdjust, InputPacket* input = nullptr) override; void DrawBackground(void) override; void Ticker(void) override; void Render() override; diff --git a/source/games/sw/src/input.cpp b/source/games/sw/src/input.cpp index 0b7e69ccc..d81bb0137 100644 --- a/source/games/sw/src/input.cpp +++ b/source/games/sw/src/input.cpp @@ -160,7 +160,7 @@ static void processWeapon(PLAYER* const pp) } } -void GameInterface::GetInput(ControlInfo* const hidInput, double const scaleAdjust, InputPacket *packet) +void GameInterface::GetInput(const double scaleAdjust, InputPacket *packet) { PLAYER* pp = &Player[myconnectindex]; @@ -170,10 +170,13 @@ void GameInterface::GetInput(ControlInfo* const hidInput, double const scaleAdju return; } + HIDInput hidInput; + getHidInput(&hidInput); + InputPacket input {}; - ApplyGlobalInput(loc, hidInput); - processMovement(&input, &loc, hidInput, scaleAdjust, 0, !pp->sop, pp->sop_control ? 3. / 1.40625 : 1.); + ApplyGlobalInput(loc, &hidInput); + processMovement(&input, &loc, &hidInput, scaleAdjust, 0, !pp->sop, pp->sop_control ? 3. / 1.40625 : 1.); processWeapon(pp); if (!SyncInput()) diff --git a/source/games/sw/src/player.h b/source/games/sw/src/player.h index 60a9747ad..bb00b973d 100644 --- a/source/games/sw/src/player.h +++ b/source/games/sw/src/player.h @@ -125,7 +125,7 @@ void DoPlayer(void); void domovethings(void); void InitAllPlayers(void); void InitMultiPlayerInfo(const DVector3& spawnpos, const DAngle startang); -void MoveScrollMode2D(PLAYER* pp, ControlInfo* const hidInput); +void MoveScrollMode2D(PLAYER* pp, HIDInput* const hidInput); void DoPlayerDivePalette(PLAYER* pp); void DoPlayerNightVisionPalette(PLAYER* pp); void DoPlayerStopDiveNoWarp(PLAYER* pp); From fc069feac6269ff7b08cee4005a0db43280ea8bc Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Fri, 17 Mar 2023 20:45:52 +1100 Subject: [PATCH 41/67] - Negate `ControlInfo::dyaw` to match data out of backend. --- source/core/gameinput.cpp | 4 ++-- source/core/inputstate.cpp | 6 +++--- source/games/duke/src/input.cpp | 24 ++++++++++++------------ 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index 7913857db..e93778e56 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -127,12 +127,12 @@ void processMovement(InputPacket* const currInput, InputPacket* const inputBuffe { const float turndir = clamp(turning + strafing * !allowstrafe, -1.f, 1.f); const float turnspeed = float(getTicrateScale(YAW_TURNSPEEDS[keymove]) * turnscale * (isTurboTurnTime() ? 1. : YAW_PREAMBLESCALE)); - currInput->avel += hidInput->mouseturnx + (hidInput->dyaw * hidspeed + turndir * turnspeed) * scaleAdjustf; + currInput->avel += hidInput->mouseturnx - (hidInput->dyaw * hidspeed - turndir * turnspeed) * scaleAdjustf; if (turndir) updateTurnHeldAmt(scaleAdjust); else resetTurnHeldAmt(); } else { - currInput->svel += hidInput->mousemovex + (hidInput->dyaw + turning) * keymove * scaleAdjustf; + currInput->svel += hidInput->mousemovex - (hidInput->dyaw - turning) * keymove * scaleAdjustf; } // process player pitch input. diff --git a/source/core/inputstate.cpp b/source/core/inputstate.cpp index b4c59fb12..3bda76595 100644 --- a/source/core/inputstate.cpp +++ b/source/core/inputstate.cpp @@ -212,7 +212,7 @@ void getHidInput(HIDInput* const hidInput) I_GetAxes(joyaxes); - hidInput->dyaw += -joyaxes[JOYAXIS_Yaw]; + hidInput->dyaw += joyaxes[JOYAXIS_Yaw]; hidInput->dpitch += -joyaxes[JOYAXIS_Pitch]; hidInput->dforward += joyaxes[JOYAXIS_Forward] * .5f; hidInput->dside += joyaxes[JOYAXIS_Side] * .5f; @@ -405,9 +405,9 @@ void ApplyGlobalInput(InputPacket& input, HIDInput* hidInput, bool const croucha else dpad_lock &= ~1; if (hidInput->dforward < 0 && !(dpad_lock & 2)) { dpad_lock |= 2; input.setNewWeapon(WeaponSel_Next); } else dpad_lock &= ~2; - if ((hidInput->dside < 0 || hidInput->dyaw < 0) && !(dpad_lock & 4)) { dpad_lock |= 4; input.actions |= SB_INVPREV; } + if ((hidInput->dside < 0 || hidInput->dyaw > 0) && !(dpad_lock & 4)) { dpad_lock |= 4; input.actions |= SB_INVPREV; } else dpad_lock &= ~4; - if ((hidInput->dside > 0 || hidInput->dyaw > 0) && !(dpad_lock & 8)) { dpad_lock |= 8; input.actions |= SB_INVNEXT; } + if ((hidInput->dside > 0 || hidInput->dyaw < 0) && !(dpad_lock & 8)) { dpad_lock |= 8; input.actions |= SB_INVNEXT; } else dpad_lock &= ~8; // This eats the controller input for regular use diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 892c2eb81..97589d589 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -564,13 +564,13 @@ static float motoApplyTurn(player_struct* p, HIDInput* const hidInput, bool cons { resetTurnHeldAmt(); - if (kbdLeft || hidInput->mouseturnx < 0 || hidInput->dyaw < 0) + if (kbdLeft || hidInput->mouseturnx < 0 || hidInput->dyaw > 0) { p->TiltStatus -= (float)factor; if (p->TiltStatus < -10) p->TiltStatus = -10; } - else if (kbdRight || hidInput->mouseturnx > 0 || hidInput->dyaw > 0) + else if (kbdRight || hidInput->mouseturnx > 0 || hidInput->dyaw < 0) { p->TiltStatus += (float)factor; if (p->TiltStatus > 10) @@ -584,7 +584,7 @@ static float motoApplyTurn(player_struct* p, HIDInput* const hidInput, bool cons constexpr float velScale = (3.f / 10.f); const float baseVel = (buttonMap.ButtonDown(gamefunc_Move_Backward) || hidInput->dforward < 0) && p->MotoSpeed <= 0 ? -VEHICLETURN : VEHICLETURN; - if (kbdLeft || p->moto_drink < 0 || hidInput->mouseturnx < 0 || hidInput->dyaw < 0) + if (kbdLeft || p->moto_drink < 0 || hidInput->mouseturnx < 0 || hidInput->dyaw > 0) { p->TiltStatus -= (float)factor; @@ -597,13 +597,13 @@ static float motoApplyTurn(player_struct* p, HIDInput* const hidInput, bool cons if (hidInput->mouseturnx < 0) turnvel -= Sgn(baseVel) * sqrtf(abs(p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * -(hidInput->mouseturnx / factor) * (7.f / 20.f)); - if (hidInput->dyaw < 0) + if (hidInput->dyaw > 0) turnvel += (p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * hidInput->dyaw; updateTurnHeldAmt(factor); } - if (kbdRight || p->moto_drink > 0 || hidInput->mouseturnx > 0 || hidInput->dyaw > 0) + if (kbdRight || p->moto_drink > 0 || hidInput->mouseturnx > 0 || hidInput->dyaw < 0) { p->TiltStatus += (float)factor; @@ -616,7 +616,7 @@ static float motoApplyTurn(player_struct* p, HIDInput* const hidInput, bool cons if (hidInput->mouseturnx > 0) turnvel += Sgn(baseVel) * sqrtf(abs(p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * (hidInput->mouseturnx / factor) * (7.f / 20.f)); - if (hidInput->dyaw > 0) + if (hidInput->dyaw < 0) turnvel += (p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * hidInput->dyaw; updateTurnHeldAmt(factor); @@ -657,7 +657,7 @@ static float boatApplyTurn(player_struct *p, HIDInput* const hidInput, bool cons const float velScale = !p->NotOnWater? 1.f : (6.f / 19.f); const float baseVel = VEHICLETURN * velScale; - if (kbdLeft || p->moto_drink < 0 || hidInput->mouseturnx < 0 || hidInput->dyaw < 0) + if (kbdLeft || p->moto_drink < 0 || hidInput->mouseturnx < 0 || hidInput->dyaw > 0) { if (!p->NotOnWater) { @@ -672,13 +672,13 @@ static float boatApplyTurn(player_struct *p, HIDInput* const hidInput, bool cons if (hidInput->mouseturnx < 0) turnvel -= Sgn(baseVel) * sqrtf(abs(baseVel) * -(hidInput->mouseturnx / factor) * (7.f / 20.f)); - if (hidInput->dyaw < 0) + if (hidInput->dyaw > 0) turnvel += baseVel * hidInput->dyaw; updateTurnHeldAmt(factor); } - if (kbdRight || p->moto_drink > 0 || hidInput->mouseturnx > 0 || hidInput->dyaw > 0) + if (kbdRight || p->moto_drink > 0 || hidInput->mouseturnx > 0 || hidInput->dyaw < 0) { if (!p->NotOnWater) { @@ -693,7 +693,7 @@ static float boatApplyTurn(player_struct *p, HIDInput* const hidInput, bool cons if (hidInput->mouseturnx > 0) turnvel += Sgn(baseVel) * sqrtf(abs(baseVel) * (hidInput->mouseturnx / factor) * (7.f / 20.f)); - if (hidInput->dyaw > 0) + if (hidInput->dyaw < 0) turnvel += baseVel * hidInput->dyaw; updateTurnHeldAmt(factor); @@ -739,8 +739,8 @@ static void processVehicleInput(player_struct *p, HIDInput* const hidInput, Inpu // Cancel out micro-movement if (fabs(hidInput->mouseturnx) < (m_sensitivity_x * m_yaw * backendinputscale() * 2.f)) hidInput->mouseturnx = 0; - p->vehTurnLeft = kbdLeft || hidInput->mouseturnx < 0 || hidInput->dyaw < 0; - p->vehTurnRight = kbdRight || hidInput->mouseturnx > 0 || hidInput->dyaw > 0; + p->vehTurnLeft = kbdLeft || hidInput->mouseturnx < 0 || hidInput->dyaw > 0; + p->vehTurnRight = kbdRight || hidInput->mouseturnx > 0 || hidInput->dyaw < 0; if (p->OnBoat || !p->moto_underwater) { From 08d22f49f4966bce4b22ed230618e643b56f310f Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Fri, 17 Mar 2023 20:37:09 +1100 Subject: [PATCH 42/67] - Negate `ControlInfo::dpitch` to match data out of backend. --- source/core/gameinput.cpp | 4 ++-- source/core/inputstate.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index e93778e56..da97d5b05 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -137,9 +137,9 @@ void processMovement(InputPacket* const currInput, InputPacket* const inputBuffe // process player pitch input. if (!(inputBuffer->actions & SB_AIMMODE)) - currInput->horz += hidInput->mouseturny + hidInput->dpitch * hidspeed * scaleAdjustf; + currInput->horz += hidInput->mouseturny - hidInput->dpitch * hidspeed * scaleAdjustf; else - currInput->fvel -= hidInput->mousemovey + hidInput->dpitch * keymove * scaleAdjustf; + currInput->fvel -= hidInput->mousemovey - hidInput->dpitch * keymove * scaleAdjustf; // process movement input. currInput->fvel += moving * keymove; diff --git a/source/core/inputstate.cpp b/source/core/inputstate.cpp index 3bda76595..5da4b3edd 100644 --- a/source/core/inputstate.cpp +++ b/source/core/inputstate.cpp @@ -213,7 +213,7 @@ void getHidInput(HIDInput* const hidInput) I_GetAxes(joyaxes); hidInput->dyaw += joyaxes[JOYAXIS_Yaw]; - hidInput->dpitch += -joyaxes[JOYAXIS_Pitch]; + hidInput->dpitch += joyaxes[JOYAXIS_Pitch]; hidInput->dforward += joyaxes[JOYAXIS_Forward] * .5f; hidInput->dside += joyaxes[JOYAXIS_Side] * .5f; } From eed9716d86d66f6aedbeca6f989784b7cd1068db Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Fri, 17 Mar 2023 20:42:19 +1100 Subject: [PATCH 43/67] - Move `joyaxes[]` array from `getHidInput()` directly into `ControlInfo`. --- source/core/gameinput.cpp | 12 ++++----- source/core/inputstate.cpp | 44 ++++++++------------------------- source/core/inputstate.h | 14 +++++------ source/games/duke/src/input.cpp | 42 +++++++++++++++---------------- 4 files changed, 44 insertions(+), 68 deletions(-) diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index da97d5b05..9f38183b6 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -119,27 +119,27 @@ void processMovement(InputPacket* const currInput, InputPacket* const inputBuffe // determine player input. const auto turning = buttonMap.ButtonDown(gamefunc_Turn_Right) - buttonMap.ButtonDown(gamefunc_Turn_Left); - const auto moving = buttonMap.ButtonDown(gamefunc_Move_Forward) - buttonMap.ButtonDown(gamefunc_Move_Backward) + hidInput->dforward * scaleAdjustf; - const auto strafing = buttonMap.ButtonDown(gamefunc_Strafe_Right) - buttonMap.ButtonDown(gamefunc_Strafe_Left) - hidInput->dside * scaleAdjustf; + const auto moving = buttonMap.ButtonDown(gamefunc_Move_Forward) - buttonMap.ButtonDown(gamefunc_Move_Backward) + hidInput->joyaxes[JOYAXIS_Forward] * scaleAdjustf; + const auto strafing = buttonMap.ButtonDown(gamefunc_Strafe_Right) - buttonMap.ButtonDown(gamefunc_Strafe_Left) - hidInput->joyaxes[JOYAXIS_Side] * scaleAdjustf; // process player angle input. if (!(buttonMap.ButtonDown(gamefunc_Strafe) && allowstrafe)) { const float turndir = clamp(turning + strafing * !allowstrafe, -1.f, 1.f); const float turnspeed = float(getTicrateScale(YAW_TURNSPEEDS[keymove]) * turnscale * (isTurboTurnTime() ? 1. : YAW_PREAMBLESCALE)); - currInput->avel += hidInput->mouseturnx - (hidInput->dyaw * hidspeed - turndir * turnspeed) * scaleAdjustf; + currInput->avel += hidInput->mouseturnx - (hidInput->joyaxes[JOYAXIS_Yaw] * hidspeed - turndir * turnspeed) * scaleAdjustf; if (turndir) updateTurnHeldAmt(scaleAdjust); else resetTurnHeldAmt(); } else { - currInput->svel += hidInput->mousemovex - (hidInput->dyaw - turning) * keymove * scaleAdjustf; + currInput->svel += hidInput->mousemovex - (hidInput->joyaxes[JOYAXIS_Yaw] - turning) * keymove * scaleAdjustf; } // process player pitch input. if (!(inputBuffer->actions & SB_AIMMODE)) - currInput->horz += hidInput->mouseturny - hidInput->dpitch * hidspeed * scaleAdjustf; + currInput->horz += hidInput->mouseturny - hidInput->joyaxes[JOYAXIS_Pitch] * hidspeed * scaleAdjustf; else - currInput->fvel -= hidInput->mousemovey - hidInput->dpitch * keymove * scaleAdjustf; + currInput->fvel -= hidInput->mousemovey - hidInput->joyaxes[JOYAXIS_Pitch] * keymove * scaleAdjustf; // process movement input. currInput->fvel += moving * keymove; diff --git a/source/core/inputstate.cpp b/source/core/inputstate.cpp index 5da4b3edd..01bd661b5 100644 --- a/source/core/inputstate.cpp +++ b/source/core/inputstate.cpp @@ -195,30 +195,6 @@ int32_t handleevents(void) return 0; } -//========================================================================== -// -// -// -//========================================================================== - -void getHidInput(HIDInput* const hidInput) -{ - inputState.GetMouseDelta(hidInput); - - if (use_joystick) - { - // Handle joysticks/game controllers. - float joyaxes[NUM_JOYAXIS]; - - I_GetAxes(joyaxes); - - hidInput->dyaw += joyaxes[JOYAXIS_Yaw]; - hidInput->dpitch += joyaxes[JOYAXIS_Pitch]; - hidInput->dforward += joyaxes[JOYAXIS_Forward] * .5f; - hidInput->dside += joyaxes[JOYAXIS_Side] * .5f; - } -} - //--------------------------------------------------------------------------- // // @@ -401,33 +377,33 @@ void ApplyGlobalInput(InputPacket& input, HIDInput* hidInput, bool const croucha if (hidInput && buttonMap.ButtonDown(gamefunc_Dpad_Select)) { // These buttons should not autorepeat. The game handlers are not really equipped for that. - if (hidInput->dforward > 0 && !(dpad_lock & 1)) { dpad_lock |= 1; input.setNewWeapon(WeaponSel_Prev); } + if (hidInput->joyaxes[JOYAXIS_Forward] > 0 && !(dpad_lock & 1)) { dpad_lock |= 1; input.setNewWeapon(WeaponSel_Prev); } else dpad_lock &= ~1; - if (hidInput->dforward < 0 && !(dpad_lock & 2)) { dpad_lock |= 2; input.setNewWeapon(WeaponSel_Next); } + if (hidInput->joyaxes[JOYAXIS_Forward] < 0 && !(dpad_lock & 2)) { dpad_lock |= 2; input.setNewWeapon(WeaponSel_Next); } else dpad_lock &= ~2; - if ((hidInput->dside < 0 || hidInput->dyaw > 0) && !(dpad_lock & 4)) { dpad_lock |= 4; input.actions |= SB_INVPREV; } + if ((hidInput->joyaxes[JOYAXIS_Side] < 0 || hidInput->joyaxes[JOYAXIS_Yaw] > 0) && !(dpad_lock & 4)) { dpad_lock |= 4; input.actions |= SB_INVPREV; } else dpad_lock &= ~4; - if ((hidInput->dside > 0 || hidInput->dyaw < 0) && !(dpad_lock & 8)) { dpad_lock |= 8; input.actions |= SB_INVNEXT; } + if ((hidInput->joyaxes[JOYAXIS_Side] > 0 || hidInput->joyaxes[JOYAXIS_Yaw] < 0) && !(dpad_lock & 8)) { dpad_lock |= 8; input.actions |= SB_INVNEXT; } else dpad_lock &= ~8; // This eats the controller input for regular use - hidInput->dside = 0; - hidInput->dforward = 0; - hidInput->dyaw = 0; + hidInput->joyaxes[JOYAXIS_Side] = 0; + hidInput->joyaxes[JOYAXIS_Forward] = 0; + hidInput->joyaxes[JOYAXIS_Yaw] = 0; } else dpad_lock = 0; input.actions |= ActionsToSend; ActionsToSend = 0; - if (buttonMap.ButtonDown(gamefunc_Aim_Up) || (buttonMap.ButtonDown(gamefunc_Dpad_Aiming) && hidInput->dforward > 0)) + if (buttonMap.ButtonDown(gamefunc_Aim_Up) || (buttonMap.ButtonDown(gamefunc_Dpad_Aiming) && hidInput->joyaxes[JOYAXIS_Forward] > 0)) input.actions |= SB_AIM_UP; - if ((buttonMap.ButtonDown(gamefunc_Aim_Down) || (buttonMap.ButtonDown(gamefunc_Dpad_Aiming) && hidInput->dforward < 0))) + if ((buttonMap.ButtonDown(gamefunc_Aim_Down) || (buttonMap.ButtonDown(gamefunc_Dpad_Aiming) && hidInput->joyaxes[JOYAXIS_Forward] < 0))) input.actions |= SB_AIM_DOWN; if (buttonMap.ButtonDown(gamefunc_Dpad_Aiming)) - hidInput->dforward = 0; + hidInput->joyaxes[JOYAXIS_Forward] = 0; if (buttonMap.ButtonDown(gamefunc_Jump)) input.actions |= SB_JUMP; diff --git a/source/core/inputstate.h b/source/core/inputstate.h index 52a0740a3..bc766c7fd 100644 --- a/source/core/inputstate.h +++ b/source/core/inputstate.h @@ -16,12 +16,7 @@ struct HIDInput { - float dside; - float dup; - float dforward; - float dyaw; - float dpitch; - float droll; + float joyaxes[NUM_JOYAXIS]; float mouseturnx; float mouseturny; float mousemovex; @@ -63,7 +58,6 @@ public: extern InputState inputState; -void getHidInput(HIDInput* const hidInput); int32_t handleevents(void); enum GameFunction_t @@ -116,6 +110,12 @@ inline float backendinputscale() return (1.f / 16.f); } +inline void getHidInput(HIDInput* const hidInput) +{ + inputState.GetMouseDelta(hidInput); + if (use_joystick) I_GetAxes(hidInput->joyaxes); +} + //--------------------------------------------------------------------------- // // Inline functions to help with edge cases where synchronised input is needed. diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 97589d589..1e8edefee 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -564,13 +564,13 @@ static float motoApplyTurn(player_struct* p, HIDInput* const hidInput, bool cons { resetTurnHeldAmt(); - if (kbdLeft || hidInput->mouseturnx < 0 || hidInput->dyaw > 0) + if (kbdLeft || hidInput->mouseturnx < 0 || hidInput->joyaxes[JOYAXIS_Yaw] > 0) { p->TiltStatus -= (float)factor; if (p->TiltStatus < -10) p->TiltStatus = -10; } - else if (kbdRight || hidInput->mouseturnx > 0 || hidInput->dyaw < 0) + else if (kbdRight || hidInput->mouseturnx > 0 || hidInput->joyaxes[JOYAXIS_Yaw] < 0) { p->TiltStatus += (float)factor; if (p->TiltStatus > 10) @@ -579,12 +579,12 @@ static float motoApplyTurn(player_struct* p, HIDInput* const hidInput, bool cons } else { - if (kbdLeft || kbdRight || p->moto_drink || hidInput->mouseturnx || hidInput->dyaw) + if (kbdLeft || kbdRight || p->moto_drink || hidInput->mouseturnx || hidInput->joyaxes[JOYAXIS_Yaw]) { constexpr float velScale = (3.f / 10.f); - const float baseVel = (buttonMap.ButtonDown(gamefunc_Move_Backward) || hidInput->dforward < 0) && p->MotoSpeed <= 0 ? -VEHICLETURN : VEHICLETURN; + const float baseVel = (buttonMap.ButtonDown(gamefunc_Move_Backward) || hidInput->joyaxes[JOYAXIS_Forward] < 0) && p->MotoSpeed <= 0 ? -VEHICLETURN : VEHICLETURN; - if (kbdLeft || p->moto_drink < 0 || hidInput->mouseturnx < 0 || hidInput->dyaw > 0) + if (kbdLeft || p->moto_drink < 0 || hidInput->mouseturnx < 0 || hidInput->joyaxes[JOYAXIS_Yaw] > 0) { p->TiltStatus -= (float)factor; @@ -597,13 +597,13 @@ static float motoApplyTurn(player_struct* p, HIDInput* const hidInput, bool cons if (hidInput->mouseturnx < 0) turnvel -= Sgn(baseVel) * sqrtf(abs(p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * -(hidInput->mouseturnx / factor) * (7.f / 20.f)); - if (hidInput->dyaw > 0) - turnvel += (p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * hidInput->dyaw; + if (hidInput->joyaxes[JOYAXIS_Yaw] > 0) + turnvel += (p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * hidInput->joyaxes[JOYAXIS_Yaw]; updateTurnHeldAmt(factor); } - if (kbdRight || p->moto_drink > 0 || hidInput->mouseturnx > 0 || hidInput->dyaw < 0) + if (kbdRight || p->moto_drink > 0 || hidInput->mouseturnx > 0 || hidInput->joyaxes[JOYAXIS_Yaw] < 0) { p->TiltStatus += (float)factor; @@ -616,8 +616,8 @@ static float motoApplyTurn(player_struct* p, HIDInput* const hidInput, bool cons if (hidInput->mouseturnx > 0) turnvel += Sgn(baseVel) * sqrtf(abs(p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * (hidInput->mouseturnx / factor) * (7.f / 20.f)); - if (hidInput->dyaw < 0) - turnvel += (p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * hidInput->dyaw; + if (hidInput->joyaxes[JOYAXIS_Yaw] < 0) + turnvel += (p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * hidInput->joyaxes[JOYAXIS_Yaw]; updateTurnHeldAmt(factor); } @@ -652,12 +652,12 @@ static float boatApplyTurn(player_struct *p, HIDInput* const hidInput, bool cons if (p->MotoSpeed) { - if (kbdLeft || kbdRight || p->moto_drink || hidInput->mouseturnx || hidInput->dyaw) + if (kbdLeft || kbdRight || p->moto_drink || hidInput->mouseturnx || hidInput->joyaxes[JOYAXIS_Yaw]) { const float velScale = !p->NotOnWater? 1.f : (6.f / 19.f); const float baseVel = VEHICLETURN * velScale; - if (kbdLeft || p->moto_drink < 0 || hidInput->mouseturnx < 0 || hidInput->dyaw > 0) + if (kbdLeft || p->moto_drink < 0 || hidInput->mouseturnx < 0 || hidInput->joyaxes[JOYAXIS_Yaw] > 0) { if (!p->NotOnWater) { @@ -672,13 +672,13 @@ static float boatApplyTurn(player_struct *p, HIDInput* const hidInput, bool cons if (hidInput->mouseturnx < 0) turnvel -= Sgn(baseVel) * sqrtf(abs(baseVel) * -(hidInput->mouseturnx / factor) * (7.f / 20.f)); - if (hidInput->dyaw > 0) - turnvel += baseVel * hidInput->dyaw; + if (hidInput->joyaxes[JOYAXIS_Yaw] > 0) + turnvel += baseVel * hidInput->joyaxes[JOYAXIS_Yaw]; updateTurnHeldAmt(factor); } - if (kbdRight || p->moto_drink > 0 || hidInput->mouseturnx > 0 || hidInput->dyaw < 0) + if (kbdRight || p->moto_drink > 0 || hidInput->mouseturnx > 0 || hidInput->joyaxes[JOYAXIS_Yaw] < 0) { if (!p->NotOnWater) { @@ -693,8 +693,8 @@ static float boatApplyTurn(player_struct *p, HIDInput* const hidInput, bool cons if (hidInput->mouseturnx > 0) turnvel += Sgn(baseVel) * sqrtf(abs(baseVel) * (hidInput->mouseturnx / factor) * (7.f / 20.f)); - if (hidInput->dyaw < 0) - turnvel += baseVel * hidInput->dyaw; + if (hidInput->joyaxes[JOYAXIS_Yaw] < 0) + turnvel += baseVel * hidInput->joyaxes[JOYAXIS_Yaw]; updateTurnHeldAmt(factor); } @@ -739,13 +739,13 @@ static void processVehicleInput(player_struct *p, HIDInput* const hidInput, Inpu // Cancel out micro-movement if (fabs(hidInput->mouseturnx) < (m_sensitivity_x * m_yaw * backendinputscale() * 2.f)) hidInput->mouseturnx = 0; - p->vehTurnLeft = kbdLeft || hidInput->mouseturnx < 0 || hidInput->dyaw > 0; - p->vehTurnRight = kbdRight || hidInput->mouseturnx > 0 || hidInput->dyaw < 0; + p->vehTurnLeft = kbdLeft || hidInput->mouseturnx < 0 || hidInput->joyaxes[JOYAXIS_Yaw] > 0; + p->vehTurnRight = kbdRight || hidInput->mouseturnx > 0 || hidInput->joyaxes[JOYAXIS_Yaw] < 0; if (p->OnBoat || !p->moto_underwater) { - p->vehForwardScale = min((buttonMap.ButtonDown(gamefunc_Move_Forward) || buttonMap.ButtonDown(gamefunc_Strafe)) + hidInput->dforward, 1.f); - p->vehReverseScale = min(buttonMap.ButtonDown(gamefunc_Move_Backward) + -hidInput->dforward, 1.f); + p->vehForwardScale = min((buttonMap.ButtonDown(gamefunc_Move_Forward) || buttonMap.ButtonDown(gamefunc_Strafe)) + hidInput->joyaxes[JOYAXIS_Forward], 1.f); + p->vehReverseScale = min(buttonMap.ButtonDown(gamefunc_Move_Backward) + -hidInput->joyaxes[JOYAXIS_Forward], 1.f); p->vehBraking = buttonMap.ButtonDown(gamefunc_Run); } From a45890e0641f65565e56490c6333243c9a2b659a Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sat, 18 Mar 2023 09:15:15 +1100 Subject: [PATCH 44/67] - Move some Duke-specific stuff out of `ApplyGlobalInput()`. --- source/core/inputstate.cpp | 8 ++++---- source/core/inputstate.h | 2 +- source/games/duke/src/input.cpp | 8 +++++++- source/games/duke/src/player_d.cpp | 2 +- source/games/duke/src/player_r.cpp | 2 +- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/source/core/inputstate.cpp b/source/core/inputstate.cpp index 01bd661b5..b43ff16b4 100644 --- a/source/core/inputstate.cpp +++ b/source/core/inputstate.cpp @@ -370,7 +370,7 @@ CCMD(show_weapon) gi->ToggleShowWeapon(); } -void ApplyGlobalInput(InputPacket& input, HIDInput* hidInput, bool const crouchable, bool const disableToggle) +void ApplyGlobalInput(InputPacket& input, HIDInput* const hidInput) { if (WeaponToSend != 0) input.setNewWeapon(WeaponToSend); WeaponToSend = 0; @@ -413,11 +413,11 @@ void ApplyGlobalInput(InputPacket& input, HIDInput* hidInput, bool const croucha if (buttonMap.ButtonDown(gamefunc_Toggle_Crouch)) { - crouch_toggle = !crouch_toggle && crouchable; - if (crouchable) buttonMap.ClearButton(gamefunc_Toggle_Crouch); + crouch_toggle = !crouch_toggle; + buttonMap.ClearButton(gamefunc_Toggle_Crouch); } - if (buttonMap.ButtonDown(gamefunc_Crouch) || buttonMap.ButtonDown(gamefunc_Jump) || disableToggle) + if (buttonMap.ButtonDown(gamefunc_Crouch) || buttonMap.ButtonDown(gamefunc_Jump)) crouch_toggle = false; if (buttonMap.ButtonDown(gamefunc_Fire)) diff --git a/source/core/inputstate.h b/source/core/inputstate.h index bc766c7fd..377aaab7e 100644 --- a/source/core/inputstate.h +++ b/source/core/inputstate.h @@ -96,7 +96,7 @@ enum GameFunction_t }; void SetupGameButtons(); -void ApplyGlobalInput(InputPacket& input, HIDInput* const hidInput, bool const crouchable = true, bool const disableToggle = false); +void ApplyGlobalInput(InputPacket& input, HIDInput* const hidInput); extern ESyncBits ActionsToSend; extern bool gamesetinput; diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 1e8edefee..32be5c849 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -530,9 +530,15 @@ static void processInputBits(player_struct *p, HIDInput* const hidInput) bool const crouchable = sectorLotag != ST_2_UNDERWATER && (sectorLotag != ST_1_ABOVE_WATER || p->spritebridge); bool const disableToggle = p->jetpack_on || (!crouchable && p->on_ground) || (isRRRA() && (p->OnMotorcycle || p->OnBoat)); - ApplyGlobalInput(loc, hidInput, crouchable, disableToggle); + ApplyGlobalInput(loc, hidInput); if (isRR() && (loc.actions & SB_CROUCH)) loc.actions &= ~SB_JUMP; + if (!crouchable || disableToggle) + { + crouch_toggle = false; + loc.actions &= ~SB_CROUCH; + } + if (p->OnMotorcycle || p->OnBoat) { // mask out all actions not compatible with vehicles. diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index 4c49e6bd3..cdc7c255b 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -1738,7 +1738,7 @@ static void movement(int snum, ESyncBits actions, sectortype* psect, double floo p->on_warping_sector = 0; - if ((actions & SB_CROUCH) || crouch_toggle) // FIXME: The crouch_toggle check here is not network safe and needs revision when multiplayer is going. + if (actions & SB_CROUCH) { playerCrouch(snum); } diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index fa1f1b375..27d188228 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -2106,7 +2106,7 @@ static void movement(int snum, ESyncBits actions, sectortype* psect, double floo p->on_warping_sector = 0; - if (((actions & SB_CROUCH) || crouch_toggle) && !p->OnMotorcycle) // FIXME: The crouch_toggle check here is not network safe and needs revision when multiplayer is going. + if ((actions & SB_CROUCH) && !p->OnMotorcycle) { playerCrouch(snum); } From b07732bae40edfb2690d0790d217f5f9ba274051 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sat, 18 Mar 2023 09:09:16 +1100 Subject: [PATCH 45/67] - Duke: Remove duplicated call to `SetupGameButtons()` that's done globally in `RunGame()`. --- source/games/duke/src/game.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/source/games/duke/src/game.cpp b/source/games/duke/src/game.cpp index 05dd9d2a2..95c7ef709 100644 --- a/source/games/duke/src/game.cpp +++ b/source/games/duke/src/game.cpp @@ -402,7 +402,6 @@ void GameInterface::app_init() //Net_SendClientInfo(); setupbackdrop(); - SetupGameButtons(); InitCheats(); checkcommandline(); registerosdcommands(); From 292030b59e9cec30991e5ff1e12415c26977fcab Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sat, 18 Mar 2023 19:17:28 +1100 Subject: [PATCH 46/67] - Duke: Repair issues with going underwater after taking some stuff out of the global state. * Really, need to do something about this `crouch_toggle` malarkey... --- source/games/duke/src/input.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 32be5c849..57c818dbf 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -533,7 +533,7 @@ static void processInputBits(player_struct *p, HIDInput* const hidInput) ApplyGlobalInput(loc, hidInput); if (isRR() && (loc.actions & SB_CROUCH)) loc.actions &= ~SB_JUMP; - if (!crouchable || disableToggle) + if (crouch_toggle && (!crouchable || disableToggle)) { crouch_toggle = false; loc.actions &= ~SB_CROUCH; From a4f0a75a58196212c1523cc08711acd77d00e16e Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sat, 18 Mar 2023 11:40:42 +1100 Subject: [PATCH 47/67] - SW: Simplify unsynchronised input setup. * Had complicated flagging and setup for SO vehicles that never worked and doubt I'd ever get to work. * Setup now lends itself well to a potential more generic input setup. --- source/games/sw/src/game.h | 2 - source/games/sw/src/input.cpp | 24 +------- source/games/sw/src/interpso.cpp | 14 ++--- source/games/sw/src/player.cpp | 101 +++++++++---------------------- 4 files changed, 33 insertions(+), 108 deletions(-) diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index 801578132..9c3d7a7bb 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -567,8 +567,6 @@ enum PF_TANK = (BIT(29)), // Doin the tank thang PF_WEAPON_DOWN = (BIT(31)), PF2_TELEPORTED = (BIT(0)), - PF2_INPUT_CAN_AIM = (BIT(1)), // Allow calling DoPlayerHorizon() from processMovement() - PF2_INPUT_CAN_TURN_GENERAL = (BIT(2)), // Allow calling DoPlayerTurn() from processMovement() PF2_INPUT_CAN_TURN_VEHICLE = (BIT(3)), // Allow calling DoPlayerTurnVehicle() from processMovement() PF2_INPUT_CAN_TURN_TURRET = (BIT(4)), // Allow calling DoPlayerTurnTurret() from processMovement() }; diff --git a/source/games/sw/src/input.cpp b/source/games/sw/src/input.cpp index d81bb0137..e72b90dc5 100644 --- a/source/games/sw/src/input.cpp +++ b/source/games/sw/src/input.cpp @@ -34,9 +34,6 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms BEGIN_SW_NS -void DoPlayerTurnVehicle(PLAYER* pp, DAngle& plyaw, float avel, double z, double floor_dist); -void DoPlayerTurnTurret(PLAYER* pp, DAngle& plyaw, float avel); - static InputPacket loc; //--------------------------------------------------------------------------- @@ -181,25 +178,8 @@ void GameInterface::GetInput(const double scaleAdjust, InputPacket *packet) if (!SyncInput()) { - if ((pp->Flags2 & PF2_INPUT_CAN_AIM)) - { - pp->Angles.CameraAngles.Pitch += DAngle::fromDeg(input.horz); - } - - if ((pp->Flags2 & PF2_INPUT_CAN_TURN_GENERAL)) - { - pp->Angles.CameraAngles.Yaw += DAngle::fromDeg(input.avel); - } - - if ((pp->Flags2 & PF2_INPUT_CAN_TURN_VEHICLE)) - { - DoPlayerTurnVehicle(pp, pp->Angles.CameraAngles.Yaw, input.avel, pp->actor->getOffsetZ() + 10, abs(pp->actor->getOffsetZ() + 10 - pp->sop->floor_loz)); - } - - if ((pp->Flags2 & PF2_INPUT_CAN_TURN_TURRET)) - { - DoPlayerTurnTurret(pp, pp->Angles.CameraAngles.Yaw, input.avel); - } + pp->Angles.CameraAngles.Yaw += DAngle::fromDeg(input.avel); + pp->Angles.CameraAngles.Pitch += DAngle::fromDeg(input.horz); } if (packet) diff --git a/source/games/sw/src/interpso.cpp b/source/games/sw/src/interpso.cpp index 1ff68d8bc..8229b99e7 100644 --- a/source/games/sw/src/interpso.cpp +++ b/source/games/sw/src/interpso.cpp @@ -385,11 +385,9 @@ void so_updateinterpolations(void) // Stick at beginning of domovethings for (sop = SectorObject, interp = so_interpdata; sop < &SectorObject[MAX_SECTOR_OBJECTS]; sop++, interp++) { - bool skip = !SyncInput() && (sop->track == SO_TURRET); - if (SO_EMPTY(sop) || skip) + if (SO_EMPTY(sop)) continue; - if (interp->tic < interp->lasttic) interp->tic += synctics; for (i = 0, data = interp->data; i < interp->numinterpolations; i++, data++) @@ -436,11 +434,9 @@ void so_dointerpolations(double interpfrac) // Stick at beg for (sop = SectorObject, interp = so_interpdata; sop < &SectorObject[MAX_SECTOR_OBJECTS]; sop++, interp++) { - bool skip = !SyncInput() && (sop->track == SO_TURRET); - if (SO_EMPTY(sop) || skip) + if (SO_EMPTY(sop)) continue; - for (i = 0; i < interp->numinterpolations; i++) { auto actorofang = interp->data[i].actorofang; @@ -472,8 +468,7 @@ void so_dointerpolations(double interpfrac) // Stick at beg for (sop = SectorObject, interp = so_interpdata; sop < &SectorObject[MAX_SECTOR_OBJECTS]; sop++, interp++) { - bool skip = !SyncInput() && (sop->track == SO_TURRET); - if (SO_EMPTY(sop) || skip) + if (SO_EMPTY(sop)) continue; // Check if interpolation has been explicitly disabled @@ -542,8 +537,7 @@ void so_restoreinterpolations(void) // Stick at end of drawscree for (sop = SectorObject, interp = so_interpdata; sop < &SectorObject[MAX_SECTOR_OBJECTS]; sop++, interp++) { - bool skip = !SyncInput() && (sop->track == SO_TURRET); - if (SO_EMPTY(sop) || skip) + if (SO_EMPTY(sop)) continue; for (i = 0, data = interp->data; i < interp->numinterpolations; i++, data++) diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index a391e64a5..70e92ca8d 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -146,7 +146,6 @@ void DoPlayerFly(PLAYER* pp); void DoPlayerBeginClimb(PLAYER* pp); void DoPlayerClimb(PLAYER* pp); void DoPlayerBeginDie(PLAYER* pp); -void DoPlayerDie(PLAYER* pp); // void DoPlayerBeginOperateBoat(PLAYER* pp); void DoPlayerBeginOperateVehicle(PLAYER* pp); void DoPlayerBeginOperate(PLAYER* pp); @@ -1529,28 +1528,28 @@ void UpdatePlayerSpriteAngle(PLAYER* pp) // //--------------------------------------------------------------------------- -void DoPlayerTurnVehicle(PLAYER* pp, DAngle& plyaw, float avel, double zz, double floordist) +void DoPlayerTurnVehicle(PLAYER* pp, double zz, double floordist) { SECTOR_OBJECT* sop = pp->sop; if (sop->drive_angspeed) { float drive_oavel = pp->drive_avel; - pp->drive_avel = float((avel * sop->drive_angspeed + (drive_oavel * (sop->drive_angslide - 1))) / sop->drive_angslide); + pp->drive_avel = float((pp->input.avel * sop->drive_angspeed + (drive_oavel * (sop->drive_angslide - 1))) / sop->drive_angslide); - avel = pp->drive_avel; + pp->input.avel = pp->drive_avel; } else { - avel *= synctics * 0.125f; + pp->input.avel *= synctics * 0.125f; } - if (avel != 0) + if (pp->input.avel != 0) { - auto sum = plyaw + DAngle::fromDeg(avel); + auto sum = pp->actor->spr.Angles.Yaw + DAngle::fromDeg(pp->input.avel); if (MultiClipTurn(pp, sum, zz, floordist)) { - plyaw = sum; + pp->actor->spr.Angles.Yaw = sum; } } } @@ -1594,7 +1593,7 @@ void DoPlayerTurnVehicleRect(PLAYER* pp, DVector2* pos, DVector2* opos) // //--------------------------------------------------------------------------- -void DoPlayerTurnTurret(PLAYER* pp, DAngle& plyaw, float avel) +void DoPlayerTurnTurret(PLAYER* pp) { DAngle new_ang, diff; SECTOR_OBJECT* sop = pp->sop; @@ -1602,18 +1601,18 @@ void DoPlayerTurnTurret(PLAYER* pp, DAngle& plyaw, float avel) if (sop->drive_angspeed) { float drive_oavel = pp->drive_avel; - pp->drive_avel = float((avel * sop->drive_angspeed + (drive_oavel * (sop->drive_angslide - 1))) / sop->drive_angslide); + pp->drive_avel = float((pp->input.avel * sop->drive_angspeed + (drive_oavel * (sop->drive_angslide - 1))) / sop->drive_angslide); - avel = pp->drive_avel; + pp->input.avel = pp->drive_avel; } else { - avel = avel * synctics * 0.25f; + pp->input.avel = pp->input.avel * synctics * 0.25f; } - if (fabs(avel) >= FLT_EPSILON) + if (fabs(pp->input.avel) >= FLT_EPSILON) { - new_ang = plyaw + DAngle::fromDeg(avel); + new_ang = pp->actor->spr.Angles.Yaw + DAngle::fromDeg(pp->input.avel); if (sop->limit_ang_center >= nullAngle) { @@ -1628,10 +1627,10 @@ void DoPlayerTurnTurret(PLAYER* pp, DAngle& plyaw, float avel) } } - plyaw = new_ang; + pp->actor->spr.Angles.Yaw = new_ang; } - OperateSectorObject(pp->sop, plyaw, pp->sop->pmid); + OperateSectorObject(pp->sop, pp->actor->spr.Angles.Yaw, pp->sop->pmid); } //--------------------------------------------------------------------------- @@ -2026,11 +2025,7 @@ void DoPlayerMove(PLAYER* pp) pp->Angles.doViewYaw(&pp->input); - if (!SyncInput()) - { - pp->Flags2 |= (PF2_INPUT_CAN_TURN_GENERAL); - } - else + if (SyncInput()) { pp->actor->spr.Angles.Yaw += DAngle::fromDeg(pp->input.avel); } @@ -2154,11 +2149,7 @@ void DoPlayerMove(PLAYER* pp) DoPlayerSetWadeDepth(pp); - if (!SyncInput()) - { - pp->Flags2 |= (PF2_INPUT_CAN_AIM); - } - else + if (SyncInput()) { pp->actor->spr.Angles.Pitch += DAngle::fromDeg(pp->input.horz); } @@ -2581,9 +2572,6 @@ void DoPlayerMoveVehicle(PLAYER* pp) PlaySOsound(pp->sop->mid_sector,SO_IDLE_SOUND); } - // force synchronised input here for now. - setForcedSyncInput(); - if (PLAYER_MOVING(pp) == 0) pp->Flags &= ~(PF_PLAYER_MOVED); else @@ -2695,14 +2683,8 @@ void DoPlayerMoveVehicle(PLAYER* pp) } else { - if (!SyncInput()) - { - pp->Flags2 |= (PF2_INPUT_CAN_TURN_VEHICLE); - } - else - { - DoPlayerTurnVehicle(pp, pp->actor->spr.Angles.Yaw, pp->input.avel, zz, floordist); - } + setForcedSyncInput(); + DoPlayerTurnVehicle(pp, zz, floordist); auto save_cstat = plActor->spr.cstat; plActor->spr.cstat &= ~(CSTAT_SPRITE_BLOCK); @@ -2741,11 +2723,7 @@ void DoPlayerMoveVehicle(PLAYER* pp) OperateSectorObject(pp->sop, pp->actor->spr.Angles.Yaw, pp->actor->spr.pos.XY()); pp->cursector = save_sect; // for speed - if (!SyncInput()) - { - pp->Flags2 |= (PF2_INPUT_CAN_AIM); - } - else + if (SyncInput()) { pp->actor->spr.Angles.Pitch += DAngle::fromDeg(pp->input.horz); } @@ -2773,25 +2751,15 @@ void DoPlayerMoveTurret(PLAYER* pp) PlaySOsound(pp->sop->mid_sector, SO_IDLE_SOUND); } - if (!SyncInput()) - { - pp->Flags2 |= (PF2_INPUT_CAN_TURN_TURRET); - } - else - { - DoPlayerTurnTurret(pp, pp->actor->spr.Angles.Yaw, pp->input.avel); - } + setForcedSyncInput(); + DoPlayerTurnTurret(pp); if (PLAYER_MOVING(pp) == 0) pp->Flags &= ~(PF_PLAYER_MOVED); else pp->Flags |= (PF_PLAYER_MOVED); - if (!SyncInput()) - { - pp->Flags2 |= (PF2_INPUT_CAN_AIM); - } - else + if (SyncInput()) { pp->actor->spr.Angles.Pitch += DAngle::fromDeg(pp->input.horz); } @@ -3389,11 +3357,7 @@ void DoPlayerClimb(PLAYER* pp) // setsprite to players location ChangeActorSect(pp->actor, pp->cursector); - if (!SyncInput()) - { - pp->Flags2 |= (PF2_INPUT_CAN_AIM); - } - else + if (SyncInput()) { pp->actor->spr.Angles.Pitch += DAngle::fromDeg(pp->input.horz); } @@ -5904,6 +5868,7 @@ void DoPlayerBeginDie(PLAYER* pp) pp->Flags |= (PF_DEAD); plActor->user.Flags &= ~(SPR_BOUNCE); pp->Flags &= ~(PF_HEAD_CONTROL); + setForcedSyncInput(); } //--------------------------------------------------------------------------- @@ -5996,14 +5961,7 @@ void DoPlayerDeathFollowKiller(PLAYER* pp) // allow turning if (pp->Flags & (PF_DEAD_HEAD|PF_HEAD_CONTROL)) { - if (!SyncInput()) - { - pp->Flags2 |= (PF2_INPUT_CAN_TURN_GENERAL); - } - else - { - pp->actor->spr.Angles.Yaw += DAngle::fromDeg(pp->input.avel); - } + pp->actor->spr.Angles.Yaw += DAngle::fromDeg(pp->input.avel); UpdatePlayerSpriteAngle(pp); } @@ -6996,18 +6954,13 @@ void domovethings(void) { WeaponOperate(pp); PlayerOperateEnv(pp); + resetForcedSyncInput(); } // do for moving sectors DoPlayerSectorUpdatePreMove(pp); ChopsCheck(pp); - // Reset flags used while tying input to framerate - pp->Flags2 &= ~(PF2_INPUT_CAN_AIM|PF2_INPUT_CAN_TURN_GENERAL|PF2_INPUT_CAN_TURN_VEHICLE|PF2_INPUT_CAN_TURN_TURRET); - - // disable synchronised input if set by game. - resetForcedSyncInput(); - // convert fvel/svel into a vector before performing actions. const auto velvect = DVector2(pp->input.fvel, pp->input.svel).Rotated(pp->actor->spr.Angles.Yaw); pp->input.fvel = (float)velvect.X; From b1888a44c35a23e48794cbb9a4e636f3ca181072 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sat, 18 Mar 2023 13:23:19 +1100 Subject: [PATCH 48/67] - SW: Process weapon bits within the ticker and not the input handler. --- source/games/sw/src/input.cpp | 15 +++++++-------- source/games/sw/src/player.cpp | 4 ++++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/source/games/sw/src/input.cpp b/source/games/sw/src/input.cpp index e72b90dc5..49fca0d1c 100644 --- a/source/games/sw/src/input.cpp +++ b/source/games/sw/src/input.cpp @@ -77,13 +77,13 @@ enum // //--------------------------------------------------------------------------- -static void processWeapon(PLAYER* const pp) +void processWeapon(PLAYER* const pp) { DSWActor* plActor = pp->actor; if (plActor == nullptr) return; int i; - if (loc.getNewWeapon() == WeaponSel_Next) + if (pp->input.getNewWeapon() == WeaponSel_Next) { int next_weapon = plActor->user.WeaponNum + 1; int start_weapon; @@ -116,9 +116,9 @@ static void processWeapon(PLAYER* const pp) } } - loc.setNewWeapon(next_weapon + 1); + pp->input.setNewWeapon(next_weapon + 1); } - else if (loc.getNewWeapon() == WeaponSel_Prev) + else if (pp->input.getNewWeapon() == WeaponSel_Prev) { int prev_weapon = plActor->user.WeaponNum - 1; int start_weapon; @@ -148,12 +148,12 @@ static void processWeapon(PLAYER* const pp) } } } - loc.setNewWeapon(prev_weapon + 1); + pp->input.setNewWeapon(prev_weapon + 1); } - else if (loc.getNewWeapon() == WeaponSel_Alt) + else if (pp->input.getNewWeapon() == WeaponSel_Alt) { int which_weapon = plActor->user.WeaponNum + 1; - loc.setNewWeapon(which_weapon); + pp->input.setNewWeapon(which_weapon); } } @@ -174,7 +174,6 @@ void GameInterface::GetInput(const double scaleAdjust, InputPacket *packet) ApplyGlobalInput(loc, &hidInput); processMovement(&input, &loc, &hidInput, scaleAdjust, 0, !pp->sop, pp->sop_control ? 3. / 1.40625 : 1.); - processWeapon(pp); if (!SyncInput()) { diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index 70e92ca8d..97c93c4e8 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -173,6 +173,7 @@ int GetOverlapSector2(const DVector2& pos, sectortype** over, sectortype** under void PlayerToRemote(PLAYER* pp); void PlayerRemoteInit(PLAYER* pp); void PlayerSpawnPosition(PLAYER* pp); +void processWeapon(PLAYER* const pp); extern short target_ang; @@ -6944,6 +6945,9 @@ void domovethings(void) } } + // process weapon bits + processWeapon(pp); + // auto tracking mode for single player multi-game if (numplayers <= 1 && PlayerTrackingMode && pnum == screenpeek && screenpeek != myconnectindex) { From 5a6495956f7710d2ef95347f61513cb71a32c1e5 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sat, 18 Mar 2023 13:26:15 +1100 Subject: [PATCH 49/67] - Duke: Move `Quick_Kick` button test into `ApplyGlobalInput()` as it doesn't seem to share a bit with any other game anymore. --- source/core/inputstate.cpp | 3 +++ source/games/duke/src/input.cpp | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/core/inputstate.cpp b/source/core/inputstate.cpp index b43ff16b4..d7564908f 100644 --- a/source/core/inputstate.cpp +++ b/source/core/inputstate.cpp @@ -449,5 +449,8 @@ void ApplyGlobalInput(InputPacket& input, HIDInput* const hidInput) if (buttonMap.ButtonDown(gamefunc_Look_Right)) input.actions |= SB_LOOK_RIGHT; + if (buttonMap.ButtonDown(gamefunc_Quick_Kick)) + input.actions |= SB_QUICK_KICK; + } diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 57c818dbf..395bd6d7d 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -547,9 +547,6 @@ static void processInputBits(player_struct *p, HIDInput* const hidInput) } 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 ((isRR() && p->drink_amt > 88)) loc.actions |= SB_LOOK_LEFT; if ((isRR() && p->drink_amt > 99)) loc.actions |= SB_LOOK_DOWN; } From 37dda1aa0e9f0046cdc5decf7e4e609d4fd129f6 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sat, 18 Mar 2023 19:19:20 +1100 Subject: [PATCH 50/67] - Duke: Move input bit pre-processing into `hud_input()`. * Really, _really_ need to do something about this `crouch_toggle` malarkey... --- source/games/duke/src/input.cpp | 62 ++++++++++++++------------------- 1 file changed, 26 insertions(+), 36 deletions(-) diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 395bd6d7d..49e2f0400 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -73,6 +73,31 @@ void hud_input(int plnum) // Backup weapon here as hud_input() is the first function where any one of the weapon variables can change. p->backupweapon(); + // Set-up crouch bools. + const int sectorLotag = p->insector() ? p->cursector->lotag : 0; + const bool crouchable = sectorLotag != ST_2_UNDERWATER && (sectorLotag != ST_1_ABOVE_WATER || p->spritebridge); + const bool disableToggle = p->jetpack_on || (!crouchable && p->on_ground) || (isRRRA() && (p->OnMotorcycle || p->OnBoat)); + + if (isRR() && (p->sync.actions & SB_CROUCH)) p->sync.actions &= ~SB_JUMP; + + if (crouch_toggle && (!crouchable || disableToggle)) + { + crouch_toggle = false; + p->sync.actions &= ~SB_CROUCH; + } + + if (p->OnMotorcycle || p->OnBoat) + { + // mask out all actions not compatible with vehicles. + p->sync.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 ((isRR() && p->drink_amt > 88)) p->sync.actions |= SB_LOOK_LEFT; + if ((isRR() && p->drink_amt > 99)) p->sync.actions |= SB_LOOK_DOWN; + } + if (isRR()) { if (PlayerInput(plnum, SB_QUICK_KICK) && p->last_pissed_time == 0) @@ -517,41 +542,6 @@ enum static constexpr float VEHICLETURN = (20.f * 360.f / 2048.f); -//--------------------------------------------------------------------------- -// -// handles the input bits -// -//--------------------------------------------------------------------------- - -static void processInputBits(player_struct *p, HIDInput* const hidInput) -{ - // Set-up crouch bools. - int const sectorLotag = p->insector() ? p->cursector->lotag : 0; - bool const crouchable = sectorLotag != ST_2_UNDERWATER && (sectorLotag != ST_1_ABOVE_WATER || p->spritebridge); - bool const disableToggle = p->jetpack_on || (!crouchable && p->on_ground) || (isRRRA() && (p->OnMotorcycle || p->OnBoat)); - - ApplyGlobalInput(loc, hidInput); - if (isRR() && (loc.actions & SB_CROUCH)) loc.actions &= ~SB_JUMP; - - if (crouch_toggle && (!crouchable || disableToggle)) - { - crouch_toggle = false; - loc.actions &= ~SB_CROUCH; - } - - 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 ((isRR() && p->drink_amt > 88)) loc.actions |= SB_LOOK_LEFT; - if ((isRR() && p->drink_amt > 99)) loc.actions |= SB_LOOK_DOWN; - } -} - //--------------------------------------------------------------------------- // // split out for readability @@ -822,7 +812,7 @@ void GameInterface::GetInput(const double scaleAdjust, InputPacket* packet) auto const p = &ps[myconnectindex]; InputPacket input{}; - processInputBits(p, &hidInput); + ApplyGlobalInput(loc, &hidInput); if (isRRRA() && (p->OnMotorcycle || p->OnBoat)) { From 51a20211f367582145b0d74678ee4dfd79df0529 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sat, 18 Mar 2023 12:10:29 +1100 Subject: [PATCH 51/67] - Duke: Tidy up some repeated bools in vehicle input code. --- source/games/duke/src/input.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 49e2f0400..034fbd919 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -557,13 +557,13 @@ static float motoApplyTurn(player_struct* p, HIDInput* const hidInput, bool cons { resetTurnHeldAmt(); - if (kbdLeft || hidInput->mouseturnx < 0 || hidInput->joyaxes[JOYAXIS_Yaw] > 0) + if (p->vehTurnLeft) { p->TiltStatus -= (float)factor; if (p->TiltStatus < -10) p->TiltStatus = -10; } - else if (kbdRight || hidInput->mouseturnx > 0 || hidInput->joyaxes[JOYAXIS_Yaw] < 0) + else if (p->vehTurnRight) { p->TiltStatus += (float)factor; if (p->TiltStatus > 10) @@ -572,12 +572,12 @@ static float motoApplyTurn(player_struct* p, HIDInput* const hidInput, bool cons } else { - if (kbdLeft || kbdRight || p->moto_drink || hidInput->mouseturnx || hidInput->joyaxes[JOYAXIS_Yaw]) + if (p->vehTurnLeft || p->vehTurnRight || p->moto_drink) { constexpr float velScale = (3.f / 10.f); const float baseVel = (buttonMap.ButtonDown(gamefunc_Move_Backward) || hidInput->joyaxes[JOYAXIS_Forward] < 0) && p->MotoSpeed <= 0 ? -VEHICLETURN : VEHICLETURN; - if (kbdLeft || p->moto_drink < 0 || hidInput->mouseturnx < 0 || hidInput->joyaxes[JOYAXIS_Yaw] > 0) + if (p->vehTurnLeft || p->moto_drink < 0) { p->TiltStatus -= (float)factor; @@ -596,7 +596,7 @@ static float motoApplyTurn(player_struct* p, HIDInput* const hidInput, bool cons updateTurnHeldAmt(factor); } - if (kbdRight || p->moto_drink > 0 || hidInput->mouseturnx > 0 || hidInput->joyaxes[JOYAXIS_Yaw] < 0) + if (p->vehTurnRight || p->moto_drink > 0) { p->TiltStatus += (float)factor; @@ -645,12 +645,12 @@ static float boatApplyTurn(player_struct *p, HIDInput* const hidInput, bool cons if (p->MotoSpeed) { - if (kbdLeft || kbdRight || p->moto_drink || hidInput->mouseturnx || hidInput->joyaxes[JOYAXIS_Yaw]) + if (p->vehTurnLeft || p->vehTurnRight || p->moto_drink) { const float velScale = !p->NotOnWater? 1.f : (6.f / 19.f); const float baseVel = VEHICLETURN * velScale; - if (kbdLeft || p->moto_drink < 0 || hidInput->mouseturnx < 0 || hidInput->joyaxes[JOYAXIS_Yaw] > 0) + if (p->vehTurnLeft || p->moto_drink < 0) { if (!p->NotOnWater) { @@ -671,7 +671,7 @@ static float boatApplyTurn(player_struct *p, HIDInput* const hidInput, bool cons updateTurnHeldAmt(factor); } - if (kbdRight || p->moto_drink > 0 || hidInput->mouseturnx > 0 || hidInput->joyaxes[JOYAXIS_Yaw] < 0) + if (p->vehTurnRight || p->moto_drink > 0) { if (!p->NotOnWater) { From 401236980c86090b31638487a52f50e235ef4ea0 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sat, 18 Mar 2023 12:14:20 +1100 Subject: [PATCH 52/67] - Duke: Tidy up some unnecessarily deep branches in vehicle input code. --- source/games/duke/src/input.cpp | 191 +++++++++++++++----------------- 1 file changed, 88 insertions(+), 103 deletions(-) diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 034fbd919..af6fd177c 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -570,60 +570,57 @@ static float motoApplyTurn(player_struct* p, HIDInput* const hidInput, bool cons p->TiltStatus = 10; } } + else if (p->vehTurnLeft || p->vehTurnRight || p->moto_drink) + { + constexpr float velScale = (3.f / 10.f); + const float baseVel = (buttonMap.ButtonDown(gamefunc_Move_Backward) || hidInput->joyaxes[JOYAXIS_Forward] < 0) && p->MotoSpeed <= 0 ? -VEHICLETURN : VEHICLETURN; + + if (p->vehTurnLeft || p->moto_drink < 0) + { + p->TiltStatus -= (float)factor; + + if (p->TiltStatus < -10) + p->TiltStatus = -10; + + if (kbdLeft) + turnvel -= isTurboTurnTime() && p->MotoSpeed > 0 ? baseVel : baseVel * velScale; + + if (hidInput->mouseturnx < 0) + turnvel -= Sgn(baseVel) * sqrtf(abs(p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * -(hidInput->mouseturnx / factor) * (7.f / 20.f)); + + if (hidInput->joyaxes[JOYAXIS_Yaw] > 0) + turnvel += (p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * hidInput->joyaxes[JOYAXIS_Yaw]; + + updateTurnHeldAmt(factor); + } + + if (p->vehTurnRight || p->moto_drink > 0) + { + p->TiltStatus += (float)factor; + + if (p->TiltStatus > 10) + p->TiltStatus = 10; + + if (kbdRight) + turnvel += isTurboTurnTime() && p->MotoSpeed > 0 ? baseVel : baseVel * velScale; + + if (hidInput->mouseturnx > 0) + turnvel += Sgn(baseVel) * sqrtf(abs(p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * (hidInput->mouseturnx / factor) * (7.f / 20.f)); + + if (hidInput->joyaxes[JOYAXIS_Yaw] < 0) + turnvel += (p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * hidInput->joyaxes[JOYAXIS_Yaw]; + + updateTurnHeldAmt(factor); + } + } else { - if (p->vehTurnLeft || p->vehTurnRight || p->moto_drink) - { - constexpr float velScale = (3.f / 10.f); - const float baseVel = (buttonMap.ButtonDown(gamefunc_Move_Backward) || hidInput->joyaxes[JOYAXIS_Forward] < 0) && p->MotoSpeed <= 0 ? -VEHICLETURN : VEHICLETURN; + resetTurnHeldAmt(); - if (p->vehTurnLeft || p->moto_drink < 0) - { - p->TiltStatus -= (float)factor; - - if (p->TiltStatus < -10) - p->TiltStatus = -10; - - if (kbdLeft) - turnvel -= isTurboTurnTime() && p->MotoSpeed > 0 ? baseVel : baseVel * velScale; - - if (hidInput->mouseturnx < 0) - turnvel -= Sgn(baseVel) * sqrtf(abs(p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * -(hidInput->mouseturnx / factor) * (7.f / 20.f)); - - if (hidInput->joyaxes[JOYAXIS_Yaw] > 0) - turnvel += (p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * hidInput->joyaxes[JOYAXIS_Yaw]; - - updateTurnHeldAmt(factor); - } - - if (p->vehTurnRight || p->moto_drink > 0) - { - p->TiltStatus += (float)factor; - - if (p->TiltStatus > 10) - p->TiltStatus = 10; - - if (kbdRight) - turnvel += isTurboTurnTime() && p->MotoSpeed > 0 ? baseVel : baseVel * velScale; - - if (hidInput->mouseturnx > 0) - turnvel += Sgn(baseVel) * sqrtf(abs(p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * (hidInput->mouseturnx / factor) * (7.f / 20.f)); - - if (hidInput->joyaxes[JOYAXIS_Yaw] < 0) - turnvel += (p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * hidInput->joyaxes[JOYAXIS_Yaw]; - - updateTurnHeldAmt(factor); - } - } - else - { - resetTurnHeldAmt(); - - if (p->TiltStatus > 0) - p->TiltStatus -= (float)factor; - else if (p->TiltStatus < 0) - p->TiltStatus += (float)factor; - } + if (p->TiltStatus > 0) + p->TiltStatus -= (float)factor; + else if (p->TiltStatus < 0) + p->TiltStatus += (float)factor; } if (fabs(p->TiltStatus) < factor) @@ -643,63 +640,51 @@ static float boatApplyTurn(player_struct *p, HIDInput* const hidInput, bool cons float turnvel = 0; p->oTiltStatus = p->TiltStatus; - if (p->MotoSpeed) + if (p->MotoSpeed && (p->vehTurnLeft || p->vehTurnRight || p->moto_drink)) { - if (p->vehTurnLeft || p->vehTurnRight || p->moto_drink) + const float velScale = !p->NotOnWater? 1.f : (6.f / 19.f); + const float baseVel = VEHICLETURN * velScale; + + if (p->vehTurnLeft || p->moto_drink < 0) { - const float velScale = !p->NotOnWater? 1.f : (6.f / 19.f); - const float baseVel = VEHICLETURN * velScale; - - if (p->vehTurnLeft || p->moto_drink < 0) + if (!p->NotOnWater) { - if (!p->NotOnWater) - { - p->TiltStatus -= (float)factor; - if (p->TiltStatus < -10) - p->TiltStatus = -10; - } - - if (kbdLeft) - turnvel -= isTurboTurnTime() ? baseVel : baseVel * velScale; - - if (hidInput->mouseturnx < 0) - turnvel -= Sgn(baseVel) * sqrtf(abs(baseVel) * -(hidInput->mouseturnx / factor) * (7.f / 20.f)); - - if (hidInput->joyaxes[JOYAXIS_Yaw] > 0) - turnvel += baseVel * hidInput->joyaxes[JOYAXIS_Yaw]; - - updateTurnHeldAmt(factor); - } - - if (p->vehTurnRight || p->moto_drink > 0) - { - if (!p->NotOnWater) - { - p->TiltStatus += (float)factor; - if (p->TiltStatus > 10) - p->TiltStatus = 10; - } - - if (kbdRight) - turnvel += isTurboTurnTime() ? baseVel : baseVel * velScale; - - if (hidInput->mouseturnx > 0) - turnvel += Sgn(baseVel) * sqrtf(abs(baseVel) * (hidInput->mouseturnx / factor) * (7.f / 20.f)); - - if (hidInput->joyaxes[JOYAXIS_Yaw] < 0) - turnvel += baseVel * hidInput->joyaxes[JOYAXIS_Yaw]; - - updateTurnHeldAmt(factor); - } - } - else if (!p->NotOnWater) - { - resetTurnHeldAmt(); - - if (p->TiltStatus > 0) p->TiltStatus -= (float)factor; - else if (p->TiltStatus < 0) + if (p->TiltStatus < -10) + p->TiltStatus = -10; + } + + if (kbdLeft) + turnvel -= isTurboTurnTime() ? baseVel : baseVel * velScale; + + if (hidInput->mouseturnx < 0) + turnvel -= Sgn(baseVel) * sqrtf(abs(baseVel) * -(hidInput->mouseturnx / factor) * (7.f / 20.f)); + + if (hidInput->joyaxes[JOYAXIS_Yaw] > 0) + turnvel += baseVel * hidInput->joyaxes[JOYAXIS_Yaw]; + + updateTurnHeldAmt(factor); + } + + if (p->vehTurnRight || p->moto_drink > 0) + { + if (!p->NotOnWater) + { p->TiltStatus += (float)factor; + if (p->TiltStatus > 10) + p->TiltStatus = 10; + } + + if (kbdRight) + turnvel += isTurboTurnTime() ? baseVel : baseVel * velScale; + + if (hidInput->mouseturnx > 0) + turnvel += Sgn(baseVel) * sqrtf(abs(baseVel) * (hidInput->mouseturnx / factor) * (7.f / 20.f)); + + if (hidInput->joyaxes[JOYAXIS_Yaw] < 0) + turnvel += baseVel * hidInput->joyaxes[JOYAXIS_Yaw]; + + updateTurnHeldAmt(factor); } } else if (!p->NotOnWater) From 5fe4b0fdb1b5ad955da4bbf3d20492117d0c406a Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sat, 18 Mar 2023 12:44:37 +1100 Subject: [PATCH 53/67] - Exhumed: Eliminate `inita` global. --- source/games/exhumed/src/bubbles.cpp | 4 +++- source/games/exhumed/src/engine.h | 1 - source/games/exhumed/src/exhumed.cpp | 3 +-- source/games/exhumed/src/init.cpp | 17 +++++++---------- source/games/exhumed/src/input.cpp | 2 -- source/games/exhumed/src/move.cpp | 1 - source/games/exhumed/src/osdcmds.cpp | 5 ++++- source/games/exhumed/src/player.cpp | 13 ------------- source/games/exhumed/src/player.h | 1 - source/games/exhumed/src/sound.cpp | 6 ++++-- source/games/exhumed/src/view.cpp | 7 ------- 11 files changed, 19 insertions(+), 41 deletions(-) diff --git a/source/games/exhumed/src/bubbles.cpp b/source/games/exhumed/src/bubbles.cpp index 414bde9e5..f33e6345f 100644 --- a/source/games/exhumed/src/bubbles.cpp +++ b/source/games/exhumed/src/bubbles.cpp @@ -22,6 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "sequence.h" #include "mapinfo.h" #include +#include "player.h" BEGIN_PS_NS @@ -53,6 +54,7 @@ DExhumedActor* BuildBubble(const DVector3& pos, sectortype* pSector) } auto pActor = insertActor(pSector, 402); + auto pPlayerActor = PlayerList[nLocalPlayer].pActor; pActor->spr.pos = pos; pActor->spr.cstat = 0; @@ -63,7 +65,7 @@ DExhumedActor* BuildBubble(const DVector3& pos, sectortype* pSector) pActor->spr.xoffset = 0; pActor->spr.yoffset = 0; pActor->spr.picnum = 1; - pActor->spr.Angles.Yaw = inita; + pActor->spr.Angles.Yaw = pPlayerActor->spr.Angles.Yaw; pActor->vel.X = 0; pActor->vel.Y = 0; pActor->vel.Z = -1200 / 256.; diff --git a/source/games/exhumed/src/engine.h b/source/games/exhumed/src/engine.h index 764a1cab7..496c5bd62 100644 --- a/source/games/exhumed/src/engine.h +++ b/source/games/exhumed/src/engine.h @@ -57,7 +57,6 @@ enum { }; extern DVector3 initpos; -extern DAngle inita; extern sectortype* initsectp; extern int nCurChunkNum; diff --git a/source/games/exhumed/src/exhumed.cpp b/source/games/exhumed/src/exhumed.cpp index 0bb0d9963..35f5bb7c3 100644 --- a/source/games/exhumed/src/exhumed.cpp +++ b/source/games/exhumed/src/exhumed.cpp @@ -369,7 +369,6 @@ void GameInterface::Ticker() { // this must be done before the view is backed up. PlayerList[nLocalPlayer].Angles.resetCameraAngles(); - UpdatePlayerSpriteAngle(&PlayerList[nLocalPlayer]); // disable synchronised input if set by game. resetForcedSyncInput(); @@ -381,7 +380,7 @@ void GameInterface::Ticker() auto& lPlayerVel = PlayerList[nLocalPlayer].vel; - auto inputvect = DVector2(PlayerList[nLocalPlayer].input.fvel, PlayerList[nLocalPlayer].input.svel).Rotated(inita) * 0.375; + auto inputvect = DVector2(PlayerList[nLocalPlayer].input.fvel, PlayerList[nLocalPlayer].input.svel).Rotated(PlayerList[nLocalPlayer].pActor->spr.Angles.Yaw) * 0.375; for (int i = 0; i < 4; i++) { diff --git a/source/games/exhumed/src/init.cpp b/source/games/exhumed/src/init.cpp index cc6277a4b..de752aca7 100644 --- a/source/games/exhumed/src/init.cpp +++ b/source/games/exhumed/src/init.cpp @@ -40,7 +40,6 @@ enum }; DVector3 initpos; -DAngle inita; sectortype* initsectp; int nCurChunkNum = 0; @@ -147,7 +146,6 @@ uint8_t LoadLevel(MapRecord* map) SpawnSpriteDef spawned; int16_t mapang; loadMap(currentLevel->fileName, 0, &initpos, &mapang, &initsect, spawned); - inita = DAngle::fromBuild(mapang); initsectp = initsect; auto actors = spawnactors(spawned); @@ -164,6 +162,13 @@ uint8_t LoadLevel(MapRecord* map) precache(); LoadObjects(actors); + + for (int i = 0; i < nTotalPlayers; i++) + { + SetSavePoint(i, initpos, initsectp, DAngle::fromBuild(mapang)); + RestartPlayer(i); + InitPlayerKeys(i); + } return true; } @@ -180,13 +185,6 @@ void InitLevel(MapRecord* map) if (!LoadLevel(map)) { I_Error("Cannot load %s...\n", map->fileName.GetChars()); } - - for (int i = 0; i < nTotalPlayers; i++) - { - SetSavePoint(i, initpos, initsectp, inita); - RestartPlayer(i); - InitPlayerKeys(i); - } EndLevel = 0; ResetView(); ResetEngine(); @@ -854,7 +852,6 @@ void SerializeInit(FSerializer& arc) if (arc.BeginObject("init")) { arc("init", initpos) - ("inita", inita) ("initsect", initsectp) ("curchunk", nCurChunkNum) .Array("counters", Counters, kNumCounters) diff --git a/source/games/exhumed/src/input.cpp b/source/games/exhumed/src/input.cpp index 275be4165..e460ab936 100644 --- a/source/games/exhumed/src/input.cpp +++ b/source/games/exhumed/src/input.cpp @@ -85,8 +85,6 @@ void GameInterface::GetInput(const double scaleAdjust, InputPacket* packet) { pPlayer->bPlayerPan = pPlayer->bLockPan = true; } - - UpdatePlayerSpriteAngle(pPlayer); } if (packet) diff --git a/source/games/exhumed/src/move.cpp b/source/games/exhumed/src/move.cpp index b96095163..4b5114f25 100644 --- a/source/games/exhumed/src/move.cpp +++ b/source/games/exhumed/src/move.cpp @@ -945,7 +945,6 @@ void MoveSector(sectortype* pSector, DAngle nAngle, DVector2& nVel) */ auto pActor = PlayerList[nLocalPlayer].pActor; initpos = pActor->spr.pos; - inita = pActor->spr.Angles.Yaw; initsectp = pActor->sector(); } diff --git a/source/games/exhumed/src/osdcmds.cpp b/source/games/exhumed/src/osdcmds.cpp index 3d795cf5c..dda1f0926 100644 --- a/source/games/exhumed/src/osdcmds.cpp +++ b/source/games/exhumed/src/osdcmds.cpp @@ -73,13 +73,16 @@ static int osdcmd_doors(CCmdFuncPtr parm) static int osdcmd_spawn(CCmdFuncPtr parm) { + auto pActor = PlayerList[nLocalPlayer].pActor; if (parm->numparms != 1) return CCMD_SHOWHELP; + if (!pActor) return CCMD_SHOWHELP; auto c = parm->parms[0]; auto sectp = initsectp; + auto inita = pActor->spr.Angles.Yaw; if (!stricmp(c, "anubis")) BuildAnubis(nullptr, initpos, sectp, inita, false); else if (!stricmp(c, "spider")) BuildSpider(nullptr, initpos, sectp, inita); else if (!stricmp(c, "mummy")) BuildMummy(nullptr, initpos, sectp, inita); - else if (!stricmp(c, "fish")) BuildFish(nullptr, initpos.plusZ(PlayerList[nLocalPlayer].pActor->viewzoffset), sectp, inita); + else if (!stricmp(c, "fish")) BuildFish(nullptr, initpos.plusZ(pActor->viewzoffset), sectp, inita); else if (!stricmp(c, "lion")) BuildLion(nullptr, initpos, sectp, inita); else if (!stricmp(c, "lava")) BuildLava(nullptr, initpos, sectp, inita, nNetPlayerCount); else if (!stricmp(c, "rex")) BuildRex(nullptr, initpos, sectp, inita, nNetPlayerCount); diff --git a/source/games/exhumed/src/player.cpp b/source/games/exhumed/src/player.cpp index 442a17a96..200cb7039 100644 --- a/source/games/exhumed/src/player.cpp +++ b/source/games/exhumed/src/player.cpp @@ -664,17 +664,6 @@ static void pickupMessage(int no) // //--------------------------------------------------------------------------- -void UpdatePlayerSpriteAngle(Player* pPlayer) -{ - if (pPlayer->pActor) inita = pPlayer->pActor->spr.Angles.Yaw.Normalized360(); -} - -//--------------------------------------------------------------------------- -// -// -// -//--------------------------------------------------------------------------- - void AIPlayer::Draw(RunListEvent* ev) { int nPlayer = RunData[ev->nRun].nObjIndex; @@ -987,7 +976,6 @@ void AIPlayer::Tick(RunListEvent* ev) } PlayerList[nPlayer].Angles.doYawKeys(&PlayerList[nLocalPlayer].input); - UpdatePlayerSpriteAngle(&PlayerList[nPlayer]); // player.zvel is modified within Gravity() double zVel = pPlayerActor->vel.Z; @@ -2600,7 +2588,6 @@ sectdone: { initpos = pPlayerActor->spr.pos; initsectp = pPlayerActor->sector(); - inita = pPlayerActor->spr.Angles.Yaw; } if (!PlayerList[nPlayer].nHealth) diff --git a/source/games/exhumed/src/player.h b/source/games/exhumed/src/player.h index dceddcb9f..777d582e8 100644 --- a/source/games/exhumed/src/player.h +++ b/source/games/exhumed/src/player.h @@ -122,7 +122,6 @@ int GetPlayerFromActor(DExhumedActor* actor); void SetPlayerMummified(int nPlayer, int bIsMummified); int AddAmmo(int nPlayer, int nWeapon, int nAmmoAmount); void ShootStaff(int nPlayer); -void UpdatePlayerSpriteAngle(Player* pPlayer); END_PS_NS diff --git a/source/games/exhumed/src/sound.cpp b/source/games/exhumed/src/sound.cpp index 6b4d49f53..1b19b2ad8 100644 --- a/source/games/exhumed/src/sound.cpp +++ b/source/games/exhumed/src/sound.cpp @@ -500,6 +500,8 @@ void GameInterface::UpdateSounds() if (nFreeze) return; + const auto pActor = PlayerList[nLocalPlayer].pActor; + DVector3 pos; DAngle ang; if (nSnakeCam > -1) @@ -508,10 +510,10 @@ void GameInterface::UpdateSounds() pos = pSnake->pSprites[0]->spr.pos; ang = pSnake->pSprites[0]->spr.Angles.Yaw; } - else + else if (pActor) { pos = initpos; - ang = inita; + ang = pActor->spr.Angles.Yaw; } SoundListener listener; listener.angle = float(-ang.Radians()); // Build uses a period of 2048. diff --git a/source/games/exhumed/src/view.cpp b/source/games/exhumed/src/view.cpp index 835a82400..cf3b3edda 100644 --- a/source/games/exhumed/src/view.cpp +++ b/source/games/exhumed/src/view.cpp @@ -204,7 +204,6 @@ void DrawView(double interpfrac, bool sceneonly) // update render angles. pPlayer->Angles.updateCameraAngles(interpfrac); - UpdatePlayerSpriteAngle(pPlayer); if (nSnakeCam >= 0 && !sceneonly) { @@ -342,12 +341,6 @@ void DrawView(double interpfrac, bool sceneonly) if (ang2.Degrees() < 0) ang2 = -ang2; - if (ang2 > mapangle(10)) - { - inita -= ang2 * (1. / 8.); - return; - } - if (bSubTitles) { subtitleOverlay.Start(I_GetTimeNS() * (120. / 1'000'000'000)); From d30ce9691af9258f1d4609cfd3727731964d7ec0 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sat, 18 Mar 2023 12:49:44 +1100 Subject: [PATCH 54/67] - Exhumed: Eliminate `initpos` global. --- source/games/exhumed/src/engine.h | 1 - source/games/exhumed/src/init.cpp | 9 +++------ source/games/exhumed/src/move.cpp | 1 - source/games/exhumed/src/osdcmds.cpp | 1 + source/games/exhumed/src/player.cpp | 1 - source/games/exhumed/src/sequence.cpp | 2 +- source/games/exhumed/src/sound.cpp | 6 +++--- 7 files changed, 8 insertions(+), 13 deletions(-) diff --git a/source/games/exhumed/src/engine.h b/source/games/exhumed/src/engine.h index 496c5bd62..de4c39f03 100644 --- a/source/games/exhumed/src/engine.h +++ b/source/games/exhumed/src/engine.h @@ -56,7 +56,6 @@ enum { kSectLava = 0x4000, }; -extern DVector3 initpos; extern sectortype* initsectp; extern int nCurChunkNum; diff --git a/source/games/exhumed/src/init.cpp b/source/games/exhumed/src/init.cpp index de752aca7..5a7b667b8 100644 --- a/source/games/exhumed/src/init.cpp +++ b/source/games/exhumed/src/init.cpp @@ -39,7 +39,6 @@ enum kTagRamses = 61, }; -DVector3 initpos; sectortype* initsectp; int nCurChunkNum = 0; @@ -144,6 +143,7 @@ uint8_t LoadLevel(MapRecord* map) sectortype* initsect; SpawnSpriteDef spawned; + DVector3 initpos; int16_t mapang; loadMap(currentLevel->fileName, 0, &initpos, &mapang, &initsect, spawned); initsectp = initsect; @@ -769,7 +769,7 @@ void ExamineSprites(TArray& actors) { auto pActor = insertActor(initsectp, 0); - pActor->spr.pos = initpos; + pActor->spr.pos = PlayerList[nLocalPlayer].pActor->spr.pos; pActor->spr.cstat = CSTAT_SPRITE_INVISIBLE; nNetStartSprite[nNetStartSprites] = pActor; nNetStartSprites++; @@ -837,8 +837,6 @@ void LoadObjects(TArray& actors) runlist_ChangeChannel(nChannel, 0); runlist_ReadyChannel(nChannel); } - - nCamerapos = initpos; } //--------------------------------------------------------------------------- @@ -851,8 +849,7 @@ void SerializeInit(FSerializer& arc) { if (arc.BeginObject("init")) { - arc("init", initpos) - ("initsect", initsectp) + arc("initsect", initsectp) ("curchunk", nCurChunkNum) .Array("counters", Counters, kNumCounters) .EndObject(); diff --git a/source/games/exhumed/src/move.cpp b/source/games/exhumed/src/move.cpp index 4b5114f25..e00350e21 100644 --- a/source/games/exhumed/src/move.cpp +++ b/source/games/exhumed/src/move.cpp @@ -944,7 +944,6 @@ void MoveSector(sectortype* pSector, DAngle nAngle, DVector2& nVel) TODO: Might need to be done elsewhere too? */ auto pActor = PlayerList[nLocalPlayer].pActor; - initpos = pActor->spr.pos; initsectp = pActor->sector(); } diff --git a/source/games/exhumed/src/osdcmds.cpp b/source/games/exhumed/src/osdcmds.cpp index dda1f0926..394498d6a 100644 --- a/source/games/exhumed/src/osdcmds.cpp +++ b/source/games/exhumed/src/osdcmds.cpp @@ -77,6 +77,7 @@ static int osdcmd_spawn(CCmdFuncPtr parm) if (parm->numparms != 1) return CCMD_SHOWHELP; if (!pActor) return CCMD_SHOWHELP; auto c = parm->parms[0]; + auto& initpos = pActor->spr.pos; auto sectp = initsectp; auto inita = pActor->spr.Angles.Yaw; if (!stricmp(c, "anubis")) BuildAnubis(nullptr, initpos, sectp, inita, false); diff --git a/source/games/exhumed/src/player.cpp b/source/games/exhumed/src/player.cpp index 200cb7039..663245264 100644 --- a/source/games/exhumed/src/player.cpp +++ b/source/games/exhumed/src/player.cpp @@ -2586,7 +2586,6 @@ sectdone: // loc_1C3B4: if (nPlayer == nLocalPlayer) { - initpos = pPlayerActor->spr.pos; initsectp = pPlayerActor->sector(); } diff --git a/source/games/exhumed/src/sequence.cpp b/source/games/exhumed/src/sequence.cpp index 90689ff74..cb93e1c7c 100644 --- a/source/games/exhumed/src/sequence.cpp +++ b/source/games/exhumed/src/sequence.cpp @@ -676,7 +676,7 @@ int seq_PlotSequence(int nSprite, int16_t edx, int16_t nFrame, int16_t ecx) auto pSector =pTSprite->sectp; double nFloorZ = pSector->floorz; - if (nFloorZ <= PlayerList[nLocalPlayer].pActor->viewzoffset + initpos.Z) { + if (nFloorZ <= PlayerList[nLocalPlayer].pActor->viewzoffset + PlayerList[nLocalPlayer].pActor->spr.pos.Z) { pTSprite->ownerActor = nullptr; } else diff --git a/source/games/exhumed/src/sound.cpp b/source/games/exhumed/src/sound.cpp index 1b19b2ad8..cfd0b7151 100644 --- a/source/games/exhumed/src/sound.cpp +++ b/source/games/exhumed/src/sound.cpp @@ -433,9 +433,9 @@ void EXSoundEngine::CalcPosVel(int type, const void* source, const float pt[3], Snake* pSnake = &SnakeList[nSnakeCam]; campos = pSnake->pSprites[0]->spr.pos; } - else + else if (const auto pActor = PlayerList[nLocalPlayer].pActor) { - campos = initpos; + campos = pActor->spr.pos; } auto fcampos = GetSoundPos(campos); @@ -512,7 +512,7 @@ void GameInterface::UpdateSounds() } else if (pActor) { - pos = initpos; + pos = pActor->spr.pos; ang = pActor->spr.Angles.Yaw; } SoundListener listener; From 0cf44e42fc2818b9b0c833927399c697a60215da Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sat, 18 Mar 2023 12:52:54 +1100 Subject: [PATCH 55/67] - Exhumed: Eliminate `initsectp` global. --- source/games/exhumed/src/engine.h | 2 -- source/games/exhumed/src/gun.cpp | 2 +- source/games/exhumed/src/init.cpp | 10 +++------- source/games/exhumed/src/map.cpp | 1 + source/games/exhumed/src/move.cpp | 9 --------- source/games/exhumed/src/osdcmds.cpp | 2 +- source/games/exhumed/src/player.cpp | 6 ------ 7 files changed, 6 insertions(+), 26 deletions(-) diff --git a/source/games/exhumed/src/engine.h b/source/games/exhumed/src/engine.h index de4c39f03..bc1d958f2 100644 --- a/source/games/exhumed/src/engine.h +++ b/source/games/exhumed/src/engine.h @@ -56,8 +56,6 @@ enum { kSectLava = 0x4000, }; -extern sectortype* initsectp; - extern int nCurChunkNum; // all static counters combined in an array for easier maintenance. diff --git a/source/games/exhumed/src/gun.cpp b/source/games/exhumed/src/gun.cpp index 09b92fbda..797d6de69 100644 --- a/source/games/exhumed/src/gun.cpp +++ b/source/games/exhumed/src/gun.cpp @@ -942,7 +942,7 @@ void DrawWeapons(double interpfrac) int var_28 = var_30 + WeaponInfo[nWeapon].b[var_34]; - int8_t nShade = initsectp->ceilingshade; + int8_t nShade = PlayerList[nLocalPlayer].pActor->sector()->ceilingshade; int nDouble = PlayerList[nLocalPlayer].nDouble; int nPal = kPalNormal; diff --git a/source/games/exhumed/src/init.cpp b/source/games/exhumed/src/init.cpp index 5a7b667b8..3e51e0a72 100644 --- a/source/games/exhumed/src/init.cpp +++ b/source/games/exhumed/src/init.cpp @@ -39,8 +39,6 @@ enum kTagRamses = 61, }; -sectortype* initsectp; - int nCurChunkNum = 0; int Counters[kNumCounters]; @@ -146,7 +144,6 @@ uint8_t LoadLevel(MapRecord* map) DVector3 initpos; int16_t mapang; loadMap(currentLevel->fileName, 0, &initpos, &mapang, &initsect, spawned); - initsectp = initsect; auto actors = spawnactors(spawned); int i; @@ -165,7 +162,7 @@ uint8_t LoadLevel(MapRecord* map) for (int i = 0; i < nTotalPlayers; i++) { - SetSavePoint(i, initpos, initsectp, DAngle::fromBuild(mapang)); + SetSavePoint(i, initpos, initsect, DAngle::fromBuild(mapang)); RestartPlayer(i); InitPlayerKeys(i); } @@ -767,7 +764,7 @@ void ExamineSprites(TArray& actors) if (nNetPlayerCount) { - auto pActor = insertActor(initsectp, 0); + auto pActor = insertActor(PlayerList[nLocalPlayer].pActor->sector(), 0); pActor->spr.pos = PlayerList[nLocalPlayer].pActor->spr.pos; pActor->spr.cstat = CSTAT_SPRITE_INVISIBLE; @@ -849,8 +846,7 @@ void SerializeInit(FSerializer& arc) { if (arc.BeginObject("init")) { - arc("initsect", initsectp) - ("curchunk", nCurChunkNum) + arc("curchunk", nCurChunkNum) .Array("counters", Counters, kNumCounters) .EndObject(); } diff --git a/source/games/exhumed/src/map.cpp b/source/games/exhumed/src/map.cpp index a0d67d17f..c2557cf70 100644 --- a/source/games/exhumed/src/map.cpp +++ b/source/games/exhumed/src/map.cpp @@ -45,6 +45,7 @@ void GrabMap() void UpdateMap() { + const auto initsectp = PlayerList[nLocalPlayer].pActor->sector(); if (initsectp->ceilingpal != 3 || (PlayerList[nLocalPlayer].nTorch != 0)) { MarkSectorSeen(initsectp); } diff --git a/source/games/exhumed/src/move.cpp b/source/games/exhumed/src/move.cpp index e00350e21..901b34744 100644 --- a/source/games/exhumed/src/move.cpp +++ b/source/games/exhumed/src/move.cpp @@ -936,15 +936,6 @@ void MoveSector(sectortype* pSector, DAngle nAngle, DVector2& nVel) } nVel = vect; - - /* - Update player position variables, in case the player sprite was moved by a sector, - Otherwise these can be out of sync when used in sound code (before being updated in PlayerFunc()). - Can cause local player sounds to play off-centre. - TODO: Might need to be done elsewhere too? - */ - auto pActor = PlayerList[nLocalPlayer].pActor; - initsectp = pActor->sector(); } //--------------------------------------------------------------------------- diff --git a/source/games/exhumed/src/osdcmds.cpp b/source/games/exhumed/src/osdcmds.cpp index 394498d6a..162e020ef 100644 --- a/source/games/exhumed/src/osdcmds.cpp +++ b/source/games/exhumed/src/osdcmds.cpp @@ -78,7 +78,7 @@ static int osdcmd_spawn(CCmdFuncPtr parm) if (!pActor) return CCMD_SHOWHELP; auto c = parm->parms[0]; auto& initpos = pActor->spr.pos; - auto sectp = initsectp; + auto sectp = pActor->sector(); auto inita = pActor->spr.Angles.Yaw; if (!stricmp(c, "anubis")) BuildAnubis(nullptr, initpos, sectp, inita, false); else if (!stricmp(c, "spider")) BuildSpider(nullptr, initpos, sectp, inita); diff --git a/source/games/exhumed/src/player.cpp b/source/games/exhumed/src/player.cpp index 663245264..da0e68a0a 100644 --- a/source/games/exhumed/src/player.cpp +++ b/source/games/exhumed/src/player.cpp @@ -2583,12 +2583,6 @@ sectdone: } } - // loc_1C3B4: - if (nPlayer == nLocalPlayer) - { - initsectp = pPlayerActor->sector(); - } - if (!PlayerList[nPlayer].nHealth) { PlayerList[nPlayer].nThrust.Zero(); From 1af60fb02b43395a28ab03c20d3b043747804662 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sat, 18 Mar 2023 13:02:06 +1100 Subject: [PATCH 56/67] - Exhumed: Clear local input accumulation buffer after copying a packet, just like the other games. --- source/games/exhumed/src/input.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/source/games/exhumed/src/input.cpp b/source/games/exhumed/src/input.cpp index e460ab936..bca31c758 100644 --- a/source/games/exhumed/src/input.cpp +++ b/source/games/exhumed/src/input.cpp @@ -57,12 +57,7 @@ void GameInterface::GetInput(const double scaleAdjust, InputPacket* packet) HIDInput hidInput; getHidInput(&hidInput); - if (packet != nullptr) - { - localInput = {}; - ApplyGlobalInput(localInput, &hidInput); - if (PlayerList[nLocalPlayer].nHealth == 0) localInput.actions &= SB_OPEN; - } + ApplyGlobalInput(localInput, &hidInput); Player* pPlayer = &PlayerList[nLocalPlayer]; InputPacket input {}; @@ -90,6 +85,7 @@ void GameInterface::GetInput(const double scaleAdjust, InputPacket* packet) if (packet) { *packet = localInput; + localInput = {}; } } From 42a895d6662bb1eccbbedde6e9ee86d0a55a79b0 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sat, 18 Mar 2023 19:29:15 +1100 Subject: [PATCH 57/67] - Exhumed: Move dead checks out of the input handler and into the ticker. --- source/games/exhumed/src/exhumed.cpp | 10 ++++++++++ source/games/exhumed/src/input.cpp | 16 ++-------------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/source/games/exhumed/src/exhumed.cpp b/source/games/exhumed/src/exhumed.cpp index 35f5bb7c3..c2637f0df 100644 --- a/source/games/exhumed/src/exhumed.cpp +++ b/source/games/exhumed/src/exhumed.cpp @@ -390,6 +390,16 @@ void GameInterface::Ticker() } UpdateInterpolations(); + if (nFreeze) setForcedSyncInput(); + + if (PlayerList[nLocalPlayer].nHealth <= 0) + { + setForcedSyncInput(); + auto& packet = PlayerList[nLocalPlayer].input; + packet.fvel = packet.svel = packet.avel = packet.horz = 0; + lPlayerVel.Zero(); + } + if (PlayerList[nLocalPlayer].input.actions & SB_INVPREV) { int nItem = PlayerList[nLocalPlayer].nItem; diff --git a/source/games/exhumed/src/input.cpp b/source/games/exhumed/src/input.cpp index bca31c758..e0096aa2d 100644 --- a/source/games/exhumed/src/input.cpp +++ b/source/games/exhumed/src/input.cpp @@ -62,24 +62,12 @@ void GameInterface::GetInput(const double scaleAdjust, InputPacket* packet) Player* pPlayer = &PlayerList[nLocalPlayer]; InputPacket input {}; - if (PlayerList[nLocalPlayer].nHealth != 0) - { - processMovement(&input, &localInput, &hidInput, scaleAdjust); - } - else - { - pPlayer->vel.Zero(); - } + processMovement(&input, &localInput, &hidInput, scaleAdjust); - if (!SyncInput() && gamestate == GS_LEVEL && !nFreeze) + if (!SyncInput() && gamestate == GS_LEVEL) { pPlayer->Angles.CameraAngles.Yaw += DAngle::fromDeg(input.avel); pPlayer->Angles.CameraAngles.Pitch += DAngle::fromDeg(input.horz); - - if (input.horz) - { - pPlayer->bPlayerPan = pPlayer->bLockPan = true; - } } if (packet) From b8ba78cf894983d20abe07a84c5c48bbcfaa1bf3 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sat, 18 Mar 2023 13:46:49 +1100 Subject: [PATCH 58/67] - Exhumed: Use array pointers in `GameInterface::Ticker()` for one's sanity. --- source/games/exhumed/src/exhumed.cpp | 76 ++++++++++++++-------------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/source/games/exhumed/src/exhumed.cpp b/source/games/exhumed/src/exhumed.cpp index c2637f0df..8f9e5cae8 100644 --- a/source/games/exhumed/src/exhumed.cpp +++ b/source/games/exhumed/src/exhumed.cpp @@ -367,42 +367,44 @@ void GameInterface::Ticker() } else if (EndLevel == 0) { + // Shorten some constant array accesses. + const auto pPlayer = &PlayerList[nLocalPlayer]; + auto& pInput = pPlayer->input; + // this must be done before the view is backed up. - PlayerList[nLocalPlayer].Angles.resetCameraAngles(); + pPlayer->Angles.resetCameraAngles(); // disable synchronised input if set by game. resetForcedSyncInput(); // set new player input, factoring in previous view centering. - auto oldactions = PlayerList[nLocalPlayer].input.actions; - PlayerList[nLocalPlayer].input = playercmds[nLocalPlayer].ucmd; - if (oldactions & SB_CENTERVIEW) PlayerList[nLocalPlayer].input.actions |= SB_CENTERVIEW; + const auto oldactions = pInput.actions; + pInput = playercmds[nLocalPlayer].ucmd; + if (oldactions & SB_CENTERVIEW) pInput.actions |= SB_CENTERVIEW; - auto& lPlayerVel = PlayerList[nLocalPlayer].vel; - - auto inputvect = DVector2(PlayerList[nLocalPlayer].input.fvel, PlayerList[nLocalPlayer].input.svel).Rotated(PlayerList[nLocalPlayer].pActor->spr.Angles.Yaw) * 0.375; + const auto inputvect = DVector2(pInput.fvel, pInput.svel).Rotated(pPlayer->pActor->spr.Angles.Yaw) * 0.375; for (int i = 0; i < 4; i++) { // Velocities are stored as Q14.18 - lPlayerVel += inputvect; - lPlayerVel *= 0.953125; + pPlayer->vel += inputvect; + pPlayer->vel *= 0.953125; } UpdateInterpolations(); if (nFreeze) setForcedSyncInput(); - if (PlayerList[nLocalPlayer].nHealth <= 0) + if (pPlayer->nHealth <= 0) { setForcedSyncInput(); - auto& packet = PlayerList[nLocalPlayer].input; + auto& packet = pInput; packet.fvel = packet.svel = packet.avel = packet.horz = 0; - lPlayerVel.Zero(); + pPlayer->vel.Zero(); } - if (PlayerList[nLocalPlayer].input.actions & SB_INVPREV) + if (pInput.actions & SB_INVPREV) { - int nItem = PlayerList[nLocalPlayer].nItem; + int nItem = pPlayer->nItem; int i; for (i = 6; i > 0; i--) @@ -410,16 +412,16 @@ void GameInterface::Ticker() nItem--; if (nItem < 0) nItem = 5; - if (PlayerList[nLocalPlayer].items[nItem] != 0) + if (pPlayer->items[nItem] != 0) break; } - if (i > 0) PlayerList[nLocalPlayer].nItem = nItem; + if (i > 0) pPlayer->nItem = nItem; } - if (PlayerList[nLocalPlayer].input.actions & SB_INVNEXT) + if (pInput.actions & SB_INVNEXT) { - int nItem = PlayerList[nLocalPlayer].nItem; + int nItem = pPlayer->nItem; int i; for (i = 6; i > 0; i--) @@ -427,57 +429,57 @@ void GameInterface::Ticker() nItem++; if (nItem == 6) nItem = 0; - if (PlayerList[nLocalPlayer].items[nItem] != 0) + if (pPlayer->items[nItem] != 0) break; } - if (i > 0) PlayerList[nLocalPlayer].nItem = nItem; + if (i > 0) pPlayer->nItem = nItem; } - if (PlayerList[nLocalPlayer].input.actions & SB_INVUSE) + if (pInput.actions & SB_INVUSE) { - if (PlayerList[nLocalPlayer].nItem != -1) + if (pPlayer->nItem != -1) { - PlayerList[nLocalPlayer].input.setItemUsed(PlayerList[nLocalPlayer].nItem); + pInput.setItemUsed(pPlayer->nItem); } } for (int i = 0; i < 6; i++) { - if (PlayerList[nLocalPlayer].input.isItemUsed(i)) + if (pInput.isItemUsed(i)) { - PlayerList[nLocalPlayer].input.clearItemUsed(i); - if (PlayerList[nLocalPlayer].items[i] > 0) + pInput.clearItemUsed(i); + if (pPlayer->items[i] > 0) { - if (nItemMagic[i] <= PlayerList[nLocalPlayer].nMagic) + if (nItemMagic[i] <= pPlayer->nMagic) { - PlayerList[nLocalPlayer].nCurrentItem = i; + pPlayer->nCurrentItem = i; break; } } } } - auto currWeap = PlayerList[nLocalPlayer].nCurrentWeapon; - int weap2 = PlayerList[nLocalPlayer].input.getNewWeapon(); + auto currWeap = pPlayer->nCurrentWeapon; + int weap2 = pInput.getNewWeapon(); if (weap2 == WeaponSel_Next) { auto newWeap = currWeap == 6 ? 0 : currWeap + 1; - while (newWeap != 0 && (!(PlayerList[nLocalPlayer].nPlayerWeapons & (1 << newWeap)) || (PlayerList[nLocalPlayer].nPlayerWeapons & (1 << newWeap) && PlayerList[nLocalPlayer].nAmmo[newWeap] == 0))) + while (newWeap != 0 && (!(pPlayer->nPlayerWeapons & (1 << newWeap)) || (pPlayer->nPlayerWeapons & (1 << newWeap) && pPlayer->nAmmo[newWeap] == 0))) { newWeap++; if (newWeap > 6) newWeap = 0; } - PlayerList[nLocalPlayer].input.setNewWeapon(newWeap + 1); + pInput.setNewWeapon(newWeap + 1); } else if (weap2 == WeaponSel_Prev) { auto newWeap = currWeap == 0 ? 6 : currWeap - 1; - while (newWeap != 0 && ((!(PlayerList[nLocalPlayer].nPlayerWeapons & (1 << newWeap)) || (PlayerList[nLocalPlayer].nPlayerWeapons & (1 << newWeap) && PlayerList[nLocalPlayer].nAmmo[newWeap] == 0)))) + while (newWeap != 0 && ((!(pPlayer->nPlayerWeapons & (1 << newWeap)) || (pPlayer->nPlayerWeapons & (1 << newWeap) && pPlayer->nAmmo[newWeap] == 0)))) { newWeap--; } - PlayerList[nLocalPlayer].input.setNewWeapon(newWeap + 1); + pInput.setNewWeapon(newWeap + 1); } else if (weap2 == WeaponSel_Alt) { @@ -485,10 +487,10 @@ void GameInterface::Ticker() } // make weapon selection persist until it gets used up. - int weap = PlayerList[nLocalPlayer].input.getNewWeapon(); - if (weap2 <= 0 || weap2 > 7) PlayerList[nLocalPlayer].input.setNewWeapon(weap); + int weap = pInput.getNewWeapon(); + if (weap2 <= 0 || weap2 > 7) pInput.setNewWeapon(weap); - PlayerList[nLocalPlayer].pTarget = Ra[nLocalPlayer].pTarget = bestTarget; + pPlayer->pTarget = Ra[nLocalPlayer].pTarget = bestTarget; PlayClock += 4; if (PlayClock == 8) gameaction = ga_autosave; // let the game run for 1 frame before saving. From bd3e9b305e038035447b9098276fa3a286ac9fbf Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sat, 18 Mar 2023 17:35:30 +1100 Subject: [PATCH 59/67] - Adjust signatures of input functions slightly for consistency. --- source/core/gameinput.cpp | 2 +- source/core/gameinput.h | 2 +- source/core/inputstate.cpp | 44 ++++++++++++++--------------- source/core/inputstate.h | 2 +- source/games/blood/src/controls.cpp | 4 +-- source/games/duke/src/input.cpp | 16 +++++------ source/games/exhumed/src/input.cpp | 4 +-- source/games/sw/src/input.cpp | 4 +-- 8 files changed, 39 insertions(+), 39 deletions(-) diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index 9f38183b6..709370f7b 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -110,7 +110,7 @@ void resetTurnHeldAmt() // //--------------------------------------------------------------------------- -void processMovement(InputPacket* const currInput, InputPacket* const inputBuffer, HIDInput* const hidInput, const double scaleAdjust, const int drink_amt, const bool allowstrafe, const double turnscale) +void processMovement(HIDInput* const hidInput, InputPacket* const inputBuffer, InputPacket* const currInput, const double scaleAdjust, const int drink_amt, const bool allowstrafe, const double turnscale) { // set up variables. const int keymove = 1 << int(!!(inputBuffer->actions & SB_RUN)); diff --git a/source/core/gameinput.h b/source/core/gameinput.h index 378ca98ae..3205f6c34 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -83,4 +83,4 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngles& w, P void updateTurnHeldAmt(const double scaleAdjust); bool isTurboTurnTime(); void resetTurnHeldAmt(); -void processMovement(InputPacket* const currInput, InputPacket* const inputBuffer, HIDInput* const hidInput, const double scaleAdjust, const int drink_amt = 0, const bool allowstrafe = true, const double turnscale = 1); +void processMovement(HIDInput* const hidInput, InputPacket* const inputBuffer, InputPacket* const currInput, const double scaleAdjust, const int drink_amt = 0, const bool allowstrafe = true, const double turnscale = 1); diff --git a/source/core/inputstate.cpp b/source/core/inputstate.cpp index d7564908f..211edc07c 100644 --- a/source/core/inputstate.cpp +++ b/source/core/inputstate.cpp @@ -370,46 +370,46 @@ CCMD(show_weapon) gi->ToggleShowWeapon(); } -void ApplyGlobalInput(InputPacket& input, HIDInput* const hidInput) +void ApplyGlobalInput(HIDInput* const hidInput, InputPacket* const inputBuffer) { - if (WeaponToSend != 0) input.setNewWeapon(WeaponToSend); + if (WeaponToSend != 0) inputBuffer->setNewWeapon(WeaponToSend); WeaponToSend = 0; if (hidInput && buttonMap.ButtonDown(gamefunc_Dpad_Select)) { // These buttons should not autorepeat. The game handlers are not really equipped for that. - if (hidInput->joyaxes[JOYAXIS_Forward] > 0 && !(dpad_lock & 1)) { dpad_lock |= 1; input.setNewWeapon(WeaponSel_Prev); } + if (hidInput->joyaxes[JOYAXIS_Forward] > 0 && !(dpad_lock & 1)) { dpad_lock |= 1; inputBuffer->setNewWeapon(WeaponSel_Prev); } else dpad_lock &= ~1; - if (hidInput->joyaxes[JOYAXIS_Forward] < 0 && !(dpad_lock & 2)) { dpad_lock |= 2; input.setNewWeapon(WeaponSel_Next); } + if (hidInput->joyaxes[JOYAXIS_Forward] < 0 && !(dpad_lock & 2)) { dpad_lock |= 2; inputBuffer->setNewWeapon(WeaponSel_Next); } else dpad_lock &= ~2; - if ((hidInput->joyaxes[JOYAXIS_Side] < 0 || hidInput->joyaxes[JOYAXIS_Yaw] > 0) && !(dpad_lock & 4)) { dpad_lock |= 4; input.actions |= SB_INVPREV; } + if ((hidInput->joyaxes[JOYAXIS_Side] < 0 || hidInput->joyaxes[JOYAXIS_Yaw] > 0) && !(dpad_lock & 4)) { dpad_lock |= 4; inputBuffer->actions |= SB_INVPREV; } else dpad_lock &= ~4; - if ((hidInput->joyaxes[JOYAXIS_Side] > 0 || hidInput->joyaxes[JOYAXIS_Yaw] < 0) && !(dpad_lock & 8)) { dpad_lock |= 8; input.actions |= SB_INVNEXT; } + if ((hidInput->joyaxes[JOYAXIS_Side] > 0 || hidInput->joyaxes[JOYAXIS_Yaw] < 0) && !(dpad_lock & 8)) { dpad_lock |= 8; inputBuffer->actions |= SB_INVNEXT; } else dpad_lock &= ~8; - // This eats the controller input for regular use + // This eats the controller inputBuffer-> for regular use hidInput->joyaxes[JOYAXIS_Side] = 0; hidInput->joyaxes[JOYAXIS_Forward] = 0; hidInput->joyaxes[JOYAXIS_Yaw] = 0; } else dpad_lock = 0; - input.actions |= ActionsToSend; + inputBuffer->actions |= ActionsToSend; ActionsToSend = 0; if (buttonMap.ButtonDown(gamefunc_Aim_Up) || (buttonMap.ButtonDown(gamefunc_Dpad_Aiming) && hidInput->joyaxes[JOYAXIS_Forward] > 0)) - input.actions |= SB_AIM_UP; + inputBuffer->actions |= SB_AIM_UP; if ((buttonMap.ButtonDown(gamefunc_Aim_Down) || (buttonMap.ButtonDown(gamefunc_Dpad_Aiming) && hidInput->joyaxes[JOYAXIS_Forward] < 0))) - input.actions |= SB_AIM_DOWN; + inputBuffer->actions |= SB_AIM_DOWN; if (buttonMap.ButtonDown(gamefunc_Dpad_Aiming)) hidInput->joyaxes[JOYAXIS_Forward] = 0; if (buttonMap.ButtonDown(gamefunc_Jump)) - input.actions |= SB_JUMP; + inputBuffer->actions |= SB_JUMP; if (buttonMap.ButtonDown(gamefunc_Crouch) || buttonMap.ButtonDown(gamefunc_Toggle_Crouch) || crouch_toggle) - input.actions |= SB_CROUCH; + inputBuffer->actions |= SB_CROUCH; if (buttonMap.ButtonDown(gamefunc_Toggle_Crouch)) { @@ -421,36 +421,36 @@ void ApplyGlobalInput(InputPacket& input, HIDInput* const hidInput) crouch_toggle = false; if (buttonMap.ButtonDown(gamefunc_Fire)) - input.actions |= SB_FIRE; + inputBuffer->actions |= SB_FIRE; if (buttonMap.ButtonDown(gamefunc_Alt_Fire)) - input.actions |= SB_ALTFIRE; + inputBuffer->actions |= SB_ALTFIRE; if (buttonMap.ButtonDown(gamefunc_Open)) { if (isBlood()) buttonMap.ClearButton(gamefunc_Open); - input.actions |= SB_OPEN; + inputBuffer->actions |= SB_OPEN; } if (G_CheckAutorun(buttonMap.ButtonDown(gamefunc_Run))) - input.actions |= SB_RUN; + inputBuffer->actions |= SB_RUN; if (!in_mousemode && !buttonMap.ButtonDown(gamefunc_Mouse_Aiming)) - input.actions |= SB_AIMMODE; + inputBuffer->actions |= SB_AIMMODE; if (buttonMap.ButtonDown(gamefunc_Look_Up)) - input.actions |= SB_LOOK_UP; + inputBuffer->actions |= SB_LOOK_UP; if (buttonMap.ButtonDown(gamefunc_Look_Down)) - input.actions |= SB_LOOK_DOWN; + inputBuffer->actions |= SB_LOOK_DOWN; if (buttonMap.ButtonDown(gamefunc_Look_Left)) - input.actions |= SB_LOOK_LEFT; + inputBuffer->actions |= SB_LOOK_LEFT; if (buttonMap.ButtonDown(gamefunc_Look_Right)) - input.actions |= SB_LOOK_RIGHT; + inputBuffer->actions |= SB_LOOK_RIGHT; if (buttonMap.ButtonDown(gamefunc_Quick_Kick)) - input.actions |= SB_QUICK_KICK; + inputBuffer->actions |= SB_QUICK_KICK; } diff --git a/source/core/inputstate.h b/source/core/inputstate.h index 377aaab7e..416856bfd 100644 --- a/source/core/inputstate.h +++ b/source/core/inputstate.h @@ -96,7 +96,7 @@ enum GameFunction_t }; void SetupGameButtons(); -void ApplyGlobalInput(InputPacket& input, HIDInput* const hidInput); +void ApplyGlobalInput(HIDInput* const hidInput, InputPacket* const inputBuffer); extern ESyncBits ActionsToSend; extern bool gamesetinput; diff --git a/source/games/blood/src/controls.cpp b/source/games/blood/src/controls.cpp index 36d2d1f79..4fbf373cb 100644 --- a/source/games/blood/src/controls.cpp +++ b/source/games/blood/src/controls.cpp @@ -54,8 +54,8 @@ void GameInterface::GetInput(const double scaleAdjust, InputPacket* packet) PLAYER* pPlayer = &gPlayer[myconnectindex]; InputPacket input{}; - ApplyGlobalInput(gInput, &hidInput); - processMovement(&input, &gInput, &hidInput, scaleAdjust); + ApplyGlobalInput(&hidInput, &gInput); + processMovement(&hidInput, &gInput, &input, scaleAdjust); // Perform unsynchronised angle/horizon if not dead. if (!SyncInput() && gamestate == GS_LEVEL && pPlayer->actor->xspr.health != 0) diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index af6fd177c..cb77ec8ad 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -709,7 +709,7 @@ static float boatApplyTurn(player_struct *p, HIDInput* const hidInput, bool cons // //--------------------------------------------------------------------------- -static void processVehicleInput(player_struct *p, HIDInput* const hidInput, InputPacket& input, double const scaleAdjust) +static void processVehicleInput(player_struct *p, HIDInput* const hidInput, InputPacket* const inputBuffer, InputPacket* const currInput, const double scaleAdjust) { bool const kbdLeft = buttonMap.ButtonDown(gamefunc_Turn_Left) || buttonMap.ButtonDown(gamefunc_Strafe_Left); bool const kbdRight = buttonMap.ButtonDown(gamefunc_Turn_Right) || buttonMap.ButtonDown(gamefunc_Strafe_Right); @@ -729,16 +729,16 @@ static void processVehicleInput(player_struct *p, HIDInput* const hidInput, Inpu if (p->OnMotorcycle) { - input.avel = motoApplyTurn(p, hidInput, kbdLeft, kbdRight, (float)scaleAdjust); + currInput->avel = motoApplyTurn(p, hidInput, kbdLeft, kbdRight, (float)scaleAdjust); if (p->moto_underwater) p->MotoSpeed = 0; } else { - input.avel = boatApplyTurn(p, hidInput, kbdLeft, kbdRight, (float)scaleAdjust); + currInput->avel = boatApplyTurn(p, hidInput, kbdLeft, kbdRight, (float)scaleAdjust); } - loc.fvel = clamp((float)p->MotoSpeed, -(MAXVELMOTO >> 3), MAXVELMOTO) * (1.f / 40.f); - loc.avel += input.avel; + inputBuffer->fvel = clamp((float)p->MotoSpeed, -(MAXVELMOTO >> 3), MAXVELMOTO) * (1.f / 40.f); + inputBuffer->avel += currInput->avel; } //--------------------------------------------------------------------------- @@ -797,15 +797,15 @@ void GameInterface::GetInput(const double scaleAdjust, InputPacket* packet) auto const p = &ps[myconnectindex]; InputPacket input{}; - ApplyGlobalInput(loc, &hidInput); + ApplyGlobalInput(&hidInput, &loc); if (isRRRA() && (p->OnMotorcycle || p->OnBoat)) { - processVehicleInput(p, &hidInput, input, scaleAdjust); + processVehicleInput(p, &hidInput, &loc, &input, scaleAdjust); } else { - processMovement(&input, &loc, &hidInput, scaleAdjust, p->drink_amt); + processMovement(&hidInput, &loc, &input, scaleAdjust, p->drink_amt); } FinalizeInput(p, input); diff --git a/source/games/exhumed/src/input.cpp b/source/games/exhumed/src/input.cpp index e0096aa2d..600d3feaa 100644 --- a/source/games/exhumed/src/input.cpp +++ b/source/games/exhumed/src/input.cpp @@ -57,12 +57,12 @@ void GameInterface::GetInput(const double scaleAdjust, InputPacket* packet) HIDInput hidInput; getHidInput(&hidInput); - ApplyGlobalInput(localInput, &hidInput); + ApplyGlobalInput(&hidInput, &localInput); Player* pPlayer = &PlayerList[nLocalPlayer]; InputPacket input {}; - processMovement(&input, &localInput, &hidInput, scaleAdjust); + processMovement(&hidInput, &localInput, &input, scaleAdjust); if (!SyncInput() && gamestate == GS_LEVEL) { diff --git a/source/games/sw/src/input.cpp b/source/games/sw/src/input.cpp index 49fca0d1c..47d36e972 100644 --- a/source/games/sw/src/input.cpp +++ b/source/games/sw/src/input.cpp @@ -172,8 +172,8 @@ void GameInterface::GetInput(const double scaleAdjust, InputPacket *packet) InputPacket input {}; - ApplyGlobalInput(loc, &hidInput); - processMovement(&input, &loc, &hidInput, scaleAdjust, 0, !pp->sop, pp->sop_control ? 3. / 1.40625 : 1.); + ApplyGlobalInput(&hidInput, &loc); + processMovement(&hidInput, &loc, &input, scaleAdjust, 0, !pp->sop, pp->sop_control ? 3. / 1.40625 : 1.); if (!SyncInput()) { From 4355a447219c81237bf8520c537c224e427b718e Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sat, 18 Mar 2023 19:28:02 +1100 Subject: [PATCH 60/67] - Duke: Rework input blocking setup. * Takes the duplicated conditions out of the input handler and makes the ticker responsible by forcing synchronised input. --- source/core/gamecontrol.cpp | 6 +++ source/games/duke/src/gameexec.cpp | 4 +- source/games/duke/src/input.cpp | 37 ------------------- source/games/duke/src/player.cpp | 5 +++ source/games/duke/src/player_d.cpp | 12 +++++- source/games/duke/src/player_r.cpp | 12 +++++- source/games/duke/src/types.h | 5 +++ .../static/zscript/games/duke/actors/crane.zs | 1 + .../zscript/games/duke/actors/viewscreen.zs | 1 + wadsrc/static/zscript/razebase.zs | 1 + 10 files changed, 43 insertions(+), 41 deletions(-) diff --git a/source/core/gamecontrol.cpp b/source/core/gamecontrol.cpp index 364f968a9..2a7887895 100644 --- a/source/core/gamecontrol.cpp +++ b/source/core/gamecontrol.cpp @@ -1512,6 +1512,12 @@ DEFINE_ACTION_FUNCTION_NATIVE(_Raze, GetBuildTime, I_GetBuildTime) ACTION_RETURN_INT(I_GetBuildTime()); } +DEFINE_ACTION_FUNCTION_NATIVE(_Raze, forceSyncInput, setForcedSyncInput) +{ + setForcedSyncInput(); + return 0; +} + DEFINE_ACTION_FUNCTION(_Raze, PickTexture) { PARAM_PROLOGUE; diff --git a/source/games/duke/src/gameexec.cpp b/source/games/duke/src/gameexec.cpp index dbe99c024..094a668fb 100644 --- a/source/games/duke/src/gameexec.cpp +++ b/source/games/duke/src/gameexec.cpp @@ -551,7 +551,7 @@ void DoPlayer(bool bSet, int lVar1, int lLabelID, int lVar2, DDukeActor* sActor, break; case PLAYER_NEWOWNER: - if (bSet) ps[iPlayer].newOwner = vValue.safeActor(); + if (bSet && (ps[iPlayer].newOwner = vValue.safeActor())) setForcedSyncInput(); else SetGameVarID(lVar2, ps[iPlayer].newOwner, sActor, sPlayer); break; @@ -621,7 +621,7 @@ void DoPlayer(bool bSet, int lVar1, int lLabelID, int lVar2, DDukeActor* sActor, break; case PLAYER_ON_CRANE: - if (bSet) ps[iPlayer].on_crane = vValue.safeActor(); + if (bSet && (ps[iPlayer].on_crane = vValue.safeActor())) setForcedSyncInput(); else SetGameVarID(lVar2, (ps[iPlayer].on_crane), sActor, sPlayer); break; diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index cb77ec8ad..8136d78e6 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -741,41 +741,6 @@ static void processVehicleInput(player_struct *p, HIDInput* const hidInput, Inpu inputBuffer->avel += currInput->avel; } -//--------------------------------------------------------------------------- -// -// finalizes the input and passes it to the global input buffer -// -//--------------------------------------------------------------------------- - -static void FinalizeInput(player_struct *p, InputPacket& input) -{ - if (gamestate != GS_LEVEL || movementBlocked(p) || p->GetActor()->spr.extra <= 0) - { - // neutralize all movement when not in a game, blocked or in automap follow mode - loc.fvel = loc.svel = 0; - loc.avel = loc.horz = 0; - input.avel = input.horz = 0; - } - else - { - if (p->on_crane != nullptr) - { - loc.fvel = input.fvel = 0; - loc.svel = input.svel = 0; - } - - if (p->newOwner != nullptr || p->on_crane != nullptr) - { - loc.avel = input.avel = 0; - } - - if (p->newOwner != nullptr || (p->sync.actions & SB_CENTERVIEW && abs(p->GetActor()->spr.Angles.Pitch.Degrees()) > 2.2370)) - { - loc.horz = input.horz = 0; - } - } -} - //--------------------------------------------------------------------------- // @@ -808,8 +773,6 @@ void GameInterface::GetInput(const double scaleAdjust, InputPacket* packet) processMovement(&hidInput, &loc, &input, scaleAdjust, p->drink_amt); } - FinalizeInput(p, input); - if (!SyncInput() && p->GetActor()->spr.extra > 0) { p->Angles.CameraAngles.Yaw += p->adjustavel(input.avel); diff --git a/source/games/duke/src/player.cpp b/source/games/duke/src/player.cpp index 87b2a32bc..96ebdc601 100644 --- a/source/games/duke/src/player.cpp +++ b/source/games/duke/src/player.cpp @@ -545,6 +545,9 @@ void playerisdead(int snum, int psectlotag, double floorz, double ceilingz) auto p = &ps[snum]; auto actor = p->GetActor(); + // lock input when dead. + setForcedSyncInput(); + if (p->dead_flag == 0) { if (actor->spr.pal != 1) @@ -958,6 +961,8 @@ bool movementBlocked(player_struct *p) p->hard_landing || p->access_incs > 0 || p->knee_incs > 0 || + p->GetActor()->spr.extra <= 0 || + (p->dead_flag && !ud.god) || (blockingweapon() && p->kickback_pic > 1 && p->kickback_pic < weapondelay())); } diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index cdc7c255b..4c920a269 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -2713,6 +2713,7 @@ void processinput_d(int snum) if (p->newOwner != nullptr) { + setForcedSyncInput(); p->vel.X = p->vel.Y = 0; pact->vel.X = 0; @@ -2730,7 +2731,10 @@ void processinput_d(int snum) auto oldpos = p->GetActor()->opos; if (p->on_crane != nullptr) + { + setForcedSyncInput(); goto HORIZONLY; + } p->playerweaponsway(pact->vel.X); @@ -2765,6 +2769,7 @@ void processinput_d(int snum) doubvel = 0; p->vel.X = 0; p->vel.Y = 0; + setForcedSyncInput(); } else if (SyncInput()) { @@ -2985,7 +2990,12 @@ HORIZONLY: playerAimDown(snum, actions); } - if (SyncInput()) + if (p->centeringView()) + { + p->sync.horz = 0; + setForcedSyncInput(); + } + else if (SyncInput()) { p->GetActor()->spr.Angles.Pitch += GetPlayerHorizon(snum); } diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index 27d188228..c29d1806b 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -3382,6 +3382,7 @@ void processinput_r(int snum) if (p->newOwner != nullptr) { + setForcedSyncInput(); p->vel.X = p->vel.Y = 0; pact->vel.X = 0; @@ -3399,7 +3400,10 @@ void processinput_r(int snum) auto oldpos = p->GetActor()->opos; if (p->on_crane != nullptr) + { + setForcedSyncInput(); goto HORIZONLY; + } p->playerweaponsway(pact->vel.X); @@ -3448,6 +3452,7 @@ void processinput_r(int snum) doubvel = 0; p->vel.X = 0; p->vel.Y = 0; + setForcedSyncInput(); } else if (SyncInput()) { @@ -3796,7 +3801,12 @@ HORIZONLY: p->GetActor()->spr.Angles.Pitch += maphoriz(d); } - if (SyncInput()) + if (p->centeringView()) + { + p->sync.horz = 0; + setForcedSyncInput(); + } + else if (SyncInput()) { p->GetActor()->spr.Angles.Pitch += GetPlayerHorizon(snum); } diff --git a/source/games/duke/src/types.h b/source/games/duke/src/types.h index 368134a08..042cbde11 100644 --- a/source/games/duke/src/types.h +++ b/source/games/duke/src/types.h @@ -345,6 +345,11 @@ struct player_struct { bobpos = GetActor()->spr.pos.XY(); } + + bool centeringView() + { + return (sync.actions & SB_CENTERVIEW) && abs(GetActor()->spr.Angles.Pitch.Degrees()) > 2.2370; + } }; struct Cycler diff --git a/wadsrc/static/zscript/games/duke/actors/crane.zs b/wadsrc/static/zscript/games/duke/actors/crane.zs index b55db4265..414eeedad 100644 --- a/wadsrc/static/zscript/games/duke/actors/crane.zs +++ b/wadsrc/static/zscript/games/duke/actors/crane.zs @@ -151,6 +151,7 @@ class DukeCrane : DukeActor plr.on_crane = self; plr.actor.PlayActorSound("CRANEGRAB"); plr.settargetangle(self.angle + 180); + Raze.forceSyncInput(); } else { diff --git a/wadsrc/static/zscript/games/duke/actors/viewscreen.zs b/wadsrc/static/zscript/games/duke/actors/viewscreen.zs index 5a2962526..e04c9fd2b 100644 --- a/wadsrc/static/zscript/games/duke/actors/viewscreen.zs +++ b/wadsrc/static/zscript/games/duke/actors/viewscreen.zs @@ -47,6 +47,7 @@ class DukeViewscreen : DukeActor camsprite = self; user.newOwner = acti; + Raze.forceSyncInput(); return true; } } diff --git a/wadsrc/static/zscript/razebase.zs b/wadsrc/static/zscript/razebase.zs index a3f412e33..b4a161713 100644 --- a/wadsrc/static/zscript/razebase.zs +++ b/wadsrc/static/zscript/razebase.zs @@ -171,6 +171,7 @@ struct Raze static double bobval(double angle) { return sin(angle * (360. / 2048)); } native static TextureID PickTexture(TextureID texid); native static int GetBuildTime(); + native static void forceSyncInput(); native static Font PickBigFont(String cmptext = ""); native static Font PickSmallFont(String cmptext = ""); native static int SoundEnabled(); From 3442290fa2b84415f24427f4734019a8c1e4c7e9 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sat, 18 Mar 2023 19:20:53 +1100 Subject: [PATCH 61/67] - Repair bad setup for global input scale uncovered after making Duke better. * `I_GetInputFrac()` must always be called, even if we don't use it otherwise the value grows too large. --- source/core/mainloop.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/core/mainloop.cpp b/source/core/mainloop.cpp index 196ea891e..7267adae5 100644 --- a/source/core/mainloop.cpp +++ b/source/core/mainloop.cpp @@ -136,7 +136,7 @@ void G_BuildTiccmd(ticcmd_t* cmd) } cmd->ucmd = {}; I_GetEvent(); - gi->GetInput(inputScale, &cmd->ucmd); + gi->GetInput(!SyncInput() ? inputScale : 1., &cmd->ucmd); cmd->consistency = consistency[myconnectindex][(maketic / ticdup) % BACKUPTICS]; } @@ -564,7 +564,7 @@ void TryRunTics (void) oldentertics = entertic; // update the scale factor for unsynchronised input here. - inputScale = !SyncInput() ? I_GetInputFrac() : 1.; + inputScale = I_GetInputFrac(); // get available tics NetUpdate (); @@ -614,7 +614,7 @@ void TryRunTics (void) if (!SyncInput()) { I_GetEvent(); - gi->GetInput(inputScale); + gi->GetInput(!SyncInput() ? inputScale : 1.); } return; } From ee294d7fa074b6a2cda1e83c62f21cfb8d4799ec Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sat, 18 Mar 2023 19:22:10 +1100 Subject: [PATCH 62/67] - Blood: Force synchronised input while dead. --- source/games/blood/src/controls.cpp | 2 +- source/games/blood/src/player.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/source/games/blood/src/controls.cpp b/source/games/blood/src/controls.cpp index 4fbf373cb..ea1ed63ea 100644 --- a/source/games/blood/src/controls.cpp +++ b/source/games/blood/src/controls.cpp @@ -58,7 +58,7 @@ void GameInterface::GetInput(const double scaleAdjust, InputPacket* packet) processMovement(&hidInput, &gInput, &input, scaleAdjust); // Perform unsynchronised angle/horizon if not dead. - if (!SyncInput() && gamestate == GS_LEVEL && pPlayer->actor->xspr.health != 0) + if (!SyncInput() && gamestate == GS_LEVEL) { pPlayer->Angles.CameraAngles.Yaw += DAngle::fromDeg(input.avel); pPlayer->Angles.CameraAngles.Pitch += DAngle::fromDeg(input.horz); diff --git a/source/games/blood/src/player.cpp b/source/games/blood/src/player.cpp index 6ff6d4b75..0020256d4 100644 --- a/source/games/blood/src/player.cpp +++ b/source/games/blood/src/player.cpp @@ -1524,6 +1524,9 @@ void ProcessInput(PLAYER* pPlayer) WeaponProcess(pPlayer); if (actor->xspr.health == 0) { + // force synchronised input upon death. + setForcedSyncInput(); + bool bSeqStat = playerSeqPlaying(pPlayer, 16); DBloodActor* fragger = pPlayer->fragger; if (fragger) From 65ee4b14d6fcd2d32dd5d03d5e881ce1139efd1f Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sat, 18 Mar 2023 16:31:38 +1100 Subject: [PATCH 63/67] - Move `gi->getConsoleActor()` directly into the header. --- source/games/blood/src/blood.h | 2 +- source/games/blood/src/osdcmd.cpp | 5 -- source/games/duke/src/ccmds.cpp | 5 -- source/games/duke/src/duke3d.h | 4 +- source/games/exhumed/src/exhumed.h | 3 +- source/games/exhumed/src/osdcmds.cpp | 11 ---- source/games/sw/src/game.h | 92 ++++++++++++++-------------- source/games/sw/src/osdcmds.cpp | 11 ---- 8 files changed, 52 insertions(+), 81 deletions(-) diff --git a/source/games/blood/src/blood.h b/source/games/blood/src/blood.h index 4994f2682..b3b381854 100644 --- a/source/games/blood/src/blood.h +++ b/source/games/blood/src/blood.h @@ -132,7 +132,7 @@ struct GameInterface : public ::GameInterface bool DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos, const DAngle cang, const DVector2& xydim, const double czoom, double const interpfrac) override; DAngle playerPitchMin() override { return DAngle::fromDeg(54.575); } DAngle playerPitchMax() override { return DAngle::fromDeg(-43.15); } - DCoreActor* getConsoleActor() override; + DCoreActor* getConsoleActor() override { return gPlayer[myconnectindex].actor; } void ToggleThirdPerson() override; void SwitchCoopView() override; void ToggleShowWeapon() override; diff --git a/source/games/blood/src/osdcmd.cpp b/source/games/blood/src/osdcmd.cpp index 9ecf2429a..cead07397 100644 --- a/source/games/blood/src/osdcmd.cpp +++ b/source/games/blood/src/osdcmd.cpp @@ -31,11 +31,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. BEGIN_BLD_NS -DCoreActor* GameInterface::getConsoleActor() -{ - return gPlayer[myconnectindex].actor; -} - void GameInterface::ToggleThirdPerson() { if (gamestate != GS_LEVEL) return; diff --git a/source/games/duke/src/ccmds.cpp b/source/games/duke/src/ccmds.cpp index 0cbfc875c..e46488cc5 100644 --- a/source/games/duke/src/ccmds.cpp +++ b/source/games/duke/src/ccmds.cpp @@ -118,11 +118,6 @@ static int ccmd_spawn(CCmdFuncPtr parm) return CCMD_OK; } -DCoreActor* GameInterface::getConsoleActor() -{ - return ps[myconnectindex].GetActor(); -} - void GameInterface::ToggleThirdPerson() { if (gamestate != GS_LEVEL) return; diff --git a/source/games/duke/src/duke3d.h b/source/games/duke/src/duke3d.h index 430abe230..a85ada872 100644 --- a/source/games/duke/src/duke3d.h +++ b/source/games/duke/src/duke3d.h @@ -19,6 +19,8 @@ BEGIN_DUKE_NS +extern player_struct ps[MAXPLAYERS]; + struct GameInterface : public ::GameInterface { const char* Name() override { return "Duke"; } @@ -50,7 +52,7 @@ struct GameInterface : public ::GameInterface void NewGame(MapRecord* map, int skill, bool) override; void LevelCompleted(MapRecord* map, int skill) override; bool DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos, const DAngle cang, const DVector2& xydim, const double czoom, double const interpfrac) override; - DCoreActor* getConsoleActor() override; + DCoreActor* getConsoleActor() override { return ps[myconnectindex].GetActor(); } void ToggleThirdPerson() override; void SwitchCoopView() override; void ToggleShowWeapon() override; diff --git a/source/games/exhumed/src/exhumed.h b/source/games/exhumed/src/exhumed.h index c89973a50..8c0269eea 100644 --- a/source/games/exhumed/src/exhumed.h +++ b/source/games/exhumed/src/exhumed.h @@ -34,6 +34,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "exhumedactor.h" #include "serialize_obj.h" #include "texturemanager.h" +#include "player.h" BEGIN_PS_NS @@ -234,7 +235,7 @@ struct GameInterface : public ::GameInterface bool DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos, const DAngle cang, const DVector2& xydim, const double czoom, double const interpfrac) override; DAngle playerPitchMin() override { return DAngle::fromDeg(49.5); } DAngle playerPitchMax() override { return DAngle::fromDeg(-49.5); } - DCoreActor* getConsoleActor() override; + DCoreActor* getConsoleActor() override { return PlayerList[nLocalPlayer].pActor; } void ToggleThirdPerson() override; void processSprites(tspriteArray& tsprites, const DVector3& view, DAngle viewang, double interpfrac) override; int GetCurrentSkill() override; diff --git a/source/games/exhumed/src/osdcmds.cpp b/source/games/exhumed/src/osdcmds.cpp index 162e020ef..482824946 100644 --- a/source/games/exhumed/src/osdcmds.cpp +++ b/source/games/exhumed/src/osdcmds.cpp @@ -39,17 +39,6 @@ BEGIN_PS_NS // //--------------------------------------------------------------------------- -DCoreActor* GameInterface::getConsoleActor() -{ - return PlayerList[nLocalPlayer].pActor; -} - -//--------------------------------------------------------------------------- -// -// -// -//--------------------------------------------------------------------------- - static int osdcmd_doors(CCmdFuncPtr parm) { for (int i = 0; i < kMaxChannels; i++) diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index 9c3d7a7bb..68cb35b62 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -1661,52 +1661,6 @@ extern int ChopTics; extern int Bunny_Count; -struct GameInterface : public ::GameInterface -{ - const char* Name() override { return "ShadowWarrior"; } - void app_init() override; - void LoadTextureInfo(TilesetBuildInfo& info) override; - void SetupSpecialTextures(TilesetBuildInfo& info) override; - void loadPalette() override; - void clearlocalinputstate() override; - void FreeLevelData() override; - bool GenerateSavePic() override; - void MenuSound(EMenuSounds snd) override; - bool CanSave() override; - bool StartGame(FNewGameStartup& gs) override; - FSavegameInfo GetSaveSig() override; - void SerializeGameState(FSerializer& arc); - void SetAmbience(bool on) override { if (on) StartAmbientSound(); else StopAmbientSound(); } - void UpdateSounds() override; - void ErrorCleanup() override; - void GetInput(const double scaleAdjust, InputPacket* input = nullptr) override; - void DrawBackground(void) override; - void Ticker(void) override; - void Render() override; - //void DrawWeapons() override; - void Startup() override; - const char *CheckCheatMode() override; - const char* GenericCheat(int player, int cheat) override; - void LevelCompleted(MapRecord *map, int skill) override; - void NextLevel(MapRecord *map, int skill) override; - void NewGame(MapRecord *map, int skill, bool) override; - bool DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos, const DAngle cang, const DVector2& xydim, const double czoom, double const interpfrac) override; - DCoreActor* getConsoleActor() override; - void ToggleThirdPerson() override; - void SwitchCoopView() override; - void processSprites(tspriteArray& tsprites, const DVector3& view, DAngle viewang, double smoothRatio) override; - void UpdateCameras(double smoothratio) override; - void EnterPortal(DCoreActor* viewer, int type) override; - void LeavePortal(DCoreActor* viewer, int type) override; - void ExitFromMenu() override; - int GetCurrentSkill() override; - void StartSoundEngine() override; - - - GameStats getStats() override; -}; - - END_SW_NS #include "swactor.h" @@ -1897,6 +1851,52 @@ struct PLAYER extern PLAYER Player[MAX_SW_PLAYERS_REG+1]; +struct GameInterface : public ::GameInterface +{ + const char* Name() override { return "ShadowWarrior"; } + void app_init() override; + void LoadTextureInfo(TilesetBuildInfo& info) override; + void SetupSpecialTextures(TilesetBuildInfo& info) override; + void loadPalette() override; + void clearlocalinputstate() override; + void FreeLevelData() override; + bool GenerateSavePic() override; + void MenuSound(EMenuSounds snd) override; + bool CanSave() override; + bool StartGame(FNewGameStartup& gs) override; + FSavegameInfo GetSaveSig() override; + void SerializeGameState(FSerializer& arc); + void SetAmbience(bool on) override { if (on) StartAmbientSound(); else StopAmbientSound(); } + void UpdateSounds() override; + void ErrorCleanup() override; + void GetInput(const double scaleAdjust, InputPacket* input = nullptr) override; + void DrawBackground(void) override; + void Ticker(void) override; + void Render() override; + //void DrawWeapons() override; + void Startup() override; + const char *CheckCheatMode() override; + const char* GenericCheat(int player, int cheat) override; + void LevelCompleted(MapRecord *map, int skill) override; + void NextLevel(MapRecord *map, int skill) override; + void NewGame(MapRecord *map, int skill, bool) override; + bool DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos, const DAngle cang, const DVector2& xydim, const double czoom, double const interpfrac) override; + DCoreActor* getConsoleActor() override { return Player[myconnectindex].actor; } + void ToggleThirdPerson() override; + void SwitchCoopView() override; + void processSprites(tspriteArray& tsprites, const DVector3& view, DAngle viewang, double smoothRatio) override; + void UpdateCameras(double smoothratio) override; + void EnterPortal(DCoreActor* viewer, int type) override; + void LeavePortal(DCoreActor* viewer, int type) override; + void ExitFromMenu() override; + int GetCurrentSkill() override; + void StartSoundEngine() override; + + + GameStats getStats() override; +}; + + // OVER and UNDER water macros inline bool SectorIsDiveArea(sectortype* sect) { diff --git a/source/games/sw/src/osdcmds.cpp b/source/games/sw/src/osdcmds.cpp index e2720b157..5d0e0d00a 100644 --- a/source/games/sw/src/osdcmds.cpp +++ b/source/games/sw/src/osdcmds.cpp @@ -54,17 +54,6 @@ BEGIN_SW_NS // //--------------------------------------------------------------------------- -DCoreActor* GameInterface::getConsoleActor() -{ - return Player[myconnectindex].actor; -} - -//--------------------------------------------------------------------------- -// -// -// -//--------------------------------------------------------------------------- - static int osdcmd_mirror(CCmdFuncPtr parm) { char base[80]; From b3c27a177e4787bf9341973039e73c1403e1b230 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sat, 18 Mar 2023 19:48:18 +1100 Subject: [PATCH 64/67] - Consolidate each game's `gi-GetInput()` into a unified function. * Eliminates a lot of boilerplate. * Consolidation of input accumulation buffers discretely used in each game. * Allows privatisation of `PlayerAngles::CameraAngles`. --- source/core/gameinput.cpp | 52 +++++++++++++++++- source/core/gameinput.h | 15 +++-- source/core/gamestruct.h | 9 ++- source/core/inputstate.cpp | 2 +- source/core/mainloop.cpp | 5 +- source/games/blood/all.cpp | 1 - source/games/blood/src/blood.h | 3 +- source/games/blood/src/controls.cpp | 85 ----------------------------- source/games/duke/src/duke3d.h | 5 +- source/games/duke/src/game_misc.cpp | 2 +- source/games/duke/src/input.cpp | 44 +-------------- source/games/exhumed/src/exhumed.h | 3 +- source/games/exhumed/src/input.cpp | 51 ----------------- source/games/sw/src/draw.cpp | 4 +- source/games/sw/src/game.cpp | 3 - source/games/sw/src/game.h | 6 +- source/games/sw/src/input.cpp | 49 ----------------- source/games/sw/src/network.h | 1 - source/games/sw/src/save.cpp | 1 - 19 files changed, 82 insertions(+), 259 deletions(-) diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index 709370f7b..60dde8ba4 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -21,6 +21,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ //------------------------------------------------------------------------- +#include "menu.h" +#include "gamestate.h" #include "gameinput.h" //--------------------------------------------------------------------------- @@ -49,6 +51,7 @@ static constexpr double PITCH_HORIZOFFSPEED = 4.375; static constexpr DAngle PITCH_CNTRSINEOFFSET = DAngle90 / 8.; static constexpr DAngle PITCH_HORIZOFFCLIMB = DAngle::fromDeg(-38.); static constexpr DAngle PITCH_HORIZOFFPUSH = DAngle::fromDeg(0.4476); +static InputPacket inputBuffer{}; //--------------------------------------------------------------------------- @@ -110,9 +113,11 @@ void resetTurnHeldAmt() // //--------------------------------------------------------------------------- -void processMovement(HIDInput* const hidInput, InputPacket* const inputBuffer, InputPacket* const currInput, const double scaleAdjust, const int drink_amt, const bool allowstrafe, const double turnscale) +void processMovement(HIDInput* const hidInput, InputPacket* const inputBuffer, InputPacket* const currInput, const double scaleAdjust, const InputOptions& inputOpts) { // set up variables. + const bool allowstrafe = isDukeEngine() ? true : inputOpts.first; + const double turnscale = inputOpts.second; const int keymove = 1 << int(!!(inputBuffer->actions & SB_RUN)); const float hidspeed = float(getTicrateScale(YAW_TURNSPEEDS[2]) * turnscale); const float scaleAdjustf = float(scaleAdjust); @@ -146,8 +151,8 @@ void processMovement(HIDInput* const hidInput, InputPacket* const inputBuffer, I currInput->svel += strafing * keymove * allowstrafe; // process RR's drunk state. - if (isRR() && drink_amt >= 66 && drink_amt <= 87) - currInput->svel += drink_amt & 1 ? -currInput->fvel : currInput->fvel; + if (isRR() && inputOpts.first) + currInput->svel += inputOpts.first & 1 ? -currInput->fvel : currInput->fvel; // add collected input to game's local input accumulation packet. inputBuffer->fvel = clamp(inputBuffer->fvel + currInput->fvel, -(float)keymove, (float)keymove); @@ -157,6 +162,47 @@ void processMovement(HIDInput* const hidInput, InputPacket* const inputBuffer, I } +//--------------------------------------------------------------------------- +// +// Processes input and returns a packet if provided. +// +//--------------------------------------------------------------------------- + +void clearLocalInputBuffer() +{ + inputBuffer = {}; +} + +void getInput(const double scaleAdjust, PlayerAngles* const plrAngles, InputPacket* packet) +{ + if (paused || M_Active() || gamestate != GS_LEVEL || !plrAngles || !plrAngles->pActor) + { + clearLocalInputBuffer(); + return; + } + + const auto inputOpts = gi->GetInputOptions(); + InputPacket input{}; + HIDInput hidInput{}; + getHidInput(&hidInput); + ApplyGlobalInput(&hidInput, &inputBuffer); + gi->GetInput(&hidInput, &inputBuffer, &input, !SyncInput() ? scaleAdjust : 1., inputOpts); + + // Directly update the camera angles if we're unsynchronised. + if (!SyncInput()) + { + plrAngles->CameraAngles.Yaw += DAngle::fromDeg(input.avel); + plrAngles->CameraAngles.Pitch += DAngle::fromDeg(input.horz); + } + + if (packet) + { + *packet = inputBuffer; + clearLocalInputBuffer(); + } +} + + //--------------------------------------------------------------------------- // // Adjust player's pitch by way of keyboard input. diff --git a/source/core/gameinput.h b/source/core/gameinput.h index 3205f6c34..1ab5674b1 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -8,13 +8,11 @@ struct PlayerAngles // Player viewing angles, separate from the camera. DRotator PrevViewAngles, ViewAngles; - // Player camera angles, not for direct manipulation within the playsim. - DRotator CameraAngles; - // Holder of current yaw spin state for the 180 degree turn. DAngle YawSpin; friend FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngles& w, PlayerAngles* def); + friend void getInput(const double scaleAdjust, PlayerAngles* const plrAngles, InputPacket* packet); // Prototypes. void doPitchKeys(InputPacket* const input); @@ -34,6 +32,10 @@ struct PlayerAngles } // Render angle functions. + const DRotator& getCameraAngles() + { + return CameraAngles; + } DRotator getRenderAngles(const double interpfrac) { // Get angles and return with clamped off pitch. @@ -71,8 +73,8 @@ struct PlayerAngles } private: - // Private data which should never be accessed publically. - DRotator PrevLerpAngles; + // Private data which should never be accessed publicly. + DRotator PrevLerpAngles, CameraAngles; DCoreActor* pActor; }; @@ -83,4 +85,5 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngles& w, P void updateTurnHeldAmt(const double scaleAdjust); bool isTurboTurnTime(); void resetTurnHeldAmt(); -void processMovement(HIDInput* const hidInput, InputPacket* const inputBuffer, InputPacket* const currInput, const double scaleAdjust, const int drink_amt = 0, const bool allowstrafe = true, const double turnscale = 1); +void clearLocalInputBuffer(); +void getInput(const double scaleAdjust, PlayerAngles* const plrAngles, InputPacket* packet = nullptr); diff --git a/source/core/gamestruct.h b/source/core/gamestruct.h index 9f1e3cb9c..5d01278fc 100644 --- a/source/core/gamestruct.h +++ b/source/core/gamestruct.h @@ -17,6 +17,10 @@ struct sectortype; struct tspritetype; class DCoreActor; struct MapRecord; +struct PlayerAngles; + +using InputOptions = std::pair; +void processMovement(HIDInput* const hidInput, InputPacket* const inputBuffer, InputPacket* const currInput, const double scaleAdjust, const InputOptions& inputOpts); struct GameStats { @@ -69,7 +73,6 @@ struct GameInterface virtual void LoadTextureInfo(TilesetBuildInfo& info) {} virtual void SetupSpecialTextures(TilesetBuildInfo&) {} virtual void loadPalette(); - virtual void clearlocalinputstate() {} virtual void UpdateScreenSize() {} virtual void FreeLevelData(); virtual void FreeGameData() {} @@ -88,7 +91,8 @@ struct GameInterface virtual void DrawPlayerSprite(const DVector2& origin, bool onteam) {} virtual void SetAmbience(bool on) {} virtual void ExitFromMenu() { throw CExitEvent(0); } - virtual void GetInput(const double scaleAdjust, InputPacket* packet = nullptr) {} + virtual void GetInput(HIDInput* const hidInput, InputPacket* const inputBuffer, InputPacket* const currInput, const double scaleAdjust, const InputOptions& inputOpts) { processMovement(hidInput, inputBuffer, currInput, scaleAdjust, inputOpts); } + virtual InputOptions GetInputOptions() { return std::make_pair(true, 1.); } virtual void UpdateSounds() {} virtual void ErrorCleanup() {} virtual void Startup() {} @@ -105,6 +109,7 @@ struct GameInterface virtual DAngle playerPitchMin() { return DAngle::fromDeg(57.375); } virtual DAngle playerPitchMax() { return DAngle::fromDeg(-57.375); } virtual DCoreActor* getConsoleActor() = 0; + virtual PlayerAngles* getConsoleAngles() = 0; virtual void ToggleThirdPerson() { } virtual void SwitchCoopView() { Printf("Unsupported command\n"); } virtual void ToggleShowWeapon() { Printf("Unsupported command\n"); } diff --git a/source/core/inputstate.cpp b/source/core/inputstate.cpp index 211edc07c..e514c9260 100644 --- a/source/core/inputstate.cpp +++ b/source/core/inputstate.cpp @@ -142,7 +142,7 @@ void InputState::ClearAllInput() { ActionsToSend = 0; crouch_toggle = false; - gi->clearlocalinputstate(); // also clear game local input state. + clearLocalInputBuffer(); // also clear game local input state. } else if (gamestate == GS_LEVEL && crouch_toggle) { diff --git a/source/core/mainloop.cpp b/source/core/mainloop.cpp index 7267adae5..6f7681280 100644 --- a/source/core/mainloop.cpp +++ b/source/core/mainloop.cpp @@ -91,6 +91,7 @@ #include "i_interface.h" #include "texinfo.h" #include "texturemanager.h" +#include "gameinput.h" CVAR(Bool, vid_activeinbackground, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) CVAR(Bool, r_ticstability, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) @@ -136,7 +137,7 @@ void G_BuildTiccmd(ticcmd_t* cmd) } cmd->ucmd = {}; I_GetEvent(); - gi->GetInput(!SyncInput() ? inputScale : 1., &cmd->ucmd); + getInput(inputScale, gi->getConsoleAngles(), &cmd->ucmd); cmd->consistency = consistency[myconnectindex][(maketic / ticdup) % BACKUPTICS]; } @@ -614,7 +615,7 @@ void TryRunTics (void) if (!SyncInput()) { I_GetEvent(); - gi->GetInput(!SyncInput() ? inputScale : 1.); + getInput(inputScale, gi->getConsoleAngles()); } return; } diff --git a/source/games/blood/all.cpp b/source/games/blood/all.cpp index 9d5a25080..614475060 100644 --- a/source/games/blood/all.cpp +++ b/source/games/blood/all.cpp @@ -30,7 +30,6 @@ #include "src/blood.cpp" #include "src/callback.cpp" #include "src/choke.cpp" -#include "src/controls.cpp" #include "src/db.cpp" #include "src/dude.cpp" #include "src/endgame.cpp" diff --git a/source/games/blood/src/blood.h b/source/games/blood/src/blood.h index b3b381854..797eb61e9 100644 --- a/source/games/blood/src/blood.h +++ b/source/games/blood/src/blood.h @@ -111,7 +111,6 @@ struct GameInterface : public ::GameInterface void app_init() override; void SerializeGameState(FSerializer& arc) override; void loadPalette() override; - void clearlocalinputstate() override; bool GenerateSavePic() override; void FreeLevelData() override; void FreeGameData() override; @@ -120,7 +119,6 @@ struct GameInterface : public ::GameInterface void MenuClosed() override; bool CanSave() override; void UpdateSounds() override; - void GetInput(const double scaleAdjust, InputPacket* packet = nullptr) override; void Ticker() override; void DrawBackground() override; void Startup() override; @@ -133,6 +131,7 @@ struct GameInterface : public ::GameInterface DAngle playerPitchMin() override { return DAngle::fromDeg(54.575); } DAngle playerPitchMax() override { return DAngle::fromDeg(-43.15); } DCoreActor* getConsoleActor() override { return gPlayer[myconnectindex].actor; } + PlayerAngles* getConsoleAngles() override { return &gPlayer[myconnectindex].Angles; } void ToggleThirdPerson() override; void SwitchCoopView() override; void ToggleShowWeapon() override; diff --git a/source/games/blood/src/controls.cpp b/source/games/blood/src/controls.cpp index ea1ed63ea..e69de29bb 100644 --- a/source/games/blood/src/controls.cpp +++ b/source/games/blood/src/controls.cpp @@ -1,85 +0,0 @@ -#pragma once -//------------------------------------------------------------------------- -/* -Copyright (C) 2020 Christoph Oelckers & Mitchell Richters - -This file is part of Raze. - -Raze is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License version 2 -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - -See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ -//------------------------------------------------------------------------- - -#include "ns.h" // Must come before everything else! - -#include "blood.h" -#include "gamestate.h" -#include "inputstate.h" -#include "gamestruct.h" -#include "razemenu.h" - -BEGIN_BLD_NS - -static InputPacket gInput; - -//--------------------------------------------------------------------------- -// -// -// -//--------------------------------------------------------------------------- - -void GameInterface::GetInput(const double scaleAdjust, InputPacket* packet) -{ - if (paused || M_Active()) - { - gInput = {}; - return; - } - - HIDInput hidInput; - getHidInput(&hidInput); - - PLAYER* pPlayer = &gPlayer[myconnectindex]; - InputPacket input{}; - - ApplyGlobalInput(&hidInput, &gInput); - processMovement(&hidInput, &gInput, &input, scaleAdjust); - - // Perform unsynchronised angle/horizon if not dead. - if (!SyncInput() && gamestate == GS_LEVEL) - { - pPlayer->Angles.CameraAngles.Yaw += DAngle::fromDeg(input.avel); - pPlayer->Angles.CameraAngles.Pitch += DAngle::fromDeg(input.horz); - } - - if (packet) - { - *packet = gInput; - gInput = {}; - } -} - -//--------------------------------------------------------------------------- -// -// This is called from InputState::ClearAllInput and resets all static state being used here. -// -//--------------------------------------------------------------------------- - -void GameInterface::clearlocalinputstate() -{ - gInput = {}; -} - -END_BLD_NS diff --git a/source/games/duke/src/duke3d.h b/source/games/duke/src/duke3d.h index a85ada872..446e5c6bb 100644 --- a/source/games/duke/src/duke3d.h +++ b/source/games/duke/src/duke3d.h @@ -27,7 +27,6 @@ struct GameInterface : public ::GameInterface void app_init() override; void loadPalette() override; void SetupSpecialTextures(TilesetBuildInfo& info) override; - void clearlocalinputstate() override; bool GenerateSavePic() override; void PlayHudSound() override; GameStats getStats() override; @@ -40,7 +39,8 @@ struct GameInterface : public ::GameInterface void SerializeGameState(FSerializer& arc) override; void ExitFromMenu() override; void DrawPlayerSprite(const DVector2& origin, bool onteam) override; - void GetInput(const double scaleAdjust, InputPacket* packet = nullptr) override; + void GetInput(HIDInput* const hidInput, InputPacket* const inputBuffer, InputPacket* const currInput, const double scaleAdjust, const InputOptions& inputOpts) override; + InputOptions GetInputOptions() override { return std::make_pair(ps[myconnectindex].drink_amt >= 66 && ps[myconnectindex].drink_amt <= 87, 1.); } void UpdateSounds() override; void Startup() override; void DrawBackground() override; @@ -53,6 +53,7 @@ struct GameInterface : public ::GameInterface void LevelCompleted(MapRecord* map, int skill) override; bool DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos, const DAngle cang, const DVector2& xydim, const double czoom, double const interpfrac) override; DCoreActor* getConsoleActor() override { return ps[myconnectindex].GetActor(); } + PlayerAngles* getConsoleAngles() override { return &ps[myconnectindex].Angles; } void ToggleThirdPerson() override; void SwitchCoopView() override; void ToggleShowWeapon() override; diff --git a/source/games/duke/src/game_misc.cpp b/source/games/duke/src/game_misc.cpp index fe6dd8159..2a655b1d7 100644 --- a/source/games/duke/src/game_misc.cpp +++ b/source/games/duke/src/game_misc.cpp @@ -419,7 +419,7 @@ bool GameInterface::DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos, double j = clamp(czoom * act->spr.scale.Y + abs(pp.truefz - act->getOffsetZ()) * REPEAT_SCALE, (1. / 3.), 2.); auto const vec = OutAutomapVector(mxy - cpos, cangvect, czoom, xydim); - auto const daang = -(pp.Angles.CameraAngles.Yaw - cang).Normalized360().Degrees(); + auto const daang = -(pp.Angles.getCameraAngles().Yaw - cang).Normalized360().Degrees(); DrawTexture(twod, tileGetTexture(i), vec.X, vec.Y, DTA_TranslationIndex, TRANSLATION(Translation_Remap + setpal(&pp), act->spr.pal), DTA_CenterOffset, true, DTA_Rotate, daang, DTA_Color, shadeToLight(act->spr.shade), DTA_ScaleX, j, DTA_ScaleY, j, TAG_DONE); diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 8136d78e6..91a06ccc2 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -44,9 +44,6 @@ EXTERN_CVAR(Float, m_yaw) BEGIN_DUKE_NS -// State timer counters. -static InputPacket loc; // input accumulation buffer. - //--------------------------------------------------------------------------- // // handles all HUD related input, i.e. inventory item selection and activation plus weapon selection. @@ -748,53 +745,18 @@ static void processVehicleInput(player_struct *p, HIDInput* const hidInput, Inpu // //--------------------------------------------------------------------------- -void GameInterface::GetInput(const double scaleAdjust, InputPacket* packet) +void GameInterface::GetInput(HIDInput* const hidInput, InputPacket* const inputBuffer, InputPacket* const currInput, const double scaleAdjust, const InputOptions& inputOpts) { - if (paused || gamestate != GS_LEVEL) - { - loc = {}; - return; - } - - HIDInput hidInput; - getHidInput(&hidInput); - auto const p = &ps[myconnectindex]; - InputPacket input{}; - - ApplyGlobalInput(&hidInput, &loc); if (isRRRA() && (p->OnMotorcycle || p->OnBoat)) { - processVehicleInput(p, &hidInput, &loc, &input, scaleAdjust); + processVehicleInput(p, hidInput, inputBuffer, currInput, scaleAdjust); } else { - processMovement(&hidInput, &loc, &input, scaleAdjust, p->drink_amt); + processMovement(hidInput, inputBuffer, currInput, scaleAdjust, inputOpts); } - - if (!SyncInput() && p->GetActor()->spr.extra > 0) - { - p->Angles.CameraAngles.Yaw += p->adjustavel(input.avel); - p->Angles.CameraAngles.Pitch += DAngle::fromDeg(input.horz); - } - - if (packet) - { - *packet = loc; - loc = {}; - } -} - -//--------------------------------------------------------------------------- -// -// This is called from InputState::ClearAllInput and resets all static state being used here. -// -//--------------------------------------------------------------------------- - -void GameInterface::clearlocalinputstate() -{ - loc = {}; } diff --git a/source/games/exhumed/src/exhumed.h b/source/games/exhumed/src/exhumed.h index 8c0269eea..519c98561 100644 --- a/source/games/exhumed/src/exhumed.h +++ b/source/games/exhumed/src/exhumed.h @@ -212,7 +212,6 @@ struct GameInterface : public ::GameInterface const char* Name() override { return "Exhumed"; } void app_init() override; void SetupSpecialTextures(TilesetBuildInfo& info) override; - void clearlocalinputstate() override; void loadPalette() override; bool GenerateSavePic() override; void MenuOpened() override; @@ -226,7 +225,6 @@ struct GameInterface : public ::GameInterface void DrawBackground() override; void Render() override; //void DrawWeapons() override; - void GetInput(const double scaleAdjust, InputPacket* packet = nullptr) override; void Startup() override; const char* GenericCheat(int player, int cheat) override; void NewGame(MapRecord *map, int skill, bool) override; @@ -236,6 +234,7 @@ struct GameInterface : public ::GameInterface DAngle playerPitchMin() override { return DAngle::fromDeg(49.5); } DAngle playerPitchMax() override { return DAngle::fromDeg(-49.5); } DCoreActor* getConsoleActor() override { return PlayerList[nLocalPlayer].pActor; } + PlayerAngles* getConsoleAngles() override { return &PlayerList[nLocalPlayer].Angles; } void ToggleThirdPerson() override; void processSprites(tspriteArray& tsprites, const DVector3& view, DAngle viewang, double interpfrac) override; int GetCurrentSkill() override; diff --git a/source/games/exhumed/src/input.cpp b/source/games/exhumed/src/input.cpp index 600d3feaa..7c82e0d69 100644 --- a/source/games/exhumed/src/input.cpp +++ b/source/games/exhumed/src/input.cpp @@ -25,8 +25,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. BEGIN_PS_NS -static InputPacket localInput; - //--------------------------------------------------------------------------- // // @@ -39,53 +37,4 @@ void ClearSpaceBar(int nPlayer) buttonMap.ClearButton(gamefunc_Open); } - -//--------------------------------------------------------------------------- -// -// -// -//--------------------------------------------------------------------------- - -void GameInterface::GetInput(const double scaleAdjust, InputPacket* packet) -{ - if (paused || M_Active()) - { - localInput = {}; - return; - } - - HIDInput hidInput; - getHidInput(&hidInput); - - ApplyGlobalInput(&hidInput, &localInput); - - Player* pPlayer = &PlayerList[nLocalPlayer]; - InputPacket input {}; - - processMovement(&hidInput, &localInput, &input, scaleAdjust); - - if (!SyncInput() && gamestate == GS_LEVEL) - { - pPlayer->Angles.CameraAngles.Yaw += DAngle::fromDeg(input.avel); - pPlayer->Angles.CameraAngles.Pitch += DAngle::fromDeg(input.horz); - } - - if (packet) - { - *packet = localInput; - localInput = {}; - } -} - -//--------------------------------------------------------------------------- -// -// This is called from InputState::ClearAllInput and resets all static state being used here. -// -//--------------------------------------------------------------------------- - -void GameInterface::clearlocalinputstate() -{ - localInput = {}; -} - END_PS_NS diff --git a/source/games/sw/src/draw.cpp b/source/games/sw/src/draw.cpp index 7d0ca917e..734ce4def 100644 --- a/source/games/sw/src/draw.cpp +++ b/source/games/sw/src/draw.cpp @@ -803,7 +803,7 @@ static void analyzesprites(tspriteArray& tsprites, const DVector3& viewpos, doub } tsp->pos = pos; - tsp->Angles.Yaw = pp->Angles.CameraAngles.Yaw; + tsp->Angles.Yaw = pp->Angles.getCameraAngles().Yaw; //continue; } else @@ -1445,7 +1445,7 @@ bool GameInterface::DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos, if (spnum >= 0) { - const auto daang = -(pp->Angles.CameraAngles.Yaw - cang).Normalized360().Degrees(); + const auto daang = -(pp->Angles.getCameraAngles().Yaw - cang).Normalized360().Degrees(); auto vect = OutAutomapVector(mxy - cpos, cangvect, czoom, xydim); // This repeat scale is correct. diff --git a/source/games/sw/src/game.cpp b/source/games/sw/src/game.cpp index 138270295..724659674 100644 --- a/source/games/sw/src/game.cpp +++ b/source/games/sw/src/game.cpp @@ -502,9 +502,6 @@ void InitRunLevel(void) // send packets with player info InitNetPlayerOptions(); - // Initialize Game part of network code - InitNetVars(); - if (currentLevel) { PlaySong(currentLevel->music, currentLevel->cdSongId); diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index 68cb35b62..119a90ff3 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -1587,8 +1587,6 @@ void SyncStatMessage(void); // sync.c int COVERsetgamemode(int mode, int xdim, int ydim, int bpp); // draw.c void ScreenCaptureKeys(void); // draw.c -void computergetinput(int snum,InputPacket *syn); // jplayer.c - void SetupMirrorTiles(void); // rooms.c bool FAF_Sector(sectortype* sect); // rooms.c double GetZadjustment(sectortype* sect,short hitag); // rooms.c @@ -1858,7 +1856,6 @@ struct GameInterface : public ::GameInterface void LoadTextureInfo(TilesetBuildInfo& info) override; void SetupSpecialTextures(TilesetBuildInfo& info) override; void loadPalette() override; - void clearlocalinputstate() override; void FreeLevelData() override; bool GenerateSavePic() override; void MenuSound(EMenuSounds snd) override; @@ -1869,7 +1866,7 @@ struct GameInterface : public ::GameInterface void SetAmbience(bool on) override { if (on) StartAmbientSound(); else StopAmbientSound(); } void UpdateSounds() override; void ErrorCleanup() override; - void GetInput(const double scaleAdjust, InputPacket* input = nullptr) override; + InputOptions GetInputOptions() override { return std::make_pair(!Player[myconnectindex].sop, Player[myconnectindex].sop_control ? 3. / 1.40625 : 1.); } void DrawBackground(void) override; void Ticker(void) override; void Render() override; @@ -1882,6 +1879,7 @@ struct GameInterface : public ::GameInterface void NewGame(MapRecord *map, int skill, bool) override; bool DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos, const DAngle cang, const DVector2& xydim, const double czoom, double const interpfrac) override; DCoreActor* getConsoleActor() override { return Player[myconnectindex].actor; } + PlayerAngles* getConsoleAngles() override { return &Player[myconnectindex].Angles; } void ToggleThirdPerson() override; void SwitchCoopView() override; void processSprites(tspriteArray& tsprites, const DVector3& view, DAngle viewang, double smoothRatio) override; diff --git a/source/games/sw/src/input.cpp b/source/games/sw/src/input.cpp index 47d36e972..fd2948d38 100644 --- a/source/games/sw/src/input.cpp +++ b/source/games/sw/src/input.cpp @@ -34,19 +34,12 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms BEGIN_SW_NS -static InputPacket loc; - //--------------------------------------------------------------------------- // // // //--------------------------------------------------------------------------- -void InitNetVars(void) -{ - loc = {}; -} - void InitTimingVars(void) { PlayClock = 0; @@ -157,46 +150,4 @@ void processWeapon(PLAYER* const pp) } } -void GameInterface::GetInput(const double scaleAdjust, InputPacket *packet) -{ - PLAYER* pp = &Player[myconnectindex]; - - if (paused || M_Active() || pp->actor == nullptr) - { - loc = {}; - return; - } - - HIDInput hidInput; - getHidInput(&hidInput); - - InputPacket input {}; - - ApplyGlobalInput(&hidInput, &loc); - processMovement(&hidInput, &loc, &input, scaleAdjust, 0, !pp->sop, pp->sop_control ? 3. / 1.40625 : 1.); - - if (!SyncInput()) - { - pp->Angles.CameraAngles.Yaw += DAngle::fromDeg(input.avel); - pp->Angles.CameraAngles.Pitch += DAngle::fromDeg(input.horz); - } - - if (packet) - { - *packet = loc; - loc = {}; - } -} - -//--------------------------------------------------------------------------- -// -// This is called from InputState::ClearAllInput and resets all static state being used here. -// -//--------------------------------------------------------------------------- - -void GameInterface::clearlocalinputstate() -{ - loc = {}; -} - END_SW_NS diff --git a/source/games/sw/src/network.h b/source/games/sw/src/network.h index 08df66605..55f4aa91e 100644 --- a/source/games/sw/src/network.h +++ b/source/games/sw/src/network.h @@ -74,7 +74,6 @@ struct gNET extern gNET gNet; void UpdateInputs(void); -void InitNetVars(void); void InitTimingVars(void); void InitNetPlayerOptions(void); inline void SW_SendMessage(short, const char*) {} diff --git a/source/games/sw/src/save.cpp b/source/games/sw/src/save.cpp index d1b87182c..d85487d5b 100644 --- a/source/games/sw/src/save.cpp +++ b/source/games/sw/src/save.cpp @@ -1160,7 +1160,6 @@ void GameInterface::SerializeGameState(FSerializer& arc) InitTimingVars(); PlayClock = SavePlayClock; defineSky(nullptr, pskybits_override, nullptr, 0, parallaxyscale_override / 8192.f); - InitNetVars(); screenpeek = myconnectindex; From 672c53c35c6e5b18d8ea925d9bb3265d61b193c6 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sat, 18 Mar 2023 19:54:05 +1100 Subject: [PATCH 65/67] - Move CCMD `pause` to gamecontrol.cpp so it can be static. --- source/core/gamecontrol.cpp | 7 +++++++ source/core/gamecontrol.h | 1 - source/core/inputstate.cpp | 6 ------ 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/source/core/gamecontrol.cpp b/source/core/gamecontrol.cpp index 2a7887895..fd24e9227 100644 --- a/source/core/gamecontrol.cpp +++ b/source/core/gamecontrol.cpp @@ -178,6 +178,7 @@ CVAR(Bool, disableautoload, false, CVAR_ARCHIVE | CVAR_NOINITCALL | CVAR_GLOBALC extern int hud_size_max; +static bool sendPause; bool pausedWithKey; bool gamesetinput = false; @@ -1289,6 +1290,12 @@ void CONFIG_ReadCombatMacros() //========================================================================== +CCMD(pause) +{ + sendPause = true; +} + + CCMD(snd_reset) { Mus_Stop(); diff --git a/source/core/gamecontrol.h b/source/core/gamecontrol.h index a950583b9..0647ec113 100644 --- a/source/core/gamecontrol.h +++ b/source/core/gamecontrol.h @@ -235,7 +235,6 @@ enum extern int paused; extern int chatmodeon; -extern bool sendPause; extern int lastTic; extern int PlayClock; diff --git a/source/core/inputstate.cpp b/source/core/inputstate.cpp index e514c9260..1bb8cb5d7 100644 --- a/source/core/inputstate.cpp +++ b/source/core/inputstate.cpp @@ -48,7 +48,6 @@ static int WeaponToSend = 0; ESyncBits ActionsToSend = 0; static int dpad_lock = 0; -bool sendPause; bool crouch_toggle; // Mouse speeds @@ -323,11 +322,6 @@ CCMD(holsterweapon) ActionsToSend |= SB_HOLSTER; } -CCMD(pause) -{ - sendPause = true; -} - CCMD(warptocoords) { if (netgame) From 366423a09be95961f78c736dd386afeb287637ab Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sat, 18 Mar 2023 20:14:01 +1100 Subject: [PATCH 66/67] - Extra const-ness that I'm not sure matters or not. --- source/core/gameinput.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/core/gameinput.h b/source/core/gameinput.h index 1ab5674b1..c82061a67 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -32,7 +32,7 @@ struct PlayerAngles } // Render angle functions. - const DRotator& getCameraAngles() + const DRotator& getCameraAngles() const { return CameraAngles; } From 1147030bcafbd36a6231e33e4775829aa64b4930 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sat, 18 Mar 2023 21:16:50 +1100 Subject: [PATCH 67/67] - Remove concept of `InputOptions`, its messy and unnecessary. --- source/core/gameinput.cpp | 11 ++++------- source/core/gamestruct.h | 6 ++---- source/games/duke/src/duke3d.h | 3 +-- source/games/duke/src/input.cpp | 4 ++-- source/games/sw/src/game.h | 2 +- 5 files changed, 10 insertions(+), 16 deletions(-) diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index 60dde8ba4..abf235326 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -113,11 +113,9 @@ void resetTurnHeldAmt() // //--------------------------------------------------------------------------- -void processMovement(HIDInput* const hidInput, InputPacket* const inputBuffer, InputPacket* const currInput, const double scaleAdjust, const InputOptions& inputOpts) +void processMovement(HIDInput* const hidInput, InputPacket* const inputBuffer, InputPacket* const currInput, const double scaleAdjust, const int drink_amt, const bool allowstrafe, const double turnscale) { // set up variables. - const bool allowstrafe = isDukeEngine() ? true : inputOpts.first; - const double turnscale = inputOpts.second; const int keymove = 1 << int(!!(inputBuffer->actions & SB_RUN)); const float hidspeed = float(getTicrateScale(YAW_TURNSPEEDS[2]) * turnscale); const float scaleAdjustf = float(scaleAdjust); @@ -151,8 +149,8 @@ void processMovement(HIDInput* const hidInput, InputPacket* const inputBuffer, I currInput->svel += strafing * keymove * allowstrafe; // process RR's drunk state. - if (isRR() && inputOpts.first) - currInput->svel += inputOpts.first & 1 ? -currInput->fvel : currInput->fvel; + if (isRR() && drink_amt >= 66 && drink_amt <= 87) + currInput->svel += drink_amt & 1 ? -currInput->fvel : currInput->fvel; // add collected input to game's local input accumulation packet. inputBuffer->fvel = clamp(inputBuffer->fvel + currInput->fvel, -(float)keymove, (float)keymove); @@ -181,12 +179,11 @@ void getInput(const double scaleAdjust, PlayerAngles* const plrAngles, InputPack return; } - const auto inputOpts = gi->GetInputOptions(); InputPacket input{}; HIDInput hidInput{}; getHidInput(&hidInput); ApplyGlobalInput(&hidInput, &inputBuffer); - gi->GetInput(&hidInput, &inputBuffer, &input, !SyncInput() ? scaleAdjust : 1., inputOpts); + gi->GetInput(&hidInput, &inputBuffer, &input, !SyncInput() ? scaleAdjust : 1.); // Directly update the camera angles if we're unsynchronised. if (!SyncInput()) diff --git a/source/core/gamestruct.h b/source/core/gamestruct.h index 5d01278fc..1dbea4441 100644 --- a/source/core/gamestruct.h +++ b/source/core/gamestruct.h @@ -19,8 +19,7 @@ class DCoreActor; struct MapRecord; struct PlayerAngles; -using InputOptions = std::pair; -void processMovement(HIDInput* const hidInput, InputPacket* const inputBuffer, InputPacket* const currInput, const double scaleAdjust, const InputOptions& inputOpts); +void processMovement(HIDInput* const hidInput, InputPacket* const inputBuffer, InputPacket* const currInput, const double scaleAdjust, const int drink_amt = 0, const bool allowstrafe = true, const double turnscale = 1.); struct GameStats { @@ -91,8 +90,7 @@ struct GameInterface virtual void DrawPlayerSprite(const DVector2& origin, bool onteam) {} virtual void SetAmbience(bool on) {} virtual void ExitFromMenu() { throw CExitEvent(0); } - virtual void GetInput(HIDInput* const hidInput, InputPacket* const inputBuffer, InputPacket* const currInput, const double scaleAdjust, const InputOptions& inputOpts) { processMovement(hidInput, inputBuffer, currInput, scaleAdjust, inputOpts); } - virtual InputOptions GetInputOptions() { return std::make_pair(true, 1.); } + virtual void GetInput(HIDInput* const hidInput, InputPacket* const inputBuffer, InputPacket* const currInput, const double scaleAdjust) { processMovement(hidInput, inputBuffer, currInput, scaleAdjust); } virtual void UpdateSounds() {} virtual void ErrorCleanup() {} virtual void Startup() {} diff --git a/source/games/duke/src/duke3d.h b/source/games/duke/src/duke3d.h index 446e5c6bb..060d8bed0 100644 --- a/source/games/duke/src/duke3d.h +++ b/source/games/duke/src/duke3d.h @@ -39,8 +39,7 @@ struct GameInterface : public ::GameInterface void SerializeGameState(FSerializer& arc) override; void ExitFromMenu() override; void DrawPlayerSprite(const DVector2& origin, bool onteam) override; - void GetInput(HIDInput* const hidInput, InputPacket* const inputBuffer, InputPacket* const currInput, const double scaleAdjust, const InputOptions& inputOpts) override; - InputOptions GetInputOptions() override { return std::make_pair(ps[myconnectindex].drink_amt >= 66 && ps[myconnectindex].drink_amt <= 87, 1.); } + void GetInput(HIDInput* const hidInput, InputPacket* const inputBuffer, InputPacket* const currInput, const double scaleAdjust) override; void UpdateSounds() override; void Startup() override; void DrawBackground() override; diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 91a06ccc2..fc17a7727 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -745,7 +745,7 @@ static void processVehicleInput(player_struct *p, HIDInput* const hidInput, Inpu // //--------------------------------------------------------------------------- -void GameInterface::GetInput(HIDInput* const hidInput, InputPacket* const inputBuffer, InputPacket* const currInput, const double scaleAdjust, const InputOptions& inputOpts) +void GameInterface::GetInput(HIDInput* const hidInput, InputPacket* const inputBuffer, InputPacket* const currInput, const double scaleAdjust) { auto const p = &ps[myconnectindex]; @@ -755,7 +755,7 @@ void GameInterface::GetInput(HIDInput* const hidInput, InputPacket* const inputB } else { - processMovement(hidInput, inputBuffer, currInput, scaleAdjust, inputOpts); + processMovement(hidInput, inputBuffer, currInput, scaleAdjust, p->drink_amt); } } diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index 119a90ff3..e8160e584 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -1866,7 +1866,7 @@ struct GameInterface : public ::GameInterface void SetAmbience(bool on) override { if (on) StartAmbientSound(); else StopAmbientSound(); } void UpdateSounds() override; void ErrorCleanup() override; - InputOptions GetInputOptions() override { return std::make_pair(!Player[myconnectindex].sop, Player[myconnectindex].sop_control ? 3. / 1.40625 : 1.); } + void GetInput(HIDInput* const hidInput, InputPacket* const inputBuffer, InputPacket* const currInput, const double scaleAdjust) override { processMovement(hidInput, inputBuffer, currInput, scaleAdjust, 0, Player[myconnectindex].sop, Player[myconnectindex].sop_control ? 3. / 1.40625 : 1.); } void DrawBackground(void) override; void Ticker(void) override; void Render() override;