X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=sbar.c;h=18f3b7ee891682f17daed95bb01e0136daf00f8f;hb=d719609802e7fba8f1685d8fbce9d4f581fb32a9;hp=c6fcbf648fc57eb4c0950bb10f2c498a8dde31d9;hpb=34043d3ceaa5a64215903acac3038b35048b7505;p=xonotic%2Fdarkplaces.git diff --git a/sbar.c b/sbar.c index c6fcbf64..18f3b7ee 100644 --- a/sbar.c +++ b/sbar.c @@ -1090,6 +1090,27 @@ static void get_showspeed_unit(int unitnumber, double *conversion_factor, const } } +static double showfps_nexttime = 0, showfps_lasttime = -1; +static double showfps_framerate = 0; +static int showfps_framecount = 0; + +void Sbar_ShowFPS_Update(void) +{ + double interval = 1; + double newtime; + newtime = realtime; + if (newtime >= showfps_nexttime) + { + showfps_framerate = showfps_framecount / (newtime - showfps_lasttime); + if (showfps_nexttime < newtime - interval * 1.5) + showfps_nexttime = newtime; + showfps_lasttime = newtime; + showfps_nexttime += interval; + showfps_framecount = 0; + } + showfps_framecount++; +} + void Sbar_ShowFPS(void) { float fps_x, fps_y, fps_scalex, fps_scaley, fps_height; @@ -1110,32 +1131,13 @@ void Sbar_ShowFPS(void) topspeedstring[0] = 0; if (showfps.integer) { - float calc; - static double nexttime = 0, lasttime = 0; - static double framerate = 0; - static int framecount = 0; - double interval = 1; - double newtime; - newtime = Sys_DoubleTime(); - if (newtime >= nexttime) - { - framerate = framecount / (newtime - lasttime); - if (nexttime < newtime - interval * 1.5) - nexttime = newtime; - lasttime = newtime; - nexttime += interval; - framecount = 0; - } - framecount++; - calc = framerate; - red = (calc < 1.0f); - + red = (showfps_framerate < 1.0f); if(showfps.integer == 2) - dpsnprintf(fpsstring, sizeof(fpsstring), "%7.3f mspf", (1000.0 / calc)); + dpsnprintf(fpsstring, sizeof(fpsstring), "%7.3f mspf", (1000.0 / showfps_framerate)); else if (red) - dpsnprintf(fpsstring, sizeof(fpsstring), "%4i spf", (int)(1.0 / calc + 0.5)); + dpsnprintf(fpsstring, sizeof(fpsstring), "%4i spf", (int)(1.0 / showfps_framerate + 0.5)); else - dpsnprintf(fpsstring, sizeof(fpsstring), "%4i fps", (int)(calc + 0.5)); + dpsnprintf(fpsstring, sizeof(fpsstring), "%4i fps", (int)(showfps_framerate + 0.5)); } if (showtime.integer) strlcpy(timestring, Sys_TimeString(showtime_format.string), sizeof(timestring)); @@ -1717,8 +1719,6 @@ void Sbar_Draw (void) } } - Sbar_ShowFPS(); - if (cl.csqc_vidvars.drawcrosshair && crosshair.integer >= 1 && !cl.intermission && !r_letterbox.value) { pic = Draw_CachePic (va("gfx/crosshair%i", crosshair.integer));