Annotation of doom/r_main.c, revision 1.1.1.6

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.