home *** CD-ROM | disk | FTP | other *** search
/ ST-Computer Leser-CD 2000 January / LCD_01_2000.iso / games / doom / pmdoom / src / r_main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-12-17  |  16.1 KB  |  845 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. /*     Rendering main loop and setup functions, */
  21. /*      utility functions (BSP, geometry, trigonometry). */
  22. /*     See tables.c, too. */
  23. /*  */
  24. /* ----------------------------------------------------------------------------- */
  25.  
  26.  
  27. static const char rcsid[] = "$Id: r_main.c,v 1.5 1997/02/03 22:45:12 b1 Exp $";
  28.  
  29.  
  30.  
  31. #include <stdlib.h>
  32. #include <math.h>
  33.  
  34.  
  35. #include "doomdef.h"
  36. #include "d_net.h"
  37.  
  38. #include "m_bbox.h"
  39.  
  40. #include "r_local.h"
  41. #include "r_sky.h"
  42.  
  43. #include "i_video.h"
  44.  
  45.  
  46.  
  47. /*  Fineangles in the SCREENWIDTH wide window. */
  48. #define FIELDOFVIEW        2048    
  49.  
  50. int            viewangleoffset;
  51.  
  52. /*  increment every time a check is made */
  53. int            validcount = 1;        
  54.  
  55.  
  56. lighttable_t*        fixedcolormap;
  57. extern lighttable_t**    walllights;
  58.  
  59. int            centerx;
  60. int            centery;
  61.  
  62. fixed_t            centerxfrac;
  63. fixed_t            centeryfrac;
  64. fixed_t            projection;
  65.  
  66. /*  just for profiling purposes */
  67. int            framecount;    
  68.  
  69. int            sscount;
  70. int            linecount;
  71. int            loopcount;
  72.  
  73. fixed_t            viewx;
  74. fixed_t            viewy;
  75. fixed_t            viewz;
  76.  
  77. angle_t            viewangle;
  78.  
  79. fixed_t            viewcos;
  80. fixed_t            viewsin;
  81.  
  82. player_t*        viewplayer;
  83.  
  84. /*  0 = high, 1 = low */
  85. int            detailshift;    
  86.  
  87. /*  */
  88. /*  precalculated math tables */
  89. /*  */
  90. angle_t            clipangle;
  91.  
  92. /*  The viewangletox[viewangle + FINEANGLES/4] lookup */
  93. /*  maps the visible view angles to screen X coordinates, */
  94. /*  flattening the arc to a flat projection plane. */
  95. /*  There will be many angles mapped to the same X.  */
  96. int            viewangletox[FINEANGLES/2];
  97.  
  98. /*  The xtoviewangleangle[] table maps a screen pixel */
  99. /*  to the lowest viewangle that maps back to x ranges */
  100. /*  from clipangle to -clipangle. */
  101. angle_t            xtoviewangle[SCREENWIDTH+1];
  102.  
  103.  
  104. /*  UNUSED. */
  105. /*  The finetangentgent[angle+FINEANGLES/4] table */
  106. /*  holds the fixed_t tangent values for view angles, */
  107. /*  ranging from MININT to 0 to MAXINT. */
  108. /*  fixed_t        finetangent[FINEANGLES/2]; */
  109.  
  110. /*  fixed_t        finesine[5*FINEANGLES/4]; */
  111. fixed_t*        finecosine = &finesine[FINEANGLES/4];
  112.  
  113.  
  114. lighttable_t*        scalelight[LIGHTLEVELS][MAXLIGHTSCALE];
  115. lighttable_t*        scalelightfixed[MAXLIGHTSCALE];
  116. lighttable_t*        zlight[LIGHTLEVELS][MAXLIGHTZ];
  117.  
  118. /*  bumped light from gun blasts */
  119. int            extralight;            
  120.  
  121.  
  122.  
  123. void (*colfunc) (void);
  124. void (*basecolfunc) (void);
  125. void (*fuzzcolfunc) (void);
  126. void (*transcolfunc) (void);
  127. void (*spanfunc) (void);
  128.  
  129.  
  130.  
  131. /*  */
  132. /*  R_AddPointToBox */
  133. /*  Expand a given bbox */
  134. /*  so that it encloses a given point. */
  135. /*  */
  136. void
  137. R_AddPointToBox
  138. ( int        x,
  139.   int        y,
  140.   fixed_t*    box )
  141. {
  142.     if (x< box[BOXLEFT])
  143.     box[BOXLEFT] = x;
  144.     if (x> box[BOXRIGHT])
  145.     box[BOXRIGHT] = x;
  146.     if (y< box[BOXBOTTOM])
  147.     box[BOXBOTTOM] = y;
  148.     if (y> box[BOXTOP])
  149.     box[BOXTOP] = y;
  150. }
  151.  
  152.  
  153. /*  */
  154. /*  R_PointOnSide */
  155. /*  Traverse BSP (sub) tree, */
  156. /*   check point against partition plane. */
  157. /*  Returns side 0 (front) or 1 (back). */
  158. /*  */
  159. int
  160. R_PointOnSide
  161. ( fixed_t    x,
  162.   fixed_t    y,
  163.   node_t*    node )
  164. {
  165.     fixed_t    dx;
  166.     fixed_t    dy;
  167.     fixed_t    left;
  168.     fixed_t    right;
  169.     
  170.     if (!node->dx)
  171.     {
  172.     if (x <= node->x)
  173.         return node->dy > 0;
  174.     
  175.     return node->dy < 0;
  176.     }
  177.     if (!node->dy)
  178.     {
  179.     if (y <= node->y)
  180.         return node->dx < 0;
  181.     
  182.     return node->dx > 0;
  183.     }
  184.     
  185.     dx = (x - node->x);
  186.     dy = (y - node->y);
  187.     
  188.     /*  Try to quickly decide by looking at sign bits. */
  189.     if ( (node->dy ^ node->dx ^ dx ^ dy)&0x80000000 )
  190.     {
  191.     if  ( (node->dy ^ dx) & 0x80000000 )
  192.     {
  193.         /*  (left is negative) */
  194.         return 1;
  195.     }
  196.     return 0;
  197.     }
  198.  
  199.     left = FixedMul ( node->dy>>FRACBITS , dx );
  200.     right = FixedMul ( dy , node->dx>>FRACBITS );
  201.     
  202.     if (right < left)
  203.     {
  204.     /*  front side */
  205.     return 0;
  206.     }
  207.     /*  back side */
  208.     return 1;            
  209. }
  210.  
  211.  
  212. int
  213. R_PointOnSegSide
  214. ( fixed_t    x,
  215.   fixed_t    y,
  216.   seg_t*    line )
  217. {
  218.     fixed_t    lx;
  219.     fixed_t    ly;
  220.     fixed_t    ldx;
  221.     fixed_t    ldy;
  222.     fixed_t    dx;
  223.     fixed_t    dy;
  224.     fixed_t    left;
  225.     fixed_t    right;
  226.     
  227.     lx = line->v1->x;
  228.     ly = line->v1->y;
  229.     
  230.     ldx = line->v2->x - lx;
  231.     ldy = line->v2->y - ly;
  232.     
  233.     if (!ldx)
  234.     {
  235.     if (x <= lx)
  236.         return ldy > 0;
  237.     
  238.     return ldy < 0;
  239.     }
  240.     if (!ldy)
  241.     {
  242.     if (y <= ly)
  243.         return ldx < 0;
  244.     
  245.     return ldx > 0;
  246.     }
  247.     
  248.     dx = (x - lx);
  249.     dy = (y - ly);
  250.     
  251.     /*  Try to quickly decide by looking at sign bits. */
  252.     if ( (ldy ^ ldx ^ dx ^ dy)&0x80000000 )
  253.     {
  254.     if  ( (ldy ^ dx) & 0x80000000 )
  255.     {
  256.         /*  (left is negative) */
  257.         return 1;
  258.     }
  259.     return 0;
  260.     }
  261.  
  262.     left = FixedMul ( ldy>>FRACBITS , dx );
  263.     right = FixedMul ( dy , ldx>>FRACBITS );
  264.     
  265.     if (right < left)
  266.     {
  267.     /*  front side */
  268.     return 0;
  269.     }
  270.     /*  back side */
  271.     return 1;            
  272. }
  273.  
  274.  
  275. /*  */
  276. /*  R_PointToAngle */
  277. /*  To get a global angle from cartesian coordinates, */
  278. /*   the coordinates are flipped until they are in */
  279. /*   the first octant of the coordinate system, then */
  280. /*   the y (<=x) is scaled and divided by x to get a */
  281. /*   tangent (slope) value which is looked up in the */
  282. /*   tantoangle[] table. */
  283.  
  284. /*  */
  285.  
  286.  
  287.  
  288.  
  289. angle_t
  290. R_PointToAngle
  291. ( fixed_t    x,
  292.   fixed_t    y )
  293. {    
  294.     x -= viewx;
  295.     y -= viewy;
  296.     
  297.     if ( (!x) && (!y) )
  298.     return 0;
  299.  
  300.     if (x>= 0)
  301.     {
  302.     /*  x >=0 */
  303.     if (y>= 0)
  304.     {
  305.         /*  y>= 0 */
  306.  
  307.         if (x>y)
  308.         {
  309.         /*  octant 0 */
  310.         return tantoangle[ SlopeDiv(y,x)];
  311.         }
  312.         else
  313.         {
  314.         /*  octant 1 */
  315.         return ANG90-1-tantoangle[ SlopeDiv(x,y)];
  316.         }
  317.     }
  318.     else
  319.     {
  320.         /*  y<0 */
  321.         y = -y;
  322.  
  323.         if (x>y)
  324.         {
  325.         /*  octant 8 */
  326.         return -tantoangle[SlopeDiv(y,x)];
  327.         }
  328.         else
  329.         {
  330.         /*  octant 7 */
  331.         return ANG270+tantoangle[ SlopeDiv(x,y)];
  332.         }
  333.     }
  334.     }
  335.     else
  336.     {
  337.     /*  x<0 */
  338.     x = -x;
  339.  
  340.     if (y>= 0)
  341.     {
  342.         /*  y>= 0 */
  343.         if (x>y)
  344.         {
  345.         /*  octant 3 */
  346.         return ANG180-1-tantoangle[ SlopeDiv(y,x)];
  347.         }
  348.         else
  349.         {
  350.         /*  octant 2 */
  351.         return ANG90+ tantoangle[ SlopeDiv(x,y)];
  352.         }
  353.     }
  354.     else
  355.     {
  356.         /*  y<0 */
  357.         y = -y;
  358.  
  359.         if (x>y)
  360.         {
  361.         /*  octant 4 */
  362.         return ANG180+tantoangle[ SlopeDiv(y,x)];
  363.         }
  364.         else
  365.         {
  366.          /*  octant 5 */
  367.         return ANG270-1-tantoangle[ SlopeDiv(x,y)];
  368.         }
  369.     }
  370.     }
  371.     return 0;
  372. }
  373.  
  374.  
  375. angle_t
  376. R_PointToAngle2
  377. ( fixed_t    x1,
  378.   fixed_t    y1,
  379.   fixed_t    x2,
  380.   fixed_t    y2 )
  381. {    
  382.     viewx = x1;
  383.     viewy = y1;
  384.     
  385.     return R_PointToAngle (x2, y2);
  386. }
  387.  
  388.  
  389. fixed_t
  390. R_PointToDist
  391. ( fixed_t    x,
  392.   fixed_t    y )
  393. {
  394.     int        angle;
  395.     fixed_t    dx;
  396.     fixed_t    dy;
  397.     fixed_t    temp;
  398.     fixed_t    dist;
  399.     
  400.     dx = abs(x - viewx);
  401.     dy = abs(y - viewy);
  402.     
  403.     if (dy>dx)
  404.     {
  405.     temp = dx;
  406.     dx = dy;
  407.     dy = temp;
  408.     }
  409.     
  410.     angle = (tantoangle[ FixedDiv(dy,dx)>>DBITS ]+ANG90) >> ANGLETOFINESHIFT;
  411.  
  412.     /*  use as cosine */
  413.     dist = FixedDiv (dx, finesine[angle] );    
  414.     
  415.     return dist;
  416. }
  417.  
  418.  
  419.  
  420.  
  421. /*  */
  422. /*  R_InitPointToAngle */
  423. /*  */
  424. void R_InitPointToAngle (void)
  425. {
  426. }
  427.  
  428.  
  429. /*  */
  430. /*  R_ScaleFromGlobalAngle */
  431. /*  Returns the texture mapping scale */
  432. /*   for the current line (horizontal span) */
  433. /*   at the given angle. */
  434. /*  rw_distance must be calculated first. */
  435. /*  */
  436. fixed_t R_ScaleFromGlobalAngle (angle_t visangle)
  437. {
  438.     fixed_t        scale;
  439.     int            anglea;
  440.     int            angleb;
  441.     int            sinea;
  442.     int            sineb;
  443.     fixed_t        num;
  444.     int            den;
  445.  
  446.     anglea = ANG90 + (visangle-viewangle);
  447.     angleb = ANG90 + (visangle-rw_normalangle);
  448.  
  449.     /*  both sines are allways positive */
  450.     sinea = finesine[anglea>>ANGLETOFINESHIFT];    
  451.     sineb = finesine[angleb>>ANGLETOFINESHIFT];
  452.     num = FixedMul(projection,sineb)<<detailshift;
  453.     den = FixedMul(rw_distance,sinea);
  454.  
  455.     if (den > num>>16)
  456.     {
  457.     scale = FixedDiv (num, den);
  458.  
  459.     if (scale > 64*FRACUNIT)
  460.         scale = 64*FRACUNIT;
  461.     else if (scale < 256)
  462.         scale = 256;
  463.     }
  464.     else
  465.     scale = 64*FRACUNIT;
  466.     
  467.     return scale;
  468. }
  469.  
  470.  
  471.  
  472. /*  */
  473. /*  R_InitTables */
  474. /*  */
  475. void R_InitTables (void)
  476. {
  477. }
  478.  
  479.  
  480.  
  481. /*  */
  482. /*  R_InitTextureMapping */
  483. /*  */
  484. void R_InitTextureMapping (void)
  485. {
  486.     int            i;
  487.     int            x;
  488.     int            t;
  489.     fixed_t        focallength;
  490.     
  491.     /*  Use tangent table to generate viewangletox: */
  492.     /*   viewangletox will give the next greatest x */
  493.     /*   after the view angle. */
  494.     /*  */
  495.     /*  Calc focallength */
  496.     /*   so FIELDOFVIEW angles covers SCREENWIDTH. */
  497.     focallength = FixedDiv (centerxfrac,
  498.                 finetangent[FINEANGLES/4+FIELDOFVIEW/2] );
  499.     
  500.     for (i=0 ; i<FINEANGLES/2 ; i++)
  501.     {
  502.     if (finetangent[i] > FRACUNIT*2)
  503.         t = -1;
  504.     else if (finetangent[i] < -FRACUNIT*2)
  505.         t = viewwidth+1;
  506.     else
  507.     {
  508.         t = FixedMul (finetangent[i], focallength);
  509.         t = (centerxfrac - t+FRACUNIT-1)>>FRACBITS;
  510.  
  511.         if (t < -1)
  512.         t = -1;
  513.         else if (t>viewwidth+1)
  514.         t = viewwidth+1;
  515.     }
  516.     viewangletox[i] = t;
  517.     }
  518.     
  519.     /*  Scan viewangletox[] to generate xtoviewangle[]: */
  520.     /*   xtoviewangle will give the smallest view angle */
  521.     /*   that maps to x.     */
  522.     for (x=0;x<=viewwidth;x++)
  523.     {
  524.     i = 0;
  525.     while (viewangletox[i]>x)
  526.         i++;
  527.     xtoviewangle[x] = (i<<ANGLETOFINESHIFT)-ANG90;
  528.     }
  529.     
  530.     /*  Take out the fencepost cases from viewangletox. */
  531.     for (i=0 ; i<FINEANGLES/2 ; i++)
  532.     {
  533.     t = FixedMul (finetangent[i], focallength);
  534.     t = centerx - t;
  535.     
  536.     if (viewangletox[i] == -1)
  537.         viewangletox[i] = 0;
  538.     else if (viewangletox[i] == viewwidth+1)
  539.         viewangletox[i]  = viewwidth;
  540.     }
  541.     
  542.     clipangle = xtoviewangle[0];
  543. }
  544.  
  545.  
  546.  
  547. /*  */
  548. /*  R_InitLightTables */
  549. /*  Only inits the zlight table, */
  550. /*   because the scalelight table changes with view size. */
  551. /*  */
  552. #define DISTMAP        2
  553.  
  554. void R_InitLightTables (void)
  555. {
  556.     int        i;
  557.     int        j;
  558.     int        level;
  559.     int        startmap;     
  560.     int        scale;
  561.     
  562.     /*  Calculate the light levels to use */
  563.     /*   for each level / distance combination. */
  564.     for (i=0 ; i< LIGHTLEVELS ; i++)
  565.     {
  566.     startmap = ((LIGHTLEVELS-1-i)*2)*NUMCOLORMAPS/LIGHTLEVELS;
  567.     for (j=0 ; j<MAXLIGHTZ ; j++)
  568.     {
  569.         scale = FixedDiv ((SCREENWIDTH/2*FRACUNIT), (j+1)<<LIGHTZSHIFT);
  570.         scale >>= LIGHTSCALESHIFT;
  571.         level = startmap - scale/DISTMAP;
  572.         
  573.         if (level < 0)
  574.         level = 0;
  575.  
  576.         if (level >= NUMCOLORMAPS)
  577.         level = NUMCOLORMAPS-1;
  578.  
  579.         zlight[i][j] = colormaps + level*256;
  580.     }
  581.     }
  582. }
  583.  
  584.  
  585.  
  586. /*  */
  587. /*  R_SetViewSize */
  588. /*  Do not really change anything here, */
  589. /*   because it might be in the middle of a refresh. */
  590. /*  The change will take effect next refresh. */
  591. /*  */
  592. boolean        setsizeneeded;
  593. int        setblocks;
  594. int        setdetail;
  595.  
  596.  
  597. void
  598. R_SetViewSize
  599. ( int        blocks,
  600.   int        detail )
  601. {
  602.     setsizeneeded = true;
  603.     setblocks = blocks;
  604.     setdetail = detail;
  605. }
  606.  
  607.  
  608. /*  */
  609. /*  R_ExecuteSetViewSize */
  610. /*  */
  611. void R_ExecuteSetViewSize (void)
  612. {
  613.     fixed_t    cosadj;
  614.     fixed_t    dy;
  615.     int        i;
  616.     int        j;
  617.     int        level;
  618.     int        startmap;     
  619.  
  620.     setsizeneeded = false;
  621.  
  622.     if (setblocks == 11)
  623.     {
  624.     scaledviewwidth = SCREENWIDTH;
  625.     viewheight = SCREENHEIGHT;
  626.     }
  627.     else
  628.     {
  629.     scaledviewwidth = setblocks*32;
  630.     viewheight = (setblocks*168/10)&~7;
  631.     }
  632.     
  633.     detailshift = setdetail;
  634.     viewwidth = scaledviewwidth>>detailshift;
  635.     
  636.     centery = viewheight/2;
  637.     centerx = viewwidth/2;
  638.     centerxfrac = centerx<<FRACBITS;
  639.     centeryfrac = centery<<FRACBITS;
  640.     projection = centerxfrac;
  641.  
  642.     if (!detailshift)
  643.     {
  644.     colfunc = basecolfunc = R_DrawColumn;
  645.     fuzzcolfunc = R_DrawFuzzColumn;
  646.     transcolfunc = R_DrawTranslatedColumn;
  647.     spanfunc = R_DrawSpan;
  648.     }
  649.     else
  650.     {
  651.     colfunc = basecolfunc = R_DrawColumnLow;
  652.     fuzzcolfunc = R_DrawFuzzColumnLow;
  653.     transcolfunc = R_DrawTranslatedColumnLow;
  654.     spanfunc = R_DrawSpanLow;
  655.     }
  656.  
  657.     R_InitBuffer (scaledviewwidth, viewheight);
  658.     
  659.     R_InitTextureMapping ();
  660.     
  661.     /*  psprite scales */
  662.     pspritescale = FRACUNIT*viewwidth/SCREENWIDTH;
  663.     pspriteiscale = FRACUNIT*SCREENWIDTH/viewwidth;
  664.     
  665.     /*  thing clipping */
  666.     for (i=0 ; i<viewwidth ; i++)
  667.     screenheightarray[i] = viewheight;
  668.     
  669.     /*  planes */
  670.     for (i=0 ; i<viewheight ; i++)
  671.     {
  672.     dy = ((i-viewheight/2)<<FRACBITS)+FRACUNIT/2;
  673.     dy = abs(dy);
  674.     yslope[i] = FixedDiv ( (viewwidth<<detailshift)/2*FRACUNIT, dy);
  675.     }
  676.     
  677.     for (i=0 ; i<viewwidth ; i++)
  678.     {
  679.     cosadj = abs(finecosine[xtoviewangle[i]>>ANGLETOFINESHIFT]);
  680.     distscale[i] = FixedDiv (FRACUNIT,cosadj);
  681.     }
  682.     
  683.     /*  Calculate the light levels to use */
  684.     /*   for each level / scale combination. */
  685.     for (i=0 ; i< LIGHTLEVELS ; i++)
  686.     {
  687.     startmap = ((LIGHTLEVELS-1-i)*2)*NUMCOLORMAPS/LIGHTLEVELS;
  688.     for (j=0 ; j<MAXLIGHTSCALE ; j++)
  689.     {
  690.         level = startmap - j*SCREENWIDTH/(viewwidth<<detailshift)/DISTMAP;
  691.         
  692.         if (level < 0)
  693.         level = 0;
  694.  
  695.         if (level >= NUMCOLORMAPS)
  696.         level = NUMCOLORMAPS-1;
  697.  
  698.         scalelight[i][j] = colormaps + level*256;
  699.     }
  700.     }
  701. }
  702.  
  703.  
  704.  
  705. /*  */
  706. /*  R_Init */
  707. /*  */
  708. extern int    detailLevel;
  709. extern int    screenblocks;
  710.  
  711.  
  712.  
  713. void R_Init (void)
  714. {
  715.     R_InitData ();
  716.     printf(".");
  717. /*     printf ("\nR_InitData"); */
  718.     R_InitPointToAngle ();
  719. /*     printf ("\nR_InitPointToAngle"); */
  720.     printf(".");
  721.     R_InitTables ();
  722.     /*  viewwidth / viewheight / detailLevel are set by the defaults */
  723. /*     printf ("\nR_InitTables"); */
  724.     printf(".");
  725.  
  726.     R_SetViewSize (screenblocks, detailLevel);
  727.  
  728.     R_InitPlanes ();
  729. /*     printf ("\nR_InitPlanes"); */
  730.     printf(".");
  731.     R_InitLightTables ();
  732. /*     printf ("\nR_InitLightTables"); */
  733.     printf(".");
  734.     R_InitSkyMap ();
  735. /*     printf ("\nR_InitSkyMap"); */
  736.     printf(".");
  737.     R_InitTranslationTables ();
  738. /*     printf ("\nR_InitTranslationsTables");     */
  739.     printf("...");
  740.  
  741.     framecount = 0;
  742. }
  743.  
  744.  
  745. /*  */
  746. /*  R_PointInSubsector */
  747. /*  */
  748. subsector_t*
  749. R_PointInSubsector
  750. ( fixed_t    x,
  751.   fixed_t    y )
  752. {
  753.     node_t*    node;
  754.     int        side;
  755.     int        nodenum;
  756.  
  757.     /*  single subsector is a special case */
  758.     if (!numnodes)                
  759.     return subsectors;
  760.         
  761.     nodenum = numnodes-1;
  762.  
  763.     while (! (nodenum & NF_SUBSECTOR) )
  764.     {
  765.     node = &nodes[nodenum];
  766.     side = R_PointOnSide (x, y, node);
  767.     nodenum = node->children[side];
  768.     }
  769.     
  770.     return &subsectors[nodenum & ~NF_SUBSECTOR];
  771. }
  772.  
  773.  
  774.  
  775. /*  */
  776. /*  R_SetupFrame */
  777. /*  */
  778. void R_SetupFrame (player_t* player)
  779. {        
  780.     int        i;
  781.     
  782.     viewplayer = player;
  783.     viewx = player->mo->x;
  784.     viewy = player->mo->y;
  785.     viewangle = player->mo->angle + viewangleoffset;
  786.     extralight = player->extralight;
  787.  
  788.     viewz = player->viewz;
  789.     
  790.     viewsin = finesine[viewangle>>ANGLETOFINESHIFT];
  791.     viewcos = finecosine[viewangle>>ANGLETOFINESHIFT];
  792.     
  793.     sscount = 0;
  794.     
  795.     if (player->fixedcolormap)
  796.     {
  797.     fixedcolormap = colormaps + player->fixedcolormap*256;
  798.     
  799.     walllights = scalelightfixed;
  800.  
  801.     for (i=0 ; i<MAXLIGHTSCALE ; i++)
  802.         scalelightfixed[i] = fixedcolormap;
  803.     }
  804.     else
  805.     fixedcolormap = 0;
  806.         
  807.     framecount++;
  808.     validcount++;
  809. }
  810.  
  811.  
  812.  
  813. /*  */
  814. /*  R_RenderView */
  815. /*  */
  816. void R_RenderPlayerView (player_t* player)
  817. {    
  818.     R_SetupFrame (player);
  819.  
  820.     /*  Clear buffers. */
  821.     R_ClearClipSegs ();
  822.     R_ClearDrawSegs ();
  823.     R_ClearPlanes ();
  824.     R_ClearSprites ();
  825.     
  826.     /*  check for new console commands. */
  827.     NetUpdate ();
  828.  
  829.     /*  The head node is the last node output. */
  830.     R_RenderBSPNode (numnodes-1);
  831.     
  832.     /*  Check for new console commands. */
  833.     NetUpdate ();
  834.     
  835.     R_DrawPlanes ();
  836.     
  837.     /*  Check for new console commands. */
  838.     NetUpdate ();
  839.     
  840.     R_DrawMasked ();
  841.  
  842.     /*  Check for new console commands. */
  843.     NetUpdate ();                
  844. }
  845.