Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy2/src/core/Core.cc @ 2344

Last change on this file since 2344 was 2344, checked in by rgrieder, 16 years ago

Completed destruction of static elements like XMLPort, Identifier, etc.
Of initially about 250 memory leaks (not in the actual meaning but the memory was never freed anyway) only 1 remains in TinyCpp.

  • Core class is now a normal Singleton that gets created and destroyed in main.
  • The same goes for Language, LuaBind, SignalHandler and PlayerManager.
  • Added a new std::set to the CommandExecutor so that the external ConsoleCommands can get destroyed too.
  • Code for destroying CommandLineArguments
  • Added destruction code for ConstructionCallbacks in Identifier
  • Moved internal identifier map (the one with the typeid(.) names) in a static function in Identifier. This was necessary in order to destroy ALL Identifiers with the static destruction function. Before it was possible to create an Identifier with having a class instance (that would call RegisterObject) for instance by simply accessing it via getIdentifier.
  • Removed a big memory leak in Button (forgot to destroy the ConfigValueContainers)
  • Added destruction code for InputBufferListenerTuples in InputBuffer destructor.
  • Added destruction code for load and save executors in both XMLPortParam and XMLPortObject
  • Added destruction code for ConsoleCommands in GSRoot, GSGraphics and GSLevel (temporary solution anyway)
  • Deleting the CEGUILua script module seems to work properly now, one memory leak less (GUIManager.cc)
  • Added global destruction calls in Main.cc
  • Property svn:eol-style set to native
File size: 5.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 *      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(singletonRef_s == 0);
59        singletonRef_s = this;
60
61        this->setConfigValues();
62    }
63
64    /**
65        @brief Sets the bool to true to avoid static functions accessing a deleted object.
66    */
67    Core::~Core()
68    {
69        assert(singletonRef_s);
70        singletonRef_s = 0;
71    }
72
73    /**
74        @brief Function to collect the SetConfigValue-macro calls.
75    */
76    void Core::setConfigValues()
77    {
78        SetConfigValue(softDebugLevelConsole_, 3).description("The maximal level of debug output shown in the console").callback(this, &Core::debugLevelChanged);
79        SetConfigValue(softDebugLevelLogfile_, 3).description("The maximal level of debug output shown in the logfile").callback(this, &Core::debugLevelChanged);
80        SetConfigValue(softDebugLevelShell_, 1).description("The maximal level of debug output shown in the ingame shell").callback(this, &Core::debugLevelChanged);
81        SetConfigValue(language_, Language::getLanguage().defaultLanguage_).description("The language of the ingame text").callback(this, &Core::languageChanged);
82    }
83
84    /**
85        @brief Callback function if the debug level has changed.
86    */
87    void Core::debugLevelChanged()
88    {
89        // softDebugLevel_ is the maximum of the 3 variables
90        this->softDebugLevel_ = this->softDebugLevelConsole_;
91        if (this->softDebugLevelLogfile_ > this->softDebugLevel_)
92            this->softDebugLevel_ = this->softDebugLevelLogfile_;
93        if (this->softDebugLevelShell_ > this->softDebugLevel_)
94            this->softDebugLevel_ = this->softDebugLevelShell_;
95
96        OutputHandler::setSoftDebugLevel(OutputHandler::LD_All,     this->softDebugLevel_);
97        OutputHandler::setSoftDebugLevel(OutputHandler::LD_Console, this->softDebugLevelConsole_);
98        OutputHandler::setSoftDebugLevel(OutputHandler::LD_Logfile, this->softDebugLevelLogfile_);
99        OutputHandler::setSoftDebugLevel(OutputHandler::LD_Shell,   this->softDebugLevelShell_);
100    }
101
102    /**
103        @brief Callback function if the language has changed.
104    */
105    void Core::languageChanged()
106    {
107        // Read the translation file after the language was configured
108        Language::getLanguage().readTranslatedLanguageFile();
109    }
110
111    /**
112        @brief Returns the softDebugLevel for the given device (returns a default-value if the class ist right about to be created).
113        @param device The device
114        @return The softDebugLevel
115    */
116    int Core::getSoftDebugLevel(OutputHandler::OutputDevice device)
117    {
118        switch (device)
119        {
120        case OutputHandler::LD_All:
121            return Core::getInstance().softDebugLevel_;
122        case OutputHandler::LD_Console:
123            return Core::getInstance().softDebugLevelConsole_;
124        case OutputHandler::LD_Logfile:
125            return Core::getInstance().softDebugLevelLogfile_;
126        case OutputHandler::LD_Shell:
127            return Core::getInstance().softDebugLevelShell_;
128        default:
129            assert(0);
130            return 2;
131        }
132    }
133
134     /**
135        @brief Sets the softDebugLevel for the given device. Please use this only temporary and restore the value afterwards, as it overrides the configured value.
136        @param device The device
137        @param level The level
138    */
139     void Core::setSoftDebugLevel(OutputHandler::OutputDevice device, int level)
140     {
141        if (device == OutputHandler::LD_All)
142            Core::getInstance().softDebugLevel_ = level;
143        else if (device == OutputHandler::LD_Console)
144            Core::getInstance().softDebugLevelConsole_ = level;
145        else if (device == OutputHandler::LD_Logfile)
146            Core::getInstance().softDebugLevelLogfile_ = level;
147        else if (device == OutputHandler::LD_Shell)
148            Core::getInstance().softDebugLevelShell_ = level;
149
150        OutputHandler::setSoftDebugLevel(device, level);
151     }
152
153    /**
154        @brief Returns the configured language.
155    */
156    const std::string& Core::getLanguage()
157    {
158        return Core::getInstance().language_;
159    }
160
161    /**
162        @brief Sets the language in the config-file back to the default.
163    */
164    void Core::resetLanguage()
165    {
166        Core::getInstance().resetLanguageIntern();
167    }
168
169    /**
170        @brief Sets the language in the config-file back to the default.
171    */
172    void Core::resetLanguageIntern()
173    {
174        ResetConfigValue(language_);
175    }
176}
Note: See TracBrowser for help on using the repository browser.