unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Clinton Ebadi <clinton@unknownlamer.org>
To: Sylvain Beucler <beuc@beuc.net>
Cc: guile-user@gnu.org
Subject: Re: Long-lived Guile scripts in a mono-threaded game engine
Date: Tue, 27 May 2008 14:19:36 -0400	[thread overview]
Message-ID: <87fxs3624n.fsf@unknownlamer.org> (raw)
In-Reply-To: <20080527161445.GB18239@perso.beuc.net> (Sylvain Beucler's message of "Tue\, 27 May 2008 18\:14\:45 +0200")

Sylvain Beucler <beuc@beuc.net> writes:

>> IOW, `say_stop' does a `(sleep 2)' (or `sleep (2)'), or waits for some
>> UI event, is that right?
> ---
>> what is the nature of the pause? (I think that that might be important.)
>> How do you interrupt the tight little say_stop sleep loop (if that's what
>> it is) when you are using C bindings?
>
> Basically, a timestamp (for 'say_stop' and 'wait') or more generally a
> goal (coordinates for 'move_stop') is attached to the script. The game
> loop, before refreshing the screen, passes on each active script and
> see if it needs to be resumed.
>
> If at a point the engine needs 3s to load a bunch of graphics and
> sounds from the disk (e.g. during a screen change), the paused script
> won't wake up during that, but instead will be awaken by the engine
> when it's done with the loading.
>
> So the script does not (sleep). In this game, the engine is a mini-OS
> with a non-preemptive process model. This is often used in games for
> efficiency and ease of debugging (no concurrency). In my case this is
> because the code was like this before I put my hands on it :)
>
> Currently when the script engine interprets 'say_stop("Hello");', it
> will set the timestamp at now+2s, save the script resume point, and
> return to the main game loop.

You are pretty much doing what call/cc does, and so could
straightforwardly rewrite the functions that cause scripts to freeze
to capture the current continuation and schedule an event to resume
this continuation when needed. So something like:

(define (say-stop message)
  (call/cc (lambda (k)
	     (%say-stop message k))))

This might be worth trying and might perform well enough, but Guile's
call/cc is fairly slow and heavyweight as it must copy the entire C
stack.

An alternative approach could use a thread per script. You'd stash the
thread you want to resume into the event, put it to sleep immediately,
and awaken it again when the event triggers. This would probably be
fairly easy to implement using condition variables. The disadvantage
here is that now every script has a thread which could become
problematic if enough scripts are loaded.

-- 
                   It's no contest, but we still race there                   
                Like the saintly tortoise and the godless hare                




  parent reply	other threads:[~2008-05-27 18:19 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-26 21:19 Long-lived Guile scripts in a mono-threaded game engine Sylvain Beucler
2008-05-27  7:58 ` Ludovic Courtès
2008-05-27  8:33   ` Sylvain Beucler
2008-05-27 13:20     ` Ludovic Courtès
2008-05-27 16:14       ` Sylvain Beucler
2008-05-27 18:08         ` Ludovic Courtès
2008-05-27 19:57           ` Sylvain Beucler
2008-05-27 20:30             ` Clinton Ebadi
2008-05-27 18:19         ` Clinton Ebadi [this message]
2008-05-27 21:49           ` Neil Jerram
2008-05-27 13:42     ` Paul Emsley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87fxs3624n.fsf@unknownlamer.org \
    --to=clinton@unknownlamer.org \
    --cc=beuc@beuc.net \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).