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:
@@ -180,6 +180,7 @@ namespace OpenRA
|
||||
}
|
||||
|
||||
public static event Action BeforeGameStart = () => { };
|
||||
public static event Action AfterGameStart = () => { };
|
||||
internal static void StartGame(string mapUID, WorldType type)
|
||||
{
|
||||
// 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.
|
||||
// e.g. audio notifications that the game is starting.
|
||||
OrderManager.World.PostLoadComplete(worldRenderer);
|
||||
|
||||
AfterGameStart();
|
||||
}
|
||||
|
||||
public static void RestartGame()
|
||||
|
||||
@@ -20,6 +20,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
public class PerfDebugLogic : ChromeLogic
|
||||
{
|
||||
readonly Stopwatch fpsTimer;
|
||||
readonly List<(int Frame, TimeSpan Time)> frameTimings = new(32);
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public PerfDebugLogic(Widget widget, WorldRenderer worldRenderer)
|
||||
{
|
||||
@@ -29,8 +32,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var perfText = widget.Get<LabelWidget>("PERF_TEXT");
|
||||
perfText.IsVisible = () => Game.Settings.Debug.PerfText;
|
||||
|
||||
var fpsTimer = Stopwatch.StartNew();
|
||||
var frameTimings = new List<(int Frame, TimeSpan Time)>(32) { (Game.RenderFrame, TimeSpan.Zero) };
|
||||
fpsTimer = Stopwatch.StartNew();
|
||||
frameTimings.Add((Game.RenderFrame, TimeSpan.Zero));
|
||||
perfText.GetText = () =>
|
||||
{
|
||||
// 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" +
|
||||
$"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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user