diff --git a/src/Monster.m b/src/Monster.m index 120787d..cce0543 100644 --- a/src/Monster.m +++ b/src/Monster.m @@ -271,7 +271,8 @@ enemylos(Monster *m, OFVector3D *v) self.yaw = self.targetYaw; } - vdist(disttoenemy, vectoenemy, self.origin, self.enemy.origin); + float disttoenemy = + OFDistanceOfVectors3D(self.origin, self.enemy.origin); self.pitch = atan2(self.enemy.origin.z - self.origin.z, disttoenemy) * 180 / PI; @@ -469,7 +470,8 @@ enemylos(Monster *m, OFVector3D *v) } } else { v.z += monster.eyeHeight; - vdist(dist, t, monster.origin, v); + float dist = + OFDistanceOfVectors3D(monster.origin, v); v.z -= monster.eyeHeight; if (dist < 4) diff --git a/src/cube.h b/src/cube.h index c67c418..465f9ce 100644 --- a/src/cube.h +++ b/src/cube.h @@ -286,10 +286,6 @@ extern bool demoplayback; #define PI (3.1415927f) #define PI2 (2 * PI) -// simplistic vector ops -#define vdist(d, v, e, s) \ - OFVector3D v = OFSubtractVectors3D(s, e); \ - float d = sqrtf(OFDotProductOfVectors3D(v, v)); #define vreject(v, u, max) \ ((v).x > (u).x + (max) || (v).x < (u).x - (max) || \ (v).y > (u).y + (max) || (v).y < (u).y - (max)) diff --git a/src/entities.m b/src/entities.m index 38c6b61..f7cf5d5 100644 --- a/src/entities.m +++ b/src/entities.m @@ -321,7 +321,7 @@ checkitems() OFVector3D v = OFMakeVector3D( e.x, e.y, (float)S(e.x, e.y)->floor + player1.eyeHeight); - vdist(dist, t, player1.origin, v); + float dist = OFDistanceOfVectors3D(player1.origin, v); if (dist < (e.type == TELEPORT ? 4 : 2.5)) pickup(i, player1); diff --git a/src/renderparticles.m b/src/renderparticles.m index cc161a5..ab57497 100644 --- a/src/renderparticles.m +++ b/src/renderparticles.m @@ -152,7 +152,8 @@ particle_splash(int type, int num, int fade, const OFVector3D *p) void particle_trail(int type, int fade, const OFVector3D *s, const OFVector3D *e) { - vdist(d, v, *s, *e); + float d = OFDistanceOfVectors3D(*s, *e); + OFVector3D v = OFSubtractVectors3D(*s, *e); v = OFMultiplyVector3D(v, 1.0f / (d * 2 + 0.1f)); OFVector3D p = *s; for (int i = 0; i < ((int)d * 2); i++) { diff --git a/src/savegamedemo.m b/src/savegamedemo.m index 8e55d15..c88fb68 100644 --- a/src/savegamedemo.m +++ b/src/savegamedemo.m @@ -497,7 +497,8 @@ demoplaybackstep() fixwrap(a, player1); fixwrap(c, player1); fixwrap(z, player1); - vdist(dist, v, z.origin, c.origin); + float dist = + OFDistanceOfVectors3D(z.origin, c.origin); // if teleport or spawn, don't interpolate if (dist < 16) { catmulrom(z.origin, a.origin, b.origin, diff --git a/src/sound.m b/src/sound.m index d45f81d..3e127fa 100644 --- a/src/sound.m +++ b/src/sound.m @@ -111,10 +111,15 @@ static void updatechanvol(int chan, const OFVector3D *loc) { int vol = soundvol, pan = 255 / 2; + if (loc) { - vdist(dist, v, *loc, player1.origin); - vol -= (int)(dist * 3 * soundvol / - 255); // simple mono distance attenuation + OFVector3D origin = player1.origin; + float dist = OFDistanceOfVectors3D(*loc, origin); + OFVector3D v = OFSubtractVectors3D(*loc, origin); + + // simple mono distance attenuation + vol -= (int)(dist * 3 * soundvol / 255); + if (stereo && (v.x != 0 || v.y != 0)) { // relative angle of sound along X-Y axis float yaw = @@ -123,6 +128,7 @@ updatechanvol(int chan, const OFVector3D *loc) pan = (int)(255.9f * (0.5 * sin(yaw) + 0.5f)); } } + vol = (vol * MAXVOL) / 255; Mix_Volume(chan, vol); Mix_SetPanning(chan, 255 - pan, pan); diff --git a/src/weapon.m b/src/weapon.m index ae2df82..7ec674b 100644 --- a/src/weapon.m +++ b/src/weapon.m @@ -73,7 +73,7 @@ COMMAND(weapon, ARG_3STR, ^(OFString *a1, OFString *a2, OFString *a3) { void createrays(const OFVector3D *from, const OFVector3D *to) { - vdist(dist, dvec, *from, *to); + float dist = OFDistanceOfVectors3D(*from, *to); float f = dist * SGSPREAD / 1000; for (int i = 0; i < SGRAYS; i++) #define RNDD (rnd(101) - 50) * f @@ -186,13 +186,19 @@ radialeffect( { if (o.state != CS_ALIVE) return; - vdist(dist, temp, *v, o.origin); + + OFVector3D origin = o.origin; + float dist = OFDistanceOfVectors3D(*v, origin); + OFVector3D temp = OFSubtractVectors3D(*v, origin); dist -= 2; // account for eye distance imprecision + if (dist < RL_DAMRAD) { if (dist < 0) dist = 0; + int damage = (int)(qdam * (1 - (dist / RL_DAMRAD))); hit(cn, damage, o, at); + temp = OFMultiplyVector3D(temp, (RL_DAMRAD - dist) * damage / 800); o.velocity = OFAddVectors3D(o.velocity, temp); @@ -264,7 +270,9 @@ moveprojectiles(float time) int qdam = guns[p.gun].damage * (p.owner.quadMillis ? 4 : 1); if ([p.owner isKindOfClass:Monster.class]) qdam /= MONSTERDAMAGEFACTOR; - vdist(dist, v, p.o, p.to); + OFVector3D po = p.o, pto = pto; + float dist = OFDistanceOfVectors3D(po, pto); + OFVector3D v = OFSubtractVectors3D(po, pto); float dtime = dist * 1000 / p.speed; if (time > dtime) dtime = time; @@ -348,7 +356,8 @@ hitpush(int target, int damage, DynamicEntity *d, DynamicEntity *at, const OFVector3D *from, const OFVector3D *to) { hit(target, damage, d, at); - vdist(dist, v, *from, *to); + float dist = OFDistanceOfVectors3D(*from, *to); + OFVector3D v = OFSubtractVectors3D(*from, *to); v = OFMultiplyVector3D(v, damage / dist / 50); d.velocity = OFAddVectors3D(d.velocity, v); } @@ -398,7 +407,8 @@ shoot(DynamicEntity *d, const OFVector3D *targ) OFVector3D to = *targ; from.z -= 0.2f; // below eye - vdist(dist, unitv, from, to); + float dist = OFDistanceOfVectors3D(from, to); + OFVector3D unitv = OFSubtractVectors3D(from, to); unitv = OFMultiplyVector3D(unitv, 1.0f / dist); OFVector3D kickback = OFMultiplyVector3D(unitv, guns[d.gunSelect].kickamount * -0.01f); diff --git a/src/world.m b/src/world.m index 3b60ec5..d0f3ebd 100644 --- a/src/world.m +++ b/src/world.m @@ -298,7 +298,7 @@ closestent() // used for delent and edit mode ent display return; OFVector3D v = OFMakeVector3D(e.x, e.y, e.z); - vdist(dist, t, player1.origin, v); + float dist = OFDistanceOfVectors3D(player1.origin, v); if (dist < bdist) { best = i; bdist = dist;