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

@ -67,7 +67,7 @@ namespace Server.Factions
set
{
CurrentState = value;
LastStateTime = DateTime.UtcNow;
LastStateTime = Core.Now;
}
}
@ -89,12 +89,7 @@ namespace Server.Factions
_ => PendingPeriod
};
var until = LastStateTime + period - DateTime.UtcNow;
if (until < TimeSpan.Zero)
{
until = TimeSpan.Zero;
}
var until = Utility.Max(LastStateTime + period - Core.Now, TimeSpan.Zero);
return until;
}
@ -108,7 +103,7 @@ namespace Server.Factions
_ => PendingPeriod
};
LastStateTime = DateTime.UtcNow - period + value;
LastStateTime = Core.Now - period + value;
}
}
@ -290,7 +285,7 @@ namespace Server.Factions
{
case ElectionState.Pending:
{
if (LastStateTime + PendingPeriod > DateTime.UtcNow)
if (LastStateTime + PendingPeriod > Core.Now)
{
break;
}
@ -304,7 +299,7 @@ namespace Server.Factions
}
case ElectionState.Campaign:
{
if (LastStateTime + CampaignPeriod > DateTime.UtcNow)
if (LastStateTime + CampaignPeriod > Core.Now)
{
break;
}
@ -346,7 +341,7 @@ namespace Server.Factions
}
case ElectionState.Election:
{
if (LastStateTime + VotingPeriod > DateTime.UtcNow)
if (LastStateTime + VotingPeriod > Core.Now)
{
break;
}
@ -413,7 +408,7 @@ namespace Server.Factions
Address = IPAddress.None;
}
Time = DateTime.UtcNow;
Time = Core.Now;
}
public Voter(IGenericReader reader, Mobile candidate)