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

Author Topic: sf::sleep problem  (Read 12423 times)

0 Members and 2 Guests are viewing this topic.

Bizarreofnature

  • Newbie
  • *
  • Posts: 48
    • View Profile
sf::sleep problem
« on: February 02, 2018, 06:39:47 pm »
Hello!

Quote
sf::sleep (sf::seconds ( ((1.0f / 60) - cTimer.GetElapsedTime ()) ));

GetElapsedTime returns as float.

It doesnt work. The weird thing is that even the following does NOT work:

Quote
sf::sleep (sf::seconds (1.0f) );

Please help me, i already googled like crazy and nothing :-/

Best regards,
Bizarreofnature

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: sf::sleep problem
« Reply #1 on: February 02, 2018, 06:46:48 pm »
"Doesn't work" is not a problem description.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Bizarreofnature

  • Newbie
  • *
  • Posts: 48
    • View Profile
Re: sf::sleep problem
« Reply #2 on: February 02, 2018, 06:48:51 pm »
Yes, you are right. Im sorry.

For example the following does not sleep for 0.1 sec, it sleeps for 1 sec.

Quote
sf::sleep (sf::seconds (0.1f) );

while

Quote
sf::sleep (sf::seconds (1.0f) );

sleeps the same time

Bizarreofnature

  • Newbie
  • *
  • Posts: 48
    • View Profile
Re: sf::sleep problem
« Reply #3 on: February 02, 2018, 06:54:03 pm »
Even

Quote
sf::sleep (sf::seconds (100.0f) );

sleeps for 1 sec. Wtf.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: sf::sleep problem
« Reply #4 on: February 02, 2018, 07:07:26 pm »
And how do you determine that?

sf::sleep just calls a system function, so if that doesn't do its job then you might have a weird system or some weird driver or some weird application.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Bizarreofnature

  • Newbie
  • *
  • Posts: 48
    • View Profile
Re: sf::sleep problem
« Reply #5 on: February 02, 2018, 07:09:42 pm »
By dragging the window.

So i guess its better to use the setFramerateLimit function to limit fps?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: sf::sleep problem
« Reply #6 on: February 02, 2018, 07:27:22 pm »
By dragging the window?

How does that measure anything?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Bizarreofnature

  • Newbie
  • *
  • Posts: 48
    • View Profile
Re: sf::sleep problem
« Reply #7 on: February 02, 2018, 07:34:50 pm »
By dragging the window?

How does that measure anything?

It actually does. When i use sleep it "freezes" the window for a certain time.

Bizarreofnature

  • Newbie
  • *
  • Posts: 48
    • View Profile
Re: sf::sleep problem
« Reply #8 on: February 02, 2018, 07:36:58 pm »
I just tried sf::milliseconds. It works.
The problem is sf::seconds.

EDIT: What should i do?
« Last Edit: February 02, 2018, 07:55:44 pm by Bizarreofnature »

Bizarreofnature

  • Newbie
  • *
  • Posts: 48
    • View Profile
Re: sf::sleep problem
« Reply #9 on: February 02, 2018, 08:25:45 pm »
Its ok, ive made it with microseconds. Too bad seconds didnt work  :(

Elias Daler

  • Hero Member
  • *****
  • Posts: 599
    • View Profile
    • Blog
    • Email
Re: sf::sleep problem
« Reply #10 on: February 03, 2018, 11:37:43 am »
Try doing this and see if "2" is printed with 5 sec delay.
std::cout << "1" << std::endl;
sf::sleep(sf::seconds(5.0));
std::cout << "2" << std::endl;

Testing sleep by moving a window is not the best way, because OS may handle window movement in another thread, I think.
Tomb Painter, Re:creation dev (abandoned, doing other things) | edw.is | @EliasDaler

Bizarreofnature

  • Newbie
  • *
  • Posts: 48
    • View Profile
Re: sf::sleep problem
« Reply #11 on: February 03, 2018, 03:29:55 pm »
I tried it. It doesnt work. Whatever value i try it always waits around 3-4 sec.

Ive tried 5.0, 1.5, 0.5

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::sleep problem
« Reply #12 on: February 03, 2018, 03:45:37 pm »
What's your OS?
Laurent Gomila - SFML developer

Bizarreofnature

  • Newbie
  • *
  • Posts: 48
    • View Profile
Re: sf::sleep problem
« Reply #13 on: February 03, 2018, 05:18:36 pm »
Win7 pro

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: sf::sleep problem
« Reply #14 on: February 03, 2018, 05:28:34 pm »
Have you tried separately from your project?
Try this complete example:
#include <SFML/System.hpp>
#include <iostream>
int main()
{
        std::cout << "1" << std::endl;
        sf::sleep(sf::seconds(5.0));
        std::cout << "2" << std::endl;
        return EXIT_SUCCESS;
}
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything