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:
parent
5de6edbeb8
commit
6c4308bce6
208 changed files with 660 additions and 793 deletions
|
|
@ -185,7 +185,7 @@ namespace Server.Gumps
|
|||
AddLabel(150, 270, LabelHue, Core.ScriptItems.ToString());
|
||||
|
||||
AddLabel(20, 290, LabelHue, "Uptime:");
|
||||
AddLabel(150, 290, LabelHue, FormatTimeSpan(DateTime.UtcNow - Clock.ServerStart));
|
||||
AddLabel(150, 290, LabelHue, FormatTimeSpan(Core.Now - Clock.ServerStart));
|
||||
|
||||
AddLabel(20, 310, LabelHue, "Memory:");
|
||||
AddLabel(150, 310, LabelHue, FormatByteAmount(GC.GetTotalMemory(false)));
|
||||
|
|
@ -902,17 +902,7 @@ namespace Server.Gumps
|
|||
}
|
||||
else
|
||||
{
|
||||
var remaining = DateTime.UtcNow - banTime;
|
||||
|
||||
if (remaining < TimeSpan.Zero)
|
||||
{
|
||||
remaining = TimeSpan.Zero;
|
||||
}
|
||||
else if (remaining > banDuration)
|
||||
{
|
||||
remaining = banDuration;
|
||||
}
|
||||
|
||||
var remaining = (Core.Now - banTime).Clamp(TimeSpan.Zero, banDuration);
|
||||
var remMinutes = remaining.TotalMinutes;
|
||||
var totMinutes = banDuration.TotalMinutes;
|
||||
|
||||
|
|
|
|||
|
|
@ -229,7 +229,7 @@ namespace Server.Gumps
|
|||
{
|
||||
var a = m_List[i];
|
||||
|
||||
a.SetBanTags(from, DateTime.UtcNow, duration);
|
||||
a.SetBanTags(from, Core.Now, duration);
|
||||
|
||||
if (comment != null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ namespace Server.Gumps
|
|||
{
|
||||
m_Mobile.SendLocalizedMessage(1010405); // You cannot change guild types while in a Faction!
|
||||
}
|
||||
else if (m_Guild.TypeLastChange.AddDays(7) > DateTime.UtcNow)
|
||||
else if (m_Guild.TypeLastChange.AddDays(7) > Core.Now)
|
||||
{
|
||||
m_Mobile.SendLocalizedMessage(1011142); // You have already changed your guild type recently.
|
||||
// TODO: Clilocs 1011142-1011145 suggest a timer for pending changes
|
||||
|
|
|
|||
|
|
@ -70,9 +70,9 @@ namespace Server.Guilds
|
|||
|
||||
var timeRemaining = TimeSpan.Zero;
|
||||
|
||||
if (activeWar.WarLength != TimeSpan.Zero && activeWar.WarBeginning + activeWar.WarLength > DateTime.UtcNow)
|
||||
if (activeWar.WarLength != TimeSpan.Zero && activeWar.WarBeginning + activeWar.WarLength > Core.Now)
|
||||
{
|
||||
timeRemaining = activeWar.WarBeginning + activeWar.WarLength - DateTime.UtcNow;
|
||||
timeRemaining = activeWar.WarBeginning + activeWar.WarLength - Core.Now;
|
||||
}
|
||||
|
||||
time = $"{timeRemaining.Hours:D2}:{DateTime.MinValue + timeRemaining:mm}";
|
||||
|
|
@ -234,7 +234,7 @@ namespace Server.Guilds
|
|||
{
|
||||
// Accept the war
|
||||
guild.PendingWars.Remove(war);
|
||||
war.WarBeginning = DateTime.UtcNow;
|
||||
war.WarBeginning = Core.Now;
|
||||
guild.AcceptedWars.Add(war);
|
||||
|
||||
if (alliance?.IsMember(guild) == true)
|
||||
|
|
@ -260,7 +260,7 @@ namespace Server.Guilds
|
|||
// Technically SHOULD say Your guild is now at war w/out any info, intentional diff.
|
||||
|
||||
otherGuild.PendingWars.Remove(otherWar);
|
||||
otherWar.WarBeginning = DateTime.UtcNow;
|
||||
otherWar.WarBeginning = Core.Now;
|
||||
otherGuild.AcceptedWars.Add(otherWar);
|
||||
|
||||
if (otherAlliance != null && m_Other.Alliance.IsMember(m_Other))
|
||||
|
|
|
|||
|
|
@ -1510,7 +1510,7 @@ namespace Server.Gumps
|
|||
); // You cannot redeed a house with a guildstone inside.
|
||||
}
|
||||
else if (Core.ML && from.AccessLevel < AccessLevel.GameMaster &&
|
||||
DateTime.UtcNow <= m_House.BuiltOn.AddHours(1))
|
||||
Core.Now <= m_House.BuiltOn.AddHours(1))
|
||||
{
|
||||
from.SendLocalizedMessage(
|
||||
1080178
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ namespace Server.Gumps
|
|||
}
|
||||
}
|
||||
|
||||
if (ai.Attacker.Player && DateTime.UtcNow - ai.LastCombatTime < TimeSpan.FromSeconds(30.0) &&
|
||||
if (ai.Attacker.Player && Core.Now - ai.LastCombatTime < TimeSpan.FromSeconds(30.0) &&
|
||||
!toGive.Contains(ai.Attacker))
|
||||
{
|
||||
toGive.Add(ai.Attacker);
|
||||
|
|
@ -52,7 +52,7 @@ namespace Server.Gumps
|
|||
|
||||
foreach (var ai in m.Aggressed)
|
||||
{
|
||||
if (ai.Defender.Player && DateTime.UtcNow - ai.LastCombatTime < TimeSpan.FromSeconds(30.0) &&
|
||||
if (ai.Defender.Player && Core.Now - ai.LastCombatTime < TimeSpan.FromSeconds(30.0) &&
|
||||
!toGive.Contains(ai.Defender))
|
||||
{
|
||||
toGive.Add(ai.Defender);
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ namespace Server.Gumps
|
|||
|
||||
AddLabel(45, y, 0x481, $"{inventory.ShopName} ({inventory.VendorName})");
|
||||
|
||||
var expire = inventory.ExpireTime - DateTime.UtcNow;
|
||||
var expire = inventory.ExpireTime - Core.Now;
|
||||
var hours = (int)expire.TotalHours;
|
||||
|
||||
AddLabel(320, y, 0x481, hours.ToString());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue