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)
Location:
code/branches/gui/src/orxonox/gamestates
Files:
7 edited

Legend:

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

    r1661 r1662  
    3333#include "core/input/InputManager.h"
    3434#include "core/input/SimpleInputState.h"
    35 #include "core/input/KeyBinder.h"
    36 #include "overlays/console/InGameConsole.h"
    3735#include "gui/GUIManager.h"
    3836
  • code/branches/gui/src/orxonox/gamestates/GSGraphics.cc

    r1661 r1662  
    3535#include <OgreWindowEventUtilities.h>
    3636
     37#include "core/ConsoleCommand.h"
     38#include "core/ConfigValueIncludes.h"
    3739#include "core/input/InputManager.h"
    38 #include "core/input/SimpleInputState.h"
    39 #include "core/input/KeyBinder.h"
    4040#include "core/Core.h"
    41 
    42 #include "GraphicsEngine.h"
    4341#include "overlays/console/InGameConsole.h"
    4442#include "gui/GUIManager.h"
     43#include "GraphicsEngine.h"
    4544
    4645namespace orxonox
     
    8887        guiManager_ = new GUIManager();
    8988        guiManager_->initialise();
     89
     90        // use the ogre timer class to measure time.
     91        timer_ = new Ogre::Timer();
     92
     93        // add console commands
     94        FunctorMember<GSGraphics>* functor = createFunctor(&GSGraphics::exitGame);
     95        functor->setObject(this);
     96        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "exit"));
    9097    }
    9198
    9299    void GSGraphics::leave()
    93100    {
    94         if (this->guiManager_)
    95           delete guiManager_;
    96 
    97         if (this->console_)
    98           delete this->console_;
    99 
    100         if (inputManager_)
    101           delete inputManager_;
    102 
    103         // TODO: deintialise graphics
    104     }
    105 
     101        delete this->timer_;
     102
     103        delete this->guiManager_;
     104
     105        delete this->console_;
     106
     107        delete this->inputManager_;
     108
     109        // TODO: destroy render window
     110    }
     111
     112    /**
     113        Main loop of the orxonox game.
     114        We use the Ogre::Timer to measure time since it uses the most precise
     115        method an a platform (however the windows timer lacks time when under
     116        heavy kernel load!).
     117        There is a simple mechanism to measure the average time spent in our
     118        ticks as it may indicate performance issues.
     119        A note about the Ogre::FrameListener: Even though we don't use them,
     120        they still get called. However, the delta times are not correct (except
     121        for timeSinceLastFrame, which is the most important). A little research
     122        as shown that there is probably only one FrameListener that doesn't even
     123        need the time. So we shouldn't run into problems.
     124    */
    106125    bool GSGraphics::tick(float dt)
    107126    {
     127        // note: paramter 'dt' is of no meaning
     128
    108129        Ogre::Root& ogreRoot = Ogre::Root::getSingleton();
    109 
    110         // use the ogre timer class to measure time.
    111         if (!timer_)
    112             timer_ = new Ogre::Timer();
    113130
    114131        unsigned long frameCount = 0;
     
    146163                    this->getActiveChild()->tick(dt);
    147164
     165                // tick console
     166                this->console_->tick(dt);
     167
    148168                // get current time once again
    149169                timeAfterTick = timer_->getMicroseconds();
  • code/branches/gui/src/orxonox/gamestates/GSGraphics.h

    r1661 r1662  
    3131
    3232#include "OrxonoxPrereqs.h"
     33#include <OgrePrerequisites.h>
    3334#include "core/GameState.h"
     35#include "core/OrxonoxClass.h"
    3436
    3537namespace orxonox
     
    4345        bool tick(float dt);
    4446        void setConfigValues();
     47
     48        void exitGame() { this->bAbort_ = true; }
    4549
    4650    private:
  • 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}
  • code/branches/gui/src/orxonox/gamestates/GSLevel.h

    r1661 r1662  
    4949        void setTimeFactor(float factor);
    5050
    51         float                 timefactor_;       //!< A factor to change the gamespeed
     51        float timefactor_;       //!< A factor to change the gamespeed
     52
     53        KeyBinder*            keyBinder_;        //!< tool that loads and manages the input bindings
     54        Radar*                radar_;            //!< represents the Radar (not the HUD part)
     55        Level*                startLevel_;       //!< current hard coded default level
     56        Level*                hud_;              //!< 'level' object fo the HUD
    5257    };
    5358}
  • code/branches/gui/src/orxonox/gamestates/GSRoot.cc

    r1661 r1662  
    3030#include "GSRoot.h"
    3131
    32 #include <cassert>
    3332#include "core/Factory.h"
    3433#include "core/ConfigFileManager.h"
     
    3635#include "core/ConsoleCommand.h"
    3736#include "core/Debug.h"
    38 //#include "core/Exception.h"
     37#include "core/Exception.h"
    3938#include "core/TclBind.h"
    4039#include "core/Core.h"
     
    6564        Factory::createClassHierarchy();
    6665
    67         // TODO: config values
    68         //setConfigValues();
    69 
    7066        const Settings::CommandLineArgument* dataPath = Settings::getCommandLineArgument("dataPath");
    7167        assert(dataPath);
     
    8177        TclBind::getInstance().setDataPath(Settings::getDataPath());
    8278
     79        // initialise graphics engine. Doesn't load the render window yet!
    8380        graphicsEngine_ = new GraphicsEngine();
    8481        graphicsEngine_->setup();       // creates ogre root and other essentials
    8582
     83        // console commands
     84        FunctorMember<GSRoot>* functor = createFunctor(&GSRoot::loadGame);
     85        functor->setObject(this);
     86        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "loadGame"));
    8687    }
    8788
     
    9899        return true;
    99100    }
     101
     102    /**
     103    @brief
     104        Requests a state.
     105    */
     106    void GSRoot::loadGame(const std::string& name)
     107    {
     108        this->requestState(name);
     109    }
    100110}
  • code/branches/gui/src/orxonox/gamestates/GSRoot.h

    r1661 r1662  
    4242
    4343        bool tick(float dt);
     44        void loadGame(const std::string& name);
    4445
    4546    private:
Note: See TracChangeset for help on using the changeset viewer.