From b9e1cbb5de37b237ef8b0f9ba49c7ce6b9636d52 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Thu, 26 Nov 2020 16:37:37 +1100 Subject: [PATCH] - gamecontrol.h: Move `getHalfLookAng()` into `PlayerAngle` struct as `look_anghalf()`. * Uses internal struct variables at full BAM precision. --- source/blood/src/hudsprites.cpp | 4 ++-- source/blood/src/view.cpp | 2 +- source/blood/src/view.h | 2 +- source/core/gamecontrol.h | 11 ----------- source/core/gameinput.h | 11 +++++++++++ source/exhumed/src/gameloop.cpp | 3 +-- source/exhumed/src/gun.cpp | 2 +- source/games/duke/src/game_misc.cpp | 2 +- source/games/duke/src/hudweapon_d.cpp | 2 +- source/games/duke/src/hudweapon_r.cpp | 2 +- source/sw/src/draw.cpp | 2 +- source/sw/src/panel.cpp | 4 ++-- 12 files changed, 23 insertions(+), 24 deletions(-) diff --git a/source/blood/src/hudsprites.cpp b/source/blood/src/hudsprites.cpp index 3a47327ad..d9456d2b8 100644 --- a/source/blood/src/hudsprites.cpp +++ b/source/blood/src/hudsprites.cpp @@ -95,9 +95,9 @@ static void viewBurnTime(int gScale) } -void hudDraw(PLAYER *gView, VIEW *pView, int nSectnum, double bobx, double boby, double zDelta, int basepal, double smoothratio) +void hudDraw(PLAYER *gView, int nSectnum, double bobx, double boby, double zDelta, int basepal, double smoothratio) { - double look_anghalf = getHalfLookAng(pView->look_ang.asq16(), gView->angle.look_ang.asq16(), cl_syncinput, smoothratio); + double look_anghalf = gView->angle.look_anghalf(smoothratio); DrawCrosshair(kCrosshairTile, gView->pXSprite->health >> 4, -look_anghalf, 0, 2); diff --git a/source/blood/src/view.cpp b/source/blood/src/view.cpp index 0ee123017..8cd5723cb 100644 --- a/source/blood/src/view.cpp +++ b/source/blood/src/view.cpp @@ -972,7 +972,7 @@ void viewDrawScreen(bool sceneonly) } } #endif - hudDraw(gView, &gPrevView[gViewIndex], nSectnum, v4c, v48, zDelta, basepal, gInterpolate); + hudDraw(gView, nSectnum, v4c, v48, zDelta, basepal, gInterpolate); } UpdateDacs(0, true); // keep the view palette active only for the actual 3D view and its overlays. if (automapMode != am_off) diff --git a/source/blood/src/view.h b/source/blood/src/view.h index 7e43c4f94..7e1822c03 100644 --- a/source/blood/src/view.h +++ b/source/blood/src/view.h @@ -141,7 +141,7 @@ extern LOCATION gPrevSpriteLoc[kMaxSprites]; extern int gLastPal; extern double gInterpolate; -void hudDraw(PLAYER* gView, VIEW *pView, int nSectnum, double bobx, double boby, double zDelta, int basepal, double smoothratio); +void hudDraw(PLAYER* gView, int nSectnum, double bobx, double boby, double zDelta, int basepal, double smoothratio); void viewInitializePrediction(void); void viewUpdatePrediction(InputPacket *pInput); void viewCorrectPrediction(void); diff --git a/source/core/gamecontrol.h b/source/core/gamecontrol.h index 9e5b4b14e..1dee1e6e1 100644 --- a/source/core/gamecontrol.h +++ b/source/core/gamecontrol.h @@ -226,14 +226,3 @@ extern int chatmodeon; extern bool sendPause; extern int lastTic; - -//--------------------------------------------------------------------------- -// -// Return half player's q16look_ang directly or interpolated as required. -// -//--------------------------------------------------------------------------- - -inline double getHalfLookAng(fixed_t const oq16look_ang, fixed_t const q16look_ang, bool interpolate, double smoothratio) -{ - return (!interpolate ? q16look_ang : oq16look_ang + fmulscale16(q16look_ang - oq16look_ang, smoothratio)) * (0.5 / FRACUNIT); -} diff --git a/source/core/gameinput.h b/source/core/gameinput.h index 4326b4c71..0c57a41e6 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -246,11 +246,22 @@ struct PlayerAngle return bamang(prev + xs_CRoundToUInt(ratio * (((curr + dang - prev) & 0xFFFFFFFF) - dang))); } + lookangle interpolatedlookang(double const smoothratio) + { + double const ratio = smoothratio * (1. / FRACUNIT); + return bamlook(olook_ang.asbam() + xs_CRoundToInt(ratio * (look_ang - olook_ang).asbam())); + } + lookangle interpolatedrotscrn(double const smoothratio) { double const ratio = smoothratio * (1. / FRACUNIT); return bamlook(orotscrnang.asbam() + xs_CRoundToInt(ratio * (rotscrnang - orotscrnang).asbam())); } + + double look_anghalf(double const smoothratio) + { + return (!cl_syncinput ? look_ang : interpolatedlookang(smoothratio)).asbam() * (0.5 / BAMUNIT); // Used within draw code for weapon and crosshair when looking left/right. + } }; class FSerializer; diff --git a/source/exhumed/src/gameloop.cpp b/source/exhumed/src/gameloop.cpp index 8b4c5461d..53adf3a44 100644 --- a/source/exhumed/src/gameloop.cpp +++ b/source/exhumed/src/gameloop.cpp @@ -90,11 +90,10 @@ void GameInterface::Render() } double const smoothratio = calc_smoothratio(); - double const look_anghalf = getHalfLookAng(PlayerList[nLocalPlayer].angle.olook_ang.asq16(), PlayerList[nLocalPlayer].angle.look_ang.asq16(), cl_syncinput, smoothratio); DrawView(smoothratio); DrawStatusBar(); - DrawCrosshair(MAXTILES, PlayerList[nLocalPlayer].nHealth >> 3, -look_anghalf, 0, 1); + DrawCrosshair(MAXTILES, PlayerList[nLocalPlayer].nHealth >> 3, -PlayerList[nLocalPlayer].angle.look_anghalf(smoothratio), 0, 1); if (paused && !M_Active()) { diff --git a/source/exhumed/src/gun.cpp b/source/exhumed/src/gun.cpp index 503596920..636f64cac 100644 --- a/source/exhumed/src/gun.cpp +++ b/source/exhumed/src/gun.cpp @@ -983,7 +983,7 @@ void DrawWeapons(double smooth) nShade = sprite[PlayerList[nLocalPlayer].nSprite].shade; } - double const look_anghalf = getHalfLookAng(PlayerList[nLocalPlayer].angle.olook_ang.asq16(), PlayerList[nLocalPlayer].angle.look_ang.asq16(), cl_syncinput, smooth); + double const look_anghalf = PlayerList[nLocalPlayer].angle.look_anghalf(smooth); double const looking_arc = fabs(look_anghalf) / 4.5; xOffset -= look_anghalf; diff --git a/source/games/duke/src/game_misc.cpp b/source/games/duke/src/game_misc.cpp index 74193b023..5aeae5d89 100644 --- a/source/games/duke/src/game_misc.cpp +++ b/source/games/duke/src/game_misc.cpp @@ -301,7 +301,7 @@ void drawoverlays(double smoothratio) if (ps[myconnectindex].newOwner == nullptr && ud.cameraactor == nullptr) { - DrawCrosshair(TILE_CROSSHAIR, ps[screenpeek].last_extra, -getHalfLookAng(pp->angle.olook_ang.asq16(), pp->angle.look_ang.asq16(), cl_syncinput, smoothratio), pp->over_shoulder_on ? 2.5 : 0, isRR() ? 0.5 : 1); + DrawCrosshair(TILE_CROSSHAIR, ps[screenpeek].last_extra, -pp->angle.look_anghalf(smoothratio), pp->over_shoulder_on ? 2.5 : 0, isRR() ? 0.5 : 1); } if (paused == 2) diff --git a/source/games/duke/src/hudweapon_d.cpp b/source/games/duke/src/hudweapon_d.cpp index 9c0af6c37..00664a80d 100644 --- a/source/games/duke/src/hudweapon_d.cpp +++ b/source/games/duke/src/hudweapon_d.cpp @@ -282,7 +282,7 @@ void displayweapon_d(int snum, double smoothratio) o = 0; horiz16th = get16thOfHoriz(snum, cl_syncinput, smoothratio); - look_anghalf = getHalfLookAng(p->angle.olook_ang.asq16(), p->angle.look_ang.asq16(), cl_syncinput, smoothratio); + look_anghalf = p->angle.look_anghalf(smoothratio); looking_arc = fabs(look_anghalf) / 4.5; weapon_sway = p->oweapon_sway + fmulscale16(p->weapon_sway - p->oweapon_sway, smoothratio); kickback_pic = p->okickback_pic + fmulscale16(*kb - p->okickback_pic, smoothratio); diff --git a/source/games/duke/src/hudweapon_r.cpp b/source/games/duke/src/hudweapon_r.cpp index 4e1ab6a90..8ca561b5c 100644 --- a/source/games/duke/src/hudweapon_r.cpp +++ b/source/games/duke/src/hudweapon_r.cpp @@ -125,7 +125,7 @@ void displayweapon_r(int snum, double smoothratio) o = 0; - look_anghalf = getHalfLookAng(p->angle.olook_ang.asq16(), p->angle.look_ang.asq16(), cl_syncinput, smoothratio); + look_anghalf = p->angle.look_anghalf(smoothratio); looking_arc = fabs(look_anghalf) / 4.5; weapon_sway = p->oweapon_sway + fmulscale16((p->weapon_sway - p->oweapon_sway), smoothratio); TiltStatus = !cl_syncinput ? p->TiltStatus : p->oTiltStatus + fmulscale16((p->TiltStatus - p->oTiltStatus), smoothratio); diff --git a/source/sw/src/draw.cpp b/source/sw/src/draw.cpp index 73b95f046..751a2b74f 100644 --- a/source/sw/src/draw.cpp +++ b/source/sw/src/draw.cpp @@ -1259,7 +1259,7 @@ void DrawCrosshair(PLAYERp pp) if (!(CameraTestMode)) { USERp u = User[pp->PlayerSprite]; - ::DrawCrosshair(2326, u->Health, -getHalfLookAng(pp->angle.olook_ang.asq16(), pp->angle.look_ang.asq16(), cl_syncinput, smoothratio), TEST(pp->Flags, PF_VIEW_FROM_OUTSIDE) ? 5 : 0, 2, shadeToLight(10)); + ::DrawCrosshair(2326, u->Health, -pp->angle.look_anghalf(smoothratio), TEST(pp->Flags, PF_VIEW_FROM_OUTSIDE) ? 5 : 0, 2, shadeToLight(10)); } } diff --git a/source/sw/src/panel.cpp b/source/sw/src/panel.cpp index 7344dec66..2d32cec4a 100644 --- a/source/sw/src/panel.cpp +++ b/source/sw/src/panel.cpp @@ -6929,8 +6929,8 @@ pDisplaySprites(PLAYERp pp, double smoothratio) short ang; int flags; - double look_anghalf = getHalfLookAng(pp->angle.olook_ang.asq16(), pp->angle.look_ang.asq16(), cl_syncinput, smoothratio); - double looking_arc = fabs(look_anghalf) / 4.5; + double const look_anghalf = pp->angle.look_anghalf(smoothratio); + double const looking_arc = fabs(look_anghalf) / 4.5; TRAVERSE(&pp->PanelSpriteList, psp, next) {