]> git.jsancho.org Git - gacela.git/blobdiff - src/gacela.scm
Properties for meshes.
[gacela.git] / src / gacela.scm
index 63d6bd3e6992ea3d5703671faf90a699d80c385c..70ac867c2b995108b5ed2a188f043d173c6c84dd 100644 (file)
@@ -33,7 +33,6 @@
            game-loop
            gacela-script
            game-running?
-           set-game-code
            show-mob-hash
            hide-mob-hash
            get-active-mobs
@@ -58,7 +57,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-meshes)
                (flip-screen)
                (delay-frame))))
   (quit-video))
 (define (game-running?)
   loop-flag)
 
-(define (set-game-code game-function)
-  (set! game-code game-function))
-
 
 ;;; Game Properties
 
 (define-macro (define-scene name . body)
   `(define (,name)
      ,@body))
+
+
+;;; Views Factory
+
+(define default-view (make-hash-table))
+
+(define* (draw-meshes #:optional (meshes (hash-map->list (lambda (k v) v) default-view)))
+  (cond ((not (null? meshes))
+        (catch #t
+                 (lambda () ((car meshes) 'draw))
+                 (lambda (key . args) #f))
+        (draw-meshes (cdr meshes)))))
+
+
+(module-map (lambda (sym var)
+             (if (not (eq? sym '%module-public-interface))
+                 (module-export! (current-module) (list sym))))
+           (current-module))