40 m_nDelayFrames = nDelayFrames;
56 m_fMinCycleTimeMS = FLT_MAX;
57 m_fMaxCycleTimeMS = -FLT_MAX;
63 int nCycleTime = calculateTimeDiff(m_nCycleSec, m_nCycleUSec,
true);
66 updateMembers(nCycleTime);
85 bool bValidTime = (m_nUpdates != 0);
86 int nOverallCycleTime = (1.0f / fFrameRate) * 1000000;
91 int nWantedUSec = (1.0f / fFrameRate) * 1000000;
98 nTimeDiff = calculateTimeDiff(m_nCycleSec, m_nCycleUSec);
101 while (nTimeDiff < nWantedUSec);
104 nOverallCycleTime = calculateTimeDiff(m_nCycleSec, m_nCycleUSec,
true);
107 calculateTimeDiff(m_nCycleSec, m_nCycleUSec,
true);
108 updateMembers(nOverallCycleTime);
119 return m_nUpdates > m_nDelayFrames;
129 if (m_nUpdates <= m_nDelayFrames)
139 if (m_nUpdates <= 10)
144 float fMeanTimeMS = 0.0f;
146 for (
int i = 0 ; i < 10 ; i++)
148 fMeanTimeMS += m_fLastCycleTimesMS[i];
151 return fMeanTimeMS / 10;
161 return m_fMinCycleTimeMS;
171 return m_fMaxCycleTimeMS;
177 void FPSCounter::updateMembers(
int nCycleTime)
180 bool bValidTime = (m_nUpdates != 0);
183 recalculateFPS(nCycleTime);
187 recalculateStats(nCycleTime);
191 void FPSCounter::recalculateFPS(
int nCycleUSec)
193 m_nIntervalTime += nCycleUSec;
196 if ((m_nUpdates % m_nDelayFrames == 0) && (m_nUpdates != 0))
199 float fTimeDiff = m_nIntervalTime / 1000000.0f;
200 m_fFPS = (1.0f / fTimeDiff) * m_nDelayFrames;
205 void FPSCounter::recalculateStats(
int nCycleUSec)
207 float fTimeMS =
float(nCycleUSec) / 1000.0f;
209 if (fTimeMS < m_fMinCycleTimeMS)
211 m_fMinCycleTimeMS = fTimeMS;
214 if (fTimeMS > m_fMaxCycleTimeMS)
216 m_fMaxCycleTimeMS = fTimeMS;
219 m_fLastCycleTimesMS[(m_nUpdates - 1) % 10] = fTimeMS;
223 int FPSCounter::calculateTimeDiff(
long& nSec,
long& nUSec,
bool bSetTime)
226 gettimeofday(&t,
nullptr);
227 int nTimeDiff = (t.tv_sec - nSec) * 1000000 + ((
int) t.tv_usec - nUSec);