fix(core): Caches DateTime.NowUtc (#548)

- [X] Caches DateTime.NowUtc on the game loop (not other threads)
- [X] Replaces all locations where it makes sense
- [X] Adds Min/Max for `IComparable` (TimeSpan, DateTimes, etc)

Closes #261
This commit is contained in:
Kamron Batman 2021-03-13 01:32:04 -08:00 • committed by GitHub
parent 5de6edbeb8
commit 6c4308bce6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
208 changed files with 660 additions and 793 deletions

View file

@ -13,9 +13,9 @@ namespace Server.Engines.Events
public static void Initialize()
{
var now = DateTime.UtcNow;
var now = Core.Now;
if (DateTime.UtcNow >= HolidaySettings.StartHalloween && DateTime.UtcNow <= HolidaySettings.FinishHalloween)
if (now >= HolidaySettings.StartHalloween && now <= HolidaySettings.FinishHalloween)
{
EventSink.Speech += EventSink_Speech;
}
@ -165,7 +165,7 @@ namespace Server.Engines.Events
return;
}
var now = DateTime.UtcNow;
var now = Core.Now;
if (CheckMobile(begged))
{

View file

@ -23,7 +23,7 @@ namespace Server.Engines.Events
public static void Initialize()
{
var now = DateTime.UtcNow;
var now = Core.Now;
if (now >= HolidaySettings.StartHalloween && now <= HolidaySettings.FinishHalloween)
{

View file

@ -48,7 +48,7 @@ namespace Server.Engines.Events
m_QueueDelaySeconds = 120;
m_QueueClearIntervalSeconds = 1800;
var today = DateTime.UtcNow;
var today = Core.Now;
var tick = TimeSpan.FromSeconds(m_QueueDelaySeconds);
var clear = TimeSpan.FromSeconds(m_QueueClearIntervalSeconds);
@ -80,7 +80,7 @@ namespace Server.Engines.Events
m_DeathQueue.Clear();
if (DateTime.UtcNow <= HolidaySettings.FinishHalloween)
if (Core.Now <= HolidaySettings.FinishHalloween)
{
m_ClearTimer.Stop();
}
@ -90,7 +90,7 @@ namespace Server.Engines.Events
{
PlayerMobile player = null;
if (DateTime.UtcNow <= HolidaySettings.FinishHalloween)
if (Core.Now <= HolidaySettings.FinishHalloween)
{
for (var index = 0; m_DeathQueue.Count > 0 && index < m_DeathQueue.Count; index++)
{

View file

@ -86,7 +86,7 @@ namespace Server.Items
public bool IsSigned => m_Line1 != null || m_Line2 != null || m_Line3 != null;
public bool CanSign => !IsSigned || DateTime.UtcNow <= EditLimit;
public bool CanSign => !IsSigned || Core.Now <= EditLimit;
public override void AddNameProperty(ObjectPropertyList list)
{
@ -237,7 +237,7 @@ namespace Server.Items
if (!m_Bear.IsSigned)
{
m_Bear.EditLimit = DateTime.UtcNow + TimeSpan.FromMinutes(10);
m_Bear.EditLimit = Core.Now + TimeSpan.FromMinutes(10);
}
m_Bear.Line1 = Utility.FixHtml(line1);

View file

@ -57,7 +57,7 @@ namespace Server.Items
public static bool CheckSeason(Mobile from)
{
if (DateTime.UtcNow.Month == 2)
if (Core.Now.Month == 2)
{
return true;
}