Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 4, 2015, 9:12:21 PM (9 years ago)
Author:
landauf
Message:

merged branch core7 back to trunk

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/orxonox/gamestates/GSLevel.cc

    r10299 r10624  
    4444#include "core/Loader.h"
    4545#include "core/XMLFile.h"
    46 #include "core/command/ConsoleCommand.h"
     46#include "core/command/ConsoleCommandIncludes.h"
    4747
    4848#include "LevelManager.h"
     49#include "Level.h"
    4950#include "PlayerManager.h"
    5051#include "GSRoot.h"
     
    9596        }
    9697
     98        this->prepareObjectTracking();
     99
    97100        if (GameMode::isMaster())
    98101        {
     
    128131        if (GameMode::isMaster())
    129132            this->unloadLevel();
     133        else
     134            this->unloadLevelAsClient();
     135
     136        this->performObjectTracking();
    130137
    131138        if (GameMode::showsGraphics())
     
    161168    }
    162169
    163     void GSLevel::loadLevel()
     170    void GSLevel::prepareObjectTracking()
    164171    {
    165172        for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(); it != ObjectList<BaseObject>::end(); ++it)
    166173            this->staticObjects_.insert(*it);
    167 
    168         // call the loader
    169         startFile_ = new XMLFile(LevelManager::getInstance().getDefaultLevel());
    170         bool loaded = Loader::open(startFile_);
    171 
    172         Core::getInstance().updateLastLevelTimestamp();
    173         if(!loaded)
    174             GSRoot::delayedStartMainMenu();
    175     }
    176 
    177     void GSLevel::unloadLevel()
    178     {
    179         Loader::unload(startFile_);
    180         delete startFile_;
    181 
     174    }
     175
     176    void GSLevel::performObjectTracking()
     177    {
    182178        orxout(internal_info) << "Remaining objects:" << endl;
    183179        unsigned int i = 0;
     
    187183            if (find == this->staticObjects_.end())
    188184            {
    189                 orxout(internal_info) << ++i << ": " << it->getIdentifier()->getName() << " (" << *it << "), references: " << it->getReferenceCount() << endl;
     185                orxout(internal_warning) << ++i << ": " << it->getIdentifier()->getName() << " (" << *it << "), references: " << it->getReferenceCount() << endl;
    190186            }
    191187        }
     
    194190        else
    195191            orxout(internal_warning) << i << " objects remaining. Try harder!" << endl;
     192    }
     193
     194    void GSLevel::loadLevel()
     195    {
     196        // call the loader
     197        startFile_ = new XMLFile(LevelManager::getInstance().getDefaultLevel());
     198        bool loaded = Loader::getInstance().load(startFile_);
     199
     200        Core::getInstance().getConfig()->updateLastLevelTimestamp();
     201        if(!loaded)
     202            GSRoot::delayedStartMainMenu();
     203    }
     204
     205    void GSLevel::unloadLevel()
     206    {
     207        Loader::getInstance().unload(startFile_);
     208        delete startFile_;
     209    }
     210
     211    /**
     212     * Unloads a level when the game instance is (or was) a client in a multiplayer session.
     213     * In this case, cleanup after unloading a level is done differently because certain things (e.g. the xml file) are unknown.
     214     */
     215    void GSLevel::unloadLevelAsClient()
     216    {
     217        for (ObjectList<Level>::iterator it = ObjectList<Level>::begin(); it != ObjectList<Level>::end(); )
     218        {
     219            StrongPtr<Level> level = *(it++); // StrongPtr prevents that the Level gets destroyed while we loop over it
     220            for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(level); it != ObjectList<BaseObject>::end(level); )
     221                (it++)->destroy();
     222        }
     223
     224        for (ObjectList<Synchronisable>::iterator it = ObjectList<Synchronisable>::begin(); it != ObjectList<Synchronisable>::end(); )
     225        {
     226            if (it->getSyncMode() != 0x0)
     227                (it++)->destroy();
     228            else
     229                ++it;
     230        }
    196231    }
    197232
     
    252287    ///////////////////////////////////////////////////////////////////////////
    253288
    254     RegisterAbstractClass(GSLevelMemento).inheritsFrom(Class(OrxonoxInterface));
     289    RegisterAbstractClass(GSLevelMemento).inheritsFrom<OrxonoxInterface>();
    255290
    256291    GSLevelMemento::GSLevelMemento()
Note: See TracChangeset for help on using the changeset viewer.