From d4f62befb2f78b36f9ca483425daacabf4a065e7 Mon Sep 17 00:00:00 2001 From: Mag-nus Date: Tue, 13 Feb 2024 16:20:07 -0600 Subject: [PATCH 1/2] Switch PhysicsTimer PhysicsTimer.CurrentTime evalulated the stopwatch every single call. This simply redirects the timer to use the master Timers.PortalYearTicks timer --- Source/ACE.Server/Physics/Common/PhysicsTimer.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Source/ACE.Server/Physics/Common/PhysicsTimer.cs b/Source/ACE.Server/Physics/Common/PhysicsTimer.cs index 9cdee9dd6e..e2e023f54f 100644 --- a/Source/ACE.Server/Physics/Common/PhysicsTimer.cs +++ b/Source/ACE.Server/Physics/Common/PhysicsTimer.cs @@ -1,5 +1,7 @@ using System.Diagnostics; +using ACE.Server.Entity; + namespace ACE.Server.Physics.Common { /// @@ -10,11 +12,14 @@ public class PhysicsTimer { private static readonly Stopwatch _timer; + /* /// /// This should only be used by the ACE.Server.Physics namespace and physics related properties /// For a equally precise timer outside of this namespace, you can use WorldManager.PortalYearTicks /// public static double CurrentTime => _timer.Elapsed.TotalSeconds; + */ + public static double CurrentTime => Timers.PortalYearTicks; static PhysicsTimer() { From 19d60b6581cdab07cd3b2957db6f006853fa5c67 Mon Sep 17 00:00:00 2001 From: Mag-nus Date: Sun, 24 Mar 2024 09:23:09 -0500 Subject: [PATCH 2/2] Update PhysicsTimer.cs --- .../ACE.Server/Physics/Common/PhysicsTimer.cs | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/Source/ACE.Server/Physics/Common/PhysicsTimer.cs b/Source/ACE.Server/Physics/Common/PhysicsTimer.cs index e2e023f54f..b31925ff57 100644 --- a/Source/ACE.Server/Physics/Common/PhysicsTimer.cs +++ b/Source/ACE.Server/Physics/Common/PhysicsTimer.cs @@ -1,4 +1,4 @@ -using System.Diagnostics; +using System; using ACE.Server.Entity; @@ -10,20 +10,19 @@ namespace ACE.Server.Physics.Common /// public class PhysicsTimer { - private static readonly Stopwatch _timer; + // When using PhysicsTimer outside of a running ACE instance, you must uncomment these lines and use this version of the timer. Otherwise, your CurrentTime will not increment. + // You can use this method when running in an ACE instance, it's just less efficient. + /*private static readonly System.Diagnostics.Stopwatch _timer; - /* - /// - /// This should only be used by the ACE.Server.Physics namespace and physics related properties - /// For a equally precise timer outside of this namespace, you can use WorldManager.PortalYearTicks - /// public static double CurrentTime => _timer.Elapsed.TotalSeconds; - */ - public static double CurrentTime => Timers.PortalYearTicks; static PhysicsTimer() { - _timer = Stopwatch.StartNew(); - } + _timer = System.Diagnostics.Stopwatch.StartNew(); + }*/ + + + // When using PhysicsTimer in a running ACE instance, you should use this timer instead. It is more efficient. Timers.PortalYearTicks is incremented by the WorldManager. + public static double CurrentTime => Timers.PortalYearTicks; } }