X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=src%2Fgacela_mobs.scm;h=e0e2edd8ba5f7c718b7b6807a6354a98f2faec9e;hb=ca3edcecf937f854c1b5d9eeac566d85dc749cd0;hp=8120e0369b649f089e7508dcdb83a5e3adbd2f5f;hpb=03149b3e627438a3dd317e62aba2befce52cc324;p=gacela.git diff --git a/src/gacela_mobs.scm b/src/gacela_mobs.scm index 8120e03..e0e2edd 100755 --- a/src/gacela_mobs.scm +++ b/src/gacela_mobs.scm @@ -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)) @@ -38,56 +39,49 @@ (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)) - -(define-macro (lambda-look . 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 () - (glPushMatrix) - ,@look-lines - (glPopMatrix))))) - -(define-macro (define-mob mob-head . look) +(define (run-mobs mobs) + (for-each + (lambda (m) + (glPushMatrix) + (m) + (glPopMatrix)) + mobs)) + + +;;; Making mobs + +(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)))))))) - (cond ((not (null? ',look)) - (display ',look) - (newline))) - mob)) + `(define ,(string->symbol (string-concatenate (list "make-" (symbol->string name)))) + (lambda () + (lambda-mob ,attr ,@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)))))))