Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10281


Ignore:
Timestamp:
Feb 24, 2015, 10:54:24 PM (10 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

Location:
code/trunk
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/data/defaultConfig/keybindings.ini

    r9939 r10281  
    3535KeyF3="OrxonoxOverlay show QuestGUI"
    3636KeyF4="OrxonoxOverlay show PickupInventory"
    37 KeyF5="startchat"
    38 KeyF6=
     37KeyF5="reloadLevel"
     38KeyF6="startchat"
    3939KeyF7=
    4040KeyF8=
  • code/trunk/src/orxonox/OrxonoxPrereqs.h

    r10216 r10281  
    7777    class Radar;
    7878    class Scene;
     79    class GSLevelMemento;
     80    struct GSLevelMementoState;
    7981
    8082    // chat
  • 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}
  • code/trunk/src/orxonox/gamestates/GSLevel.h

    r9667 r10281  
    5151        static void changeGame(const std::string& level); //!< Terminates the current game and starts a new game.
    5252
     53        void reloadLevel();
     54
    5355    protected:
    5456        void loadLevel();
  • code/trunk/src/orxonox/gametypes/Gametype.cc

    r9984 r10281  
    4545#include "worldentities/pawns/Pawn.h"
    4646#include "overlays/OverlayGroup.h"
     47#include "Scene.h"
    4748
    4849namespace orxonox
     
    525526        GSLevel::startMainMenu();
    526527    }
     528
     529    GSLevelMementoState* Gametype::exportMementoState()
     530    {
     531        for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
     532        {
     533            if (it->first->isHumanPlayer() && it->first->getControllableEntity() && it->first->getControllableEntity()->getCamera())
     534            {
     535                Camera* camera = it->first->getControllableEntity()->getCamera();
     536
     537                GametypeMementoState* state = new GametypeMementoState();
     538                state->cameraPosition_ = camera->getWorldPosition();
     539                state->cameraOrientation_ = camera->getWorldOrientation();
     540                state->sceneName_ = camera->getScene()->getName();
     541                return state;
     542            }
     543        }
     544
     545        return NULL;
     546    }
     547
     548    void Gametype::importMementoState(const std::vector<GSLevelMementoState*>& states)
     549    {
     550        // find correct memento state
     551        GametypeMementoState* state = NULL;
     552        for (size_t i = 0; i < states.size(); ++i)
     553        {
     554            state = dynamic_cast<GametypeMementoState*>(states[i]);
     555            if (state)
     556                break;
     557        }
     558
     559        if (!state)
     560            return;
     561
     562        // find correct scene
     563        Scene* scene = NULL;
     564        for (ObjectList<Scene>::iterator it = ObjectList<Scene>::begin(); it != ObjectList<Scene>::end(); ++it)
     565        {
     566            if (it->getName() == state->sceneName_)
     567            {
     568                scene = *it;
     569                break;
     570            }
     571        }
     572
     573        if (!scene)
     574        {
     575            orxout(internal_warning) << "Could not find scene with name " << state->sceneName_ << endl;
     576            return;
     577        }
     578
     579        // find correct player and assign default entity with original position & orientation
     580        for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
     581        {
     582            if (it->first->isHumanPlayer())
     583            {
     584                ControllableEntity* entity = this->defaultControllableEntity_.fabricate(scene->getContext());
     585                entity->setPosition(state->cameraPosition_);
     586                entity->setOrientation(state->cameraOrientation_);
     587                it->first->startControl(entity);
     588                break;
     589            }
     590        }
     591    }
    527592}
  • code/trunk/src/orxonox/gametypes/Gametype.h

    r9980 r10281  
    4141#include "infos/GametypeInfo.h"
    4242#include "tools/Timer.h"
     43#include "gamestates/GSLevelMemento.h"
    4344
    4445namespace orxonox
     
    6364    };
    6465
    65     class _OrxonoxExport Gametype : public BaseObject, public Tickable
     66    class _OrxonoxExport Gametype : public BaseObject, public Tickable, public GSLevelMemento
    6667    {
    6768        friend class PlayerInfo;
     
    172173            virtual void spawnDeadPlayersIfRequested();
    173174
     175            virtual GSLevelMementoState* exportMementoState();
     176            virtual void importMementoState(const std::vector<GSLevelMementoState*>& states);
     177
    174178            SmartPtr<GametypeInfo> gtinfo_;
    175179
     
    201205            Timer showMenuTimer_;
    202206    };
     207
     208    /**
     209        @brief Keeps position and orientation of the camera, as well as the name of current scene.
     210    */
     211    struct _OrxonoxExport GametypeMementoState : public GSLevelMementoState
     212    {
     213        Vector3 cameraPosition_;
     214        Quaternion cameraOrientation_;
     215        std::string sceneName_;
     216    };
    203217}
    204218
Note: See TracChangeset for help on using the changeset viewer.