Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2844


Ignore:
Timestamp:
Mar 25, 2009, 5:23:00 PM (15 years ago)
Author:
rgrieder
Message:

Implemented new GameState concept. It doesn't differ that much from the old one, but there's still lots of changes.
The most important change is that one GameState can occur multiple times in the hierarchy.

Short log:

  • No RootGameState anymore. Simply the highest is root.
  • Game::requestGameState(name) can refer to the parent, grandparent, great-grandparent, etc. or one of the children.
  • Requested states are saved. So if you select "level", the next request (even right after the call) will be relative to "level"
  • Game::popState() will simply unload the current one
  • Re added Main.cc again because Game as well as GameState have been moved to the core
  • Adapted all GameStates to the new system

Things should already work, except for network support because standalone only works with a little hack.
We can now start creating a better hierarchy.

Location:
code/branches/gui/src
Files:
2 deleted
27 edited
1 copied
2 moved

Legend:

Unmodified
Added
Removed
  • code/branches/gui/src/core/CMakeLists.txt

    r2710 r2844  
    2424  Core.cc
    2525  Event.cc
     26  Game.cc
    2627  GameState.cc
    2728  Language.cc
     
    2930  ObjectListBase.cc
    3031  OrxonoxClass.cc
    31   RootGameState.cc
    3232
    3333  # command
  • code/branches/gui/src/core/CorePrereqs.h

    r2817 r2844  
    166166
    167167  // game states
     168  class Game;
    168169  class GameState;
    169   class RootGameState;
     170  struct GameStateTreeNode;
    170171
    171172  // input
  • code/branches/gui/src/core/Game.cc

    r2843 r2844  
    3333*/
    3434
    35 #include "OrxonoxStableHeaders.h"
    3635#include "Game.h"
    3736
     
    4140#include "util/Debug.h"
    4241#include "util/Exception.h"
    43 #include "core/CommandLine.h"
    44 #include "core/ConsoleCommand.h"
    45 #include "core/Core.h"
    46 #include "core/Identifier.h"
    47 #include "core/CoreIncludes.h"
    48 #include "core/ConfigValueIncludes.h"
    49 
    50 #include "gamestates/GSRoot.h"
    51 #include "gamestates/GSGraphics.h"
    52 #include "gamestates/GSStandalone.h"
    53 #include "gamestates/GSServer.h"
    54 #include "gamestates/GSClient.h"
    55 #include "gamestates/GSDedicated.h"
    56 #include "gamestates/GSGUI.h"
    57 #include "gamestates/GSIOConsole.h"
    58 
    59 /*
    60 @brief
    61     Main method. Game starts here (except for static initialisations).
    62 */
    63 int main(int argc, char** argv)
    64 {
    65     {
    66         orxonox::Game orxonox(argc, argv);
    67         orxonox.run();
    68         // objects gets destroyed here!
    69     }
    70 
    71     // Clean up class hierarchy stuff (identifiers, xmlport, configvalue, consolecommand)
    72     // Needs to be done after Game destructor because of ~OrxonoxClass
    73     orxonox::Identifier::destroyAllIdentifiers();
    74 
    75     return 0;
    76 }
     42#include "Clock.h"
     43#include "CommandLine.h"
     44#include "ConsoleCommand.h"
     45#include "Core.h"
     46#include "CoreIncludes.h"
     47#include "ConfigValueIncludes.h"
     48#include "GameState.h"
    7749
    7850namespace orxonox
     
    8355    }
    8456
     57    struct _CoreExport GameStateTreeNode
     58    {
     59        GameState*                      state_;
     60        GameStateTreeNode*              parent_;
     61        std::vector<GameStateTreeNode*> children_;
     62    };
     63
    8564    SetCommandLineArgument(state, "gui").shortcut("s");
     65    SetCommandLineSwitch(startWithConsole);
    8666    SetConsoleCommandShortcutExternAlias(stop_game, "exit");
    8767
     68    std::map<std::string, GameState*> Game::allStates_s;
    8869    Game* Game::singletonRef_s = 0;
    8970
     
    9677        assert(singletonRef_s == 0);
    9778        singletonRef_s = this;
     79
     80        this->rootStateNode_ = 0;
     81        this->activeStateNode_ = 0;
    9882
    9983        this->abort_ = false;
     
    121105        // Destroy pretty much everyhting left
    122106        delete this->core_;
     107
     108        // Delete all GameStates created by the macros
     109        for (std::map<std::string, GameState*>::const_iterator it = allStates_s.begin(); it != allStates_s.end(); ++it)
     110            delete it->second;
    123111
    124112        assert(singletonRef_s);
     
    144132    void Game::run()
    145133    {
    146         // create the gamestates
    147         GSRoot root;
    148         GSGraphics graphics;
    149         GSStandalone standalone;
    150         GSServer server;
    151         GSClient client;
    152         GSDedicated dedicated;
    153         GSGUI gui;
    154         GSIOConsole ioConsole;
    155 
    156         // make the hierarchy
    157         root.addChild(&graphics);
    158         graphics.addChild(&standalone);
    159         graphics.addChild(&server);
    160         graphics.addChild(&client);
    161         graphics.addChild(&gui);
    162         root.addChild(&ioConsole);
    163         root.addChild(&dedicated);
    164 
    165         root.activate();
    166 
    167         // get initial state from command line
    168         root.gotoState(CommandLine::getValue("state"));
     134        // </EXPORT THIS>
     135        this->setStateHierarchy(
     136        "root"
     137        " graphics"
     138        "  gui"
     139        "  standalone"
     140        "   level"
     141        "  server"
     142        "   level"
     143        "  client"
     144        "   level"
     145        " dedicated"
     146        "  level"
     147        " ioConsole"
     148        );
     149        // </EXPORT THIS>
     150
     151
     152        // Always start with the root state
     153        this->requestedStateNodes_.push_back(this->rootStateNode_);
     154        this->activeStateNode_ = this->rootStateNode_;
     155        this->loadState(this->rootStateNode_->state_);
     156
     157        // <EXPORT THIS>
     158        if (CommandLine::getValue("startWithConsole").getBool())
     159        {
     160            // Start the game in the console
     161            this->requestState("ioConsole");
     162        }
     163        else
     164        {
     165            // Start in GUI main menu
     166            this->requestState("graphics");
     167            this->requestState("gui");
     168        }
     169        // </EXPORT THIS>
    169170
    170171        this->gameClock_->capture(); // first delta time should be about 0 seconds
    171         while (!this->abort_)
     172        while (!this->abort_ && !this->activeStates_.empty())
    172173        {
    173174            this->gameClock_->capture();
     
    179180            this->periodTime_ += this->gameClock_->getDeltaTimeMicroseconds();
    180181
    181             // UPDATE
    182             root.tick(*this->gameClock_);
     182            // UPDATE STATE STACK
     183            while (this->requestedStateNodes_.size() > 1)
     184            {
     185                // Note: this->requestedStateNodes_.front() is the currently active state node
     186                std::vector<GameStateTreeNode*>::iterator it = this->requestedStateNodes_.begin() + 1;
     187                if (*it == this->activeStateNode_->parent_)
     188                    this->unloadState(this->activeStateNode_->state_);
     189                else // has to be child
     190                    this->loadState((*it)->state_);
     191                this->activeStateNode_ = *it;
     192                this->requestedStateNodes_.erase(this->requestedStateNodes_.begin());
     193            }
     194
     195            // UPDATE, bottom to top in the stack
     196            for (std::vector<GameState*>::const_iterator it = this->activeStates_.begin();
     197                it != this->activeStates_.end(); ++it)
     198                (*it)->update(*this->gameClock_);
    183199
    184200            // STATISTICS
     
    206222                this->periodTime_ -= this->statisticsRefreshCycle_;
    207223            }
    208 
    209             if (root.stateRequest_ != "")
    210                 root.gotoState(root.stateRequest_);
    211         }
    212 
    213         root.gotoState("root");
    214         root.deactivate();
     224        }
     225
     226        // Unload all remaining states
     227        while (!this->activeStates_.empty())
     228            this->unloadState(this->activeStates_.back());
     229        this->activeStateNode_ = 0;
     230        this->requestedStateNodes_.clear();
    215231    }
    216232
     
    226242        this->periodTickTime_+=length;
    227243    }
     244
     245
     246    /***** GameState related *****/
     247
     248    void Game::requestState(const std::string& name)
     249    {
     250        GameState* state = this->getState(name);
     251        if (state == NULL || this->activeStateNode_ == NULL)
     252            return;
     253
     254        GameStateTreeNode* requestedNode = 0;
     255
     256        // this->requestedStateNodes_.back() is the currently active state
     257        GameStateTreeNode* lastRequestedNode = this->requestedStateNodes_.back();
     258
     259        // Already the active node?
     260        if (state == lastRequestedNode->state_)
     261        {
     262            COUT(2) << "Warning: Requesting the currently active state! Ignoring." << std::endl;
     263            return;
     264        }
     265
     266        // Check children first
     267        for (unsigned int i = 0; i < lastRequestedNode->children_.size(); ++i)
     268        {
     269            if (lastRequestedNode->children_[i]->state_ == state)
     270            {
     271                requestedNode = lastRequestedNode->children_[i];
     272                break;
     273            }
     274        }
     275
     276        // Check parent and all its grand parents
     277        GameStateTreeNode* currentNode = lastRequestedNode;
     278        while (requestedNode == NULL && currentNode->parent_ != NULL)
     279        {
     280            if (currentNode->state_ == state)
     281                requestedNode = currentNode;
     282            currentNode = currentNode->parent_;
     283        }
     284
     285        if (requestedNode == NULL)
     286            COUT(1) << "Error: Requested GameState transition is not allowed. Ignoring." << std::endl;
     287        else
     288            this->requestedStateNodes_.push_back(requestedNode);
     289    }
     290
     291    void Game::popState()
     292    {
     293        if (this->activeStateNode_ != NULL && this->requestedStateNodes_.back()->parent_)
     294            this->requestState(this->requestedStateNodes_.back()->parent_->state_->getName());
     295        else
     296            COUT(2) << "Warning: Could not pop GameState. Ignoring." << std::endl;
     297    }
     298
     299    GameState* Game::getState(const std::string& name)
     300    {
     301        std::map<std::string, GameState*>::const_iterator it = allStates_s.find(name);
     302        if (it != allStates_s.end())
     303            return it->second;
     304        else
     305        {
     306            COUT(1) << "Error: Could not find GameState '" << name << "'. Ignoring." << std::endl;
     307            return 0;
     308        }
     309    }
     310
     311    void Game::setStateHierarchy(const std::string& str)
     312    {
     313        // Split string into pieces of the form whitespacesText
     314        std::vector<std::pair<std::string, unsigned> > stateStrings;
     315        size_t pos = 0;
     316        size_t startPos = 0;
     317        while (pos < str.size())
     318        {
     319            unsigned indentation = 0;
     320            while(pos < str.size() && str[pos] == ' ')
     321                ++indentation, ++pos;
     322            startPos = pos;
     323            while(pos < str.size() && str[pos] != ' ')
     324                ++pos;
     325            stateStrings.push_back(std::pair<std::string, unsigned>(
     326                str.substr(startPos, pos - startPos), indentation));
     327        }
     328        unsigned int currentLevel = 0;
     329        GameStateTreeNode* currentNode = 0;
     330        for (std::vector<std::pair<std::string, unsigned> >::const_iterator it = stateStrings.begin(); it != stateStrings.end(); ++it)
     331        {
     332            std::string newStateName = it->first;
     333            unsigned newLevel = it->second;
     334            GameState* newState = this->getState(newStateName);
     335            if (!newState)
     336                ThrowException(GameState, std::string("GameState with name '") + newStateName + "' not found!");
     337            if (newLevel == 0)
     338            {
     339                // root
     340                if (this->rootStateNode_ != NULL)
     341                    ThrowException(GameState, "No two root GameStates are allowed!");
     342                GameStateTreeNode* newNode = new GameStateTreeNode;
     343                newNode->state_ = newState;
     344                newNode->parent_ = 0;
     345                this->rootStateNode_ = newNode;
     346                currentNode = this->rootStateNode_;
     347            }
     348            else if (currentNode)
     349            {
     350                GameStateTreeNode* newNode = new GameStateTreeNode;
     351                newNode->state_ = newState;
     352                if (newLevel < currentLevel)
     353                {
     354                    // Get down the hierarchy
     355                    do
     356                        currentNode = currentNode->parent_;
     357                    while (newLevel < --currentLevel);
     358                }
     359                if (newLevel == currentLevel)
     360                {
     361                    // same level
     362                    newNode->parent_ = currentNode->parent_;
     363                    newNode->parent_->children_.push_back(newNode);
     364                }
     365                else if (newLevel == currentLevel + 1)
     366                {
     367                    // child
     368                    newNode->parent_ = currentNode;
     369                    currentNode->children_.push_back(newNode);
     370                }
     371                else
     372                    ThrowException(GameState, "Indentation error while parsing the hierarchy.");
     373                currentNode = newNode;
     374                currentLevel = newLevel;
     375            }
     376            else
     377            {
     378                ThrowException(GameState, "No root GameState specified!");
     379            }
     380        }
     381    }
     382
     383    /*** Internal ***/
     384
     385    void Game::loadState(GameState* state)
     386    {
     387        state->activate();
     388        this->activeStates_.push_back(state);
     389    }
     390
     391    void Game::unloadState(orxonox::GameState* state)
     392    {
     393        state->deactivate();
     394        this->activeStates_.pop_back();
     395    }
     396
     397    /*static*/ bool Game::addGameState(GameState* state)
     398    {
     399        std::map<std::string, GameState*>::const_iterator it = allStates_s.find(state->getName());
     400        if (it == allStates_s.end())
     401            allStates_s[state->getName()] = state;
     402        else
     403            ThrowException(GameState, "Cannot add two GameStates with the same name to 'Game'.");
     404
     405        // just a required dummy return value
     406        return true;
     407    }
    228408}
  • code/branches/gui/src/core/Game.h

    r2843 r2844  
    3636#define _Game_H__
    3737
    38 #include "OrxonoxPrereqs.h"
     38#include "CorePrereqs.h"
    3939#include <cassert>
    4040#include <list>
    41 #include "core/OrxonoxClass.h"
     41#include <map>
     42#include <vector>
     43#include "OrxonoxClass.h"
     44
     45#define AddGameState(classname, name, ...) \
     46    static bool bGameStateDummy_##classname##__LINE__ = orxonox::Game::addGameState(new classname(name, __VA_ARGS__))
    4247
    4348namespace orxonox
     
    4752        Main class responsible for running the game.
    4853    */
    49     class _OrxonoxExport Game : public OrxonoxClass
     54    class _CoreExport Game : public OrxonoxClass
    5055    {
    5156    public:
     
    5459        void setConfigValues();
    5560
     61        void setStateHierarchy(const std::string& str);
     62        GameState* getState(const std::string& name);
     63
    5664        void run();
    5765        void stop();
     66
     67        void requestState(const std::string& name);
     68        void popState();
    5869
    5970        float getAvgTickTime() { return this->avgTickTime_; }
     
    6273        void addTickTime(uint32_t length);
    6374
     75        static bool addGameState(GameState* state);
    6476        static Game& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
    6577
     
    7385        Game(Game&); // don't mess with singletons
    7486
    75         Core* core_;
    76         Clock* gameClock_;
     87        void loadState(GameState* state);
     88        void unloadState(GameState* state);
    7789
    78         bool abort_;
     90        std::vector<GameState*>         activeStates_;
     91        GameStateTreeNode*              rootStateNode_;
     92        GameStateTreeNode*              activeStateNode_;
     93        std::vector<GameStateTreeNode*> requestedStateNodes_;
     94
     95        Core*                           core_;
     96        Clock*                          gameClock_;
     97
     98        bool                            abort_;
    7999
    80100        // variables for time statistics
    81         uint64_t              statisticsStartTime_;
    82         std::list<statisticsTickInfo>
    83                               statisticsTickTimes_;
    84         uint32_t              periodTime_;
    85         uint32_t              periodTickTime_;
    86         float                 avgFPS_;
    87         float                 avgTickTime_;
     101        uint64_t                        statisticsStartTime_;
     102        std::list<statisticsTickInfo>   statisticsTickTimes_;
     103        uint32_t                        periodTime_;
     104        uint32_t                        periodTickTime_;
     105        float                           avgFPS_;
     106        float                           avgTickTime_;
    88107
    89108        // config values
    90         unsigned int          statisticsRefreshCycle_;
    91         unsigned int          statisticsAvgLength_;
     109        unsigned int                    statisticsRefreshCycle_;
     110        unsigned int                    statisticsAvgLength_;
    92111
     112        static std::map<std::string, GameState*> allStates_s;
    93113        static Game* singletonRef_s;        //!< Pointer to the Singleton
    94114    };
  • code/branches/gui/src/core/GameState.cc

    r2817 r2844  
    3434
    3535#include "GameState.h"
     36#include <cassert>
    3637#include "util/Debug.h"
    3738#include "util/Exception.h"
     39#include "Clock.h"
    3840
    3941namespace orxonox
     
    4648        : name_(name)
    4749        , parent_(0)
    48         , activeChild_(0)
    49         //, bPausegetParent()(false)
    5050    {
    51         Operations temp = {false, false, false, false, false};
    52         this->operation_ = temp;
     51        State temp = {false, false, false, false, false};
     52        this->activity_ = temp;
    5353    }
    5454
     
    5959    GameState::~GameState()
    6060    {
    61         OrxAssert(this->operation_.active == false, "Deleting an active GameState is a very bad idea..");
     61        OrxAssert(this->activity_.active == false, "Deleting an active GameState is a very bad idea..");
    6262    }
    6363
     
    7171    void GameState::addChild(GameState* state)
    7272    {
    73         if (!state)
    74             return;
    75         // check if the state/tree to be added has states in it that already exist in this tree.
    76         for (std::map<std::string, GameState*>::const_iterator it = state->allChildren_.begin();
    77             it != state->allChildren_.end(); ++it)
     73        assert(state != NULL);
     74
     75        std::map<std::string, GameState*>::const_iterator it = this->children_.find(state->getName());
     76        if (it == this->children_.end())
    7877        {
    79             if (this->getState(it->second->getName()))
    80             {
    81                 ThrowException(GameState, "Cannot add a GameState to the hierarchy twice.");
    82                 return;
    83             }
     78            this->children_[state->getName()] = state;
     79            // mark us as parent
     80            state->setParent(this);
    8481        }
    85         if (this->getState(state->name_))
     82        else
    8683        {
    87             ThrowException(GameState, "Cannot add a GameState to the hierarchy twice.");
    88             return;
     84            ThrowException(GameState, "Cannot add two children with the same name");
    8985        }
    90         // Make sure we don't add a tree that already has an active state.
    91         if (state->getCurrentState())
    92         {
    93             ThrowException(GameState, "Cannot merge a tree that is already active.");
    94             return;
    95         }
    96 
    97         // merge the child's children into this tree
    98         for (std::map<std::string, GameState*>::const_iterator it = state->allChildren_.begin();
    99             it != state->allChildren_.end(); ++it)
    100             this->grandchildAdded(state, it->second);
    101         // merge 'state' into this tree
    102         this->grandchildAdded(state, state);
    103 
    104         // mark us as parent
    105         state->setParent(this);
    10686    }
    10787
     
    11595    void GameState::removeChild(GameState* state)
    11696    {
    117         std::map<GameState*, GameState*>::iterator it = this->grandchildrenToChildren_.find(state);
    118         if (it != this->grandchildrenToChildren_.end())
    119         {
    120             if (state->isInSubtree(getCurrentState()))
    121             {
    122                 ThrowException(GameState, "Cannot remove an active game state child '"
    123                     + state->getName() + "' from '" + name_ + "'.");
    124                 //COUT(2) << "Warning: Cannot remove an active game state child '" << state->getName()
    125                 //    << "' from '" << name_ << "'." << std::endl;
    126             }
    127             else
    128             {
    129                 for (std::map<GameState*, GameState*>::const_iterator it = state->grandchildrenToChildren_.begin();
    130                     it != state->grandchildrenToChildren_.end(); ++it)
    131                     this->grandchildRemoved(it->first);
    132                 this->grandchildRemoved(state);
    133             }
    134         }
     97        assert(state != NULL);
     98
     99        std::map<std::string, GameState*>::iterator it = this->children_.find(state->getName());
     100        if (it != this->children_.end())
     101            this->children_.erase(it);
    135102        else
    136103        {
    137104            ThrowException(GameState, "Game state '" + name_ + "' doesn't have a child named '"
    138105                + state->getName() + "'.");
    139             //COUT(2) << "Warning: Game state '" << name_ << "' doesn't have a child named '"
    140             //    << state->getName() << "'. Removal skipped." << std::endl;
    141106        }
    142107    }
    143108
    144     /**
    145     @brief
    146         Removes a child by name. This splits the tree in two parts,
    147         each of them functional on its own.
    148     @param state
    149         GameState by name
    150     */
    151 
    152     void GameState::removeChild(const std::string& name)
     109    void GameState::activateInternal()
    153110    {
    154         GameState* state = getState(name);
    155         if (state)
    156         {
    157             removeChild(state);
    158         }
    159         else
    160         {
    161             ThrowException(GameState, "GameState '" + name + "' doesn't exist.");
    162             //COUT(2) << "Warning: GameState '" << name << "' doesn't exist." << std::endl;
    163         }
     111        this->activity_.activating = true;
     112        this->activate();
     113        this->activity_.activating = false;
     114        this->activity_.active = true;
    164115    }
    165116
    166     /**
    167     @brief
    168         Tells a state that one of its children has added a child. This is necessary
    169         to fill the internal maps correctly.
    170     @param child
    171         The child who notices this state.
    172     @param grandchild
    173         The child that has been added.
    174     */
    175     inline void GameState::grandchildAdded(GameState* child, GameState* grandchild)
     117    void GameState::deactivateInternal()
    176118    {
    177         // fill the two maps correctly.
    178         this->allChildren_[grandchild->getName()] = grandchild;
    179         this->grandchildrenToChildren_[grandchild] = child;
    180         if (this->getParent())
    181             this->getParent()->grandchildAdded(this, grandchild);
     119        this->activity_.active = false;
     120        this->activity_.deactivating = true;
     121        this->activate();
     122        this->activity_.deactivating = false;
     123        this->activity_.suspended = false;
     124        this->activity_.updating = false;
    182125    }
    183126
    184     /**
    185     @brief
    186         Tells a state that one of its children has removed a child. This is necessary
    187         to fill the internal maps correctly.
    188     @param child
    189         The child who notices this state.
    190     @param grandchild
    191         The child that has been removed.
    192     */
    193     inline void GameState::grandchildRemoved(GameState* grandchild)
     127    void GameState::updateInternal(const Clock& time)
    194128    {
    195         // adjust the two maps correctly.
    196         this->allChildren_.erase(grandchild->getName());
    197         this->grandchildrenToChildren_.erase(grandchild);
    198         if (this->getParent())
    199             this->getParent()->grandchildRemoved(grandchild);
    200     }
    201 
    202     /**
    203     @brief
    204         Checks whether a specific game states exists in the hierarchy.
    205     @remarks
    206         Remember that the every node has a map with all its child nodes.
    207     */
    208     GameState* GameState::getState(const std::string& name)
    209     {
    210         if (this->getParent())
    211             return this->getParent()->getState(name);
    212         else
    213         {
    214             // The map only contains children, so check ourself first
    215             if (name == this->name_)
    216                 return this;
    217             // Search in the map. If there is no entry, we can be sure the state doesn't exist.
    218             std::map<std::string, GameState*>::const_iterator it = this->allChildren_.find(name);
    219             return (it!= this->allChildren_.end() ? it->second : 0);
    220         }
    221     }
    222 
    223     /**
    224     @brief
    225         Returns the root node of the tree.
    226     */
    227     GameState* GameState::getRoot()
    228     {
    229         if (this->getParent())
    230             return this->getParent()->getRoot();
    231         else
    232             return this;
    233     }
    234 
    235     /**
    236     @brief
    237         Returns the current active state.
    238     @remarks
    239         Remember that the current active state is the one that does not
    240         have active children itself. Many states can be active at once.
    241     */
    242     GameState* GameState::getCurrentState()
    243     {
    244         if (this->operation_.active)
    245         {
    246             if (this->activeChild_)
    247                 return this->activeChild_->getCurrentState();
    248             else
    249                 return this;
    250         }
    251         else
    252         {
    253             if (this->getParent())
    254                 return this->getParent()->getCurrentState();
    255             else
    256                 return 0;
    257         }
    258     }
    259 
    260     /**
    261     @brief
    262         Determines whether 'state' is in this subtree, including this node.
    263     */
    264     bool GameState::isInSubtree(GameState* state) const
    265     {
    266         return (grandchildrenToChildren_.find(state) != grandchildrenToChildren_.end()
    267                 || state == this);
    268     }
    269 
    270     /**
    271     @brief
    272         Makes a state transition according to the state tree. You can choose any state
    273         in the tree to do the call. The function finds the current state on its own.
    274     @param state
    275         The state to be entered, has to exist in the tree.
    276     */
    277     void GameState::requestState(const std::string& name)
    278     {
    279         assert(getRoot());
    280         getRoot()->requestState(name);
    281     }
    282 
    283     /**
    284     @brief
    285         Internal method that actually makes the state transition. Since it is internal,
    286         the method can assume certain things to be granted (like 'this' is always active).
    287     */
    288     void GameState::makeTransition(GameState* source, GameState* destination)
    289     {
    290         if (source == this->getParent())
    291         {
    292             // call is from the parent
    293             this->activate();
    294         }
    295         else if (source == 0)
    296         {
    297             // call was just started by root
    298             // don't do anyting yet
    299         }
    300         else
    301         {
    302             // call is from a child
    303             this->activeChild_ = 0;
    304         }
    305 
    306         if (destination == this)
    307             return;
    308 
    309         // Check for 'destination' in the children map first
    310         std::map<GameState*, GameState*>::const_iterator it
    311             = this->grandchildrenToChildren_.find(destination);
    312         if (it != this->grandchildrenToChildren_.end())
    313         {
    314             // child state. Don't use 'state', might be a grandchild!
    315             this->activeChild_ = it->second;
    316             it->second->makeTransition(this, destination);
    317         }
    318         else
    319         {
    320             // parent. We can be sure of this.
    321             assert(this->getParent() != 0);
    322 
    323             this->deactivate();
    324             this->getParent()->makeTransition(this, destination);
    325         }
    326     }
    327 
    328     /**
    329     @brief
    330         Activates the state. Only sets bActive_ to true and notifies the parent.
    331     */
    332     void GameState::activate()
    333     {
    334         this->operation_.active = true;
    335         this->operation_.entering = true;
    336         this->enter();
    337         this->operation_.entering = false;
    338     }
    339 
    340     /**
    341         Activates the state. Only sets bActive_ to false and notifies the parent.
    342     */
    343     void GameState::deactivate()
    344     {
    345         this->operation_.leaving = true;
    346         this->leave();
    347         this->operation_.leaving = false;
    348         this->operation_.active = false;
    349     }
    350 
    351     /**
    352     @brief
    353         Update method that calls ticked() with enclosed bRunning_ = true
    354         If there was a state transition request within ticked() then this
    355         method will transition in the end.
    356     @param dt Delta time
    357     @note
    358         This method is not virtual! You cannot override it therefore.
    359     */
    360     void GameState::tick(const Clock& time)
    361     {
    362         this->operation_.running = true;
    363         this->ticked(time);
    364         this->operation_.running = false;
     129        this->activity_.updating = true;
     130        this->update(time);
     131        this->activity_.updating = false;
    365132    }
    366133}
  • code/branches/gui/src/core/GameState.h

    r2817 r2844  
    3939
    4040#include <string>
    41 #include <vector>
    4241#include <map>
    43 #include <cassert>
    44 #include "Clock.h"
     42#include "CorePrereqs.h"
    4543
    4644namespace orxonox
     
    6260    class _CoreExport GameState
    6361    {
    64         friend class RootGameState;
    65         // Hack
    6662        friend class Game;
    6763
     
    7167            Gives information about what the GameState is currently doing
    7268        */
    73         struct Operations
     69        struct State
    7470        {
    75             unsigned active    : 1;
    76             unsigned entering  : 1;
    77             unsigned leaving  : 1;
    78             unsigned running   : 1;
    79             unsigned suspended : 1;
     71            unsigned active       : 1;
     72            unsigned activating   : 1;
     73            unsigned deactivating : 1;
     74            unsigned updating     : 1;
     75            unsigned suspended    : 1;
    8076        };
    8177
     
    8581
    8682        const std::string& getName() const { return name_; }
    87         const Operations getOperation() const { return this->operation_; }
    88         bool isInSubtree(GameState* state) const;
    89 
    90         GameState* getState(const std::string& name);
    91         GameState* getRoot();
    92         //! Returns the currently active game state
    93         virtual GameState* getCurrentState();
    94 
    95         virtual void requestState(const std::string& name);
     83        const State getActivity() const    { return this->activity_; }
     84        GameState* getParent() const       { return this->parent_; }
    9685
    9786        void addChild(GameState* state);
    9887        void removeChild(GameState* state);
    99         void removeChild(const std::string& name);
    10088
    10189    protected:
    102         virtual void enter() = 0;
    103         virtual void leave() = 0;
    104         virtual void ticked(const Clock& time) = 0;
    105 
    106         GameState* getActiveChild() { return this->activeChild_; }
    107 
    108         void tickChild(const Clock& time) { if (this->getActiveChild()) this->getActiveChild()->tick(time); }
    109 
    110         GameState* getParent() const     { return this->parent_; }
    111         void setParent(GameState* state) { this->parent_ = state; }
     90        virtual void activate() = 0;
     91        virtual void deactivate() = 0;
     92        virtual void update(const Clock& time) = 0;
    11293
    11394    private:
    114         //! Performs a transition to 'destination'
    115         virtual void makeTransition(GameState* source, GameState* destination);
    116 
    117         void grandchildAdded(GameState* child, GameState* grandchild);
    118         void grandchildRemoved(GameState* grandchild);
    119 
    120         void tick(const Clock& time);
    121         void activate();
    122         void deactivate();
     95        void setParent(GameState* state) { this->parent_ = state; }
     96        void setActivity(State activity);
     97        void activateInternal();
     98        void deactivateInternal();
     99        void updateInternal(const Clock& time);
    123100
    124101        const std::string                        name_;
    125         Operations                               operation_;
     102        State                                    activity_;
    126103        GameState*                               parent_;
    127         GameState*                               activeChild_;
    128         //bool                                     bPauseParent_;
    129         std::map<std::string, GameState*>        allChildren_;
    130         std::map<GameState*, GameState*>         grandchildrenToChildren_;
     104        std::map<std::string, GameState*>        children_;
    131105    };
    132106}
  • code/branches/gui/src/network/Server.h

    r2800 r2844  
    5353  const int CLIENTID_SERVER = 0;
    5454  const unsigned int NETWORK_FREQUENCY = 25;
    55   const float NETWORK_PERIOD = 1./NETWORK_FREQUENCY;
     55  const float NETWORK_PERIOD = 1.f/NETWORK_FREQUENCY;
    5656
    5757  /**
  • code/branches/gui/src/orxonox/CMakeLists.txt

    r2805 r2844  
    2020SET_SOURCE_FILES(ORXONOX_SRC_FILES
    2121  CameraManager.cc
    22   Game.cc
    2322  GraphicsManager.cc
    2423  LevelManager.cc
     24  Main.cc
    2525  PawnManager.cc
    2626  PlayerManager.cc
  • code/branches/gui/src/orxonox/Main.cc

    r2801 r2844  
    3636#include "OrxonoxConfig.h"
    3737
    38 #include <exception>
    39 #include <cassert>
     38#include "util/Debug.h"
     39#include "core/Identifier.h"
     40#include "core/Game.h"
    4041
    41 #include "util/Debug.h"
    42 #include "core/Core.h"
    43 #include "core/Identifier.h"
    44 
    45 #include "gamestates/GSRoot.h"
    46 #include "gamestates/GSGraphics.h"
    47 #include "gamestates/GSStandalone.h"
    48 #include "gamestates/GSServer.h"
    49 #include "gamestates/GSClient.h"
    50 #include "gamestates/GSDedicated.h"
    51 #include "gamestates/GSGUI.h"
    52 #include "gamestates/GSIOConsole.h"
    53 
    54 #ifdef ORXONOX_PLATFORM_APPLE
    55 #include <CoreFoundation/CoreFoundation.h>
    56 
    57 // This function will locate the path to our application on OS X,
    58 // unlike windows you can not rely on the curent working directory
    59 // for locating your configuration files and resources.
    60              std::string macBundlePath()
    61 {
    62     char path[1024];
    63     CFBundleRef mainBundle = CFBundleGetMainBundle();
    64     assert(mainBundle);
    65 
    66     CFURLRef mainBundleURL = CFBundleCopyBundleURL(mainBundle);
    67     assert(mainBundleURL);
    68 
    69     CFStringRef cfStringRef = CFURLCopyFileSystemPath( mainBundleURL, kCFURLPOSIXPathStyle);
    70     assert(cfStringRef);
    71 
    72     CFStringGetCString(cfStringRef, path, 1024, kCFStringEncodingASCII);
    73 
    74     CFRelease(mainBundleURL);
    75     CFRelease(cfStringRef);
    76 
    77     return std::string(path);
    78 }
    79 #endif
    80 
    81 
    82 
     42/*
     43@brief
     44    Main method. Game starts here (except for static initialisations).
     45*/
    8346int main(int argc, char** argv)
    8447{
    85     orxonox::Core* core = new orxonox::Core(argc, argv);
    86     if (!core->isLoaded())
    8748    {
    88         COUT(0) << "Core was not fully loaded, probably an exception occurred during consruction. Aborting" << std::endl;
    89         abort();
    90     }
    91 
    92     // put GameStates in its own scope so we can destroy the identifiers at the end of main().
    93     {
    94         using namespace orxonox;
    95         // create the gamestates
    96         GSRoot root;
    97         GSGraphics graphics;
    98         GSStandalone standalone;
    99         GSServer server;
    100         GSClient client;
    101         GSDedicated dedicated;
    102         GSGUI gui;
    103         GSIOConsole ioConsole;
    104 
    105         // make the hierarchy
    106         root.addChild(&graphics);
    107         graphics.addChild(&standalone);
    108         graphics.addChild(&server);
    109         graphics.addChild(&client);
    110         graphics.addChild(&gui);
    111         root.addChild(&ioConsole);
    112         root.addChild(&dedicated);
    113 
    114         // Here happens the game
    115         root.start();
    116     }
    117 
    118     // Destroy pretty much everyhting left
    119     delete core;
     49        orxonox::Game orxonox(argc, argv);
     50        orxonox.run();
     51    } // orxonox gets destroyed right here!
    12052
    12153    // Clean up class hierarchy stuff (identifiers, xmlport, configvalue, consolecommand)
    122     // Needs to be done after 'delete core' because of ~OrxonoxClass
     54    // Needs to be done after Game destructor because of ~OrxonoxClass
    12355    orxonox::Identifier::destroyAllIdentifiers();
    12456
  • code/branches/gui/src/orxonox/OrxonoxPrereqs.h

    r2801 r2844  
    7777    namespace MunitionType
    7878    {
    79 
    80 
    81 
    8279        enum Enum
    8380        { laserGunMunition };
     
    238235    //gui
    239236    class GUIManager;
    240 
    241     // game states
    242     class GSRoot;
    243     class GSGraphics;
    244     class GSIO;
    245     class GSIOConsole;
    246     class GSLevel;
    247     class GSStandalone;
    248     class GSServer;
    249     class GSClient;
    250     class GSGUI;
    251237}
    252238
  • code/branches/gui/src/orxonox/gamestates/GSClient.cc

    r2817 r2844  
    3535#include "core/Core.h"
    3636#include "network/Client.h"
     37#include "core/Game.h"
    3738
    3839namespace orxonox
    3940{
     41    AddGameState(GSClient, "client");
     42
    4043    SetCommandLineArgument(ip, "127.0.0.1").information("#.#.#.#");
    4144
    42     GSClient::GSClient()
    43         : GameState("client")
     45    GSClient::GSClient(const std::string& name)
     46        : GameState(name)
    4447        , client_(0)
    4548    {
     
    5053    }
    5154
    52     void GSClient::enter()
     55    void GSClient::activate()
    5356    {
    5457        Core::setIsClient(true);
     
    5962            ThrowException(InitialisationFailed, "Could not establish connection with server.");
    6063
    61         GSLevel::enter();
    62 
    6364        client_->update(Core::getGameClock());
    6465    }
    6566
    66     void GSClient::leave()
     67    void GSClient::deactivate()
    6768    {
    68         GSLevel::leave();
    69 
    7069        client_->closeConnection();
    7170
     
    7675    }
    7776
    78     void GSClient::ticked(const Clock& time)
     77    void GSClient::update(const Clock& time)
    7978    {
    80         GSLevel::ticked(time);
    8179        client_->update(time);
    82 
    83         this->tickChild(time);
    8480    }
    8581}
  • code/branches/gui/src/orxonox/gamestates/GSClient.h

    r2817 r2844  
    3333#include "core/GameState.h"
    3434#include "network/NetworkPrereqs.h"
    35 #include "GSLevel.h"
    3635
    3736namespace orxonox
    3837{
    39     class _OrxonoxExport GSClient : public GameState, public GSLevel
     38    class _OrxonoxExport GSClient : public GameState
    4039    {
    4140    public:
    42         GSClient();
     41        GSClient(const std::string& name);
    4342        ~GSClient();
    4443
     44        void activate();
     45        void deactivate();
     46        void update(const Clock& time);
    4547
    4648    private:
    47         void enter();
    48         void leave();
    49         void ticked(const Clock& time);
    50 
    5149        Client* client_;
    5250    };
  • code/branches/gui/src/orxonox/gamestates/GSDedicated.cc

    r2817 r2844  
    3737#include "objects/Tickable.h"
    3838#include "util/Sleep.h"
     39#include "core/Game.h"
    3940
    4041namespace orxonox
    4142{
    42     GSDedicated::GSDedicated()
    43         : GameState("dedicated")
     43    AddGameState(GSDedicated, "dedicated");
     44
     45    GSDedicated::GSDedicated(const std::string& name)
     46        : GameState(name)
    4447        , server_(0)
    4548        , timeSinceLastUpdate_(0)
     
    5154    }
    5255
    53     void GSDedicated::enter()
     56    void GSDedicated::activate()
    5457    {
    5558        Core::setHasServer(true);
     
    5861        COUT(0) << "Loading scene in server mode" << std::endl;
    5962
    60         GSLevel::enter();
    61 
    6263        server_->open();
    6364    }
    6465
    65     void GSDedicated::leave()
     66    void GSDedicated::deactivate()
    6667    {
    67         GSLevel::leave();
    68 
    6968        this->server_->close();
    7069        delete this->server_;
     
    7372    }
    7473
    75     void GSDedicated::ticked(const Clock& time)
     74    void GSDedicated::update(const Clock& time)
    7675    {
    7776//        static float startTime = time.getSecondsPrecise();
     
    8382//            COUT(0) << "estimated ticks/sec: " << nrOfTicks/(time.getSecondsPrecise()-startTime) << endl;
    8483            timeSinceLastUpdate_ -= static_cast<unsigned int>(timeSinceLastUpdate_ / NETWORK_PERIOD) * NETWORK_PERIOD;
    85             GSLevel::ticked(time);
    8684            server_->update(time);
    87             this->tickChild(time);
    8885        }
    8986        else
  • code/branches/gui/src/orxonox/gamestates/GSDedicated.h

    r2817 r2844  
    3333#include "core/GameState.h"
    3434#include "network/NetworkPrereqs.h"
    35 #include "GSLevel.h"
    3635
    3736namespace orxonox
    3837{
    39     class _OrxonoxExport GSDedicated : public GameState, public GSLevel
     38    class _OrxonoxExport GSDedicated : public GameState
    4039    {
    4140    public:
    42         GSDedicated();
     41        GSDedicated(const std::string& name);
    4342        ~GSDedicated();
    4443
     44        void activate();
     45        void deactivate();
     46        void update(const Clock& time);
     47
    4548    private:
    46         void enter();
    47         void leave();
    48         void ticked(const Clock& time);
    49 
    50         Server*      server_;
    51         float        timeSinceLastUpdate_;
     49        Server* server_;
     50        float   timeSinceLastUpdate_;
    5251    };
    5352}
  • code/branches/gui/src/orxonox/gamestates/GSGUI.cc

    r2817 r2844  
    3232#include <OgreViewport.h>
    3333#include "core/Clock.h"
     34#include "core/ConsoleCommand.h"
    3435#include "core/input/InputManager.h"
    3536#include "core/input/SimpleInputState.h"
    3637#include "gui/GUIManager.h"
    3738#include "GraphicsManager.h"
     39#include "core/Game.h"
    3840
    3941namespace orxonox
    4042{
    41     GSGUI::GSGUI()
    42         : GameState("gui")
     43    AddGameState(GSGUI, "gui");
     44
     45    GSGUI::GSGUI(const std::string& name)
     46        : GameState(name)
    4347    {
    4448    }
     
    4852    }
    4953
    50     void GSGUI::enter()
     54    void GSGUI::activate()
    5155    {
    5256        guiManager_ = GUIManager::getInstancePtr();
     
    5660        guiManager_->showGUI("MainMenu", 0);
    5761        GraphicsManager::getInstance().getViewport()->setCamera(guiManager_->getCamera());
     62
     63        {
     64            // time factor console command
     65            FunctorMember<GSGUI>* functor = createFunctor(&GSGUI::startGame);
     66            functor->setObject(this);
     67            this->ccStartGame_ = createConsoleCommand(functor, "startGame");
     68            CommandExecutor::addConsoleCommandShortcut(this->ccStartGame_);
     69        }
    5870    }
    5971
    60     void GSGUI::leave()
     72    void GSGUI::deactivate()
    6173    {
     74        if (this->ccStartGame_)
     75        {
     76            delete this->ccStartGame_;
     77            this->ccStartGame_ = 0;
     78        }
     79
    6280        guiManager_->hideGUI();
    6381    }
    6482
    65     void GSGUI::ticked(const Clock& time)
     83    void GSGUI::update(const Clock& time)
    6684    {
    6785        // tick CEGUI
    6886        guiManager_->update(time);
     87    }
    6988
    70         this->tickChild(time);
     89    void GSGUI::startGame()
     90    {
     91        // HACK - HACK
     92        Game::getInstance().popState();
     93        Game::getInstance().requestState("standalone");
     94        Game::getInstance().requestState("level");
    7195    }
    7296}
  • code/branches/gui/src/orxonox/gamestates/GSGUI.h

    r2817 r2844  
    3838    {
    3939    public:
    40         GSGUI();
     40        GSGUI(const std::string& name);
    4141        ~GSGUI();
    4242
     43        void activate();
     44        void deactivate();
     45        void update(const Clock& time);
     46
     47        void startGame();
     48
    4349    private:
    44         void enter();
    45         void leave();
    46         void ticked(const Clock& time);
     50        GUIManager* guiManager_;
    4751
    48         GUIManager* guiManager_;
     52        // console commands
     53        ConsoleCommand* ccStartGame_;
    4954    };
    5055}
  • code/branches/gui/src/orxonox/gamestates/GSGraphics.cc

    r2817 r2844  
    4545#include "gui/GUIManager.h"
    4646#include "GraphicsManager.h"
    47 #include "Game.h"
     47#include "core/Game.h"
    4848
    4949namespace orxonox
    5050{
    51     GSGraphics::GSGraphics()
    52         : GameState("graphics")
     51    AddGameState(GSGraphics, "graphics");
     52
     53    GSGraphics::GSGraphics(const std::string& name)
     54        : GameState(name)
    5355        , inputManager_(0)
    5456        , console_(0)
     
    6062    {
    6163        RegisterRootObject(GSGraphics);
    62         setConfigValues();
    6364    }
    6465
     
    7172    }
    7273
    73     void GSGraphics::enter()
     74    void GSGraphics::activate()
    7475    {
     76        setConfigValues();
     77
    7578        Core::setShowsGraphics(true);
    7679
     
    108111    }
    109112
    110     void GSGraphics::leave()
     113    void GSGraphics::deactivate()
    111114    {
    112115        if (Core::showsGraphics())
     
    146149        need the time. So we shouldn't run into problems.
    147150    */
    148     void GSGraphics::ticked(const Clock& time)
     151    void GSGraphics::update(const Clock& time)
    149152    {
    150153        uint64_t timeBeforeTick = time.getRealMicroseconds();
     
    152155        this->inputManager_->update(time);        // tick console
    153156        this->console_->update(time);
    154         this->tickChild(time);
    155157
    156158        uint64_t timeAfterTick = time.getRealMicroseconds();
  • code/branches/gui/src/orxonox/gamestates/GSGraphics.h

    r2817 r2844  
    3232#include "OrxonoxPrereqs.h"
    3333#include "core/GameState.h"
    34 #include "core/OrxonoxClass.h"
    3534#include "tools/WindowEventListener.h"
    3635
     
    3938    class _OrxonoxExport GSGraphics : public GameState, public WindowEventListener
    4039    {
    41         friend class ClassIdentifier<GSGraphics>;
    42 
    4340    public:
    44         GSGraphics();
     41        GSGraphics(const std::string& name);
    4542        ~GSGraphics();
    46 
    47     private: // functions
    48         void enter();
    49         void leave();
    50         void ticked(const Clock& time);
    51 
    5243        void setConfigValues();
    5344
     45        void activate();
     46        void deactivate();
     47        void update(const Clock& time);
     48
     49    private:
    5450        // Window events from WindowEventListener
    5551        void windowResized(unsigned int newWidth, unsigned int newHeight);
    5652        void windowFocusChanged();
    5753
    58     private:
    5954        // managed singletons
    6055        InputManager*         inputManager_;
  • code/branches/gui/src/orxonox/gamestates/GSIOConsole.cc

    r2817 r2844  
    3636
    3737#include "core/ConsoleCommand.h"
     38#include "core/Game.h"
    3839
    3940namespace orxonox
    4041{
    41     GSIOConsole::GSIOConsole()
    42         : GameState("ioConsole")
     42    AddGameState(GSIOConsole, "ioConsole");
     43
     44    GSIOConsole::GSIOConsole(const std::string& name)
     45        : GameState(name)
    4346    {
    4447    }
     
    4851    }
    4952
    50     void GSIOConsole::enter()
     53    void GSIOConsole::activate()
    5154    {
    5255    }
    5356
    54     void GSIOConsole::leave()
     57    void GSIOConsole::deactivate()
    5558    {
    5659    }
    5760
    58     void GSIOConsole::ticked(const Clock& time)
     61    void GSIOConsole::update(const Clock& time)
    5962    {
    6063        std::string command;
    6164        std::getline(std::cin, command);
    6265        CommandExecutor::execute(command, true);
    63        
    64         tickChild(time);
    6566    }
    6667}
  • code/branches/gui/src/orxonox/gamestates/GSIOConsole.h

    r2817 r2844  
    3131
    3232#include "OrxonoxPrereqs.h"
    33 #include <OgrePrerequisites.h>
    3433#include "core/GameState.h"
    3534
     
    3938    {
    4039    public:
    41         GSIOConsole();
     40        GSIOConsole(const std::string& name);
    4241        ~GSIOConsole();
    4342
     43        void activate();
     44        void deactivate();
     45        void update(const Clock& time);
     46
    4447    private:
    45         void enter();
    46         void leave();
    47         void ticked(const Clock& time);
     48
    4849    };
    4950}
  • code/branches/gui/src/orxonox/gamestates/GSLevel.cc

    r2817 r2844  
    4747#include "LevelManager.h"
    4848#include "PlayerManager.h"
     49#include "core/Game.h"
    4950
    5051namespace orxonox
    5152{
     53    AddGameState(GSLevel, "level");
     54
    5255    SetCommandLineArgument(level, "presentation.oxw").shortcut("l");
    5356
    54     GSLevel::GSLevel()
    55 //        : GameState(name)
    56         : keyBinder_(0)
     57    GSLevel::GSLevel(const std::string& name)
     58        : GameState(name)
     59        , keyBinder_(0)
    5760        , inputState_(0)
    5861        , radar_(0)
     
    6568        this->ccKeybind_ = 0;
    6669        this->ccTkeybind_ = 0;
    67 
     70    }
     71
     72    GSLevel::~GSLevel()
     73    {
     74    }
     75
     76    void GSLevel::setConfigValues()
     77    {
     78        SetConfigValue(keyDetectorCallbackCode_, "KeybindBindingStringKeyName=");
     79    }
     80
     81    void GSLevel::activate()
     82    {
    6883        setConfigValues();
    69     }
    70 
    71     GSLevel::~GSLevel()
    72     {
    73     }
    74 
    75     void GSLevel::setConfigValues()
    76     {
    77         SetConfigValue(keyDetectorCallbackCode_, "KeybindBindingStringKeyName=");
    78     }
    79 
    80     void GSLevel::enter()
    81     {
     84
    8285        if (Core::showsGraphics())
    8386        {
     
    126129    }
    127130
    128     void GSLevel::leave()
     131    void GSLevel::deactivate()
    129132    {
    130133        // destroy console commands
     
    188191    }
    189192
    190     void GSLevel::ticked(const Clock& time)
    191     {
    192         // Commented by 1337: Temporarily moved to GSGraphics.
     193    void GSLevel::update(const Clock& time)
     194    {
     195        // Note: Temporarily moved to GSGraphics.
    193196        //// Call the scene objects
    194197        //for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it)
     
    233236        Command string that can be executed by the CommandExecutor
    234237        OR: Internal string "KeybindBindingStringKeyName=" used for the second call to identify
    235         the key/button/axis that has been activated. This is configured above in enter().
     238        the key/button/axis that has been activated. This is configured above in activate().
    236239    */
    237240    void GSLevel::keybindInternal(const std::string& command, bool bTemporary)
  • code/branches/gui/src/orxonox/gamestates/GSLevel.h

    r2817 r2844  
    3131
    3232#include "OrxonoxPrereqs.h"
     33#include "core/OrxonoxClass.h"
    3334#include "core/GameState.h"
    34 #include "core/OrxonoxClass.h"
    3535
    3636namespace orxonox
    3737{
    38     class _OrxonoxExport GSLevel : public OrxonoxClass
     38    class _OrxonoxExport GSLevel : public GameState, public OrxonoxClass
    3939    {
    40         friend class ClassIdentifier<GSLevel>;
    4140    public:
    42         GSLevel();
     41        GSLevel(const std::string& name);
    4342        ~GSLevel();
    44 
    45         // was private before (is public now because of console command in GSStandalone)
    4643        void setConfigValues();
    4744
     45        void activate();
     46        void deactivate();
     47        void update(const Clock& time);
     48
    4849    protected:
    49         void enter();
    50         void leave();
    51         void ticked(const Clock& time);
    52 
    5350        void loadLevel();
    5451        void unloadLevel();
  • code/branches/gui/src/orxonox/gamestates/GSRoot.cc

    r2843 r2844  
    3232#include "util/Exception.h"
    3333#include "util/Debug.h"
     34#include "core/Clock.h"
    3435#include "core/Core.h"
    35 #include "core/CoreIncludes.h"
    3636#include "core/ConsoleCommand.h"
    3737#include "tools/TimeFactorListener.h"
    3838#include "tools/Timer.h"
    3939#include "objects/Tickable.h"
    40 #include "Game.h"
     40#include "core/Game.h"
    4141
    4242namespace orxonox
    4343{
    44     GSRoot::GSRoot()
    45         : RootGameState("root")
     44    AddGameState(GSRoot, "root");
     45
     46    GSRoot::GSRoot(const std::string& name)
     47        : GameState(name)
    4648        , timeFactor_(1.0f)
    4749        , bPaused_(false)
     
    5658    }
    5759
    58     void GSRoot::enter()
     60    void GSRoot::activate()
    5961    {
    6062        // reset game speed to normal
    6163        timeFactor_ = 1.0f;
    62 
    63         {
    64             // add console commands
    65             FunctorMember01<GameState, const std::string&>* functor = createFunctor(&GameState::requestState);
    66             functor->setObject(this);
    67             this->ccSelectGameState_ = createConsoleCommand(functor, "selectGameState");
    68             CommandExecutor::addConsoleCommandShortcut(this->ccSelectGameState_);
    69         }
    7064
    7165        {
     
    8680    }
    8781
    88     void GSRoot::leave()
     82    void GSRoot::deactivate()
    8983    {
    90         // destroy console commands
    91         delete this->ccSelectGameState_;
    92 
    9384        if (this->ccSetTimeFactor_)
    9485        {
     
    10495    }
    10596
    106     void GSRoot::ticked(const Clock& time)
     97    void GSRoot::update(const Clock& time)
    10798    {
    10899        uint64_t timeBeforeTick = time.getRealMicroseconds();
     
    129120        // Also add our tick time to the list in GSRoot
    130121        Game::getInstance().addTickTime(timeAfterTick - timeBeforeTick);
    131 
    132         this->tickChild(time);
    133122    }
    134123
  • code/branches/gui/src/orxonox/gamestates/GSRoot.h

    r2843 r2844  
    3131
    3232#include "OrxonoxPrereqs.h"
    33 
    34 #include <list>
    35 #include "core/RootGameState.h"
     33#include "core/GameState.h"
    3634#include "core/OrxonoxClass.h"
    3735
    3836namespace orxonox
    3937{
    40     class _OrxonoxExport GSRoot : public RootGameState
     38    class _OrxonoxExport GSRoot : public GameState
    4139    {
    42         friend class ClassIdentifier<GSRoot>;
     40    public:
     41        GSRoot(const std::string& name);
     42        ~GSRoot();
    4343
    44     public:
    45    
    46     public:
    47         GSRoot();
    48         ~GSRoot();
     44        void activate();
     45        void deactivate();
     46        void update(const Clock& time);
    4947
    5048        // this has to be public because proteced triggers a bug in msvc
     
    5553
    5654    private:
    57         void enter();
    58         void leave();
    59         void ticked(const Clock& time);
    60 
    6155        float                 timeFactor_;       //!< A factor that sets the gamespeed. 1 is normal.
    6256        bool                  bPaused_;
     
    6458
    6559        // console commands
    66         ConsoleCommand*       ccSelectGameState_;
    6760        ConsoleCommand*       ccSetTimeFactor_;
    6861        ConsoleCommand*       ccPause_;
  • code/branches/gui/src/orxonox/gamestates/GSServer.cc

    r2817 r2844  
    3333#include "core/Core.h"
    3434#include "network/Server.h"
     35#include "core/Game.h"
    3536
    3637namespace orxonox
    3738{
     39    AddGameState(GSServer, "server");
     40
    3841    SetCommandLineArgument(port, 55556).shortcut("p").information("0-65535");
    3942
    40     GSServer::GSServer()
    41         : GameState("server")
     43    GSServer::GSServer(const std::string& name)
     44        : GameState(name)
    4245        , server_(0)
    4346    {
     
    4851    }
    4952
    50     void GSServer::enter()
     53    void GSServer::activate()
    5154    {
    5255        Core::setHasServer(true);
     
    5558        COUT(0) << "Loading scene in server mode" << std::endl;
    5659
    57         GSLevel::enter();
    58 
    5960        server_->open();
    6061    }
    6162
    62     void GSServer::leave()
     63    void GSServer::deactivate()
    6364    {
    64         GSLevel::leave();
    65 
    6665        this->server_->close();
    6766        delete this->server_;
     
    7069    }
    7170
    72     void GSServer::ticked(const Clock& time)
     71    void GSServer::update(const Clock& time)
    7372    {
    74         GSLevel::ticked(time);
    7573        server_->update(time);
    76         this->tickChild(time);
    7774    }
    7875}
  • code/branches/gui/src/orxonox/gamestates/GSServer.h

    r2817 r2844  
    3333#include "core/GameState.h"
    3434#include "network/NetworkPrereqs.h"
    35 #include "GSLevel.h"
    3635
    3736namespace orxonox
    3837{
    39     class _OrxonoxExport GSServer : public GameState, public GSLevel
     38    class _OrxonoxExport GSServer : public GameState
    4039    {
    4140    public:
    42         GSServer();
     41        GSServer(const std::string& name);
    4342        ~GSServer();
    4443
     44        void activate();
     45        void deactivate();
     46        void update(const Clock& time);
     47
    4548    private:
    46         void enter();
    47         void leave();
    48         void ticked(const Clock& time);
    49 
    50         Server*      server_;
     49        Server* server_;
    5150    };
    5251}
  • code/branches/gui/src/orxonox/gamestates/GSStandalone.cc

    r2834 r2844  
    3636#include "gui/GUIManager.h"
    3737#include "GraphicsManager.h"
     38#include "core/Game.h"
    3839
    3940namespace orxonox
    4041{
    41     GSStandalone::GSStandalone()
    42         : GameState("standalone")
     42    AddGameState(GSStandalone, "standalone");
     43
     44    GSStandalone::GSStandalone(const std::string& name)
     45        : GameState(name)
    4346    {
    4447    }
     
    4952
    5053
    51     void GSStandalone::enter()
     54    void GSStandalone::activate()
    5255    {
    5356        Core::setIsStandalone(true);
    54 
    55         GSLevel::enter();
    5657
    5758        guiManager_ = GUIManager::getInstancePtr();
     
    6061    }
    6162
    62     void GSStandalone::leave()
     63    void GSStandalone::deactivate()
    6364    {
    64         GSLevel::leave();
    65 
    6665        Core::setIsStandalone(false);
    6766    }
    6867
    69     void GSStandalone::ticked(const Clock& time)
     68    void GSStandalone::update(const Clock& time)
    7069    {
    7170        //Ogre::Viewport* viewport = GraphicsManager::getInstance().getViewport();
     
    7776        // tick CEGUI
    7877        guiManager_->update(time);
    79 
    80         GSLevel::ticked(time);
    81         this->tickChild(time);
    8278    }
    8379}
  • code/branches/gui/src/orxonox/gamestates/GSStandalone.h

    r2817 r2844  
    3232#include "OrxonoxPrereqs.h"
    3333#include "core/GameState.h"
    34 #include "GSLevel.h"
    3534
    3635namespace orxonox
    3736{
    38     class _OrxonoxExport GSStandalone : public GameState, public GSLevel
     37    class _OrxonoxExport GSStandalone : public GameState
    3938    {
    4039    public:
    41         GSStandalone();
     40        GSStandalone(const std::string& name);
    4241        ~GSStandalone();
    4342
     43        void activate();
     44        void deactivate();
     45        void update(const Clock& time);
     46
    4447    private:
    45         void enter();
    46         void leave();
    47         void ticked(const Clock& time);
    48 
    49         GUIManager*     guiManager_;
     48        GUIManager* guiManager_;
    5049    };
    5150}
  • code/branches/gui/src/orxonox/overlays/debug/DebugFPSText.cc

    r2817 r2844  
    3232#include "util/Convert.h"
    3333#include "core/CoreIncludes.h"
    34 #include "Game.h"
     34#include "core/Game.h"
    3535
    3636namespace orxonox
  • code/branches/gui/src/orxonox/overlays/debug/DebugRTRText.cc

    r2817 r2844  
    3232#include "core/CoreIncludes.h"
    3333#include "util/Convert.h"
    34 #include "Game.h"
     34#include "core/Game.h"
    3535
    3636namespace orxonox
Note: See TracChangeset for help on using the changeset viewer.