guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Long-lived Guile scripts in a mono-threaded game engine


From: Ludovic Courtès
Subject: Re: Long-lived Guile scripts in a mono-threaded game engine
Date: Tue, 27 May 2008 15:20:55 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux)

Salut,

Sylvain Beucler <address@hidden> writes:

> Here's a sample script (very close to the C bindings, for a start):
>
> (define (hit)
>   (if (> (sp_gethitpoints (current_sprite)) 10)
>     (begin
>       (sp_sethitpoints (current_sprite) (- (sp_hitpoints (current_sprite)) 
> 10))
>       (dialog1))
>     (begin
>       (say_stop "ARRRRrr.." (current_sprite))
>       (sp_kill (current_sprite) 0)
>       (say_stop "Uh, I was supposed to protect him, not kill him!" 1)))
>   (set_honour! (- (get_honour) 1)))
>
> (define (dialog1)
>   (say_stop "Why are you hitting me, player?" (current_sprite))
>   (say_stop "Uh, sorry I won't do that again" 1))
>
>
> Now every time we see a (say_stop), the script will pause for 2
> seconds, so the player can read the text.

IOW, `say_stop' does a `(sleep 2)' (or `sleep (2)'), or waits for some
UI event, is that right?

> If I use CPS, this means I'll have to rewrite all my scripts in CPS
> style.

Yes, but you said this was work-in-progress, so I suppose there's no
backward compatibility concern.  ;-)

> This would be pretty cumbersome. This is supposed to introduce
> people to the beautiful world of scheme, not scare them to death ;)

Well, it's not necessarily that scary, and it depends on how often you'd
have to use it.

> call/cc has another issue: how do I return? Let's say I'm in the
> middle of (dialog1) and I need to stop the script. Maybe with a set of
> double continuations: one continuation at the top level to return to
> the point before I called the initial procedure (which would stops the
> script); and another one that is set at each (say_stop) to return to
> the following line (to resume the script).

Yes, something like that: a continuation to invoke the "scheduler" (the
engine), which would be passed the continuation within `dialog1' that
needs to be resumed eventually.

> Hopefully this is not as inefficient as you suggested.

Depends on how often (and when) you do it, but expect it to be
inefficient as it copies the stack (see the "Continuations" node in the
manual).

It may actually be simpler to run the Scheme code in a separate POSIX
thread, and have it woken up by the engine when it should start working.

Thanks,
Ludovic.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]