[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" |
---|
[3154] | 39 | |
---|
[2805] | 40 | #include <cassert> |
---|
[2817] | 41 | #include <list> |
---|
[2844] | 42 | #include <map> |
---|
| 43 | #include <vector> |
---|
[3124] | 44 | #include <boost/shared_ptr.hpp> |
---|
[3154] | 45 | |
---|
[2844] | 46 | #include "OrxonoxClass.h" |
---|
[2805] | 47 | |
---|
[3084] | 48 | /** |
---|
| 49 | @def |
---|
| 50 | Adds a new GameState to the Game. The second parameter is the name as string |
---|
| 51 | and every following paramter is a constructor argument (which is usually non existent) |
---|
| 52 | */ |
---|
| 53 | #define AddGameState(classname, ...) \ |
---|
| 54 | static bool MACRO_CONCATENATE(bGameStateDummy_##classname, __LINE__) = orxonox::Game::addGameState(new classname(__VA_ARGS__)) |
---|
[2844] | 55 | |
---|
[3036] | 56 | // tolua_begin |
---|
[2805] | 57 | namespace orxonox |
---|
| 58 | { |
---|
| 59 | /** |
---|
| 60 | @brief |
---|
| 61 | Main class responsible for running the game. |
---|
| 62 | */ |
---|
[3036] | 63 | class _CoreExport Game |
---|
| 64 | // tolua_end |
---|
| 65 | : public OrxonoxClass |
---|
| 66 | // tolua_begin |
---|
[2805] | 67 | { |
---|
[3036] | 68 | //tolua_end |
---|
[2805] | 69 | public: |
---|
| 70 | Game(int argc, char** argv); |
---|
| 71 | ~Game(); |
---|
[2817] | 72 | void setConfigValues(); |
---|
[2805] | 73 | |
---|
[2844] | 74 | void setStateHierarchy(const std::string& str); |
---|
| 75 | GameState* getState(const std::string& name); |
---|
| 76 | |
---|
[2805] | 77 | void run(); |
---|
| 78 | void stop(); |
---|
| 79 | |
---|
[2844] | 80 | void requestState(const std::string& name); |
---|
[2850] | 81 | void requestStates(const std::string& names); |
---|
[2844] | 82 | void popState(); |
---|
| 83 | |
---|
[2846] | 84 | const Clock& getGameClock() { return *this->gameClock_; } |
---|
| 85 | |
---|
[2817] | 86 | float getAvgTickTime() { return this->avgTickTime_; } |
---|
| 87 | float getAvgFPS() { return this->avgFPS_; } |
---|
| 88 | |
---|
| 89 | void addTickTime(uint32_t length); |
---|
| 90 | |
---|
[2844] | 91 | static bool addGameState(GameState* state); |
---|
[2927] | 92 | static void destroyStates(); |
---|
[3036] | 93 | static Game& getInstance() { assert(singletonRef_s); return *singletonRef_s; } //tolua_export |
---|
[2805] | 94 | |
---|
[3036] | 95 | void setLevel(std::string levelName); //tolua_export |
---|
[3037] | 96 | std::string getLevel(); //tolua_export |
---|
[3036] | 97 | |
---|
[2805] | 98 | private: |
---|
[2817] | 99 | struct statisticsTickInfo |
---|
| 100 | { |
---|
| 101 | uint64_t tickTime; |
---|
| 102 | uint32_t tickLength; |
---|
| 103 | }; |
---|
| 104 | |
---|
[2805] | 105 | Game(Game&); // don't mess with singletons |
---|
| 106 | |
---|
[2844] | 107 | void loadState(GameState* state); |
---|
| 108 | void unloadState(GameState* state); |
---|
[2805] | 109 | |
---|
[2844] | 110 | std::vector<GameState*> activeStates_; |
---|
[3124] | 111 | boost::shared_ptr<GameStateTreeNode> rootStateNode_; |
---|
| 112 | boost::shared_ptr<GameStateTreeNode> activeStateNode_; |
---|
| 113 | std::vector<boost::shared_ptr<GameStateTreeNode> > requestedStateNodes_; |
---|
[2805] | 114 | |
---|
[2844] | 115 | Core* core_; |
---|
| 116 | Clock* gameClock_; |
---|
| 117 | |
---|
| 118 | bool abort_; |
---|
| 119 | |
---|
[2817] | 120 | // variables for time statistics |
---|
[2844] | 121 | uint64_t statisticsStartTime_; |
---|
| 122 | std::list<statisticsTickInfo> statisticsTickTimes_; |
---|
| 123 | uint32_t periodTime_; |
---|
| 124 | uint32_t periodTickTime_; |
---|
| 125 | float avgFPS_; |
---|
| 126 | float avgTickTime_; |
---|
[2817] | 127 | |
---|
| 128 | // config values |
---|
[2844] | 129 | unsigned int statisticsRefreshCycle_; |
---|
| 130 | unsigned int statisticsAvgLength_; |
---|
[3036] | 131 | std::string levelName_; |
---|
[2817] | 132 | |
---|
[2844] | 133 | static std::map<std::string, GameState*> allStates_s; |
---|
[2805] | 134 | static Game* singletonRef_s; //!< Pointer to the Singleton |
---|
[3036] | 135 | // tolua_begin |
---|
[2805] | 136 | }; |
---|
| 137 | } |
---|
[3036] | 138 | //tolua_end |
---|
[2805] | 139 | #endif /* _Game_H__ */ |
---|