Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/mergeFS18/src/libraries/core/CoreConfig.cc @ 12258

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

merged branch cpp11_v3 back to trunk

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