Cube  Diff

Differences From Artifact [8eeba4e2ca]:

To Artifact [cc23cfc264]:


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









41
42
43
44
45
46
47
25
26
27
28
29
30
31









32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47







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







		};
	});
}

int selh = 0;
bool selset = false;

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

int cx, cy, ch;

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

bool dragging = false;
204
205
206
207
208
209
210
211

212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228

229
230
231
232
233
234
235
236
237
238

239
240
241
242
243
244
245
204
205
206
207
208
209
210

211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227

228
229
230
231
232
233
234
235
236
237

238
239
240
241
242
243
244
245







-
+
















-
+









-
+







			if (s->tag)
				linestyle(GRIDW, 0xFF, 0x40, 0x40);
			else if (s->type == FHF || s->type == CHF)
				linestyle(GRIDW, 0x80, 0xFF, 0x80);
			else
				linestyle(GRIDW, 0x80, 0x80, 0x80);
			block b = { ix, iy, 1, 1 };
			box(b, h1, h2, h3, h4);
			box(&b, h1, h2, h3, h4);
			linestyle(GRID8, 0x40, 0x40, 0xFF);
			if (!(ix & GRIDM))
				line(ix, iy, h1, ix, iy + 1, h4);
			if (!(ix + 1 & GRIDM))
				line(ix + 1, iy, h2, ix + 1, iy + 1, h3);
			if (!(iy & GRIDM))
				line(ix, iy, h1, ix + 1, iy, h2);
			if (!(iy + 1 & GRIDM))
				line(ix, iy + 1, h4, ix + 1, iy + 1, h3);
		}
	}

	if (!SOLID(s)) {
		float ih = sheight(s, s, z);
		linestyle(GRIDS, 0xFF, 0xFF, 0xFF);
		block b = { cx, cy, 1, 1 };
		box(b, ih, sheight(s, SWS(s, 1, 0, ssize), z),
		box(&b, ih, sheight(s, SWS(s, 1, 0, ssize), z),
		    sheight(s, SWS(s, 1, 1, ssize), z),
		    sheight(s, SWS(s, 0, 1, ssize), z));
		linestyle(GRIDS, 0xFF, 0x00, 0x00);
		dot(cx, cy, ih);
		ch = (int)ih;
	}

	if (selset) {
		linestyle(GRIDS, 0xFF, 0x40, 0x40);
		box(sel, (float)selh, (float)selh, (float)selh, (float)selh);
		box(&sel, (float)selh, (float)selh, (float)selh, (float)selh);
	}
}

static OFMutableData *undos; // unlimited undo
VARP(undomegs, 0, 1, 10);    // bounded by n megs

void
260
261
262
263
264
265
266
267

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

283
284
285
286
287
288
289
290
291
292
293
294

295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315

316
317
318
319
320
321
322
260
261
262
263
264
265
266

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

282
283
284
285
286
287
288
289
290
291
292
293

294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314

315
316
317
318
319
320
321
322







-
+














-
+











-
+




















-
+







void
makeundo()
{
	if (undos == nil)
		undos =
		    [[OFMutableData alloc] initWithItemSize:sizeof(block *)];

	block *copy = blockcopy(sel);
	block *copy = blockcopy(&sel);
	[undos addItem:&copy];
	pruneundos(undomegs << 20);
}

void
editundo()
{
	EDITMP;
	if (undos.count == 0) {
		conoutf(@"nothing more to undo");
		return;
	}
	block *p = *(block **)undos.lastItem;
	[undos removeLastItem];
	blockpaste(*p);
	blockpaste(p);
	OFFreeMemory(p);
}

block *copybuf = NULL;

void
copy()
{
	EDITSELMP;
	if (copybuf)
		OFFreeMemory(copybuf);
	copybuf = blockcopy(sel);
	copybuf = blockcopy(&sel);
}

void
paste()
{
	EDITMP;
	if (!copybuf) {
		conoutf(@"nothing to paste");
		return;
	}
	sel.xs = copybuf->xs;
	sel.ys = copybuf->ys;
	correctsel();
	if (!selset || sel.xs != copybuf->xs || sel.ys != copybuf->ys) {
		conoutf(@"incorrect selection");
		return;
	}
	makeundo();
	copybuf->x = sel.x;
	copybuf->y = sel.y;
	blockpaste(*copybuf);
	blockpaste(copybuf);
}

void
tofronttex() // maintain most recently used of the texture lists when applying
             // texture
{
	loopi(3)
347
348
349
350
351
352
353
354

355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373

374
375
376
377
378
379

380
381
382
383
384
385
386
347
348
349
350
351
352
353

354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372

373
374
375
376
377
378

379
380
381
382
383
384
385
386







-
+


















-
+





-
+







}

// the core editing function. all the *xy functions perform the core operations
// and are also called directly from the network, the function below it is
// strictly triggered locally. They all have very similar structure.

void
editheightxy(bool isfloor, int amount, block &sel)
editheightxy(bool isfloor, int amount, const block *sel)
{
	loopselxy(
	    if (isfloor) {
		    s->floor += amount;
		    if (s->floor >= s->ceil)
			    s->floor = s->ceil - 1;
	    } else {
		    s->ceil += amount;
		    if (s->ceil <= s->floor)
			    s->ceil = s->floor + 1;
	    });
}

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

void
edittexxy(int type, int t, block &sel)
edittexxy(int type, int t, const block *sel)
{
	loopselxy(switch (type) {
	        case 0:
		        s->ftex = t;
		        break;
	        case 1:
		        s->wtex = t;
405
406
407
408
409
410
411
412

413
414
415
416
417
418
419
405
406
407
408
409
410
411

412
413
414
415
416
417
418
419







-
+







		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);
	edittexxy(type, t, &sel);
	addmsg(1, 7, SV_EDITT, sel.x, sel.y, sel.xs, sel.ys, type, t);
}

void
replace()
{
	EDITSELMP;
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
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







-
+



-
+














-
+







		case 3:
			if (s->utex == rtex.utex)
				s->utex = lasttex;
			break;
		}
	}
	block b = { 0, 0, ssize, ssize };
	remip(b);
	remip(&b);
}

void
edittypexy(int type, block &sel)
edittypexy(int type, const 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);
	edittypexy(type, &sel);
	addmsg(1, 6, SV_EDITS, sel.x, sel.y, sel.xs, sel.ys, type);
}

void
heightfield(int t)
{
	edittype(t == 0 ? FHF : CHF);
481
482
483
484
485
486
487
488

489
490
491
492
493
494
495
481
482
483
484
485
486
487

488
489
490
491
492
493
494
495







-
+







corner()
{
	edittype(CORNER);
}
COMMAND(corner, ARG_NONE)

void
editequalisexy(bool isfloor, block &sel)
editequalisexy(bool isfloor, const block *sel)
{
	int low = 127, hi = -128;
	loopselxy({
		if (s->floor < low)
			low = s->floor;
		if (s->ceil > hi)
			hi = s->ceil;
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
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







-
+





-
+









-
+







}

void
equalize(int flr)
{
	bool isfloor = flr == 0;
	EDITSEL;
	editequalisexy(isfloor, sel);
	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, block &sel)
setvdeltaxy(int delta, const block *sel)
{
	loopselxy(s->vdelta = max(s->vdelta + delta, 0));
	remipmore(sel);
}

void
setvdelta(int delta)
{
	EDITSEL;
	setvdeltaxy(delta, sel);
	setvdeltaxy(delta, &sel);
	addmsg(1, 6, SV_EDITD, sel.x, sel.y, sel.xs, sel.ys, delta);
}

const int MAXARCHVERT = 50;
int archverts[MAXARCHVERT][MAXARCHVERT];
bool archvinit = false;

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







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














+
+
+













-
+


-
+















+
+
+







	EDITSELMP;
	sel.xs++;
	sel.ys++;
	if (sel.xs > MAXARCHVERT)
		sel.xs = MAXARCHVERT;
	if (sel.ys > MAXARCHVERT)
		sel.ys = MAXARCHVERT;
	block *sel_ = &sel;
	// Ugly hack to make the macro work.
	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)));
	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);
}

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++;
	block *sel_ = &sel;
	// Ugly hack to make the macro work.
	block *sel = sel_;
	loopselxy(s->vdelta = xd * x + yd * y + off);
	remipmore(sel);
}

void
perlin(int scale, int seed, int psize)
{
	EDITSELMP;
	sel.xs++;
	sel.ys++;
	makeundo();
	sel.xs--;
	sel.ys--;
	perlinarea(sel, scale, seed, psize);
	perlinarea(&sel, scale, seed, psize);
	sel.xs++;
	sel.ys++;
	remipmore(sel);
	remipmore(&sel);
	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;
	block *sel_ = &sel;
	// Ugly hack to make the macro work.
	block *sel = sel_;
	loopselxy(s->tag = tag);
}

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