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 | * Fabian 'x3n' Landau |
---|
24 | * Reto Grieder |
---|
25 | * Co-authors: |
---|
26 | * ... |
---|
27 | * |
---|
28 | */ |
---|
29 | |
---|
30 | /** |
---|
31 | @file |
---|
32 | @brief Declaration of the Core class. |
---|
33 | |
---|
34 | The Core class is a singleton, only used to configure some variables |
---|
35 | in the core through the config-file. |
---|
36 | */ |
---|
37 | |
---|
38 | #ifndef _Core_H__ |
---|
39 | #define _Core_H__ |
---|
40 | |
---|
41 | #include "CorePrereqs.h" |
---|
42 | |
---|
43 | #include <cassert> |
---|
44 | #include "OrxonoxClass.h" |
---|
45 | #include "util/OutputHandler.h" |
---|
46 | |
---|
47 | // Only allow main to access postMainInitialisation, so we need a forward declaration |
---|
48 | int main(int, char**); |
---|
49 | // boost::filesystem header has quite a large tail, use forward declaration |
---|
50 | namespace boost { namespace filesystem |
---|
51 | { |
---|
52 | struct path_traits; |
---|
53 | template<class String, class Traits> class basic_path; |
---|
54 | typedef basic_path< std::string, path_traits> path; |
---|
55 | } } |
---|
56 | |
---|
57 | namespace orxonox |
---|
58 | { |
---|
59 | //! The Core class is a singleton, only used to configure some config-values. |
---|
60 | class _CoreExport Core : public OrxonoxClass |
---|
61 | { |
---|
62 | public: |
---|
63 | Core(int argc, char** argv); |
---|
64 | ~Core(); |
---|
65 | void setConfigValues(); |
---|
66 | |
---|
67 | bool isLoaded() { return this->loaded_; } |
---|
68 | void update(const Clock& time); |
---|
69 | |
---|
70 | static Core& getInstance() { assert(Core::singletonRef_s); return *Core::singletonRef_s; } |
---|
71 | |
---|
72 | static int getSoftDebugLevel(OutputHandler::OutputDevice device = OutputHandler::LD_All); |
---|
73 | static void setSoftDebugLevel(OutputHandler::OutputDevice device, int level); |
---|
74 | static const std::string& getLanguage(); |
---|
75 | static void resetLanguage(); |
---|
76 | |
---|
77 | static void tsetMediaPath(const std::string& path) |
---|
78 | { assert(singletonRef_s); singletonRef_s->_tsetMediaPath(path); } |
---|
79 | static const boost::filesystem::path& getMediaPath(); |
---|
80 | static const boost::filesystem::path& getConfigPath(); |
---|
81 | static const boost::filesystem::path& getLogPath(); |
---|
82 | static std::string getMediaPathString(); |
---|
83 | static std::string getConfigPathString(); |
---|
84 | static std::string getLogPathString(); |
---|
85 | |
---|
86 | // fast access global variables. |
---|
87 | static bool showsGraphics() { return bShowsGraphics_s; } |
---|
88 | static bool hasServer() { return bHasServer_s; } |
---|
89 | static bool isClient() { return bIsClient_s; } |
---|
90 | static bool isStandalone() { return bIsStandalone_s; } |
---|
91 | static bool isMaster() { return bIsMaster_s; } |
---|
92 | static void setShowsGraphics(bool val) { bShowsGraphics_s = val; updateIsMaster(); } |
---|
93 | static void setHasServer (bool val) { bHasServer_s = val; updateIsMaster(); } |
---|
94 | static void setIsClient (bool val) { bIsClient_s = val; updateIsMaster(); } |
---|
95 | static void setIsStandalone (bool val) { bIsStandalone_s = val; updateIsMaster(); } |
---|
96 | static void updateIsMaster () { bIsMaster_s = (bHasServer_s || bIsStandalone_s); } |
---|
97 | |
---|
98 | private: |
---|
99 | Core(const Core&); |
---|
100 | |
---|
101 | void checkDevBuild(); |
---|
102 | void setExecutablePath(); |
---|
103 | void createDirectories(); |
---|
104 | void setThreadAffinity(int limitToCPU); |
---|
105 | |
---|
106 | void resetLanguageIntern(); |
---|
107 | void initializeRandomNumberGenerator(); |
---|
108 | void debugLevelChanged(); |
---|
109 | void languageChanged(); |
---|
110 | void mediaPathChanged(); |
---|
111 | void _tsetMediaPath(const std::string& path); |
---|
112 | |
---|
113 | // Singletons |
---|
114 | ConfigFileManager* configFileManager_; |
---|
115 | Language* languageInstance_; |
---|
116 | LuaBind* luaBind_; |
---|
117 | Shell* shell_; |
---|
118 | SignalHandler* signalHandler_; |
---|
119 | TclBind* tclBind_; |
---|
120 | TclThreadManager* tclThreadManager_; |
---|
121 | |
---|
122 | int softDebugLevel_; //!< The debug level |
---|
123 | int softDebugLevelConsole_; //!< The debug level for the console |
---|
124 | int softDebugLevelLogfile_; //!< The debug level for the logfile |
---|
125 | int softDebugLevelShell_; //!< The debug level for the ingame shell |
---|
126 | std::string language_; //!< The language |
---|
127 | bool bInitializeRandomNumberGenerator_; //!< If true, srand(time(0)) is called |
---|
128 | std::string mediaPathString_; //!< Path to the data/media file folder as string |
---|
129 | bool isDevBuild_; //!< True for builds in the build directory (not installed) |
---|
130 | bool loaded_; //!< Only true if constructor was interrupted |
---|
131 | |
---|
132 | static bool bShowsGraphics_s; //!< global variable that tells whether to show graphics |
---|
133 | static bool bHasServer_s; //!< global variable that tells whether this is a server |
---|
134 | static bool bIsClient_s; |
---|
135 | static bool bIsStandalone_s; |
---|
136 | static bool bIsMaster_s; |
---|
137 | |
---|
138 | static Core* singletonRef_s; |
---|
139 | }; |
---|
140 | } |
---|
141 | |
---|
142 | #endif /* _Core_H__ */ |
---|