Jump to content
  • Advertisement
Sign in to follow this  
wforl

game clock jumping around

This topic is 3715 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

My fps seems to be jumping around ~ +-10%, even when the game has nothing loaded or is doing any real processing. This is the function, which is called every frame to update, but i choose to update the screen text displaying the fps either every second or 500 ms. but as i said above the fps is varying quite alot, with nothing being done, so im guessing theres a discrep in my update code.
void Clock::update()
{
	static __int64 prevTimeStamp = 0;
	static __int64 currentStamp = 0;
	
	
	QueryPerformanceCounter((LARGE_INTEGER*)&currentStamp);
	
	if(prevTimeStamp == 0)
		prevTimeStamp = currentStamp;

	__int64 ticsElapsed = currentStamp - prevTimeStamp; 

	if(ticsElapsed != 0)
	{
		FrameLapse = (double)ticsElapsed/(double)oneMilliSecondInTicks;

		this->FPS = (float)1000.0f/(float)FrameLapse;
		this->Time_MSec += FrameLapse;

		if(Time_MSec >= 1000.0f)
		{
			while(Time_MSec >= 1000.0f)
			{
				this->Total_MSec += 1000.0f;
				this->Time_MSec -= 1000.0f;
			}
		}
	}

	prevTimeStamp = currentStamp;
}

Share this post


Link to post
Share on other sites
Advertisement
Could you post you system specs? I heard once there were issues with Performance timing and MultiCore CPUs. Don't know if this still applies...

Share this post


Link to post
Share on other sites
Quote:
Original post by Madhed
Could you post you system specs? I heard once there were issues with Performance timing and MultiCore CPUs. Don't know if this still applies...


This question can be solved quickly, either by setting the Affinity in Task Manager, or by setting the affinity via SetProcessAffinityMask.

Share this post


Link to post
Share on other sites
Quote:
Original post by nife87This question can be solved quickly, either by setting the Affinity in Task Manager, or by setting the affinity viaSetProcessAffinityMask.
That sounds almost too good to be true. The jumping clock phenomenon is something that has been bugging many people (including myself) for a long time, especially as there is no non-RDTSC based timer better than 1ms on a wide variety of Windows Computers. So if you need better than 1ms resolution, you're kind of screwed.
Have you actually tried your proposed solution, and does it work reliably? Would be great if it did.

Also, do you have a working solution at hand which still lets your application take advantage of all the available cores?
I'm thinking something like binding only one thread to CPU0 for the sole purpose of querying the timer might work. So the actual application can run on whatever core is opportune and can have several threads execute in parallel.
However, I'm not sure it's entirely trivial to properly implement and synchronize this, so you get both more or less accurate and high-resolution results and don't burn too many CPU cycles.
Basically, you could write the realtime stamp to a known memory location from the bound thread and read from whatever other thread needs it. It probably wouldn't even need atomic ops, since it doesn't really matter as long as it's monotonous.
However, you'd have to either sleep regularly which preserves accuracy but reduces the resolution, or do some kind of double-locking, so the counter thread only wakes up and delivers a result when you need one. That'll have better resolution, but locking is quite expensive. Or, you'd have to poll continuously, which burns cycles and invalidates the cache line like crazy, so any read will be a certain cache miss. Or...? Something better?

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!