[Orxonox-commit 1084] r5805 - in code/branches/core5/src: libraries/core modules/gamestates orxonox

landauf at orxonox.net landauf at orxonox.net
Sun Sep 27 02:33:49 CEST 2009


Author: landauf
Date: 2009-09-27 02:33:48 +0200 (Sun, 27 Sep 2009)
New Revision: 5805

Modified:
   code/branches/core5/src/libraries/core/BaseObject.h
   code/branches/core5/src/libraries/core/OrxonoxClass.cc
   code/branches/core5/src/libraries/core/OrxonoxClass.h
   code/branches/core5/src/libraries/core/SmartPtr.h
   code/branches/core5/src/modules/gamestates/GSLevel.cc
   code/branches/core5/src/orxonox/CameraManager.cc
   code/branches/core5/src/orxonox/CameraManager.h
   code/branches/core5/src/orxonox/Scene.cc
Log:
 - Enhanced SmartPtr:
   a) It stores now two pointers, one OrxonoxClass* (for reference counting) and one T* (for normal use).
   b) Incrementing the reference is now optional in the constructor for raw pointers. This is needed because Scene has a selfreference but should still be destroyable.
 - Changed BaseObject to store a SmartPtr to it's Scene instead of a normal pointer.
 - Changed setScene and getScene to deal directly with SmartPtr instead of a Scene* pointer to avoid casting-to-OrxonoxClass issues.
 - Fixed two problems with lost SceneManagers in CameraManger:
   a) added a SmartPtr to the Scene for the fallback camera
   b) added a call to GUIManager in the destructor to release the scene manager
 - Enabled unloading in GSLevel again (after years). Works if playing without bots.

Modified: code/branches/core5/src/libraries/core/BaseObject.h
===================================================================
--- code/branches/core5/src/libraries/core/BaseObject.h	2009-09-26 21:16:49 UTC (rev 5804)
+++ code/branches/core5/src/libraries/core/BaseObject.h	2009-09-27 00:33:48 UTC (rev 5805)
@@ -52,6 +52,7 @@
 #include "util/mbool.h"
 #include "OrxonoxClass.h"
 #include "Super.h"
+#include "SmartPtr.h"
 
 namespace orxonox
 {
@@ -133,8 +134,8 @@
             inline void setCreator(BaseObject* creator) { this->creator_ = creator; }
             inline BaseObject* getCreator() const { return this->creator_; }
 
-            inline void setScene(Scene* scene) { this->scene_ = scene; }
-            inline Scene* getScene() const { return this->scene_; }
+            inline void setScene(const SmartPtr<Scene>& scene) { this->scene_ = scene; }
+            inline const SmartPtr<Scene>& getScene() const { return this->scene_; }
 
             inline void setGametype(Gametype* gametype)
             {
@@ -193,7 +194,7 @@
             std::string            loaderIndentation_;         //!< Indentation of the debug output in the Loader
             Namespace*             namespace_;
             BaseObject*            creator_;
-            Scene*                 scene_;
+            SmartPtr<Scene>        scene_;
             Gametype*              gametype_;
             Gametype*              oldGametype_;
             std::set<Template*>    templates_;

Modified: code/branches/core5/src/libraries/core/OrxonoxClass.cc
===================================================================
--- code/branches/core5/src/libraries/core/OrxonoxClass.cc	2009-09-26 21:16:49 UTC (rev 5804)
+++ code/branches/core5/src/libraries/core/OrxonoxClass.cc	2009-09-27 00:33:48 UTC (rev 5805)
@@ -54,7 +54,7 @@
 //        if (!this->requestedDestruction_)
 //            COUT(2) << "Warning: Destroyed object without destroy() (" << this->getIdentifier()->getName() << ")" << std::endl;
 
-        assert(this->referenceCount_ == 0);
+        assert(this->referenceCount_ <= 0);
 
         delete this->metaList_;
 

Modified: code/branches/core5/src/libraries/core/OrxonoxClass.h
===================================================================
--- code/branches/core5/src/libraries/core/OrxonoxClass.h	2009-09-26 21:16:49 UTC (rev 5804)
+++ code/branches/core5/src/libraries/core/OrxonoxClass.h	2009-09-27 00:33:48 UTC (rev 5805)
@@ -134,7 +134,7 @@
             Identifier* identifier_;                   //!< The Identifier of the object
             std::set<const Identifier*>* parents_;     //!< List of all parents of the object
             MetaObjectList* metaList_;                 //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in
-            unsigned int referenceCount_;              //!< Counts the references from smart pointers to this object
+            int referenceCount_;                       //!< Counts the references from smart pointers to this object
             bool requestedDestruction_;                //!< Becomes true after someone called delete on this object
 
             //! 'Fast map' that holds this-pointers of all derived types

Modified: code/branches/core5/src/libraries/core/SmartPtr.h
===================================================================
--- code/branches/core5/src/libraries/core/SmartPtr.h	2009-09-26 21:16:49 UTC (rev 5804)
+++ code/branches/core5/src/libraries/core/SmartPtr.h	2009-09-27 00:33:48 UTC (rev 5805)
@@ -41,34 +41,44 @@
     class SmartPtr
     {
         public:
-            inline SmartPtr() : pointer_(0)
+            inline SmartPtr() : pointer_(0), base_(0)
             {
             }
 
-            inline SmartPtr(T* pointer) : pointer_(pointer)
+            inline SmartPtr(int) : pointer_(0), base_(0)
             {
-                if (this->pointer_)
-                    this->pointer_->incrementReferenceCount();
             }
 
-            inline SmartPtr(const SmartPtr& other) : pointer_(other.pointer_)
+            inline SmartPtr(T* pointer, bool bAddRef = true) : pointer_(pointer), base_(pointer)
             {
-                if (this->pointer_)
-                    this->pointer_->incrementReferenceCount();
+                if (this->base_ && bAddRef)
+                    this->base_->incrementReferenceCount();
             }
 
+            inline SmartPtr(const SmartPtr& other) : pointer_(other.pointer_), base_(other.base_)
+            {
+                if (this->base_)
+                    this->base_->incrementReferenceCount();
+            }
+
             template <class O>
-            inline SmartPtr(const SmartPtr<O>& other) : pointer_(other.get())
+            inline SmartPtr(const SmartPtr<O>& other) : pointer_(other.get()), base_(other.base_)
             {
-                if (this->pointer_)
-                    this->pointer_->incrementReferenceCount();
+                if (this->base_)
+                    this->base_->incrementReferenceCount();
             }
 
             inline ~SmartPtr()
             {
-                if (this->pointer_)
-                    this->pointer_->decrementReferenceCount();
+                if (this->base_)
+                    this->base_->decrementReferenceCount();
             }
+            
+            inline const SmartPtr& operator=(int)
+            {
+                SmartPtr(0).swap(*this);
+                return *this;
+            }
 
             inline const SmartPtr& operator=(T* pointer)
             {
@@ -95,7 +105,7 @@
             }
 
             inline operator T*() const
-            {std::cout << "(implizit)";
+            {
                 return this->pointer_;
             }
 
@@ -116,9 +126,16 @@
 
             inline void swap(SmartPtr& other)
             {
-                T* temp = this->pointer_;
-                this->pointer_ = other.pointer_;
-                other.pointer_ = temp;
+                {
+                    T* temp = this->pointer_;
+                    this->pointer_ = other.pointer_;
+                    other.pointer_ = temp;
+                }
+                {
+                    OrxonoxClass* temp = this->base_;
+                    this->base_ = other.base_;
+                    other.base_ = temp;
+                }
             }
 
             inline void reset()
@@ -128,6 +145,7 @@
 
         private:
             T* pointer_;
+            OrxonoxClass* base_;
     };
 
     template <class A, class B>

Modified: code/branches/core5/src/modules/gamestates/GSLevel.cc
===================================================================
--- code/branches/core5/src/modules/gamestates/GSLevel.cc	2009-09-26 21:16:49 UTC (rev 5804)
+++ code/branches/core5/src/modules/gamestates/GSLevel.cc	2009-09-27 00:33:48 UTC (rev 5805)
@@ -241,11 +241,7 @@
 
     void GSLevel::unloadLevel()
     {
-        //////////////////////////////////////////////////////////////////////////////////////////
-        // TODO // TODO // TODO // TODO // TODO // TODO // TODO // TODO // TODO // TODO // TODO //
-        //////////////////////////////////////////////////////////////////////////////////////////
-        // Loader::unload(startFile_); // TODO: REACTIVATE THIS IF LOADER::UNLOAD WORKS PROPERLY /
-        //////////////////////////////////////////////////////////////////////////////////////////
+        Loader::unload(startFile_s);
 
         delete startFile_s;
     }

Modified: code/branches/core5/src/orxonox/CameraManager.cc
===================================================================
--- code/branches/core5/src/orxonox/CameraManager.cc	2009-09-26 21:16:49 UTC (rev 5804)
+++ code/branches/core5/src/orxonox/CameraManager.cc	2009-09-27 00:33:48 UTC (rev 5805)
@@ -52,7 +52,8 @@
     CameraManager::~CameraManager()
     {
         if (this->fallbackCamera_)
-            this->fallbackCamera_->getSceneManager()->destroyCamera(this->fallbackCamera_);
+            this->fallbackCameraScene_->getSceneManager()->destroyCamera(this->fallbackCamera_);
+        GUIManager::getInstance().setCamera(0);
     }
 
     Camera* CameraManager::getActiveCamera() const
@@ -73,7 +74,7 @@
             this->cameraList_.front()->removeFocus();
         else if (this->fallbackCamera_)
         {
-            this->fallbackCamera_->getSceneManager()->destroyCamera(this->fallbackCamera_);
+            this->fallbackCameraScene_->getSceneManager()->destroyCamera(this->fallbackCamera_);
             this->fallbackCamera_ = 0;
         }
 
@@ -106,7 +107,10 @@
             {
                 // there are no more cameras, create a fallback
                 if (!this->fallbackCamera_)
-                    this->fallbackCamera_ = camera->getScene()->getSceneManager()->createCamera(getUniqueNumberString());
+                {
+                    this->fallbackCameraScene_ = camera->getScene();
+                    this->fallbackCamera_ = this->fallbackCameraScene_->getSceneManager()->createCamera(getUniqueNumberString());
+                }
                 this->useCamera(this->fallbackCamera_);
             }
         }

Modified: code/branches/core5/src/orxonox/CameraManager.h
===================================================================
--- code/branches/core5/src/orxonox/CameraManager.h	2009-09-26 21:16:49 UTC (rev 5804)
+++ code/branches/core5/src/orxonox/CameraManager.h	2009-09-27 00:33:48 UTC (rev 5805)
@@ -41,6 +41,7 @@
 #include <list>
 #include "util/OgreForwardRefs.h"
 #include "util/Singleton.h"
+#include "core/SmartPtr.h"
 
 namespace orxonox
 {
@@ -66,6 +67,7 @@
             std::list<Camera*>    cameraList_;
             Ogre::Viewport*       viewport_;
             Ogre::Camera*         fallbackCamera_;
+            SmartPtr<Scene>       fallbackCameraScene_;
 
             static CameraManager* singletonPtr_s;
     };

Modified: code/branches/core5/src/orxonox/Scene.cc
===================================================================
--- code/branches/core5/src/orxonox/Scene.cc	2009-09-26 21:16:49 UTC (rev 5804)
+++ code/branches/core5/src/orxonox/Scene.cc	2009-09-27 00:33:48 UTC (rev 5805)
@@ -53,7 +53,7 @@
     {
         RegisterObject(Scene);
 
-        this->setScene(this);
+        this->setScene(SmartPtr<Scene>(this, false));
         this->bShadows_ = true;
 
         if (GameMode::showsGraphics())




More information about the Orxonox-commit mailing list