2005-07-20 06:12:13 +00:00
|
|
|
#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.
|
2005-07-20 06:12:13 +00:00
|
|
|
class FPSDisplayTask : public photon::Task
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FPSDisplayTask() :
|
2005-08-07 07:12:46 +00:00
|
|
|
Task("FPSDisplayTask"),
|
|
|
|
app(Application::getInstance()),
|
2005-07-20 06:12:13 +00:00
|
|
|
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:
|
2005-08-07 07:12:46 +00:00
|
|
|
Application& app;
|
2005-07-20 06:12:13 +00:00
|
|
|
double lastUpdate;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif //FPSDISPLAYTASK_HPP
|