[Orxonox-commit 1190] r5911 - in code/branches/core5/src: libraries/core modules/objects orxonox orxonox/graphics

rgrieder at orxonox.net rgrieder at orxonox.net
Thu Oct 8 22:56:29 CEST 2009


Author: rgrieder
Date: 2009-10-08 22:56:29 +0200 (Thu, 08 Oct 2009)
New Revision: 5911

Modified:
   code/branches/core5/src/libraries/core/GUIManager.cc
   code/branches/core5/src/libraries/core/GUIManager.h
   code/branches/core5/src/modules/objects/Planet.cc
   code/branches/core5/src/orxonox/CameraManager.cc
   code/branches/core5/src/orxonox/CameraManager.h
   code/branches/core5/src/orxonox/Scene.cc
   code/branches/core5/src/orxonox/Scene.h
   code/branches/core5/src/orxonox/graphics/Camera.cc
Log:
Fixed CameraManager issue with the fallback scene by assigning each Scene a CameraManager directly.
Use this->getScene()->getCameraManager() to get the camera manager.

Modified: code/branches/core5/src/libraries/core/GUIManager.cc
===================================================================
--- code/branches/core5/src/libraries/core/GUIManager.cc	2009-10-08 19:47:28 UTC (rev 5910)
+++ code/branches/core5/src/libraries/core/GUIManager.cc	2009-10-08 20:56:29 UTC (rev 5911)
@@ -100,6 +100,7 @@
     GUIManager::GUIManager(Ogre::RenderWindow* renderWindow, const std::pair<int, int>& mousePosition, bool bFullScreen)
         : renderWindow_(renderWindow)
         , resourceProvider_(0)
+        , camera_(NULL)
     {
         using namespace CEGUI;
 
@@ -173,6 +174,7 @@
     */
     void GUIManager::setCamera(Ogre::Camera* camera)
     {
+        this->camera_ = camera;
         if (camera == NULL)
             this->guiRenderer_->setTargetSceneManager(0);
         else

Modified: code/branches/core5/src/libraries/core/GUIManager.h
===================================================================
--- code/branches/core5/src/libraries/core/GUIManager.h	2009-10-08 19:47:28 UTC (rev 5910)
+++ code/branches/core5/src/libraries/core/GUIManager.h	2009-10-08 20:56:29 UTC (rev 5911)
@@ -70,6 +70,7 @@
         void executeCode(const std::string& str);
 
         void setCamera(Ogre::Camera* camera);
+        Ogre::Camera* getCamera() { return this->camera_; }
 
         static GUIManager* getInstancePtr() { return singletonPtr_s; }
 
@@ -100,6 +101,7 @@
         CEGUI::ResourceProvider*             resourceProvider_; //!< CEGUI's resource provider
         CEGUI::Logger*                       ceguiLogger_;      //!< CEGUI's logger to be able to log CEGUI errors in our log
         std::map<std::string, PlayerInfo*>   players_;          //!< Stores the player (owner) for each gui
+        Ogre::Camera*                        camera_;           //!< Camera used to render the scene with the GUI
 
         static GUIManager*                   singletonPtr_s;    //!< Singleton reference to GUIManager
 

Modified: code/branches/core5/src/modules/objects/Planet.cc
===================================================================
--- code/branches/core5/src/modules/objects/Planet.cc	2009-10-08 19:47:28 UTC (rev 5910)
+++ code/branches/core5/src/modules/objects/Planet.cc	2009-10-08 20:56:29 UTC (rev 5911)
@@ -46,7 +46,7 @@
     /**
      * @brief Constructor
      */
-    Planet::Planet(BaseObject* creator): MovableEntity(creator)
+    Planet::Planet(BaseObject* creator) : MovableEntity(creator)
     {
         RegisterObject(Planet);
         this->registerVariables();
@@ -63,13 +63,13 @@
 
     void Planet::tick(float dt)
     {
-        if(!this->isVisible())
+        if (!this->isVisible())
             return;
 
         if (GameMode::showsGraphics())
         {
-            Camera* activeCamera = CameraManager::getInstance().getActiveCamera();
-            if(activeCamera)
+            Camera* activeCamera = this->getScene()->getCameraManager()->getActiveCamera();
+            if (activeCamera)
             {
                 float distance = this->getPosition().distance( activeCamera->getWorldPosition() );
                 //             COUT(2) << distance << std::endl;

Modified: code/branches/core5/src/orxonox/CameraManager.cc
===================================================================
--- code/branches/core5/src/orxonox/CameraManager.cc	2009-10-08 19:47:28 UTC (rev 5910)
+++ code/branches/core5/src/orxonox/CameraManager.cc	2009-10-08 20:56:29 UTC (rev 5911)
@@ -37,32 +37,33 @@
 #include "core/GraphicsManager.h"
 #include "core/GUIManager.h"
 #include "core/ObjectList.h"
-#include "core/ScopedSingletonManager.h"
 #include "tools/Shader.h"
 #include "graphics/Camera.h"
 #include "Scene.h"
 
 namespace orxonox
 {
-    CameraManager* CameraManager::singletonPtr_s = 0;
-    ManageScopedSingleton(CameraManager, ScopeID::Graphics, false);
-
-    CameraManager::CameraManager()
-        : viewport_(GraphicsManager::getInstance().getViewport())
+    CameraManager::CameraManager(BaseObject* creator)
+        : BaseObject(creator)
+        , viewport_(GraphicsManager::getInstance().getViewport())
+        , fallbackCamera_(NULL)
     {
-        this->fallbackCamera_ = 0;
+        assert(GameMode::showsGraphics());
     }
 
     CameraManager::~CameraManager()
     {
+        for (std::list<Camera*>::iterator it = this->cameraList_.begin(); it != this->cameraList_.end();)
+            if ((*it)->camera_ == GUIManager::getInstance().getCamera())
+                GUIManager::getInstance().setCamera(NULL);
+
         if (this->fallbackCamera_)
-            this->fallbackCameraScene_->getSceneManager()->destroyCamera(this->fallbackCamera_);
-        GUIManager::getInstance().setCamera(0);
+            this->getScene()->getSceneManager()->destroyCamera(this->fallbackCamera_);
     }
 
     Camera* CameraManager::getActiveCamera() const
     {
-        if (this->cameraList_.size() > 0)
+        if (!this->cameraList_.empty())
             return this->cameraList_.front();
         else
             return 0;
@@ -70,24 +71,18 @@
 
     void CameraManager::requestFocus(Camera* camera)
     {
-        if (!GameMode::showsGraphics())
-            return;
-
         // notify old camera (if it exists)
-        if (this->cameraList_.size() > 0)
+        if (!this->cameraList_.empty())
             this->cameraList_.front()->removeFocus();
-        else if (this->fallbackCamera_)
-        {
-            this->fallbackCameraScene_->getSceneManager()->destroyCamera(this->fallbackCamera_);
-            this->fallbackCamera_ = 0;
-        }
 
         camera->setFocus();
 
         // make sure we don't add it twice
-        for (std::list<Camera*>::iterator it = this->cameraList_.begin(); it != this->cameraList_.end(); ++it)
+        for (std::list<Camera*>::iterator it = this->cameraList_.begin(); it != this->cameraList_.end();)
             if ((*it) == camera)
-                return;
+                this->cameraList_.erase(it++);
+            else
+                ++it;
 
         // add to list
         this->cameraList_.push_front(camera);
@@ -95,33 +90,25 @@
 
     void CameraManager::releaseFocus(Camera* camera)
     {
-        if (!GameMode::showsGraphics())
-            return;
-
         // notify the cam of releasing the focus
-        if (this->cameraList_.front() == camera)
+        if (!this->cameraList_.empty() && this->cameraList_.front() == camera)
         {
             camera->removeFocus();
             this->cameraList_.pop_front();
 
             // set new focus if possible
-            if (this->cameraList_.size() > 0)
+            if (!this->cameraList_.empty())
                 this->cameraList_.front()->setFocus();
             else
             {
                 // there are no more cameras, create a fallback
                 if (!this->fallbackCamera_)
-                {
-                    this->fallbackCameraScene_ = camera->getScene();
-                    this->fallbackCamera_ = this->fallbackCameraScene_->getSceneManager()->createCamera(getUniqueNumberString());
-                }
+                    this->fallbackCamera_ = camera->getScene()->getSceneManager()->createCamera(getUniqueNumberString());
                 this->useCamera(this->fallbackCamera_);
             }
         }
         else
-        {
             this->cameraList_.remove(camera);
-        }
     }
 
     void CameraManager::useCamera(Ogre::Camera* camera)

Modified: code/branches/core5/src/orxonox/CameraManager.h
===================================================================
--- code/branches/core5/src/orxonox/CameraManager.h	2009-10-08 19:47:28 UTC (rev 5910)
+++ code/branches/core5/src/orxonox/CameraManager.h	2009-10-08 20:56:29 UTC (rev 5911)
@@ -40,17 +40,14 @@
 #include <cassert>
 #include <list>
 #include "util/OgreForwardRefs.h"
-#include "util/Singleton.h"
-#include "core/OrxonoxClass.h"
-#include "core/SmartPtr.h"
+#include "core/BaseObject.h"
 
 namespace orxonox
 {
-    class _OrxonoxExport CameraManager : public Singleton<CameraManager>, public OrxonoxClass
+    class _OrxonoxExport CameraManager : public BaseObject
     {
-            friend class Singleton<CameraManager>;
         public:
-            CameraManager();
+            CameraManager(BaseObject* creator);
             ~CameraManager();
 
             Camera* getActiveCamera() const;
@@ -60,17 +57,12 @@
 
             void useCamera(Ogre::Camera* camera);
 
-            static CameraManager* getInstancePtr() { return singletonPtr_s; }
-
         private:
             CameraManager(const CameraManager&); // don't use
 
             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-10-08 19:47:28 UTC (rev 5910)
+++ code/branches/core5/src/orxonox/Scene.cc	2009-10-08 20:56:29 UTC (rev 5911)
@@ -44,6 +44,7 @@
 #include "core/XMLPort.h"
 #include "tools/BulletConversions.h"
 #include "Radar.h"
+#include "CameraManager.h"
 #include "worldentities/WorldEntity.h"
 
 namespace orxonox
@@ -64,6 +65,7 @@
             this->rootSceneNode_ = this->sceneManager_->getRootSceneNode();
 
             this->radar_ = new Radar();
+            this->cameraManager_ = new CameraManager(this);
         }
         else
         {
@@ -72,6 +74,7 @@
             this->rootSceneNode_ = this->sceneManager_->getRootSceneNode();
 
             this->radar_ = 0;
+            this->cameraManager_ = 0;
         }
 
         // No physics yet, XMLPort will do that.
@@ -93,13 +96,21 @@
         if (this->isInitialized())
         {
             if (GameMode::showsGraphics())
+            {
+                // Check whether we're still using this scene manager for the GUI
+                if (GUIManager::getInstance().getCamera() && GUIManager::getInstance().getCamera()->getSceneManager() == this->sceneManager_)
+                    GUIManager::getInstance().setCamera(NULL);
                 Ogre::Root::getSingleton().destroySceneManager(this->sceneManager_);
+            }
             else
                 delete this->sceneManager_;
 
             if (this->radar_)
                 this->radar_->destroy();
 
+            if (this->cameraManager_)
+                this->cameraManager_->destroy();
+
             this->setPhysicalWorld(false);
         }
     }

Modified: code/branches/core5/src/orxonox/Scene.h
===================================================================
--- code/branches/core5/src/orxonox/Scene.h	2009-10-08 19:47:28 UTC (rev 5910)
+++ code/branches/core5/src/orxonox/Scene.h	2009-10-08 20:56:29 UTC (rev 5911)
@@ -72,6 +72,9 @@
 
             inline Radar* getRadar()
                 { return this->radar_; }
+
+            inline CameraManager* getCameraManager()
+                { return this->cameraManager_.get(); }
             
             inline virtual uint32_t getSceneID() const { return this->getObjectID(); }
 
@@ -96,6 +99,7 @@
             std::list<BaseObject*>   objects_;
             bool                     bShadows_;
             Radar*                   radar_;
+            SmartPtr<CameraManager>  cameraManager_;
 
 
         /////////////

Modified: code/branches/core5/src/orxonox/graphics/Camera.cc
===================================================================
--- code/branches/core5/src/orxonox/graphics/Camera.cc	2009-10-08 19:47:28 UTC (rev 5910)
+++ code/branches/core5/src/orxonox/graphics/Camera.cc	2009-10-08 20:56:29 UTC (rev 5911)
@@ -37,6 +37,7 @@
 #include "util/StringUtils.h"
 #include "core/CoreIncludes.h"
 #include "core/ConfigValueIncludes.h"
+#include "core/GameMode.h"
 #include "Scene.h"
 #include "CameraManager.h"
 
@@ -48,6 +49,8 @@
     {
         RegisterObject(Camera);
 
+        if (!GameMode::showsGraphics())
+            ThrowException(AbortLoading, "Can't create Camera, no graphics.");
         if (!this->getScene())
             ThrowException(AbortLoading, "Can't create Camera, no scene.");
         if (!this->getScene()->getSceneManager())
@@ -116,12 +119,12 @@
 
     void Camera::requestFocus()
     {
-        CameraManager::getInstance().requestFocus(this);
+        this->getScene()->getCameraManager()->requestFocus(this);
     }
 
     void Camera::releaseFocus()
     {
-        CameraManager::getInstance().releaseFocus(this);
+        this->getScene()->getCameraManager()->releaseFocus(this);
     }
 
     /**
@@ -136,7 +139,7 @@
     void Camera::setFocus()
     {
         this->bHasFocus_ = true;
-        CameraManager::getInstance().useCamera(this->camera_);
+        this->getScene()->getCameraManager()->useCamera(this->camera_);
     }
 
     void Camera::setDrag(bool bDrag)




More information about the Orxonox-commit mailing list