Annotation of quake1/r_misc.c, revision 1.1.1.1

1.1       root        1: // r_misc.c
                      2: 
                      3: #include "quakedef.h"
                      4: #include "r_local.h"
                      5: 
                      6: 
                      7: /*
                      8: ===============
                      9: R_CheckVariables
                     10: ===============
                     11: */
                     12: void R_CheckVariables (void)
                     13: {
                     14:        static float    oldbright;
                     15: 
                     16:        if (r_fullbright.value != oldbright)
                     17:        {
                     18:                oldbright = r_fullbright.value;
                     19:                D_FlushCaches ();       // so all lighting changes
                     20:        }
                     21: }
                     22: 
                     23: 
                     24: /*
                     25: ============
                     26: Show
                     27: 
                     28: Debugging use
                     29: ============
                     30: */
                     31: void Show (void)
                     32: {
                     33:        vrect_t vr;
                     34: 
                     35:        vr.x = vr.y = 0;
                     36:        vr.width = vid.width;
                     37:        vr.height = vid.height;
                     38:        vr.pnext = NULL;
                     39:        VID_Update (&vr);
                     40: }
                     41: 
                     42: 
                     43: /*
                     44: ====================
                     45: R_TimeRefresh_f
                     46: 
                     47: For program optimization
                     48: ====================
                     49: */
                     50: void R_TimeRefresh_f (void)
                     51: {
                     52:        int                     i;
                     53:        float           start, stop, time;
                     54:        int                     startangle;
                     55:        vrect_t         vr;
                     56: 
                     57:        startangle = r_refdef.viewangles[1];
                     58:        
                     59:        start = Sys_FloatTime ();
                     60:        for (i=0 ; i<128 ; i++)
                     61:        {
                     62:                r_refdef.viewangles[1] = i/128.0*360.0;
                     63:                R_RenderView ();
                     64:                vr.x = r_refdef.vrect.x;
                     65:                vr.y = r_refdef.vrect.y;
                     66:                vr.width = r_refdef.vrect.width;
                     67:                vr.height = r_refdef.vrect.height;
                     68:                vr.pnext = NULL;
                     69:                VID_Update (&vr);
                     70:        }
                     71:        stop = Sys_FloatTime ();
                     72:        time = stop-start;
                     73:        Con_Printf ("%f seconds (%f fps)\n", time, 128/time);
                     74:        
                     75:        r_refdef.viewangles[1] = startangle;
                     76: }
                     77: 
                     78: 
                     79: /*
                     80: ================
                     81: R_LineGraph
                     82: 
                     83: Only called by R_DisplayTime
                     84: ================
                     85: */
                     86: void R_LineGraph (int x, int y, int h)
                     87: {
                     88:        int             i;
                     89:        byte    *dest;
                     90:        int             s;
                     91: 
                     92: // FIXME: should be disabled on no-buffer adapters, or should be in the driver
                     93:        
                     94:        x += r_refdef.vrect.x;
                     95:        y += r_refdef.vrect.y;
                     96:        
                     97:        dest = vid.buffer + vid.rowbytes*y + x;
                     98:        
                     99:        s = r_graphheight.value;
                    100:        
                    101:        if (h>s)
                    102:                h = s;
                    103:                
                    104:        for (i=0 ; i<h ; i++, dest -= vid.rowbytes*2)
                    105:        {
                    106:                dest[0] = 0xff;
                    107:                *(dest-vid.rowbytes) = 0x30;
                    108:        }
                    109:        for ( ; i<s ; i++, dest -= vid.rowbytes*2)
                    110:        {
                    111:                dest[0] = 0x30;
                    112:                *(dest-vid.rowbytes) = 0x30;
                    113:        }
                    114: }
                    115: 
                    116: /*
                    117: ==============
                    118: R_TimeGraph
                    119: 
                    120: Performance monitoring tool
                    121: ==============
                    122: */
                    123: #define        MAX_TIMINGS             100
                    124: extern float mouse_x, mouse_y;
                    125: void R_TimeGraph (void)
                    126: {
                    127:        static  int             timex;
                    128:        int             a;
                    129:        float   r_time2;
                    130:        static byte     r_timings[MAX_TIMINGS];
                    131:        int             x;
                    132:        
                    133:        r_time2 = Sys_FloatTime ();
                    134: 
                    135:        a = (r_time2-r_time1)/0.01;
                    136: //a = fabs(mouse_y * 0.05);
                    137: //a = (int)((r_refdef.vieworg[2] + 1024)/1)%(int)r_graphheight.value;
                    138: //a = fabs(velocity[0])/20;
                    139: //a = ((int)fabs(origin[0])/8)%20;
                    140: //a = (cl.idealpitch + 30)/5;
                    141:        r_timings[timex] = a;
                    142:        a = timex;
                    143: 
                    144:        if (r_refdef.vrect.width <= MAX_TIMINGS)
                    145:                x = r_refdef.vrect.width-1;
                    146:        else
                    147:                x = r_refdef.vrect.width -
                    148:                                (r_refdef.vrect.width - MAX_TIMINGS)/2;
                    149:        do
                    150:        {
                    151:                R_LineGraph (x, r_refdef.vrect.height-2, r_timings[a]);
                    152:                if (x==0)
                    153:                        break;          // screen too small to hold entire thing
                    154:                x--;
                    155:                a--;
                    156:                if (a == -1)
                    157:                        a = MAX_TIMINGS-1;
                    158:        } while (a != timex);
                    159: 
                    160:        timex = (timex+1)%MAX_TIMINGS;
                    161: }
                    162: 
                    163: 
                    164: /*
                    165: =============
                    166: R_PrintTimes
                    167: =============
                    168: */
                    169: void R_PrintTimes (void)
                    170: {
                    171:        float   r_time2;
                    172:        float           ms;
                    173: 
                    174:        r_time2 = Sys_FloatTime ();
                    175: 
                    176:        ms = 1000* (r_time2 - r_time1);
                    177:        
                    178:        Con_Printf ("%5.1f ms %3i/%3i/%3i poly %3i surf\n",
                    179:                                ms, c_faceclip, r_polycount, r_drawnpolycount, c_surf);
                    180:        c_surf = 0;
                    181: }
                    182: 
                    183: 
                    184: /*
                    185: =============
                    186: R_PrintDSpeeds
                    187: =============
                    188: */
                    189: void R_PrintDSpeeds (void)
                    190: {
                    191:        float   ms, dp_time, r_time2, rw_time, db_time, se_time, de_time, dv_time;
                    192: 
                    193:        r_time2 = Sys_FloatTime ();
                    194: 
                    195:        dp_time = (dp_time2 - dp_time1) * 1000;
                    196:        rw_time = (rw_time2 - rw_time1) * 1000;
                    197:        db_time = (db_time2 - db_time1) * 1000;
                    198:        se_time = (se_time2 - se_time1) * 1000;
                    199:        de_time = (de_time2 - de_time1) * 1000;
                    200:        dv_time = (dv_time2 - dv_time1) * 1000;
                    201:        ms = (r_time2 - r_time1) * 1000;
                    202: 
                    203:        Con_Printf ("%3i %4.1fp %3iw %4.1fb %3is %4.1fe %4.1fv\n",
                    204:                                (int)ms, dp_time, (int)rw_time, db_time, (int)se_time, de_time,
                    205:                                dv_time);
                    206: }
                    207: 
                    208: 
                    209: /*
                    210: =============
                    211: R_PrintAliasStats
                    212: =============
                    213: */
                    214: void R_PrintAliasStats (void)
                    215: {
                    216:        Con_Printf ("%3i polygon model drawn\n", r_amodels_drawn);
                    217: }
                    218: 
                    219: 
                    220: void WarpPalette (void)
                    221: {
                    222:        int             i,j;
                    223:        byte    newpalette[768];
                    224:        int             basecolor[3];
                    225:        
                    226:        basecolor[0] = 130;
                    227:        basecolor[1] = 80;
                    228:        basecolor[2] = 50;
                    229: 
                    230: // pull the colors halfway to bright brown
                    231:        for (i=0 ; i<256 ; i++)
                    232:        {
                    233:                for (j=0 ; j<3 ; j++)
                    234:                {
                    235:                        newpalette[i*3+j] = (host_basepal[i*3+j] + basecolor[j])/2;
                    236:                }
                    237:        }
                    238:        
                    239:        VID_ShiftPalette (newpalette);
                    240: }
                    241: 
                    242: 
                    243: /*
                    244: ===================
                    245: R_TransformFrustum
                    246: ===================
                    247: */
                    248: void R_TransformFrustum (void)
                    249: {
                    250:        int             i;
                    251:        vec3_t  v, v2;
                    252:        
                    253:        for (i=0 ; i<4 ; i++)
                    254:        {
                    255:                v[0] = screenedge[i].normal[2];
                    256:                v[1] = -screenedge[i].normal[0];
                    257:                v[2] = screenedge[i].normal[1];
                    258: 
                    259:                v2[0] = v[1]*vright[0] + v[2]*vup[0] + v[0]*vpn[0];
                    260:                v2[1] = v[1]*vright[1] + v[2]*vup[1] + v[0]*vpn[1];
                    261:                v2[2] = v[1]*vright[2] + v[2]*vup[2] + v[0]*vpn[2];
                    262: 
                    263:                VectorCopy (v2, view_clipplanes[i].normal);
                    264: 
                    265:                view_clipplanes[i].dist = DotProduct (modelorg, v2);
                    266:        }
                    267: }
                    268: 
                    269: 
                    270: #if !id386
                    271: 
                    272: /*
                    273: ================
                    274: TransformVector
                    275: ================
                    276: */
                    277: void TransformVector (vec3_t in, vec3_t out)
                    278: {
                    279:        out[0] = DotProduct(in,vright);
                    280:        out[1] = DotProduct(in,vup);
                    281:        out[2] = DotProduct(in,vpn);            
                    282: }
                    283: 
                    284: #endif
                    285: 
                    286: 
                    287: /*
                    288: ================
                    289: R_TransformPlane
                    290: ================
                    291: */
                    292: void R_TransformPlane (mplane_t *p, float *normal, float *dist)
                    293: {
                    294:        float   d;
                    295:        
                    296:        d = DotProduct (r_origin, p->normal);
                    297:        *dist = p->dist - d;
                    298: // TODO: when we have rotating entities, this will need to use the view matrix
                    299:        TransformVector (p->normal, normal);
                    300: }
                    301: 
                    302: 
                    303: /*
                    304: ===============
                    305: R_SetUpFrustumIndexes
                    306: ===============
                    307: */
                    308: void R_SetUpFrustumIndexes (void)
                    309: {
                    310:        int             i, j, *pindex;
                    311: 
                    312:        pindex = r_frustum_indexes;
                    313: 
                    314:        for (i=0 ; i<4 ; i++)
                    315:        {
                    316:                for (j=0 ; j<3 ; j++)
                    317:                {
                    318:                        if (view_clipplanes[i].normal[j] < 0)
                    319:                        {
                    320:                                pindex[j] = j;
                    321:                                pindex[j+3] = j+3;
                    322:                        }
                    323:                        else
                    324:                        {
                    325:                                pindex[j] = j+3;
                    326:                                pindex[j+3] = j;
                    327:                        }
                    328:                }
                    329: 
                    330:        // FIXME: do just once at start
                    331:                pfrustum_indexes[i] = pindex;
                    332:                pindex += 6;
                    333:        }
                    334: }
                    335: 
                    336: 
                    337: /*
                    338: ===============
                    339: R_SetupFrame
                    340: ===============
                    341: */
                    342: void R_SetupFrame (void)
                    343: {
                    344:        int                             edgecount;
                    345:        vrect_t                 vrect;
                    346:        float                   w, h;
                    347: 
                    348: // don't allow cheats in multiplayer
                    349:        if (cl.maxclients > 1)
                    350:        {
                    351:                Cvar_Set ("r_draworder", "0");
                    352:                Cvar_Set ("r_fullbright", "0");
                    353:                Cvar_Set ("r_ambient", "0");
                    354:                Cvar_Set ("r_drawflat", "0");
                    355:        }
                    356: 
                    357:        if (r_numsurfs.value)
                    358:        {
                    359:                if ((surface_p - surfaces) > r_maxsurfsseen)
                    360:                        r_maxsurfsseen = surface_p - surfaces;
                    361: 
                    362:                Con_Printf ("Used %d of %d surfs; %d max\n", surface_p - surfaces,
                    363:                                surf_max - surfaces, r_maxsurfsseen);
                    364:        }
                    365: 
                    366:        if (r_numedges.value)
                    367:        {
                    368:                edgecount = edge_p - r_edges;
                    369: 
                    370:                if (edgecount > r_maxedgesseen)
                    371:                        r_maxedgesseen = edgecount;
                    372: 
                    373:                Con_Printf ("Used %d of %d edges; %d max\n", edgecount,
                    374:                                r_numallocatededges, r_maxedgesseen);
                    375:        }
                    376: 
                    377:        r_refdef.ambientlight = r_ambient.value;
                    378: 
                    379:        if (r_refdef.ambientlight < 0)
                    380:                r_refdef.ambientlight = 0;
                    381: 
                    382:        if (!sv.active)
                    383:                r_draworder.value = 0;  // don't let cheaters look behind walls
                    384:                
                    385:        R_CheckVariables ();
                    386:        
                    387:        R_AnimateLight ();
                    388: 
                    389:        r_framecount++;
                    390: 
                    391:        numbtofpolys = 0;
                    392: 
                    393: // debugging
                    394: #if 0
                    395: r_refdef.vieworg[0]=  80;
                    396: r_refdef.vieworg[1]=      64;
                    397: r_refdef.vieworg[2]=      40;
                    398: r_refdef.viewangles[0]=    0;
                    399: r_refdef.viewangles[1]=    46.763641357;
                    400: r_refdef.viewangles[2]=    0;
                    401: #endif
                    402: 
                    403: // build the transformation matrix for the given view angles
                    404:        VectorCopy (r_refdef.vieworg, modelorg);
                    405:        VectorCopy (r_refdef.vieworg, r_origin);
                    406: 
                    407:        AngleVectors (r_refdef.viewangles, vpn, vright, vup);
                    408: 
                    409: // current viewleaf
                    410:        r_oldviewleaf = r_viewleaf;
                    411:        r_viewleaf = Mod_PointInLeaf (r_origin, cl.worldmodel);
                    412: 
                    413:        r_dowarpold = r_dowarp;
                    414:        r_dowarp = r_waterwarp.value && (r_viewleaf->contents <= CONTENTS_WATER);
                    415: 
                    416:        if ((r_dowarp != r_dowarpold) || r_viewchanged)
                    417:        {
                    418:                if (r_dowarp)
                    419:                {
                    420:                        if ((vid.width <= vid.maxwarpwidth) &&
                    421:                                (vid.height <= vid.maxwarpheight))
                    422:                        {
                    423:                                vrect.x = 0;
                    424:                                vrect.y = 0;
                    425:                                vrect.width = vid.width;
                    426:                                vrect.height = vid.height;
                    427: 
                    428:                                R_ViewChanged (&vrect, sb_lines, vid.aspect);
                    429:                        }
                    430:                        else
                    431:                        {
                    432:                                w = vid.width;
                    433:                                h = vid.height;
                    434: 
                    435:                                if (w > vid.maxwarpwidth)
                    436:                                {
                    437:                                        h *= (float)vid.maxwarpwidth / w;
                    438:                                        w = vid.maxwarpwidth;
                    439:                                }
                    440: 
                    441:                                if (h > vid.maxwarpheight)
                    442:                                {
                    443:                                        h = vid.maxwarpheight;
                    444:                                        w *= (float)vid.maxwarpheight / h;
                    445:                                }
                    446: 
                    447:                                vrect.x = 0;
                    448:                                vrect.y = 0;
                    449:                                vrect.width = (int)w;
                    450:                                vrect.height = (int)h;
                    451: 
                    452:                                R_ViewChanged (&vrect,
                    453:                                                           (int)((float)sb_lines * (h/(float)vid.height)),
                    454:                                                           vid.aspect * (h / w) *
                    455:                                                                 ((float)vid.width / (float)vid.height));
                    456:                        }
                    457:                }
                    458:                else
                    459:                {
                    460:                        vrect.x = 0;
                    461:                        vrect.y = 0;
                    462:                        vrect.width = vid.width;
                    463:                        vrect.height = vid.height;
                    464: 
                    465:                        R_ViewChanged (&vrect, sb_lines, vid.aspect);
                    466:                }
                    467: 
                    468:                r_viewchanged = false;
                    469:        }
                    470: 
                    471: // start off with just the four screen edge clip planes
                    472:        R_TransformFrustum ();
                    473: 
                    474: // save base values
                    475:        VectorCopy (vpn, base_vpn);
                    476:        VectorCopy (vright, base_vright);
                    477:        VectorCopy (vup, base_vup);
                    478: 
                    479:        R_SetSkyFrame ();
                    480: 
                    481:        R_SetUpFrustumIndexes ();
                    482: 
                    483:        r_cache_thrash = false;
                    484: 
                    485: // clear frame counts
                    486:        c_faceclip = 0;
                    487:        d_spanpixcount = 0;
                    488:        r_polycount = 0;
                    489:        r_drawnpolycount = 0;
                    490:        r_wholepolycount = 0;
                    491:        r_amodels_drawn = 0;
                    492:        r_outofsurfaces = 0;
                    493:        r_outofedges = 0;
                    494: 
                    495:        D_SetupFrame ();
                    496: }
                    497: 

unix.superglobalmegacorp.com

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