Performance changes:

Added a dual cache for LookupSequence, to avoid the massive stricmp overhead associated with the fetching of animations.

git-svn-id: https://unknownworlds.svn.cloudforge.com/ns1@221 67975925-1194-0748-b3d5-c16f83f1a3a1
This commit is contained in:
tankefugl 2005-06-29 15:37:01 +00:00
parent dc79b89150
commit f083c5eb31
5 changed files with 23 additions and 11 deletions

View File

@ -128,7 +128,7 @@ void CBaseMonster :: MakeIdealYaw( Vector vecTarget ) { }
float CBaseMonster::ChangeYaw ( int yawSpeed ) { return 0; } float CBaseMonster::ChangeYaw ( int yawSpeed ) { return 0; }
int CBaseAnimating :: LookupActivity ( int activity ) { return 0; } int CBaseAnimating :: LookupActivity ( int activity ) { return 0; }
int CBaseAnimating :: LookupActivityHeaviest ( int activity ) { return 0; } int CBaseAnimating :: LookupActivityHeaviest ( int activity ) { return 0; }
int CBaseAnimating :: LookupSequence ( const char *label ) { return 0; } int CBaseAnimating :: LookupSequence ( const char *label, int queue ) { return 0; }
void CBaseAnimating :: ResetSequenceInfo ( ) { } void CBaseAnimating :: ResetSequenceInfo ( ) { }
BOOL CBaseAnimating :: GetSequenceFlags( ) { return FALSE; } BOOL CBaseAnimating :: GetSequenceFlags( ) { return FALSE; }
void CBaseAnimating :: DispatchAnimEvents ( float flInterval ) { } void CBaseAnimating :: DispatchAnimEvents ( float flInterval ) { }

View File

@ -97,11 +97,18 @@ int CBaseAnimating :: LookupActivityHeaviest ( int activity )
//========================================================= //=========================================================
//========================================================= //=========================================================
int CBaseAnimating :: LookupSequence ( const char *label ) int CBaseAnimating :: LookupSequence ( const char *label, int queue )
{ {
void *pmodel = GET_MODEL_PTR( ENT(pev) ); void *pmodel = GET_MODEL_PTR( ENT(pev) );
return ::LookupSequence( pmodel, label ); if (strcmp(label, this->mPreviousLookupString[queue]) == 0)
{
return this->mPreviousLookupSequence[queue];
}
strcpy(this->mPreviousLookupString[queue], label);
this->mPreviousLookupSequence[queue] = ::LookupSequence( pmodel, label );
return this->mPreviousLookupSequence[queue];
} }
const char* CBaseAnimating::LookupSequence(int inSequence) const char* CBaseAnimating::LookupSequence(int inSequence)

View File

@ -173,12 +173,12 @@ int LookupSequence( void *pmodel, const char *label )
} }
//if(GetGameRules()->GetIsTesting()) //if(GetGameRules()->GetIsTesting())
if(CVAR_GET_FLOAT(kvTesting) > 0) //if(CVAR_GET_FLOAT(kvTesting) > 0)
{ //{
char theMessage[256]; // char theMessage[256];
sprintf(theMessage, "%s%s\n", "Couldn't find animation: ", label); // sprintf(theMessage, "%s%s\n", "Couldn't find animation: ", label);
ALERT(at_console, theMessage); // ALERT(at_console, theMessage);
} //}
return -1; return -1;
} }

View File

@ -482,7 +482,7 @@ public:
int GetSequenceFlags( void ); int GetSequenceFlags( void );
int LookupActivity ( int activity ); int LookupActivity ( int activity );
int LookupActivityHeaviest ( int activity ); int LookupActivityHeaviest ( int activity );
int LookupSequence ( const char *label ); int LookupSequence ( const char *label, int queue = 0);
const char* LookupSequence(int inSequence); const char* LookupSequence(int inSequence);
void ResetSequenceInfo ( ); void ResetSequenceInfo ( );
void DispatchAnimEvents ( float flFutureInterval = 0.1 ); // Handle events that have happend since last time called up until X seconds into the future void DispatchAnimEvents ( float flFutureInterval = 0.1 ); // Handle events that have happend since last time called up until X seconds into the future
@ -505,6 +505,11 @@ public:
float m_flLastEventCheck; // last time the event list was checked float m_flLastEventCheck; // last time the event list was checked
BOOL m_fSequenceFinished;// flag set when StudioAdvanceFrame moves across a frame boundry BOOL m_fSequenceFinished;// flag set when StudioAdvanceFrame moves across a frame boundry
BOOL m_fSequenceLoops; // true if the sequence loops BOOL m_fSequenceLoops; // true if the sequence loops
// For performance gain during LookupSequence:
//void *mPreviousLookupModel[3];
char mPreviousLookupString[3][64];
int mPreviousLookupSequence[3];
}; };

View File

@ -1404,7 +1404,7 @@ void CBasePlayer::SetAnimation( PLAYER_ANIM playerAnim )
} }
// Set the gaitsequence // Set the gaitsequence
gaitDesired = LookupSequence(szAnim); gaitDesired = LookupSequence(szAnim, 1);
if(gaitDesired == -1) if(gaitDesired == -1)
{ {
gaitDesired = 0; gaitDesired = 0;