mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-25 22:18:34 +01:00
Fixed UiMetrics.ForceAreaUpdateTime being inaccurate for nested elements
This commit is contained in:
parent
3ad024b95a
commit
6a3c797eba
3 changed files with 16 additions and 14 deletions
|
@ -69,6 +69,7 @@ Fixes
|
||||||
- Fixed children of Panel scroll bars also being scrolled
|
- Fixed children of Panel scroll bars also being scrolled
|
||||||
- Fixed RootElement.CanSelectContent and Element.IsSelected returning incorrect results when CanBeSelected changes
|
- 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 dropdowns with some non-selectable children failing to navigate when using gamepad controls
|
||||||
|
- Fixed UiMetrics.ForceAreaUpdateTime being inaccurate for nested elements
|
||||||
|
|
||||||
Removals
|
Removals
|
||||||
- Marked StyleProp equality members as obsolete
|
- Marked StyleProp equality members as obsolete
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
@ -409,6 +410,7 @@ namespace MLEM.Ui.Elements {
|
||||||
protected RectangleF ParentArea => this.Parent?.ChildPaddedArea ?? (RectangleF) this.system.Viewport;
|
protected RectangleF ParentArea => this.Parent?.ChildPaddedArea ?? (RectangleF) this.system.Viewport;
|
||||||
|
|
||||||
private readonly List<Element> children = new List<Element>();
|
private readonly List<Element> children = new List<Element>();
|
||||||
|
private readonly Stopwatch stopwatch = new Stopwatch();
|
||||||
private bool sortedChildrenDirty;
|
private bool sortedChildrenDirty;
|
||||||
private IList<Element> sortedChildren;
|
private IList<Element> sortedChildren;
|
||||||
private UiSystem system;
|
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
|
// which would cause our ForceUpdateArea code to be run twice, so we only update our parent instead
|
||||||
if (this.Parent != null && this.Parent.UpdateAreaIfDirty())
|
if (this.Parent != null && this.Parent.UpdateAreaIfDirty())
|
||||||
return;
|
return;
|
||||||
this.System.Stopwatch.Restart();
|
this.stopwatch.Restart();
|
||||||
|
|
||||||
var parentArea = this.ParentArea;
|
var parentArea = this.ParentArea;
|
||||||
var parentCenterX = parentArea.X + parentArea.Width / 2;
|
var parentCenterX = parentArea.X + parentArea.Width / 2;
|
||||||
|
@ -569,8 +571,8 @@ namespace MLEM.Ui.Elements {
|
||||||
var recursion = 0;
|
var recursion = 0;
|
||||||
UpdateDisplayArea(actualSize);
|
UpdateDisplayArea(actualSize);
|
||||||
|
|
||||||
this.System.Stopwatch.Stop();
|
this.stopwatch.Stop();
|
||||||
this.System.Metrics.ForceAreaUpdateTime += this.System.Stopwatch.Elapsed;
|
this.System.Metrics.ForceAreaUpdateTime += this.stopwatch.Elapsed;
|
||||||
this.System.Metrics.ForceAreaUpdates++;
|
this.System.Metrics.ForceAreaUpdates++;
|
||||||
|
|
||||||
void UpdateDisplayArea(Vector2 newSize) {
|
void UpdateDisplayArea(Vector2 newSize) {
|
||||||
|
|
|
@ -182,9 +182,8 @@ namespace MLEM.Ui {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event RootCallback OnRootRemoved;
|
public event RootCallback OnRootRemoved;
|
||||||
|
|
||||||
internal readonly Stopwatch Stopwatch = new Stopwatch();
|
|
||||||
|
|
||||||
private readonly List<RootElement> rootElements = new List<RootElement>();
|
private readonly List<RootElement> rootElements = new List<RootElement>();
|
||||||
|
private readonly Stopwatch stopwatch = new Stopwatch();
|
||||||
private float globalScale = 1;
|
private float globalScale = 1;
|
||||||
private bool drewEarly;
|
private bool drewEarly;
|
||||||
private UiStyle style;
|
private UiStyle style;
|
||||||
|
@ -253,14 +252,14 @@ namespace MLEM.Ui {
|
||||||
/// <param name="time">The game's time</param>
|
/// <param name="time">The game's time</param>
|
||||||
public override void Update(GameTime time) {
|
public override void Update(GameTime time) {
|
||||||
this.Metrics.ResetUpdates();
|
this.Metrics.ResetUpdates();
|
||||||
this.Stopwatch.Restart();
|
this.stopwatch.Restart();
|
||||||
|
|
||||||
this.Controls.Update();
|
this.Controls.Update();
|
||||||
for (var i = this.rootElements.Count - 1; i >= 0; i--)
|
for (var i = this.rootElements.Count - 1; i >= 0; i--)
|
||||||
this.rootElements[i].Element.Update(time);
|
this.rootElements[i].Element.Update(time);
|
||||||
|
|
||||||
this.Stopwatch.Stop();
|
this.stopwatch.Stop();
|
||||||
this.Metrics.UpdateTime += this.Stopwatch.Elapsed;
|
this.Metrics.UpdateTime += this.stopwatch.Elapsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -271,15 +270,15 @@ namespace MLEM.Ui {
|
||||||
/// <param name="batch">The sprite batch to use for drawing</param>
|
/// <param name="batch">The sprite batch to use for drawing</param>
|
||||||
public void DrawEarly(GameTime time, SpriteBatch batch) {
|
public void DrawEarly(GameTime time, SpriteBatch batch) {
|
||||||
this.Metrics.ResetDraws();
|
this.Metrics.ResetDraws();
|
||||||
this.Stopwatch.Restart();
|
this.stopwatch.Restart();
|
||||||
|
|
||||||
foreach (var root in this.rootElements) {
|
foreach (var root in this.rootElements) {
|
||||||
if (!root.Element.IsHidden)
|
if (!root.Element.IsHidden)
|
||||||
root.Element.DrawEarly(time, batch, this.DrawAlpha * root.Element.DrawAlpha, this.BlendState, this.SamplerState, this.DepthStencilState, this.Effect, root.Transform);
|
root.Element.DrawEarly(time, batch, this.DrawAlpha * root.Element.DrawAlpha, this.BlendState, this.SamplerState, this.DepthStencilState, this.Effect, root.Transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Stopwatch.Stop();
|
this.stopwatch.Stop();
|
||||||
this.Metrics.DrawTime += this.Stopwatch.Elapsed;
|
this.Metrics.DrawTime += this.stopwatch.Elapsed;
|
||||||
this.drewEarly = true;
|
this.drewEarly = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -292,7 +291,7 @@ namespace MLEM.Ui {
|
||||||
public void Draw(GameTime time, SpriteBatch batch) {
|
public void Draw(GameTime time, SpriteBatch batch) {
|
||||||
if (!this.drewEarly)
|
if (!this.drewEarly)
|
||||||
this.Metrics.ResetDraws();
|
this.Metrics.ResetDraws();
|
||||||
this.Stopwatch.Restart();
|
this.stopwatch.Restart();
|
||||||
|
|
||||||
foreach (var root in this.rootElements) {
|
foreach (var root in this.rootElements) {
|
||||||
if (root.Element.IsHidden)
|
if (root.Element.IsHidden)
|
||||||
|
@ -303,8 +302,8 @@ namespace MLEM.Ui {
|
||||||
batch.End();
|
batch.End();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Stopwatch.Stop();
|
this.stopwatch.Stop();
|
||||||
this.Metrics.DrawTime += this.Stopwatch.Elapsed;
|
this.Metrics.DrawTime += this.stopwatch.Elapsed;
|
||||||
this.drewEarly = false;
|
this.drewEarly = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue