Cube  Check-in [6259424802]

Overview
Comment:Remove vdist
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 62594248024eb944735c20b4877f3e6ea07cd93e7f723e718986e86d3c43e944
User & Date: js on 2025-03-23 21:31:55
Other Links: manifest | tags
Context
2025-03-23
21:52
Avoid pointless pointers check-in: 304230c1e1 user: js tags: trunk
21:31
Remove vdist check-in: 6259424802 user: js tags: trunk
19:40
Clean up identifiers, use blocks for commands check-in: d7661be1b1 user: js tags: trunk
Changes

Modified src/Monster.m from [4c3ede25d7] to [f00a1d74b4].

267
268
269
270
271
272
273

274
275
276
277
278
279
280
281
			self.yaw = self.targetYaw;
	} else {
		self.yaw -= curtime * 0.5f;
		if (self.targetYaw > self.yaw)
			self.yaw = self.targetYaw;
	}


	vdist(disttoenemy, vectoenemy, self.origin, self.enemy.origin);
	self.pitch =
	    atan2(self.enemy.origin.z - self.origin.z, disttoenemy) * 180 / PI;

	// special case: if we run into scenery
	if (self.blocked) {
		self.blocked = false;
		// try to jump over obstackle (rare)







>
|







267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
			self.yaw = self.targetYaw;
	} else {
		self.yaw -= curtime * 0.5f;
		if (self.targetYaw > self.yaw)
			self.yaw = self.targetYaw;
	}

	float disttoenemy =
	    OFDistanceOfVectors3D(self.origin, self.enemy.origin);
	self.pitch =
	    atan2(self.enemy.origin.z - self.origin.z, disttoenemy) * 180 / PI;

	// special case: if we run into scenery
	if (self.blocked) {
		self.blocked = false;
		// try to jump over obstackle (rare)
465
466
467
468
469
470
471

472
473
474
475
476
477
478
479
			if (monster.state == CS_DEAD) {
				if (lastmillis - monster.lastAction < 2000) {
					monster.move = 0;
					moveplayer(monster, 1, false);
				}
			} else {
				v.z += monster.eyeHeight;

				vdist(dist, t, monster.origin, v);
				v.z -= monster.eyeHeight;

				if (dist < 4)
					teleport(i, monster);
			}
		}
	}];







>
|







466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
			if (monster.state == CS_DEAD) {
				if (lastmillis - monster.lastAction < 2000) {
					monster.move = 0;
					moveplayer(monster, 1, false);
				}
			} else {
				v.z += monster.eyeHeight;
				float dist =
				    OFDistanceOfVectors3D(monster.origin, v);
				v.z -= monster.eyeHeight;

				if (dist < 4)
					teleport(i, monster);
			}
		}
	}];

Modified src/cube.h from [6875cee25c] to [5dab6dec5b].

282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#define VIRTH 1800
#define FONTH 64
#define PIXELTAB (VIRTW / 12)

#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))
#define vlinterp(v, f, u, g)                   \
	{                                      \
		(v).x = (v).x * f + (u).x * g; \
		(v).y = (v).y * f + (u).y * g; \







<
<
<
<







282
283
284
285
286
287
288




289
290
291
292
293
294
295
#define VIRTH 1800
#define FONTH 64
#define PIXELTAB (VIRTW / 12)

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





#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; \
		(v).y = (v).y * f + (u).y * g; \

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

317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
			return;

		if (OUTBORD(e.x, e.y))
			return;

		OFVector3D v = OFMakeVector3D(
		    e.x, e.y, (float)S(e.x, e.y)->floor + player1.eyeHeight);
		vdist(dist, t, player1.origin, v);

		if (dist < (e.type == TELEPORT ? 4 : 2.5))
			pickup(i, player1);
	}];
}

void







|







317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
			return;

		if (OUTBORD(e.x, e.y))
			return;

		OFVector3D v = OFMakeVector3D(
		    e.x, e.y, (float)S(e.x, e.y)->floor + player1.eyeHeight);
		float dist = OFDistanceOfVectors3D(player1.origin, v);

		if (dist < (e.type == TELEPORT ? 4 : 2.5))
			pickup(i, player1);
	}];
}

void

Modified src/renderparticles.m from [e9255a3806] to [dcdd211b54].

148
149
150
151
152
153
154
155

156
157
158
159
160
161
162
		newparticle(p, &d, rnd(fade * 3), type);
	}
}

void
particle_trail(int type, int fade, const OFVector3D *s, const OFVector3D *e)
{
	vdist(d, v, *s, *e);

	v = OFMultiplyVector3D(v, 1.0f / (d * 2 + 0.1f));
	OFVector3D p = *s;
	for (int i = 0; i < ((int)d * 2); i++) {
		p = OFAddVectors3D(p, v);
		OFVector3D d =
		    OFMakeVector3D(rnd(11) - 5, rnd(11) - 5, rnd(11) - 5);
		newparticle(&p, &d, rnd(fade) + fade, type);







|
>







148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
		newparticle(p, &d, rnd(fade * 3), type);
	}
}

void
particle_trail(int type, int fade, const OFVector3D *s, const OFVector3D *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++) {
		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 [1beb03a02a] to [e40f20042f].

493
494
495
496
497
498
499

500
501
502
503
504
505
506
507
				// if(a==z || b==c)
				//	printf("* %d\n", lastmillis);
				float bf = (itime - a.lastUpdate) /
				    (float)(b.lastUpdate - a.lastUpdate);
				fixwrap(a, player1);
				fixwrap(c, player1);
				fixwrap(z, player1);

				vdist(dist, v, z.origin, c.origin);
				// if teleport or spawn, don't interpolate
				if (dist < 16) {
					catmulrom(z.origin, a.origin, b.origin,
					    c.origin, bf, player1.origin);
					OFVector3D vz = OFMakeVector3D(
					    z.yaw, z.pitch, z.roll);
					OFVector3D va = OFMakeVector3D(







>
|







493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
				// if(a==z || b==c)
				//	printf("* %d\n", lastmillis);
				float bf = (itime - a.lastUpdate) /
				    (float)(b.lastUpdate - a.lastUpdate);
				fixwrap(a, player1);
				fixwrap(c, player1);
				fixwrap(z, player1);
				float dist =
				    OFDistanceOfVectors3D(z.origin, c.origin);
				// if teleport or spawn, don't interpolate
				if (dist < 16) {
					catmulrom(z.origin, a.origin, b.origin,
					    c.origin, bf, player1.origin);
					OFVector3D vz = OFMakeVector3D(
					    z.yaw, z.pitch, z.roll);
					OFVector3D va = OFMakeVector3D(

Modified src/sound.m from [24cd809ba3] to [1d0c412a26].

107
108
109
110
111
112
113

114
115




116
117
118
119
120
121
122
123
124
125

126
127
128
129
130
131
132

VAR(stereo, 0, 1, 1);

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
		if (stereo && (v.x != 0 || v.y != 0)) {
			// relative angle of sound along X-Y axis
			float yaw =
			    -atan2(v.x, v.y) - player1.yaw * (PI / 180.0f);
			// range is from 0 (left) to 255 (right)
			pan = (int)(255.9f * (0.5 * sin(yaw) + 0.5f));
		}
	}

	vol = (vol * MAXVOL) / 255;
	Mix_Volume(chan, vol);
	Mix_SetPanning(chan, 255 - pan, pan);
}

static void
newsoundloc(int chan, const OFVector3D *loc)







>

|
>
>
>
>
|
|








>







107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138

VAR(stereo, 0, 1, 1);

static void
updatechanvol(int chan, const OFVector3D *loc)
{
	int vol = soundvol, pan = 255 / 2;

	if (loc) {
		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 =
			    -atan2(v.x, v.y) - player1.yaw * (PI / 180.0f);
			// range is from 0 (left) to 255 (right)
			pan = (int)(255.9f * (0.5 * sin(yaw) + 0.5f));
		}
	}

	vol = (vol * MAXVOL) / 255;
	Mix_Volume(chan, vol);
	Mix_SetPanning(chan, 255 - pan, pan);
}

static void
newsoundloc(int chan, const OFVector3D *loc)

Modified src/weapon.m from [a4ab4f9d09] to [51629f2c3a].

69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
	    (a3.length > 0 ? a3.cube_intValue : -1));
})

// 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++)
#define RNDD (rnd(101) - 50) * f
		sg[i] = OFAddVectors3D(*to, OFMakeVector3D(RNDD, RNDD, RNDD));
}

// if lineseg hits entity bounding box







|







69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
	    (a3.length > 0 ? a3.cube_intValue : -1));
})

// create random spread of rays for the shotgun
void
createrays(const OFVector3D *from, const OFVector3D *to)
{
	float dist = OFDistanceOfVectors3D(*from, *to);
	float f = dist * SGSPREAD / 1000;
	for (int i = 0; i < SGRAYS; i++)
#define RNDD (rnd(101) - 50) * f
		sg[i] = OFAddVectors3D(*to, OFMakeVector3D(RNDD, RNDD, RNDD));
}

// if lineseg hits entity bounding box
182
183
184
185
186
187
188
189



190

191
192
193

194
195

196
197
198
199
200
201
202

static void
radialeffect(
    DynamicEntity *o, const OFVector3D *v, int cn, int qdam, DynamicEntity *at)
{
	if (o.state != CS_ALIVE)
		return;
	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 =
		    OFMultiplyVector3D(temp, (RL_DAMRAD - dist) * damage / 800);
		o.velocity = OFAddVectors3D(o.velocity, temp);
	}
}

static void







|
>
>
>

>



>


>







182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208

static void
radialeffect(
    DynamicEntity *o, const OFVector3D *v, int cn, int qdam, DynamicEntity *at)
{
	if (o.state != CS_ALIVE)
		return;

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

static void
260
261
262
263
264
265
266
267


268
269
270
271
272
273
274

		if (!p.inuse)
			continue;

		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;
		v = OFMultiplyVector3D(v, time / dtime);
		v = OFAddVectors3D(v, p.o);
		if (p.local) {
			for (id player in players)







|
>
>







266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282

		if (!p.inuse)
			continue;

		int qdam = guns[p.gun].damage * (p.owner.quadMillis ? 4 : 1);
		if ([p.owner isKindOfClass:Monster.class])
			qdam /= MONSTERDAMAGEFACTOR;
		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;
		v = OFMultiplyVector3D(v, time / dtime);
		v = OFAddVectors3D(v, p.o);
		if (p.local) {
			for (id player in players)
344
345
346
347
348
349
350
351

352
353
354
355
356
357
358
}

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

	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)







|
>







352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
}

void
hitpush(int target, int damage, DynamicEntity *d, DynamicEntity *at,
    const OFVector3D *from, const OFVector3D *to)
{
	hit(target, damage, d, at);
	float dist = OFDistanceOfVectors3D(*from, *to);
	OFVector3D v = OFSubtractVectors3D(*from, *to);
	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)
394
395
396
397
398
399
400

401
402
403
404
405
406
407
408
	}
	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);
	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;








>
|







403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
	}
	if (d.gunSelect)
		d.ammo[d.gunSelect]--;
	OFVector3D from = d.origin;
	OFVector3D to = *targ;
	from.z -= 0.2f; // below eye

	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);
	d.velocity = OFAddVectors3D(d.velocity, kickback);
	if (d.pitch < 80.0f)
		d.pitch += guns[d.gunSelect].kickamount * 0.05f;

Modified src/world.m from [e48df32f18] to [892a60074f].

294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
	__block int best;
	__block float bdist = 99999;
	[ents enumerateObjectsUsingBlock:^(Entity *e, size_t i, bool *stop) {
		if (e.type == NOTUSED)
			return;

		OFVector3D v = OFMakeVector3D(e.x, e.y, e.z);
		vdist(dist, t, player1.origin, v);
		if (dist < bdist) {
			best = i;
			bdist = dist;
		}
	}];

	return (bdist == 99999 ? -1 : best);







|







294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
	__block int best;
	__block float bdist = 99999;
	[ents enumerateObjectsUsingBlock:^(Entity *e, size_t i, bool *stop) {
		if (e.type == NOTUSED)
			return;

		OFVector3D v = OFMakeVector3D(e.x, e.y, e.z);
		float dist = OFDistanceOfVectors3D(player1.origin, v);
		if (dist < bdist) {
			best = i;
			bdist = dist;
		}
	}];

	return (bdist == 99999 ? -1 : best);