From 52d1383f14d1de3505efca3639ab0bff061709fc Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Wed, 25 May 2022 03:50:06 +0300 Subject: [PATCH] engine: client: fix various useless checks, unused variables & defines, double assignments and mistypings --- engine/client/cl_custom.c | 2 +- engine/client/cl_efrag.c | 2 -- engine/client/cl_game.c | 4 ++-- engine/client/cl_main.c | 7 +++---- engine/client/cl_parse.c | 15 ++------------- engine/client/cl_pmove.c | 1 - engine/client/cl_tent.c | 3 +-- engine/client/console.c | 33 ++++++++++++++------------------- engine/client/in_touch.c | 1 - engine/client/keys.c | 2 +- engine/client/s_dsp.c | 10 +++------- engine/client/s_main.c | 1 - 12 files changed, 27 insertions(+), 54 deletions(-) diff --git a/engine/client/cl_custom.c b/engine/client/cl_custom.c index e1baee8f..b279b361 100644 --- a/engine/client/cl_custom.c +++ b/engine/client/cl_custom.c @@ -106,7 +106,7 @@ void CL_RemoveFromResourceList( resource_t *pResource ) if( pResource->pPrev == NULL || pResource->pNext == NULL ) Host_Error( "mislinked resource in CL_RemoveFromResourceList\n" ); - if ( pResource->pNext == pResource || pResource->pPrev == pResource ) + if( pResource->pNext == pResource || pResource->pPrev == pResource ) Host_Error( "attempt to free last entry in list.\n" ); pResource->pPrev->pNext = pResource->pNext; diff --git a/engine/client/cl_efrag.c b/engine/client/cl_efrag.c index 5df1b6bd..366134a2 100644 --- a/engine/client/cl_efrag.c +++ b/engine/client/cl_efrag.c @@ -188,8 +188,6 @@ void R_StoreEfrags( efrag_t **ppefrag, int framecount ) case mod_brush: case mod_studio: case mod_sprite: - pent = pefrag->entity; - if( pent->visframe != framecount ) { if( CL_AddVisibleEntity( pent, ET_FRAGMENTED )) diff --git a/engine/client/cl_game.c b/engine/client/cl_game.c index dfd1f1d9..0737489e 100644 --- a/engine/client/cl_game.c +++ b/engine/client/cl_game.c @@ -2299,9 +2299,9 @@ static void GAME_EXPORT pfnKillEvents( int entnum, const char *eventname ) int i; event_state_t *es; event_info_t *ei; - int eventIndex = CL_EventIndex( eventname ); + word eventIndex = CL_EventIndex( eventname ); - if( eventIndex < 0 || eventIndex >= MAX_EVENTS ) + if( eventIndex >= MAX_EVENTS ) return; if( entnum < 0 || entnum > clgame.maxEntities ) diff --git a/engine/client/cl_main.c b/engine/client/cl_main.c index 688c7fc0..c5807555 100644 --- a/engine/client/cl_main.c +++ b/engine/client/cl_main.c @@ -2345,11 +2345,10 @@ Replace the displayed name for some resources */ const char *CL_CleanFileName( const char *filename ) { - const char *pfilename = filename; - if( COM_CheckString( filename ) && filename[0] == '!' ) - pfilename = "customization"; - return pfilename; + return "customization"; + + return filename; } diff --git a/engine/client/cl_parse.c b/engine/client/cl_parse.c index daf819d9..27c1a3d4 100644 --- a/engine/client/cl_parse.c +++ b/engine/client/cl_parse.c @@ -484,6 +484,8 @@ void CL_BatchResourceRequest( qboolean initialize ) switch( p->type ) { case t_sound: + case t_model: + case t_eventscript: if( !CL_CheckFile( &msg, p )) break; CL_MoveToOnHandList( p ); @@ -491,11 +493,6 @@ void CL_BatchResourceRequest( qboolean initialize ) case t_skin: CL_MoveToOnHandList( p ); break; - case t_model: - if( !CL_CheckFile( &msg, p )) - break; - CL_MoveToOnHandList( p ); - break; case t_decal: if( !HPAK_GetDataPointer( CUSTOM_RES_PATH, p, NULL, NULL )) { @@ -520,11 +517,6 @@ void CL_BatchResourceRequest( qboolean initialize ) break; CL_MoveToOnHandList( p ); break; - case t_eventscript: - if( !CL_CheckFile( &msg, p )) - break; - CL_MoveToOnHandList( p ); - break; case t_world: ASSERT( 0 ); break; @@ -2389,14 +2381,11 @@ CL_ParseBaseline void CL_LegacyParseBaseline( sizebuf_t *msg ) { int i, newnum; - entity_state_t nullstate; qboolean player; cl_entity_t *ent; Delta_InitClient (); // finalize client delta's - memset( &nullstate, 0, sizeof( nullstate )); - newnum = MSG_ReadWord( msg ); player = CL_IsPlayerIndex( newnum ); diff --git a/engine/client/cl_pmove.c b/engine/client/cl_pmove.c index 897a717b..3d3a9a98 100644 --- a/engine/client/cl_pmove.c +++ b/engine/client/cl_pmove.c @@ -992,7 +992,6 @@ void CL_SetupPMove( playermove_t *pmove, local_state_t *from, usercmd_t *ucmd, q pmove->flFallVelocity = ps->flFallVelocity; pmove->flSwimTime = cd->flSwimTime; VectorCopy( cd->punchangle, pmove->punchangle ); - pmove->flSwimTime = cd->flSwimTime; pmove->flNextPrimaryAttack = 0.0f; // not used by PM_ code pmove->effects = ps->effects; pmove->flags = cd->flags; diff --git a/engine/client/cl_tent.c b/engine/client/cl_tent.c index 2be8132f..1e9c19e9 100644 --- a/engine/client/cl_tent.c +++ b/engine/client/cl_tent.c @@ -1482,7 +1482,6 @@ void GAME_EXPORT R_FunnelSprite( const vec3_t org, int modelIndex, int reverse ) pTemp->entity.baseline.angles[2] = COM_RandomFloat( -100.0f, 100.0f ); pTemp->entity.curstate.framerate = COM_RandomFloat( 0.1f, 0.4f ); pTemp->flags = FTENT_ROTATE|FTENT_FADEOUT; - pTemp->entity.curstate.framerate = 10; vel = dest[2] / 8.0f; if( vel < 64.0f ) vel = 64.0f; @@ -2920,7 +2919,7 @@ void CL_PlayerDecal( int playernum, int customIndex, int entityIndex, float *pos { if( FBitSet( pCust->resource.ucFlags, RES_CUSTOM ) && pCust->resource.type == t_decal && pCust->bTranslated ) { - if( !pCust->nUserData1 && pCust->pInfo != NULL ) + if( !pCust->nUserData1 ) { const char *decalname = va( "player%dlogo%d", playernum, customIndex ); pCust->nUserData1 = GL_LoadTextureInternal( decalname, pCust->pInfo, TF_DECAL ); diff --git a/engine/client/console.c b/engine/client/console.c index 2c2d6cf5..e53aafce 100644 --- a/engine/client/console.c +++ b/engine/client/console.c @@ -1069,7 +1069,7 @@ int Con_DrawGenericString( int x, int y, const char *string, rgba_t setColor, qb Con_UtfProcessChar( 0 ); // draw the colored text - *(uint *)color = *(uint *)setColor; + memcpy( color, setColor, sizeof( color )); s = string; while( *s ) @@ -2174,6 +2174,9 @@ void Con_DrawSolidConsole( int lines ) int i, x, y; float fraction; int start; + int stringLen, width = 0, charH; + string curbuild; + byte color[4]; if( lines <= 0 ) return; @@ -2187,28 +2190,20 @@ void Con_DrawSolidConsole( int lines ) if( !con.curFont || !host.allow_console ) return; // nothing to draw - if( host.allow_console ) - { - // draw current version - int stringLen, width = 0, charH; - string curbuild; - byte color[4]; + // draw current version + memcpy( color, g_color_table[7], sizeof( color )); - memcpy( color, g_color_table[7], sizeof( color )); + Q_snprintf( curbuild, MAX_STRING, "%s %i/%s (%s-%s build %i)", XASH_ENGINE_NAME, PROTOCOL_VERSION, XASH_VERSION, Q_buildos(), Q_buildarch(), Q_buildnum( )); + Con_DrawStringLen( curbuild, &stringLen, &charH ); + start = refState.width - stringLen; + stringLen = Con_StringLength( curbuild ); - Q_snprintf( curbuild, MAX_STRING, "%s %i/%s (%s-%s build %i)", XASH_ENGINE_NAME, PROTOCOL_VERSION, XASH_VERSION, Q_buildos(), Q_buildarch(), Q_buildnum( )); + fraction = lines / (float)refState.height; + color[3] = Q_min( fraction * 2.0f, 1.0f ) * 255; // fadeout version number - Con_DrawStringLen( curbuild, &stringLen, &charH ); - start = refState.width - stringLen; - stringLen = Con_StringLength( curbuild ); - - fraction = lines / (float)refState.height; - color[3] = Q_min( fraction * 2.0f, 1.0f ) * 255; // fadeout version number - - for( i = 0; i < stringLen; i++ ) - width += Con_DrawCharacter( start + width, 0, curbuild[i], color ); - } + for( i = 0; i < stringLen; i++ ) + width += Con_DrawCharacter( start + width, 0, curbuild[i], color ); // draw the text if( CON_LINES_COUNT > 0 ) diff --git a/engine/client/in_touch.c b/engine/client/in_touch.c index f59c88c5..5bd454d0 100644 --- a/engine/client/in_touch.c +++ b/engine/client/in_touch.c @@ -786,7 +786,6 @@ static touch_button_t *Touch_AddButton( touchbuttonlist_t *list, button->flags = privileged ? 0 : TOUCH_FL_UNPRIVILEGED | TOUCH_FL_CLIENT; MakeRGBA( button->color, color[0], color[1], color[2], color[3] ); button->command[0] = 0; - button->flags = 0; button->fade = 1; Touch_SetCommand( button, command ); diff --git a/engine/client/keys.c b/engine/client/keys.c index 97b2e629..682f44ad 100644 --- a/engine/client/keys.c +++ b/engine/client/keys.c @@ -1044,7 +1044,7 @@ static qboolean OSK_KeyEvent( int key, int down ) else osk.curlayout++; - osk.shift = osk.curbutton.val == OSK_SHIFT; + osk.shift = true; osk.curbutton.val = osk_keylayout[osk.curlayout][osk.curbutton.y][osk.curbutton.x]; break; case OSK_BACKSPACE: diff --git a/engine/client/s_dsp.c b/engine/client/s_dsp.c index 4d57675c..d0bbca0b 100644 --- a/engine/client/s_dsp.c +++ b/engine/client/s_dsp.c @@ -33,7 +33,6 @@ GNU General Public License for more details. #define MAXDLY (STEREODLY + 1) #define MAXLP 10 -#define MAXPRESETS 29 typedef struct sx_preset_s { @@ -79,7 +78,7 @@ typedef struct dly_s int *lpdelayline; } dly_t; -const sx_preset_t rgsxpre[MAXPRESETS] = +const sx_preset_t rgsxpre[] = { // -------reverb-------- -------delay-------- // lp mod size refl rvblp delay feedback dlylp left @@ -116,7 +115,7 @@ const sx_preset_t rgsxpre[MAXPRESETS] = // 0x0045dca8 enginegl.exe // SHA256: 42383d32cd712e59ee2c1bd78b7ba48814e680e7026c4223e730111f34a60d66 -const sx_preset_t rgsxpre_hlalpha052[MAXPRESETS] = +const sx_preset_t rgsxpre_hlalpha052[] = { // -------reverb-------- -------delay-------- // lp mod size refl rvblp delay feedback dlylp left @@ -882,7 +881,7 @@ void CheckNewDspPresets( void ) else idsp_room = room_type->value; // don't pass invalid presets - idsp_room = bound( 0, idsp_room, MAXPRESETS - 1 ); + idsp_room = bound( 0, idsp_room, MAX_ROOM_TYPES ); if( FBitSet( hisound->flags, FCVAR_CHANGED )) { @@ -893,9 +892,6 @@ void CheckNewDspPresets( void ) if( idsp_room == room_typeprev && idsp_room == 0 ) return; - if( idsp_room > MAX_ROOM_TYPES ) - return; - if( idsp_room != room_typeprev ) { const sx_preset_t *cur; diff --git a/engine/client/s_main.c b/engine/client/s_main.c index a88546b1..6c926552 100644 --- a/engine/client/s_main.c +++ b/engine/client/s_main.c @@ -1155,7 +1155,6 @@ void S_RawSamples( uint samples, uint rate, word width, word channels, const byt int snd_vol = 128; if( entnum < 0 ) snd_vol = 256; // bg track or movie track - if( snd_vol < 0 ) snd_vol = 0; // fixup negative values S_RawEntSamples( entnum, samples, rate, width, channels, data, snd_vol ); }