From: jsancho Date: Thu, 15 Mar 2012 15:32:21 +0000 (+0000) Subject: Adjustments for running games from emacs or shell. X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=1e23ab1af645ad52cdbb0fde99d01fa21226f1cc;p=gacela.git Adjustments for running games from emacs or shell. --- diff --git a/emacs/emacs_conf.lisp b/emacs/emacs_conf.lisp index cee867d..db027e5 100644 --- a/emacs/emacs_conf.lisp +++ b/emacs/emacs_conf.lisp @@ -1,24 +1,28 @@ -;;; Gacela configuration +;;; Guile configuration -(defun launch-gacela () +(defun launch-guile () (interactive) - (start-process "gacela" "gacela" "/home/jsancho/proyectos/gacela/trunk/src/gacela" "--dev")) + (let ((process-connection-type nil)) + (start-process "guile" "guile" "/usr/bin/guile"))) -(defun send-to-gacela () +(defun send-to-guile () (interactive) - (cond ((not (get-process "gacela")) - (launch-gacela))) - (process-send-string "gacela" "(begin ") - (cond ((use-region-p) - (process-send-region "gacela" (region-beginning) (region-end))) - (t - (process-send-string "gacela" "(run-game) (hide-all-mobs)") - (process-send-region "gacela" (point-min-marker) (point-max-marker)))) - (process-send-string "gacela" "\n)\n")) + (cond ((not (get-process "guile")) + (launch-guile))) -(define-key global-map [(ctrl x) (ctrl g)] 'send-to-gacela) + (process-send-string + "guile" + (replace-regexp-in-string + "\t" " " + (cond ((use-region-p) + (buffer-substring-no-properties (region-beginning) (region-end))) + (t + (buffer-substring-no-properties (point-min-marker) (point-max-marker))))))) -(define-key-after global-map [menu-bar tools gacela] (cons "Gacela" (make-sparse-keymap "hoot hoot")) 'games) -(define-key global-map [menu-bar tools gacela send] '("Send to Gacela" . send-to-gacela)) -(define-key global-map [menu-bar tools gacela launch] '("Launch Gacela" . launch-gacela)) + +(define-key global-map [(ctrl x) (ctrl g)] 'send-to-guile) + +(define-key-after global-map [menu-bar tools guile] (cons "Guile" (make-sparse-keymap "hoot hoot")) 'games) +(define-key global-map [menu-bar tools guile send] '("Send to Guile" . send-to-guile)) +(define-key global-map [menu-bar tools guile launch] '("Launch Guile" . launch-guile)) diff --git a/games/asteroids/asteroids.scm b/games/asteroids/asteroids.scm index 0487e32..a12c1de 100644 --- a/games/asteroids/asteroids.scm +++ b/games/asteroids/asteroids.scm @@ -1,3 +1,7 @@ +#!/usr/bin/guile \ +-e gacela-script -s +!# + (use-modules (gacela gacela) (gacela math)) (init-gacela) diff --git a/games/tetris/tetris.scm b/games/tetris/tetris.scm index d27a086..ce7e774 100644 --- a/games/tetris/tetris.scm +++ b/games/tetris/tetris.scm @@ -1,3 +1,11 @@ +#!/usr/bin/guile \ +-e gacela-script -s +!# + +(use-modules (gacela gacela) + (gacela widgets timer)) +(init-gacela) + (set-game-properties! #:title "Gacela Tetris" #:fps 15) (define (tetramine-i) @@ -119,7 +127,7 @@ (set! points (+ points (* (more-lines-better l) 10))) (set! lines (+ lines l))))) -(define game #f) +(define game-func #f) (define display-game-over #f) (define tetramine #f) @@ -131,7 +139,7 @@ (font (load-font "lazy.ttf" #:size 20)) (game-over #f)) - (set! game + (set! game-func (lambda () (if game-over (display-game-over) (tetramine)))) @@ -183,8 +191,8 @@ (let ((frame 0.0) (fps (make-timer)) (update (make-timer))) (start-timer update) (start-timer fps) - (run-game - (game) + (game + (game-func) (set! frame (+ frame 1)) (cond ((> (get-time update) 1000) (display (/ frame (/ (get-time fps) 1000.0))) diff --git a/src/gacela.scm b/src/gacela.scm index e3bead6..d027cfa 100644 --- a/src/gacela.scm +++ b/src/gacela.scm @@ -33,6 +33,7 @@ init-gacela quit-gacela game-loop + gacela-script game-running? set-game-code show-mob-hash @@ -146,11 +147,16 @@ (game-loop))))) (define (init-gacela) - (set! game-loop-thread (call-with-new-thread (lambda () (game)))) + (hide-all-mobs) + (set-game-code (lambda () #f)) + (cond ((not game-loop-thread) + (set! game-loop-thread (call-with-new-thread (lambda () (game)))))) (while (not loop-flag)) #t) (define (quit-gacela) + (hide-all-mobs) + (set-game-code (lambda () #f)) (set! game-loop-thread #f) (set! loop-flag #f)) @@ -177,6 +183,9 @@ (delay-frame)))) (quit-video)) +(define (gacela-script args) + (while loop-flag (sleep 1))) + (define (game-running?) loop-flag)