Commits

Christian Kellermann committed a6fcd08 Merge

Fixes for timer logic in the main event-loop merged in from Scott Tincman

  • Participants
  • Parent commits 688499a, 5aa7425

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 (current-milliseconds)))
+    (let ((last (time->seconds (current-time))))
       (call-with-current-continuation
        (lambda (escape)
          (let loop ()
-           (let* ((now (current-milliseconds))
-                  (dt (min (/ 1 30) (/ (- now last)
-                                       1000))))
+           (let* ((now (time->seconds (current-time)))
+                  (dt (- now last)))
              (call-with-current-continuation
               (lambda (k)
                 (with-exception-handler
                     escape)))))
              (show!)
              (set! last now)
-             (when (< (- now last) minimum-wait)
-               (thread-sleep! (- minimum-wait (- now last))))
+	     (let ((duration (- (time->seconds (current-time)) last)))
+	       (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