added FPSDisplayTask and a VideoCore::UpdateTask

This commit is contained in:
James Turk 2005-07-20 06:12:13 +00:00
parent 2a35d276de
commit 6edf689539
7 changed files with 59 additions and 86 deletions

View File

@ -5,11 +5,11 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // 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" #include "photon.hpp"
using namespace photon; using namespace photon;
#include <boost/lexical_cast.hpp> #include "FPSDisplayTask.hpp" // used to display FPS in title bar
// actual test is only compiled if OpenAL is in use // actual test is only compiled if OpenAL is in use
#ifdef PHOTON_USE_OPENAL #ifdef PHOTON_USE_OPENAL
@ -23,7 +23,6 @@ class MainTask : public Task , public InputListener
public: public:
MainTask() : MainTask() :
Task("MainTask"), Task("MainTask"),
app(AppCore::getInstance()),
video(video::VideoCore::getInstance()) video(video::VideoCore::getInstance())
{ {
video.setOrthoView(800,600); // setup view video.setOrthoView(800,600); // setup view
@ -160,20 +159,9 @@ public:
// called once per frame // called once per frame
void update() 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<std::string>(app.getFramerate()) );
t = app.getTime();
}
// used for calculating draw position // used for calculating draw position
static const photon::uint fontHeight(font.getHeight()); static const photon::uint fontHeight(font.getHeight());
video.clear(); // clear display before drawing
// draw the status of all 6 sounds // draw the status of all 6 sounds
font.beginDraw(0, 0*fontHeight) << "(C)himes is " << status[0] << font.beginDraw(0, 0*fontHeight) << "(C)himes is " << status[0] <<
"playing" << font.endDraw(); "playing" << font.endDraw();
@ -195,8 +183,6 @@ private:
audio::Sample chimes, ocean, rain, stream, thunder, waterdrop; audio::Sample chimes, ocean, rain, stream, thunder, waterdrop;
std::string status[6]; std::string status[6];
// references to singleton cores
AppCore& app;
video::VideoCore& video; video::VideoCore& video;
}; };
@ -209,9 +195,11 @@ public:
// create window // create window
AppCore::getInstance().createDisplay(800,600,32,0,0,false); AppCore::getInstance().createDisplay(800,600,32,0,0,false);
// create sound device // 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())); Kernel::getInstance().addTask(TaskPtr(new MainTask()));
// run Kernel until task finishes // run Kernel until task finishes
Kernel::getInstance().run(); Kernel::getInstance().run();

33
test/FPSDisplayTask.hpp Normal file
View File

@ -0,0 +1,33 @@
#ifndef FPSDISPLAYTASK_HPP
#define FPSDISPLAYTASK_HPP
#include "photon.hpp"
#include <boost/lexical_cast.hpp>
// 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<std::string>(app.getFramerate()) );
lastUpdate = app.getTime();
}
}
private:
photon::AppCore& app;
double lastUpdate;
};
#endif //FPSDISPLAYTASK_HPP

View File

@ -5,12 +5,11 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // 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" #include "photon.hpp"
using namespace photon; using namespace photon;
#include <boost/lexical_cast.hpp> #include "FPSDisplayTask.hpp" // used to display FPS in title bar
class MainTask : public Task class MainTask : public Task
{ {
@ -33,18 +32,6 @@ public:
void update() 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<std::string>(app.getFramerate()) );
t = app.getTime();
}
// clear screen
video.clear();
// draw the three strings to the screen // draw the three strings to the screen
font.setColor(video::Color(0,128,128)); font.setColor(video::Color(0,128,128));
font.drawText(0, 0, "Photon"); font.drawText(0, 0, "Photon");
@ -71,6 +58,8 @@ public:
{ {
AppCore::getInstance().createDisplay(800,600,32,0,0,false); 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().addTask(TaskPtr(new MainTask()));
Kernel::getInstance().run(); Kernel::getInstance().run();

View File

@ -5,11 +5,11 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // 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" #include "photon.hpp"
using namespace photon; using namespace photon;
#include <boost/lexical_cast.hpp> #include "FPSDisplayTask.hpp" // used to display FPS in title bar
class MainTask : public Task class MainTask : public Task
{ {
@ -41,18 +41,6 @@ public:
void update() 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<std::string>(app.getFramerate()) );
t = app.getTime();
}
// clear screen
video.clear();
// draw in top left corner // draw in top left corner
img[0].draw(0,0); img[0].draw(0,0);
@ -82,6 +70,8 @@ public:
{ {
AppCore::getInstance().createDisplay(800,600,32,0,0,false); 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().addTask(TaskPtr(new MainTask()));
Kernel::getInstance().run(); Kernel::getInstance().run();

View File

@ -5,11 +5,11 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // 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" #include "photon.hpp"
using namespace photon; using namespace photon;
#include <boost/lexical_cast.hpp> #include "FPSDisplayTask.hpp" // used to display FPS in title bar
class MainTask : public Task, public InputListener class MainTask : public Task, public InputListener
{ {
@ -58,21 +58,10 @@ public:
void update() 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<std::string>(app.getFramerate()) );
t = app.getTime();
}
// used for spacing text vertically // used for spacing text vertically
static const photon::uint fontHeight(font.getHeight()); static const photon::uint fontHeight(font.getHeight());
photon::uint curHeight(0); photon::uint curHeight(0);
video.clear(); // clear display
// draw input event/status notifications, increment curHeight on each // draw input event/status notifications, increment curHeight on each
// draw so that text is properly spaced vertically // draw so that text is properly spaced vertically
font.beginDraw(0,curHeight) << "Last event: " << lastEvent << font.beginDraw(0,curHeight) << "Last event: " << lastEvent <<
@ -133,6 +122,8 @@ public:
{ {
AppCore::getInstance().createDisplay(800,600,32,0,0,false); 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().addTask(TaskPtr(new MainTask()));
Kernel::getInstance().run(); Kernel::getInstance().run();

View File

@ -5,11 +5,11 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // 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" #include "photon.hpp"
using namespace photon; using namespace photon;
#include <boost/lexical_cast.hpp> #include "FPSDisplayTask.hpp" // used to display FPS in title bar
class MainTask : public Task class MainTask : public Task
{ {
@ -30,18 +30,7 @@ public:
void update() 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<std::string>(app.getFramerate()) );
t = app.getTime();
}
static const math::Point2 center(400, 300); // used for clock static const math::Point2 center(400, 300); // used for clock
video.clear();
unsigned int i,j; //used throughout demo unsigned int i,j; //used throughout demo
@ -96,6 +85,8 @@ public:
{ {
AppCore::getInstance().createDisplay(800,600,32,0,0,false); 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().addTask(TaskPtr(new MainTask()));
Kernel::getInstance().run(); Kernel::getInstance().run();

View File

@ -5,11 +5,11 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // 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" #include "photon.hpp"
using namespace photon; using namespace photon;
#include <boost/lexical_cast.hpp> #include "FPSDisplayTask.hpp" // used to display FPS in title bar
class MainTask : public Task class MainTask : public Task
{ {
@ -38,17 +38,6 @@ public:
void update() 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<std::string>(app.getFramerate()) );
t = app.getTime();
}
video.clear();
// draw first texture at actual size // draw first texture at actual size
tex[0].bind(); tex[0].bind();
glBegin(GL_QUADS); glBegin(GL_QUADS);
@ -96,6 +85,8 @@ public:
{ {
AppCore::getInstance().createDisplay(800,600,32,0,0,false); 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().addTask(TaskPtr(new MainTask()));
Kernel::getInstance().run(); Kernel::getInstance().run();