engine: server: slight refactoring, make SV_ModelHandle inlined, move PlayerIsFrozen to sv_client, fix packet loss data type

This commit is contained in:
Alibek Omarov 2025-01-14 12:04:48 +03:00
parent 38c82a3f76
commit 1d4f7b2f94
5 changed files with 47 additions and 57 deletions

View file

@ -498,10 +498,24 @@ qboolean SV_ProcessUserAgent( netadr_t from, const char *useragent );
qboolean SV_InitGame( void ); qboolean SV_InitGame( void );
void SV_ActivateServer( int runPhysics ); void SV_ActivateServer( int runPhysics );
qboolean SV_SpawnServer( const char *server, const char *startspot, qboolean background ); qboolean SV_SpawnServer( const char *server, const char *startspot, qboolean background );
model_t *SV_ModelHandle( int modelindex );
void SV_DeactivateServer( void ); void SV_DeactivateServer( void );
void SV_FreeTestPacket( 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 // sv_phys.c
// //
@ -673,7 +687,6 @@ void SV_ClearGameState( void );
// sv_pmove.c // sv_pmove.c
// //
void SV_InitClientMove( void ); void SV_InitClientMove( void );
qboolean SV_PlayerIsFrozen( edict_t *pClient );
void SV_RunCmd( sv_client_t *cl, usercmd_t *ucmd, int random_seed ); void SV_RunCmd( sv_client_t *cl, usercmd_t *ucmd, int random_seed );
// //

View file

@ -477,7 +477,7 @@ static void SV_ConnectClient( netadr_t from )
// reset stats // reset stats
newcl->next_checkpingtime = -1.0; 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 // if this was the first client on the server, or the last client
// the server can hold, send a heartbeat to the master. // the server can hold, send a heartbeat to the master.
@ -1170,7 +1170,7 @@ SV_EstablishTimeBase
Finangles latency and the like. 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; double runcmd_time = 0.0;
int i, cmdnum = dropped; 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 SV_ParseClientMove
@ -3226,29 +3240,20 @@ each of the backup packets.
*/ */
static void SV_ParseClientMove( sv_client_t *cl, sizebuf_t *msg ) static void SV_ParseClientMove( sv_client_t *cl, sizebuf_t *msg )
{ {
client_frame_t *frame; const usercmd_t nullcmd = { 0 }, *from = &nullcmd; // first cmd are starting from null-compressed usercmd_t
int key, checksum1; client_frame_t *frame = &cl->frames[cl->netchan.incoming_acknowledged & SV_UPDATE_MASK];
int i, numbackup, totalcmds, numcmds; usercmd_t cmds[CMD_BACKUP] = { 0 }, *to;
usercmd_t nullcmd, *to, *from; edict_t *player = cl->edict;
usercmd_t cmds[CMD_BACKUP]; model_t *model;
float packet_loss;
edict_t *player;
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); net_drop -= (numcmds - 1);
if( totalcmds < 0 || totalcmds >= CMD_MASK ) if( totalcmds < 0 || totalcmds >= CMD_MASK )
@ -3258,8 +3263,6 @@ static void SV_ParseClientMove( sv_client_t *cl, sizebuf_t *msg )
return; return;
} }
from = &nullcmd; // first cmd are starting from null-compressed usercmd_t
for( i = totalcmds - 1; i >= 0; i-- ) for( i = totalcmds - 1; i >= 0; i-- )
{ {
to = &cmds[i]; to = &cmds[i];

View file

@ -492,14 +492,15 @@ SV_EmitPings
*/ */
static void SV_EmitPings( sizebuf_t *msg ) static void SV_EmitPings( sizebuf_t *msg )
{ {
sv_client_t *cl; sv_client_t *cl;
int packet_loss; int i;
int i, ping;
MSG_BeginServerCmd( msg, svc_pings ); MSG_BeginServerCmd( msg, svc_pings );
for( i = 0, cl = svs.clients; i < svs.maxclients; i++, cl++ ) for( i = 0, cl = svs.clients; i < svs.maxclients; i++, cl++ )
{ {
int packet_loss, ping;
if( cl->state != cs_spawned ) if( cl->state != cs_spawned )
continue; continue;

View file

@ -273,20 +273,6 @@ int GAME_EXPORT SV_GenericIndex( const char *filename )
return i; 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 ) static resourcetype_t SV_DetermineResourceType( const char *filename )
{ {
if( !Q_strncmp( filename, DEFAULT_SOUNDPATH, sizeof( DEFAULT_SOUNDPATH ) - 1 ) && Sound_SupportedFileFormat( COM_FileExtension( filename ))) if( !Q_strncmp( filename, DEFAULT_SOUNDPATH, sizeof( DEFAULT_SOUNDPATH ) - 1 ) && Sound_SupportedFileFormat( COM_FileExtension( filename )))

View file

@ -23,19 +23,6 @@ GNU General Public License for more details.
static qboolean has_update = false; static qboolean has_update = false;
static void SV_GetTrueOrigin( sv_client_t *cl, int edictnum, vec3_t origin ); 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 ) 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 ); Assert( tr != NULL );