Sign in to follow this  
Antonym

Calculating FPS

Recommended Posts

Antonym    179
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.

Share this post


Link to post
Share on other sites
Antonym    179
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;

Share this post


Link to post
Share on other sites
Storyyeller    215
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_;
};

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this