Path: /sdk/add_on/contextmgr/
The CContextMgr
is a class designed to aid the management of multiple simultaneous scripts executing in parallel. It supports both concurrent script threads and co-routines.
If the application doesn't need multiple contexts, i.e. all scripts that are executed always complete before the next script is executed, then this class is not necessary.
The context manager uses asIScriptEngine::RequestContext to take advantage of any context callbacks registered with the engine, e.g. for debugging or pooling.
Multiple context managers can be used, for example when you have a group of scripts controlling in-game objects, and another group of scripts controlling GUI elements, then each of these groups may be managed by different context managers.
Observe that the context manager class hasn't been designed for multi-threading, so you need to be careful if your application needs to execute scripts from multiple threads.
funcdef void coroutine(dictionary@); void createCoRoutine(coroutine @, dictionary @); void yield();
funcdef void coroutine(dictionary@)
void createCoRoutine(coroutine @, dictionary @)
This function is used to create a co-routine. The co-routine will initiate in a yielded state, i.e. it will only begin execution once the control is given to it by the current thread.
Multiple co-routines can be created, and they will each take turn to execute in round-robin fashion.
void yield()
Yields control of the execution for the next co-routine in the queue.
When a co-routine receives control it will resume execution from the last call to yield, or the entry point if this is the first time the co-routine is allowed to execute.