Cube  Diff

Differences From Artifact [a098c5d67b]:

To Artifact [9b7cf3b555]:


1
2
3
4
5
6
7
8
9
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
50
51
52
53
54
55
// rendercubes.cpp: sits in between worldrender.cpp and rendergl.cpp and fills
// the vertex array for different cube surfaces.

#include "cube.h"

vertex *verts = NULL;
int curvert;
int curmaxverts = 10000;

void
setarraypointers()
{
	glVertexPointer(3, GL_FLOAT, sizeof(vertex), &verts[0].x);
	glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(vertex), &verts[0].r);
	glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), &verts[0].u);
}

void
reallocv()
{
	verts =
	    (vertex *)OFResizeMemory(verts, (curmaxverts *= 2), sizeof(vertex));
	curmaxverts -= 10;
	setarraypointers();
}

// generating the actual vertices is done dynamically every frame and sits at
// the leaves of all these functions, and are part of the cpu bottleneck on
// really slow machines, hence the macros.

#define vertcheck()                         \
	{                                   \
		if (curvert >= curmaxverts) \
			reallocv();         \
	}

#define vertf(v1, v2, v3, ls, t1, t2)         \
	{                                     \
		vertex &v = verts[curvert++]; \
		v.u = t1;                     \
		v.v = t2;                     \
		v.x = v1;                     \
		v.y = v2;                     \
		v.z = v3;                     \
		v.r = ls->r;                  \
		v.g = ls->g;                  \
		v.b = ls->b;                  \
		v.a = 255;                    \
	}

#define vert(v1, v2, v3, ls, t1, t2)                                      \
	{                                                                 \
		vertf((float)(v1), (float)(v2), (float)(v3), ls, t1, t2); \
	}






|

|




|
|
|






|














|
|
|
|
|
|
|
|
|
|
|
|







1
2
3
4
5
6
7
8
9
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
50
51
52
53
54
55
// rendercubes.cpp: sits in between worldrender.cpp and rendergl.cpp and fills
// the vertex array for different cube surfaces.

#include "cube.h"

static struct vertex *verts = NULL;
int curvert;
static int curmaxverts = 10000;

void
setarraypointers()
{
	glVertexPointer(3, GL_FLOAT, sizeof(struct vertex), &verts[0].x);
	glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(struct vertex), &verts[0].r);
	glTexCoordPointer(2, GL_FLOAT, sizeof(struct vertex), &verts[0].u);
}

void
reallocv()
{
	verts =
	    OFResizeMemory(verts, (curmaxverts *= 2), sizeof(struct vertex));
	curmaxverts -= 10;
	setarraypointers();
}

// generating the actual vertices is done dynamically every frame and sits at
// the leaves of all these functions, and are part of the cpu bottleneck on
// really slow machines, hence the macros.

#define vertcheck()                         \
	{                                   \
		if (curvert >= curmaxverts) \
			reallocv();         \
	}

#define vertf(v1, v2, v3, ls, t1, t2)                 \
	{                                             \
		struct vertex *v = &verts[curvert++]; \
		v->u = t1;                            \
		v->v = t2;                            \
		v->x = v1;                            \
		v->y = v2;                            \
		v->z = v3;                            \
		v->r = ls->r;                         \
		v->g = ls->g;                         \
		v->b = ls->b;                         \
		v->a = 255;                           \
	}

#define vert(v1, v2, v3, ls, t1, t2)                                      \
	{                                                                 \
		vertf((float)(v1), (float)(v2), (float)(v3), ls, t1, t2); \
	}

84
85
86
87
88
89
90
91
92
93

94
95
96
97
98
99
100
101
102
103
	}
void
finishstrips()
{
	stripend();
}

sqr sbright, sdark;
VAR(lighterror, 1, 8, 100);


void
render_flat(int wtex, int x, int y, int size, int h, sqr *l1, sqr *l2, sqr *l3,
    sqr *l4, bool isceil) // floor/ceil quads
{
	vertcheck();
	if (showm) {
		l3 = l1 = &sbright;
		l4 = l2 = &sdark;
	}








|


>

|
|







84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
	}
void
finishstrips()
{
	stripend();
}

static struct sqr sbright, sdark;
VAR(lighterror, 1, 8, 100);

// floor/ceil quads
void
render_flat(int wtex, int x, int y, int size, int h, struct sqr *l1,
    struct sqr *l2, struct sqr *l3, struct sqr *l4, bool isceil)
{
	vertcheck();
	if (showm) {
		l3 = l1 = &sbright;
		l4 = l2 = &sdark;
	}

167
168
169
170
171
172
173

174
175
176
177
178
179
180
181
182
183
184
		vert(x + size, h, y + size, l3, xo + xs, yo + ys);
	}

	oy = y;
	nquads++;
}


void
render_flatdelta(int wtex, int x, int y, int size, float h1, float h2, float h3,
    float h4, sqr *l1, sqr *l2, sqr *l3, sqr *l4,
    bool isceil) // floor/ceil quads on a slope
{
	vertcheck();
	if (showm) {
		l3 = l1 = &sbright;
		l4 = l2 = &sdark;
	}








>


|
|







168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
		vert(x + size, h, y + size, l3, xo + xs, yo + ys);
	}

	oy = y;
	nquads++;
}

// floor/ceil quads on a slope
void
render_flatdelta(int wtex, int x, int y, int size, float h1, float h2, float h3,
    float h4, struct sqr *l1, struct sqr *l2, struct sqr *l3, struct sqr *l4,
    bool isceil)
{
	vertcheck();
	if (showm) {
		l3 = l1 = &sbright;
		l4 = l2 = &sdark;
	}

225
226
227
228
229
230
231

232
233
234
235
236
237
238
239
240
241
		    (float)x + size, h3, (float)y + size, l3, xo + xs, yo + ys);
	}

	oy = y;
	nquads++;
}


void
render_2tris(sqr *h, sqr *s, int x1, int y1, int x2, int y2, int x3, int y3,
    sqr *l1, sqr *l2, sqr *l3) // floor/ceil tris on a corner cube
{
	stripend();
	vertcheck();

	int sx, sy;
	int gltex = lookuptexture(h->ftex, &sx, &sy);
	float xf = TEXTURESCALE / sx;







>

|
|







227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
		    (float)x + size, h3, (float)y + size, l3, xo + xs, yo + ys);
	}

	oy = y;
	nquads++;
}

// floor/ceil tris on a corner cube
void
render_2tris(struct sqr *h, struct sqr *s, int x1, int y1, int x2, int y2,
    int x3, int y3, struct sqr *l1, struct sqr *l2, struct sqr *l3)
{
	stripend();
	vertcheck();

	int sx, sy;
	int gltex = lookuptexture(h->ftex, &sx, &sy);
	float xf = TEXTURESCALE / sx;
254
255
256
257
258
259
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
	vertf((float)x2, h->ceil, (float)y2, l2, xf * x2, yf * y2);
	vertf((float)x1, h->ceil, (float)y1, l1, xf * x1, yf * y1);
	addstrip(gltex, curvert - 3, 3);
	nquads++;
}

void
render_tris(int x, int y, int size, bool topleft, sqr *h1, sqr *h2, sqr *s,
    sqr *t, sqr *u, sqr *v)
{
	if (topleft) {
		if (h1)
			render_2tris(h1, s, x + size, y + size, x, y + size, x,
			    y, u, v, s);
		if (h2)
			render_2tris(h2, s, x, y, x + size, y, x + size,
			    y + size, s, t, v);
	} else {
		if (h1)
			render_2tris(
			    h1, s, x, y, x + size, y, x, y + size, s, t, u);
		if (h2)
			render_2tris(h2, s, x + size, y, x + size, y + size, x,
			    y + size, t, u, v);
	}
}

void
render_square(int wtex, float floor1, float floor2, float ceil1, float ceil2,
    int x1, int y1, int x2, int y2, int size, sqr *l1, sqr *l2,
    bool flip) // wall quads
{
	stripend();
	vertcheck();
	if (showm) {
		l1 = &sbright;
		l2 = &sdark;







|
|




















|







257
258
259
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
	vertf((float)x2, h->ceil, (float)y2, l2, xf * x2, yf * y2);
	vertf((float)x1, h->ceil, (float)y1, l1, xf * x1, yf * y1);
	addstrip(gltex, curvert - 3, 3);
	nquads++;
}

void
render_tris(int x, int y, int size, bool topleft, struct sqr *h1,
    struct sqr *h2, struct sqr *s, struct sqr *t, struct sqr *u, struct sqr *v)
{
	if (topleft) {
		if (h1)
			render_2tris(h1, s, x + size, y + size, x, y + size, x,
			    y, u, v, s);
		if (h2)
			render_2tris(h2, s, x, y, x + size, y, x + size,
			    y + size, s, t, v);
	} else {
		if (h1)
			render_2tris(
			    h1, s, x, y, x + size, y, x, y + size, s, t, u);
		if (h2)
			render_2tris(h2, s, x + size, y, x + size, y + size, x,
			    y + size, t, u, v);
	}
}

void
render_square(int wtex, float floor1, float floor2, float ceil1, float ceil2,
    int x1, int y1, int x2, int y2, int size, struct sqr *l1, struct sqr *l2,
    bool flip) // wall quads
{
	stripend();
	vertcheck();
	if (showm) {
		l1 = &sbright;
		l2 = &sdark;
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330

int wx1, wy1, wx2, wy2;

VAR(watersubdiv, 1, 4, 64);
VARF(waterlevel, -128, -128, 127,
    if (!noteditmode()) hdr.waterlevel = waterlevel);

inline void
vertw(int v1, float v2, int v3, sqr *c, float t1, float t2, float t)
{
	vertcheck();
	vertf((float)v1, v2 - (float)sin(v1 * v3 * 0.1 + t) * 0.2f, (float)v3,
	    c, t1, t2);
}

inline float







|
|







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

int wx1, wy1, wx2, wy2;

VAR(watersubdiv, 1, 4, 64);
VARF(waterlevel, -128, -128, 127,
    if (!noteditmode()) hdr.waterlevel = waterlevel);

static inline void
vertw(int v1, float v2, int v3, struct sqr *c, float t1, float t2, float t)
{
	vertcheck();
	vertf((float)v1, v2 - (float)sin(v1 * v3 * 0.1 + t) * 0.2f, (float)v3,
	    c, t1, t2);
}

inline float
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
	float xf = TEXTURESCALE / sx;
	float yf = TEXTURESCALE / sy;
	float xs = watersubdiv * xf;
	float ys = watersubdiv * yf;
	float t1 = lastmillis / 300.0f;
	float t2 = lastmillis / 4000.0f;

	sqr dl;
	dl.r = dl.g = dl.b = 255;

	for (int xx = wx1; xx < wx2; xx += watersubdiv) {
		for (int yy = wy1; yy < wy2; yy += watersubdiv) {
			float xo = xf * (xx + t2);
			float yo = yf * (yy + t2);
			if (yy == wy1) {







|







362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
	float xf = TEXTURESCALE / sx;
	float yf = TEXTURESCALE / sy;
	float xs = watersubdiv * xf;
	float ys = watersubdiv * yf;
	float t1 = lastmillis / 300.0f;
	float t2 = lastmillis / 4000.0f;

	struct sqr dl;
	dl.r = dl.g = dl.b = 255;

	for (int xx = wx1; xx < wx2; xx += watersubdiv) {
		for (int yy = wy1; yy < wy2; yy += watersubdiv) {
			float xo = xf * (xx + t2);
			float yo = yf * (yy + t2);
			if (yy == wy1) {