diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ec39d1..c47ae21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,6 +69,7 @@ Fixes - Fixed children of Panel scroll bars also being scrolled - Fixed RootElement.CanSelectContent and Element.IsSelected returning incorrect results when CanBeSelected changes - Fixed dropdowns with some non-selectable children failing to navigate when using gamepad controls +- Fixed UiMetrics.ForceAreaUpdateTime being inaccurate for nested elements Removals - Marked StyleProp equality members as obsolete diff --git a/MLEM.Ui/Elements/Element.cs b/MLEM.Ui/Elements/Element.cs index 7a57448..8afe267 100644 --- a/MLEM.Ui/Elements/Element.cs +++ b/MLEM.Ui/Elements/Element.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Diagnostics; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -409,6 +410,7 @@ namespace MLEM.Ui.Elements { protected RectangleF ParentArea => this.Parent?.ChildPaddedArea ?? (RectangleF) this.system.Viewport; private readonly List children = new List(); + private readonly Stopwatch stopwatch = new Stopwatch(); private bool sortedChildrenDirty; private IList sortedChildren; private UiSystem system; @@ -559,7 +561,7 @@ namespace MLEM.Ui.Elements { // which would cause our ForceUpdateArea code to be run twice, so we only update our parent instead if (this.Parent != null && this.Parent.UpdateAreaIfDirty()) return; - this.System.Stopwatch.Restart(); + this.stopwatch.Restart(); var parentArea = this.ParentArea; var parentCenterX = parentArea.X + parentArea.Width / 2; @@ -569,8 +571,8 @@ namespace MLEM.Ui.Elements { var recursion = 0; UpdateDisplayArea(actualSize); - this.System.Stopwatch.Stop(); - this.System.Metrics.ForceAreaUpdateTime += this.System.Stopwatch.Elapsed; + this.stopwatch.Stop(); + this.System.Metrics.ForceAreaUpdateTime += this.stopwatch.Elapsed; this.System.Metrics.ForceAreaUpdates++; void UpdateDisplayArea(Vector2 newSize) { diff --git a/MLEM.Ui/UiSystem.cs b/MLEM.Ui/UiSystem.cs index d494dac..e93b68c 100644 --- a/MLEM.Ui/UiSystem.cs +++ b/MLEM.Ui/UiSystem.cs @@ -182,9 +182,8 @@ namespace MLEM.Ui { /// public event RootCallback OnRootRemoved; - internal readonly Stopwatch Stopwatch = new Stopwatch(); - private readonly List rootElements = new List(); + private readonly Stopwatch stopwatch = new Stopwatch(); private float globalScale = 1; private bool drewEarly; private UiStyle style; @@ -253,14 +252,14 @@ namespace MLEM.Ui { /// The game's time public override void Update(GameTime time) { this.Metrics.ResetUpdates(); - this.Stopwatch.Restart(); + this.stopwatch.Restart(); this.Controls.Update(); for (var i = this.rootElements.Count - 1; i >= 0; i--) this.rootElements[i].Element.Update(time); - this.Stopwatch.Stop(); - this.Metrics.UpdateTime += this.Stopwatch.Elapsed; + this.stopwatch.Stop(); + this.Metrics.UpdateTime += this.stopwatch.Elapsed; } /// @@ -271,15 +270,15 @@ namespace MLEM.Ui { /// The sprite batch to use for drawing public void DrawEarly(GameTime time, SpriteBatch batch) { this.Metrics.ResetDraws(); - this.Stopwatch.Restart(); + this.stopwatch.Restart(); foreach (var root in this.rootElements) { if (!root.Element.IsHidden) root.Element.DrawEarly(time, batch, this.DrawAlpha * root.Element.DrawAlpha, this.BlendState, this.SamplerState, this.DepthStencilState, this.Effect, root.Transform); } - this.Stopwatch.Stop(); - this.Metrics.DrawTime += this.Stopwatch.Elapsed; + this.stopwatch.Stop(); + this.Metrics.DrawTime += this.stopwatch.Elapsed; this.drewEarly = true; } @@ -292,7 +291,7 @@ namespace MLEM.Ui { public void Draw(GameTime time, SpriteBatch batch) { if (!this.drewEarly) this.Metrics.ResetDraws(); - this.Stopwatch.Restart(); + this.stopwatch.Restart(); foreach (var root in this.rootElements) { if (root.Element.IsHidden) @@ -303,8 +302,8 @@ namespace MLEM.Ui { batch.End(); } - this.Stopwatch.Stop(); - this.Metrics.DrawTime += this.Stopwatch.Elapsed; + this.stopwatch.Stop(); + this.Metrics.DrawTime += this.stopwatch.Elapsed; this.drewEarly = false; }