timing stuff

This commit is contained in:
Alug committed 2024-03-05 09:44:56 +01:00
1 parent f3ad43d6f2
commit 644a4dae31
2 files changed
+31 -21

No files matched your search

+2 -2
View File
@@ -6179,8 +6179,8 @@ boolean TryRunTics(tic_t realtics)
}
// Get packets from the server
double frame = ((double)SDL_GetPerformanceCounter() / tic_frequency);
netUpdateFudge = (((double)SDL_GetPerformanceCounter() / tic_frequency) - frame); // record the timefudge where the net update typically occurs
double frame = ((double)I_GetPreciseTime() / I_GetPrecisePrecision());
netUpdateFudge = (((double)I_GetPreciseTime() / I_GetPrecisePrecision()) - frame); // record the timefudge where the net update typically occurs
NetUpdate();
+29 -19
View File
@@ -938,43 +938,46 @@ static void Command_Saveloadtest(void)
#include "i_net.h"
extern int netUpdateFudge;
static void Command_Autotimefudge(void)
void Command_Autotimefudge(void)
{
UINT64 startTime = I_GetPrecisePrecision();
static UINT64 packetTimeFudge[512];
// you can use SDL_GetPerformanceFrequency() instead of tic_frequency to get more precise timings
double startTime = ((double)I_GetPreciseTime() / I_GetPrecisePrecision());
double packetTimeFudge[64];
int numReceivedPackets = 0;
int numSampleTics = 14;
const double numSampleTics = 10;
int i;
double lastTimeReceivedPacket;
if (server)
if (server && netgame)
{
if (netgame)
{
CONS_Printf("Servers do not need a time fudge! Heck, why are you hosting with this exe anyway? You don't need to ;)\n");
}
CONS_Printf("Servers do not need time fudging!\n");
return;
}
// New experimental version! Run a precise while loop that picks up packets instantly
while (I_GetPrecisePrecision() - startTime < ((UINT64)numSampleTics * 1000000 / NEWTICRATE))
lastTimeReceivedPacket = (double)SDL_GetPerformanceCounter() / I_GetPrecisePrecision();
while ((abs((double)SDL_GetPerformanceCounter() / I_GetPrecisePrecision() - startTime) < numSampleTics) || numReceivedPackets < 10)
{
I_NetGet();
if (doomcom->remotenode != -1 && I_GetPrecisePrecision() - startTime > (unsigned long long)2*1000000/NEWTICRATE) // wait a couple frames before recording
if ((doomcom->remotenode != -1)) // Packet received
{
unsigned long long frame = I_GetPrecisePrecision() * NEWTICRATE / 1000000;
packetTimeFudge[numReceivedPackets++] = (I_GetPrecisePrecision() - frame * 1000000 / NEWTICRATE) * 100 * NEWTICRATE / 1000000
- netUpdateFudge; // gets the time fudge offset (0-100)
packetTimeFudge[numReceivedPackets] = 100 * abs(((double)SDL_GetPerformanceCounter() / I_GetPrecisePrecision() - lastTimeReceivedPacket) - netUpdateFudge); // gets the time fudge offset (0-100)
CONS_Printf("%i: %d\n", numReceivedPackets, packetTimeFudge[numReceivedPackets]);
numReceivedPackets++;
lastTimeReceivedPacket = (double)SDL_GetPerformanceCounter() / I_GetPrecisePrecision();
}
}
if (numReceivedPackets > 0)
{
int minOffset = 100, maxOffset = 0, averageOffset = 0;
int newTimeFudge;
int estimatedRange;
UINT8 minOffset = 100, maxOffset = 0, averageOffset = 0;
UINT8 newTimeFudge;
UINT8 estimatedRange;
for (i = 0; i < numReceivedPackets; i++)
{
if (packetTimeFudge[i] < 0)
continue;
minOffset = min(minOffset, packetTimeFudge[i]);
maxOffset = max(maxOffset, packetTimeFudge[i]);
}
@@ -995,9 +998,15 @@ static void Command_Autotimefudge(void)
estimatedRange = maxOffset - minOffset;
averageOffset = (maxOffset + minOffset) / 2;
CONS_Printf("%i packets, min: %d max: %d avg: %d est. range: %d (mynetupdate: %i)\n", numReceivedPackets, minOffset, maxOffset, averageOffset,
CONS_Printf("%i packets received\n Timer fluctuations:\nmin: %d max: %d avg: %d est. range: %d (network update time: %lf)\n", numReceivedPackets, minOffset, maxOffset, averageOffset,
estimatedRange, netUpdateFudge);
if (averageOffset <= 0)
{
CONS_Printf("Timers are OK, no time fudging required\n");
return;
}
newTimeFudge = (cv_timefudge.value + averageOffset + 50) % 100;
CONS_Printf("New time fudge: %i%%\n", newTimeFudge);
@@ -1005,6 +1014,7 @@ static void Command_Autotimefudge(void)
}
}
// =========================================================================
// CLIENT STARTUP
// =========================================================================