From 0fb04927385d4ac7276db0fe21ebeb964f477d79 Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Sun, 1 Oct 2023 18:27:02 +0300 Subject: [PATCH] Show Editor window true framerate in the fps counter widget --- Source/Editor/Viewport/EditorViewport.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Source/Editor/Viewport/EditorViewport.cs b/Source/Editor/Viewport/EditorViewport.cs index 1e24560d8..f90e345e6 100644 --- a/Source/Editor/Viewport/EditorViewport.cs +++ b/Source/Editor/Viewport/EditorViewport.cs @@ -1241,6 +1241,10 @@ namespace FlaxEditor.Viewport private class FpsCounter : Control { + private int fps; + private int accumFrames; + private float lastUpdate; + public FpsCounter(float x, float y) : base(x, y, 64, 32) { @@ -1250,7 +1254,15 @@ namespace FlaxEditor.Viewport { base.Draw(); - int fps = Engine.FramesPerSecond; + accumFrames++; + float timeNow = Time.TimeSinceStartup; + if (timeNow - lastUpdate >= 1.0f) + { + fps = accumFrames; + lastUpdate = timeNow; + accumFrames = 0; + } + Color color = Color.Green; if (fps < 13) color = Color.Red;