1
1
forked from 0ad/0ad

Disable XML validation when loading templates for AI, to save startup time

This was SVN commit r8959.
This commit is contained in:
Ykkrosh 2011-02-20 20:45:39 +00:00
parent 6ba12dd2ff
commit b24396740c
3 changed files with 27 additions and 1 deletions

View File

@ -540,7 +540,7 @@ private:
for (size_t i = 0; i < templateNames.size(); ++i)
{
const CParamNode* node = cmpTemplateManager->GetTemplate(templateNames[i]);
const CParamNode* node = cmpTemplateManager->GetTemplateWithoutValidation(templateNames[i]);
if (node)
templates.push_back(std::make_pair(templateNames[i], node));
}

View File

@ -125,6 +125,8 @@ public:
virtual const CParamNode* GetTemplate(std::string templateName);
virtual const CParamNode* GetTemplateWithoutValidation(std::string templateName);
virtual const CParamNode* LoadLatestTemplate(entity_id_t ent);
virtual std::string GetCurrentTemplateName(entity_id_t ent);
@ -219,6 +221,22 @@ const CParamNode* CCmpTemplateManager::GetTemplate(std::string templateName)
return &templateRoot;
}
const CParamNode* CCmpTemplateManager::GetTemplateWithoutValidation(std::string templateName)
{
// Load the template if necessary
if (!LoadTemplateFile(templateName, 0))
{
LOGERROR(L"Failed to load entity template '%hs'", templateName.c_str());
return NULL;
}
const CParamNode& templateRoot = m_TemplateFileData[templateName].GetChild("Entity");
if (!templateRoot.IsOk())
return NULL;
return &templateRoot;
}
const CParamNode* CCmpTemplateManager::LoadLatestTemplate(entity_id_t ent)
{
std::map<entity_id_t, std::string>::const_iterator it = m_LatestTemplates.find(ent);

View File

@ -66,6 +66,14 @@ public:
*/
virtual const CParamNode* GetTemplate(std::string templateName) = 0;
/**
* Like GetTemplate, except without doing the XML validation (so it's faster but
* may return invalid templates).
*
* @return NULL on error
*/
virtual const CParamNode* GetTemplateWithoutValidation(std::string templateName) = 0;
/**
* Returns the template most recently specified for the entity 'ent'.
* Used during deserialization.