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