Reset FPS counter on game start.

This avoids this displayed counter being dragged down by lower FPS during loading prior to the game starting.
This commit is contained in:
RoosterDragon
2023-11-14 19:32:10 +00:00
committed by Gustas
parent 58e447d8d0
commit 399cef8fb2
2 changed files with 29 additions and 2 deletions

View File

@@ -180,6 +180,7 @@ namespace OpenRA
} }
public static event Action BeforeGameStart = () => { }; public static event Action BeforeGameStart = () => { };
public static event Action AfterGameStart = () => { };
internal static void StartGame(string mapUID, WorldType type) internal static void StartGame(string mapUID, WorldType type)
{ {
// Dispose of the old world before creating a new one. // Dispose of the old world before creating a new one.
@@ -227,6 +228,8 @@ namespace OpenRA
// PostLoadComplete is designed for anything that should trigger at the very end of loading. // PostLoadComplete is designed for anything that should trigger at the very end of loading.
// e.g. audio notifications that the game is starting. // e.g. audio notifications that the game is starting.
OrderManager.World.PostLoadComplete(worldRenderer); OrderManager.World.PostLoadComplete(worldRenderer);
AfterGameStart();
} }
public static void RestartGame() public static void RestartGame()

View File

@@ -20,6 +20,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{ {
public class PerfDebugLogic : ChromeLogic public class PerfDebugLogic : ChromeLogic
{ {
readonly Stopwatch fpsTimer;
readonly List<(int Frame, TimeSpan Time)> frameTimings = new(32);
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public PerfDebugLogic(Widget widget, WorldRenderer worldRenderer) public PerfDebugLogic(Widget widget, WorldRenderer worldRenderer)
{ {
@@ -29,8 +32,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var perfText = widget.Get<LabelWidget>("PERF_TEXT"); var perfText = widget.Get<LabelWidget>("PERF_TEXT");
perfText.IsVisible = () => Game.Settings.Debug.PerfText; perfText.IsVisible = () => Game.Settings.Debug.PerfText;
var fpsTimer = Stopwatch.StartNew(); fpsTimer = Stopwatch.StartNew();
var frameTimings = new List<(int Frame, TimeSpan Time)>(32) { (Game.RenderFrame, TimeSpan.Zero) }; frameTimings.Add((Game.RenderFrame, TimeSpan.Zero));
perfText.GetText = () => perfText.GetText = () =>
{ {
// Calculate FPS as a rolling average over the last ~1 second of frames. // Calculate FPS as a rolling average over the last ~1 second of frames.
@@ -51,6 +54,27 @@ namespace OpenRA.Mods.Common.Widgets.Logic
$"Viewport Size: {viewportSize.Width} x {viewportSize.Height} / {Game.Renderer.WorldDownscaleFactor}\n" + $"Viewport Size: {viewportSize.Width} x {viewportSize.Height} / {Game.Renderer.WorldDownscaleFactor}\n" +
$"WFB Size: {wfbSize.Width} x {wfbSize.Height}"; $"WFB Size: {wfbSize.Width} x {wfbSize.Height}";
}; };
Game.AfterGameStart += OnGameStart;
}
void OnGameStart()
{
// Reset timings so our average doesn't include loading time.
frameTimings.Clear();
frameTimings.Add((Game.RenderFrame, fpsTimer.Elapsed));
}
bool disposed;
protected override void Dispose(bool disposing)
{
if (disposing && !disposed)
{
disposed = true;
Game.AfterGameStart -= OnGameStart;
}
base.Dispose(disposing);
} }
} }
} }