forked from cschladetsch/CsharpFlow
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTimeFrame.cs
More file actions
45 lines (37 loc) · 927 Bytes
/
TimeFrame.cs
File metadata and controls
45 lines (37 loc) · 927 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// (C) 2012 Christian Schladetsch. See http://www.schladetsch.net/flow/license.txt for Licensing information.
using System;
using System.Diagnostics;
namespace Flow
{
/// <summary>
/// TODO: delta-capping, pausing, introduction of zulu/sim time differences
/// </summary>
internal class TimeFrame : ITimeFrame
{
private Stopwatch _stopwatch;
public TimeFrame()
{
_stopwatch = new Stopwatch();
Now = TimeSpan.Zero;
Last = TimeSpan.Zero;
Delta = TimeSpan.Zero;
}
/// <inheritdoc />
public System.TimeSpan Last { get; internal set; }
/// <inheritdoc />
public System.TimeSpan Now { get; internal set; }
/// <inheritdoc />
public System.TimeSpan Delta { get; internal set; }
public void Step()
{
if (_stopwatch.IsRunning == false)
{
_stopwatch.Reset();
_stopwatch.Start();
}
Last = Now;
Delta = _stopwatch.Elapsed - Last;
Now = _stopwatch.Elapsed;
}
}
}