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:
Scags 2020-10-02 18:25:27 -05:00 committed by GitHub
parent ef36604666
commit 6fd9d1ce11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 1 deletions

View File

@ -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);

View File

@ -123,6 +123,7 @@ private:
StringHashMap<AddressConf> m_Addresses;
const char *m_pEngine;
const char *m_pBaseEngine;
time_t m_ModTime;
};
class GameConfigManager :