[Orxonox-commit 3622] r8307 - in code/branches/kicklib2/src/orxonox: . worldentities/pawns

rgrieder at orxonox.net rgrieder at orxonox.net
Fri Apr 22 22:23:04 CEST 2011


Author: rgrieder
Date: 2011-04-22 22:23:04 +0200 (Fri, 22 Apr 2011)
New Revision: 8307

Modified:
   code/branches/kicklib2/src/orxonox/PawnManager.cc
   code/branches/kicklib2/src/orxonox/PawnManager.h
   code/branches/kicklib2/src/orxonox/worldentities/pawns/Pawn.cc
Log:
Manage PawnManager by Scopes. Then the singleton should get deleted in any case.

Modified: code/branches/kicklib2/src/orxonox/PawnManager.cc
===================================================================
--- code/branches/kicklib2/src/orxonox/PawnManager.cc	2011-04-22 19:51:25 UTC (rev 8306)
+++ code/branches/kicklib2/src/orxonox/PawnManager.cc	2011-04-22 20:23:04 UTC (rev 8307)
@@ -28,12 +28,13 @@
 
 #include "PawnManager.h"
 
+#include "util/ScopedSingletonManager.h"
 #include "core/CoreIncludes.h"
 #include "worldentities/pawns/Pawn.h"
 
 namespace orxonox
 {
-    PawnManager* PawnManager::singletonPtr_s = 0;
+    ManageScopedSingleton(PawnManager, ScopeID::Root, false);
 
     PawnManager::PawnManager()
     {
@@ -42,26 +43,19 @@
 
     PawnManager::~PawnManager()
     {
+        // Be sure to delete all the pawns
+        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); )
+            (it++)->destroy();
     }
 
-    void PawnManager::touch()
+    void PawnManager::preUpdate(const Clock& time)
     {
-        if (!PawnManager::singletonPtr_s)
-            new PawnManager();
-    }
-
-    void PawnManager::tick(float dt)
-    {
-        unsigned int count = 0;
-        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++count)
+        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); )
         {
             if (!it->isAlive())
                 (it++)->destroy();
             else
                 ++it;
         }
-
-        if (count == 0)
-            this->destroy();
     }
 }

Modified: code/branches/kicklib2/src/orxonox/PawnManager.h
===================================================================
--- code/branches/kicklib2/src/orxonox/PawnManager.h	2011-04-22 19:51:25 UTC (rev 8306)
+++ code/branches/kicklib2/src/orxonox/PawnManager.h	2011-04-22 20:23:04 UTC (rev 8307)
@@ -36,17 +36,16 @@
 
 namespace orxonox
 {
-    class _OrxonoxExport PawnManager : protected Singleton<PawnManager>, public Tickable
+    class _OrxonoxExport PawnManager : public Singleton<PawnManager>, public Tickable
     {
             friend class Singleton<PawnManager>;
         public:
-            static void touch();
+            PawnManager();
+            virtual ~PawnManager();
 
-            virtual void tick(float dt);
+            virtual void preUpdate(const Clock& time);
 
         private:
-            PawnManager();
-            virtual ~PawnManager();
 
             static PawnManager* singletonPtr_s;
     };

Modified: code/branches/kicklib2/src/orxonox/worldentities/pawns/Pawn.cc
===================================================================
--- code/branches/kicklib2/src/orxonox/worldentities/pawns/Pawn.cc	2011-04-22 19:51:25 UTC (rev 8306)
+++ code/branches/kicklib2/src/orxonox/worldentities/pawns/Pawn.cc	2011-04-22 20:23:04 UTC (rev 8307)
@@ -35,7 +35,6 @@
 #include "core/XMLPort.h"
 #include "network/NetworkFunction.h"
 
-#include "PawnManager.h"
 #include "infos/PlayerInfo.h"
 #include "controllers/Controller.h"
 #include "gametypes/Gametype.h"
@@ -58,7 +57,6 @@
     {
         RegisterObject(Pawn);
 
-        PawnManager::touch();
         this->bAlive_ = true;
         this->bReload_ = false;
 




More information about the Orxonox-commit mailing list