Jump to content
  • Advertisement
Sign in to follow this  
fuzinavl

waiting instead of for()

This topic is 4828 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

My app will be single-threaded, and I would like all script logic to be done within the same game frame, so instead of: for(;;) { ... if( quitTimeOut && quitTimeOut < timeGetTime() ) ... } isn't there a function that will wait until: a) the script finishes executing its method b) a timeout defined in my C++ occurs whichever comes first? It seems that rolling around in a loop would eat processor cycles that the script could be using. I'm using a MingW compiler.

Share this post


Link to post
Share on other sites
Advertisement
How about sleep? You pass it the number of milliseconds to sleep:

// This will waste yet another second.
sleep( 1000 );


Greetz,

Illco

Share this post


Link to post
Share on other sites
Since your application is single threaded, it is either executing a script or it is processing your application code. The application is already waiting for the script to finish, so you don't need a function for that. The Execute() method only returns when the script finishes or is suspended by a call to Suspend(), either from the line callback or from an application function called from the script.

If your scripts finishes early and you don't want to start the next frame yet, then you could use sleep() to have the application wait until it is time to start the next frame. However, why would you want to do that?



Share this post


Link to post
Share on other sites
Let me rephrase the question:

In my single-threaded app, I want the script to run for 3 milliseconds at most. If the script finishes early, I need it to return control to the C++ program right away. I can only trust the C++ program to enforce these 2 rules.

How can I do this?

Share this post


Link to post
Share on other sites
fuzinavl:

I show how to implement timeouts for scripts in the sample Events. You should look specifically on how the line callback function is implemented.

Deyja:

while(true) may be clearer (it's a matter of opinion) but it is not accepted without warning by all compilers. The same compilers don't complain about for(;;) though, so my recommendation is to go with for(;;).

Share this post


Link to post
Share on other sites
r = mainCtx->SetLineCallback(asFUNCTION(LineCallback), &timeOut, asCALL_CDECL);

doh! (again). I was interchanging timeOut and quitTimeOut variables.

I didn't realize AS had this situation taken care of for me *and*, I can define what should happen in the situation! YAY!

Hopefully I can wrap this all up in a simple .h library and share it around soon.

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!