Last active
August 29, 2015 14:17
-
-
Save jjvdangelo/2a04bc9369b6fe19a116 to your computer and use it in GitHub Desktop.
Turning a regular game timer into a sequence to experiment with looking at the game loop as something that iterates the timer sequence instead of an imperative while loop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Timer | |
open System.Diagnostics | |
type TimeInfo = | |
{ TotalElapsed: float | |
Delta: float } | |
let start () = | |
let last = | |
ref { TotalElapsed = 0. | |
Delta = 0. } | |
let watch = | |
Stopwatch.StartNew () | |
seq { | |
let totalElapsed = | |
watch.Elapsed.TotalMilliseconds | |
let last' = !last | |
last := { TotalElapsed = totalElapsed | |
Delta = totalElapsed - last'.TotalElapsed } | |
yield !last } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just a quick jot of a thought, nothing more.