Cube  Check-in [0c8fc2f148]

Overview
Comment:Remove vadd/vsub/vmul/vdiv
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 0c8fc2f1482a22d97a114b5b35f2a4d55d2d72a113178070d87fffab40fa8586
User & Date: js on 2025-03-23 14:49:15
Other Links: manifest | tags
Context
2025-03-23
17:41
Remove dotprod check-in: da90479adf user: js tags: trunk
14:49
Remove vadd/vsub/vmul/vdiv check-in: 0c8fc2f148 user: js tags: trunk
14:17
Adjust to ObjFW changes check-in: 85566b261d user: js tags: trunk
Changes

Modified src/cube.h from [de779124b5] to [38ea0aa1b6].

284
285
286
287
288
289
290
291
292
293
294
295
296


297
298
299
300
301
302
303
304
284
285
286
287
288
289
290






291
292

293
294
295
296
297
298
299







-
-
-
-
-
-
+
+
-







#define PIXELTAB (VIRTW / 12)

#define PI (3.1415927f)
#define PI2 (2 * PI)

// 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; \
#define vdist(d, v, e, s)                         \
	OFVector3D v = OFSubtractVectors3D(s, e); \
	vsub(v, e);       \
	float d = (float)sqrt(dotprod(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))
#define vlinterp(v, f, u, g)                   \
	{                                      \
		(v).x = (v).x * f + (u).x * g; \

Modified src/entities.m from [aa08365e90] to [27ea25a917].

290
291
292
293
294
295
296
297
298
299



300
301
302
303
304
305
306
290
291
292
293
294
295
296



297
298
299
300
301
302
303
304
305
306







-
-
-
+
+
+







	case JUMPPAD: {
		static int lastjumppad = 0;
		if (lastmillis - lastjumppad < 300)
			break;
		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;
	}
	}
}

void

Modified src/physics.m from [bf839677bd] to [498044e3ca].

288
289
290
291
292
293
294
295
296
297
298
299






300
301
302
303
304
305
306

307
308
309
310
311
312
313
288
289
290
291
292
293
294





295
296
297
298
299
300
301
302
303
304
305
306

307
308
309
310
311
312
313
314







-
-
-
-
-
+
+
+
+
+
+






-
+







	const float friction =
	    water ? 20.0f : (pl.onFloor || floating ? 6.0f : 30.0f);

	const float fpsfric = friction / curtime * 20.0f;

	// 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 =
			    OFMakeVector3D(pl.velocity.x, pl.velocity.y, 2);
		}
	} else {
		// apply velocity with collision

Modified src/renderparticles.m from [8491151e32] to [e9255a3806].

117
118
119
120
121
122
123
124

125
126
127


128
129
130
131
132
133
134
117
118
119
120
121
122
123

124



125
126
127
128
129
130
131
132
133







-
+
-
-
-
+
+







			*pp = p->next;
			p->next = parempty;
			parempty = p;
		} else {
			if (pt->gr)
				p->o.z -= ((lastmillis - p->millis) / 3.0f) *
				    curtime / (pt->gr * 10000);
			OFVector3D a = p->d;
			OFVector3D a = OFMultiplyVector3D(p->d, time);
			vmul(a, time);
			vdiv(a, 20000.0f);
			vadd(p->o, a);
			a = OFMultiplyVector3D(a, 1.0f / 20000.0f);
			p->o = OFAddVectors3D(p->o, a);
			pp = &p->next;
		}
	}

	glEnable(GL_FOG);
	glDisable(GL_BLEND);
	glDepthMask(GL_TRUE);
150
151
152
153
154
155
156
157

158
159
160

161
162
163
164
165
149
150
151
152
153
154
155

156
157
158

159
160
161
162
163
164







-
+


-
+





	}
}

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);
	}
}

Modified src/savegamedemo.m from [d2d1d77a28] to [3891d96448].

384
385
386
387
388
389
390
391
392
393
394





395
396
397
398
399
400
401
402






403
404
405
406
407
408
409
410
411
412







413
414
415
416
417
418
419
384
385
386
387
388
389
390




391
392
393
394
395








396
397
398
399
400
401










402
403
404
405
406
407
408
409
410
411
412
413
414
415







-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+







	setclient(democlientnum, [player1 copy]);
	readdemotime();
}

VAR(demodelaymsec, 0, 120, 500);

// spline interpolation
#define catmulrom(z, a, b, c, s, dest)           \
	{                                        \
		OFVector3D t1 = b, t2 = c;       \
                                                 \
#define catmulrom(z, a, b, c, s, dest)                                  \
	{                                                               \
		OFVector3D t1 = OFSubtractVectors3D(b, z);              \
		t1 = OFMultiplyVector3D(t1, 0.5f);                      \
                                                                        \
		vsub(t1, z);                     \
		vmul(t1, 0.5f);                  \
		vsub(t2, a);                     \
		vmul(t2, 0.5f);                  \
                                                 \
		float s2 = s * s;                \
		float s3 = s * s2;               \
                                                 \
		OFVector3D t2 = OFSubtractVectors3D(c, a);              \
		t2 = OFMultiplyVector3D(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);                  \
		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
fixwrap(DynamicEntity *a, DynamicEntity *b)
{
	while (b.yaw - a.yaw > 180)
		a.yaw += 360;

Modified src/weapon.m from [acb2ec57ac] to [da3cdeb33a].

73
74
75
76
77
78
79
80

81
82

83
84
85
86
87
88
89
90
91
92
93
94
95


96
97
98
99
100
101
102
103
104
105

106
107

108
109
110
111
112
113
114
73
74
75
76
77
78
79

80
81

82



83
84
85
86
87
88
89
90


91
92
93
94
95
96
97
98
99
100
101

102


103
104
105
106
107
108
109
110







-
+

-
+
-
-
-








-
-
+
+









-
+
-
-
+








// create random spread of rays for the shotgun
void
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] = OFAddVectors3D(*to, OFMakeVector3D(RNDD, RNDD, RNDD));
		sg[i] = *to;
		vadd(sg[i], r);
	}
}

// if lineseg hits entity bounding box
static bool
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)
		p = from;
	else {
		float c2 = dotprod(v, v);
		if (c2 <= c1)
			p = to;
		else {
			float f = c1 / c2;
			v = OFMultiplyVector3D(v, c1 / c2);
			vmul(v, f);
			vadd(v, *from);
			v = OFAddVectors3D(v, *from);
			p = &v;
		}
	}

	return (p->x <= d.origin.x + d.radius &&
	    p->x >= d.origin.x - d.radius && p->y <= d.origin.y + d.radius &&
	    p->y >= d.origin.y - d.radius && p->z <= d.origin.z + d.aboveEye &&
195
196
197
198
199
200
201

202
203


204
205
206
207
208
209
210
191
192
193
194
195
196
197
198


199
200
201
202
203
204
205
206
207







+
-
-
+
+







	vdist(dist, temp, *v, o.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 =
		vmul(temp, (RL_DAMRAD - dist) * damage / 800);
		vadd(o.velocity, temp);
		    OFMultiplyVector3D(temp, (RL_DAMRAD - dist) * damage / 800);
		o.velocity = OFAddVectors3D(o.velocity, temp);
	}
}

static void
splash(Projectile *p, const OFVector3D *v, const OFVector3D *vold,
    int notthisplayer, int notthismonster, int qdam)
{
269
270
271
272
273
274
275
276
277


278
279
280
281
282
283
284
266
267
268
269
270
271
272


273
274
275
276
277
278
279
280
281







-
-
+
+







		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);
		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])
					projdamage(player, p, &v, i, -1, qdam);

			if (p.owner != player1)
				projdamage(player1, p, &v, -1, -1, qdam);
350
351
352
353
354
355
356
357
358


359
360
361
362
363
364
365
347
348
349
350
351
352
353


354
355
356
357
358
359
360
361
362







-
-
+
+








void
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);
	vmul(v, damage / dist / 50);
	vadd(d.velocity, v);
	v = OFMultiplyVector3D(v, damage / dist / 50);
	d.velocity = OFAddVectors3D(d.velocity, v);
}

void
raydamage(DynamicEntity *o, const OFVector3D *from, const OFVector3D *to,
    DynamicEntity *d, int i)
{
	if (o.state != CS_ALIVE)
400
401
402
403
404
405
406
407
408
409
410




411
412
413
414
415

416
417

418
419
420
421
422
423
424
397
398
399
400
401
402
403




404
405
406
407
408
409
410
411

412


413
414
415
416
417
418
419
420







-
-
-
-
+
+
+
+




-
+
-
-
+







	if (d.gunSelect)
		d.ammo[d.gunSelect]--;
	OFVector3D from = d.origin;
	OFVector3D to = *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
		unitv = OFMultiplyVector3D(unitv, 3); // punch range
		to = from;
		vadd(to, unitv);
		to = OFAddVectors3D(from, unitv);
	}
	if (d.gunSelect == GUN_SG)
		createrays(&from, &to);

	if (d.quadMillis && attacktime > 200)
		playsoundc(S_ITEMPUP);
	shootv(d.gunSelect, &from, &to, d, true);