Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 19, 2008, 8:12:15 PM (16 years ago)
Author:
rgrieder
Message:
  • Changed static Executor/Functor in ConsoleCommand to generic one that enables console commands for member functions. (This is more of a temporary solution, but can be made permanent with right adjustments)
  • The whole GameState thing seems to works so far. But I there's only standalone mode at the moment
  • Console now shows in GUI too. I will have to implement a master InputState in the InputManager (little bit of a break with the concept, but probably necessary)
File:
1 edited

Legend:

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

    r1661 r1662  
    2323 *      Reto Grieder
    2424 *   Co-authors:
    25  *      ...
     25 *      Fabian 'x3n' Landau
    2626 *
    2727 */
     
    3030#include "GSLevel.h"
    3131
    32 #include "GraphicsEngine.h"
    3332#include "core/ConsoleCommand.h"
    3433#include "core/input/InputManager.h"
    3534#include "core/input/SimpleInputState.h"
    3635#include "core/input/KeyBinder.h"
     36#include "core/Loader.h"
    3737#include "overlays/console/InGameConsole.h"
    3838#include "gui/GUIManager.h"
     39#include "objects/Backlight.h"
     40#include "tools/ParticleInterface.h"
     41#include "Radar.h"
     42#include "Settings.h"
     43#include "GraphicsEngine.h"
    3944
    4045namespace orxonox
     
    4348        : GameState("level")
    4449        , timefactor_(1.0f)
     50        , keyBinder_(0)
     51        , radar_(0)
     52        , startLevel_(0)
     53        , hud_(0)
    4554    {
    4655    }
     
    5261    void GSLevel::enter()
    5362    {
    54         KeyBinder* keyBinder = new KeyBinder();
    55         keyBinder->loadBindings();
    56         InputManager::getInstance().createInputState<SimpleInputState>("game", 20)->setHandler(keyBinder);
     63        keyBinder_ = new KeyBinder();
     64        keyBinder_->loadBindings();
     65        InputManager::getInstance().createInputState<SimpleInputState>("game", 20)->setHandler(keyBinder_);
     66
     67        // create Ogre SceneManager for the level
     68        GraphicsEngine::getInstance().createNewScene();
     69
     70        // Start the Radar
     71        this->radar_ = new Radar();
     72
     73        // Load the HUD
     74        COUT(3) << "Orxonox: Loading HUD" << std::endl;
     75        hud_ = new Level(Settings::getDataPath() + "overlay/hud.oxo");
     76        Loader::load(hud_);
     77
     78        // call the loader
     79        COUT(0) << "Loading level..." << std::endl;
     80        startLevel_ = new Level(Settings::getDataPath() + "levels/sample.oxw");
     81        Loader::open(startLevel_);
    5782
    5883        // add console commands
    59         //ConsoleCommand* command = createConsoleCommand(createFunctor(&classname::function), )
    60         //CommandExecutor::addConsoleCommandShortcut(command);
     84        FunctorMember<GSLevel>* functor = createFunctor(&GSLevel::setTimeFactor);
     85        functor->setObject(this);
     86        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "setTimeFactor"));
     87
     88        // level is loaded: we can start capturing the input
     89        InputManager::getInstance().requestEnterState("game");
    6190    }
    6291
    6392    void GSLevel::leave()
    6493    {
     94        InputManager::getInstance().requestLeaveState("game");
     95
     96        // TODO: Remove and destroy console command
     97
     98        Loader::unload(startLevel_);
     99        delete this->startLevel_;
     100
     101        Loader::unload(hud_);
     102        delete this->hud_;
     103
     104        // this call will delete every BaseObject!
     105        // But currently this will call methods of objects that exist no more
     106        // The only 'memory leak' is the ParticleSpawer. They would be deleted here
     107        // and call a sceneNode method that has already been destroy by the corresponding space ship.
     108        //Loader::close();
     109
     110        delete this->radar_;
     111
     112        // TODO: delete SceneManager
     113
     114        InputManager::getInstance().destroyState("game");
     115        delete this->keyBinder_;
    65116    }
    66117
     
    74125            it->tick(dt * this->timefactor_);
    75126
     127        // TODO: split file into server/client/standalone
    76128        // call server/client with normal dt
    77129        //if (client_g)
     
    87139        Changes the speed of Orxonox
    88140    */
    89     //void GSLevel::setTimeFactor(float factor)
    90     //{
    91     //    float change = factor / Orxonox::getInstance().getTimeFactor();
    92     //    Orxonox::getInstance().timefactor_ = factor;
    93     //    for (Iterator<ParticleInterface> it = ObjectList<ParticleInterface>::begin(); it; ++it)
    94     //        it->setSpeedFactor(it->getSpeedFactor() * change);
     141    void GSLevel::setTimeFactor(float factor)
     142    {
     143        float change = factor / this->timefactor_;
     144        this->timefactor_ = factor;
     145        for (Iterator<ParticleInterface> it = ObjectList<ParticleInterface>::begin(); it; ++it)
     146            it->setSpeedFactor(it->getSpeedFactor() * change);
    95147
    96     //    for (Iterator<Backlight> it = ObjectList<Backlight>::begin(); it; ++it)
    97     //        it->setTimeFactor(Orxonox::getInstance().getTimeFactor());
    98     //}
     148        for (Iterator<Backlight> it = ObjectList<Backlight>::begin(); it; ++it)
     149            it->setTimeFactor(timefactor_);
     150    }
    99151}
Note: See TracChangeset for help on using the changeset viewer.