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)
{