using System;
using MLEM.Ui.Elements;
namespace MLEM.Ui {
///
/// A snapshot of update and rendering statistics from to be used for runtime debugging and profiling.
///
public struct UiMetrics {
///
/// The amount of time that took.
/// Can be divided by to get an average per area update.
///
public TimeSpan ForceAreaUpdateTime { get; internal set; }
///
/// The amount of time that took.
/// Can be divided by to get an average per update.
///
public TimeSpan UpdateTime { get; internal set; }
///
/// The amount of times that was called.
///
public uint ForceAreaUpdates { get; internal set; }
///
/// The amount of times that was called.
///
public uint ActualAreaUpdates { get; internal set; }
///
/// The amount of times that was called.
///
public uint Updates { get; internal set; }
///
/// The amount of time that took.
/// Can be divided by to get an average per draw.
///
public TimeSpan DrawTime { get; internal set; }
///
/// The amount of times that was called.
///
public uint Draws { get; internal set; }
///
/// Resets all update-related metrics to 0.
///
public void ResetUpdates() {
this.ForceAreaUpdateTime = TimeSpan.Zero;
this.UpdateTime = TimeSpan.Zero;
this.ForceAreaUpdates = 0;
this.ActualAreaUpdates = 0;
this.Updates = 0;
}
///
/// Resets all rendering-related metrics to 0.
///
public void ResetDraws() {
this.DrawTime = TimeSpan.Zero;
this.Draws = 0;
}
/// Returns the fully qualified type name of this instance.
/// The fully qualified type name.
public override string ToString() {
return $"{nameof(this.ForceAreaUpdateTime)}: {this.ForceAreaUpdateTime}, {nameof(this.UpdateTime)}: {this.UpdateTime}, {nameof(this.ForceAreaUpdates)}: {this.ForceAreaUpdates}, {nameof(this.ActualAreaUpdates)}: {this.ActualAreaUpdates}, {nameof(this.Updates)}: {this.Updates}, {nameof(this.DrawTime)}: {this.DrawTime}, {nameof(this.Draws)}: {this.Draws}";
}
///
/// Adds two ui metrics together, causing all of their values to be combined.
///
/// The left metrics
/// The right metrics
/// The sum of both metrics
public static UiMetrics operator +(UiMetrics left, UiMetrics right) {
return new UiMetrics {
ForceAreaUpdateTime = left.ForceAreaUpdateTime + right.ForceAreaUpdateTime,
UpdateTime = left.UpdateTime + right.UpdateTime,
ForceAreaUpdates = left.ForceAreaUpdates + right.ForceAreaUpdates,
ActualAreaUpdates = left.ActualAreaUpdates + right.ActualAreaUpdates,
Updates = left.Updates + right.Updates,
DrawTime = left.DrawTime + right.DrawTime,
Draws = left.Draws + right.Draws
};
}
///
/// Subtracts two ui metrics from each other, causing their values to be subtracted.
///
/// The left metrics
/// The right metrics
/// The difference of both metrics
public static UiMetrics operator -(UiMetrics left, UiMetrics right) {
return new UiMetrics {
ForceAreaUpdateTime = left.ForceAreaUpdateTime - right.ForceAreaUpdateTime,
UpdateTime = left.UpdateTime - right.UpdateTime,
ForceAreaUpdates = left.ForceAreaUpdates - right.ForceAreaUpdates,
ActualAreaUpdates = left.ActualAreaUpdates - right.ActualAreaUpdates,
Updates = left.Updates - right.Updates,
DrawTime = left.DrawTime - right.DrawTime,
Draws = left.Draws - right.Draws
};
}
}
}