diff --git a/test/Audio_test.cpp b/test/Audio_test.cpp index 8a1ac93..c10fbdd 100644 --- a/test/Audio_test.cpp +++ b/test/Audio_test.cpp @@ -5,11 +5,11 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: Audio_test.cpp,v 1.5 2005/07/19 18:35:20 cozman Exp $ +// $Id: Audio_test.cpp,v 1.6 2005/07/20 06:12:13 cozman Exp $ #include "photon.hpp" using namespace photon; -#include +#include "FPSDisplayTask.hpp" // used to display FPS in title bar // actual test is only compiled if OpenAL is in use #ifdef PHOTON_USE_OPENAL @@ -23,7 +23,6 @@ class MainTask : public Task , public InputListener public: MainTask() : Task("MainTask"), - app(AppCore::getInstance()), video(video::VideoCore::getInstance()) { video.setOrthoView(800,600); // setup view @@ -160,20 +159,9 @@ public: // called once per frame void update() { - // used to measure FPS and display it in the title bar - static double t=0; - if(app.getTime() - t > 1.0) - { - app.setTitle("FPS: " + - boost::lexical_cast(app.getFramerate()) ); - t = app.getTime(); - } - // used for calculating draw position static const photon::uint fontHeight(font.getHeight()); - video.clear(); // clear display before drawing - // draw the status of all 6 sounds font.beginDraw(0, 0*fontHeight) << "(C)himes is " << status[0] << "playing" << font.endDraw(); @@ -195,8 +183,6 @@ private: audio::Sample chimes, ocean, rain, stream, thunder, waterdrop; std::string status[6]; - // references to singleton cores - AppCore& app; video::VideoCore& video; }; @@ -209,9 +195,11 @@ public: // create window AppCore::getInstance().createDisplay(800,600,32,0,0,false); // create sound device - AudioCore::initAudioDevice("OSS"); + AudioCore::initAudioDevice("OSS"); - // add the task to the Kernel + // be sure to add FPSDisplayTask + Kernel::getInstance().addTask(TaskPtr(new FPSDisplayTask())); + // add the main task to the Kernel Kernel::getInstance().addTask(TaskPtr(new MainTask())); // run Kernel until task finishes Kernel::getInstance().run(); diff --git a/test/FPSDisplayTask.hpp b/test/FPSDisplayTask.hpp new file mode 100644 index 0000000..e1eb04e --- /dev/null +++ b/test/FPSDisplayTask.hpp @@ -0,0 +1,33 @@ +#ifndef FPSDISPLAYTASK_HPP +#define FPSDISPLAYTASK_HPP + +#include "photon.hpp" +#include + +// used to measure FPS and display it in the title bar +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(app.getFramerate()) ); + lastUpdate = app.getTime(); + } + } + +private: + photon::AppCore& app; + double lastUpdate; +}; + +#endif //FPSDISPLAYTASK_HPP diff --git a/test/Font_test.cpp b/test/Font_test.cpp index 7cdcec1..9db55ac 100644 --- a/test/Font_test.cpp +++ b/test/Font_test.cpp @@ -5,12 +5,11 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: Font_test.cpp,v 1.6 2005/07/19 18:47:28 cozman Exp $ +// $Id: Font_test.cpp,v 1.7 2005/07/20 06:12:13 cozman Exp $ #include "photon.hpp" using namespace photon; -#include - +#include "FPSDisplayTask.hpp" // used to display FPS in title bar class MainTask : public Task { @@ -33,18 +32,6 @@ public: void update() { - // used to measure FPS and display it in the title bar - static double t=0; - if(app.getTime() - t > 1.0) - { - app.setTitle("FPS: " + - boost::lexical_cast(app.getFramerate()) ); - t = app.getTime(); - } - - // clear screen - video.clear(); - // draw the three strings to the screen font.setColor(video::Color(0,128,128)); font.drawText(0, 0, "Photon"); @@ -71,6 +58,8 @@ public: { AppCore::getInstance().createDisplay(800,600,32,0,0,false); + // be sure to add FPSDisplayTask + Kernel::getInstance().addTask(TaskPtr(new FPSDisplayTask())); Kernel::getInstance().addTask(TaskPtr(new MainTask())); Kernel::getInstance().run(); diff --git a/test/Image_test.cpp b/test/Image_test.cpp index 8343820..ee35704 100644 --- a/test/Image_test.cpp +++ b/test/Image_test.cpp @@ -5,11 +5,11 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: Image_test.cpp,v 1.6 2005/07/20 01:35:11 cozman Exp $ +// $Id: Image_test.cpp,v 1.7 2005/07/20 06:12:13 cozman Exp $ #include "photon.hpp" using namespace photon; -#include +#include "FPSDisplayTask.hpp" // used to display FPS in title bar class MainTask : public Task { @@ -41,18 +41,6 @@ public: void update() { - // used to measure FPS and display it in the title bar - static double t=0; - if(app.getTime() - t > 1.0) - { - app.setTitle("FPS: " + - boost::lexical_cast(app.getFramerate()) ); - t = app.getTime(); - } - - // clear screen - video.clear(); - // draw in top left corner img[0].draw(0,0); @@ -82,6 +70,8 @@ public: { AppCore::getInstance().createDisplay(800,600,32,0,0,false); + // be sure to add FPSDisplayTask + Kernel::getInstance().addTask(TaskPtr(new FPSDisplayTask())); Kernel::getInstance().addTask(TaskPtr(new MainTask())); Kernel::getInstance().run(); diff --git a/test/Input_test.cpp b/test/Input_test.cpp index 088c534..6b4194c 100644 --- a/test/Input_test.cpp +++ b/test/Input_test.cpp @@ -5,11 +5,11 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: Input_test.cpp,v 1.3 2005/07/19 20:32:00 cozman Exp $ +// $Id: Input_test.cpp,v 1.4 2005/07/20 06:12:13 cozman Exp $ #include "photon.hpp" using namespace photon; -#include +#include "FPSDisplayTask.hpp" // used to display FPS in title bar class MainTask : public Task, public InputListener { @@ -58,21 +58,10 @@ public: void update() { - // used to measure FPS and display it in the title bar - static double t=0; - if(app.getTime() - t > 1.0) - { - app.setTitle("FPS: " + - boost::lexical_cast(app.getFramerate()) ); - t = app.getTime(); - } - // used for spacing text vertically static const photon::uint fontHeight(font.getHeight()); photon::uint curHeight(0); - video.clear(); // clear display - // draw input event/status notifications, increment curHeight on each // draw so that text is properly spaced vertically font.beginDraw(0,curHeight) << "Last event: " << lastEvent << @@ -133,6 +122,8 @@ public: { AppCore::getInstance().createDisplay(800,600,32,0,0,false); + // be sure to add FPSDisplayTask + Kernel::getInstance().addTask(TaskPtr(new FPSDisplayTask())); Kernel::getInstance().addTask(TaskPtr(new MainTask())); Kernel::getInstance().run(); diff --git a/test/Pen_test.cpp b/test/Pen_test.cpp index 32ad795..bd6ceb4 100644 --- a/test/Pen_test.cpp +++ b/test/Pen_test.cpp @@ -5,11 +5,11 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: Pen_test.cpp,v 1.4 2005/07/20 03:58:54 cozman Exp $ +// $Id: Pen_test.cpp,v 1.5 2005/07/20 06:12:13 cozman Exp $ #include "photon.hpp" using namespace photon; -#include +#include "FPSDisplayTask.hpp" // used to display FPS in title bar class MainTask : public Task { @@ -30,18 +30,7 @@ public: void update() { - // used to measure FPS and display it in the title bar - static double t=0; - if(app.getTime() - t > 1.0) - { - app.setTitle("FPS: " + - boost::lexical_cast(app.getFramerate()) ); - t = app.getTime(); - } - static const math::Point2 center(400, 300); // used for clock - - video.clear(); unsigned int i,j; //used throughout demo @@ -96,6 +85,8 @@ public: { AppCore::getInstance().createDisplay(800,600,32,0,0,false); + // be sure to add FPSDisplayTask + Kernel::getInstance().addTask(TaskPtr(new FPSDisplayTask())); Kernel::getInstance().addTask(TaskPtr(new MainTask())); Kernel::getInstance().run(); diff --git a/test/Texture_test.cpp b/test/Texture_test.cpp index 6c28fc1..11ed492 100644 --- a/test/Texture_test.cpp +++ b/test/Texture_test.cpp @@ -5,11 +5,11 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: Texture_test.cpp,v 1.5 2005/07/20 01:35:11 cozman Exp $ +// $Id: Texture_test.cpp,v 1.6 2005/07/20 06:12:13 cozman Exp $ #include "photon.hpp" using namespace photon; -#include +#include "FPSDisplayTask.hpp" // used to display FPS in title bar class MainTask : public Task { @@ -38,17 +38,6 @@ public: void update() { - // used to measure FPS and display it in the title bar - static double t=0; - if(app.getTime() - t > 1.0) - { - app.setTitle("FPS: " + - boost::lexical_cast(app.getFramerate()) ); - t = app.getTime(); - } - - video.clear(); - // draw first texture at actual size tex[0].bind(); glBegin(GL_QUADS); @@ -96,6 +85,8 @@ public: { AppCore::getInstance().createDisplay(800,600,32,0,0,false); + // be sure to add FPSDisplayTask + Kernel::getInstance().addTask(TaskPtr(new FPSDisplayTask())); Kernel::getInstance().addTask(TaskPtr(new MainTask())); Kernel::getInstance().run();