fix: Fixes tick count calculcations (#1366)

This commit is contained in:
Kamron Batman 2023-03-09 21:00:17 -08:00 committed by GitHub
parent 0645251ec7
commit dda55889f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 23 additions and 35 deletions

View file

@ -120,6 +120,8 @@ public static class Core
public static Thread Thread { get; private set; }
private static long _firstTick;
[ThreadStatic]
private static long _tickCount;
@ -164,6 +166,8 @@ public static class Core
}
}
public static long Uptime => Thread.CurrentThread != Thread ? 0 : TickCount - _firstTick;
private static long _cycleIndex = 1;
private static float[] _cyclesPerSecond = new float[128];
@ -515,6 +519,7 @@ public static class Core
TcpServer.Start();
EventSink.InvokeServerStarted();
_firstTick = TickCount;
RunEventLoop();
}

View file

@ -39,21 +39,17 @@ public partial class NetState
var now = Core.TickCount;
var lastIndex = -1;
// Expire old steps
while (_expiredIndex != _stepIndex)
{
var step = _steps[_expiredIndex];
// Is the step ahead of us, or the next step rolled over and we didn't yet
if (step > now || lastIndex > -1 && _steps[lastIndex] > step)
if (step - now > 0)
{
break;
}
lastIndex = _expiredIndex++;
if (_expiredIndex == stepsLength)
{
_expiredIndex -= stepsLength;

View file

@ -164,7 +164,7 @@ public static class TcpServer
var ticks = Core.TickCount;
if (_nextMaximumSocketsReachedMessage <= ticks)
if (ticks - _nextMaximumSocketsReachedMessage > 0)
{
if (socket.RemoteEndPoint is IPEndPoint ipep)
{

View file

@ -240,8 +240,7 @@ namespace Server.Engines.Help
m.SendMessage("A new page has been placed in the queue.");
}
if (m?.AccessLevel >= AccessLevel.Counselor && m.AutoPageNotify &&
Core.TickCount - m.LastMoveTime < 600000)
if (m?.AccessLevel >= AccessLevel.Counselor && m.AutoPageNotify && Core.TickCount - m.LastMoveTime < 600000)
{
isStaffOnline = true;
}

View file

@ -184,7 +184,7 @@ namespace Server.Gumps
AddLabel(150, 270, LabelHue, Core.ScriptItems.ToString());
AddLabel(20, 290, LabelHue, "Uptime:");
AddLabel(150, 290, LabelHue, FormatTimeSpan(TimeSpan.FromMilliseconds(Core.TickCount)));
AddLabel(150, 290, LabelHue, FormatTimeSpan(TimeSpan.FromMilliseconds(Core.Uptime)));
AddLabel(20, 310, LabelHue, "Memory:");
AddLabel(150, 310, LabelHue, FormatByteAmount(GC.GetTotalMemory(false)));

View file

@ -141,7 +141,7 @@ namespace Server.Network
return true;
}
if (Core.TickCount < ns.GetPacketTime(packetID) + Delays[packetID])
if (Core.TickCount - ns.GetPacketTime(packetID) + Delays[packetID] > 0)
{
drop = true;
return false;

View file

@ -26,7 +26,7 @@ public abstract partial class MonsterAbility
/// <returns>Boolean indicating the ability can trigger.</returns>
public virtual bool CanTrigger(BaseCreature source, MonsterAbilityTrigger trigger)
{
if (_nextTriggerTicks?.TryGetValue(source, out var nextTrigger) == true && Core.TickCount < nextTrigger)
if (_nextTriggerTicks?.TryGetValue(source, out var nextTrigger) == true && nextTrigger - Core.TickCount > 0)
{
return false;
}

View file

@ -36,7 +36,7 @@ namespace Server.Network
public static void QueryCompactShardStats(NetState state, CircularBufferReader reader, int packetLength)
{
state.SendCompactShardStats(
(uint)(Core.TickCount / 1000),
(uint)(Core.Uptime / 1000),
TcpServer.Instances.Count - 1, // Shame if you modify this!
World.Items.Count,
World.Mobiles.Count,
@ -49,7 +49,7 @@ namespace Server.Network
const long ticksInHour = 1000 * 60 * 60;
state.SendExtendedShardStats(
ServerList.ServerName,
(int)(Core.TickCount / ticksInHour),
(int)(Core.Uptime / ticksInHour),
TcpServer.Instances.Count - 1, // Shame if you modify this!
World.Items.Count,
World.Mobiles.Count,

View file

@ -67,8 +67,8 @@ namespace Server.SkillHandlers
number = 500402; // You are too far away to beg from her.
}
}
else if (!Core.ML && from.Mounted
) // If we're on a mount, who would give us money? TODO: guessed it's removed since ML
// If we're on a mount, who would give us money? TODO: guessed it's removed since ML
else if (!Core.ML && from.Mounted)
{
number = 500404; // They seem unwilling to give you any money.
}
@ -119,11 +119,8 @@ namespace Server.SkillHandlers
}
else if (m_From.Karma < 0 && badKarmaChance > Utility.RandomDouble())
{
m_Target.PublicOverheadMessage(
MessageType.Regular,
m_Target.SpeechHue,
500406
); // Thou dost not look trustworthy... no gold for thee today!
// Thou dost not look trustworthy... no gold for thee today!
m_Target.PublicOverheadMessage(MessageType.Regular, m_Target.SpeechHue, 500406);
}
else if (m_From.CheckTargetSkill(SkillName.Begging, m_Target, 0.0, 100.0))
{
@ -150,11 +147,8 @@ namespace Server.SkillHandlers
if (consumed > 0)
{
m_Target.PublicOverheadMessage(
MessageType.Regular,
m_Target.SpeechHue,
500405
); // I feel sorry for thee...
// I feel sorry for thee...
m_Target.PublicOverheadMessage(MessageType.Regular, m_Target.SpeechHue, 500405);
var gold = new Gold(consumed);
@ -175,20 +169,14 @@ namespace Server.SkillHandlers
}
else
{
m_Target.PublicOverheadMessage(
MessageType.Regular,
m_Target.SpeechHue,
500407
); // I have not enough money to give thee any!
// I have not enough money to give thee any!
m_Target.PublicOverheadMessage(MessageType.Regular, m_Target.SpeechHue, 500407);
}
}
else
{
m_Target.PublicOverheadMessage(
MessageType.Regular,
m_Target.SpeechHue,
500407
); // I have not enough money to give thee any!
// I have not enough money to give thee any!
m_Target.PublicOverheadMessage(MessageType.Regular, m_Target.SpeechHue, 500407);
}
}
else