Commits

Christian Kellermann  committed e948da9

world-update-delay can regulate delays between world-changes runs now

  • Participants
  • Parent commits e476fbb

Comments (0)

Files changed (1)

          update-sprite!
          world-changes
          world-inits
-         world-ends)
+         world-ends
+         world-update-delay)
 
 (import chicken scheme)
 (use (srfi 1 4 18) cairo data-structures extras sdl-base clojurian-syntax matchable)
 (define *world-inits* values)
 (define *world-changes* values)
 (define *world-ends* values)
+(define *minimum-wait* 0)
 
 (define (world-ends f) (set! *world-ends* f))
 (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-syntax set-color
   (syntax-rules ()
     ((_ color) (apply cairo-set-source-rgba `(,*c* ,@color)))))
           (pump (cons event events))
           (reverse events)))))
 
-(define (event-handler #!optional minimum-wait)
+(define (event-handler #!optional (minimum-wait *minimum-wait*))
   (lambda ()
     (let ((last (current-milliseconds)))
       (call-with-current-continuation
                     escape)))))
              (show!)
              (set! last now)
-             (when (< dt minimum-wait)
-               (thread-sleep! (- minimum-wait dt)))
+             (when (< (- now last) minimum-wait)
+               (thread-sleep! (- minimum-wait (- now last))))
              (loop)))))
              (call-with-current-continuation
               (lambda (k)