From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Sylvain Beucler Newsgroups: gmane.lisp.guile.user Subject: Long-lived Guile scripts in a mono-threaded game engine Date: Mon, 26 May 2008 23:19:00 +0200 Message-ID: <20080526211900.GB14261@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 1211836768 1876 80.91.229.12 (26 May 2008 21:19:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 26 May 2008 21:19:28 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Mon May 26 23:20:08 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 1K0k6l-0003Cu-Ox for guile-user@m.gmane.org; Mon, 26 May 2008 23:19:56 +0200 Original-Received: from localhost ([127.0.0.1]:53408 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K0k60-000853-LO for guile-user@m.gmane.org; Mon, 26 May 2008 17:19:08 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1K0k5w-00084v-Iq for guile-user@gnu.org; Mon, 26 May 2008 17:19:04 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1K0k5u-00084P-Uf for guile-user@gnu.org; Mon, 26 May 2008 17:19:04 -0400 Original-Received: from [199.232.76.173] (port=51957 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K0k5u-00084I-Ob for guile-user@gnu.org; Mon, 26 May 2008 17:19:02 -0400 Original-Received: from smtp3-g19.free.fr ([212.27.42.29]:46311) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1K0k5u-0003cZ-9U for guile-user@gnu.org; Mon, 26 May 2008 17:19:02 -0400 Original-Received: from smtp3-g19.free.fr (localhost.localdomain [127.0.0.1]) by smtp3-g19.free.fr (Postfix) with ESMTP id 7D8B317B571 for ; Mon, 26 May 2008 23:19:01 +0200 (CEST) Original-Received: from localhost.localdomain (unknown [82.238.35.175]) by smtp3-g19.free.fr (Postfix) with ESMTP id 5C9CE17B59B for ; Mon, 26 May 2008 23:19:01 +0200 (CEST) Original-Received: from me by localhost.localdomain with local (Exim 4.69) (envelope-from ) id 1K0k5s-0003lg-UH for guile-user@gnu.org; Mon, 26 May 2008 23:19:00 +0200 Content-Disposition: inline X-Operating-System: GNU/Linux User-Agent: Mutt/1.5.17+20080114 (2008-01-14) X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) 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:6573 Archived-At: i, I'm contemplating adding Guile support in GNU FreeDink, which is a game engine for Dink Smallwood, a 2D scripted game. Currently there's a "manually coded" scripting engine which is pretty limited and buggy, though it works decently enough and was already used for large extensions. I'd like to add Guile as an alternative :) Currently I'm facing several issues, the main one is how to manage long-lived scripts: The engine runs in a single thread, and the game loop essentially: - passes over all sprites in a screen, and runs the scripts attached to those sprites - detect collisions and run associated scripted hooks - perform other non-scripted transformations such as sprite progressive moves, update the status bar, etc. - the game screen is then refreshed with the new game state - repeat 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). I guess one possibility is to run all scripts as independent threads, and make them lock on a global mutex. However, as emphasized in this article http://harkal.sylphis3d.com/2005/08/10/multithreaded-game-scripting-with-stackless-python/ I would appreciate non-preemtiveness, for simplicity. I think what I'm looking for is similar to Lua's coroutines (a.k.a. fake threads - one coroutine at a time) http://lua-users.org/wiki/CoroutinesTutorial It's also important that running scripts can be terminated by the game engine if need be. How would you do this with Guile? :) Thanks, -- Sylvain