From c811dec8ed984797804768213051ebfcfab3533c Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 4 Feb 2007 02:01:16 +0000 Subject: [PATCH] move some singleton data out of the header --- stepmania/src/NoteSkinManager.cpp | 33 +++++++++++++++++++++++-------- stepmania/src/NoteSkinManager.h | 11 +---------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/stepmania/src/NoteSkinManager.cpp b/stepmania/src/NoteSkinManager.cpp index 7b776396e6..57ab290506 100644 --- a/stepmania/src/NoteSkinManager.cpp +++ b/stepmania/src/NoteSkinManager.cpp @@ -11,6 +11,7 @@ #include "PrefsManager.h" #include "Foreach.h" #include "ActorUtil.h" +#include NoteSkinManager* NOTESKIN = NULL; // global object accessable from anywhere in the program @@ -20,6 +21,20 @@ const RString NOTESKINS_DIR = "NoteSkins/"; const RString GLOBAL_BASE_NOTESKIN_DIR = NOTESKINS_DIR + "common/default/"; static map g_PathCache; +struct NoteSkinData +{ + RString sName; + IniFile metrics; + + // When looking for an element, search these dirs from head to tail. + vector vsDirSearchOrder; +}; + +namespace +{ + static map g_mapNameToData; +}; + NoteSkinManager::NoteSkinManager() { GAME_BASE_NOTESKIN_NAME.Load( "NoteSkinManager", "GameBaseNoteSkin" ); @@ -39,6 +54,8 @@ NoteSkinManager::~NoteSkinManager() { // Unregister with Lua. LUA->UnsetGlobal( "NOTESKIN" ); + + g_mapNameToData.clear(); } void NoteSkinManager::RefreshNoteSkinData( const Game* pGame ) @@ -56,12 +73,12 @@ void NoteSkinManager::RefreshNoteSkinData( const Game* pGame ) StripCvs( asNoteSkinNames ); - m_mapNameToData.clear(); + g_mapNameToData.clear(); for( unsigned j=0; j::const_iterator iter = m_mapNameToData.begin(); - iter != m_mapNameToData.end(); ++iter ) + for( map::const_iterator iter = g_mapNameToData.begin(); + iter != g_mapNameToData.end(); ++iter ) { AddTo.push_back( iter->second.sName ); } @@ -174,8 +191,8 @@ RString NoteSkinManager::GetMetric( const RString &sButtonName, const RString &s ASSERT( !m_sCurrentNoteSkin.empty() ); RString sNoteSkinName = m_sCurrentNoteSkin; sNoteSkinName.MakeLower(); - map::const_iterator it = m_mapNameToData.find(sNoteSkinName); - ASSERT_M( it != m_mapNameToData.end(), sNoteSkinName ); // this NoteSkin doesn't exist! + map::const_iterator it = g_mapNameToData.find(sNoteSkinName); + ASSERT_M( it != g_mapNameToData.end(), sNoteSkinName ); // this NoteSkin doesn't exist! const NoteSkinData& data = it->second; RString sReturn; @@ -215,8 +232,8 @@ try_again: if( it != g_PathCache.end() ) return it->second; - map::const_iterator iter = m_mapNameToData.find( m_sCurrentNoteSkin ); - ASSERT( iter != m_mapNameToData.end() ); + map::const_iterator iter = g_mapNameToData.find( m_sCurrentNoteSkin ); + ASSERT( iter != g_mapNameToData.end() ); const NoteSkinData &data = iter->second; RString sPath; // fill this in below diff --git a/stepmania/src/NoteSkinManager.h b/stepmania/src/NoteSkinManager.h index 7c65e48497..9e3fce6181 100644 --- a/stepmania/src/NoteSkinManager.h +++ b/stepmania/src/NoteSkinManager.h @@ -8,9 +8,9 @@ #include "PlayerNumber.h" #include "IniFile.h" #include "ThemeMetric.h" -#include class Game; +struct NoteSkinData; class NoteSkinManager { @@ -44,18 +44,9 @@ protected: RString GetPathFromDirAndFile( const RString &sDir, const RString &sFileName ); void GetAllNoteSkinNamesForGame( const Game *pGame, vector &AddTo ); - struct NoteSkinData - { - RString sName; - IniFile metrics; - - // When looking for an element, search these dirs from head to tail. - vector vsDirSearchOrder; - }; void LoadNoteSkinData( const RString &sNoteSkinName, NoteSkinData& data_out ); void LoadNoteSkinDataRecursive( const RString &sNoteSkinName, NoteSkinData& data_out ); RString m_sCurrentNoteSkin; - map m_mapNameToData; const Game* m_pCurGame; };