Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 8, 2009, 10:56:29 PM (15 years ago)
Author:
rgrieder
Message:

Fixed CameraManager issue with the fallback scene by assigning each Scene a CameraManager directly.
Use this→getScene()→getCameraManager() to get the camera manager.

Location:
code/branches/core5/src/orxonox
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core5/src/orxonox/CameraManager.cc

    r5877 r5911  
    3838#include "core/GUIManager.h"
    3939#include "core/ObjectList.h"
    40 #include "core/ScopedSingletonManager.h"
    4140#include "tools/Shader.h"
    4241#include "graphics/Camera.h"
     
    4544namespace orxonox
    4645{
    47     CameraManager* CameraManager::singletonPtr_s = 0;
    48     ManageScopedSingleton(CameraManager, ScopeID::Graphics, false);
    49 
    50     CameraManager::CameraManager()
    51         : viewport_(GraphicsManager::getInstance().getViewport())
     46    CameraManager::CameraManager(BaseObject* creator)
     47        : BaseObject(creator)
     48        , viewport_(GraphicsManager::getInstance().getViewport())
     49        , fallbackCamera_(NULL)
    5250    {
    53         this->fallbackCamera_ = 0;
     51        assert(GameMode::showsGraphics());
    5452    }
    5553
    5654    CameraManager::~CameraManager()
    5755    {
     56        for (std::list<Camera*>::iterator it = this->cameraList_.begin(); it != this->cameraList_.end();)
     57            if ((*it)->camera_ == GUIManager::getInstance().getCamera())
     58                GUIManager::getInstance().setCamera(NULL);
     59
    5860        if (this->fallbackCamera_)
    59             this->fallbackCameraScene_->getSceneManager()->destroyCamera(this->fallbackCamera_);
    60         GUIManager::getInstance().setCamera(0);
     61            this->getScene()->getSceneManager()->destroyCamera(this->fallbackCamera_);
    6162    }
    6263
    6364    Camera* CameraManager::getActiveCamera() const
    6465    {
    65         if (this->cameraList_.size() > 0)
     66        if (!this->cameraList_.empty())
    6667            return this->cameraList_.front();
    6768        else
     
    7172    void CameraManager::requestFocus(Camera* camera)
    7273    {
    73         if (!GameMode::showsGraphics())
    74             return;
    75 
    7674        // notify old camera (if it exists)
    77         if (this->cameraList_.size() > 0)
     75        if (!this->cameraList_.empty())
    7876            this->cameraList_.front()->removeFocus();
    79         else if (this->fallbackCamera_)
    80         {
    81             this->fallbackCameraScene_->getSceneManager()->destroyCamera(this->fallbackCamera_);
    82             this->fallbackCamera_ = 0;
    83         }
    8477
    8578        camera->setFocus();
    8679
    8780        // make sure we don't add it twice
    88         for (std::list<Camera*>::iterator it = this->cameraList_.begin(); it != this->cameraList_.end(); ++it)
     81        for (std::list<Camera*>::iterator it = this->cameraList_.begin(); it != this->cameraList_.end();)
    8982            if ((*it) == camera)
    90                 return;
     83                this->cameraList_.erase(it++);
     84            else
     85                ++it;
    9186
    9287        // add to list
     
    9691    void CameraManager::releaseFocus(Camera* camera)
    9792    {
    98         if (!GameMode::showsGraphics())
    99             return;
    100 
    10193        // notify the cam of releasing the focus
    102         if (this->cameraList_.front() == camera)
     94        if (!this->cameraList_.empty() && this->cameraList_.front() == camera)
    10395        {
    10496            camera->removeFocus();
     
    10698
    10799            // set new focus if possible
    108             if (this->cameraList_.size() > 0)
     100            if (!this->cameraList_.empty())
    109101                this->cameraList_.front()->setFocus();
    110102            else
     
    112104                // there are no more cameras, create a fallback
    113105                if (!this->fallbackCamera_)
    114                 {
    115                     this->fallbackCameraScene_ = camera->getScene();
    116                     this->fallbackCamera_ = this->fallbackCameraScene_->getSceneManager()->createCamera(getUniqueNumberString());
    117                 }
     106                    this->fallbackCamera_ = camera->getScene()->getSceneManager()->createCamera(getUniqueNumberString());
    118107                this->useCamera(this->fallbackCamera_);
    119108            }
    120109        }
    121110        else
    122         {
    123111            this->cameraList_.remove(camera);
    124         }
    125112    }
    126113
  • code/branches/core5/src/orxonox/CameraManager.h

    r5867 r5911  
    4141#include <list>
    4242#include "util/OgreForwardRefs.h"
    43 #include "util/Singleton.h"
    44 #include "core/OrxonoxClass.h"
    45 #include "core/SmartPtr.h"
     43#include "core/BaseObject.h"
    4644
    4745namespace orxonox
    4846{
    49     class _OrxonoxExport CameraManager : public Singleton<CameraManager>, public OrxonoxClass
     47    class _OrxonoxExport CameraManager : public BaseObject
    5048    {
    51             friend class Singleton<CameraManager>;
    5249        public:
    53             CameraManager();
     50            CameraManager(BaseObject* creator);
    5451            ~CameraManager();
    5552
     
    6158            void useCamera(Ogre::Camera* camera);
    6259
    63             static CameraManager* getInstancePtr() { return singletonPtr_s; }
    64 
    6560        private:
    6661            CameraManager(const CameraManager&); // don't use
     
    6964            Ogre::Viewport*       viewport_;
    7065            Ogre::Camera*         fallbackCamera_;
    71             SmartPtr<Scene>       fallbackCameraScene_;
    72 
    73             static CameraManager* singletonPtr_s;
    7466    };
    7567}
  • code/branches/core5/src/orxonox/Scene.cc

    r5839 r5911  
    4545#include "tools/BulletConversions.h"
    4646#include "Radar.h"
     47#include "CameraManager.h"
    4748#include "worldentities/WorldEntity.h"
    4849
     
    6566
    6667            this->radar_ = new Radar();
     68            this->cameraManager_ = new CameraManager(this);
    6769        }
    6870        else
     
    7375
    7476            this->radar_ = 0;
     77            this->cameraManager_ = 0;
    7578        }
    7679
     
    9497        {
    9598            if (GameMode::showsGraphics())
     99            {
     100                // Check whether we're still using this scene manager for the GUI
     101                if (GUIManager::getInstance().getCamera() && GUIManager::getInstance().getCamera()->getSceneManager() == this->sceneManager_)
     102                    GUIManager::getInstance().setCamera(NULL);
    96103                Ogre::Root::getSingleton().destroySceneManager(this->sceneManager_);
     104            }
    97105            else
    98106                delete this->sceneManager_;
     
    100108            if (this->radar_)
    101109                this->radar_->destroy();
     110
     111            if (this->cameraManager_)
     112                this->cameraManager_->destroy();
    102113
    103114            this->setPhysicalWorld(false);
  • code/branches/core5/src/orxonox/Scene.h

    r5839 r5911  
    7373            inline Radar* getRadar()
    7474                { return this->radar_; }
     75
     76            inline CameraManager* getCameraManager()
     77                { return this->cameraManager_.get(); }
    7578           
    7679            inline virtual uint32_t getSceneID() const { return this->getObjectID(); }
     
    97100            bool                     bShadows_;
    98101            Radar*                   radar_;
     102            SmartPtr<CameraManager>  cameraManager_;
    99103
    100104
  • code/branches/core5/src/orxonox/graphics/Camera.cc

    r5738 r5911  
    3838#include "core/CoreIncludes.h"
    3939#include "core/ConfigValueIncludes.h"
     40#include "core/GameMode.h"
    4041#include "Scene.h"
    4142#include "CameraManager.h"
     
    4950        RegisterObject(Camera);
    5051
     52        if (!GameMode::showsGraphics())
     53            ThrowException(AbortLoading, "Can't create Camera, no graphics.");
    5154        if (!this->getScene())
    5255            ThrowException(AbortLoading, "Can't create Camera, no scene.");
     
    117120    void Camera::requestFocus()
    118121    {
    119         CameraManager::getInstance().requestFocus(this);
     122        this->getScene()->getCameraManager()->requestFocus(this);
    120123    }
    121124
    122125    void Camera::releaseFocus()
    123126    {
    124         CameraManager::getInstance().releaseFocus(this);
     127        this->getScene()->getCameraManager()->releaseFocus(this);
    125128    }
    126129
     
    137140    {
    138141        this->bHasFocus_ = true;
    139         CameraManager::getInstance().useCamera(this->camera_);
     142        this->getScene()->getCameraManager()->useCamera(this->camera_);
    140143    }
    141144
Note: See TracChangeset for help on using the changeset viewer.