Cube  Diff

Differences From Artifact [f5920b6aeb]:

To Artifact [46292a408f]:


10
11
12
13
14
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
// the edge of the map

block sel;

OF_CONSTRUCTOR()
{
	enqueueInit(^{
		sel = (block){
		    variable(@"selx", 0, 0, 4096, &sel.x, NULL, false),
		    variable(@"sely", 0, 0, 4096, &sel.y, NULL, false),
		    variable(@"selxs", 0, 0, 4096, &sel.xs, NULL, false),
		    variable(@"selys", 0, 0, 4096, &sel.ys, NULL, false),
		};
	});
}

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

int cx, cy, ch;

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

bool dragging = false;
int lastx, lasty, lasth;

int lasttype = 0, lasttex = 0;
sqr rtex;








|
|
|
|
|




















|







10
11
12
13
14
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
// the edge of the map

block sel;

OF_CONSTRUCTOR()
{
	enqueueInit(^{
		sel = (block) {
			variable(@"selx", 0, 0, 4096, &sel.x, NULL, false),
			variable(@"sely", 0, 0, 4096, &sel.y, NULL, false),
			variable(@"selxs", 0, 0, 4096, &sel.xs, NULL, false),
			variable(@"selys", 0, 0, 4096, &sel.ys, NULL, false),
		};
	});
}

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

int cx, cy, ch;

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

bool dragging = false;
int lastx, lasty, lasth;

int lasttype = 0, lasttex = 0;
sqr rtex;

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
#define EDITMP                              \
	if (noteditmode() || multiplayer()) \
		return;

void
selectpos(int x, int y, int xs, int ys)
{
	block s = {x, y, xs, ys};
	sel = s;
	selh = 0;
	correctsel();
}

void
makesel()
{
	block s = {min(lastx, cx), min(lasty, cy), abs(lastx - cx) + 1,
	    abs(lasty - cy) + 1};
	sel = s;
	selh = max(lasth, ch);
	correctsel();
	if (selset)
		rtex = *S(sel.x, sel.y);
}








|








|
|







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
#define EDITMP                              \
	if (noteditmode() || multiplayer()) \
		return;

void
selectpos(int x, int y, int xs, int ys)
{
	block s = { x, y, xs, ys };
	sel = s;
	selh = 0;
	correctsel();
}

void
makesel()
{
	block s = { min(lastx, cx), min(lasty, cy), abs(lastx - cx) + 1,
		abs(lasty - cy) + 1 };
	sel = s;
	selh = max(lasth, ch);
	correctsel();
	if (selset)
		rtex = *S(sel.x, sel.y);
}

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
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
	cx = (int)x;
	cy = (int)y;

	if (OUTBORD(cx, cy))
		return;
	sqr *s = S(cx, cy);


	if (fabs(sheight(s, s, z) - z) > 1) // selected wall
	{
		x += x > player1->o.x ? 0.5f : -0.5f; // find right wall cube
		y += y > player1->o.y ? 0.5f : -0.5f;

		cx = (int)x;
		cy = (int)y;

		if (OUTBORD(cx, cy))
			return;
	};


	if (dragging)
		makesel();

	const int GRIDSIZE = 5;
	const float GRIDW = 0.5f;
	const float GRID8 = 2.0f;
	const float GRIDS = 2.0f;
	const int GRIDM = 0x7;

	// render editing grid

	for (int ix = cx - GRIDSIZE; ix <= cx + GRIDSIZE; ix++)
		for (int iy = cy - GRIDSIZE; iy <= cy + GRIDSIZE; iy++) {
			if (OUTBORD(ix, iy))
				continue;
			sqr *s = S(ix, iy);
			if (SOLID(s))
				continue;
			float h1 = sheight(s, s, z);
			float h2 = sheight(s, SWS(s, 1, 0, ssize), z);
			float h3 = sheight(s, SWS(s, 1, 1, ssize), z);
			float h4 = sheight(s, SWS(s, 0, 1, ssize), z);
			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);
			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),
		    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);
	};

}

vector<block *> undos;    // unlimited undo
VARP(undomegs, 0, 1, 10); // bounded by n megs

void
pruneundos(int maxremain) // bound memory







>
|
<








<
>












|
















|










<
>
>




|






<
>




<
>







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
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
	cx = (int)x;
	cy = (int)y;

	if (OUTBORD(cx, cy))
		return;
	sqr *s = S(cx, cy);

	// selected wall
	if (fabs(sheight(s, s, z) - z) > 1) {

		x += x > player1->o.x ? 0.5f : -0.5f; // find right wall cube
		y += y > player1->o.y ? 0.5f : -0.5f;

		cx = (int)x;
		cy = (int)y;

		if (OUTBORD(cx, cy))
			return;

	}

	if (dragging)
		makesel();

	const int GRIDSIZE = 5;
	const float GRIDW = 0.5f;
	const float GRID8 = 2.0f;
	const float GRIDS = 2.0f;
	const int GRIDM = 0x7;

	// render editing grid

	for (int ix = cx - GRIDSIZE; ix <= cx + GRIDSIZE; ix++) {
		for (int iy = cy - GRIDSIZE; iy <= cy + GRIDSIZE; iy++) {
			if (OUTBORD(ix, iy))
				continue;
			sqr *s = S(ix, iy);
			if (SOLID(s))
				continue;
			float h1 = sheight(s, s, z);
			float h2 = sheight(s, SWS(s, 1, 0, ssize), z);
			float h3 = sheight(s, SWS(s, 1, 1, ssize), z);
			float h4 = sheight(s, SWS(s, 0, 1, ssize), z);
			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);
			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),
		    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);

	}
}

vector<block *> undos;    // unlimited undo
VARP(undomegs, 0, 1, 10); // bounded by n megs

void
pruneundos(int maxremain) // bound memory
312
313
314
315
316
317
318
319

320
321
322
323
324
325
326
327
328
329
330
331
332

333
334
335
336
337
338
339
		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;
			curedittex[i] = -1;
		};

	}
}

void
editdrag(bool isdown)
{
	if (dragging = isdown) {
		lastx = cx;
		lasty = cy;
		lasth = ch;
		selset = false;
		tofronttex();
	};

	makesel();
}

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








<
>












<
>







313
314
315
316
317
318
319

320
321
322
323
324
325
326
327
328
329
330
331
332

333
334
335
336
337
338
339
340
		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;
			curedittex[i] = -1;

		}
	}
}

void
editdrag(bool isdown)
{
	if (dragging = isdown) {
		lastx = cx;
		lasty = cy;
		lasth = ch;
		selset = false;
		tofronttex();

	}
	makesel();
}

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

386
387
388
389
390
391
392
393

394
395
396
397
398
399
400
{
	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);







<
>







387
388
389
390
391
392
393

394
395
396
397
398
399
400
401
{
	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);
420
421
422
423
424
425
426
427
428

429
430
431
432
433
434
435
436
			if (s->ctex == rtex.ctex)
				s->ctex = lasttex;
			break;
		case 3:
			if (s->utex == rtex.utex)
				s->utex = lasttex;
			break;
		};
	}

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

void
edittypexy(int type, block &sel)
{
	loopselxy(s->type = type);







<
|
>
|







421
422
423
424
425
426
427

428
429
430
431
432
433
434
435
436
437
			if (s->ctex == rtex.ctex)
				s->ctex = lasttex;
			break;
		case 3:
			if (s->utex == rtex.utex)
				s->utex = lasttex;
			break;

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

void
edittypexy(int type, block &sel)
{
	loopselxy(s->type = type);
522
523
524
525
526
527
528
529

530
531
532
533
534
535
536

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)







<
>







523
524
525
526
527
528
529

530
531
532
533
534
535
536
537

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)
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
}

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;
	loopselxy(s->tag = tag);
}







|







584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
}

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;
	loopselxy(s->tag = tag);
}