Browse Source

Modified Profiler to output milliseconds also for total accumulated data.
Added profiling blocks to scene loading & object instantiation.
Optimized Serializable XML loading to not contain n^2 complexity if attributes are found in order.

Lasse Öörni 14 years ago
parent
commit
4c581e39f3

+ 6 - 3
Engine/Core/Profiler.cpp

@@ -91,7 +91,10 @@ String Profiler::GetData(bool showUnused, bool showAccumulated, bool showTotal)
     if (!showTotal)
         output += String("Block                          Count   Average   Total\n \n");
     else
-        output += String("Block                             Frame average (msec)      Accumulated total (sec)\n \n");
+    {
+        output += String("Block                                       Frame average                    Accumulated total\n\n");
+        output += String("                                    Count     Average       Total      Count     Average       Total\n\n");
+    }
     
     GetData(root_, output, 0, showUnused, showAccumulated, showTotal);
     
@@ -156,9 +159,9 @@ void Profiler::GetData(ProfilerBlock* block, String& output, unsigned indent, bo
                     avgFrameTotalTime = 0.0f;
                 }
                 
-                sprintf(line, "%s %5u %8.3f %8.3f %10u %8.3f %8.3f\n",
+                sprintf(line, "%s %10u %11.3f %11.3f %10u %11.3f %11.3f\n",
                     indentedName, avgFrameCount, avgFrameTime, avgFrameTotalTime,
-                    totalCount, avgTotalTime / 1000.0f, totalTime / 1000.0);
+                    totalCount, avgTotalTime, totalTime);
             }
             output += String(line);
             

+ 0 - 2
Engine/Graphics/Direct3D9/D3D9Graphics.cpp

@@ -1100,8 +1100,6 @@ void Graphics::SetShaderParameter(StringHash param, const Matrix3x4& matrix)
 
 void Graphics::RegisterShaderParameter(StringHash param, const ShaderParameter& definition)
 {
-    PROFILE(RegisterShaderParameter);
-    
     HashMap<StringHash, ShaderParameter>::Iterator i = shaderParameters_.Find(param);
     
     if (i == shaderParameters_.End())

+ 22 - 19
Engine/Scene/Scene.cpp

@@ -93,6 +93,8 @@ void Scene::RegisterObject(Context* context)
 
 bool Scene::Load(Deserializer& source)
 {
+    PROFILE(LoadScene);
+    
     StopAsyncLoading();
     
     // Check ID
@@ -116,6 +118,8 @@ bool Scene::Load(Deserializer& source)
 
 bool Scene::Save(Serializer& dest)
 {
+    PROFILE(SaveScene);
+    
     // Write ID first
     if (!dest.WriteFileID("USCN"))
     {
@@ -132,6 +136,8 @@ bool Scene::Save(Serializer& dest)
 
 bool Scene::LoadXML(const XMLElement& source)
 {
+    PROFILE(LoadSceneXML);
+    
     StopAsyncLoading();
     
     // Load the whole scene, then perform post-load if successfully loaded
@@ -147,26 +153,19 @@ bool Scene::LoadXML(const XMLElement& source)
 
 bool Scene::LoadXML(Deserializer& source)
 {
-    StopAsyncLoading();
-    
     SharedPtr<XMLFile> xml(new XMLFile(context_));
     if (!xml->Load(source))
         return false;
     
     LOGINFO("Loading scene from " + source.GetName());
     
-    // Load the whole scene, then perform post-load if successfully loaded
-    if (Node::LoadXML(xml->GetRoot()))
-    {
-        FinishLoading(&source);
-        return true;
-    }
-    else
-        return false;
+    return LoadXML(xml->GetRoot());
 }
 
 bool Scene::SaveXML(Serializer& dest)
 {
+    PROFILE(SaveSceneXML);
+    
     SharedPtr<XMLFile> xml(new XMLFile(context_));
     XMLElement rootElem = xml->CreateRoot("scene");
     if (!SaveXML(rootElem))
@@ -276,6 +275,8 @@ void Scene::StopAsyncLoading()
 
 Node* Scene::Instantiate(Deserializer& source, const Vector3& position, const Quaternion& rotation, CreateMode mode)
 {
+    PROFILE(Instantiate);
+    
     SceneResolver resolver;
     unsigned nodeID = source.ReadInt();
     // Rewrite IDs when instantiating
@@ -295,17 +296,10 @@ Node* Scene::Instantiate(Deserializer& source, const Vector3& position, const Qu
     }
 }
 
-Node* Scene::InstantiateXML(Deserializer& source, const Vector3& position, const Quaternion& rotation, CreateMode mode)
-{
-    SharedPtr<XMLFile> xml(new XMLFile(context_));
-    if (!xml->Load(source))
-        return false;
-    
-    return InstantiateXML(xml->GetRoot(), position, rotation, mode);
-}
-
 Node* Scene::InstantiateXML(const XMLElement& source, const Vector3& position, const Quaternion& rotation, CreateMode mode)
 {
+    PROFILE(InstantiateXML);
+    
     SceneResolver resolver;
     unsigned nodeID = source.GetInt("id");
     // Rewrite IDs when instantiating
@@ -325,6 +319,15 @@ Node* Scene::InstantiateXML(const XMLElement& source, const Vector3& position, c
     }
 }
 
+Node* Scene::InstantiateXML(Deserializer& source, const Vector3& position, const Quaternion& rotation, CreateMode mode)
+{
+    SharedPtr<XMLFile> xml(new XMLFile(context_));
+    if (!xml->Load(source))
+        return false;
+    
+    return InstantiateXML(xml->GetRoot(), position, rotation, mode);
+}
+
 void Scene::Clear()
 {
     StopAsyncLoading();

+ 2 - 2
Engine/Scene/Scene.h

@@ -87,9 +87,9 @@ public:
     /// Instantiate scene content from binary data. Return root node if successful.
     Node* Instantiate(Deserializer& source, const Vector3& position, const Quaternion& rotation, CreateMode mode = REPLICATED);
     /// Instantiate scene content from XML data. Return root node if successful.
-    Node* InstantiateXML(Deserializer& source, const Vector3& position, const Quaternion& rotation, CreateMode mode = REPLICATED);
-    /// Instantiate scene content from XML data. Return root node if successful.
     Node* InstantiateXML(const XMLElement& source, const Vector3& position, const Quaternion& rotation, CreateMode mode = REPLICATED);
+    /// Instantiate scene content from XML data. Return root node if successful.
+    Node* InstantiateXML(Deserializer& source, const Vector3& position, const Quaternion& rotation, CreateMode mode = REPLICATED);
     /// Clear scene completely of nodes and components.
     void Clear();
     /// %Set active flag. Only active scenes will be updated automatically.

+ 21 - 13
Engine/Scene/Serializable.cpp

@@ -262,17 +262,20 @@ bool Serializable::LoadXML(const XMLElement& source)
     
     loading_ = true;
     
-    for (unsigned i = 0; i < attributes->Size(); ++i)
+    XMLElement attrElem = source.GetChild("attribute");
+    unsigned startIndex = 0;
+    
+    while (attrElem)
     {
-        const AttributeInfo& attr = attributes->At(i);
-        if (!(attr.mode_ & AM_FILE))
-            continue;
+        String name = attrElem.GetString("name");
         
-        XMLElement attrElem = source.GetChild("attribute");
-        bool found = false;
-        while (attrElem)
+        unsigned i = startIndex;
+        unsigned attempts = attributes->Size();
+        
+        while (attempts)
         {
-            if (attrElem.GetString("name") == attr.name_)
+            const AttributeInfo& attr = attributes->At(i);
+            if ((attr.mode_ & AM_FILE) && attr.name_ == name)
             {
                 // If enums specified, do enum lookup and int assignment. Otherwise assign the variant directly
                 if (attr.enumNames_)
@@ -299,15 +302,20 @@ bool Serializable::LoadXML(const XMLElement& source)
                 else
                     OnSetAttribute(attr, attrElem.GetVariantValue(attr.type_));
                 
-                found = true;
+                startIndex = (i + 1) % attributes->Size();
                 break;
             }
-            
-            attrElem = attrElem.GetNext("attribute");
+            else
+            {
+                i = (i + 1) % attributes->Size();
+                --attempts;
+            }
         }
         
-        if (!found)
-            LOGWARNING("Attribute " + String(attr.name_) + " not found in XML data");
+        if (!attempts)
+            LOGWARNING("Unknown attribute " + name + " in XML data");
+        
+        attrElem = attrElem.GetNext("attribute");
     }
     
     loading_ = false;