︙ | | | ︙ | |
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
|
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); \
}
int nquads;
const float TEXTURESCALE = 32.0f;
bool floorstrip = false, deltastrip = false;
int oh, oy, ox, ogltex; // the o* vars are used by the stripification
int ol3r, ol3g, ol3b, ol4r, ol4g, ol4b;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
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); \
}
int nquads;
const float TEXTURESCALE = 32.0f;
bool floorstrip = false, deltastrip = false;
int oh, oy, ox, ogltex; // the o* vars are used by the stripification
int ol3r, ol3g, ol3b, ol4r, ol4g, ol4b;
|
︙ | | | ︙ | |
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
|
void
mipstats(int a, int b, int c)
{
if (showm)
conoutf(@"1x1/2x2/4x4: %d / %d / %d", a, b, c);
}
#define stripend() \
{ \
if (floorstrip || deltastrip) { \
addstrip(ogltex, firstindex, curvert - firstindex); \
floorstrip = deltastrip = false; \
}; \
};
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
|
|
|
|
|
|
|
<
>
|
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
|
void
mipstats(int a, int b, int c)
{
if (showm)
conoutf(@"1x1/2x2/4x4: %d / %d / %d", a, b, c);
}
#define stripend() \
{ \
if (floorstrip || deltastrip) { \
addstrip(ogltex, firstindex, curvert - firstindex); \
floorstrip = deltastrip = false; \
}; \
};
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
|
︙ | | | ︙ | |
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
float yf = TEXTURESCALE / sy;
float xs = size * xf;
float ys = size * yf;
float xo = xf * x;
float yo = yf * y;
bool first = !floorstrip || y != oy + size || ogltex != gltex ||
h != oh || x != ox;
if (first) // start strip here
{
stripend();
firstindex = curvert;
ogltex = gltex;
oh = h;
|
|
|
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
float yf = TEXTURESCALE / sy;
float xs = size * xf;
float ys = size * yf;
float xo = xf * x;
float yo = yf * y;
bool first = !floorstrip || y != oy + size || ogltex != gltex ||
h != oh || x != ox;
if (first) // start strip here
{
stripend();
firstindex = curvert;
ogltex = gltex;
oh = h;
|
︙ | | | ︙ | |
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
} else {
vert(x, h, y + size, l4, xo, yo + ys);
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();
|
<
>
|
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
} else {
vert(x, h, y + size, l4, xo, yo + ys);
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();
|
︙ | | | ︙ | |
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
vertf((float)x, h4, (float)y + size, l4, xo, yo + ys);
vertf(
(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();
|
<
>
|
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
vertf((float)x, h4, (float)y + size, l4, xo, yo + ys);
vertf(
(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();
|
︙ | | | ︙ | |
252
253
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
|
yf = TEXTURESCALE / sy;
vertf((float)x3, h->ceil, (float)y3, l3, xf * x3, yf * y3);
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();
|
<
>
<
>
|
252
253
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
|
yf = TEXTURESCALE / sy;
vertf((float)x3, h->ceil, (float)y3, l3, xf * x3, yf * y3);
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();
|
︙ | | | ︙ | |
308
309
310
311
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
340
341
342
343
344
345
346
347
|
vertf((float)x2, ceil2, (float)y2, l2, xo + xs, -yf * ceil2);
vertf((float)x1, floor1, (float)y1, l1, xo, -floor1 * yf);
vertf((float)x2, floor2, (float)y2, l2, xo + xs, -floor2 * yf);
};
nquads++;
addstrip(gltex, curvert - 4, 4);
};
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
dx(float x)
{
return x + (float)sin(x * 2 + lastmillis / 1000.0f) * 0.04f;
};
inline float
dy(float x)
{
return x + (float)sin(x * 2 + lastmillis / 900.0f + PI / 5) * 0.05f;
};
// renders water for bounding rect area that contains water... simple but very
// inefficient
int
renderwater(float hf)
{
|
<
>
<
>
<
>
<
>
|
308
309
310
311
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
340
341
342
343
344
345
346
347
|
vertf((float)x2, ceil2, (float)y2, l2, xo + xs, -yf * ceil2);
vertf((float)x1, floor1, (float)y1, l1, xo, -floor1 * yf);
vertf((float)x2, floor2, (float)y2, l2, xo + xs, -floor2 * yf);
};
nquads++;
addstrip(gltex, curvert - 4, 4);
}
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
dx(float x)
{
return x + (float)sin(x * 2 + lastmillis / 1000.0f) * 0.04f;
}
inline float
dy(float x)
{
return x + (float)sin(x * 2 + lastmillis / 900.0f + PI / 5) * 0.05f;
}
// renders water for bounding rect area that contains water... simple but very
// inefficient
int
renderwater(float hf)
{
|
︙ | | | ︙ | |
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
|
glDrawArrays(GL_TRIANGLE_STRIP, curvert -= n, n);
};
glDisable(GL_BLEND);
glDepthMask(GL_TRUE);
return nquads;
};
void
addwaterquad(int x, int y, int size) // update bounding rect that contains water
{
int x2 = x + size;
int y2 = y + size;
if (wx1 < 0) {
|
<
>
|
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
|
glDrawArrays(GL_TRIANGLE_STRIP, curvert -= n, n);
};
glDisable(GL_BLEND);
glDepthMask(GL_TRUE);
return nquads;
}
void
addwaterquad(int x, int y, int size) // update bounding rect that contains water
{
int x2 = x + size;
int y2 = y + size;
if (wx1 < 0) {
|
︙ | | | ︙ | |
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
|
if (y < wy1)
wy1 = y;
if (x2 > wx2)
wx2 = x2;
if (y2 > wy2)
wy2 = y2;
};
};
void
resetcubes()
{
if (!verts)
reallocv();
floorstrip = deltastrip = false;
wx1 = -1;
nquads = 0;
sbright.r = sbright.g = sbright.b = 255;
sdark.r = sdark.g = sdark.b = 0;
};
|
<
>
<
>
|
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
|
if (y < wy1)
wy1 = y;
if (x2 > wx2)
wx2 = x2;
if (y2 > wy2)
wy2 = y2;
};
}
void
resetcubes()
{
if (!verts)
reallocv();
floorstrip = deltastrip = false;
wx1 = -1;
nquads = 0;
sbright.r = sbright.g = sbright.b = 255;
sdark.r = sdark.g = sdark.b = 0;
}
|