- 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
{
const auto normalized = (signed int)BAMs();
return (normalized > 0) - (normalized < 0);
return ::Sgn(int(BAMs()));
}
};

View file

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