From: jsancho Date: Sun, 12 Jun 2011 08:04:12 +0000 (+0000) Subject: (no commit message) X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=b82a1140db7d69b576d6b625c4932d66123a36fd;p=gacela.git --- diff --git a/src/gacela.scm b/src/gacela.scm index 6be5ee8..248f183 100644 --- a/src/gacela.scm +++ b/src/gacela.scm @@ -220,9 +220,10 @@ (define game-running? #f) (define set-game-code #f) -(let ((running #f) (game-code #f) (mobs-function (lambda () #f))) +(let ((running #f) (game-code #f) (mobs '())) (set! game-loop (lambda () + (set! mobs (get-active-mobs)) (set! running #t) (quit? #f) (do () ((quit?)) @@ -233,11 +234,9 @@ (cond ((not (quit?)) (glClear (+ GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT)) (to-origin) - (cond ((reload-mobs?) - (set! mobs-function (get-mobs-function)) - (mobs-reloaded))) + (cond ((mobs-changed?) (set! mobs (get-active-mobs)))) (if (procedure? game-code) (game-code)) - (mobs-function) + (process-mobs mobs) (SDL_GL_SwapBuffers) (delay-frame)))) (set! running #f))) diff --git a/src/gacela_events.scm b/src/gacela_events.scm index a57e9a1..cd93985 100644 --- a/src/gacela_events.scm +++ b/src/gacela_events.scm @@ -45,7 +45,7 @@ (cond ((not (null? events)) (let ((event (car events))) (cond ((= (assoc-ref event 'type) SDL_KEYDOWN) (key-press (assoc-ref event 'key.keysym.sym))) - ((= (assoc-ref event 'type) SDL_KEYUP) (key-release (assoc-ref event :key.keysym.sym))))) + ((= (assoc-ref event 'type) SDL_KEYUP) (key-release (assoc-ref event 'key.keysym.sym))))) (process-keyboard-events (cdr events))))) (define key? #f) diff --git a/src/gacela_mobs.scm b/src/gacela_mobs.scm index 3e3e17a..de76938 100755 --- a/src/gacela_mobs.scm +++ b/src/gacela_mobs.scm @@ -17,44 +17,39 @@ ;;; Mobs Factory -(define add-mob-symbol #f) +(define add-mob-lambda #f) (define kill-mob-symbol #f) (define get-active-mobs #f) -(define reload-mobs? #f) -(define mobs-reloaded #f) +(define mobs-changed? #f) -(let ((active-mobs '()) (reload #f)) - (set! add-mob-symbol +(let ((active-mobs '()) (changed #f)) + (set! add-mob-lambda (lambda (mob) (pushnew mob active-mobs) - (set! reload #t))) + (set! changed #t))) (set! kill-mob-symbol (lambda (mob) (set! active-mobs (lset-difference eq? active-mobs (list mob))) - (set! reload #t))) + (set! changed #t))) (set! get-active-mobs - (lambda () active-mobs)) + (lambda* (#:optional (refreshed #t)) + (set! changed (not refreshed)) + active-mobs)) - (set! reload-mobs? - (lambda () reload)) + (set! mobs-changed? + (lambda () changed))) - (set! mobs-reloaded - (lambda () (set! reload #f)))) (define-macro (add-mob mob) - `(add-mob-symbol ',mob)) + `(add-mob-lambda (lambda (option) (,mob option)))) (define-macro (kill-mob mob) `(kill-mob-symbol ',mob)) -(define-macro (get-mobs-function) - (let ((mobs (get-active-mobs))) - (cond ((null? mobs) - `(lambda () #f)) - (else - `(lambda () ,@(map (lambda (mob) `(,mob #:render)) mobs)))))) +(define (process-mobs mobs) + (for-each (lambda (m) (m #:render)) mobs)) (define-macro (define-mob mob-head . look) (let ((name (car mob-head)) (attr (cdr mob-head)))