From 99e11714e5bcbfccb48ffac54469a2de452c69b9 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sat, 5 Jun 2004 08:36:21 +0000 Subject: [PATCH] Keep steps by StepsType, to speed up the common case of searching by it. Catalog writing (still for only one course) down to .381s; still too much time to be spending for one course on every load. I'd make catalog writing only happen if something has changed, but that would mean introducing some form of course caching, which I'd rather avoid ... --- stepmania/src/Song.cpp | 70 ++++++++++++++++++++++++++++-------------- stepmania/src/song.h | 3 +- 2 files changed, 49 insertions(+), 24 deletions(-) diff --git a/stepmania/src/Song.cpp b/stepmania/src/Song.cpp index f25245a3a7..36df03741c 100644 --- a/stepmania/src/Song.cpp +++ b/stepmania/src/Song.cpp @@ -91,6 +91,8 @@ void Song::Reset() for( unsigned i=0; i &vSteps ) /* Don't use RemoveSteps; autogen notes havn't yet been created and it'll * create them. */ + FOREACH_StepsType( st ) + { + for( int k=this->m_vpStepsByType[st].size()-1; k>=0; k-- ) + { + if( this->m_vpStepsByType[st][k] == s2 ) + { + // delete this->m_vpStepsByType[k]; // delete below + this->m_vpStepsByType[st].erase( this->m_vpStepsByType[st].begin()+k ); + break; + } + } + } + for( int k=this->m_vpSteps.size()-1; k>=0; k-- ) { if( this->m_vpSteps[k] == s2 ) @@ -866,19 +881,14 @@ void Song::ReCalculateRadarValuesAndLastBeat() void Song::GetSteps( vector& arrayAddTo, StepsType st, Difficulty dc, int iMeterLow, int iMeterHigh, const CString &sDescription, bool bIncludeAutoGen, int Max ) const { - /* Ignore m_bAutogenSteps for STEPS_TYPE_LIGHTS_CABINET. */ - if( st != STEPS_TYPE_LIGHTS_CABINET && !PREFSMAN->m_bAutogenSteps ) - bIncludeAutoGen = false; - if( !Max ) return; - for( unsigned i=0; i& vpSteps = GetAllSteps(st); + for( unsigned i=0; im_StepsType != st ) - continue; if( dc != DIFFICULTY_INVALID && dc != pSteps->GetDifficulty() ) continue; if( iMeterLow != -1 && iMeterLow > pSteps->GetMeter() ) @@ -903,16 +913,11 @@ void Song::GetSteps( vector& arrayAddTo, StepsType st, Difficulty dc, in Steps* Song::GetStepsByDifficulty( StepsType st, Difficulty dc, bool bIncludeAutoGen ) const { - /* Ignore m_bAutogenSteps for STEPS_TYPE_LIGHTS_CABINET. */ - if( st != STEPS_TYPE_LIGHTS_CABINET && !PREFSMAN->m_bAutogenSteps ) - bIncludeAutoGen = false; - const vector& vpSteps = m_vpSteps; + const vector& vpSteps = GetAllSteps(st); for( unsigned i=0; im_StepsType != st ) - continue; if( dc != DIFFICULTY_INVALID && dc != pSteps->GetDifficulty() ) continue; if( !bIncludeAutoGen && pSteps->IsAutogen() ) @@ -926,22 +931,15 @@ Steps* Song::GetStepsByDifficulty( StepsType st, Difficulty dc, bool bIncludeAut Steps* Song::GetStepsByMeter( StepsType st, int iMeterLow, int iMeterHigh ) const { - /* Ignore m_bAutogenSteps for STEPS_TYPE_LIGHTS_CABINET. */ - bool bIncludeAutoGen = (st == STEPS_TYPE_LIGHTS_CABINET || PREFSMAN->m_bAutogenSteps); - - const vector& vpSteps = m_vpSteps; + const vector& vpSteps = GetAllSteps(st); for( unsigned i=0; im_StepsType != st ) - continue; if( iMeterLow > pSteps->GetMeter() ) continue; if( iMeterHigh < pSteps->GetMeter() ) continue; - if( !bIncludeAutoGen && pSteps->IsAutogen() ) - continue; return pSteps; } @@ -1133,13 +1131,25 @@ void Song::AutoGen( StepsType ntTo, StepsType ntFrom ) { Steps* pNewNotes = new Steps; pNewNotes->AutogenFrom(pOriginalNotes, ntTo); - this->m_vpSteps.push_back( pNewNotes ); + this->AddSteps( pNewNotes ); } } } void Song::RemoveAutoGenNotes() { + FOREACH_StepsType(st) + { + for( int j=m_vpStepsByType[st].size()-1; j>=0; j-- ) + { + if( m_vpStepsByType[st][j]->IsAutogen() ) + { +// delete m_vpSteps[j]; // delete below + m_vpStepsByType[st].erase( m_vpStepsByType[st].begin()+j ); + } + } + } + for( int j=m_vpSteps.size()-1; j>=0; j-- ) { if( m_vpSteps[j]->IsAutogen() ) @@ -1296,6 +1306,8 @@ CString Song::GetFullTranslitTitle() const void Song::AddSteps( Steps* pSteps ) { m_vpSteps.push_back( pSteps ); + ASSERT_M( pSteps->m_StepsType < NUM_STEPS_TYPES, ssprintf("%i", pSteps->m_StepsType) ); + m_vpStepsByType[pSteps->m_StepsType].push_back( pSteps ); } void Song::RemoveSteps( const Steps* pSteps ) @@ -1305,6 +1317,18 @@ void Song::RemoveSteps( const Steps* pSteps ) RemoveAutoGenNotes(); + + vector &vpSteps = m_vpStepsByType[pSteps->m_StepsType]; + for( int j=vpSteps.size()-1; j>=0; j-- ) + { + if( vpSteps[j] == pSteps ) + { +// delete vpSteps[j]; // delete below + vpSteps.erase( vpSteps.begin()+j ); + break; + } + } + for( int j=m_vpSteps.size()-1; j>=0; j-- ) { if( m_vpSteps[j] == pSteps ) diff --git a/stepmania/src/song.h b/stepmania/src/song.h index 0dc5018437..6650cb5343 100644 --- a/stepmania/src/song.h +++ b/stepmania/src/song.h @@ -173,7 +173,7 @@ public: bool SongCompleteForStyle( const StyleDef *st ) const; bool HasStepsType( StepsType st ) const; bool HasStepsTypeAndDifficulty( StepsType st, Difficulty dc ) const; - const vector& GetAllSteps() const { return m_vpSteps; } + const vector& GetAllSteps( StepsType st=STEPS_TYPE_INVALID ) const { return st==STEPS_TYPE_INVALID? m_vpSteps:m_vpStepsByType[st]; } void GetSteps( vector& arrayAddTo, StepsType st = STEPS_TYPE_INVALID, Difficulty dc = DIFFICULTY_INVALID, int iMeterLow = -1, int iMeterHigh = -1, const CString &sDescription = "", bool bIncludeAutoGen = true, int Max = -1 ) const; Steps* GetStepsByDifficulty( StepsType st, Difficulty dc, bool bIncludeAutoGen = true ) const; Steps* GetStepsByMeter( StepsType st, int iMeterLow, int iMeterHigh ) const; @@ -199,6 +199,7 @@ private: void DeleteDuplicateSteps( vector &vSteps ); vector m_vpSteps; + vector m_vpStepsByType[NUM_STEPS_TYPES]; }; #endif