Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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.

File:
1 moved

Legend:

Unmodified
Added
Removed
  • 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    };
Note: See TracChangeset for help on using the changeset viewer.