From 81aba34c6bf1799cd47ae745e4340220554772fd Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 6 Mar 2024 02:14:26 +0100 Subject: [PATCH] try and fix some fudge timing stuff --- src/d_clisrv.c | 4 ++-- src/d_netcmd.c | 12 ++++++------ src/i_system.h | 1 + src/sdl/i_system.c | 5 ++++- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index ac3722879..675f69ef9 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -6195,8 +6195,8 @@ boolean TryRunTics(tic_t realtics) } // Get packets from the server - double frame = ((double)I_GetPreciseTime() / I_GetPrecisePrecision()); - netUpdateFudge = (((double)I_GetPreciseTime() / I_GetPrecisePrecision()) - frame); // record the timefudge where the net update typically occurs + double frame = ((double)I_GetPreciseTime() / tic_frequency); + netUpdateFudge = (((double)I_GetPreciseTime() / tic_frequency) - frame); // record the timefudge where the net update typically occurs NetUpdate(); diff --git a/src/d_netcmd.c b/src/d_netcmd.c index cfe091f2a..84ce4f4c4 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -577,7 +577,7 @@ static CV_PossibleValue_t netdelay_cons_t[] = { {0, "MIN"}, {250, "MAX"}, {0, NU consvar_t cv_netdelay = { "netdelay", "0", 0, netdelay_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; static CV_PossibleValue_t netjitter_cons_t[] = { {0, "MIN"}, {5, "MAX"}, {0, NULL} }; -consvar_t cv_netjitter = { "netjitter", "0", 0, netdelay_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; +consvar_t cv_netjitter = { "netjitter", "0", 0, netjitter_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; consvar_t cv_netsmoothing = { "netsmoothing", "Off", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL }; @@ -858,7 +858,7 @@ extern double netUpdateFudge; void Command_Autotimefudge(void) { // you can use SDL_GetPerformanceFrequency() instead of tic_frequency to get more precise timings - double startTime = ((double)I_GetPreciseTime() / I_GetPrecisePrecision()); + double startTime = ((double)I_GetPreciseTime() / tic_frequency); double packetTimeFudge[64]; int numReceivedPackets = 0; const double numSampleTics = 10; @@ -871,16 +871,16 @@ void Command_Autotimefudge(void) return; } - lastTimeReceivedPacket = (double)SDL_GetPerformanceCounter() / I_GetPrecisePrecision(); - while ((abs((double)SDL_GetPerformanceCounter() / I_GetPrecisePrecision() - startTime) < numSampleTics) || numReceivedPackets < 10) + lastTimeReceivedPacket = (double)SDL_GetPerformanceCounter() / tic_frequency; + while ((abs((double)SDL_GetPerformanceCounter() / tic_frequency - startTime) < numSampleTics) || numReceivedPackets < 10) { I_NetGet(); if ((doomcom->remotenode != -1)) // Packet received { - packetTimeFudge[numReceivedPackets] = 100 * abs(((double)I_GetPreciseTime() / I_GetPrecisePrecision() - lastTimeReceivedPacket) - netUpdateFudge); // gets the time fudge offset (0-100) + packetTimeFudge[numReceivedPackets] = 100 * abs(((double)I_GetPreciseTime() / tic_frequency - lastTimeReceivedPacket) - netUpdateFudge); // gets the time fudge offset (0-100) CONS_Printf("%i: %d\n", numReceivedPackets, packetTimeFudge[numReceivedPackets]); numReceivedPackets++; - lastTimeReceivedPacket = (double)I_GetPreciseTime() / I_GetPrecisePrecision(); + lastTimeReceivedPacket = (double)I_GetPreciseTime() / tic_frequency; } } diff --git a/src/i_system.h b/src/i_system.h index 716890e67..9c27cef88 100644 --- a/src/i_system.h +++ b/src/i_system.h @@ -25,6 +25,7 @@ */ #define MAX_QUIT_FUNCS 16 +extern double tic_frequency; /** \brief Graphic system had started up */ diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 1cc1c23e0..33d0dcf39 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -3180,6 +3180,7 @@ static int lastTimeFudge = -1; extern consvar_t cv_timefudge; static Uint64 timer_frequency; +double tic_frequency; precise_t I_GetPreciseTime(void) { @@ -3197,7 +3198,7 @@ void I_SetTime(tic_t tic, int fudge, boolean useAbsoluteFudge) { tic = max(tic, SDL_GetTicks()); if (useAbsoluteFudge) - elapsed = elapsed + (fudge / 100) * SDL_GetPerformanceFrequency(); + elapsed = elapsed + (fudge / 100) * tic_frequency; } @@ -3258,6 +3259,8 @@ void I_StartupTimer(void) I_InitFrameTime(0, R_GetFramerateCap()); elapsed_frames = 0.0; + + tic_frequency = timer_frequency / (double)NEWTICRATE; } void I_Sleep(UINT32 ms)