Ticket #4076: vfsExtendedTemplates.diff

File vfsExtendedTemplates.diff, 18.2 KB (added by sanderd17, 8 years ago)

New experiment, with altered VFS

  • source/graphics/MapReader.cpp

     
    358358    VfsPath filename_xml = pathname.ChangeExtension(L".xml");
    359359
    360360    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)
    362362        return PSRETURN_File_ReadFailed;
    363363
    364364    // Define all the relevant elements used in the XML file
     
    467467    // must only assign once, so do it here
    468468    node_idx = entity_idx = 0;
    469469
    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)
    471471        throw PSERROR_File_ReadFailed();
    472472
    473473    // define the elements and attributes that are frequently used in the XML file,
  • source/graphics/MaterialManager.cpp

     
    5151        return iter->second;
    5252
    5353    CXeromyces xeroFile;
    54     if (xeroFile.Load(g_VFS, pathname, "material") != PSRETURN_OK)
     54    if (xeroFile.Load(g_VFS, pathname, 0, "material") != PSRETURN_OK)
    5555        return CMaterial();
    5656
    5757    #define EL(x) int el_##x = xeroFile.GetElementID(#x)
  • source/graphics/ObjectBase.cpp

     
    211211    m_UsedFiles.insert(pathname);
    212212
    213213    CXeromyces XeroFile;
    214     if (XeroFile.Load(g_VFS, pathname, "actor") != PSRETURN_OK)
     214    if (XeroFile.Load(g_VFS, pathname, 0, "actor") != PSRETURN_OK)
    215215        return false;
    216216
    217217    // Define all the elements used in the XML file
  • source/graphics/ParticleEmitterType.cpp

     
    361361    m_Texture = g_Renderer.GetTextureManager().GetErrorTexture();
    362362
    363363    CXeromyces XeroFile;
    364     PSRETURN ret = XeroFile.Load(g_VFS, path, "particle");
     364    PSRETURN ret = XeroFile.Load(g_VFS, path, 0, "particle");
    365365    if (ret != PSRETURN_OK)
    366366        return false;
    367367
  • source/graphics/TerrainProperties.cpp

     
    4646CTerrainPropertiesPtr CTerrainProperties::FromXML(const CTerrainPropertiesPtr& parent, const VfsPath& pathname)
    4747{
    4848    CXeromyces XeroFile;
    49     if (XeroFile.Load(g_VFS, pathname, "terrain") != PSRETURN_OK)
     49    if (XeroFile.Load(g_VFS, pathname, 0, "terrain") != PSRETURN_OK)
    5050        return CTerrainPropertiesPtr();
    5151
    5252    XMBElement root = XeroFile.GetRoot();
  • source/graphics/TerrainTextureEntry.cpp

     
    4545    ENSURE(properties);
    4646   
    4747    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)
    4949    {
    5050        LOGERROR("Terrain xml not found (%s)", path.string8());
    5151        return;
  • source/graphics/TextureConverter.cpp

     
    9696CTextureConverter::SettingsFile* CTextureConverter::LoadSettings(const VfsPath& path) const
    9797{
    9898    CXeromyces XeroFile;
    99     if (XeroFile.Load(m_VFS, path, "texture") != PSRETURN_OK)
     99    if (XeroFile.Load(m_VFS, path, 0, "texture") != PSRETURN_OK)
    100100        return NULL;
    101101
    102102    // Define all the elements used in the XML file
  • source/gui/CGUI.cpp

     
    849849    Paths.insert(Filename);
    850850
    851851    CXeromyces XeroFile;
    852     if (XeroFile.Load(g_VFS, Filename, "gui") != PSRETURN_OK)
     852    if (XeroFile.Load(g_VFS, Filename, 0, "gui") != PSRETURN_OK)
    853853        return;
    854854
    855855    XMBElement node = XeroFile.GetRoot();
     
    11651165                Paths.insert(filename);
    11661166
    11671167                CXeromyces XeroIncluded;
    1168                 if (XeroIncluded.Load(g_VFS, filename, "gui") != PSRETURN_OK)
     1168                if (XeroIncluded.Load(g_VFS, filename, 0, "gui") != PSRETURN_OK)
    11691169                {
    11701170                    LOGERROR("GUI: Error reading included XML: '%s'", utf8_from_wstring(filename));
    11711171                    continue;
     
    12021202                    // one might use the same parts of the GUI in different situations
    12031203                    Paths.insert(path);
    12041204                    CXeromyces XeroIncluded;
    1205                     if (XeroIncluded.Load(g_VFS, path, "gui") != PSRETURN_OK)
     1205                    if (XeroIncluded.Load(g_VFS, path, 0, "gui") != PSRETURN_OK)
    12061206                    {
    12071207                        LOGERROR("GUI: Error reading included XML: '%s'", path.string8());
    12081208                        continue;
  • source/gui/GUIManager.cpp

     
    198198    page.inputs.insert(path);
    199199
    200200    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)
    202202        // Fail silently (Xeromyces reported the error)
    203203        return;
    204204
  • source/lib/file/vfs/vfs.cpp

     
    113113            fileInfos->reserve(files.size());
    114114            for(VfsDirectory::VfsFiles::const_iterator it = files.begin(); it != files.end(); ++it)
    115115            {
    116                 const VfsFile& file = it->second;
     116                const VfsFile& file = it->second[0];
    117117                fileInfos->push_back(CFileInfo(file.Name(), file.Size(), file.MTime()));
    118118            }
    119119        }
  • source/lib/file/vfs/vfs_tree.cpp

     
    1 /* Copyright (c) 2013 Wildfire Games
     1/* Copyright (c) 2016 Wildfire Games
    22 *
    33 * Permission is hereby granted, free of charge, to any person obtaining
    44 * a copy of this software and associated documentation files (the
     
    5252
    5353static bool ShouldReplaceWith(const VfsFile& previousFile, const VfsFile& newFile)
    5454{
    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
    6256    {
    6357        const double howMuchNewer = difftime(newFile.MTime(), previousFile.MTime());
    6458        const double threshold = 2.0;   // FAT timestamp resolution [seconds]
     
    7064        // mtime resolution)
    7165    }
    7266
    73     // 3) precedence (efficiency of file provider)
     67    // 2) precedence (efficiency of file provider)
    7468    if(newFile.Loader()->Precedence() < previousFile.Loader()->Precedence())
    7569        return false;
    7670
     
    8074
    8175VfsFile* VfsDirectory::AddFile(const VfsFile& file)
    8276{
    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)
    8679    {
    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        }
    9193    }
    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();
    9897}
    9998
    10099
     
    117116VfsFile* VfsDirectory::GetFile(const VfsPath& name)
    118117{
    119118    VfsFiles::iterator it = m_files.find(name.string());
    120     if(it == m_files.end())
     119    if(it == m_files.end() || it->second.empty())
    121120        return 0;
    122     return &it->second;
     121    return &it->second[0];
    123122}
    124123
    125124
     
    185184    const std::wstring indentation(4*indentLevel, ' ');
    186185    for(VfsDirectory::VfsFiles::const_iterator it = files.begin(); it != files.end(); ++it)
    187186    {
    188         const VfsFile& file = it->second;
     187        const VfsFile& file = it->second[0];
    189188        descriptions += indentation;
    190189        descriptions += FileDescription(file);
    191190        descriptions += L"\n";
  • source/lib/file/vfs/vfs_tree.h

     
    7878class VfsDirectory
    7979{
    8080public:
    81     typedef std::map<VfsPath, VfsFile> VfsFiles;
     81    typedef std::map<VfsPath, std::vector<VfsFile>> VfsFiles;
    8282    typedef std::map<VfsPath, VfsDirectory> VfsSubdirectories;
    8383
    8484    VfsDirectory();
  • source/ps/TemplateLoader.cpp

     
    1 /* Copyright (C) 2015 Wildfire Games.
     1/* Copyright (C) 2016 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    3030static CParamNode NULL_NODE(false);
    3131
    3232
    33 bool CTemplateLoader::LoadTemplateFile(const std::string& templateName, int depth)
     33
     34
     35bool CTemplateLoader::LoadTemplateFile(const std::string& templateName, size_t modPriorityLevel, int depth)
    3436{
    3537    // If this file was already loaded, we don't need to do anything
    3638    if (m_TemplateFileData.find(templateName) != m_TemplateFileData.end())
     
    5557    {
    5658        // Load the base entity template, if it wasn't already loaded
    5759        std::string baseName = templateName.substr(8);
    58         if (!LoadTemplateFile(baseName, depth+1))
     60        if (!LoadTemplateFile(baseName, 0, depth + 1))
    5961        {
    6062            LOGERROR("Failed to load entity template '%s'", baseName.c_str());
    6163            return false;
     
    7072    {
    7173        // Load the base entity template, if it wasn't already loaded
    7274        std::string baseName = templateName.substr(7);
    73         if (!LoadTemplateFile(baseName, depth+1))
     75        if (!LoadTemplateFile(baseName, 0, depth + 1))
    7476        {
    7577            LOGERROR("Failed to load entity template '%s'", baseName.c_str());
    7678            return false;
     
    8587    {
    8688        // Load the base entity template, if it wasn't already loaded
    8789        std::string baseName = templateName.substr(7);
    88         if (!LoadTemplateFile(baseName, depth+1))
     90        if (!LoadTemplateFile(baseName, 0, depth + 1))
    8991        {
    9092            LOGERROR("Failed to load entity template '%s'", baseName.c_str());
    9193            return false;
     
    100102    {
    101103        // Load the base entity template, if it wasn't already loaded
    102104        std::string baseName = templateName.substr(11);
    103         if (!LoadTemplateFile(baseName, depth+1))
     105        if (!LoadTemplateFile(baseName, 0, depth + 1))
    104106        {
    105107            LOGERROR("Failed to load entity template '%s'", baseName.c_str());
    106108            return false;
     
    115117    {
    116118        // Load the base entity template, if it wasn't already loaded
    117119        std::string baseName = templateName.substr(13);
    118         if (!LoadTemplateFile(baseName, depth+1))
     120        if (!LoadTemplateFile(baseName, 0, depth + 1))
    119121        {
    120122            LOGERROR("Failed to load entity template '%s'", baseName.c_str());
    121123            return false;
     
    130132    {
    131133        // Load the base entity template, if it wasn't already loaded
    132134        std::string baseName = templateName.substr(9);
    133         if (!LoadTemplateFile(baseName, depth+1))
     135        if (!LoadTemplateFile(baseName, 0, depth + 1))
    134136        {
    135137            LOGERROR("Failed to load entity template '%s'", baseName.c_str());
    136138            return false;
     
    144146
    145147    VfsPath path = VfsPath(TEMPLATE_ROOT) / wstring_from_utf8(templateName + ".xml");
    146148    CXeromyces xero;
    147     PSRETURN ok = xero.Load(g_VFS, path);
     149    PSRETURN ok = xero.Load(g_VFS, path, modPriorityLevel);
    148150    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
    150152
    151153    int attr_parent = xero.GetAttributeID("parent");
    152154    CStr parentName = xero.GetRoot().GetAttributes().GetNamedItem(attr_parent);
     
    159161            return false;
    160162        }
    161163
    162         // Ensure the parent is loaded
    163         if (!LoadTemplateFile(parentName, depth+1))
     164        if (parentName == "MOD")
    164165        {
    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            }
    167172        }
     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            }
    168181
    169         CParamNode& parentData = m_TemplateFileData[parentName];
     182            CParamNode& parentData = m_TemplateFileData[parentName];
    170183
    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        }
    173187    }
    174188
    175189    // Load the new file into the template data (overriding parent values)
     
    330344const CParamNode& CTemplateLoader::GetTemplateFileData(const std::string& templateName)
    331345{
    332346    // Load the template if necessary
    333     if (!LoadTemplateFile(templateName, 0))
     347    if (!LoadTemplateFile(templateName, 0, 0))
    334348    {
    335349        LOGERROR("Failed to load entity template '%s'", templateName.c_str());
    336350        return NULL_NODE;
     
    343357{
    344358    // Load the base actor template if necessary
    345359    const char* templateName = "special/actor";
    346     if (!LoadTemplateFile(templateName, 0))
     360    if (!LoadTemplateFile(templateName, 0, 0))
    347361    {
    348362        LOGERROR("Failed to load entity template '%s'", templateName);
    349363        return;
  • source/ps/TemplateLoader.h

     
    7373     * and saves into m_TemplateFileData. Also loads any parents that are not yet
    7474     * loaded. Returns false on error.
    7575     * @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
    7678     */
    77     bool LoadTemplateFile(const std::string& templateName, int depth);
     79    bool LoadTemplateFile(const std::string& templateName, size_t modPriorityLevel, int depth);
    7880
    7981    /**
    8082     * Constructs a standard static-decorative-object template for the given actor
  • source/ps/XML/Xeromyces.cpp

     
    107107    return g_ValidatorCache.find(name)->second;
    108108}
    109109
    110 PSRETURN CXeromyces::Load(const PIVFS& vfs, const VfsPath& filename, const std::string& validatorName /* = "" */)
     110PSRETURN CXeromyces::Load(const PIVFS& vfs, const VfsPath& filename, size_t modPriorityLevel, const std::string& validatorName /* = "" */)
    111111{
    112112    ENSURE(g_XeromycesStarted);
    113113
     
    147147    return ConvertFile(vfs, filename, xmbPath, validatorName);
    148148}
    149149
    150 bool CXeromyces::GenerateCachedXMB(const PIVFS& vfs, const VfsPath& sourcePath, VfsPath& archiveCachePath, const std::string& validatorName /* = "" */)
     150bool CXeromyces::GenerateCachedXMB(const PIVFS& vfs, const VfsPath& sourcePath, VfsPath& archiveCachePath, size_t modPriorityLevel, const std::string& validatorName /* = "" */)
    151151{
    152152    CCacheLoader cacheLoader(vfs, L".xmb");
    153153
  • source/ps/XML/Xeromyces.h

     
    4646    /**
    4747     * Load from an XML file (with invisible XMB caching).
    4848     */
    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 = "");
    5050
    5151    /**
    5252     * Load from an in-memory XML string (with no caching).
     
    5858     * Returns the XMB path in @p archiveCachePath.
    5959     * Returns false on error.
    6060     */
    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 = "");
    6262
    6363    /**
    6464     * Call once when initialising the program, to load libxml2.
  • source/simulation2/system/ParamNode.cpp

     
    4545void CParamNode::LoadXML(CParamNode& ret, const VfsPath& path, const std::string& validatorName)
    4646{
    4747    CXeromyces xero;
    48     PSRETURN ok = xero.Load(g_VFS, path, validatorName);
     48    PSRETURN ok = xero.Load(g_VFS, path, 0, validatorName);
    4949    if (ok != PSRETURN_OK)
    5050        return; // (Xeromyces already logged an error)
    5151
  • source/soundmanager/scripting/SoundGroup.cpp

     
    283283bool CSoundGroup::LoadSoundGroup(const VfsPath& pathnameXML)
    284284{
    285285    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)
    287287    {
    288288        HandleError(L"error loading file", pathnameXML, ERR::FAIL);
    289289        return false;