Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1662


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
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • code/branches/gui/src/core/ConsoleCommand.cc

    r1505 r1662  
    3131namespace orxonox
    3232{
    33     ConsoleCommand::ConsoleCommand(FunctorStatic* functor, const std::string& name) : ExecutorStatic(functor, name)
     33    ConsoleCommand::ConsoleCommand(Functor* functor, const std::string& name) : Executor(functor, name)
    3434    {
    3535        this->accessLevel_ = AccessLevel::None;
  • code/branches/gui/src/core/ConsoleCommand.h

    r1549 r1662  
    7070    }
    7171
    72     class _CoreExport ConsoleCommand : public ExecutorStatic
     72    class _CoreExport ConsoleCommand : public Executor
    7373    {
    7474        public:
    75             ConsoleCommand(FunctorStatic* functor, const std::string& name = "");
     75            ConsoleCommand(Functor* functor, const std::string& name = "");
    7676
    7777            inline ConsoleCommand& setDescription(const std::string& description)
    78                 { this->ExecutorStatic::setDescription(description); return (*this); }
     78                { this->Executor::setDescription(description); return (*this); }
    7979            inline ConsoleCommand& setDescriptionParam(int param, const std::string& description)
    80                 { this->ExecutorStatic::setDescriptionParam(param, description); return (*this); }
     80                { this->Executor::setDescriptionParam(param, description); return (*this); }
    8181            inline ConsoleCommand& setDescriptionReturnvalue(const std::string& description)
    82                 { this->ExecutorStatic::setDescriptionReturnvalue(description); return (*this); }
     82                { this->Executor::setDescriptionReturnvalue(description); return (*this); }
    8383            inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1)
    84                 { this->ExecutorStatic::setDefaultValues(param1); return (*this); }
     84                { this->Executor::setDefaultValues(param1); return (*this); }
    8585            inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2)
    86                 { this->ExecutorStatic::setDefaultValues(param1, param2); return (*this); }
     86                { this->Executor::setDefaultValues(param1, param2); return (*this); }
    8787            inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3)
    88                 { this->ExecutorStatic::setDefaultValues(param1, param2, param3); return (*this); }
     88                { this->Executor::setDefaultValues(param1, param2, param3); return (*this); }
    8989            inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4)
    90                 { this->ExecutorStatic::setDefaultValues(param1, param2, param3, param4); return (*this); }
     90                { this->Executor::setDefaultValues(param1, param2, param3, param4); return (*this); }
    9191            inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4, const MultiTypeMath& param5)
    92                 { this->ExecutorStatic::setDefaultValues(param1, param2, param3, param4, param5); return (*this); }
     92                { this->Executor::setDefaultValues(param1, param2, param3, param4, param5); return (*this); }
    9393            inline ConsoleCommand& setDefaultValue(unsigned int index, const MultiTypeMath& param)
    94                 { this->ExecutorStatic::setDefaultValue(index, param); return (*this); }
     94                { this->Executor::setDefaultValue(index, param); return (*this); }
    9595
    9696            inline ConsoleCommand& setAccessLevel(AccessLevel::Level level)
     
    135135    };
    136136
    137     inline ConsoleCommand* createConsoleCommand(FunctorStatic* functor, const std::string& name = "")
     137    inline ConsoleCommand* createConsoleCommand(Functor* functor, const std::string& name = "")
    138138    {
    139139        return new ConsoleCommand(functor, name);
  • code/branches/gui/src/orxonox/Orxonox.cc

    r1661 r1662  
    8888namespace orxonox
    8989{
    90   SetConsoleCommand(Orxonox, exit, true).setKeybindMode(KeybindMode::OnPress);
    91   SetConsoleCommand(Orxonox, slomo, true).setAccessLevel(AccessLevel::Offline).setDefaultValue(0, 1.0).setAxisParamIndex(0).setIsAxisRelative(false);
    92   SetConsoleCommand(Orxonox, setTimeFactor, true).setAccessLevel(AccessLevel::Offline).setDefaultValue(0, 1.0);
    93   SetConsoleCommand(Orxonox, loadGame, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, "standalone");
     90  //SetConsoleCommand(Orxonox, exit, true).setKeybindMode(KeybindMode::OnPress);
     91  //SetConsoleCommand(Orxonox, slomo, true).setAccessLevel(AccessLevel::Offline).setDefaultValue(0, 1.0).setAxisParamIndex(0).setIsAxisRelative(false);
     92  //SetConsoleCommand(Orxonox, setTimeFactor, true).setAccessLevel(AccessLevel::Offline).setDefaultValue(0, 1.0);
     93  //SetConsoleCommand(Orxonox, loadGame, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, "standalone");
    9494
    9595  /**
  • 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:
  • code/branches/gui/src/orxonox/gui/GUIManager.cc

    r1661 r1662  
    163163                // load the background scene
    164164                loadScenes();
     165                //CEGUI::KeyEventArgs e;
     166                //e.codepoint
    165167            }
    166168            catch (CEGUI::Exception& ex)
  • code/branches/gui/src/orxonox/objects/Backlight.cc

    r1654 r1662  
    6868        this->ribbonTrail_->setMaterialName("Trail/backlighttrail");
    6969
    70         this->setTimeFactor(Orxonox::getInstance().getTimeFactor());
     70        //this->setTimeFactor(Orxonox::getInstance().getTimeFactor());
     71        this->setTimeFactor(1.0f);
    7172    }
    7273
  • code/branches/gui/src/orxonox/overlays/console/InGameConsole.h

    r1642 r1662  
    3737
    3838#include "core/Shell.h"
    39 #include "objects/Tickable.h"
     39#include "core/OrxonoxClass.h"
    4040#include "tools/WindowEventListener.h"
    4141
     
    4343namespace orxonox
    4444{
    45     class _OrxonoxExport InGameConsole : public TickableReal, public ShellListener, public WindowEventListener
     45    class _OrxonoxExport InGameConsole : virtual public OrxonoxClass, public ShellListener, public WindowEventListener
    4646    {
    4747    public: // functions
  • code/branches/gui/src/orxonox/tools/ParticleInterface.cc

    r1654 r1662  
    5656    this->detaillevel_ = (unsigned int)detaillevel;
    5757    this->particleSystem_ = GraphicsEngine::getInstance().getLevelSceneManager()->createParticleSystem("particles" + getConvertedValue<unsigned int, std::string>(ParticleInterface::counter_s++), templateName);
    58     this->particleSystem_->setSpeedFactor(Orxonox::getInstance().getTimeFactor());
     58    //this->particleSystem_->setSpeedFactor(Orxonox::getInstance().getTimeFactor());
     59    this->particleSystem_->setSpeedFactor(1.0f);
    5960
    6061    if (GraphicsEngine::getInstance().getDetailLevelParticle() < (unsigned int)this->detaillevel_)
     
    171172  void ParticleInterface::setSpeedFactor(float factor)
    172173  {
    173     this->particleSystem_->setSpeedFactor(Orxonox::getInstance().getTimeFactor() * factor);
     174    //this->particleSystem_->setSpeedFactor(Orxonox::getInstance().getTimeFactor() * factor);
     175    this->particleSystem_->setSpeedFactor(1.0f * factor);
    174176  }
    175177  float ParticleInterface::getSpeedFactor() const
    176178  {
    177     return (this->particleSystem_->getSpeedFactor() / Orxonox::getInstance().getTimeFactor());
     179    //return (this->particleSystem_->getSpeedFactor() / Orxonox::getInstance().getTimeFactor());
     180    return (this->particleSystem_->getSpeedFactor() / 1.0f);
    178181  }
    179182
Note: See TracChangeset for help on using the changeset viewer.