Changeset View
Changeset View
Standalone View
Standalone View
source/ps/TemplateLoader.cpp
/* Copyright (C) 2017 Wildfire Games. | /* Copyright (C) 2018 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
Show All 12 Lines | |||||
#include "lib/utf8.h" | #include "lib/utf8.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/Filesystem.h" | #include "ps/Filesystem.h" | ||||
#include "ps/XML/Xeromyces.h" | #include "ps/XML/Xeromyces.h" | ||||
static const wchar_t TEMPLATE_ROOT[] = L"simulation/templates/"; | static const wchar_t TEMPLATE_ROOT[] = L"simulation/templates/"; | ||||
static const wchar_t ACTOR_ROOT[] = L"art/actors/"; | static const wchar_t ACTOR_ROOT[] = L"art/actors/"; | ||||
static CParamNode NULL_NODE(false); | static CParamNode nullptr_NODE(false); | ||||
bool CTemplateLoader::LoadTemplateFile(const std::string& templateName, int depth) | bool CTemplateLoader::LoadTemplateFile(const std::string& templateName, int depth) | ||||
{ | { | ||||
// If this file was already loaded, we don't need to do anything | // If this file was already loaded, we don't need to do anything | ||||
if (m_TemplateFileData.find(templateName) != m_TemplateFileData.end()) | if (m_TemplateFileData.find(templateName) != m_TemplateFileData.end()) | ||||
return true; | return true; | ||||
// Handle infinite loops more gracefully than running out of stack space and crashing | // Handle infinite loops more gracefully than running out of stack space and crashing | ||||
▲ Show 20 Lines • Show All 138 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
const CParamNode& CTemplateLoader::GetTemplateFileData(const std::string& templateName) | const CParamNode& CTemplateLoader::GetTemplateFileData(const std::string& templateName) | ||||
{ | { | ||||
// Load the template if necessary | // Load the template if necessary | ||||
if (!LoadTemplateFile(templateName, 0)) | if (!LoadTemplateFile(templateName, 0)) | ||||
{ | { | ||||
LOGERROR("Failed to load entity template '%s'", templateName.c_str()); | LOGERROR("Failed to load entity template '%s'", templateName.c_str()); | ||||
return NULL_NODE; | return nullptr_NODE; | ||||
} | } | ||||
return m_TemplateFileData[templateName]; | return m_TemplateFileData[templateName]; | ||||
} | } | ||||
void CTemplateLoader::ConstructTemplateActor(const std::string& actorName, CParamNode& out) | void CTemplateLoader::ConstructTemplateActor(const std::string& actorName, CParamNode& out) | ||||
{ | { | ||||
// Copy the actor template | // Copy the actor template | ||||
Show All 17 Lines |
Wildfire Games · Phabricator