Browse Source

Add inherited XMLFile resource as dependency. Approximate patched size.

Yao Wei Tjong 姚伟忠 12 years ago
parent
commit
a5246036fb
2 changed files with 12 additions and 3 deletions
  1. 3 2
      Source/Engine/Resource/ResourceCache.cpp
  2. 9 1
      Source/Engine/Resource/XMLFile.cpp

+ 3 - 2
Source/Engine/Resource/ResourceCache.cpp

@@ -755,7 +755,8 @@ void ResourceCache::HandleBeginFrame(StringHash eventType, VariantMap& eventData
                 LOGDEBUG("Reloading changed resource " + fileName);
                 ReloadResource(resource);
             }
-            else
+            // Always perform dependency resource check for resource loaded from XML file as it could be used in inheritance
+            if (!resource || GetExtension(resource->GetName()) == ".xml")
             {
                 // Check if this is a dependency resource, reload dependents
                 HashMap<StringHash, HashSet<StringHash> >::ConstIterator j = dependentResources_.Find(fileNameHash);
@@ -763,7 +764,7 @@ void ResourceCache::HandleBeginFrame(StringHash eventType, VariantMap& eventData
                 {
                     // Reloading a resource may modify the dependency tracking structure. Therefore collect the
                     // resources we need to reload first
-                    Vector<SharedPtr<Resource> > dependents;
+                    Vector<SharedPtr<Resource> > dependents(j->second_.Size());
                     
                     for (HashSet<StringHash>::ConstIterator k = j->second_.Begin(); k != j->second_.End(); ++k)
                     {

+ 9 - 1
Source/Engine/Resource/XMLFile.cpp

@@ -115,10 +115,18 @@ bool XMLFile::Load(Deserializer& source)
         // Patch this XMLFile and leave the original inherited XMLFile as it is
         pugi::xml_document* patchDocument = document_;
         document_ = new pugi::xml_document();
-        document_->reset(*inheritedXMLFile->document_);      // Unfortunately there is no way to adjust the data size correctly
+        document_->reset(*inheritedXMLFile->document_);
         Patch(rootElem);
         delete patchDocument;
+
+        // Store resource dependencies so we know when to reload/repatch when the inherited resource changes
+        cache->StoreResourceDependency(this, inherit);
+
+        // Approximate patched data size
+        dataSize += inheritedXMLFile->GetRoot().GetUInt("dataSize");
     }
+    else
+        rootElem.SetUInt("dataSize", dataSize);
 
     // Note: this probably does not reflect internal data structure size accurately
     SetMemoryUse(dataSize);