diff --git a/src/Clock.ml b/src/Clock.ml index dfa2b22a18da909056ceacbe1f322207cccc50e1..6a417fcbbf5ad7b38f3e1bb815a4c67a053eb6d8 100644 --- a/src/Clock.ml +++ b/src/Clock.ml @@ -22,8 +22,8 @@ type clock = { mutable now: float; (* The number of ticks that have taken place. *) mutable ticks: int; - (* The elapsed time, in integer seconds. *) - mutable second: int; + (* The last time [tick] was called for this clock. *) + mutable last: float; (* A circular array of the times at which the most recent round ticks took place. *) window: float array; @@ -39,7 +39,7 @@ let make granularity = start; now = start; ticks = 0; - second = 0; + last = 0.; window = Array.make n start; next = 0; } in @@ -55,11 +55,10 @@ let tick clock f = clock.window.(clock.next) <- clock.now; let n = Array.length clock.window in clock.next <- (clock.next + 1) mod n; - let second' = truncate (clock.now -. clock.start) in (* Check if roughly one new second has elapsed. If so, call the user function [f]. *) - if second' > clock.second then begin - clock.second <- second'; + if clock.now > clock.last +. 1. then begin + clock.last <- clock.now; f() end end