optimize adding background changes
I have a song with 5841 background changes and it took 3 seconds to load that song.
This commit is contained in:
@@ -129,6 +129,13 @@ void BackgroundUtil::SortBackgroundChangesArray( vector<BackgroundChange> &vBack
|
|||||||
sort( vBackgroundChanges.begin(), vBackgroundChanges.end(), CompareBackgroundChanges );
|
sort( vBackgroundChanges.begin(), vBackgroundChanges.end(), CompareBackgroundChanges );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BackgroundUtil::AddBackgroundChange( vector<BackgroundChange> &vBackgroundChanges, BackgroundChange seg )
|
||||||
|
{
|
||||||
|
vector<BackgroundChange>::iterator it;
|
||||||
|
it = upper_bound( vBackgroundChanges.begin(), vBackgroundChanges.end(), seg, CompareBackgroundChanges );
|
||||||
|
vBackgroundChanges.insert( it, seg );
|
||||||
|
}
|
||||||
|
|
||||||
void BackgroundUtil::GetBackgroundEffects( const RString &_sName, vector<RString> &vsPathsOut, vector<RString> &vsNamesOut )
|
void BackgroundUtil::GetBackgroundEffects( const RString &_sName, vector<RString> &vsPathsOut, vector<RString> &vsNamesOut )
|
||||||
{
|
{
|
||||||
RString sName = _sName;
|
RString sName = _sName;
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ struct BackgroundChange
|
|||||||
/** @brief Shared background-related routines. */
|
/** @brief Shared background-related routines. */
|
||||||
namespace BackgroundUtil
|
namespace BackgroundUtil
|
||||||
{
|
{
|
||||||
|
void AddBackgroundChange( vector<BackgroundChange> &vBackgroundChanges, BackgroundChange seg );
|
||||||
void SortBackgroundChangesArray( vector<BackgroundChange> &vBackgroundChanges );
|
void SortBackgroundChangesArray( vector<BackgroundChange> &vBackgroundChanges );
|
||||||
|
|
||||||
void GetBackgroundEffects( const RString &sName, vector<RString> &vsPathsOut, vector<RString> &vsNamesOut );
|
void GetBackgroundEffects( const RString &sName, vector<RString> &vsPathsOut, vector<RString> &vsNamesOut );
|
||||||
|
|||||||
+2
-4
@@ -175,14 +175,12 @@ void Song::AddBackgroundChange( BackgroundLayer iLayer, BackgroundChange seg )
|
|||||||
}
|
}
|
||||||
|
|
||||||
ASSERT( iLayer >= 0 && iLayer < NUM_BackgroundLayer );
|
ASSERT( iLayer >= 0 && iLayer < NUM_BackgroundLayer );
|
||||||
GetBackgroundChanges(iLayer).push_back( seg );
|
BackgroundUtil::AddBackgroundChange( GetBackgroundChanges(iLayer), seg );
|
||||||
BackgroundUtil::SortBackgroundChangesArray( GetBackgroundChanges(iLayer) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Song::AddForegroundChange( BackgroundChange seg )
|
void Song::AddForegroundChange( BackgroundChange seg )
|
||||||
{
|
{
|
||||||
GetForegroundChanges().push_back( seg );
|
BackgroundUtil::AddBackgroundChange( GetForegroundChanges(), seg );
|
||||||
BackgroundUtil::SortBackgroundChangesArray( GetForegroundChanges() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Song::AddLyricSegment( LyricSegment seg )
|
void Song::AddLyricSegment( LyricSegment seg )
|
||||||
|
|||||||
Reference in New Issue
Block a user