From 3c20a64af8385041a5d890a8a481ebc34683e2bb Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 12 Aug 2007 22:26:42 +0000 Subject: [PATCH] CachedObjectPointer, CachedObjectPointer --- stepmania/src/Course.cpp | 2 ++ stepmania/src/Course.h | 3 +++ stepmania/src/CourseUtil.cpp | 25 ++++++++++++------------- stepmania/src/CourseUtil.h | 2 ++ stepmania/src/Trail.cpp | 2 ++ stepmania/src/Trail.h | 3 +++ stepmania/src/TrailUtil.cpp | 11 +++++++++-- stepmania/src/TrailUtil.h | 2 ++ 8 files changed, 35 insertions(+), 15 deletions(-) diff --git a/stepmania/src/Course.cpp b/stepmania/src/Course.cpp index 0fb82963a7..912481fe2f 100644 --- a/stepmania/src/Course.cpp +++ b/stepmania/src/Course.cpp @@ -21,6 +21,8 @@ static Preference MAX_SONGS_IN_EDIT_COURSE( "MaxSongsInEditCourse", -1 ); +CACHED_REGISTER_CLASS(Course); + static const char *CourseTypeNames[] = { "Nonstop", "Oni", diff --git a/stepmania/src/Course.h b/stepmania/src/Course.h index 2568145cad..8874523ba6 100644 --- a/stepmania/src/Course.h +++ b/stepmania/src/Course.h @@ -8,6 +8,7 @@ #include "EnumHelper.h" #include "Trail.h" #include "RageTypes.h" +#include "RageUtil_CachedObject.h" #include "SongUtil.h" #include "StepsUtil.h" #include @@ -216,6 +217,8 @@ public: /* Preferred styles: */ set m_setStyles; + + CachedObject m_CachedObject; }; #endif diff --git a/stepmania/src/CourseUtil.cpp b/stepmania/src/CourseUtil.cpp index 8791d8565d..1359c85858 100644 --- a/stepmania/src/CourseUtil.cpp +++ b/stepmania/src/CourseUtil.cpp @@ -345,6 +345,8 @@ void CourseID::FromCourse( const Course *p ) // Strip off leading "/". 2005/05/21 file layer changes added a leading slash. if( sPath.Left(1) == "/" ) sPath.erase( sPath.begin() ); + + m_Cache.Unset(); } Course *CourseID::ToCourse() const @@ -355,21 +357,17 @@ Course *CourseID::ToCourse() const if( sPath2.Left(1) != "/" ) sPath2 = "/" + sPath2; - if( !sPath2.empty() ) - { - Course *pCourse = SONGMAN->GetCourseFromPath( sPath2 ); - if( pCourse ) - return pCourse; - } + Course *pCourse = NULL; + if( m_Cache.Get(&pCourse) ) + return pCourse; + if( pCourse == NULL && !sPath2.empty() ) + pCourse = SONGMAN->GetCourseFromPath( sPath2 ); - if( !sFullTitle.empty() ) - { - Course *pCourse = SONGMAN->GetCourseFromName( sFullTitle ); - if( pCourse ) - return pCourse; - } + if( pCourse == NULL && !sFullTitle.empty() ) + pCourse = SONGMAN->GetCourseFromName( sFullTitle ); + m_Cache.Set( pCourse ); - return NULL; + return pCourse; } XNode* CourseID::CreateNode() const @@ -391,6 +389,7 @@ void CourseID::LoadFromNode( const XNode* pNode ) sPath = RString(); if( !pNode->GetAttrValue("Path", sPath) ) pNode->GetAttrValue( "FullTitle", sFullTitle ); + m_Cache.Unset(); } RString CourseID::ToString() const diff --git a/stepmania/src/CourseUtil.h b/stepmania/src/CourseUtil.h index 37a22fcee4..e8caeb4d95 100644 --- a/stepmania/src/CourseUtil.h +++ b/stepmania/src/CourseUtil.h @@ -5,6 +5,7 @@ #include "GameConstantsAndTypes.h" #include "Difficulty.h" +#include "RageUtil_CachedObject.h" class Course; class Profile; @@ -58,6 +59,7 @@ public: private: RString sPath; RString sFullTitle; + mutable CachedObjectPointer m_Cache; }; #endif diff --git a/stepmania/src/Trail.cpp b/stepmania/src/Trail.cpp index c9df205e6b..78e2fb3d44 100644 --- a/stepmania/src/Trail.cpp +++ b/stepmania/src/Trail.cpp @@ -8,6 +8,8 @@ #include "NoteDataUtil.h" #include "CommonMetrics.h" +CACHED_REGISTER_CLASS(Trail); + void TrailEntry::GetAttackArray( AttackArray &out ) const { if( !Modifiers.empty() ) diff --git a/stepmania/src/Trail.h b/stepmania/src/Trail.h index dd2f399831..4edc41f40e 100644 --- a/stepmania/src/Trail.h +++ b/stepmania/src/Trail.h @@ -6,6 +6,7 @@ #include "Attack.h" #include "RadarValues.h" #include "Difficulty.h" +#include "RageUtil_CachedObject.h" class Song; class Steps; @@ -72,6 +73,8 @@ public: bool IsSecret() const; bool ContainsSong( const Song *pSong ) const; + CachedObject m_CachedObject; + // Lua void PushSelf( lua_State *L ); }; diff --git a/stepmania/src/TrailUtil.cpp b/stepmania/src/TrailUtil.cpp index 8ca2c2a020..f3be798cfc 100644 --- a/stepmania/src/TrailUtil.cpp +++ b/stepmania/src/TrailUtil.cpp @@ -18,6 +18,7 @@ void TrailID::FromTrail( const Trail *p ) st = p->m_StepsType; cd = p->m_CourseDifficulty; } + m_Cache.Unset(); } Trail *TrailID::ToTrail( const Course *p, bool bAllowNull ) const @@ -25,8 +26,13 @@ Trail *TrailID::ToTrail( const Course *p, bool bAllowNull ) const ASSERT( p ); Trail *pRet = NULL; - if( st != StepsType_Invalid && cd != Difficulty_Invalid ) - pRet = p->GetTrail( st, cd ); + if( !m_Cache.Get(&pRet) ) + { + if( st != StepsType_Invalid && cd != Difficulty_Invalid ) + pRet = p->GetTrail( st, cd ); + m_Cache.Set( pRet ); + } + if( !bAllowNull && pRet == NULL ) RageException::Throw( "%i, %i, \"%s\"", st, cd, p->GetDisplayFullTitle().c_str() ); @@ -54,6 +60,7 @@ void TrailID::LoadFromNode( const XNode* pNode ) pNode->GetAttrValue( "CourseDifficulty", sTemp ); cd = StringToDifficulty( sTemp ); + m_Cache.Unset(); } RString TrailID::ToString() const diff --git a/stepmania/src/TrailUtil.h b/stepmania/src/TrailUtil.h index 2eb33b5c55..bee610cd46 100644 --- a/stepmania/src/TrailUtil.h +++ b/stepmania/src/TrailUtil.h @@ -3,6 +3,7 @@ #include "GameConstantsAndTypes.h" #include "Difficulty.h" +#include "RageUtil_CachedObject.h" class Song; class Trail; @@ -13,6 +14,7 @@ class TrailID { StepsType st; CourseDifficulty cd; + mutable CachedObjectPointer m_Cache; public: TrailID() { Unset(); }