]> git.jsancho.org Git - gacela.git/commitdiff
New game function with its own thread.
authorJavier Sancho <jsf@jsancho.org>
Sun, 17 Jun 2012 20:01:40 +0000 (22:01 +0200)
committerJavier Sancho <jsf@jsancho.org>
Sun, 17 Jun 2012 20:01:40 +0000 (22:01 +0200)
src/gacela.scm

index cf72902541cd0c521fd79308a7c9917ce1017df4..7e96a808700204c15003647a28c6a434b9fe196d 100644 (file)
@@ -34,7 +34,6 @@
            game-loop
            gacela-script
            game-running?
-           set-game-code
            show-mob-hash
            hide-mob-hash
            get-active-mobs
@@ -59,7 +58,6 @@
 ;;; Main Loop
 
 (define loop-flag #f)
-(define game-code #f)
 (define game-loop-thread #f)
 
 (define-macro (run-in-game-loop proc)
 (run-in-game-loop resize-screen)
 
 (define-macro (game . code)
-  `(let ((game-function ,(if (null? code)
-                            `(lambda () #f)
-                            `(lambda () ,@code))))
-     (set-game-code game-function)
-     (cond ((not (game-running?))
-           (game-loop)))))
+  (if (null? code)
+      #f
+      `(call-with-new-thread (lambda () ,@code))))
 
 (define (init-gacela)
   (hide-all-mobs)
-  (set-game-code (lambda () #f))
   (cond ((not game-loop-thread)
-        (set! game-loop-thread (call-with-new-thread (lambda () (game))))))
+        (set! game-loop-thread (call-with-new-thread (lambda () (cond ((not (game-running?)) (game-loop))))))))
   (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))
 
                (clear-screen)
                (to-origin)
                (refresh-active-mobs)
-               (if (procedure? game-code)
-                   (catch #t
-                          (lambda () (game-code))
-                          (lambda (key . args) #f)))
                (run-mobs)
                (draw-bricks)
                (flip-screen)
 (define (game-running?)
   loop-flag)
 
-(define (set-game-code game-function)
-  (set! game-code game-function))
-
 
 ;;; Game Properties