2
0
mirror of https://github.com/FWGS/hlsdk-xash3d synced 2024-11-22 09:57:21 +01:00

A little optimizations.

This commit is contained in:
Andrey Akhmichin 2019-09-24 03:00:37 +05:00
parent 4623cb0dc2
commit c9fdcd91e8
15 changed files with 40 additions and 38 deletions

View File

@ -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 );

View File

@ -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 );

View File

@ -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 );
}

View File

@ -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
}

View File

@ -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;

View File

@ -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.
}

View File

@ -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++;

View File

@ -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 );
}

View File

@ -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;

View File

@ -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.

View File

@ -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;
}

View File

@ -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;

View File

@ -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;

View File

@ -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 );

View File

@ -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 );