core/logic/GameConfigs.cpp
changeset 4038 92fba8db1d33
parent 4007 d6f1e42f0263
child 4058 c3ebd769e128
     1.1 --- a/core/logic/GameConfigs.cpp	Thu Aug 22 21:45:42 2013 -0400
     1.2 +++ b/core/logic/GameConfigs.cpp	Fri Aug 23 00:18:11 2013 -0700
     1.3 @@ -121,7 +121,6 @@
     1.4  	strncopy(m_File, file, sizeof(m_File));
     1.5  	m_pAddresses = new KTrie<AddressConf>();
     1.6  	m_pStrings = new BaseStringTable(512);
     1.7 -	m_RefCount = 0;
     1.8  
     1.9  	m_CustomLevel = 0;
    1.10  	m_CustomHandler = NULL;
    1.11 @@ -141,8 +140,7 @@
    1.12  
    1.13  CGameConfig::~CGameConfig()
    1.14  {
    1.15 -	delete m_pAddresses;
    1.16 -	delete m_pStrings;
    1.17 +	g_GameConfigs.RemoveCachedConfig(this);
    1.18  }
    1.19  
    1.20  SMCResult CGameConfig::ReadSMC_NewSection(const SMCStates *states, const char *name)
    1.21 @@ -1009,17 +1007,6 @@
    1.22  	return true;
    1.23  }
    1.24  
    1.25 -void CGameConfig::IncRefCount()
    1.26 -{
    1.27 -	m_RefCount++;
    1.28 -}
    1.29 -
    1.30 -unsigned int CGameConfig::DecRefCount()
    1.31 -{
    1.32 -	m_RefCount--;
    1.33 -	return m_RefCount;
    1.34 -}
    1.35 -
    1.36  GameConfigManager::GameConfigManager()
    1.37  {
    1.38  }
    1.39 @@ -1073,7 +1060,7 @@
    1.40  	if ((ppConfig = m_Lookup.retrieve(file)) != NULL)
    1.41  	{
    1.42  		pConfig = *ppConfig;
    1.43 -		pConfig->IncRefCount();
    1.44 +		pConfig->AddRef();
    1.45  		*_pConfig = pConfig;
    1.46  		return true;
    1.47  	}
    1.48 @@ -1090,22 +1077,14 @@
    1.49  	m_cfgs.push_back(pConfig);
    1.50  	m_Lookup.insert(file, pConfig);
    1.51  
    1.52 -	pConfig->IncRefCount();
    1.53 -
    1.54  	*_pConfig = pConfig;
    1.55 -
    1.56  	return retval;
    1.57  }
    1.58  
    1.59  void GameConfigManager::CloseGameConfigFile(IGameConfig *cfg)
    1.60  {
    1.61  	CGameConfig *pConfig = (CGameConfig *)cfg;
    1.62 -
    1.63 -	if (pConfig->DecRefCount() == 0)
    1.64 -	{
    1.65 -		m_Lookup.remove(pConfig->m_File);
    1.66 -		delete pConfig;
    1.67 -	}
    1.68 +	pConfig->Release();
    1.69  }
    1.70  
    1.71  extern Handle_t g_GameConfigsType;
    1.72 @@ -1155,3 +1134,8 @@
    1.73  void GameConfigManager::ReleaseLock()
    1.74  {
    1.75  }
    1.76 +
    1.77 +void GameConfigManager::RemoveCachedConfig(CGameConfig *config)
    1.78 +{
    1.79 +	m_Lookup.remove(config->m_File);
    1.80 +}