From 80ff918b173c1230cdd530ea975607318927b6ca Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Thu, 26 Nov 2020 17:26:29 +1100 Subject: [PATCH] - gameinput.h: For PlayerAngle struct methods `settarget()`, properly set target as angle + delta between angle & target within method and not game-side. --- source/core/binaryangle.h | 2 ++ source/core/gameinput.cpp | 14 ++++++++++++++ source/core/gameinput.h | 9 +++++---- source/games/duke/src/actors.cpp | 3 +-- source/sw/src/game.h | 1 - source/sw/src/player.cpp | 12 +++--------- 6 files changed, 25 insertions(+), 16 deletions(-) diff --git a/source/core/binaryangle.h b/source/core/binaryangle.h index ffd3ec2f0..198abc6d7 100644 --- a/source/core/binaryangle.h +++ b/source/core/binaryangle.h @@ -247,6 +247,7 @@ class binangle friend constexpr binangle bamang(uint32_t v); friend constexpr binangle q16ang(uint32_t v); friend constexpr binangle buildang(uint32_t v); + friend binangle buildfang(double v); friend binangle radang(double v); friend binangle degang(double v); @@ -350,6 +351,7 @@ public: inline constexpr binangle bamang(uint32_t v) { return binangle(v); } inline constexpr binangle q16ang(uint32_t v) { return binangle(v << 5); } inline constexpr binangle buildang(uint32_t v) { return binangle(v << BAMBITS); } +inline binangle buildfang(double v) { return binangle(xs_CRoundToUInt(v * BAMUNIT)); } inline binangle radang(double v) { return binangle(xs_CRoundToUInt(v * (0x80000000u / pi::pi()))); } inline binangle degang(double v) { return binangle(FloatToAngle(v)); } diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index dd6b5d503..ce515f974 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -49,6 +49,20 @@ int getincangle(int a, int na) return na-a; } +double getincanglef(double a, double na) +{ + a = fmod(a, 2048.); + na = fmod(na, 2048.); + + if(fabs(a-na) >= 1024) + { + if(na > 1024) na -= 2048; + if(a > 1024) a -= 2048; + } + + return na-a; +} + fixed_t getincangleq16(fixed_t a, fixed_t na) { a &= 0x7FFFFFF; diff --git a/source/core/gameinput.h b/source/core/gameinput.h index ce4dc94ee..d99f7c1c8 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -6,6 +6,7 @@ #include "packet.h" int getincangle(int a, int na); +double getincanglef(double a, double na); fixed_t getincangleq16(fixed_t a, fixed_t na); lookangle getincanglebam(binangle a, binangle na); @@ -171,7 +172,7 @@ struct PlayerAngle { if (!cl_syncinput && !backup) { - target = value << BAMBITS; + target = (ang + getincanglebam(ang, buildang(value))).asbam(); if (target == 0) target += 1; } else @@ -185,12 +186,12 @@ struct PlayerAngle { if (!cl_syncinput && !backup) { - target = value * BAMUNIT; + target = (ang + getincanglebam(ang, buildfang(value))).asbam(); if (target == 0) target += 1; } else { - ang = bamang(xs_CRoundToUInt(value * BAMUNIT)); + ang = buildfang(value); if (backup) oang = ang; } } @@ -199,7 +200,7 @@ struct PlayerAngle { if (!cl_syncinput && !backup) { - target = value.asbam(); + target = (ang + getincanglebam(ang, value)).asbam(); if (target == 0) target += 1; } else diff --git a/source/games/duke/src/actors.cpp b/source/games/duke/src/actors.cpp index 2b1d7f559..e6bb8f7fc 100644 --- a/source/games/duke/src/actors.cpp +++ b/source/games/duke/src/actors.cpp @@ -730,8 +730,7 @@ void movecrane(DDukeActor *actor, int crane) actor->SetActiveCrane(true); ps[p].on_crane = actor; S_PlayActorSound(isRR() ? 390 : DUKE_GRUNT, ps[p].GetActor()); - auto ang = ps[p].angle.ang; - ps[p].angle.settarget(ang + getincanglebam(ang, buildang(spri->ang + 1024))); + ps[p].angle.settarget(spri->ang + 1024); } else { diff --git a/source/sw/src/game.h b/source/sw/src/game.h index c343bb67d..ea82545d4 100644 --- a/source/sw/src/game.h +++ b/source/sw/src/game.h @@ -885,7 +885,6 @@ struct PLAYERstruct short pnum; // carry along the player number short LadderSector; - binangle LadderAngle; int lx,ly; // ladder x and y short JumpDuration; short WadeDepth; diff --git a/source/sw/src/player.cpp b/source/sw/src/player.cpp index a35b53089..4558806a5 100644 --- a/source/sw/src/player.cpp +++ b/source/sw/src/player.cpp @@ -3651,8 +3651,7 @@ DoPlayerClimb(PLAYERp pp) nx = MOVEx(100, lsp->ang); ny = MOVEy(100, lsp->ang); - // set angle player is supposed to face. - pp->LadderAngle = buildang(lsp->ang + 1024); + // set ladder sector pp->LadderSector = wall[wal].nextsector; // set players "view" distance from the ladder - needs to be farther than @@ -3661,8 +3660,7 @@ DoPlayerClimb(PLAYERp pp) pp->lx = lsp->x + nx * 5; pp->ly = lsp->y + ny * 5; - auto& PlayerAngle = pp->angle.ang; - pp->angle.settarget(PlayerAngle + getincanglebam(PlayerAngle, pp->LadderAngle)); + pp->angle.settarget(lsp->ang + 1024); } } } @@ -4058,9 +4056,6 @@ PlayerOnLadder(PLAYERp pp) nx = MOVEx(100, lsp->ang); ny = MOVEy(100, lsp->ang); - // set angle player is supposed to face. - pp->LadderAngle = buildang(lsp->ang + 1024); - #if DEBUG if (wall[wal].nextsector < 0) { @@ -4078,8 +4073,7 @@ PlayerOnLadder(PLAYERp pp) pp->lx = lsp->x + nx * 5; pp->ly = lsp->y + ny * 5; - auto& PlayerAngle = pp->angle.ang; - pp->angle.settarget(PlayerAngle + getincanglebam(PlayerAngle, pp->LadderAngle)); + pp->angle.settarget(lsp->ang + 1024); return true; }