SFML community forums

Help => System => Topic started by: Bizarreofnature on February 02, 2018, 06:39:47 pm

Title: sf::sleep problem
Post by: Bizarreofnature 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
Title: Re: sf::sleep problem
Post by: eXpl0it3r on February 02, 2018, 06:46:48 pm
"Doesn't work" is not a problem description.
Title: Re: sf::sleep problem
Post by: Bizarreofnature 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
Title: Re: sf::sleep problem
Post by: Bizarreofnature on February 02, 2018, 06:54:03 pm
Even

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

sleeps for 1 sec. Wtf.
Title: Re: sf::sleep problem
Post by: eXpl0it3r 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.
Title: Re: sf::sleep problem
Post by: Bizarreofnature 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?
Title: Re: sf::sleep problem
Post by: eXpl0it3r on February 02, 2018, 07:27:22 pm
By dragging the window?

How does that measure anything?
Title: Re: sf::sleep problem
Post by: Bizarreofnature 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.
Title: Re: sf::sleep problem
Post by: Bizarreofnature 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?
Title: Re: sf::sleep problem
Post by: Bizarreofnature on February 02, 2018, 08:25:45 pm
Its ok, ive made it with microseconds. Too bad seconds didnt work  :(
Title: Re: sf::sleep problem
Post by: Elias Daler 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.
Title: Re: sf::sleep problem
Post by: Bizarreofnature 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
Title: Re: sf::sleep problem
Post by: Laurent on February 03, 2018, 03:45:37 pm
What's your OS?
Title: Re: sf::sleep problem
Post by: Bizarreofnature on February 03, 2018, 05:18:36 pm
Win7 pro
Title: Re: sf::sleep problem
Post by: Hapax 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;
}
Title: Re: sf::sleep problem
Post by: eXpl0it3r on February 03, 2018, 06:02:40 pm
And try it without dragging your window, as that will make rendering stop working, while the sleep itself still goes on.

Point is, there's no reason why sf::seconds or sf::milliseconds would behave differently, as they both just create an sf::Time object with the given input. As such it sounds a lot like an user error, i.e. you interpreting some behavior wrongly.
Title: Re: sf::sleep problem
Post by: Bizarreofnature on February 03, 2018, 10:06:17 pm
I figured what it is. It's my compiler.
It seems like it doesnt compile everything from new.
It more like compiles certain things and takes other things from old compilations.
Wtf.

Im using vs 2017.

Anyone can help?  :(