Duplicate Animation Events Fix

From Valve Developer Community
Revision as of 08:38, 27 December 2009 by Kohan (talk | contribs)

Jump to: navigation, search

Introduction

This is neither a prediction issue NOR a duplicated animation issue. It has to do with the introduction of the new PlayerAnimState code in the 15 June 2009 Orange Box SDK release.

The introduction of the PlayerAnimState brings great changes to controlling the animations on the player. The problem is it was thrown into an already messy animation code that involves literally hundreds of calls to functions in various levels of virtualization...

Regardless, at the end of the CHL2MPPlayerAnimState::DoAnimationEvent(...) function there is a little present from Valve. That is to do the View Model animation that corresponds to the third person anim! However, the problem lies in the way Valve detects network variable changes, those pesky "Parity" variables you might see around, specifically m_nResetEventsParity.

Let's backtrack a little, all weapons call their own viewmodel animations with a function called SendWeaponAnim(...) which does exactly that and also increments the m_nResetEventsParity.

Now the animation doesn't play twice because most weapon calls are in the same frame and it doesn't send the m_nNewSequenceParity since the sequence doesn't change. However, m_nResetEventsParity does get changed and it royally messes everything up. Since the PlayerAnimState stuff is only invoked client side it changes the event parity (sometimes) before the server update changes it, which is why this is an intermittent problem.

Requirements

  • Using the latest OB SDK code

Solution

Simply comment out the following lines of code in hl2mp_playeranimstate.cpp:

In function CHL2MPPlayerAnimState::DoAnimationEvent(...)

#ifdef CLIENT_DLL
	// Make the weapon play the animation as well
	if ( iGestureActivity != ACT_INVALID )
	{
		CBaseCombatWeapon *pWeapon = GetHL2MPPlayer()->GetActiveWeapon();
		if ( pWeapon )
		{
			pWeapon->EnsureCorrectRenderingModel();
			pWeapon->SendWeaponAnim( iGestureActivity );
			// Force animation events!
			pWeapon->ResetEventsParity();		// reset event parity so the animation events will occur on the weapon. 
			pWeapon->DoAnimationEvents( pWeapon->GetModelPtr() );
		}
	}
#endif

Notes and Future Work

Future version of the SDK might fix this problem the other way, and that is to rely on this player animation code to setup the viewmodel animations instead of the weapon handling it's own animations in the specific parts of the code (PrimaryAttack, Draw, Holster, etc.)