[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 | |
---|
[2662] | 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); |
---|
[2662] | 57 | |
---|
| 58 | assert(Core::singletonRef_s == 0); |
---|
| 59 | Core::singletonRef_s = this; |
---|
| 60 | this->bInitializeRandomNumberGenerator_ = false; |
---|
| 61 | |
---|
[1505] | 62 | this->setConfigValues(); |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | /** |
---|
| 66 | @brief Sets the bool to true to avoid static functions accessing a deleted object. |
---|
| 67 | */ |
---|
[1524] | 68 | Core::~Core() |
---|
[1505] | 69 | { |
---|
[2662] | 70 | assert(Core::singletonRef_s); |
---|
| 71 | Core::singletonRef_s = 0; |
---|
[1505] | 72 | } |
---|
| 73 | |
---|
| 74 | /** |
---|
| 75 | @brief Function to collect the SetConfigValue-macro calls. |
---|
| 76 | */ |
---|
[1524] | 77 | void Core::setConfigValues() |
---|
[1505] | 78 | { |
---|
[1747] | 79 | SetConfigValue(softDebugLevelConsole_, 3).description("The maximal level of debug output shown in the console").callback(this, &Core::debugLevelChanged); |
---|
| 80 | SetConfigValue(softDebugLevelLogfile_, 3).description("The maximal level of debug output shown in the logfile").callback(this, &Core::debugLevelChanged); |
---|
| 81 | SetConfigValue(softDebugLevelShell_, 1).description("The maximal level of debug output shown in the ingame shell").callback(this, &Core::debugLevelChanged); |
---|
| 82 | SetConfigValue(language_, Language::getLanguage().defaultLanguage_).description("The language of the ingame text").callback(this, &Core::languageChanged); |
---|
[2662] | 83 | SetConfigValue(bInitializeRandomNumberGenerator_, true).description("If true, all random actions are different each time you start the game").callback(this, &Core::initializeRandomNumberGenerator); |
---|
[1747] | 84 | } |
---|
[1505] | 85 | |
---|
[1747] | 86 | /** |
---|
| 87 | @brief Callback function if the debug level has changed. |
---|
| 88 | */ |
---|
| 89 | void Core::debugLevelChanged() |
---|
| 90 | { |
---|
[1505] | 91 | // softDebugLevel_ is the maximum of the 3 variables |
---|
| 92 | this->softDebugLevel_ = this->softDebugLevelConsole_; |
---|
| 93 | if (this->softDebugLevelLogfile_ > this->softDebugLevel_) |
---|
| 94 | this->softDebugLevel_ = this->softDebugLevelLogfile_; |
---|
| 95 | if (this->softDebugLevelShell_ > this->softDebugLevel_) |
---|
| 96 | this->softDebugLevel_ = this->softDebugLevelShell_; |
---|
| 97 | |
---|
[1747] | 98 | OutputHandler::setSoftDebugLevel(OutputHandler::LD_All, this->softDebugLevel_); |
---|
| 99 | OutputHandler::setSoftDebugLevel(OutputHandler::LD_Console, this->softDebugLevelConsole_); |
---|
| 100 | OutputHandler::setSoftDebugLevel(OutputHandler::LD_Logfile, this->softDebugLevelLogfile_); |
---|
| 101 | OutputHandler::setSoftDebugLevel(OutputHandler::LD_Shell, this->softDebugLevelShell_); |
---|
| 102 | } |
---|
[1505] | 103 | |
---|
[1747] | 104 | /** |
---|
| 105 | @brief Callback function if the language has changed. |
---|
| 106 | */ |
---|
| 107 | void Core::languageChanged() |
---|
| 108 | { |
---|
| 109 | // Read the translation file after the language was configured |
---|
| 110 | Language::getLanguage().readTranslatedLanguageFile(); |
---|
[1505] | 111 | } |
---|
| 112 | |
---|
| 113 | /** |
---|
| 114 | @brief Returns the softDebugLevel for the given device (returns a default-value if the class ist right about to be created). |
---|
| 115 | @param device The device |
---|
| 116 | @return The softDebugLevel |
---|
| 117 | */ |
---|
[1524] | 118 | int Core::getSoftDebugLevel(OutputHandler::OutputDevice device) |
---|
[1505] | 119 | { |
---|
[2662] | 120 | switch (device) |
---|
[1505] | 121 | { |
---|
[2662] | 122 | case OutputHandler::LD_All: |
---|
| 123 | return Core::getInstance().softDebugLevel_; |
---|
| 124 | case OutputHandler::LD_Console: |
---|
| 125 | return Core::getInstance().softDebugLevelConsole_; |
---|
| 126 | case OutputHandler::LD_Logfile: |
---|
| 127 | return Core::getInstance().softDebugLevelLogfile_; |
---|
| 128 | case OutputHandler::LD_Shell: |
---|
| 129 | return Core::getInstance().softDebugLevelShell_; |
---|
| 130 | default: |
---|
| 131 | assert(0); |
---|
| 132 | return 2; |
---|
[1505] | 133 | } |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | /** |
---|
| 137 | @brief Sets the softDebugLevel for the given device. Please use this only temporary and restore the value afterwards, as it overrides the configured value. |
---|
| 138 | @param device The device |
---|
| 139 | @param level The level |
---|
| 140 | */ |
---|
[1524] | 141 | void Core::setSoftDebugLevel(OutputHandler::OutputDevice device, int level) |
---|
[1505] | 142 | { |
---|
[2662] | 143 | if (device == OutputHandler::LD_All) |
---|
| 144 | Core::getInstance().softDebugLevel_ = level; |
---|
| 145 | else if (device == OutputHandler::LD_Console) |
---|
| 146 | Core::getInstance().softDebugLevelConsole_ = level; |
---|
| 147 | else if (device == OutputHandler::LD_Logfile) |
---|
| 148 | Core::getInstance().softDebugLevelLogfile_ = level; |
---|
| 149 | else if (device == OutputHandler::LD_Shell) |
---|
| 150 | Core::getInstance().softDebugLevelShell_ = level; |
---|
[1747] | 151 | |
---|
[2662] | 152 | OutputHandler::setSoftDebugLevel(device, level); |
---|
[1505] | 153 | } |
---|
| 154 | |
---|
| 155 | /** |
---|
| 156 | @brief Returns the configured language. |
---|
| 157 | */ |
---|
[1524] | 158 | const std::string& Core::getLanguage() |
---|
[1505] | 159 | { |
---|
[2662] | 160 | return Core::getInstance().language_; |
---|
[1505] | 161 | } |
---|
| 162 | |
---|
| 163 | /** |
---|
| 164 | @brief Sets the language in the config-file back to the default. |
---|
| 165 | */ |
---|
[1524] | 166 | void Core::resetLanguage() |
---|
[1505] | 167 | { |
---|
[1524] | 168 | Core::getInstance().resetLanguageIntern(); |
---|
[1505] | 169 | } |
---|
| 170 | |
---|
| 171 | /** |
---|
| 172 | @brief Sets the language in the config-file back to the default. |
---|
| 173 | */ |
---|
[1524] | 174 | void Core::resetLanguageIntern() |
---|
[1505] | 175 | { |
---|
| 176 | ResetConfigValue(language_); |
---|
| 177 | } |
---|
[2662] | 178 | |
---|
| 179 | void Core::initializeRandomNumberGenerator() |
---|
| 180 | { |
---|
| 181 | static bool bInitialized = false; |
---|
| 182 | if (!bInitialized && this->bInitializeRandomNumberGenerator_) |
---|
| 183 | { |
---|
| 184 | srand(time(0)); |
---|
| 185 | rand(); |
---|
| 186 | bInitialized = true; |
---|
| 187 | } |
---|
| 188 | } |
---|
[1505] | 189 | } |
---|