Calculating FPS

Started by
3 comments, last by Antonym 14 years ago
I am trying to find out the frames per second in a game I am working on. I tried FRAPS but it won't show the FPS for my exe, I tried it with a different exe and it worked though :S. If I try running my exe in a different computer it does work. I decided to try and do it manually but the FPS won't go over 60. I was told this max could be disabled by setting vertical sync in the nvidia control panel to force off but nothing changed, oddly enough it did work for the other exe. In both computers the FPS won't go over 60 for my exe. Any thoughts/ideas? Thanks.
Advertisement
Could you be accidentally setting vsync in your code?

Also:
http://www.gamedev.net/community/forums/topic.asp?topic_id=566568#3625746
Quote:
Could you be accidentally setting vsync in your code?


Maybe, how does one enable vsync in code?

I looked at the thread and the fpsAccurate gives 60, the fpsInstantaneous gives 0.

unsigned float currentTick = 0;unsigned float lastTick = 0;unsigned float elapsedTicks = 0;unsigned float fpsTimer = 0;unsigned float fpsFrameCount = 0;unsigned float fpsAccurate = 0;unsigned float fpsInstantaneous = 0;bool timer_start = false;void play_state::draw(){	app->d3d->start_render();	if(!timer_start){		timer_start = true;		currentTick = 0;		lastTick = 0;		elapsedTicks = 0;		currentTick = lastTick = timeGetTime();	}	lastTick = currentTick;	currentTick = timeGetTime();	elapsedTicks = currentTick - lastTick;	float elapsedTime = elapsedTicks / 1000.f;	++fpsFrameCount;	fpsTimer += elapsedTicks;	if ( fpsTimer >= 10000 ) {		fpsAccurate = fpsFrameCount;		fpsFrameCount = 0;		fpsTimer = 0;	}	if ( elapsedTicks )		fpsInstantaneous = 1000 / elapsedTicks;
By the way, you can get more accurate time values using QueryPerformanceCounter.

Here's a useful piece of code I found.
#pragma once#include <windows.h>/// Create a Timer, which will immediately begin counting/// up from 0.0 seconds./// You can call reset() to make it start over.class Timer {  public:    Timer() {      reset();    }    /// reset() makes the timer start over counting from 0.0 seconds.    void reset() {      unsigned __int64 pf;      QueryPerformanceFrequency( (LARGE_INTEGER *)&pf );      freq_ = 1.0 / (double)pf;      QueryPerformanceCounter( (LARGE_INTEGER *)&baseTime_ );    }    /// seconds() returns the number of seconds (to very high resolution)    /// elapsed since the timer was last created or reset().    double seconds() {      unsigned __int64 val;      QueryPerformanceCounter( (LARGE_INTEGER *)&val );      return (val - baseTime_) * freq_;    }    /// seconds() returns the number of milliseconds (to very high resolution)    /// elapsed since the timer was last created or reset().    double milliseconds() {      return seconds() * 1000.0;    }  private:    double freq_;    unsigned __int64 baseTime_;};
I trust exceptions about as far as I can throw them.
I used that with my original though no difference, it won't go over 60 :S.

Edit: Nevermind! Problem solved, using the search function I found this:

http://www.gamedev.net/community/forums/topic.asp?topic_id=480375

[Edited by - Antonym on April 24, 2010 2:20:45 PM]

This topic is closed to new replies.

Advertisement