add GetTrails
make GetTrail return value not become invalid after ClearCache() is called
This commit is contained in:
+24
-12
@@ -266,6 +266,7 @@ void Course::Init()
|
|||||||
ZERO( m_iCustomMeter );
|
ZERO( m_iCustomMeter );
|
||||||
m_entries.clear();
|
m_entries.clear();
|
||||||
m_sPath = m_sName = m_sNameTranslit = m_sBannerPath = m_sCDTitlePath = "";
|
m_sPath = m_sName = m_sNameTranslit = m_sBannerPath = m_sCDTitlePath = "";
|
||||||
|
ZERO( m_TrailCacheValid );
|
||||||
}
|
}
|
||||||
|
|
||||||
void Course::Save()
|
void Course::Save()
|
||||||
@@ -554,23 +555,21 @@ CString Course::GetDisplayName() const
|
|||||||
|
|
||||||
/* This is called by many simple functions, like Course::GetTotalSeconds, and may
|
/* This is called by many simple functions, like Course::GetTotalSeconds, and may
|
||||||
* be called on all songs to sort. It can take time to execute, so we cache the
|
* be called on all songs to sort. It can take time to execute, so we cache the
|
||||||
* results. */
|
* results. Returned pointers remain valid for the lifetime of the Course. */
|
||||||
|
/* XXX: if !HasCourseDifficulty(cd), return NULL instead of COURSE_DIFFICULTY_REGULAR */
|
||||||
Trail* Course::GetTrail( StepsType st, CourseDifficulty cd ) const
|
Trail* Course::GetTrail( StepsType st, CourseDifficulty cd ) const
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Look in the Trail cache
|
// Look in the Trail cache
|
||||||
//
|
//
|
||||||
const TrailParams params( st, cd );
|
if( m_TrailCacheValid[st][cd] )
|
||||||
TrailCache::iterator it = m_TrailCache.find( params );
|
return &m_TrailCache[st][cd];
|
||||||
if( it != m_TrailCache.end() )
|
|
||||||
{
|
|
||||||
return &it->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Construct a new Trail, add it to the cache, then return it.
|
// Construct a new Trail, add it to the cache, then return it.
|
||||||
//
|
//
|
||||||
Trail trail;
|
Trail &trail = m_TrailCache[st][cd];
|
||||||
|
trail = Trail();
|
||||||
GetTrailUnsorted( st, cd, trail );
|
GetTrailUnsorted( st, cd, trail );
|
||||||
|
|
||||||
if( this->m_bSortByMeter )
|
if( this->m_bSortByMeter )
|
||||||
@@ -599,9 +598,8 @@ Trail* Course::GetTrail( StepsType st, CourseDifficulty cd ) const
|
|||||||
trail.m_vEntries[i] = entries[i].entry;
|
trail.m_vEntries[i] = entries[i].entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Cache results. */
|
m_TrailCacheValid[st][cd] = true;
|
||||||
m_TrailCache[params] = trail;
|
return &m_TrailCache[st][cd];
|
||||||
return &m_TrailCache[params];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Course::GetTrailUnsorted( StepsType st, CourseDifficulty cd, Trail &trail ) const
|
void Course::GetTrailUnsorted( StepsType st, CourseDifficulty cd, Trail &trail ) const
|
||||||
@@ -803,6 +801,20 @@ void Course::GetTrailUnsorted( StepsType st, CourseDifficulty cd, Trail &trail )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Course::GetTrails( vector<Trail*> &out, StepsType st ) const
|
||||||
|
{
|
||||||
|
FOREACH_CourseDifficulty( cd )
|
||||||
|
{
|
||||||
|
if( !HasCourseDifficulty(st, cd) )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Trail *pTrail = GetTrail( st, cd );
|
||||||
|
if( pTrail == NULL )
|
||||||
|
continue;
|
||||||
|
out.push_back( pTrail );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool Course::HasMods() const
|
bool Course::HasMods() const
|
||||||
{
|
{
|
||||||
for( unsigned i=0; i<m_entries.size(); i++ )
|
for( unsigned i=0; i<m_entries.size(); i++ )
|
||||||
@@ -826,7 +838,7 @@ bool Course::AllSongsAreFixed() const
|
|||||||
|
|
||||||
void Course::ClearCache()
|
void Course::ClearCache()
|
||||||
{
|
{
|
||||||
m_TrailCache.clear();
|
ZERO( m_TrailCacheValid );
|
||||||
}
|
}
|
||||||
|
|
||||||
RageColor Course::GetColor() const
|
RageColor Course::GetColor() const
|
||||||
|
|||||||
@@ -96,6 +96,7 @@ public:
|
|||||||
|
|
||||||
// Dereferences course_entries and returns only the playable Songs and Steps
|
// Dereferences course_entries and returns only the playable Songs and Steps
|
||||||
Trail* GetTrail( StepsType st, CourseDifficulty cd ) const;
|
Trail* GetTrail( StepsType st, CourseDifficulty cd ) const;
|
||||||
|
void GetTrails( vector<Trail*> &out, StepsType st ) const;
|
||||||
float GetMeter( StepsType st, CourseDifficulty cd ) const;
|
float GetMeter( StepsType st, CourseDifficulty cd ) const;
|
||||||
bool HasMods() const;
|
bool HasMods() const;
|
||||||
bool AllSongsAreFixed() const;
|
bool AllSongsAreFixed() const;
|
||||||
@@ -134,9 +135,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
void GetTrailUnsorted( StepsType st, CourseDifficulty cd, Trail &trail ) const;
|
void GetTrailUnsorted( StepsType st, CourseDifficulty cd, Trail &trail ) const;
|
||||||
|
|
||||||
typedef pair<StepsType,CourseDifficulty> TrailParams;
|
mutable Trail m_TrailCache[NUM_STEPS_TYPES][NUM_COURSE_DIFFICULTIES];
|
||||||
typedef map<TrailParams, Trail> TrailCache;
|
mutable bool m_TrailCacheValid[NUM_STEPS_TYPES][NUM_COURSE_DIFFICULTIES];
|
||||||
mutable TrailCache m_TrailCache;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user