A little optimizations.

This commit is contained in:
Night Owl 2018-04-07 04:01:09 +05:00
parent b22ea2889f
commit 7c66c3aa9c
16 changed files with 527 additions and 472 deletions

View File

@ -802,7 +802,7 @@ int CHudAmmo::Draw( float flTime )
int iCrossX; int iCrossX;
int iCrossY; int iCrossY;
int iCrossLength; int iCrossLength;
char *chCrossHair = "+"; // Heh const char *chCrossHair = "+"; // Heh
//if( !( gHUD.m_iWeaponBits & ( 1 << ( WEAPON_SUIT ) ) ) ) //if( !( gHUD.m_iWeaponBits & ( 1 << ( WEAPON_SUIT ) ) ) )
// return 1; // return 1;
@ -845,7 +845,7 @@ int CHudAmmo::Draw( float flTime )
y = ScreenHeight - gHUD.m_iFontHeight - gHUD.m_iFontHeight / 2; y = ScreenHeight - gHUD.m_iFontHeight - gHUD.m_iFontHeight / 2;
/******************* DRAW CROSSHAIR *********************/ /******************* DRAW CROSSHAIR *********************/
iCrossLength = gHUD.m_scrinfo.charWidths[*chCrossHair]; iCrossLength = gHUD.m_scrinfo.charWidths[(unsigned char)*chCrossHair];
iCrossY = ScreenHeight / 2 - gHUD.m_scrinfo.iCharHeight / 2; iCrossY = ScreenHeight / 2 - gHUD.m_scrinfo.iCharHeight / 2;
iCrossX = ScreenWidth / 2 - iCrossLength / 2; iCrossX = ScreenWidth / 2 - iCrossLength / 2;

View File

@ -40,9 +40,9 @@
gHUD.y.UserCmd_##x( ); \ gHUD.y.UserCmd_##x( ); \
} }
inline float CVAR_GET_FLOAT( const char *x ) { return gEngfuncs.pfnGetCvarFloat( (char*)x ); } inline float CVAR_GET_FLOAT( const char *x ) { return gEngfuncs.pfnGetCvarFloat( x ); }
inline char* CVAR_GET_STRING( const char *x ) { return gEngfuncs.pfnGetCvarString( (char*)x ); } inline char* CVAR_GET_STRING( const char *x ) { return gEngfuncs.pfnGetCvarString( x ); }
inline struct cvar_s *CVAR_CREATE( const char *cv, const char *val, const int flags ) { return gEngfuncs.pfnRegisterVariable( (char*)cv, (char*)val, flags ); } inline struct cvar_s *CVAR_CREATE( const char *cv, const char *val, const int flags ) { return gEngfuncs.pfnRegisterVariable( cv, val, flags ); }
#define SPR_Load ( *gEngfuncs.pfnSPR_Load ) #define SPR_Load ( *gEngfuncs.pfnSPR_Load )
#define SPR_Set ( *gEngfuncs.pfnSPR_Set ) #define SPR_Set ( *gEngfuncs.pfnSPR_Set )
@ -108,16 +108,16 @@ inline int TextMessageDrawChar( int x, int y, int number, int r, int g, int b )
inline int DrawConsoleString( int x, int y, const char *string ) inline int DrawConsoleString( int x, int y, const char *string )
{ {
if( hud_textmode->value == 1 ) if( hud_textmode->value == 1 )
return gHUD.DrawHudString( x, y, 9999, (char*)string, 255 * g_hud_text_color[0], 255 * g_hud_text_color[1], 255 * g_hud_text_color[2] ); return gHUD.DrawHudString( x, y, 9999, string, 255 * g_hud_text_color[0], 255 * g_hud_text_color[1], 255 * g_hud_text_color[2] );
return gEngfuncs.pfnDrawConsoleString( x, y, (char*) string ); return gEngfuncs.pfnDrawConsoleString( x, y, string );
} }
inline void GetConsoleStringSize( const char *string, int *width, int *height ) inline void GetConsoleStringSize( const char *string, int *width, int *height )
{ {
if( hud_textmode->value == 1 ) if( hud_textmode->value == 1 )
*height = 13, *width = gHUD.DrawHudStringLen( (char*)string ); *height = 13, *width = gHUD.DrawHudStringLen( string );
else else
gEngfuncs.pfnDrawConsoleStringLen( (char*)string, width, height ); gEngfuncs.pfnDrawConsoleStringLen( string, width, height );
} }
int DrawUtfString( int xpos, int ypos, int iMaxX, const char *szIt, int r, int g, int b ); int DrawUtfString( int xpos, int ypos, int iMaxX, const char *szIt, int r, int g, int b );
@ -126,7 +126,7 @@ inline int ConsoleStringLen( const char *string )
{ {
int _width = 0, _height = 0; int _width = 0, _height = 0;
if( hud_textmode->value == 1 ) if( hud_textmode->value == 1 )
return gHUD.DrawHudStringLen( (char*)string ); return gHUD.DrawHudStringLen( string );
GetConsoleStringSize( string, &_width, &_height ); GetConsoleStringSize( string, &_width, &_height );
return _width; return _width;
} }

File diff suppressed because it is too large Load Diff

View File

@ -317,8 +317,8 @@ void CBasePlayerItem::AttachToPlayer ( CBasePlayer *pPlayer ) { }
int CBasePlayerWeapon::AddDuplicate( CBasePlayerItem *pOriginal ) { return 0; } int CBasePlayerWeapon::AddDuplicate( CBasePlayerItem *pOriginal ) { return 0; }
int CBasePlayerWeapon::AddToPlayer( CBasePlayer *pPlayer ) { return FALSE; } int CBasePlayerWeapon::AddToPlayer( CBasePlayer *pPlayer ) { return FALSE; }
int CBasePlayerWeapon::UpdateClientData( CBasePlayer *pPlayer ) { return 0; } int CBasePlayerWeapon::UpdateClientData( CBasePlayer *pPlayer ) { return 0; }
BOOL CBasePlayerWeapon :: AddPrimaryAmmo( int iCount, char *szName, int iMaxClip, int iMaxCarry ) { return TRUE; } BOOL CBasePlayerWeapon :: AddPrimaryAmmo( int iCount, const char *szName, int iMaxClip, int iMaxCarry ) { return TRUE; }
BOOL CBasePlayerWeapon :: AddSecondaryAmmo( int iCount, char *szName, int iMax ) { return TRUE; } BOOL CBasePlayerWeapon :: AddSecondaryAmmo( int iCount, const char *szName, int iMax ) { return TRUE; }
BOOL CBasePlayerWeapon :: IsUseable( void ) { return TRUE; } BOOL CBasePlayerWeapon :: IsUseable( void ) { return TRUE; }
int CBasePlayerWeapon::PrimaryAmmoIndex( void ) { return -1; } int CBasePlayerWeapon::PrimaryAmmoIndex( void ) { return -1; }
int CBasePlayerWeapon::SecondaryAmmoIndex( void ) { return -1; } int CBasePlayerWeapon::SecondaryAmmoIndex( void ) { return -1; }

View File

@ -83,21 +83,21 @@ we set up the m_pPlayer field.
*/ */
void HUD_PrepEntity( CBaseEntity *pEntity, CBasePlayer *pWeaponOwner ) void HUD_PrepEntity( CBaseEntity *pEntity, CBasePlayer *pWeaponOwner )
{ {
memset( &ev[ num_ents ], 0, sizeof( entvars_t ) ); memset( &ev[num_ents], 0, sizeof(entvars_t) );
pEntity->pev = &ev[ num_ents++ ]; pEntity->pev = &ev[num_ents++];
pEntity->Precache(); pEntity->Precache();
pEntity->Spawn(); pEntity->Spawn();
if ( pWeaponOwner ) if( pWeaponOwner )
{ {
ItemInfo info; ItemInfo info;
CBasePlayerWeapon *pWeapon = (CBasePlayerWeapon *)pEntity;
pWeapon->m_pPlayer = pWeaponOwner;
((CBasePlayerWeapon *)pEntity)->m_pPlayer = pWeaponOwner; pWeapon->GetItemInfo( &info );
((CBasePlayerWeapon *)pEntity)->GetItemInfo( &info );
g_pWpns[ info.iId ] = (CBasePlayerWeapon *)pEntity; g_pWpns[info.iId] = pWeapon;
} }
} }
@ -121,7 +121,7 @@ CQuakeNail *CQuakeNail::CreateNail( Vector vecOrigin, Vector vecAngles, CBaseEnt
return NULL; return NULL;
} }
void CBasePlayer :: Precache( void ) void CBasePlayer::Precache( void )
{ {
m_usShotgunSingle = PRECACHE_EVENT( 1, "events/shotgun1.sc" ); m_usShotgunSingle = PRECACHE_EVENT( 1, "events/shotgun1.sc" );
m_usShotgunDouble = PRECACHE_EVENT( 1, "events/shotgun2.sc" ); m_usShotgunDouble = PRECACHE_EVENT( 1, "events/shotgun2.sc" );
@ -141,7 +141,7 @@ CBaseEntity :: Killed
If weapons code "kills" an entity, just set its effects to EF_NODRAW If weapons code "kills" an entity, just set its effects to EF_NODRAW
===================== =====================
*/ */
void CBaseEntity :: Killed( entvars_t *pevAttacker, int iGib ) void CBaseEntity::Killed( entvars_t *pevAttacker, int iGib )
{ {
pev->effects |= EF_NODRAW; pev->effects |= EF_NODRAW;
} }
@ -151,7 +151,7 @@ void CBaseEntity :: Killed( entvars_t *pevAttacker, int iGib )
CBasePlayerWeapon :: DefaultReload CBasePlayerWeapon :: DefaultReload
===================== =====================
*/ */
BOOL CBasePlayerWeapon :: DefaultReload( int iClipSize, int iAnim, float fDelay ) BOOL CBasePlayerWeapon::DefaultReload( int iClipSize, int iAnim, float fDelay )
{ {
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + fDelay; m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + fDelay;
@ -444,7 +444,7 @@ void CBasePlayer::Spawn( void )
BOOL CQuakeGun::Deploy( ) BOOL CQuakeGun::Deploy( )
{ {
gEngfuncs.CL_LoadModel( "models/v_axe.mdl", &m_pPlayer->pev->viewmodel ); gEngfuncs.CL_LoadModel( "models/v_axe.mdl", &m_pPlayer->pev->viewmodel );
strcpy( m_pPlayer->m_szAnimExtention, "onehanded" ); m_pPlayer->m_pszAnimExtention = "onehanded";
return TRUE; return TRUE;
} }

View File

@ -168,7 +168,7 @@ struct efx_api_s
TEMPENTITY *(*R_DefaultSprite)( float *pos, int spriteIndex, float framerate ); TEMPENTITY *(*R_DefaultSprite)( float *pos, int spriteIndex, float framerate );
TEMPENTITY *(*R_TempSprite)( float *pos, float *dir, float scale, int modelIndex, int rendermode, int renderfx, float a, float life, int flags ); TEMPENTITY *(*R_TempSprite)( float *pos, float *dir, float scale, int modelIndex, int rendermode, int renderfx, float a, float life, int flags );
int (*Draw_DecalIndex)( int id ); int (*Draw_DecalIndex)( int id );
int (*Draw_DecalIndexFromName)( char *name ); int (*Draw_DecalIndexFromName)( const char *name );
void (*R_DecalShoot)( int textureIndex, int entity, int modelIndex, float *position, int flags ); void (*R_DecalShoot)( int textureIndex, int entity, int modelIndex, float *position, int flags );
void (*R_AttachTentToPlayer)( int client, int modelIndex, float zoffset, float life ); void (*R_AttachTentToPlayer)( int client, int modelIndex, float zoffset, float life );
void (*R_KillAttachedTents)( int client ); void (*R_KillAttachedTents)( int client );

View File

@ -142,18 +142,6 @@ void AgResetMap()
while ((pEntity = UTIL_FindEntityByClassname( pEntity, "weaponbox" )) != NULL) while ((pEntity = UTIL_FindEntityByClassname( pEntity, "weaponbox" )) != NULL)
UTIL_Remove(pEntity); UTIL_Remove(pEntity);
pEntity = NULL;
while ((pEntity = UTIL_FindEntityByClassname( pEntity, "monster_satchel" )) != NULL)
UTIL_Remove(pEntity);
pEntity = NULL;
while ((pEntity = UTIL_FindEntityByClassname( pEntity, "monster_tripmine" )) != NULL)
UTIL_Remove(pEntity);
pEntity = NULL;
while ((pEntity = UTIL_FindEntityByClassname( pEntity, "monster_snark" )) != NULL)
UTIL_Remove(pEntity);
pEntity = NULL; pEntity = NULL;
while ((pEntity = UTIL_FindEntityByClassname( pEntity, "beam" )) != NULL) while ((pEntity = UTIL_FindEntityByClassname( pEntity, "beam" )) != NULL)
UTIL_Remove(pEntity); UTIL_Remove(pEntity);

View File

@ -132,7 +132,7 @@ BOOL CQuakeGun::Deploy( )
{ {
m_pPlayer->pev->viewmodel = MAKE_STRING("models/v_crowbar.mdl"); m_pPlayer->pev->viewmodel = MAKE_STRING("models/v_crowbar.mdl");
m_pPlayer->pev->weaponmodel = MAKE_STRING("models/p_9mmhandgun.mdl"); m_pPlayer->pev->weaponmodel = MAKE_STRING("models/p_9mmhandgun.mdl");
strcpy( m_pPlayer->m_szAnimExtention, "onehanded" ); m_pPlayer->m_pszAnimExtention = "onehanded";
#ifdef CLIENT_DLL #ifdef CLIENT_DLL
g_flLightTime = 0.0; g_flLightTime = 0.0;

View File

@ -832,9 +832,9 @@ void CItemAmmo::Spawn( void )
void CItemAmmo::Precache( void ) void CItemAmmo::Precache( void )
{ {
if (pev->spawnflags & BIG_AMMOBOX) if (pev->spawnflags & BIG_AMMOBOX)
PRECACHE_MODEL( (char*)STRING(m_isLargeBox) ); PRECACHE_MODEL( STRING(m_isLargeBox) );
else else
PRECACHE_MODEL( (char*)STRING(m_isSmallBox) ); PRECACHE_MODEL( STRING(m_isSmallBox) );
} }
BOOL CItemAmmo::MyTouch( CBasePlayer *pPlayer ) BOOL CItemAmmo::MyTouch( CBasePlayer *pPlayer )

View File

@ -218,7 +218,7 @@ void CBasePlayer::W_SetCurrentAmmo( int sendanim /* = 1 */ )
pev->viewmodel = iszViewModel; pev->viewmodel = iszViewModel;
pev->weaponmodel = iszWeaponModel; pev->weaponmodel = iszWeaponModel;
strcpy( m_szAnimExtention, szAnimExt ); m_pszAnimExtention = szAnimExt;
#else #else
{ {

View File

@ -823,7 +823,7 @@ void CBaseDoor::Blocked( CBaseEntity *pOther )
if( m_fNextSoundPlay <= gpGlobals->time ) if( m_fNextSoundPlay <= gpGlobals->time )
{ {
m_fNextSoundPlay = gpGlobals->time + 0.3; m_fNextSoundPlay = gpGlobals->time + 0.3;
STOP_SOUND( ENT( pev ), CHAN_STATIC, (char*)STRING( pev->noiseMoving ) ); STOP_SOUND( ENT( pev ), CHAN_STATIC, STRING( pev->noiseMoving ) );
} }
// Block all door pieces with the same targetname here. // Block all door pieces with the same targetname here.

View File

@ -87,7 +87,7 @@ CHalfLifeMultiplay::CHalfLifeMultiplay()
#endif #endif
int length; int length;
char *pFileList = (char*)LOAD_FILE_FOR_ME( "motd.txt", &length ); const char *pFileList = (const char*)LOAD_FILE_FOR_ME( "motd.txt", &length );
if( pFileList ) if( pFileList )
g_bHaveMOTD = true; g_bHaveMOTD = true;

View File

@ -725,7 +725,7 @@ void CBasePlayer::SetAnimation( PLAYER_ANIM playerAnim )
strcpy( szAnim, "crouch_shoot_" ); strcpy( szAnim, "crouch_shoot_" );
else else
strcpy( szAnim, "ref_shoot_" ); strcpy( szAnim, "ref_shoot_" );
strcat( szAnim, m_szAnimExtention ); strcat( szAnim, m_pszAnimExtention );
animDesired = LookupSequence( szAnim ); animDesired = LookupSequence( szAnim );
if( animDesired == -1 ) if( animDesired == -1 )
animDesired = 0; animDesired = 0;
@ -752,7 +752,7 @@ void CBasePlayer::SetAnimation( PLAYER_ANIM playerAnim )
strcpy( szAnim, "crouch_aim_" ); strcpy( szAnim, "crouch_aim_" );
else else
strcpy( szAnim, "ref_aim_" ); strcpy( szAnim, "ref_aim_" );
strcat( szAnim, m_szAnimExtention ); strcat( szAnim, m_pszAnimExtention );
animDesired = LookupSequence( szAnim ); animDesired = LookupSequence( szAnim );
if( animDesired == -1 ) if( animDesired == -1 )
animDesired = 0; animDesired = 0;

View File

@ -251,7 +251,7 @@ public:
int Classify ( void ); int Classify ( void );
void SetAnimation( PLAYER_ANIM playerAnim ); void SetAnimation( PLAYER_ANIM playerAnim );
void SetWeaponAnimType( const char *szExtention ); void SetWeaponAnimType( const char *szExtention );
char m_szAnimExtention[32]; const char *m_pszAnimExtention;
// custom player functions // custom player functions
virtual void ImpulseCommands( void ); virtual void ImpulseCommands( void );

View File

@ -794,7 +794,7 @@ void CBasePlayerWeapon::SendWeaponAnim( int iAnim, int skiplocal )
MESSAGE_END(); MESSAGE_END();
} }
BOOL CBasePlayerWeapon::AddPrimaryAmmo( int iCount, char *szName, int iMaxClip, int iMaxCarry ) BOOL CBasePlayerWeapon::AddPrimaryAmmo( int iCount, const char *szName, int iMaxClip, int iMaxCarry )
{ {
int iIdAmmo; int iIdAmmo;
@ -831,7 +831,7 @@ BOOL CBasePlayerWeapon::AddPrimaryAmmo( int iCount, char *szName, int iMaxClip,
return iIdAmmo > 0 ? TRUE : FALSE; return iIdAmmo > 0 ? TRUE : FALSE;
} }
BOOL CBasePlayerWeapon::AddSecondaryAmmo( int iCount, char *szName, int iMax ) BOOL CBasePlayerWeapon::AddSecondaryAmmo( int iCount, const char *szName, int iMax )
{ {
int iIdAmmo; int iIdAmmo;
@ -906,7 +906,7 @@ BOOL CBasePlayerWeapon::DefaultDeploy( const char *szViewModel, const char *szWe
m_pPlayer->pev->viewmodel = MAKE_STRING( szViewModel ); m_pPlayer->pev->viewmodel = MAKE_STRING( szViewModel );
m_pPlayer->pev->weaponmodel = MAKE_STRING( szWeaponModel ); m_pPlayer->pev->weaponmodel = MAKE_STRING( szWeaponModel );
strcpy( m_pPlayer->m_szAnimExtention, szAnimExt ); m_pPlayer->m_pszAnimExtention = szAnimExt;
SendWeaponAnim( iAnim, skiplocal ); SendWeaponAnim( iAnim, skiplocal );
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.5; m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.5;
@ -1056,13 +1056,13 @@ int CBasePlayerWeapon::ExtractAmmo( CBasePlayerWeapon *pWeapon )
{ {
// blindly call with m_iDefaultAmmo. It's either going to be a value or zero. If it is zero, // blindly call with m_iDefaultAmmo. It's either going to be a value or zero. If it is zero,
// we only get the ammo in the weapon's clip, which is what we want. // we only get the ammo in the weapon's clip, which is what we want.
iReturn = pWeapon->AddPrimaryAmmo( m_iDefaultAmmo, (char *)pszAmmo1(), iMaxClip(), iMaxAmmo1() ); iReturn = pWeapon->AddPrimaryAmmo( m_iDefaultAmmo, pszAmmo1(), iMaxClip(), iMaxAmmo1() );
m_iDefaultAmmo = 0; m_iDefaultAmmo = 0;
} }
if( pszAmmo2() != NULL ) if( pszAmmo2() != NULL )
{ {
iReturn = pWeapon->AddSecondaryAmmo( 0, (char *)pszAmmo2(), iMaxAmmo2() ); iReturn = pWeapon->AddSecondaryAmmo( 0, pszAmmo2(), iMaxAmmo2() );
} }
return iReturn; return iReturn;
@ -1084,7 +1084,7 @@ int CBasePlayerWeapon::ExtractClipAmmo( CBasePlayerWeapon *pWeapon )
iAmmo = m_iClip; iAmmo = m_iClip;
} }
return pWeapon->m_pPlayer->GiveAmmo( iAmmo, (char *)pszAmmo1(), iMaxAmmo1() ); // , &m_iPrimaryAmmoType return pWeapon->m_pPlayer->GiveAmmo( iAmmo, pszAmmo1(), iMaxAmmo1() ); // , &m_iPrimaryAmmoType
} }
//========================================================= //=========================================================

View File

@ -294,8 +294,8 @@ public:
virtual int AddWeapon( void ) { ExtractAmmo( this ); return TRUE; }; // Return TRUE if you want to add yourself to the player virtual int AddWeapon( void ) { ExtractAmmo( this ); return TRUE; }; // Return TRUE if you want to add yourself to the player
// generic "shared" ammo handlers // generic "shared" ammo handlers
BOOL AddPrimaryAmmo( int iCount, char *szName, int iMaxClip, int iMaxCarry ); BOOL AddPrimaryAmmo( int iCount, const char *szName, int iMaxClip, int iMaxCarry );
BOOL AddSecondaryAmmo( int iCount, char *szName, int iMaxCarry ); BOOL AddSecondaryAmmo( int iCount, const char *szName, int iMaxCarry );
virtual void UpdateItemInfo( void ) {}; // updates HUD state virtual void UpdateItemInfo( void ) {}; // updates HUD state