Jump to content
  • Advertisement
Sign in to follow this  
DividedByZero

Problems getting timing right

This topic is 2482 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys,

I have made a couter that is part of a class, that I am trying to get right.

So, far I am able to accurately assess the frames per second in a scene. But, I am having problems calculating the time since the last frame, so that movement and animations run at the same speed on any computer.

But I am finding, different PC's are giving different movement speeds although I want them to be the same.

int Engine::counterFramerate()
{
// get curent PC frequecy (incase of overclocking during test)
LARGE_INTEGER li;
start=current;
QueryPerformanceCounter(&li);
current=(double(li.QuadPart))/1000;
nCounter++;
total=total+current-start;
tslf=(current-start);
if((total)>=1000)
{
nFramesPerSecond=nCounter;
nCounter=0;
QueryPerformanceCounter(&li);
PCCounter=double(li.QuadPart);
start=PCCounter;
total=0;
}
return nFramesPerSecond;
}

double Engine::counterTimeSinceLastFrame()
{
return tslf;
}


counterFramerate() returns FPS and counterTimeSinceLastFrame() should return the time lapsed since the last frame but doesn't seem to be doing so correctly.

Can anyone see where I might have gone wrong?

Thanks in advance smile.png

Share this post


Link to post
Share on other sites
Advertisement
I count the time needed for rendering 10 frames and use fixed steps for physics. With 200-700 physical steps per second, you do not need to interpolate from fixed physics to dynamic framerate. You can use vertical synchronization if rendering is faster than the monitor.

Share this post


Link to post
Share on other sites
I am now dividing by [size="2"]QueryPerformanceFrequency(), which is now qiving me more reasonable numbers to play with.

[size="2"]Although, the result between frames is often the same. Does this mean the framerate is too fast for QueryPerformanceCounter() to see a difference?

[size="2"]I thought this was what [size="2"]QueryPerformanceCounter() was for, to give a higher degree of accuracy than GetTickCount().

Share this post


Link to post
Share on other sites
The accuracy of the timer can be bad for short durations because the the CPU do many things at the same time and in the wrong order to get more speed. Sometimes, I get a negative duration when trying to measure how long it takes to do something.

Share this post


Link to post
Share on other sites
I have gone back to the good old GetTickCount() and locking my framerate to 100 FPS.

I have since read lots of nasty things about the performance counters. Including docs published by Microsoft about its downfalls.

Now my app seems to run pretty close on systems with different specs.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!