Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/core/Game.h @ 3211

Last change on this file since 3211 was 3196, checked in by rgrieder, 15 years ago

Merged pch branch back to trunk.

  • Property svn:eol-style set to native
File size: 4.1 KB
RevLine 
[2805]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Reto Grieder
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30@file
31@brief
32    Declaration of Game Singleton.
33 */
34
35#ifndef _Game_H__
36#define _Game_H__
37
[2844]38#include "CorePrereqs.h"
[3196]39
[2805]40#include <cassert>
[2817]41#include <list>
[2844]42#include <map>
[3196]43#include <string>
[2844]44#include <vector>
[3196]45#include <boost/shared_ptr.hpp>
46#include <boost/preprocessor/cat.hpp>
47
[2844]48#include "OrxonoxClass.h"
[2805]49
[3084]50/**
51@def
52    Adds a new GameState to the Game. The second parameter is the name as string
53    and every following paramter is a constructor argument (which is usually non existent)
54*/
55#define AddGameState(classname, ...) \
[3196]56    static bool BOOST_PP_CAT(bGameStateDummy_##classname, __LINE__) = orxonox::Game::addGameState(new classname(__VA_ARGS__))
[2844]57
[3036]58// tolua_begin
[2805]59namespace orxonox
60{
61    /**
62    @brief
63        Main class responsible for running the game.
64    */
[3036]65    class _CoreExport Game
66    // tolua_end
67        : public OrxonoxClass
68    // tolua_begin
[2805]69    {
[3036]70    //tolua_end
[2805]71    public:
72        Game(int argc, char** argv);
73        ~Game();
[2817]74        void setConfigValues();
[2805]75
[2844]76        void setStateHierarchy(const std::string& str);
77        GameState* getState(const std::string& name);
78
[2805]79        void run();
80        void stop();
81
[2844]82        void requestState(const std::string& name);
[2850]83        void requestStates(const std::string& names);
[2844]84        void popState();
85
[2846]86        const Clock& getGameClock() { return *this->gameClock_; }
87
[2817]88        float getAvgTickTime() { return this->avgTickTime_; }
89        float getAvgFPS()      { return this->avgFPS_; }
90
91        void addTickTime(uint32_t length);
92
[2844]93        static bool addGameState(GameState* state);
[2927]94        static void destroyStates();
[3036]95        static Game& getInstance() { assert(singletonRef_s); return *singletonRef_s; } //tolua_export
[2805]96
[3036]97        void setLevel(std::string levelName); //tolua_export
[3037]98        std::string getLevel(); //tolua_export
[3036]99
[2805]100    private:
[2817]101        struct statisticsTickInfo
102        {
103            uint64_t    tickTime;
104            uint32_t    tickLength;
105        };
106
[2805]107        Game(Game&); // don't mess with singletons
108
[2844]109        void loadState(GameState* state);
110        void unloadState(GameState* state);
[2805]111
[2844]112        std::vector<GameState*>         activeStates_;
[3196]113        boost::shared_ptr<GameStateTreeNode> rootStateNode_;
114        boost::shared_ptr<GameStateTreeNode> activeStateNode_;
115        std::vector<boost::shared_ptr<GameStateTreeNode> > requestedStateNodes_;
[2805]116
[2844]117        Core*                           core_;
118        Clock*                          gameClock_;
119
120        bool                            abort_;
121
[2817]122        // variables for time statistics
[2844]123        uint64_t                        statisticsStartTime_;
124        std::list<statisticsTickInfo>   statisticsTickTimes_;
125        uint32_t                        periodTime_;
126        uint32_t                        periodTickTime_;
127        float                           avgFPS_;
128        float                           avgTickTime_;
[2817]129
130        // config values
[2844]131        unsigned int                    statisticsRefreshCycle_;
132        unsigned int                    statisticsAvgLength_;
[3036]133        std::string                     levelName_;
[2817]134
[2844]135        static std::map<std::string, GameState*> allStates_s;
[2805]136        static Game* singletonRef_s;        //!< Pointer to the Singleton
[3036]137        // tolua_begin
[2805]138    };
139}
[3036]140//tolua_end
[2805]141#endif /* _Game_H__ */
Note: See TracBrowser for help on using the repository browser.