Skip to content

Commit

Permalink
Move map tokenizer and getter to ElunaConfig
Browse files Browse the repository at this point in the history
This is a much more appropriate place for this than the Loader
  • Loading branch information
Foereaper committed Jul 19, 2024
1 parent 4d67920 commit 9c5a3b2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 27 deletions.
26 changes: 26 additions & 0 deletions ElunaConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@ void ElunaConfig::Initialize()
SetConfig(CONFIG_ELUNA_ONLY_ON_MAPS, "Eluna.OnlyOnMaps", "");
SetConfig(CONFIG_ELUNA_REQUIRE_PATH_EXTRA, "Eluna.RequirePaths", "");
SetConfig(CONFIG_ELUNA_REQUIRE_CPATH_EXTRA, "Eluna.RequireCPaths", "");

// tokenize OnlyOnMaps
m_requiredMaps.clear();
std::istringstream maps(GetConfig(CONFIG_ELUNA_ONLY_ON_MAPS));
while (maps.good())
{
std::string mapIdStr;
std::getline(maps, mapIdStr, ',');
if (maps.fail() || maps.bad())
break;
try {
uint32 mapId = std::stoul(mapIdStr);
m_requiredMaps.emplace_back(mapId);
}
catch (std::exception&) {
ELUNA_LOG_ERROR("[Eluna]: Error tokenizing Eluna.OnlyOnMaps, invalid config value '%s'", mapIdStr.c_str());
}
}
}

void ElunaConfig::SetConfig(ElunaConfigBoolValues index, char const* fieldname, bool defvalue)
Expand Down Expand Up @@ -69,3 +87,11 @@ bool ElunaConfig::IsElunaCompatibilityMode()
{
return GetConfig(CONFIG_ELUNA_COMPATIBILITY_MODE);
}

bool ElunaConfig::ShouldMapLoadEluna(uint32 id)
{
if (!m_requiredMaps.size())
return true;

return (std::find(m_requiredMaps.begin(), m_requiredMaps.end(), id) != m_requiredMaps.end());
}
3 changes: 3 additions & 0 deletions ElunaConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,16 @@ class ElunaConfig

bool IsElunaEnabled();
bool IsElunaCompatibilityMode();
bool ShouldMapLoadEluna(uint32 mapId);

private:
bool _configBoolValues[CONFIG_ELUNA_BOOL_COUNT];
std::string _configStringValues[CONFIG_ELUNA_STRING_COUNT];

void SetConfig(ElunaConfigBoolValues index, char const* fieldname, bool defvalue);
void SetConfig(ElunaConfigStringValues index, char const* fieldname, std::string defvalue);

std::list<uint32> m_requiredMaps;
};

#define sElunaConfig ElunaConfig::instance()
Expand Down
25 changes: 0 additions & 25 deletions ElunaLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,23 +157,6 @@ void ElunaLoader::LoadScripts()
if (!m_requirecPath.empty())
m_requirecPath.erase(m_requirecPath.end() - 1);

m_requiredMaps.clear();
std::istringstream maps(sElunaConfig->GetConfig(CONFIG_ELUNA_ONLY_ON_MAPS));
while (maps.good())
{
std::string mapIdStr;
std::getline(maps, mapIdStr, ',');
if (maps.fail() || maps.bad())
break;
try {
uint32 mapId = std::stoul(mapIdStr);
m_requiredMaps.emplace_back(mapId);
}
catch (std::exception&) {
ELUNA_LOG_ERROR("[Eluna]: Error tokenizing Eluna.OnlyOnMaps, invalid config value '%s'", mapIdStr.c_str());
}
}

ELUNA_LOG_INFO("[Eluna]: Loaded and precompiled %u scripts in %u ms", uint32(m_scriptCache.size()), ElunaUtil::GetTimeDiff(oldMSTime));

// set the cache state to ready
Expand Down Expand Up @@ -368,14 +351,6 @@ void ElunaLoader::CombineLists()
m_scripts.clear();
}

bool ElunaLoader::ShouldMapLoadEluna(uint32 id)
{
if (!m_requiredMaps.size())
return true;

return (std::find(m_requiredMaps.begin(), m_requiredMaps.end(), id) != m_requiredMaps.end());
}

void ElunaLoader::ReloadElunaForMap(int mapId)
{
// reload the script cache asynchronously
Expand Down
2 changes: 0 additions & 2 deletions ElunaLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class ElunaLoader
static ElunaLoader* instance();

void LoadScripts();
bool ShouldMapLoadEluna(uint32 mapId);
void ReloadElunaForMap(int mapId);

uint8 GetCacheState() const { return m_cacheState; }
Expand Down Expand Up @@ -80,7 +79,6 @@ class ElunaLoader
std::string m_requirecPath;
std::list<LuaScript> m_scripts;
std::list<LuaScript> m_extensions;
std::list<uint32> m_requiredMaps;
std::thread m_reloadThread;
};

Expand Down

0 comments on commit 9c5a3b2

Please sign in to comment.