Skip to content

Commit

Permalink
- position cleanup in actor.cpp (mainly queball and recon)
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Aug 9, 2022
1 parent d3bfc78 commit 4e0c513
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 26 deletions.
6 changes: 0 additions & 6 deletions source/build/include/build.h
Expand Up @@ -177,12 +177,6 @@ inline int32_t ksqrt(uint64_t num)
return int(sqrt(double(num)));
}

int32_t getangle(int32_t xvect, int32_t yvect);
inline int32_t getangle(const vec2_t& vec)
{
return getangle(vec.X, vec.Y);
}

inline constexpr uint32_t uhypsq(int32_t const dx, int32_t const dy)
{
return (uint32_t)dx*dx + (uint32_t)dy*dy;
Expand Down
2 changes: 1 addition & 1 deletion source/build/src/engine.cpp
Expand Up @@ -189,7 +189,7 @@ int32_t rintersect(int32_t x1, int32_t y1, int32_t z1,
}


int32_t getangle(int32_t xvect, int32_t yvect)
int32_t _getangle(int32_t xvect, int32_t yvect)
{
int32_t rv;

Expand Down
16 changes: 16 additions & 0 deletions source/core/binaryangle.h
Expand Up @@ -42,6 +42,7 @@
#include "xs_Float.h" // needed for reliably overflowing float->int conversions.
#include "serializer.h"
#include "math/cmath.h"
#include "intvec.h"

class FSerializer;

Expand Down Expand Up @@ -368,6 +369,21 @@ inline binangle bvectangbam(double x, double y)
return radang(atan2(y, x));
}

inline int getangle(double xvect, double yvect)
{
return bvectangbam(xvect, yvect).asbuild();
}

inline int getangle(const DVector2& vec)
{
return getangle(vec.X, vec.Y);
}

inline int getangle(const vec2_t& vec)
{
return getangle(vec.X, vec.Y);
}


//---------------------------------------------------------------------------
//
Expand Down
36 changes: 18 additions & 18 deletions source/games/duke/src/actors.cpp
Expand Up @@ -441,7 +441,7 @@ void moveplayers(void)

if (p->actorsqu != nullptr)
{
p->angle.addadjustment(getincanglebam(p->angle.ang, bvectangbam(p->actorsqu->int_pos().X - p->player_int_pos().X, p->actorsqu->int_pos().Y - p->player_int_pos().Y)) >> 2);
p->angle.addadjustment(getincanglebam(p->angle.ang, bvectangbam(p->actorsqu->spr.pos.X - p->pos.X, p->actorsqu->spr.pos.Y - p->pos.Y)) >> 2);
}

if (act->spr.extra > 0)
Expand All @@ -461,7 +461,7 @@ void moveplayers(void)

if (p->wackedbyactor != nullptr && p->wackedbyactor->spr.statnum < MAXSTATUS)
{
p->angle.addadjustment(getincanglebam(p->angle.ang, bvectangbam(p->wackedbyactor->int_pos().X - p->player_int_pos().X, p->wackedbyactor->int_pos().Y - p->player_int_pos().Y)) >> 1);
p->angle.addadjustment(getincanglebam(p->angle.ang, bvectangbam(p->wackedbyactor->spr.pos.X - p->pos.X, p->wackedbyactor->spr.pos.Y - p->pos.Y)) >> 1);
}
}
act->spr.ang = p->angle.ang.asbuild();
Expand Down Expand Up @@ -1499,7 +1499,7 @@ bool queball(DDukeActor *actor, int pocket, int queball, int stripeball)
{
// if(actor->spr.pal == 12)
{
int j = getincangle(ps[p].angle.ang.asbuild(), getangle(actor->int_pos().X - ps[p].player_int_pos().X, actor->int_pos().Y - ps[p].player_int_pos().Y));
int j = getincangle(ps[p].angle.ang.asbuild(), getangle(actor->spr.pos.XY() - ps[p].pos.XY()));
if (j > -64 && j < 64 && PlayerInput(p, SB_OPEN))
if (ps[p].toggle_key_flag == 1)
{
Expand All @@ -1509,7 +1509,7 @@ bool queball(DDukeActor *actor, int pocket, int queball, int stripeball)
{
if (act2->spr.picnum == queball || act2->spr.picnum == stripeball)
{
j = getincangle(ps[p].angle.ang.asbuild(), getangle(act2->int_pos().X - ps[p].player_int_pos().X, act2->int_pos().Y - ps[p].player_int_pos().Y));
j = getincangle(ps[p].angle.ang.asbuild(), getangle(act2->spr.pos.XY() - ps[p].pos.XY()));
if (j > -64 && j < 64)
{
int l;
Expand All @@ -1531,7 +1531,7 @@ bool queball(DDukeActor *actor, int pocket, int queball, int stripeball)
}
if (x < 512 && actor->sector() == ps[p].cursector)
{
actor->spr.ang = getangle(actor->int_pos().X - ps[p].player_int_pos().X, actor->int_pos().Y - ps[p].player_int_pos().Y);
actor->spr.ang = getangle(actor->spr.pos.XY() - ps[p].pos.XY());
actor->spr.xvel = 48;
}
}
Expand Down Expand Up @@ -1677,13 +1677,13 @@ void recon(DDukeActor *actor, int explosion, int firelaser, int attacksnd, int p
fi.shoot(actor, firelaser);
actor->spr.ang = a;
}
if (actor->temp_data[2] > (26 * 3) || !cansee(actor->int_pos().X, actor->int_pos().Y, actor->int_pos().Z - (16 << 8), actor->sector(), ps[p].player_int_pos().X, ps[p].player_int_pos().Y, ps[p].player_int_pos().Z, ps[p].cursector))
if (actor->temp_data[2] > (26 * 3) || !cansee(actor->spr.pos.plusZ(-16), actor->sector(), ps[p].pos, ps[p].cursector))
{
actor->temp_data[0] = 0;
actor->temp_data[2] = 0;
}
else actor->tempang +=
getincangle(actor->tempang, getangle(ps[p].player_int_pos().X - actor->int_pos().X, ps[p].player_int_pos().Y - actor->int_pos().Y)) / 3;
getincangle(actor->tempang, getangle(ps[p].pos.XY() - actor->spr.pos.XY())) / 3;
}
else if (actor->temp_data[0] == 2 || actor->temp_data[0] == 3)
{
Expand All @@ -1693,14 +1693,14 @@ void recon(DDukeActor *actor, int explosion, int firelaser, int attacksnd, int p

if (actor->temp_data[0] == 2)
{
int l = ps[p].player_int_pos().Z - actor->int_pos().Z;
if (abs(l) < (48 << 8)) actor->temp_data[0] = 3;
else actor->add_int_z(Sgn(ps[p].player_int_pos().Z - actor->int_pos().Z) << shift); // The shift here differs between Duke and RR.
double l = ps[p].pos.Z - actor->spr.pos.Z;
if (fabs(l) < 48) actor->temp_data[0] = 3;
else actor->spr.pos.Z += (Sgn(ps[p].pos.Z - actor->spr.pos.Z) * shift); // The shift here differs between Duke and RR.
}
else
{
actor->temp_data[2]++;
if (actor->temp_data[2] > (26 * 3) || !cansee(actor->int_pos().X, actor->int_pos().Y, actor->int_pos().Z - (16 << 8), actor->sector(), ps[p].player_int_pos().X, ps[p].player_int_pos().Y, ps[p].player_int_pos().Z, ps[p].cursector))
if (actor->temp_data[2] > (26 * 3) || !cansee(actor->spr.pos.plusZ(-16), actor->sector(), ps[p].pos, ps[p].cursector))
{
actor->temp_data[0] = 1;
actor->temp_data[2] = 0;
Expand All @@ -1711,7 +1711,7 @@ void recon(DDukeActor *actor, int explosion, int firelaser, int attacksnd, int p
fi.shoot(actor, firelaser);
}
}
actor->spr.ang += getincangle(actor->spr.ang, getangle(ps[p].player_int_pos().X - actor->int_pos().X, ps[p].player_int_pos().Y - actor->int_pos().Y)) >> 2;
actor->spr.ang += getincangle(actor->spr.ang, getangle(ps[p].pos.XY() - actor->spr.pos.XY())) >> 2;
}

if (actor->temp_data[0] != 2 && actor->temp_data[0] != 3 && Owner)
Expand All @@ -1722,7 +1722,7 @@ void recon(DDukeActor *actor, int explosion, int firelaser, int attacksnd, int p
a = actor->spr.ang;
actor->spr.xvel >>= 1;
}
else a = getangle(Owner->int_pos().X - actor->int_pos().X, Owner->int_pos().Y - actor->int_pos().Y);
else a = getangle(Owner->spr.pos.XY() - actor->spr.pos.XY());

if (actor->temp_data[0] == 1 || actor->temp_data[0] == 4) // Found a locator and going with it
{
Expand Down Expand Up @@ -1773,11 +1773,11 @@ void recon(DDukeActor *actor, int explosion, int firelaser, int attacksnd, int p
actor->temp_data[3] = getincangle(actor->spr.ang, a);
actor->spr.ang += actor->temp_data[3] >> 3;

if (actor->int_pos().Z < Owner->int_pos().Z - 512)
actor->add_int_z(512);
else if (actor->int_pos().Z > Owner->int_pos().Z + 512)
actor->add_int_z(-512);
else actor->set_int_z(Owner->int_pos().Z);
if (actor->spr.pos.Z < Owner->spr.pos.Z - 2)
actor->spr.pos.Z += 2;
else if (actor->spr.pos.Z > Owner->spr.pos.Z + 2)
actor->spr.pos -= 2;
else actor->spr.pos.Z = Owner->spr.pos.Z;
}

if (roamsnd >= 0 && S_CheckActorSoundPlaying(actor, roamsnd) < 1)
Expand Down
2 changes: 1 addition & 1 deletion source/games/duke/src/actors_r.cpp
Expand Up @@ -2811,7 +2811,7 @@ void moveactors_r(void)
case UFO3:
case UFO4:
case UFO5:
recon(act, EXPLOSION2, FIRELASER, -1, -1, 457, 8, [](DDukeActor* act) ->int
recon(act, EXPLOSION2, FIRELASER, -1, -1, 457, 1, [](DDukeActor* act) ->int
{
if (isRRRA() && ufospawnsminion)
return MINION;
Expand Down

0 comments on commit 4e0c513

Please sign in to comment.