From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: ludo@gnu.org (Ludovic =?iso-8859-1?Q?Court=E8s?=) Newsgroups: gmane.lisp.guile.user Subject: Re: Long-lived Guile scripts in a mono-threaded game engine Date: Tue, 27 May 2008 15:20:55 +0200 Message-ID: <87hccjnars.fsf@gnu.org> References: <20080526211900.GB14261@perso.beuc.net> <87fxs4yy89.fsf@gnu.org> <20080527083324.GA16693@perso.beuc.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1211894567 31697 80.91.229.12 (27 May 2008 13:22:47 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 27 May 2008 13:22:47 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Tue May 27 15:23:27 2008 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1K0z7l-0003sI-Q7 for guile-user@m.gmane.org; Tue, 27 May 2008 15:21:58 +0200 Original-Received: from localhost ([127.0.0.1]:38543 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K0z70-0007ng-Fv for guile-user@m.gmane.org; Tue, 27 May 2008 09:21:10 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1K0z6w-0007nR-Bf for guile-user@gnu.org; Tue, 27 May 2008 09:21:06 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1K0z6v-0007nF-Uw for guile-user@gnu.org; Tue, 27 May 2008 09:21:06 -0400 Original-Received: from [199.232.76.173] (port=43921 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K0z6v-0007nC-PS for guile-user@gnu.org; Tue, 27 May 2008 09:21:05 -0400 Original-Received: from main.gmane.org ([80.91.229.2]:52379 helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1K0z6v-0000ON-J9 for guile-user@gnu.org; Tue, 27 May 2008 09:21:05 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1K0z6t-0003PG-9v for guile-user@gnu.org; Tue, 27 May 2008 13:21:03 +0000 Original-Received: from 193.50.110.184 ([193.50.110.184]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 27 May 2008 13:21:03 +0000 Original-Received: from ludo by 193.50.110.184 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 27 May 2008 13:21:03 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 62 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 193.50.110.184 X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 9 Prairial an 216 de la =?iso-8859-1?Q?R=E9volution?= X-PGP-Key-ID: 0xEA52ECF4 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 821D 815D 902A 7EAB 5CEE D120 7FBA 3D4F EB1F 5364 X-OS: i686-pc-linux-gnu User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) Cancel-Lock: sha1:W6SzzX0Ar/HA+Fugd1Xw57gDxlU= X-detected-kernel: by monty-python.gnu.org: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:6578 Archived-At: Salut, Sylvain Beucler 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.