From 57a452a705047c1ae16855edd6e2be0effe779c2 Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Sun, 12 Nov 2023 16:08:41 +0000 Subject: [PATCH] Ensure PerfHistory is reset when starting a new game. Ensure stale perf history data, to ensure the data is useful and the perf graph widget displays useful information. - Remove stale data from the previous game when starting a new game. This avoids the graph showing values from the previous game when a new game starts. - Remove data that was collected during loading. This avoids displaying data points that were collected whilst the loading screen was visible. Data collected whilst loading is not relevant to the in-game performance graph. The performance graph when starting a new game will now display accurate information from the first tick of the game, whereas previously it displayed some stale information as well. --- OpenRA.Game/Game.cs | 9 ++++++++- OpenRA.Game/Support/PerfHistory.cs | 6 ++++++ OpenRA.Game/Support/PerfItem.cs | 7 +++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index bff7eb4511..3f5c8ddfa3 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -602,7 +602,10 @@ namespace OpenRA if (orderManager.LastTickTime.ShouldAdvance(tick)) { - using (new PerfSample("tick_time")) + if (orderManager.GameStarted && orderManager.LocalFrameNumber == 0) + PerfHistory.Reset(); // Remove history that occurred whilst the new game was loading. + + using (var sample = new PerfSample("tick_time")) { orderManager.LastTickTime.AdvanceTickTime(tick); @@ -611,7 +614,11 @@ namespace OpenRA Sync.RunUnsynced(world, orderManager.TickImmediate); if (world == null) + { + if (orderManager.GameStarted) + PerfHistory.Reset(); // Remove old history when a new game starts. return; + } if (orderManager.TryTick()) { diff --git a/OpenRA.Game/Support/PerfHistory.cs b/OpenRA.Game/Support/PerfHistory.cs index 0d6a774e69..13731a8105 100644 --- a/OpenRA.Game/Support/PerfHistory.cs +++ b/OpenRA.Game/Support/PerfHistory.cs @@ -47,5 +47,11 @@ namespace OpenRA.Support if (item.HasNormalTick) item.Tick(); } + + public static void Reset() + { + foreach (var item in Items.Values) + item.ResetSamples(); + } } } diff --git a/OpenRA.Game/Support/PerfItem.cs b/OpenRA.Game/Support/PerfItem.cs index 4fb933ed57..c88a7d055c 100644 --- a/OpenRA.Game/Support/PerfItem.cs +++ b/OpenRA.Game/Support/PerfItem.cs @@ -72,5 +72,12 @@ namespace OpenRA.Support return samples[n]; } } + + public void ResetSamples() + { + head = 1; + tail = 0; + Val = 0.0; + } } }