cleanup: Use ThemeMetric

Don't choose locked Songs/Courses in GetRandom*
This commit is contained in:
Chris Danford
2005-05-22 15:05:15 +00:00
parent cac3d56730
commit b995407f42
2 changed files with 43 additions and 28 deletions
+38 -28
View File
@@ -29,7 +29,6 @@
#include "Foreach.h" #include "Foreach.h"
#include "StatsManager.h" #include "StatsManager.h"
#include "Style.h" #include "Style.h"
#include "ThemeMetric.h"
SongManager* SONGMAN = NULL; // global and accessable from anywhere in our program SongManager* SONGMAN = NULL; // global and accessable from anywhere in our program
@@ -39,8 +38,6 @@ SongManager* SONGMAN = NULL; // global and accessable from anywhere in our progr
#define MAX_EDITS_PER_PROFILE 200 #define MAX_EDITS_PER_PROFILE 200
#define MAX_EDIT_SIZE_BYTES 30*1024 // 30KB #define MAX_EDIT_SIZE_BYTES 30*1024 // 30KB
static const ThemeMetric<int> NUM_GROUP_COLORS ("SongManager","NumGroupColors");
#define GROUP_COLOR( i ) THEME->GetMetricC("SongManager",ssprintf("GroupColor%d",i+1))
static const ThemeMetric<RageColor> BEGINNER_COLOR ("SongManager","BeginnerColor"); static const ThemeMetric<RageColor> BEGINNER_COLOR ("SongManager","BeginnerColor");
static const ThemeMetric<RageColor> EASY_COLOR ("SongManager","EasyColor"); static const ThemeMetric<RageColor> EASY_COLOR ("SongManager","EasyColor");
static const ThemeMetric<RageColor> MEDIUM_COLOR ("SongManager","MediumColor"); static const ThemeMetric<RageColor> MEDIUM_COLOR ("SongManager","MediumColor");
@@ -50,24 +47,13 @@ static const ThemeMetric<RageColor> EDIT_COLOR ("SongManager","EditColor");
static const ThemeMetric<RageColor> EXTRA_COLOR ("SongManager","ExtraColor"); static const ThemeMetric<RageColor> EXTRA_COLOR ("SongManager","ExtraColor");
static const ThemeMetric<int> EXTRA_COLOR_METER ("SongManager","ExtraColorMeter"); static const ThemeMetric<int> EXTRA_COLOR_METER ("SongManager","ExtraColorMeter");
vector<RageColor> g_vGroupColors; CString GROUP_COLOR_NAME( size_t i ) { return ssprintf("GroupColor%d",i+1); }
RageTimer g_LastMetricUpdate; /* can't use RageTimer globally */
static void UpdateMetrics()
{
if( !g_LastMetricUpdate.IsZero() && g_LastMetricUpdate.PeekDeltaTime() < 1 )
return;
g_LastMetricUpdate.Touch();
g_vGroupColors.clear();
for( int i=0; i<NUM_GROUP_COLORS; i++ )
g_vGroupColors.push_back( GROUP_COLOR(i) );
}
SongManager::SongManager() SongManager::SongManager()
{ {
g_LastMetricUpdate.SetZero(); NUM_GROUP_COLORS.Load("SongManager","NumGroupColors");
UpdateMetrics(); GROUP_COLOR .Load("SongManager",GROUP_COLOR_NAME,NUM_GROUP_COLORS);
} }
SongManager::~SongManager() SongManager::~SongManager()
@@ -345,8 +331,6 @@ bool SongManager::DoesGroupExist( CString sGroupName )
RageColor SongManager::GetGroupColor( const CString &sGroupName ) RageColor SongManager::GetGroupColor( const CString &sGroupName )
{ {
UpdateMetrics();
// search for the group index // search for the group index
unsigned i; unsigned i;
for( i=0; i<m_sGroupNames.size(); i++ ) for( i=0; i<m_sGroupNames.size(); i++ )
@@ -356,7 +340,7 @@ RageColor SongManager::GetGroupColor( const CString &sGroupName )
} }
ASSERT_M( i != m_sGroupNames.size(), sGroupName ); // this is not a valid group ASSERT_M( i != m_sGroupNames.size(), sGroupName ); // this is not a valid group
return g_vGroupColors[i%g_vGroupColors.size()]; return GROUP_COLOR.GetValue( i%NUM_GROUP_COLORS );
} }
RageColor SongManager::GetSongColor( const Song* pSong ) RageColor SongManager::GetSongColor( const Song* pSong )
@@ -983,10 +967,20 @@ Song* SongManager::GetRandomSong()
return NULL; return NULL;
static int i = 0; static int i = 0;
i++;
wrap( i, m_pShuffledSongs.size() );
return m_pShuffledSongs[ i ]; for( int iThrowAway=0; iThrowAway<100; iThrowAway++ )
{
i++;
wrap( i, m_pShuffledSongs.size() );
Song *pSong = m_pShuffledSongs[ i ];
if( pSong->IsTutorial() )
continue;
if( UNLOCKMAN->SongIsLocked(pSong) )
continue;
return pSong;
}
return NULL;
} }
Course* SongManager::GetRandomCourse() Course* SongManager::GetRandomCourse()
@@ -995,10 +989,22 @@ Course* SongManager::GetRandomCourse()
return NULL; return NULL;
static int i = 0; static int i = 0;
i++;
wrap( i, m_pShuffledCourses.size() );
return m_pShuffledCourses[ i ]; for( int iThrowAway=0; iThrowAway<100; iThrowAway++ )
{
i++;
wrap( i, m_pShuffledCourses.size() );
Course *pCourse = m_pShuffledCourses[ i ];
if( pCourse->m_bIsAutogen && !PREFSMAN->m_bAutogenGroupCourses )
continue;
if( pCourse->GetCourseType() == COURSE_TYPE_ENDLESS )
continue;
if( UNLOCKMAN->CourseIsLocked(pCourse) )
continue;
return pCourse;
}
return NULL;
} }
Song* SongManager::GetSongFromDir( CString sDir ) Song* SongManager::GetSongFromDir( CString sDir )
@@ -1268,8 +1274,10 @@ public:
LuaHelpers::CreateTableFromArray<Course*>( v, L ); LuaHelpers::CreateTableFromArray<Course*>( v, L );
return 1; return 1;
} }
static int FindSong( T* p, lua_State *L ) { Song *pS = p->FindSong(SArg(1)); if(pS) pS->PushSelf(L); else lua_pushnil(L); return 1; } static int FindSong( T* p, lua_State *L ) { Song *pS = p->FindSong(SArg(1)); if(pS) pS->PushSelf(L); else lua_pushnil(L); return 1; }
static int FindCourse( T* p, lua_State *L ) { Course *pC = p->FindCourse(SArg(1)); if(pC) pC->PushSelf(L); else lua_pushnil(L); return 1; } static int FindCourse( T* p, lua_State *L ) { Course *pC = p->FindCourse(SArg(1)); if(pC) pC->PushSelf(L); else lua_pushnil(L); return 1; }
static int GetRandomSong( T* p, lua_State *L ) { Song *pS = p->GetRandomSong(); if(pS) pS->PushSelf(L); else lua_pushnil(L); return 1; }
static int GetRandomCourse( T* p, lua_State *L ){ Course *pC = p->GetRandomCourse(); if(pC) pC->PushSelf(L); else lua_pushnil(L); return 1; }
static void Register(lua_State *L) static void Register(lua_State *L)
{ {
@@ -1277,6 +1285,8 @@ public:
ADD_METHOD( GetAllCourses ) ADD_METHOD( GetAllCourses )
ADD_METHOD( FindSong ) ADD_METHOD( FindSong )
ADD_METHOD( FindCourse ) ADD_METHOD( FindCourse )
ADD_METHOD( GetRandomSong )
ADD_METHOD( GetRandomCourse )
Luna<T>::Register( L ); Luna<T>::Register( L );
// Add global singleton if constructed already. If it's not constructed yet, // Add global singleton if constructed already. If it's not constructed yet,
+5
View File
@@ -17,6 +17,7 @@ struct lua_State;
#include "PlayerNumber.h" #include "PlayerNumber.h"
#include "Difficulty.h" #include "Difficulty.h"
#include "Course.h" #include "Course.h"
#include "ThemeMetric.h"
class SongManager class SongManager
{ {
@@ -117,6 +118,10 @@ protected:
vector<Course*> m_pCourses; vector<Course*> m_pCourses;
vector<Course*> m_pBestCourses[NUM_PROFILE_SLOTS][NUM_COURSE_TYPES]; vector<Course*> m_pBestCourses[NUM_PROFILE_SLOTS][NUM_COURSE_TYPES];
vector<Course*> m_pShuffledCourses; // used by GetRandomCourse vector<Course*> m_pShuffledCourses; // used by GetRandomCourse
ThemeMetric<int> NUM_GROUP_COLORS;
ThemeMetric1D<RageColor> GROUP_COLOR;
}; };
static const CString EDIT_SUBDIR = "Edits/"; static const CString EDIT_SUBDIR = "Edits/";