Ok here it goes. I've recently integrated Angelscript to our team's game engine and
I've got some questions.
The way i've made it now:
I have a seperate module for each type of job, e.g gui, entity control etc.
Let's concentrate on Entity Control for the moment. Each Entity has a Script Component which's job is to cache the function ID provided by the asIScriptEngine of the script function that the parent Entity must execute (defined in a file specifying the function's module and the function's prototype).
On each update (every frame) the Script Component prepares a context with the cached ID, passes a handle to it's parent Entity as a paremeter to the Script Function and executes it.
The problem arises here, say that a script is like this:
void main(Entity@ currentEntity){ if(currentEntity.isHit(player)) { Spawn_Particle("Fire_Burst", ...) currentEntity.Echo("THOU ART DOOMED!"); currentEntity.Kill(); }}
As you can understand, this script's operations will all be executed in the same frame (something which is not good), because angelscript executes the Main script function first and then returns control to the host application, which in turn updates the Entities, the Player, the Screen etc.
Is it possible to script the engine in a way that's independent of how it is updated? I thought about executing the script function in a separate thread but it seems a little bit overwhelming since the engine doesn't support multithreading currently.