]> git.jsancho.org Git - gacela.git/blobdiff - src/gacela.scm
Now yes, we have views.
[gacela.git] / src / gacela.scm
index 63d6bd3e6992ea3d5703671faf90a699d80c385c..8fa9f52faac1994ee591856dcb6455bd888f22fd 100644 (file)
@@ -18,6 +18,7 @@
 (define-module (gacela gacela)
   #:use-module (gacela events)
   #:use-module (gacela video)
+  #:use-module ((gacela video) #:renamer (symbol-prefix-proc 'video:))
   #:use-module (gacela audio)
   #:use-module (ice-9 optargs)
   #:export (*title*
@@ -33,7 +34,6 @@
            game-loop
            gacela-script
            game-running?
-           set-game-code
            show-mob-hash
            hide-mob-hash
            get-active-mobs
@@ -58,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-views)
                (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 active-views (make-hash-table))
+
+(define* (draw-views #:optional (views (hash-map->list (lambda (k v) v) active-views)))
+  (cond ((not (null? views))
+        (catch #t
+                 (lambda* () ((car views)))
+                 (lambda (key . args) #f))
+        (draw-views (cdr views)))))
+
+;; (define-macro (define-view name content)
+;;   `(begin
+;;      (hash-set! active-views ',name (lambda () (glmatrix-block ,content)))
+;;      ',name))
+
+
+;;; Views Primitives
+
+;(define-macro (translate x y view-or-z . view)
+;  (let* ((z (if (null? view) 0 view-or-z))
+;       (view (if (null? view) view-or-z (car view))))
+;    `(begin
+;       (gltranslate ,x ,y ,z)
+;       ,view)))
+
+
+(module-map (lambda (sym var)
+             (if (not (eq? sym '%module-public-interface))
+                 (module-export! (current-module) (list sym))))
+           (current-module))