SFML community forums
Help => System => Topic started by: Hericage on April 10, 2009, 02:16:49 am
-
Couldn't find any information about this so I figuered i'd had to ask :)
We're currently working on a game projekt and we've done some prototyping in SFML.. From what we can see a sf::Clock will return incorrect values if used along with a sleep.
example1:
sf::Clock Clock;
while(true)
{
//do some stuff, break after 60 seconds
Sleep(1);
}
std::cout << Clock.GetElapsedTime() << std::endl;
we tested with a stop watch and broke the loop manually after 60 seconds, the Clock.GetElapsedTime() would return a value of ~35 seconds.
example2:
sf::Clock Clock;
while(true)
{
//do some stuff, break after 60 seconds
//Sleep(1);
}
std::cout << Clock.GetElapsedTime() << std::endl;
with the sleep out of the way, and the programm still running for 60 seconds, it returned a far more precise value.
Is there something we're doing wrong or is this a bug?
to work around it we're using floats in wich we add all the sleep values and then add the Clocks time.
edit: I'm using windows XP btw.
-
I guess the low-level function I'm using is counting in process time, not in absolute time. I don't know if any function can do this, I have to investigate.
-
Boost says something about that :
posix time[/url]"]Get the local time using a sub second resolution clock. On Unix systems this is implemented using GetTimeOfDay. On most Win32 platforms it is implemented using ftime. Win32 systems often do not achieve microsecond resolution via this API. If higher resolution is critical to your application test your platform to see the achieved resolution.
Maybe it'll help you.
-
It's not a problem of resolution, SFML is already using the most accurate timer on Windows. It's a matter of measuring the absolute time rather than the process time (i.e. the time elapsed while the process is running on the OS scheduler). I think most functions measure the process time.
-
Yeap, I was mislead with the "less accurate" (line 54, Platform.cpp, Win32), I think.
Is it the reason which Hericage has problem ? (Not having UseHighPerformanceTimer = false)
-
No.