From b77fa5eabb1318a71966fe4cb736c047b4051c6a Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sat, 15 May 2021 22:25:28 +0200 Subject: Add clock durations --- guile/starlet/clock.scm | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/guile/starlet/clock.scm b/guile/starlet/clock.scm index 349aeb4..bd00d50 100644 --- a/guile/starlet/clock.scm +++ b/guile/starlet/clock.scm @@ -32,7 +32,7 @@ clock-stopped? clock-reversed? - time-elapsed)) + elapsed-fraction)) (define (time-now) @@ -123,7 +123,12 @@ (delay-time #:init-form (error "Delay time must be specified") #:init-keyword #:delay-time - #:getter get-delay-time)) + #:getter get-delay-time) + + (duration + #:init-value #f + #:init-keyword #:duration + #:getter get-duration)) (define-method (clock-stopped? (clock )) @@ -139,6 +144,12 @@ (get-delay-time clock)))) +(define-method (elapsed-fraction (clock )) + (min 1.0 + (/ (time-elapsed clock) + (get-duration clock)))) + + (define-method (stop-clock! (clock )) (error "Can only stop a top-level clock.")) @@ -151,7 +162,8 @@ (error "Can only reverse a top-level clock.")) -(define (make-delayed-clock clock delay-time) +(define (make-delayed-clock clock delay-time duration) (make #:parent clock - #:delay-time delay-time)) + #:delay-time delay-time + #:duration duration)) -- cgit v1.2.3