summaryrefslogtreecommitdiff
path: root/apps/plugins/doom/r_bsp.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/doom/r_bsp.c')
-rw-r--r--apps/plugins/doom/r_bsp.c104
1 files changed, 64 insertions, 40 deletions
diff --git a/apps/plugins/doom/r_bsp.c b/apps/plugins/doom/r_bsp.c
index 358787dc58..e6ce74c029 100644
--- a/apps/plugins/doom/r_bsp.c
+++ b/apps/plugins/doom/r_bsp.c
@@ -29,21 +29,14 @@
29 * 29 *
30 *-----------------------------------------------------------------------------*/ 30 *-----------------------------------------------------------------------------*/
31 31
32#include "doomdef.h" 32#include "doomstat.h"
33
34#include "m_bbox.h" 33#include "m_bbox.h"
35
36#include "i_system.h" 34#include "i_system.h"
37
38#include "r_main.h" 35#include "r_main.h"
36#include "r_segs.h"
39#include "r_plane.h" 37#include "r_plane.h"
40#include "r_things.h" 38#include "r_things.h"
41 39#include "r_bsp.h" // cph - sanity checking
42// State.
43#include "doomstat.h"
44#include "r_state.h"
45#include "r_segs.h"
46#include "rockmacros.h"
47 40
48seg_t *curline; 41seg_t *curline;
49side_t *sidedef; 42side_t *sidedef;
@@ -52,14 +45,19 @@ sector_t *frontsector;
52sector_t *backsector; 45sector_t *backsector;
53drawseg_t *ds_p; 46drawseg_t *ds_p;
54 47
48// killough 4/7/98: indicates doors closed wrt automap bugfix:
49// cph - replaced by linedef rendering flags - int doorclosed;
55 50
51// killough: New code which removes 2s linedef limit
56drawseg_t *drawsegs; 52drawseg_t *drawsegs;
57unsigned maxdrawsegs; 53unsigned maxdrawsegs;
54// drawseg_t drawsegs[MAXDRAWSEGS]; // old code -- killough
58 55
59// 56//
60// R_ClearDrawSegs 57// R_ClearDrawSegs
61// 58//
62void R_ClearDrawSegs (void) 59
60void R_ClearDrawSegs(void)
63{ 61{
64 ds_p = drawsegs; 62 ds_p = drawsegs;
65} 63}
@@ -79,16 +77,24 @@ byte solidcol[SCREENWIDTH] IBSS_ATTR;
79void R_ClipWallSegment(int first, int last, boolean solid) 77void R_ClipWallSegment(int first, int last, boolean solid)
80{ 78{
81 byte *p; 79 byte *p;
82 while (first < last) { 80 while (first < last)
83 if (solidcol[first]) { 81 {
84 if (!(p = memchr(solidcol+first, 0, last-first))) return; // All solid 82 if (solidcol[first])
83 {
84 if (!(p = memchr(solidcol+first, 0, last-first)))
85 return; // All solid
85 first = p - solidcol; 86 first = p - solidcol;
86 } else { 87 }
88 else
89 {
87 int to; 90 int to;
88 if (!(p = memchr(solidcol+first, 1, last-first))) to = last; 91 if (!(p = memchr(solidcol+first, 1, last-first)))
89 else to = p - solidcol; 92 to = last;
93 else
94 to = p - solidcol;
90 R_StoreWallRange(first, to-1); 95 R_StoreWallRange(first, to-1);
91 if (solid) { 96 if (solid)
97 {
92 memset(solidcol+first,1,to-first); 98 memset(solidcol+first,1,to-first);
93 } 99 }
94 first = to; 100 first = to;
@@ -136,7 +142,8 @@ static void R_RecalcLineFlags(void)
136 ) 142 )
137 ) 143 )
138 linedef->r_flags = RF_CLOSED; 144 linedef->r_flags = RF_CLOSED;
139 else { 145 else
146 {
140 // Reject empty lines used for triggers 147 // Reject empty lines used for triggers
141 // and special events. 148 // and special events.
142 // Identical floor and ceiling on both sides, 149 // Identical floor and ceiling on both sides,
@@ -151,17 +158,22 @@ static void R_RecalcLineFlags(void)
151 sizeof(frontsector->ceiling_xoffs) + sizeof(frontsector->ceiling_yoffs) + 158 sizeof(frontsector->ceiling_xoffs) + sizeof(frontsector->ceiling_yoffs) +
152 sizeof(frontsector->ceilingpic) + sizeof(frontsector->floorpic) + 159 sizeof(frontsector->ceilingpic) + sizeof(frontsector->floorpic) +
153 sizeof(frontsector->lightlevel) + sizeof(frontsector->floorlightsec) + 160 sizeof(frontsector->lightlevel) + sizeof(frontsector->floorlightsec) +
154 sizeof(frontsector->ceilinglightsec))) { 161 sizeof(frontsector->ceilinglightsec)))
155 linedef->r_flags = 0; return; 162 {
156 } else 163 linedef->r_flags = 0;
164 return;
165 }
166 else
157 linedef->r_flags = RF_IGNORE; 167 linedef->r_flags = RF_IGNORE;
158 } 168 }
159 169
160 /* cph - I'm too lazy to try and work with offsets in this */ 170 /* cph - I'm too lazy to try and work with offsets in this */
161 if (curline->sidedef->rowoffset) return; 171 if (curline->sidedef->rowoffset)
172 return;
162 173
163 /* Now decide on texture tiling */ 174 /* Now decide on texture tiling */
164 if (linedef->flags & ML_TWOSIDED) { 175 if (linedef->flags & ML_TWOSIDED)
176 {
165 int c; 177 int c;
166 178
167 /* Does top texture need tiling */ 179 /* Does top texture need tiling */
@@ -173,7 +185,9 @@ static void R_RecalcLineFlags(void)
173 if ((c = frontsector->floorheight - backsector->floorheight) > 0 && 185 if ((c = frontsector->floorheight - backsector->floorheight) > 0 &&
174 (textureheight[texturetranslation[curline->sidedef->bottomtexture]] > c)) 186 (textureheight[texturetranslation[curline->sidedef->bottomtexture]] > c))
175 linedef->r_flags |= RF_BOT_TILE; 187 linedef->r_flags |= RF_BOT_TILE;
176 } else { 188 }
189 else
190 {
177 int c; 191 int c;
178 /* Does middle texture need tiling */ 192 /* Does middle texture need tiling */
179 if ((c = frontsector->ceilingheight - frontsector->floorheight) > 0 && 193 if ((c = frontsector->ceilingheight - frontsector->floorheight) > 0 &&
@@ -228,13 +242,17 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec,
228 tempsec->floor_xoffs = s->floor_xoffs; 242 tempsec->floor_xoffs = s->floor_xoffs;
229 tempsec->floor_yoffs = s->floor_yoffs; 243 tempsec->floor_yoffs = s->floor_yoffs;
230 244
231 if (underwater) { 245 if (underwater)
232 if (s->ceilingpic == skyflatnum) { 246 {
247 if (s->ceilingpic == skyflatnum)
248 {
233 tempsec->floorheight = tempsec->ceilingheight+1; 249 tempsec->floorheight = tempsec->ceilingheight+1;
234 tempsec->ceilingpic = tempsec->floorpic; 250 tempsec->ceilingpic = tempsec->floorpic;
235 tempsec->ceiling_xoffs = tempsec->floor_xoffs; 251 tempsec->ceiling_xoffs = tempsec->floor_xoffs;
236 tempsec->ceiling_yoffs = tempsec->floor_yoffs; 252 tempsec->ceiling_yoffs = tempsec->floor_yoffs;
237 } else { 253 }
254 else
255 {
238 tempsec->ceilingpic = s->ceilingpic; 256 tempsec->ceilingpic = s->ceilingpic;
239 tempsec->ceiling_xoffs = s->ceiling_xoffs; 257 tempsec->ceiling_xoffs = s->ceiling_xoffs;
240 tempsec->ceiling_yoffs = s->ceiling_yoffs; 258 tempsec->ceiling_yoffs = s->ceiling_yoffs;
@@ -384,7 +402,8 @@ static void R_AddLine (seg_t *line)
384 402
385static const int checkcoord[12][4] = // killough -- static const 403static const int checkcoord[12][4] = // killough -- static const
386 { 404 {
387 {3,0,2,1}, 405 {
406 3,0,2,1},
388 {3,0,2,0}, 407 {3,0,2,0},
389 {3,1,2,0}, 408 {3,1,2,0},
390 {0}, 409 {0},
@@ -421,7 +440,8 @@ static boolean R_CheckBBox(const fixed_t *bspcoord)
421 440
422 // cph - replaced old code, which was unclear and badly commented 441 // cph - replaced old code, which was unclear and badly commented
423 // Much more efficient code now 442 // Much more efficient code now
424 if ((signed)angle1 < (signed)angle2) { /* it's "behind" us */ 443 if ((signed)angle1 < (signed)angle2)
444 { /* it's "behind" us */
425 /* Either angle1 or angle2 is behind us, so it doesn't matter if we 445 /* Either angle1 or angle2 is behind us, so it doesn't matter if we
426 * change it to the corect sign 446 * change it to the corect sign
427 */ 447 */
@@ -431,10 +451,14 @@ static boolean R_CheckBBox(const fixed_t *bspcoord)
431 angle2 = INT_MIN; 451 angle2 = INT_MIN;
432 } 452 }
433 453
434 if ((signed)angle2 >= (signed)clipangle) return false; // Both off left edge 454 if ((signed)angle2 >= (signed)clipangle)
435 if ((signed)angle1 <= -(signed)clipangle) return false; // Both off right edge 455 return false; // Both off left edge
436 if ((signed)angle1 >= (signed)clipangle) angle1 = clipangle; // Clip at left edge 456 if ((signed)angle1 <= -(signed)clipangle)
437 if ((signed)angle2 <= -(signed)clipangle) angle2 = 0-clipangle; // Clip at right edge 457 return false; // Both off right edge
458 if ((signed)angle1 >= (signed)clipangle)
459 angle1 = clipangle; // Clip at left edge
460 if ((signed)angle2 <= -(signed)clipangle)
461 angle2 = 0-clipangle; // Clip at right edge
438 462
439 // Find the first clippost 463 // Find the first clippost
440 // that touches the source post 464 // that touches the source post
@@ -450,7 +474,8 @@ static boolean R_CheckBBox(const fixed_t *bspcoord)
450 if (sx1 == sx2) 474 if (sx1 == sx2)
451 return false; 475 return false;
452 476
453 if (!memchr(solidcol+sx1, 0, sx2-sx1)) return false; 477 if (!memchr(solidcol+sx1, 0, sx2-sx1))
478 return false;
454 // All columns it covers are already solidly covered 479 // All columns it covers are already solidly covered
455 } 480 }
456 481
@@ -477,6 +502,7 @@ static void R_Subsector(int num)
477 int ceilinglightlevel; // killough 4/11/98 502 int ceilinglightlevel; // killough 4/11/98
478 503
479#ifdef RANGECHECK 504#ifdef RANGECHECK
505
480 if (num>=numsubsectors) 506 if (num>=numsubsectors)
481 I_Error ("R_Subsector: ss %i with numss = %i", num, numsubsectors); 507 I_Error ("R_Subsector: ss %i with numss = %i", num, numsubsectors);
482#endif 508#endif
@@ -485,7 +511,7 @@ static void R_Subsector(int num)
485 frontsector = sub->sector; 511 frontsector = sub->sector;
486 count = sub->numlines; 512 count = sub->numlines;
487 line = &segs[sub->firstline]; 513 line = &segs[sub->firstline];
488// sscount++; 514 // sscount++;
489 515
490 // killough 3/8/98, 4/4/98: Deep water / fake ceiling effect 516 // killough 3/8/98, 4/4/98: Deep water / fake ceiling effect
491 frontsector = R_FakeFlat(frontsector, &tempsec, &floorlightlevel, 517 frontsector = R_FakeFlat(frontsector, &tempsec, &floorlightlevel,
@@ -497,8 +523,7 @@ static void R_Subsector(int num)
497 523
498 floorplane = frontsector->floorheight < viewz || // killough 3/7/98 524 floorplane = frontsector->floorheight < viewz || // killough 3/7/98
499 (frontsector->heightsec != -1 && 525 (frontsector->heightsec != -1 &&
500 sectors[frontsector->heightsec].ceilingpic == skyflatnum) 526 sectors[frontsector->heightsec].ceilingpic == skyflatnum) ?
501 ?
502 R_FindPlane(frontsector->floorheight, 527 R_FindPlane(frontsector->floorheight,
503 frontsector->floorpic == skyflatnum && // kilough 10/98 528 frontsector->floorpic == skyflatnum && // kilough 10/98
504 frontsector->sky & PL_SKYFLAT ? frontsector->sky : 529 frontsector->sky & PL_SKYFLAT ? frontsector->sky :
@@ -511,8 +536,7 @@ static void R_Subsector(int num)
511 ceilingplane = frontsector->ceilingheight > viewz || 536 ceilingplane = frontsector->ceilingheight > viewz ||
512 frontsector->ceilingpic == skyflatnum || 537 frontsector->ceilingpic == skyflatnum ||
513 (frontsector->heightsec != -1 && 538 (frontsector->heightsec != -1 &&
514 sectors[frontsector->heightsec].floorpic == skyflatnum) 539 sectors[frontsector->heightsec].floorpic == skyflatnum) ?
515 ?
516 R_FindPlane(frontsector->ceilingheight, // killough 3/8/98 540 R_FindPlane(frontsector->ceilingheight, // killough 3/8/98
517 frontsector->ceilingpic == skyflatnum && // kilough 10/98 541 frontsector->ceilingpic == skyflatnum && // kilough 10/98
518 frontsector->sky & PL_SKYFLAT ? frontsector->sky : 542 frontsector->sky & PL_SKYFLAT ? frontsector->sky :