Cube  Check-in [6b85eefc85]

Overview
Comment:Remove loop[ijkl]

They confused clang-format a lot.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 6b85eefc857c74c00d7ef693e312cc15df53201a6712aee8ba8d57c643c1703b
User & Date: js on 2025-03-23 02:47:40
Other Links: manifest | tags
Context
2025-03-23
02:59
Remove u{char,short,int} check-in: b5bfe2af86 user: js tags: trunk
02:47
Remove loop[ijkl] check-in: 6b85eefc85 user: js tags: trunk
02:03
Convert monster into a class check-in: e8f80b0482 user: js tags: trunk
Changes

Modified src/MD2.m from [92d0f266d8] to [1b5856edcb].

123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151

152
153
154
155
156
157
158
159
160
161
{
	OFAssert(_mverts[frame] == NULL);

	_mverts[frame] = OFAllocMemory(_numVerts, sizeof(OFVector3D));
	struct md2_frame *cf =
	    (struct md2_frame *)((char *)_frames + _frameSize * frame);
	float sc = 16.0f / scale;
	loop(vi, _numVerts)
	{
		uchar *cv = (uchar *)&cf->vertices[vi].vertex;
		OFVector3D *v = &(_mverts[frame])[vi];
		v->x = (snap(sn, cv[0] * cf->scale[0]) + cf->translate[0]) / sc;
		v->y =
		    -(snap(sn, cv[1] * cf->scale[1]) + cf->translate[1]) / sc;
		v->z = (snap(sn, cv[2] * cf->scale[2]) + cf->translate[2]) / sc;
	}
}

- (void)renderWithLight:(OFColor *)light
                  frame:(int)frame
                  range:(int)range
               position:(OFVector3D)position
                    yaw:(float)yaw
                  pitch:(float)pitch
                  scale:(float)sc
                  speed:(float)speed
                   snap:(int)sn
               basetime:(int)basetime
{

	loopi(range) if (!_mverts[frame + i])[self scaleWithFrame:frame + i
	                                                    scale:sc
	                                                     snap:sn];

	glPushMatrix();
	glTranslatef(position.x, position.y, position.z);
	glRotatef(yaw + 180, 0, -1, 0);
	glRotatef(pitch, 0, 0, 1);

	float red, green, blue;







|
<




















>
|
<
|







123
124
125
126
127
128
129
130

131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152

153
154
155
156
157
158
159
160
{
	OFAssert(_mverts[frame] == NULL);

	_mverts[frame] = OFAllocMemory(_numVerts, sizeof(OFVector3D));
	struct md2_frame *cf =
	    (struct md2_frame *)((char *)_frames + _frameSize * frame);
	float sc = 16.0f / scale;
	for (int vi = 0; vi < _numVerts; vi++) {

		uchar *cv = (uchar *)&cf->vertices[vi].vertex;
		OFVector3D *v = &(_mverts[frame])[vi];
		v->x = (snap(sn, cv[0] * cf->scale[0]) + cf->translate[0]) / sc;
		v->y =
		    -(snap(sn, cv[1] * cf->scale[1]) + cf->translate[1]) / sc;
		v->z = (snap(sn, cv[2] * cf->scale[2]) + cf->translate[2]) / sc;
	}
}

- (void)renderWithLight:(OFColor *)light
                  frame:(int)frame
                  range:(int)range
               position:(OFVector3D)position
                    yaw:(float)yaw
                  pitch:(float)pitch
                  scale:(float)sc
                  speed:(float)speed
                   snap:(int)sn
               basetime:(int)basetime
{
	for (int i = 0; i < range; i++)
		if (!_mverts[frame + i])

			[self scaleWithFrame:frame + i scale:sc snap:sn];

	glPushMatrix();
	glTranslatef(position.x, position.y, position.z);
	glRotatef(yaw + 180, 0, -1, 0);
	glRotatef(pitch, 0, 0, 1);

	float red, green, blue;
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
			if (numVertex > 0) {
				glBegin(GL_TRIANGLE_STRIP);
			} else {
				glBegin(GL_TRIANGLE_FAN);
				numVertex = -numVertex;
			}

			loopi(numVertex)
			{
				float tu = *((float *)command++);
				float tv = *((float *)command++);
				glTexCoord2f(tu, tv);
				int vn = *command++;
#define ip(c) verts1[vn].c *frac2 + verts2[vn].c *frac1
				glVertex3f(ip(x), ip(z), ip(y));
			}







|
<







187
188
189
190
191
192
193
194

195
196
197
198
199
200
201
			if (numVertex > 0) {
				glBegin(GL_TRIANGLE_STRIP);
			} else {
				glBegin(GL_TRIANGLE_FAN);
				numVertex = -numVertex;
			}

			for (int i = 0; i < numVertex; i++) {

				float tu = *((float *)command++);
				float tv = *((float *)command++);
				glTexCoord2f(tu, tv);
				int vn = *command++;
#define ip(c) verts1[vn].c *frac2 + verts2[vn].c *frac1
				glVertex3f(ip(x), ip(z), ip(y));
			}

Modified src/clientgame.m from [d0a68a37a3] to [e2809031d4].

194
195
196
197
198
199
200
201
202

203
204
205
206
207
208
209
	lastmillis = millis;
}

// brute force but effective way to find a free spawn spot in the map
void
entinmap(DynamicEntity *d)
{
	loopi(100) // try max 100 times
	{

		float dx = (rnd(21) - 10) / 10.0f * i; // increasing distance
		float dy = (rnd(21) - 10) / 10.0f * i;
		OFVector3D old = d.origin;
		d.origin = OFAddVector3D(d.origin, OFMakeVector3D(dx, dy, 0));
		if (collide(d, true, 0, 0))
			return;
		d.origin = old;







|
<
>







194
195
196
197
198
199
200
201

202
203
204
205
206
207
208
209
	lastmillis = millis;
}

// brute force but effective way to find a free spawn spot in the map
void
entinmap(DynamicEntity *d)
{
	// try max 100 times

	for (int i = 0; i < 100; i++) {
		float dx = (rnd(21) - 10) / 10.0f * i; // increasing distance
		float dy = (rnd(21) - 10) / 10.0f * i;
		OFVector3D old = d.origin;
		d.origin = OFAddVector3D(d.origin, OFMakeVector3D(dx, dy, 0));
		if (collide(d, true, 0, 0))
			return;
		d.origin = old;
217
218
219
220
221
222
223

224
225
226
227
228
229
230
231
int fixspawn = 2;

// place at random spawn. also used by monsters!
void
spawnplayer(DynamicEntity *d)
{
	int r = fixspawn-- > 0 ? 4 : rnd(10) + 1;

	loopi(r) spawncycle = findentity(PLAYERSTART, spawncycle + 1);
	if (spawncycle != -1) {
		d.origin = OFMakeVector3D(
		    ents[spawncycle].x, ents[spawncycle].y, ents[spawncycle].z);
		d.yaw = ents[spawncycle].attr1;
		d.pitch = 0;
		d.roll = 0;
	} else







>
|







217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
int fixspawn = 2;

// place at random spawn. also used by monsters!
void
spawnplayer(DynamicEntity *d)
{
	int r = fixspawn-- > 0 ? 4 : rnd(10) + 1;
	for (int i = 0; i < r; i++)
		spawncycle = findentity(PLAYERSTART, spawncycle + 1);
	if (spawncycle != -1) {
		d.origin = OFMakeVector3D(
		    ents[spawncycle].x, ents[spawncycle].y, ents[spawncycle].z);
		d.yaw = ents[spawncycle].attr1;
		d.pitch = 0;
		d.roll = 0;
	} else

Modified src/clients.m from [90d8557e37] to [e57ccf0fe6].

209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
	                                            capacity:num + 2];
	[msg addItem:&num];
	[msg addItem:&rel];
	[msg addItem:&type];

	va_list marker;
	va_start(marker, type);
	loopi(num - 1)
	{
		int tmp = va_arg(marker, int);
		[msg addItem:&tmp];
	}
	va_end(marker);
	[msg makeImmutable];

	if (messages == nil)







|
<







209
210
211
212
213
214
215
216

217
218
219
220
221
222
223
	                                            capacity:num + 2];
	[msg addItem:&num];
	[msg addItem:&rel];
	[msg addItem:&type];

	va_list marker;
	va_start(marker, type);
	for (int i = 0; i < num - 1; i++) {

		int tmp = va_arg(marker, int);
		[msg addItem:&tmp];
	}
	va_end(marker);
	[msg makeImmutable];

	if (messages == nil)
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
			sendstring(player1.team, &p);
			putint(&p, player1.lifeSequence);
		}
		for (OFData *msg in messages) {
			// send messages collected during the previous frames
			if (*(int *)[msg itemAtIndex:1])
				packet->flags = ENET_PACKET_FLAG_RELIABLE;
			loopi(*(int *)[msg itemAtIndex:0])
			    putint(&p, *(int *)[msg itemAtIndex:i + 2]);
		}
		[messages removeAllObjects];
		if (lastmillis - lastping > 250) {
			putint(&p, SV_PING);
			putint(&p, lastmillis);
			lastping = lastmillis;
		}







|
|







340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
			sendstring(player1.team, &p);
			putint(&p, player1.lifeSequence);
		}
		for (OFData *msg in messages) {
			// send messages collected during the previous frames
			if (*(int *)[msg itemAtIndex:1])
				packet->flags = ENET_PACKET_FLAG_RELIABLE;
			for (int i = 0; i < *(int *)[msg itemAtIndex:0]; i++)
				putint(&p, *(int *)[msg itemAtIndex:i + 2]);
		}
		[messages removeAllObjects];
		if (lastmillis - lastping > 250) {
			putint(&p, SV_PING);
			putint(&p, lastmillis);
			lastping = lastmillis;
		}

Modified src/commands.m from [5ae3539b0c] to [4117ae0f6a].

236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
	char *p = copy;
	const int MAXWORDS = 25; // limit, remove
	OFString *w[MAXWORDS];
	int val = 0;
	for (bool cont = true; cont;) {
		// for each ; seperated statement
		int numargs = MAXWORDS;
		loopi(MAXWORDS)
		{
			// collect all argument values
			w[i] = @"";
			if (i > numargs)
				continue;
			// parse and evaluate exps
			char *s = parseword(&p);
			if (!s) {







|
<







236
237
238
239
240
241
242
243

244
245
246
247
248
249
250
	char *p = copy;
	const int MAXWORDS = 25; // limit, remove
	OFString *w[MAXWORDS];
	int val = 0;
	for (bool cont = true; cont;) {
		// for each ; seperated statement
		int numargs = MAXWORDS;
		for (int i = 0; i < MAXWORDS; i++) {

			// collect all argument values
			w[i] = @"";
			if (i > numargs)
				continue;
			// parse and evaluate exps
			char *s = parseword(&p);
			if (!s) {
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
}

void
loopa(OFString *times, OFString *body)
{
	int t = times.cube_intValue;

	loopi(t)
	{
		intset(@"i", i);
		execute(body, true);
	}
}

void
whilea(OFString *cond, OFString *body)







|
<







416
417
418
419
420
421
422
423

424
425
426
427
428
429
430
}

void
loopa(OFString *times, OFString *body)
{
	int t = times.cube_intValue;

	for (int i = 0; i < t; i++) {

		intset(@"i", i);
		execute(body, true);
	}
}

void
whilea(OFString *cond, OFString *body)
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
void
at(OFString *s_, OFString *pos)
{
	int n = pos.cube_intValue;
	char *copy __attribute__((__cleanup__(cleanup))) =
	    strdup(s_.UTF8String);
	char *s = copy;
	loopi(n)
	{
		s += strcspn(s, " \0");
		s += strspn(s, " ");
	}
	s[strcspn(s, " \0")] = 0;
	concat(@(s));
}








|
<







471
472
473
474
475
476
477
478

479
480
481
482
483
484
485
void
at(OFString *s_, OFString *pos)
{
	int n = pos.cube_intValue;
	char *copy __attribute__((__cleanup__(cleanup))) =
	    strdup(s_.UTF8String);
	char *s = copy;
	for (int i = 0; i < n; i++) {

		s += strcspn(s, " \0");
		s += strspn(s, " ");
	}
	s[strcspn(s, " \0")] = 0;
	concat(@(s));
}

Modified src/console.m from [2703ba3edf] to [1ac50365c9].

91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
			if (nd == ndraw)
				break;
		}

		i++;
	}

	loopj(nd)
	{
		draw_text(refs[j], FONTH / 3,
		    (FONTH / 4 * 5) * (nd - j - 1) + FONTH / 3, 2);
	}
}

// keymap is defined externally in keymap.cfg

static OFMutableArray<KeyMapping *> *keyMappings = nil;

void







|
<


<







91
92
93
94
95
96
97
98

99
100

101
102
103
104
105
106
107
			if (nd == ndraw)
				break;
		}

		i++;
	}

	for (int j = 0; j < nd; j++)

		draw_text(refs[j], FONTH / 3,
		    (FONTH / 4 * 5) * (nd - j - 1) + FONTH / 3, 2);

}

// keymap is defined externally in keymap.cfg

static OFMutableArray<KeyMapping *> *keyMappings = nil;

void

Modified src/editing.m from [85210314d4] to [f776852317].

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

41
42
43
44
45
46
47
48
		};
	});
}

int selh = 0;
bool selset = false;

#define loopselxy(b)                                               \
	{                                                          \
		makeundo();                                        \
		loop(x, sel->xs) loop(y, sel->ys)                  \
		{                                                  \
			struct sqr *s = S(sel->x + x, sel->y + y); \
			b;                                         \
		}                                                  \

		remip(sel, 0);                                     \
	}

int cx, cy, ch;

int curedittex[] = { -1, -1, -1 };

bool dragging = false;







|
|
|
|
|
|
|
|
>
|







26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
		};
	});
}

int selh = 0;
bool selset = false;

#define loopselxy(b)                                                       \
	{                                                                  \
		makeundo();                                                \
		for (int x = 0; x < sel->xs; x++) {                        \
			for (int y = 0; y < sel->ys; y++) {                \
				struct sqr *s = S(sel->x + x, sel->y + y); \
				b;                                         \
			}                                                  \
		}                                                          \
		remip(sel, 0);                                             \
	}

int cx, cy, ch;

int curedittex[] = { -1, -1, -1 };

bool dragging = false;
287
288
289
290
291
292
293

294
295

296
297
298
299
300
301
302

static struct block *copybuf = NULL;

void
copy()
{
	EDITSELMP;

	if (copybuf)
		OFFreeMemory(copybuf);

	copybuf = blockcopy(&sel);
}

void
paste()
{
	EDITMP;







>


>







288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305

static struct block *copybuf = NULL;

void
copy()
{
	EDITSELMP;

	if (copybuf)
		OFFreeMemory(copybuf);

	copybuf = blockcopy(&sel);
}

void
paste()
{
	EDITMP;
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
	blockpaste(copybuf);
}

void
tofronttex() // maintain most recently used of the texture lists when applying
             // texture
{
	loopi(3)
	{
		int c = curedittex[i];
		if (c >= 0) {
			uchar *p = hdr.texlists[i];
			int t = p[c];
			for (int a = c - 1; a >= 0; a--)
				p[a + 1] = p[a];
			p[0] = t;







|
<







320
321
322
323
324
325
326
327

328
329
330
331
332
333
334
	blockpaste(copybuf);
}

void
tofronttex() // maintain most recently used of the texture lists when applying
             // texture
{
	for (int i = 0; i < 3; i++) {

		int c = curedittex[i];
		if (c >= 0) {
			uchar *p = hdr.texlists[i];
			int t = p[c];
			for (int a = c - 1; a >= 0; a--)
				p[a + 1] = p[a];
			p[0] = t;
367
368
369
370
371
372
373

374
375
376
377
378
379
380
	    });
}

void
editheight(int flr, int amount)
{
	EDITSEL;

	bool isfloor = flr == 0;
	editheightxy(isfloor, amount, &sel);
	addmsg(1, 7, SV_EDITH, sel.x, sel.y, sel.xs, sel.ys, isfloor, amount);
}
COMMAND(editheight, ARG_2INT)

void







>







369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
	    });
}

void
editheight(int flr, int amount)
{
	EDITSEL;

	bool isfloor = flr == 0;
	editheightxy(isfloor, amount, &sel);
	addmsg(1, 7, SV_EDITH, sel.x, sel.y, sel.xs, sel.ys, isfloor, amount);
}
COMMAND(editheight, ARG_2INT)

void
396
397
398
399
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
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443


444
445
446
447
448
449
450
451
452
453
454
455
456
457

458
459
460
461
462
463

464
465
466
467
468
469
470
	});
}

void
edittex(int type, int dir)
{
	EDITSEL;

	if (type < 0 || type > 3)
		return;

	if (type != lasttype) {
		tofronttex();
		lasttype = type;
	}

	int atype = type == 3 ? 1 : type;
	int i = curedittex[atype];
	i = i < 0 ? 0 : i + dir;
	curedittex[atype] = i = min(max(i, 0), 255);
	int t = lasttex = hdr.texlists[atype][i];
	edittexxy(type, t, &sel);
	addmsg(1, 7, SV_EDITT, sel.x, sel.y, sel.xs, sel.ys, type, t);
}

void
replace()
{
	EDITSELMP;
	loop(x, ssize) loop(y, ssize)
	{


		struct sqr *s = S(x, y);
		switch (lasttype) {
		case 0:
			if (s->ftex == rtex.ftex)
				s->ftex = lasttex;
			break;
		case 1:
			if (s->wtex == rtex.wtex)
				s->wtex = lasttex;
			break;
		case 2:
			if (s->ctex == rtex.ctex)
				s->ctex = lasttex;
			break;
		case 3:
			if (s->utex == rtex.utex)
				s->utex = lasttex;
			break;
		}
	}


	struct block b = { 0, 0, ssize, ssize };
	remip(&b, 0);
}

void
edittypexy(int type, const struct block *sel)
{
	loopselxy(s->type = type);
}

void
edittype(int type)
{
	EDITSEL;

	if (type == CORNER &&
	    (sel.xs != sel.ys || sel.xs == 3 || (sel.xs > 4 && sel.xs != 8) ||
	        sel.x & ~-sel.xs || sel.y & ~-sel.ys)) {
		conoutf(@"corner selection must be power of 2 aligned");
		return;
	}

	edittypexy(type, &sel);
	addmsg(1, 6, SV_EDITS, sel.x, sel.y, sel.xs, sel.ys, type);
}

void
heightfield(int t)
{







>


>




>













<
|
>
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>














>






>







399
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
425
426
427

428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
	});
}

void
edittex(int type, int dir)
{
	EDITSEL;

	if (type < 0 || type > 3)
		return;

	if (type != lasttype) {
		tofronttex();
		lasttype = type;
	}

	int atype = type == 3 ? 1 : type;
	int i = curedittex[atype];
	i = i < 0 ? 0 : i + dir;
	curedittex[atype] = i = min(max(i, 0), 255);
	int t = lasttex = hdr.texlists[atype][i];
	edittexxy(type, t, &sel);
	addmsg(1, 7, SV_EDITT, sel.x, sel.y, sel.xs, sel.ys, type, t);
}

void
replace()
{
	EDITSELMP;


	for (int x = 0; x < ssize; x++) {
		for (int y = 0; y < ssize; y++) {
			struct sqr *s = S(x, y);
			switch (lasttype) {
			case 0:
				if (s->ftex == rtex.ftex)
					s->ftex = lasttex;
				break;
			case 1:
				if (s->wtex == rtex.wtex)
					s->wtex = lasttex;
				break;
			case 2:
				if (s->ctex == rtex.ctex)
					s->ctex = lasttex;
				break;
			case 3:
				if (s->utex == rtex.utex)
					s->utex = lasttex;
				break;
			}
		}
	}

	struct block b = { 0, 0, ssize, ssize };
	remip(&b, 0);
}

void
edittypexy(int type, const struct block *sel)
{
	loopselxy(s->type = type);
}

void
edittype(int type)
{
	EDITSEL;

	if (type == CORNER &&
	    (sel.xs != sel.ys || sel.xs == 3 || (sel.xs > 4 && sel.xs != 8) ||
	        sel.x & ~-sel.xs || sel.y & ~-sel.ys)) {
		conoutf(@"corner selection must be power of 2 aligned");
		return;
	}

	edittypexy(type, &sel);
	addmsg(1, 6, SV_EDITS, sel.x, sel.y, sel.xs, sel.ys, type);
}

void
heightfield(int t)
{
505
506
507
508
509
510
511
512

513

514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529

530
531
532
533
534
535
536
537
538
539
540
541
542


543
544
545
546
547
548
549
550
551
552
553

554
555

556
557
558
559

560
561
562
563
564
565
566
567
568
569
570
571
572
573
574

575
576
577
578
579

580
581

582
583
584
585
586
587
588
589
590
591
592

593
594

595

596
597

598

599
600

601

602
603
604
605
606
607
608
609

610
611
612
613
614
615
616

617
618
619
620
621
622
623
624
625
626

627
628
629
630
631
632
633
			s->floor = s->ceil - 1;
	});
}

void
equalize(int flr)
{
	bool isfloor = flr == 0;

	EDITSEL;

	editequalisexy(isfloor, &sel);
	addmsg(1, 6, SV_EDITE, sel.x, sel.y, sel.xs, sel.ys, isfloor);
}
COMMAND(equalize, ARG_1INT)

void
setvdeltaxy(int delta, const struct block *sel)
{
	loopselxy(s->vdelta = max(s->vdelta + delta, 0));
	remipmore(sel, 0);
}

void
setvdelta(int delta)
{
	EDITSEL;

	setvdeltaxy(delta, &sel);
	addmsg(1, 6, SV_EDITD, sel.x, sel.y, sel.xs, sel.ys, delta);
}

#define MAXARCHVERT 50
int archverts[MAXARCHVERT][MAXARCHVERT];
bool archvinit = false;

void
archvertex(int span, int vert, int delta)
{
	if (!archvinit) {
		archvinit = true;


		loop(s, MAXARCHVERT) loop(v, MAXARCHVERT) archverts[s][v] = 0;
	}
	if (span >= MAXARCHVERT || vert >= MAXARCHVERT || span < 0 || vert < 0)
		return;
	archverts[span][vert] = delta;
}

void
arch(int sidedelta, int _a)
{
	EDITSELMP;

	sel.xs++;
	sel.ys++;

	if (sel.xs > MAXARCHVERT)
		sel.xs = MAXARCHVERT;
	if (sel.ys > MAXARCHVERT)
		sel.ys = MAXARCHVERT;

	struct block *sel_ = &sel;
	// Ugly hack to make the macro work.
	struct block *sel = sel_;
	loopselxy(s->vdelta = sel->xs > sel->ys
	        ? (archverts[sel->xs - 1][x] +
	              (y == 0 || y == sel->ys - 1 ? sidedelta : 0))
	        : (archverts[sel->ys - 1][y] +
	              (x == 0 || x == sel->xs - 1 ? sidedelta : 0)));
	remipmore(sel, 0);
}

void
slope(int xd, int yd)
{
	EDITSELMP;

	int off = 0;
	if (xd < 0)
		off -= xd * sel.xs;
	if (yd < 0)
		off -= yd * sel.ys;

	sel.xs++;
	sel.ys++;

	struct block *sel_ = &sel;
	// Ugly hack to make the macro work.
	struct block *sel = sel_;
	loopselxy(s->vdelta = xd * x + yd * y + off);
	remipmore(sel, 0);
}

void
perlin(int scale, int seed, int psize)
{
	EDITSELMP;

	sel.xs++;
	sel.ys++;

	makeundo();

	sel.xs--;
	sel.ys--;

	perlinarea(&sel, scale, seed, psize);

	sel.xs++;
	sel.ys++;

	remipmore(&sel, 0);

	sel.xs--;
	sel.ys--;
}

VARF(
    fullbright, 0, 0, 1, if (fullbright) {
	    if (noteditmode())
		    return;

	    loopi(mipsize) world[i].r = world[i].g = world[i].b = 176;
    });

void
edittag(int tag)
{
	EDITSELMP;

	struct block *sel_ = &sel;
	// Ugly hack to make the macro work.
	struct block *sel = sel_;
	loopselxy(s->tag = tag);
}

void
newent(OFString *what, OFString *a1, OFString *a2, OFString *a3, OFString *a4)
{
	EDITSEL;

	newentity(sel.x, sel.y, (int)player1.origin.z, what,
	    [a1 cube_intValueWithBase:0], [a2 cube_intValueWithBase:0],
	    [a3 cube_intValueWithBase:0], [a4 cube_intValueWithBase:0]);
}

COMMANDN(select, selectpos, ARG_4INT)
COMMAND(edittag, ARG_1INT)







|
>

>
















>













>
>
|










>


>




>















>





>


>











>


>

>


>

>


>

>








>
|






>










>







516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
			s->floor = s->ceil - 1;
	});
}

void
equalize(int flr)
{
	bool isfloor = (flr == 0);

	EDITSEL;

	editequalisexy(isfloor, &sel);
	addmsg(1, 6, SV_EDITE, sel.x, sel.y, sel.xs, sel.ys, isfloor);
}
COMMAND(equalize, ARG_1INT)

void
setvdeltaxy(int delta, const struct block *sel)
{
	loopselxy(s->vdelta = max(s->vdelta + delta, 0));
	remipmore(sel, 0);
}

void
setvdelta(int delta)
{
	EDITSEL;

	setvdeltaxy(delta, &sel);
	addmsg(1, 6, SV_EDITD, sel.x, sel.y, sel.xs, sel.ys, delta);
}

#define MAXARCHVERT 50
int archverts[MAXARCHVERT][MAXARCHVERT];
bool archvinit = false;

void
archvertex(int span, int vert, int delta)
{
	if (!archvinit) {
		archvinit = true;
		for (int s = 0; s < MAXARCHVERT; s++)
			for (int v = 0; v < MAXARCHVERT; v++)
				archverts[s][v] = 0;
	}
	if (span >= MAXARCHVERT || vert >= MAXARCHVERT || span < 0 || vert < 0)
		return;
	archverts[span][vert] = delta;
}

void
arch(int sidedelta, int _a)
{
	EDITSELMP;

	sel.xs++;
	sel.ys++;

	if (sel.xs > MAXARCHVERT)
		sel.xs = MAXARCHVERT;
	if (sel.ys > MAXARCHVERT)
		sel.ys = MAXARCHVERT;

	struct block *sel_ = &sel;
	// Ugly hack to make the macro work.
	struct block *sel = sel_;
	loopselxy(s->vdelta = sel->xs > sel->ys
	        ? (archverts[sel->xs - 1][x] +
	              (y == 0 || y == sel->ys - 1 ? sidedelta : 0))
	        : (archverts[sel->ys - 1][y] +
	              (x == 0 || x == sel->xs - 1 ? sidedelta : 0)));
	remipmore(sel, 0);
}

void
slope(int xd, int yd)
{
	EDITSELMP;

	int off = 0;
	if (xd < 0)
		off -= xd * sel.xs;
	if (yd < 0)
		off -= yd * sel.ys;

	sel.xs++;
	sel.ys++;

	struct block *sel_ = &sel;
	// Ugly hack to make the macro work.
	struct block *sel = sel_;
	loopselxy(s->vdelta = xd * x + yd * y + off);
	remipmore(sel, 0);
}

void
perlin(int scale, int seed, int psize)
{
	EDITSELMP;

	sel.xs++;
	sel.ys++;

	makeundo();

	sel.xs--;
	sel.ys--;

	perlinarea(&sel, scale, seed, psize);

	sel.xs++;
	sel.ys++;

	remipmore(&sel, 0);

	sel.xs--;
	sel.ys--;
}

VARF(
    fullbright, 0, 0, 1, if (fullbright) {
	    if (noteditmode())
		    return;
	    for (int i = 0; i < mipsize; i++)
		    world[i].r = world[i].g = world[i].b = 176;
    });

void
edittag(int tag)
{
	EDITSELMP;

	struct block *sel_ = &sel;
	// Ugly hack to make the macro work.
	struct block *sel = sel_;
	loopselxy(s->tag = tag);
}

void
newent(OFString *what, OFString *a1, OFString *a2, OFString *a3, OFString *a4)
{
	EDITSEL;

	newentity(sel.x, sel.y, (int)player1.origin.z, what,
	    [a1 cube_intValueWithBase:0], [a2 cube_intValueWithBase:0],
	    [a3 cube_intValueWithBase:0], [a4 cube_intValueWithBase:0]);
}

COMMANDN(select, selectpos, ARG_4INT)
COMMAND(edittag, ARG_1INT)

Modified src/menus.m from [9e1b20764c] to [9134766c32].

57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
	OFString *title;
	if (vmenu > 1)
		title = [OFString stringWithFormat:@"[ %@ menu ]", m.name];
	else
		title = m.name;
	int mdisp = m.items.count;
	int w = 0;
	loopi(mdisp)
	{
		int x = text_width(m.items[i].text);
		if (x > w)
			w = x;
	}
	int tw = text_width(title);
	if (tw > w)
		w = tw;
	int step = FONTH / 4 * 5;
	int h = (mdisp + 2) * step;
	int y = (VIRTH - h) / 2;
	int x = (VIRTW - w) / 2;
	blendbox(x - FONTH / 2 * 3, y - FONTH, x + w + FONTH / 2 * 3,
	    y + h + FONTH, true);
	draw_text(title, x, y, 2);
	y += FONTH * 2;
	if (vmenu) {
		int bh = y + m.menusel * step;
		blendbox(
		    x - FONTH, bh - 10, x + w + FONTH, bh + FONTH + 10, false);
	}
	loopj(mdisp)
	{
		draw_text(m.items[j].text, x, y, 2);
		y += step;
	}
	return true;
}

void







|
<




















|
<







57
58
59
60
61
62
63
64

65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85

86
87
88
89
90
91
92
	OFString *title;
	if (vmenu > 1)
		title = [OFString stringWithFormat:@"[ %@ menu ]", m.name];
	else
		title = m.name;
	int mdisp = m.items.count;
	int w = 0;
	for (int i = 0; i < mdisp; i++) {

		int x = text_width(m.items[i].text);
		if (x > w)
			w = x;
	}
	int tw = text_width(title);
	if (tw > w)
		w = tw;
	int step = FONTH / 4 * 5;
	int h = (mdisp + 2) * step;
	int y = (VIRTH - h) / 2;
	int x = (VIRTW - w) / 2;
	blendbox(x - FONTH / 2 * 3, y - FONTH, x + w + FONTH / 2 * 3,
	    y + h + FONTH, true);
	draw_text(title, x, y, 2);
	y += FONTH * 2;
	if (vmenu) {
		int bh = y + m.menusel * step;
		blendbox(
		    x - FONTH, bh - 10, x + w + FONTH, bh + FONTH + 10, false);
	}
	for (int j = 0; j < mdisp; j++) {

		draw_text(m.items[j].text, x, y, 2);
		y += step;
	}
	return true;
}

void

Modified src/physics.m from [6e6b41ef3d] to [0149f2d0e3].

354
355
356
357
358
359
360
361
362

363
364
365
366
367
368
369
			pl.timeInAir = 0;
		}
		// at high fps, gravity kicks in too fast
		const float drop = dropf * curtime / gravity / 100 / moveres;
		// extra smoothness when lifting up stairs
		const float rise = speed / moveres / 1.2f;

		loopi(moveres) // discrete steps collision detection & sliding
		{

			// try move forward
			pl.origin = OFAddVector3D(pl.origin,
			    OFMakeVector3D(f * d.x, f * d.y, f * d.z));
			if (collide(pl, false, drop, rise))
				continue;

			// player stuck, try slide along y axis







|
<
>







354
355
356
357
358
359
360
361

362
363
364
365
366
367
368
369
			pl.timeInAir = 0;
		}
		// at high fps, gravity kicks in too fast
		const float drop = dropf * curtime / gravity / 100 / moveres;
		// extra smoothness when lifting up stairs
		const float rise = speed / moveres / 1.2f;

		// discrete steps collision detection & sliding

		for (int i = 0; i < moveres; i++) {
			// try move forward
			pl.origin = OFAddVector3D(pl.origin,
			    OFMakeVector3D(f * d.x, f * d.y, f * d.z));
			if (collide(pl, false, drop, rise))
				continue;

			// player stuck, try slide along y axis
437
438
439
440
441
442
443

444
445

446
447
	}
	pl.inWater = water;
}

void
moveplayer(DynamicEntity *pl, int moveres, bool local)
{

	loopi(physicsrepeat) moveplayer4(pl, moveres, local,
	    i ? curtime / physicsrepeat

	      : curtime - curtime / physicsrepeat * (physicsrepeat - 1));
}







>
|
|
>
|

437
438
439
440
441
442
443
444
445
446
447
448
449
	}
	pl.inWater = water;
}

void
moveplayer(DynamicEntity *pl, int moveres, bool local)
{
	for (int i = 0; i < physicsrepeat; i++)
		moveplayer4(pl, moveres, local,
		    i ? curtime / physicsrepeat
		      : curtime -
		            curtime / physicsrepeat * (physicsrepeat - 1));
}

Modified src/renderextras.m from [81b3ccc9f0] to [2902b001e4].

91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
static struct sphere spheres[MAXSPHERES], *slist = NULL, *sempty = NULL;
bool sinit = false;

void
newsphere(const OFVector3D *o, float max, int type)
{
	if (!sinit) {
		loopi(MAXSPHERES)
		{
			spheres[i].next = sempty;
			sempty = &spheres[i];
		}
		sinit = true;
	}
	if (sempty) {
		struct sphere *p = sempty;







|
<







91
92
93
94
95
96
97
98

99
100
101
102
103
104
105
static struct sphere spheres[MAXSPHERES], *slist = NULL, *sempty = NULL;
bool sinit = false;

void
newsphere(const OFVector3D *o, float max, int type)
{
	if (!sinit) {
		for (int i = 0; i < MAXSPHERES; i++) {

			spheres[i].next = sempty;
			sempty = &spheres[i];
		}
		sinit = true;
	}
	if (sempty) {
		struct sphere *p = sempty;
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229

	if ([lastsky isEqual:basename])
		return;

	static const OFString *side[] = { @"ft", @"bk", @"lf", @"rt", @"dn",
		@"up" };
	int texnum = 14;
	loopi(6)
	{
		OFString *path = [OFString
		    stringWithFormat:@"packages/%@_%@.jpg", basename, side[i]];

		int xs, ys;
		if (!installtex(texnum + i,
		        [Cube.sharedInstance.gameDataIRI
		            IRIByAppendingPathComponent:path],







|
<







213
214
215
216
217
218
219
220

221
222
223
224
225
226
227

	if ([lastsky isEqual:basename])
		return;

	static const OFString *side[] = { @"ft", @"bk", @"lf", @"rt", @"dn",
		@"up" };
	int texnum = 14;
	for (int i = 0; i < 6; i++) {

		OFString *path = [OFString
		    stringWithFormat:@"packages/%@_%@.jpg", basename, side[i]];

		int xs, ys;
		if (!installtex(texnum + i,
		        [Cube.sharedInstance.gameDataIRI
		            IRIByAppendingPathComponent:path],

Modified src/rendergl.m from [d2bce2bd10] to [34f844358a].

108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
			s = converted;
		} @finally {
			SDL_FreeFormat(format);
		}
	}

#if 0
		loopi(s->w * s->h * 3)
		{
			uchar *p = (uchar *)s->pixels + i;
			*p = 255 - *p;
		}
#endif
	glBindTexture(GL_TEXTURE_2D, tnum);
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
	    clamp ? GL_CLAMP_TO_EDGE : GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
	    clamp ? GL_CLAMP_TO_EDGE : GL_REPEAT);







|
<
|
|
|







108
109
110
111
112
113
114
115

116
117
118
119
120
121
122
123
124
125
			s = converted;
		} @finally {
			SDL_FreeFormat(format);
		}
	}

#if 0
	for (int i = 0; i < s->w * s->h * 3; i++) {

		uchar *p = (uchar *)s->pixels + i;
		*p = 255 - *p;
	}
#endif
	glBindTexture(GL_TEXTURE_2D, tnum);
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
	    clamp ? GL_CLAMP_TO_EDGE : GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
	    clamp ? GL_CLAMP_TO_EDGE : GL_REPEAT);
175
176
177
178
179
180
181


182
183
184
185
186
187
188
189
// ( cube texture, frame ) -> ( opengl id, name )
static int mapping[256][MAXFRAMES];
static OFString *mapname[256][MAXFRAMES];

void
purgetextures()
{


	loopi(256) loop(j, MAXFRAMES) mapping[i][j] = 0;
}

int curtexnum = 0;

void
texturereset()
{







>
>
|







174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// ( cube texture, frame ) -> ( opengl id, name )
static int mapping[256][MAXFRAMES];
static OFString *mapname[256][MAXFRAMES];

void
purgetextures()
{
	for (int i = 0; i < 256; i++)
		for (int j = 0; j < MAXFRAMES; j++)
			mapping[i][j] = 0;
}

int curtexnum = 0;

void
texturereset()
{
217
218
219
220
221
222
223
224
225

226
227
228
229
230
231
232
		return tid;
	}

	*xs = *ys = 16;
	if (tid == 0)
		return 1; // crosshair :)

	loopi(curtex) // lazily happens once per "texture" command, basically
	{

		if ([mapname[tex][frame] isEqual:texname[i]]) {
			mapping[tex][frame] = tid = i + FIRSTTEX;
			*xs = texx[i];
			*ys = texy[i];
			return tid;
		}
	}







|
<
>







218
219
220
221
222
223
224
225

226
227
228
229
230
231
232
233
		return tid;
	}

	*xs = *ys = 16;
	if (tid == 0)
		return 1; // crosshair :)

	// lazily happens once per "texture" command, basically

	for (int i = 0; i < curtex; i++) {
		if ([mapname[tex][frame] isEqual:texname[i]]) {
			mapping[tex][frame] = tid = i + FIRSTTEX;
			*xs = texx[i];
			*ys = texy[i];
			return tid;
		}
	}

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

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

VARP(maxparticles, 100, 2000, MAXPARTICLES - 500);

static void
newparticle(const OFVector3D *o, const OFVector3D *d, int fade, int type)
{
	if (!parinit) {
		loopi(MAXPARTICLES)
		{
			particles[i].next = parempty;
			parempty = &particles[i];
		}
		parinit = true;
	}
	if (parempty) {
		struct particle *p = parempty;







|
<







17
18
19
20
21
22
23
24

25
26
27
28
29
30
31

VARP(maxparticles, 100, 2000, MAXPARTICLES - 500);

static void
newparticle(const OFVector3D *o, const OFVector3D *d, int fade, int type)
{
	if (!parinit) {
		for (int i = 0; i < MAXPARTICLES; i++) {

			particles[i].next = parempty;
			parempty = &particles[i];
		}
		parinit = true;
	}
	if (parempty) {
		struct particle *p = parempty;
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
	glDisable(GL_BLEND);
	glDepthMask(GL_TRUE);
}

void
particle_splash(int type, int num, int fade, const OFVector3D *p)
{
	loopi(num)
	{
		const int radius = type == 5 ? 50 : 150;
		int x, y, z;
		do {
			x = rnd(radius * 2) - radius;
			y = rnd(radius * 2) - radius;
			z = rnd(radius * 2) - radius;
		} while (x * x + y * y + z * z > radius * radius);
		OFVector3D d = OFMakeVector3D(x, y, z);
		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);
	vdiv(v, d * 2 + 0.1f);
	OFVector3D p = *s;
	loopi((int)d * 2)
	{
		vadd(p, v);
		OFVector3D d =
		    OFMakeVector3D(rnd(11) - 5, rnd(11) - 5, rnd(11) - 5);
		newparticle(&p, &d, rnd(fade) + fade, type);
	}
}







|
<


















|
<






133
134
135
136
137
138
139
140

141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159

160
161
162
163
164
165
	glDisable(GL_BLEND);
	glDepthMask(GL_TRUE);
}

void
particle_splash(int type, int num, int fade, const OFVector3D *p)
{
	for (int i = 0; i < num; i++) {

		const int radius = type == 5 ? 50 : 150;
		int x, y, z;
		do {
			x = rnd(radius * 2) - radius;
			y = rnd(radius * 2) - radius;
			z = rnd(radius * 2) - radius;
		} while (x * x + y * y + z * z > radius * radius);
		OFVector3D d = OFMakeVector3D(x, y, z);
		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);
	vdiv(v, d * 2 + 0.1f);
	OFVector3D p = *s;
	for (int i = 0; i < ((int)d * 2); i++) {

		vadd(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 [fc99f9e9f6] to [c92a453804].

241
242
243
244
245
246
247

248
249
250
251
252
253

254
255
256
257
258
259
260
		monster.lastAction = monster.trigger = lastmillis + 500;
		if (monster.state == CS_DEAD)
			monster.lastAction = 0;
	}
	[Monster restoreAll];

	int nplayers = gzgeti();

	loopi(nplayers) if (!gzget())
	{
		DynamicEntity *d = getclient(i);
		assert(d);
		gzread(f, data.mutableItems, data.count);
		[d setFromSerializedData:data];

	}

	conoutf(@"savegame restored");
	if (demoloading)
		startdemo();
	else
		stop();







>
|
<
|
|
|
|
>







241
242
243
244
245
246
247
248
249

250
251
252
253
254
255
256
257
258
259
260
261
		monster.lastAction = monster.trigger = lastmillis + 500;
		if (monster.state == CS_DEAD)
			monster.lastAction = 0;
	}
	[Monster restoreAll];

	int nplayers = gzgeti();
	for (int i = 0; i < nplayers; i++) {
		if (!gzget()) {

			DynamicEntity *d = getclient(i);
			assert(d);
			gzread(f, data.mutableItems, data.count);
			[d setFromSerializedData:data];
		}
	}

	conoutf(@"savegame restored");
	if (demoloading)
		startdemo();
	else
		stop();
317
318
319
320
321
322
323

324
325
326
327
328
329
330
331
		gzput(player1.gunSelect);
		gzput(player1.lastAttackGun);
		gzputi(player1.lastAction - starttime);
		gzputi(player1.gunWait);
		gzputi(player1.health);
		gzputi(player1.armour);
		gzput(player1.armourType);

		loopi(NUMGUNS) gzput(player1.ammo[i]);
		gzput(player1.state);
		gzputi(bdamage);
		bdamage = 0;
		gzputi(ddamage);
		if (ddamage) {
			gzputv(&dorig);
			ddamage = 0;







>
|







318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
		gzput(player1.gunSelect);
		gzput(player1.lastAttackGun);
		gzputi(player1.lastAction - starttime);
		gzputi(player1.gunWait);
		gzputi(player1.health);
		gzputi(player1.armour);
		gzput(player1.armourType);
		for (int i = 0; i < NUMGUNS; i++)
			gzput(player1.ammo[i]);
		gzput(player1.state);
		gzputi(bdamage);
		bdamage = 0;
		gzputi(ddamage);
		if (ddamage) {
			gzputv(&dorig);
			ddamage = 0;
444
445
446
447
448
449
450

451
452
453
454
455
456
457
458
			target.gunSelect = gzget();
			target.lastAttackGun = gzget();
			target.lastAction = scaletime(gzgeti());
			target.gunWait = gzgeti();
			target.health = gzgeti();
			target.armour = gzgeti();
			target.armourType = gzget();

			loopi(NUMGUNS) target.ammo[i] = gzget();
			target.state = gzget();
			target.lastMove = playbacktime;
			if ((bdamage = gzgeti()))
				damageblend(bdamage);
			if ((ddamage = gzgeti())) {
				gzgetv(&dorig);
				particle_splash(3, ddamage, 1000, &dorig);







>
|







446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
			target.gunSelect = gzget();
			target.lastAttackGun = gzget();
			target.lastAction = scaletime(gzgeti());
			target.gunWait = gzgeti();
			target.health = gzgeti();
			target.armour = gzgeti();
			target.armourType = gzget();
			for (int i = 0; i < NUMGUNS; i++)
				target.ammo[i] = gzget();
			target.state = gzget();
			target.lastMove = playbacktime;
			if ((bdamage = gzgeti()))
				damageblend(bdamage);
			if ((ddamage = gzgeti())) {
				gzgetv(&dorig);
				particle_splash(3, ddamage, 1000, &dorig);

Modified src/server.m from [7cdeba7547] to [98a7979cee].

249
250
251
252
253
254
255

256
257
258
259
260
261
262
263
			if (cn < 0 || cn >= clients.count ||
			    clients[cn].type == ST_EMPTY) {
				disconnect_client(sender, @"client num");
				return;
			}
			int size = msgsizelookup(type);
			assert(size != -1);

			loopi(size - 2) getint(&p);
			break;
		}

		case SV_SENDMAP: {
			sgetstr();
			int mapsize = getint(&p);
			sendmaps(sender, @(text), mapsize, p);







>
|







249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
			if (cn < 0 || cn >= clients.count ||
			    clients[cn].type == ST_EMPTY) {
				disconnect_client(sender, @"client num");
				return;
			}
			int size = msgsizelookup(type);
			assert(size != -1);
			for (int i = 0; i < size - 2; i++)
				getint(&p);
			break;
		}

		case SV_SENDMAP: {
			sgetstr();
			int mapsize = getint(&p);
			sendmaps(sender, @(text), mapsize, p);
276
277
278
279
280
281
282

283
284
285
286
287
288
289
290

		default: {
			int size = msgsizelookup(type);
			if (size == -1) {
				disconnect_client(sender, @"tag type");
				return;
			}

			loopi(size - 1) getint(&p);
		}
		}
	}

	if (p > end) {
		disconnect_client(sender, @"end of packet");
		return;







>
|







277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292

		default: {
			int size = msgsizelookup(type);
			if (size == -1) {
				disconnect_client(sender, @"tag type");
				return;
			}
			for (int i = 0; i < size - 1; i++)
				getint(&p);
		}
		}
	}

	if (p > end) {
		disconnect_client(sender, @"end of packet");
		return;
542
543
544
545
546
547
548

549
550
551
552
553
554
555
556
		ENetAddress address = { ENET_HOST_ANY, CUBE_SERVER_PORT };
		if (ip.length > 0 &&
		    enet_address_set_host(&address, ip.UTF8String) < 0)
			printf("WARNING: server ip not resolved");
		serverhost = enet_host_create(&address, MAXCLIENTS, 0, uprate);
		if (!serverhost)
			fatal(@"could not create server host\n");

		loopi(MAXCLIENTS) serverhost->peers[i].data = (void *)-1;
	}

	resetserverifempty();

	// do not return, this becomes main loop
	if (isdedicated) {
#ifdef _WIN32







>
|







544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
		ENetAddress address = { ENET_HOST_ANY, CUBE_SERVER_PORT };
		if (ip.length > 0 &&
		    enet_address_set_host(&address, ip.UTF8String) < 0)
			printf("WARNING: server ip not resolved");
		serverhost = enet_host_create(&address, MAXCLIENTS, 0, uprate);
		if (!serverhost)
			fatal(@"could not create server host\n");
		for (int i = 0; i < MAXCLIENTS; i++)
			serverhost->peers[i].data = (void *)-1;
	}

	resetserverifempty();

	// do not return, this becomes main loop
	if (isdedicated) {
#ifdef _WIN32

Modified src/sound.m from [8879a01acd] to [4ad5c2248e].

142
143
144
145
146
147
148
149
150


151
152
153
154

155
156
157
158
159
160
161
}

void
updatevol()
{
	if (nosound)
		return;
	loopi(MAXCHAN) if (soundlocs[i].inuse)
	{


		if (Mix_Playing(i))
			updatechanvol(i, &soundlocs[i].loc);
		else
			soundlocs[i].inuse = false;

	}
}

void
playsoundc(int n)
{
	addmsg(0, 2, SV_SOUND, n);







<
|
>
>
|
|
|
|
>







142
143
144
145
146
147
148

149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
}

void
updatevol()
{
	if (nosound)
		return;


	for (int i = 0; i < MAXCHAN; i++) {
		if (soundlocs[i].inuse) {
			if (Mix_Playing(i))
				updatechanvol(i, &soundlocs[i].loc);
			else
				soundlocs[i].inuse = false;
		}
	}
}

void
playsoundc(int n)
{
	addmsg(0, 2, SV_SOUND, n);

Modified src/tools.h from [277ccadbda] to [1e36fccfb6].

26
27
28
29
30
31
32
33
34
35

36
37
38
39
40
41
42
43
44
45
46
47
48
typedef unsigned short ushort;
typedef unsigned int uint;

#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))
#define rnd(max) (rand() % (max))
#define rndreset() (srand(1))
#define rndtime()                                   \
	{                                           \
		loopi(lastmillis & 0xF) rnd(i + 1); \

	}
#define loop(v, m) for (int v = 0; v < (m); v++)
#define loopi(m) loop(i, m)
#define loopj(m) loop(j, m)
#define loopk(m) loop(k, m)
#define loopl(m) loop(l, m)

#ifndef OF_WINDOWS
# define __cdecl
#endif

#define fast_f2nat(val) ((int)(val))








|
|
|
>

<
<
<
<
<







26
27
28
29
30
31
32
33
34
35
36
37





38
39
40
41
42
43
44
typedef unsigned short ushort;
typedef unsigned int uint;

#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))
#define rnd(max) (rand() % (max))
#define rndreset() (srand(1))
#define rndtime()                                            \
	{                                                    \
		for (int i = 0; i < (lastmillis & 0xF); i++) \
			rnd(i + 1);                          \
	}






#ifndef OF_WINDOWS
# define __cdecl
#endif

#define fast_f2nat(val) ((int)(val))

Modified src/tools.m from [f9cb2ee264] to [9fca1834ea].

1
2
3
4
5
6
7
8
9
10
11
12
13
14


15
16
17
18

19
20
// implementation of generic tools

#include "tools.h"

///////////////////////// misc tools ///////////////////////

void
endianswap(
    void *memory, int stride, int length) // little indians as storage format
{
	if (*((char *)&stride))
		return;
	loop(w, length) loop(i, stride / 2)
	{


		uchar *p = (uchar *)memory + w * stride;
		uchar t = p[i];
		p[i] = p[stride - i - 1];
		p[stride - i - 1] = t;

	}
}












<
|
>
>
|
|
|
|
>


1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20
21
22
// implementation of generic tools

#include "tools.h"

///////////////////////// misc tools ///////////////////////

void
endianswap(
    void *memory, int stride, int length) // little indians as storage format
{
	if (*((char *)&stride))
		return;


	for (int w = 0; w < length; w++) {
		for (int i = 0; i < stride / 2; i++) {
			uchar *p = (uchar *)memory + w * stride;
			uchar t = p[i];
			p[i] = p[stride - i - 1];
			p[stride - i - 1] = t;
		}
	}
}

Modified src/weapon.m from [6b111961c9] to [acb2ec57ac].

73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88

// 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;
	loopi(SGRAYS)
	{
#define RNDD (rnd(101) - 50) * f
		OFVector3D r = OFMakeVector3D(RNDD, RNDD, RNDD);
		sg[i] = *to;
		vadd(sg[i], r);
	}
}








|
<







73
74
75
76
77
78
79
80

81
82
83
84
85
86
87

// 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
		OFVector3D r = OFMakeVector3D(RNDD, RNDD, RNDD);
		sg[i] = *to;
		vadd(sg[i], r);
	}
}

164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
		p.local = local;
		p.owner = owner;
		p.gun = gun;
		return;
	}
}

void
hit(int target, int damage, __kindof DynamicEntity *d, DynamicEntity *at)
{
	OFVector3D o = d.origin;
	if (d == player1)
		selfdamage(damage, at == player1 ? -1 : -2, at);
	else if ([d isKindOfClass:Monster.class])
		[d incurDamage:damage fromEntity:at];







|







163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
		p.local = local;
		p.owner = owner;
		p.gun = gun;
		return;
	}
}

static void
hit(int target, int damage, __kindof DynamicEntity *d, DynamicEntity *at)
{
	OFVector3D o = d.origin;
	if (d == player1)
		selfdamage(damage, at == player1 ? -1 : -2, at);
	else if ([d isKindOfClass:Monster.class])
		[d incurDamage:damage fromEntity:at];
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
		int damage = (int)(qdam * (1 - (dist / RL_DAMRAD)));
		hit(cn, damage, o, at);
		vmul(temp, (RL_DAMRAD - dist) * damage / 800);
		vadd(o.velocity, temp);
	}
}

void
splash(Projectile *p, const OFVector3D *v, const OFVector3D *vold,
    int notthisplayer, int notthismonster, int qdam)
{
	particle_splash(0, 50, 300, v);
	p.inuse = false;

	if (p.gun != GUN_RL) {







|







200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
		int damage = (int)(qdam * (1 - (dist / RL_DAMRAD)));
		hit(cn, damage, o, at);
		vmul(temp, (RL_DAMRAD - dist) * damage / 800);
		vadd(o.velocity, temp);
	}
}

static void
splash(Projectile *p, const OFVector3D *v, const OFVector3D *vold,
    int notthisplayer, int notthismonster, int qdam)
{
	particle_splash(0, 50, 300, v);
	p.inuse = false;

	if (p.gun != GUN_RL) {
318
319
320
321
322
323
324

325
326
327
328
329
330
331
332
	playsound(guns[gun].sound, d == player1 ? NULL : &loc);
	int pspeed = 25;
	switch (gun) {
	case GUN_FIST:
		break;

	case GUN_SG: {

		loopi(SGRAYS) particle_splash(0, 5, 200, &sg[i]);
		break;
	}

	case GUN_CG:
		particle_splash(0, 100, 250, to);
		// particle_trail(1, 10, from, to);
		break;







>
|







317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
	playsound(guns[gun].sound, d == player1 ? NULL : &loc);
	int pspeed = 25;
	switch (gun) {
	case GUN_FIST:
		break;

	case GUN_SG: {
		for (int i = 0; i < SGRAYS; i++)
			particle_splash(0, 5, 200, &sg[i]);
		break;
	}

	case GUN_CG:
		particle_splash(0, 100, 250, to);
		// particle_trail(1, 10, from, to);
		break;
367
368
369
370
371
372
373

374

375
376
377
378
379
380
381
	int qdam = guns[d.gunSelect].damage;
	if (d.quadMillis)
		qdam *= 4;
	if ([d isKindOfClass:Monster.class])
		qdam /= MONSTERDAMAGEFACTOR;
	if (d.gunSelect == GUN_SG) {
		int damage = 0;

		loop(r, SGRAYS) if (intersect(o, from, &sg[r])) damage += qdam;

		if (damage)
			hitpush(i, damage, o, d, from, to);
	} else if (intersect(o, from, to))
		hitpush(i, qdam, o, d, from, to);
}

void







>
|
>







367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
	int qdam = guns[d.gunSelect].damage;
	if (d.quadMillis)
		qdam *= 4;
	if ([d isKindOfClass:Monster.class])
		qdam /= MONSTERDAMAGEFACTOR;
	if (d.gunSelect == GUN_SG) {
		int damage = 0;
		for (int r = 0; r < SGRAYS; r++)
			if (intersect(o, from, &sg[r]))
				damage += qdam;
		if (damage)
			hitpush(i, damage, o, d, from, to);
	} else if (intersect(o, from, to))
		hitpush(i, qdam, o, d, from, to);
}

void

Modified src/world.m from [97ecb02030] to [9e368d7a28].

15
16
17
18
19
20
21
22
23

24

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

44
45
46



47
48


49
50
51
52

53

54
55
56
57
58
59
60
61
62
63

64
65
66
67
68
69
70

// set all cubes with "tag" to space, if tag is 0 then reset ALL tagged cubes
// according to type
void
settag(int tag, int type)
{
	int maxx = 0, maxy = 0, minx = ssize, miny = ssize;
	loop(x, ssize) loop(y, ssize)
	{

		struct sqr *s = S(x, y);

		if (s->tag) {
			if (tag) {
				if (tag == s->tag)
					s->type = SPACE;
				else
					continue;
			} else {
				s->type = type ? SOLID : SPACE;
			}
			if (x > maxx)
				maxx = x;
			if (y > maxy)
				maxy = y;
			if (x < minx)
				minx = x;
			if (y < miny)
				miny = y;
		}
	}

	struct block b = { minx, miny, maxx - minx + 1, maxy - miny + 1 };
	if (maxx)
		remip(&b, 0); // remip minimal area of changed geometry



}



void
resettagareas()
{
	settag(0, 0);

} // reset for editing or map saving

void
settagareas()
{
	settag(0, 1);

	[ents enumerateObjectsUsingBlock:^(Entity *e, size_t i, bool *stop) {
		if (ents[i].type == CARROT)
			setspawn(i, true);
	}];
} // set for playing


void
trigger(int tag, int type, bool savegame)
{
	if (!tag)
		return;








|
<
>
|
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
|
|
|
>
>
>
|
|
>
>




>
|
>









<
>







15
16
17
18
19
20
21
22

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

72
73
74
75
76
77
78
79

// set all cubes with "tag" to space, if tag is 0 then reset ALL tagged cubes
// according to type
void
settag(int tag, int type)
{
	int maxx = 0, maxy = 0, minx = ssize, miny = ssize;
	for (int x = 0; x < ssize; x++) {

		for (int y = 0; y < ssize; y++) {
			struct sqr *s = S(x, y);

			if (s->tag) {
				if (tag) {
					if (tag == s->tag)
						s->type = SPACE;
					else
						continue;
				} else
					s->type = type ? SOLID : SPACE;

				if (x > maxx)
					maxx = x;
				if (y > maxy)
					maxy = y;
				if (x < minx)
					minx = x;
				if (y < miny)
					miny = y;
			}
		}
	}

	if (maxx) {
		// remip minimal area of changed geometry
		struct block b = { minx, miny, maxx - minx + 1,
			maxy - miny + 1 };
		remip(&b, 0);
	}
}

// reset for editing or map saving
void
resettagareas()
{
	settag(0, 0);
}

// set for playing
void
settagareas()
{
	settag(0, 1);

	[ents enumerateObjectsUsingBlock:^(Entity *e, size_t i, bool *stop) {
		if (ents[i].type == CARROT)
			setspawn(i, true);
	}];

}

void
trigger(int tag, int type, bool savegame)
{
	if (!tag)
		return;

119
120
121
122
123
124
125

126

127
128
129
130

131

132
133

134
135
136
137
138
139
140

141

142

143

144
145
146

147
148

149
150

151

152
153
154
155
156
157

158
159
160
161

162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
			o[1] = SWS(w, x + 1, y, ws);
			o[2] = SWS(w, x + 1, y + 1, ws);
			o[3] = SWS(w, x, y + 1, ws);
			// the target cube in the higher mip level
			struct sqr *r = SWS(v, x / 2, y / 2, vs);
			*r = *o[0];
			uchar nums[MAXTYPE];

			loopi(MAXTYPE) nums[i] = 0;

			loopj(4) nums[o[j]->type]++;
			// cube contains both solid and space, treated
			// specially in the renderer
			r->type = SEMISOLID;

			loopk(MAXTYPE) if (nums[k] == 4) r->type = k;

			if (!SOLID(r)) {
				int floor = 127, ceil = -128;

				loopi(4) if (!SOLID(o[i]))
				{
					int fh = o[i]->floor;
					int ch = o[i]->ceil;
					if (r->type == SEMISOLID) {
						if (o[i]->type == FHF)
							// crap hack, needed

							// for rendering large

							// mips next to hfs

							fh -= o[i]->vdelta / 4 +

							    2;
						if (o[i]->type == CHF)
							// FIXME: needs to

							// somehow take into
							// account middle

							// vertices on higher
							// mips

							ch += o[i]->vdelta / 4 +

							    2;
					}
					if (fh < floor)
						// take lowest floor and
						// highest ceil, so we never
						// have to see missing

						// lower/upper from the side
						floor = fh;
					if (ch > ceil)
						ceil = ch;

				}
				r->floor = floor;
				r->ceil = ceil;
			}
			if (r->type == CORNER)
				// special case: don't ever split even if
				// textures etc are different
				goto mip;
			r->defer = 1;
			if (SOLID(r)) {
				loopi(3)
				{
					if (o[i]->wtex != o[3]->wtex)
						// on an all solid cube, only
						// thing that needs to be equal
						// for a perfect mip is the
						// wall texture
						goto c;
				}
			} else {
				loopi(3)
				{
					// perfect mip even if light is not
					// exactly equal
					if (o[i]->type != o[3]->type ||
					    o[i]->floor != o[3]->floor ||
					    o[i]->ceil != o[3]->ceil ||
					    o[i]->ftex != o[3]->ftex ||
					    o[i]->ctex != o[3]->ctex ||







>
|
>
|



>
|
>


>
|
<
|
|
|
|
|
>
|
>
|
>
|
>
|
|
|
>
|
|
>
|
|
>
|
>
|
|
|
|
|
|
>
|
|
|
|
>










|
<








|
<







128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148

149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
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
209
210
211
			o[1] = SWS(w, x + 1, y, ws);
			o[2] = SWS(w, x + 1, y + 1, ws);
			o[3] = SWS(w, x, y + 1, ws);
			// the target cube in the higher mip level
			struct sqr *r = SWS(v, x / 2, y / 2, vs);
			*r = *o[0];
			uchar nums[MAXTYPE];
			for (int i = 0; i < MAXTYPE; i++)
				nums[i] = 0;
			for (int j = 0; j < 4; j++)
				nums[o[j]->type]++;
			// cube contains both solid and space, treated
			// specially in the renderer
			r->type = SEMISOLID;
			for (int k = 0; k < MAXTYPE; k++)
				if (nums[k] == 4)
					r->type = k;
			if (!SOLID(r)) {
				int floor = 127, ceil = -128;
				for (int i = 0; i < 4; i++) {
					if (!SOLID(o[i])) {

						int fh = o[i]->floor;
						int ch = o[i]->ceil;
						if (r->type == SEMISOLID) {
							if (o[i]->type == FHF)
								// crap hack,
								// needed for
								// rendering
								// large mips
								// next to hfs
								fh -=
								    o[i]->vdelta /
								        4 +
								    2;
							if (o[i]->type == CHF)
								// FIXME: needs
								// to somehow
								// take into
								// account
								// middle
								// vertices on
								// higher mips
								ch +=
								    o[i]->vdelta /
								        4 +
								    2;
						}
						if (fh < floor)
							// take lowest floor and
							// highest ceil, so we
							// never have to see
							// missing lower/upper
							// from the side
							floor = fh;
						if (ch > ceil)
							ceil = ch;
					}
				}
				r->floor = floor;
				r->ceil = ceil;
			}
			if (r->type == CORNER)
				// special case: don't ever split even if
				// textures etc are different
				goto mip;
			r->defer = 1;
			if (SOLID(r)) {
				for (int i = 0; i < 3; i++) {

					if (o[i]->wtex != o[3]->wtex)
						// on an all solid cube, only
						// thing that needs to be equal
						// for a perfect mip is the
						// wall texture
						goto c;
				}
			} else {
				for (int i = 0; i < 3; i++) {

					// perfect mip even if light is not
					// exactly equal
					if (o[i]->type != o[3]->type ||
					    o[i]->floor != o[3]->floor ||
					    o[i]->ceil != o[3]->ceil ||
					    o[i]->ftex != o[3]->ftex ||
					    o[i]->ctex != o[3]->ctex ||
224
225
226
227
228
229
230

231

232
233
234
235
236
237
238
					                ->vdelta)
						goto c;
				}
			}
			{
				// if any of the constituents is not perfect,
				// then this one isn't either

				loopi(4) if (o[i]->defer) goto c;

			}
		mip:
			r->defer = 0;
		c:;
		}
	s.x /= 2;
	s.y /= 2;







>
|
>







245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
					                ->vdelta)
						goto c;
				}
			}
			{
				// if any of the constituents is not perfect,
				// then this one isn't either
				for (int i = 0; i < 4; i++)
					if (o[i]->defer)
						goto c;
			}
		mip:
			r->defer = 0;
		c:;
		}
	s.x /= 2;
	s.y /= 2;
318
319
320
321
322
323
324

325

326
327
328
329
330
331
332
	if (t == LIGHT)
		calclight();
}

int
findtype(OFString *what)
{

	loopi(MAXENTTYPES) if ([what isEqual:entnames[i]]) return i;

	conoutf(@"unknown entity type \"%@\"", what);
	return NOTUSED;
}

Entity *
newentity(int x, int y, int z, OFString *what, int v1, int v2, int v3, int v4)
{







>
|
>







341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
	if (t == LIGHT)
		calclight();
}

int
findtype(OFString *what)
{
	for (int i = 0; i < MAXENTTYPES; i++)
		if ([what isEqual:entnames[i]])
			return i;
	conoutf(@"unknown entity type \"%@\"", what);
	return NOTUSED;
}

Entity *
newentity(int x, int y, int z, OFString *what, int v1, int v2, int v3, int v4)
{
424
425
426
427
428
429
430

431

432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453

int
findentity(int type, int index)
{
	for (int i = index; i < ents.count; i++)
		if (ents[i].type == type)
			return i;

	loopj(index) if (ents[j].type == type) return j;

	return -1;
}

struct sqr *wmip[LARGEST_FACTOR * 2];

void
setupworld(int factor)
{
	ssize = 1 << (sfactor = factor);
	cubicsize = ssize * ssize;
	mipsize = cubicsize * 134 / 100;
	struct sqr *w = world =
	    OFAllocZeroedMemory(mipsize, sizeof(struct sqr));
	loopi(LARGEST_FACTOR * 2)
	{
		wmip[i] = w;
		w += cubicsize >> (i * 2);
	}
}

// main empty world creation routine, if passed factor -1 will enlarge old
// world by 1







>
|
>













|
<







449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472

473
474
475
476
477
478
479

int
findentity(int type, int index)
{
	for (int i = index; i < ents.count; i++)
		if (ents[i].type == type)
			return i;
	for (int j = 0; j < index; j++)
		if (ents[j].type == type)
			return j;
	return -1;
}

struct sqr *wmip[LARGEST_FACTOR * 2];

void
setupworld(int factor)
{
	ssize = 1 << (sfactor = factor);
	cubicsize = ssize * ssize;
	mipsize = cubicsize * 134 / 100;
	struct sqr *w = world =
	    OFAllocZeroedMemory(mipsize, sizeof(struct sqr));
	for (int i = 0; i < LARGEST_FACTOR * 2; i++) {

		wmip[i] = w;
		w += cubicsize >> (i * 2);
	}
}

// main empty world creation routine, if passed factor -1 will enlarge old
// world by 1
466
467
468
469
470
471
472
473
474

475
476
477
478
479
480
481
482
483
484

485
486
487
488
489
490
491
492
493
494

495
496

497
498
499
500
501
502
503
504
505
506

507


508
509
510
511
512
513
514
515
	}
	if (factor < SMALLEST_FACTOR)
		factor = SMALLEST_FACTOR;
	if (factor > LARGEST_FACTOR)
		factor = LARGEST_FACTOR;
	setupworld(factor);

	loop(x, ssize) loop(y, ssize)
	{

		struct sqr *s = S(x, y);
		s->r = s->g = s->b = 150;
		s->ftex = DEFAULT_FLOOR;
		s->ctex = DEFAULT_CEIL;
		s->wtex = s->utex = DEFAULT_WALL;
		s->type = SOLID;
		s->floor = 0;
		s->ceil = 16;
		s->vdelta = 0;
		s->defer = 0;

	}

	strncpy(hdr.head, "CUBE", 4);
	hdr.version = MAPVERSION;
	hdr.headersize = sizeof(struct header);
	hdr.sfactor = sfactor;

	if (copy) {
		loop(x, ssize / 2) loop(y, ssize / 2)
		{

			*S(x + ssize / 4, y + ssize / 4) =
			    *SWS(oldworld, x, y, ssize / 2);

		}

		for (Entity *e in ents) {
			e.x += ssize / 4;
			e.y += ssize / 4;
		}
	} else {
		char buffer[128] = "Untitled Map by Unknown";
		memcpy(hdr.maptitle, buffer, 128);
		hdr.waterlevel = -100000;

		loopi(15) hdr.reserved[i] = 0;


		loopk(3) loopi(256) hdr.texlists[k][i] = i;
		[ents removeAllObjects];
		struct block b = { 8, 8, ssize - 16, ssize - 16 };
		edittypexy(SPACE, &b);
	}

	calclight();
	startmap(@"base/unnamed");







|
<
>
|
|
|
|
|
|
|
|
|
|
>








|
<
>
|
|
>










>
|
>
>
|







492
493
494
495
496
497
498
499

500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520

521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
	}
	if (factor < SMALLEST_FACTOR)
		factor = SMALLEST_FACTOR;
	if (factor > LARGEST_FACTOR)
		factor = LARGEST_FACTOR;
	setupworld(factor);

	for (int x = 0; x < ssize; x++) {

		for (int y = 0; y < ssize; y++) {
			struct sqr *s = S(x, y);
			s->r = s->g = s->b = 150;
			s->ftex = DEFAULT_FLOOR;
			s->ctex = DEFAULT_CEIL;
			s->wtex = s->utex = DEFAULT_WALL;
			s->type = SOLID;
			s->floor = 0;
			s->ceil = 16;
			s->vdelta = 0;
			s->defer = 0;
		}
	}

	strncpy(hdr.head, "CUBE", 4);
	hdr.version = MAPVERSION;
	hdr.headersize = sizeof(struct header);
	hdr.sfactor = sfactor;

	if (copy) {
		for (int x = 0; x < ssize / 2; x++) {

			for (int y = 0; y < ssize / 2; y++) {
				*S(x + ssize / 4, y + ssize / 4) =
				    *SWS(oldworld, x, y, ssize / 2);
			}
		}

		for (Entity *e in ents) {
			e.x += ssize / 4;
			e.y += ssize / 4;
		}
	} else {
		char buffer[128] = "Untitled Map by Unknown";
		memcpy(hdr.maptitle, buffer, 128);
		hdr.waterlevel = -100000;
		for (int i = 0; i < 15; i++)
			hdr.reserved[i] = 0;
		for (int k = 0; k < 3; k++)
			for (int i = 0; i < 256; i++)
				hdr.texlists[k][i] = i;
		[ents removeAllObjects];
		struct block b = { 8, 8, ssize - 16, ssize - 16 };
		edittypexy(SPACE, &b);
	}

	calclight();
	startmap(@"base/unnamed");

Modified src/worldio.m from [cfdf69a801] to [a9d5711584].

57
58
59
60
61
62
63
64
65

66

67
68
69
70
71
72

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
{
	return s->type != FHF && s->type != CHF;
}

void
voptimize() // reset vdeltas on non-hf cubes
{
	loop(x, ssize) loop(y, ssize)
	{

		struct sqr *s = S(x, y);

		if (x && y) {
			if (nhf(s) && nhf(S(x - 1, y)) &&
			    nhf(S(x - 1, y - 1)) && nhf(S(x, y - 1)))
				s->vdelta = 0;
		} else
			s->vdelta = 0;

	}
}

static void
topt(struct sqr *s, bool *wf, bool *uf, int *wt, int *ut)
{
	struct sqr *o[4];
	o[0] = SWS(s, 0, -1, ssize);
	o[1] = SWS(s, 0, 1, ssize);
	o[2] = SWS(s, 1, 0, ssize);
	o[3] = SWS(s, -1, 0, ssize);
	*wf = true;
	*uf = true;
	if (SOLID(s)) {

		loopi(4) if (!SOLID(o[i]))
		{
			*wf = false;
			*wt = s->wtex;
			*ut = s->utex;
			return;
		}

	} else {

		loopi(4) if (!SOLID(o[i]))
		{
			if (o[i]->floor < s->floor) {
				*wt = s->wtex;
				*wf = false;
			}
			if (o[i]->ceil > s->ceil) {
				*ut = s->utex;
				*uf = false;

			}
		}
	}
}

void
toptimize() // FIXME: only does 2x2, make atleast for 4x4 also







|
<
>
|
>
|
|
|
|
|
|
>














>
|
<
|
|
|
|
|
>

>
|
<
|
|
|
|
|
|
|
>







57
58
59
60
61
62
63
64

65
66
67
68
69
70
71
72
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
{
	return s->type != FHF && s->type != CHF;
}

void
voptimize() // reset vdeltas on non-hf cubes
{
	for (int x = 0; x < ssize; x++) {

		for (int y = 0; y < ssize; y++) {
			struct sqr *s = S(x, y);

			if (x && y) {
				if (nhf(s) && nhf(S(x - 1, y)) &&
				    nhf(S(x - 1, y - 1)) && nhf(S(x, y - 1)))
					s->vdelta = 0;
			} else
				s->vdelta = 0;
		}
	}
}

static void
topt(struct sqr *s, bool *wf, bool *uf, int *wt, int *ut)
{
	struct sqr *o[4];
	o[0] = SWS(s, 0, -1, ssize);
	o[1] = SWS(s, 0, 1, ssize);
	o[2] = SWS(s, 1, 0, ssize);
	o[3] = SWS(s, -1, 0, ssize);
	*wf = true;
	*uf = true;
	if (SOLID(s)) {
		for (int i = 0; i < 4; i++) {
			if (!SOLID(o[i])) {

				*wf = false;
				*wt = s->wtex;
				*ut = s->utex;
				return;
			}
		}
	} else {
		for (int i = 0; i < 4; i++) {
			if (!SOLID(o[i])) {

				if (o[i]->floor < s->floor) {
					*wt = s->wtex;
					*wf = false;
				}
				if (o[i]->ceil > s->ceil) {
					*ut = s->utex;
					*uf = false;
				}
			}
		}
	}
}

void
toptimize() // FIXME: only does 2x2, make atleast for 4x4 also
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
			topt(s[0], &wf[0], &uf[0], &wt, &ut);
			topt(s[1] = SWS(s[0], 0, 1, ssize), &wf[1], &uf[1], &wt,
			    &ut);
			topt(s[2] = SWS(s[0], 1, 1, ssize), &wf[2], &uf[2], &wt,
			    &ut);
			topt(s[3] = SWS(s[0], 1, 0, ssize), &wf[3], &uf[3], &wt,
			    &ut);
			loopi(4)
			{
				if (wf[i])
					s[i]->wtex = wt;
				if (uf[i])
					s[i]->utex = ut;
			}
		}
	}







|
<







122
123
124
125
126
127
128
129

130
131
132
133
134
135
136
			topt(s[0], &wf[0], &uf[0], &wt, &ut);
			topt(s[1] = SWS(s[0], 0, 1, ssize), &wf[1], &uf[1], &wt,
			    &ut);
			topt(s[2] = SWS(s[0], 1, 1, ssize), &wf[2], &uf[2], &wt,
			    &ut);
			topt(s[3] = SWS(s[0], 1, 0, ssize), &wf[3], &uf[3], &wt,
			    &ut);
			for (int i = 0; i < 4; i++) {

				if (wf[i])
					s[i]->wtex = wt;
				if (uf[i])
					s[i]->utex = ut;
			}
		}
	}
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
			gzputc(f, 255); \
			sc -= 255;      \
		} else {                \
			gzputc(f, sc);  \
			sc = 0;         \
		}                       \
	}
	loopk(cubicsize)
	{
		struct sqr *s = &world[k];
#define c(f) (s->f == t->f)
		// 4 types of blocks, to compress a bit:
		// 255 (2): same as previous block + count
		// 254 (3): same as previous, except light // deprecated
		// SOLID (5)
		// anything else (9)







|
<







209
210
211
212
213
214
215
216

217
218
219
220
221
222
223
			gzputc(f, 255); \
			sc -= 255;      \
		} else {                \
			gzputc(f, sc);  \
			sc = 0;         \
		}                       \
	}
	for (int k = 0; k < cubicsize; k++) {

		struct sqr *s = &world[k];
#define c(f) (s->f == t->f)
		// 4 types of blocks, to compress a bit:
		// 255 (2): same as previous block + count
		// 254 (3): same as previous, except light // deprecated
		// SOLID (5)
		// anything else (9)
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
	if (hdr.version >= 4) {
		gzread(f, &hdr.waterlevel, sizeof(int) * 16);
		endianswap(&hdr.waterlevel, sizeof(int), 16);
	} else {
		hdr.waterlevel = -100000;
	}
	[ents removeAllObjects];
	loopi(hdr.numents)
	{
		struct persistent_entity tmp;
		gzread(f, &tmp, sizeof(struct persistent_entity));
		endianswap(&tmp, sizeof(short), 4);

		Entity *e = [Entity entity];
		e.x = tmp.x;
		e.y = tmp.y;







|
<







283
284
285
286
287
288
289
290

291
292
293
294
295
296
297
	if (hdr.version >= 4) {
		gzread(f, &hdr.waterlevel, sizeof(int) * 16);
		endianswap(&hdr.waterlevel, sizeof(int), 16);
	} else {
		hdr.waterlevel = -100000;
	}
	[ents removeAllObjects];
	for (int i = 0; i < hdr.numents; i++) {

		struct persistent_entity tmp;
		gzread(f, &tmp, sizeof(struct persistent_entity));
		endianswap(&tmp, sizeof(short), 4);

		Entity *e = [Entity entity];
		e.x = tmp.x;
		e.y = tmp.y;
308
309
310
311
312
313
314

315
316
317
318
319
320
321
322
323
324
325
			if (e.attr1 > 32)
				e.attr1 = 32; // 12_03 and below
		}
	}
	free(world);
	setupworld(hdr.sfactor);
	char texuse[256];

	loopi(256) texuse[i] = 0;
	struct sqr *t = NULL;
	loopk(cubicsize)
	{
		struct sqr *s = &world[k];
		int type = gzgetc(f);
		switch (type) {
		case 255: {
			int n = gzgetc(f);
			for (int i = 0; i < n; i++, k++)
				memcpy(&world[k], t, sizeof(struct sqr));







>
|

|
<







309
310
311
312
313
314
315
316
317
318
319

320
321
322
323
324
325
326
			if (e.attr1 > 32)
				e.attr1 = 32; // 12_03 and below
		}
	}
	free(world);
	setupworld(hdr.sfactor);
	char texuse[256];
	for (int i = 0; i < 256; i++)
		texuse[i] = 0;
	struct sqr *t = NULL;
	for (int k = 0; k < cubicsize; k++) {

		struct sqr *s = &world[k];
		int type = gzgetc(f);
		switch (type) {
		case 255: {
			int n = gzgetc(f);
			for (int i = 0; i < n; i++, k++)
				memcpy(&world[k], t, sizeof(struct sqr));
378
379
380
381
382
383
384


385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
		if (!SOLID(s))
			texuse[s->utex] = texuse[s->ftex] = texuse[s->ctex] = 1;
	}
	gzclose(f);
	calclight();
	settagareas();
	int xs, ys;


	loopi(256) if (texuse[i]) lookuptexture(i, &xs, &ys);
	conoutf(@"read map %@ (%d milliseconds)", cgzname,
	    SDL_GetTicks() - lastmillis);
	conoutf(@"%s", hdr.maptitle);
	startmap(mname);
	loopl(256)
	{
		// can this be done smarter?
		OFString *aliasname =
		    [OFString stringWithFormat:@"level_trigger_%d", l];
		if (identexists(aliasname))
			alias(aliasname, @"");
	}
	OFIRI *gameDataIRI = Cube.sharedInstance.gameDataIRI;
	execfile([gameDataIRI
	    IRIByAppendingPathComponent:@"data/default_map_settings.cfg"]);
	execfile([gameDataIRI IRIByAppendingPathComponent:pcfname]);
	execfile([gameDataIRI IRIByAppendingPathComponent:mcfname]);
}







>
>
|




|
<












379
380
381
382
383
384
385
386
387
388
389
390
391
392
393

394
395
396
397
398
399
400
401
402
403
404
405
		if (!SOLID(s))
			texuse[s->utex] = texuse[s->ftex] = texuse[s->ctex] = 1;
	}
	gzclose(f);
	calclight();
	settagareas();
	int xs, ys;
	for (int i = 0; i < 256; i++)
		if (texuse[i])
			lookuptexture(i, &xs, &ys);
	conoutf(@"read map %@ (%d milliseconds)", cgzname,
	    SDL_GetTicks() - lastmillis);
	conoutf(@"%s", hdr.maptitle);
	startmap(mname);
	for (int l = 0; l < 256; l++) {

		// can this be done smarter?
		OFString *aliasname =
		    [OFString stringWithFormat:@"level_trigger_%d", l];
		if (identexists(aliasname))
			alias(aliasname, @"");
	}
	OFIRI *gameDataIRI = Cube.sharedInstance.gameDataIRI;
	execfile([gameDataIRI
	    IRIByAppendingPathComponent:@"data/default_map_settings.cfg"]);
	execfile([gameDataIRI IRIByAppendingPathComponent:pcfname]);
	execfile([gameDataIRI IRIByAppendingPathComponent:mcfname]);
}

Modified src/worldlight.m from [3113d251d8] to [20e5b19402].

57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
			int stepg = fast_f2nat(g / (float)steps);
			int b = light.attr4 << PRECBITS;
			int stepb = fast_f2nat(b / (float)steps);
			g /= lightscale;
			stepg /= lightscale;
			b /= lightscale;
			stepb /= lightscale;
			loopi(steps)
			{
				struct sqr *s = S(x >> PRECBITS, y >> PRECBITS);
				int tl = (l >> PRECBITS) + s->r;
				s->r = tl > 255 ? 255 : tl;
				tl = (g >> PRECBITS) + s->g;
				s->g = tl > 255 ? 255 : tl;
				tl = (b >> PRECBITS) + s->b;
				s->b = tl > 255 ? 255 : tl;







|
<







57
58
59
60
61
62
63
64

65
66
67
68
69
70
71
			int stepg = fast_f2nat(g / (float)steps);
			int b = light.attr4 << PRECBITS;
			int stepb = fast_f2nat(b / (float)steps);
			g /= lightscale;
			stepg /= lightscale;
			b /= lightscale;
			stepb /= lightscale;
			for (int i = 0; i < steps; i++) {

				struct sqr *s = S(x >> PRECBITS, y >> PRECBITS);
				int tl = (l >> PRECBITS) + s->r;
				s->r = tl > 255 ? 255 : tl;
				tl = (g >> PRECBITS) + s->g;
				s->g = tl > 255 ? 255 : tl;
				tl = (b >> PRECBITS) + s->b;
				s->b = tl > 255 ? 255 : tl;
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
115
116
117
			int dimness = rnd((255 - light.attr2) / 16 + 1);
			x += stepx * dimness;
			y += stepy * dimness;

			if (OUTBORD(x >> PRECBITS, y >> PRECBITS))
				return;

			loopi(steps)
			{
				struct sqr *s = S(x >> PRECBITS, y >> PRECBITS);
				int tl = (l >> PRECBITS) + s->r;
				s->r = s->g = s->b = tl > 255 ? 255 : tl;
				if (SOLID(s))
					return;
				x += stepx;
				y += stepy;
				l -= stepl;
				stepl -= 25;
			}
		}
	} else // the old (white) light code, here for the few people with old
	       // video cards that don't support overbright
	{
		loopi(steps)
		{
			struct sqr *s = S(x >> PRECBITS, y >> PRECBITS);
			int light = l >> PRECBITS;
			if (light > s->r)
				s->r = s->g = s->b = (uchar)light;
			if (SOLID(s))
				return;
			x += stepx;







|
<














|
<







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
			int dimness = rnd((255 - light.attr2) / 16 + 1);
			x += stepx * dimness;
			y += stepy * dimness;

			if (OUTBORD(x >> PRECBITS, y >> PRECBITS))
				return;

			for (int i = 0; i < steps; i++) {

				struct sqr *s = S(x >> PRECBITS, y >> PRECBITS);
				int tl = (l >> PRECBITS) + s->r;
				s->r = s->g = s->b = tl > 255 ? 255 : tl;
				if (SOLID(s))
					return;
				x += stepx;
				y += stepy;
				l -= stepl;
				stepl -= 25;
			}
		}
	} else // the old (white) light code, here for the few people with old
	       // video cards that don't support overbright
	{
		for (int i = 0; i < steps; i++) {

			struct sqr *s = S(x >> PRECBITS, y >> PRECBITS);
			int light = l >> PRECBITS;
			if (light > s->r)
				s->r = s->g = s->b = (uchar)light;
			if (SOLID(s))
				return;
			x += stepx;
146
147
148
149
150
151
152
153
154


155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174

175
176

177
178
179
180
181
182
183
	rndtime();
}

// median filter, smooths out random noise in light and makes it more mipable
void
postlightarea(const struct block *a)
{
	loop(x, a->xs) loop(y, a->ys) // assumes area not on edge of world
	{


		struct sqr *s = S(x + a->x, y + a->y);
#define median(m)                                                            \
	s->m =                                                               \
	    (s->m * 2 + SW(s, 1, 0)->m * 2 + SW(s, 0, 1)->m * 2 +            \
	        SW(s, -1, 0)->m * 2 + SW(s, 0, -1)->m * 2 + SW(s, 1, 1)->m + \
	        SW(s, 1, -1)->m + SW(s, -1, 1)->m + SW(s, -1, -1)->m) /      \
	    14; // median is 4/2/1 instead
		median(r);
		median(g);
		median(b);
	}

	remip(a, 0);
}

void
calclight()
{
	loop(x, ssize) loop(y, ssize)
	{

		struct sqr *s = S(x, y);
		s->r = s->g = s->b = 10;

	}

	for (Entity *e in ents)
		if (e.type == LIGHT)
			calclightsource(e);

	struct block b = { 1, 1, ssize - 2, ssize - 2 };







|
<
>
>
|






|
|
|
|







|
<
>
|
|
>







143
144
145
146
147
148
149
150

151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171

172
173
174
175
176
177
178
179
180
181
182
	rndtime();
}

// median filter, smooths out random noise in light and makes it more mipable
void
postlightarea(const struct block *a)
{
	// assumes area not on edge of world

	for (int x = 0; x < a->xs; x++)
		for (int y = 0; y < a->ys; y++) {
			struct sqr *s = S(x + a->x, y + a->y);
#define median(m)                                                            \
	s->m =                                                               \
	    (s->m * 2 + SW(s, 1, 0)->m * 2 + SW(s, 0, 1)->m * 2 +            \
	        SW(s, -1, 0)->m * 2 + SW(s, 0, -1)->m * 2 + SW(s, 1, 1)->m + \
	        SW(s, 1, -1)->m + SW(s, -1, 1)->m + SW(s, -1, -1)->m) /      \
	    14; // median is 4/2/1 instead
			median(r);
			median(g);
			median(b);
		}

	remip(a, 0);
}

void
calclight()
{
	for (int x = 0; x < ssize; x++) {

		for (int y = 0; y < ssize; y++) {
			struct sqr *s = S(x, y);
			s->r = s->g = s->b = 10;
		}
	}

	for (Entity *e in ents)
		if (e.type == LIGHT)
			calclightsource(e);

	struct block b = { 1, 1, ssize - 2, ssize - 2 };

Modified src/worldocull.m from [8d9314d707] to [504811d94d].

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
	odist = getvar(@"fog") * 1.5f;

	float apitch = (float)fabs(player1.pitch);
	float af = getvar(@"fov") / 2 + apitch / 1.5f + 3;
	float byaw = (player1.yaw - 90 + af) / 360 * PI2;
	float syaw = (player1.yaw - 90 - af) / 360 * PI2;

	loopi(NUMRAYS)
	{
		float angle = i * PI2 / NUMRAYS;
		if ((apitch > 45 // must be bigger if fov>120
		        || (angle < byaw && angle > syaw) ||
		        (angle < byaw - PI2 && angle > syaw - PI2) ||
		        (angle < byaw + PI2 && angle > syaw + PI2)) &&
		    !OUTBORD(vx, vy) &&
		    !SOLID(S(fast_f2nat(vx),







|
<







29
30
31
32
33
34
35
36

37
38
39
40
41
42
43
	odist = getvar(@"fog") * 1.5f;

	float apitch = (float)fabs(player1.pitch);
	float af = getvar(@"fov") / 2 + apitch / 1.5f + 3;
	float byaw = (player1.yaw - 90 + af) / 360 * PI2;
	float syaw = (player1.yaw - 90 - af) / 360 * PI2;

	for (int i = 0; i < NUMRAYS; i++) {

		float angle = i * PI2 / NUMRAYS;
		if ((apitch > 45 // must be bigger if fov>120
		        || (angle < byaw && angle > syaw) ||
		        (angle < byaw - PI2 && angle > syaw - PI2) ||
		        (angle < byaw + PI2 && angle > syaw + PI2)) &&
		    !OUTBORD(vx, vy) &&
		    !SOLID(S(fast_f2nat(vx),

Modified src/worldrender.m from [37acc1d08b] to [ae30288fea].

314
315
316
317
318
319
320

321
322
323
324
325
326
327
328
// does some out of date view frustrum optimisation that doesn't contribute much
// anymore

void
render_world(
    float vx, float vy, float vh, int yaw, int pitch, float fov, int w, int h)
{

	loopi(LARGEST_FACTOR) stats[i] = 0;
	min_lod = MIN_LOD + abs(pitch) / 12;
	yaw = 360 - yaw;
	float widef = fov / 75.0f;
	int cdist = abs(yaw % 90 - 45);
	// hack to avoid popup at high fovs at 45 yaw
	if (cdist < 7) {
		// less if lod worked better







>
|







314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
// does some out of date view frustrum optimisation that doesn't contribute much
// anymore

void
render_world(
    float vx, float vy, float vh, int yaw, int pitch, float fov, int w, int h)
{
	for (int i = 0; i < LARGEST_FACTOR; i++)
		stats[i] = 0;
	min_lod = MIN_LOD + abs(pitch) / 12;
	yaw = 360 - yaw;
	float widef = fov / 75.0f;
	int cdist = abs(yaw % 90 - 45);
	// hack to avoid popup at high fovs at 45 yaw
	if (cdist < 7) {
		// less if lod worked better