(define (make-timer)
(let ((start 0) (paused 0) (state 'stopped))
(lambda (op)
- (cond ((eq? op 'start-timer)
- (set! start (SDL_GetTicks))
- (set! state 'running))
+ (case op
+ ((start-timer)
+ (set! start (SDL_GetTicks))
+ (set! state 'running))
- ((eq? op 'stop-timer)
- (set! state 'stopped))
+ ((stop-timer)
+ (set! state 'stopped))
- ((eq? op 'get-time)
- (cond ((eq? state 'stopped) 0)
- ((eq? state 'paused) paused)
- (else (- (SDL_GetTicks) start))))
+ ((get-time)
+ (cond ((eq? state 'stopped) 0)
+ ((eq? state 'paused) paused)
+ (else (- (SDL_GetTicks) start))))
- ((eq? op 'get-state)
- state)
+ ((get-state)
+ state)
- ((eq? op 'pause-timer)
- (cond ((eq? state 'running)
- (set! paused (- (SDL_GetTicks) start))
- (set! state 'paused))))
+ ((pause-timer)
+ (cond ((eq? state 'running)
+ (set! paused (- (SDL_GetTicks) start))
+ (set! state 'paused))))
- ((eq? op 'resume-timer)
- (cond ((eq? state 'paused)
- (set! start (- (SDL_GetTicks) paused))
- (set! state 'running))))))))
+ ((resume-timer)
+ (cond ((eq? state 'paused)
+ (set! start (- (SDL_GetTicks) paused))
+ (set! state 'running))))))))
(define (start-timer timer)
(timer 'start-timer))