home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 28 / amigaformatcd28.iso / -screenplay- / otherstuff / adoomppc_src / r_segs.c < prev    next >
C/C++ Source or Header  |  1998-04-23  |  18KB  |  801 lines

  1. // Emacs style mode select   -*- C++ -*- 
  2. //-----------------------------------------------------------------------------
  3. //
  4. // $Id:$
  5. //
  6. // Copyright (C) 1993-1996 by id Software, Inc.
  7. //
  8. // This source is available for distribution and/or modification
  9. // only under the terms of the DOOM Source Code License as
  10. // published by id Software. All rights reserved.
  11. //
  12. // The source is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
  15. // for more details.
  16. //
  17. // $Log:$
  18. //
  19. // DESCRIPTION:
  20. //    All the clipping: columns, horizontal spans, sky columns.
  21. //
  22. //-----------------------------------------------------------------------------
  23.  
  24.  
  25. static const char
  26. rcsid[] = "$Id: r_segs.c,v 1.3 1997/01/29 20:10:19 b1 Exp $";
  27.  
  28.  
  29.  
  30.  
  31.  
  32. #include <stdlib.h>
  33.  
  34. #include "i_system.h"
  35.  
  36. #include "doomdef.h"
  37. #include "doomstat.h"
  38.  
  39. #include "r_local.h"
  40. #include "r_sky.h"
  41.  
  42.  
  43. // OPTIMIZE: closed two sided lines as single sided
  44.  
  45. // True if any of the segs textures might be visible.
  46. boolean        segtextured;    
  47.  
  48. // False if the back side is the same plane.
  49. boolean        markfloor;    
  50. boolean        markceiling;
  51.  
  52. boolean        maskedtexture;
  53. int        toptexture;
  54. int        bottomtexture;
  55. int        midtexture;
  56.  
  57.  
  58. angle_t        rw_normalangle;
  59. // angle to line origin
  60. int        rw_angle1;    
  61.  
  62. //
  63. // regular wall
  64. //
  65. int        rw_x;
  66. int        rw_stopx;
  67. angle_t        rw_centerangle;
  68. fixed_t        rw_offset;
  69. fixed_t        rw_distance;
  70. fixed_t        rw_scale;
  71. fixed_t        rw_scalestep;
  72. fixed_t        rw_midtexturemid;
  73. fixed_t        rw_toptexturemid;
  74. fixed_t        rw_bottomtexturemid;
  75.  
  76. int        worldtop;
  77. int        worldbottom;
  78. int        worldhigh;
  79. int        worldlow;
  80.  
  81. fixed_t        pixhigh;
  82. fixed_t        pixlow;
  83. fixed_t        pixhighstep;
  84. fixed_t        pixlowstep;
  85.  
  86. fixed_t        topfrac;
  87. fixed_t        topstep;
  88.  
  89. fixed_t        bottomfrac;
  90. fixed_t        bottomstep;
  91.  
  92.  
  93. lighttable_t**    walllights;
  94.  
  95. short*        maskedtexturecol;
  96.  
  97.  
  98.  
  99. //
  100. // R_RenderMaskedSegRange
  101. //
  102. void
  103. R_RenderMaskedSegRange
  104. ( drawseg_t*    ds,
  105.   int        x1,
  106.   int        x2 )
  107. {
  108.     unsigned    index;
  109.     column_t*    col;
  110.     int        lightnum;
  111.     int        texnum;
  112.     
  113.     // Calculate light table.
  114.     // Use different light tables
  115.     //   for horizontal / vertical / diagonal. Diagonal?
  116.     // OPTIMIZE: get rid of LIGHTSEGSHIFT globally
  117.     curline = ds->curline;
  118.     frontsector = curline->frontsector;
  119.     backsector = curline->backsector;
  120.     texnum = texturetranslation[curline->sidedef->midtexture];
  121.     
  122.     lightnum = (frontsector->lightlevel >> LIGHTSEGSHIFT)+extralight;
  123.  
  124.     if (curline->v1->y == curline->v2->y)
  125.     lightnum--;
  126.     else if (curline->v1->x == curline->v2->x)
  127.     lightnum++;
  128.  
  129.     if (lightnum < 0)        
  130.     walllights = scalelight[0];
  131.     else if (lightnum >= LIGHTLEVELS)
  132.     walllights = scalelight[LIGHTLEVELS-1];
  133.     else
  134.     walllights = scalelight[lightnum];
  135.  
  136.     maskedtexturecol = ds->maskedtexturecol;
  137.  
  138.     rw_scalestep = ds->scalestep;        
  139.     spryscale = ds->scale1 + (x1 - ds->x1)*rw_scalestep;
  140.     mfloorclip = ds->sprbottomclip;
  141.     mceilingclip = ds->sprtopclip;
  142.     
  143.     // find positioning
  144.     if (curline->linedef->flags & ML_DONTPEGBOTTOM)
  145.     {
  146.     dc_texturemid = frontsector->floorheight > backsector->floorheight
  147.         ? frontsector->floorheight : backsector->floorheight;
  148.     dc_texturemid = dc_texturemid + textureheight[texnum] - viewz;
  149.     }
  150.     else
  151.     {
  152.     dc_texturemid =frontsector->ceilingheight<backsector->ceilingheight
  153.         ? frontsector->ceilingheight : backsector->ceilingheight;
  154.     dc_texturemid = dc_texturemid - viewz;
  155.     }
  156.     dc_texturemid += curline->sidedef->rowoffset;
  157.             
  158.     if (fixedcolormap)
  159.     dc_colormap = fixedcolormap;
  160.     
  161.     // draw the columns
  162.     for (dc_x = x1 ; dc_x <= x2 ; dc_x++)
  163.     {
  164.     // calculate lighting
  165.     if (maskedtexturecol[dc_x] != MAXSHORT)
  166.     {
  167.         if (!fixedcolormap)
  168.         {
  169.         index = spryscale>>LIGHTSCALESHIFT;
  170.  
  171.         if (index >=  MAXLIGHTSCALE )
  172.             index = MAXLIGHTSCALE-1;
  173.  
  174.         dc_colormap = walllights[index];
  175.         }
  176.             
  177.         sprtopscreen = centeryfrac - FixedMul(dc_texturemid, spryscale);
  178.         dc_iscale = 0xffffffffu / (unsigned)spryscale;
  179.         
  180.         // draw the texture
  181.         col = (column_t *)( 
  182.         (byte *)R_GetColumn(texnum,maskedtexturecol[dc_x]) -3);
  183.             
  184.         R_DrawMaskedColumn (col);
  185.  
  186.         maskedtexturecol[dc_x] = MAXSHORT;
  187.     }
  188.     spryscale += rw_scalestep;
  189.     }
  190.     
  191. }
  192.  
  193.  
  194.  
  195.  
  196. //#define DO_STATS
  197.  
  198. #ifdef DO_STATS
  199. unsigned int stats[26] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  200. #define STATS(x) stats[x]++
  201. #else
  202. #define STATS(x)
  203. #endif
  204.  
  205.  
  206. //
  207. // R_RenderSegLoop
  208. // Draws zero, one, or two textures (and possibly a masked
  209. //  texture) for walls.
  210. // Can draw or mark the starting pixel of floor and ceiling
  211. //  textures.
  212. // CALLED: CORE LOOPING ROUTINE.
  213. //
  214. #define HEIGHTBITS        12
  215. #define HEIGHTUNIT        (1<<HEIGHTBITS)
  216.  
  217. void R_RenderSegLoop (void)
  218. {
  219.     angle_t        angle;
  220.     unsigned        index;
  221.     int            yl;
  222.     int            yh;
  223.     int            mid;
  224.     fixed_t        texturecolumn;
  225.     int            top;
  226.     int            bottom;
  227.  
  228.     //texturecolumn = 0;                // shut up compiler warning
  229.  
  230.     STATS(0);  /* 45443 */
  231.     for ( ; rw_x < rw_stopx ; rw_x++)
  232.     {
  233.         STATS(1);  /* 1603733 */
  234.     // mark floor / ceiling areas
  235.     yl = (topfrac+HEIGHTUNIT-1)>>HEIGHTBITS;
  236.  
  237.     // no space above wall?
  238.     if (yl < ceilingclip[rw_x]+1) {
  239.             STATS(2);  /* 1016131 */
  240.         yl = ceilingclip[rw_x]+1;
  241.     }
  242.  
  243.     if (markceiling)
  244.     {
  245.             STATS(3);  /* 1291140 */
  246.         top = ceilingclip[rw_x]+1;
  247.         bottom = yl-1;
  248.  
  249.         if (bottom >= floorclip[rw_x]) {
  250.                 STATS(4);  /* 50179 */
  251.         bottom = floorclip[rw_x]-1;
  252.             }
  253.         if (top <= bottom)
  254.         {
  255.                 STATS(5);  /* 439559 */
  256.         ceilingplane->top[rw_x] = top;
  257.         ceilingplane->bottom[rw_x] = bottom;
  258.         }
  259.     }
  260.         
  261.     yh = bottomfrac>>HEIGHTBITS;
  262.  
  263.     if (yh >= floorclip[rw_x]) {
  264.             STATS(6);  /* 670449 */
  265.         yh = floorclip[rw_x]-1;
  266.         }
  267.     if (markfloor)
  268.     {
  269.             STATS(7);  /* 1298743 */
  270.         top = yh+1;
  271.         bottom = floorclip[rw_x]-1;
  272.         if (top <= ceilingclip[rw_x]) {
  273.                 STATS(8);  /* 49048 */
  274.         top = ceilingclip[rw_x]+1;
  275.             }
  276.         if (top <= bottom)
  277.         {
  278.                 STATS(9);  /* 726501 */
  279.         floorplane->top[rw_x] = top;
  280.         floorplane->bottom[rw_x] = bottom;
  281.         }
  282.     }
  283.     
  284.     // texturecolumn and lighting are independent of wall tiers
  285.     if (segtextured)
  286.     {
  287.             STATS(10);  /* 1261482 */
  288.         // calculate texture offset
  289.         angle = (rw_centerangle + xtoviewangle[rw_x])>>ANGLETOFINESHIFT;
  290.         texturecolumn = rw_offset-FixedMul(finetangent[angle],rw_distance);
  291.         texturecolumn >>= FRACBITS;
  292.         // calculate lighting
  293.         index = rw_scale>>LIGHTSCALESHIFT;
  294.  
  295.         if (index >=  MAXLIGHTSCALE ) {
  296.                 STATS(11);  /* 169980 */
  297.         index = MAXLIGHTSCALE-1;
  298.             }
  299.         dc_colormap = walllights[index];
  300.         dc_x = rw_x;
  301.         dc_iscale = 0xffffffffu / (unsigned)rw_scale;
  302.     }
  303.     
  304.     // draw the wall tiers
  305.     if (midtexture)
  306.     {
  307.             STATS(12);  /* 560607 */
  308.         // single sided line
  309.         dc_yl = yl;
  310.         dc_yh = yh;
  311.         dc_texturemid = rw_midtexturemid;
  312.         dc_source = R_GetColumn(midtexture,texturecolumn);
  313.         colfunc ();
  314.         ceilingclip[rw_x] = viewheight;
  315.         floorclip[rw_x] = -1;
  316.     }
  317.     else
  318.     {
  319.             STATS(13);  /* 1043126 */
  320.         // two sided line
  321.         if (toptexture)
  322.         {
  323.                 STATS(14);  /* 314333 */
  324.         // top wall
  325.         mid = pixhigh>>HEIGHTBITS;
  326.         pixhigh += pixhighstep;
  327.  
  328.         if (mid >= floorclip[rw_x]) {
  329.                     STATS(15);  /* 45511 */
  330.             mid = floorclip[rw_x]-1;
  331.                 }
  332.         if (mid >= yl)
  333.         {
  334.                     STATS(16);  /* 139708 */
  335.             dc_yl = yl;
  336.             dc_yh = mid;
  337.             dc_texturemid = rw_toptexturemid;
  338.             dc_source = R_GetColumn(toptexture,texturecolumn);
  339.             colfunc ();
  340.             ceilingclip[rw_x] = mid;
  341.         }
  342.         else {
  343.                     STATS(17);  /* 174625 */
  344.             ceilingclip[rw_x] = yl-1;
  345.                 }
  346.         }
  347.         else
  348.         {
  349.                 STATS(18);  /* 728793 */
  350.         // no top wall
  351.         if (markceiling) {
  352.                     STATS(19);  /* 439926 */
  353.             ceilingclip[rw_x] = yl-1;
  354.                 }
  355.         }
  356.             
  357.         if (bottomtexture)
  358.         {
  359.                 STATS(20);  /* 446785 */
  360.         // bottom wall
  361.         mid = (pixlow+HEIGHTUNIT-1)>>HEIGHTBITS;
  362.         pixlow += pixlowstep;
  363.  
  364.         // no space above wall?
  365.         if (mid <= ceilingclip[rw_x]) {
  366.                     STATS(21);  /* 67461 */
  367.             mid = ceilingclip[rw_x]+1;
  368.         }
  369.         if (mid <= yh)
  370.         {
  371.                     STATS(22);  /* 366880 */
  372.             dc_yl = mid;
  373.             dc_yh = yh;
  374.             dc_texturemid = rw_bottomtexturemid;
  375.             dc_source = R_GetColumn(bottomtexture,
  376.                         texturecolumn);
  377.             colfunc ();
  378.             floorclip[rw_x] = mid;
  379.         }
  380.         else {
  381.                     STATS(23);  /* 79905 */
  382.             floorclip[rw_x] = yh+1;
  383.                 }
  384.         }
  385.         else
  386.         {
  387.                 STATS(24);  /* 596341 */
  388.         // no bottom wall
  389.         if (markfloor)
  390.             floorclip[rw_x] = yh+1;
  391.         }
  392.             
  393.         if (maskedtexture)
  394.         {
  395.                 STATS(25);  /* 0 */
  396.         // save texturecol
  397.         //  for backdrawing of masked mid texture
  398.         maskedtexturecol[rw_x] = texturecolumn;
  399.         }
  400.     }
  401.         
  402.     rw_scale += rw_scalestep;
  403.     topfrac += topstep;
  404.     bottomfrac += bottomstep;
  405.  
  406.     }
  407. }
  408.  
  409. #ifdef DO_STATS
  410. void _STDdo_stats (void)
  411. {
  412.   int i;
  413.  
  414.   for (i = 0; i < 26; i++)
  415.      printf ("stats[%2d] = %u\n", i, stats[i]);
  416. }
  417. #endif
  418.  
  419.  
  420.  
  421.  
  422. //
  423. // R_StoreWallRange
  424. // A wall segment will be drawn
  425. //  between start and stop pixels (inclusive).
  426. //
  427. void
  428. R_StoreWallRange
  429. ( int    start,
  430.   int    stop )
  431. {
  432.     fixed_t        hyp;
  433.     fixed_t        sineval;
  434.     angle_t        distangle, offsetangle;
  435.     fixed_t        vtop;
  436.     int            lightnum;
  437.  
  438.     // don't overflow and crash
  439.     if (ds_p == &drawsegs[MAXDRAWSEGS])
  440.     return;        
  441.         
  442. #ifdef RANGECHECK
  443.     if (start >=viewwidth || start > stop)
  444.     I_Error ("Bad R_RenderWallRange: %i to %i", start , stop);
  445. #endif
  446.     
  447.     sidedef = curline->sidedef;
  448.     linedef = curline->linedef;
  449.  
  450.     // mark the segment as visible for auto map
  451.     linedef->flags |= ML_MAPPED;
  452.     
  453.     // calculate rw_distance for scale calculation
  454.     rw_normalangle = curline->angle + ANG90;
  455.     offsetangle = iabs(rw_normalangle-rw_angle1);
  456.     
  457.     if (offsetangle > ANG90)
  458.     offsetangle = ANG90;
  459.  
  460.     distangle = ANG90 - offsetangle;
  461.     hyp = R_PointToDist (curline->v1->x, curline->v1->y);
  462.     sineval = finesine[distangle>>ANGLETOFINESHIFT];
  463.     rw_distance = FixedMul (hyp, sineval);
  464.         
  465.     
  466.     ds_p->x1 = rw_x = start;
  467.     ds_p->x2 = stop;
  468.     ds_p->curline = curline;
  469.     rw_stopx = stop+1;
  470.     
  471.     // calculate scale at both ends and step
  472.     ds_p->scale1 = rw_scale = 
  473.     R_ScaleFromGlobalAngle (viewangle + xtoviewangle[start]);
  474.     
  475.     if (stop > start )
  476.     {
  477.     ds_p->scale2 = R_ScaleFromGlobalAngle (viewangle + xtoviewangle[stop]);
  478.     ds_p->scalestep = rw_scalestep = 
  479.         (ds_p->scale2 - rw_scale) / (stop-start);
  480.     }
  481.     else
  482.     {
  483.     // UNUSED: try to fix the stretched line bug
  484. #if 0
  485.     if (rw_distance < FRACUNIT/2)
  486.     {
  487.         fixed_t        trx,try;
  488.         fixed_t        gxt,gyt;
  489.  
  490.         trx = curline->v1->x - viewx;
  491.         try = curline->v1->y - viewy;
  492.             
  493.         gxt = FixedMul(trx,viewcos); 
  494.         gyt = -FixedMul(try,viewsin); 
  495.         ds_p->scale1 = FixedDiv(projection, gxt-gyt)<<detailshift;
  496.     }
  497. #endif
  498.     ds_p->scale2 = ds_p->scale1;
  499.     }
  500.     
  501.     // calculate texture boundaries
  502.     //  and decide if floor / ceiling marks are needed
  503.     worldtop = frontsector->ceilingheight - viewz;
  504.     worldbottom = frontsector->floorheight - viewz;
  505.     
  506.     midtexture = toptexture = bottomtexture = maskedtexture = 0;
  507.     ds_p->maskedtexturecol = NULL;
  508.     
  509.     if (!backsector)
  510.     {
  511.     // single sided line
  512.     midtexture = texturetranslation[sidedef->midtexture];
  513.     // a single sided line is terminal, so it must mark ends
  514.     markfloor = markceiling = true;
  515.     if (linedef->flags & ML_DONTPEGBOTTOM)
  516.     {
  517.         vtop = frontsector->floorheight +
  518.         textureheight[sidedef->midtexture];
  519.         // bottom of texture at bottom
  520.         rw_midtexturemid = vtop - viewz;    
  521.     }
  522.     else
  523.     {
  524.         // top of texture at top
  525.         rw_midtexturemid = worldtop;
  526.     }
  527.     rw_midtexturemid += sidedef->rowoffset;
  528.  
  529.     ds_p->silhouette = SIL_BOTH;
  530.     ds_p->sprtopclip = screenheightarray;
  531.     ds_p->sprbottomclip = negonearray;
  532.     ds_p->bsilheight = MAXINT;
  533.     ds_p->tsilheight = MININT;
  534.     }
  535.     else
  536.     {
  537.     // two sided line
  538.     ds_p->sprtopclip = ds_p->sprbottomclip = NULL;
  539.     ds_p->silhouette = 0;
  540.     
  541.     if (frontsector->floorheight > backsector->floorheight)
  542.     {
  543.         ds_p->silhouette = SIL_BOTTOM;
  544.         ds_p->bsilheight = frontsector->floorheight;
  545.     }
  546.     else if (backsector->floorheight > viewz)
  547.     {
  548.         ds_p->silhouette = SIL_BOTTOM;
  549.         ds_p->bsilheight = MAXINT;
  550.         // ds_p->sprbottomclip = negonearray;
  551.     }
  552.     
  553.     if (frontsector->ceilingheight < backsector->ceilingheight)
  554.     {
  555.         ds_p->silhouette |= SIL_TOP;
  556.         ds_p->tsilheight = frontsector->ceilingheight;
  557.     }
  558.     else if (backsector->ceilingheight < viewz)
  559.     {
  560.         ds_p->silhouette |= SIL_TOP;
  561.         ds_p->tsilheight = MININT;
  562.         // ds_p->sprtopclip = screenheightarray;
  563.     }
  564.         
  565.     if (backsector->ceilingheight <= frontsector->floorheight)
  566.     {
  567.         ds_p->sprbottomclip = negonearray;
  568.         ds_p->bsilheight = MAXINT;
  569.         ds_p->silhouette |= SIL_BOTTOM;
  570.     }
  571.     
  572.     if (backsector->floorheight >= frontsector->ceilingheight)
  573.     {
  574.         ds_p->sprtopclip = screenheightarray;
  575.         ds_p->tsilheight = MININT;
  576.         ds_p->silhouette |= SIL_TOP;
  577.     }
  578.     
  579.     worldhigh = backsector->ceilingheight - viewz;
  580.     worldlow = backsector->floorheight - viewz;
  581.         
  582.     // hack to allow height changes in outdoor areas
  583.     if (frontsector->ceilingpic == skyflatnum 
  584.         && backsector->ceilingpic == skyflatnum)
  585.     {
  586.         worldtop = worldhigh;
  587.     }
  588.     
  589.             
  590.     if (worldlow != worldbottom 
  591.         || backsector->floorpic != frontsector->floorpic
  592.         || backsector->lightlevel != frontsector->lightlevel)
  593.     {
  594.         markfloor = true;
  595.     }
  596.     else
  597.     {
  598.         // same plane on both sides
  599.         markfloor = false;
  600.     }
  601.     
  602.             
  603.     if (worldhigh != worldtop 
  604.         || backsector->ceilingpic != frontsector->ceilingpic
  605.         || backsector->lightlevel != frontsector->lightlevel)
  606.     {
  607.         markceiling = true;
  608.     }
  609.     else
  610.     {
  611.         // same plane on both sides
  612.         markceiling = false;
  613.     }
  614.     
  615.     if (backsector->ceilingheight <= frontsector->floorheight
  616.         || backsector->floorheight >= frontsector->ceilingheight)
  617.     {
  618.         // closed door
  619.         markceiling = markfloor = true;
  620.     }
  621.     
  622.  
  623.     if (worldhigh < worldtop)
  624.     {
  625.         // top texture
  626.         toptexture = texturetranslation[sidedef->toptexture];
  627.         if (linedef->flags & ML_DONTPEGTOP)
  628.         {
  629.         // top of texture at top
  630.         rw_toptexturemid = worldtop;
  631.         }
  632.         else
  633.         {
  634.         vtop =
  635.             backsector->ceilingheight
  636.             + textureheight[sidedef->toptexture];
  637.         
  638.         // bottom of texture
  639.         rw_toptexturemid = vtop - viewz;    
  640.         }
  641.     }
  642.     if (worldlow > worldbottom)
  643.     {
  644.         // bottom texture
  645.         bottomtexture = texturetranslation[sidedef->bottomtexture];
  646.  
  647.         if (linedef->flags & ML_DONTPEGBOTTOM )
  648.         {
  649.         // bottom of texture at bottom
  650.         // top of texture at top
  651.         rw_bottomtexturemid = worldtop;
  652.         }
  653.         else    // top of texture at top
  654.         rw_bottomtexturemid = worldlow;
  655.     }
  656.     rw_toptexturemid += sidedef->rowoffset;
  657.     rw_bottomtexturemid += sidedef->rowoffset;
  658.     
  659.     // allocate space for masked texture tables
  660.     if (sidedef->midtexture)
  661.     {
  662.         // masked midtexture
  663.         maskedtexture = true;
  664.         ds_p->maskedtexturecol = maskedtexturecol = lastopening - rw_x;
  665.         lastopening += rw_stopx - rw_x;
  666.     }
  667.     }
  668.     
  669.     // calculate rw_offset (only needed for textured lines)
  670.     segtextured = midtexture | toptexture | bottomtexture | maskedtexture;
  671.  
  672.     if (segtextured)
  673.     {
  674.     offsetangle = rw_normalangle-rw_angle1;
  675.     
  676.     if (offsetangle > ANG180)
  677.         offsetangle = -offsetangle;
  678.  
  679.     if (offsetangle > ANG90)
  680.         offsetangle = ANG90;
  681.  
  682.     sineval = finesine[offsetangle >>ANGLETOFINESHIFT];
  683.     rw_offset = FixedMul (hyp, sineval);
  684.  
  685.     if (rw_normalangle-rw_angle1 < ANG180)
  686.         rw_offset = -rw_offset;
  687.  
  688.     rw_offset += sidedef->textureoffset + curline->offset;
  689.     rw_centerangle = ANG90 + viewangle - rw_normalangle;
  690.     
  691.     // calculate light table
  692.     //  use different light tables
  693.     //  for horizontal / vertical / diagonal
  694.     // OPTIMIZE: get rid of LIGHTSEGSHIFT globally
  695.     if (!fixedcolormap)
  696.     {
  697.         lightnum = (frontsector->lightlevel >> LIGHTSEGSHIFT)+extralight;
  698.  
  699.         if (curline->v1->y == curline->v2->y)
  700.         lightnum--;
  701.         else if (curline->v1->x == curline->v2->x)
  702.         lightnum++;
  703.  
  704.         if (lightnum < 0)        
  705.         walllights = scalelight[0];
  706.         else if (lightnum >= LIGHTLEVELS)
  707.         walllights = scalelight[LIGHTLEVELS-1];
  708.         else
  709.         walllights = scalelight[lightnum];
  710.     }
  711.     }
  712.     
  713.     // if a floor / ceiling plane is on the wrong side
  714.     //  of the view plane, it is definitely invisible
  715.     //  and doesn't need to be marked.
  716.     
  717.   
  718.     if (frontsector->floorheight >= viewz)
  719.     {
  720.     // above view plane
  721.     markfloor = false;
  722.     }
  723.     
  724.     if (frontsector->ceilingheight <= viewz 
  725.     && frontsector->ceilingpic != skyflatnum)
  726.     {
  727.     // below view plane
  728.     markceiling = false;
  729.     }
  730.  
  731.     
  732.     // calculate incremental stepping values for texture edges
  733.     worldtop >>= 4;
  734.     worldbottom >>= 4;
  735.     
  736.     topstep = -FixedMul (rw_scalestep, worldtop);
  737.     topfrac = (centeryfrac>>4) - FixedMul (worldtop, rw_scale);
  738.  
  739.     bottomstep = -FixedMul (rw_scalestep,worldbottom);
  740.     bottomfrac = (centeryfrac>>4) - FixedMul (worldbottom, rw_scale);
  741.     
  742.  
  743.     if (backsector)
  744.     {    
  745.     worldhigh >>= 4;
  746.     worldlow >>= 4;
  747.  
  748.     if (worldhigh < worldtop)
  749.     {
  750.         pixhigh = (centeryfrac>>4) - FixedMul (worldhigh, rw_scale);
  751.         pixhighstep = -FixedMul (rw_scalestep,worldhigh);
  752.     }
  753.     
  754.     if (worldlow > worldbottom)
  755.     {
  756.         pixlow = (centeryfrac>>4) - FixedMul (worldlow, rw_scale);
  757.         pixlowstep = -FixedMul (rw_scalestep,worldlow);
  758.     }
  759.     }
  760.     
  761.     // render it
  762.     if (markceiling)
  763.     ceilingplane = R_CheckPlane (ceilingplane, rw_x, rw_stopx-1);
  764.     
  765.     if (markfloor)
  766.     floorplane = R_CheckPlane (floorplane, rw_x, rw_stopx-1);
  767.  
  768.     R_RenderSegLoop ();
  769.  
  770.     
  771.     // save sprite clipping info
  772.     if ( ((ds_p->silhouette & SIL_TOP) || maskedtexture)
  773.      && !ds_p->sprtopclip)
  774.     {
  775.     memcpy (lastopening, ceilingclip+start, 2*(rw_stopx-start));
  776.     ds_p->sprtopclip = lastopening - start;
  777.     lastopening += rw_stopx - start;
  778.     }
  779.     
  780.     if ( ((ds_p->silhouette & SIL_BOTTOM) || maskedtexture)
  781.      && !ds_p->sprbottomclip)
  782.     {
  783.     memcpy (lastopening, floorclip+start, 2*(rw_stopx-start));
  784.     ds_p->sprbottomclip = lastopening - start;
  785.     lastopening += rw_stopx - start;    
  786.     }
  787.  
  788.     if (maskedtexture && !(ds_p->silhouette&SIL_TOP))
  789.     {
  790.     ds_p->silhouette |= SIL_TOP;
  791.     ds_p->tsilheight = MININT;
  792.     }
  793.     if (maskedtexture && !(ds_p->silhouette&SIL_BOTTOM))
  794.     {
  795.     ds_p->silhouette |= SIL_BOTTOM;
  796.     ds_p->bsilheight = MAXINT;
  797.     }
  798.     ds_p++;
  799. }
  800.  
  801.