Browse Source

Create bone scene nodes as local.
Added Scene::StopAsyncLoading().

Lasse Öörni 14 years ago
parent
commit
e2a3f60c16
4 changed files with 36 additions and 18 deletions
  1. 1 0
      Engine/Engine/SceneAPI.cpp
  2. 2 1
      Engine/Graphics/AnimatedModel.cpp
  3. 25 11
      Engine/Scene/Scene.cpp
  4. 8 6
      Engine/Scene/Scene.h

+ 1 - 0
Engine/Engine/SceneAPI.cpp

@@ -86,6 +86,7 @@ static void RegisterScene(asIScriptEngine* engine)
     engine->RegisterObjectMethod("Scene", "bool SaveXML(File@+)", asFUNCTION(SceneSaveXML), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod("Scene", "bool LoadAsync(File@+)", asMETHOD(Scene, LoadAsync), asCALL_THISCALL);
     engine->RegisterObjectMethod("Scene", "bool LoadAsyncXML(File@+)", asMETHOD(Scene, LoadAsyncXML), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Scene", "void StopAsyncLoading()", asMETHOD(Scene, StopAsyncLoading), asCALL_THISCALL);
     engine->RegisterObjectMethod("Scene", "Component@+ GetComponentByID(uint)", asMETHOD(Scene, GetComponentByID), asCALL_THISCALL);
     engine->RegisterObjectMethod("Scene", "Node@+ GetNodeByID(uint)", asMETHOD(Scene, GetNodeByID), asCALL_THISCALL);
     engine->RegisterObjectMethod("Scene", "void Update(float)", asMETHOD(Scene, Update), asCALL_THISCALL);

+ 2 - 1
Engine/Graphics/AnimatedModel.cpp

@@ -661,7 +661,8 @@ void AnimatedModel::SetSkeleton(const Skeleton& skeleton, bool createBones)
             std::vector<Bone>& bones = skeleton_.GetModifiableBones();
             for (std::vector<Bone>::iterator i = bones.begin(); i != bones.end(); ++i)
             {
-                Node* boneNode = node_->CreateChild(i->name_);
+                // Create bones as local, as they are never to be directly synchronized over the network
+                Node* boneNode = node_->CreateChild(i->name_, true);
                 boneNode->AddListener(this);
                 boneNode->SetTransform(i->initialPosition_, i->initialRotation_, i->initialScale_);
                 i->node_ = boneNode;

+ 25 - 11
Engine/Scene/Scene.cpp

@@ -75,6 +75,8 @@ void Scene::RegisterObject(Context* context)
 
 bool Scene::Load(Deserializer& source)
 {
+    StopAsyncLoading();
+    
     // Check ID
     if (source.ReadID() != "USCN")
     {
@@ -106,6 +108,8 @@ bool Scene::Save(Serializer& dest)
 
 bool Scene::LoadXML(const XMLElement& source)
 {
+    StopAsyncLoading();
+    
     // Load the whole scene, then perform post-load if successfully loaded
     if (Node::LoadXML(source))
     {
@@ -118,6 +122,8 @@ bool Scene::LoadXML(const XMLElement& source)
 
 bool Scene::LoadXML(Deserializer& source)
 {
+    StopAsyncLoading();
+    
     SharedPtr<XMLFile> xml(new XMLFile(context_));
     if (!xml->Load(source))
         return false;
@@ -143,6 +149,8 @@ bool Scene::LoadAsync(File* file)
         return false;
     }
     
+    StopAsyncLoading();
+    
     // Check ID
     if (file->ReadID() != "USCN")
     {
@@ -173,6 +181,8 @@ bool Scene::LoadAsyncXML(File* file)
         return false;
     }
     
+    StopAsyncLoading();
+    
     SharedPtr<XMLFile> xmlFile(new XMLFile(context_));
     if (!xmlFile->Load(*file))
         return false;
@@ -201,11 +211,19 @@ bool Scene::LoadAsyncXML(File* file)
     return true;
 }
 
+void Scene::StopAsyncLoading()
+{
+    asyncLoading_ = false;
+    asyncProgress_.file_.Reset();
+    asyncProgress_.xmlFile_.Reset();
+    asyncProgress_.xmlElement_ = XMLElement();
+}
+
 void Scene::Update(float timeStep)
 {
     if (asyncLoading_)
     {
-        UpdateAsyncLoad();
+        UpdateAsyncLoading();
         return;
     }
     
@@ -378,9 +396,9 @@ void Scene::HandleUpdate(StringHash eventType, VariantMap& eventData)
         Update(eventData[P_TIMESTEP].GetFloat());
 }
 
-void Scene::UpdateAsyncLoad()
+void Scene::UpdateAsyncLoading()
 {
-    PROFILE(UpdateAsyncLoad);
+    PROFILE(UpdateAsyncLoading);
     
     Timer asyncLoadTimer;
     
@@ -388,7 +406,7 @@ void Scene::UpdateAsyncLoad()
     {
         if (asyncProgress_.loadedNodes_ >= asyncProgress_.totalNodes_)
         {
-            FinishAsyncLoad();
+            FinishAsyncLoading();
             return;
         }
         
@@ -407,7 +425,7 @@ void Scene::UpdateAsyncLoad()
         
         ++asyncProgress_.loadedNodes_;
         
-        // Break if time limit elapsed, so that we keep sufficient FPS
+        // Break if time limit exceeded, so that we keep sufficient FPS
         if (asyncLoadTimer.GetMSec(true) >= ASYNC_LOAD_MAX_MSEC)
             break;
     }
@@ -422,14 +440,10 @@ void Scene::UpdateAsyncLoad()
     SendEvent(E_ASYNCLOADPROGRESS, eventData);
 }
 
-void Scene::FinishAsyncLoad()
+void Scene::FinishAsyncLoading()
 {
     PostLoad();
-    
-    asyncLoading_ = false;
-    asyncProgress_.file_.Reset();
-    asyncProgress_.xmlFile_.Reset();
-    asyncProgress_.xmlElement_ = XMLElement();
+    StopAsyncLoading();
     
     using namespace AsyncLoadFinished;
     

+ 8 - 6
Engine/Scene/Scene.h

@@ -90,6 +90,8 @@ public:
     bool LoadAsync(File* file);
     /// Load from an XML file asynchronously. Return true if started successfully
     bool LoadAsyncXML(File* file);
+    /// Stop asynchronous loading
+    void StopAsyncLoading();
     /// Update scene
     void Update(float timeStep);
     /// Set networking mode
@@ -105,9 +107,9 @@ public:
     NetworkMode GetNetworkMode() const { return networkMode_; }
     /// Return active flag
     bool IsActive() const { return active_; }
-    /// Return async loading flag
+    /// Return asynchronous loading flag
     bool IsAsyncLoading() const { return asyncLoading_; }
-    /// Return async loading progress between 0.0 and 1.0, or 1.0 if not async loading
+    /// Return asynchronous loading progress between 0.0 and 1.0, or 1.0 if not in progress
     float GetAsyncProgress() const;
     
     /// Get free node ID, either non-local or local
@@ -127,9 +129,9 @@ private:
     /// Handle the logic update event to update the scene, if active
     void HandleUpdate(StringHash eventType, VariantMap& eventData);
     /// Update asynchronous loading
-    void UpdateAsyncLoad();
+    void UpdateAsyncLoading();
     /// Finish asynchronous loading
-    void FinishAsyncLoad();
+    void FinishAsyncLoading();
     
     /// Map of scene nodes by ID
     std::map<unsigned, Node*> allNodes_;
@@ -137,7 +139,7 @@ private:
     std::map<unsigned, Component*> allComponents_;
     /// Networking mode
     NetworkMode networkMode_;
-    /// Async loading progress
+    /// Asynchronous loading progress
     AsyncProgress asyncProgress_;
     /// Next free non-local node ID
     unsigned nonLocalNodeID_;
@@ -149,7 +151,7 @@ private:
     unsigned localComponentID_;
     /// Active flag
     bool active_;
-    /// Async loading flag
+    /// Asynchronous loading flag
     bool asyncLoading_;
 };