X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=src%2Fgacela_mobs.scm;h=5e159075b945586567e7154096dd4386de42b53e;hb=023823491bfe1a64e136bcc2d47c6ec5803f23bf;hp=51ce54917e9a241a6d68d8ff93ec8673f10cda21;hpb=b30f9aab67a8ae786aabcc586d1aa65a06bb8bbc;p=gacela.git diff --git a/src/gacela_mobs.scm b/src/gacela_mobs.scm index 51ce549..5e15907 100755 --- a/src/gacela_mobs.scm +++ b/src/gacela_mobs.scm @@ -48,8 +48,11 @@ (define-macro (hide-mob mob) `(hide-mob-hash ',mob)) -(define (process-mobs mobs) - (for-each (lambda (m) (m #:render)) mobs)) +(define (run-mob-actions mobs) + (for-each (lambda (m) (m 'run-actions)) mobs)) + +(define (render-mobs mobs) + (for-each (lambda (m) (m 'render)) mobs)) ;;; Actions and looks for mobs @@ -62,35 +65,25 @@ (define (attr-def attr) (let ((name (car attr)) (value (cadr attr))) - `(,name (get-attr attributes ',name ,value)))) - -;; (defmacro make-behaviour (name attr &rest code) -;; `(defun ,(get-behaviour-fun-name name) (object-attr) -;; (let ,(mapcar #'attribute-definition attr) -;; ,@code -;; ,(cons 'progn (mapcar #'attribute-save (reverse attr))) -;; object-attr))) - -;; (defun get-behaviour-fun-name (name) -;; (intern (concatenate 'string "BEHAVIOUR-" (string-upcase (string name))) 'gacela)) - -;; (defun attribute-name (attribute) -;; (intern (string attribute) 'keyword)) - -;; (define (attribute-definition attribute) -;; (let* ((name (cond ((list? attribute) (car attribute)) -;; (else attribute))) -;; (pname (attribute-name name)) -;; (value (cond ((listp attribute) (cadr attribute))))) -;; `(,name (getf object-attr ,pname ,value)))) - -;; (defun attribute-save (attribute) -;; (let* ((name (cond ((listp attribute) (car attribute)) -;; (t attribute))) -;; (pname (attribute-name name))) -;; `(setf (getf object-attr ,pname) ,name))) - -(define-macro (lambda-look . look) + `(,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 @@ -106,10 +99,11 @@ (receive (look-lines look-images) (process-look look) `(let ,look-images - (lambda () - (glPushMatrix) - ,@look-lines - (glPopMatrix))))) + (lambda (attributes) + (let ,(map attr-def attr) + (glPushMatrix) + ,@look-lines + (glPopMatrix)))))) ;;; Making mobs @@ -122,7 +116,7 @@ (define-macro (lambda-mob attr . look) `(let ((mob #f)) (set! mob - (let ((attr ',attr) (actions '()) (renders '())) + (let ((attr ',attr) (actions '()) (looks '())) (lambda (option . params) (case option ((get-attr) @@ -133,11 +127,42 @@ actions) ((set-actions) (if (not (null? params)) (set! actions (car params)))) - ((get-renders) - renders) - ((set-renders) - (if (not (null? params)) (set! renders (car params)))))))) + ((get-looks) + looks) + ((set-looks) + (if (not (null? params)) (set! looks (car params)))) + ((run-actions) + (for-each + (lambda (action) + (set! attr ((cdr action) attr))) + actions)) + ((render) + (for-each + (lambda (look) + ((cdr look) attr)) + looks)))))) (cond ((not (null? ',look)) - (display ',look) - (newline))) + (mob 'set-looks + (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) + (mob 'set-actions (assoc-set! (mob 'get-actions) name action))) + +(define (quit-mob-action mob name) + (mob 'set-actions (assoc-remove! (mob 'get-actions) name))) + +(define (add-mob-look mob name look) + (mob 'set-looks (assoc-set! (mob 'get-looks) name look))) + +(define (quit-mob-look mob name) + (mob 'set-looks (assoc-remove! (mob 'get-looks) name)))