From e91d88fd2b5a07cb6648dbe7338d00abc9acc338 Mon Sep 17 00:00:00 2001 From: Jonathan Schleifer Date: Sun, 23 Mar 2025 14:49:15 +0000 Subject: [PATCH] Remove vadd/vsub/vmul/vdiv FossilOrigin-Name: 0c8fc2f1482a22d97a114b5b35f2a4d55d2d72a113178070d87fffab40fa8586 --- src/cube.h | 9 ++------- src/entities.m | 6 +++--- src/physics.m | 13 +++++++------ src/renderparticles.m | 11 +++++------ src/savegamedemo.m | 40 ++++++++++++++++++---------------------- src/weapon.m | 42 +++++++++++++++++++----------------------- 6 files changed, 54 insertions(+), 67 deletions(-) diff --git a/src/cube.h b/src/cube.h index 9a82e3d..e6eab65 100644 --- a/src/cube.h +++ b/src/cube.h @@ -288,13 +288,8 @@ extern bool demoplayback; // simplistic vector ops #define dotprod(u, v) ((u).x * (v).x + (u).y * (v).y + (u).z * (v).z) -#define vmul(u, f) u = OFMultiplyVector3D(u, f) -#define vdiv(u, f) u = OFMultiplyVector3D(u, (f) / 1.0f) -#define vadd(u, v) u = OFAddVectors3D(u, v) -#define vsub(u, v) u = OFSubtractVectors3D(u, v) -#define vdist(d, v, e, s) \ - OFVector3D v = s; \ - vsub(v, e); \ +#define vdist(d, v, e, s) \ + OFVector3D v = OFSubtractVectors3D(s, e); \ float d = (float)sqrt(dotprod(v, v)); #define vreject(v, u, max) \ ((v).x > (u).x + (max) || (v).x < (u).x - (max) || \ diff --git a/src/entities.m b/src/entities.m index 0ed433e..38c6b61 100644 --- a/src/entities.m +++ b/src/entities.m @@ -294,9 +294,9 @@ pickup(int n, DynamicEntity *d) lastjumppad = lastmillis; OFVector3D v = OFMakeVector3D((int)(char)ents[n].attr3 / 10.0f, (int)(char)ents[n].attr2 / 10.0f, ents[n].attr1 / 10.0f); - player1.velocity = - OFMakeVector3D(player1.velocity.x, player1.velocity.y, 0); - vadd(player1.velocity, v); + player1.velocity = OFAddVectors3D( + OFMakeVector3D(player1.velocity.x, player1.velocity.y, 0), + v); playsoundc(S_JUMPPAD); break; } diff --git a/src/physics.m b/src/physics.m index b09c099..22b3790 100644 --- a/src/physics.m +++ b/src/physics.m @@ -292,18 +292,19 @@ moveplayer4(DynamicEntity *pl, int moveres, bool local, int curtime) // slowly apply friction and direction to // velocity, gives a smooth movement - vmul(pl.velocity, fpsfric - 1); - vadd(pl.velocity, d); - vdiv(pl.velocity, fpsfric); - d = pl.velocity; - vmul(d, speed); // d is now frametime based velocity vector + OFVector3D velocity = OFMultiplyVector3D(pl.velocity, fpsfric - 1); + velocity = OFAddVectors3D(velocity, d); + velocity = OFMultiplyVector3D(velocity, 1.0f / fpsfric); + pl.velocity = velocity; + // d is now frametime based velocity vector + d = OFMultiplyVector3D(velocity, speed); pl.blocked = false; pl.moving = true; if (floating) { // just apply velocity - vadd(pl.origin, d); + pl.origin = OFAddVectors3D(pl.origin, d); if (pl.jumpNext) { pl.jumpNext = false; pl.velocity = diff --git a/src/renderparticles.m b/src/renderparticles.m index 3af1c62..cc161a5 100644 --- a/src/renderparticles.m +++ b/src/renderparticles.m @@ -121,10 +121,9 @@ render_particles(int time) if (pt->gr) p->o.z -= ((lastmillis - p->millis) / 3.0f) * curtime / (pt->gr * 10000); - OFVector3D a = p->d; - vmul(a, time); - vdiv(a, 20000.0f); - vadd(p->o, a); + OFVector3D a = OFMultiplyVector3D(p->d, time); + a = OFMultiplyVector3D(a, 1.0f / 20000.0f); + p->o = OFAddVectors3D(p->o, a); pp = &p->next; } } @@ -154,10 +153,10 @@ void particle_trail(int type, int fade, const OFVector3D *s, const OFVector3D *e) { vdist(d, v, *s, *e); - vdiv(v, d * 2 + 0.1f); + v = OFMultiplyVector3D(v, 1.0f / (d * 2 + 0.1f)); OFVector3D p = *s; for (int i = 0; i < ((int)d * 2); i++) { - vadd(p, v); + p = OFAddVectors3D(p, v); OFVector3D d = OFMakeVector3D(rnd(11) - 5, rnd(11) - 5, rnd(11) - 5); newparticle(&p, &d, rnd(fade) + fade, type); diff --git a/src/savegamedemo.m b/src/savegamedemo.m index f23d2a5..b79da0a 100644 --- a/src/savegamedemo.m +++ b/src/savegamedemo.m @@ -388,28 +388,24 @@ startdemo() VAR(demodelaymsec, 0, 120, 500); // spline interpolation -#define catmulrom(z, a, b, c, s, dest) \ - { \ - OFVector3D t1 = b, t2 = c; \ - \ - vsub(t1, z); \ - vmul(t1, 0.5f); \ - vsub(t2, a); \ - vmul(t2, 0.5f); \ - \ - float s2 = s * s; \ - float s3 = s * s2; \ - \ - dest = a; \ - OFVector3D t = b; \ - \ - vmul(dest, 2 * s3 - 3 * s2 + 1); \ - vmul(t, -2 * s3 + 3 * s2); \ - vadd(dest, t); \ - vmul(t1, s3 - 2 * s2 + s); \ - vadd(dest, t1); \ - vmul(t2, s3 - s2); \ - vadd(dest, t2); \ +#define catmulrom(z, a, b, c, s, dest) \ + { \ + OFVector3D t1 = OFSubtractVectors3D(b, z); \ + t1 = OFMultiplyVector3D(t1, 0.5f); \ + \ + OFVector3D t2 = OFSubtractVectors3D(c, a); \ + t2 = OFMultiplyVector3D(t2, 0.5f); \ + \ + float s2 = s * s; \ + float s3 = s * s2; \ + \ + dest = OFMultiplyVector3D(a, 2 * s3 - 3 * s2 + 1); \ + OFVector3D t = OFMultiplyVector3D(b, -2 * s3 + 3 * s2); \ + dest = OFAddVectors3D(dest, t); \ + t1 = OFMultiplyVector3D(t1, s3 - 2 * s2 + s); \ + dest = OFAddVectors3D(dest, t1); \ + t2 = OFMultiplyVector3D(t2, s3 - s2); \ + dest = OFAddVectors3D(dest, t2); \ } void diff --git a/src/weapon.m b/src/weapon.m index 9c8e085..fb70cfa 100644 --- a/src/weapon.m +++ b/src/weapon.m @@ -77,12 +77,9 @@ createrays(const OFVector3D *from, const OFVector3D *to) { vdist(dist, dvec, *from, *to); float f = dist * SGSPREAD / 1000; - for (int i = 0; i < SGRAYS; i++) { + for (int i = 0; i < SGRAYS; i++) #define RNDD (rnd(101) - 50) * f - OFVector3D r = OFMakeVector3D(RNDD, RNDD, RNDD); - sg[i] = *to; - vadd(sg[i], r); - } + sg[i] = OFAddVectors3D(*to, OFMakeVector3D(RNDD, RNDD, RNDD)); } // if lineseg hits entity bounding box @@ -91,8 +88,8 @@ intersect(DynamicEntity *d, const OFVector3D *from, const OFVector3D *to) { OFVector3D v = *to, w = d.origin; const OFVector3D *p; - vsub(v, *from); - vsub(w, *from); + v = OFSubtractVectors3D(v, *from); + w = OFSubtractVectors3D(w, *from); float c1 = dotprod(w, v); if (c1 <= 0) @@ -102,9 +99,8 @@ intersect(DynamicEntity *d, const OFVector3D *from, const OFVector3D *to) if (c2 <= c1) p = to; else { - float f = c1 / c2; - vmul(v, f); - vadd(v, *from); + v = OFMultiplyVector3D(v, c1 / c2); + v = OFAddVectors3D(v, *from); p = &v; } } @@ -199,8 +195,9 @@ radialeffect( dist = 0; int damage = (int)(qdam * (1 - (dist / RL_DAMRAD))); hit(cn, damage, o, at); - vmul(temp, (RL_DAMRAD - dist) * damage / 800); - vadd(o.velocity, temp); + temp = + OFMultiplyVector3D(temp, (RL_DAMRAD - dist) * damage / 800); + o.velocity = OFAddVectors3D(o.velocity, temp); } } @@ -273,8 +270,8 @@ moveprojectiles(float time) float dtime = dist * 1000 / p.speed; if (time > dtime) dtime = time; - vmul(v, time / dtime); - vadd(v, p.o); + v = OFMultiplyVector3D(v, time / dtime); + v = OFAddVectors3D(v, p.o); if (p.local) { for (id player in players) if (player != [OFNull null]) @@ -354,8 +351,8 @@ hitpush(int target, int damage, DynamicEntity *d, DynamicEntity *at, { hit(target, damage, d, at); vdist(dist, v, *from, *to); - vmul(v, damage / dist / 50); - vadd(d.velocity, v); + v = OFMultiplyVector3D(v, damage / dist / 50); + d.velocity = OFAddVectors3D(d.velocity, v); } void @@ -404,17 +401,16 @@ shoot(DynamicEntity *d, const OFVector3D *targ) from.z -= 0.2f; // below eye vdist(dist, unitv, from, to); - vdiv(unitv, dist); - OFVector3D kickback = unitv; - vmul(kickback, guns[d.gunSelect].kickamount * -0.01f); - vadd(d.velocity, kickback); + unitv = OFMultiplyVector3D(unitv, 1.0f / dist); + OFVector3D kickback = + OFMultiplyVector3D(unitv, guns[d.gunSelect].kickamount * -0.01f); + d.velocity = OFAddVectors3D(d.velocity, kickback); if (d.pitch < 80.0f) d.pitch += guns[d.gunSelect].kickamount * 0.05f; if (d.gunSelect == GUN_FIST || d.gunSelect == GUN_BITE) { - vmul(unitv, 3); // punch range - to = from; - vadd(to, unitv); + unitv = OFMultiplyVector3D(unitv, 3); // punch range + to = OFAddVectors3D(from, unitv); } if (d.gunSelect == GUN_SG) createrays(&from, &to);