MCPcopy Create free account
hub / github.com/dhewm/dhewm3 / SCR_DrawFPS

Function SCR_DrawFPS

neo/framework/Console.cpp:197–242  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

195*/
196#define FPS_FRAMES 64
197float SCR_DrawFPS( float y ) {
198 static float previousTimes[FPS_FRAMES];
199 static int index;
200 static double previous;
201
202 // don't use serverTime, because that will be drifting to
203 // correct for internet lag changes, timescales, timedemos, etc
204 double t = Sys_MillisecondsPrecise();
205 float frameTime = t - previous;
206 previous = t;
207
208 previousTimes[index % FPS_FRAMES] = frameTime;
209 index++;
210 if ( index > FPS_FRAMES ) {
211 // average multiple frames together to smooth changes out a bit
212 float total = 0.0f;
213 float minTime = 10000;
214 float maxTime = 0;
215 for ( int i = 0 ; i < FPS_FRAMES ; i++ ) {
216 float pt = previousTimes[i];
217 total += pt;
218 minTime = Min( minTime, pt );
219 maxTime = Max( maxTime, pt );
220 }
221 if ( total == 0.0f ) {
222 total = 0.1f;
223 }
224 float fps = (1000.0f * FPS_FRAMES) / total;
225
226 char* s = va( "%.2ffps", fps );
227 int w = strlen( s ) * BIGCHAR_WIDTH;
228
229 renderSystem->DrawBigStringExt( 635 - w, idMath::FtoiFast( y ) + 2, s, colorWhite, true, localConsole.charSetShader);
230
231 if ( com_showFPS.GetInteger() > 1 ) {
232 y += BIGCHAR_HEIGHT + 4;
233
234 s = va( "avg %.2fms min %.2f max %.2f", total * (1.0f / FPS_FRAMES), minTime, maxTime );
235 w = strlen ( s ) * SMALLCHAR_WIDTH;
236 renderSystem->DrawSmallStringExt( 635 - w, idMath::FtoiFast( y ) + 2, s, colorWhite, true, localConsole.charSetShader );
237 }
238
239 }
240
241 return y + BIGCHAR_HEIGHT + 4;
242}
243
244/*
245==================

Callers 1

DrawMethod · 0.85

Calls 7

MinFunction · 0.85
MaxFunction · 0.85
vaFunction · 0.85
DrawBigStringExtMethod · 0.80
GetIntegerMethod · 0.80
DrawSmallStringExtMethod · 0.80
Sys_MillisecondsPreciseFunction · 0.50

Tested by

no test coverage detected