From: jsancho Date: Sun, 25 Dec 2011 20:57:50 +0000 (+0000) Subject: Frames per second. X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=f6a1e853e80bdaf59862bf314ec3d3bd515fd73e;p=gacela.git Frames per second. --- diff --git a/src/gacela.scm b/src/gacela.scm index d6515ec..256e940 100644 --- a/src/gacela.scm +++ b/src/gacela.scm @@ -144,9 +144,8 @@ ; (refresh-active-mobs) (set! loop-flag #t) (init-video 640 480 32) -; (quit! #f) (while loop-flag -; (init-frame-time) + (init-frame-time) ; (check-connections) (process-events) (cond ((not (quit?)) @@ -159,8 +158,7 @@ (lambda (key . args) #f))) ; (run-mobs) (flip-screen) -; (delay-frame)))) - ))) + (delay-frame)))) (quit-video)) (define (game-running?) diff --git a/src/video.scm b/src/video.scm index e0b7a6d..7eda879 100644 --- a/src/video.scm +++ b/src/video.scm @@ -145,29 +145,22 @@ ;;; Frames per second -(define set-frames-per-second #f) -(define init-frame-time #f) -(define get-frame-time #f) -(define delay-frame #f) - -;; (let ((time 0) (time-per-frame (/ 1000.0 *frames-per-second*))) -;; (set! set-frames-per-second -;; (lambda (fps) -;; (set! time-per-frame (/ 1000.0 fps)))) - -;; (set! init-frame-time -;; (lambda () -;; (set! time (SDL_GetTicks)))) - -;; (set! get-frame-time -;; (lambda () -;; time)) - -;; (set! delay-frame -;; (lambda () -;; (let ((frame-time (- (SDL_GetTicks) time))) -;; (cond ((< frame-time time-per-frame) -;; (SDL_Delay (- time-per-frame frame-time)))))))) +(define time 0) +(define time-per-frame 50) ;in ms + +(define (set-frames-per-second fps) + (set! time-per-frame (/ 1000.0 fps))) + +(define (init-frame-time) + (set! time (SDL_GetTicks))) + +(define (get-frame-time) + time) + +(define (delay-frame) + (let ((frame-time (- (SDL_GetTicks) time))) + (cond ((< frame-time time-per-frame) + (SDL_Delay (- time-per-frame frame-time)))))) ;;; Drawing