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.

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.