Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/core/CoreSettings.cc @ 1052

Last change on this file since 1052 was 1052, checked in by landauf, 16 years ago

merged core2 back to trunk
there might be some errors, wasn't able to test it yet due to some strange g++ and linker behaviour.

File size: 5.3 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *
4 *
5 *   License notice:
6 *
7 *   This program is free software; you can redistribute it and/or
8 *   modify it under the terms of the GNU General Public License
9 *   as published by the Free Software Foundation; either version 2
10 *   of the License, or (at your option) any later version.
11 *
12 *   This program is distributed in the hope that it will be useful,
13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 *   GNU General Public License for more details.
16 *
17 *   You should have received a copy of the GNU General Public License
18 *   along with this program; if not, write to the Free Software
19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 *
21 *   Author:
22 *      Fabian 'x3n' Landau
23 *   Co-authors:
24 *      ...
25 *
26 */
27
28/**
29    @file CoreSettings.cc
30    @brief Implementation of the CoreSettings class.
31*/
32
33#include "CoreSettings.h"
34#include "Language.h"
35#include "CoreIncludes.h"
36#include "ConfigValueIncludes.h"
37
38namespace orxonox
39{
40    /**
41        @brief Constructor: Registers the object and sets the config-values.
42        @param A reference to a global variable, used to avoid an infinite recursion in getSoftDebugLevel()
43    */
44    CoreSettings::CoreSettings()
45    {
46        RegisterRootObject(CoreSettings);
47        this->setConfigValues();
48    }
49
50    bool& CoreSettings::isCreatingCoreSettings()
51    {
52        static bool bCreatingCoreSettings = true;
53        static bool bFirstTime = true;
54        if (bFirstTime)
55        {
56            bFirstTime = false;
57            CoreSettings::getInstance();
58        }
59        return bCreatingCoreSettings;
60    }
61
62    /**
63        @brief Returns a unique instance of CoreSettings.
64        @return The instance
65    */
66    CoreSettings& CoreSettings::getInstance()
67    {
68        static CoreSettings instance = CoreSettings();
69
70        // If bCreatingSoftDebugLevelObject is true, we're just about to create an instance of the DebugLevel class
71        if (CoreSettings::isCreatingCoreSettings())
72        {
73            isCreatingCoreSettings() = false;
74            instance.setConfigValues();
75        }
76        return instance;
77    }
78
79    /**
80        @brief Function to collect the SetConfigValue-macro calls.
81    */
82    void CoreSettings::setConfigValues()
83    {
84        SetConfigValue(softDebugLevelConsole_, 3).description("The maximal level of debug output shown in the console");
85        SetConfigValue(softDebugLevelLogfile_, 3).description("The maximal level of debug output shown in the logfile");
86        SetConfigValue(softDebugLevelShell_, 1).description("The maximal level of debug output shown in the ingame shell");
87
88        // softDebugLevel_ is the maximum of the 3 variables
89        this->softDebugLevel_ = this->softDebugLevelConsole_;
90        if (this->softDebugLevelLogfile_ > this->softDebugLevel_)
91            this->softDebugLevel_ = this->softDebugLevelLogfile_;
92        if (this->softDebugLevelShell_ > this->softDebugLevel_)
93            this->softDebugLevel_ = this->softDebugLevelShell_;
94
95
96        std::string temp = this->language_;
97        SetConfigValue(language_, Language::getLanguage().defaultLanguage_).description("The language of the ingame text");
98
99        if (this->language_ != temp)
100        {
101            // Read the translation file after the language was configured
102            Language::getLanguage().readTranslatedLanguageFile();
103        }
104    }
105
106    /**
107        @brief Static function that holds the singleton.
108    */
109    int CoreSettings::getSoftDebugLevel(OutputHandler::OutputDevice device)
110    {
111        if (!CoreSettings::isCreatingCoreSettings())
112        {
113            if (device == OutputHandler::LD_All)
114                return CoreSettings::getInstance().softDebugLevel_;
115            else if (device == OutputHandler::LD_Console)
116                return CoreSettings::getInstance().softDebugLevelConsole_;
117            else if (device == OutputHandler::LD_Logfile)
118                return CoreSettings::getInstance().softDebugLevelLogfile_;
119            else if (device == OutputHandler::LD_Shell)
120                return CoreSettings::getInstance().softDebugLevelShell_;
121        }
122
123        // Return a constant value while we're creating the object
124        return 2;
125    }
126
127    /**
128        @brief Returns the configured language.
129    */
130    const std::string& CoreSettings::getLanguage()
131    {
132        if (!CoreSettings::isCreatingCoreSettings())
133            return CoreSettings::getInstance().language_;
134
135        return Language::getLanguage().defaultLanguage_;
136    }
137
138    /**
139        @brief Sets the language in the config-file back to the default.
140    */
141    void CoreSettings::resetLanguage()
142    {
143        CoreSettings::getInstance().resetLanguageIntern();
144    }
145
146    /**
147        @brief Sets the language in the config-file back to the default.
148    */
149    void CoreSettings::resetLanguageIntern()
150    {
151        ResetConfigValue(language_);
152    }
153}
154
155/**
156    @brief Returns the soft debug level, stored in the only existing instance of the DebugLevel class, configured in the config-file.
157    @return The soft debug level
158*/
159int getSoftDebugLevel()
160{
161    return orxonox::CoreSettings::getSoftDebugLevel();
162}
Note: See TracBrowser for help on using the repository browser.