]> git.jsancho.org Git - gacela.git/blobdiff - src/gacela_mobs.scm
(no commit message)
[gacela.git] / src / gacela_mobs.scm
index 69f702f409d8c8e4ae86cf5675ec362d1c6b0e74..ca4d5d37c08d00fb7825fd9ecf9c6559c530eea1 100755 (executable)
@@ -20,6 +20,7 @@
 (define show-mob-hash #f)
 (define hide-mob-hash #f)
 (define get-active-mobs #f)
+(define clear-active-mobs #f)
 (define mobs-changed? #f)
 
 (let ((active-mobs (make-hash-table)) (changed #f))
          (set! changed (not refreshed))
          (hash-map->list (lambda (k v) v) active-mobs)))
 
+  (set! clear-active-mobs
+       (lambda ()
+         (set! changed #t)
+         (hash-clear! active-mobs)))
+
   (set! mobs-changed?
        (lambda () changed)))
 
 
 (define-macro (show-mob mob)
-  `(show-mob-hash ',mob (lambda (option) (,mob option))))
+  (cond ((list? mob)
+        `(let ((m ,mob))
+           (show-mob-hash (m 'get-mob-id) m)))
+       (else
+        `(show-mob-hash (,mob 'get-mob-id) (lambda () (,mob))))))
 
 (define-macro (hide-mob mob)
-  `(hide-mob-hash ',mob))
-
-(define (process-mobs mobs)
-  (for-each (lambda (m) (m #:render)) mobs))
-
-
-;;; Actions and looks for mobs
-
-(define (get-attr list name default)
-  (let ((value (assoc-ref list name)))
-    (cond (value (car value))
-         (else default))))
-
-(define (attr-def attr)
-  (let ((name (car attr))
-       (value (cadr attr)))
-    `(,name (get-attr attributes ',name ',value))))
-
-(define (attr-save attr)
-  (let ((name (car attr)))
-    `(set! attributes (assoc-set! attributes ',name (list ,name)))))
-
-(define-macro (define-action action-head . code)
-  (let ((name (car action-head)) (attr (cdr action-head)))
-    `(define ,name
-       (lambda-action ,attr ,@code))))
-
-(define-macro (lambda-action attr . code)
-  `(lambda (attributes)
-     (let ,(map attr-def attr)
-       ,@code
-       ,(cons 'begin (map attr-save attr))
-       attributes)))
-
-(define-macro (lambda-look attr . look)
-  (define (process-look look)
-    (cond ((null? look) (values '() '()))
-         (else
-          (let ((line (car look)))
-            (receive (lines images) (process-look (cdr look))
-                     (cond ((string? line)
-                            (let ((var (gensym)))
-                              (values (cons `(draw-texture ,var) lines)
-                                      (cons `(,var (load-texture ,line)) images))))
-                           (else
-                            (values (cons line lines)
-                                    images))))))))
-
-  (receive (look-lines look-images) (process-look look)
-          `(let ,look-images
-               (lambda (attributes)
-                 (let ,(map attr-def attr)
-                   (glPushMatrix)
-                   ,@look-lines
-                   (glPopMatrix))))))
+  (cond ((list? mob)
+        `(let ((m ,mob))
+           (hide-mob-hash (m 'get-mob-id) m)))
+       (else
+        `(hide-mob-hash (,mob 'get-mob-id) (lambda () (,mob))))))
+
+(define-macro (kill-me)
+  `(hide-mob-hash mob-id))
+
+(define (run-mobs mobs)
+  (for-each
+   (lambda (m)
+     (glPushMatrix)
+     (m)
+     (glPopMatrix))
+   mobs))
 
 
 ;;; Making mobs
 
-(define-macro (define-mob mob-head . look)
+(define-macro (define-mob mob-head . body)
   (let ((name (car mob-head)) (attr (cdr mob-head)))
-    `(define ,name
-       (lambda-mob ,attr ,@look))))
-
-(define-macro (lambda-mob attr . look)
-  `(let ((mob #f))
-     (set! mob
-          (let ((attr ',attr) (actions '()) (renders '()))
-            (lambda (option . params)
-              (case option
-                ((get-attr)
-                 attr)
-                ((set-attr)
-                 (if (not (null? params)) (set! attr (car params))))
-                ((get-actions)
-                 actions)
-                ((set-actions)
-                 (if (not (null? params)) (set! actions (car params))))
-                ((get-renders)
-                 renders)
-                ((set-renders)
-                 (if (not (null? params)) (set! renders (car params))))
-                ((actions)
-                 (for-each
-                  (lambda (action)
-                    (set! attr ((cdr action) attr)))
-                  actions))
-                ((render)
-                 (for-each
-                  (lambda (render)
-                    ((cdr render) attr))
-                  renders))))))
-     (cond ((not (null? ',look))
-           (mob 'set-renders
-                (list (cons
-                       'default-look
-                       (lambda-look ,attr ,@look))))))
-     mob))
-
-(define (get-mob-attr mob var)
-  (let ((value (assoc-ref (mob 'get-attr) var)))
-    (if value (car value) #f)))
-
-(define (set-mob-attr! mob var value)
-  (mob 'set-attr (assoc-set! (mob 'get-attr) var (list value))))
-
-(define (add-mob-action mob name action)
-  )
+    `(define ,(string->symbol (string-concatenate (list "make-" (symbol->string name))))
+       (lambda* (#:key ,@attr)
+        (lambda-mob () ,@body)))))
+
+(define-macro (lambda-mob attr . body)
+  `(let ,(cons '(mob-id (gensym)) attr)
+     (lambda* (#:optional (option #f))
+       (case option
+        ((get-mob-id)
+         mob-id)
+        (else
+         (catch #t
+                (lambda () ,@body)
+                (lambda (key . args) #f)))))))