From 1d4f7b2f947d6d9ae21d3a02c08de275cde08d7f Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Tue, 14 Jan 2025 12:04:48 +0300 Subject: [PATCH] engine: server: slight refactoring, make SV_ModelHandle inlined, move PlayerIsFrozen to sv_client, fix packet loss data type --- engine/server/server.h | 17 +++++++++++-- engine/server/sv_client.c | 53 +++++++++++++++++++++------------------ engine/server/sv_frame.c | 7 +++--- engine/server/sv_init.c | 14 ----------- engine/server/sv_pmove.c | 13 ---------- 5 files changed, 47 insertions(+), 57 deletions(-) diff --git a/engine/server/server.h b/engine/server/server.h index f1e6fad0..d7c92347 100644 --- a/engine/server/server.h +++ b/engine/server/server.h @@ -498,10 +498,24 @@ qboolean SV_ProcessUserAgent( netadr_t from, const char *useragent ); qboolean SV_InitGame( void ); void SV_ActivateServer( int runPhysics ); qboolean SV_SpawnServer( const char *server, const char *startspot, qboolean background ); -model_t *SV_ModelHandle( int modelindex ); void SV_DeactivateServer( void ); void SV_FreeTestPacket( void ); +/* +================ +SV_ModelHandle + +get model by handle +================ +*/ +static inline model_t *GAME_EXPORT SV_ModelHandle( int modelindex ) +{ + if( modelindex < 0 || modelindex >= MAX_MODELS ) + return NULL; + return sv.models[modelindex]; +} + + // // sv_phys.c // @@ -673,7 +687,6 @@ void SV_ClearGameState( void ); // sv_pmove.c // void SV_InitClientMove( void ); -qboolean SV_PlayerIsFrozen( edict_t *pClient ); void SV_RunCmd( sv_client_t *cl, usercmd_t *ucmd, int random_seed ); // diff --git a/engine/server/sv_client.c b/engine/server/sv_client.c index b3cc22be..1a4a21b0 100644 --- a/engine/server/sv_client.c +++ b/engine/server/sv_client.c @@ -477,7 +477,7 @@ static void SV_ConnectClient( netadr_t from ) // reset stats newcl->next_checkpingtime = -1.0; - newcl->packet_loss = 0.0f; + newcl->packet_loss = 0; // if this was the first client on the server, or the last client // the server can hold, send a heartbeat to the master. @@ -1170,7 +1170,7 @@ SV_EstablishTimeBase Finangles latency and the like. =================== */ -static void SV_EstablishTimeBase( sv_client_t *cl, usercmd_t *cmds, int dropped, int numbackup, int numcmds ) +static void SV_EstablishTimeBase( sv_client_t *cl, const usercmd_t *cmds, int dropped, int numbackup, int numcmds ) { double runcmd_time = 0.0; int i, cmdnum = dropped; @@ -3212,6 +3212,20 @@ void SV_ConnectionlessPacket( netadr_t from, sizebuf_t *msg ) } } +static qboolean SV_PlayerIsFrozen( const edict_t *pClient ) +{ + if( sv_background_freeze.value && sv.background ) + return true; + + if( FBitSet( host.features, ENGINE_QUAKE_COMPATIBLE )) + return false; + + if( FBitSet( pClient->v.flags, FL_FROZEN )) + return true; + + return false; +} + /* ================== SV_ParseClientMove @@ -3226,29 +3240,20 @@ each of the backup packets. */ static void SV_ParseClientMove( sv_client_t *cl, sizebuf_t *msg ) { - client_frame_t *frame; - int key, checksum1; - int i, numbackup, totalcmds, numcmds; - usercmd_t nullcmd, *to, *from; - usercmd_t cmds[CMD_BACKUP]; - float packet_loss; - edict_t *player; - model_t *model; + const usercmd_t nullcmd = { 0 }, *from = &nullcmd; // first cmd are starting from null-compressed usercmd_t + client_frame_t *frame = &cl->frames[cl->netchan.incoming_acknowledged & SV_UPDATE_MASK]; + usercmd_t cmds[CMD_BACKUP] = { 0 }, *to; + edict_t *player = cl->edict; + model_t *model; - player = cl->edict; + int key = MSG_GetRealBytesRead( msg ); + int checksum1 = MSG_ReadByte( msg ); + int packet_loss = MSG_ReadByte( msg ); + int numbackup = MSG_ReadByte( msg ); + int numcmds = MSG_ReadByte( msg ); + int totalcmds = numcmds + numbackup; + int i; - frame = &cl->frames[cl->netchan.incoming_acknowledged & SV_UPDATE_MASK]; - memset( &nullcmd, 0, sizeof( usercmd_t )); - memset( cmds, 0, sizeof( cmds )); - - key = MSG_GetRealBytesRead( msg ); - checksum1 = MSG_ReadByte( msg ); - packet_loss = MSG_ReadByte( msg ); - - numbackup = MSG_ReadByte( msg ); - numcmds = MSG_ReadByte( msg ); - - totalcmds = numcmds + numbackup; net_drop -= (numcmds - 1); if( totalcmds < 0 || totalcmds >= CMD_MASK ) @@ -3258,8 +3263,6 @@ static void SV_ParseClientMove( sv_client_t *cl, sizebuf_t *msg ) return; } - from = &nullcmd; // first cmd are starting from null-compressed usercmd_t - for( i = totalcmds - 1; i >= 0; i-- ) { to = &cmds[i]; diff --git a/engine/server/sv_frame.c b/engine/server/sv_frame.c index 5d94d9f1..2fc62872 100644 --- a/engine/server/sv_frame.c +++ b/engine/server/sv_frame.c @@ -492,14 +492,15 @@ SV_EmitPings */ static void SV_EmitPings( sizebuf_t *msg ) { - sv_client_t *cl; - int packet_loss; - int i, ping; + sv_client_t *cl; + int i; MSG_BeginServerCmd( msg, svc_pings ); for( i = 0, cl = svs.clients; i < svs.maxclients; i++, cl++ ) { + int packet_loss, ping; + if( cl->state != cs_spawned ) continue; diff --git a/engine/server/sv_init.c b/engine/server/sv_init.c index c11a4537..cf0e43f3 100644 --- a/engine/server/sv_init.c +++ b/engine/server/sv_init.c @@ -273,20 +273,6 @@ int GAME_EXPORT SV_GenericIndex( const char *filename ) return i; } -/* -================ -SV_ModelHandle - -get model by handle -================ -*/ -model_t *GAME_EXPORT SV_ModelHandle( int modelindex ) -{ - if( modelindex < 0 || modelindex >= MAX_MODELS ) - return NULL; - return sv.models[modelindex]; -} - static resourcetype_t SV_DetermineResourceType( const char *filename ) { if( !Q_strncmp( filename, DEFAULT_SOUNDPATH, sizeof( DEFAULT_SOUNDPATH ) - 1 ) && Sound_SupportedFileFormat( COM_FileExtension( filename ))) diff --git a/engine/server/sv_pmove.c b/engine/server/sv_pmove.c index fbb82caa..f128a593 100644 --- a/engine/server/sv_pmove.c +++ b/engine/server/sv_pmove.c @@ -23,19 +23,6 @@ GNU General Public License for more details. static qboolean has_update = false; static void SV_GetTrueOrigin( sv_client_t *cl, int edictnum, vec3_t origin ); -qboolean SV_PlayerIsFrozen( edict_t *pClient ) -{ - if( sv_background_freeze.value && sv.background ) - return true; - - if( FBitSet( host.features, ENGINE_QUAKE_COMPATIBLE )) - return false; - - if( FBitSet( pClient->v.flags, FL_FROZEN )) - return true; - return false; -} - void SV_ClipPMoveToEntity( physent_t *pe, const vec3_t start, vec3_t mins, vec3_t maxs, const vec3_t end, pmtrace_t *tr ) { Assert( tr != NULL );