[1505] | 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 | * Co-authors: |
---|
[1755] | 25 | * Reto Grieder |
---|
[1505] | 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | /** |
---|
[1524] | 30 | @file Core.cc |
---|
| 31 | @brief Implementation of the Core class. |
---|
[1505] | 32 | */ |
---|
| 33 | |
---|
[1524] | 34 | #include "Core.h" |
---|
[1756] | 35 | #include <cassert> |
---|
[1505] | 36 | #include "Language.h" |
---|
| 37 | #include "CoreIncludes.h" |
---|
| 38 | #include "ConfigValueIncludes.h" |
---|
[1755] | 39 | //#include "input/InputManager.h" |
---|
| 40 | //#include "TclThreadManager.h" |
---|
[1505] | 41 | |
---|
| 42 | namespace orxonox |
---|
| 43 | { |
---|
| 44 | /** |
---|
| 45 | @brief Constructor: Registers the object and sets the config-values. |
---|
| 46 | @param A reference to a global variable, used to avoid an infinite recursion in getSoftDebugLevel() |
---|
| 47 | */ |
---|
[1524] | 48 | Core::Core() |
---|
[1505] | 49 | { |
---|
[1524] | 50 | RegisterRootObject(Core); |
---|
[1505] | 51 | this->setConfigValues(); |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | /** |
---|
| 55 | @brief Sets the bool to true to avoid static functions accessing a deleted object. |
---|
| 56 | */ |
---|
[1524] | 57 | Core::~Core() |
---|
[1505] | 58 | { |
---|
| 59 | isCreatingCoreSettings() = true; |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | /** |
---|
[1524] | 63 | @brief Returns true if the Core instance is not yet ready and the static functions have to return a default value. |
---|
[1505] | 64 | */ |
---|
[1524] | 65 | bool& Core::isCreatingCoreSettings() |
---|
[1505] | 66 | { |
---|
| 67 | static bool bCreatingCoreSettings = true; |
---|
| 68 | static bool bFirstTime = true; |
---|
| 69 | if (bFirstTime) |
---|
| 70 | { |
---|
| 71 | bFirstTime = false; |
---|
[1524] | 72 | Core::getInstance(); |
---|
[1505] | 73 | } |
---|
| 74 | return bCreatingCoreSettings; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | /** |
---|
[1524] | 78 | @brief Returns a unique instance of Core. |
---|
[1505] | 79 | @return The instance |
---|
| 80 | */ |
---|
[1524] | 81 | Core& Core::getInstance() |
---|
[1505] | 82 | { |
---|
[1756] | 83 | static Core instance; |
---|
[1505] | 84 | |
---|
| 85 | // If bCreatingSoftDebugLevelObject is true, we're just about to create an instance of the DebugLevel class |
---|
[1756] | 86 | //if (Core::isCreatingCoreSettings()) |
---|
| 87 | //{ |
---|
| 88 | // isCreatingCoreSettings() = false; |
---|
| 89 | // instance.setConfigValues(); |
---|
| 90 | //} |
---|
[1505] | 91 | return instance; |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | /** |
---|
| 95 | @brief Function to collect the SetConfigValue-macro calls. |
---|
| 96 | */ |
---|
[1524] | 97 | void Core::setConfigValues() |
---|
[1505] | 98 | { |
---|
[1747] | 99 | SetConfigValue(softDebugLevelConsole_, 3).description("The maximal level of debug output shown in the console").callback(this, &Core::debugLevelChanged); |
---|
| 100 | SetConfigValue(softDebugLevelLogfile_, 3).description("The maximal level of debug output shown in the logfile").callback(this, &Core::debugLevelChanged); |
---|
| 101 | SetConfigValue(softDebugLevelShell_, 1).description("The maximal level of debug output shown in the ingame shell").callback(this, &Core::debugLevelChanged); |
---|
| 102 | SetConfigValue(language_, Language::getLanguage().defaultLanguage_).description("The language of the ingame text").callback(this, &Core::languageChanged); |
---|
| 103 | } |
---|
[1505] | 104 | |
---|
[1747] | 105 | /** |
---|
| 106 | @brief Callback function if the debug level has changed. |
---|
| 107 | */ |
---|
| 108 | void Core::debugLevelChanged() |
---|
| 109 | { |
---|
[1505] | 110 | // softDebugLevel_ is the maximum of the 3 variables |
---|
| 111 | this->softDebugLevel_ = this->softDebugLevelConsole_; |
---|
| 112 | if (this->softDebugLevelLogfile_ > this->softDebugLevel_) |
---|
| 113 | this->softDebugLevel_ = this->softDebugLevelLogfile_; |
---|
| 114 | if (this->softDebugLevelShell_ > this->softDebugLevel_) |
---|
| 115 | this->softDebugLevel_ = this->softDebugLevelShell_; |
---|
| 116 | |
---|
[1747] | 117 | OutputHandler::setSoftDebugLevel(OutputHandler::LD_All, this->softDebugLevel_); |
---|
| 118 | OutputHandler::setSoftDebugLevel(OutputHandler::LD_Console, this->softDebugLevelConsole_); |
---|
| 119 | OutputHandler::setSoftDebugLevel(OutputHandler::LD_Logfile, this->softDebugLevelLogfile_); |
---|
| 120 | OutputHandler::setSoftDebugLevel(OutputHandler::LD_Shell, this->softDebugLevelShell_); |
---|
| 121 | } |
---|
[1505] | 122 | |
---|
[1747] | 123 | /** |
---|
| 124 | @brief Callback function if the language has changed. |
---|
| 125 | */ |
---|
| 126 | void Core::languageChanged() |
---|
| 127 | { |
---|
| 128 | // Read the translation file after the language was configured |
---|
| 129 | Language::getLanguage().readTranslatedLanguageFile(); |
---|
[1505] | 130 | } |
---|
| 131 | |
---|
| 132 | /** |
---|
| 133 | @brief Returns the softDebugLevel for the given device (returns a default-value if the class ist right about to be created). |
---|
| 134 | @param device The device |
---|
| 135 | @return The softDebugLevel |
---|
| 136 | */ |
---|
[1524] | 137 | int Core::getSoftDebugLevel(OutputHandler::OutputDevice device) |
---|
[1505] | 138 | { |
---|
[1524] | 139 | if (!Core::isCreatingCoreSettings()) |
---|
[1505] | 140 | { |
---|
[1756] | 141 | switch (device) |
---|
| 142 | { |
---|
| 143 | case OutputHandler::LD_All: |
---|
[1524] | 144 | return Core::getInstance().softDebugLevel_; |
---|
[1756] | 145 | case OutputHandler::LD_Console: |
---|
[1524] | 146 | return Core::getInstance().softDebugLevelConsole_; |
---|
[1756] | 147 | case OutputHandler::LD_Logfile: |
---|
[1524] | 148 | return Core::getInstance().softDebugLevelLogfile_; |
---|
[1756] | 149 | case OutputHandler::LD_Shell: |
---|
[1524] | 150 | return Core::getInstance().softDebugLevelShell_; |
---|
[1756] | 151 | default: |
---|
| 152 | assert(0); |
---|
| 153 | } |
---|
[1505] | 154 | } |
---|
| 155 | |
---|
| 156 | // Return a constant value while we're creating the object |
---|
| 157 | return 2; |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | /** |
---|
| 161 | @brief Sets the softDebugLevel for the given device. Please use this only temporary and restore the value afterwards, as it overrides the configured value. |
---|
| 162 | @param device The device |
---|
| 163 | @param level The level |
---|
| 164 | */ |
---|
[1524] | 165 | void Core::setSoftDebugLevel(OutputHandler::OutputDevice device, int level) |
---|
[1505] | 166 | { |
---|
[1524] | 167 | if (!Core::isCreatingCoreSettings()) |
---|
[1505] | 168 | { |
---|
| 169 | if (device == OutputHandler::LD_All) |
---|
[1524] | 170 | Core::getInstance().softDebugLevel_ = level; |
---|
[1505] | 171 | else if (device == OutputHandler::LD_Console) |
---|
[1524] | 172 | Core::getInstance().softDebugLevelConsole_ = level; |
---|
[1505] | 173 | else if (device == OutputHandler::LD_Logfile) |
---|
[1524] | 174 | Core::getInstance().softDebugLevelLogfile_ = level; |
---|
[1505] | 175 | else if (device == OutputHandler::LD_Shell) |
---|
[1524] | 176 | Core::getInstance().softDebugLevelShell_ = level; |
---|
[1747] | 177 | |
---|
| 178 | OutputHandler::setSoftDebugLevel(device, level); |
---|
[1505] | 179 | } |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | /** |
---|
| 183 | @brief Returns the configured language. |
---|
| 184 | */ |
---|
[1524] | 185 | const std::string& Core::getLanguage() |
---|
[1505] | 186 | { |
---|
[1524] | 187 | if (!Core::isCreatingCoreSettings()) |
---|
| 188 | return Core::getInstance().language_; |
---|
[1505] | 189 | |
---|
| 190 | return Language::getLanguage().defaultLanguage_; |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | /** |
---|
| 194 | @brief Sets the language in the config-file back to the default. |
---|
| 195 | */ |
---|
[1524] | 196 | void Core::resetLanguage() |
---|
[1505] | 197 | { |
---|
[1524] | 198 | Core::getInstance().resetLanguageIntern(); |
---|
[1505] | 199 | } |
---|
| 200 | |
---|
| 201 | /** |
---|
| 202 | @brief Sets the language in the config-file back to the default. |
---|
| 203 | */ |
---|
[1524] | 204 | void Core::resetLanguageIntern() |
---|
[1505] | 205 | { |
---|
| 206 | ResetConfigValue(language_); |
---|
| 207 | } |
---|
[1524] | 208 | |
---|
[1755] | 209 | ///** |
---|
| 210 | // @brief Ticks every core class in a specified sequence. Has to be called |
---|
| 211 | // every Orxonox tick! |
---|
| 212 | // @param dt Delta Time |
---|
| 213 | //*/ |
---|
| 214 | //void Core::tick(float dt) |
---|
| 215 | //{ |
---|
| 216 | // TclThreadManager::getInstance().tick(dt); |
---|
| 217 | // InputManager::getInstance().tick(dt); |
---|
| 218 | //} |
---|
[1505] | 219 | } |
---|