From 50a9ca49f37bd371c367ab9ff75881ae6d653077 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 12 Sep 2022 00:11:44 +0200 Subject: [PATCH] - floatified player_struct::hitang --- source/common/utility/m_fixed.h | 2 +- source/games/duke/src/actors_d.cpp | 8 +++----- source/games/duke/src/actors_r.cpp | 8 +++----- source/games/duke/src/gameexec.cpp | 4 ++-- source/games/duke/src/sectors_d.cpp | 2 +- source/games/duke/src/sectors_r.cpp | 2 +- source/games/duke/src/types.h | 4 +++- wadsrc/static/zscript/games/duke/dukeactor.zs | 2 +- 8 files changed, 15 insertions(+), 17 deletions(-) diff --git a/source/common/utility/m_fixed.h b/source/common/utility/m_fixed.h index adf9ac8ee..e4dd17bf9 100644 --- a/source/common/utility/m_fixed.h +++ b/source/common/utility/m_fixed.h @@ -16,7 +16,7 @@ __forceinline constexpr int64_t DivScaleL(int64_t a, int64_t b, int shift) { ret #include "xs_Float.h" template -inline fixed_t FloatToFixed(double f) +constexpr fixed_t FloatToFixed(double f) { return int(f * (1 << b)); } diff --git a/source/games/duke/src/actors_d.cpp b/source/games/duke/src/actors_d.cpp index 6734c1613..d5f82fb58 100644 --- a/source/games/duke/src/actors_d.cpp +++ b/source/games/duke/src/actors_d.cpp @@ -349,7 +349,7 @@ void hitradius_d(DDukeActor* actor, int r, int hp1, int hp2, int hp3, int h if (d < r && cansee(act2->spr.pos.plusZ(-8), act2->sector(), actor->spr.pos.plusZ(-12), actor->sector())) { - act2->hitang = getangle(act2->spr.pos - actor->spr.pos); + act2->hitang = VecToAngle(act2->spr.pos - actor->spr.pos); if (actor->spr.picnum == RPG && act2->spr.extra > 0) act2->attackertype = RPG; @@ -631,13 +631,11 @@ int ifhitbyweapon_d(DDukeActor *actor) if (attackerflag(actor, SFLAG2_DOUBLEDMGTHRUST)) { - ps[p].__vel.X += actor->hitextra * bcos(actor->hitang, 2); - ps[p].__vel.Y += actor->hitextra * bsin(actor->hitang, 2); + ps[p].vel.XY() += actor->hitang.ToVector() * actor->hitextra * 0.25 * VEL_FACTOR; } else { - ps[p].__vel.X += actor->hitextra * bcos(actor->hitang, 1); - ps[p].__vel.Y += actor->hitextra * bsin(actor->hitang, 1); + ps[p].vel.XY() += actor->hitang.ToVector() * actor->hitextra * 0.125 * VEL_FACTOR; } } else diff --git a/source/games/duke/src/actors_r.cpp b/source/games/duke/src/actors_r.cpp index 0a9bcf2d8..bf2f2bd9f 100644 --- a/source/games/duke/src/actors_r.cpp +++ b/source/games/duke/src/actors_r.cpp @@ -300,7 +300,7 @@ void hitradius_r(DDukeActor* actor, int r, int hp1, int hp2, int hp3, int h continue; } - act2->hitang = getangle(act2->int_pos().X - actor->int_pos().X, act2->int_pos().Y - actor->int_pos().Y); + act2->hitang = VecToAngle(act2->spr.pos - actor->spr.pos); if (actor->spr.picnum == RPG && act2->spr.extra > 0) act2->attackertype = RPG; @@ -534,13 +534,11 @@ int ifhitbyweapon_r(DDukeActor *actor) if (attackerflag(actor, SFLAG2_DOUBLEDMGTHRUST)) { - ps[p].__vel.X += actor->hitextra * bcos(actor->hitang, 2); - ps[p].__vel.Y += actor->hitextra * bsin(actor->hitang, 2); + ps[p].vel.XY() += actor->hitang.ToVector() * actor->hitextra * 0.25 * VEL_FACTOR; } else { - ps[p].__vel.X += actor->hitextra * bcos(actor->hitang, 1); - ps[p].__vel.Y += actor->hitextra * bsin(actor->hitang, 1); + ps[p].vel.XY() += actor->hitang.ToVector() * actor->hitextra * 0.125 * VEL_FACTOR; } } else diff --git a/source/games/duke/src/gameexec.cpp b/source/games/duke/src/gameexec.cpp index 4bb4ad6c4..71e57973c 100644 --- a/source/games/duke/src/gameexec.cpp +++ b/source/games/duke/src/gameexec.cpp @@ -1270,8 +1270,8 @@ void DoActor(bool bSet, int lVar1, int lLabelID, int lVar2, DDukeActor* sActor, else SetGameVarID(lVar2, act->attackertype, sActor, sPlayer); break; case ACTOR_HTANG: - if (bSet) act->hitang = lValue; - else SetGameVarID(lVar2, act->hitang, sActor, sPlayer); + if (bSet) act->hitang = mapangle(lValue); + else SetGameVarID(lVar2, act->hitang.Buildang(), sActor, sPlayer); break; case ACTOR_HTEXTRA: if (bSet) act->hitextra = lValue; diff --git a/source/games/duke/src/sectors_d.cpp b/source/games/duke/src/sectors_d.cpp index 418c085b6..9b9c73135 100644 --- a/source/games/duke/src/sectors_d.cpp +++ b/source/games/duke/src/sectors_d.cpp @@ -1423,7 +1423,7 @@ void checkhitsprite_d(DDukeActor* targ, DDukeActor* proj) targ->attackertype = hitpic; targ->hitextra += proj->spr.extra; - targ->hitang = proj->int_ang(); + targ->hitang = proj->spr.angle; targ->SetHitOwner(Owner); } diff --git a/source/games/duke/src/sectors_r.cpp b/source/games/duke/src/sectors_r.cpp index 2bc992673..302a631e8 100644 --- a/source/games/duke/src/sectors_r.cpp +++ b/source/games/duke/src/sectors_r.cpp @@ -2364,7 +2364,7 @@ void checkhitsprite_r(DDukeActor* targ, DDukeActor* proj) targ->attackertype = proj->spr.picnum; targ->hitextra += proj->spr.extra; if (targ->spr.picnum != COW) - targ->hitang = proj->int_ang(); + targ->hitang = proj->spr.angle; targ->SetHitOwner(proj->GetOwner()); } diff --git a/source/games/duke/src/types.h b/source/games/duke/src/types.h index dc25616a4..0dc4b46b1 100644 --- a/source/games/duke/src/types.h +++ b/source/games/duke/src/types.h @@ -46,10 +46,11 @@ public: uint8_t cgg; uint8_t spriteextra; // moved here for easier maintenance. This was originally a hacked in field in the sprite structure called 'filler'. - short attackertype, hitang, hitextra, movflag; + short attackertype, hitextra, movflag; short tempang, dispicnum, basepicnum; short timetosleep; vec2_t ovel; + DAngle hitang; double floorz, ceilingz; union { @@ -199,6 +200,7 @@ struct CraneDef TObjPtr poleactor; }; +constexpr double VEL_FACTOR = FloatToFixed<18>(1); struct player_struct { union diff --git a/wadsrc/static/zscript/games/duke/dukeactor.zs b/wadsrc/static/zscript/games/duke/dukeactor.zs index 329762327..5d849bff0 100644 --- a/wadsrc/static/zscript/games/duke/dukeactor.zs +++ b/wadsrc/static/zscript/games/duke/dukeactor.zs @@ -28,7 +28,7 @@ class DukeActor : CoreActor native native DukeActor ownerActor, hitOwnerActor; native uint8 cgg; native uint8 spriteextra; // moved here for easier maintenance. This was originally a hacked in field in the sprite structure called 'filler'. - native int16 /*attackertype,*/ hitang, hitextra, movflag; + native int16 /*attackertype, hitang,*/ hitextra, movflag; native int16 tempang; /*, dispicnum;*/ native int16 timetosleep; native double floorz, ceilingz;