public void MeasureTime() { nowTime = StaticTimer.GetElapsedSeconds(); deltaUpdateTime += (nowTime - lastTime) / updateTimeLimit; deltaRenderTime += (nowTime - lastTime) / renderTimeLimit; lastTime = nowTime; }
/// <summary> /// The timer will reset if 1 second has passed. /// This information can be used to update game logic in any way desireable. /// </summary> public bool ShouldReset() { var ret = StaticTimer.GetElapsedSeconds() - timer > 1.0; if (ret) { timer += 1.0; CapturedUpdates = updates; CapturedFrames = frames; updates = 0; frames = 0; } return(ret); }
public GameTimer(int ups, int fps = 0) { if (ups < 0 || fps < 0) { throw new ArgumentOutOfRangeException( $"GameTimer must have positive count values: (ups={ups},fps={fps})"); } desiredMaxFPS = fps; timeLimit = 1.0 / ups; lastTime = StaticTimer.GetElapsedSeconds(); deltaTime = 0.0; nowTime = 0.0; timer = lastTime; frames = 0; updates = 0; CapturedFrames = 0; CapturedUpdates = 0; }
/// <summary> /// Check if the specified time span has elapsed /// </summary> public bool HasExpired() { var nowTime = StaticTimer.GetElapsedMilliseconds(); return(nowTime - timeOfCreation > timeSpanMilliseconds); }
/// <summary> /// Reset this object's timer /// </summary> public void ResetTimer() { timeOfCreation = StaticTimer.GetElapsedMilliseconds(); }
public void MeasureTime() { nowTime = StaticTimer.GetElapsedSeconds(); deltaTime += (nowTime - lastTime) / timeLimit; lastTime = nowTime; }