Jump to content

  • Log In with Google      Sign In   
  • Create Account


- - - - -

Suggestions for future AngelScript features


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
24 replies to this topic

#21 Andreas Jonsson   Moderators   -  Reputation: 3061

Like
Likes
Like

Posted 19 April 2004 - 05:27 AM

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

Sponsor:

#22 leblebi   Members   -  Reputation: 124

Like
Likes
Like

Posted 23 April 2004 - 11:15 AM

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.



#23 Andreas Jonsson   Moderators   -  Reputation: 3061

Like
Likes
Like

Posted 24 April 2004 - 10:25 AM

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

#24 wade182   Members   -  Reputation: 122

Like
Likes
Like

Posted 25 April 2004 - 08:25 PM

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]

#25 Andreas Jonsson   Moderators   -  Reputation: 3061

Like
Likes
Like

Posted 26 April 2004 - 02:24 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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS