Game/FPSCounter: Use sp::Stopwatch
This commit is contained in:
parent
f62373dcbc
commit
3855cdd541
2 changed files with 6 additions and 7 deletions
|
|
@ -2,7 +2,7 @@
|
||||||
#ifndef SPECTRE_FPS_COUNTER_H
|
#ifndef SPECTRE_FPS_COUNTER_H
|
||||||
#define SPECTRE_FPS_COUNTER_H
|
#define SPECTRE_FPS_COUNTER_H
|
||||||
|
|
||||||
#include <Spectre/Math/Time.h>
|
#include <Spectre/System/Stopwatch.h>
|
||||||
|
|
||||||
// Simple FPS counter.
|
// Simple FPS counter.
|
||||||
|
|
||||||
|
|
@ -35,7 +35,8 @@ private :
|
||||||
unsigned int m_count;
|
unsigned int m_count;
|
||||||
|
|
||||||
// Last time we updated the counter.
|
// Last time we updated the counter.
|
||||||
Time m_time;
|
//Time m_time;
|
||||||
|
Stopwatch m_watch;
|
||||||
|
|
||||||
// Update rate (at what interval should we update)
|
// Update rate (at what interval should we update)
|
||||||
Time m_updateRate;
|
Time m_updateRate;
|
||||||
|
|
|
||||||
|
|
@ -36,14 +36,12 @@ void FPSCounter::setUpdateRate(unsigned int rate)
|
||||||
|
|
||||||
bool FPSCounter::update()
|
bool FPSCounter::update()
|
||||||
{
|
{
|
||||||
Time current = Time::milliseconds(system::getMilliseconds());
|
Time elapsed = m_watch.elapsed();
|
||||||
Time elapsed = current - m_time;
|
|
||||||
|
|
||||||
if (elapsed >= m_updateRate) {
|
if (elapsed >= m_updateRate) {
|
||||||
m_fps = m_count / elapsed.seconds();
|
m_fps = m_count / elapsed.seconds();
|
||||||
|
|
||||||
m_time = current;
|
reset();
|
||||||
m_count = 0;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -51,7 +49,7 @@ bool FPSCounter::update()
|
||||||
|
|
||||||
void FPSCounter::reset()
|
void FPSCounter::reset()
|
||||||
{
|
{
|
||||||
m_time = Time::milliseconds(system::getMilliseconds());
|
m_watch.restart();
|
||||||
m_count = 0;
|
m_count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue