Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/core/CoreConfig.cc @ 10741

Last change on this file since 10741 was 10624, checked in by landauf, 9 years ago

merged branch core7 back to trunk

File size: 7.1 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#include "CoreConfig.h"
30
31#include "util/output/LogWriter.h"
32#include "util/output/OutputManager.h"
33#include "core/CoreIncludes.h"
34#include "core/config/ConfigValueIncludes.h"
35#include "core/Language.h"
36#include "core/ApplicationPaths.h"
37
38namespace orxonox
39{
40    RegisterClassNoArgs(CoreConfig);
41
42    CoreConfig::CoreConfig()
43        : bDevMode_(false)
44        , bStartIOConsole_(true)
45        , lastLevelTimestamp_(0)
46        , ogreConfigTimestamp_(0)
47    {
48        RegisterObject(CoreConfig);
49        this->setConfigValues();
50    }
51
52    //! Function to collect the SetConfigValue-macro calls.
53    void CoreConfig::setConfigValues()
54    {
55        SetConfigValueExternal(OutputManager::getInstance().getLogWriter()->configurableMaxLevel_,
56                               OutputManager::getInstance().getLogWriter()->getConfigurableSectionName(),
57                               OutputManager::getInstance().getLogWriter()->getConfigurableMaxLevelName(),
58                               OutputManager::getInstance().getLogWriter()->configurableMaxLevel_)
59            .description("The maximum level of output shown in the log file")
60            .callback(static_cast<BaseWriter*>(OutputManager::getInstance().getLogWriter()), &BaseWriter::changedConfigurableLevel);
61        SetConfigValueExternal(OutputManager::getInstance().getLogWriter()->configurableAdditionalContextsMaxLevel_,
62                               OutputManager::getInstance().getLogWriter()->getConfigurableSectionName(),
63                               OutputManager::getInstance().getLogWriter()->getConfigurableAdditionalContextsMaxLevelName(),
64                               OutputManager::getInstance().getLogWriter()->configurableAdditionalContextsMaxLevel_)
65            .description("The maximum level of output shown in the log file for additional contexts")
66            .callback(static_cast<BaseWriter*>(OutputManager::getInstance().getLogWriter()), &BaseWriter::changedConfigurableAdditionalContextsLevel);
67        SetConfigValueExternal(OutputManager::getInstance().getLogWriter()->configurableAdditionalContexts_,
68                               OutputManager::getInstance().getLogWriter()->getConfigurableSectionName(),
69                               OutputManager::getInstance().getLogWriter()->getConfigurableAdditionalContextsName(),
70                               OutputManager::getInstance().getLogWriter()->configurableAdditionalContexts_)
71            .description("Additional output contexts shown in the log file")
72            .callback(static_cast<BaseWriter*>(OutputManager::getInstance().getLogWriter()), &BaseWriter::changedConfigurableAdditionalContexts);
73
74        SetConfigValue(bDevMode_, ApplicationPaths::buildDirectoryRun())
75            .description("Developer mode. If not set, hides some things from the user to not confuse him.")
76            .callback(this, &CoreConfig::devModeChanged);
77        SetConfigValue(language_, Language::getInstance().defaultLanguage_)
78            .description("The language of the in game text")
79            .callback(this, &CoreConfig::languageChanged);
80        SetConfigValue(bInitRandomNumberGenerator_, true)
81            .description("If true, all random actions are different each time you start the game")
82            .callback(this, &CoreConfig::initRandomNumberGenerator);
83        SetConfigValue(bStartIOConsole_, true)
84            .description("Set to false if you don't want to use the IOConsole (for Lua debugging for instance)");
85        SetConfigValue(lastLevelTimestamp_, 0)
86            .description("Timestamp when the last level was started.");
87        SetConfigValue(ogreConfigTimestamp_, 0)
88            .description("Timestamp when the ogre config file was changed.");
89    }
90
91    /** Callback function for changes in the dev mode that affect debug levels.
92        The function behaves according to these rules:
93        - 'normal' mode is defined based on where the program was launched: if
94          the launch path was the build directory, development mode \c on is
95          normal, otherwise normal means development mode \c off.
96        - Debug levels should not be hard configured (\c config instead of
97          \c tconfig) in non 'normal' mode to avoid strange behaviour.
98        - Changing the development mode from 'normal' to the other state will
99          immediately change the debug levels to predefined values which can be
100          reconfigured with \c tconfig.
101    @note
102        The debug levels for the IOConsole and the InGameConsole can be found
103        in the Shell class. The same rules apply.
104    */
105    void CoreConfig::devModeChanged()
106    {
107        // Inform listeners
108        ObjectList<DevModeListener>::iterator it = ObjectList<DevModeListener>::begin();
109        for (; it != ObjectList<DevModeListener>::end(); ++it)
110            it->devModeChanged(bDevMode_);
111    }
112
113    //! Callback function if the language has changed.
114    void CoreConfig::languageChanged()
115    {
116        // Read the translation file after the language was configured
117        bool success = Language::getInstance().readTranslatedLanguageFile(this->language_);
118        if (!success)
119        {
120            // Set the language in the config-file back to the default.
121            ResetConfigValue(language_);
122            orxout(internal_info, context::language) << "Reset language to " << this->language_ << '.' << endl;
123        }
124    }
125
126    void CoreConfig::initRandomNumberGenerator()
127    {
128        static bool bInitialized = false;
129        if (!bInitialized && this->bInitRandomNumberGenerator_)
130        {
131            srand(static_cast<unsigned int>(time(0)));
132            rand();
133            bInitialized = true;
134        }
135    }
136
137    void CoreConfig::updateLastLevelTimestamp()
138    {
139        ModifyConfigValue(lastLevelTimestamp_, set, static_cast<long long>(time(NULL)));
140    }
141
142    void CoreConfig::updateOgreConfigTimestamp()
143    {
144        ModifyConfigValue(ogreConfigTimestamp_, set, static_cast<long long>(time(NULL)));
145    }
146
147
148    RegisterAbstractClass(DevModeListener).inheritsFrom<Listable>();
149
150    DevModeListener::DevModeListener()
151    {
152        RegisterObject(DevModeListener);
153    }
154}
Note: See TracBrowser for help on using the repository browser.