[Orxonox-commit 3218] r7911 - code/trunk/src/modules/pong

landauf at orxonox.net landauf at orxonox.net
Fri Feb 18 00:08:00 CET 2011


Author: landauf
Date: 2011-02-18 00:08:00 +0100 (Fri, 18 Feb 2011)
New Revision: 7911

Modified:
   code/trunk/src/modules/pong/Pong.cc
   code/trunk/src/modules/pong/Pong.h
Log:
Pong gametype should delete the objects it created

Modified: code/trunk/src/modules/pong/Pong.cc
===================================================================
--- code/trunk/src/modules/pong/Pong.cc	2011-02-17 23:07:04 UTC (rev 7910)
+++ code/trunk/src/modules/pong/Pong.cc	2011-02-17 23:08:00 UTC (rev 7911)
@@ -61,6 +61,30 @@
         this->botclass_ = Class(PongBot);
     }
 
+    Pong::~Pong()
+    {
+        if (this->isInitialized())
+            this->cleanup();
+    }
+
+    void Pong::cleanup()
+    {
+        if (this->ball_)
+        {
+            this->ball_->destroy();
+            this->ball_ = 0;
+        }
+
+        for (size_t i = 0; i < 2; ++i)
+        {
+            if (this->bat_[0])
+            {
+                this->bat_[0]->destroy();
+                this->bat_[0] = 0;
+            }
+        }
+    }
+
     void Pong::start()
     {
         if (this->center_)
@@ -122,11 +146,7 @@
 
     void Pong::end()
     {
-        if (this->ball_)
-        {
-            this->ball_->destroy();
-            this->ball_ = 0;
-        }
+        this->cleanup();
 
         Deathmatch::end();
     }

Modified: code/trunk/src/modules/pong/Pong.h
===================================================================
--- code/trunk/src/modules/pong/Pong.h	2011-02-17 23:07:04 UTC (rev 7910)
+++ code/trunk/src/modules/pong/Pong.h	2011-02-17 23:08:00 UTC (rev 7911)
@@ -40,7 +40,7 @@
     {
         public:
             Pong(BaseObject* creator);
-            virtual ~Pong() {}
+            virtual ~Pong();
 
             virtual void start();
             virtual void end();
@@ -59,6 +59,7 @@
             virtual void spawnPlayersIfRequested();
 
             void startBall();
+            void cleanup();
 
             WeakPtr<PongCenterpoint> center_;
             WeakPtr<PongBall> ball_;




More information about the Orxonox-commit mailing list