// r_misc.c #include "quakedef.h" #include "r_local.h" /* =============== R_CheckVariables =============== */ void R_CheckVariables (void) { static float oldbright; if (r_fullbright.value != oldbright) { oldbright = r_fullbright.value; D_FlushCaches (); // so all lighting changes } } /* ============ Show Debugging use ============ */ void Show (void) { vrect_t vr; vr.x = vr.y = 0; vr.width = vid.width; vr.height = vid.height; vr.pnext = NULL; VID_Update (&vr); } /* ==================== R_TimeRefresh_f For program optimization ==================== */ void R_TimeRefresh_f (void) { int i; float start, stop, time; int startangle; vrect_t vr; if (cls.state != ca_active) { Con_Printf("Not connected to a server\n"); return; } startangle = r_refdef.viewangles[1]; start = Sys_DoubleTime (); for (i=0 ; i<128 ; i++) { r_refdef.viewangles[1] = i/128.0*360.0; VID_LockBuffer (); R_RenderView (); VID_UnlockBuffer (); vr.x = r_refdef.vrect.x; vr.y = r_refdef.vrect.y; vr.width = r_refdef.vrect.width; vr.height = r_refdef.vrect.height; vr.pnext = NULL; VID_Update (&vr); } stop = Sys_DoubleTime (); time = stop-start; Con_Printf ("%f seconds (%f fps)\n", time, 128/time); r_refdef.viewangles[1] = startangle; } /* ================ R_LineGraph Only called by R_DisplayTime ================ */ void R_LineGraph (int x, int y, int h) { int i; byte *dest; int s; int color; // FIXME: should be disabled on no-buffer adapters, or should be in the driver // x += r_refdef.vrect.x; // y += r_refdef.vrect.y; dest = vid.buffer + vid.rowbytes*y + x; s = r_graphheight.value; if (h == 10000) color = 175; // yellow else if (h == 9999) color = 143; // red else if (h == 9998) color = 249; // blue else color = 242; // pink if (h>s) h = s; for (i=0 ; i r_refdef.vrect.height) { s = r_refdef.vrect.height; } //show actual received bytes here (h) if(h > s) { h = s; } for(i = 0; i < h; i++, dest -= vid.rowbytes) { dest[0] = ((i+1)%marker == 0) ? 143 : 255; if(!(drawType&1)) { // Expanded if(!(drawType&2)) { // Solid *(dest-vid.rowbytes) = 53; } dest -= vid.rowbytes; } } //show uncompressed bytes here (h2) if(h2 > s) { h2 = s; } for(i = h; i < h2; i++, dest -= vid.rowbytes) { dest[0] = ((i+1)%marker == 0) ? 130 : 244; if(!(drawType&1)) { // Expanded if(!(drawType&2)) { // Solid *(dest-vid.rowbytes) = 53; } dest -= vid.rowbytes; } } if(drawType&4) { // No background return; } for(; i < s; i++, dest -= vid.rowbytes) { dest[0] = 53; if(!(drawType&1)) { // Expanded if(!(drawType&2)) { // Solid *(dest-vid.rowbytes) = 53; } dest -= vid.rowbytes; } } } /* ============== R_TimeGraph Performance monitoring tool ============== */ #define MAX_TIMINGS 100 #define GRAPH_TYPE_COUNT 2 extern float mouse_x, mouse_y; extern int LastServerMessageSize;//uncompressed extern int LastCompMessageSize;//compressed void R_TimeGraph(void) { int a; int x; int drawType; int graphType; static int timex; static byte r_timings[MAX_TIMINGS];//compressed static byte r_timings2[MAX_TIMINGS];//uncompressed static int graphMarkers[GRAPH_TYPE_COUNT] = { 10000, 10 }; graphType = (int)r_timegraph.value; if(graphType < 1 || graphType > GRAPH_TYPE_COUNT) { return; } drawType = (int)((r_timegraph.value-floor(r_timegraph.value)+1E-3)*10); if(graphType == 1) { // Frame times a = (Sys_DoubleTime () - r_time1) / 0.01; r_timings[timex] = a; r_timings2[timex] = a; } else { // Packet sizes a = LastCompMessageSize/10; LastCompMessageSize = 0; r_timings[timex] = a; a = LastServerMessageSize/10; LastServerMessageSize = 0; r_timings2[timex] = a; } //a = fabs(mouse_y * 0.05); //a = (int)((r_refdef.vieworg[2] + 1024)/1)%(int)r_graphheight.value; //a = fabs(velocity[0])/20; //a = ((int)fabs(origin[0])/8)%20; //a = (cl.idealpitch + 30)/5; a = timex; if(r_refdef.vrect.width <= MAX_TIMINGS) { x = r_refdef.vrect.width-1; } else { x = r_refdef.vrect.width -(r_refdef.vrect.width-MAX_TIMINGS)/2; } do { R_LineGraph2(x, r_refdef.vrect.height-2, r_timings[a], r_timings2[a], drawType, graphMarkers[graphType-1]); if(x == 0) { break; // screen too small to hold entire thing } x--; a--; if(a == -1) { a = MAX_TIMINGS-1; } } while(a != timex); timex = (timex+1)%MAX_TIMINGS; } /* ============== R_NetGraph ============== */ #define NET_TIMINGS 256 void R_NetGraph (void) { int a, x, y, y2, w, i; static int packet_latency[256]; frame_t *frame; int lost; char st[80]; if (vid.width - 16 <= NET_TIMINGS) w = vid.width - 16; else w = NET_TIMINGS; for (i=cls.netchan.outgoing_sequence-UPDATE_BACKUP+1 ; i <= cls.netchan.outgoing_sequence ; i++) { frame = &cl.frames[i&UPDATE_MASK]; if (frame->receivedtime == -1) packet_latency[i&255] = 9999; // dropped else if (frame->receivedtime == -2) packet_latency[i&255] = 10000; // choked else if (frame->invalid) packet_latency[i&255] = 9998; // invalid delta else packet_latency[i&255] = (frame->receivedtime - frame->senttime)*20; } x = -((vid.width - 320)>>1); y = vid.height - sb_lines - 24 - (int)r_graphheight.value*2 - 2; M_DrawTextBox (x, y, (w+7)/8, ((int)r_graphheight.value*2+7)/8 + 1); y2 = y + 8; y = vid.height - sb_lines - 8 - 2; x = 8; lost = 0; for (a=0 ; anormal); *dist = p->dist - d; // TODO: when we have rotating entities, this will need to use the view matrix TransformVector (p->normal, normal); } /* =============== R_SetUpFrustumIndexes =============== */ void R_SetUpFrustumIndexes (void) { int i, j, *pindex; pindex = r_frustum_indexes; for (i=0 ; i<4 ; i++) { for (j=0 ; j<3 ; j++) { if (view_clipplanes[i].normal[j] < 0) { pindex[j] = j; pindex[j+3] = j+3; } else { pindex[j] = j+3; pindex[j+3] = j; } } // FIXME: do just once at start pfrustum_indexes[i] = pindex; pindex += 6; } } /* =============== R_SetupFrame =============== */ void R_SetupFrame (void) { int edgecount; vrect_t vrect; float w, h; // don't allow cheats in multiplayer r_draworder.value = 0; r_fullbright.value = 0; r_ambient.value = 0; r_drawflat.value = 0; if (r_numsurfs.value) { if ((surface_p - surfaces) > r_maxsurfsseen) r_maxsurfsseen = surface_p - surfaces; Con_Printf ("Used %d of %d surfs; %d max\n", surface_p - surfaces, surf_max - surfaces, r_maxsurfsseen); } if (r_numedges.value) { edgecount = edge_p - r_edges; if (edgecount > r_maxedgesseen) r_maxedgesseen = edgecount; Con_Printf ("Used %d of %d edges; %d max\n", edgecount, r_numallocatededges, r_maxedgesseen); } r_refdef.ambientlight = r_ambient.value; if (r_refdef.ambientlight < 0) r_refdef.ambientlight = 0; // if (!sv.active) r_draworder.value = 0; // don't let cheaters look behind walls R_CheckVariables (); R_AnimateLight (); r_framecount++; numbtofpolys = 0; // debugging #if 0 r_refdef.vieworg[0]= 80; r_refdef.vieworg[1]= 64; r_refdef.vieworg[2]= 40; r_refdef.viewangles[0]= 0; r_refdef.viewangles[1]= 46.763641357; r_refdef.viewangles[2]= 0; #endif // build the transformation matrix for the given view angles VectorCopy (r_refdef.vieworg, modelorg); VectorCopy (r_refdef.vieworg, r_origin); AngleVectors (r_refdef.viewangles, vpn, vright, vup); // current viewleaf r_oldviewleaf = r_viewleaf; r_viewleaf = Mod_PointInLeaf (r_origin, cl.worldmodel); r_dowarpold = r_dowarp; r_dowarp = r_waterwarp.value && (r_viewleaf->contents <= CONTENTS_WATER); if ((r_dowarp != r_dowarpold) || r_viewchanged) { if (r_dowarp) { if ((vid.width <= vid.maxwarpwidth) && (vid.height <= vid.maxwarpheight)) { vrect.x = 0; vrect.y = 0; vrect.width = vid.width; vrect.height = vid.height; R_ViewChanged (&vrect, sb_lines, vid.aspect); } else { w = vid.width; h = vid.height; if (w > vid.maxwarpwidth) { h *= (float)vid.maxwarpwidth / w; w = vid.maxwarpwidth; } if (h > vid.maxwarpheight) { h = vid.maxwarpheight; w *= (float)vid.maxwarpheight / h; } vrect.x = 0; vrect.y = 0; vrect.width = (int)w; vrect.height = (int)h; R_ViewChanged (&vrect, (int)((float)sb_lines * (h/(float)vid.height)), vid.aspect * (h / w) * ((float)vid.width / (float)vid.height)); } } else { vrect.x = 0; vrect.y = 0; vrect.width = vid.width; vrect.height = vid.height; R_ViewChanged (&vrect, sb_lines, vid.aspect); } r_viewchanged = false; } // start off with just the four screen edge clip planes R_TransformFrustum (); // save base values VectorCopy (vpn, base_vpn); VectorCopy (vright, base_vright); VectorCopy (vup, base_vup); VectorCopy (modelorg, base_modelorg); R_SetSkyFrame (); R_SetUpFrustumIndexes (); r_cache_thrash = false; // clear frame counts c_faceclip = 0; d_spanpixcount = 0; r_polycount = 0; r_drawnpolycount = 0; r_wholepolycount = 0; r_amodels_drawn = 0; r_outofsurfaces = 0; r_outofedges = 0; D_SetupFrame (); }