Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 26, 2008, 4:26:04 PM (16 years ago)
Author:
rgrieder
Message:

Still working on the GameStates, but I have to save the work because of some major changes.

  • Exported InputManager- and TclThreadManager-tick to GSGraphics instead of Core
  • Fixed a few bugs in GameState by adding an internal state variable as bitfield (quite practical)
  • Fixed a bug in InputManager that occurred when destroying an active InputState
  • Added GSIO and GSIOConsole (3 lines of loop code with std::cin, but works ;))
  • Added more boost thread includes to OrxonoxStableHeaders.h
  • Many changes in all GameState derived classes
Location:
code/branches/gui/src/orxonox/gamestates
Files:
10 added
8 edited

Legend:

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

    r1662 r1670  
    5858    }
    5959
    60     bool GSGUI::tick(float dt)
     60    void GSGUI::ticked(float dt)
    6161    {
    6262        // tick CEGUI
    6363        GUIManager::getInstance().tick(dt);
    6464
    65         return true;
     65        this->tickChild(dt);
    6666    }
    6767}
  • code/branches/gui/src/orxonox/gamestates/GSGUI.h

    r1661 r1670  
    4444        void enter();
    4545        void leave();
    46         bool tick(float dt);
     46        void ticked(float dt);
    4747
    4848    };
  • code/branches/gui/src/orxonox/gamestates/GSGraphics.cc

    r1662 r1670  
    3838#include "core/ConfigValueIncludes.h"
    3939#include "core/input/InputManager.h"
    40 #include "core/Core.h"
     40#include "core/TclThreadManager.h"
     41//#include "core/Core.h"
    4142#include "overlays/console/InGameConsole.h"
    4243#include "gui/GUIManager.h"
     
    4849        : GameState("graphics")
    4950        , timer_(0)
    50         , bAbort_(false)
    5151        , debugRefreshTime_(0.0f)
    5252        , inputManager_(0)
     
    9090        // use the ogre timer class to measure time.
    9191        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"));
    9792    }
    9893
     
    123118        need the time. So we shouldn't run into problems.
    124119    */
    125     bool GSGraphics::tick(float dt)
     120    void GSGraphics::ticked(float dt)
    126121    {
    127122        // note: paramter 'dt' is of no meaning
     
    147142        {
    148143            timer_->reset();
    149             while (!bAbort_)
     144            while (!this->hasScheduledTransition())
    150145            {
    151146                // get current time
     
    154149                float dt = (timeBeforeTick - timeBeforeTickOld) / 1000000.0;
    155150
    156 
    157                 // tick the core (needs real time for input and tcl thread management)
    158                 // TODO: ticks of InputManager and tcl thread manager have to be separated.
    159                 Core::tick(dt);
    160 
    161                 // tick child state
    162                 if (this->getActiveChild())
    163                     this->getActiveChild()->tick(dt);
     151                this->inputManager_->tick(dt);
     152                TclThreadManager::getInstance().tick(dt);
     153
     154                this->tickChild(dt);
    164155
    165156                // tick console
     
    210201            COUT(1) << ex.what() << std::endl;
    211202            COUT(1) << "Main loop was stopped by an unhandled exception. Shutting down." << std::endl;
    212         }        return true;
     203        }
    213204    }
    214205}
  • code/branches/gui/src/orxonox/gamestates/GSGraphics.h

    r1662 r1670  
    4343        ~GSGraphics();
    4444
    45         bool tick(float dt);
    4645        void setConfigValues();
    47 
    48         void exitGame() { this->bAbort_ = true; }
    4946
    5047    private:
    5148        void enter();
    5249        void leave();
     50        void ticked(float dt);
    5351
    5452        Ogre::Timer*          timer_;            //!< Main loop timer
    55         bool                  bAbort_;           //!< aborts the render loop if true
    5653
    5754        // config values
  • code/branches/gui/src/orxonox/gamestates/GSLevel.cc

    r1664 r1670  
    3030#include "GSLevel.h"
    3131
    32 #include "core/ConsoleCommand.h"
    3332#include "core/input/InputManager.h"
    3433#include "core/input/SimpleInputState.h"
    3534#include "core/input/KeyBinder.h"
    3635#include "core/Loader.h"
    37 #include "core/CommandLine.h"
    38 #include "overlays/console/InGameConsole.h"
    39 #include "gui/GUIManager.h"
    4036#include "objects/Backlight.h"
    4137#include "tools/ParticleInterface.h"
     38#include "Settings.h"
    4239#include "Radar.h"
    43 #include "Settings.h"
    4440#include "GraphicsEngine.h"
    4541
    4642namespace orxonox
    4743{
    48     SetCommandLineArgument(port, 55556).setShortcut("p").setInformation("PORT");
    49     SetCommandLineArgument(ip, "127.0.0.0").setInformation("#.#.#.#");
    50 
    51     GSLevel::GSLevel()
    52         : GameState("level")
     44    GSLevel::GSLevel(const std::string& name)
     45        : GameState(name)
    5346        , timefactor_(1.0f)
    5447        , keyBinder_(0)
     48        , inputState_(0)
    5549        , radar_(0)
    5650        , startLevel_(0)
     
    6559    void GSLevel::enter()
    6660    {
     61        inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("game", 20);
    6762        keyBinder_ = new KeyBinder();
    6863        keyBinder_->loadBindings();
    69         InputManager::getInstance().createInputState<SimpleInputState>("game", 20)->setHandler(keyBinder_);
     64        inputState_->setHandler(keyBinder_);
    7065
    7166        // create Ogre SceneManager for the level
     
    7974        hud_ = new Level(Settings::getDataPath() + "overlay/hud.oxo");
    8075        Loader::load(hud_);
    81 
    82         // call the loader
    83         COUT(0) << "Loading level..." << std::endl;
    84         startLevel_ = new Level(Settings::getDataPath() + "levels/sample.oxw");
    85         Loader::open(startLevel_);
    86 
    87         // add console commands
    88         FunctorMember<GSLevel>* functor = createFunctor(&GSLevel::setTimeFactor);
    89         functor->setObject(this);
    90         CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "setTimeFactor"));
    91 
    92         // level is loaded: we can start capturing the input
    93         InputManager::getInstance().requestEnterState("game");
    9476    }
    9577
    9678    void GSLevel::leave()
    9779    {
    98         InputManager::getInstance().requestLeaveState("game");
    99 
    100         // TODO: Remove and destroy console command
    101 
    102         Loader::unload(startLevel_);
    103         delete this->startLevel_;
    104 
    10580        Loader::unload(hud_);
    10681        delete this->hud_;
     
    11691        // TODO: delete SceneManager
    11792
    118         InputManager::getInstance().destroyState("game");
     93        inputState_->setHandler(0);
     94        InputManager::getInstance().requestDestroyState("game");
    11995        delete this->keyBinder_;
    12096    }
    12197
    122     bool GSLevel::tick(float dt)
     98    void GSLevel::ticked(float dt)
    12399    {
    124100        // Call those objects that need the real time
     
    128104        for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it)
    129105            it->tick(dt * this->timefactor_);
    130 
    131         // TODO: split file into server/client/standalone
    132         // call server/client with normal dt
    133         //if (client_g)
    134         //    client_g->tick(dt * this->timefactor_);
    135         //if (server_g)
    136         //    server_g->tick(dt * this->timefactor_);
    137 
    138         return true;
    139106    }
    140107
     
    153120            it->setTimeFactor(timefactor_);
    154121    }
     122
     123    void GSLevel::loadLevel()
     124    {
     125        // call the loader
     126        COUT(0) << "Loading level..." << std::endl;
     127        startLevel_ = new Level(Settings::getDataPath() + "levels/sample.oxw");
     128        Loader::open(startLevel_);
     129    }
     130
     131    void GSLevel::unloadLevel()
     132    {
     133        Loader::unload(startLevel_);
     134        delete this->startLevel_;
     135    }
    155136}
  • code/branches/gui/src/orxonox/gamestates/GSLevel.h

    r1662 r1670  
    3838    {
    3939    public:
    40         GSLevel();
    41         ~GSLevel();
     40        GSLevel(const std::string& name);
     41        virtual ~GSLevel();
    4242
    43         bool tick(float dt);
     43        // this has to be public because proteced triggers a bug in msvc
     44        // when taking the function address.
     45        void setTimeFactor(float factor);
     46        float getTimeFactor() { return this->timefactor_; }
     47
     48    protected:
     49        virtual void enter();
     50        virtual void leave();
     51        virtual void ticked(float dt);
     52
     53        void loadLevel();
     54        void unloadLevel();
    4455
    4556    private:
    46         void enter();
    47         void leave();
    48 
    49         void setTimeFactor(float factor);
    5057
    5158        float timefactor_;       //!< A factor to change the gamespeed
    5259
    5360        KeyBinder*            keyBinder_;        //!< tool that loads and manages the input bindings
     61        SimpleInputState*     inputState_;
    5462        Radar*                radar_;            //!< represents the Radar (not the HUD part)
    5563        Level*                startLevel_;       //!< current hard coded default level
  • code/branches/gui/src/orxonox/gamestates/GSRoot.cc

    r1664 r1670  
    5252        , settings_(0)
    5353        , graphicsEngine_(0)
     54        , bExit_(false)
    5455    {
    5556    }
     
    101102
    102103        std::string dataPath;
    103         CommandLine::getCommandLineValue("dataPath", &dataPath);
     104        CommandLine::getValue("dataPath", &dataPath);
    104105        if (dataPath != "")
    105106        {
     
    122123        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "loadGame"));
    123124
    124         requestState("gui");
     125        // add console commands
     126        functor = createFunctor(&GSRoot::exitGame);
     127        functor->setObject(this);
     128        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "exit"));
    125129    }
    126130
     
    128132    {
    129133        delete graphicsEngine_;
     134        delete settings_;
    130135
    131         delete settings_;
     136        // TODO: remove and destroy console commands
    132137    }
    133138
    134     bool GSRoot::tick(float dt)
     139    void GSRoot::ticked(float dt)
    135140    {
    136         if (this->getActiveChild())
    137             this->getActiveChild()->tick(dt);
    138         return true;
     141        this->tickChild(dt);
    139142    }
    140143
  • code/branches/gui/src/orxonox/gamestates/GSRoot.h

    r1664 r1670  
    4242
    4343        void feedCommandLine(int argc, char** argv);
    44         bool tick(float dt);
    4544        void loadGame(const std::string& name);
     45
     46        void exitGame()
     47        { requestState("root"); }
     48        bool isGameFinished() { return (this->getActiveChild() == 0); }
    4649
    4750    private:
    4851        void enter();
    4952        void leave();
     53        void ticked(float dt);
    5054
    5155        Settings*             settings_;
    5256        GraphicsEngine*       graphicsEngine_;   //!< our dearest graphics engine <3
     57        bool                  bExit_;
    5358    };
    5459}
Note: See TracChangeset for help on using the changeset viewer.