+ int calc;
+ if (showfps.integer > 1)
+ {
+ static double currtime, frametimes[32];
+ double newtime, total;
+ int count, i;
+ static int framecycle = 0;
+
+ newtime = Sys_DoubleTime();
+ frametimes[framecycle] = newtime - currtime;
+ total = 0;
+ count = 0;
+ while(total < 0.2 && count < 32 && frametimes[i = (framecycle - count) & 31])
+ {
+ total += frametimes[i];
+ count++;
+ }
+ framecycle++;
+ framecycle &= 31;
+ if (showfps.integer == 2)
+ calc = (int) (((double) count / total) + 0.5);
+ else // showfps 3, rapid update
+ calc = (int) ((1.0 / (newtime - currtime)) + 0.5);
+ currtime = newtime;
+ }
+ else
+ {
+ static double nexttime = 0, lasttime = 0;
+ static int framerate = 0, framecount = 0;
+ double newtime;
+ newtime = Sys_DoubleTime();
+ if (newtime >= nexttime)
+ {
+ framerate = (int) (framecount / (newtime - lasttime) + 0.5);
+ lasttime = newtime;
+ nexttime = max(nexttime + 1, lasttime - 1);
+ framecount = 0;
+ }
+ framecount++;
+ calc = framerate;
+ }
+ dpsnprintf(fpsstring, sizeof(fpsstring), "%4i fps", calc);
+ }
+ if (showtime.integer)
+ strlcpy(timestring, Sys_TimeString(showtime_format.string), sizeof(timestring));
+ if (showdate.integer)
+ strlcpy(datestring, Sys_TimeString(showdate_format.string), sizeof(datestring));
+ if (fpsstring[0] || timestring[0])
+ {
+ fps_scalex = 12;
+ fps_scaley = 12;
+ fps_height = fps_scaley * ((fpsstring[0] != 0) + (timestring[0] != 0) + (datestring[0] != 0));
+ //fps_y = vid_conheight.integer - sb_lines; // yes this may draw over the sbar
+ //fps_y = bound(0, fps_y, vid_conheight.integer - fps_height);
+ fps_y = vid_conheight.integer - fps_height;
+ if (fpsstring[0])
+ {
+ fps_x = vid_conwidth.integer - fps_scalex * strlen(fpsstring);
+ DrawQ_Fill(fps_x, fps_y, fps_scalex * strlen(fpsstring), fps_scaley, 0, 0, 0, 0.5, 0);
+ DrawQ_String(fps_x, fps_y, fpsstring, 0, fps_scalex, fps_scaley, 1, 1, 1, 1, 0);
+ fps_y += fps_scaley;
+ }
+ if (timestring[0])
+ {
+ fps_x = vid_conwidth.integer - fps_scalex * strlen(timestring);
+ DrawQ_Fill(fps_x, fps_y, fps_scalex * strlen(timestring), fps_scaley, 0, 0, 0, 0.5, 0);
+ DrawQ_String(fps_x, fps_y, timestring, 0, fps_scalex, fps_scaley, 1, 1, 1, 1, 0);
+ fps_y += fps_scaley;
+ }
+ if (datestring[0])
+ {
+ fps_x = vid_conwidth.integer - fps_scalex * strlen(datestring);
+ DrawQ_Fill(fps_x, fps_y, fps_scalex * strlen(datestring), fps_scaley, 0, 0, 0, 0.5, 0);
+ DrawQ_String(fps_x, fps_y, datestring, 0, fps_scalex, fps_scaley, 1, 1, 1, 1, 0);
+ fps_y += fps_scaley;
+ }