Color legend plain property method
Measures the frame rate and the frame times of a game loop, called once per drawn frame: the frame rate over a window of frames, the last frame’s time, and the longest frame of the window.
A sealed class. The quick start guide shows it in context, with code. It isn’t thread-safe: call it from the thread that runs the loop, see threads.
Names are colored by what they are: a property or a method; values and fields keep the plain color.
Properties
FrameRate →
int · Read-only. Frames per second, rounded to the nearest whole number, a tie to the even one: the frames of the last window divided by its time, or 1 divided by the last frame’s time if UpdateEveryFrame is true, where a frame of no time reads 0. 0 until the first window closes, and after Reset.
FrameTime →
float · Read-only. The time of the last recorded frame, in seconds, set by every Update that records a frame, in either mode. 0 until a frame is recorded, and after Reset.
RefreshRateInSeconds →
float · The length of the averaging window, in seconds: 0.5 by default. The frame that brings the window to this length or past it closes it. Zero, negative, NaN and infinite values are ignored, and the length stays as it was. A new length applies to the window in progress, which isn’t discarded. Not used if UpdateEveryFrame is true; kept by Reset.
UpdateEveryFrame →
bool · false, the default: FrameRate and WorstFrameTimePerRefresh come from a window of frames, recalculated when it closes. true: from every frame alone, recalculated every frame. A change discards the frames collected for the window in progress; the readings keep their values until the next recalculation. Setting the value it already has does nothing. Kept by Reset.
WorstFrameTimePerRefresh →
float · Read-only. The longest frame of the last window, in seconds, or the last frame’s time, the same as FrameTime, if UpdateEveryFrame is true. 0 until the first window closes, and after Reset.
Methods
FrameRateCounter() →
FrameRateCounter() · A counter that averages over a window of 0.5 seconds, with every reading at 0 and the clock of Update() not started yet.
Reset() →
Reset() · Sets every reading back to 0, discards the frames collected for the window in progress, and stops the clock of Update(), so its next call only starts it again. UpdateEveryFrame and RefreshRateInSeconds keep their values.
Update() →
Update() · Records one frame, the time since the previous call, measured with Stopwatch.GetTimestamp. The first call, and the first after Reset, only starts the clock: it records no frame and returns false. Returns true when FrameRate and WorstFrameTimePerRefresh were recalculated by this call: when it closed a window, or for every recorded frame if UpdateEveryFrame is true.
Update(double elapsedSeconds) · Records one frame that took the given time, and leaves the clock of Update() as it is. Returns true when the readings were recalculated by this call, as above.
| Parameter | Type | Description |
|---|---|---|
elapsedSeconds |
double |
The time since the previous frame, in seconds. Not checked: a zero is a frame of no time, and a negative value takes time away from the window. |