From cb7f2ad8af7b46060615e6a757fcff577c0a9f30 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Tue, 13 Jan 2026 05:40:53 +0500 Subject: [PATCH] engine: replace Sys_DoubleTime with Platform_DoubleTime in internal code, only use Sys_DoubleTime in APIs As Sys_DoubleTime is marked with GAME_EXPORT attribute that helps us to maintain compatible binary interface. --- engine/client/cl_main.c | 6 +++--- engine/client/cl_netgraph.c | 2 +- engine/client/cl_parse.c | 2 +- engine/client/cl_qparse.c | 2 +- engine/client/cl_scrn.c | 2 +- engine/client/console.c | 2 +- engine/client/mod_dbghulls.c | 4 ++-- engine/client/s_dsp.c | 4 ++-- engine/client/voice.c | 6 +++--- engine/common/base_cmd.c | 4 ++-- engine/common/common.c | 11 ----------- engine/common/host.c | 28 ++++++++++++++-------------- engine/common/imagelib/img_main.c | 6 +++--- engine/common/soundlib/snd_utils.c | 4 ++-- engine/common/system.c | 10 ++++++++++ engine/common/system.h | 3 ++- engine/server/sv_init.c | 4 ++-- engine/server/sv_phys.c | 4 ++-- 18 files changed, 52 insertions(+), 52 deletions(-) diff --git a/engine/client/cl_main.c b/engine/client/cl_main.c index 79586cfd..feee3cc4 100644 --- a/engine/client/cl_main.c +++ b/engine/client/cl_main.c @@ -223,7 +223,7 @@ static void CL_CheckClientState( void ) CL_ServerCommand(true, "specmode 4\n"); } - Con_DPrintf( "client connected at %.2f sec\n", Sys_DoubleTime() - cls.timestart ); + Con_DPrintf( "client connected at %.2f sec\n", Platform_DoubleTime() - cls.timestart ); } } @@ -1157,7 +1157,7 @@ static void CL_SendConnectPacket( connprotocol_t proto, int challenge ) Con_Printf( "Trying to connect with modern protocol\n" ); } - cls.timestart = Sys_DoubleTime(); + cls.timestart = Platform_DoubleTime(); } /* @@ -2740,7 +2740,7 @@ static void CL_ReadPackets( void ) return; // if in the debugger last frame, don't timeout - if( host.frametime > 5.0f ) cls.netchan.last_received = Sys_DoubleTime(); + if( host.frametime > 5.0f ) cls.netchan.last_received = Platform_DoubleTime(); // check timeout if( cls.state >= ca_connected && cls.state != ca_cinematic && !cls.demoplayback ) diff --git a/engine/client/cl_netgraph.c b/engine/client/cl_netgraph.c index 7dc79b17..74c6ce58 100644 --- a/engine/client/cl_netgraph.c +++ b/engine/client/cl_netgraph.c @@ -172,7 +172,7 @@ get frame data info, like chokes, packet losses, also update graph, packet and c static void NetGraph_GetFrameData( float *latency, int *latency_count ) { int i, choke_count = 0, loss_count = 0; - double newtime = Sys_DoubleTime(); + double newtime = Platform_DoubleTime(); static double nexttime = 0; float loss, choke; diff --git a/engine/client/cl_parse.c b/engine/client/cl_parse.c index e364a112..2375cc2e 100644 --- a/engine/client/cl_parse.c +++ b/engine/client/cl_parse.c @@ -876,7 +876,7 @@ void CL_ParseServerData( sizebuf_t *msg, connprotocol_t proto ) break; } - cls.timestart = Sys_DoubleTime(); + cls.timestart = Platform_DoubleTime(); cls.demowaiting = false; // server is changed // wipe the client_t struct diff --git a/engine/client/cl_qparse.c b/engine/client/cl_qparse.c index 0b34daae..b3aeaacd 100644 --- a/engine/client/cl_qparse.c +++ b/engine/client/cl_qparse.c @@ -188,7 +188,7 @@ static void CL_ParseQuakeServerInfo( sizebuf_t *msg ) int i; Con_Reportf( "Serverdata packet received.\n" ); - cls.timestart = Sys_DoubleTime(); + cls.timestart = Platform_DoubleTime(); cls.demowaiting = false; // server is changed diff --git a/engine/client/cl_scrn.c b/engine/client/cl_scrn.c index 7bf5b308..7471593f 100644 --- a/engine/client/cl_scrn.c +++ b/engine/client/cl_scrn.c @@ -73,7 +73,7 @@ void SCR_DrawFPS( int height ) default: return; } - newtime = Sys_DoubleTime(); + newtime = Platform_DoubleTime(); if( newtime >= nexttime ) { framerate = framecount / (newtime - lasttime); diff --git a/engine/client/console.c b/engine/client/console.c index 7d657180..6b981d66 100644 --- a/engine/client/console.c +++ b/engine/client/console.c @@ -1782,7 +1782,7 @@ void Con_DrawDebug( void ) { int length; Q_snprintf( dlstring, sizeof( dlstring ), "Downloading [%d remaining]: ^2%s^7 %5.1f%% time %.f secs", - host.downloadcount, host.downloadfile, scr_download.value, Sys_DoubleTime() - timeStart ); + host.downloadcount, host.downloadfile, scr_download.value, Platform_DoubleTime() - timeStart ); Con_DrawStringLen( dlstring, &length, NULL ); length = Q_max( length, 300 ); diff --git a/engine/client/mod_dbghulls.c b/engine/client/mod_dbghulls.c index 80a7af51..a1af8774 100644 --- a/engine/client/mod_dbghulls.c +++ b/engine/client/mod_dbghulls.c @@ -707,7 +707,7 @@ static void Mod_CreatePolygonsForHull( int hullnum ) Mod_InitDebugHulls( mod ); // FIXME: build hulls for separate bmodels (shells, medkits etc) Con_Printf( "generating polygons for hull %u...\n", hullnum ); - start = Sys_DoubleTime(); + start = Platform_DoubleTime(); // rebuild hulls list for( i = 0; i < world.num_hull_models; i++ ) @@ -718,7 +718,7 @@ static void Mod_CreatePolygonsForHull( int hullnum ) Q_snprintf( name, sizeof( name ), "*%i", i + 1 ); mod = Mod_FindName( name, false ); } - end = Sys_DoubleTime(); + end = Platform_DoubleTime(); Con_Printf( "build time %.3f secs\n", end - start ); } diff --git a/engine/client/s_dsp.c b/engine/client/s_dsp.c index 01cb7471..f2955dd2 100644 --- a/engine/client/s_dsp.c +++ b/engine/client/s_dsp.c @@ -935,12 +935,12 @@ static void SX_Profiling_f( void ) Con_Printf( "Profiling 10000 calls to DSP. Sample count is 512, room_type is %i\n", idsp_room ); - start = Sys_DoubleTime(); + start = Platform_DoubleTime(); for( calls = 10000; calls; calls-- ) { DSP_Process( testbuffer, 512 ); } - end = Sys_DoubleTime(); + end = Platform_DoubleTime(); Con_Printf( "----------\nTook %g seconds.\n", end - start ); diff --git a/engine/client/voice.c b/engine/client/voice.c index 005b89ef..9edde377 100644 --- a/engine/client/voice.c +++ b/engine/client/voice.c @@ -430,7 +430,7 @@ static uint Voice_GetOpusCompressedData( byte *out, uint maxsize, uint *frames ) if( voice.input_file ) { uint numbytes; - double updateInterval, curtime = Sys_DoubleTime(); + double updateInterval, curtime = Platform_DoubleTime(); updateInterval = curtime - voice.start_time; voice.start_time = curtime; @@ -505,7 +505,7 @@ static uint Voice_GetGSCompressedData( byte *out, uint maxsize, uint *frames ) if( voice.input_file ) { uint numbytes; - double updateInterval, curtime = Sys_DoubleTime(); + double updateInterval, curtime = Platform_DoubleTime(); updateInterval = curtime - voice.start_time; voice.start_time = curtime; @@ -875,7 +875,7 @@ void Voice_RecordStart( void ) Sound_Process( &voice.input_file, voice.samplerate, voice.width, VOICE_PCM_CHANNELS, SOUND_RESAMPLE ); voice.input_file_pos = 0; - voice.start_time = Sys_DoubleTime(); + voice.start_time = Platform_DoubleTime(); voice.is_recording = true; } else diff --git a/engine/common/base_cmd.c b/engine/common/base_cmd.c index 714cdd1d..d582fe7b 100644 --- a/engine/common/base_cmd.c +++ b/engine/common/base_cmd.c @@ -298,7 +298,7 @@ void BaseCmd_Test_f( void ) stats.valid = true; stats.lookups = 0; - start = Sys_DoubleTime() * 1000; + start = Platform_DoubleTime() * 1000; for( i = 0; i < 1000; i++ ) { @@ -328,7 +328,7 @@ void BaseCmd_Test_f( void ) Cvar_LookupVars( 0, NULL, &stats.valid, (setpair_t)BaseCmd_CheckCvars ); } - end = Sys_DoubleTime() * 1000; + end = Platform_DoubleTime() * 1000; dt = end - start; diff --git a/engine/common/common.c b/engine/common/common.c index 09d23018..3bd9dabf 100644 --- a/engine/common/common.c +++ b/engine/common/common.c @@ -886,17 +886,6 @@ int GAME_EXPORT COM_CheckParm( char *parm, char **ppnext ) return i; } -/* -============= -pfnTime - -============= -*/ -float GAME_EXPORT pfnTime( void ) -{ - return (float)Sys_DoubleTime(); -} - qboolean COM_IsSafeFileToDownload( const char *filename ) { char lwrfilename[4096]; diff --git a/engine/common/host.c b/engine/common/host.c index bf6cdf0e..3f1f0d89 100644 --- a/engine/common/host.c +++ b/engine/common/host.c @@ -107,17 +107,17 @@ static const feature_message_t engine_features[] = { ENGINE_STEP_POSHISTORY_LERP, "MOVETYPE_STEP Position History Based Lerping" }, }; -static void Sys_MakeVersionString( char *out, size_t len ) +static void Host_MakeVersionString( char *out, size_t len ) { Q_snprintf( out, len, XASH_ENGINE_NAME " %i/" XASH_VERSION " (%s-%s build %i)", PROTOCOL_VERSION, Q_buildos(), Q_buildarch(), Q_buildnum( )); } -static void Sys_PrintUsage( const char *exename ) +static void Host_PrintUsage( const char *exename ) { string version_str; const char *usage_str; - Sys_MakeVersionString( version_str, sizeof( version_str )); + Host_MakeVersionString( version_str, sizeof( version_str )); #if XASH_MESSAGEBOX != MSGBOX_STDERR #if XASH_WIN32 @@ -224,14 +224,14 @@ static void Sys_PrintUsage( const char *exename ) Sys_Quit( NULL ); } -static void Sys_PrintBugcompUsage( const char *exename ) +static void Host_PrintBugcompUsage( const char *exename ) { string version_str; char usage_str[4096]; char *p = usage_str; int i; - Sys_MakeVersionString( version_str, sizeof( version_str )); + Host_MakeVersionString( version_str, sizeof( version_str )); p += Q_snprintf( p, sizeof( usage_str ) - ( usage_str - p ), "Known bugcomp flags are:\n" ); for( i = 0; i < ARRAYSIZE( bugcomp_features ); i++ ) @@ -691,9 +691,9 @@ static qboolean Host_Autosleep( double dt, double scale ) { // Platform_Sleep isn't guaranteed to sleep an exact amount of microseconds // so we measure the real sleep time and use it to decrease the window - double t1 = Sys_DoubleTime(), t2; + double t1 = Platform_DoubleTime(), t2; Platform_NanoSleep( sleep * 1000 ); // in usec! - t2 = Sys_DoubleTime(); + t2 = Platform_DoubleTime(); realsleeptime = t2 - t1; timewindow -= realsleeptime; @@ -777,7 +777,7 @@ void Host_Frame( double time ) if( !Host_FilterTime( time )) return; - t1 = Sys_DoubleTime(); + t1 = Platform_DoubleTime(); if( host.framecount == 0 ) Con_DPrintf( "Time to first frame: %.3f seconds\n", t1 - host.starttime ); @@ -790,7 +790,7 @@ void Host_Frame( double time ) HTTP_Run(); // both server and client host.framecount++; - host.pureframetime = Sys_DoubleTime() - t1; + host.pureframetime = Platform_DoubleTime() - t1; } /* @@ -1021,10 +1021,10 @@ static void Host_InitCommon( int argc, char **argv, const char *progname, qboole string arg; if( Sys_CheckParm( "-help" ) || Sys_CheckParm( "-h" ) || Sys_CheckParm( "--help" )) - Sys_PrintUsage( exename ); + Host_PrintUsage( exename ); if( Sys_GetParmFromCmdLine( "-bugcomp", arg ) && !Q_stricmp( arg, "help" )) - Sys_PrintBugcompUsage( exename ); + Host_PrintBugcompUsage( exename ); } host.change_game = bChangeGame || Sys_CheckParm( "-changegame" ); @@ -1187,7 +1187,7 @@ int EXPORT Host_Main( int argc, char **argv, const char *progname, int bChangeGa if( setjmp( return_from_main_buf )) return error_on_exit; - host.starttime = Sys_DoubleTime(); + host.starttime = Platform_DoubleTime(); pChangeGame = func; // may be NULL @@ -1306,7 +1306,7 @@ int EXPORT Host_Main( int argc, char **argv, const char *progname, int bChangeGa if( Sys_GetParmFromCmdLine( "-timedemo", demoname )) Cbuf_AddTextf( "timedemo %s\n", demoname ); - oldtime = Sys_DoubleTime() - 0.1; + oldtime = Platform_DoubleTime() - 0.1; if( Host_IsDedicated( )) { @@ -1333,7 +1333,7 @@ int EXPORT Host_Main( int argc, char **argv, const char *progname, int bChangeGa // main window message loop while( host.status != HOST_CRASHED ) { - double newtime = Sys_DoubleTime(); + double newtime = Platform_DoubleTime(); COM_Frame( newtime - oldtime ); oldtime = newtime; } diff --git a/engine/common/imagelib/img_main.c b/engine/common/imagelib/img_main.c index 1d7cd952..c3079410 100644 --- a/engine/common/imagelib/img_main.c +++ b/engine/common/imagelib/img_main.c @@ -117,7 +117,7 @@ static void Image_ReportLookupsCount( const char *name ) static void Image_IncrementLookupTime( void ) { - double t = Sys_DoubleTime(); + double t = Platform_DoubleTime(); double dt = t - g_lookup_start; g_lookup_time += dt; @@ -125,7 +125,7 @@ static void Image_IncrementLookupTime( void ) g_lookups++; g_lookups_total++; - g_lookup_start = Sys_DoubleTime(); + g_lookup_start = Platform_DoubleTime(); } #else static void Image_ReportLookupsCount( const char *name ) @@ -164,7 +164,7 @@ void Image_Reset( void ) #if DEBUG_LOOKUPS_COUNT g_lookups = 0; g_lookup_time = 0.0f; - g_lookup_start = Sys_DoubleTime(); + g_lookup_start = Platform_DoubleTime(); #endif // DEBUG_LOOKUPS_COUNT } diff --git a/engine/common/soundlib/snd_utils.c b/engine/common/soundlib/snd_utils.c index 355a7093..2c315402 100644 --- a/engine/common/soundlib/snd_utils.c +++ b/engine/common/soundlib/snd_utils.c @@ -370,7 +370,7 @@ static qboolean Sound_ResampleInternal( wavdata_t *sc, int outrate, int outwidth if( inrate == outrate && inwidth == outwidth && inchannels == outchannels ) return false; - t1 = Sys_DoubleTime(); + t1 = Platform_DoubleTime(); stepscale = (double)inrate / outrate; // this is usually 0.5, 1, or 2 outcount = sc->samples / stepscale; @@ -404,7 +404,7 @@ static qboolean Sound_ResampleInternal( wavdata_t *sc, int outrate, int outwidth return false; } - t2 = Sys_DoubleTime(); + t2 = Platform_DoubleTime(); sc->rate = outrate; sc->width = outwidth; diff --git a/engine/common/system.c b/engine/common/system.c index d4f2e222..20de119e 100644 --- a/engine/common/system.c +++ b/engine/common/system.c @@ -67,6 +67,16 @@ double GAME_EXPORT Sys_DoubleTime( void ) return Platform_DoubleTime(); } +/* +=============== +Sys_FloatTime +=============== +*/ +float GAME_EXPORT Sys_FloatTime( void ) +{ + return (float)Platform_DoubleTime(); +} + /* ================ Sys_DebugBreak diff --git a/engine/common/system.h b/engine/common/system.h index 0b79ed64..180f0854 100644 --- a/engine/common/system.h +++ b/engine/common/system.h @@ -51,7 +51,8 @@ typedef struct dll_info_s } dll_info_t; extern int error_on_exit; -double Sys_DoubleTime( void ); +double GAME_EXPORT Sys_DoubleTime( void ); // only for binary compatibility, use Platform_DoubleTime instead +float GAME_EXPORT Sys_FloatTime( void ); // only for binary compatibility, use Platform_DoubleTime instead char *Sys_GetClipboardData( void ); const char *Sys_GetCurrentUser( void ); int Sys_CheckParm( const char *parm ); diff --git a/engine/server/sv_init.c b/engine/server/sv_init.c index 27d19c1e..a18ad71e 100644 --- a/engine/server/sv_init.c +++ b/engine/server/sv_init.c @@ -664,7 +664,7 @@ void SV_ActivateServer( int runPhysics ) host.movevars_changed = true; Host_SetServerState( ss_active ); - Con_DPrintf( "level loaded at %.2f sec\n", Sys_DoubleTime() - svs.timestart ); + Con_DPrintf( "level loaded at %.2f sec\n", Platform_DoubleTime() - svs.timestart ); if( sv.ignored_static_ents ) Con_Printf( S_WARN "%i static entities was rejected due buffer overflow\n", sv.ignored_static_ents ); @@ -1027,7 +1027,7 @@ qboolean SV_SpawnServer( const char *mapname, const char *startspot, qboolean ba Log_Printf( "Loading map \"%s\"\n", mapname ); Log_PrintServerVars(); - svs.timestart = Sys_DoubleTime(); + svs.timestart = Platform_DoubleTime(); svs.spawncount++; // any partially connected client will be restarted for( i = 0; i < ARRAYSIZE( svs.challenge_salt ); i++ ) diff --git a/engine/server/sv_phys.c b/engine/server/sv_phys.c index 86e9527c..c360c6e5 100644 --- a/engine/server/sv_phys.c +++ b/engine/server/sv_phys.c @@ -74,11 +74,11 @@ static void SV_CheckAllEnts( void ) if( !sv_check_errors.value || sv.state != ss_active ) return; - if(( nextcheck - Sys_DoubleTime()) > 0.0 ) + if(( nextcheck - Platform_DoubleTime()) > 0.0 ) return; // don't check entities every frame (but every 5 secs) - nextcheck = Sys_DoubleTime() + 5.0; + nextcheck = Platform_DoubleTime() + 5.0; // check edicts errors for( i = svs.maxclients + 1; i < svgame.numEntities; i++ )