Skip to content

Commit 8c896ae

Browse files
authored
Merge pull request #468 from cattslmao/tc2-carryover
Various performance related commits carried over from TC2.
2 parents 82ddf25 + f6f5e9f commit 8c896ae

27 files changed

Lines changed: 168 additions & 85 deletions

src/game/client/c_baseanimating.cpp

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,9 @@ CStudioHdr *C_BaseAnimating::OnNewModel()
12161216
}
12171217
m_BoneAccessor.Init( this, m_CachedBoneData.Base() ); // Always call this in case the studiohdr_t has changed.
12181218

1219+
// Reset the accumulated bone mask.
1220+
m_iAccumulatedBoneMask = 0;
1221+
12191222
// Free any IK data
12201223
if (m_pIk)
12211224
{
@@ -2286,16 +2289,24 @@ bool C_BaseAnimating::PutAttachment( int number, const matrix3x4_t &attachmentTo
22862289
return false;
22872290

22882291
CAttachmentData *pAtt = &m_Attachments[number-1];
2289-
if ( gpGlobals->frametime > 0 && pAtt->m_nLastFramecount > 0 && pAtt->m_nLastFramecount == gpGlobals->framecount - 1 )
2292+
if ( gpGlobals->frametime > 0 && pAtt->m_nLastFramecount > 0 && pAtt->m_nLastFramecount < gpGlobals->framecount )
22902293
{
22912294
Vector vecPreviousOrigin, vecOrigin;
22922295
MatrixPosition( pAtt->m_AttachmentToWorld, vecPreviousOrigin );
22932296
MatrixPosition( attachmentToWorld, vecOrigin );
2294-
pAtt->m_vOriginVelocity = (vecOrigin - vecPreviousOrigin) / gpGlobals->frametime;
2297+
2298+
// compensate for the fact that the previous origin could have been multiple frames behind
2299+
pAtt->m_vOriginVelocity = (vecOrigin - vecPreviousOrigin) / (gpGlobals->frametime * (gpGlobals->framecount - pAtt->m_nLastFramecount));
2300+
// only update the frame count if the position changed, so we don't have to recompute attachments
2301+
if ( !pAtt->m_vOriginVelocity.IsZero( 0.00001f ) )
2302+
{
2303+
pAtt->m_nLastFramecount = gpGlobals->framecount;
2304+
}
22952305
}
22962306
else
22972307
{
22982308
pAtt->m_vOriginVelocity.Init();
2309+
pAtt->m_nLastFramecount = gpGlobals->framecount;
22992310
}
23002311
pAtt->m_nLastFramecount = gpGlobals->framecount;
23012312
pAtt->m_bAnglesComputed = false;
@@ -2308,6 +2319,20 @@ bool C_BaseAnimating::PutAttachment( int number, const matrix3x4_t &attachmentTo
23082319
return true;
23092320
}
23102321

2322+
bool C_BaseAnimating::GetAttachmentDeferred( int number, matrix3x4_t& matrix )
2323+
{
2324+
if ( number < 1 || number > m_Attachments.Count() )
2325+
return false;
2326+
2327+
// allow visual effects (eg. particles) to be a frame behind bone setup so that there are not messy dependencies.
2328+
CAttachmentData* pAtt = &m_Attachments[number - 1];
2329+
const bool bShouldUpdate = pAtt->m_nLastFramecount < gpGlobals->framecount - 1;
2330+
if ( bShouldUpdate && !CalcAttachments() )
2331+
return false;
2332+
2333+
matrix = pAtt->m_AttachmentToWorld;
2334+
return true;
2335+
}
23112336

23122337
bool C_BaseAnimating::SetupBones_AttachmentHelper( CStudioHdr *hdr )
23132338
{
@@ -3122,6 +3147,22 @@ bool C_BaseAnimating::SetupBones( matrix3x4_t *pBoneToWorldOut, int nMaxBones, i
31223147
}
31233148
}
31243149

3150+
// If we're setting up LOD N, we have set up all lower LODs also
3151+
// because lower LODs always use subsets of the bones of higher LODs.
3152+
int nLOD = 0;
3153+
int nMask = BONE_USED_BY_VERTEX_LOD0;
3154+
3155+
for ( ; nLOD < MAX_NUM_LODS; ++nLOD, nMask <<= 1 )
3156+
{
3157+
if ( boneMask & nMask )
3158+
break;
3159+
}
3160+
3161+
for ( ; nLOD < MAX_NUM_LODS; ++nLOD, nMask <<= 1 )
3162+
{
3163+
boneMask |= nMask;
3164+
}
3165+
31253166
#ifdef DEBUG_BONE_SETUP_THREADING
31263167
if ( cl_warn_thread_contested_bone_setup.GetBool() )
31273168
{
@@ -3154,7 +3195,9 @@ bool C_BaseAnimating::SetupBones( matrix3x4_t *pBoneToWorldOut, int nMaxBones, i
31543195
m_flLastBoneSetupTime = currentTime;
31553196
}
31563197
m_iPrevBoneMask = m_iAccumulatedBoneMask;
3157-
m_iAccumulatedBoneMask = 0;
3198+
3199+
// Keep record of the fact that we've used attachments. Because of deferred attachments, we can't keep track from the previous frame.
3200+
m_iAccumulatedBoneMask = m_iAccumulatedBoneMask & BONE_USED_BY_ATTACHMENT;
31583201

31593202
#ifdef STUDIO_ENABLE_PERF_COUNTERS
31603203
CStudioHdr *hdr = GetModelPtr();
@@ -3189,7 +3232,7 @@ bool C_BaseAnimating::SetupBones( matrix3x4_t *pBoneToWorldOut, int nMaxBones, i
31893232
return false;
31903233

31913234
// Setup our transform based on render angles and origin.
3192-
matrix3x4_t parentTransform;
3235+
ALIGN16 matrix3x4_t parentTransform ALIGN16_POST;
31933236
AngleMatrix( GetRenderAngles(), GetRenderOrigin(), parentTransform );
31943237

31953238
// Load the boneMask with the total of what was asked for last frame.

src/game/client/c_baseanimating.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ class C_BaseAnimating : public C_BaseEntity, private IModelLoadCallback
278278
// Attachments.
279279
bool GetAttachment( const char *szName, Vector &absOrigin );
280280
bool GetAttachment( const char *szName, Vector &absOrigin, QAngle &absAngles );
281+
virtual bool GetAttachmentDeferred( int number, matrix3x4_t& matrix );
281282

282283
// Inherited from C_BaseEntity
283284
virtual bool GetAttachment( int number, Vector &origin );

src/game/client/c_baseflex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ Vector C_BaseFlex::SetViewTarget( CStudioHdr *pStudioHdr )
574574
if (m_iEyeAttachment > 0)
575575
{
576576
matrix3x4_t attToWorld;
577-
if (!GetAttachment( m_iEyeAttachment, attToWorld ))
577+
if (!GetAttachmentDeferred( m_iEyeAttachment, attToWorld ))
578578
{
579579
return Vector( 0, 0, 0);
580580
}

src/game/client/c_smokestack.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ void C_SmokeStack::RenderParticles( CParticleRenderIterator *pIterator )
406406
// makes it get translucent and fade out for a longer time.
407407
//float alpha = cosf( -M_PI_F + tLifetime * M_PI_F * 2.f ) * 0.5f + 0.5f;
408408
float tLifetime = pParticle->m_Lifetime * m_InvLifetime;
409-
float alpha = TableCos( -M_PI_F + tLifetime * M_PI_F * 2.f ) * 0.5f + 0.5f;
409+
float alpha = FastCos( -M_PI_F + tLifetime * M_PI_F * 2.f ) * 0.5f + 0.5f;
410410
if( tLifetime > 0.5f )
411411
alpha *= alpha;
412412

src/game/client/glow_overlay.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ void CGlowOverlay::UpdateSkyGlowObstruction( float zFar, bool bCacheFullSceneSta
159159
if ( PixelVisibility_IsAvailable() )
160160
{
161161
// Trace a ray at the object.
162-
Vector pos = CurrentViewOrigin() + m_vDirection * zFar * 0.999f;
162+
Vector pos = CurrentViewOrigin() + m_vDirection * zFar * 0.99f;
163163

164164
// UNDONE: Can probably do only the pixelvis query in this case if you can figure out where
165165
// to put it - or save the position of this trace

src/game/client/in_steamcontroller.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ void CInput::ApplySteamControllerCameraMove( QAngle& viewangles, CUserCmd *cmd,
6969
//roll the view angles so roll is 0 (the HL2 assumed state) and mouse adjustments are relative to the screen.
7070
//Assuming roll is unchanging, we want mouse left to translate to screen left at all times (same for right, up, and down)
7171

72-
ConVarRef cl_pitchdown ( "cl_pitchdown" );
73-
ConVarRef cl_pitchup ( "cl_pitchup" );
72+
static ConVarRef cl_pitchdown ( "cl_pitchdown" );
73+
static ConVarRef cl_pitchup ( "cl_pitchup" );
7474

7575
// Scale yaw and pitch inputs by sensitivity, and make sure they are within acceptable limits (important to avoid exploits, e.g. during Demoman charge we must restrict allowed yaw).
7676
float yaw = CAM_CapYaw( sc_yaw_sensitivity.GetFloat() * vecPosition.x );

src/game/client/tf/c_tf_player.cpp

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,20 @@ bool C_TFRagdoll::GetAttachment( int iAttachment, matrix3x4_t &attachmentToWorld
13331333
}
13341334
}
13351335

1336+
bool C_TFRagdoll::GetAttachmentDeferred( int iAttachment, matrix3x4_t& attachmentToWorld )
1337+
{
1338+
int iHeadAttachment = LookupAttachment( "head" );
1339+
if ( IsDecapitation() && (iAttachment == iHeadAttachment) )
1340+
{
1341+
MatrixCopy( m_mHeadAttachment, attachmentToWorld );
1342+
return true;
1343+
}
1344+
else
1345+
{
1346+
return BaseClass::GetAttachmentDeferred( iAttachment, attachmentToWorld );
1347+
}
1348+
}
1349+
13361350
//-----------------------------------------------------------------------------
13371351
// Purpose:
13381352
// Input : -
@@ -1373,6 +1387,9 @@ bool C_TFRagdoll::IsRagdollVisible()
13731387
#define DISSOLVE_FADE_OUT_START_TIME 2.0f
13741388
#define DISSOLVE_FADE_OUT_END_TIME 2.0f
13751389

1390+
extern ConVar g_ragdoll_lvfadespeed;
1391+
extern ConVar g_ragdoll_fadespeed;
1392+
13761393
void C_TFRagdoll::ClientThink( void )
13771394
{
13781395
SetNextClientThink( CLIENT_THINK_ALWAYS );
@@ -1514,9 +1531,16 @@ void C_TFRagdoll::ClientThink( void )
15141531
if ( m_bFadingOut == true )
15151532
{
15161533
int iAlpha = GetRenderColor().a;
1517-
int iFadeSpeed = 600.0f;
1534+
int iFadeSpeed = ( g_RagdollLVManager.IsLowViolence() ) ? g_ragdoll_lvfadespeed.GetInt() : g_ragdoll_fadespeed.GetInt();
15181535

1519-
iAlpha = MAX( iAlpha - ( iFadeSpeed * gpGlobals->frametime ), 0 );
1536+
if (iFadeSpeed < 1)
1537+
{
1538+
iAlpha = 0;
1539+
}
1540+
else
1541+
{
1542+
iAlpha = MAX( iAlpha - ( iFadeSpeed * gpGlobals->frametime ), 0 );
1543+
}
15201544

15211545
SetRenderMode( kRenderTransAlpha );
15221546
SetRenderColorA( iAlpha );
@@ -1535,15 +1559,22 @@ void C_TFRagdoll::ClientThink( void )
15351559
if ( cl_ragdoll_forcefade.GetBool() )
15361560
{
15371561
m_bFadingOut = true;
1538-
float flDelay = cl_ragdoll_fade_time.GetFloat() * 0.33f;
1539-
m_fDeathTime = gpGlobals->curtime + flDelay;
1540-
15411562
RemoveAllDecals();
1542-
}
15431563

1544-
// Fade out after the specified delay.
1545-
StartFadeOut( cl_ragdoll_fade_time.GetFloat() * 0.33f );
1546-
return;
1564+
float flDelay = cl_ragdoll_fade_time.GetFloat() * 0.33f;
1565+
if (flDelay > 0.01f)
1566+
{
1567+
m_fDeathTime = gpGlobals->curtime + flDelay;
1568+
return;
1569+
}
1570+
m_fDeathTime = -1;
1571+
}
1572+
else
1573+
{
1574+
// Fade out after the specified delay.
1575+
StartFadeOut( cl_ragdoll_fade_time.GetFloat() * 0.33f );
1576+
return;
1577+
}
15471578
}
15481579

15491580
// Remove us if our death time has passed.
@@ -6867,15 +6898,15 @@ int C_TFPlayer::DrawModel( int flags )
68676898
// Don't draw the model at all if we're fully invisible
68686899
if ( GetEffectiveInvisibilityLevel() >= 1.0f )
68696900
{
6870-
if ( m_hHalloweenBombHat && ( g_pMaterialSystemHardwareConfig->GetDXSupportLevel() < 90 ) && !m_hHalloweenBombHat->IsEffectActive( EF_NODRAW ) )
6901+
if ( m_hHalloweenBombHat && ( g_pMaterialSystemHardwareConfig->GetDXSupportLevel() < 90 || g_pMaterialSystemHardwareConfig->PreferReducedFillrate() ) && !m_hHalloweenBombHat->IsEffectActive( EF_NODRAW ) )
68716902
{
68726903
m_hHalloweenBombHat->SetEffects( EF_NODRAW );
68736904
}
68746905
return 0;
68756906
}
68766907
else
68776908
{
6878-
if ( m_hHalloweenBombHat && ( g_pMaterialSystemHardwareConfig->GetDXSupportLevel() < 90 ) && m_hHalloweenBombHat->IsEffectActive( EF_NODRAW ) )
6909+
if ( m_hHalloweenBombHat && ( g_pMaterialSystemHardwareConfig->GetDXSupportLevel() < 90 || g_pMaterialSystemHardwareConfig->PreferReducedFillrate() ) && m_hHalloweenBombHat->IsEffectActive( EF_NODRAW ) )
68796910
{
68806911
m_hHalloweenBombHat->RemoveEffects( EF_NODRAW );
68816912
}
@@ -7526,7 +7557,7 @@ void C_TFPlayer::DropWearable( C_TFWearable *pItem, const breakablepropparams_t
75267557
}
75277558

75287559
pEntity->m_nSkin = m_nSkin;
7529-
pEntity->StartFadeOut( 15.0f );
7560+
pEntity->StartFadeOut( cl_ragdoll_fade_time.GetFloat() );
75307561

75317562
IPhysicsObject *pPhysicsObject = pEntity->VPhysicsGetObject();
75327563
if ( !pPhysicsObject )

src/game/client/tf/c_tf_player.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,7 @@ class C_TFRagdoll : public C_BaseFlex
10641064
int GetDamageCustom() { return m_iDamageCustom; }
10651065

10661066
virtual bool GetAttachment( int iAttachment, matrix3x4_t &attachmentToWorld );
1067+
virtual bool GetAttachmentDeferred( int iAttachment, matrix3x4_t& attachmentToWorld );
10671068

10681069
int GetClass() { return m_iClass; }
10691070

src/game/client/tf/tf_hud_notification_panel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ void CHudNotificationPanel::MsgFunc_HudNotify( bf_read &msg )
101101
// Ignore notifications in minmode
102102
if ( !bForceShow )
103103
{
104-
ConVarRef cl_hud_minmode( "cl_hud_minmode", true );
104+
static ConVarRef cl_hud_minmode( "cl_hud_minmode", true );
105105
if ( cl_hud_minmode.IsValid() && cl_hud_minmode.GetBool() )
106106
return;
107107
}
@@ -140,7 +140,7 @@ void CHudNotificationPanel::MsgFunc_HudNotify( bf_read &msg )
140140
void CHudNotificationPanel::MsgFunc_HudNotifyCustom( bf_read &msg )
141141
{
142142
// Ignore notifications in minmode
143-
ConVarRef cl_hud_minmode( "cl_hud_minmode", true );
143+
static ConVarRef cl_hud_minmode( "cl_hud_minmode", true );
144144
if ( cl_hud_minmode.IsValid() && cl_hud_minmode.GetBool() )
145145
return;
146146

src/game/client/tf/vgui/tf_classmenu.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,11 @@ void CTFClassMenu::SetVisible( bool state )
11791179

11801180
if ( state )
11811181
{
1182+
if (m_pTFPlayerModelPanel)
1183+
{
1184+
m_pTFPlayerModelPanel->SetVisible( true );
1185+
}
1186+
11821187
engine->ServerCmd( "menuopen" ); // to the server
11831188
engine->ClientCmd( "_cl_classmenuopen 1" ); // for other panels
11841189
CBroadcastRecipientFilter filter;
@@ -1198,6 +1203,11 @@ void CTFClassMenu::SetVisible( bool state )
11981203
{
11991204
engine->ServerCmd( "menuclosed" );
12001205
engine->ClientCmd( "_cl_classmenuopen 0" );
1206+
1207+
if (m_pTFPlayerModelPanel)
1208+
{
1209+
m_pTFPlayerModelPanel->SetVisible( false );
1210+
}
12011211

12021212
if ( TFGameRules() && TFGameRules()->IsMannVsMachineMode() )
12031213
{

0 commit comments

Comments
 (0)