Jump to content
  • Advertisement
Sign in to follow this  
Caliel

Re: Long running scripts & concurrent contexts

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

In the SDK/Samples folder there is a concurrent context example.  In the same two scripts are executed, script1/script2, with each script having a for loop that sleeps for 1 second.  Within the main.cpp, the following function then causes the scripts to execute:

 

for(;;)
{
// Check if any key was pressed
if( kbhit() )
{
contextManager.AbortAll();
break;
}
 
// Allow the contextManager to determine which script to execute next
contextManager.ExecuteScripts();
}

 

 

I understand the contextManager.ExecuteScripts() causes the "main" in each of the scripts to be executed, and more particularly, given time to perform their loop before yielding back and sleeping.  
 
However, what I do not understand (nor can find in the documentation) is the answer to the following questions:
 
  1. Does the ExecuteScripts() method only call the main function in each thread?  I assume this is true, but I can't find the answer within the contextmanager addon sourcecode.  It would be good to know why ExecuteScripts is calling 'main' and if its limited to only operating on that interface method.  It would be nice to be able to write a class with a method that is intended to be long-running and called by the ContextManager.  I know I can get there by having an object instantiated in main and calling its methods.. but I'd like to avoid that if possible.
  2. This leads to my second question, what if I want to call a script function from the C++ side.  For instance, what if I want to call Obj::SomeLongRunningMethod() that sleeps every 500 ms and performs some type of long-running state control.

Thanks very much

 

Share this post


Link to post
Share on other sites
Advertisement

The context manager doesn't by itself what is being executed. You just add the already prepared contexts to the manager, and then the manager will cycle through them to let each execute for a portion of time before the next. If you add the context as a co-routine to another, then the switch will only happen when one of the contexts call yield(), but if you add the context as a concurrent routine the switch will happen on a timing interval.

You can call class methods from the application too. Just prepare the context with the method, and set up the object to invoke the method on. Once the context is prepared you can give it to the context manager to manage the execution.

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!