Skip to content

Instantly share code, notes, and snippets.

@jjvdangelo
Last active August 29, 2015 14:17
Show Gist options
  • Save jjvdangelo/2a04bc9369b6fe19a116 to your computer and use it in GitHub Desktop.
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.
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 }
@jjvdangelo
Copy link
Author

Just a quick jot of a thought, nothing more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment