[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 | /** |
---|
[2171] | 30 | @file |
---|
[1524] | 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" |
---|
| 39 | |
---|
| 40 | namespace orxonox |
---|
| 41 | { |
---|
[2087] | 42 | bool Core::bShowsGraphics_s = false; |
---|
| 43 | bool Core::bHasServer_s = false; |
---|
| 44 | bool Core::bIsClient_s = false; |
---|
| 45 | bool Core::bIsStandalone_s = false; |
---|
| 46 | bool Core::bIsMaster_s = false; |
---|
| 47 | |
---|
[2344] | 48 | Core* Core::singletonRef_s = 0; |
---|
| 49 | |
---|
[1505] | 50 | /** |
---|
| 51 | @brief Constructor: Registers the object and sets the config-values. |
---|
| 52 | @param A reference to a global variable, used to avoid an infinite recursion in getSoftDebugLevel() |
---|
| 53 | */ |
---|
[1524] | 54 | Core::Core() |
---|
[1505] | 55 | { |
---|
[1524] | 56 | RegisterRootObject(Core); |
---|
[2344] | 57 | |
---|
| 58 | assert(singletonRef_s == 0); |
---|
| 59 | singletonRef_s = this; |
---|
| 60 | |
---|
[1505] | 61 | this->setConfigValues(); |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | /** |
---|
| 65 | @brief Sets the bool to true to avoid static functions accessing a deleted object. |
---|
| 66 | */ |
---|
[1524] | 67 | Core::~Core() |
---|
[1505] | 68 | { |
---|
[2344] | 69 | assert(singletonRef_s); |
---|
| 70 | singletonRef_s = 0; |
---|
[1505] | 71 | } |
---|
| 72 | |
---|
| 73 | /** |
---|
| 74 | @brief Function to collect the SetConfigValue-macro calls. |
---|
| 75 | */ |
---|
[1524] | 76 | void Core::setConfigValues() |
---|
[1505] | 77 | { |
---|
[1747] | 78 | SetConfigValue(softDebugLevelConsole_, 3).description("The maximal level of debug output shown in the console").callback(this, &Core::debugLevelChanged); |
---|
| 79 | SetConfigValue(softDebugLevelLogfile_, 3).description("The maximal level of debug output shown in the logfile").callback(this, &Core::debugLevelChanged); |
---|
| 80 | SetConfigValue(softDebugLevelShell_, 1).description("The maximal level of debug output shown in the ingame shell").callback(this, &Core::debugLevelChanged); |
---|
| 81 | SetConfigValue(language_, Language::getLanguage().defaultLanguage_).description("The language of the ingame text").callback(this, &Core::languageChanged); |
---|
| 82 | } |
---|
[1505] | 83 | |
---|
[1747] | 84 | /** |
---|
| 85 | @brief Callback function if the debug level has changed. |
---|
| 86 | */ |
---|
| 87 | void Core::debugLevelChanged() |
---|
| 88 | { |
---|
[1505] | 89 | // softDebugLevel_ is the maximum of the 3 variables |
---|
| 90 | this->softDebugLevel_ = this->softDebugLevelConsole_; |
---|
| 91 | if (this->softDebugLevelLogfile_ > this->softDebugLevel_) |
---|
| 92 | this->softDebugLevel_ = this->softDebugLevelLogfile_; |
---|
| 93 | if (this->softDebugLevelShell_ > this->softDebugLevel_) |
---|
| 94 | this->softDebugLevel_ = this->softDebugLevelShell_; |
---|
| 95 | |
---|
[1747] | 96 | OutputHandler::setSoftDebugLevel(OutputHandler::LD_All, this->softDebugLevel_); |
---|
| 97 | OutputHandler::setSoftDebugLevel(OutputHandler::LD_Console, this->softDebugLevelConsole_); |
---|
| 98 | OutputHandler::setSoftDebugLevel(OutputHandler::LD_Logfile, this->softDebugLevelLogfile_); |
---|
| 99 | OutputHandler::setSoftDebugLevel(OutputHandler::LD_Shell, this->softDebugLevelShell_); |
---|
| 100 | } |
---|
[1505] | 101 | |
---|
[1747] | 102 | /** |
---|
| 103 | @brief Callback function if the language has changed. |
---|
| 104 | */ |
---|
| 105 | void Core::languageChanged() |
---|
| 106 | { |
---|
| 107 | // Read the translation file after the language was configured |
---|
| 108 | Language::getLanguage().readTranslatedLanguageFile(); |
---|
[1505] | 109 | } |
---|
| 110 | |
---|
| 111 | /** |
---|
| 112 | @brief Returns the softDebugLevel for the given device (returns a default-value if the class ist right about to be created). |
---|
| 113 | @param device The device |
---|
| 114 | @return The softDebugLevel |
---|
| 115 | */ |
---|
[1524] | 116 | int Core::getSoftDebugLevel(OutputHandler::OutputDevice device) |
---|
[1505] | 117 | { |
---|
[2344] | 118 | switch (device) |
---|
[1505] | 119 | { |
---|
[2344] | 120 | case OutputHandler::LD_All: |
---|
| 121 | return Core::getInstance().softDebugLevel_; |
---|
| 122 | case OutputHandler::LD_Console: |
---|
| 123 | return Core::getInstance().softDebugLevelConsole_; |
---|
| 124 | case OutputHandler::LD_Logfile: |
---|
| 125 | return Core::getInstance().softDebugLevelLogfile_; |
---|
| 126 | case OutputHandler::LD_Shell: |
---|
| 127 | return Core::getInstance().softDebugLevelShell_; |
---|
| 128 | default: |
---|
| 129 | assert(0); |
---|
| 130 | return 2; |
---|
[1505] | 131 | } |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | /** |
---|
| 135 | @brief Sets the softDebugLevel for the given device. Please use this only temporary and restore the value afterwards, as it overrides the configured value. |
---|
| 136 | @param device The device |
---|
| 137 | @param level The level |
---|
| 138 | */ |
---|
[1524] | 139 | void Core::setSoftDebugLevel(OutputHandler::OutputDevice device, int level) |
---|
[1505] | 140 | { |
---|
[2344] | 141 | if (device == OutputHandler::LD_All) |
---|
| 142 | Core::getInstance().softDebugLevel_ = level; |
---|
| 143 | else if (device == OutputHandler::LD_Console) |
---|
| 144 | Core::getInstance().softDebugLevelConsole_ = level; |
---|
| 145 | else if (device == OutputHandler::LD_Logfile) |
---|
| 146 | Core::getInstance().softDebugLevelLogfile_ = level; |
---|
| 147 | else if (device == OutputHandler::LD_Shell) |
---|
| 148 | Core::getInstance().softDebugLevelShell_ = level; |
---|
[1747] | 149 | |
---|
[2344] | 150 | OutputHandler::setSoftDebugLevel(device, level); |
---|
[1505] | 151 | } |
---|
| 152 | |
---|
| 153 | /** |
---|
| 154 | @brief Returns the configured language. |
---|
| 155 | */ |
---|
[1524] | 156 | const std::string& Core::getLanguage() |
---|
[1505] | 157 | { |
---|
[2344] | 158 | return Core::getInstance().language_; |
---|
[1505] | 159 | } |
---|
| 160 | |
---|
| 161 | /** |
---|
| 162 | @brief Sets the language in the config-file back to the default. |
---|
| 163 | */ |
---|
[1524] | 164 | void Core::resetLanguage() |
---|
[1505] | 165 | { |
---|
[1524] | 166 | Core::getInstance().resetLanguageIntern(); |
---|
[1505] | 167 | } |
---|
| 168 | |
---|
| 169 | /** |
---|
| 170 | @brief Sets the language in the config-file back to the default. |
---|
| 171 | */ |
---|
[1524] | 172 | void Core::resetLanguageIntern() |
---|
[1505] | 173 | { |
---|
| 174 | ResetConfigValue(language_); |
---|
| 175 | } |
---|
| 176 | } |
---|