We have a lot of duplicate, redundant checks between UNLOCKMAN->SongIsLocked

and Song::GetDisplayed/Song::NormallyDisplayed, which leads to inconsistency.

Make UnlockManager::SongIsLocked() handle both.  Returns a bitfield; most
cases only need to test true or false.

(Also adds m_bEnabled; not used yet.)
This commit is contained in:
Glenn Maynard
2007-08-13 21:20:51 +00:00
parent 4d3b3315b8
commit 3e3c1deea4
13 changed files with 64 additions and 44 deletions
+2 -2
View File
@@ -100,7 +100,7 @@ void CatalogXml::Save( LoadingWindow *loading_window )
if( pSong->IsTutorial() ) if( pSong->IsTutorial() )
continue; // skip: Tutorial song. continue; // skip: Tutorial song.
if( UNLOCKMAN->SongIsLocked(pSong) ) if( !pSong->NormallyDisplayed() )
continue; // skip: Locked song. continue; // skip: Locked song.
iTotalSongs++; iTotalSongs++;
iNumSongsInGroup++; iNumSongsInGroup++;
@@ -184,7 +184,7 @@ void CatalogXml::Save( LoadingWindow *loading_window )
if( pSong->IsTutorial() ) if( pSong->IsTutorial() )
continue; // skip: Tutorial song. continue; // skip: Tutorial song.
if( UNLOCKMAN->SongIsLocked(pSong) ) if( !pSong->NormallyDisplayed() )
continue; // skip: Locked song. continue; // skip: Locked song.
SongID songID; SongID songID;
+1 -1
View File
@@ -63,7 +63,7 @@ void EditMenu::GetSongsToShowForGroup( const RString &sGroup, vector<Song*> &vpS
for( int i=vpSongsOut.size()-1; i>=0; i-- ) for( int i=vpSongsOut.size()-1; i>=0; i-- )
{ {
const Song* pSong = vpSongsOut[i]; const Song* pSong = vpSongsOut[i];
if( UNLOCKMAN->SongIsLocked(pSong) || pSong->IsTutorial() || SONGMAN->WasLoadedFromAdditionalSongs(pSong) ) if( !pSong->NormallyDisplayed() || pSong->IsTutorial() || SONGMAN->WasLoadedFromAdditionalSongs(pSong) )
vpSongsOut.erase( vpSongsOut.begin()+i ); vpSongsOut.erase( vpSongsOut.begin()+i );
} }
break; break;
+6 -2
View File
@@ -343,11 +343,15 @@ void MusicWheel::GetSongList( vector<Song*> &arraySongs, SortOrder so, const RSt
{ {
Song* pSong = apAllSongs[i]; Song* pSong = apAllSongs[i];
int iLocked = UNLOCKMAN->SongIsLocked( pSong );
if( iLocked & LOCKED_DISABLED )
continue;
/* If we're on an extra stage, and this song is selected, ignore #SELECTABLE. */ /* If we're on an extra stage, and this song is selected, ignore #SELECTABLE. */
if( pSong != GAMESTATE->m_pCurSong || !GAMESTATE->IsAnExtraStage() ) if( pSong != GAMESTATE->m_pCurSong || !GAMESTATE->IsAnExtraStage() )
{ {
/* Hide songs that asked to be hidden via #SELECTABLE. */ /* Hide songs that asked to be hidden via #SELECTABLE. */
if( !pSong->NormallyDisplayed() ) if( iLocked & LOCKED_SELECTABLE )
continue; continue;
if( so!=SORT_ROULETTE && UNLOCKMAN->SongIsRouletteOnly( pSong ) ) if( so!=SORT_ROULETTE && UNLOCKMAN->SongIsRouletteOnly( pSong ) )
continue; continue;
@@ -355,7 +359,7 @@ void MusicWheel::GetSongList( vector<Song*> &arraySongs, SortOrder so, const RSt
/* Hide locked songs. If RANDOM_PICKS_LOCKED_SONGS, hide in Roulette and Random, /* Hide locked songs. If RANDOM_PICKS_LOCKED_SONGS, hide in Roulette and Random,
* too. */ * too. */
if( (so!=SORT_ROULETTE || !RANDOM_PICKS_LOCKED_SONGS) && UNLOCKMAN->SongIsLocked(pSong) ) if( (so!=SORT_ROULETTE || !RANDOM_PICKS_LOCKED_SONGS) && iLocked )
continue; continue;
// If the song has at least one steps, add it. // If the song has at least one steps, add it.
+3 -3
View File
@@ -253,7 +253,7 @@ int Profile::GetTotalStepsWithTopGrade( StepsType st, Difficulty d, Grade g ) co
FOREACH_CONST( Song*, SONGMAN->GetSongs(), pSong ) FOREACH_CONST( Song*, SONGMAN->GetSongs(), pSong )
{ {
if( (*pSong)->GetDisplayed() == Song::SHOW_NEVER ) if( !(*pSong)->NormallyDisplayed() )
continue; // skip continue; // skip
FOREACH_CONST( Steps*, (*pSong)->GetAllSteps(), pSteps ) FOREACH_CONST( Steps*, (*pSong)->GetAllSteps(), pSteps )
@@ -315,7 +315,7 @@ float Profile::GetSongsPossible( StepsType st, Difficulty dc ) const
{ {
Song* pSong = vSongs[i]; Song* pSong = vSongs[i];
if( pSong->GetDisplayed() == Song::SHOW_NEVER ) if( !pSong->NormallyDisplayed() )
continue; // skip continue; // skip
vector<Steps*> vSteps = pSong->GetAllSteps(); vector<Steps*> vSteps = pSong->GetAllSteps();
@@ -355,7 +355,7 @@ float Profile::GetSongsActual( StepsType st, Difficulty dc ) const
if( pSong == NULL ) if( pSong == NULL )
continue; continue;
if( pSong->GetDisplayed() == Song::SHOW_NEVER ) if( !pSong->NormallyDisplayed() )
continue; // skip continue; // skip
CHECKPOINT_M( ssprintf("Profile::GetSongsActual: song %s", pSong->GetSongDir().c_str()) ); CHECKPOINT_M( ssprintf("Profile::GetSongsActual: song %s", pSong->GetSongDir().c_str()) );
+1 -1
View File
@@ -83,7 +83,7 @@ void ScreenJukebox::SetSong()
ASSERT( pSong != NULL ); ASSERT( pSong != NULL );
if( !pSong->HasMusic() ) if( !pSong->HasMusic() )
continue; // skip continue; // skip
if( UNLOCKMAN->SongIsLocked(pSong) ) if( !pSong->NormallyDisplayed() )
continue; continue;
if( !pSong->ShowInDemonstrationAndRanking() ) if( !pSong->ShowInDemonstrationAndRanking() )
continue; // skip continue; // skip
+1 -1
View File
@@ -39,7 +39,7 @@ static void GetAllSongsToShow( vector<Song*> &vpOut, bool bShowOnlyMostRecentSco
vpOut.clear(); vpOut.clear();
FOREACH_CONST( Song*, SONGMAN->GetSongs(), s ) FOREACH_CONST( Song*, SONGMAN->GetSongs(), s )
{ {
if( UNLOCKMAN->SongIsLocked(*s) ) if( !(*s)->NormallyDisplayed() )
continue; // skip continue; // skip
if( !(*s)->ShowInDemonstrationAndRanking() ) if( !(*s)->ShowInDemonstrationAndRanking() )
continue; // skip continue; // skip
+1 -1
View File
@@ -39,7 +39,7 @@ void ScreenSelectGroup::Init()
{ {
bool DisplaySong = aAllSongs[j]->NormallyDisplayed(); bool DisplaySong = aAllSongs[j]->NormallyDisplayed();
if( UNLOCKMAN->SongIsLocked( aAllSongs[j] ) ) if( !aAllSongs[j]->NormallyDisplayed() )
DisplaySong = false; DisplaySong = false;
if( aAllSongs[j]->SongCompleteForStyle(GAMESTATE->GetCurrentStyle()) && if( aAllSongs[j]->SongCompleteForStyle(GAMESTATE->GetCurrentStyle()) &&
+8 -6
View File
@@ -26,7 +26,7 @@
#include "NotesLoaderSM.h" #include "NotesLoaderSM.h"
#include "NotesWriterDWI.h" #include "NotesWriterDWI.h"
#include "NotesWriterSM.h" #include "NotesWriterSM.h"
#include "UnlockManager.h"
#include "LyricsLoader.h" #include "LyricsLoader.h"
#include <time.h> #include <time.h>
@@ -66,6 +66,7 @@ Song::Song()
m_fLastBeat = -1; m_fLastBeat = -1;
m_fSpecifiedLastBeat = -1; m_fSpecifiedLastBeat = -1;
m_SelectionDisplay = SHOW_ALWAYS; m_SelectionDisplay = SHOW_ALWAYS;
m_bEnabled = true;
m_DisplayBPMType = DISPLAY_ACTUAL; m_DisplayBPMType = DISPLAY_ACTUAL;
m_fSpecifiedBPMMin = 0; m_fSpecifiedBPMMin = 0;
m_fSpecifiedBPMMax = 0; m_fSpecifiedBPMMax = 0;
@@ -1042,13 +1043,14 @@ bool Song::HasEdits( StepsType st ) const
return false; return false;
} }
Song::SelectionDisplay Song::GetDisplayed() const /* Return false if the song should not be displayed for selection in normal
* gameplay (but may still be available in random selection, during extra
* stages, or in other special conditions). */
bool Song::NormallyDisplayed() const
{ {
if( !PREFSMAN->m_bHiddenSongs ) return UNLOCKMAN == NULL || !UNLOCKMAN->SongIsLocked(this);
return SHOW_ALWAYS;
return m_SelectionDisplay;
} }
bool Song::NormallyDisplayed() const { return GetDisplayed() == SHOW_ALWAYS; }
bool Song::ShowInDemonstrationAndRanking() const { return !IsTutorial() && NormallyDisplayed(); } bool Song::ShowInDemonstrationAndRanking() const { return !IsTutorial() && NormallyDisplayed(); }
+7 -11
View File
@@ -582,7 +582,8 @@ int SongManager::GetNumUnlockedSongs() const
int iNum = 0; int iNum = 0;
FOREACH_CONST( Song*, m_pSongs, i ) FOREACH_CONST( Song*, m_pSongs, i )
{ {
if( UNLOCKMAN->SongIsLocked( *i ) ) // If locked for any reason other than LOCKED_LOCK:
if( UNLOCKMAN->SongIsLocked(*i) & ~LOCKED_LOCK )
continue; continue;
++iNum; ++iNum;
} }
@@ -594,9 +595,8 @@ int SongManager::GetNumSelectableAndUnlockedSongs() const
int iNum = 0; int iNum = 0;
FOREACH_CONST( Song*, m_pSongs, i ) FOREACH_CONST( Song*, m_pSongs, i )
{ {
if( UNLOCKMAN->SongIsLocked( *i ) ) // If locked for any reason other than LOCKED_LOCK or LOCKED_SELECTABLE:
continue; if( UNLOCKMAN->SongIsLocked(*i) & ~(LOCKED_LOCK|LOCKED_SELECTABLE) )
if( (*i)->GetDisplayed() != Song::SHOW_ALWAYS )
continue; continue;
++iNum; ++iNum;
} }
@@ -1102,7 +1102,7 @@ Song* SongManager::GetRandomSong()
Song *pSong = m_pShuffledSongs[ i ]; Song *pSong = m_pShuffledSongs[ i ];
if( pSong->IsTutorial() ) if( pSong->IsTutorial() )
continue; continue;
if( UNLOCKMAN->SongIsLocked(pSong) ) if( !pSong->NormallyDisplayed() )
continue; continue;
return pSong; return pSong;
} }
@@ -1251,12 +1251,8 @@ void SongManager::UpdatePopular()
for ( unsigned j=0; j < apBestSongs.size() ; ++j ) for ( unsigned j=0; j < apBestSongs.size() ; ++j )
{ {
bool bFiltered = false; bool bFiltered = false;
/* Filter out hidden songs. */
if( apBestSongs[j]->GetDisplayed() != Song::SHOW_ALWAYS )
bFiltered = true;
/* Filter out locked songs. */ /* Filter out locked songs. */
// XXX Hack, this depends on UNLOCKMAN being around. if( !apBestSongs[j]->NormallyDisplayed() )
if( UNLOCKMAN && UNLOCKMAN->SongIsLocked(apBestSongs[j]) )
bFiltered = true; bFiltered = true;
if( !bFiltered ) if( !bFiltered )
continue; continue;
@@ -1328,7 +1324,7 @@ void SongManager::UpdatePreferredSort()
Song *pSong = NULL; Song *pSong = NULL;
if( !sLine.empty() ) if( !sLine.empty() )
pSong = FindSong( sLine ); pSong = FindSong( sLine );
if( pSong && pSong->GetDisplayed() != Song::SHOW_NEVER ) if( pSong && UNLOCKMAN->SongIsLocked(pSong) & LOCKED_SELECTABLE )
vpSongs.push_back( pSong ); vpSongs.push_back( pSong );
} }
} }
+7 -4
View File
@@ -24,6 +24,9 @@ bool SongCriteria::Matches( const Song *pSong ) const
if( !m_sGroupName.empty() && m_sGroupName != pSong->m_sGroupName ) if( !m_sGroupName.empty() && m_sGroupName != pSong->m_sGroupName )
return false; return false;
if( UNLOCKMAN->SongIsLocked(pSong) & LOCKED_DISABLED )
return false;
if( m_bUseSongGenreAllowedList ) if( m_bUseSongGenreAllowedList )
{ {
if( find(m_vsSongGenreAllowedList.begin(),m_vsSongGenreAllowedList.end(),pSong->m_sGenre) == m_vsSongGenreAllowedList.end() ) if( find(m_vsSongGenreAllowedList.begin(),m_vsSongGenreAllowedList.end(),pSong->m_sGenre) == m_vsSongGenreAllowedList.end() )
@@ -34,11 +37,11 @@ bool SongCriteria::Matches( const Song *pSong ) const
{ {
DEFAULT_FAIL(m_Selectable); DEFAULT_FAIL(m_Selectable);
case Selectable_Yes: case Selectable_Yes:
if( pSong->GetDisplayed() != Song::SHOW_ALWAYS ) if( UNLOCKMAN && !(UNLOCKMAN->SongIsLocked(pSong) & LOCKED_SELECTABLE) )
return false; return false;
break; break;
case Selectable_No: case Selectable_No:
if( pSong->GetDisplayed() != Song::SHOW_NEVER ) if( UNLOCKMAN && UNLOCKMAN->SongIsLocked(pSong) & LOCKED_SELECTABLE )
return false; return false;
break; break;
case Selectable_DontCare: case Selectable_DontCare:
@@ -73,11 +76,11 @@ bool SongCriteria::Matches( const Song *pSong ) const
{ {
DEFAULT_FAIL(m_Locked); DEFAULT_FAIL(m_Locked);
case Locked_Locked: case Locked_Locked:
if( UNLOCKMAN && !UNLOCKMAN->SongIsLocked(pSong) ) if( UNLOCKMAN && !(UNLOCKMAN->SongIsLocked(pSong) & LOCKED_LOCK) )
return false; return false;
break; break;
case Locked_Unlocked: case Locked_Unlocked:
if( UNLOCKMAN && UNLOCKMAN->SongIsLocked(pSong) ) if( UNLOCKMAN && UNLOCKMAN->SongIsLocked(pSong) & LOCKED_LOCK )
return false; return false;
break; break;
case Locked_DontCare: case Locked_DontCare:
+13 -9
View File
@@ -118,16 +118,20 @@ bool UnlockManager::CourseIsLocked( const Course *course ) const
return p->IsLocked(); return p->IsLocked();
} }
bool UnlockManager::SongIsLocked( const Song *song ) const int UnlockManager::SongIsLocked( const Song *pSong ) const
{ {
if( !PREFSMAN->m_bUseUnlockSystem ) int iRet = 0;
return false; if( PREFSMAN->m_bUseUnlockSystem )
{
const UnlockEntry *p = FindSong( song ); const UnlockEntry *p = FindSong( pSong );
if( p == NULL ) if( p != NULL && p->IsLocked() )
return false; iRet |= LOCKED_LOCK;
}
return p->IsLocked(); if( PREFSMAN->m_bHiddenSongs && pSong->m_SelectionDisplay == Song::SHOW_NEVER )
iRet |= LOCKED_SELECTABLE;
if( !pSong->m_bEnabled )
iRet |= LOCKED_DISABLED;
return iRet;
} }
/* Return true if the song is *only* available in roulette. */ /* Return true if the song is *only* available in roulette. */
+11 -1
View File
@@ -90,6 +90,16 @@ public:
void PushSelf( lua_State *L ); void PushSelf( lua_State *L );
}; };
// Option is locked due to an unsatisfied unlock entry.
#define LOCKED_LOCK 0x1
// Option is locked due to a #SELECTABLE tag.
#define LOCKED_SELECTABLE 0x2
// Option is disabled by the operator. (For courses, this means that a song in the
// course is disabled.)
#define LOCKED_DISABLED 0x4
class UnlockManager class UnlockManager
{ {
friend class UnlockEntry; friend class UnlockEntry;
@@ -100,7 +110,7 @@ public:
void Reload(); void Reload();
float PointsUntilNextUnlock( UnlockRequirement t ) const; float PointsUntilNextUnlock( UnlockRequirement t ) const;
bool SongIsLocked( const Song *song ) const; int SongIsLocked( const Song *pSong ) const;
bool SongIsRouletteOnly( const Song *song ) const; bool SongIsRouletteOnly( const Song *song ) const;
bool StepsIsLocked( const Song *pSong, const Steps *pSteps ) const; bool StepsIsLocked( const Song *pSong, const Steps *pSteps ) const;
bool CourseIsLocked( const Course *course ) const; bool CourseIsLocked( const Course *course ) const;
+3 -2
View File
@@ -101,6 +101,7 @@ public:
ProfileSlot m_LoadedFromProfile; // ProfileSlot_Invalid if wasn't loaded from a profile ProfileSlot m_LoadedFromProfile; // ProfileSlot_Invalid if wasn't loaded from a profile
bool m_bIsSymLink; bool m_bIsSymLink;
bool m_bEnabled;
RString m_sMainTitle, m_sSubTitle, m_sArtist; RString m_sMainTitle, m_sSubTitle, m_sArtist;
RString m_sMainTitleTranslit, m_sSubTitleTranslit, m_sArtistTranslit; RString m_sMainTitleTranslit, m_sSubTitleTranslit, m_sArtistTranslit;
@@ -206,7 +207,8 @@ public:
bool IsEasy( StepsType st ) const; bool IsEasy( StepsType st ) const;
bool IsTutorial() const; bool IsTutorial() const;
bool HasEdits( StepsType st ) const; bool HasEdits( StepsType st ) const;
SelectionDisplay GetDisplayed() const;
bool SetEnabled( bool b ) { m_bEnabled = b; }
bool NormallyDisplayed() const; bool NormallyDisplayed() const;
bool ShowInDemonstrationAndRanking() const; bool ShowInDemonstrationAndRanking() const;
@@ -232,7 +234,6 @@ public:
void PushSelf( lua_State *L ); void PushSelf( lua_State *L );
private: private:
vector<Steps*> m_vpSteps; vector<Steps*> m_vpSteps;
vector<Steps*> m_vpStepsByType[NUM_StepsType]; vector<Steps*> m_vpStepsByType[NUM_StepsType];
}; };