Simplify.

This commit is contained in:
Glenn Maynard
2003-07-18 06:38:05 +00:00
parent 7330fd157a
commit 32831d5af2
3 changed files with 80 additions and 135 deletions
+6 -6
View File
@@ -63,7 +63,7 @@ ScreenUnlock::ScreenUnlock() : ScreenAttract("ScreenUnlock")
// get pertaining songentry // get pertaining songentry
LOG->Trace("UnlockScreen: Searching for %s", DISPLAYED_SONG(i).c_str()); LOG->Trace("UnlockScreen: Searching for %s", DISPLAYED_SONG(i).c_str());
SongEntry *pSong = GAMESTATE->m_pUnlockingSys->FindSong( DISPLAYED_SONG(i) ); SongEntry *pSong = GAMESTATE->m_pUnlockingSys->FindLockEntry( DISPLAYED_SONG(i) );
if( pSong == NULL) if( pSong == NULL)
{ {
@@ -107,15 +107,15 @@ ScreenUnlock::ScreenUnlock() : ScreenAttract("ScreenUnlock")
CString DisplayedSong = DISPLAYED_SONG(i); CString DisplayedSong = DISPLAYED_SONG(i);
DisplayedSong.MakeUpper(); DisplayedSong.MakeUpper();
SongEntry *pSong = GAMESTATE->m_pUnlockingSys->FindSong(DisplayedSong); SongEntry *pSong = GAMESTATE->m_pUnlockingSys->FindLockEntry(DisplayedSong);
/* Reset zoom before using SetTextMaxWidth. */ /* Reset zoom before using SetTextMaxWidth. */
text->SetZoom(ScrollingTextZoom); text->SetZoom(ScrollingTextZoom);
if (pSong != NULL && pSong->ActualSong != NULL) if (pSong && pSong->m_pSong != NULL)
{ {
CString title = pSong->ActualSong->GetDisplayMainTitle(); CString title = pSong->m_pSong->GetDisplayMainTitle();
CString subtitle = pSong->ActualSong->GetDisplayMainTitle(); CString subtitle = pSong->m_pSong->GetDisplayMainTitle();
if( subtitle != "" ) if( subtitle != "" )
title = title + "\n" + subtitle; title = title + "\n" + subtitle;
text->SetTextMaxWidth( MaxWidth, title ); text->SetTextMaxWidth( MaxWidth, title );
@@ -142,7 +142,7 @@ ScreenUnlock::ScreenUnlock() : ScreenAttract("ScreenUnlock")
text->SetText("???"); text->SetText("???");
// text->SetZoom(ScrollingTextZoom * 1.99); // text->SetZoom(ScrollingTextZoom * 1.99);
} else { } else {
RageColor color = SONGMAN->GetGroupColor(pSong->ActualSong->m_sGroupName); RageColor color = SONGMAN->GetGroupColor(pSong->m_pSong->m_sGroupName);
text->SetGlobalDiffuseColor(color); text->SetGlobalDiffuseColor(color);
} }
} }
+49 -103
View File
@@ -61,18 +61,10 @@ bool UnlockSystem::CourseIsLocked( const Course *course )
// comparison, its the same thing. // comparison, its the same thing.
SongEntry *p = FindCourse( course ); SongEntry *p = FindCourse( course );
CString tmp;
if (p) if (p)
{ p->UpdateLocked();
p->isCourse = true; // updates flag here
p->updateLocked();
if (!p->isLocked) tmp = "un";
}
return (p != NULL) && (p->isLocked);
return p != NULL && p->isLocked;
} }
bool UnlockSystem::SongIsLocked( const Song *song ) bool UnlockSystem::SongIsLocked( const Song *song )
@@ -81,7 +73,7 @@ bool UnlockSystem::SongIsLocked( const Song *song )
if( p == NULL ) if( p == NULL )
return false; return false;
p->updateLocked(); p->UpdateLocked();
LOG->Trace( "current status: %slocked", p->isLocked? "":"un" ); LOG->Trace( "current status: %slocked", p->isLocked? "":"un" );
@@ -95,7 +87,7 @@ bool UnlockSystem::SongIsRoulette( const Song *song )
return p && (p->m_iRouletteSeed != 0) ; return p && (p->m_iRouletteSeed != 0) ;
} }
SongEntry *UnlockSystem::FindSong( CString songname ) SongEntry *UnlockSystem::FindLockEntry( CString songname )
{ {
for(unsigned i = 0; i < m_SongEntries.size(); i++) for(unsigned i = 0; i < m_SongEntries.size(); i++)
if (!songname.CompareNoCase(m_SongEntries[i].m_sSongName)) if (!songname.CompareNoCase(m_SongEntries[i].m_sSongName))
@@ -104,60 +96,20 @@ SongEntry *UnlockSystem::FindSong( CString songname )
return NULL; return NULL;
} }
SongEntry *UnlockSystem::FindCourse( const Course *pCourse ) SongEntry *UnlockSystem::FindSong( const Song *pSong )
{ {
CString CourseName = pCourse->m_sTranslitName;
for(unsigned i = 0; i < m_SongEntries.size(); i++) for(unsigned i = 0; i < m_SongEntries.size(); i++)
{ if (m_SongEntries[i].m_pSong == pSong )
if( !CourseName.CompareNoCase(m_SongEntries[i].m_sSongName) )
return &m_SongEntries[i]; return &m_SongEntries[i];
}
return NULL; return NULL;
} }
SongEntry *UnlockSystem::FindSong( const Song *pSong ) SongEntry *UnlockSystem::FindCourse( const Course *pCourse )
{ {
/* Manual binary searches are a bad idea; they're insanely easy to get
* wrong. This breaks the matching, anyway ... */
/*
int left = 0;
int right = m_SongEntries.size() - 1;
CString songtitle = pSong->GetFullTranslitTitle();
songtitle.MakeUpper();
while (left != right)
{
int mid = (left + right)/2;
if (songtitle <= m_SongEntries[mid].m_sSongName )
right = mid;
else
left = mid + 1;
}
if (m_SongEntries[left].GetSong() == pSong)
{
LOG->Trace("UnlockSystem: Retrieved: %s", pSong->GetFullTranslitTitle().c_str());
return &m_SongEntries[left];
}
LOG->Trace("UnlockSystem: Failed to find %s", pSong->GetFullTranslitTitle().c_str());
LOG->Trace(" (landed on %s)", m_SongEntries[left].m_sSongName.c_str() );
*/
/* This should be good enough; it doesn't iterate over all installed songs. (This
* is probably called for all songs, so that was probably n^2.) */
for(unsigned i = 0; i < m_SongEntries.size(); i++) for(unsigned i = 0; i < m_SongEntries.size(); i++)
{ if (m_SongEntries[i].m_pCourse== pCourse )
if( pSong->Matches("", m_SongEntries[i].m_sSongName) )
return &m_SongEntries[i]; return &m_SongEntries[i];
// if (m_SongEntries[i].GetSong() == pSong )
// return &m_SongEntries[i];
}
return NULL; return NULL;
} }
@@ -174,62 +126,50 @@ SongEntry::SongEntry()
m_fToastysSeen = 0; m_fToastysSeen = 0;
m_iRouletteSeed = 0; m_iRouletteSeed = 0;
ActualSong = NULL; m_pSong = NULL;
m_pCourse = NULL;
isLocked = true; isLocked = true;
isCourse = false;
} }
static bool CompareSongEntries(const SongEntry &se1, const SongEntry &se2) void SongEntry::UpdateLocked()
{ {
return se1.m_sSongName < se2.m_sSongName; if (!isLocked)
} return;
bool SongEntry::updateLocked() const UnlockSystem *UNLOCKS = GAMESTATE->m_pUnlockingSys;
{
if (!(isLocked)) return true; // if its already true
UnlockSystem *UNLOCKS = GAMESTATE->m_pUnlockingSys; isLocked = true;
bool locked[8]; if ( m_fArcadePointsRequired && UNLOCKS->ArcadePoints < m_fArcadePointsRequired )
for(int i=0; i < 8; i++) isLocked = false;
locked[i] = true;
if (m_fArcadePointsRequired != 0) if ( m_fDancePointsRequired && UNLOCKS->DancePoints < m_fDancePointsRequired )
locked[0] = ( UNLOCKS->ArcadePoints < m_fArcadePointsRequired); isLocked = false;
if (m_fDancePointsRequired != 0) if ( m_fSongPointsRequired && UNLOCKS->SongPoints < m_fSongPointsRequired )
locked[1] = ( UNLOCKS->DancePoints < m_fDancePointsRequired); isLocked = false;
if (m_fSongPointsRequired != 0) if ( m_fExtraStagesCleared && UNLOCKS->ExtraClearPoints < m_fExtraStagesCleared )
locked[2] = ( UNLOCKS->SongPoints < m_fSongPointsRequired); isLocked = false;
if (m_fExtraStagesCleared != 0) if ( m_fExtraStagesFailed && UNLOCKS->ExtraFailPoints < m_fExtraStagesFailed )
locked[3] = ( UNLOCKS->ExtraClearPoints < m_fExtraStagesCleared); isLocked = false;
if (m_fExtraStagesFailed != 0) if ( m_fStagesCleared && UNLOCKS->StagesCleared < m_fStagesCleared )
locked[4] = ( UNLOCKS->ExtraFailPoints < m_fExtraStagesFailed); isLocked = false;
if (m_fStagesCleared != 0) if ( m_fToastysSeen && UNLOCKS->ToastyPoints < m_fToastysSeen )
locked[5] = ( UNLOCKS->StagesCleared < m_fStagesCleared); isLocked = false;
if (m_fToastysSeen != 0) if ( m_iRouletteSeed )
locked[6] = ( UNLOCKS->ToastyPoints < m_fToastysSeen);
if (m_iRouletteSeed != 0)
{ {
CString tmp = UNLOCKS->RouletteSeeds; const CString &tmp = UNLOCKS->RouletteSeeds;
LOG->Trace("Seed in question: %d Roulette seeds: %s", LOG->Trace("Seed in question: %d Roulette seeds: %s", m_iRouletteSeed, tmp.c_str() );
m_iRouletteSeed, tmp.c_str() ); if( tmp[m_iRouletteSeed] != '1' )
locked[7] = (tmp[m_iRouletteSeed] != '1'); isLocked = false;
} }
isLocked = true;
for(int j=0; j < 8; j++)
isLocked = isLocked && locked[j];
return !isLocked;
} }
bool UnlockSystem::LoadFromDATFile( CString sPath ) bool UnlockSystem::LoadFromDATFile( CString sPath )
@@ -302,9 +242,7 @@ bool UnlockSystem::LoadFromDATFile( CString sPath )
MaxRouletteSlot = max( MaxRouletteSlot, (int) datavalue ); MaxRouletteSlot = max( MaxRouletteSlot, (int) datavalue );
} }
} }
current.updateLocked(); current.UpdateLocked();
current.ActualSong = SONGMAN->FindSong( "", current.m_sSongName );
m_SongEntries.push_back(current); m_SongEntries.push_back(current);
} }
@@ -312,8 +250,7 @@ bool UnlockSystem::LoadFromDATFile( CString sPath )
InitRouletteSeeds(MaxRouletteSlot); // resize roulette seeds InitRouletteSeeds(MaxRouletteSlot); // resize roulette seeds
// for more efficient use of file // for more efficient use of file
// sort list so we can make use of binary searching UpdateSongs();
sort( m_SongEntries.begin(), m_SongEntries.end(), CompareSongEntries );
for(i=0; i < m_SongEntries.size(); i++) for(i=0; i < m_SongEntries.size(); i++)
{ {
@@ -321,8 +258,8 @@ bool UnlockSystem::LoadFromDATFile( CString sPath )
if (!m_SongEntries[i].isLocked) tmp = "un"; if (!m_SongEntries[i].isLocked) tmp = "un";
LOG->Trace( "UnlockSystem Entry %s", m_SongEntries[i].m_sSongName.c_str() ); LOG->Trace( "UnlockSystem Entry %s", m_SongEntries[i].m_sSongName.c_str() );
if (m_SongEntries[i].ActualSong != NULL) if (m_SongEntries[i].m_pSong != NULL)
LOG->Trace( " Translit %s", m_SongEntries[i].ActualSong->GetDisplayMainTitle().c_str() ); LOG->Trace( " Translit %s", m_SongEntries[i].m_pSong->GetTranslitMainTitle().c_str() );
LOG->Trace( " AP %f", m_SongEntries[i].m_fArcadePointsRequired ); LOG->Trace( " AP %f", m_SongEntries[i].m_fArcadePointsRequired );
LOG->Trace( " DP %f", m_SongEntries[i].m_fDancePointsRequired ); LOG->Trace( " DP %f", m_SongEntries[i].m_fDancePointsRequired );
LOG->Trace( " SP %f", m_SongEntries[i].m_fSongPointsRequired ); LOG->Trace( " SP %f", m_SongEntries[i].m_fSongPointsRequired );
@@ -381,9 +318,18 @@ float UnlockSystem::SongPointsUntilNextUnlock()
return fSmallestPoints - SongPoints; return fSmallestPoints - SongPoints;
} }
Song *SongEntry::GetSong() const /* Update the song pointer. Only call this when it's likely to have changed,
* such as on load, or when a song title changes in the editor. */
void UnlockSystem::UpdateSongs()
{ {
return SONGMAN->FindSong( "", m_sSongName ); for( unsigned i = 0; i < m_SongEntries.size(); ++i )
{
m_SongEntries[i].m_pSong = NULL;
m_SongEntries[i].m_pCourse = NULL;
m_SongEntries[i].m_pSong = SONGMAN->FindSong( "", m_SongEntries[i].m_sSongName );
if( m_SongEntries[i].m_pSong == NULL )
m_SongEntries[i].m_pCourse = SONGMAN->FindCourse( m_SongEntries[i].m_sSongName );
}
} }
// This is mainly to streamline the INI for unnecessary values. // This is mainly to streamline the INI for unnecessary values.
+16 -17
View File
@@ -21,12 +21,12 @@ class Song;
struct SongEntry struct SongEntry
{ {
CString m_sSongName; /* Name of the song in the DWI/SM file itself.. This allows CString m_sSongName;
for a lot easier compatibility since a lot of people's
song folders are named differantly, song names tend to
be the same in the file.*/
Song* ActualSong; // pointer to actual song /* A cached pointer to the song or course this entry refers to. Only one of
* these will be non-NULL. */
Song *m_pSong;
Course *m_pCourse;
float m_fDancePointsRequired; // Ways to unlock/lock songs. float m_fDancePointsRequired; // Ways to unlock/lock songs.
float m_fArcadePointsRequired; float m_fArcadePointsRequired;
@@ -38,16 +38,15 @@ struct SongEntry
int m_iRouletteSeed; int m_iRouletteSeed;
bool isLocked; // cached locked tag bool isLocked; // cached locked tag
bool isCourse; // used for unlock screen bool IsCourse() const { return m_pCourse != NULL; }
SongEntry();
// if song is selectable vai two means // if song is selectable vai two means
bool SelectableWheel(); bool SelectableWheel();
bool SelectableRoulette(); bool SelectableRoulette();
bool updateLocked(); //updates isLocked flag void UpdateLocked(); // updates isLocked
Song *GetSong() const;
void UpdateData();
}; };
class UnlockSystem class UnlockSystem
@@ -60,19 +59,16 @@ public:
float SongPointsUntilNextUnlock(); float SongPointsUntilNextUnlock();
// returns # of points till next unlock - used for ScreenUnlock // returns # of points till next unlock - used for ScreenUnlock
SongEntry *FindSong( CString songname ); // Used on select screens:
// retrieves a corresponding SongEntry, or NULL if none exists
bool SongIsLocked( const Song *song ); bool SongIsLocked( const Song *song );
bool SongIsRoulette( const Song *song ); bool SongIsRoulette( const Song *song );
bool CourseIsLocked( const Course *course ); bool CourseIsLocked( const Course *course );
// used on select screens
bool LoadFromDATFile( CString sPath );
// executed when program is first executed // executed when program is first executed
bool LoadFromDATFile( CString sPath );
vector<SongEntry> m_SongEntries;
// All locked songs are stored here // All locked songs are stored here
vector<SongEntry> m_SongEntries;
// functions that add to values // functions that add to values
float UnlockAddAP(Grade credit); float UnlockAddAP(Grade credit);
@@ -102,8 +98,11 @@ public:
float StagesCleared; float StagesCleared;
CString RouletteSeeds; CString RouletteSeeds;
void UpdateSongs();
SongEntry *FindLockEntry( CString lockname );
private: private:
void SortSongEntriesArray(); // sorts unlocks
SongEntry *FindSong( const Song *pSong ); SongEntry *FindSong( const Song *pSong );
SongEntry *FindCourse( const Course *pCourse ); SongEntry *FindCourse( const Course *pCourse );