a simple fps monitor

This commit is contained in:
Oliver Kiehl 2004-04-15 20:20:04 +00:00
parent b1c5d0728d
commit 1964209430
5 changed files with 27 additions and 4 deletions

View file

@ -42,6 +42,9 @@ void Engine::mainLoop() {
movieTime_ = 0;
frameTime_ = 0;
frameStart_ = SDL_GetTicks();
unsigned int frameCounter = 0;
unsigned int timeAccum = 0;
char fps[8] = "";
for (;;) {
// Process events
@ -152,6 +155,15 @@ void Engine::mainLoop() {
(*i)->draw();
}
if (SHOWFPS_GLOBAL) {
if (timeAccum > 1000) {
sprintf(fps, "%7.2f", (double)(frameCounter * 1000) / (double)timeAccum );
frameCounter = 0;
timeAccum = 0;
}
g_driver->drawEmergString(550, 25, fps, Color(255, 255, 255));
}
currScene_->drawBitmaps(ObjectState::OBJSTATE_OVERLAY);
g_driver->flipBuffer();
@ -165,6 +177,11 @@ void Engine::mainLoop() {
frameTime_ = newStart - frameStart_;
frameStart_ = newStart;
if (SHOWFPS_GLOBAL) {
frameCounter++;
timeAccum += frameTime_;
}
lua_beginblock();
set_frameTime(frameTime_);
lua_endblock();