From ea98978ae7a3c5ab2ca3841584f1e4686180bd78 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Tue, 28 Jul 2020 12:30:09 +1000 Subject: [PATCH] - move `p->wackedbyactor` chase-cam code into `applylook()` for increased smoothness. --- source/games/duke/src/actors.cpp | 9 ---- source/games/duke/src/input.cpp | 6 +-- source/games/duke/src/player.cpp | 70 ++++++++++++++++++-------------- 3 files changed, 41 insertions(+), 44 deletions(-) diff --git a/source/games/duke/src/actors.cpp b/source/games/duke/src/actors.cpp index 09c3620b3..317b68e4f 100644 --- a/source/games/duke/src/actors.cpp +++ b/source/games/duke/src/actors.cpp @@ -483,20 +483,11 @@ void moveplayers(void) //Players } else { - p->posx = s->x; p->posy = s->y; p->posz = s->z - (20 << 8); p->newowner = -1; - - if (p->wackedbyactor >= 0 && sprite[p->wackedbyactor].statnum < MAXSTATUS) - { - int ang = p->getang(); - ang += getincangle(ang, getangle(sprite[p->wackedbyactor].x - p->posx, sprite[p->wackedbyactor].y - p->posy)) >> 1; - p->setang(ang & 2047, true); - } - } s->ang = p->getang(); } diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 103647670..8b45e4d32 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -1259,12 +1259,8 @@ void GetInput() if (!synchronized_input) { - if (sprite[p->i].extra > 0) - { - applylook(myconnectindex, scaleAdjust); - } - // Do these in the same order as the old code. + applylook(myconnectindex, scaleAdjust); calcviewpitch(p, scaleAdjust); sethorizon(myconnectindex, loc.bits, scaleAdjust, true); } diff --git a/source/games/duke/src/player.cpp b/source/games/duke/src/player.cpp index 5f668ce48..31d32042c 100644 --- a/source/games/duke/src/player.cpp +++ b/source/games/duke/src/player.cpp @@ -800,42 +800,52 @@ void applylook(int snum, double factor) { auto p = &ps[snum]; - p->addrotscrnang(factor * -0.5 * fix16_to_dbl(p->q16rotscrnang)); - if (abs(p->q16rotscrnang) < FRACUNIT) p->q16rotscrnang = 0; - - p->addlookang(factor * -0.25 * fix16_to_dbl(p->q16look_ang)); - if (abs(p->q16look_ang) < FRACUNIT) p->q16look_ang = 0; - - if (p->lookLeft) + if (sprite[p->i].extra > 0) { - p->addlookang(factor * -152); - p->addrotscrnang(factor * 24); - } + p->addrotscrnang(factor * -0.5 * fix16_to_dbl(p->q16rotscrnang)); + if (abs(p->q16rotscrnang) < FRACUNIT) p->q16rotscrnang = 0; - if (p->lookRight) - { - p->addlookang(factor * 152); - p->addrotscrnang(factor * -24); - } + p->addlookang(factor * -0.25 * fix16_to_dbl(p->q16look_ang)); + if (abs(p->q16look_ang) < FRACUNIT) p->q16look_ang = 0; - if (p->actorsqu >= 0) - { - p->q16ang += fix16_from_dbl(factor * (getincangle(p->getang(), getangle(sprite[p->actorsqu].x - p->posx, sprite[p->actorsqu].y - p->posy)) >> 2)); - } - - if (p->one_eighty_count < 0 && p->on_crane < 0) - { - fixed_t add = fix16_from_dbl(factor * 128); - p->one_eighty_count += add; - if (p->one_eighty_count > 0) + if (p->lookLeft) { - // Don't overshoot our target. With variable factor this is possible. - add -= p->one_eighty_count; - p->one_eighty_count = 0; + p->addlookang(factor * -152); + p->addrotscrnang(factor * 24); + } + + if (p->lookRight) + { + p->addlookang(factor * 152); + p->addrotscrnang(factor * -24); + } + + if (p->actorsqu >= 0) + { + p->q16ang += fix16_from_dbl(factor * (getincangle(p->getang(), getangle(sprite[p->actorsqu].x - p->posx, sprite[p->actorsqu].y - p->posy)) >> 2)); + } + + if (p->one_eighty_count < 0 && p->on_crane < 0) + { + fixed_t add = fix16_from_dbl(factor * 128); + p->one_eighty_count += add; + if (p->one_eighty_count > 0) + { + // Don't overshoot our target. With variable factor this is possible. + add -= p->one_eighty_count; + p->one_eighty_count = 0; + } + p->q16ang += add; + } + apply_seasick(p, factor); + } + else + { + if (p->wackedbyactor >= 0 && sprite[p->wackedbyactor].statnum < MAXSTATUS) + { + p->q16ang += fix16_from_dbl(factor * (getincangle(p->getang(), getangle(sprite[p->wackedbyactor].x - p->posx, sprite[p->wackedbyactor].y - p->posy)) >> 1)); } - p->q16ang += add; } - apply_seasick(p, factor); } //---------------------------------------------------------------------------