Best way to calculate frames per second, and how to do it?

Started by
2 comments, last by johnnyBravo 20 years, 8 months ago
Hey, I want to put up a frames counter per second for my program. My attempt at it failed, even though i don''t see why. But anyway I''m wondering what the best timer function would be and how to use it with a frames counter per second? Thanks
Advertisement
"But anyway I'm wondering what the best timer function would be and how to use it with a frames counter per second?"

on windows? unix?

I don't know if that's "the best", but...

if it's on windows, I'd use QueryPerformanceCounter() and QueryPerformanceFrequency()...
if it's on unix, have a look at gettimeofday() manual pages...


[edited by - sBibi on July 26, 2003 9:44:44 PM]
mytime = GetSystemTime() ''Milliseconds framecounter = 0lastFps = 0do     DoFrame()     print lastFps     framecounter+1          if (GetSystemTime() - mytime >= 1000) '' one second         mytime = GetSystemTime()         lastFps = framecounter         framecounter = 0     end ifloop 


This may pseudo work...
[size="2"]I like the Walrus best.
My FPS update code (C#), part of class FrameCounter:

public void Update(){// number of frames since game start++m_totalFrameCount;// number of frames since last fps update++m_framesSinceUpdate;// m_method is a certain timing method (exchangable)// Time returns the current time in millisecondsfloat now   = m_method.Time;float delta = now - m_lastUpdate;// m_frameDuration is the length of last framem_frameDuration	= now - m_lastFrameTime;m_lastFrameTime = now;// m_updateInterval is the number of // milliseconds between two updatesif(delta > m_updateInterval){	// m_currentFps should explain itself 	m_currentFps = 1000.0f * ((float)m_framesSinceUpdate) / delta;        // m_samplesForAvgFps: number of samples used         // to calculate an average frame rate	++m_samplesForAvgFps;        // calculate average FPS	m_avgFps += (m_currentFps - m_avgFps) / (float)m_samplesForAvgFps;        // reset some vars	m_framesSinceUpdate = 0;	m_lastUpdate = now;        // fire .NET event 	OnUpdated();}}  


Hope you understand it

Regards, VizOne

-----------------------------
Andre Loker
GentleStorm Studios - Germany
http://www.gentlestorm.de

[edited by - VizOne on July 27, 2003 11:02:32 AM]
Andre Loker | Personal blog on .NET

This topic is closed to new replies.

Advertisement