+(define-macro (show-mob mob)
+ `(show-mob-hash ',mob (lambda (option) (,mob option))))
+
+(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)))
+ `(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 . 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)))))
+
+
+;;; Making mobs
+
+(define-macro (define-mob mob-head . look)
+ (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))))))))
+ (cond ((not (null? ',look))
+ (display ',look)
+ (newline)))
+ mob))