Commits

Scott Tincman  committed 5aa7425

Change event-handler to use global *minimum-wait*. This allows
world-update-delay to be usable.

Updated world-update-delay to behave as a parameter.

Updated wiki documentation to reflect current changes

  • Participants
  • Parent commits 44ca328

Comments (0)

Files changed (2)

 (define (world-changes f) (set! *world-changes* f))
 (define (world-inits f) (set! *world-inits* f))
 
-(define (world-update-delay d)
-  (unless (number? d)
-          (error "Please provide a number for the world-update-delay, given " d))
-  (set! *minimum-wait* d))
+(define (world-update-delay . d)
+  (if (null? d)
+      *minimum-wait*
+      (if (number? (car d))
+	  (set! *minimum-wait* (car d))
+	  (error "Please provide a number for the world-update-delay, given " (car d)))))
 
 (define-syntax set-color
   (syntax-rules ()
           (pump (cons event events))
           (reverse events)))))
 
-(define (event-handler minimum-wait)
+(define (event-handler)
   (lambda ()
     (let ((last (time->seconds (current-time))))
       (call-with-current-continuation
              (show!)
              (set! last now)
 	     (let ((duration (- (time->seconds (current-time)) last)))
-	       (when (< duration minimum-wait)
-		     (thread-sleep! (- minimum-wait duration))))
+	       (when (< duration *minimum-wait*)
+		     (thread-sleep! (- *minimum-wait* duration))))
              (loop)))))
              (call-with-current-continuation
               (lambda (k)
   (sdl-flip *s*)
   (if run-in-background
       (thread-start!
-       (make-thread (event-handler minimum-wait) "doodle-event-loop"))
+       (make-thread (event-handler) "doodle-event-loop"))
       (thread-join!
        (thread-start!
-        (make-thread (event-handler minimum-wait) "doodle-event-loop"))))))
+        (make-thread (event-handler) "doodle-event-loop"))))))
 time delta of the last call and the events that occured. If
 {{minimum-wait}} is given and the delta is smaller than
 {{minimum-wait}} the thread will sleep for the remaining
-time. {{minimum-wait}} takes a value in milliseconds.
+time. {{minimum-wait}} takes a value in seconds.
 
 ===== Parameters
 <parameter>(world-inits (lambda () ...))</parameter>
 
 A procedure that gets called every iteration of the event loop. The
 {{event}} parameter holds the event, {{dt}} is the time difference in
-milliseconds between the last and current
-iteration. {{exit-continuation}} can be used to jump out of the
-event-loop.
+seconds between the last and current iteration.
+{{exit-continuation}} can be used to jump out of the event-loop.
+
+<parameter>(world-update-delay flonum)</parameter>
+
+The minimum delay between updates. Aka, the minimum-wait property in the event-loop.
 
 ===== Events