mirror of
https://github.com/ZDoom/Raze.git
synced 2025-01-18 22:51:50 +00:00
- Replace player's rotscrnang
and look_ang
angles with DAngle
objects.
* Went the el cheapo route and added some floating point Build angle methods. As these and the integer build methods are really just refactoring aids, we'll come back to this in due course.
This commit is contained in:
parent
728edc182d
commit
13ea55b4cb
11 changed files with 57 additions and 40 deletions
|
@ -1212,6 +1212,11 @@ public:
|
|||
return TAngle(bang * (90. / 512));
|
||||
}
|
||||
|
||||
static constexpr TAngle fromBuildf(double bang)
|
||||
{
|
||||
return TAngle(bang * (90. / 512));
|
||||
}
|
||||
|
||||
static constexpr TAngle fromQ16(int bang)
|
||||
{
|
||||
return TAngle(bang * (90. / 16384));
|
||||
|
@ -1334,6 +1339,11 @@ public:
|
|||
return int(Degrees_ * (512 / 90.0));
|
||||
}
|
||||
|
||||
constexpr double Buildfang() const
|
||||
{
|
||||
return Degrees_ * (512 / 90.0);
|
||||
}
|
||||
|
||||
constexpr int Q16() const
|
||||
{
|
||||
return int(Degrees_ * (16384 / 90.0));
|
||||
|
@ -1364,6 +1374,12 @@ public:
|
|||
{
|
||||
return clamp(Tan(), -max, max);
|
||||
}
|
||||
|
||||
constexpr int Sgn() const
|
||||
{
|
||||
const auto normalized = (signed int)BAMs();
|
||||
return (normalized > 0) - (normalized < 0);
|
||||
}
|
||||
};
|
||||
|
||||
template<class T>
|
||||
|
|
|
@ -48,9 +48,9 @@ inline static fixedhoriz getscaledhoriz(const double value, const double scaleAd
|
|||
return buildfhoriz(scaleAdjust * ((object.asbuildf() * getTicrateScale(value)) + push));
|
||||
}
|
||||
|
||||
inline static binangle getscaledangle(const double value, const double scaleAdjust, const binangle& object, const double push)
|
||||
inline static DAngle getscaledangle(const double value, const double scaleAdjust, const DAngle& object, const double push)
|
||||
{
|
||||
return buildfang(scaleAdjust * ((object.signedbuildf() * getTicrateScale(value)) + push));
|
||||
return DAngle::fromBuildf(scaleAdjust * ((object.Normalized180().Buildfang() * getTicrateScale(value)) + push));
|
||||
}
|
||||
|
||||
inline static void scaletozero(fixedhoriz& object, const double value, const double scaleAdjust, const double push = DBL_MAX)
|
||||
|
@ -62,12 +62,12 @@ inline static void scaletozero(fixedhoriz& object, const double value, const dou
|
|||
}
|
||||
}
|
||||
|
||||
inline static void scaletozero(binangle& object, const double value, const double scaleAdjust, const double push = DBL_MAX)
|
||||
inline static void scaletozero(DAngle& object, const double value, const double scaleAdjust, const double push = DBL_MAX)
|
||||
{
|
||||
if (auto sgn = Sgn(object.signedbam()))
|
||||
if (auto sgn = object.Sgn())
|
||||
{
|
||||
object -= getscaledangle(value, scaleAdjust, object, push == DBL_MAX ? sgn * getPushScale(scaleAdjust) : push);
|
||||
if (sgn != Sgn(object.signedbam())) object = bamang(0);
|
||||
if (sgn != object.Sgn()) object = DAngle::fromDeg(0.);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -375,8 +375,8 @@ void PlayerAngle::applyinput(float const avel, ESyncBits* actions, double const
|
|||
{
|
||||
if (*actions & key)
|
||||
{
|
||||
look_ang += buildfang(getTicrateScale(LOOKINGSPEED) * scaleAdjust * direction);
|
||||
rotscrnang -= buildfang(getTicrateScale(ROTATESPEED) * scaleAdjust * direction);
|
||||
look_ang += DAngle::fromBuildf(getTicrateScale(LOOKINGSPEED) * scaleAdjust * direction);
|
||||
rotscrnang -= DAngle::fromBuildf(getTicrateScale(ROTATESPEED) * scaleAdjust * direction);
|
||||
}
|
||||
};
|
||||
doLookKeys(SB_LOOK_LEFT, -1);
|
||||
|
|
|
@ -124,7 +124,8 @@ private:
|
|||
|
||||
struct PlayerAngle
|
||||
{
|
||||
binangle ang, oang, look_ang, olook_ang, rotscrnang, orotscrnang;
|
||||
binangle ang, oang;
|
||||
DAngle look_ang, olook_ang, rotscrnang, orotscrnang;
|
||||
double spin;
|
||||
|
||||
friend FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngle& w, PlayerAngle* def);
|
||||
|
@ -147,11 +148,11 @@ struct PlayerAngle
|
|||
}
|
||||
|
||||
// Commonly used getters.
|
||||
binangle osum() { return oang + olook_ang; }
|
||||
binangle sum() { return ang + look_ang; }
|
||||
binangle osum() { return oang + bamang(olook_ang.BAMs()); }
|
||||
binangle sum() { return ang + bamang(look_ang.BAMs()); }
|
||||
binangle interpolatedsum(double const smoothratio) { return interpolatedangle(osum(), sum(), smoothratio); }
|
||||
binangle interpolatedlookang(double const smoothratio) { return interpolatedangle(olook_ang, look_ang, smoothratio); }
|
||||
binangle interpolatedrotscrn(double const smoothratio) { return interpolatedangle(orotscrnang, rotscrnang, smoothratio); }
|
||||
DAngle interpolatedlookang(double const smoothratio) { return interpolatedangle(olook_ang, look_ang, smoothratio); }
|
||||
DAngle interpolatedrotscrn(double const smoothratio) { return interpolatedangle(orotscrnang, rotscrnang, smoothratio); }
|
||||
|
||||
// Ticrate playsim adjustment helpers.
|
||||
void resetadjustment() { adjustment = 0; }
|
||||
|
@ -162,9 +163,9 @@ struct PlayerAngle
|
|||
void unlockinput() { inputdisabled = false; }
|
||||
bool movementlocked() { return targetset() || inputdisabled; }
|
||||
|
||||
// Draw code helpers.
|
||||
double look_anghalf(double const smoothratio) { return (!SyncInput() ? look_ang : interpolatedlookang(smoothratio)).signedbuildf() * 0.5; }
|
||||
double looking_arc(double const smoothratio) { return fabs((!SyncInput() ? look_ang : interpolatedlookang(smoothratio)).signedbuildf()) * (1. / 9.); }
|
||||
// Draw code helpers. The logic where these are used rely heavily on Build's angle period.
|
||||
double look_anghalf(double const smoothratio) { return (!SyncInput() ? look_ang : interpolatedlookang(smoothratio)).Normalized180().Buildfang() * 0.5; }
|
||||
double looking_arc(double const smoothratio) { return fabs((!SyncInput() ? look_ang : interpolatedlookang(smoothratio)).Normalized180().Buildfang()) * (1. / 9.); }
|
||||
|
||||
// Ticrate playsim adjustment setters and processor.
|
||||
void addadjustment(binangle const value)
|
||||
|
|
|
@ -75,8 +75,8 @@ void viewBackupView(int nPlayer)
|
|||
pView->bobWidth = pPlayer->bobWidth;
|
||||
pView->shakeBobY = pPlayer->swayHeight;
|
||||
pView->shakeBobX = pPlayer->swayWidth;
|
||||
pView->look_ang = DAngle::fromBam(pPlayer->angle.look_ang.asbam());
|
||||
pView->rotscrnang = DAngle::fromBam(pPlayer->angle.rotscrnang.asbam());
|
||||
pView->look_ang = pPlayer->angle.look_ang;
|
||||
pView->rotscrnang = pPlayer->angle.rotscrnang;
|
||||
pPlayer->angle.backup();
|
||||
pPlayer->horizon.backup();
|
||||
}
|
||||
|
@ -534,13 +534,13 @@ void SetupView(int& cX, int& cY, int& cZ, DAngle& cA, fixedhoriz& cH, sectortype
|
|||
{
|
||||
cA = DAngle::fromBam(gView->angle.sum().asbam());
|
||||
cH = gView->horizon.sum();
|
||||
rotscrnang = DAngle::fromBam(gView->angle.rotscrnang.asbam());
|
||||
rotscrnang = gView->angle.rotscrnang;
|
||||
}
|
||||
else
|
||||
{
|
||||
cA = DAngle::fromBam(gView->angle.interpolatedsum(gInterpolate).asbam());
|
||||
cH = gView->horizon.interpolatedsum(gInterpolate);
|
||||
rotscrnang = DAngle::fromBam(gView->angle.interpolatedrotscrn(gInterpolate).asbam());
|
||||
rotscrnang = gView->angle.interpolatedrotscrn(gInterpolate);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -490,8 +490,8 @@ void DoPlayer(bool bSet, int lVar1, int lLabelID, int lVar2, DDukeActor* sActor,
|
|||
break;
|
||||
|
||||
case PLAYER_LOOK_ANG:
|
||||
if (bSet) ps[iPlayer].angle.look_ang = buildang(lValue);
|
||||
else SetGameVarID(lVar2, ps[iPlayer].angle.look_ang.asbuild(), sActor, sPlayer);
|
||||
if (bSet) ps[iPlayer].angle.look_ang = DAngle::fromBuild(lValue);
|
||||
else SetGameVarID(lVar2, ps[iPlayer].angle.look_ang.Buildang(), sActor, sPlayer);
|
||||
break;
|
||||
|
||||
case PLAYER_LAST_EXTRA:
|
||||
|
@ -713,9 +713,9 @@ void DoPlayer(bool bSet, int lVar1, int lLabelID, int lVar2, DDukeActor* sActor,
|
|||
if (bSet)
|
||||
{
|
||||
ps[iPlayer].angle.orotscrnang = ps[iPlayer].angle.rotscrnang;
|
||||
ps[iPlayer].angle.rotscrnang = buildang(lValue);
|
||||
ps[iPlayer].angle.rotscrnang = DAngle::fromBuild(lValue);
|
||||
}
|
||||
else SetGameVarID(lVar2, ps[iPlayer].angle.rotscrnang.asbuild(), sActor, sPlayer);
|
||||
else SetGameVarID(lVar2, ps[iPlayer].angle.rotscrnang.Buildang(), sActor, sPlayer);
|
||||
break;
|
||||
|
||||
case PLAYER_DEAD_FLAG:
|
||||
|
@ -2255,7 +2255,7 @@ int ParseState::parse(void)
|
|||
ps[g_p].weapreccnt = 0;
|
||||
ps[g_p].ftq = 0;
|
||||
ps[g_p].vel.X = ps[g_p].vel.Y = 0;
|
||||
if (!isRR()) ps[g_p].angle.orotscrnang = ps[g_p].angle.rotscrnang = buildang(0);
|
||||
if (!isRR()) ps[g_p].angle.orotscrnang = ps[g_p].angle.rotscrnang = DAngle::fromDeg(0.);
|
||||
|
||||
ps[g_p].falling_counter = 0;
|
||||
|
||||
|
|
|
@ -122,7 +122,7 @@ void forceplayerangle(int snum)
|
|||
|
||||
p->horizon.addadjustment(buildhoriz(64));
|
||||
p->sync.actions |= SB_CENTERVIEW;
|
||||
p->angle.rotscrnang = p->angle.look_ang = buildang(n >> 1);
|
||||
p->angle.rotscrnang = p->angle.look_ang = DAngle::fromBuild(n >> 1);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
@ -631,10 +631,10 @@ void playerisdead(int snum, int psectlotag, int fz, int cz)
|
|||
|
||||
updatesector(p->player_int_pos().X, p->player_int_pos().Y, &p->cursector);
|
||||
|
||||
pushmove(p->pos, &p->cursector, 128L, (4 << 8), (20 << 8), CLIPMASK0);
|
||||
pushmove(p->pos, &p->cursector, 128, (4 << 8), (20 << 8), CLIPMASK0);
|
||||
|
||||
if (fz > cz + (16 << 8) && actor->spr.pal != 1)
|
||||
p->angle.rotscrnang = buildang(p->dead_flag + ((fz + p->player_int_pos().Z) >> 7));
|
||||
p->angle.rotscrnang = DAngle::fromBuild(p->dead_flag + ((fz + p->player_int_pos().Z) >> 7));
|
||||
|
||||
p->on_warping_sector = 0;
|
||||
|
||||
|
@ -746,16 +746,16 @@ void player_struct::apply_seasick(double factor)
|
|||
if (SeaSick < 250)
|
||||
{
|
||||
if (SeaSick >= 180)
|
||||
angle.rotscrnang += buildfang(24 * factor);
|
||||
angle.rotscrnang += DAngle::fromDeg(24 * factor * BAngToDegree);
|
||||
else if (SeaSick >= 130)
|
||||
angle.rotscrnang -= buildfang(24 * factor);
|
||||
angle.rotscrnang -= DAngle::fromDeg(24 * factor * BAngToDegree);
|
||||
else if (SeaSick >= 70)
|
||||
angle.rotscrnang += buildfang(24 * factor);
|
||||
angle.rotscrnang += DAngle::fromDeg(24 * factor * BAngToDegree);
|
||||
else if (SeaSick >= 20)
|
||||
angle.rotscrnang -= buildfang(24 * factor);
|
||||
angle.rotscrnang -= DAngle::fromDeg(24 * factor * BAngToDegree);
|
||||
}
|
||||
if (SeaSick < 250)
|
||||
angle.look_ang = buildfang(((krand() & 255) - 128) * factor);
|
||||
angle.look_ang = DAngle::fromDeg(((krand() & 255) - 128) * factor * BAngToDegree);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -177,8 +177,8 @@ void resetplayerstats(int snum)
|
|||
p->jetpack_on = 0;
|
||||
p->holoduke_on = nullptr;
|
||||
|
||||
p->angle.olook_ang = p->angle.look_ang = buildang(512 - (((~currentLevel->levelNumber) & 1) << 10));
|
||||
p->angle.orotscrnang = p->angle.rotscrnang = buildang(0);
|
||||
p->angle.olook_ang = p->angle.look_ang = DAngle::fromBuild(512 - (((~currentLevel->levelNumber) & 1) << 10));
|
||||
p->angle.orotscrnang = p->angle.rotscrnang = DAngle::fromDeg(0.);
|
||||
|
||||
p->newOwner =nullptr;
|
||||
p->jumping_counter = 0;
|
||||
|
|
|
@ -281,7 +281,7 @@ void displayrooms(int snum, double smoothratio, bool sceneonly)
|
|||
setgamepalette(setpal(p));
|
||||
|
||||
// set screen rotation.
|
||||
rotscrnang = DAngle::fromBam((!SyncInput() ? p->angle.rotscrnang : p->angle.interpolatedrotscrn(smoothratio)).asbam());
|
||||
rotscrnang = !SyncInput() ? p->angle.rotscrnang : p->angle.interpolatedrotscrn(smoothratio);
|
||||
|
||||
#if 0
|
||||
if ((snum == myconnectindex) && (numplayers > 1))
|
||||
|
|
|
@ -268,7 +268,7 @@ struct player_struct
|
|||
short weaprecs[256], weapreccnt;
|
||||
unsigned int interface_toggle_flag;
|
||||
|
||||
short dead_flag, show_empty_weapon; // JBF 20031220: added orotscrnang
|
||||
short dead_flag, show_empty_weapon;
|
||||
short scuba_amount, jetpack_amount, steroids_amount, shield_amount;
|
||||
short pycount, frag_ps;
|
||||
short transporter_hold, last_full_weapon, footprintshade, boot_amount;
|
||||
|
|
|
@ -242,13 +242,13 @@ void DrawView(double smoothRatio, bool sceneonly)
|
|||
{
|
||||
pan = PlayerList[nLocalPlayer].horizon.sum();
|
||||
nAngle = DAngle::fromBam(PlayerList[nLocalPlayer].angle.sum().asbam());
|
||||
rotscrnang = DAngle::fromBam(PlayerList[nLocalPlayer].angle.rotscrnang.asbam());
|
||||
rotscrnang = PlayerList[nLocalPlayer].angle.rotscrnang;
|
||||
}
|
||||
else
|
||||
{
|
||||
pan = PlayerList[nLocalPlayer].horizon.interpolatedsum(smoothRatio);
|
||||
nAngle = DAngle::fromBam(PlayerList[nLocalPlayer].angle.interpolatedsum(smoothRatio).asbam());
|
||||
rotscrnang = DAngle::fromBam(PlayerList[nLocalPlayer].angle.interpolatedrotscrn(smoothRatio).asbam());
|
||||
rotscrnang = PlayerList[nLocalPlayer].angle.interpolatedrotscrn(smoothRatio);
|
||||
}
|
||||
|
||||
if (!bCamera)
|
||||
|
|
|
@ -1402,13 +1402,13 @@ void drawscreen(PLAYER* pp, double smoothratio, bool sceneonly)
|
|||
{
|
||||
tang = DAngle::fromBam(camerapp->angle.interpolatedsum(smoothratio).asbam());
|
||||
thoriz = camerapp->horizon.interpolatedsum(smoothratio);
|
||||
trotscrnang = DAngle::fromBam(camerapp->angle.interpolatedrotscrn(smoothratio).asbam());
|
||||
trotscrnang = camerapp->angle.interpolatedrotscrn(smoothratio);
|
||||
}
|
||||
else
|
||||
{
|
||||
tang = DAngle::fromBam(pp->angle.sum().asbam());
|
||||
thoriz = pp->horizon.sum();
|
||||
trotscrnang = DAngle::fromBam(pp->angle.rotscrnang.asbam());
|
||||
trotscrnang = pp->angle.rotscrnang;
|
||||
}
|
||||
tsect = camerapp->cursector;
|
||||
|
||||
|
|
Loading…
Reference in a new issue