Annotation of doom/r_plane.c, revision 1.1.1.4

1.1.1.3   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.4 ! root        8: // This program is free software; you can redistribute it and/or
        !             9: // modify it under the terms of the GNU General Public License
        !            10: // as published by the Free Software Foundation; either version 2
        !            11: // of the License, or (at your option) any later version.
1.1.1.3   root       12: //
1.1.1.4 ! root       13: // This program is distributed in the hope that it will be useful,
1.1.1.3   root       14: // but WITHOUT ANY WARRANTY; without even the implied warranty of
1.1.1.4 ! root       15: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        !            16: // GNU General Public License for more details.
1.1.1.3   root       17: //
                     18: // $Log:$
                     19: //
                     20: // DESCRIPTION:
                     21: //     Here is a core component: drawing the floors and ceilings,
                     22: //      while maintaining a per column clipping list only.
                     23: //     Moreover, the sky areas have to be determined.
                     24: //
                     25: //-----------------------------------------------------------------------------
1.1       root       26: 
                     27: 
1.1.1.3   root       28: static const char
                     29: rcsid[] = "$Id: r_plane.c,v 1.4 1997/02/03 16:47:55 b1 Exp $";
1.1       root       30: 
1.1.1.3   root       31: #include <stdlib.h>
1.1       root       32: 
1.1.1.3   root       33: #include "i_system.h"
                     34: #include "z_zone.h"
                     35: #include "w_wad.h"
1.1       root       36: 
1.1.1.3   root       37: #include "doomdef.h"
                     38: #include "doomstat.h"
1.1       root       39: 
1.1.1.3   root       40: #include "r_local.h"
                     41: #include "r_sky.h"
1.1       root       42: 
1.1.1.2   root       43: 
                     44: 
1.1.1.3   root       45: planefunction_t                floorfunc;
                     46: planefunction_t                ceilingfunc;
1.1.1.2   root       47: 
1.1.1.3   root       48: //
                     49: // opening
                     50: //
1.1.1.2   root       51: 
1.1.1.3   root       52: // Here comes the obnoxious "visplane".
                     53: #define MAXVISPLANES   128
                     54: visplane_t             visplanes[MAXVISPLANES];
                     55: visplane_t*            lastvisplane;
                     56: visplane_t*            floorplane;
                     57: visplane_t*            ceilingplane;
1.1.1.2   root       58: 
1.1.1.3   root       59: // ?
                     60: #define MAXOPENINGS    SCREENWIDTH*64
                     61: short                  openings[MAXOPENINGS];
                     62: short*                 lastopening;
1.1.1.2   root       63: 
                     64: 
1.1.1.3   root       65: //
1.1.1.2   root       66: // Clip values are the solid pixel bounding the range.
1.1.1.3   root       67: //  floorclip starts out SCREENHEIGHT
                     68: //  ceilingclip starts out -1
1.1.1.2   root       69: //
1.1.1.3   root       70: short                  floorclip[SCREENWIDTH];
                     71: short                  ceilingclip[SCREENWIDTH];
                     72: 
1.1.1.2   root       73: //
1.1.1.3   root       74: // spanstart holds the start of a plane span
                     75: // initialized to 0 at start
1.1.1.2   root       76: //
1.1.1.3   root       77: int                    spanstart[SCREENHEIGHT];
                     78: int                    spanstop[SCREENHEIGHT];
1.1       root       79: 
1.1.1.2   root       80: //
1.1.1.3   root       81: // texture mapping
1.1.1.2   root       82: //
1.1.1.3   root       83: lighttable_t**         planezlight;
                     84: fixed_t                        planeheight;
                     85: 
                     86: fixed_t                        yslope[SCREENHEIGHT];
                     87: fixed_t                        distscale[SCREENWIDTH];
                     88: fixed_t                        basexscale;
                     89: fixed_t                        baseyscale;
                     90: 
                     91: fixed_t                        cachedheight[SCREENHEIGHT];
                     92: fixed_t                        cacheddistance[SCREENHEIGHT];
                     93: fixed_t                        cachedxstep[SCREENHEIGHT];
                     94: fixed_t                        cachedystep[SCREENHEIGHT];
                     95: 
1.1       root       96: 
                     97: 
1.1.1.2   root       98: //
                     99: // R_InitPlanes
1.1.1.3   root      100: // Only at game startup.
1.1.1.2   root      101: //
1.1.1.3   root      102: void R_InitPlanes (void)
1.1       root      103: {
1.1.1.3   root      104:   // Doh!
1.1       root      105: }
                    106: 
1.1.1.3   root      107: 
1.1.1.2   root      108: //
                    109: // R_MapPlane
                    110: //
1.1.1.3   root      111: // Uses global vars:
                    112: //  planeheight
                    113: //  ds_source
                    114: //  basexscale
                    115: //  baseyscale
                    116: //  viewx
                    117: //  viewy
                    118: //
                    119: // BASIC PRIMITIVE
                    120: //
                    121: void
                    122: R_MapPlane
                    123: ( int          y,
                    124:   int          x1,
                    125:   int          x2 )
1.1       root      126: {
1.1.1.3   root      127:     angle_t    angle;
                    128:     fixed_t    distance;
                    129:     fixed_t    length;
                    130:     unsigned   index;
                    131:        
1.1       root      132: #ifdef RANGECHECK
1.1.1.3   root      133:     if (x2 < x1
                    134:        || x1<0
                    135:        || x2>=viewwidth
                    136:        || (unsigned)y>viewheight)
                    137:     {
                    138:        I_Error ("R_MapPlane: %i, %i at %i",x1,x2,y);
                    139:     }
1.1       root      140: #endif
                    141: 
1.1.1.3   root      142:     if (planeheight != cachedheight[y])
                    143:     {
                    144:        cachedheight[y] = planeheight;
                    145:        distance = cacheddistance[y] = FixedMul (planeheight, yslope[y]);
                    146:        ds_xstep = cachedxstep[y] = FixedMul (distance,basexscale);
                    147:        ds_ystep = cachedystep[y] = FixedMul (distance,baseyscale);
                    148:     }
                    149:     else
                    150:     {
                    151:        distance = cacheddistance[y];
                    152:        ds_xstep = cachedxstep[y];
                    153:        ds_ystep = cachedystep[y];
                    154:     }
1.1       root      155:        
1.1.1.3   root      156:     length = FixedMul (distance,distscale[x1]);
                    157:     angle = (viewangle + xtoviewangle[x1])>>ANGLETOFINESHIFT;
                    158:     ds_xfrac = viewx + FixedMul(finecosine[angle], length);
                    159:     ds_yfrac = -viewy - FixedMul(finesine[angle], length);
                    160: 
                    161:     if (fixedcolormap)
                    162:        ds_colormap = fixedcolormap;
                    163:     else
                    164:     {
                    165:        index = distance >> LIGHTZSHIFT;
                    166:        
                    167:        if (index >= MAXLIGHTZ )
                    168:            index = MAXLIGHTZ-1;
1.1.1.2   root      169: 
1.1.1.3   root      170:        ds_colormap = planezlight[index];
                    171:     }
                    172:        
                    173:     ds_y = y;
                    174:     ds_x1 = x1;
                    175:     ds_x2 = x2;
1.1       root      176: 
1.1.1.3   root      177:     // high or low detail
                    178:     spanfunc ();       
1.1.1.2   root      179: }
1.1       root      180: 
1.1.1.3   root      181: 
1.1.1.2   root      182: //
                    183: // R_ClearPlanes
1.1.1.3   root      184: // At begining of frame.
1.1.1.2   root      185: //
1.1.1.3   root      186: void R_ClearPlanes (void)
1.1       root      187: {
1.1.1.3   root      188:     int                i;
                    189:     angle_t    angle;
                    190:     
                    191:     // opening / clipping determination
                    192:     for (i=0 ; i<viewwidth ; i++)
                    193:     {
                    194:        floorclip[i] = viewheight;
                    195:        ceilingclip[i] = -1;
                    196:     }
                    197: 
                    198:     lastvisplane = visplanes;
                    199:     lastopening = openings;
                    200:     
                    201:     // texture calculation
                    202:     memset (cachedheight, 0, sizeof(cachedheight));
                    203: 
                    204:     // left to right mapping
                    205:     angle = (viewangle-ANG90)>>ANGLETOFINESHIFT;
                    206:        
                    207:     // scale will be unit scale at SCREENWIDTH/2 distance
                    208:     basexscale = FixedDiv (finecosine[angle],centerxfrac);
                    209:     baseyscale = -FixedDiv (finesine[angle],centerxfrac);
                    210: }
1.1.1.2   root      211: 
1.1       root      212: 
                    213: 
                    214: 
1.1.1.2   root      215: //
                    216: // R_FindPlane
                    217: //
1.1.1.3   root      218: visplane_t*
                    219: R_FindPlane
                    220: ( fixed_t      height,
                    221:   int          picnum,
                    222:   int          lightlevel )
1.1       root      223: {
1.1.1.3   root      224:     visplane_t*        check;
                    225:        
                    226:     if (picnum == skyflatnum)
                    227:     {
                    228:        height = 0;                     // all skys map together
                    229:        lightlevel = 0;
                    230:     }
                    231:        
                    232:     for (check=visplanes; check<lastvisplane; check++)
                    233:     {
                    234:        if (height == check->height
                    235:            && picnum == check->picnum
                    236:            && lightlevel == check->lightlevel)
                    237:        {
                    238:            break;
                    239:        }
                    240:     }
                    241:     
                    242:                        
                    243:     if (check < lastvisplane)
                    244:        return check;
                    245:                
                    246:     if (lastvisplane - visplanes == MAXVISPLANES)
                    247:        I_Error ("R_FindPlane: no more visplanes");
                    248:                
                    249:     lastvisplane++;
                    250: 
                    251:     check->height = height;
                    252:     check->picnum = picnum;
                    253:     check->lightlevel = lightlevel;
                    254:     check->minx = SCREENWIDTH;
                    255:     check->maxx = -1;
                    256:     
                    257:     memset (check->top,0xff,sizeof(check->top));
                    258:                
                    259:     return check;
1.1       root      260: }
                    261: 
1.1.1.3   root      262: 
1.1.1.2   root      263: //
                    264: // R_CheckPlane
                    265: //
1.1.1.3   root      266: visplane_t*
                    267: R_CheckPlane
                    268: ( visplane_t*  pl,
                    269:   int          start,
                    270:   int          stop )
1.1       root      271: {
1.1.1.3   root      272:     int                intrl;
                    273:     int                intrh;
                    274:     int                unionl;
                    275:     int                unionh;
                    276:     int                x;
                    277:        
                    278:     if (start < pl->minx)
                    279:     {
                    280:        intrl = pl->minx;
                    281:        unionl = start;
                    282:     }
                    283:     else
                    284:     {
                    285:        unionl = pl->minx;
                    286:        intrl = start;
                    287:     }
                    288:        
                    289:     if (stop > pl->maxx)
                    290:     {
                    291:        intrh = pl->maxx;
                    292:        unionh = stop;
                    293:     }
                    294:     else
                    295:     {
                    296:        unionh = pl->maxx;
                    297:        intrh = stop;
                    298:     }
                    299: 
                    300:     for (x=intrl ; x<= intrh ; x++)
                    301:        if (pl->top[x] != 0xff)
                    302:            break;
                    303: 
                    304:     if (x > intrh)
                    305:     {
                    306:        pl->minx = unionl;
                    307:        pl->maxx = unionh;
                    308: 
                    309:        // use the same one
                    310:        return pl;              
                    311:     }
                    312:        
                    313:     // make a new visplane
                    314:     lastvisplane->height = pl->height;
                    315:     lastvisplane->picnum = pl->picnum;
                    316:     lastvisplane->lightlevel = pl->lightlevel;
                    317:     
                    318:     pl = lastvisplane++;
                    319:     pl->minx = start;
                    320:     pl->maxx = stop;
                    321: 
                    322:     memset (pl->top,0xff,sizeof(pl->top));
                    323:                
                    324:     return pl;
1.1       root      325: }
                    326: 
1.1.1.3   root      327: 
1.1.1.2   root      328: //
                    329: // R_MakeSpans
                    330: //
1.1.1.3   root      331: void
                    332: R_MakeSpans
                    333: ( int          x,
                    334:   int          t1,
                    335:   int          b1,
                    336:   int          t2,
                    337:   int          b2 )
1.1       root      338: {
1.1.1.3   root      339:     while (t1 < t2 && t1<=b1)
                    340:     {
                    341:        R_MapPlane (t1,spanstart[t1],x-1);
                    342:        t1++;
                    343:     }
                    344:     while (b1 > b2 && b1>=t1)
                    345:     {
                    346:        R_MapPlane (b1,spanstart[b1],x-1);
                    347:        b1--;
                    348:     }
                    349:        
                    350:     while (t2 < t1 && t2<=b2)
                    351:     {
                    352:        spanstart[t2] = x;
                    353:        t2++;
                    354:     }
                    355:     while (b2 > b1 && b2>=t2)
                    356:     {
                    357:        spanstart[b2] = x;
                    358:        b2--;
                    359:     }
1.1       root      360: }
                    361: 
1.1.1.3   root      362: 
                    363: 
1.1.1.2   root      364: //
                    365: // R_DrawPlanes
1.1.1.3   root      366: // At the end of each frame.
1.1.1.2   root      367: //
1.1.1.3   root      368: void R_DrawPlanes (void)
1.1       root      369: {
1.1.1.3   root      370:     visplane_t*                pl;
                    371:     int                        light;
                    372:     int                        x;
                    373:     int                        stop;
                    374:     int                        angle;
                    375:                                
1.1       root      376: #ifdef RANGECHECK
1.1.1.3   root      377:     if (ds_p - drawsegs > MAXDRAWSEGS)
                    378:        I_Error ("R_DrawPlanes: drawsegs overflow (%i)",
                    379:                 ds_p - drawsegs);
                    380:     
                    381:     if (lastvisplane - visplanes > MAXVISPLANES)
                    382:        I_Error ("R_DrawPlanes: visplane overflow (%i)",
                    383:                 lastvisplane - visplanes);
                    384:     
                    385:     if (lastopening - openings > MAXOPENINGS)
                    386:        I_Error ("R_DrawPlanes: opening overflow (%i)",
                    387:                 lastopening - openings);
1.1       root      388: #endif
                    389: 
1.1.1.3   root      390:     for (pl = visplanes ; pl < lastvisplane ; pl++)
                    391:     {
                    392:        if (pl->minx > pl->maxx)
                    393:            continue;
                    394: 
                    395:        
                    396:        // sky flat
                    397:        if (pl->picnum == skyflatnum)
1.1       root      398:        {
1.1.1.3   root      399:            dc_iscale = pspriteiscale>>detailshift;
                    400:            
                    401:            // Sky is allways drawn full bright,
                    402:            //  i.e. colormaps[0] is used.
                    403:            // Because of this hack, sky is not affected
                    404:            //  by INVUL inverse mapping.
                    405:            dc_colormap = colormaps;
                    406:            dc_texturemid = skytexturemid;
                    407:            for (x=pl->minx ; x <= pl->maxx ; x++)
                    408:            {
                    409:                dc_yl = pl->top[x];
                    410:                dc_yh = pl->bottom[x];
                    411: 
                    412:                if (dc_yl <= dc_yh)
1.1.1.2   root      413:                {
1.1.1.3   root      414:                    angle = (viewangle + xtoviewangle[x])>>ANGLETOSKYSHIFT;
                    415:                    dc_x = x;
                    416:                    dc_source = R_GetColumn(skytexture, angle);
                    417:                    colfunc ();
1.1.1.2   root      418:                }
1.1.1.3   root      419:            }
                    420:            continue;
                    421:        }
                    422:        
                    423:        // regular flat
                    424:        ds_source = W_CacheLumpNum(firstflat +
                    425:                                   flattranslation[pl->picnum],
                    426:                                   PU_STATIC);
                    427:        
                    428:        planeheight = abs(pl->height-viewz);
                    429:        light = (pl->lightlevel >> LIGHTSEGSHIFT)+extralight;
1.1       root      430: 
1.1.1.3   root      431:        if (light >= LIGHTLEVELS)
                    432:            light = LIGHTLEVELS-1;
1.1.1.2   root      433: 
1.1.1.3   root      434:        if (light < 0)
                    435:            light = 0;
                    436: 
                    437:        planezlight = zlight[light];
                    438: 
                    439:        pl->top[pl->maxx+1] = 0xff;
                    440:        pl->top[pl->minx-1] = 0xff;
                    441:                
                    442:        stop = pl->maxx + 1;
                    443: 
                    444:        for (x=pl->minx ; x<= stop ; x++)
                    445:        {
                    446:            R_MakeSpans(x,pl->top[x-1],
                    447:                        pl->bottom[x-1],
                    448:                        pl->top[x],
                    449:                        pl->bottom[x]);
1.1       root      450:        }
1.1.1.3   root      451:        
                    452:        Z_ChangeTag (ds_source, PU_CACHE);
                    453:     }
1.1       root      454: }

unix.superglobalmegacorp.com

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