From: jsancho Date: Sun, 5 Jun 2011 12:16:38 +0000 (+0000) Subject: (no commit message) X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=23dc2e79bfa98af475cafe3754f85c94949a4e8c;p=gacela.git --- diff --git a/src/gacela_loader.scm b/src/gacela_loader.scm index b44169a..183df1d 100644 --- a/src/gacela_loader.scm +++ b/src/gacela_loader.scm @@ -20,3 +20,4 @@ (primitive-load-path "gacela_draw.scm") (primitive-load-path "gacela_ttf.scm") (primitive-load-path "gacela_mobs.scm") +(primitive-load-path "gacela_misc.scm") diff --git a/src/gacela_misc.scm b/src/gacela_misc.scm index d486b26..42c8841 100644 --- a/src/gacela_misc.scm +++ b/src/gacela_misc.scm @@ -15,6 +15,14 @@ ;;; along with this program. If not, see . + +;;; Additional modules + +(use-modules (srfi srfi-1)) + + +;;; Functions + (define (nearest-power-of-two n) (define (power p n) (cond ((> (* p 2) n) p) diff --git a/src/gacela_mobs.scm b/src/gacela_mobs.scm index d273556..3f7fb74 100755 --- a/src/gacela_mobs.scm +++ b/src/gacela_mobs.scm @@ -17,36 +17,33 @@ ;;; Mobs Factory -(define-macro (hash-add-mob hash-table mob) - `(hash-set! ,hash-table (procedure-name ,mob) (lambda () (,mob)))) - -(define-macro (hash-remove-mob hash-table mob) - `(hash-remove! ,hash-table (procedure-name ,mob))) - - (define add-mob #f) (define kill-mob #f) -(define get-mob-world #f) -(define mobs #f) -(define vreload #f) +(define get-active-mobs #f) +(define reload-mobs? #f) +(define reload-mobs #f) -(let ((active-mobs (make-hash-table)) (reload #f)) +(let ((active-mobs '(m1 m2)) (reload #f)) (set! add-mob (lambda (mob) - (hash-add-mob active-mobs mob) + (pushnew (procedure-name mob) active-mobs) (set! reload #t))) (set! kill-mob (lambda (mob) - (hash-remove-mob active-mobs mob) + (set! active-mobs (lset-difference eq? active-mobs (list (procedure-name mob)))) (set! reload #t))) - (set! get-mob-world + (set! get-active-mobs + (lambda () active-mobs)) + + (set! reload-mobs? + (lambda () reload)) + + (set! reload-mobs (lambda () - (cond (reload - (set! reload #f) - (hash-map->list (lambda (k v) v) active-mobs)) - (else #f)))) + #f))) - (set! mobs (lambda () active-mobs)) - (set! vreload (lambda () reload))) +(define-macro (get-mobs-function) + (let ((mobs (get-active-mobs))) + `(lambda () ,@(map (lambda (mob) `(,mob)) ,mobs))))