Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation/src/core/Core.cc @ 2736

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

Merged objecthierarchy2 into presentation branch

Couln't merge 2 lines in Gamestate.cc and a whole block of code in GSDedicated.cc (it seems like oli implemented in both branches something like a network-tick-limiter but with different approaches)

Not yet tested in network mode and with bots
The SpaceShips movement is also not yet fully adopted to the new physics (see Engine class)

  • Property svn:eol-style set to native
File size: 6.5 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 *      Reto Grieder
26 *
27 */
28
29/**
30    @file
31    @brief Implementation of the Core class.
32*/
33
34#include "Core.h"
35#include <cassert>
36#include "Language.h"
37#include "CoreIncludes.h"
38#include "ConfigValueIncludes.h"
39
40namespace orxonox
41{
42    bool Core::bShowsGraphics_s = false;
43    bool Core::bHasServer_s     = false;
44    bool Core::bIsClient_s      = false;
45    bool Core::bIsStandalone_s  = false;
46    bool Core::bIsMaster_s      = false;
47
48    Core* Core::singletonRef_s = 0;
49
50    /**
51        @brief Constructor: Registers the object and sets the config-values.
52        @param A reference to a global variable, used to avoid an infinite recursion in getSoftDebugLevel()
53    */
54    Core::Core()
55    {
56        RegisterRootObject(Core);
57
58        assert(Core::singletonRef_s == 0);
59        Core::singletonRef_s = this;
60        this->bInitializeRandomNumberGenerator_ = false;
61
62        this->setConfigValues();
63    }
64
65    /**
66        @brief Sets the bool to true to avoid static functions accessing a deleted object.
67    */
68    Core::~Core()
69    {
70        assert(Core::singletonRef_s);
71        Core::singletonRef_s = 0;
72    }
73
74    /**
75        @brief Function to collect the SetConfigValue-macro calls.
76    */
77    void Core::setConfigValues()
78    {
79        SetConfigValue(softDebugLevelConsole_, 3).description("The maximal level of debug output shown in the console").callback(this, &Core::debugLevelChanged);
80        SetConfigValue(softDebugLevelLogfile_, 3).description("The maximal level of debug output shown in the logfile").callback(this, &Core::debugLevelChanged);
81        SetConfigValue(softDebugLevelShell_, 1).description("The maximal level of debug output shown in the ingame shell").callback(this, &Core::debugLevelChanged);
82        SetConfigValue(language_, Language::getLanguage().defaultLanguage_).description("The language of the ingame text").callback(this, &Core::languageChanged);
83        SetConfigValue(bInitializeRandomNumberGenerator_, true).description("If true, all random actions are different each time you start the game").callback(this, &Core::initializeRandomNumberGenerator);
84    }
85
86    /**
87        @brief Callback function if the debug level has changed.
88    */
89    void Core::debugLevelChanged()
90    {
91        // softDebugLevel_ is the maximum of the 3 variables
92        this->softDebugLevel_ = this->softDebugLevelConsole_;
93        if (this->softDebugLevelLogfile_ > this->softDebugLevel_)
94            this->softDebugLevel_ = this->softDebugLevelLogfile_;
95        if (this->softDebugLevelShell_ > this->softDebugLevel_)
96            this->softDebugLevel_ = this->softDebugLevelShell_;
97
98        OutputHandler::setSoftDebugLevel(OutputHandler::LD_All,     this->softDebugLevel_);
99        OutputHandler::setSoftDebugLevel(OutputHandler::LD_Console, this->softDebugLevelConsole_);
100        OutputHandler::setSoftDebugLevel(OutputHandler::LD_Logfile, this->softDebugLevelLogfile_);
101        OutputHandler::setSoftDebugLevel(OutputHandler::LD_Shell,   this->softDebugLevelShell_);
102    }
103
104    /**
105        @brief Callback function if the language has changed.
106    */
107    void Core::languageChanged()
108    {
109        // Read the translation file after the language was configured
110        Language::getLanguage().readTranslatedLanguageFile();
111    }
112
113    /**
114        @brief Returns the softDebugLevel for the given device (returns a default-value if the class ist right about to be created).
115        @param device The device
116        @return The softDebugLevel
117    */
118    int Core::getSoftDebugLevel(OutputHandler::OutputDevice device)
119    {
120        switch (device)
121        {
122        case OutputHandler::LD_All:
123            return Core::getInstance().softDebugLevel_;
124        case OutputHandler::LD_Console:
125            return Core::getInstance().softDebugLevelConsole_;
126        case OutputHandler::LD_Logfile:
127            return Core::getInstance().softDebugLevelLogfile_;
128        case OutputHandler::LD_Shell:
129            return Core::getInstance().softDebugLevelShell_;
130        default:
131            assert(0);
132            return 2;
133        }
134    }
135
136     /**
137        @brief Sets the softDebugLevel for the given device. Please use this only temporary and restore the value afterwards, as it overrides the configured value.
138        @param device The device
139        @param level The level
140    */
141     void Core::setSoftDebugLevel(OutputHandler::OutputDevice device, int level)
142     {
143        if (device == OutputHandler::LD_All)
144            Core::getInstance().softDebugLevel_ = level;
145        else if (device == OutputHandler::LD_Console)
146            Core::getInstance().softDebugLevelConsole_ = level;
147        else if (device == OutputHandler::LD_Logfile)
148            Core::getInstance().softDebugLevelLogfile_ = level;
149        else if (device == OutputHandler::LD_Shell)
150            Core::getInstance().softDebugLevelShell_ = level;
151
152        OutputHandler::setSoftDebugLevel(device, level);
153     }
154
155    /**
156        @brief Returns the configured language.
157    */
158    const std::string& Core::getLanguage()
159    {
160        return Core::getInstance().language_;
161    }
162
163    /**
164        @brief Sets the language in the config-file back to the default.
165    */
166    void Core::resetLanguage()
167    {
168        Core::getInstance().resetLanguageIntern();
169    }
170
171    /**
172        @brief Sets the language in the config-file back to the default.
173    */
174    void Core::resetLanguageIntern()
175    {
176        ResetConfigValue(language_);
177    }
178
179    void Core::initializeRandomNumberGenerator()
180    {
181        static bool bInitialized = false;
182        if (!bInitialized && this->bInitializeRandomNumberGenerator_)
183        {
184            srand(time(0));
185            rand();
186            bInitialized = true;
187        }
188    }
189}
Note: See TracBrowser for help on using the repository browser.