Suggestions for future AngelScript features

Started by
23 comments, last by WitchLord 19 years, 11 months ago
OK, could you save me the time from studying the Lua manual and tell me a little more about how coroutines work?

What little I know about coroutines is that they work kind of like threads, except they are not managed by the processor. Instead the coroutines themselves give control to one another.

How would you like this to work in AngelScript? Can you give an example?

AngelScript can already have several contexts running like coroutines. Though they can only give up control to the host application by suspension. The host application would be responsible for resuming the next context.

__________________________________________________________
www.AngelCode.com - game development and more...
AngelScript - free scripting library - Tower - free puzzle game

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

Advertisement
All this requests and stuff, but I''d like to request something else. If you could provide some documents about how the script engine works maybe we can contribute ourselves. I for one would like to help development of angelscript but I have no idea where to start.

I would like to. If only I had the patience and time to do so.

I''ll see what I can do, further on. Or if you want to start on such a document I will be more than happy to answer any questions you might have.

Thanks for your interest in helping out.

__________________________________________________________
www.AngelCode.com - game development and more...
AngelScript - free scripting library - Tower - free puzzle game

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

quote:Original post by WitchLord
OK, could you save me the time from studying the Lua manual and tell me a little more about how coroutines work?

What little I know about coroutines is that they work kind of like threads, except they are not managed by the processor. Instead the coroutines themselves give control to one another.


Hi, I just ran into AngelScript - it's a pretty cool language, I think the compiler/sdk is very well designed too.

At Treyarch we have used a script language similar to AngelScript since 1998, it's C++ like with interfaces into application classes, various features like operator overloading, etc..

The main difference is that our language is based on this same concept of coroutines, or more specifically cooperative multithreading- it's mostly just a difference in the way the contexts and VM deal with suspending execution.

Here's a simple example:

void wait_fade(a,b,duration){  float t = time();  while ( time()-t<duration )  {    fade_screen( a + (b-a)*(time()-t)/duration );    yield;  }}void wait(duration){  float t = time();  while ( time()-t<duration )    yield;}void flythrough(){  // control camera through level}void show_text(text,duration){  // draw text on screen for duration with fadein and fadeout}void intro(){  spawn flythrough();  fade(0,1,2.0);  wait(2.0);  spawn show_text("Credit #1",1.0);  wait(2.0);  spawn show_text("Credit #2",1.0);  wait(5.0);  fade(1,0,2.0);}


So the idea is that you have yield, which is essentially a SUSPEND bytecode as a keyword, and spawn, which takes a function plus arguments and creates a new context for it (which will be destroyed when it returns) and adds it to the list of threads.

Each frame, each active thread is run until it yields (that is, there are no SUSPEND opcodes anywhere except for yield).

Anyway, this has proven to be extremely powerful scripting system for us, thus its long life. It could probably be added into AngelScript without too much trouble, maybe as an #ifdefed optional feature or an addon or something.

-Wade

[edited by - wade182 on April 26, 2004 3:31:01 AM]

[edited by - wade182 on April 26, 2004 3:32:13 AM]
Thanks for the info wade182.

In AngelScript you can write your own yield statement by declaring a system function like this:

void YieldContext(){  asIContext *ctx = GetActiveContext();  ctx->Suspend();} 


engine->RegisterGlobalFunction("void Yield();", asFUNCTION(YieldContext), asCALL_CDECL);

A spawn statement would be created similarly, and would tell the host application to create a new context with the parameters sent to it. With AngelScript it requires more work from the host application to get coroutines going, but it is definitely supported.

In either case I''ll see what I can do about supporting it natively in the AngelScript.

__________________________________________________________
www.AngelCode.com - game development and more...
AngelScript - free scripting library - Tower - free puzzle game

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