Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core7/src/libraries/core/CoreConfig.cc @ 10479

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

moved config values and all related functions from Game and Core to GameConfig and CoreConfig respectively. this ensures that no framework features are used by Game and Core before Core itself initialized the framework.

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