Ticket #4076: vfsExtendedTemplates.diff
File vfsExtendedTemplates.diff, 18.2 KB (added by , 8 years ago) |
---|
-
source/graphics/MapReader.cpp
358 358 VfsPath filename_xml = pathname.ChangeExtension(L".xml"); 359 359 360 360 CXeromyces xmb_file; 361 if (xmb_file.Load(g_VFS, filename_xml, "scenario") != PSRETURN_OK)361 if (xmb_file.Load(g_VFS, filename_xml, 0, "scenario") != PSRETURN_OK) 362 362 return PSRETURN_File_ReadFailed; 363 363 364 364 // Define all the relevant elements used in the XML file … … 467 467 // must only assign once, so do it here 468 468 node_idx = entity_idx = 0; 469 469 470 if (xmb_file.Load(g_VFS, xml_filename, "scenario") != PSRETURN_OK)470 if (xmb_file.Load(g_VFS, xml_filename, 0, "scenario") != PSRETURN_OK) 471 471 throw PSERROR_File_ReadFailed(); 472 472 473 473 // define the elements and attributes that are frequently used in the XML file, -
source/graphics/MaterialManager.cpp
51 51 return iter->second; 52 52 53 53 CXeromyces xeroFile; 54 if (xeroFile.Load(g_VFS, pathname, "material") != PSRETURN_OK)54 if (xeroFile.Load(g_VFS, pathname, 0, "material") != PSRETURN_OK) 55 55 return CMaterial(); 56 56 57 57 #define EL(x) int el_##x = xeroFile.GetElementID(#x) -
source/graphics/ObjectBase.cpp
211 211 m_UsedFiles.insert(pathname); 212 212 213 213 CXeromyces XeroFile; 214 if (XeroFile.Load(g_VFS, pathname, "actor") != PSRETURN_OK)214 if (XeroFile.Load(g_VFS, pathname, 0, "actor") != PSRETURN_OK) 215 215 return false; 216 216 217 217 // Define all the elements used in the XML file -
source/graphics/ParticleEmitterType.cpp
361 361 m_Texture = g_Renderer.GetTextureManager().GetErrorTexture(); 362 362 363 363 CXeromyces XeroFile; 364 PSRETURN ret = XeroFile.Load(g_VFS, path, "particle");364 PSRETURN ret = XeroFile.Load(g_VFS, path, 0, "particle"); 365 365 if (ret != PSRETURN_OK) 366 366 return false; 367 367 -
source/graphics/TerrainProperties.cpp
46 46 CTerrainPropertiesPtr CTerrainProperties::FromXML(const CTerrainPropertiesPtr& parent, const VfsPath& pathname) 47 47 { 48 48 CXeromyces XeroFile; 49 if (XeroFile.Load(g_VFS, pathname, "terrain") != PSRETURN_OK)49 if (XeroFile.Load(g_VFS, pathname, 0, "terrain") != PSRETURN_OK) 50 50 return CTerrainPropertiesPtr(); 51 51 52 52 XMBElement root = XeroFile.GetRoot(); -
source/graphics/TerrainTextureEntry.cpp
45 45 ENSURE(properties); 46 46 47 47 CXeromyces XeroFile; 48 if (XeroFile.Load(g_VFS, path, "terrain_texture") != PSRETURN_OK)48 if (XeroFile.Load(g_VFS, path, 0, "terrain_texture") != PSRETURN_OK) 49 49 { 50 50 LOGERROR("Terrain xml not found (%s)", path.string8()); 51 51 return; -
source/graphics/TextureConverter.cpp
96 96 CTextureConverter::SettingsFile* CTextureConverter::LoadSettings(const VfsPath& path) const 97 97 { 98 98 CXeromyces XeroFile; 99 if (XeroFile.Load(m_VFS, path, "texture") != PSRETURN_OK)99 if (XeroFile.Load(m_VFS, path, 0, "texture") != PSRETURN_OK) 100 100 return NULL; 101 101 102 102 // Define all the elements used in the XML file -
source/gui/CGUI.cpp
849 849 Paths.insert(Filename); 850 850 851 851 CXeromyces XeroFile; 852 if (XeroFile.Load(g_VFS, Filename, "gui") != PSRETURN_OK)852 if (XeroFile.Load(g_VFS, Filename, 0, "gui") != PSRETURN_OK) 853 853 return; 854 854 855 855 XMBElement node = XeroFile.GetRoot(); … … 1165 1165 Paths.insert(filename); 1166 1166 1167 1167 CXeromyces XeroIncluded; 1168 if (XeroIncluded.Load(g_VFS, filename, "gui") != PSRETURN_OK)1168 if (XeroIncluded.Load(g_VFS, filename, 0, "gui") != PSRETURN_OK) 1169 1169 { 1170 1170 LOGERROR("GUI: Error reading included XML: '%s'", utf8_from_wstring(filename)); 1171 1171 continue; … … 1202 1202 // one might use the same parts of the GUI in different situations 1203 1203 Paths.insert(path); 1204 1204 CXeromyces XeroIncluded; 1205 if (XeroIncluded.Load(g_VFS, path, "gui") != PSRETURN_OK)1205 if (XeroIncluded.Load(g_VFS, path, 0, "gui") != PSRETURN_OK) 1206 1206 { 1207 1207 LOGERROR("GUI: Error reading included XML: '%s'", path.string8()); 1208 1208 continue; -
source/gui/GUIManager.cpp
198 198 page.inputs.insert(path); 199 199 200 200 CXeromyces xero; 201 if (xero.Load(g_VFS, path, "gui_page") != PSRETURN_OK)201 if (xero.Load(g_VFS, path, 0, "gui_page") != PSRETURN_OK) 202 202 // Fail silently (Xeromyces reported the error) 203 203 return; 204 204 -
source/lib/file/vfs/vfs.cpp
113 113 fileInfos->reserve(files.size()); 114 114 for(VfsDirectory::VfsFiles::const_iterator it = files.begin(); it != files.end(); ++it) 115 115 { 116 const VfsFile& file = it->second ;116 const VfsFile& file = it->second[0]; 117 117 fileInfos->push_back(CFileInfo(file.Name(), file.Size(), file.MTime())); 118 118 } 119 119 } -
source/lib/file/vfs/vfs_tree.cpp
1 /* Copyright (c) 201 3Wildfire Games1 /* Copyright (c) 2016 Wildfire Games 2 2 * 3 3 * Permission is hereby granted, free of charge, to any person obtaining 4 4 * a copy of this software and associated documentation files (the … … 52 52 53 53 static bool ShouldReplaceWith(const VfsFile& previousFile, const VfsFile& newFile) 54 54 { 55 // 1) priority (override mods) 56 if(newFile.Priority() < previousFile.Priority()) 57 return false; 58 if(newFile.Priority() > previousFile.Priority()) 59 return true; 60 61 // 2) timestamp 55 // 1) timestamp 62 56 { 63 57 const double howMuchNewer = difftime(newFile.MTime(), previousFile.MTime()); 64 58 const double threshold = 2.0; // FAT timestamp resolution [seconds] … … 70 64 // mtime resolution) 71 65 } 72 66 73 // 3) precedence (efficiency of file provider)67 // 2) precedence (efficiency of file provider) 74 68 if(newFile.Loader()->Precedence() < previousFile.Loader()->Precedence()) 75 69 return false; 76 70 … … 80 74 81 75 VfsFile* VfsDirectory::AddFile(const VfsFile& file) 82 76 { 83 std::pair<VfsPath, VfsFile> value = std::make_pair(file.Name(), file); 84 std::pair<VfsFiles::iterator, bool> ret = m_files.insert(value); 85 if(!ret.second) // already existed 77 std::vector<VfsFile>& fileList = m_files[file.Name()]; 78 for (size_t i = 0; i < fileList.size(); ++i) 86 79 { 87 VfsFile& previousFile = ret.first->second; 88 const VfsFile& newFile = value.second; 89 if(ShouldReplaceWith(previousFile, newFile)) 90 previousFile = newFile; 80 VfsFile previousFile = fileList[i]; 81 if (previousFile.Priority() == file.Priority()) 82 { 83 if (ShouldReplaceWith(previousFile, file)) 84 fileList[i] = file; 85 return &fileList[i]; 86 } 87 else if (previousFile.Priority() <= file.Priority()) 88 { 89 fileList.emplace(fileList.begin() + i, file); 90 stats_vfs_file_add(file.Size()); 91 return &fileList[i]; 92 } 91 93 } 92 else 93 { 94 stats_vfs_file_add(file.Size()); 95 } 96 97 return &(*ret.first).second; 94 fileList.push_back(file); 95 stats_vfs_file_add(file.Size()); 96 return &fileList.back(); 98 97 } 99 98 100 99 … … 117 116 VfsFile* VfsDirectory::GetFile(const VfsPath& name) 118 117 { 119 118 VfsFiles::iterator it = m_files.find(name.string()); 120 if(it == m_files.end() )119 if(it == m_files.end() || it->second.empty()) 121 120 return 0; 122 return &it->second ;121 return &it->second[0]; 123 122 } 124 123 125 124 … … 185 184 const std::wstring indentation(4*indentLevel, ' '); 186 185 for(VfsDirectory::VfsFiles::const_iterator it = files.begin(); it != files.end(); ++it) 187 186 { 188 const VfsFile& file = it->second ;187 const VfsFile& file = it->second[0]; 189 188 descriptions += indentation; 190 189 descriptions += FileDescription(file); 191 190 descriptions += L"\n"; -
source/lib/file/vfs/vfs_tree.h
78 78 class VfsDirectory 79 79 { 80 80 public: 81 typedef std::map<VfsPath, VfsFile> VfsFiles;81 typedef std::map<VfsPath, std::vector<VfsFile>> VfsFiles; 82 82 typedef std::map<VfsPath, VfsDirectory> VfsSubdirectories; 83 83 84 84 VfsDirectory(); -
source/ps/TemplateLoader.cpp
1 /* Copyright (C) 201 5Wildfire Games.1 /* Copyright (C) 2016 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 30 30 static CParamNode NULL_NODE(false); 31 31 32 32 33 bool CTemplateLoader::LoadTemplateFile(const std::string& templateName, int depth) 33 34 35 bool CTemplateLoader::LoadTemplateFile(const std::string& templateName, size_t modPriorityLevel, int depth) 34 36 { 35 37 // If this file was already loaded, we don't need to do anything 36 38 if (m_TemplateFileData.find(templateName) != m_TemplateFileData.end()) … … 55 57 { 56 58 // Load the base entity template, if it wasn't already loaded 57 59 std::string baseName = templateName.substr(8); 58 if (!LoadTemplateFile(baseName, depth+1))60 if (!LoadTemplateFile(baseName, 0, depth + 1)) 59 61 { 60 62 LOGERROR("Failed to load entity template '%s'", baseName.c_str()); 61 63 return false; … … 70 72 { 71 73 // Load the base entity template, if it wasn't already loaded 72 74 std::string baseName = templateName.substr(7); 73 if (!LoadTemplateFile(baseName, depth+1))75 if (!LoadTemplateFile(baseName, 0, depth + 1)) 74 76 { 75 77 LOGERROR("Failed to load entity template '%s'", baseName.c_str()); 76 78 return false; … … 85 87 { 86 88 // Load the base entity template, if it wasn't already loaded 87 89 std::string baseName = templateName.substr(7); 88 if (!LoadTemplateFile(baseName, depth+1))90 if (!LoadTemplateFile(baseName, 0, depth + 1)) 89 91 { 90 92 LOGERROR("Failed to load entity template '%s'", baseName.c_str()); 91 93 return false; … … 100 102 { 101 103 // Load the base entity template, if it wasn't already loaded 102 104 std::string baseName = templateName.substr(11); 103 if (!LoadTemplateFile(baseName, depth+1))105 if (!LoadTemplateFile(baseName, 0, depth + 1)) 104 106 { 105 107 LOGERROR("Failed to load entity template '%s'", baseName.c_str()); 106 108 return false; … … 115 117 { 116 118 // Load the base entity template, if it wasn't already loaded 117 119 std::string baseName = templateName.substr(13); 118 if (!LoadTemplateFile(baseName, depth+1))120 if (!LoadTemplateFile(baseName, 0, depth + 1)) 119 121 { 120 122 LOGERROR("Failed to load entity template '%s'", baseName.c_str()); 121 123 return false; … … 130 132 { 131 133 // Load the base entity template, if it wasn't already loaded 132 134 std::string baseName = templateName.substr(9); 133 if (!LoadTemplateFile(baseName, depth+1))135 if (!LoadTemplateFile(baseName, 0, depth + 1)) 134 136 { 135 137 LOGERROR("Failed to load entity template '%s'", baseName.c_str()); 136 138 return false; … … 144 146 145 147 VfsPath path = VfsPath(TEMPLATE_ROOT) / wstring_from_utf8(templateName + ".xml"); 146 148 CXeromyces xero; 147 PSRETURN ok = xero.Load(g_VFS, path );149 PSRETURN ok = xero.Load(g_VFS, path, modPriorityLevel); 148 150 if (ok != PSRETURN_OK) 149 return false; // (Xeromyces already logged an error with the full filename)151 return false; // Xeromyces already logged an error with the full filename 150 152 151 153 int attr_parent = xero.GetAttributeID("parent"); 152 154 CStr parentName = xero.GetRoot().GetAttributes().GetNamedItem(attr_parent); … … 159 161 return false; 160 162 } 161 163 162 // Ensure the parent is loaded 163 if (!LoadTemplateFile(parentName, depth+1)) 164 if (parentName == "MOD") 164 165 { 165 LOGERROR("Failed to load parent '%s' of entity template '%s'", parentName.c_str(), templateName.c_str()); 166 return false; 166 // Ensure the parent is loaded 167 if (!LoadTemplateFile(templateName, modPriorityLevel + 1, depth)) 168 { 169 LOGERROR("Failed to load parent from lower priority mod of entity template '%s'", templateName.c_str()); 170 return false; 171 } 167 172 } 173 else 174 { 175 // Ensure the parent is loaded 176 if (!LoadTemplateFile(parentName, 0, depth + 1)) 177 { 178 LOGERROR("Failed to load parent '%s' of entity template '%s'", parentName.c_str(), templateName.c_str()); 179 return false; 180 } 168 181 169 CParamNode& parentData = m_TemplateFileData[parentName];182 CParamNode& parentData = m_TemplateFileData[parentName]; 170 183 171 // Initialise this template with its parent 172 m_TemplateFileData[templateName] = parentData; 184 // Initialise this template with its parent 185 m_TemplateFileData[templateName] = parentData; 186 } 173 187 } 174 188 175 189 // Load the new file into the template data (overriding parent values) … … 330 344 const CParamNode& CTemplateLoader::GetTemplateFileData(const std::string& templateName) 331 345 { 332 346 // Load the template if necessary 333 if (!LoadTemplateFile(templateName, 0 ))347 if (!LoadTemplateFile(templateName, 0, 0)) 334 348 { 335 349 LOGERROR("Failed to load entity template '%s'", templateName.c_str()); 336 350 return NULL_NODE; … … 343 357 { 344 358 // Load the base actor template if necessary 345 359 const char* templateName = "special/actor"; 346 if (!LoadTemplateFile(templateName, 0 ))360 if (!LoadTemplateFile(templateName, 0, 0)) 347 361 { 348 362 LOGERROR("Failed to load entity template '%s'", templateName); 349 363 return; -
source/ps/TemplateLoader.h
73 73 * and saves into m_TemplateFileData. Also loads any parents that are not yet 74 74 * loaded. Returns false on error. 75 75 * @param templateName XML filename to load (not a |-separated string) 76 * @param modPriorityLevel mod to load the file from, 0 for the highest priority mod 77 * @param depth counter to prevent infinite loops, initialise to 0 76 78 */ 77 bool LoadTemplateFile(const std::string& templateName, int depth);79 bool LoadTemplateFile(const std::string& templateName, size_t modPriorityLevel, int depth); 78 80 79 81 /** 80 82 * Constructs a standard static-decorative-object template for the given actor -
source/ps/XML/Xeromyces.cpp
107 107 return g_ValidatorCache.find(name)->second; 108 108 } 109 109 110 PSRETURN CXeromyces::Load(const PIVFS& vfs, const VfsPath& filename, const std::string& validatorName /* = "" */)110 PSRETURN CXeromyces::Load(const PIVFS& vfs, const VfsPath& filename, size_t modPriorityLevel, const std::string& validatorName /* = "" */) 111 111 { 112 112 ENSURE(g_XeromycesStarted); 113 113 … … 147 147 return ConvertFile(vfs, filename, xmbPath, validatorName); 148 148 } 149 149 150 bool CXeromyces::GenerateCachedXMB(const PIVFS& vfs, const VfsPath& sourcePath, VfsPath& archiveCachePath, const std::string& validatorName /* = "" */)150 bool CXeromyces::GenerateCachedXMB(const PIVFS& vfs, const VfsPath& sourcePath, VfsPath& archiveCachePath, size_t modPriorityLevel, const std::string& validatorName /* = "" */) 151 151 { 152 152 CCacheLoader cacheLoader(vfs, L".xmb"); 153 153 -
source/ps/XML/Xeromyces.h
46 46 /** 47 47 * Load from an XML file (with invisible XMB caching). 48 48 */ 49 PSRETURN Load(const PIVFS& vfs, const VfsPath& filename, const std::string& validatorName = "");49 PSRETURN Load(const PIVFS& vfs, const VfsPath& filename, size_t modPriorityLevel = 0, const std::string& validatorName = ""); 50 50 51 51 /** 52 52 * Load from an in-memory XML string (with no caching). … … 58 58 * Returns the XMB path in @p archiveCachePath. 59 59 * Returns false on error. 60 60 */ 61 bool GenerateCachedXMB(const PIVFS& vfs, const VfsPath& sourcePath, VfsPath& archiveCachePath, const std::string& validatorName = "");61 bool GenerateCachedXMB(const PIVFS& vfs, const VfsPath& sourcePath, VfsPath& archiveCachePath, size_t modPriorityLevel = 0, const std::string& validatorName = ""); 62 62 63 63 /** 64 64 * Call once when initialising the program, to load libxml2. -
source/simulation2/system/ParamNode.cpp
45 45 void CParamNode::LoadXML(CParamNode& ret, const VfsPath& path, const std::string& validatorName) 46 46 { 47 47 CXeromyces xero; 48 PSRETURN ok = xero.Load(g_VFS, path, validatorName);48 PSRETURN ok = xero.Load(g_VFS, path, 0, validatorName); 49 49 if (ok != PSRETURN_OK) 50 50 return; // (Xeromyces already logged an error) 51 51 -
source/soundmanager/scripting/SoundGroup.cpp
283 283 bool CSoundGroup::LoadSoundGroup(const VfsPath& pathnameXML) 284 284 { 285 285 CXeromyces XeroFile; 286 if (XeroFile.Load(g_VFS, pathnameXML, "sound_group") != PSRETURN_OK)286 if (XeroFile.Load(g_VFS, pathnameXML, 0, "sound_group") != PSRETURN_OK) 287 287 { 288 288 HandleError(L"error loading file", pathnameXML, ERR::FAIL); 289 289 return false;