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

@ -20,7 +20,7 @@ namespace UOContent.Tests
).Compile();
var ns = PacketTestUtilities.CreateTestNetState();
BuffInfo.SendAddBuffPacket(ns, mob, iconID, titleCliloc, secondaryCliloc, args, timeSpan);
BuffInfo.SendAddBuffPacket(ns, mob, iconID, titleCliloc, secondaryCliloc, args, (int)timeSpan.TotalMilliseconds);
var result = ns.SendPipe.Reader.TryRead();
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);

View file

@ -11,7 +11,9 @@ namespace Server.Network
info.TitleCliloc,
info.SecondaryCliloc,
info.Args,
info.TimeStart != DateTime.MinValue ? info.TimeStart + info.TimeLength - DateTime.UtcNow : TimeSpan.Zero
info.TimeStart != 0 ?
TimeSpan.FromMilliseconds(info.TimeStart + (long)info.TimeLength.TotalMilliseconds - Core.TickCount) :
TimeSpan.Zero
)
{
}
@ -37,12 +39,7 @@ namespace Server.Network
Stream.Fill(4);
if (length < TimeSpan.Zero)
{
length = TimeSpan.Zero;
}
Stream.Write((short)length.TotalSeconds); // Time in seconds
Stream.Write((short)Math.Max(length.TotalSeconds, 0)); // Time in seconds
Stream.Fill(3);
Stream.Write(titleCliloc);