cpp_photon/test/FPSDisplayTask.hpp

36 lines
908 B
C++
Raw Normal View History

#ifndef FPSDISPLAYTASK_HPP
#define FPSDISPLAYTASK_HPP
#include "photon.hpp"
#include <boost/lexical_cast.hpp>
2005-07-20 07:30:13 +00:00
// Used to measure FPS and display it in the title bar. Pretty good example
// of when to use a Task, logic is entirely separate from rest of application
// and should be executed regularly.
class FPSDisplayTask : public photon::Task
{
public:
FPSDisplayTask() :
Task("FPSDisplayTask", 1000000), // extremely low priority
app(photon::AppCore::getInstance()),
lastUpdate(0)
{ }
void update()
{
// update (at most) once a second
if(app.getTime() - lastUpdate > 1.0)
{
app.setTitle("FPS: " +
boost::lexical_cast<std::string>(app.getFramerate()) );
lastUpdate = app.getTime();
}
}
private:
photon::AppCore& app;
double lastUpdate;
};
#endif //FPSDISPLAYTASK_HPP