Advertisement

RequestContext() / ReturnContext() question

Started by September 02, 2015 06:45 PM
0 comments, last by WitchLord 9 years, 2 months ago
On this page, the documentation says:
It is seldom necessary to maintain more than one script context at a time, with the only exceptions being when a script calls an application function that in turn calls another script before returning, and if multiple scripts are running in parallel.
Try to avoid associating a unique context with each object that may need to call scripts. Instead keep a shared pool of contexts that can be requested by the objects on a need-to basis.

It sounds like that's what aslScriptEngine::RequestContext() and aslScriptEngine::ReturnContext() do for me, as convenience functions?
So if I have several scripts I'm wanting to run in parallel (not multithreaded, but with their execution being suspended and resumed at different times with their states needing to be preserved), can I just let AngelScript handle the pool of contexts for me using the two above functions?

I'll need to make a clarification on that page in the manual. Thanks for brining this up.

RequestContext and ReturnContext does not implement the context pool for you. However, they are there to simplify the implementation of a context pool. By default, these methods internally calls CreateContext and Release, but if you register the context callbacks they will call those instead of CreateContext/Release. Registering the context callbacks will allow the application to prepare the context for the engine's internal calls too, thus allowing the application to trace/debug even these internal calls (internal calls happens for example when initializing global variables or destroying objects from the garbage collector). The add-ons are also using the RequestContext and ReturnContext calls so all goes to the same place.

A basic implementation of a context pool is described here on the fine tuning page in the manual.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement