- Duke: Change int_ang() usage in camera().

* This commit also restores the original method of incrementing the camera's angle that was replaced due to a hiccup/stutter where the angle suddenly skipped forward by 16 instead of 8, but with a fix from EDuke32. This avoids using 3x extra `temp_data[]` slots.
This commit is contained in:
Mitchell Richters 2022-08-29 18:17:38 +10:00 committed by Christoph Oelckers
parent 0dcd209d91
commit 19d21555a6
2 changed files with 13 additions and 33 deletions

View file

@ -1385,8 +1385,7 @@ public:
int Sgn() const int Sgn() const
{ {
const auto normalized = (signed int)BAMs(); return ::Sgn(int(BAMs()));
return (normalized > 0) - (normalized < 0);
} }
}; };

View file

@ -1950,10 +1950,11 @@ void camera(DDukeActor *actor)
{ {
if (actor->temp_data[0] == 0) if (actor->temp_data[0] == 0)
{ {
actor->temp_data[1] += 8;
if (gs.camerashitable) if (gs.camerashitable)
{ {
int j = fi.ifhitbyweapon(actor); if (fi.ifhitbyweapon(actor) >= 0)
if (j >= 0)
{ {
actor->temp_data[0] = 1; // static actor->temp_data[0] = 1; // static
actor->spr.cstat = CSTAT_SPRITE_INVISIBLE; actor->spr.cstat = CSTAT_SPRITE_INVISIBLE;
@ -1965,38 +1966,18 @@ void camera(DDukeActor *actor)
if (actor->spr.hitag > 0) if (actor->spr.hitag > 0)
{ {
// alias our temp_data array indexes. auto const angle = DAngle::fromBuild(8);
auto& increment = actor->temp_data[1];
auto& minimum = actor->temp_data[2];
auto& maximum = actor->temp_data[3];
auto& setupflag = actor->temp_data[4];
// set up camera if already not. if (actor->temp_data[1] < actor->spr.hitag)
if (setupflag != 1) actor->spr.angle += angle;
{ else if (actor->temp_data[1] < (actor->spr.hitag * 3))
increment = 8; actor->spr.angle -= angle;
minimum = actor->int_ang() - actor->spr.hitag - increment; else if (actor->temp_data[1] < (actor->spr.hitag << 2))
maximum = actor->int_ang() + actor->spr.hitag - increment; actor->spr.angle += angle;
setupflag = 1;
}
// update angle accordingly.
if (actor->int_ang() == minimum || actor->int_ang() == maximum)
{
increment = -increment;
actor->add_int_ang(increment);
}
else if (actor->int_ang() + increment < minimum)
{
actor->set_int_ang(minimum);
}
else if (actor->int_ang() + increment > maximum)
{
actor->set_int_ang(maximum);
}
else else
{ {
actor->add_int_ang(increment); actor->spr.angle += angle;
actor->temp_data[1] = 0;
} }
} }
} }