-(define-macro (the-mob type attr publish fun-name)
- (let ((mob-id-symbol (gensym))
- (type-symbol (gensym))
- (time-symbol (gensym))
- (data-symbol (gensym)))
- `(let ((,mob-id-symbol (gensym))
- (,type-symbol ,type)
- (,time-symbol 0)
- (,data-symbol '())
- ,@attr)
- (lambda* (#:optional (option #f))
- (define (kill-me)
- (hide-mob-hash ,mob-id-symbol))
- (define (save-data)
- (let ((time (get-frame-time)))
- (cond ((not (= time ,time-symbol))
- (set! ,time-symbol time)
- (set! ,data-symbol ,(cons 'list (map (lambda (x) `(cons ',(car x) ,(car x))) publish)))))))
- (define (get-data)
- ,data-symbol)
- (define (filter-mobs type fun)
- #t)
- (define (map-mobs fun type)
- (let ((mobs (filter (lambda (m) (and (eq? (m 'get-type) type) (not (eq? (m 'get-mob-id) ,mob-id-symbol)))) (get-active-mobs))))
- (map (lambda (m) (fun (m 'get-data))) mobs)))
- (case option
- ((get-mob-id)
- ,mob-id-symbol)
- ((get-type)
- ,type-symbol)
- ((get-data)
- (save-data)
- ,data-symbol)
- (else
- (save-data)
- (,fun-name 123)))))))
+(define-macro (the-mob type init-data fun-name)
+ `(let ((mob-id (gensym))
+ (mob-time 0)
+ (mob-data ,init-data)
+ (saved-data ,init-data))
+ (lambda* (#:optional (option #f))
+ (define (save-data)
+ (let ((time (get-frame-time)))
+ (cond ((not (= time mob-time))
+ (set! mob-time time)
+ (set! saved-data mob-data)))))
+; (define (filter-mobs type fun)
+; #t)
+; (define (map-mobs fun type)
+; (let ((mobs (filter (lambda (m) (and (eq? (m 'get-type) type) (not (eq? (m 'get-mob-id) ,mob-id-symbol)))) (get-active-mobs))))
+; (map (lambda (m) (fun (m 'get-data))) mobs)))
+ (case option
+ ((get-mob-id)
+ mob-id)
+ ((get-type)
+ ,type)
+ ((get-data)
+ (save-data)
+ saved-data)
+ (else
+ (save-data)
+ (set! mob-data (,fun-name mob-id mob-data)))))))