From 1a03c56eececb8fed3437f6f2b728f38a3c00586 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 28 Sep 2022 17:56:41 +0200 Subject: [PATCH] - floatifying player::slope, part 1 --- source/core/coreactor.h | 5 ----- source/games/blood/src/player.cpp | 10 +++++----- source/games/blood/src/player.h | 4 +++- source/games/blood/src/weapon.cpp | 10 +++++----- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/source/core/coreactor.h b/source/core/coreactor.h index 0daf1128e..e286536ba 100644 --- a/source/core/coreactor.h +++ b/source/core/coreactor.h @@ -88,11 +88,6 @@ public: spr.angle = spr.angle.Normalized360(); } - vec3_t int_vel() const - { - return vec3_t(FloatToFixed(vel.X), FloatToFixed(vel.Y), FloatToFixed(vel.Z)); - } - void ZeroVelocityXY() { vel .X = vel .Y = 0; diff --git a/source/games/blood/src/player.cpp b/source/games/blood/src/player.cpp index 74f9e13d8..422777bc8 100644 --- a/source/games/blood/src/player.cpp +++ b/source/games/blood/src/player.cpp @@ -820,7 +820,7 @@ void playerStart(int nPlayer, int bNewLevel) pPlayer->actor->spr.cstat &= ~CSTAT_SPRITE_INVISIBLE; pPlayer->bloodlust = 0; pPlayer->horizon.horiz = pPlayer->horizon.horizoff = nullAngle; - pPlayer->slope = 0; + pPlayer->_slope = 0; pPlayer->fragger = nullptr; pPlayer->underwaterTime = 1200; pPlayer->bubbleTime = 0; @@ -1419,7 +1419,7 @@ int ActionScan(PLAYER* pPlayer, HitInfo* out) { auto plActor = pPlayer->actor; *out = {}; - auto pos = DVector3(plActor->spr.angle.ToVector() * 1024., pPlayer->slope * inttoworld); + auto pos = DVector3(plActor->spr.angle.ToVector(), pPlayer->flt_slope()); int hit = HitScan(pPlayer->actor, pPlayer->zView, pos, 0x10000040, 128); double hitDist = (plActor->spr.pos.XY() - gHitInfo.hitpos.XY()).Length(); if (hitDist < 64) @@ -1731,7 +1731,7 @@ void ProcessInput(PLAYER* pPlayer) pPlayer->angle.unlockinput(); pPlayer->horizon.unlockinput(); - pPlayer->slope = -pPlayer->horizon.horiz.Tan() * 16384.; + pPlayer->_slope = -pPlayer->horizon.horiz.Tan() * 16384.; if (pInput->actions & SB_INVPREV) { pInput->actions &= ~SB_INVPREV; @@ -1922,7 +1922,7 @@ DBloodActor* playerFireMissile(PLAYER* pPlayer, int xyoff_, int dx, int dy, int DBloodActor* playerFireThing(PLAYER* pPlayer, int xyoff_, int zvel_, int thingType, int nSpeed_) { double xyoff = xyoff_ * inttoworld; - double zvel = FixedToFloat(pPlayer->slope + zvel_); + double zvel = FixedToFloat(pPlayer->int_slope() + zvel_); double nSpeed = FixedToFloat(nSpeed_); return actFireThing(pPlayer->actor, xyoff, pPlayer->zWeapon - pPlayer->actor->spr.pos.Z, zvel, thingType, nSpeed); } @@ -2462,7 +2462,7 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, PLAYER& w, PLAYER* ("zviewvel", w.zViewVel) ("zweapon", w.zWeapon) ("zweaponvel", w.zWeaponVel) - ("slope", w.slope) + ("slope", w._slope) ("underwater", w.isUnderwater) .Array("haskey", w.hasKey, 8) ("hasflag", w.hasFlag) diff --git a/source/games/blood/src/player.h b/source/games/blood/src/player.h index c19a8c7e6..9b0a8f299 100644 --- a/source/games/blood/src/player.h +++ b/source/games/blood/src/player.h @@ -113,7 +113,9 @@ struct PLAYER double zWeapon; double ozWeapon; double zWeaponVel; - int slope; // Q18.14, like dudeslope + int _slope; // Q18.14, like dudeslope + int int_slope() const { return _slope; } + int flt_slope() const { return _slope / 16384.; } bool isUnderwater; bool hasKey[8]; int8_t hasFlag; diff --git a/source/games/blood/src/weapon.cpp b/source/games/blood/src/weapon.cpp index ecb3500b4..a05e2a455 100644 --- a/source/games/blood/src/weapon.cpp +++ b/source/games/blood/src/weapon.cpp @@ -424,7 +424,7 @@ void UpdateAimVector(PLAYER* pPlayer) assert(pPlayer != NULL); auto plActor = pPlayer->actor; DVector3 pos(plActor->spr.pos.XY(), pPlayer->zWeapon); - DVector3 Aim(plActor->spr.angle.ToVector(), pPlayer->slope / 16384.); + DVector3 Aim(plActor->spr.angle.ToVector(), pPlayer->flt_slope()); WEAPONTRACK* pWeaponTrack = &gWeaponTrack[pPlayer->curWeapon]; DBloodActor* targetactor = nullptr; @@ -455,7 +455,7 @@ void UpdateAimVector(PLAYER* pPlayer) double t = nDist * 4096 / pWeaponTrack->seeker; pos2 += actor->vel * t; } - DVector3 lpos = pos + DVector3(plActor->spr.angle.ToVector(), pPlayer->slope / 16384.) * nDist; + DVector3 lpos = pos + DVector3(plActor->spr.angle.ToVector(), pPlayer->flt_slope()) * nDist; double zRange = nDist * (9460 / 16384.); double top, bottom; @@ -502,7 +502,7 @@ void UpdateAimVector(PLAYER* pPlayer) if (nDist == 0 || nDist > 3200) continue; - DVector3 lpos = pos + DVector3(plActor->spr.angle.ToVector(), pPlayer->slope / 16384.) * nDist; + DVector3 lpos = pos + DVector3(plActor->spr.angle.ToVector(), pPlayer->flt_slope()) * nDist; double zRange = nDist * (9460 / 16384.); double top, bottom; @@ -533,14 +533,14 @@ void UpdateAimVector(PLAYER* pPlayer) } DVector3 Aim2(Aim); Aim2.XY() = Aim2.XY().Rotated(-plActor->spr.angle); - Aim2.Z -= pPlayer->slope / 16384.; + Aim2.Z -= pPlayer->flt_slope(); pPlayer->relAim.dx = interpolatedvalue(pPlayer->relAim.dx, int(Aim2.X * 16384), FixedToFloat(pWeaponTrack->aimSpeedHorz)); pPlayer->relAim.dy = interpolatedvalue(pPlayer->relAim.dy, int(Aim2.Y * 16384), FixedToFloat(pWeaponTrack->aimSpeedHorz)); pPlayer->relAim.dz = interpolatedvalue(pPlayer->relAim.dz, int(Aim2.Z * 16384), FixedToFloat(pWeaponTrack->aimSpeedVert)); pPlayer->aim = pPlayer->relAim; RotateVector((int*)&pPlayer->aim.dx, (int*)&pPlayer->aim.dy, plActor->int_ang()); - pPlayer->aim.dz += pPlayer->slope; + pPlayer->aim.dz += pPlayer->int_slope(); pPlayer->aimTarget = targetactor; }