From 92379863f12ef1d7e499cae0f7a75cb668f51cfa Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 4 Sep 2022 00:04:01 +0200 Subject: [PATCH] - don't use DAngle for calculating bobbing amplitudes. It makes more sense here to have a dedicated function since this is not really angular math. --- source/core/gamefuncs.h | 5 +++++ source/games/duke/src/player_d.cpp | 10 +++++----- source/games/duke/src/player_r.cpp | 8 ++++---- source/games/sw/src/actor.cpp | 4 ++-- source/games/sw/src/coolg.cpp | 2 +- source/games/sw/src/eel.cpp | 2 +- source/games/sw/src/hornet.cpp | 2 +- source/games/sw/src/player.cpp | 4 ++-- source/games/sw/src/skull.cpp | 4 ++-- 9 files changed, 23 insertions(+), 18 deletions(-) diff --git a/source/core/gamefuncs.h b/source/core/gamefuncs.h index 26eb74f73..c76361e46 100644 --- a/source/core/gamefuncs.h +++ b/source/core/gamefuncs.h @@ -603,4 +603,9 @@ inline void alignflorslope(sectortype* sect, const DVector3& pos) sect->setfloorslope(getslopeval(sect, pos.X * worldtoint, pos.Y * worldtoint, pos.Z * zworldtoint, sect->int_floorz())); } +inline double BobVal(int val) +{ + return g_sinbam((unsigned)val << 21); +} + #include "updatesector.h" diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index c0920b4f9..c5f87beb2 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -1679,7 +1679,7 @@ static void operateJetpack(int snum, ESyncBits actions, int psectlotag, int fz, p->pycount += 32; p->pycount &= 2047; - p->pyoff = DAngle::fromBuild(p->pycount).Sin(); + p->pyoff = BobVal(p->pycount); if (p->jetpack_on && S_CheckActorSoundPlaying(pact, DUKE_SCREAM)) { @@ -1764,7 +1764,7 @@ static void movement(int snum, ESyncBits actions, sectortype* psect, int fz_, in i = 34; p->pycount += 32; p->pycount &= 2047; - p->pyoff = DAngle::fromBuild(p->pycount).Sin() * 2; + p->pyoff = BobVal(p->pycount) * 2; } else i = 12; @@ -1942,7 +1942,7 @@ static void underwater(int snum, ESyncBits actions, int fz_, int cz_) p->pycount += 32; p->pycount &= 2047; - p->pyoff = DAngle::fromBuild(p->pycount).Sin(); + p->pyoff = BobVal(p->pycount); if (!S_CheckActorSoundPlaying(pact, DUKE_UNDERWATER)) S_PlayActorSound(DUKE_UNDERWATER, pact); @@ -3059,10 +3059,10 @@ HORIZONLY: { p->pycount += 52; p->pycount &= 2047; - p->pyoff = DAngle::fromBuild(p->pycount).Sin() * pact->int_xvel(); + p->pyoff = BobVal(p->pycount) * pact->int_xvel(); const double factor = 64. / 1596; // What is 1596? - p->pyoff = abs(pact->int_xvel() * DAngle::fromBuild(p->pycount).Sin()) * factor; + p->pyoff = abs(pact->int_xvel() * BobVal(p->pycount)) * factor; } } else if (psectlotag != 2 && psectlotag != 1) diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index b4af609fd..943370fdb 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -2080,7 +2080,7 @@ static void movement(int snum, ESyncBits actions, sectortype* psect, int fz_, in i = 34; p->pycount += 32; p->pycount &= 2047; - p->pyoff = DAngle::fromBuild(p->pycount).Sin() * 2; + p->pyoff = BobVal(p->pycount) * 2; } else i = 12; @@ -2300,7 +2300,7 @@ static void underwater(int snum, ESyncBits actions, int fz_, int cz_) p->pycount += 32; p->pycount &= 2047; - p->pyoff = DAngle::fromBuild(p->pycount).Sin(); + p->pyoff = BobVal(p->pycount); if (!S_CheckActorSoundPlaying(pact, DUKE_UNDERWATER)) S_PlayActorSound(DUKE_UNDERWATER, pact); @@ -3605,7 +3605,7 @@ void processinput_r(int snum) { p->pycount += 32; p->pycount &= 2047; - p->pyoff = DAngle::fromBuild(p->pycount).Sin() * (p->SeaSick? 32 : 1); + p->pyoff = BobVal(p->pycount) * (p->SeaSick? 32 : 1); } if (psectlotag == ST_2_UNDERWATER) @@ -3889,7 +3889,7 @@ HORIZONLY: p->pycount += 52; p->pycount &= 2047; const double factor = 64. / 1596; // What is 1596? - p->pyoff = abs(pact->int_xvel() * DAngle::fromBuild(p->pycount).Sin()) * factor; + p->pyoff = abs(pact->int_xvel() * BobVal(p->pycount)) * factor; } } else if (psectlotag != ST_2_UNDERWATER && psectlotag != 1 && (!isRRRA() || !p->sea_sick_stat)) diff --git a/source/games/sw/src/actor.cpp b/source/games/sw/src/actor.cpp index 78ea1bd7d..537baaada 100644 --- a/source/games/sw/src/actor.cpp +++ b/source/games/sw/src/actor.cpp @@ -421,7 +421,7 @@ int DoActorDebris(DSWActor* actor) if (actor->sector()->hasU() && FixedToInt(actor->sector()->depth_fixed) > 10) // JBF: added null check { actor->user.WaitTics = (actor->user.WaitTics + (ACTORMOVETICS << 3)) & 1023; - actor->spr.pos.Z = actor->user.loz - 2 * DAngle::fromBuild(actor->user.WaitTics).Sin(); + actor->spr.pos.Z = actor->user.loz - 2 * BobVal(actor->user.WaitTics); } } else @@ -443,7 +443,7 @@ int DoFireFly(DSWActor* actor) actor->user.WaitTics = (actor->user.WaitTics + (ACTORMOVETICS << 1)) & 2047; - actor->spr.pos.Z = actor->user.pos.Z + 32 * DAngle::fromBuild(actor->user.WaitTics).Sin(); + actor->spr.pos.Z = actor->user.pos.Z + 32 * BobVal(actor->user.WaitTics); return 0; } diff --git a/source/games/sw/src/coolg.cpp b/source/games/sw/src/coolg.cpp index ba785a2cf..a22bf6788 100644 --- a/source/games/sw/src/coolg.cpp +++ b/source/games/sw/src/coolg.cpp @@ -658,7 +658,7 @@ int DoCoolgMatchPlayerZ(DSWActor* actor) actor->user.pos.Z = max(actor->user.pos.Z, hiz + actor->user.ceiling_dist); actor->user.Counter = (actor->user.Counter + (ACTORMOVETICS<<3)) & 2047; - actor->spr.pos.Z = actor->user.pos.Z + COOLG_BOB_AMT * DAngle::fromBuild(actor->user.Counter).Sin(); + actor->spr.pos.Z = actor->user.pos.Z + COOLG_BOB_AMT * BobVal(actor->user.Counter); bound = actor->user.hiz + actor->user.ceiling_dist + COOLG_BOB_AMT; if (actor->spr.pos.Z < bound) diff --git a/source/games/sw/src/eel.cpp b/source/games/sw/src/eel.cpp index 7c86487e8..24e8ed2ea 100644 --- a/source/games/sw/src/eel.cpp +++ b/source/games/sw/src/eel.cpp @@ -494,7 +494,7 @@ int DoEelMatchPlayerZ(DSWActor* actor) actor->user.pos.Z = max(actor->user.pos.Z, hiz + actor->user.ceiling_dist); actor->user.Counter = (actor->user.Counter + (ACTORMOVETICS << 3) + (ACTORMOVETICS << 1)) & 2047; - actor->spr.pos.Z = actor->user.pos.Z + EEL_BOB_AMT * DAngle::fromBuild(actor->user.Counter).Sin(); + actor->spr.pos.Z = actor->user.pos.Z + EEL_BOB_AMT * BobVal(actor->user.Counter); bound = actor->user.hiz + actor->user.ceiling_dist + EEL_BOB_AMT; if (actor->spr.pos.Z < bound) diff --git a/source/games/sw/src/hornet.cpp b/source/games/sw/src/hornet.cpp index 2e07279b2..5c582d996 100644 --- a/source/games/sw/src/hornet.cpp +++ b/source/games/sw/src/hornet.cpp @@ -390,7 +390,7 @@ int DoHornetMatchPlayerZ(DSWActor* actor) actor->user.pos.Z = max(actor->user.pos.Z, hiz + actor->user.ceiling_dist); actor->user.Counter = (actor->user.Counter + (ACTORMOVETICS << 3) + (ACTORMOVETICS << 1)) & 2047; - actor->spr.pos.Z = actor->user.pos.Z + HORNET_BOB_AMT * DAngle::fromBuild(actor->user.Counter).Sin(); + actor->spr.pos.Z = actor->user.pos.Z + HORNET_BOB_AMT * BobVal(actor->user.Counter); bound = actor->user.hiz + actor->user.ceiling_dist + HORNET_BOB_AMT; if (actor->spr.pos.Z < bound) diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index 96b4b6244..ac124ac8e 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -1607,7 +1607,7 @@ void DoPlayerBob(PLAYER* pp) pp->bcnt &= 2047; // move pp->q16horiz up and down from 100 using sintable - pp->bob_z = amt * DAngle::fromBuild(pp->bcnt).Sin(); + pp->bob_z = amt * BobVal(pp->bcnt); } void DoPlayerBeginRecoil(PLAYER* pp, short pix_amt) @@ -1643,7 +1643,7 @@ void DoPlayerRecoil(PLAYER* pp) void DoPlayerSpriteBob(PLAYER* pp, double player_height, double bobamt, short bob_speed) { pp->bob_ndx = (pp->bob_ndx + (synctics << bob_speed)) & 2047; - pp->pbob_amt = bobamt * DAngle::fromBuild(pp->bob_ndx).Sin(); + pp->pbob_amt = bobamt * BobVal(pp->bob_ndx); pp->actor->spr.pos.Z = pp->pos.Z + player_height + pp->pbob_amt; } diff --git a/source/games/sw/src/skull.cpp b/source/games/sw/src/skull.cpp index b2a9694bc..ee612a7e4 100644 --- a/source/games/sw/src/skull.cpp +++ b/source/games/sw/src/skull.cpp @@ -404,7 +404,7 @@ int DoSkullBob(DSWActor* actor) const int SKULL_BOB_AMT = 16; actor->user.Counter = (actor->user.Counter + (ACTORMOVETICS << 3) + (ACTORMOVETICS << 1)) & 2047; - actor->spr.pos.Z = actor->user.pos.Z + SKULL_BOB_AMT * 1.5 * DAngle::fromBuild(actor->user.Counter).Sin(); + actor->spr.pos.Z = actor->user.pos.Z + SKULL_BOB_AMT * 1.5 * BobVal(actor->user.Counter); return 0; } @@ -771,7 +771,7 @@ int DoBettyBob(DSWActor* actor) const int BETTY_BOB_AMT = 16; actor->user.Counter = (actor->user.Counter + (ACTORMOVETICS << 3) + (ACTORMOVETICS << 1)) & 2047; - actor->spr.pos.Z = actor->user.pos.Z + BETTY_BOB_AMT * 1.5 * DAngle::fromBuild(actor->user.Counter).Sin(); + actor->spr.pos.Z = actor->user.pos.Z + BETTY_BOB_AMT * 1.5 * BobVal(actor->user.Counter); return 0; }