Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Feb 24, 2015, 10:54:24 PM (9 years ago)
Author:
landauf
Message:

added command 'reloadLevel' (by default on F5) which reloads the level while the player's camera remains at the same position

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/orxonox/gamestates/GSLevel.cc

    r8858 r10281  
    2929
    3030#include "GSLevel.h"
     31#include "GSLevelMemento.h"
    3132
    3233#include <OgreCompositorManager.h>
     
    3738#include "core/input/KeyBinderManager.h"
    3839#include "core/Core.h"
     40#include "core/CoreIncludes.h"
    3941#include "core/Game.h"
    4042#include "core/GameMode.h"
     
    5456    static const std::string __CC_startMainMenu_name = "startMainMenu";
    5557    static const std::string __CC_changeGame_name = "changeGame";
     58    static const std::string __CC_reloadLevel_name = "reloadLevel";
    5659
    5760    SetConsoleCommand(__CC_startMainMenu_name, &GSLevel::startMainMenu).deactivate();
    5861    SetConsoleCommand(__CC_changeGame_name, &GSLevel::changeGame).defaultValues("").deactivate();
     62    SetConsoleCommand(__CC_reloadLevel_name, &GSLevel::reloadLevel).deactivate();
    5963
    6064    GSLevel::GSLevel(const GameStateInfo& info)
     
    108112
    109113        if (GameMode::isStandalone())
     114        {
    110115            ModifyConsoleCommand(__CC_changeGame_name).activate();
     116            ModifyConsoleCommand(__CC_reloadLevel_name).setObject(this).activate();
     117        }
    111118    }
    112119
     
    140147
    141148        if (GameMode::isStandalone())
     149        {
    142150            ModifyConsoleCommand(__CC_changeGame_name).deactivate();
     151            ModifyConsoleCommand(__CC_reloadLevel_name).setObject(NULL).deactivate();
     152        }
    143153    }
    144154
     
    185195        else
    186196            orxout(internal_info) << " Try harder!" << endl;
     197    }
     198
     199    void GSLevel::reloadLevel()
     200    {
     201        // export all states
     202        std::vector<GSLevelMementoState*> states;
     203        for (ObjectList<GSLevelMemento>::iterator it = ObjectList<GSLevelMemento>::begin(); it != ObjectList<GSLevelMemento>::end(); ++it)
     204        {
     205            GSLevelMementoState* state = it->exportMementoState();
     206            if (state)
     207                states.push_back(state);
     208        }
     209
     210        // reload level (or better: reload the whole gamestate)
     211        this->deactivate();
     212        this->activate();
     213
     214        // import all states
     215        for (ObjectList<GSLevelMemento>::iterator it = ObjectList<GSLevelMemento>::begin(); it != ObjectList<GSLevelMemento>::end(); ++it)
     216            it->importMementoState(states);
     217
     218        // delete states
     219        for (size_t i = 0; i < states.size(); ++i)
     220            delete states[i];
    187221    }
    188222
     
    214248        Game::getInstance().requestStates("standalone, level");
    215249    }
     250
     251
     252
     253    ///////////////////////////////////////////////////////////////////////////
     254
     255    RegisterAbstractClass(GSLevelMemento).inheritsFrom(Class(OrxonoxInterface));
     256
     257    GSLevelMemento::GSLevelMemento()
     258    {
     259        RegisterObject(GSLevelMemento);
     260    }
    216261}
Note: See TracChangeset for help on using the changeset viewer.