@@ -384,8 +384,8 @@ class CViewModelInvisProxy : public CBaseInvisMaterialProxy
384384 virtual void OnBind ( C_BaseEntity *pC_BaseEntity );
385385};
386386
387- #define TF_VM_MIN_INVIS 0.22
388- #define TF_VM_MAX_INVIS 0.5
387+ #define TF_VM_MIN_INVIS 0 .22f
388+ #define TF_VM_MAX_INVIS 0 .5f
389389
390390// -----------------------------------------------------------------------------
391391// Purpose:
@@ -475,6 +475,9 @@ class CInvisProxy : public CBaseInvisMaterialProxy
475475{
476476public:
477477 virtual void OnBind ( C_BaseEntity *pC_BaseEntity ) OVERRIDE;
478+ private:
479+ CTFPlayer *pPlayer = NULL ;
480+ C_BaseEntity *pCachedEntity = NULL ;
478481};
479482
480483// -----------------------------------------------------------------------------
@@ -487,59 +490,64 @@ void CInvisProxy::OnBind( C_BaseEntity *pC_BaseEntity )
487490
488491 C_BaseEntity *pEnt = pC_BaseEntity;
489492
490- CTFPlayer *pPlayer = NULL ;
491-
492- // Check if we have a move parent and if it's a player
493- C_BaseEntity *pMoveParent = pEnt->GetMoveParent ();
494- if ( pMoveParent && pMoveParent->IsPlayer () )
493+ if ( pEnt != pCachedEntity )
495494 {
496- pPlayer = ToTFPlayer ( pMoveParent );
495+ pPlayer = NULL ;
496+ pCachedEntity = pEnt;
497497 }
498498
499- // If it's not a player then check for viewmodel.
500499 if ( !pPlayer )
501500 {
502- CBaseEntity *pEntParent = pMoveParent ? pMoveParent : pEnt;
503-
504- CTFViewModel *pVM = dynamic_cast <CTFViewModel *>( pEntParent );
505- if ( pVM )
501+ // Check if we have a move parent and if it's a player
502+ C_BaseEntity *pMoveParent = pEnt->GetMoveParent ();
503+ if ( pMoveParent && pMoveParent->IsPlayer () )
506504 {
507- pPlayer = ToTFPlayer ( pVM-> GetOwner () );
505+ pPlayer = ToTFPlayer ( pMoveParent );
508506 }
509- }
510-
511- if ( !pPlayer )
512- {
513- if ( pEnt->IsPlayer () )
507+ // If it's not a player then check for viewmodel.
508+ if ( !pPlayer )
514509 {
515- pPlayer = dynamic_cast <C_TFPlayer*>( pEnt );
510+ CBaseEntity *pEntParent = pMoveParent ? pMoveParent : pEnt;
511+
512+ CTFViewModel *pVM = dynamic_cast <CTFViewModel *>( pEntParent );
513+ if ( pVM )
514+ {
515+ pPlayer = ToTFPlayer ( pVM->GetOwner () );
516+ }
516517 }
517- else
518+
519+ if ( !pPlayer )
518520 {
519- IHasOwner *pOwnerInterface = dynamic_cast <IHasOwner*>( pEnt );
520- if ( pOwnerInterface )
521+ if ( pEnt->IsPlayer () )
522+ {
523+ pPlayer = dynamic_cast <C_TFPlayer*>( pEnt );
524+ }
525+ else
521526 {
522- pPlayer = ToTFPlayer ( pOwnerInterface->GetOwnerViaInterface () );
527+ IHasOwner *pOwnerInterface = dynamic_cast <IHasOwner*>( pEnt );
528+ if ( pOwnerInterface )
529+ {
530+ pPlayer = ToTFPlayer ( pOwnerInterface->GetOwnerViaInterface () );
531+ }
523532 }
524533 }
525- }
526-
527- if ( !pPlayer )
528- {
529- m_pPercentInvisible-> SetFloatValue ( 0 . 0f ) ;
530- return ;
534+
535+ if ( !pPlayer )
536+ {
537+ m_pPercentInvisible-> SetFloatValue ( 0 . 0f );
538+ return ;
539+ }
531540 }
532541
533542 // If we're the local player, use the old "vm_invis" code. Otherwise, use the "weapon_invis".
534543 if ( pPlayer->IsLocalPlayer () )
535544 {
536545 float flPercentInvisible = pPlayer->GetPercentInvisible ();
537- float flWeaponInvis = flPercentInvisible;
538546
539547 // remap from 0.22 to 0.5
540548 // but drop to 0.0 if we're not invis at all
541- flWeaponInvis = ( flPercentInvisible < 0.01 ) ?
542- 0.0 :
549+ float flWeaponInvis = ( flPercentInvisible < 0 .01f ) ?
550+ 0 .0f :
543551 RemapVal ( flPercentInvisible, 0.0 , 1.0 , TF_VM_MIN_INVIS, TF_VM_MAX_INVIS );
544552
545553 // Exaggerated blink effect on bump.
0 commit comments