From f083c5eb31d2ee813172f1c8bcb929140a969acf Mon Sep 17 00:00:00 2001 From: tankefugl Date: Wed, 29 Jun 2005 15:37:01 +0000 Subject: [PATCH] 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 --- .../source/cl_dll/hl/hl_baseentity.cpp | 2 +- dev/performance-3.0.5/source/dlls/animating.cpp | 11 +++++++++-- dev/performance-3.0.5/source/dlls/animation.cpp | 12 ++++++------ dev/performance-3.0.5/source/dlls/cbase.h | 7 ++++++- dev/performance-3.0.5/source/dlls/player.cpp | 2 +- 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/dev/performance-3.0.5/source/cl_dll/hl/hl_baseentity.cpp b/dev/performance-3.0.5/source/cl_dll/hl/hl_baseentity.cpp index 27b9f24..df235f0 100644 --- a/dev/performance-3.0.5/source/cl_dll/hl/hl_baseentity.cpp +++ b/dev/performance-3.0.5/source/cl_dll/hl/hl_baseentity.cpp @@ -128,7 +128,7 @@ void CBaseMonster :: MakeIdealYaw( Vector vecTarget ) { } float CBaseMonster::ChangeYaw ( int yawSpeed ) { return 0; } int CBaseAnimating :: LookupActivity ( 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 ( ) { } BOOL CBaseAnimating :: GetSequenceFlags( ) { return FALSE; } void CBaseAnimating :: DispatchAnimEvents ( float flInterval ) { } diff --git a/dev/performance-3.0.5/source/dlls/animating.cpp b/dev/performance-3.0.5/source/dlls/animating.cpp index f3638a1..4c4cd7d 100644 --- a/dev/performance-3.0.5/source/dlls/animating.cpp +++ b/dev/performance-3.0.5/source/dlls/animating.cpp @@ -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) ); - 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) diff --git a/dev/performance-3.0.5/source/dlls/animation.cpp b/dev/performance-3.0.5/source/dlls/animation.cpp index 3bdd302..2ce9a47 100644 --- a/dev/performance-3.0.5/source/dlls/animation.cpp +++ b/dev/performance-3.0.5/source/dlls/animation.cpp @@ -173,12 +173,12 @@ int LookupSequence( void *pmodel, const char *label ) } //if(GetGameRules()->GetIsTesting()) - if(CVAR_GET_FLOAT(kvTesting) > 0) - { - char theMessage[256]; - sprintf(theMessage, "%s%s\n", "Couldn't find animation: ", label); - ALERT(at_console, theMessage); - } + //if(CVAR_GET_FLOAT(kvTesting) > 0) + //{ + // char theMessage[256]; + // sprintf(theMessage, "%s%s\n", "Couldn't find animation: ", label); + // ALERT(at_console, theMessage); + //} return -1; } diff --git a/dev/performance-3.0.5/source/dlls/cbase.h b/dev/performance-3.0.5/source/dlls/cbase.h index dfff62a..3977cc5 100644 --- a/dev/performance-3.0.5/source/dlls/cbase.h +++ b/dev/performance-3.0.5/source/dlls/cbase.h @@ -482,7 +482,7 @@ public: int GetSequenceFlags( void ); int LookupActivity ( int activity ); int LookupActivityHeaviest ( int activity ); - int LookupSequence ( const char *label ); + int LookupSequence ( const char *label, int queue = 0); const char* LookupSequence(int inSequence); void ResetSequenceInfo ( ); 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 BOOL m_fSequenceFinished;// flag set when StudioAdvanceFrame moves across a frame boundry BOOL m_fSequenceLoops; // true if the sequence loops + + // For performance gain during LookupSequence: + //void *mPreviousLookupModel[3]; + char mPreviousLookupString[3][64]; + int mPreviousLookupSequence[3]; }; diff --git a/dev/performance-3.0.5/source/dlls/player.cpp b/dev/performance-3.0.5/source/dlls/player.cpp index 2ef51d5..0448e96 100644 --- a/dev/performance-3.0.5/source/dlls/player.cpp +++ b/dev/performance-3.0.5/source/dlls/player.cpp @@ -1404,7 +1404,7 @@ void CBasePlayer::SetAnimation( PLAYER_ANIM playerAnim ) } // Set the gaitsequence - gaitDesired = LookupSequence(szAnim); + gaitDesired = LookupSequence(szAnim, 1); if(gaitDesired == -1) { gaitDesired = 0;