Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 9, 2011, 5:06:49 AM (13 years ago)
Author:
rgrieder
Message:

Added and incorporated new class DestructionHelper: instead of doing the destruction of certain singletons implicitly via scoped_ptrs and ScopeGuards, use a method named destroy() that essentially achieves the same, but makes the destruction sequence obvious.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/libraries/core/Game.cc

    r8351 r8423  
    7878
    7979    Game::Game(const std::string& cmdLine)
    80         // Destroy factories before the Core!
    81         : gsFactoryDestroyer_(Game::GameStateFactory::getFactories(), &std::map<std::string, shared_ptr<GameStateFactory> >::clear)
    82     {
    83         this->bAbort_ = false;
    84         bChangingState_ = false;
    85 
     80        : gameClock_(NULL)
     81        , core_(NULL)
     82        , bChangingState_(false)
     83        , bAbort_(false)
     84        , destructionHelper_(this)
     85    {
    8686#ifdef ORXONOX_PLATFORM_WINDOWS
    8787        minimumSleepTime_ = 1000/*us*/;
     
    103103
    104104        // Set up a basic clock to keep time
    105         this->gameClock_.reset(new Clock());
     105        this->gameClock_ = new Clock();
    106106
    107107        // Create the Core
    108         this->core_.reset(new Core(cmdLine));
     108        this->core_ = new Core(cmdLine);
    109109
    110110        // Do this after the Core creation!
     
    127127    }
    128128
    129     /**
    130     @brief
    131         All destruction code is handled by scoped_ptrs and SimpleScopeGuards.
    132     */
    133     Game::~Game()
     129    void Game::destroy()
    134130    {
    135131        // Remove us from the object lists again to avoid problems when destroying them
    136132        this->unregisterObject();
     133
     134        assert(loadedStates_.size() <= 1); // Just empty root GameState
     135        // Destroy all GameStates (shared_ptrs take care of actual destruction)
     136        constructedStates_.clear();
     137
     138        GameStateFactory::getFactories().clear();
     139        safeObjectDelete(&core_);
     140        safeObjectDelete(&gameClock_);
    137141    }
    138142
Note: See TracChangeset for help on using the changeset viewer.