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