Annotation of quake1/r_misc.c, revision 1.1.1.2

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

unix.superglobalmegacorp.com

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