simplify singleton registration
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include "Character.h"
|
||||
#include "GameState.h"
|
||||
#include "Foreach.h"
|
||||
#include "LuaManager.h"
|
||||
|
||||
#define CHARACTERS_DIR "/Characters/"
|
||||
|
||||
@@ -10,6 +11,15 @@ CharacterManager* CHARMAN = NULL; // global object accessable from anywhere in t
|
||||
|
||||
CharacterManager::CharacterManager()
|
||||
{
|
||||
// Register with Lua.
|
||||
{
|
||||
Lua *L = LUA->Get();
|
||||
lua_pushstring( L, "CHARMAN" );
|
||||
CHARMAN->PushSelf( L );
|
||||
lua_settable( L, LUA_GLOBALSINDEX );
|
||||
LUA->Release( L );
|
||||
}
|
||||
|
||||
for( unsigned i=0; i<m_pCharacters.size(); i++ )
|
||||
SAFE_DELETE( m_pCharacters[i] );
|
||||
m_pCharacters.clear();
|
||||
@@ -47,6 +57,9 @@ CharacterManager::~CharacterManager()
|
||||
{
|
||||
for( unsigned i=0; i<m_pCharacters.size(); i++ )
|
||||
SAFE_DELETE( m_pCharacters[i] );
|
||||
|
||||
// Unregister with Lua.
|
||||
LUA->UnsetGlobal( "CHARMAN" );
|
||||
}
|
||||
|
||||
void CharacterManager::GetCharacters( vector<Character*> &apCharactersOut )
|
||||
@@ -127,16 +140,6 @@ public:
|
||||
ADD_METHOD( GetCharacter );
|
||||
|
||||
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( CHARMAN )
|
||||
{
|
||||
lua_pushstring(L, "CHARMAN");
|
||||
CHARMAN->PushSelf( L );
|
||||
lua_settable(L, LUA_GLOBALSINDEX);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "RageUtil.h"
|
||||
#include "RageThreads.h"
|
||||
#include "EnumHelper.h"
|
||||
#include "LuaManager.h"
|
||||
|
||||
#include <set>
|
||||
#include <map>
|
||||
@@ -141,10 +142,20 @@ static map<RString,SubscribersSet> g_MessageToSubscribers;
|
||||
|
||||
MessageManager::MessageManager()
|
||||
{
|
||||
// Register with Lua.
|
||||
{
|
||||
Lua *L = LUA->Get();
|
||||
lua_pushstring( L, "MESSAGEMAN" );
|
||||
this->PushSelf( L );
|
||||
lua_settable( L, LUA_GLOBALSINDEX );
|
||||
LUA->Release( L );
|
||||
}
|
||||
}
|
||||
|
||||
MessageManager::~MessageManager()
|
||||
{
|
||||
// Unregister with Lua.
|
||||
LUA->UnsetGlobal( "MESSAGEMAN" );
|
||||
}
|
||||
|
||||
void MessageManager::Subscribe( IMessageSubscriber* pSubscriber, const RString& sMessage )
|
||||
@@ -304,16 +315,6 @@ public:
|
||||
ADD_METHOD( Broadcast );
|
||||
|
||||
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( MESSAGEMAN )
|
||||
{
|
||||
lua_pushstring(L, "MESSAGEMAN");
|
||||
MESSAGEMAN->PushSelf( L );
|
||||
lua_settable(L, LUA_GLOBALSINDEX);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+13
-10
@@ -7,6 +7,7 @@
|
||||
#include "arch/arch_default.h"
|
||||
#include "Foreach.h"
|
||||
#include "Preference.h"
|
||||
#include "LuaManager.h"
|
||||
|
||||
RageInput* INPUTMAN = NULL; // globally accessable input device
|
||||
|
||||
@@ -16,6 +17,15 @@ RageInput::RageInput()
|
||||
{
|
||||
LOG->Trace( "RageInput::RageInput()" );
|
||||
|
||||
// Register with Lua.
|
||||
{
|
||||
Lua *L = LUA->Get();
|
||||
lua_pushstring( L, "INPUTMAN" );
|
||||
INPUTMAN->PushSelf( L );
|
||||
lua_settable( L, LUA_GLOBALSINDEX );
|
||||
LUA->Release( L );
|
||||
}
|
||||
|
||||
m_sDriverList = g_sInputDrivers;
|
||||
if( m_sDriverList.empty() )
|
||||
m_sDriverList = DEFAULT_INPUT_DRIVER_LIST;
|
||||
@@ -28,6 +38,9 @@ RageInput::~RageInput()
|
||||
/* Delete optional devices. */
|
||||
for( unsigned i = 0; i < m_pDevices.size(); ++i )
|
||||
delete m_pDevices[i];
|
||||
|
||||
// Unregister with Lua.
|
||||
LUA->UnsetGlobal( "INPUTMAN" );
|
||||
}
|
||||
|
||||
void RageInput::LoadDrivers()
|
||||
@@ -189,16 +202,6 @@ public:
|
||||
ADD_METHOD( GetDescriptions );
|
||||
|
||||
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( INPUTMAN )
|
||||
{
|
||||
lua_pushstring(L, "INPUTMAN");
|
||||
INPUTMAN->PushSelf( L );
|
||||
lua_settable(L, LUA_GLOBALSINDEX);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -50,11 +50,26 @@ LuaFunction( UnlockRewardTypeToLocalizedString, UnlockRewardTypeToLocalizedStrin
|
||||
|
||||
UnlockManager::UnlockManager()
|
||||
{
|
||||
// Register with Lua.
|
||||
{
|
||||
Lua *L = LUA->Get();
|
||||
lua_pushstring( L, "UNLOCKMAN" );
|
||||
this->PushSelf( L );
|
||||
lua_settable( L, LUA_GLOBALSINDEX );
|
||||
LUA->Release( L );
|
||||
}
|
||||
|
||||
UNLOCKMAN = this;
|
||||
|
||||
Load();
|
||||
}
|
||||
|
||||
UnlockManager::~UnlockManager()
|
||||
{
|
||||
// Unregister with Lua.
|
||||
LUA->UnsetGlobal( "UNLOCKMAN" );
|
||||
}
|
||||
|
||||
void UnlockManager::UnlockSong( const Song *song )
|
||||
{
|
||||
const UnlockEntry *p = FindSong( song );
|
||||
@@ -750,16 +765,6 @@ public:
|
||||
ADD_METHOD( GetStepsUnlockedByEntryID );
|
||||
|
||||
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( UNLOCKMAN )
|
||||
{
|
||||
lua_pushstring(L, "UNLOCKMAN");
|
||||
UNLOCKMAN->PushSelf( L );
|
||||
lua_settable(L, LUA_GLOBALSINDEX);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -93,6 +93,7 @@ class UnlockManager
|
||||
|
||||
public:
|
||||
UnlockManager();
|
||||
~UnlockManager();
|
||||
void Reload();
|
||||
|
||||
// returns # of points till next unlock - used for ScreenUnlock
|
||||
|
||||
Reference in New Issue
Block a user