[Orxonox-commit 5907] r10566 - in code/branches/core7/src: libraries/network orxonox/gamestates

landauf at orxonox.net landauf at orxonox.net
Tue Sep 8 15:42:30 CEST 2015


Author: landauf
Date: 2015-09-08 15:42:30 +0200 (Tue, 08 Sep 2015)
New Revision: 10566

Modified:
   code/branches/core7/src/libraries/network/Client.cc
   code/branches/core7/src/orxonox/gamestates/GSLevel.cc
   code/branches/core7/src/orxonox/gamestates/GSLevel.h
Log:
moved destruction of all level objects from Client to GSLevel. (there's still a bug with unloading in client mode which was introduced in r10563)

Modified: code/branches/core7/src/libraries/network/Client.cc
===================================================================
--- code/branches/core7/src/libraries/network/Client.cc	2015-08-30 12:36:27 UTC (rev 10565)
+++ code/branches/core7/src/libraries/network/Client.cc	2015-09-08 13:42:30 UTC (rev 10566)
@@ -193,16 +193,6 @@
 
   void Client::connectionClosed()
   {
-    ObjectList<Synchronisable>::iterator it;
-    for(it = ObjectList<Synchronisable>::begin(); it; )
-    {
-      if( it->getSyncMode() != 0x0 )
-        (it++)->destroy();
-      else
-      {
-        ++it;
-      }
-    }
     Game::getInstance().popState();
     Game::getInstance().popState();
   }

Modified: code/branches/core7/src/orxonox/gamestates/GSLevel.cc
===================================================================
--- code/branches/core7/src/orxonox/gamestates/GSLevel.cc	2015-08-30 12:36:27 UTC (rev 10565)
+++ code/branches/core7/src/orxonox/gamestates/GSLevel.cc	2015-09-08 13:42:30 UTC (rev 10566)
@@ -94,6 +94,8 @@
             guiKeysOnlyInputState_->setKeyHandler(&GUIManager::getInstance());
         }
 
+        this->prepareObjectTracking();
+
         if (GameMode::isMaster())
         {
             this->loadLevel();
@@ -127,7 +129,11 @@
 
         if (GameMode::isMaster())
             this->unloadLevel();
+        else
+            this->unloadLevelAsClient();
 
+        this->performObjectTracking();
+
         if (GameMode::showsGraphics())
         {
 #if OGRE_VERSION < 0x010700
@@ -160,11 +166,32 @@
         //    it->tick(time.getDeltaTime() * this->timeFactor_);
     }
 
-    void GSLevel::loadLevel()
+    void GSLevel::prepareObjectTracking()
     {
         for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(); it != ObjectList<BaseObject>::end(); ++it)
             this->staticObjects_.insert(*it);
+    }
 
+    void GSLevel::performObjectTracking()
+    {
+        orxout(internal_info) << "Remaining objects:" << endl;
+        unsigned int i = 0;
+        for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(); it != ObjectList<BaseObject>::end(); ++it)
+        {
+            std::set<BaseObject*>::const_iterator find = this->staticObjects_.find(*it);
+            if (find == this->staticObjects_.end())
+            {
+                orxout(internal_warning) << ++i << ": " << it->getIdentifier()->getName() << " (" << *it << "), references: " << it->getReferenceCount() << endl;
+            }
+        }
+        if (i == 0)
+            orxout(internal_info) << i << " objects remaining. Well done!" << endl;
+        else
+            orxout(internal_warning) << i << " objects remaining. Try harder!" << endl;
+    }
+
+    void GSLevel::loadLevel()
+    {
         // call the loader
         startFile_ = new XMLFile(LevelManager::getInstance().getDefaultLevel());
         bool loaded = Loader::getInstance().load(startFile_);
@@ -178,21 +205,24 @@
     {
         Loader::getInstance().unload(startFile_);
         delete startFile_;
+    }
 
-        orxout(internal_info) << "Remaining objects:" << endl;
-        unsigned int i = 0;
-        for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(); it != ObjectList<BaseObject>::end(); ++it)
+    /**
+     * Unloads a level when the game instance is (or was) a client in a multiplayer session.
+     * In this case, cleanup after unloading a level is done differently because certain things (e.g. the xml file) are unknown.
+     */
+    void GSLevel::unloadLevelAsClient()
+    {
+        ObjectList<Synchronisable>::iterator it;
+        for(it = ObjectList<Synchronisable>::begin(); it; )
         {
-            std::set<BaseObject*>::const_iterator find = this->staticObjects_.find(*it);
-            if (find == this->staticObjects_.end())
+            if( it->getSyncMode() != 0x0 )
+                (it++)->destroy();
+            else
             {
-                orxout(internal_info) << ++i << ": " << it->getIdentifier()->getName() << " (" << *it << "), references: " << it->getReferenceCount() << endl;
+                ++it;
             }
         }
-        if (i == 0)
-            orxout(internal_info) << i << " objects remaining. Well done!" << endl;
-        else
-            orxout(internal_warning) << i << " objects remaining. Try harder!" << endl;
     }
 
     void GSLevel::reloadLevel()

Modified: code/branches/core7/src/orxonox/gamestates/GSLevel.h
===================================================================
--- code/branches/core7/src/orxonox/gamestates/GSLevel.h	2015-08-30 12:36:27 UTC (rev 10565)
+++ code/branches/core7/src/orxonox/gamestates/GSLevel.h	2015-09-08 13:42:30 UTC (rev 10566)
@@ -52,10 +52,14 @@
 
         void reloadLevel();
 
-    protected:
+    private:
         void loadLevel();
         void unloadLevel();
+        void unloadLevelAsClient();
 
+        void prepareObjectTracking();
+        void performObjectTracking();
+
         InputState*              gameInputState_;          //!< input state for normal ingame playing
         InputState*              guiMouseOnlyInputState_;  //!< input state if we only need the mouse to use the GUI
         InputState*              guiKeysOnlyInputState_;   //!< input state if we only need the keys to use the GUI




More information about the Orxonox-commit mailing list