| 1 |
/* Emacs style mode select -*- C -*- |
| 2 |
*----------------------------------------------------------------------------- |
| 3 |
* |
| 4 |
* |
| 5 |
* PrBoom: a Doom port merged with LxDoom and LSDLDoom |
| 6 |
* based on BOOM, a modified and improved DOOM engine |
| 7 |
* Copyright (C) 1999 by |
| 8 |
* id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman |
| 9 |
* Copyright (C) 1999-2000 by |
| 10 |
* Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze |
| 11 |
* Copyright 2005, 2006 by |
| 12 |
* Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko |
| 13 |
* |
| 14 |
* This program is free software; you can redistribute it and/or |
| 15 |
* modify it under the terms of the GNU General Public License |
| 16 |
* as published by the Free Software Foundation; either version 2 |
| 17 |
* of the License, or (at your option) any later version. |
| 18 |
* |
| 19 |
* This program is distributed in the hope that it will be useful, |
| 20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 |
* GNU General Public License for more details. |
| 23 |
* |
| 24 |
* You should have received a copy of the GNU General Public License |
| 25 |
* along with this program; if not, write to the Free Software |
| 26 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 27 |
* 02111-1307, USA. |
| 28 |
* |
| 29 |
* DESCRIPTION: |
| 30 |
* BSP traversal, handling of LineSegs for rendering. |
| 31 |
* |
| 32 |
*-----------------------------------------------------------------------------*/ |
| 33 |
|
| 34 |
#include "doomstat.h" |
| 35 |
#include "m_bbox.h" |
| 36 |
#include "p_spec.h" |
| 37 |
#include "r_main.h" |
| 38 |
#include "r_segs.h" |
| 39 |
#include "r_plane.h" |
| 40 |
#include "r_things.h" |
| 41 |
#include "r_bsp.h" // cph - sanity checking |
| 42 |
#include "v_video.h" |
| 43 |
#include "lprintf.h" |
| 44 |
|
| 45 |
// Turned off because it causes regressions on some maps (issue #256). Fixing |
| 46 |
// this requires doing bleed with subsector granularity. |
| 47 |
#define EXPERIMENTAL_BLEED 0 |
| 48 |
// Threshold below player view of sector floor at which it becomes |
| 49 |
// subject to flat bleeding, in addition to the case of it being |
| 50 |
// above the player view. |
| 51 |
// FIXME: the number probably needs tweaking, and is |
| 52 |
// an approximation of software rendering behavior. Presumably |
| 53 |
// bleedthrough normally occurs when the sector's floor is so |
| 54 |
// low that it is completely occluded from the current view. |
| 55 |
#define FLOOR_BLEED_THRESHOLD 400 |
| 56 |
// Same, but for ceiling |
| 57 |
#define CEILING_BLEED_THRESHOLD 400 |
| 58 |
|
| 59 |
int currentsubsectornum; |
| 60 |
|
| 61 |
seg_t *curline; |
| 62 |
side_t *sidedef; |
| 63 |
line_t *linedef; |
| 64 |
sector_t *frontsector; |
| 65 |
sector_t *backsector; |
| 66 |
sector_t *poly_frontsector; |
| 67 |
dboolean poly_add_line; |
| 68 |
drawseg_t *ds_p; |
| 69 |
|
| 70 |
// killough 4/7/98: indicates doors closed wrt automap bugfix: |
| 71 |
// cph - replaced by linedef rendering flags - int doorclosed; |
| 72 |
|
| 73 |
// killough: New code which removes 2s linedef limit |
| 74 |
drawseg_t *drawsegs; |
| 75 |
unsigned maxdrawsegs; |
| 76 |
// drawseg_t drawsegs[MAXDRAWSEGS]; // old code -- killough |
| 77 |
|
| 78 |
// |
| 79 |
// R_ClearDrawSegs |
| 80 |
// |
| 81 |
|
| 82 |
void R_ClearDrawSegs(void) |
| 83 |
{ |
| 84 |
ds_p = drawsegs; |
| 85 |
} |
| 86 |
|
| 87 |
// CPhipps - |
| 88 |
// Instead of clipsegs, let's try using an array with one entry for each column, |
| 89 |
// indicating whether it's blocked by a solid wall yet or not. |
| 90 |
|
| 91 |
// e6y: resolution limitation is removed |
| 92 |
byte *solidcol; |
| 93 |
|
| 94 |
// CPhipps - |
| 95 |
// R_ClipWallSegment |
| 96 |
// |
| 97 |
// Replaces the old R_Clip*WallSegment functions. It draws bits of walls in those |
| 98 |
// columns which aren't solid, and updates the solidcol[] array appropriately |
| 99 |
|
| 100 |
static void R_ClipWallSegment(int first, int last, dboolean solid) |
| 101 |
{ |
| 102 |
byte *p; |
| 103 |
while (first < last) { |
| 104 |
if (solidcol[first]) { |
| 105 |
if (!(p = memchr(solidcol+first, 0, last-first))) return; // All solid |
| 106 |
first = p - solidcol; |
| 107 |
} else { |
| 108 |
int to; |
| 109 |
if (!(p = memchr(solidcol+first, 1, last-first))) to = last; |
| 110 |
else to = p - solidcol; |
| 111 |
R_StoreWallRange(first, to-1); |
| 112 |
if (solid) { |
| 113 |
memset(solidcol+first,1,to-first); |
| 114 |
} |
| 115 |
first = to; |
| 116 |
} |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
// |
| 121 |
// R_ClearClipSegs |
| 122 |
// |
| 123 |
|
| 124 |
void R_ClearClipSegs (void) |
| 125 |
{ |
| 126 |
memset(solidcol, 0, SCREENWIDTH); |
| 127 |
} |
| 128 |
|
| 129 |
// killough 1/18/98 -- This function is used to fix the automap bug which |
| 130 |
// showed lines behind closed doors simply because the door had a dropoff. |
| 131 |
// |
| 132 |
// cph - converted to R_RecalcLineFlags. This recalculates all the flags for |
| 133 |
// a line, including closure and texture tiling. |
| 134 |
|
| 135 |
static void R_RecalcLineFlags(line_t *linedef) |
| 136 |
{ |
| 137 |
linedef->r_validcount = gametic; |
| 138 |
|
| 139 |
/* First decide if the line is closed, normal, or invisible */ |
| 140 |
if (!(linedef->flags & ML_TWOSIDED) |
| 141 |
|| backsector->ceilingheight <= frontsector->floorheight |
| 142 |
|| backsector->floorheight >= frontsector->ceilingheight |
| 143 |
|| ( |
| 144 |
// if door is closed because back is shut: |
| 145 |
backsector->ceilingheight <= backsector->floorheight |
| 146 |
|
| 147 |
// preserve a kind of transparent door/lift special effect: |
| 148 |
&& (backsector->ceilingheight >= frontsector->ceilingheight || |
| 149 |
curline->sidedef->toptexture) |
| 150 |
|
| 151 |
&& (backsector->floorheight <= frontsector->floorheight || |
| 152 |
curline->sidedef->bottomtexture) |
| 153 |
|
| 154 |
// properly render skies (consider door "open" if both ceilings are sky): |
| 155 |
&& (backsector->ceilingpic !=skyflatnum || |
| 156 |
frontsector->ceilingpic!=skyflatnum) |
| 157 |
) |
| 158 |
) |
| 159 |
linedef->r_flags = RF_CLOSED; |
| 160 |
else { |
| 161 |
// Reject empty lines used for triggers |
| 162 |
// and special events. |
| 163 |
// Identical floor and ceiling on both sides, |
| 164 |
// identical light levels on both sides, |
| 165 |
// and no middle texture. |
| 166 |
if ( |
| 167 |
backsector->ceilingheight != frontsector->ceilingheight |
| 168 |
|| backsector->floorheight != frontsector->floorheight |
| 169 |
|| curline->sidedef->midtexture |
| 170 |
|| P_FloorPlanesDiffer(frontsector, backsector) |
| 171 |
|| P_CeilingPlanesDiffer(frontsector, backsector) |
| 172 |
) { |
| 173 |
linedef->r_flags = 0; |
| 174 |
return; |
| 175 |
} else |
| 176 |
linedef->r_flags = RF_IGNORE; |
| 177 |
} |
| 178 |
|
| 179 |
/* cph - I'm too lazy to try and work with offsets in this */ |
| 180 |
if (curline->sidedef->rowoffset) |
| 181 |
return; |
| 182 |
|
| 183 |
/* Now decide on texture tiling */ |
| 184 |
if (linedef->flags & ML_TWOSIDED) { |
| 185 |
int c; |
| 186 |
|
| 187 |
/* Does top texture need tiling */ |
| 188 |
if (!curline->sidedef->rowoffset_top) |
| 189 |
if ( |
| 190 |
(c = frontsector->ceilingheight - backsector->ceilingheight) > 0 && |
| 191 |
(textureheight[texturetranslation[curline->sidedef->toptexture]] > c) |
| 192 |
) |
| 193 |
linedef->r_flags |= RF_TOP_TILE; |
| 194 |
|
| 195 |
/* Does bottom texture need tiling */ |
| 196 |
if (!curline->sidedef->rowoffset_bottom) |
| 197 |
if ( |
| 198 |
(c = frontsector->floorheight - backsector->floorheight) > 0 && |
| 199 |
(textureheight[texturetranslation[curline->sidedef->bottomtexture]] > c) |
| 200 |
) |
| 201 |
linedef->r_flags |= RF_BOT_TILE; |
| 202 |
} |
| 203 |
else { |
| 204 |
int c; |
| 205 |
|
| 206 |
/* Does middle texture need tiling */ |
| 207 |
if (!curline->sidedef->rowoffset_mid) |
| 208 |
if ( |
| 209 |
(c = frontsector->ceilingheight - frontsector->floorheight) > 0 && |
| 210 |
(textureheight[texturetranslation[curline->sidedef->midtexture]] > c) |
| 211 |
) |
| 212 |
linedef->r_flags |= RF_MID_TILE; |
| 213 |
} |
| 214 |
} |
| 215 |
|
| 216 |
// |
| 217 |
// killough 3/7/98: Hack floor/ceiling heights for deep water etc. |
| 218 |
// |
| 219 |
// If player's view height is underneath fake floor, lower the |
| 220 |
// drawn ceiling to be just under the floor height, and replace |
| 221 |
// the drawn floor and ceiling textures, and light level, with |
| 222 |
// the control sector's. |
| 223 |
// |
| 224 |
// Similar for ceiling, only reflected. |
| 225 |
// |
| 226 |
// killough 4/11/98, 4/13/98: fix bugs, add 'back' parameter |
| 227 |
// |
| 228 |
|
| 229 |
sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec, |
| 230 |
int *floorlightlevel, int *ceilinglightlevel, |
| 231 |
dboolean back) |
| 232 |
{ |
| 233 |
if (floorlightlevel) |
| 234 |
*floorlightlevel = P_FloorLightLevel(sec); |
| 235 |
|
| 236 |
if (ceilinglightlevel) |
| 237 |
*ceilinglightlevel = P_CeilingLightLevel(sec); |
| 238 |
|
| 239 |
if (sec->heightsec != -1) |
| 240 |
{ |
| 241 |
const sector_t *s = §ors[sec->heightsec]; |
| 242 |
int heightsec = viewplayer->mo->subsector->sector->heightsec; |
| 243 |
int underwater = heightsec!=-1 && viewz<=sectors[heightsec].floorheight; |
| 244 |
|
| 245 |
// Replace sector being drawn, with a copy to be hacked |
| 246 |
*tempsec = *sec; |
| 247 |
|
| 248 |
// Replace floor and ceiling height with other sector's heights. |
| 249 |
tempsec->floorheight = s->floorheight; |
| 250 |
tempsec->ceilingheight = s->ceilingheight; |
| 251 |
|
| 252 |
// killough 11/98: prevent sudden light changes from non-water sectors: |
| 253 |
if (underwater && (tempsec->floorheight = sec->floorheight, |
| 254 |
tempsec->ceilingheight = s->floorheight - 1, !back)) |
| 255 |
{ // head-below-floor hack |
| 256 |
tempsec->floorpic = s->floorpic; |
| 257 |
tempsec->floor_xoffs = s->floor_xoffs; |
| 258 |
tempsec->floor_yoffs = s->floor_yoffs; |
| 259 |
|
| 260 |
if (underwater) |
| 261 |
{ |
| 262 |
if (s->ceilingpic == skyflatnum) |
| 263 |
{ |
| 264 |
tempsec->floorheight = tempsec->ceilingheight+1; |
| 265 |
tempsec->ceilingpic = tempsec->floorpic; |
| 266 |
tempsec->ceiling_xoffs = tempsec->floor_xoffs; |
| 267 |
tempsec->ceiling_yoffs = tempsec->floor_yoffs; |
| 268 |
} |
| 269 |
else { |
| 270 |
tempsec->ceilingpic = s->ceilingpic; |
| 271 |
tempsec->ceiling_xoffs = s->ceiling_xoffs; |
| 272 |
tempsec->ceiling_yoffs = s->ceiling_yoffs; |
| 273 |
} |
| 274 |
} |
| 275 |
|
| 276 |
tempsec->lightlevel = s->lightlevel; |
| 277 |
|
| 278 |
if (floorlightlevel) |
| 279 |
*floorlightlevel = P_FloorLightLevel(s); |
| 280 |
|
| 281 |
if (ceilinglightlevel) |
| 282 |
*ceilinglightlevel = P_CeilingLightLevel(s); |
| 283 |
} |
| 284 |
else if (heightsec != -1 && viewz >= sectors[heightsec].ceilingheight && |
| 285 |
sec->ceilingheight > s->ceilingheight) |
| 286 |
{ // Above-ceiling hack |
| 287 |
tempsec->ceilingheight = s->ceilingheight; |
| 288 |
tempsec->floorheight = s->ceilingheight + 1; |
| 289 |
|
| 290 |
tempsec->floorpic = tempsec->ceilingpic = s->ceilingpic; |
| 291 |
tempsec->floor_xoffs = tempsec->ceiling_xoffs = s->ceiling_xoffs; |
| 292 |
tempsec->floor_yoffs = tempsec->ceiling_yoffs = s->ceiling_yoffs; |
| 293 |
|
| 294 |
if (s->floorpic != skyflatnum) |
| 295 |
{ |
| 296 |
tempsec->ceilingheight = sec->ceilingheight; |
| 297 |
tempsec->floorpic = s->floorpic; |
| 298 |
tempsec->floor_xoffs = s->floor_xoffs; |
| 299 |
tempsec->floor_yoffs = s->floor_yoffs; |
| 300 |
} |
| 301 |
|
| 302 |
tempsec->lightlevel = s->lightlevel; |
| 303 |
|
| 304 |
if (floorlightlevel) |
| 305 |
*floorlightlevel = P_FloorLightLevel(s); |
| 306 |
|
| 307 |
if (ceilinglightlevel) |
| 308 |
*ceilinglightlevel = P_CeilingLightLevel(s); |
| 309 |
} |
| 310 |
|
| 311 |
sec = tempsec; // Use other sector |
| 312 |
} |
| 313 |
return sec; |
| 314 |
} |
| 315 |
|
| 316 |
// |
| 317 |
// e6y: Check whether the player can look beyond this line |
| 318 |
// |
| 319 |
|
| 320 |
static dboolean CheckClip(seg_t * seg, sector_t * frontsector, sector_t * backsector) |
| 321 |
{ |
| 322 |
static sector_t tempsec_back, tempsec_front; |
| 323 |
|
| 324 |
backsector = R_FakeFlat(backsector, &tempsec_back, NULL, NULL, true); |
| 325 |
frontsector = R_FakeFlat(frontsector, &tempsec_front, NULL, NULL, false); |
| 326 |
|
| 327 |
// check for closed sectors! |
| 328 |
if (backsector->ceilingheight <= frontsector->floorheight) |
| 329 |
{ |
| 330 |
if (seg->sidedef->toptexture == NO_TEXTURE) |
| 331 |
return false; |
| 332 |
|
| 333 |
if (backsector->ceilingpic == skyflatnum && frontsector->ceilingpic == skyflatnum) |
| 334 |
return false; |
| 335 |
|
| 336 |
return true; |
| 337 |
} |
| 338 |
|
| 339 |
if (frontsector->ceilingheight <= backsector->floorheight) |
| 340 |
{ |
| 341 |
if (seg->sidedef->bottomtexture == NO_TEXTURE) |
| 342 |
return false; |
| 343 |
|
| 344 |
// properly render skies (consider door "open" if both floors are sky): |
| 345 |
if (backsector->ceilingpic == skyflatnum && frontsector->ceilingpic == skyflatnum) |
| 346 |
return false; |
| 347 |
|
| 348 |
return true; |
| 349 |
} |
| 350 |
|
| 351 |
if (backsector->ceilingheight <= backsector->floorheight) |
| 352 |
{ |
| 353 |
// preserve a kind of transparent door/lift special effect: |
| 354 |
if (backsector->ceilingheight < frontsector->ceilingheight) |
| 355 |
{ |
| 356 |
if (seg->sidedef->toptexture == NO_TEXTURE) |
| 357 |
return false; |
| 358 |
} |
| 359 |
if (backsector->floorheight > frontsector->floorheight) |
| 360 |
{ |
| 361 |
if (seg->sidedef->bottomtexture == NO_TEXTURE) |
| 362 |
return false; |
| 363 |
} |
| 364 |
if (backsector->ceilingpic == skyflatnum && frontsector->ceilingpic == skyflatnum) |
| 365 |
return false; |
| 366 |
|
| 367 |
if (backsector->floorpic == skyflatnum && frontsector->floorpic == skyflatnum) |
| 368 |
return false; |
| 369 |
|
| 370 |
return true; |
| 371 |
} |
| 372 |
|
| 373 |
return false; |
| 374 |
} |
| 375 |
|
| 376 |
// |
| 377 |
// R_AddLine |
| 378 |
// Clips the given segment |
| 379 |
// and adds any visible pieces to the line list. |
| 380 |
// |
| 381 |
|
| 382 |
static dboolean ignore_gl_range_clipping; |
| 383 |
|
| 384 |
static void R_AddLine (seg_t *line) |
| 385 |
{ |
| 386 |
int x1; |
| 387 |
int x2; |
| 388 |
angle_t angle1; |
| 389 |
angle_t angle2; |
| 390 |
angle_t span; |
| 391 |
angle_t tspan; |
| 392 |
static sector_t tempsec; // killough 3/8/98: ceiling/water hack |
| 393 |
|
| 394 |
curline = line; |
| 395 |
|
| 396 |
if (V_IsOpenGLMode()) |
| 397 |
{ |
| 398 |
line_t* l = line->linedef; |
| 399 |
sector_t* sec = subsectors[currentsubsectornum].sector; |
| 400 |
|
| 401 |
// Don't add plane to drawing list until we encounter a |
| 402 |
// non-self-referencing linedef in the subsector. |
| 403 |
if (sec->gl_validcount != validcount && (l == NULL || l->frontsector != l->backsector)) |
| 404 |
{ |
| 405 |
sec->gl_validcount = validcount; |
| 406 |
|
| 407 |
gld_AddPlane(currentsubsectornum, floorplane, ceilingplane); |
| 408 |
} |
| 409 |
|
| 410 |
angle1 = R_PointToPseudoAngle(line->v1->x, line->v1->y); |
| 411 |
angle2 = R_PointToPseudoAngle(line->v2->x, line->v2->y); |
| 412 |
|
| 413 |
// Back side, i.e. backface culling - read: endAngle >= startAngle! |
| 414 |
if (angle2 - angle1 < ANG180 || !line->linedef) |
| 415 |
{ |
| 416 |
return; |
| 417 |
} |
| 418 |
if (!ignore_gl_range_clipping && !gld_clipper_SafeCheckRange(angle2, angle1)) |
| 419 |
{ |
| 420 |
return; |
| 421 |
} |
| 422 |
|
| 423 |
map_subsectors[currentsubsectornum] = 1; |
| 424 |
|
| 425 |
if (!line->backsector) |
| 426 |
{ |
| 427 |
gld_clipper_SafeAddClipRange(angle2, angle1); |
| 428 |
} |
| 429 |
else |
| 430 |
{ |
| 431 |
if (line->frontsector == line->backsector) |
| 432 |
{ |
| 433 |
if (texturetranslation[line->sidedef->midtexture] == NO_TEXTURE) |
| 434 |
{ |
| 435 |
//e6y: nothing to do here! |
| 436 |
return; |
| 437 |
} |
| 438 |
} |
| 439 |
if (CheckClip(line, line->frontsector, line->backsector)) |
| 440 |
{ |
| 441 |
gld_clipper_SafeAddClipRange(angle2, angle1); |
| 442 |
} |
| 443 |
} |
| 444 |
|
| 445 |
if (ds_p == drawsegs+maxdrawsegs) // killough 1/98 -- fix 2s line HOM |
| 446 |
{ |
| 447 |
unsigned pos = ds_p - drawsegs; // jff 8/9/98 fix from ZDOOM1.14a |
| 448 |
unsigned newmax = maxdrawsegs ? maxdrawsegs*2 : 128; // killough |
| 449 |
drawsegs = Z_Realloc(drawsegs,newmax*sizeof(*drawsegs)); |
| 450 |
ds_p = drawsegs + pos; // jff 8/9/98 fix from ZDOOM1.14a |
| 451 |
maxdrawsegs = newmax; |
| 452 |
} |
| 453 |
|
| 454 |
curline->linedef->flags |= ML_MAPPED; |
| 455 |
|
| 456 |
// proff 11/99: the rest of the calculations is not needed for OpenGL |
| 457 |
ds_p++->curline = curline; |
| 458 |
gld_AddWall(curline); |
| 459 |
|
| 460 |
return; |
| 461 |
} |
| 462 |
|
| 463 |
angle1 = R_PointToAngleEx(line->v1->px, line->v1->py); |
| 464 |
angle2 = R_PointToAngleEx(line->v2->px, line->v2->py); |
| 465 |
|
| 466 |
// Clip to view edges. |
| 467 |
span = angle1 - angle2; |
| 468 |
|
| 469 |
// Back side, i.e. backface culling |
| 470 |
if (span >= ANG180) |
| 471 |
return; |
| 472 |
|
| 473 |
// Global angle needed by segcalc. |
| 474 |
rw_angle1 = angle1; |
| 475 |
angle1 -= viewangle; |
| 476 |
angle2 -= viewangle; |
| 477 |
|
| 478 |
tspan = angle1 + clipangle; |
| 479 |
if (tspan > 2*clipangle) |
| 480 |
{ |
| 481 |
tspan -= 2*clipangle; |
| 482 |
|
| 483 |
// Totally off the left edge? |
| 484 |
if (tspan >= span) |
| 485 |
return; |
| 486 |
|
| 487 |
angle1 = clipangle; |
| 488 |
} |
| 489 |
|
| 490 |
tspan = clipangle - angle2; |
| 491 |
if (tspan > 2*clipangle) |
| 492 |
{ |
| 493 |
tspan -= 2*clipangle; |
| 494 |
|
| 495 |
// Totally off the left edge? |
| 496 |
if (tspan >= span) |
| 497 |
return; |
| 498 |
angle2 = 0-clipangle; |
| 499 |
} |
| 500 |
|
| 501 |
// The seg is in the view range, |
| 502 |
// but not necessarily visible. |
| 503 |
|
| 504 |
angle1 = (angle1+ANG90)>>ANGLETOFINESHIFT; |
| 505 |
angle2 = (angle2+ANG90)>>ANGLETOFINESHIFT; |
| 506 |
|
| 507 |
// killough 1/31/98: Here is where "slime trails" can SOMETIMES occur: |
| 508 |
x1 = viewangletox[angle1]; |
| 509 |
x2 = viewangletox[angle2]; |
| 510 |
|
| 511 |
// Does not cross a pixel? |
| 512 |
if (x1 >= x2) // killough 1/31/98 -- change == to >= for robustness |
| 513 |
return; |
| 514 |
|
| 515 |
backsector = line->backsector; |
| 516 |
|
| 517 |
// Single sided line? |
| 518 |
if (backsector) |
| 519 |
// killough 3/8/98, 4/4/98: hack for invisible ceilings / deep water |
| 520 |
backsector = R_FakeFlat(backsector, &tempsec, NULL, NULL, true); |
| 521 |
|
| 522 |
/* cph - roll up linedef properties in flags */ |
| 523 |
if ((linedef = curline->linedef)->r_validcount != gametic) |
| 524 |
R_RecalcLineFlags(linedef); |
| 525 |
|
| 526 |
if (linedef->r_flags & RF_IGNORE) |
| 527 |
{ |
| 528 |
return; |
| 529 |
} |
| 530 |
else |
| 531 |
R_ClipWallSegment (x1, x2, linedef->r_flags & RF_CLOSED); |
| 532 |
} |
| 533 |
|
| 534 |
// |
| 535 |
// R_CheckBBox |
| 536 |
// Checks BSP node/subtree bounding box. |
| 537 |
// Returns true |
| 538 |
// if some part of the bbox might be visible. |
| 539 |
// |
| 540 |
|
| 541 |
static const int checkcoord[12][4] = // killough -- static const |
| 542 |
{ |
| 543 |
{3,0,2,1}, |
| 544 |
{3,0,2,0}, |
| 545 |
{3,1,2,0}, |
| 546 |
{0}, |
| 547 |
{2,0,2,1}, |
| 548 |
{0,0,0,0}, |
| 549 |
{3,1,3,0}, |
| 550 |
{0}, |
| 551 |
{2,0,3,1}, |
| 552 |
{2,1,3,1}, |
| 553 |
{2,1,3,0} |
| 554 |
}; |
| 555 |
|
| 556 |
// killough 1/28/98: static // CPhipps - const parameter, reformatted |
| 557 |
static dboolean R_CheckBBox(const fixed_t *bspcoord) |
| 558 |
{ |
| 559 |
angle_t angle1, angle2; |
| 560 |
int boxpos; |
| 561 |
const int* check; |
| 562 |
|
| 563 |
// Find the corners of the box |
| 564 |
// that define the edges from current viewpoint. |
| 565 |
boxpos = (viewx <= bspcoord[BOXLEFT] ? 0 : viewx < bspcoord[BOXRIGHT ] ? 1 : 2) + |
| 566 |
(viewy >= bspcoord[BOXTOP ] ? 0 : viewy > bspcoord[BOXBOTTOM] ? 4 : 8); |
| 567 |
|
| 568 |
if (boxpos == 5) |
| 569 |
return true; |
| 570 |
|
| 571 |
check = checkcoord[boxpos]; |
| 572 |
|
| 573 |
if (V_IsOpenGLMode()) |
| 574 |
{ |
| 575 |
angle1 = R_PointToPseudoAngle(bspcoord[check[0]], bspcoord[check[1]]); |
| 576 |
angle2 = R_PointToPseudoAngle(bspcoord[check[2]], bspcoord[check[3]]); |
| 577 |
return gld_clipper_SafeCheckRange(angle2, angle1); |
| 578 |
} |
| 579 |
|
| 580 |
angle1 = R_PointToAngleEx (bspcoord[check[0]], bspcoord[check[1]]) - viewangle; |
| 581 |
angle2 = R_PointToAngleEx (bspcoord[check[2]], bspcoord[check[3]]) - viewangle; |
| 582 |
|
| 583 |
// cph - replaced old code, which was unclear and badly commented |
| 584 |
// Much more efficient code now |
| 585 |
if ((signed)angle1 < (signed)angle2) { /* it's "behind" us */ |
| 586 |
/* Either angle1 or angle2 is behind us, so it doesn't matter if we |
| 587 |
* change it to the corect sign |
| 588 |
*/ |
| 589 |
if ((angle1 >= ANG180) && (angle1 < ANG270)) |
| 590 |
angle1 = INT_MAX; /* which is ANG180-1 */ |
| 591 |
else |
| 592 |
angle2 = INT_MIN; |
| 593 |
} |
| 594 |
|
| 595 |
if ((signed)angle2 >= (signed)clipangle) return false; // Both off left edge |
| 596 |
if ((signed)angle1 <= -(signed)clipangle) return false; // Both off right edge |
| 597 |
if ((signed)angle1 >= (signed)clipangle) angle1 = clipangle; // Clip at left edge |
| 598 |
if ((signed)angle2 <= -(signed)clipangle) angle2 = 0-clipangle; // Clip at right edge |
| 599 |
|
| 600 |
// Find the first clippost |
| 601 |
// that touches the source post |
| 602 |
// (adjacent pixels are touching). |
| 603 |
angle1 = (angle1+ANG90)>>ANGLETOFINESHIFT; |
| 604 |
angle2 = (angle2+ANG90)>>ANGLETOFINESHIFT; |
| 605 |
{ |
| 606 |
int sx1 = viewangletox[angle1]; |
| 607 |
int sx2 = viewangletox[angle2]; |
| 608 |
// const cliprange_t *start; |
| 609 |
|
| 610 |
// Does not cross a pixel. |
| 611 |
if (sx1 == sx2) |
| 612 |
return false; |
| 613 |
|
| 614 |
if (!memchr(solidcol+sx1, 0, sx2-sx1)) return false; |
| 615 |
// All columns it covers are already solidly covered |
| 616 |
} |
| 617 |
|
| 618 |
return true; |
| 619 |
} |
| 620 |
|
| 621 |
static visplane_t dummyfloorplane; |
| 622 |
static visplane_t dummyceilingplane; |
| 623 |
|
| 624 |
// e6y |
| 625 |
// New algo can handle fake flats and ceilings |
| 626 |
// much more correctly and fastly the the original |
| 627 |
static void R_HandleGLFakeFlats(sector_t *sector) |
| 628 |
{ |
| 629 |
// check if the sector is faked |
| 630 |
sector_t *tmpsec = NULL; |
| 631 |
|
| 632 |
if (frontsector == sector) |
| 633 |
{ |
| 634 |
if (!gl_use_stencil) |
| 635 |
{ |
| 636 |
// if the sector has bottomtextures, then the floorheight will be set to the |
| 637 |
// highest surounding floorheight |
| 638 |
if ((frontsector->flags & NO_BOTTOMTEXTURES) || (!floorplane)) |
| 639 |
{ |
| 640 |
tmpsec = GetBestFake(frontsector, 0, validcount); |
| 641 |
|
| 642 |
if (tmpsec && frontsector->floorheight != tmpsec->floorheight) |
| 643 |
{ |
| 644 |
dummyfloorplane.height = tmpsec->floorheight; |
| 645 |
dummyfloorplane.lightlevel = tmpsec->lightlevel; |
| 646 |
dummyfloorplane.picnum = tmpsec->floorpic; |
| 647 |
dummyfloorplane.special = tmpsec->special; |
| 648 |
floorplane = &dummyfloorplane; |
| 649 |
} |
| 650 |
} |
| 651 |
|
| 652 |
// the same for ceilings. they will be set to the lowest ceilingheight |
| 653 |
if ((frontsector->flags & NO_TOPTEXTURES) || (!ceilingplane)) |
| 654 |
{ |
| 655 |
tmpsec = GetBestFake(frontsector, 1, validcount); |
| 656 |
|
| 657 |
if (tmpsec && frontsector->ceilingheight != tmpsec->ceilingheight) |
| 658 |
{ |
| 659 |
dummyceilingplane.height = tmpsec->ceilingheight; |
| 660 |
dummyceilingplane.lightlevel = tmpsec->lightlevel; |
| 661 |
dummyceilingplane.picnum = tmpsec->ceilingpic; |
| 662 |
dummyceilingplane.special = 0; |
| 663 |
ceilingplane = &dummyceilingplane; |
| 664 |
} |
| 665 |
} |
| 666 |
} |
| 667 |
|
| 668 |
/* |
| 669 |
* Floors higher than the player's viewheight (or much lower) or |
| 670 |
* ceilings lower than the player's viewheight with no textures will |
| 671 |
* bleed the sector behind them through in the software renderer. This |
| 672 |
* is occasionally used to create an "invisible wall" effect to hide |
| 673 |
* monsters, but in the GL renderer would leave an untextured space |
| 674 |
* beneath or above unless otherwise patched. |
| 675 |
* |
| 676 |
* This code attempts to find an appropriate sector to "bleed |
| 677 |
* through" over the untextured gap. |
| 678 |
* |
| 679 |
* Note there is a corner case that is not handled: If a dummy |
| 680 |
* sector off-screen is the lowest adjacent sector to the invisible |
| 681 |
* wall, and it is at a different height than the correct |
| 682 |
* bleed-through sector, the dummy sector is copied instead of the |
| 683 |
* sector behind the player. It may be possible to address this in |
| 684 |
* a future patch by refactoring this into the renderer and tagging |
| 685 |
* visible candidate sectors during drawing. |
| 686 |
*/ |
| 687 |
if (frontsector->flags & MISSING_BOTTOMTEXTURES) |
| 688 |
{ |
| 689 |
tmpsec = NULL; |
| 690 |
|
| 691 |
if (frontsector->floorheight >= viewz) |
| 692 |
tmpsec = GetBestBleedSector(frontsector, BLEED_NONE); |
| 693 |
|
| 694 |
#if EXPERIMENTAL_BLEED |
| 695 |
if (tmpsec == NULL && |
| 696 |
viewz - frontsector->floorheight >= (FLOOR_BLEED_THRESHOLD << FRACBITS)) |
| 697 |
tmpsec = GetBestBleedSector(frontsector, BLEED_OCCLUDE); |
| 698 |
#endif |
| 699 |
|
| 700 |
if (tmpsec) |
| 701 |
{ |
| 702 |
dummyfloorplane.height = tmpsec->floorheight; |
| 703 |
dummyfloorplane.lightlevel = tmpsec->lightlevel; |
| 704 |
dummyfloorplane.picnum = tmpsec->floorpic; |
| 705 |
dummyfloorplane.special = tmpsec->special; |
| 706 |
dummyfloorplane.rotation = tmpsec->floor_rotation; |
| 707 |
dummyfloorplane.xoffs = tmpsec->floor_xoffs; |
| 708 |
dummyfloorplane.yoffs = tmpsec->floor_yoffs; |
| 709 |
dummyfloorplane.xscale = tmpsec->floor_xscale; |
| 710 |
dummyfloorplane.yscale = tmpsec->floor_yscale; |
| 711 |
|
| 712 |
floorplane = &dummyfloorplane; |
| 713 |
} |
| 714 |
} |
| 715 |
|
| 716 |
if (frontsector->flags & MISSING_TOPTEXTURES) |
| 717 |
{ |
| 718 |
tmpsec = NULL; |
| 719 |
|
| 720 |
if (frontsector->ceilingheight <= viewz) |
| 721 |
tmpsec = GetBestBleedSector(frontsector, BLEED_CEILING); |
| 722 |
|
| 723 |
#if EXPERIMENTAL_BLEED |
| 724 |
if (tmpsec == NULL && |
| 725 |
frontsector->ceilingheight - viewz >= (CEILING_BLEED_THRESHOLD << FRACBITS)) |
| 726 |
tmpsec = GetBestBleedSector(frontsector, BLEED_CEILING | BLEED_OCCLUDE); |
| 727 |
#endif |
| 728 |
|
| 729 |
if (tmpsec) |
| 730 |
{ |
| 731 |
dummyceilingplane.height = tmpsec->ceilingheight; |
| 732 |
dummyceilingplane.lightlevel = tmpsec->lightlevel; |
| 733 |
dummyceilingplane.picnum = tmpsec->ceilingpic; |
| 734 |
dummyceilingplane.special = 0; |
| 735 |
dummyceilingplane.rotation = tmpsec->ceiling_rotation; |
| 736 |
dummyceilingplane.xoffs = tmpsec->ceiling_xoffs; |
| 737 |
dummyceilingplane.yoffs = tmpsec->ceiling_yoffs; |
| 738 |
dummyceilingplane.xscale = tmpsec->ceiling_xscale; |
| 739 |
dummyceilingplane.yscale = tmpsec->ceiling_yscale; |
| 740 |
ceilingplane = &dummyceilingplane; |
| 741 |
} |
| 742 |
} |
| 743 |
} |
| 744 |
} |
| 745 |
|
| 746 |
static void R_UpdateGlobalPlanes(sector_t *sector, int *floorlightlevel, int *ceilinglightlevel) |
| 747 |
{ |
| 748 |
// TODO: this data must persist, but the reason is to be investigated |
| 749 |
static sector_t tempsec; |
| 750 |
|
| 751 |
// killough 3/8/98, 4/4/98: Deep water / fake ceiling effect |
| 752 |
frontsector = // killough 4/11/98 |
| 753 |
R_FakeFlat(sector, &tempsec, floorlightlevel, ceilinglightlevel, false); |
| 754 |
|
| 755 |
// killough 3/7/98: Add (x,y) offsets to flats, add deep water check |
| 756 |
// killough 3/16/98: add floorlightlevel |
| 757 |
// killough 10/98: add support for skies transferred from sidedefs |
| 758 |
floorplane = frontsector->floorheight < viewz || // killough 3/7/98 |
| 759 |
(frontsector->heightsec != -1 && |
| 760 |
sectors[frontsector->heightsec].ceilingpic == skyflatnum) ? |
| 761 |
R_FindPlane(frontsector->floorheight, |
| 762 |
frontsector->floorpic == skyflatnum && // kilough 10/98 |
| 763 |
frontsector->floorsky & PL_SKYFLAT ? frontsector->floorsky : |
| 764 |
frontsector->floorpic, |
| 765 |
*floorlightlevel, // killough 3/16/98 |
| 766 |
frontsector->special, |
| 767 |
frontsector->floor_xoffs, // killough 3/7/98 |
| 768 |
frontsector->floor_yoffs, |
| 769 |
frontsector->floor_rotation, |
| 770 |
frontsector->floor_xscale, |
| 771 |
frontsector->floor_yscale |
| 772 |
) : NULL; |
| 773 |
|
| 774 |
ceilingplane = frontsector->ceilingheight > viewz || |
| 775 |
frontsector->ceilingpic == skyflatnum || |
| 776 |
(frontsector->heightsec != -1 && |
| 777 |
sectors[frontsector->heightsec].floorpic == skyflatnum) ? |
| 778 |
R_FindPlane(frontsector->ceilingheight, // killough 3/8/98 |
| 779 |
frontsector->ceilingpic == skyflatnum && // kilough 10/98 |
| 780 |
frontsector->ceilingsky & PL_SKYFLAT ? frontsector->ceilingsky : |
| 781 |
frontsector->ceilingpic, |
| 782 |
*ceilinglightlevel, // killough 4/11/98 |
| 783 |
0, |
| 784 |
frontsector->ceiling_xoffs, // killough 3/7/98 |
| 785 |
frontsector->ceiling_yoffs, |
| 786 |
frontsector->ceiling_rotation, |
| 787 |
frontsector->ceiling_xscale, |
| 788 |
frontsector->ceiling_yscale |
| 789 |
) : NULL; |
| 790 |
|
| 791 |
if (V_IsOpenGLMode()) |
| 792 |
{ |
| 793 |
R_HandleGLFakeFlats(sector); |
| 794 |
} |
| 795 |
} |
| 796 |
|
| 797 |
// |
| 798 |
// R_Subsector |
| 799 |
// Determine floor/ceiling planes. |
| 800 |
// Add sprites of things in sector. |
| 801 |
// Draw one or more line segments. |
| 802 |
// |
| 803 |
// killough 1/31/98 -- made static, polished |
| 804 |
|
| 805 |
static void R_AddPolyLines(polyobj_t *poly) |
| 806 |
{ |
| 807 |
int polyCount; |
| 808 |
seg_t **polySeg; |
| 809 |
|
| 810 |
poly_add_line = true; |
| 811 |
poly_frontsector = poly->subsector->sector; |
| 812 |
polyCount = poly->numsegs; |
| 813 |
polySeg = poly->segs; |
| 814 |
while (polyCount--) |
| 815 |
{ |
| 816 |
R_AddLine(*polySeg++); |
| 817 |
} |
| 818 |
poly_add_line = false; |
| 819 |
poly_frontsector = NULL; |
| 820 |
} |
| 821 |
|
| 822 |
static void R_Subsector(int num) |
| 823 |
{ |
| 824 |
int count; |
| 825 |
seg_t *line; |
| 826 |
subsector_t *sub; |
| 827 |
int floorlightlevel; // killough 3/16/98: set floor lightlevel |
| 828 |
int ceilinglightlevel; // killough 4/11/98 |
| 829 |
|
| 830 |
#ifdef RANGECHECK |
| 831 |
if (num>=numsubsectors) |
| 832 |
I_Error ("R_Subsector: ss %i with numss = %i", num, numsubsectors); |
| 833 |
#endif |
| 834 |
|
| 835 |
sub = &subsectors[num]; |
| 836 |
currentsubsectornum = num; |
| 837 |
|
| 838 |
if (V_IsSoftwareMode() || sub->sector->gl_validcount != validcount) |
| 839 |
{ |
| 840 |
R_UpdateGlobalPlanes(sub->sector, &floorlightlevel, &ceilinglightlevel); |
| 841 |
|
| 842 |
// killough 9/18/98: Fix underwater slowdown, by passing real sector |
| 843 |
// instead of fake one. Improve sprite lighting by basing sprite |
| 844 |
// lightlevels on floor & ceiling lightlevels in the surrounding area. |
| 845 |
// |
| 846 |
// 10/98 killough: |
| 847 |
// |
| 848 |
// NOTE: TeamTNT fixed this bug incorrectly, messing up sprite lighting!!! |
| 849 |
// That is part of the 242 effect!!! If you simply pass sub->sector to |
| 850 |
// the old code you will not get correct lighting for underwater sprites!!! |
| 851 |
// Either you must pass the fake sector and handle validcount here, on the |
| 852 |
// real sector, or you must account for the lighting in some other way, |
| 853 |
// like passing it as an argument. |
| 854 |
|
| 855 |
if (sub->sector->validcount != validcount) |
| 856 |
{ |
| 857 |
sub->sector->validcount = validcount; |
| 858 |
|
| 859 |
R_AddSprites(sub, (floorlightlevel+ceilinglightlevel)/2); |
| 860 |
} |
| 861 |
} |
| 862 |
|
| 863 |
// hexen |
| 864 |
if (sub->poly) // Render the polyobj in the subsector first |
| 865 |
R_AddPolyLines(sub->poly); |
| 866 |
|
| 867 |
count = sub->numlines; |
| 868 |
line = &segs[sub->firstline]; |
| 869 |
while (count--) |
| 870 |
{ |
| 871 |
if (line->linedef) |
| 872 |
R_AddLine (line); |
| 873 |
line++; |
| 874 |
curline = NULL; /* cph 2001/11/18 - must clear curline now we're done with it, so R_ColourMap doesn't try using it for other things */ |
| 875 |
} |
| 876 |
} |
| 877 |
|
| 878 |
// |
| 879 |
// RenderBSPNode |
| 880 |
// Renders all subsectors below a given node, |
| 881 |
// traversing subtree recursively. |
| 882 |
// Just call with BSP root. |
| 883 |
// |
| 884 |
// killough 5/2/98: reformatted, removed tail recursion |
| 885 |
|
| 886 |
void R_RenderBSPNode(int bspnum) |
| 887 |
{ |
| 888 |
while (!(bspnum & NF_SUBSECTOR)) // Found a subsector? |
| 889 |
{ |
| 890 |
const node_t *bsp = &nodes[bspnum]; |
| 891 |
|
| 892 |
// Decide which side the view point is on. |
| 893 |
int side = R_PointOnSide(viewx, viewy, bsp); |
| 894 |
// Recursively divide front space. |
| 895 |
R_RenderBSPNode(bsp->children[side]); |
| 896 |
|
| 897 |
// Possibly divide back space. |
| 898 |
|
| 899 |
if (!R_CheckBBox(bsp->bbox[side^1])) |
| 900 |
return; |
| 901 |
|
| 902 |
bspnum = bsp->children[side^1]; |
| 903 |
} |
| 904 |
// e6y: support for extended nodes |
| 905 |
R_Subsector(bspnum == -1 ? 0 : bspnum & ~NF_SUBSECTOR); |
| 906 |
} |
| 907 |
|
| 908 |
void R_ForceRenderPolyObjs(void) |
| 909 |
{ |
| 910 |
int i; |
| 911 |
|
| 912 |
ignore_gl_range_clipping = true; |
| 913 |
|
| 914 |
for (i = 0; i < po_NumPolyobjs; i++) |
| 915 |
if (polyobjs[i].subsector) |
| 916 |
R_AddPolyLines(&polyobjs[i]); |
| 917 |
|
| 918 |
ignore_gl_range_clipping = false; |
| 919 |
} |