Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Clock getting paused by Sleep()  (Read 4855 times)

0 Members and 1 Guest are viewing this topic.

Hericage

  • Newbie
  • *
  • Posts: 4
    • View Profile
Clock getting paused by Sleep()
« 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:
Code: [Select]

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:
Code: [Select]

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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32451
    • View Profile
    • SFML's website
    • Email
Clock getting paused by Sleep()
« Reply #1 on: April 10, 2009, 11:34:06 am »
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.
Laurent Gomila - SFML developer

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Clock getting paused by Sleep()
« Reply #2 on: April 10, 2009, 12:12:39 pm »
Boost says something about that :
Quote from: "[url=http://www.boost.org/doc/libs/1_38_0/doc/html/date_time/posix_time.html#ptime_from_clock
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.
SFML / OS X developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32451
    • View Profile
    • SFML's website
    • Email
Clock getting paused by Sleep()
« Reply #3 on: April 10, 2009, 12:32:02 pm »
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.
Laurent Gomila - SFML developer

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Clock getting paused by Sleep()
« Reply #4 on: April 10, 2009, 01:42:41 pm »
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)
SFML / OS X developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32451
    • View Profile
    • SFML's website
    • Email
Clock getting paused by Sleep()
« Reply #5 on: April 10, 2009, 02:14:25 pm »
No.
Laurent Gomila - SFML developer