- added a Sum function to TVector familiy

Duke uses this kind of distance check quite a lot so it makes sense to add it to the vectors.
This commit is contained in:
Christoph Oelckers 2022-09-13 00:46:38 +02:00
parent 1d7f2c81b6
commit 3352783be2
3 changed files with 24 additions and 6 deletions

View file

@ -237,6 +237,12 @@ struct TVector2
{
return X*X + Y*Y;
}
double Sum() const
{
return abs(X) + abs(Y);
}
// Return a unit vector facing the same direction as this one
TVector2 Unit() const
@ -601,6 +607,12 @@ struct TVector3
{
return X*X + Y*Y + Z*Z;
}
double Sum() const
{
return abs(X) + abs(Y) + abs(Z);
}
// Return a unit vector facing the same direction as this one
TVector3 Unit() const
@ -900,6 +912,12 @@ struct TVector4
{
return X*X + Y*Y + Z*Z + W*W;
}
double Sum() const
{
return abs(X) + abs(Y) + abs(Z) + abs(W);
}
// Return a unit vector facing the same direction as this one
TVector4 Unit() const

View file

@ -4928,7 +4928,7 @@ DAngle furthestangle(DDukeActor *actor, int angs)
{
hitscan(actor->spr.pos.plusZ(-8), actor->sector(), DVector3(j.ToVector() * 1024, 0), hit, CLIPMASK1);
d = abs(hit.hitpos.X - actor->spr.pos.X) + abs(hit.hitpos.Y - actor->spr.pos.Y);
d = (hit.hitpos.XY() - actor->spr.pos.XY()).Sum();
if (d > greatestd)
{
@ -4960,8 +4960,8 @@ int furthestcanseepoint(DDukeActor *actor, DDukeActor* tosee, DVector2& pos)
{
hitscan(tosee->spr.pos.plusZ(-16), tosee->sector(), vec3_t(bcos(j), bsin(j), 16384 - (krand() & 32767)), hit, CLIPMASK1);
double d = abs(hit.hitpos.X - tosee->spr.pos.X) + abs(hit.hitpos.Y - tosee->spr.pos.Y);
double da = abs(hit.hitpos.X - actor->spr.pos.X) + abs(hit.hitpos.Y - actor->spr.pos.Y);
double d = (hit.hitpos.XY() - tosee->spr.pos.XY()).Sum();
double da = (hit.hitpos.XY() - actor->spr.pos.XY()).Sum();
if (d < da && hit.hitSector)
if (cansee(hit.hitpos, hit.hitSector, actor->spr.pos.plusZ(-16), actor->sector()))

View file

@ -227,7 +227,7 @@ int findplayer(const DDukeActor* actor, double* d)
if (ud.multimode < 2)
{
if (d) *d = abs(ps[myconnectindex].opos.X - s.X) + abs(ps[myconnectindex].opos.Y - s.Y) + abs(ps[myconnectindex].opos.Z - s.Z + 28);
if (d) *d = (ps[myconnectindex].opos - s).plusZ(28).Sum();
return myconnectindex;
}
@ -236,7 +236,7 @@ int findplayer(const DDukeActor* actor, double* d)
for (j = connecthead; j >= 0; j = connectpoint2[j])
{
x = abs(ps[j].opos.X - s.X) + abs(ps[j].opos.Y - s.Y) + abs(ps[j].opos.Z - s.Z + 28);
x = (ps[j].opos - s).plusZ(28).Sum();
if (x < closest && ps[j].GetActor()->spr.extra > 0)
{
closest_player = j;
@ -265,7 +265,7 @@ int findotherplayer(int p, double* d)
for (j = connecthead; j >= 0; j = connectpoint2[j])
if (p != j && ps[j].GetActor()->spr.extra > 0)
{
x = abs(ps[j].opos.X - ps[p].pos.X) + abs(ps[j].opos.Y - ps[p].pos.Y) + abs(ps[j].opos.Z - ps[p].pos.Z);
x = (ps[j].opos - ps[p].pos).Sum();
if (x < closest)
{