gamedata: automate reparsing on load (#1348)
* Add sm_reload_gamedata * Remove redundant cast * Automate gamedata reparsing * Update GameConfigs.cpp Co-authored-by: Kyle Sanderson <kyle.leet@gmail.com>
This commit is contained in:
parent
ef36604666
commit
6fd9d1ce11
@ -153,6 +153,23 @@ static inline bool IsPlatformCompatible(const char *platform, bool *hadPrimaryMa
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline time_t GetFileModTime(const char *path)
|
||||
{
|
||||
char filepath[PLATFORM_MAX_PATH];
|
||||
g_pSM->BuildPath(Path_SM, filepath, sizeof(filepath), "gamedata/%s.txt", path);
|
||||
#ifdef PLATFORM_WINDOWS
|
||||
struct _stat64 s;
|
||||
if (_stat64(filepath, &s) != 0)
|
||||
#elif defined PLATFORM_POSIX
|
||||
struct stat s;
|
||||
if (stat(filepath, &s) != 0)
|
||||
#endif
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return s.st_mtime;
|
||||
}
|
||||
|
||||
CGameConfig::CGameConfig(const char *file, const char *engine)
|
||||
{
|
||||
strncopy(m_File, file, sizeof(m_File));
|
||||
@ -160,6 +177,8 @@ CGameConfig::CGameConfig(const char *file, const char *engine)
|
||||
m_CustomLevel = 0;
|
||||
m_CustomHandler = NULL;
|
||||
|
||||
m_ModTime = GetFileModTime(file);
|
||||
|
||||
if (!engine)
|
||||
m_pEngine = bridge->GetSourceEngineName();
|
||||
else
|
||||
@ -1132,9 +1151,17 @@ bool GameConfigManager::LoadGameConfigFile(const char *file, IGameConfig **_pCon
|
||||
|
||||
if (m_Lookup.retrieve(file, &pConfig))
|
||||
{
|
||||
bool ret = true;
|
||||
time_t modtime = GetFileModTime(file);
|
||||
if (pConfig->m_ModTime != modtime)
|
||||
{
|
||||
pConfig->m_ModTime = modtime;
|
||||
ret = pConfig->Reparse(error, maxlength);
|
||||
}
|
||||
|
||||
pConfig->AddRef();
|
||||
*_pConfig = pConfig;
|
||||
return true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
pConfig = new CGameConfig(file);
|
||||
|
@ -123,6 +123,7 @@ private:
|
||||
StringHashMap<AddressConf> m_Addresses;
|
||||
const char *m_pEngine;
|
||||
const char *m_pBaseEngine;
|
||||
time_t m_ModTime;
|
||||
};
|
||||
|
||||
class GameConfigManager :
|
||||
|
Loading…
Reference in New Issue
Block a user