Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10524


Ignore:
Timestamp:
Jun 4, 2015, 10:32:52 PM (9 years ago)
Author:
landauf
Message:

unload graphics when the game exits

Location:
code/branches/core7/src/libraries/core
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core7/src/libraries/core/Core.cc

    r10520 r10524  
    309309
    310310        // Any exception should trigger this, even in upgradeToGraphics (see its remarks)
    311         Loki::ScopeGuard unloader = Loki::MakeObjGuard(*this, &Core::unloadGraphics);
     311        Loki::ScopeGuard unloader = Loki::MakeObjGuard(*this, &Core::unloadGraphics, true);
    312312
    313313        // Upgrade OGRE to receive a render window
     
    357357    }
    358358
    359     void Core::unloadGraphics()
     359    void Core::unloadGraphics(bool loadGraphicsManagerWithoutRenderer)
    360360    {
    361361        orxout(internal_info) << "unloading graphics in Core" << endl;
     
    368368        // Load Ogre::Root again, but without the render system
    369369        try
    370             { this->graphicsManager_ = new GraphicsManager(false); }
     370        {
     371            if (loadGraphicsManagerWithoutRenderer)
     372                this->graphicsManager_ = new GraphicsManager(false);
     373        }
    371374        catch (...)
    372375        {
  • code/branches/core7/src/libraries/core/Core.h

    r10518 r10524  
    8080
    8181            void loadGraphics();
    82             void unloadGraphics();
     82            void unloadGraphics(bool loadGraphicsManagerWithoutRenderer = true);
    8383
    8484            void loadModules();
  • code/branches/core7/src/libraries/core/Game.cc

    r10518 r10524  
    518518
    519519            core_->loadGraphics();
    520             Loki::ScopeGuard graphicsUnloader = Loki::MakeObjGuard(*this, &Game::unloadGraphics);
     520            Loki::ScopeGuard graphicsUnloader = Loki::MakeObjGuard(*this, &Game::unloadGraphics, true);
    521521
    522522            // Construct all the GameStates that require graphics
     
    539539    }
    540540
    541     void Game::unloadGraphics()
     541    void Game::unloadGraphics(bool loadGraphicsManagerWithoutRenderer)
    542542    {
    543543        if (GameMode::showsGraphics())
     
    555555            }
    556556
    557             core_->unloadGraphics();
     557            core_->unloadGraphics(loadGraphicsManagerWithoutRenderer);
    558558        }
    559559    }
     
    576576
    577577        // If state requires graphics, load it
    578         Loki::ScopeGuard graphicsUnloader = Loki::MakeObjGuard(*this, &Game::unloadGraphics);
     578        Loki::ScopeGuard graphicsUnloader = Loki::MakeObjGuard(*this, &Game::unloadGraphics, true);
    579579        if (gameStateDeclarations_s[name].bGraphicsMode && !GameMode::showsGraphics())
    580580            this->loadGraphics();
     
    612612        }
    613613        // Check if graphics is still required
    614         if (!bAbort_)
    615         {
    616             bool graphicsRequired = false;
    617             for (unsigned i = 0; i < loadedStates_.size(); ++i)
    618                 graphicsRequired |= loadedStates_[i]->getInfo().bGraphicsMode;
    619             if (!graphicsRequired)
    620                 this->unloadGraphics();
    621         }
     614        bool graphicsRequired = false;
     615        for (unsigned i = 0; i < loadedStates_.size(); ++i)
     616            graphicsRequired |= loadedStates_[i]->getInfo().bGraphicsMode;
     617        if (!graphicsRequired)
     618            this->unloadGraphics(!this->bAbort_); // if abort is false, that means the game is still running while unloading graphics. in this case we load a graphics manager without renderer (to keep all necessary ogre instances alive)
    622619        this->bChangingState_ = false;
    623620    }
  • code/branches/core7/src/libraries/core/Game.h

    r10479 r10524  
    148148
    149149        void loadGraphics();
    150         void unloadGraphics();
     150        void unloadGraphics(bool loadGraphicsManagerWithoutRenderer = true);
    151151
    152152        void parseStates(std::vector<std::pair<std::string, int> >::const_iterator& it, shared_ptr<GameStateTreeNode> currentNode);
Note: See TracChangeset for help on using the changeset viewer.