]> git.jsancho.org Git - gacela.git/blobdiff - src/gacela_mobs.scm
Publishing mob data and defining mobs events.
[gacela.git] / src / gacela_mobs.scm
index 313848c6cc7801c7ae2bbeeffc9929ea876b7895..8cca9329ec3f1041df77dc3fdf9919bc7c856adf 100755 (executable)
@@ -63,6 +63,7 @@
         `(hide-mob-hash (,mob 'get-mob-id)))))
 
 (define (run-mobs mobs)
+  (clear-mob-data)
   (for-each
    (lambda (m)
      (glPushMatrix)
           ((get-type)
            ,type-symbol)
           (else
-           (display ,(cons 'list (map (lambda (x) `(acons ',(car x) ,(car x) '())) publish)))
-           (newline)
            (catch #t
                   (lambda () ,@body)
-                  (lambda (key . args) #f))))))))
+                  (lambda (key . args) #f))
+           (cond ((not (null? ',publish))
+                  (display ,(cons 'list (map (lambda (x) `(cons ',(car x) ,(car x))) publish)))
+                  (publish-mob-data ,mob-id-symbol ,type-symbol ,(cons 'list (map (lambda (x) `(cons ',(car x) ,(car x))) publish)))))
+           (newline)))))))
 
 (define-macro (lambda-mob attr . body)
   `(the-mob 'undefined ,attr '() ,@body))
+
+
+;;; Events Engine
+
+(define publish-mob-data #f)
+(define clear-mob-data #f)
+(define def-mobs-event #f)
+
+(define published-data (make-hash-table))
+(define mobs-events (make-hash-table))
+
+(let ((nop #f))
+  (set! publish-mob-data
+       (lambda (mob-id mob-type data)
+         (let ((t (hash-ref published-data mob-type))
+               (i (cons mob-id data)))
+           (hash-set! published-data mob-type
+                      (cond (t (cons i t))
+                            (else (list i)))))))
+
+  (set! clear-mob-data
+       (lambda ()
+         (hash-clear! published-data)))
+
+  (set! def-mobs-event
+       (lambda (type1 type2 fun)
+         #f))
+)
+
+(define-macro (define-mobs-event type1 type2 . body)
+  `(def-mobs-event
+     ,type1
+     ,type2
+     ,(cond ((null? body) #f)
+           (else `(lambda () ,@body)))))