From dc9c8a0e601b0ab4241b0102709813e6a3e542a7 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 17 Jul 2020 00:32:26 +0200 Subject: [PATCH] - consolidation of pitch code for aim mode 0. --- source/games/duke/src/funct.h | 1 + source/games/duke/src/player.cpp | 34 +++++++++++++++++++++++++++++ source/games/duke/src/player_d.cpp | 18 +-------------- source/games/duke/src/player_r.cpp | 18 +-------------- source/games/duke/src/types.h | 1 + source/games/duke/src/zz_player.cpp | 33 +++------------------------- 6 files changed, 41 insertions(+), 64 deletions(-) diff --git a/source/games/duke/src/funct.h b/source/games/duke/src/funct.h index 9b0848598..ddaf5cbde 100644 --- a/source/games/duke/src/funct.h +++ b/source/games/duke/src/funct.h @@ -231,5 +231,6 @@ void setlocalplayerinput(player_struct *pp); void PlayerColorChanged(void); void nonsharedkeys(void); void apply_seasick(player_struct* p, double scalefactor); +void calcviewpitch(player_struct* p, int psectlotag, double factor); END_DUKE_NS diff --git a/source/games/duke/src/player.cpp b/source/games/duke/src/player.cpp index 37601ce1b..eee8c125c 100644 --- a/source/games/duke/src/player.cpp +++ b/source/games/duke/src/player.cpp @@ -82,6 +82,40 @@ void setlocalplayerinput(player_struct* pp) pp->weaponswitch = cl_weaponswitch; } +//--------------------------------------------------------------------------- +// +// calculates automatic view pitch for playing without a mouse +// +//--------------------------------------------------------------------------- + +void calcviewpitch(player_struct *p, int psectlotag, double factor) +{ + int psect = p->cursectnum; + if (p->aim_mode == 0 && p->on_ground && psectlotag != ST_2_UNDERWATER && (sector[psect].floorstat & 2)) + { + int x = p->posx + (sintable[(p->getang() + 512) & 2047] >> 5); + int y = p->posy + (sintable[p->getang() & 2047] >> 5); + short tempsect = psect; + updatesector(x, y, &tempsect); + + if (tempsect >= 0) + { + int k = getflorzofslope(psect, x, y); + if (psect == tempsect || abs(getflorzofslope(tempsect, x, y) - k) <= (4 << 8)) + p->addhorizoff(factor * mulscale16(p->truefz - k, 160)); + } + } + if (p->q16horizoff > 0) + { + p->addhorizoff(-factor * fix16_to_dbl((p->q16horizoff >> 3) + FRACUNIT)); + if (p->q16horizoff < 0) p->q16horizoff = 0; + } + else if (p->q16horizoff < 0) + { + p->addhorizoff(-factor * fix16_to_dbl((p->q16horizoff >> 3) + FRACUNIT)); + if (p->q16horizoff > 0) p->q16horizoff = 0; + } +} //--------------------------------------------------------------------------- // diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index dc6739824..3a0d24859 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -2645,23 +2645,7 @@ void processinput_d(int snum) { p->oq16horiz = p->q16horiz; p->oq16horizoff = p->q16horizoff; - - if (p->aim_mode == 0 && p->on_ground && psectlotag != ST_2_UNDERWATER && (sector[psect].floorstat & 2)) - { - int x = p->posx + (sintable[(p->getang() + 512) & 2047] >> 5); - int y = p->posy + (sintable[p->getang() & 2047] >> 5); - short tempsect = psect; - updatesector(x, y, &tempsect); - - if (tempsect >= 0) - { - k = getflorzofslope(psect, x, y); - if (psect == tempsect || abs(getflorzofslope(tempsect, x, y) - k) <= (4 << 8)) - p->addhorizoff(mulscale16(j - k, 160)); - } - } - if (p->q16horizoff > 0) p->q16horizoff -= ((p->q16horizoff >> 3) + FRACUNIT); - else if (p->q16horizoff < 0) p->q16horizoff += (((-p->q16horizoff) >> 3) + FRACUNIT); + calcviewpitch(p, psectlotag, 1); } if (hz >= 0 && (hz & 49152) == 49152) diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index 2953fbf7a..c77d24f7f 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -3504,23 +3504,7 @@ void processinput_r(int snum) { p->oq16horiz = p->q16horiz; p->oq16horizoff = p->q16horizoff; - - if (p->aim_mode == 0 && p->on_ground && psectlotag != ST_2_UNDERWATER && (sector[psect].floorstat & 2)) - { - int x = p->posx + (sintable[(p->getang() + 512) & 2047] >> 5); - int y = p->posy + (sintable[p->getang() & 2047] >> 5); - short tempsect = psect; - updatesector(x, y, &tempsect); - - if (tempsect >= 0) - { - k = getflorzofslope(psect, x, y); - if (psect == tempsect || abs(getflorzofslope(tempsect, x, y) - k) <= (4 << 8)) - p->addhorizoff(mulscale16(j - k, 160)); - } - } - if (p->q16horizoff > 0) p->q16horizoff -= ((p->q16horizoff >> 3) + FRACUNIT); - else if (p->q16horizoff < 0) p->q16horizoff += (((-p->q16horizoff) >> 3) + FRACUNIT); + calcviewpitch(p, psectlotag, 1); } if (hz >= 0 && (hz & 49152) == 49152) diff --git a/source/games/duke/src/types.h b/source/games/duke/src/types.h index 4a37f37ce..4ab6dfdc2 100644 --- a/source/games/duke/src/types.h +++ b/source/games/duke/src/types.h @@ -207,6 +207,7 @@ struct player_struct void setoang(int v) { oq16ang = v << FRACBITS; } void addhoriz(int v) { q16horiz += (v << FRACBITS); } void addhorizoff(int v) { q16horiz += (v << FRACBITS); } + void addhorizoff(double v) { q16horiz += int(v * 65536.); } void sethoriz(int v) { q16horiz = (v << FRACBITS); } void sethorizoff(int v) { q16horizoff = (v << FRACBITS); } int gethoriz() { return q16horiz >> FRACBITS; } diff --git a/source/games/duke/src/zz_player.cpp b/source/games/duke/src/zz_player.cpp index 4e6b6ce66..1739f6cdd 100644 --- a/source/games/duke/src/zz_player.cpp +++ b/source/games/duke/src/zz_player.cpp @@ -359,36 +359,9 @@ void P_GetInput(int const playerNum) if (pPlayer->q16horizoff >= F16(-1) && pPlayer->q16horizoff <= F16(1)) pPlayer->q16horizoff = 0; } - - // calculates automatic view angle for playing without a mouse - if (!pPlayer->aim_mode && pPlayer->on_ground && sectorLotag != ST_2_UNDERWATER && (sector[pPlayer->cursectnum].floorstat & 2)) - { - // this is some kind of horse shit approximation of where the player is looking, I guess? - vec2_t const adjustedPosition = { pPlayer->posx + (sintable[(fix16_to_int(pPlayer->q16ang) + 512) & 2047] >> 5), - pPlayer->posy + (sintable[fix16_to_int(pPlayer->q16ang) & 2047] >> 5) }; - int16_t currentSector = pPlayer->cursectnum; - - updatesector(adjustedPosition.x, adjustedPosition.y, ¤tSector); - - if (currentSector >= 0) - { - int const slopeZ = getflorzofslope(pPlayer->cursectnum, adjustedPosition.x, adjustedPosition.y); - if ((pPlayer->cursectnum == currentSector) || (klabs(getflorzofslope(currentSector, adjustedPosition.x, adjustedPosition.y) - slopeZ) <= ZOFFSET6)) - pPlayer->q16horizoff = fix16_sadd(pPlayer->q16horizoff, fix16_from_dbl(scaleAdjustmentToInterval(mulscale16(pPlayer->truefz - slopeZ, 160)))); - } - } - - if (pPlayer->q16horizoff > 0) - { - pPlayer->q16horizoff = fix16_ssub(pPlayer->q16horizoff, fix16_from_dbl(scaleAdjustmentToInterval(fix16_to_dbl((pPlayer->q16horizoff >> 3) + fix16_one)))); - pPlayer->q16horizoff = fix16_max(pPlayer->q16horizoff, 0); - } - else if (pPlayer->q16horizoff < 0) - { - pPlayer->q16horizoff = fix16_sadd(pPlayer->q16horizoff, fix16_from_dbl(scaleAdjustmentToInterval(fix16_to_dbl((-pPlayer->q16horizoff >> 3) + fix16_one)))); - pPlayer->q16horizoff = fix16_min(pPlayer->q16horizoff, 0); - } - + + calcviewpitch(pPlayer, sectorLotag, scaleAdjust); + if (thisPlayer.horizSkew) pPlayer->q16horiz = fix16_sadd(pPlayer->q16horiz, fix16_from_dbl(scaleAdjustmentToInterval(thisPlayer.horizSkew)));