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

@ -310,12 +310,9 @@ namespace Server.Engines.ConPVP
}
public Mobile Ignored => m_Ignored;
public bool Expired => DateTime.UtcNow >= m_Expire;
public bool Expired => Core.Now >= m_Expire;
public void Refresh()
{
m_Expire = DateTime.UtcNow + ExpireDelay;
}
public void Refresh() => m_Expire = Core.Now + ExpireDelay;
}
}
}

View file

@ -1298,7 +1298,7 @@ namespace Server.Engines.ConPVP
{
foreach (var info in m.Aggressed)
{
if (info.Defender.Player && DateTime.UtcNow - info.LastCombatTime < CombatDelay)
if (info.Defender.Player && Core.Now - info.LastCombatTime < CombatDelay)
{
return true;
}
@ -1306,7 +1306,7 @@ namespace Server.Engines.ConPVP
foreach (var info in m.Aggressors)
{
if (info.Attacker.Player && DateTime.UtcNow - info.LastCombatTime < CombatDelay)
if (info.Attacker.Player && Core.Now - info.LastCombatTime < CombatDelay)
{
return true;
}
@ -2601,7 +2601,7 @@ namespace Server.Engines.ConPVP
Mobile = mob;
Location = loc;
Facet = facet;
m_Expire = DateTime.UtcNow + TimeSpan.FromMinutes(30.0);
m_Expire = Core.Now + TimeSpan.FromMinutes(30.0);
}
public Mobile Mobile { get; }
@ -2610,7 +2610,7 @@ namespace Server.Engines.ConPVP
public Map Facet { get; private set; }
public bool Expired => DateTime.UtcNow >= m_Expire;
public bool Expired => Core.Now >= m_Expire;
public void Return()
{
@ -2633,7 +2633,7 @@ namespace Server.Engines.ConPVP
public void Update()
{
m_Expire = DateTime.UtcNow + TimeSpan.FromMinutes(30.0);
m_Expire = Core.Now + TimeSpan.FromMinutes(30.0);
if (Mobile.Map == Map.Internal)
{

View file

@ -313,7 +313,7 @@ namespace Server.Engines.ConPVP
}
m_Returner = from;
m_ReturnTime = DateTime.UtcNow;
m_ReturnTime = Core.Now;
SendHome();
@ -356,7 +356,7 @@ namespace Server.Engines.ConPVP
public void DropTo(Mobile mob, Mobile killer)
{
m_Fragger = killer;
m_FragTime = DateTime.UtcNow;
m_FragTime = Core.Now;
if (mob != null)
{
@ -464,7 +464,7 @@ namespace Server.Engines.ConPVP
var teamFlag = useTeam.Flag;
if (teamFlag.m_Fragger != null &&
DateTime.UtcNow < teamFlag.m_FragTime + TimeSpan.FromSeconds(5.0) &&
Core.Now < teamFlag.m_FragTime + TimeSpan.FromSeconds(5.0) &&
m_TeamInfo.Game.GetTeamInfo(teamFlag.m_Fragger) == useTeam)
{
var assistInfo = useTeam[teamFlag.m_Fragger];
@ -476,7 +476,7 @@ namespace Server.Engines.ConPVP
}
if (teamFlag.m_Returner != null &&
DateTime.UtcNow < teamFlag.m_ReturnTime + TimeSpan.FromSeconds(5.0))
Core.Now < teamFlag.m_ReturnTime + TimeSpan.FromSeconds(5.0))
{
var assistInfo = useTeam[teamFlag.m_Returner];

View file

@ -514,7 +514,7 @@ namespace Server.Engines.ConPVP
string timeUntil;
var minutesUntil = (int)Math.Round(
(tourney.SignupStart + tourney.SignupPeriod - DateTime.UtcNow)
(tourney.SignupStart + tourney.SignupPeriod - Core.Now)
.TotalMinutes
);

View file

@ -99,7 +99,7 @@ namespace Server.Engines.ConPVP
if (m_Tournament.Stage == TournamentStage.Signup)
{
var until = m_Tournament.SignupStart + m_Tournament.SignupPeriod - DateTime.UtcNow;
var until = m_Tournament.SignupStart + m_Tournament.SignupPeriod - Core.Now;
string text;
var secs = (int)until.TotalSeconds;

View file

@ -681,7 +681,7 @@ namespace Server.Engines.ConPVP
{
if (CurrentStage == TournamentStage.Signup)
{
var until = SignupStart + SignupPeriod - DateTime.UtcNow;
var until = SignupStart + SignupPeriod - Core.Now;
if (until <= TimeSpan.Zero)
{
@ -741,7 +741,7 @@ namespace Server.Engines.ConPVP
else
{
/*Alert( "Is this all?", "Pitiful. Signup extended." );
m_SignupStart = DateTime.UtcNow;*/
m_SignupStart = Core.Now;*/
Alert("Is this all?", "Pitiful. Tournament cancelled.");
CurrentStage = TournamentStage.Inactive;

View file

@ -128,7 +128,7 @@ namespace Server.Engines.ConPVP
{
if (m_Tournament.Stage == TournamentStage.Inactive)
{
m_Tournament.SignupStart = DateTime.UtcNow;
m_Tournament.SignupStart = Core.Now;
m_Tournament.Stage = TournamentStage.Signup;
m_Tournament.Participants.Clear();
m_Tournament.Pyramid.Levels.Clear();

View file

@ -19,7 +19,7 @@ namespace Server.Items
{
Title = title;
m_Rank = rank;
Date = DateTime.UtcNow;
Date = Core.Now;
LootType = LootType.Blessed;