Browse Source

Added log prints for loading & saving the scene.

Lasse Öörni 14 years ago
parent
commit
fbf5bd4076

+ 7 - 7
Engine/Network/Connection.cpp

@@ -709,6 +709,13 @@ String Connection::ToString() const
     return GetAddress() + ":" + String(GetPort());
 }
 
+void Connection::HandleAsyncLoadFinished(StringHash eventType, VariantMap& eventData)
+{
+    VectorBuffer msg;
+    msg.WriteUInt(scene_->GetChecksum());
+    SendMessage(MSG_SCENELOADED, true, true, msg);
+}
+
 void Connection::ProcessNode(Node* node)
 {
     if (!node)
@@ -900,10 +907,3 @@ void Connection::ProcessExistingNode(Node* node)
         }
     }
 }
-
-void Connection::HandleAsyncLoadFinished(StringHash eventType, VariantMap& eventData)
-{
-    VectorBuffer msg;
-    msg.WriteUInt(scene_->GetChecksum());
-    SendMessage(MSG_SCENELOADED, true, true, msg);
-}

+ 2 - 2
Engine/Network/Connection.h

@@ -136,14 +136,14 @@ public:
     String ToString() const;
     
 private:
+    /// Handle scene loaded event
+    void HandleAsyncLoadFinished(StringHash eventType, VariantMap& eventData);
     /// Process a node for sending a network update. Recurses to process depended on node(s) first
     void ProcessNode(Node* node);
     /// Process a node that the client had not yet received
     void ProcessNewNode(Node* node);
     /// Process a node that the client has already received
     void ProcessExistingNode(Node* node);
-    /// Handle scene loaded event
-    void HandleAsyncLoadFinished(StringHash eventType, VariantMap& eventData);
     
     /// kNet message connection
     kNet::SharedPtr<kNet::MessageConnection> connection_;

+ 7 - 7
Engine/Network/Network.cpp

@@ -421,6 +421,13 @@ bool Network::IsServerRunning() const
     return network_->GetServer();
 }
 
+void Network::HandleBeginFrame(StringHash eventType, VariantMap& eventData)
+{
+    using namespace BeginFrame;
+    
+    Update(eventData[P_TIMESTEP].GetFloat());
+}
+
 void Network::OnServerConnected()
 {
     serverConnection_->SetConnectPending(false);
@@ -451,10 +458,3 @@ void Network::OnServerDisconnected()
     
     serverConnection_.Reset();
 }
-
-void Network::HandleBeginFrame(StringHash eventType, VariantMap& eventData)
-{
-    using namespace BeginFrame;
-    
-    Update(eventData[P_TIMESTEP].GetFloat());
-}

+ 2 - 2
Engine/Network/Network.h

@@ -92,12 +92,12 @@ public:
     bool IsServerRunning() const;
     
 private:
+    /// Handle begin frame event
+    void HandleBeginFrame(StringHash eventType, VariantMap& eventData);
     /// Handle server connection
     void OnServerConnected();
     /// Handle server disconnection
     void OnServerDisconnected();
-    /// Handle begin frame event
-    void HandleBeginFrame(StringHash eventType, VariantMap& eventData);
     
     /// kNet Network instance
     kNet::Network* network_;

+ 56 - 38
Engine/Scene/Scene.cpp

@@ -93,6 +93,8 @@ bool Scene::Load(Deserializer& source)
         return false;
     }
     
+    LOGINFO("Loading scene from " + source.GetName());
+    
     // Load the whole scene, then perform post-load if successfully loaded
     if (Node::Load(source))
     {
@@ -112,6 +114,10 @@ bool Scene::Save(Serializer& dest)
         return false;
     }
     
+    Deserializer* ptr = dynamic_cast<Deserializer*>(&dest);
+    if (ptr)
+        LOGINFO("Saving scene to " + ptr->GetName());
+    
     return Node::Save(dest);
 }
 
@@ -130,44 +136,6 @@ bool Scene::LoadXML(const XMLElement& source)
         return false;
 }
 
-void Scene::Update(float timeStep)
-{
-    if (asyncLoading_)
-    {
-        UpdateAsyncLoading();
-        return;
-    }
-    
-    PROFILE(UpdateScene);
-    
-    using namespace SceneUpdate;
-    
-    VariantMap eventData;
-    eventData[P_SCENE] = (void*)this;
-    eventData[P_TIMESTEP] = timeStep;
-    
-    // Update variable timestep logic
-    SendEvent(E_SCENEUPDATE, eventData);
-    
-    // Update scene subsystems. If a physics world is present, it will be updated, triggering fixed timestep logic updates
-    SendEvent(E_SCENESUBSYSTEMUPDATE, eventData);
-    
-    // Post-update variable timestep logic
-    SendEvent(E_SCENEPOSTUPDATE, eventData);
-    
-    // Update smoothing if enabled (network client scenes)
-    if (IsSmoothed())
-    {
-        PROFILE(UpdateSmoothing);
-        
-        float constant = 1.0f - Clamp(powf(2.0f, -timeStep * smoothingConstant_), 0.0f, 1.0f);
-        float squaredSnapThreshold = snapThreshold_ * snapThreshold_;
-        
-        for (Map<unsigned, Node*>::ConstIterator i = allNodes_.Begin(); i != allNodes_.End() && i->first_ < FIRST_LOCAL_ID; ++i)
-            i->second_->UpdateSmoothing(constant, squaredSnapThreshold);
-    }
-}
-
 bool Scene::LoadXML(Deserializer& source)
 {
     StopAsyncLoading();
@@ -176,6 +144,8 @@ bool Scene::LoadXML(Deserializer& source)
     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()))
     {
@@ -193,6 +163,10 @@ bool Scene::SaveXML(Serializer& dest)
     if (!SaveXML(rootElem))
         return false;
     
+    Deserializer* ptr = dynamic_cast<Deserializer*>(&dest);
+    if (ptr)
+        LOGINFO("Saving scene to " + ptr->GetName());
+    
     return xml->Save(dest);
 }
 
@@ -213,6 +187,8 @@ bool Scene::LoadAsync(File* file)
         return false;
     }
     
+    LOGINFO("Loading scene from " + file->GetName());
+    
     // Clear the previous scene and load the root level components first
     Clear();
     if (!Node::Load(*file, false))
@@ -243,6 +219,8 @@ bool Scene::LoadAsyncXML(File* file)
     if (!xmlFile->Load(*file))
         return false;
     
+    LOGINFO("Loading scene from " + file->GetName());
+    
     // Clear the previous scene and load the root level components first
     Clear();
     XMLElement rootElement = xmlFile->GetRoot();
@@ -284,6 +262,46 @@ void Scene::Clear()
     checksum_ = 0;
 }
 
+
+
+void Scene::Update(float timeStep)
+{
+    if (asyncLoading_)
+    {
+        UpdateAsyncLoading();
+        return;
+    }
+    
+    PROFILE(UpdateScene);
+    
+    using namespace SceneUpdate;
+    
+    VariantMap eventData;
+    eventData[P_SCENE] = (void*)this;
+    eventData[P_TIMESTEP] = timeStep;
+    
+    // Update variable timestep logic
+    SendEvent(E_SCENEUPDATE, eventData);
+    
+    // Update scene subsystems. If a physics world is present, it will be updated, triggering fixed timestep logic updates
+    SendEvent(E_SCENESUBSYSTEMUPDATE, eventData);
+    
+    // Post-update variable timestep logic
+    SendEvent(E_SCENEPOSTUPDATE, eventData);
+    
+    // Update smoothing if enabled (network client scenes)
+    if (IsSmoothed())
+    {
+        PROFILE(UpdateSmoothing);
+        
+        float constant = 1.0f - Clamp(powf(2.0f, -timeStep * smoothingConstant_), 0.0f, 1.0f);
+        float squaredSnapThreshold = snapThreshold_ * snapThreshold_;
+        
+        for (Map<unsigned, Node*>::ConstIterator i = allNodes_.Begin(); i != allNodes_.End() && i->first_ < FIRST_LOCAL_ID; ++i)
+            i->second_->UpdateSmoothing(constant, squaredSnapThreshold);
+    }
+}
+
 void Scene::SetActive(bool enable)
 {
     active_ = enable;

+ 2 - 2
Engine/Scene/Scene.h

@@ -75,8 +75,6 @@ public:
     /// Load from XML data. Return true if successful
     virtual bool LoadXML(const XMLElement& source);
     
-    /// Update scene
-    void Update(float timeStep);
     /// Load from an XML file. Return true if successful
     bool LoadXML(Deserializer& source);
     /// Save to an XML file. Return true if successful
@@ -89,6 +87,8 @@ public:
     void StopAsyncLoading();
     /// Clear scene completely of nodes and components
     void Clear();
+    /// Update scene. Called by HandleUpdate
+    void Update(float timeStep);
     /// Set active flag. Only active scenes will be updated automatically
     void SetActive(bool enable);
     /// Set motion smoothing constant