Jump to content
  • Advertisement
Sign in to follow this  
Codorke

Sleep function in a while statement (basic)

This topic is 4841 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How can i do following statement in C++ :

while( ... ) {
   doFunction(...);
   // sleep for x millisec so doFunction( ... ) can proceed x millisec without  
   // beeing re-called during these time
}


I know this is basic procedure but i never used a sleep function before Thanks

Share this post


Link to post
Share on other sites
Advertisement
Using windows I think there is a function Sleep(int milliseconds), for which you have to include windows.h (I think).
If you don't want to rely on any other functions then in your sleep function you will have to loop untill a certain time has passed.

Share this post


Link to post
Share on other sites
If you do it in that fashion the sleep will not run until doFunction() has returned anyway, so you will be executing the function in its entirety (unless it does threading stuff inside) and then sleeping for however long, so the delay will always come after the function call.

You don't mention your thread situation though so I'm just assuming you are running in a single thread, so everything will proceed sequentially.

Share this post


Link to post
Share on other sites
I needed it to turn several pages in my 3D Book. When i click on a bookmark the pages turn too the specified page. But my pages may not turn all together. So i needed somehow something to delay the turn operation between 2 pages. But if i use the sleep function my entire program falls a sleep and the turn action from the previous page also stops executing.

So i use a flag that will be set when the previous page is turned 5 degrees. Until the flag is set no other page can be turned. And the function to turn the pages will be called until the specified page is reached.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!