From: jsancho Date: Thu, 4 Aug 2011 18:04:53 +0000 (+0000) Subject: (no commit message) X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=6630e65025bb225b39592b49edb68ff8c43d4551;p=gacela.git --- diff --git a/src/gacela_widgets.scm b/src/gacela_widgets.scm index a0e0223..04f2dcb 100755 --- a/src/gacela_widgets.scm +++ b/src/gacela_widgets.scm @@ -17,27 +17,27 @@ ;;; Timers -(defstruct timer (start 0) (paused 0) (state 'stopped)) - -(defun start-timer (timer) - (setf (timer-start timer) (SDL_GetTicks)) - (setf (timer-state timer) 'running)) - -(defun stop-timer (timer) - (setf (timer-state timer) 'stopped)) - -(defun get-time (timer) - (cond ((eq (timer-state timer) 'stopped) 0) - ((eq (timer-state timer) 'paused) (timer-paused timer)) - (t (- (SDL_GetTicks) (timer-start timer))))) - -(defun pause-timer (timer) - (cond ((eq (timer-state timer) 'running) - (setf (timer-paused timer) (- (SDL_GetTicks) (timer-start timer))) - (setf (timer-state timer) 'paused)))) - -(defun resume-timer (timer) - (cond ((eq (timer-state timer) 'paused) - (setf (timer-start timer) (- (SDL_GetTicks) (timer-paused timer))) - (setf (timer-state timer) 'running)))) - +(define (make-timer) + '((start . 0) (paused . 0) (state . stopped))) + +(define (start-timer timer) + (assoc-set! timer 'start (SDL_GetTicks)) + (assoc-set! timer state 'running)) + +(define (stop-timer timer) + (assoc-set! timer 'state 'stopped)) + +(define (get-time timer) + (cond ((eq? (assoc 'state timer) 'stopped) 0) + ((eq? (assoc 'state timer) 'paused) (assoc 'paused timer)) + (else (- (SDL_GetTicks) (assoc 'start timer))))) + +(define (pause-timer timer) + (cond ((eq? (assoc 'state timer) 'running) + (assoc-set! timer 'paused (- (SDL_GetTicks) (assoc 'start timer))) + (assoc-set! timer 'state 'paused)))) + +(define (resume-timer timer) + (cond ((eq? (assoc 'state timer) 'paused) + (assoc-set! timer 'start (- (SDL_GetTicks) (assoc 'paused timer))) + (assoc-set! timer 'state 'running))))