]> git.jsancho.org Git - gacela.git/blobdiff - src/gacela.scm
Limit to re-exports (a game must load all modules it needs).
[gacela.git] / src / gacela.scm
index d027cfa37b8c360bbfcdeb28d97a74f979a3d974..9be50b087b342f8d694503c05fc8fcf804d6d658 100644 (file)
                   define-mob
                   lambda-mob
                   define-checking-mobs)
-  #:re-export (get-current-color
-              set-current-color
-              with-color
-              progn-textures
-              draw
-              draw-texture
-              draw-line
-              draw-quad
-              draw-rectangle
-              draw-square
-              draw-cube
-              translate
-              rotate
-              to-origin
-              add-light
-              set-camera
-              camera-look
-              render-text
+  #:re-export (translate
               get-frame-time
-              key?
-              key-pressed?
-              key-released?
               3d-mode?))
 
 
 
 (define current-mob-id #f)
 
+(define translate-mob translate)
+
 (define (get-current-mob-id)
   current-mob-id)
 
           (hash-set! mob-functions mob-name name)))
     name))
 
-(define-macro (the-mob type init-data fun-name)
+(define-macro (the-mob mob-name init-data)
   `(let ((mob-id (gensym))
         (mob-z-index 0)
         (mob-time 0)
         ((get-z-index)
          mob-z-index)
         ((get-type)
-         ,type)
+         (procedure-name ,mob-name))
         ((get-data)
          (save-data)
          saved-data)
         (else
-         (save-data)
-         (let ((res (,fun-name mob-id mob-data)))
-           (set! mob-z-index (car res))
-           (set! mob-data (cadr res))))))))
-
-(define-macro (define-mob-function head . body)
-  (let ((fun-name (car head))
-       (attr (map (lambda (a) (if (list? a) a (list a #f))) (cdr head)))
+         (cond ((keyword? option)
+                (assoc-ref saved-data (keyword->symbol option)))
+               (else
+                (save-data)
+                (let ((res (,mob-name mob-id mob-data)))
+                  (set! mob-z-index (car res))
+                  (set! mob-data (cadr res))))))))))
+
+(define-macro (define-mob-function attr . body)
+  (let ((attr (map (lambda (a) (if (list? a) a (list a #f))) attr))
        (mob-id-symbol (gensym))
        (mob-id-z-index (gensym))
        (data-symbol (gensym)))
-    `(define (,fun-name ,mob-id-symbol ,data-symbol)
+    `(lambda (,mob-id-symbol ,data-symbol)
        (let ((,mob-id-z-index 0))
         (define (kill-me)
           (hide-mob-hash ,mob-id-symbol))
                 (else
                  (set! ,mob-id-z-index (+ ,mob-id-z-index z))
                  (translate-mob x y))))
-        (let ,attr
+        (let* ,attr
           ,@(map
              (lambda (a)
                `(let ((val (assoc-ref ,data-symbol ',(car a))))
           (list ,mob-id-z-index (list ,@(map (lambda (a) `(cons ',(car a) ,(car a))) attr))))))))
 
 (define-macro (define-mob mob-head . body)
-  (let* ((name (car mob-head)) (attr (cdr mob-head))
-        (fun-name (get-mob-function-name name)))
-    `(begin
-       (define-mob-function ,(cons fun-name attr) ,@body)
-       (define ,(string->symbol (string-concatenate (list "make-" (symbol->string name))))
+  (let* ((name (car mob-head))
+        (attr (cdr mob-head))
+        (make-fun-symbol (gensym))
+        (mob-fun-symbol (gensym))
+        (params-symbol (gensym)))
+    `(define (,name . ,params-symbol)
+       (define ,make-fun-symbol
         (lambda* ,(if (null? attr) '() `(#:key ,@attr))
-          (the-mob ',name (list ,@(map (lambda (a) `(cons ',(car a) ,(car a))) attr)) ,fun-name))))))
+          (the-mob ,name (list ,@(map (lambda (a) `(cons ',(car a) ,(car a))) attr)))))
+       (define ,mob-fun-symbol
+        (define-mob-function ,attr ,@body))
+       (cond ((or (null? ,params-symbol) (keyword? (car ,params-symbol)))
+             (apply ,make-fun-symbol ,params-symbol))
+            (else
+             (apply ,mob-fun-symbol ,params-symbol))))))
 
 (define-macro (lambda-mob attr . body)
   (let ((fun-name (gensym)))
 
 ;;; Functions for checking mobs (collisions and more)
 
-(define translate-mob translate)
-
 (define (map-mobs fun type)
   (let ((mobs (filter (lambda (m) (and (eq? (m 'get-type) type) (not (eq? (m 'get-mob-id) (get-current-mob-id))))) (get-active-mobs))))
     (map (lambda (m) (fun (m 'get-data))) mobs)))
          (let ,(map (lambda (a) `(,(car a) (assoc-ref m ',(cadr a)))) attr)
            ,@body))
        ',type))))
+
+
+;;; Scenes
+
+(define-macro (define-scene name . body)
+  `(define (,name)
+     ,@body))