Skip to content
Browse files

ADD fps statistic (easily running 60 fps without log)

  • Loading branch information...
1 parent 21c033a commit db4fae19d7ca4f0a423e8b0734ef4a6618e7363a @PowerKiKi committed Jun 27, 2009
View
14 application/source/Game.cpp
@@ -48,17 +48,21 @@ namespace Polukili
void Game::run(const string& initialLevel)
{
this->changeLevel(initialLevel);
+ int frameCount = 0;
+ char framePerSecond[16];
while (!this->levels.empty())
{
Level* level = this->levels.top();
-
+
level->nextStep();
level->render();
if (this->console.isEnabled())
this->console.render();
+ this->font.DisplayText(580, 16, framePerSecond);
+
this->gameWindow.Flush();
// If level is finished, resume the previous one
@@ -79,6 +83,14 @@ namespace Polukili
// We return to the launcher application via exit
if (pressed & WPAD_BUTTON_HOME) exit(0);
if (pressed & WPAD_BUTTON_PLUS) this->console.enable(!this->console.isEnabled());
+
+ // Count FPS
+ frameCount++;
+ if (this->fpsTimer.isExpired())
+ {
+ sprintf(framePerSecond, "%2d FPS", frameCount);
+ frameCount = 0;
+ }
}
}
View
2 application/source/Game.h
@@ -15,6 +15,7 @@
#include <BibScreenFont.h>
#include <ContactListener.h>
#include <Console.h>
+#include <PeriodicTimer.h>
using namespace std;
@@ -61,6 +62,7 @@ namespace Polukili
wsp::GameWindow gameWindow;
BibScreenFont font;
Console console;
+ PeriodicTimer fpsTimer;
};
} /* End of namespace Polukili */
View
18 application/source/PeriodicTimer.cpp
@@ -7,19 +7,33 @@
namespace Polukili
{
+ /*************************************************/
+ PeriodicTimer::PeriodicTimer()
+ : nextExpiry(0)
+ {
+ this->setPeriod(1000);
+ this->isExpired(); // to consume current period
+ }
/*************************************************/
PeriodicTimer::PeriodicTimer(int period)
- : period(millisecs_to_ticks(period))
+ : nextExpiry(0)
{
- this->reset();
+ this->setPeriod(period);
+ this->isExpired(); // to consume current period
}
/*************************************************/
PeriodicTimer::~PeriodicTimer()
{
}
+
+ /*************************************************/
+ void PeriodicTimer::setPeriod(int period)
+ {
+ this->period = millisecs_to_ticks(period);
+ }
/*************************************************/
bool PeriodicTimer::isExpired()
View
13 application/source/PeriodicTimer.h
@@ -15,7 +15,12 @@ namespace Polukili
public:
/**
- * Constructor a periodic timer with period in milliseconds.
+ * Constructor with a period of 1 second.
+ */
+ PeriodicTimer();
+
+ /**
+ * Constructor for a periodic timer with period in milliseconds.
*/
PeriodicTimer(int period);
@@ -25,6 +30,11 @@ namespace Polukili
~PeriodicTimer();
/**
+ * Sets the period in milliseconds.
+ */
+ void setPeriod(int period);
+
+ /**
* Returns if the period is over. If true, the period must be consumed.
*/
bool isExpired();
@@ -37,7 +47,6 @@ namespace Polukili
private:
u64 period;
u64 nextExpiry;
- bool isConsumed;
};
}

0 comments on commit db4fae1

Please sign in to comment.
Something went wrong with that request. Please try again.