Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/core/CoreSettings.cc @ 1056

Last change on this file since 1056 was 1056, checked in by landauf, 17 years ago

don't panic, no codechanges!
added a link to www.orxonox.net

File size: 5.4 KB
Line 
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 *      ...
26 *
27 */
28
29/**
30    @file CoreSettings.cc
31    @brief Implementation of the CoreSettings class.
32*/
33
34#include "CoreSettings.h"
35#include "Language.h"
36#include "CoreIncludes.h"
37#include "ConfigValueIncludes.h"
38
39namespace orxonox
40{
41    /**
42        @brief Constructor: Registers the object and sets the config-values.
43        @param A reference to a global variable, used to avoid an infinite recursion in getSoftDebugLevel()
44    */
45    CoreSettings::CoreSettings()
46    {
47        RegisterRootObject(CoreSettings);
48        this->setConfigValues();
49    }
50
51    bool& CoreSettings::isCreatingCoreSettings()
52    {
53        static bool bCreatingCoreSettings = true;
54        static bool bFirstTime = true;
55        if (bFirstTime)
56        {
57            bFirstTime = false;
58            CoreSettings::getInstance();
59        }
60        return bCreatingCoreSettings;
61    }
62
63    /**
64        @brief Returns a unique instance of CoreSettings.
65        @return The instance
66    */
67    CoreSettings& CoreSettings::getInstance()
68    {
69        static CoreSettings instance = CoreSettings();
70
71        // If bCreatingSoftDebugLevelObject is true, we're just about to create an instance of the DebugLevel class
72        if (CoreSettings::isCreatingCoreSettings())
73        {
74            isCreatingCoreSettings() = false;
75            instance.setConfigValues();
76        }
77        return instance;
78    }
79
80    /**
81        @brief Function to collect the SetConfigValue-macro calls.
82    */
83    void CoreSettings::setConfigValues()
84    {
85        SetConfigValue(softDebugLevelConsole_, 3).description("The maximal level of debug output shown in the console");
86        SetConfigValue(softDebugLevelLogfile_, 3).description("The maximal level of debug output shown in the logfile");
87        SetConfigValue(softDebugLevelShell_, 1).description("The maximal level of debug output shown in the ingame shell");
88
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
96
97        std::string temp = this->language_;
98        SetConfigValue(language_, Language::getLanguage().defaultLanguage_).description("The language of the ingame text");
99
100        if (this->language_ != temp)
101        {
102            // Read the translation file after the language was configured
103            Language::getLanguage().readTranslatedLanguageFile();
104        }
105    }
106
107    /**
108        @brief Static function that holds the singleton.
109    */
110    int CoreSettings::getSoftDebugLevel(OutputHandler::OutputDevice device)
111    {
112        if (!CoreSettings::isCreatingCoreSettings())
113        {
114            if (device == OutputHandler::LD_All)
115                return CoreSettings::getInstance().softDebugLevel_;
116            else if (device == OutputHandler::LD_Console)
117                return CoreSettings::getInstance().softDebugLevelConsole_;
118            else if (device == OutputHandler::LD_Logfile)
119                return CoreSettings::getInstance().softDebugLevelLogfile_;
120            else if (device == OutputHandler::LD_Shell)
121                return CoreSettings::getInstance().softDebugLevelShell_;
122        }
123
124        // Return a constant value while we're creating the object
125        return 2;
126    }
127
128    /**
129        @brief Returns the configured language.
130    */
131    const std::string& CoreSettings::getLanguage()
132    {
133        if (!CoreSettings::isCreatingCoreSettings())
134            return CoreSettings::getInstance().language_;
135
136        return Language::getLanguage().defaultLanguage_;
137    }
138
139    /**
140        @brief Sets the language in the config-file back to the default.
141    */
142    void CoreSettings::resetLanguage()
143    {
144        CoreSettings::getInstance().resetLanguageIntern();
145    }
146
147    /**
148        @brief Sets the language in the config-file back to the default.
149    */
150    void CoreSettings::resetLanguageIntern()
151    {
152        ResetConfigValue(language_);
153    }
154}
155
156/**
157    @brief Returns the soft debug level, stored in the only existing instance of the DebugLevel class, configured in the config-file.
158    @return The soft debug level
159*/
160int getSoftDebugLevel()
161{
162    return orxonox::CoreSettings::getSoftDebugLevel();
163}
Note: See TracBrowser for help on using the repository browser.