Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/netp6/src/core/Game.h @ 3614

Last change on this file since 3614 was 3289, checked in by scheusso, 15 years ago

a fix in Clock (more ogre-overflow safe now)
moved framerate control from gsdedicated to game
desired framerate can be controlled by config value FPSLimit_ (in the Game class) now

  • Property svn:eol-style set to native
File size: 4.2 KB
Line 
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
38#include "CorePrereqs.h"
39
40#include <cassert>
41#include <list>
42#include <map>
43#include <string>
44#include <vector>
45#include <boost/shared_ptr.hpp>
46#include <boost/preprocessor/cat.hpp>
47
48#include "OrxonoxClass.h"
49
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, ...) \
56    static bool BOOST_PP_CAT(bGameStateDummy_##classname, __LINE__) = orxonox::Game::addGameState(new classname(__VA_ARGS__))
57
58// tolua_begin
59namespace orxonox
60{
61    /**
62    @brief
63        Main class responsible for running the game.
64    */
65    class _CoreExport Game
66    // tolua_end
67        : public OrxonoxClass
68    // tolua_begin
69    {
70    //tolua_end
71    public:
72        Game(int argc, char** argv);
73        ~Game();
74        void setConfigValues();
75
76        void setStateHierarchy(const std::string& str);
77        GameState* getState(const std::string& name);
78
79        void run();
80        void stop();
81
82        void requestState(const std::string& name);
83        void requestStates(const std::string& names);
84        void popState();
85
86        const Clock& getGameClock() { return *this->gameClock_; }
87
88        float getAvgTickTime() { return this->avgTickTime_; }
89        float getAvgFPS()      { return this->avgFPS_; }
90
91        void addTickTime(uint32_t length);
92
93        static bool addGameState(GameState* state);
94        static void destroyStates();
95        static Game& getInstance() { assert(singletonRef_s); return *singletonRef_s; } //tolua_export
96
97        void setLevel(std::string levelName); //tolua_export
98        std::string getLevel(); //tolua_export
99
100    private:
101        struct statisticsTickInfo
102        {
103            uint64_t    tickTime;
104            uint32_t    tickLength;
105        };
106
107        Game(Game&); // don't mess with singletons
108
109        void loadState(GameState* state);
110        void unloadState(GameState* state);
111
112        std::vector<GameState*>         activeStates_;
113        boost::shared_ptr<GameStateTreeNode> rootStateNode_;
114        boost::shared_ptr<GameStateTreeNode> activeStateNode_;
115        std::vector<boost::shared_ptr<GameStateTreeNode> > requestedStateNodes_;
116
117        Core*                           core_;
118        Clock*                          gameClock_;
119
120        bool                            abort_;
121
122        // variables for time statistics
123        uint64_t                        statisticsStartTime_;
124        std::list<statisticsTickInfo>   statisticsTickTimes_;
125        uint32_t                        periodTime_;
126        uint32_t                        periodTickTime_;
127        float                           avgFPS_;
128        float                           avgTickTime_;
129
130        // config values
131        unsigned int                    statisticsRefreshCycle_;
132        unsigned int                    statisticsAvgLength_;
133        unsigned int                    FPSLimit_;
134        std::string                     levelName_;
135
136        static std::map<std::string, GameState*> allStates_s;
137        static Game* singletonRef_s;        //!< Pointer to the Singleton
138        // tolua_begin
139    };
140}
141//tolua_end
142#endif /* _Game_H__ */
Note: See TracBrowser for help on using the repository browser.