Make GameManager a namespace rather than a singleton since it doesn't contain any data.

This commit is contained in:
Steve Checkoway
2008-03-24 12:49:31 +00:00
parent 2e009a4072
commit 551d9bfc23
3 changed files with 49 additions and 80 deletions
+24 -43
View File
@@ -12,8 +12,6 @@
#include "Style.h" #include "Style.h"
#include "Foreach.h" #include "Foreach.h"
GameManager* GAMEMAN = NULL; // global and accessable from anywhere in our program
enum enum
{ {
TRACK_1 = 0, TRACK_1 = 0,
@@ -2445,25 +2443,7 @@ static const Game *g_Games[] =
&g_Game_Lights, &g_Game_Lights,
}; };
GameManager::GameManager() void GameManager::GetStylesForGame( const Game *pGame, vector<const Style*>& aStylesAddTo, bool editor )
{
// Register with Lua.
{
Lua *L = LUA->Get();
lua_pushstring( L, "GAMEMAN" );
this->PushSelf( L );
lua_settable( L, LUA_GLOBALSINDEX );
LUA->Release( L );
}
}
GameManager::~GameManager()
{
// Unregister with Lua.
LUA->UnsetGlobal( "GAMEMAN" );
}
void GameManager::GetStylesForGame( const Game *pGame, vector<const Style*>& aStylesAddTo, bool editor ) const
{ {
for( int s=0; pGame->m_apStyles[s]; ++s ) for( int s=0; pGame->m_apStyles[s]; ++s )
{ {
@@ -2477,7 +2457,7 @@ void GameManager::GetStylesForGame( const Game *pGame, vector<const Style*>& aSt
} }
} }
const Game *GameManager::GetGameForStyle( const Style *pStyle ) const const Game *GameManager::GetGameForStyle( const Style *pStyle )
{ {
for( size_t g=0; g<ARRAYLEN(g_Games); ++g ) for( size_t g=0; g<ARRAYLEN(g_Games); ++g )
{ {
@@ -2491,7 +2471,7 @@ const Game *GameManager::GetGameForStyle( const Style *pStyle ) const
FAIL_M(pStyle->m_szName); FAIL_M(pStyle->m_szName);
} }
const Style* GameManager::GetEditorStyleForStepsType( StepsType st ) const const Style* GameManager::GetEditorStyleForStepsType( StepsType st )
{ {
for( size_t g=0; g<ARRAYLEN(g_Games); ++g ) for( size_t g=0; g<ARRAYLEN(g_Games); ++g )
{ {
@@ -2509,7 +2489,7 @@ const Style* GameManager::GetEditorStyleForStepsType( StepsType st ) const
} }
void GameManager::GetStepsTypesForGame( const Game *pGame, vector<StepsType>& aStepsTypeAddTo ) const void GameManager::GetStepsTypesForGame( const Game *pGame, vector<StepsType>& aStepsTypeAddTo )
{ {
FOREACH_ENUM( StepsType, st ) FOREACH_ENUM( StepsType, st )
{ {
@@ -2527,7 +2507,7 @@ void GameManager::GetStepsTypesForGame( const Game *pGame, vector<StepsType>& aS
} }
} }
void GameManager::GetDemonstrationStylesForGame( const Game *pGame, vector<const Style*> &vpStylesOut ) const void GameManager::GetDemonstrationStylesForGame( const Game *pGame, vector<const Style*> &vpStylesOut )
{ {
vpStylesOut.clear(); vpStylesOut.clear();
@@ -2541,7 +2521,7 @@ void GameManager::GetDemonstrationStylesForGame( const Game *pGame, vector<const
ASSERT( vpStylesOut.size()>0 ); // this Game is missing a Style that can be used with the demonstration ASSERT( vpStylesOut.size()>0 ); // this Game is missing a Style that can be used with the demonstration
} }
const Style* GameManager::GetHowToPlayStyleForGame( const Game *pGame ) const const Style* GameManager::GetHowToPlayStyleForGame( const Game *pGame )
{ {
for( int s=0; pGame->m_apStyles[s]; ++s ) for( int s=0; pGame->m_apStyles[s]; ++s )
{ {
@@ -2554,7 +2534,7 @@ const Style* GameManager::GetHowToPlayStyleForGame( const Game *pGame ) const
return NULL; return NULL;
} }
void GameManager::GetCompatibleStyles( const Game *pGame, int iNumPlayers, vector<const Style*> &vpStylesOut ) const void GameManager::GetCompatibleStyles( const Game *pGame, int iNumPlayers, vector<const Style*> &vpStylesOut )
{ {
FOREACH_ENUM( StyleType, styleType ) FOREACH_ENUM( StyleType, styleType )
{ {
@@ -2588,7 +2568,7 @@ void GameManager::GetCompatibleStyles( const Game *pGame, int iNumPlayers, vecto
} }
} }
const Style *GameManager::GetFirstCompatibleStyle( const Game *pGame, int iNumPlayers, StepsType st ) const const Style *GameManager::GetFirstCompatibleStyle( const Game *pGame, int iNumPlayers, StepsType st )
{ {
vector<const Style*> vpStyles; vector<const Style*> vpStyles;
GetCompatibleStyles( pGame, iNumPlayers, vpStyles ); GetCompatibleStyles( pGame, iNumPlayers, vpStyles );
@@ -2601,7 +2581,7 @@ const Style *GameManager::GetFirstCompatibleStyle( const Game *pGame, int iNumPl
} }
void GameManager::GetEnabledGames( vector<const Game*>& aGamesOut ) const void GameManager::GetEnabledGames( vector<const Game*>& aGamesOut )
{ {
for( size_t g=0; g<ARRAYLEN(g_Games); ++g ) for( size_t g=0; g<ARRAYLEN(g_Games); ++g )
{ {
@@ -2611,7 +2591,7 @@ void GameManager::GetEnabledGames( vector<const Game*>& aGamesOut ) const
} }
} }
const Game* GameManager::GetDefaultGame() const const Game* GameManager::GetDefaultGame()
{ {
const Game *pDefault = NULL; const Game *pDefault = NULL;
if( pDefault == NULL ) if( pDefault == NULL )
@@ -2629,7 +2609,7 @@ const Game* GameManager::GetDefaultGame() const
return pDefault; return pDefault;
} }
int GameManager::GetIndexFromGame( const Game* pGame ) const int GameManager::GetIndexFromGame( const Game* pGame )
{ {
for( size_t g=0; g<ARRAYLEN(g_Games); ++g ) for( size_t g=0; g<ARRAYLEN(g_Games); ++g )
{ {
@@ -2640,14 +2620,14 @@ int GameManager::GetIndexFromGame( const Game* pGame ) const
return 0; return 0;
} }
const Game* GameManager::GetGameFromIndex( int index ) const const Game* GameManager::GetGameFromIndex( int index )
{ {
ASSERT( index >= 0 ); ASSERT( index >= 0 );
ASSERT( index < (int) ARRAYLEN(g_Games) ); ASSERT( index < (int) ARRAYLEN(g_Games) );
return g_Games[index]; return g_Games[index];
} }
bool GameManager::IsGameEnabled( const Game *pGame ) const bool GameManager::IsGameEnabled( const Game *pGame )
{ {
return NOTESKIN->DoNoteSkinsExistForGame( pGame ); return NOTESKIN->DoNoteSkinsExistForGame( pGame );
} }
@@ -2715,30 +2695,31 @@ const Style* GameManager::GameAndStringToStyle( const Game *game, RString sStyle
// lua start // lua start
#include "LuaBinding.h" #include "LuaBinding.h"
class LunaGameManager: public Luna<GameManager> namespace
{ {
public:
static int StepsTypeToLocalizedString( T* p, lua_State *L ) { lua_pushstring(L, p->GetStepsTypeInfo(Enum::Check<StepsType>(L, 1)).GetLocalizedString() ); return 1; } int StepsTypeToLocalizedString( lua_State *L ) { lua_pushstring(L, GameManager::GetStepsTypeInfo(Enum::Check<StepsType>(L, 1)).GetLocalizedString() ); return 1; }
static int GetFirstStepsTypeForGame( T* p, lua_State *L ) int GetFirstStepsTypeForGame( lua_State *L )
{ {
Game *pGame = Luna<Game>::check( L, 1 ); Game *pGame = Luna<Game>::check( L, 1 );
vector<StepsType> vstAddTo; vector<StepsType> vstAddTo;
p->GetStepsTypesForGame( pGame, vstAddTo ); GameManager::GetStepsTypesForGame( pGame, vstAddTo );
ASSERT( !vstAddTo.empty() ); ASSERT( !vstAddTo.empty() );
StepsType st = vstAddTo[0]; StepsType st = vstAddTo[0];
lua_pushnumber(L, st); lua_pushnumber(L, st);
return 1; return 1;
} }
LunaGameManager() const luaL_Reg GameManagerTable[] =
{ {
ADD_METHOD( StepsTypeToLocalizedString ); LIST_METHOD( StepsTypeToLocalizedString ),
ADD_METHOD( GetFirstStepsTypeForGame ); LIST_METHOD( GetFirstStepsTypeForGame ),
} { NULL, NULL }
};
}; };
LUA_REGISTER_CLASS( GameManager ) LUA_REGISTER_NAMESPACE( GameManager )
// lua end // lua end
+19 -28
View File
@@ -19,38 +19,29 @@ struct StepsTypeInfo
RString GetLocalizedString() const; RString GetLocalizedString() const;
}; };
class GameManager namespace GameManager
{ {
public: void GetStylesForGame( const Game* pGame, vector<const Style*>& aStylesAddTo, bool editor=false );
GameManager(); const Game *GetGameForStyle( const Style *pStyle );
~GameManager(); void GetStepsTypesForGame( const Game* pGame, vector<StepsType>& aStepsTypeAddTo );
const Style *GetEditorStyleForStepsType( StepsType st );
void GetDemonstrationStylesForGame( const Game *pGame, vector<const Style*> &vpStylesOut );
const Style *GetHowToPlayStyleForGame( const Game* pGame );
void GetCompatibleStyles( const Game *pGame, int iNumPlayers, vector<const Style*> &vpStylesOut );
const Style *GetFirstCompatibleStyle( const Game *pGame, int iNumPlayers, StepsType st );
void GetStylesForGame( const Game* pGame, vector<const Style*>& aStylesAddTo, bool editor=false ) const; void GetEnabledGames( vector<const Game*>& aGamesOut );
const Game *GetGameForStyle( const Style *pStyle ) const; const Game* GetDefaultGame();
void GetStepsTypesForGame( const Game* pGame, vector<StepsType>& aStepsTypeAddTo ) const; bool IsGameEnabled( const Game* pGame );
const Style *GetEditorStyleForStepsType( StepsType st ) const; int GetIndexFromGame( const Game* pGame );
void GetDemonstrationStylesForGame( const Game *pGame, vector<const Style*> &vpStylesOut ) const; const Game* GetGameFromIndex( int index );
const Style *GetHowToPlayStyleForGame( const Game* pGame ) const;
void GetCompatibleStyles( const Game *pGame, int iNumPlayers, vector<const Style*> &vpStylesOut ) const;
const Style *GetFirstCompatibleStyle( const Game *pGame, int iNumPlayers, StepsType st ) const;
void GetEnabledGames( vector<const Game*>& aGamesOut ) const; const StepsTypeInfo &GetStepsTypeInfo( StepsType st );
const Game* GetDefaultGame() const; StepsType StringToStepsType( RString sStepsType );
bool IsGameEnabled( const Game* pGame ) const; const Game* StringToGameType( RString sGameType );
int GetIndexFromGame( const Game* pGame ) const;
const Game* GetGameFromIndex( int index ) const;
static const StepsTypeInfo &GetStepsTypeInfo( StepsType st );
static StepsType StringToStepsType( RString sStepsType );
static const Game* StringToGameType( RString sGameType );
const Style* GameAndStringToStyle( const Game* pGame, RString sStyle ); const Style* GameAndStringToStyle( const Game* pGame, RString sStyle );
static RString StyleToLocalizedString( const Style* s ); RString StyleToLocalizedString( const Style* s );
}
// Lua
void PushSelf( lua_State *L );
};
extern GameManager* GAMEMAN; // global and accessable from anywhere in our program
#endif #endif
+6 -9
View File
@@ -268,7 +268,6 @@ void ShutdownGame()
SAFE_DELETE( SOUND ); /* uses GAMESTATE, PREFSMAN */ SAFE_DELETE( SOUND ); /* uses GAMESTATE, PREFSMAN */
SAFE_DELETE( PREFSMAN ); SAFE_DELETE( PREFSMAN );
SAFE_DELETE( GAMESTATE ); SAFE_DELETE( GAMESTATE );
SAFE_DELETE( GAMEMAN );
SAFE_DELETE( NOTESKIN ); SAFE_DELETE( NOTESKIN );
SAFE_DELETE( THEME ); SAFE_DELETE( THEME );
SAFE_DELETE( ANNOUNCER ); SAFE_DELETE( ANNOUNCER );
@@ -752,21 +751,20 @@ RageDisplay *CreateDisplay()
static void SwitchToLastPlayedGame() static void SwitchToLastPlayedGame()
{ {
ASSERT( GAMEMAN ); const Game *pGame = GameManager::StringToGameType( PREFSMAN->GetCurrentGame() );
const Game *pGame = GAMEMAN->StringToGameType( PREFSMAN->GetCurrentGame() );
/* If the active game type isn't actually available, revert to the default. */ /* If the active game type isn't actually available, revert to the default. */
if( pGame == NULL ) if( pGame == NULL )
pGame = GAMEMAN->GetDefaultGame(); pGame = GameManager::GetDefaultGame();
if( !GAMEMAN->IsGameEnabled( pGame ) && pGame != GAMEMAN->GetDefaultGame() ) if( !GameManager::IsGameEnabled( pGame ) && pGame != GameManager::GetDefaultGame() )
{ {
pGame = GAMEMAN->GetDefaultGame(); pGame = GameManager::GetDefaultGame();
LOG->Warn( "Default NoteSkin for \"%s\" missing, reverting to \"%s\"", LOG->Warn( "Default NoteSkin for \"%s\" missing, reverting to \"%s\"",
pGame->m_szName, GAMEMAN->GetDefaultGame()->m_szName ); pGame->m_szName, GameManager::GetDefaultGame()->m_szName );
} }
ASSERT( GAMEMAN->IsGameEnabled(pGame) ); ASSERT( GameManager::IsGameEnabled(pGame) );
StepMania::ChangeCurrentGame( pGame ); StepMania::ChangeCurrentGame( pGame );
} }
@@ -992,7 +990,6 @@ int main(int argc, char* argv[])
CheckSettings(); CheckSettings();
GAMEMAN = new GameManager;
THEME = new ThemeManager; THEME = new ThemeManager;
ANNOUNCER = new AnnouncerManager; ANNOUNCER = new AnnouncerManager;
NOTESKIN = new NoteSkinManager; NOTESKIN = new NoteSkinManager;