︙ | | | ︙ | |
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
{
if (SOLID(o) || o->type == SEMISOLID) {
float c1 = s->floor;
float c2 = s->floor;
if (s->type == FHF) {
c1 -= d1->vdelta / 4.0f;
c2 -= d2->vdelta / 4.0f;
};
float f1 = s->ceil;
float f2 = s->ceil;
if (s->type == CHF) {
f1 += d1->vdelta / 4.0f;
f2 += d2->vdelta / 4.0f;
};
// if(f1-c1<=0 && f2-c2<=0) return;
render_square(o->wtex, c1, c2, f1, f2, x1 << mip, y1 << mip,
x2 << mip, y2 << mip, 1 << mip, d1, d2, topleft);
return;
};
{
float f1 = s->floor;
float f2 = s->floor;
float c1 = o->floor;
float c2 = o->floor;
if (o->type == FHF && s->type != FHF) {
c1 -= d1->vdelta / 4.0f;
c2 -= d2->vdelta / 4.0f;
}
if (s->type == FHF && o->type != FHF) {
f1 -= d1->vdelta / 4.0f;
f2 -= d2->vdelta / 4.0f;
}
if (f1 >= c1 && f2 >= c2)
goto skip;
render_square(o->wtex, f1, f2, c1, c2, x1 << mip, y1 << mip,
x2 << mip, y2 << mip, 1 << mip, d1, d2, topleft);
};
skip: {
float f1 = o->ceil;
float f2 = o->ceil;
float c1 = s->ceil;
float c2 = s->ceil;
if (o->type == CHF && s->type != CHF) {
f1 += d1->vdelta / 4.0f;
f2 += d2->vdelta / 4.0f;
} else if (s->type == CHF && o->type != CHF) {
c1 += d1->vdelta / 4.0f;
c2 += d2->vdelta / 4.0f;
}
if (c1 <= f1 && c2 <= f2)
return;
render_square(o->utex, f1, f2, c1, c2, x1 << mip, y1 << mip, x2 << mip,
y2 << mip, 1 << mip, d1, d2, topleft);
};
}
const int MAX_MIP = 5; // 32x32 unit blocks
const int MIN_LOD = 2;
const int LOW_LOD = 25;
const int MAX_LOD = 1000;
|
<
>
<
>
<
>
<
>
<
>
|
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
{
if (SOLID(o) || o->type == SEMISOLID) {
float c1 = s->floor;
float c2 = s->floor;
if (s->type == FHF) {
c1 -= d1->vdelta / 4.0f;
c2 -= d2->vdelta / 4.0f;
}
float f1 = s->ceil;
float f2 = s->ceil;
if (s->type == CHF) {
f1 += d1->vdelta / 4.0f;
f2 += d2->vdelta / 4.0f;
}
// if(f1-c1<=0 && f2-c2<=0) return;
render_square(o->wtex, c1, c2, f1, f2, x1 << mip, y1 << mip,
x2 << mip, y2 << mip, 1 << mip, d1, d2, topleft);
return;
}
{
float f1 = s->floor;
float f2 = s->floor;
float c1 = o->floor;
float c2 = o->floor;
if (o->type == FHF && s->type != FHF) {
c1 -= d1->vdelta / 4.0f;
c2 -= d2->vdelta / 4.0f;
}
if (s->type == FHF && o->type != FHF) {
f1 -= d1->vdelta / 4.0f;
f2 -= d2->vdelta / 4.0f;
}
if (f1 >= c1 && f2 >= c2)
goto skip;
render_square(o->wtex, f1, f2, c1, c2, x1 << mip, y1 << mip,
x2 << mip, y2 << mip, 1 << mip, d1, d2, topleft);
}
skip: {
float f1 = o->ceil;
float f2 = o->ceil;
float c1 = s->ceil;
float c2 = s->ceil;
if (o->type == CHF && s->type != CHF) {
f1 += d1->vdelta / 4.0f;
f2 += d2->vdelta / 4.0f;
} else if (s->type == CHF && o->type != CHF) {
c1 += d1->vdelta / 4.0f;
c2 += d2->vdelta / 4.0f;
}
if (c1 <= f1 && c2 <= f2)
return;
render_square(o->utex, f1, f2, c1, c2, x1 << mip, y1 << mip, x2 << mip,
y2 << mip, 1 << mip, d1, d2, topleft);
}
}
const int MAX_MIP = 5; // 32x32 unit blocks
const int MIN_LOD = 2;
const int LOW_LOD = 25;
const int MAX_LOD = 1000;
|
︙ | | | ︙ | |
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
|
if (issemi(mip, x + x1, y + y1, x1, y1, x2, y2))
return true;
case CORNER:
case SOLID:
break;
default:
return true;
};
switch (SWS(w, x + x2, y + y2, msize)->type) {
case SEMISOLID:
if (issemi(mip, x + x2, y + y2, x1, y1, x2, y2))
return true;
case CORNER:
case SOLID:
break;
default:
return true;
};
return false;
}
bool render_floor, render_ceil;
// the core recursive function, renders a rect of cubes at a certain mip level
// from a viewer perspective call itself for lower mip levels, on most modern
|
<
>
<
>
|
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
|
if (issemi(mip, x + x1, y + y1, x1, y1, x2, y2))
return true;
case CORNER:
case SOLID:
break;
default:
return true;
}
switch (SWS(w, x + x2, y + y2, msize)->type) {
case SEMISOLID:
if (issemi(mip, x + x2, y + y2, x1, y1, x2, y2))
return true;
case CORNER:
case SOLID:
break;
default:
return true;
}
return false;
}
bool render_floor, render_ceil;
// the core recursive function, renders a rect of cubes at a certain mip level
// from a viewer perspective call itself for lower mip levels, on most modern
|
︙ | | | ︙ | |
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
|
vxx - lodleft; // these mark the rect inside the current rest that
// we want to render using a lower mip level
int ly = vyy - lodtop;
int rx = vxx + lodright;
int ry = vyy + lodbot;
float fsize = (float)(1 << mip);
for (int ox = x; ox < xs; ox++)
for (int oy = y; oy < ys;
oy++) // first collect occlusion information for this block
{
SWS(w, ox, oy, sz)->occluded =
isoccluded(player1->o.x, player1->o.y,
(float)(ox << mip), (float)(oy << mip), fsize);
};
int pvx = (int)vx >> mip;
int pvy = (int)vy >> mip;
if (pvx >= 0 && pvy >= 0 && pvx < sz && pvy < sz) {
// SWS(w,vxx,vyy,sz)->occluded = 0;
SWS(w, pvx, pvy, sz)->occluded =
0; // player cell never occluded
};
#define df(x) s->floor - (x->vdelta / 4.0f)
#define dc(x) s->ceil + (x->vdelta / 4.0f)
// loop through the rect 3 times (for floor/ceil/walls seperately, to
// facilitate dynamic stripify) for each we skip occluded cubes
// (occlusion at higher mip levels is a big time saver!). during the
|
|
<
|
<
>
<
>
>
<
>
|
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
|
vxx - lodleft; // these mark the rect inside the current rest that
// we want to render using a lower mip level
int ly = vyy - lodtop;
int rx = vxx + lodright;
int ry = vyy + lodbot;
float fsize = (float)(1 << mip);
for (int ox = x; ox < xs; ox++) {
// first collect occlusion information for this block
for (int oy = y; oy < ys; oy++) {
SWS(w, ox, oy, sz)->occluded =
isoccluded(player1->o.x, player1->o.y,
(float)(ox << mip), (float)(oy << mip), fsize);
}
}
int pvx = (int)vx >> mip;
int pvy = (int)vy >> mip;
if (pvx >= 0 && pvy >= 0 && pvx < sz && pvy < sz) {
// SWS(w,vxx,vyy,sz)->occluded = 0;
SWS(w, pvx, pvy, sz)->occluded =
0; // player cell never occluded
}
#define df(x) s->floor - (x->vdelta / 4.0f)
#define dc(x) s->ceil + (x->vdelta / 4.0f)
// loop through the rect 3 times (for floor/ceil/walls seperately, to
// facilitate dynamic stripify) for each we skip occluded cubes
// (occlusion at higher mip levels is a big time saver!). during the
|
︙ | | | ︙ | |
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
|
render_flat(s->ctex, xx << mip, yy << mip, 1 << mip, s->ceil, s,
t, u, v, true);
if (s->type == CHF) // if(s->ceil>=vh)
render_flatdelta(s->ctex, xx << mip, yy << mip, 1 << mip, dc(s),
dc(t), dc(u), dc(v), s, t, u, v, true);
}
}
;
LOOPH continue; // floors
LOOPD
if ((s->type == SPACE || s->type == CHF) && s->floor <= vh && render_floor) {
render_flat(s->ftex, xx << mip, yy << mip, 1 << mip, s->floor, s, t, u,
v, false);
if (s->floor < hdr.waterlevel && !SOLID(s))
addwaterquad(xx << mip, yy << mip, 1 << mip);
};
if (s->type == FHF) {
render_flatdelta(s->ftex, xx << mip, yy << mip, 1 << mip, df(s), df(t),
df(u), df(v), s, t, u, v, false);
if (s->floor - s->vdelta / 4.0f < hdr.waterlevel && !SOLID(s))
addwaterquad(xx << mip, yy << mip, 1 << mip);
};
}
}
;
LOOPH continue; // walls
LOOPD
// w
// zSt
// vu
|
<
<
>
<
<
>
|
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
|
render_flat(s->ctex, xx << mip, yy << mip, 1 << mip, s->ceil, s,
t, u, v, true);
if (s->type == CHF) // if(s->ceil>=vh)
render_flatdelta(s->ctex, xx << mip, yy << mip, 1 << mip, dc(s),
dc(t), dc(u), dc(v), s, t, u, v, true);
}
}
LOOPH continue; // floors
LOOPD
if ((s->type == SPACE || s->type == CHF) && s->floor <= vh && render_floor) {
render_flat(s->ftex, xx << mip, yy << mip, 1 << mip, s->floor, s, t, u,
v, false);
if (s->floor < hdr.waterlevel && !SOLID(s))
addwaterquad(xx << mip, yy << mip, 1 << mip);
}
if (s->type == FHF) {
render_flatdelta(s->ftex, xx << mip, yy << mip, 1 << mip, df(s), df(t),
df(u), df(v), s, t, u, v, false);
if (s->floor - s->vdelta / 4.0f < hdr.waterlevel && !SOLID(s))
addwaterquad(xx << mip, yy << mip, 1 << mip);
}
}
}
LOOPH continue; // walls
LOOPD
// w
// zSt
// vu
|
︙ | | | ︙ | |
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
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
|
if (SOLID(w)) {
render_wall(w, h2 = s, xx + 1, yy, xx, yy + 1, mip, t,
v, false);
topleft = false;
} else if (SOLID(v)) {
render_wall(v, h2 = s, xx, yy, xx + 1, yy + 1, mip, s,
u, false);
};
} else if (SOLID(t)) {
if (SOLID(w)) {
render_wall(w, h1 = s, xx + 1, yy + 1, xx, yy, mip, u,
s, false);
} else if (SOLID(v)) {
render_wall(v, h1 = s, xx, yy + 1, xx + 1, yy, mip, v,
t, false);
topleft = false;
};
} else {
normalwall = false;
bool wv = w->ceil - w->floor < v->ceil - v->floor;
if (z->ceil - z->floor < t->ceil - t->floor) {
if (wv) {
render_wall(h1 = s, h2 = v, xx + 1, yy, xx,
yy + 1, mip, t, v, false);
topleft = false;
} else {
render_wall(h1 = s, h2 = w, xx, yy, xx + 1,
yy + 1, mip, s, u, false);
};
} else {
if (wv) {
render_wall(h2 = s, h1 = v, xx + 1, yy + 1, xx,
yy, mip, u, s, false);
} else {
render_wall(h2 = s, h1 = w, xx, yy + 1, xx + 1,
yy, mip, v, t, false);
topleft = false;
};
};
};
render_tris(
xx << mip, yy << mip, 1 << mip, topleft, h1, h2, s, t, u, v);
}
if (normalwall) {
bool inner = xx != sz - 1 && yy != sz - 1;
|
<
>
<
>
<
>
<
<
<
>
>
>
|
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
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
|
if (SOLID(w)) {
render_wall(w, h2 = s, xx + 1, yy, xx, yy + 1, mip, t,
v, false);
topleft = false;
} else if (SOLID(v)) {
render_wall(v, h2 = s, xx, yy, xx + 1, yy + 1, mip, s,
u, false);
}
} else if (SOLID(t)) {
if (SOLID(w)) {
render_wall(w, h1 = s, xx + 1, yy + 1, xx, yy, mip, u,
s, false);
} else if (SOLID(v)) {
render_wall(v, h1 = s, xx, yy + 1, xx + 1, yy, mip, v,
t, false);
topleft = false;
}
} else {
normalwall = false;
bool wv = w->ceil - w->floor < v->ceil - v->floor;
if (z->ceil - z->floor < t->ceil - t->floor) {
if (wv) {
render_wall(h1 = s, h2 = v, xx + 1, yy, xx,
yy + 1, mip, t, v, false);
topleft = false;
} else {
render_wall(h1 = s, h2 = w, xx, yy, xx + 1,
yy + 1, mip, s, u, false);
}
} else {
if (wv) {
render_wall(h2 = s, h1 = v, xx + 1, yy + 1, xx,
yy, mip, u, s, false);
} else {
render_wall(h2 = s, h1 = w, xx, yy + 1, xx + 1,
yy, mip, v, t, false);
topleft = false;
}
}
}
render_tris(
xx << mip, yy << mip, 1 << mip, topleft, h1, h2, s, t, u, v);
}
if (normalwall) {
bool inner = xx != sz - 1 && yy != sz - 1;
|
︙ | | | ︙ | |
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
|
(!SOLID(s) || w->type != CORNER) &&
(w->type != SEMISOLID || issemi(mip, xx, yy - 1, 0, 1, 1, 1)))
render_wall(s, w, xx, yy, xx + 1, yy, mip, s, t, false);
if (yy <= vyy && inner && !SOLID(v) &&
(!SOLID(s) || v->type != CORNER) &&
(v->type != SEMISOLID || issemi(mip, xx, yy + 1, 0, 0, 1, 0)))
render_wall(s, v, xx, yy + 1, xx + 1, yy + 1, mip, v, u, true);
};
}
}
;
}
;
void
distlod(int &low, int &high, int angle, float widef)
{
float f = 90.0f / lod / widef;
low = (int)((90 - angle) / f);
high = (int)(angle / f);
|
<
<
<
>
|
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
|
(!SOLID(s) || w->type != CORNER) &&
(w->type != SEMISOLID || issemi(mip, xx, yy - 1, 0, 1, 1, 1)))
render_wall(s, w, xx, yy, xx + 1, yy, mip, s, t, false);
if (yy <= vyy && inner && !SOLID(v) &&
(!SOLID(s) || v->type != CORNER) &&
(v->type != SEMISOLID || issemi(mip, xx, yy + 1, 0, 0, 1, 0)))
render_wall(s, v, xx, yy + 1, xx + 1, yy + 1, mip, v, u, true);
}
}
}
}
void
distlod(int &low, int &high, int angle, float widef)
{
float f = 90.0f / lod / widef;
low = (int)((90 - angle) / f);
high = (int)(angle / f);
|
︙ | | | ︙ | |
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
348
349
350
351
352
353
354
355
356
357
358
359
|
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);
if (cdist < 7) // hack to avoid popup at high fovs at 45 yaw
{
min_lod = max(min_lod,
(int)(MIN_LOD +
(10 - cdist) / 1.0f *
widef)); // less if lod worked better
widef = 1.0f;
};
lod = MAX_LOD;
lodtop = lodbot = lodleft = lodright = min_lod;
if (yaw > 45 && yaw <= 135) {
lodleft = lod;
distlod(lodtop, lodbot, yaw - 45, widef);
} else if (yaw > 135 && yaw <= 225) {
lodbot = lod;
distlod(lodleft, lodright, yaw - 135, widef);
} else if (yaw > 225 && yaw <= 315) {
lodright = lod;
distlod(lodbot, lodtop, yaw - 225, widef);
} else {
lodtop = lod;
distlod(
lodright, lodleft, yaw <= 45 ? yaw + 45 : yaw - 315, widef);
};
float hyfov = fov * h / w / 2;
render_floor = pitch < hyfov;
render_ceil = -pitch < hyfov;
render_seg_new(
vx, vy, vh, MAX_MIP, 0, 0, ssize >> MAX_MIP, ssize >> MAX_MIP);
mipstats(stats[0], stats[1], stats[2]);
}
|
|
<
>
>
|
<
|
<
<
>
<
>
|
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
348
349
350
351
352
353
354
|
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
min_lod =
max(min_lod, (int)(MIN_LOD + (10 - cdist) / 1.0f * widef));
widef = 1.0f;
}
lod = MAX_LOD;
lodtop = lodbot = lodleft = lodright = min_lod;
if (yaw > 45 && yaw <= 135) {
lodleft = lod;
distlod(lodtop, lodbot, yaw - 45, widef);
} else if (yaw > 135 && yaw <= 225) {
lodbot = lod;
distlod(lodleft, lodright, yaw - 135, widef);
} else if (yaw > 225 && yaw <= 315) {
lodright = lod;
distlod(lodbot, lodtop, yaw - 225, widef);
} else {
lodtop = lod;
distlod(
lodright, lodleft, yaw <= 45 ? yaw + 45 : yaw - 315, widef);
}
float hyfov = fov * h / w / 2;
render_floor = pitch < hyfov;
render_ceil = -pitch < hyfov;
render_seg_new(
vx, vy, vh, MAX_MIP, 0, 0, ssize >> MAX_MIP, ssize >> MAX_MIP);
mipstats(stats[0], stats[1], stats[2]);
}
|