From c9fdcd91e8eeffce706b65731fe67589176fa88a Mon Sep 17 00:00:00 2001 From: Andrey Akhmichin Date: Tue, 24 Sep 2019 03:00:37 +0500 Subject: [PATCH] A little optimizations. --- cl_dll/hud_spectator.cpp | 2 +- cl_dll/input.cpp | 2 +- dlls/animation.cpp | 2 +- dlls/bmodels.cpp | 2 +- dlls/buttons.cpp | 2 +- dlls/doors.cpp | 6 ++---- dlls/h_battery.cpp | 15 ++++++--------- dlls/multiplay_gamerules.cpp | 15 ++++++++++----- dlls/plats.cpp | 3 +-- dlls/player.cpp | 4 ++-- dlls/scripted.cpp | 5 ++++- dlls/sound.cpp | 6 +++--- dlls/teamplay_gamerules.cpp | 4 ++-- dlls/triggers.cpp | 6 +++--- dlls/util.cpp | 4 ++-- 15 files changed, 40 insertions(+), 38 deletions(-) diff --git a/cl_dll/hud_spectator.cpp b/cl_dll/hud_spectator.cpp index edb743ba..889dc686 100644 --- a/cl_dll/hud_spectator.cpp +++ b/cl_dll/hud_spectator.cpp @@ -842,7 +842,7 @@ bool CHudSpectator::ParseOverviewFile() m_OverviewData.layersHeights[0] = 0.0f; strcpy( m_OverviewData.map, gEngfuncs.pfnGetLevelName() ); - if( strlen( m_OverviewData.map ) == 0 ) + if( m_OverviewData.map[0] == '\0' ) return false; // not active yet strcpy( levelname, m_OverviewData.map + 5 ); diff --git a/cl_dll/input.cpp b/cl_dll/input.cpp index 0abd542b..628ff088 100644 --- a/cl_dll/input.cpp +++ b/cl_dll/input.cpp @@ -169,7 +169,7 @@ int KB_ConvertString( char *in, char **ppout ) *pEnd = '\0'; pBinding = NULL; - if( strlen( binding + 1 ) > 0 ) + if( binding[1] != '\0' ) { // See if there is a binding for binding? pBinding = gEngfuncs.Key_LookupBinding( binding + 1 ); diff --git a/dlls/animation.cpp b/dlls/animation.cpp index f84ec380..9f70f3d1 100644 --- a/dlls/animation.cpp +++ b/dlls/animation.cpp @@ -203,7 +203,7 @@ void SequencePrecache( void *pmodel, const char *pSequenceName ) // of it's name if it is. if( IsSoundEvent( pevent[i].event ) ) { - if( !strlen( pevent[i].options ) ) + if( pevent[i].options[0] == '\0' ) { ALERT( at_error, "Bad sound event %d in sequence %s :: %s (sound is \"%s\")\n", pevent[i].event, pstudiohdr->name, pSequenceName, pevent[i].options ); } diff --git a/dlls/bmodels.cpp b/dlls/bmodels.cpp index fe56b6ac..b75a0fa8 100644 --- a/dlls/bmodels.cpp +++ b/dlls/bmodels.cpp @@ -434,7 +434,7 @@ void CFuncRotating::Precache( void ) BOOL NullSound = FALSE; // set up fan sounds - if( !FStringNull( pev->message ) && strlen( szSoundFile ) > 0 ) + if( !FStringNull( pev->message ) && szSoundFile[0] != '\0' ) { // if a path is set for a wave, use it } diff --git a/dlls/buttons.cpp b/dlls/buttons.cpp index 90bc42e5..f7441b3f 100644 --- a/dlls/buttons.cpp +++ b/dlls/buttons.cpp @@ -694,7 +694,7 @@ CBaseButton::BUTTON_CODE CBaseButton::ButtonResponseToTouch( void ) void CBaseButton::ButtonTouch( CBaseEntity *pOther ) { // Ignore touches by anything but players - if( !FClassnameIs( pOther->pev, "player" ) ) + if( !pOther->IsPlayer() ) return; m_hActivator = pOther; diff --git a/dlls/doors.cpp b/dlls/doors.cpp index 085ee441..9091d70a 100644 --- a/dlls/doors.cpp +++ b/dlls/doors.cpp @@ -520,10 +520,8 @@ void CBaseDoor::Precache( void ) // void CBaseDoor::DoorTouch( CBaseEntity *pOther ) { - entvars_t *pevToucher = pOther->pev; - // Ignore touches by anything but players - if( !FClassnameIs( pevToucher, "player" ) ) + if( !pOther->IsPlayer() ) return; // If door has master, and it's not ready to trigger, @@ -542,7 +540,7 @@ void CBaseDoor::DoorTouch( CBaseEntity *pOther ) m_hActivator = pOther;// remember who activated the door - if( DoorActivate()) + if( DoorActivate() ) SetTouch( NULL ); // Temporarily disable the touch function, until movement is finished. } diff --git a/dlls/h_battery.cpp b/dlls/h_battery.cpp index dabbc06c..6c6b9869 100644 --- a/dlls/h_battery.cpp +++ b/dlls/h_battery.cpp @@ -106,8 +106,12 @@ void CRecharge::Precache() void CRecharge::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ) { + // Make sure that we have a caller + if( !pActivator ) + return; + // if it's not a player, ignore - if( !FClassnameIs( pActivator->pev, "player" ) ) + if( !pActivator->IsPlayer() ) return; // if there is no juice left, turn it off @@ -135,16 +139,8 @@ void CRecharge::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE use if( m_flNextCharge >= gpGlobals->time ) return; - // Make sure that we have a caller - if( !pActivator ) - return; - m_hActivator = pActivator; - //only recharge the player - if( !m_hActivator->IsPlayer() ) - return; - // Play the on sound or the looping charging sound if( !m_iOn ) { @@ -152,6 +148,7 @@ void CRecharge::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE use EMIT_SOUND( ENT( pev ), CHAN_ITEM, "items/suitchargeok1.wav", 0.85, ATTN_NORM ); m_flSoundTime = 0.56 + gpGlobals->time; } + if( ( m_iOn == 1 ) && ( m_flSoundTime <= gpGlobals->time ) ) { m_iOn++; diff --git a/dlls/multiplay_gamerules.cpp b/dlls/multiplay_gamerules.cpp index de91ac6e..358a4470 100644 --- a/dlls/multiplay_gamerules.cpp +++ b/dlls/multiplay_gamerules.cpp @@ -1331,7 +1331,8 @@ int ReloadMapCycleFile( const char *filename, mapcycle_t *cycle ) hasbuffer = 0; pFileList = COM_Parse( pFileList ); - if( strlen( com_token ) <= 0 ) + + if( com_token[0] == '\0' ) break; strcpy( szMap, com_token ); @@ -1340,7 +1341,8 @@ int ReloadMapCycleFile( const char *filename, mapcycle_t *cycle ) if( COM_TokenWaiting( pFileList ) ) { pFileList = COM_Parse( pFileList ); - if( strlen( com_token ) > 0 ) + + if( com_token[0] != '\0' ) { hasbuffer = 1; strcpy( szBuffer, com_token ); @@ -1496,7 +1498,8 @@ void ExtractCommandString( char *s, char *szCommand ) *o = 0; strcat( szCommand, pkey ); - if( strlen( value ) > 0 ) + + if( value[0] != '\0' ) { strcat( szCommand, " " ); strcat( szCommand, value ); @@ -1631,13 +1634,15 @@ void CHalfLifeMultiplay::ChangeLevel( void ) { ALERT( at_console, "PLAYER COUNT: min %i max %i current %i\n", minplayers, maxplayers, curplayers ); } - if( strlen( szRules ) > 0 ) + + if( szRules != '\0' ) { ALERT( at_console, "RULES: %s\n", szRules ); } CHANGE_LEVEL( szNextMap, NULL ); - if( strlen( szCommands ) > 0 ) + + if( szCommands[0] != '\0' ) { SERVER_COMMAND( szCommands ); } diff --git a/dlls/plats.cpp b/dlls/plats.cpp index 5a96a36b..8356d55e 100644 --- a/dlls/plats.cpp +++ b/dlls/plats.cpp @@ -358,8 +358,7 @@ void CPlatTrigger::SpawnInsideTrigger( CFuncPlat *pPlatform ) void CPlatTrigger::Touch( CBaseEntity *pOther ) { // Ignore touches by non-players - entvars_t *pevToucher = pOther->pev; - if( !FClassnameIs( pevToucher, "player" ) ) + if( !pOther->IsPlayer() ) return; CFuncPlat *pPlatform = (CFuncPlat*)(CBaseEntity*)m_hPlatform; diff --git a/dlls/player.cpp b/dlls/player.cpp index 926bf1e1..43d1d28e 100644 --- a/dlls/player.cpp +++ b/dlls/player.cpp @@ -2762,7 +2762,7 @@ edict_t *EntSelectSpawnPoint( CBaseEntity *pPlayer ) } // If startspot is set, (re)spawn there. - if( FStringNull( gpGlobals->startspot ) || !strlen(STRING( gpGlobals->startspot ) ) ) + if( FStringNull( gpGlobals->startspot ) || (STRING( gpGlobals->startspot ) )[0] == '\0') { pSpot = UTIL_FindEntityByClassname( NULL, "info_player_start" ); if( !FNullEnt( pSpot ) ) @@ -4432,7 +4432,7 @@ void CBasePlayer::DropPlayerItem( char *pszItemName ) return; } - if( !strlen( pszItemName ) ) + if( pszItemName[0] == '\0' ) { // if this string has no length, the client didn't type a name! // assume player wants to drop the active item. diff --git a/dlls/scripted.cpp b/dlls/scripted.cpp index 41638b39..8e3a88ab 100644 --- a/dlls/scripted.cpp +++ b/dlls/scripted.cpp @@ -1068,14 +1068,17 @@ BOOL CScriptedSentence::AcceptableSpeaker( CBaseMonster *pMonster ) { if( pev->spawnflags & SF_SENTENCE_FOLLOWERS ) { - if( pMonster->m_hTargetEnt == 0 || !FClassnameIs( pMonster->m_hTargetEnt->pev, "player" ) ) + if( pMonster->m_hTargetEnt == 0 || !pMonster->m_hTargetEnt->IsPlayer() ) return FALSE; } + BOOL override; + if( pev->spawnflags & SF_SENTENCE_INTERRUPT ) override = TRUE; else override = FALSE; + if( pMonster->CanPlaySentence( override ) ) return TRUE; } diff --git a/dlls/sound.cpp b/dlls/sound.cpp index acc2dbf7..8fc5cb89 100644 --- a/dlls/sound.cpp +++ b/dlls/sound.cpp @@ -184,7 +184,7 @@ void CAmbientGeneric::Spawn( void ) const char *szSoundFile = STRING( pev->message ); - if( FStringNull( pev->message ) || strlen( szSoundFile ) < 1 ) + if( FStringNull( pev->message ) || szSoundFile[0] == '\0' ) { ALERT( at_error, "EMPTY AMBIENT AT: %f, %f, %f\n", pev->origin.x, pev->origin.y, pev->origin.z ); pev->nextthink = gpGlobals->time + 0.1; @@ -218,7 +218,7 @@ void CAmbientGeneric::Precache( void ) { const char *szSoundFile = STRING( pev->message ); - if( !FStringNull( pev->message ) && strlen( szSoundFile ) > 1 ) + if( !FStringNull( pev->message ) && szSoundFile[0] != '\0' ) { if( *szSoundFile != '!' ) PRECACHE_SOUND( szSoundFile ); @@ -1732,7 +1732,7 @@ void CSpeaker::Spawn( void ) { const char *szSoundFile = STRING( pev->message ); - if( !m_preset && ( FStringNull( pev->message ) || strlen( szSoundFile ) < 1 ) ) + if( !m_preset && ( FStringNull( pev->message ) || szSoundFile[0] == '\0' ) ) { ALERT( at_error, "SPEAKER with no Level/Sentence! at: %f, %f, %f\n", pev->origin.x, pev->origin.y, pev->origin.z ); pev->nextthink = gpGlobals->time + 0.1; diff --git a/dlls/teamplay_gamerules.cpp b/dlls/teamplay_gamerules.cpp index 87b695e7..d3b5c5e3 100644 --- a/dlls/teamplay_gamerules.cpp +++ b/dlls/teamplay_gamerules.cpp @@ -52,14 +52,14 @@ CHalfLifeTeamplay::CHalfLifeTeamplay() if( teamoverride.value ) { const char *pTeamList = STRING( pWorld->v.team ); - if( pTeamList && strlen( pTeamList ) ) + if( pTeamList && pTeamList[0] != '\0' ) { strncpy( m_szTeamList, pTeamList, TEAMPLAY_TEAMLISTLENGTH ); } } } // Has the server set teams - if( strlen( m_szTeamList ) ) + if( m_szTeamList[0] != '\0' ) m_teamLimit = TRUE; else m_teamLimit = FALSE; diff --git a/dlls/triggers.cpp b/dlls/triggers.cpp index 6d8fef04..b7633498 100644 --- a/dlls/triggers.cpp +++ b/dlls/triggers.cpp @@ -1124,7 +1124,7 @@ void CBaseTrigger::ActivateMultiTrigger( CBaseEntity *pActivator ) if( pev->nextthink > gpGlobals->time ) return; // still waiting for reset time - if( !UTIL_IsMasterTriggered( m_sMaster,pActivator ) ) + if( !UTIL_IsMasterTriggered( m_sMaster, pActivator ) ) return; if( FClassnameIs( pev, "trigger_secret" ) ) @@ -1191,7 +1191,7 @@ void CBaseTrigger::CounterUse( CBaseEntity *pActivator, CBaseEntity *pCaller, US BOOL fTellActivator = ( m_hActivator != 0 ) && - FClassnameIs( m_hActivator->pev, "player" ) && + m_hActivator->IsPlayer() && !FBitSet( pev->spawnflags, SPAWNFLAG_NOMESSAGE ); if( m_cTriggersLeft != 0 ) { @@ -1499,7 +1499,7 @@ void CChangeLevel::ChangeLevelNow( CBaseEntity *pActivator ) // void CChangeLevel::TouchChangeLevel( CBaseEntity *pOther ) { - if( !FClassnameIs( pOther->pev, "player" ) ) + if( !pOther->IsPlayer() ) return; ChangeLevelNow( pOther ); diff --git a/dlls/util.cpp b/dlls/util.cpp index a5160876..a66b5fbc 100644 --- a/dlls/util.cpp +++ b/dlls/util.cpp @@ -2196,7 +2196,7 @@ int CRestore::ReadField( void *pBaseData, TYPEDESCRIPTION *pFields, int fieldCou pString++; } pInputData = pString; - if( strlen( (char *)pInputData ) == 0 ) + if( ( (char *)pInputData )[0] == '\0' ) *( (string_t *)pOutputData ) = 0; else { @@ -2291,7 +2291,7 @@ int CRestore::ReadField( void *pBaseData, TYPEDESCRIPTION *pFields, int fieldCou *( (void**)pOutputData ) = *(void **)pInputData; break; case FIELD_FUNCTION: - if( strlen( (char *)pInputData ) == 0 ) + if( ( (char *)pInputData )[0] == '\0' ) *( (void**)pOutputData ) = 0; else *( (void**)pOutputData ) = (void*)FUNCTION_FROM_NAME( (char *)pInputData );