diff --git a/stepmania/src/SongManager.cpp b/stepmania/src/SongManager.cpp index 5f1f02ba9e..67b828e09b 100644 --- a/stepmania/src/SongManager.cpp +++ b/stepmania/src/SongManager.cpp @@ -29,7 +29,6 @@ #include "Foreach.h" #include "StatsManager.h" #include "Style.h" -#include "ThemeMetric.h" 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_EDIT_SIZE_BYTES 30*1024 // 30KB -static const ThemeMetric NUM_GROUP_COLORS ("SongManager","NumGroupColors"); -#define GROUP_COLOR( i ) THEME->GetMetricC("SongManager",ssprintf("GroupColor%d",i+1)) static const ThemeMetric BEGINNER_COLOR ("SongManager","BeginnerColor"); static const ThemeMetric EASY_COLOR ("SongManager","EasyColor"); static const ThemeMetric MEDIUM_COLOR ("SongManager","MediumColor"); @@ -50,24 +47,13 @@ static const ThemeMetric EDIT_COLOR ("SongManager","EditColor"); static const ThemeMetric EXTRA_COLOR ("SongManager","ExtraColor"); static const ThemeMetric EXTRA_COLOR_METER ("SongManager","ExtraColorMeter"); -vector g_vGroupColors; -RageTimer g_LastMetricUpdate; /* can't use RageTimer globally */ +CString GROUP_COLOR_NAME( size_t i ) { return ssprintf("GroupColor%d",i+1); } -static void UpdateMetrics() -{ - if( !g_LastMetricUpdate.IsZero() && g_LastMetricUpdate.PeekDeltaTime() < 1 ) - return; - - g_LastMetricUpdate.Touch(); - g_vGroupColors.clear(); - for( int i=0; iIsTutorial() ) + continue; + if( UNLOCKMAN->SongIsLocked(pSong) ) + continue; + return pSong; + } + + return NULL; } Course* SongManager::GetRandomCourse() @@ -995,10 +989,22 @@ Course* SongManager::GetRandomCourse() return NULL; 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 ) @@ -1268,8 +1274,10 @@ public: LuaHelpers::CreateTableFromArray( v, 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 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 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) { @@ -1277,6 +1285,8 @@ public: ADD_METHOD( GetAllCourses ) ADD_METHOD( FindSong ) ADD_METHOD( FindCourse ) + ADD_METHOD( GetRandomSong ) + ADD_METHOD( GetRandomCourse ) Luna::Register( L ); // Add global singleton if constructed already. If it's not constructed yet, diff --git a/stepmania/src/SongManager.h b/stepmania/src/SongManager.h index 783509552b..b620b0de38 100644 --- a/stepmania/src/SongManager.h +++ b/stepmania/src/SongManager.h @@ -17,6 +17,7 @@ struct lua_State; #include "PlayerNumber.h" #include "Difficulty.h" #include "Course.h" +#include "ThemeMetric.h" class SongManager { @@ -117,6 +118,10 @@ protected: vector m_pCourses; vector m_pBestCourses[NUM_PROFILE_SLOTS][NUM_COURSE_TYPES]; vector m_pShuffledCourses; // used by GetRandomCourse + + + ThemeMetric NUM_GROUP_COLORS; + ThemeMetric1D GROUP_COLOR; }; static const CString EDIT_SUBDIR = "Edits/";