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

@ -72,7 +72,7 @@ namespace Server
try
{
using var op = new StreamWriter("faction-power-items.log", true);
op.WriteLine("{0}\t{1}\t{2}\t{3}", DateTime.UtcNow, killer, victim, obj);
op.WriteLine("{0}\t{1}\t{2}\t{3}", Core.Now, killer, victim, obj);
}
catch
{

View file

@ -101,25 +101,10 @@ namespace Server.Factions
public bool IsCorrupting => m_Corrupting != null && m_Corrupting != m_Corrupted;
[CommandProperty(AccessLevel.GameMaster)]
public TimeSpan TimeUntilCorruption
{
get
{
if (!IsBeingCorrupted)
{
return TimeSpan.Zero;
}
var ts = CorruptionStart + CorruptionPeriod - DateTime.UtcNow;
if (ts < TimeSpan.Zero)
{
ts = TimeSpan.Zero;
}
return ts;
}
}
public TimeSpan TimeUntilCorruption =>
!IsBeingCorrupted ?
TimeSpan.Zero :
Utility.Max(CorruptionStart + CorruptionPeriod - Core.Now, TimeSpan.Zero);
public static List<Sigil> Sigils { get; } = new();
@ -263,7 +248,7 @@ namespace Server.Factions
private void BeginCorrupting(Faction faction)
{
m_Corrupting = faction;
CorruptionStart = DateTime.UtcNow;
CorruptionStart = Core.Now;
}
private void ClearCorrupting()
@ -340,7 +325,7 @@ namespace Server.Factions
BeginCorrupting(newController);
}
}
else if (GraceStart > DateTime.MinValue && GraceStart + CorruptionGrace < DateTime.UtcNow)
else if (GraceStart > DateTime.MinValue && GraceStart + CorruptionGrace < Core.Now)
{
if (m_Corrupted != newController)
{
@ -359,7 +344,7 @@ namespace Server.Factions
}
else if (GraceStart == DateTime.MinValue)
{
GraceStart = DateTime.UtcNow;
GraceStart = Core.Now;
}
PurificationStart = DateTime.MinValue;
@ -381,7 +366,7 @@ namespace Server.Factions
tm.Sigil = this;
m_Corrupting = null;
PurificationStart = DateTime.UtcNow;
PurificationStart = Core.Now;
CorruptionStart = DateTime.MinValue;
m_Town.Capture(m_Corrupted);

View file

@ -22,7 +22,7 @@ namespace Server.Factions
Visible = false;
Faction = f;
TimeOfPlacement = DateTime.UtcNow;
TimeOfPlacement = Core.Now;
Placer = m;
}
@ -204,7 +204,7 @@ namespace Server.Factions
return false;
}
if (TimeOfPlacement + decayPeriod < DateTime.UtcNow)
if (TimeOfPlacement + decayPeriod < Core.Now)
{
Timer.DelayCall(Delete);
return true;