simplify singleton registration

This commit is contained in:
Glenn Maynard
2006-09-21 04:42:45 +00:00
parent 2b7e2849fd
commit 578c6d5726
8 changed files with 95 additions and 70 deletions
+19 -10
View File
@@ -2645,6 +2645,25 @@ static Style g_Styles[] =
#define NUM_STYLES ARRAYLEN(g_Styles)
GameManager::GameManager()
{
// 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( unsigned s=0; s<NUM_STYLES; s++ )
@@ -2908,16 +2927,6 @@ public:
ADD_METHOD( GetFirstStepsTypeForGame );
Luna<T>::Register( L );
// Add global singleton if constructed already. If it's not constructed yet,
// then we'll register it later when we reinit Lua just before
// initializing the display.
if( GAMEMAN )
{
lua_pushstring(L, "GAMEMAN");
GAMEMAN->PushSelf( L );
lua_settable(L, LUA_GLOBALSINDEX);
}
}
};
+3
View File
@@ -14,6 +14,9 @@ struct lua_State;
class GameManager
{
public:
GameManager();
~GameManager();
void GetStylesForGame( const Game* pGame, vector<const Style*>& aStylesAddTo, bool editor=false ) const;
void GetStepsTypesForGame( const Game* pGame, vector<StepsType>& aStepsTypeAddTo ) const;
const Style* GetEditorStyleForStepsType( StepsType st ) const;
+13 -10
View File
@@ -15,6 +15,7 @@
#include "Steps.h"
#include "LightsManager.h"
#include "SongUtil.h"
#include "LuaManager.h"
GameSoundManager *SOUND = NULL;
@@ -397,10 +398,22 @@ GameSoundManager::GameSoundManager()
g_Shutdown = false;
MusicThread.SetName( "Music thread" );
MusicThread.Create( MusicThread_start, this );
// Register with Lua.
{
Lua *L = LUA->Get();
lua_pushstring( L, "SOUND" );
this->PushSelf( L );
lua_settable( L, LUA_GLOBALSINDEX );
LUA->Release( L );
}
}
GameSoundManager::~GameSoundManager()
{
// Unregister with Lua.
LUA->UnsetGlobal( "SOUND" );
/* Signal the mixing thread to quit. */
LOG->Trace("Shutting down music start thread ...");
g_Mutex->Lock();
@@ -744,16 +757,6 @@ public:
ADD_METHOD( PlayOnce );
Luna<T>::Register( L );
// Add global singleton if constructed already. If it's not constructed yet,
// then we'll register it later when we reinit Lua just before
// initializing the display.
if( SOUND )
{
lua_pushstring(L, "SOUND");
SOUND->PushSelf( L );
lua_settable(L, LUA_GLOBALSINDEX);
}
}
};
+12 -10
View File
@@ -118,10 +118,22 @@ GameState::GameState() :
/* Don't reset yet; let the first screen do it, so we can
* use PREFSMAN and THEME. */
// Reset();
// Register with Lua.
{
Lua *L = LUA->Get();
lua_pushstring( L, "GAMESTATE" );
this->PushSelf( L );
lua_settable( L, LUA_GLOBALSINDEX );
LUA->Release( L );
}
}
GameState::~GameState()
{
// Unregister with Lua.
LUA->UnsetGlobal( "GAMESTATE" );
FOREACH_PlayerNumber( p )
SAFE_DELETE( m_pPlayerState[p] );
FOREACH_MultiPlayer( p )
@@ -2116,16 +2128,6 @@ public:
ADD_METHOD( GetCurrentStyle );
Luna<T>::Register( L );
// Add global singleton if constructed already. If it's not constructed yet,
// then we'll register it later when we reinit Lua just before
// initializing the display.
if( GAMESTATE )
{
lua_pushstring(L, "GAMESTATE");
GAMESTATE->PushSelf( L );
lua_settable(L, LUA_GLOBALSINDEX);
}
}
};
+13 -10
View File
@@ -12,6 +12,7 @@
#include "RageUtil_WorkerThread.h"
#include "arch/arch.h"
#include "arch/MemoryCard/MemoryCardDriver_Null.h"
#include "LuaManager.h"
MemoryCardManager* MEMCARDMAN = NULL; // global and accessable from anywhere in our program
@@ -259,6 +260,15 @@ MemoryCardManager::MemoryCardManager()
{
ASSERT( g_pWorker == NULL );
// Register with Lua.
{
Lua *L = LUA->Get();
lua_pushstring( L, "MEMCARDMAN" );
this->PushSelf( L );
lua_settable( L, LUA_GLOBALSINDEX );
LUA->Release( L );
}
g_pWorker = new ThreadedMemoryCardWorker;
m_bCardsLocked = false;
@@ -286,6 +296,9 @@ MemoryCardManager::MemoryCardManager()
MemoryCardManager::~MemoryCardManager()
{
// Unregister with Lua.
LUA->UnsetGlobal( "MESSAGEMAN" );
ASSERT( g_pWorker != NULL );
SAFE_DELETE(g_pWorker);
@@ -715,16 +728,6 @@ public:
ADD_METHOD( IsAnyPlayerUsingMemoryCard );
Luna<T>::Register( L );
// Add global singleton if constructed already. If it's not constructed yet,
// then we'll register it later when we reinit Lua just before
// initializing the display.
if( MEMCARDMAN )
{
lua_pushstring(L, "MEMCARDMAN");
MEMCARDMAN->PushSelf( L );
lua_settable(L, LUA_GLOBALSINDEX);
}
}
};
+11 -10
View File
@@ -25,10 +25,21 @@ NoteSkinManager::NoteSkinManager()
{
GAME_BASE_NOTESKIN_NAME.Load( "NoteSkinManager", "GameBaseNoteSkin" );
m_pCurGame = NULL;
// Register with Lua.
{
Lua *L = LUA->Get();
lua_pushstring( L, "NOTESKIN" );
this->PushSelf( L );
lua_settable( L, LUA_GLOBALSINDEX );
LUA->Release( L );
}
}
NoteSkinManager::~NoteSkinManager()
{
// Unregister with Lua.
LUA->UnsetGlobal( "NOTESKIN" );
}
void NoteSkinManager::RefreshNoteSkinData( const Game* pGame )
@@ -322,16 +333,6 @@ public:
ADD_METHOD( GetGameBaseNoteSkinName );
Luna<T>::Register( L );
// Add global singleton if constructed already. If it's not constructed yet,
// then we'll register it later when we reinit Lua just before
// initializing the display.
if( NOTESKIN )
{
lua_pushstring(L, "NOTESKIN");
NOTESKIN->PushSelf( L );
lua_settable(L, LUA_GLOBALSINDEX);
}
}
};
+12 -10
View File
@@ -9,6 +9,7 @@
#include "Preference.h"
#include "RageLog.h"
#include "SpecialFiles.h"
#include "LuaManager.h"
//DEFAULTS_INI_PATH = "Data/Defaults.ini"; // these can be overridden
//PREFERENCES_INI_PATH // overlay on Defaults.ini, contains the user's choices
@@ -333,6 +334,15 @@ PrefsManager::PrefsManager() :
{
Init();
ReadPrefsFromDisk();
// Register with Lua.
{
Lua *L = LUA->Get();
lua_pushstring( L, "PREFSMAN" );
this->PushSelf( L );
lua_settable( L, LUA_GLOBALSINDEX );
LUA->Release( L );
}
}
#undef TRUE_IF_DEBUG
@@ -345,6 +355,8 @@ void PrefsManager::Init()
PrefsManager::~PrefsManager()
{
// Unregister with Lua.
LUA->UnsetGlobal( "PREFSMAN" );
}
void PrefsManager::SetCurrentGame( const RString &sGame )
@@ -598,16 +610,6 @@ public:
ADD_METHOD( SetPreferenceToDefault );
Luna<T>::Register( L );
// Add global singleton if constructed already. If it's not constructed yet,
// then we'll register it later when we reinit Lua just before
// initializing the display.
if( PREFSMAN )
{
lua_pushstring(L, "PREFSMAN");
PREFSMAN->PushSelf( L );
lua_settable(L, LUA_GLOBALSINDEX);
}
}
};
+12 -10
View File
@@ -63,6 +63,15 @@ RString COURSE_GROUP_COLOR_NAME( size_t i ) { return ssprintf( "CourseGroupColor
SongManager::SongManager()
{
// Register with Lua.
{
Lua *L = LUA->Get();
lua_pushstring( L, "SONGMAN" );
this->PushSelf( L );
lua_settable( L, LUA_GLOBALSINDEX );
LUA->Release( L );
}
NUM_SONG_GROUP_COLORS .Load( "SongManager", "NumSongGroupColors" );
SONG_GROUP_COLOR .Load( "SongManager", SONG_GROUP_COLOR_NAME, NUM_SONG_GROUP_COLORS );
NUM_COURSE_GROUP_COLORS .Load( "SongManager", "NumCourseGroupColors" );
@@ -71,6 +80,9 @@ SongManager::SongManager()
SongManager::~SongManager()
{
// Unregister with Lua.
LUA->UnsetGlobal( "SONGMAN" );
// Courses depend on Songs and Songs don't depend on Courses.
// So, delete the Courses first.
FreeCourses();
@@ -1886,16 +1898,6 @@ public:
ADD_METHOD( GetExtraStageInfo );
Luna<T>::Register( L );
// Add global singleton if constructed already. If it's not constructed yet,
// then we'll register it later when we reinit Lua just before
// initializing the display.
if( SONGMAN )
{
lua_pushstring(L, "SONGMAN");
SONGMAN->PushSelf( L );
lua_settable(L, LUA_GLOBALSINDEX);
}
}
};