Annotation of doom/r_main.c, revision 1.1.1.4

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

unix.superglobalmegacorp.com

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