From d49178d5b6f040d8c7c2453eeede9e0667545885 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Tue, 19 May 2026 21:25:41 +0500 Subject: [PATCH] engine: server: refactor variable declarations --- engine/server/sv_client.c | 77 ++++++++------------ engine/server/sv_cmds.c | 61 ++++++---------- engine/server/sv_custom.c | 81 +++++++++------------ engine/server/sv_filter.c | 49 +++++-------- engine/server/sv_frame.c | 46 +++++------- engine/server/sv_game.c | 143 ++++++++++++++++---------------------- engine/server/sv_init.c | 27 ++++--- engine/server/sv_log.c | 28 +++----- engine/server/sv_main.c | 21 ++---- engine/server/sv_move.c | 6 +- engine/server/sv_phys.c | 83 +++++++++------------- engine/server/sv_pmove.c | 59 +++++++--------- engine/server/sv_query.c | 7 +- engine/server/sv_save.c | 90 +++++++++++------------- engine/server/sv_world.c | 78 ++++++++++----------- 15 files changed, 354 insertions(+), 502 deletions(-) diff --git a/engine/server/sv_client.c b/engine/server/sv_client.c index 7639f24d..e903a1c3 100644 --- a/engine/server/sv_client.c +++ b/engine/server/sv_client.c @@ -255,9 +255,7 @@ We don't do this search on a "reconnect, we just reuse the slot */ static sv_client_t *SV_FindEmptySlot( void ) { - int i; - - for( i = 0; i < svs.maxclients; i++ ) + for( int i = 0; i < svs.maxclients; i++ ) { if( svs.clients[i].state == cs_free ) return &svs.clients[i]; @@ -268,11 +266,11 @@ static sv_client_t *SV_FindEmptySlot( void ) static void SV_MaybeNotifyPlayerCountChange( const sv_client_t *cl, const char *address ) { - int i, count = 0; + int count = 0; // if this was the first client on the server, or the last client // the server can hold, send a heartbeat to the master. - for( i = 0; i < svs.maxclients; i++ ) + for( int i = 0; i < svs.maxclients; i++ ) { if( svs.clients[i].state >= cs_connected ) count++; @@ -299,7 +297,6 @@ static void SV_ConnectClient( netadr_t from ) client_frame_t *frames; sv_client_t *newcl = NULL; int qport, version; - int i; int challenge; const char *s; int extensions; @@ -369,7 +366,7 @@ static void SV_ConnectClient( netadr_t from ) } // if there is already a slot for this ip, reuse it - for( i = 0; i < svs.maxclients; i++ ) + for( int i = 0; i < svs.maxclients; i++ ) { sv_client_t *cl = &svs.clients[i]; @@ -798,8 +795,6 @@ static void SV_TestBandWidth( netadr_t from ) { const int version = Q_atoi( Cmd_Argv( 1 )); const int packetsize = Q_atoi( Cmd_Argv( 2 )); - uint32_t crc; - int ofs; // don't waste time of protocol mismatched if( version != PROTOCOL_VERSION ) @@ -828,14 +823,14 @@ static void SV_TestBandWidth( netadr_t from ) } // don't go out of bounds - ofs = packetsize - svs.testpacket_filepos - 1; + int ofs = packetsize - svs.testpacket_filepos - 1; if(( ofs < 0 ) || ( ofs > svs.testpacket_filelen )) { SV_SendChallenge( from, true ); return; } - crc = LittleLong( svs.testpacket_crcs[ofs] ); + uint32_t crc = LittleLong( svs.testpacket_crcs[ofs] ); memcpy( svs.testpacket_crcpos, &crc, sizeof( crc )); // send the datagram @@ -1058,7 +1053,6 @@ Redirect all printfs void SV_RemoteCommand( netadr_t from, sizebuf_t *msg ) { const char *adr; - int i; if( !rcon_enable.value || COM_StringEmpty( rcon_password.string )) return; @@ -1075,7 +1069,7 @@ void SV_RemoteCommand( netadr_t from, sizebuf_t *msg ) Log_Printf( "Rcon: \"%s\" from \"%s\"\n", MSG_GetData( msg ) + 4, adr ); remaining[0] = 0; - for( i = 2; i < Cmd_Argc(); i++ ) + for( int i = 2; i < Cmd_Argc(); i++ ) { p += Q_strncpy( p, "\"", sizeof( remaining ) - ( p - remaining )); p += Q_strncpy( p, Cmd_Argv( i ), sizeof( remaining ) - ( p - remaining )); @@ -1103,9 +1097,8 @@ recalc ping on current client int SV_CalcPing( const sv_client_t *cl ) { float ping = 0; - int i, count; - int idx, back; - client_frame_t *frame; + int count; + int back; // bots don't have a real ping if( FBitSet( cl->flags, FCL_FAKECLIENT ) || !cl->frames ) @@ -1120,10 +1113,10 @@ int SV_CalcPing( const sv_client_t *cl ) count = 0; - for( i = 0; i < back; i++ ) + for( int i = 0; i < back; i++ ) { - idx = cl->netchan.incoming_acknowledged + ~i; - frame = &cl->frames[idx & SV_UPDATE_MASK]; + int idx = cl->netchan.incoming_acknowledged + ~i; + client_frame_t *frame = &cl->frames[idx & SV_UPDATE_MASK]; if( frame->ping_time > 0.0f ) { @@ -1147,7 +1140,6 @@ Finangles latency and the like. 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; if( dropped < 24 ) { @@ -1159,13 +1151,13 @@ static void SV_EstablishTimeBase( sv_client_t *cl, const usercmd_t *cmds, int dr while( dropped > 0 ) { - cmdnum = dropped + numcmds - 1; + int cmdnum = dropped + numcmds - 1; runcmd_time += (double)cmds[cmdnum].msec / 1000.0; dropped--; } } - for( i = numcmds - 1; i >= 0; i-- ) + for( int i = numcmds - 1; i >= 0; i-- ) runcmd_time += cmds[i].msec / 1000.0; cl->timebase = sv.time + sv.frametime - runcmd_time; @@ -1180,7 +1172,6 @@ compute latency for client */ static float SV_CalcClientTime( sv_client_t *cl ) { - float minping, maxping; float ping = 0.0f; int i, count = 0; int backtrack; @@ -1206,8 +1197,8 @@ static float SV_CalcClientTime( sv_client_t *cl ) if( !count ) return 0.0f; - minping = 9999.0f; - maxping = -9999.0f; + float minping = 9999.0f; + float maxping = -9999.0f; ping /= count; for( i = 0; i < ( SV_UPDATE_BACKUP <= 4 ? SV_UPDATE_BACKUP : 4 ); i++ ) @@ -1241,12 +1232,11 @@ void SV_FullClientUpdate( sv_client_t *cl, sizebuf_t *msg ) char info[MAX_INFO_STRING]; char digest[16]; MD5Context_t ctx; - int i; // process userinfo before updating SV_UserinfoChanged( cl ); - i = cl - svs.clients; + int i = cl - svs.clients; MSG_BeginServerCmd( msg, svc_updateuserinfo ); MSG_WriteUBitLong( msg, i, MAX_CLIENT_BITS ); @@ -1367,7 +1357,6 @@ static void SV_PutClientInServer( sv_client_t *cl ) { SAVERESTOREDATA levelData; string name; - int i; memset( &levelData, 0, sizeof( levelData )); svgame.globals->pSaveData = &levelData; @@ -1379,7 +1368,7 @@ static void SV_PutClientInServer( sv_client_t *cl ) MSG_WriteString( &msg, name ); MSG_WriteByte( &msg, levelData.connectionCount ); - for( i = 0; i < levelData.connectionCount; i++ ) + for( int i = 0; i < levelData.connectionCount; i++ ) MSG_WriteString( &msg, levelData.levelList[i].mapName ); svgame.globals->pSaveData = NULL; @@ -1608,9 +1597,7 @@ static qboolean SV_New_f( sv_client_t *cl ) char szRejectReason[128]; char szAddress[128]; char szName[32]; - sv_client_t *cur; sizebuf_t msg; - int i; memset( msg_buf, 0, sizeof( msg_buf )); MSG_Init( &msg, "New", msg_buf, sizeof( msg_buf )); @@ -1643,8 +1630,10 @@ static qboolean SV_New_f( sv_client_t *cl ) MSG_WriteStringf( &msg, "fullserverinfo \"%s\"\n", svs.serverinfo ); // collect the info about all the players and send to me - for( i = 0, cur = svs.clients; i < svs.maxclients; i++, cur++ ) + for( int i = 0; i < svs.maxclients; i++ ) { + sv_client_t *cur = &svs.clients[i]; + if( !cur->edict || cur->state != cs_spawned ) continue; // not in game yet SV_FullClientUpdate( cur, &msg ); @@ -2218,7 +2207,7 @@ static qboolean SV_ClientStatus_f( sv_client_t *cl ) { netadr_t ip4, ip6; vec3_t origin = { 0 }; - int clients, bots, i; + int clients, bots; if( cl->state != cs_spawned ) return false; @@ -2246,7 +2235,7 @@ static qboolean SV_ClientStatus_f( sv_client_t *cl ) sv.name, (int)origin[0], (int)origin[1], (int)origin[2], clients, svs.maxclients ); - for( i = 0; i < svs.maxclients; i++ ) + for( int i = 0; i < svs.maxclients; i++ ) { const sv_client_t *pcl = &svs.clients[i]; int j = 0; @@ -2301,7 +2290,6 @@ static edict_t *SV_GetCrossEnt( edict_t *player ) float flMaxDot = 0.94; vec3_t forward; vec3_t viewPos; - int i; float maxLen = 1000; AngleVectors( player->v.v_angle, forward, NULL, NULL ); @@ -2320,7 +2308,7 @@ static edict_t *SV_GetCrossEnt( edict_t *player ) } // check untraceable entities - for ( i = 1; i < svgame.numEntities; i++, ent++ ) + for ( int i = 1; i < svgame.numEntities; i++, ent++ ) { vec3_t vecLOS; vec3_t vecOrigin; @@ -2466,12 +2454,10 @@ Print list of entities to client static qboolean SV_EntList_f( sv_client_t *cl ) { vec3_t borigin; - edict_t *ent = NULL; - int i; - for( i = 0; i < svgame.numEntities; i++ ) + for( int i = 0; i < svgame.numEntities; i++ ) { - ent = SV_EdictNum( i ); + edict_t *ent = SV_EdictNum( i ); if( !SV_IsValidEdict( ent )) continue; @@ -3437,18 +3423,16 @@ Parse resource list static void SV_ParseResourceList( sv_client_t *cl, sizebuf_t *msg ) { int totalsize; - resource_t *resource; - int i, total; resourceinfo_t ri; - total = MSG_ReadShort( msg ); + int total = MSG_ReadShort( msg ); SV_ClearResourceList( &cl->resourcesneeded ); SV_ClearResourceList( &cl->resourcesonhand ); - for( i = 0; i < total; i++ ) + for( int i = 0; i < total; i++ ) { - resource = Z_Calloc( sizeof( resource_t ) ); + resource_t *resource = Z_Calloc( sizeof( resource_t ) ); Q_strncpy( resource->szFileName, MSG_ReadString( msg ), sizeof( resource->szFileName )); resource->type = MSG_ReadByte( msg ); resource->nIndex = MSG_ReadShort( msg ); @@ -3570,7 +3554,6 @@ SV_ParseVoiceData static void SV_ParseVoiceData( sv_client_t *cl, sizebuf_t *msg ) { char received[4096]; - int i; const qboolean loopback = !!MSG_ReadByte( msg ); const uint frames = MSG_ReadByte( msg ); @@ -3598,7 +3581,7 @@ static void SV_ParseVoiceData( sv_client_t *cl, sizebuf_t *msg ) if( svs.maxclients <= 1 && sv_voice_singleplayer.value == 0.0f ) return; - for( i = 0; i < svs.maxclients; i++ ) + for( int i = 0; i < svs.maxclients; i++ ) { sv_client_t *cur = &svs.clients[i]; const qboolean local = cl == cur; diff --git a/engine/server/sv_cmds.c b/engine/server/sv_cmds.c index 31ba7d9d..ed1ee092 100644 --- a/engine/server/sv_cmds.c +++ b/engine/server/sv_cmds.c @@ -50,8 +50,6 @@ void SV_BroadcastPrintf( sv_client_t *ignore, const char *fmt, ... ) { char string[MAX_SYSPATH]; va_list argptr; - sv_client_t *cl; - int i; va_start( argptr, fmt ); Q_vsnprintf( string, sizeof( string ), fmt, argptr ); @@ -59,6 +57,9 @@ void SV_BroadcastPrintf( sv_client_t *ignore, const char *fmt, ... ) if( sv.state == ss_active ) { + sv_client_t *cl; + int i; + for( i = 0, cl = svs.clients; i < svs.maxclients; i++, cl++ ) { if( FBitSet( cl->flags, FCL_FAKECLIENT )) @@ -111,9 +112,8 @@ Sets sv_client and sv_player to the player with idnum Cmd_Argv(1) */ static sv_client_t *SV_SetPlayer( void ) { - const char *s; sv_client_t *cl; - int i, idnum; + int i; if( !svs.clients || sv.background ) return NULL; @@ -124,12 +124,12 @@ static sv_client_t *SV_SetPlayer( void ) return svs.clients; } - s = Cmd_Argv( 1 ); + const char *s = Cmd_Argv( 1 ); // numeric values are just slot numbers if( Q_isdigit( s ) || (s[0] == '-' && Q_isdigit( s + 1 ))) { - idnum = Q_atoi( s ); + int idnum = Q_atoi( s ); if( idnum < 0 || idnum >= svs.maxclients ) { @@ -169,9 +169,7 @@ check map for typically errors */ static qboolean SV_ValidateMap( const char *pMapName ) { - int flags; - - flags = SV_MapIsValid( pMapName, NULL ); + int flags = SV_MapIsValid( pMapName, NULL ); if( FBitSet( flags, MAP_INVALID_VERSION )) { @@ -230,8 +228,6 @@ static void SV_Maps_f( void ) { const char *separator = "-------------------"; const char *argStr = Cmd_Argv( 1 ); // Substr - int nummaps; - search_t *mapList; if( Cmd_Argc() != 2 ) { @@ -239,7 +235,7 @@ static void SV_Maps_f( void ) return; } - mapList = FS_Search( va( "maps/*%s*.bsp", argStr ), true, true ); + search_t *mapList = FS_Search( va( "maps/*%s*.bsp", argStr ), true, true ); if( !mapList ) { @@ -247,7 +243,7 @@ static void SV_Maps_f( void ) return; } - nummaps = Cmd_ListMaps( mapList, NULL, 0, false ); + int nummaps = Cmd_ListMaps( mapList, NULL, 0, false ); Mem_Free( mapList ); @@ -310,10 +306,8 @@ For development work static void SV_NextMap_f( void ) { char nextmap[MAX_QPATH]; - int i, next; - search_t *t; + search_t *t = FS_Search( "maps\\*.bsp", true, con_gamemaps.value ); // only in gamedir - t = FS_Search( "maps\\*.bsp", true, con_gamemaps.value ); // only in gamedir if( !t ) t = FS_Search( "maps/*.bsp", true, con_gamemaps.value ); // only in gamedir if( !t ) @@ -322,7 +316,7 @@ static void SV_NextMap_f( void ) return; } - for( i = 0; i < t->numfilenames; i++ ) + for( int i = 0; i < t->numfilenames; i++ ) { const char *ext = COM_FileExtension( t->filenames[i] ); @@ -333,7 +327,7 @@ static void SV_NextMap_f( void ) if( Q_stricmp( sv_hostmap.string, nextmap )) continue; - next = ( i + 1 ) % t->numfilenames; + int next = ( i + 1 ) % t->numfilenames; COM_FileBase( t->filenames[next], nextmap, sizeof( nextmap )); Cvar_DirectSet( &sv_hostmap, nextmap ); @@ -577,7 +571,6 @@ Kick a user off of the server static void SV_Kick_f( void ) { sv_client_t *cl; - const char *param; if( Cmd_Argc() < 2 ) { @@ -585,7 +578,7 @@ static void SV_Kick_f( void ) return; } - param = Cmd_Argv( 1 ); + const char *param = Cmd_Argv( 1 ); if( *param == '#' && Q_isdigit( param + 1 ) ) cl = SV_ClientById( Q_atoi( param + 1 ) ); @@ -633,8 +626,6 @@ SV_Status_f */ static void SV_Status_f( void ) { - int i; - #if !XASH_DEDICATED if( !svs.clients && CL_Active( )) { @@ -652,7 +643,7 @@ static void SV_Status_f( void ) Con_Printf( "map: %s\n", sv.name ); Con_Printf( "# score ping dev lastmsg qport useragent\t\tname\t\taddress\n" ); - for( i = 0; i < svs.maxclients; i++ ) + for( int i = 0; i < svs.maxclients; i++ ) { const sv_client_t *cl = &svs.clients[i]; int j = 0; @@ -661,8 +652,6 @@ static void SV_Status_f( void ) string version; string os; string arch; - int buildnum; - int input_devices; if( !cl->state ) continue; @@ -678,7 +667,7 @@ static void SV_Status_f( void ) else s = va( "%8i", SV_CalcPing( cl )); - input_devices = Q_atoi( Info_ValueForKey( cl->useragent, "d" )); + int input_devices = Q_atoi( Info_ValueForKey( cl->useragent, "d" )); if( FBitSet( input_devices, INPUT_DEVICE_MOUSE )) devices[j++] = 'm'; @@ -700,7 +689,7 @@ static void SV_Status_f( void ) Q_strncpy( version, Info_ValueForKey( cl->useragent, "v" ), sizeof( version )); Q_strncpy( os, Info_ValueForKey( cl->useragent, "o" ), sizeof( os )); Q_strncpy( arch, Info_ValueForKey( cl->useragent, "a" ), sizeof( arch )); - buildnum = Q_atoi( Info_ValueForKey( cl->useragent, "b" )); + int buildnum = Q_atoi( Info_ValueForKey( cl->useragent, "b" )); if( COM_StringEmpty( version )) Q_strncpy( version, "n/a", sizeof( version )); @@ -725,7 +714,6 @@ SV_ConSay_f */ static void SV_ConSay_f( void ) { - const char *p; char text[MAX_SYSPATH]; if( Cmd_Argc() < 2 ) return; @@ -736,7 +724,7 @@ static void SV_ConSay_f( void ) return; } - p = Cmd_Args(); + const char *p = Cmd_Args(); Q_strncpy( text, *p == '"' ? p + 1 : p, sizeof( text )); if( *p == '"' ) @@ -768,8 +756,6 @@ Examine or change the serverinfo string */ static void SV_ServerInfo_f( void ) { - convar_t *var; - if( Cmd_Argc() == 1 ) { Con_Printf( "Server info settings:\n" ); @@ -791,7 +777,7 @@ static void SV_ServerInfo_f( void ) } // if this is a cvar, change it too - var = Cvar_FindVar( Cmd_Argv( 1 )); + convar_t *var = Cvar_FindVar( Cmd_Argv( 1 )); if( var ) { freestring( var->string ); // free the old value string @@ -922,15 +908,13 @@ SV_EdictUsage_f */ static void SV_EdictUsage_f( void ) { - int active; - if( sv.state != ss_active ) { Con_Printf( "^3no server running.\n" ); return; } - active = pfnNumberOfEntities(); + int active = pfnNumberOfEntities(); Con_Printf( "%5i edicts is used\n", active ); Con_Printf( "%5i edicts is free\n", GI->max_edicts - active ); Con_Printf( "%5i total\n", GI->max_edicts ); @@ -944,18 +928,15 @@ SV_EntityInfo_f */ static void SV_EntityInfo_f( void ) { - edict_t *ent; - int i; - if( sv.state != ss_active ) { Con_Printf( "^3no server running.\n" ); return; } - for( i = 0; i < svgame.numEntities; i++ ) + for( int i = 0; i < svgame.numEntities; i++ ) { - ent = SV_EdictNum( i ); + edict_t *ent = SV_EdictNum( i ); if( !SV_IsValidEdict( ent )) continue; Con_Printf( "%5i origin: %.f %.f %.f", i, ent->v.origin[0], ent->v.origin[1], ent->v.origin[2] ); diff --git a/engine/server/sv_custom.c b/engine/server/sv_custom.c index 0529790e..38cc8b71 100644 --- a/engine/server/sv_custom.c +++ b/engine/server/sv_custom.c @@ -18,18 +18,13 @@ GNU General Public License for more details. static void SV_CreateCustomizationList( sv_client_t *cl ) { - resource_t *pResource; - customization_t *pList, *pCust; - qboolean bFound; - int nLumps; - cl->customdata.pNext = NULL; - for( pResource = cl->resourcesonhand.pNext; pResource != &cl->resourcesonhand; pResource = pResource->pNext ) + for( resource_t *pResource = cl->resourcesonhand.pNext; pResource != &cl->resourcesonhand; pResource = pResource->pNext ) { - bFound = false; + qboolean bFound = false; - for( pList = cl->customdata.pNext; pList != NULL; pList = pList->pNext ) + for( customization_t *pList = cl->customdata.pNext; pList != NULL; pList = pList->pNext ) { if( !memcmp( pList->resource.rgucMD5_hash, pResource->rgucMD5_hash, 16 )) { @@ -40,7 +35,8 @@ static void SV_CreateCustomizationList( sv_client_t *cl ) if( !bFound ) { - nLumps = 0; + customization_t *pCust; + int nLumps = 0; if( COM_CreateCustomization( &cl->customdata, pResource, -1, FCUST_FROMHPAK|FCUST_WIPEDATA, &pCust, &nLumps )) { @@ -63,12 +59,10 @@ static void SV_CreateCustomizationList( sv_client_t *cl ) static qboolean SV_FileInConsistencyList( const char *filename, consistency_t **ppout ) { - int i; - if( ppout != NULL ) *ppout = NULL; - for( i = 0; i < MAX_MODELS; i++ ) + for( int i = 0; i < MAX_MODELS; i++ ) { consistency_t *pc = &sv.consistency_list[i]; @@ -88,16 +82,10 @@ static qboolean SV_FileInConsistencyList( const char *filename, consistency_t ** void SV_ParseConsistencyResponse( sv_client_t *cl, sizebuf_t *msg ) { - int i, c, idx, value; - byte readbuffer[32]; + int c; byte nullbuffer[32]; - byte resbuffer[32]; qboolean invalid_type; - vec3_t cmins, cmaxs; int badresindex; - vec3_t mins, maxs; - FORCE_TYPE ft; - resource_t *r; memset( nullbuffer, 0, sizeof( nullbuffer )); invalid_type = false; @@ -106,7 +94,9 @@ void SV_ParseConsistencyResponse( sv_client_t *cl, sizebuf_t *msg ) while( MSG_ReadOneBit( msg )) { - idx = MSG_ReadUBitLong( msg, MAX_MODEL_BITS ); + byte readbuffer[32]; + resource_t *r; + int idx = MSG_ReadUBitLong( msg, MAX_MODEL_BITS ); if( idx < 0 || idx >= sv.num_resources ) break; @@ -119,7 +109,7 @@ void SV_ParseConsistencyResponse( sv_client_t *cl, sizebuf_t *msg ) if( !memcmp( readbuffer, nullbuffer, 32 )) { - value = MSG_ReadUBitLong( msg, 32 ); + int value = MSG_ReadUBitLong( msg, 32 ); LittleLongSW( value ); @@ -129,6 +119,11 @@ void SV_ParseConsistencyResponse( sv_client_t *cl, sizebuf_t *msg ) } else { + vec3_t cmins, cmaxs; + vec3_t mins, maxs; + byte resbuffer[32]; + FORCE_TYPE ft; + MSG_ReadBytes( msg, cmins, sizeof( cmins )); MSG_ReadBytes( msg, cmaxs, sizeof( cmaxs )); @@ -148,7 +143,7 @@ void SV_ParseConsistencyResponse( sv_client_t *cl, sizebuf_t *msg ) memcpy( mins, &resbuffer[0x01], sizeof( mins )); memcpy( maxs, &resbuffer[0x0D], sizeof( maxs )); - for( i = 0; i < 3; i++ ) + for( int i = 0; i < 3; i++ ) { if( cmins[i] < mins[i] || cmaxs[i] > maxs[i] ) { @@ -196,14 +191,13 @@ void SV_ParseConsistencyResponse( sv_client_t *cl, sizebuf_t *msg ) void SV_TransferConsistencyInfo( void ) { vec3_t mins, maxs; - int i, total = 0; - resource_t *pResource; - string filepath; - consistency_t *pc; + int total = 0; - for( i = 0; i < sv.num_resources; i++ ) + for( int i = 0; i < sv.num_resources; i++ ) { - pResource = &sv.resources[i]; + string filepath; + consistency_t *pc; + resource_t *pResource = &sv.resources[i]; if( FBitSet( pResource->ucFlags, RES_CHECKFILE )) continue; // already checked? @@ -248,9 +242,6 @@ void SV_TransferConsistencyInfo( void ) static void SV_SendConsistencyList( sv_client_t *cl, sizebuf_t *msg ) { - int i, lastcheck; - int delta; - if( svs.maxclients == 1 || !sv_consistency.value || !sv.num_consistency || FBitSet( cl->flags, FCL_HLTV_PROXY )) { ClearBits( cl->flags, FCL_FORCE_UNMODIFIED ); @@ -260,14 +251,14 @@ static void SV_SendConsistencyList( sv_client_t *cl, sizebuf_t *msg ) SetBits( cl->flags, FCL_FORCE_UNMODIFIED ); MSG_WriteOneBit( msg, 1 ); - lastcheck = 0; + int lastcheck = 0; - for( i = 0; i < sv.num_resources; i++ ) + for( int i = 0; i < sv.num_resources; i++ ) { if( !FBitSet( sv.resources[i].ucFlags, RES_CHECKFILE )) continue; - delta = i - lastcheck; + int delta = i - lastcheck; MSG_WriteOneBit( msg, 1 ); if( delta > 31 ) @@ -361,10 +352,9 @@ void SV_RemoveFromResourceList( resource_t *pResource ) void SV_ClearResourceList( resource_t *pList ) { - resource_t *p; resource_t *n; - for( p = pList->pNext; pList != p && p; p = n ) + for( resource_t *p = pList->pNext; pList != p && p; p = n ) { n = p->pNext; @@ -386,9 +376,8 @@ int SV_EstimateNeededResources( sv_client_t *cl ) { int missing = 0; int size = 0; - resource_t *p; - for( p = cl->resourcesneeded.pNext; p != &cl->resourcesneeded; p = p->pNext ) + for( resource_t *p = cl->resourcesneeded.pNext; p != &cl->resourcesneeded; p = p->pNext ) { if( p->type != t_decal ) continue; @@ -437,8 +426,6 @@ static void SV_Customization( sv_client_t *pClient, resource_t *pResource, qbool static void SV_PropagateCustomizations( sv_client_t *pHost ) { - customization_t *pCust; - resource_t *pResource; sv_client_t *cl; int i; @@ -450,10 +437,10 @@ static void SV_PropagateCustomizations( sv_client_t *pHost ) if( FBitSet( cl->flags, FCL_FAKECLIENT )) continue; - for( pCust = cl->customdata.pNext; pCust != NULL; pCust = pCust->pNext ) + for( customization_t *pCust = cl->customdata.pNext; pCust != NULL; pCust = pCust->pNext ) { if( !pCust->bInUse ) continue; - pResource = &pCust->resource; + resource_t *pResource = &pCust->resource; SV_SendCustomization( pHost, i, pResource ); } } @@ -502,10 +489,9 @@ void SV_RequestMissingResources( void ) void SV_BatchUploadRequest( sv_client_t *cl ) { - string filename; - resource_t *p, *n; + resource_t *n; - for( p = cl->resourcesneeded.pNext; p != &cl->resourcesneeded; p = n ) + for( resource_t *p = cl->resourcesneeded.pNext; p != &cl->resourcesneeded; p = n ) { n = p->pNext; @@ -519,6 +505,7 @@ void SV_BatchUploadRequest( sv_client_t *cl ) { if( FBitSet( p->ucFlags, RES_CUSTOM )) { + string filename; Q_snprintf( filename, sizeof( filename ), "!MD5%s", MD5_Print( p->rgucMD5_hash )); if( SV_CheckFile( &cl->netchan.message, filename )) @@ -556,8 +543,6 @@ void SV_SendResource( resource_t *pResource, sizebuf_t *msg ) void SV_SendResources( sv_client_t *cl, sizebuf_t *msg ) { - int i; - MSG_BeginServerCmd( msg, svc_resourcerequest ); MSG_WriteLong( msg, svs.spawncount ); MSG_WriteLong( msg, 0 ); @@ -571,7 +556,7 @@ void SV_SendResources( sv_client_t *cl, sizebuf_t *msg ) MSG_BeginServerCmd( msg, svc_resourcelist ); MSG_WriteUBitLong( msg, sv.num_resources, MAX_RESOURCE_BITS ); - for( i = 0; i < sv.num_resources; i++ ) + for( int i = 0; i < sv.num_resources; i++ ) { SV_SendResource( &sv.resources[i], msg ); } diff --git a/engine/server/sv_filter.c b/engine/server/sv_filter.c index 457ab801..38dfed08 100644 --- a/engine/server/sv_filter.c +++ b/engine/server/sv_filter.c @@ -35,9 +35,9 @@ static cidfilter_t *cidfilter = NULL; static void SV_RemoveID( const char *id ) { - cidfilter_t *filter, *prevfilter = NULL; + cidfilter_t *prevfilter = NULL; - for( filter = cidfilter; filter; filter = filter->next ) + for( cidfilter_t *filter = cidfilter; filter; filter = filter->next ) { if( Q_strcmp( filter->id, id )) { @@ -62,9 +62,8 @@ static void SV_RemoveID( const char *id ) qboolean SV_CheckID( const char *id ) { qboolean ret = false; - cidfilter_t *filter; - for( filter = cidfilter; filter; filter = filter->next ) + for( cidfilter_t *filter = cidfilter; filter; filter = filter->next ) { int len1 = Q_strlen( id ), len2 = Q_strlen( filter->id ); int len = Q_min( len1, len2 ); @@ -93,7 +92,6 @@ static void SV_BanID_f( void ) float time = Q_atof( Cmd_Argv( 1 )); const char *id = Cmd_Argv( 2 ); sv_client_t *cl = NULL; - cidfilter_t *filter; if( time ) time = host.realtime + time * 60.0f; @@ -164,7 +162,7 @@ static void SV_BanID_f( void ) SV_RemoveID( id ); - filter = Mem_Malloc( host.mempool, sizeof( cidfilter_t )); + cidfilter_t *filter = Mem_Malloc( host.mempool, sizeof( cidfilter_t )); filter->endTime = time; filter->next = cidfilter; Q_strncpy( filter->id, id, sizeof( filter->id )); @@ -176,12 +174,10 @@ static void SV_BanID_f( void ) static void SV_ListID_f( void ) { - cidfilter_t *filter; - Con_Reportf( "id ban list\n" ); Con_Reportf( "-----------\n" ); - for( filter = cidfilter; filter; filter = filter->next ) + for( cidfilter_t *filter = cidfilter; filter; filter = filter->next ) { if( filter->endTime && host.realtime > filter->endTime ) continue; // no negative time @@ -219,7 +215,6 @@ static void SV_RemoveID_f( void ) static void SV_WriteID_f( void ) { file_t *f = FS_Open( Cvar_VariableString( "bannedcfgfile" ), "w", false ); - cidfilter_t *filter; if( !f ) { @@ -232,7 +227,7 @@ static void SV_WriteID_f( void ) FS_Printf( f, "//\t\t %s - archive of id blacklist\n", Cvar_VariableString( "bannedcfgfile" )); FS_Printf( f, "//=======================================================================\n" ); - for( filter = cidfilter; filter; filter = filter->next ) + for( cidfilter_t *filter = cidfilter; filter; filter = filter->next ) if( !filter->endTime ) // only permanent FS_Printf( f, "banid 0 %s\n", filter->id ); @@ -249,8 +244,6 @@ static void SV_InitIDFilter( void ) static void SV_ShutdownIDFilter( void ) { - cidfilter_t *cidList, *cidNext; - // should be called manually because banned.cfg is not executed by engine //SV_WriteID_f(); @@ -259,7 +252,7 @@ static void SV_ShutdownIDFilter( void ) Cmd_RemoveCommand( "removeid" ); Cmd_RemoveCommand( "writeid" ); - for( cidList = cidfilter; cidList; cidList = cidNext ) + for( cidfilter_t *cidList = cidfilter, *cidNext; cidList; cidList = cidNext ) { cidNext = cidList->next; Mem_Free( cidList ); @@ -352,9 +345,7 @@ static void SV_RemoveIPFilter( ipfilter_t *toremove, qboolean removeAll, qboolea qboolean SV_CheckIP( netadr_t *adr ) { // TODO: ip rate limit - ipfilter_t *entry = ipfilter; - - for( ; entry; entry = entry->next ) + for( ipfilter_t *entry = ipfilter; entry; entry = entry->next ) { if( entry->endTime && host.realtime > entry->endTime ) continue; // expired @@ -400,7 +391,6 @@ static void SV_AddIP_f( void ) const char *adr = Cmd_Argv( 2 ); ipfilter_t filter, *newfilter; float minutes; - int i; if( Cmd_Argc() != 3 ) { @@ -433,7 +423,7 @@ static void SV_AddIP_f( void ) ipfilter = newfilter; - for( i = 0; i < svs.maxclients; i++ ) + for( int i = 0; i < svs.maxclients; i++ ) { netadr_t clientadr = svs.clients[i].netchan.remote_address; @@ -448,7 +438,7 @@ static void SV_AddIP_f( void ) static void SV_ListIP_f( void ) { qboolean haveFilter = false; - ipfilter_t filter, *f; + ipfilter_t filter; if( Cmd_Argc() > 2 ) { @@ -476,7 +466,7 @@ static void SV_ListIP_f( void ) Con_Printf( "IP filter list:\n" ); - for( f = ipfilter; f; f = f->next ) + for( ipfilter_t *f = ipfilter; f; f = f->next ) { string filterStr; @@ -515,7 +505,6 @@ static void SV_RemoveIP_f( void ) static void SV_WriteIP_f( void ) { file_t *fd = FS_Open( Cvar_VariableString( "listipcfgfile" ), "w", true ); - ipfilter_t *f; if( !fd ) { @@ -523,7 +512,7 @@ static void SV_WriteIP_f( void ) return; } - for( f = ipfilter; f; f = f->next ) + for( ipfilter_t *f = ipfilter; f; f = f->next ) { string filterStr; int size; @@ -549,12 +538,10 @@ static void SV_InitIPFilter( void ) static void SV_ShutdownIPFilter( void ) { - ipfilter_t *ipList, *ipNext; - // should be called manually because banned.cfg is not executed by engine //SV_WriteIP_f(); - for( ipList = ipfilter; ipList; ipList = ipNext ) + for( ipfilter_t *ipList = ipfilter, *ipNext; ipList; ipList = ipNext ) { ipNext = ipList->next; Mem_Free( ipList ); @@ -582,7 +569,6 @@ void SV_ShutdownFilter( void ) static void Test_StringToFilterAdr( void ) { ipfilter_t f1; - int i; struct { const char *str; @@ -614,7 +600,7 @@ static void Test_StringToFilterAdr( void ) { "fd8a:63d5:e014:0d62:ffff:ffff:ffff:ffff:ffff", false }, }; - for( i = 0; i < ARRAYSIZE( ipv4tests ); i++ ) + for( int i = 0; i < ARRAYSIZE( ipv4tests ); i++ ) { qboolean ret = NET_StringToFilterAdr( ipv4tests[i].str, &f1.adr, &f1.prefixlen ); @@ -630,7 +616,7 @@ static void Test_StringToFilterAdr( void ) } } - for( i = 0; i < ARRAYSIZE( ipv6tests ); i++ ) + for( int i = 0; i < ARRAYSIZE( ipv6tests ); i++ ) { qboolean ret = NET_StringToFilterAdr( ipv6tests[i].str, &f1.adr, &f1.prefixlen ); uint8_t x[16]; @@ -662,7 +648,6 @@ static void Test_IPFilterIncludesIPFilter( void ) "2a00:1370:8190:f9eb:3866:6126:330c:b82b" // 6 }; ipfilter_t f[7]; - int i; int tests[][3] = { // ipv4 @@ -685,12 +670,12 @@ static void Test_IPFilterIncludesIPFilter( void ) { 6, 5, true }, }; - for( i = 0; i < 7; i++ ) + for( int i = 0; i < 7; i++ ) { NET_StringToFilterAdr( adrs[i], &f[i].adr, &f[i].prefixlen ); } - for( i = 0; i < ARRAYSIZE( tests ); i++ ) + for( int i = 0; i < ARRAYSIZE( tests ); i++ ) { ret = SV_IPFilterIncludesIPFilter( &f[tests[i][0]], &f[tests[i][1]] ); diff --git a/engine/server/sv_frame.c b/engine/server/sv_frame.c index e0285f92..2bac8388 100644 --- a/engine/server/sv_frame.c +++ b/engine/server/sv_frame.c @@ -35,10 +35,8 @@ SV_EntityNumbers */ static int SV_EntityNumbers( const void *a, const void *b ) { - int ent1, ent2; - - ent1 = ((entity_state_t *)a)->number; - ent2 = ((entity_state_t *)b)->number; + int ent1 = ((entity_state_t *)a)->number; + int ent2 = ((entity_state_t *)b)->number; // watcom libc compares ents with itself if( ent1 == ent2 ) @@ -57,14 +55,10 @@ SV_AddEntitiesToPacket */ static void SV_AddEntitiesToPacket( edict_t *pViewEnt, edict_t *pClient, client_frame_t *frame, sv_ents_t *ents, qboolean from_client ) { - edict_t *ent; byte *clientpvs = NULL; byte *clientphs = NULL; qboolean fullvis = false; sv_client_t *cl = NULL; - qboolean player; - entity_state_t *state; - int e; // during an error shutdown message we may need to transmit // the shutdown message after the server has shutdown, so @@ -92,11 +86,12 @@ static void SV_AddEntitiesToPacket( edict_t *pViewEnt, edict_t *pClient, client_ if( !clientpvs ) fullvis = true; // g-cont: of course we can send world but not want to do it :-) - for( e = 1; e < svgame.numEntities; e++ ) + for( int e = 1; e < svgame.numEntities; e++ ) { byte *pset; - - ent = SV_EdictNum( e ); + edict_t *ent = SV_EdictNum( e ); + qboolean player; + entity_state_t *state; // don't double add an entity through portals (in case this already added) if( CHECKVISBIT( ents->sended, e )) @@ -184,14 +179,13 @@ set frame to NULL to check for static entities int SV_FindBestBaseline( int index, entity_state_t **baseline, entity_state_t *to, client_frame_t *frame, qboolean player ) { int bestBitCount; - int i, bitCount; int bestfound, j; bestBitCount = j = Delta_TestBaseline( *baseline, to, player, sv.time ); bestfound = index; // lookup backward for previous 64 states and try to interpret current delta as baseline - for( i = index - 1; bestBitCount > 0 && i >= 0 && ( index - i ) < ( MAX_CUSTOM_BASELINES - 1 ); i-- ) + for( int i = index - 1; bestBitCount > 0 && i >= 0 && ( index - i ) < ( MAX_CUSTOM_BASELINES - 1 ); i-- ) { // don't worry about underflow in circular buffer entity_state_t *test; @@ -204,7 +198,7 @@ int SV_FindBestBaseline( int index, entity_state_t **baseline, entity_state_t *t if( to->entityType == test->entityType ) { - bitCount = Delta_TestBaseline( test, to, player, sv.time ); + int bitCount = Delta_TestBaseline( test, to, player, sv.time ); if( bitCount < bestBitCount ) { @@ -236,7 +230,7 @@ static void SV_EmitPacketEntities( sv_client_t *cl, client_frame_t *to, sizebuf_ { entity_state_t *oldent, *newent; int oldindex, newindex; - int i, oldnum, newnum; + int oldnum, newnum; qboolean player; int oldmax; client_frame_t *from; @@ -326,7 +320,7 @@ static void SV_EmitPacketEntities( sv_client_t *cl, client_frame_t *to, sizebuf_ } else { - for( i = 0; i < sv.num_instanced; i++ ) + for( int i = 0; i < sv.num_instanced; i++ ) { if( !Q_strcmp( classname, sv.instanced[i].classname )) { @@ -372,17 +366,16 @@ static void SV_EmitEvents( sv_client_t *cl, client_frame_t *to, sizebuf_t *msg ) { event_state_t *es; event_info_t *info; - entity_state_t *state; event_args_t nullargs; int ev_count = 0; int count, ent_index; - int i, j, ev; + int i, j; memset( &nullargs, 0, sizeof( nullargs )); es = &cl->events; // count events - for( ev = 0; ev < MAX_EVENT_QUEUE; ev++ ) + for( int ev = 0; ev < MAX_EVENT_QUEUE; ev++ ) { if( es->ei[ev].index ) ev_count++; @@ -404,7 +397,7 @@ static void SV_EmitEvents( sv_client_t *cl, client_frame_t *to, sizebuf_t *msg ) for( j = 0; j < to->num_entities; j++ ) { - state = &svs.packet_entities[(to->first_entity+j) % svs.num_client_entities]; + entity_state_t *state = &svs.packet_entities[(to->first_entity+j) % svs.num_client_entities]; if( state->number == ent_index ) break; } @@ -531,7 +524,6 @@ static void SV_WriteClientdataToMessage( sv_client_t *cl, sizebuf_t *msg ) weapon_data_t *from_wd, *to_wd; client_frame_t *frame; edict_t *clent; - int i; memset( &nullcd, 0, sizeof( nullcd )); frame = &cl->frames[cl->netchan.outgoing_sequence & SV_UPDATE_MASK]; @@ -590,7 +582,7 @@ static void SV_WriteClientdataToMessage( sv_client_t *cl, sizebuf_t *msg ) { memset( &nullwd, 0, sizeof( nullwd )); - for( i = 0; i < MAX_LOCAL_WEAPONS; i++ ) + for( int i = 0; i < MAX_LOCAL_WEAPONS; i++ ) { if( cl->delta_sequence == -1 ) from_wd = &nullwd; else from_wd = &cl->frames[cl->delta_sequence & SV_UPDATE_MASK].weapondata[i]; @@ -613,9 +605,8 @@ SV_WriteEntitiesToClient static void SV_WriteEntitiesToClient( sv_client_t *cl, sizebuf_t *msg ) { client_frame_t *frame; - entity_state_t *state; static sv_ents_t frame_ents; - int i, send_pings; + int send_pings; frame = &cl->frames[cl->netchan.outgoing_sequence & SV_UPDATE_MASK]; send_pings = SV_ShouldUpdatePing( cl ); @@ -656,10 +647,10 @@ static void SV_WriteEntitiesToClient( sv_client_t *cl, sizebuf_t *msg ) frame->first_entity = svs.next_client_entities; frame->num_entities = 0; - for( i = 0; i < frame_ents.num_entities; i++ ) + for( int i = 0; i < frame_ents.num_entities; i++ ) { // add it to the circular packet_entities array - state = &svs.packet_entities[svs.next_client_entities % svs.num_client_entities]; + entity_state_t *state = &svs.packet_entities[svs.next_client_entities % svs.num_client_entities]; *state = frame_ents.entities[i]; svs.next_client_entities++; frame->num_entities++; @@ -821,7 +812,6 @@ void SV_SendClientMessages( void ) { sv_client_t *cl; int i; - double time_until_next_message; if( sv.state == ss_dead ) return; @@ -851,7 +841,7 @@ void SV_SendClientMessages( void ) // If the target time for sending is within the next frame interval ( based on last frame ), // trigger the send now. Note that in single player, // FCL_SEND_NET_MESSAGE flag is also set any time a packet arrives from the client. - time_until_next_message = cl->next_messagetime - ( host.realtime + sv.frametime ); + double time_until_next_message = cl->next_messagetime - ( host.realtime + sv.frametime ); if( time_until_next_message <= 0.0 ) SetBits( cl->flags, FCL_SEND_NET_MESSAGE ); else if( time_until_next_message > 2.0 ) // something got hosed diff --git a/engine/server/sv_game.c b/engine/server/sv_game.c index 4977889c..c8691604 100644 --- a/engine/server/sv_game.c +++ b/engine/server/sv_game.c @@ -164,12 +164,10 @@ update entity bounds, relink into world */ void SV_SetMinMaxSize( edict_t *e, const float *mins, const float *maxs, qboolean relink ) { - int i; - if( !SV_IsValidEdict( e )) return; - for( i = 0; i < 3; i++ ) + for( int i = 0; i < 3; i++ ) { if( mins[i] > maxs[i] ) { @@ -301,7 +299,6 @@ Check visibility through client camera, portal camera, etc */ static qboolean SV_CheckClientVisiblity( sv_client_t *cl, const byte *mask ) { - int i; vec3_t vieworg; mleaf_t *leaf; @@ -319,7 +316,7 @@ static qboolean SV_CheckClientVisiblity( sv_client_t *cl, const byte *mask ) return true; // visible from player view or camera view // now check all the portal cameras - for( i = 0; i < cl->num_viewents; i++ ) + for( int i = 0; i < cl->num_viewents; i++ ) { edict_t *view = cl->viewentity[i]; @@ -532,7 +529,6 @@ qboolean SV_CreateStaticEntity( sizebuf_t *msg, int index ) { entity_state_t nullstate, *baseline; entity_state_t *state; - int offset; if( index >= ( MAX_STATIC_ENTITIES - 1 )) { @@ -563,7 +559,7 @@ qboolean SV_CreateStaticEntity( sizebuf_t *msg, int index ) state->number = 0; // trying to compress with previous delta's - offset = SV_FindBestBaseline( index, &baseline, state, NULL, false ); + int offset = SV_FindBestBaseline( index, &baseline, state, NULL, false ); MSG_BeginServerCmd( msg, svc_spawnstatic ); MSG_WriteDeltaEntity( baseline, state, msg, true, DELTA_STATIC, sv.time, offset ); @@ -580,13 +576,11 @@ Write all the static ents into demo */ void SV_RestartStaticEnts( void ) { - int i; - // remove all the static entities on the client CL_ClearStaticEntities(); // resend them again - for( i = 0; i < sv.num_static_entities; i++ ) + for( int i = 0; i < sv.num_static_entities; i++ ) SV_CreateStaticEntity( &sv.reliable_datagram, i ); } @@ -617,7 +611,7 @@ void SV_RestartAmbientSounds( void ) #if !XASH_DEDICATED soundlist_t soundInfo[256]; string curtrack, looptrack; - int i, nSounds; + int nSounds; int position; if( !SV_Active( ) || Host_IsDedicated( )) @@ -625,7 +619,7 @@ void SV_RestartAmbientSounds( void ) nSounds = S_GetCurrentStaticSounds( soundInfo, 256 ); - for( i = 0; i < nSounds; i++ ) + for( int i = 0; i < nSounds; i++ ) { soundlist_t *si = &soundInfo[i]; @@ -657,10 +651,8 @@ void SV_RestartDecals( void ) // and better be reimplemented on client side #if !XASH_DEDICATED decallist_t *list; - int decalIndex; - int modelIndex; sizebuf_t *msg; - int i, numdecals; + int numdecals; if( !SV_Active( ) || Host_IsDedicated( )) return; @@ -677,16 +669,16 @@ void SV_RestartDecals( void ) msg = SV_GetReliableDatagram(); // restore decals and write them into network message - for( i = 0; i < numdecals; i++ ) + for( int i = 0; i < numdecals; i++ ) { decallist_t *entry = &list[i]; - modelIndex = SV_PEntityOfEntIndex( entry->entityIndex, true )->v.modelindex; + int modelIndex = SV_PEntityOfEntIndex( entry->entityIndex, true )->v.modelindex; // game override if( SV_RestoreCustomDecal( entry, SV_PEntityOfEntIndex( entry->entityIndex, true ), false )) continue; - decalIndex = pfnDecalIndex( entry->name ); + int decalIndex = pfnDecalIndex( entry->name ); // studiodecals will be restored at game-side if( !FBitSet( entry->flags, FDECAL_STUDIO )) @@ -1164,12 +1156,9 @@ release all the edicts from server */ void SV_FreeEdicts( void ) { - int i = 0; - edict_t *ent; - - for( i = 0; i < svgame.numEntities; i++ ) + for( int i = 0; i < svgame.numEntities; i++ ) { - ent = SV_EdictNum( i ); + edict_t *ent = SV_EdictNum( i ); if( ent->free ) continue; SV_FreeEdict( ent ); } @@ -1315,7 +1304,6 @@ pfnModelIndex static int GAME_EXPORT pfnModelIndex( const char *m ) { char name[MAX_QPATH]; - int i; if( COM_StringEmptyOrNULL( m )) return 0; @@ -1324,7 +1312,7 @@ static int GAME_EXPORT pfnModelIndex( const char *m ) Q_strncpy( name, m, sizeof( name )); COM_FixSlashes( name ); - for( i = 1; i < MAX_MODELS && sv.model_precache[i][0]; i++ ) + for( int i = 1; i < MAX_MODELS && sv.model_precache[i][0]; i++ ) { if( !Q_stricmp( sv.model_precache[i], name )) return i; @@ -1484,17 +1472,15 @@ SV_FindEntityByString */ static edict_t *GAME_EXPORT SV_FindEntityByString( edict_t *pStartEdict, const char *pszField, const char *pszValue ) { - int i = 0, e = 0; + int e = 0; const TYPEDESCRIPTION *desc = NULL; - edict_t *ed; - const char *t; if( COM_StringEmptyOrNULL( pszValue )) return svgame.edicts; if( pStartEdict ) e = NUM_FOR_EDICT( pStartEdict ); - for( i = 0; i < ARRAYSIZE( gEntvarsDescription ); i++ ) + for( int i = 0; i < ARRAYSIZE( gEntvarsDescription ); i++ ) { if( !Q_strcmp( pszField, gEntvarsDescription[i].fieldName )) { @@ -1511,7 +1497,9 @@ static edict_t *GAME_EXPORT SV_FindEntityByString( edict_t *pStartEdict, const c for( e++; e < svgame.numEntities; e++ ) { - ed = SV_EdictNum( e ); + edict_t *ed = SV_EdictNum( e ); + const char *t; + if( !SV_IsValidEdict( ed )) continue; if( e <= svs.maxclients && !SV_ClientFromEdict( ed, ( svs.maxclients != 1 ))) @@ -1568,10 +1556,7 @@ find the entity in sphere */ static edict_t *GAME_EXPORT pfnFindEntityInSphere( edict_t *pStartEdict, const float *org, float flRadius ) { - float distSquared; - int j, e = 0; - float eorg; - edict_t *ent; + int e = 0; flRadius *= flRadius; @@ -1580,7 +1565,8 @@ static edict_t *GAME_EXPORT pfnFindEntityInSphere( edict_t *pStartEdict, const f for( e++; e < svgame.numEntities; e++ ) { - ent = SV_EdictNum( e ); + edict_t *ent = SV_EdictNum( e ); + float distSquared = 0.0f; if( !SV_IsValidEdict( ent )) continue; @@ -1589,10 +1575,10 @@ static edict_t *GAME_EXPORT pfnFindEntityInSphere( edict_t *pStartEdict, const f if( e <= svs.maxclients && !SV_ClientFromEdict( ent, true )) continue; - distSquared = 0.0f; - - for( j = 0; j < 3 && distSquared <= flRadius; j++ ) + for( int j = 0; j < 3 && distSquared <= flRadius; j++ ) { + float eorg; + if( org[j] < ent->v.absmin[j] ) eorg = org[j] - ent->v.absmin[j]; else if( org[j] > ent->v.absmax[j] ) @@ -1621,7 +1607,7 @@ static int SV_CheckClientPVS( int check, qboolean bMergePVS ) byte *pvs; vec3_t vieworg; sv_client_t *cl; - int i, j, k; + int i; edict_t *ent = NULL; // cycle to the next one @@ -1658,7 +1644,7 @@ static int SV_CheckClientPVS( int check, qboolean bMergePVS ) if( !cl ) return i; // now merge PVS with all the portal cameras - for( k = 0; k < cl->num_viewents && bMergePVS; k++ ) + for( int k = 0; k < cl->num_viewents && bMergePVS; k++ ) { edict_t *view = cl->viewentity[k]; @@ -1668,7 +1654,7 @@ static int SV_CheckClientPVS( int check, qboolean bMergePVS ) VectorAdd( view->v.origin, view->v.view_ofs, vieworg ); pvs = Mod_GetPVSForPoint( vieworg ); - for( j = 0; j < world.visbytes && pvs; j++ ) + for( int j = 0; j < world.visbytes && pvs; j++ ) SetBits( clientpvs[j], pvs[j] ); } @@ -1742,10 +1728,8 @@ pfnEntitiesInPVS */ static edict_t *pfnEntitiesInPVS( edict_t *pview ) { - edict_t *pchain, *ptest; + edict_t *pchain; vec3_t viewpoint; - edict_t *pent; - int i; if( !SV_IsValidEdict( pview )) return NULL; @@ -1753,9 +1737,10 @@ static edict_t *pfnEntitiesInPVS( edict_t *pview ) VectorAdd( pview->v.origin, pview->v.view_ofs, viewpoint ); pchain = SV_EdictNum( 0 ); - for( i = 1; i < svgame.numEntities; i++ ) + for( int i = 1; i < svgame.numEntities; i++ ) { - pent = SV_EdictNum( i ); + edict_t *pent = SV_EdictNum( i ); + edict_t *ptest; if( !SV_IsValidEdict( pent )) continue; @@ -2270,8 +2255,7 @@ static void GAME_EXPORT pfnGetAimVector( edict_t* ent, float speed, float *rgflR { edict_t *check; vec3_t start, dir, end, bestdir; - float dist, bestdist; - int i, j; + float bestdist; trace_t tr; VectorCopy( svgame.globals->v_forward, rgflReturn ); // assume failure if it returns early @@ -2298,8 +2282,10 @@ static void GAME_EXPORT pfnGetAimVector( edict_t* ent, float speed, float *rgflR else bestdist = 0; check = SV_EdictNum( 1 ); // start at first client - for( i = 1; i < svgame.numEntities; i++, check++ ) + for( int i = 1; i < svgame.numEntities; i++, check++ ) { + float dist; + if( check->v.takedamage != DAMAGE_AIM ) continue; @@ -2312,7 +2298,7 @@ static void GAME_EXPORT pfnGetAimVector( edict_t* ent, float speed, float *rgflR if( check == ent ) continue; - for( j = 0; j < 3; j++ ) + for( int j = 0; j < 3; j++ ) end[j] = check->v.origin[j] + 0.5f * (check->v.mins[j] + check->v.maxs[j]); VectorSubtract( end, start, dir ); @@ -2455,12 +2441,10 @@ register decal name on client */ int GAME_EXPORT pfnDecalIndex( const char *m ) { - int i; - if( COM_StringEmptyOrNULL( m )) return -1; - for( i = 1; i < MAX_DECALS && host.draw_decals[i][0]; i++ ) + for( int i = 1; i < MAX_DECALS && host.draw_decals[i][0]; i++ ) { if( !Q_stricmp( host.draw_decals[i], m )) return i; @@ -2533,7 +2517,7 @@ pfnMessageBegin */ static void GAME_EXPORT pfnMessageBegin( int msg_dest, int msg_num, const float *pOrigin, edict_t *ed ) { - int i, iSize; + int iSize; if( svgame.msg_started ) Host_Error( "%s: New message started when msg '%s' has not been sent yet\n", __func__, svgame.msg_name ); @@ -2567,6 +2551,8 @@ static void GAME_EXPORT pfnMessageBegin( int msg_dest, int msg_num, const float } else { + int i; + // check for existing for( i = 1; i < MAX_USER_MESSAGES && svgame.msg[i].name[0]; i++ ) { @@ -3387,11 +3373,9 @@ pfnIndexOfEdict */ int GAME_EXPORT pfnIndexOfEdict( const edict_t *pEdict ) { - int number; - if( !pEdict ) return 0; // world ? - number = NUM_FOR_EDICT( pEdict ); + int number = NUM_FOR_EDICT( pEdict ); if( number < 0 || number > GI->max_edicts ) Host_Error( "bad entity number %d\n", number ); return number; @@ -3429,15 +3413,12 @@ debug thing */ static edict_t *GAME_EXPORT pfnFindEntityByVars( entvars_t *pvars ) { - edict_t *pEdict; - int i; - // don't pass invalid arguments if( !pvars ) return NULL; - for( i = 0; i < GI->max_edicts; i++ ) + for( int i = 0; i < GI->max_edicts; i++ ) { - pEdict = SV_EdictNum( i ); + edict_t *pEdict = SV_EdictNum( i ); // g-cont: we should compare pointers if( &pEdict->v == pvars ) @@ -3863,9 +3844,9 @@ returns actual entity count */ int GAME_EXPORT pfnNumberOfEntities( void ) { - int i, total = 0; + int total = 0; - for( i = 0; i < svgame.numEntities; i++ ) + for( int i = 0; i < svgame.numEntities; i++ ) { if( svgame.edicts[i].free ) continue; @@ -4030,7 +4011,7 @@ void GAME_EXPORT SV_PlaybackEventFull( int flags, const edict_t *pInvoker, word event_state_t *es; event_args_t args; event_info_t *ei = NULL; - int j, slot, bestslot; + int j, bestslot; int invokerIndex; byte *mask = NULL; vec3_t pvspoint; @@ -4138,7 +4119,8 @@ void GAME_EXPORT SV_PlaybackEventFull( int flags, const edict_t *pInvoker, word } // process all the clients - for( slot = 0, cl = svs.clients; slot < svs.maxclients; slot++, cl++ ) + cl = svs.clients; + for( int slot = 0; slot < svs.maxclients; slot++, cl++ ) { if( cl->state != cs_spawned || !cl->edict || FBitSet( cl->flags, FCL_FAKECLIENT )) continue; @@ -4328,7 +4310,7 @@ pfnCheckVisibility */ static int GAME_EXPORT pfnCheckVisibility( const edict_t *ent, byte *pset ) { - int i, leafnum; + int i; qboolean large_leafs = FBitSet( sv.worldmodel->flags, MODEL_QBSP2 ); if( !SV_IsValidEdict( ent )) @@ -4361,6 +4343,8 @@ static int GAME_EXPORT pfnCheckVisibility( const edict_t *ent, byte *pset ) } else { + int leafnum; + for( i = 0; i < MAX_ENT_LEAFS( large_leafs ); i++ ) { if( large_leafs ) @@ -4496,17 +4480,14 @@ pfnForceUnmodified */ static void GAME_EXPORT pfnForceUnmodified( FORCE_TYPE type, float *mins, float *maxs, const char *filename ) { - consistency_t *pc; - int i; - if( COM_StringEmptyOrNULL( filename )) return; if( sv.state == ss_loading ) { - for( i = 0; i < MAX_MODELS; i++ ) + for( int i = 0; i < MAX_MODELS; i++ ) { - pc = &sv.consistency_list[i]; + consistency_t *pc = &sv.consistency_list[i]; if( !pc->filename ) { @@ -4523,9 +4504,9 @@ static void GAME_EXPORT pfnForceUnmodified( FORCE_TYPE type, float *mins, float } else { - for( i = 0; i < MAX_MODELS; i++ ) + for( int i = 0; i < MAX_MODELS; i++ ) { - pc = &sv.consistency_list[i]; + consistency_t *pc = &sv.consistency_list[i]; if( !pc->filename ) continue; if( !Q_strcmp( filename, pc->filename )) @@ -4886,7 +4867,7 @@ static qboolean SV_ParseEdict( char **pfile, edict_t *ent ) { KeyValueData pkvd[256]; // per one entity qboolean adjust_origin = false, customentity; - int i, numpairs = 0; + int numpairs = 0; const char *classname = NULL; // go through all the dictionary pairs @@ -5008,7 +4989,7 @@ static qboolean SV_ParseEdict( char **pfile, edict_t *ent ) } #endif - for( i = 0; i < numpairs; i++ ) + for( int i = 0; i < numpairs; i++ ) { char *keyname, *value; char temp[MAX_VA_STRING]; @@ -5080,7 +5061,6 @@ static void SV_LoadFromFile( const char *mapname, char *entities ) { char token[2048]; qboolean create_world = true; - int inhibited; edict_t *ent; Assert( entities != NULL ); @@ -5088,7 +5068,7 @@ static void SV_LoadFromFile( const char *mapname, char *entities ) // user dll can override spawn entities function (Xash3D extension) if( !svgame.physFuncs.SV_LoadEntities || !svgame.physFuncs.SV_LoadEntities( mapname, entities )) { - inhibited = 0; + int inhibited = 0; // parse ents while(( entities = COM_ParseFile( entities, token, sizeof( token ))) != NULL ) @@ -5213,7 +5193,7 @@ void SV_UnloadProgs( void ) qboolean SV_LoadProgs( const char *name ) { - int i, version; + int version; static APIFUNCTION GetEntityAPI; static APIFUNCTION2 GetEntityAPI2; static GIVEFNPTRSTODLL GiveFnptrsToDll; @@ -5221,7 +5201,6 @@ qboolean SV_LoadProgs( const char *name ) static enginefuncs_t gpEngfuncs; static globalvars_t gpGlobals; static playermove_t gpMove; - edict_t *e; qboolean init_entity_api = false; if( svgame.hInstance ) @@ -5342,8 +5321,8 @@ qboolean SV_LoadProgs( const char *name ) svs.baselines = Z_Calloc( sizeof( entity_state_t ) * GI->max_edicts ); svgame.numEntities = svs.maxclients + 1; // clients + world - for( i = 0, e = svgame.edicts; i < GI->max_edicts; i++, e++ ) - e->free = true; // mark all edicts as freed + for( int i = 0; i < GI->max_edicts; i++ ) + svgame.edicts[i].free = true; // mark all edicts as freed Cvar_FullSet( "host_gameloaded", "1", FCVAR_READ_ONLY ); SV_AllocStringPool(); diff --git a/engine/server/sv_init.c b/engine/server/sv_init.c index ed72b974..5af5637c 100644 --- a/engine/server/sv_init.c +++ b/engine/server/sv_init.c @@ -301,7 +301,6 @@ static void SV_ReadResourceList( const char *filename ) string token; byte *afile; char *pfile; - resourcetype_t restype; afile = FS_LoadFile( filename, NULL, false ); if( !afile ) return; @@ -313,6 +312,8 @@ static void SV_ReadResourceList( const char *filename ) while(( pfile = COM_ParseFile( pfile, token, sizeof( token ))) != NULL ) { + resourcetype_t restype; + if( !COM_IsSafeFileToDownload( token )) continue; @@ -349,7 +350,6 @@ loads external resource list static void SV_CreateGenericResources( void ) { string filename; - int i; Q_strncpy( filename, sv.model_precache[1], sizeof( filename )); COM_ReplaceExtension( filename, ".res", sizeof( filename )); @@ -359,7 +359,7 @@ static void SV_CreateGenericResources( void ) SV_ReadResourceList( "reslist.txt" ); // precache wads so client can knows this map needs some extra wad files - for( i = 0; i < world.wadcount; i++ ) + for( int i = 0; i < world.wadcount; i++ ) { if( world.wadlist[i].usage > 0 ) SV_GenericIndex( world.wadlist[i].name ); @@ -375,7 +375,6 @@ add resources to common list */ static void SV_CreateResourceList( void ) { - qboolean ffirstsent = false; int i, nSize; char *s; @@ -389,6 +388,7 @@ static void SV_CreateResourceList( void ) SV_AddResource( t_generic, s, nSize, RES_FATALIFMISSING, i ); } + qboolean ffirstsent = false; for( i = 1; i < MAX_SOUNDS; i++ ) { s = sv.sound_precache[i]; @@ -554,10 +554,9 @@ remove immediate entities void SV_FreeOldEntities( void ) { edict_t *ent; - int i; // at end of frame kill all entities which supposed to it - for( i = svs.maxclients + 1; i < svgame.numEntities; i++ ) + for( int i = svs.maxclients + 1; i < svgame.numEntities; i++ ) { ent = SV_EdictNum( i ); @@ -681,7 +680,6 @@ deactivate server, free edicts, strings etc */ void SV_DeactivateServer( void ) { - int i; const char *cycle = Cvar_VariableString( "disconcfgfile" ); if( !COM_StringEmptyOrNULL( cycle )) @@ -706,7 +704,7 @@ void SV_DeactivateServer( void ) SV_EmptyStringPool( true ); Mem_EmptyPool( svgame.stringspool ); - for( i = 0; i < svs.maxclients; i++ ) + for( int i = 0; i < svs.maxclients; i++ ) { // release client frames if( svs.clients[i].frames ) @@ -860,7 +858,6 @@ static void SV_GenerateTestPacket( void ) uint32_t crc; file_t *file; byte *filepos; - int i; if( !sv_allow_testpacket.value ) { @@ -907,7 +904,7 @@ static void SV_GenerateTestPacket( void ) crc = 0; // intentional omit of CRC32_Init because of the client // TODO: shrink to minimum! - for( i = 0; i < svs.testpacket_filelen; i++ ) + for( int i = 0; i < svs.testpacket_filelen; i++ ) { CRC32_ProcessByte( &crc, filepos[i] ); svs.testpacket_crcs[i] = crc; @@ -934,9 +931,7 @@ clients along with it. */ qboolean SV_SpawnServer( const char *mapname, const char *startspot, qboolean background ) { - int i, current_skill; - edict_t *ent; - const char *cycle; + int i; SV_SetupClients(); @@ -959,7 +954,7 @@ qboolean SV_SpawnServer( const char *mapname, const char *startspot, qboolean ba for( i = 0; i < ARRAYSIZE( svs.challenge_salt ); i++ ) svs.challenge_salt[i] = COM_RandomLong( 0, 0x7FFFFFFE ); - cycle = Cvar_VariableString( "mapchangecfgfile" ); + const char *cycle = Cvar_VariableString( "mapchangecfgfile" ); if( !COM_StringEmptyOrNULL( cycle )) Cbuf_AddTextf( "exec %s\n", cycle ); @@ -996,7 +991,7 @@ qboolean SV_SpawnServer( const char *mapname, const char *startspot, qboolean ba // make cvars consistant if( coop.value ) Cvar_SetValue( "deathmatch", 0 ); - current_skill = Q_rint( skill.value ); + int current_skill = Q_rint( skill.value ); current_skill = bound( 0, current_skill, 3 ); Cvar_SetValue( "skill", (float)current_skill ); @@ -1053,6 +1048,8 @@ qboolean SV_SpawnServer( const char *mapname, const char *startspot, qboolean ba // leave slots at start for clients only for( i = 0; i < svs.maxclients; i++ ) { + edict_t *ent; + // needs to reconnect if( svs.clients[i].state > cs_connected ) svs.clients[i].state = cs_connected; diff --git a/engine/server/sv_log.c b/engine/server/sv_log.c index bd49756b..77cd548e 100644 --- a/engine/server/sv_log.c +++ b/engine/server/sv_log.c @@ -18,12 +18,9 @@ GNU General Public License for more details. void Log_Open( void ) { - time_t ltime; - struct tm *today; char szFileBase[ MAX_OSPATH ]; char szTestFile[ MAX_OSPATH ]; file_t *fp = NULL; - const char *temp; int i; if( !svs.log.active ) @@ -41,9 +38,10 @@ void Log_Open( void ) Log_Close(); // Find a new log file slot + time_t ltime; time( <ime ); - today = localtime( <ime ); - temp = Cvar_VariableString( "logsdir" ); + const struct tm *today = localtime( <ime ); + const char *temp = Cvar_VariableString( "logsdir" ); if( !COM_StringEmptyOrNULL( temp ) && !Q_strchr( temp, ':' ) && !Q_strstr( temp, ".." )) Q_snprintf( szFileBase, sizeof( szFileBase ), "%s/L%02i%02i", temp, today->tm_mon + 1, today->tm_mday ); @@ -102,21 +100,18 @@ void Log_Printf( const char *fmt, ... ) { va_list argptr; static char string[1024]; - char *p; - time_t ltime; - struct tm *today; - int len; if( !svs.log.net_log && !svs.log.active ) return; + time_t ltime; time( <ime ); - today = localtime( <ime ); + const struct tm *today = localtime( <ime ); - len = Q_snprintf( string, sizeof( string ), "%02i/%02i/%04i - %02i:%02i:%02i: ", + const int len = Q_snprintf( string, sizeof( string ), "%02i/%02i/%04i - %02i:%02i:%02i: ", today->tm_mon+1, today->tm_mday, 1900 + today->tm_year, today->tm_hour, today->tm_min, today->tm_sec ); - p = string + len; + char *p = string + len; va_start( argptr, fmt ); Q_vsnprintf( p, sizeof( string ) - len, fmt, argptr ); @@ -166,10 +161,6 @@ SV_SetLogAddress_f */ void SV_SetLogAddress_f( void ) { - const char *s; - int port; - string addr; - if( svs.log.net_log && Cmd_Argc() == 2 && !Q_strcmp( Cmd_Argv( 1 ), "off" )) { svs.log.net_log = false; @@ -190,20 +181,21 @@ void SV_SetLogAddress_f( void ) return; } - port = Q_atoi( Cmd_Argv( 2 )); + const int port = Q_atoi( Cmd_Argv( 2 )); if( !port ) { Con_Printf( "logaddress: must specify a valid port\n" ); return; } - s = Cmd_Argv( 1 ); + const char *s = Cmd_Argv( 1 ); if( COM_StringEmptyOrNULL( s )) { Con_Printf( "logaddress: unparseable address\n" ); return; } + string addr; Q_snprintf( addr, sizeof( addr ), "%s:%i", s, port ); if( !NET_StringToAdr( addr, &svs.log.net_address )) { diff --git a/engine/server/sv_main.c b/engine/server/sv_main.c index afce862f..98d4ddea 100644 --- a/engine/server/sv_main.c +++ b/engine/server/sv_main.c @@ -165,12 +165,10 @@ returns true if server have spawned players */ static qboolean SV_HasActivePlayers( void ) { - int i; - // server inactive if( !svs.clients ) return false; - for( i = 0; i < svs.maxclients; i++ ) + for( int i = 0; i < svs.maxclients; i++ ) { if( svs.clients[i].state == cs_spawned ) return true; @@ -250,7 +248,6 @@ static void SV_CheckCmdTimes( void ) { sv_client_t *cl; static double lastreset = 0; - float diff; int i; if( sv_fps.value != 0.0f ) @@ -280,7 +277,7 @@ static void SV_CheckCmdTimes( void ) cl->connecttime = host.realtime; } - diff = cl->connecttime + cl->cmdtime - host.realtime; + float diff = cl->connecttime + cl->cmdtime - host.realtime; if( diff > net_clockwindow.value ) { @@ -303,7 +300,6 @@ process incoming file (customization) */ static void SV_ProcessFile( sv_client_t *cl, const char *filename ) { - customization_t *pList; resource_t *resource; resource_t *next; byte md5[16]; @@ -345,7 +341,7 @@ static void SV_ProcessFile( sv_client_t *cl, const char *filename ) bError = false; bFound = false; - for( pList = cl->customdata.pNext; pList; pList = pList->pNext ) + for( customization_t *pList = cl->customdata.pNext; pList; pList = pList->pNext ) { if( !memcmp( pList->resource.rgucMD5_hash, resource->rgucMD5_hash, 16 )) { @@ -549,12 +545,9 @@ player processing happens outside RunWorldFrame */ static void SV_PrepWorldFrame( void ) { - edict_t *ent; - int i; - - for( i = 1; i < svgame.numEntities; i++ ) + for( int i = 1; i < svgame.numEntities; i++ ) { - ent = SV_EdictNum( i ); + edict_t *ent = SV_EdictNum( i ); if( ent->free ) continue; ClearBits( ent->v.effects, EF_MUZZLEFLASH|EF_NOINTERP ); @@ -788,7 +781,7 @@ qboolean SV_ProcessUserAgent( netadr_t from, const char *useragent ) { const char *input_devices_str = Info_ValueForKey( useragent, "d" ); const char *id = Info_ValueForKey( useragent, "uuid" ); - size_t len, i; + size_t len; len = Q_strlen( id ); if( len != 32 ) @@ -797,7 +790,7 @@ qboolean SV_ProcessUserAgent( netadr_t from, const char *useragent ) return false; } - for( i = 0; i < len; i++ ) + for( size_t i = 0; i < len; i++ ) { char c = id[i]; diff --git a/engine/server/sv_move.c b/engine/server/sv_move.c index dbc6436f..d00d027c 100644 --- a/engine/server/sv_move.c +++ b/engine/server/sv_move.c @@ -229,11 +229,9 @@ float SV_VecToYaw( const vec3_t src ) qboolean SV_MoveStep( edict_t *ent, vec3_t move, qboolean relink ) { - int i; trace_t trace; vec3_t oldorg, neworg, end; qboolean monsterClip; - edict_t *enemy; float dz; VectorCopy( ent->v.origin, oldorg ); @@ -243,8 +241,10 @@ qboolean SV_MoveStep( edict_t *ent, vec3_t move, qboolean relink ) // well, try it. Flying and swimming monsters are easiest. if( FBitSet( ent->v.flags, FL_SWIM|FL_FLY )) { + edict_t *enemy = NULL; + // try one move with vertical motion, then one without - for( i = 0; i < 2; i++ ) + for( int i = 0; i < 2; i++ ) { VectorAdd( ent->v.origin, move, neworg ); diff --git a/engine/server/sv_phys.c b/engine/server/sv_phys.c index 38fdd112..910de8e8 100644 --- a/engine/server/sv_phys.c +++ b/engine/server/sv_phys.c @@ -68,8 +68,6 @@ SV_CheckAllEnts static void SV_CheckAllEnts( void ) { static double nextcheck; - edict_t *e; - int i; if( !sv_check_errors.value || sv.state != ss_active ) return; @@ -81,9 +79,9 @@ static void SV_CheckAllEnts( void ) nextcheck = Platform_DoubleTime() + 5.0; // check edicts errors - for( i = svs.maxclients + 1; i < svgame.numEntities; i++ ) + for( int i = svs.maxclients + 1; i < svgame.numEntities; i++ ) { - e = SV_EdictNum( i ); + edict_t *e = SV_EdictNum( i ); if( e->free && e->pvPrivateData != NULL ) { @@ -121,10 +119,9 @@ void SV_CheckVelocity( edict_t *ent ) { float wishspd; float maxspd; - int i; // bound velocity - for( i = 0; i < 3; i++ ) + for( int i = 0; i < 3; i++ ) { if( IS_NAN( ent->v.velocity[i] )) { @@ -335,14 +332,13 @@ may use friction for smooth stopping static void SV_AngularMove( edict_t *ent, float frametime, float friction ) { float adjustment; - int i; VectorMA( ent->v.angles, frametime, ent->v.avelocity, ent->v.angles ); if( friction == 0.0f ) return; adjustment = frametime * (sv_stopspeed.value / 10.0f) * sv_friction.value * fabs( friction ); - for( i = 0; i < 3; i++ ) + for( int i = 0; i < 3; i++ ) { if( ent->v.avelocity[i] > 0.0f ) { @@ -368,7 +364,6 @@ use friction for smooth stopping */ static void SV_LinearMove( edict_t *ent, float frametime, float friction ) { - int i; float adjustment; VectorMA( ent->v.origin, frametime, ent->v.velocity, ent->v.origin ); @@ -376,7 +371,7 @@ static void SV_LinearMove( edict_t *ent, float frametime, float friction ) adjustment = frametime * (sv_stopspeed.value / 10.0f) * sv_friction.value * fabs( friction ); - for( i = 0; i < 3; i++ ) + for( int i = 0; i < 3; i++ ) { if( ent->v.velocity[i] > 0.0f ) { @@ -549,8 +544,7 @@ Slide off of the impacting object static int SV_ClipVelocity( vec3_t in, vec3_t normal, vec3_t out, float overbounce ) { float backoff; - float change; - int i, blocked; + int blocked; blocked = 0; if( normal[2] > 0.0f ) blocked |= 1; // floor @@ -558,9 +552,9 @@ static int SV_ClipVelocity( vec3_t in, vec3_t normal, vec3_t out, float overboun backoff = DotProduct( in, normal ) * overbounce; - for( i = 0; i < 3; i++ ) + for( int i = 0; i < 3; i++ ) { - change = normal[i] * backoff; + float change = normal[i] * backoff; out[i] = in[i] - change; if( out[i] > -1.0f && out[i] < 1.0f ) @@ -591,15 +585,14 @@ Returns the clipflags if the velocity was modified (hit something solid) */ static int SV_FlyMove( edict_t *ent, float time, trace_t *steptrace ) { - int i, j, numplanes, bumpcount, blocked; + int i, j, numplanes, blocked; vec3_t dir, end, planes[MAX_CLIP_PLANES]; vec3_t primal_velocity, original_velocity, new_velocity; - float d, time_left, allFraction; - qboolean monsterClip; + float time_left, allFraction; + qboolean monsterClip = FBitSet( ent->v.flags, FL_MONSTERCLIP ) ? true : false; trace_t trace; blocked = 0; - monsterClip = FBitSet( ent->v.flags, FL_MONSTERCLIP ) ? true : false; VectorCopy( ent->v.velocity, original_velocity ); VectorCopy( ent->v.velocity, primal_velocity ); VectorClear( new_velocity ); @@ -608,7 +601,7 @@ static int SV_FlyMove( edict_t *ent, float time, trace_t *steptrace ) allFraction = 0.0f; time_left = time; - for( bumpcount = 0; bumpcount < MAX_CLIP_PLANES - 1; bumpcount++ ) + for( int bumpcount = 0; bumpcount < MAX_CLIP_PLANES - 1; bumpcount++ ) { if( VectorIsNull( ent->v.velocity )) break; @@ -709,7 +702,7 @@ static int SV_FlyMove( edict_t *ent, float time, trace_t *steptrace ) } CrossProduct( planes[0], planes[1], dir ); - d = DotProduct( dir, ent->v.velocity ); + float d = DotProduct( dir, ent->v.velocity ); VectorScale( dir, d, ent->v.velocity ); } @@ -898,11 +891,9 @@ SV_PushMove */ static edict_t *SV_PushMove( edict_t *pusher, float movetime ) { - int i, e, block; int oldsolid; vec3_t mins, maxs, lmove; - sv_pushed_t *p, *pushed_p; - edict_t *check; + sv_pushed_t *pushed_p; if( svgame.globals->changelevel || VectorIsNull( pusher->v.velocity )) { @@ -910,7 +901,7 @@ static edict_t *SV_PushMove( edict_t *pusher, float movetime ) return NULL; } - for( i = 0; i < 3; i++ ) + for( int i = 0; i < 3; i++ ) { lmove[i] = pusher->v.velocity[i] * movetime; mins[i] = pusher->v.absmin[i] + lmove[i]; @@ -936,9 +927,10 @@ static edict_t *SV_PushMove( edict_t *pusher, float movetime ) return NULL; // see if any solid entities are inside the final position - for( e = 1; e < svgame.numEntities; e++ ) + for( int e = 1; e < svgame.numEntities; e++ ) { - check = SV_EdictNum( e ); + edict_t *check = SV_EdictNum( e ); + int block; if( !SV_IsValidEdict( check )) continue; // filter movetypes to collide with @@ -992,7 +984,7 @@ static edict_t *SV_PushMove( edict_t *pusher, float movetime ) // move back any entities we already moved // go backwards, so if the same entity was pushed // twice, it goes back to the original position - for( p = pushed_p - 1; p >= svgame.pushed; p-- ) + for( sv_pushed_t *p = pushed_p - 1; p >= svgame.pushed; p-- ) { VectorCopy( p->origin, p->ent->v.origin ); VectorCopy( p->angles, p->ent->v.angles ); @@ -1013,12 +1005,11 @@ SV_PushRotate */ static edict_t *SV_PushRotate( edict_t *pusher, float movetime ) { - int i, e, block, oldsolid; + int oldsolid; matrix4x4 start_l, end_l; vec3_t lmove, amove; - sv_pushed_t *p, *pushed_p; + sv_pushed_t *pushed_p; vec3_t org, org2, temp; - edict_t *check; if( svgame.globals->changelevel || VectorIsNull( pusher->v.avelocity )) { @@ -1026,7 +1017,7 @@ static edict_t *SV_PushRotate( edict_t *pusher, float movetime ) return NULL; } - for( i = 0; i < 3; i++ ) + for( int i = 0; i < 3; i++ ) amove[i] = pusher->v.avelocity[i] * movetime; // create pusher initial position @@ -1054,9 +1045,10 @@ static edict_t *SV_PushRotate( edict_t *pusher, float movetime ) Matrix4x4_CreateFromEntity( end_l, pusher->v.angles, pusher->v.origin, 1.0f ); // see if any solid entities are inside the final position - for( e = 1; e < svgame.numEntities; e++ ) + for( int e = 1; e < svgame.numEntities; e++ ) { - check = SV_EdictNum( e ); + edict_t *check = SV_EdictNum( e ); + int block; if( !SV_IsValidEdict( check )) continue; @@ -1129,7 +1121,7 @@ static edict_t *SV_PushRotate( edict_t *pusher, float movetime ) // move back any entities we already moved // go backwards, so if the same entity was pushed // twice, it goes back to the original position - for( p = pushed_p - 1; p >= svgame.pushed; p-- ) + for( sv_pushed_t *p = pushed_p - 1; p >= svgame.pushed; p-- ) { VectorCopy( p->origin, p->ent->v.origin ); VectorCopy( p->angles, p->ent->v.angles ); @@ -1151,10 +1143,9 @@ SV_Physics_Pusher */ static void SV_Physics_Pusher( edict_t *ent ) { - float oldtime, oldtime2; + float oldtime; float thinktime, movetime; edict_t *pBlocker; - int i; pBlocker = NULL; oldtime = ent->v.ltime; @@ -1177,7 +1168,7 @@ static void SV_Physics_Pusher( edict_t *ent ) if( !pBlocker ) { - oldtime2 = ent->v.ltime; + float oldtime2 = ent->v.ltime; // reset the local time to what it was before we rotated ent->v.ltime = oldtime; @@ -1201,7 +1192,7 @@ static void SV_Physics_Pusher( edict_t *ent ) // otherwise, just stay in place until the obstacle is gone if( pBlocker ) svgame.dllFuncs.pfnBlocked( ent, pBlocker ); - for( i = 0; i < 3; i++ ) + for( int i = 0; i < 3; i++ ) { if( ent->v.angles[i] < -3600.0f || ent->v.angles[i] > 3600.0f ) ent->v.angles[i] = fmod( ent->v.angles[i], 3600.0f ); @@ -1589,7 +1580,6 @@ static void SV_Physics_Step( edict_t *ent ) vec3_t mins, maxs; vec3_t point; trace_t trace; - int x, y; SV_WaterMove( ent ); SV_CheckVelocity( ent ); @@ -1661,12 +1651,12 @@ static void SV_Physics_Step( edict_t *ent ) point[2] = mins[2] - 1.0f; - for( x = 0; x <= 1; x++ ) + for( int x = 0; x <= 1; x++ ) { if( FBitSet( ent->v.flags, FL_ONGROUND )) break; - for( y = 0; y <= 1; y++ ) + for( int y = 0; y <= 1; y++ ) { point[0] = x ? maxs[0] : mins[0]; point[1] = y ? maxs[1] : mins[1]; @@ -1783,10 +1773,8 @@ static void SV_Physics_Entity( edict_t *ent ) static void SV_RunLightStyles( void ) { - int i; - // run lightstyles animation - for( i = 0; i < MAX_LIGHTSTYLES; i++ ) + for( int i = 0; i < MAX_LIGHTSTYLES; i++ ) { lightstyle_t *ls = &sv.lightstyles[i]; int ofs; @@ -1811,9 +1799,6 @@ SV_Physics */ void SV_Physics( void ) { - edict_t *ent; - int i; - SV_CheckAllEnts (); svgame.globals->time = sv.time; @@ -1822,9 +1807,9 @@ void SV_Physics( void ) svgame.dllFuncs.pfnStartFrame(); // treat each object in turn - for( i = 0; i < svgame.numEntities; i++ ) + for( int i = 0; i < svgame.numEntities; i++ ) { - ent = SV_EdictNum( i ); + edict_t *ent = SV_EdictNum( i ); if( !SV_IsValidEdict( ent )) continue; diff --git a/engine/server/sv_pmove.c b/engine/server/sv_pmove.c index 40f977ae..c401a9f5 100644 --- a/engine/server/sv_pmove.c +++ b/engine/server/sv_pmove.c @@ -283,12 +283,13 @@ static void SV_AddLaddersToPmove( areanode_t *node, const vec3_t pmove_mins, con { link_t *l, *next; edict_t *check; - model_t *mod; - physent_t *pe; // get ladder edicts for( l = node->solid_edicts.next; l != &node->solid_edicts; l = next ) { + model_t *mod; + physent_t *pe; + next = l->next; check = EDICT_FROM_AREA( l ); @@ -323,8 +324,6 @@ static void SV_AddLaddersToPmove( areanode_t *node, const vec3_t pmove_mins, con static void GAME_EXPORT pfnParticle( const float *origin, int color, float life, int zpos, int zvel ) { - int v; - if( !origin ) { Con_Reportf( S_ERROR "%s: NULL origin. Ignored\n", __func__ ); @@ -335,7 +334,7 @@ static void GAME_EXPORT pfnParticle( const float *origin, int color, float life, MSG_WriteVec3Coord( &sv.reliable_datagram, origin ); MSG_WriteChar( &sv.reliable_datagram, 0 ); // no x-vel MSG_WriteChar( &sv.reliable_datagram, 0 ); // no y-vel - v = bound( -128, (zpos * zvel) * 16.0f, 127 ); + int v = bound( -128, (zpos * zvel) * 16.0f, 127 ); MSG_WriteChar( &sv.reliable_datagram, v ); // write z-vel MSG_WriteByte( &sv.reliable_datagram, 1 ); MSG_WriteByte( &sv.reliable_datagram, color ); @@ -441,8 +440,6 @@ SV_InitClientMove */ void SV_InitClientMove( void ) { - int i; - Pmove_Init (); svgame.pmove->server = true; @@ -450,7 +447,7 @@ void SV_InitClientMove( void ) svgame.pmove->runfuncs = false; // enumerate client hulls - for( i = 0; i < MAX_MAP_HULLS; i++ ) + for( int i = 0; i < MAX_MAP_HULLS; i++ ) { if( svgame.dllFuncs.pfnGetHullBounds( i, host.player_mins[i], host.player_maxs[i] )) Con_Reportf( "SV: hull%i, player_mins: %g %g %g, player_maxs: %g %g %g\n", i, @@ -522,7 +519,6 @@ static void SV_SetupPMove( playermove_t *pmove, sv_client_t *cl, usercmd_t *ucmd { vec3_t absmin, absmax; edict_t *clent = cl->edict; - int i; svgame.globals->frametime = (ucmd->msec * 0.001f); @@ -581,7 +577,7 @@ static void SV_SetupPMove( playermove_t *pmove, sv_client_t *cl, usercmd_t *ucmd pmove->numphysent = 0; pmove->nummoveent = 0; - for( i = 0; i < 3; i++ ) + for( int i = 0; i < 3; i++ ) { absmin[i] = clent->v.origin[i] - 256.0f; absmax[i] = clent->v.origin[i] + 256.0f; @@ -665,12 +661,9 @@ static void SV_FinishPMove( playermove_t *pmove, sv_client_t *cl ) static entity_state_t *SV_FindEntInPack( int index, client_frame_t *frame ) { - entity_state_t *state; - int i; - - for( i = 0; i < frame->num_entities; i++ ) + for( int i = 0; i < frame->num_entities; i++ ) { - state = &svs.packet_entities[(frame->first_entity+i)%svs.num_client_entities]; + entity_state_t *state = &svs.packet_entities[(frame->first_entity+i)%svs.num_client_entities]; if( state->number == index ) return state; @@ -680,9 +673,7 @@ static entity_state_t *SV_FindEntInPack( int index, client_frame_t *frame ) static qboolean SV_UnlagCheckTeleport( vec3_t old_pos, vec3_t new_pos ) { - int i; - - for( i = 0; i < 3; i++ ) + for( int i = 0; i < 3; i++ ) { if( fabs( old_pos[i] - new_pos[i] ) > 64.0f ) return true; @@ -692,12 +683,11 @@ static qboolean SV_UnlagCheckTeleport( vec3_t old_pos, vec3_t new_pos ) static void SV_SetupMoveInterpolant( sv_client_t *cl ) { - int i, j, clientnum; + int i; float finalpush, lerp_msec; float latency, lerpFrac; client_frame_t *frame, *frame2; - entity_state_t *state, *lerpstate; - vec3_t curpos, newpos; + entity_state_t *state; sv_client_t *check; sv_interp_t *lerp; @@ -749,7 +739,7 @@ static void SV_SetupMoveInterpolant( sv_client_t *cl ) { frame = &cl->frames[(cl->netchan.outgoing_sequence - (i + 1)) & SV_UPDATE_MASK]; - for( j = 0; j < frame->num_entities; j++ ) + for( int j = 0; j < frame->num_entities; j++ ) { state = &svs.packet_entities[(frame->first_entity+j)%svs.num_client_entities]; @@ -803,6 +793,10 @@ static void SV_SetupMoveInterpolant( sv_client_t *cl ) for( i = 0; i < frame->num_entities; i++ ) { + int clientnum; + entity_state_t *lerpstate; + vec3_t curpos, newpos; + state = &svs.packet_entities[(frame->first_entity+i)%svs.num_client_entities]; if( state->number < 1 || state->number > svs.maxclients ) @@ -846,7 +840,6 @@ static void SV_SetupMoveInterpolant( sv_client_t *cl ) static void SV_RestoreMoveInterpolant( sv_client_t *cl ) { sv_client_t *check; - sv_interp_t *oldlerp; int i; if( !has_update ) @@ -860,6 +853,8 @@ static void SV_RestoreMoveInterpolant( sv_client_t *cl ) for( i = 0, check = svs.clients; i < svs.maxclients; i++, check++ ) { + sv_interp_t *oldlerp; + if( check->state != cs_spawned || check == cl ) continue; @@ -886,12 +881,8 @@ SV_RunCmd */ void SV_RunCmd( sv_client_t *cl, usercmd_t *ucmd, int random_seed ) { - edict_t *clent, *touch; + edict_t *clent; double frametime; - int i, oldmsec; - pmtrace_t *pmtrace; - trace_t trace; - vec3_t oldvel; usercmd_t cmd; // if the player got kicked, do not process commands @@ -924,7 +915,7 @@ void SV_RunCmd( sv_client_t *cl, usercmd_t *ucmd, int random_seed ) // chop up very long commands if( cmd.msec > 50 ) { - oldmsec = ucmd->msec; + int oldmsec = ucmd->msec; cmd.msec = oldmsec / 2; SV_RunCmd( cl, &cmd, random_seed ); cmd.msec = oldmsec / 2; @@ -980,15 +971,19 @@ void SV_RunCmd( sv_client_t *cl, usercmd_t *ucmd, int random_seed ) } else { + vec3_t oldvel; + // link into place and touch triggers SV_LinkEdict( clent, true ); VectorCopy( clent->v.velocity, oldvel ); // save velocity // touch other objects - for( i = 0; i < svgame.pmove->numtouch; i++ ) + for( int i = 0; i < svgame.pmove->numtouch; i++ ) { - pmtrace = &svgame.pmove->touchindex[i]; - touch = SV_EdictNum( svgame.pmove->physents[pmtrace->ent].info ); + pmtrace_t *pmtrace = &svgame.pmove->touchindex[i]; + edict_t *touch = SV_EdictNum( svgame.pmove->physents[pmtrace->ent].info ); + trace_t trace; + VectorCopy( pmtrace->deltavelocity, clent->v.velocity ); PM_ConvertTrace( &trace, pmtrace, touch ); SV_Impact( touch, clent, &trace ); diff --git a/engine/server/sv_query.c b/engine/server/sv_query.c index 2bed6ab1..7e05f0b6 100644 --- a/engine/server/sv_query.c +++ b/engine/server/sv_query.c @@ -71,7 +71,6 @@ SV_SourceQuery_Rules */ static void SV_SourceQuery_Rules( netadr_t from ) { - const cvar_t *cvar; sizebuf_t buf; char answer[MAX_PRINT_MSG - 4]; int pos; @@ -85,7 +84,7 @@ static void SV_SourceQuery_Rules( netadr_t from ) pos = MSG_GetNumBitsWritten( &buf ); MSG_WriteShort( &buf, 0 ); - for( cvar = Cvar_GetList( ); cvar; cvar = cvar->next ) + for( const cvar_t *cvar = Cvar_GetList( ); cvar; cvar = cvar->next ) { if( !FBitSet( cvar->flags, FCVAR_SERVER )) continue; @@ -123,7 +122,7 @@ static void SV_SourceQuery_Players( netadr_t from ) { sizebuf_t buf; char answer[MAX_PRINT_MSG - 4]; - int i, count = 0; + int count = 0; int pos; // respect players privacy @@ -138,7 +137,7 @@ static void SV_SourceQuery_Players( netadr_t from ) pos = MSG_GetNumBitsWritten( &buf ); MSG_WriteByte( &buf, 0 ); - for( i = 0; i < svs.maxclients; i++ ) + for( int i = 0; i < svs.maxclients; i++ ) { const sv_client_t *cl = &svs.clients[i]; diff --git a/engine/server/sv_save.c b/engine/server/sv_save.c index dab5c4b0..653a359d 100644 --- a/engine/server/sv_save.c +++ b/engine/server/sv_save.c @@ -389,16 +389,13 @@ reserve space for ETABLE's */ static void InitEntityTable( SAVERESTOREDATA *pSaveData, int entityCount ) { - ENTITYTABLE *pTable; - int i; - pSaveData->pTable = Mem_Calloc( host.mempool, sizeof( ENTITYTABLE ) * entityCount ); pSaveData->tableCount = entityCount; // setup entitytable - for( i = 0; i < entityCount; i++ ) + for( int i = 0; i < entityCount; i++ ) { - pTable = &pSaveData->pTable[i]; + ENTITYTABLE *pTable = &pSaveData->pTable[i]; pTable->pent = SV_EdictNum( i ); pTable->id = i; } @@ -413,9 +410,7 @@ check level in transition list */ static int EntryInTable( SAVERESTOREDATA *pSaveData, const char *pMapName, int index ) { - int i; - - for( i = index + 1; i < pSaveData->connectionCount; i++ ) + for( int i = index + 1; i < pSaveData->connectionCount; i++ ) { if ( !Q_stricmp( pSaveData->levelList[i].mapName, pMapName )) return i; @@ -451,9 +446,7 @@ find global offset for a given landmark */ static void LandmarkOrigin( SAVERESTOREDATA *pSaveData, vec3_t output, const char *pLandmarkName ) { - int i; - - for( i = 0; i < pSaveData->connectionCount; i++ ) + for( int i = 0; i < pSaveData->connectionCount; i++ ) { if( !Q_strcmp( pSaveData->levelList[i].landmarkName, pLandmarkName )) { @@ -499,13 +492,12 @@ remove all the temp files HL1-HL3 static void ClearSaveDir( void ) { search_t *t; - int i; // just delete all HL? files t = FS_Search( DEFAULT_SAVE_DIRECTORY "*.HL?", true, true ); if( !t ) return; // already empty - for( i = 0; i < t->numfilenames; i++ ) + for( int i = 0; i < t->numfilenames; i++ ) FS_Delete( t->filenames[i] ); Mem_Free( t ); @@ -646,18 +638,16 @@ put the HL1-HL3 files into .sav file */ static void DirectoryCopy( const char *pPath, file_t *pFile ) { - char szName[MAX_OSPATH]; - int i, fileSize; - file_t *pCopy; search_t *t; t = FS_Search( pPath, true, true ); if( !t ) return; // nothing to copy ? - for( i = 0; i < t->numfilenames; i++ ) + for( int i = 0; i < t->numfilenames; i++ ) { - pCopy = FS_Open( t->filenames[i], "rb", true ); - fileSize = FS_FileLength( pCopy ); + char szName[MAX_OSPATH]; + file_t *pCopy = FS_Open( t->filenames[i], "rb", true ); + int fileSize = FS_FileLength( pCopy ); memset( szName, 0, sizeof( szName )); // clearing the string to prevent garbage in output file Q_strncpy( szName, COM_FileWithoutPath( t->filenames[i] ), sizeof( szName )); @@ -678,13 +668,13 @@ extract the HL1-HL3 files from the .sav file */ static qboolean DirectoryExtract( file_t *pFile, int fileCount ) { - char szName[MAX_OSPATH]; - char fileName[MAX_OSPATH]; - int i, fileSize; - file_t *pCopy; - - for( i = 0; i < fileCount; i++ ) + for( int i = 0; i < fileCount; i++ ) { + char szName[MAX_OSPATH]; + char fileName[MAX_OSPATH]; + int fileSize; + file_t *pCopy; + // filename can only be as long as a map name + extension FS_Read( pFile, szName, MAX_OSPATH ); FS_Read( pFile, &fileSize, sizeof( int )); @@ -792,12 +782,11 @@ write the stringtable into file static char *StoreHashTable( SAVERESTOREDATA *pSaveData ) { char *pTokenData = pSaveData->pCurrentData; - int i; // Write entity string token table if( pSaveData->pTokens ) { - for( i = 0; i < pSaveData->tokenCount; i++ ) + for( int i = 0; i < pSaveData->tokenCount; i++ ) { const char *pszToken = pSaveData->pTokens[i] ? pSaveData->pTokens[i] : ""; @@ -823,7 +812,6 @@ build the stringtable from buffer static void BuildHashTable( SAVERESTOREDATA *pSaveData, file_t *pFile ) { char *pszTokenList = pSaveData->pBaseData; - int i; // Parse the symbol table if( pSaveData->tokenSize > 0 ) @@ -831,7 +819,7 @@ static void BuildHashTable( SAVERESTOREDATA *pSaveData, file_t *pFile ) FS_Read( pFile, pszTokenList, pSaveData->tokenSize ); // make sure the token strings pointed to by the pToken hashtable. - for( i = 0; i < pSaveData->tokenCount; i++ ) + for( int i = 0; i < pSaveData->tokenCount; i++ ) { pSaveData->pTokens[i] = *pszTokenList ? pszTokenList : NULL; while( *pszTokenList++ ); // Find next token (after next null) @@ -1056,7 +1044,7 @@ read the list of entities that are no longer in the save file for this level static void EntityPatchRead( SAVERESTOREDATA *pSaveData, const char *level ) { char name[MAX_QPATH]; - int i, size, entityId; + int size; file_t *pFile; Q_snprintf( name, sizeof( name ), DEFAULT_SAVE_DIRECTORY "%s.HL3", level ); @@ -1067,8 +1055,10 @@ static void EntityPatchRead( SAVERESTOREDATA *pSaveData, const char *level ) // patch count FS_Read( pFile, &size, sizeof( int )); - for( i = 0; i < size; i++ ) + for( int i = 0; i < size; i++ ) { + int entityId; + FS_Read( pFile, &entityId, sizeof( int )); pSaveData->pTable[entityId].flags = FENTTABLE_REMOVED; } @@ -1189,7 +1179,7 @@ static qboolean SaveClientState( SAVERESTOREDATA *pSaveData, const char *level, soundlist_t soundInfo[MAX_CHANNELS]; sv_client_t *cl = svs.clients; char name[MAX_QPATH]; - int i, id, version; + int i; char *pTokenData; decallist_t *decalList = NULL; SAVE_CLIENT header = { 0 }; @@ -1265,8 +1255,8 @@ static qboolean SaveClientState( SAVERESTOREDATA *pSaveData, const char *level, return false; } - version = CLIENT_SAVEGAME_VERSION; - id = SAVEGAME_HEADER; + int version = CLIENT_SAVEGAME_VERSION; + int id = SAVEGAME_HEADER; FS_Write( pFile, &id, sizeof( id )); FS_Write( pFile, &version, sizeof( version )); @@ -1628,10 +1618,7 @@ load current game state static int LoadGameState( char const *level, qboolean changelevel ) { SAVERESTOREDATA *pSaveData; - ENTITYTABLE *pTable; SAVE_HEADER header; - edict_t *pent; - int i; pSaveData = LoadSaveData( level ); if( !pSaveData ) return 0; // couldn't load the file @@ -1661,9 +1648,11 @@ static int LoadGameState( char const *level, qboolean changelevel ) CreateEntitiesInRestoreList( pSaveData, 0, true ); // now spawn entities - for( i = 0; i < pSaveData->tableCount; i++ ) + for( int i = 0; i < pSaveData->tableCount; i++ ) { - pTable = &pSaveData->pTable[i]; + ENTITYTABLE *pTable = &pSaveData->pTable[i]; + edict_t *pent; + pSaveData->pCurrentData = pSaveData->pBaseData + pTable->location; pSaveData->size = pTable->location; pSaveData->currentIndex = i; @@ -1705,7 +1694,6 @@ static qboolean SaveGameSlot( const char *pSaveName, const char *pSaveComment ) { char hlPath[MAX_QPATH]; char name[MAX_QPATH]; - int id, version; char *pTokenData; SAVERESTOREDATA *pSaveData; GAME_HEADER gameHeader; @@ -1753,8 +1741,8 @@ static qboolean SaveGameSlot( const char *pSaveName, const char *pSaveComment ) Cbuf_AddTextf( "saveshot \"%s\"\n", pSaveName ); Con_Printf( "Saving game to %s...\n", name ); - version = SAVEGAME_VERSION; - id = SAVEGAME_HEADER; + int version = SAVEGAME_VERSION; + int id = SAVEGAME_HEADER; FS_Write( pFile, &id, sizeof( id )); FS_Write( pFile, &version, sizeof( version )); @@ -1835,9 +1823,7 @@ moving edicts to another level */ static int CreateEntityTransitionList( SAVERESTOREDATA *pSaveData, int levelMask ) { - int i, movedCount; - ENTITYTABLE *pTable; - edict_t *pent; + int movedCount; movedCount = 0; @@ -1845,9 +1831,11 @@ static int CreateEntityTransitionList( SAVERESTOREDATA *pSaveData, int levelMask CreateEntitiesInRestoreList( pSaveData, levelMask, false ); // now spawn entities - for( i = 0; i < pSaveData->tableCount; i++ ) + for( int i = 0; i < pSaveData->tableCount; i++ ) { - pTable = &pSaveData->pTable[i]; + ENTITYTABLE *pTable = &pSaveData->pTable[i]; + edict_t *pent; + pSaveData->pCurrentData = pSaveData->pBaseData + pTable->location; pSaveData->size = pTable->location; pSaveData->currentIndex = i; @@ -2261,16 +2249,16 @@ used for reload game after player death const char *SV_GetLatestSave( void ) { static char savename[MAX_QPATH]; - int newest = 0, ft; - int i, found = 0; + int newest = 0; + int found = 0; search_t *t; if(( t = FS_Search( DEFAULT_SAVE_DIRECTORY "*.sav" , true, true )) == NULL ) return NULL; - for( i = 0; i < t->numfilenames; i++ ) + for( int i = 0; i < t->numfilenames; i++ ) { - ft = FS_FileTime( t->filenames[i], true ); + int ft = FS_FileTime( t->filenames[i], true ); // found a match? if( ft > 0 ) diff --git a/engine/server/sv_world.c b/engine/server/sv_world.c index b2e984e4..ae598dfe 100644 --- a/engine/server/sv_world.c +++ b/engine/server/sv_world.c @@ -53,14 +53,12 @@ can just be stored out and get a proper hull_t structure. */ static void SV_InitBoxHull( void ) { - int i; - box_hull.clipnodes16 = (mclipnode16_t *)box_clipnodes16; box_hull.planes = box_planes; box_hull.firstclipnode = 0; box_hull.lastclipnode = 5; - for( i = 0; i < 6; i++ ) + for( int i = 0; i < 6; i++ ) { box_planes[i].type = i>>1; box_planes[i].normal[i>>1] = 1; @@ -108,7 +106,7 @@ check clients only */ static qboolean SV_CheckSphereIntersection( edict_t *ent, const vec3_t start, const vec3_t end ) { - int i, sequence; + int sequence; float radiusSquared; vec3_t traceOrg, traceDir; studiohdr_t *pstudiohdr; @@ -134,7 +132,7 @@ static qboolean SV_CheckSphereIntersection( edict_t *ent, const vec3_t start, co VectorSubtract( end, start, traceDir ); radiusSquared = 0.0f; - for ( i = 0; i < 3; i++ ) + for ( int i = 0; i < 3; i++ ) radiusSquared += Q_max( fabs( pseqdesc->bbmin[i] ), fabs( pseqdesc->bbmax[i] )); return SphereIntersect( ent->v.origin, radiusSquared, traceOrg, traceDir ); @@ -465,12 +463,10 @@ SV_ClearWorld */ void SV_ClearWorld( void ) { - int i; - SV_InitBoxHull(); // for box testing // clear lightstyles - for( i = 0; i < MAX_LIGHTSTYLES; i++ ) + for( int i = 0; i < MAX_LIGHTSTYLES; i++ ) { sv.lightstyles[i].value = 256.0f; sv.lightstyles[i].time = 0.0f; @@ -506,14 +502,15 @@ SV_TouchLinks static void SV_TouchLinks( edict_t *ent, areanode_t *node ) { link_t *l, *next; - edict_t *touch; - hull_t *hull; - vec3_t test, offset; - model_t *mod; // touch linked edicts for( l = node->trigger_edicts.next; l != &node->trigger_edicts; l = next ) { + edict_t *touch; + hull_t *hull; + vec3_t test, offset; + model_t *mod; + next = l->next; touch = EDICT_FROM_AREA( l ); @@ -593,7 +590,6 @@ SV_FindTouchedLeafs static void SV_FindTouchedLeafs( edict_t *ent, model_t *mod, mnode_t *node, int *headnode ) { int sides; - mleaf_t *leaf; if( node->contents == CONTENTS_SOLID ) return; @@ -609,7 +605,7 @@ static void SV_FindTouchedLeafs( edict_t *ent, model_t *mod, mnode_t *node, int } else { - leaf = (mleaf_t *)node; + mleaf_t *leaf = (mleaf_t *)node; if( FBitSet( mod->flags, MODEL_QBSP2 )) ent->leafnums32[ent->num_leafs] = leaf->cluster; else @@ -640,7 +636,6 @@ SV_LinkEdict void GAME_EXPORT SV_LinkEdict( edict_t *ent, qboolean touch_triggers ) { areanode_t *node; - int headnode; if( ent->area.prev ) SV_UnlinkEdict( ent ); // unlink from old position if( ent == svgame.edicts ) return; // don't add the world @@ -657,10 +652,11 @@ void GAME_EXPORT SV_LinkEdict( edict_t *ent, qboolean touch_triggers ) } else { + int headnode = -1; + // link to PVS leafs ent->num_leafs = 0; ent->headnode = -1; - headnode = -1; if( ent->v.modelindex ) SV_FindTouchedLeafs( ent, sv.worldmodel, sv.worldmodel->nodes, &headnode ); @@ -715,14 +711,15 @@ POINT TESTING IN HULLS static void SV_WaterLinks( const vec3_t origin, int *pCont, areanode_t *node ) { link_t *l, *next; - edict_t *touch; - hull_t *hull; - vec3_t test, offset; - model_t *mod; // get water edicts for( l = node->solid_edicts.next; l != &node->solid_edicts; l = next ) { + edict_t *touch; + hull_t *hull; + vec3_t test, offset; + model_t *mod; + next = l->next; touch = EDICT_FROM_AREA( l ); @@ -838,10 +835,8 @@ void SV_ClipMoveToEntity( edict_t *ent, const vec3_t start, vec3_t mins, vec3_t hull_t *hull; model_t *model; vec3_t start_l, end_l; - vec3_t offset, temp; - int last_hitgroup; - trace_t trace_hitbox; - int i, j, hullcount; + vec3_t offset; + int hullcount; qboolean rotated, transform_bbox; matrix4x4 matrix; @@ -889,7 +884,7 @@ void SV_ClipMoveToEntity( edict_t *ent, const vec3_t start, vec3_t mins, vec3_t World_TransformAABB( matrix, mins, maxs, out_mins, out_maxs ); VectorSubtract( hull->clip_mins, out_mins, offset ); // calc new local offset - for( j = 0; j < 3; j++ ) + for( int j = 0; j < 3; j++ ) { if( start_l[j] >= 0.0f ) start_l[j] -= offset[j]; @@ -912,9 +907,10 @@ void SV_ClipMoveToEntity( edict_t *ent, const vec3_t start, vec3_t mins, vec3_t } else { - last_hitgroup = 0; + int last_hitgroup = 0; + trace_t trace_hitbox; - for( i = 0; i < hullcount; i++ ) + for( int i = 0; i < hullcount; i++ ) { PM_InitTrace( &trace_hitbox, end ); @@ -943,6 +939,8 @@ void SV_ClipMoveToEntity( edict_t *ent, const vec3_t start, vec3_t mins, vec3_t if( rotated ) { + vec3_t temp; + // transform plane VectorCopy( trace->plane.normal, temp ); Matrix4x4_TransformPositivePlane( matrix, temp, trace->plane.dist, trace->plane.normal, &trace->plane.dist ); @@ -969,7 +967,7 @@ continue the trace to the edges of the portal cutout instead. static void SV_PortalCSG( edict_t *portal, const vec3_t trace_mins, const vec3_t trace_maxs, const vec3_t start, const vec3_t end, trace_t *trace ) { vec4_t planes[6]; //far, near, right, left, up, down - int plane, k; + int plane; vec3_t worldpos; float bestfrac; int hitplane; @@ -1010,7 +1008,7 @@ static void SV_PortalCSG( edict_t *portal, const vec3_t trace_mins, const vec3_t float d = DotProduct( worldpos, planes[plane] ); vec3_t nearest; - for( k = 0; k < 3; k++ ) + for( int k = 0; k < 3; k++ ) nearest[k] = (planes[plane][k]>=0) ? trace_maxs[k] : trace_mins[k]; // front plane gets further away with side @@ -1210,11 +1208,12 @@ Mins and maxs enclose the entire area swept by the move static void SV_ClipToLinks( areanode_t *node, moveclip_t *clip ) { link_t *l, *next; - edict_t *touch; // touch linked edicts for( l = node->solid_edicts.next; l != &node->solid_edicts; l = next ) { + edict_t *touch; + next = l->next; touch = EDICT_FROM_AREA( l ); @@ -1242,11 +1241,12 @@ Mins and maxs enclose the entire area swept by the move static void SV_ClipToPortals( areanode_t *node, moveclip_t *clip ) { link_t *l, *next; - edict_t *touch; // touch linked edicts for( l = node->portal_edicts.next; l != &node->portal_edicts; l = next ) { + edict_t *touch; + next = l->next; touch = EDICT_FROM_AREA( l ); @@ -1274,11 +1274,12 @@ Mins and maxs enclose the entire area swept by the move static void SV_ClipToWorldBrush( areanode_t *node, moveclip_t *clip ) { link_t *l, *next; - edict_t *touch; - trace_t trace; for( l = node->solid_edicts.next; l != &node->solid_edicts; l = next ) { + edict_t *touch; + trace_t trace; + next = l->next; touch = EDICT_FROM_AREA( l ); @@ -1472,7 +1473,6 @@ trace_t SV_MoveToss( edict_t *tossent, edict_t *ignore ) vec3_t original_angles; vec3_t original_avelocity; trace_t trace; - int i; VectorCopy( tossent->v.origin, original_origin ); VectorCopy( tossent->v.velocity, original_velocity ); @@ -1480,7 +1480,7 @@ trace_t SV_MoveToss( edict_t *tossent, edict_t *ignore ) VectorCopy( tossent->v.avelocity, original_avelocity ); gravity = tossent->v.gravity * sv_gravity.value * 0.05f; - for( i = 0; i < 200; i++ ) + for( int i = 0; i < 200; i++ ) { SV_CheckVelocity( tossent ); tossent->v.velocity[2] -= gravity; @@ -1516,7 +1516,7 @@ SV_RecursiveLightPoint static qboolean SV_RecursiveLightPoint( model_t *model, mnode_t *node, const vec3_t start, const vec3_t end, vec3_t point_color ) { float front, back, frac; - int i, side; + int side; vec3_t mid; int numsurfaces, firstsurface; @@ -1546,7 +1546,7 @@ static qboolean SV_RecursiveLightPoint( model_t *model, mnode_t *node, const vec // check for impact on this node numsurfaces = node_numsurfaces( node, model ); firstsurface = node_firstsurface( node, model ); - for( i = 0; i < numsurfaces; i++ ) + for( int i = 0; i < numsurfaces; i++ ) { const msurface_t *surf = &model->surfaces[firstsurface + i]; const mextrasurf_t *info = surf->info; @@ -1611,13 +1611,13 @@ needs to get correct working SV_LightPoint */ void SV_SetLightStyle( int style, const char* s, float f ) { - int j, k; + int j; j = Q_strncpy( sv.lightstyles[style].pattern, s, sizeof( sv.lightstyles[0].pattern )); sv.lightstyles[style].time = f; sv.lightstyles[style].length = j; - for( k = 0; k < j; k++ ) + for( int k = 0; k < j; k++ ) sv.lightstyles[style].map[k] = (float)(s[k] - 'a'); if( sv.state != ss_active ) return;