[Top][All Lists]
[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 09:58:46 +0200 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) |
Hi Sylvain,
Sylvain Beucler <address@hidden> writes:
> I'm contemplating adding Guile support in GNU FreeDink, which is a
> game engine for Dink Smallwood, a 2D scripted game.
Nice. :-)
> Scripts last more than a single game loop. They are not basic scripts
> that describe what happens in a single engine step; instead they
> describe what happens in the story.
>
> For example, a game introduction will create sprites on the screen,
> move them around, make them say lines that the user can read (or pass
> using [space]), etc.
>
> That script can also change the current screen (which kills all other
> scripts in the current script).
>
> Multiple scripts can run in a single screen, but they run the one
> after the other, not in parallel. The order/priority is known.
>
> Scripting is essentially frozen during the screen refresh. This avoids
> putting mutexes everywhere.
>
>
>
>
> How could I do something similar with Guile? I didn't find a way to
> make a guile script pause (and return to the caller).
IIUC, "scripts" are only invoked via hooks, e.g., the engine wants to
ask them to do something specific. If that is the case, it suffices to
not invoke the script.
Surely you can implement coroutine-like behavior, either using `call/cc'
(but that is going to be prohibitively expensive), or using explicit
continuation-passing style or similar. For instance, when a hook is
called by the engine, it would systematically return a thunk (a
zero-argument procedure) that the engine would later invoke. Example:
(define (my-hook action)
(let ((stuff (do-some-computation action)))
(lambda ()
;; This will be executed at some later point, when the engine
;; feels like invoking it.
(do-the-remaining-computation stuff))))
Does this help?
Thanks,
Ludovic.
- Long-lived Guile scripts in a mono-threaded game engine, Sylvain Beucler, 2008/05/26
- Re: Long-lived Guile scripts in a mono-threaded game engine,
Ludovic Courtès <=
- Re: Long-lived Guile scripts in a mono-threaded game engine, Sylvain Beucler, 2008/05/27
- Re: Long-lived Guile scripts in a mono-threaded game engine, Ludovic Courtès, 2008/05/27
- Re: Long-lived Guile scripts in a mono-threaded game engine, Sylvain Beucler, 2008/05/27
- Re: Long-lived Guile scripts in a mono-threaded game engine, Ludovic Courtès, 2008/05/27
- Re: Long-lived Guile scripts in a mono-threaded game engine, Sylvain Beucler, 2008/05/27
- Re: Long-lived Guile scripts in a mono-threaded game engine, Clinton Ebadi, 2008/05/27
- Re: Long-lived Guile scripts in a mono-threaded game engine, Clinton Ebadi, 2008/05/27
- Re: Long-lived Guile scripts in a mono-threaded game engine, Neil Jerram, 2008/05/27
- Re: Long-lived Guile scripts in a mono-threaded game engine, Paul Emsley, 2008/05/27