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.

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 on other sites
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 on other sites
Quote:
 Original post by MadhedCould 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 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?

1. 1
2. 2
Rutin
21
3. 3
4. 4
frob
17
5. 5

• 9
• 12
• 9
• 33
• 13
• Forum Statistics

• Total Topics
632589
• Total Posts
3007243

×