-
Notifications
You must be signed in to change notification settings - Fork 200
/
Copy pathProcessingStage.cs
65 lines (56 loc) · 1.56 KB
/
ProcessingStage.cs
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.Diagnostics;
namespace BEPUphysics
{
///<summary>
/// Superclass of singlethreaded update systems.
///</summary>
public abstract class ProcessingStage
{
///<summary>
/// Gets or sets whether or not the stage should update.
///</summary>
public virtual bool Enabled { get; set; }
///<summary>
/// Fires when the stage starts working.
///</summary>
public event Action Starting;
///<summary>
/// Fires when the stage finishes working.
///</summary>
public event Action Finishing;
#if PROFILE
/// <summary>
/// Gets the time elapsed in the previous execution of this stage, not including any hooked Starting or Finishing events.
/// </summary>
public double Time
{
get
{
return (end - start) / (double)Stopwatch.Frequency;
}
}
long start, end;
#endif
///<summary>
/// Updates the stage.
///</summary>
public void Update()
{
if (!Enabled)
return;
if (Starting != null)
Starting();
#if PROFILE
start = Stopwatch.GetTimestamp();
#endif
UpdateStage();
#if PROFILE
end = Stopwatch.GetTimestamp();
#endif
if (Finishing != null)
Finishing();
}
protected abstract void UpdateStage();
}
}