From 01c0e214400e406eb320611b7ba31ea059d2fb5e Mon Sep 17 00:00:00 2001 From: Raymond Date: Tue, 7 Sep 2021 22:47:23 -0400 Subject: [PATCH] use stopwatch for more precise delta --- Dalamud/Game/Framework.cs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Dalamud/Game/Framework.cs b/Dalamud/Game/Framework.cs index 6258b51c6..2ba584ae1 100644 --- a/Dalamud/Game/Framework.cs +++ b/Dalamud/Game/Framework.cs @@ -25,6 +25,7 @@ namespace Dalamud.Game public sealed class Framework : IDisposable { private static Stopwatch statsStopwatch = new(); + private Stopwatch updateStopwatch = new(); private Hook updateHook; private Hook destroyHook; @@ -93,10 +94,15 @@ namespace Dalamud.Game public FrameworkAddressResolver Address { get; } /// - /// Gets the last time the Framework Update event was triggered. + /// Gets the last time that the Framework Update event was triggered. /// public DateTime LastUpdate { get; private set; } = DateTime.MinValue; + /// + /// Gets the last time in UTC that the Framework Update event was triggered. + /// + public DateTime LastUpdateUTC { get; private set; } = DateTime.MinValue; + /// /// Gets the delta between the last Framework Update and the currently executing one. /// @@ -137,6 +143,9 @@ namespace Dalamud.Game this.updateHook?.Dispose(); this.destroyHook?.Dispose(); this.realDestroyHook?.Dispose(); + + this.updateStopwatch.Reset(); + statsStopwatch.Reset(); } private void HookVTable() @@ -183,9 +192,12 @@ namespace Dalamud.Game if (this.DispatchUpdateEvents) { - var now = DateTime.Now; - this.UpdateDelta = now - this.LastUpdate; - this.LastUpdate = now; + this.updateStopwatch.Stop(); + this.UpdateDelta = TimeSpan.FromMilliseconds(this.updateStopwatch.ElapsedMilliseconds); + this.updateStopwatch.Restart(); + + this.LastUpdate = DateTime.Now; + this.LastUpdateUTC = DateTime.UtcNow; try {