[Orxonox-commit 5819] r10479 - in code/branches/core7/src: libraries/core libraries/core/class libraries/core/command orxonox/gamestates orxonox/gametypes
landauf at orxonox.net
landauf at orxonox.net
Mon May 25 19:20:21 CEST 2015
Author: landauf
Date: 2015-05-25 19:20:21 +0200 (Mon, 25 May 2015)
New Revision: 10479
Added:
code/branches/core7/src/libraries/core/CoreConfig.cc
code/branches/core7/src/libraries/core/CoreConfig.h
code/branches/core7/src/libraries/core/GameConfig.cc
code/branches/core7/src/libraries/core/GameConfig.h
Modified:
code/branches/core7/src/libraries/core/CMakeLists.txt
code/branches/core7/src/libraries/core/Core.cc
code/branches/core7/src/libraries/core/Core.h
code/branches/core7/src/libraries/core/CorePrereqs.h
code/branches/core7/src/libraries/core/GUIManager.cc
code/branches/core7/src/libraries/core/Game.cc
code/branches/core7/src/libraries/core/Game.h
code/branches/core7/src/libraries/core/GraphicsManager.cc
code/branches/core7/src/libraries/core/Language.cc
code/branches/core7/src/libraries/core/Language.h
code/branches/core7/src/libraries/core/class/IdentifierManager.cc
code/branches/core7/src/libraries/core/command/Shell.h
code/branches/core7/src/orxonox/gamestates/GSLevel.cc
code/branches/core7/src/orxonox/gametypes/Gametype.cc
Log:
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.
Modified: code/branches/core7/src/libraries/core/CMakeLists.txt
===================================================================
--- code/branches/core7/src/libraries/core/CMakeLists.txt 2015-05-25 15:37:15 UTC (rev 10478)
+++ code/branches/core7/src/libraries/core/CMakeLists.txt 2015-05-25 17:20:21 UTC (rev 10479)
@@ -25,6 +25,7 @@
DynLibManager.cc
Event.cc
Game.cc
+ GameConfig.cc
GameMode.cc
GameState.cc
Language.cc
@@ -42,6 +43,7 @@
BaseObject.cc
Core.cc
+ CoreConfig.cc
BUILD_UNIT OgreBuildUnit.cc
GraphicsManager.cc
Modified: code/branches/core7/src/libraries/core/Core.cc
===================================================================
--- code/branches/core7/src/libraries/core/Core.cc 2015-05-25 15:37:15 UTC (rev 10478)
+++ code/branches/core7/src/libraries/core/Core.cc 2015-05-25 17:20:21 UTC (rev 10479)
@@ -61,8 +61,6 @@
#include "PathConfig.h"
#include "commandline/CommandLineIncludes.h"
#include "config/ConfigFileManager.h"
-#include "config/ConfigValueIncludes.h"
-#include "CoreIncludes.h"
#include "DynLibManager.h"
#include "GameMode.h"
#include "GraphicsManager.h"
@@ -94,9 +92,6 @@
SetCommandLineArgument(limitToCPU, 0).information("Limits the program to one CPU/core (1, 2, 3, etc.). Default is off = 0.");
#endif
- // register Core as an abstract class to avoid problems if the class hierarchy is created within Core-constructor
- RegisterAbstractClass(Core).inheritsFrom<Configurable>();
-
Core::Core(const std::string& cmdLine)
: pathConfig_(NULL)
, dynLibManager_(NULL)
@@ -113,10 +108,7 @@
, guiManager_(NULL)
, graphicsScope_(NULL)
, bGraphicsLoaded_(false)
- , bStartIOConsole_(true)
- , lastLevelTimestamp_(0)
- , ogreConfigTimestamp_(0)
- , bDevMode_(false)
+ , config_(NULL)
, destructionHelper_(this)
{
orxout(internal_status) << "initializing Core object..." << endl;
@@ -187,21 +179,17 @@
// Do this soon after the ConfigFileManager has been created to open up the
// possibility to configure everything below here
- RegisterObject(Core);
orxout(internal_info) << "configuring Core" << endl;
- this->setConfigValues();
+ this->config_ = new CoreConfig();
+ this->config_->setConfigValues(); // TODO: move this into CoreConfig constructor (but resolve dependency to Language)
// Set the correct log path and rewrite the log file with the correct log levels
OutputManager::getInstance().getLogWriter()->setLogDirectory(PathConfig::getLogPathString());
#if !defined(ORXONOX_PLATFORM_APPLE) && !defined(ORXONOX_USE_WINMAIN)
// Create persistent IO console
- if (CommandLineParser::getValue("noIOConsole").get<bool>())
+ if (CommandLineParser::getValue("noIOConsole").get<bool>() == false && this->config_->getStartIOConsole())
{
- ModifyConfigValue(bStartIOConsole_, tset, false);
- }
- if (this->bStartIOConsole_)
- {
orxout(internal_info) << "creating IO console" << endl;
this->ioConsole_ = new IOConsole();
}
@@ -248,9 +236,6 @@
{
orxout(internal_status) << "destroying Core object..." << endl;
- // Remove us from the object lists again to avoid problems when destroying them
- this->unregisterObject();
-
safeObjectDelete(&graphicsScope_);
safeObjectDelete(&guiManager_);
safeObjectDelete(&inputManager_);
@@ -260,6 +245,7 @@
safeObjectDelete(&tclBind_);
safeObjectDelete(&ioConsole_);
safeObjectDelete(&loaderInstance_);
+ safeObjectDelete(&config_);
safeObjectDelete(&languageInstance_);
safeObjectDelete(&configFileManager_);
ConsoleCommandManager::destroyAll();
@@ -272,85 +258,6 @@
orxout(internal_status) << "finished destroying Core object" << endl;
}
- //! Function to collect the SetConfigValue-macro calls.
- void Core::setConfigValues()
- {
- SetConfigValueExternal(OutputManager::getInstance().getLogWriter()->configurableMaxLevel_,
- OutputManager::getInstance().getLogWriter()->getConfigurableSectionName(),
- OutputManager::getInstance().getLogWriter()->getConfigurableMaxLevelName(),
- OutputManager::getInstance().getLogWriter()->configurableMaxLevel_)
- .description("The maximum level of output shown in the log file")
- .callback(static_cast<BaseWriter*>(OutputManager::getInstance().getLogWriter()), &BaseWriter::changedConfigurableLevel);
- SetConfigValueExternal(OutputManager::getInstance().getLogWriter()->configurableAdditionalContextsMaxLevel_,
- OutputManager::getInstance().getLogWriter()->getConfigurableSectionName(),
- OutputManager::getInstance().getLogWriter()->getConfigurableAdditionalContextsMaxLevelName(),
- OutputManager::getInstance().getLogWriter()->configurableAdditionalContextsMaxLevel_)
- .description("The maximum level of output shown in the log file for additional contexts")
- .callback(static_cast<BaseWriter*>(OutputManager::getInstance().getLogWriter()), &BaseWriter::changedConfigurableAdditionalContextsLevel);
- SetConfigValueExternal(OutputManager::getInstance().getLogWriter()->configurableAdditionalContexts_,
- OutputManager::getInstance().getLogWriter()->getConfigurableSectionName(),
- OutputManager::getInstance().getLogWriter()->getConfigurableAdditionalContextsName(),
- OutputManager::getInstance().getLogWriter()->configurableAdditionalContexts_)
- .description("Additional output contexts shown in the log file")
- .callback(static_cast<BaseWriter*>(OutputManager::getInstance().getLogWriter()), &BaseWriter::changedConfigurableAdditionalContexts);
-
- SetConfigValue(bDevMode_, PathConfig::buildDirectoryRun())
- .description("Developer mode. If not set, hides some things from the user to not confuse him.")
- .callback(this, &Core::devModeChanged);
- SetConfigValue(language_, Language::getInstance().defaultLanguage_)
- .description("The language of the in game text")
- .callback(this, &Core::languageChanged);
- SetConfigValue(bInitRandomNumberGenerator_, true)
- .description("If true, all random actions are different each time you start the game")
- .callback(this, &Core::initRandomNumberGenerator);
- SetConfigValue(bStartIOConsole_, true)
- .description("Set to false if you don't want to use the IOConsole (for Lua debugging for instance)");
- SetConfigValue(lastLevelTimestamp_, 0)
- .description("Timestamp when the last level was started.");
- SetConfigValue(ogreConfigTimestamp_, 0)
- .description("Timestamp when the ogre config file was changed.");
- }
-
- /** Callback function for changes in the dev mode that affect debug levels.
- The function behaves according to these rules:
- - 'normal' mode is defined based on where the program was launched: if
- the launch path was the build directory, development mode \c on is
- normal, otherwise normal means development mode \c off.
- - Debug levels should not be hard configured (\c config instead of
- \c tconfig) in non 'normal' mode to avoid strange behaviour.
- - Changing the development mode from 'normal' to the other state will
- immediately change the debug levels to predefined values which can be
- reconfigured with \c tconfig.
- @note
- The debug levels for the IOConsole and the InGameConsole can be found
- in the Shell class. The same rules apply.
- */
- void Core::devModeChanged()
- {
- // Inform listeners
- ObjectList<DevModeListener>::iterator it = ObjectList<DevModeListener>::begin();
- for (; it != ObjectList<DevModeListener>::end(); ++it)
- it->devModeChanged(bDevMode_);
- }
-
- //! Callback function if the language has changed.
- void Core::languageChanged()
- {
- // Read the translation file after the language was configured
- Language::getInstance().readTranslatedLanguageFile();
- }
-
- void Core::initRandomNumberGenerator()
- {
- static bool bInitialized = false;
- if (!bInitialized && this->bInitRandomNumberGenerator_)
- {
- srand(static_cast<unsigned int>(time(0)));
- rand();
- bInitialized = true;
- }
- }
-
void Core::loadGraphics()
{
orxout(internal_info) << "loading graphics in Core" << endl;
@@ -428,12 +335,6 @@
GameMode::bShowsGraphics_s = false;
}
- //! Sets the language in the config-file back to the default.
- void Core::resetLanguage()
- {
- ResetConfigValue(language_);
- }
-
/**
@note
The code of this function has been copied and adjusted from OGRE, an open source graphics engine.
@@ -510,22 +411,4 @@
this->graphicsManager_->postUpdate(time);
}
}
-
- void Core::updateLastLevelTimestamp()
- {
- ModifyConfigValue(lastLevelTimestamp_, set, static_cast<long long>(time(NULL)));
- }
-
- void Core::updateOgreConfigTimestamp()
- {
- ModifyConfigValue(ogreConfigTimestamp_, set, static_cast<long long>(time(NULL)));
- }
-
-
- RegisterAbstractClass(DevModeListener).inheritsFrom<Listable>();
-
- DevModeListener::DevModeListener()
- {
- RegisterObject(DevModeListener);
- }
}
Modified: code/branches/core7/src/libraries/core/Core.h
===================================================================
--- code/branches/core7/src/libraries/core/Core.h 2015-05-25 15:37:15 UTC (rev 10478)
+++ code/branches/core7/src/libraries/core/Core.h 2015-05-25 17:20:21 UTC (rev 10479)
@@ -46,26 +46,17 @@
#include <string>
#include "util/DestructionHelper.h"
#include "util/Singleton.h"
-#include "config/Configurable.h"
+#include "CoreConfig.h"
namespace orxonox
{
- //! Informs about changes in the Development Mode.
- class DevModeListener : virtual public Listable
- {
- public:
- DevModeListener();
- virtual ~DevModeListener() {}
- virtual void devModeChanged(bool value) = 0;
- };
-
/**
@brief
The Core class is a singleton used to configure the program basics.
@remark
You should only create this singleton once because it destroys the identifiers!
*/
- class _CoreExport Core : public Singleton<Core>, public Configurable
+ class _CoreExport Core : public Singleton<Core>
{
friend class Singleton<Core>;
friend class Game;
@@ -85,32 +76,12 @@
/// Destructor that also executes when the object fails to construct
void destroy();
- void setConfigValues();
+ inline CoreConfig* getConfig() const
+ { return this->config_; }
- //! Returns the configured language.
- const std::string& getLanguage()
- { return this->language_; }
- void resetLanguage();
-
- void updateLastLevelTimestamp();
- inline long long getLastLevelTimestamp() const
- { return this->lastLevelTimestamp_; }
-
- void updateOgreConfigTimestamp();
- inline long long getOgreConfigTimestamp() const
- { return this->ogreConfigTimestamp_; }
-
- //! Developers bit. If returns false, some options are not available as to not confuse the normal user.
- inline bool inDevMode(void) const
- { return this->bDevMode_; }
-
private:
Core(const Core&); //!< Don't use (undefined symbol)
- void devModeChanged();
- void languageChanged();
- void initRandomNumberGenerator();
-
void preUpdate(const Clock& time);
void postUpdate(const Clock& time);
@@ -134,15 +105,11 @@
InputManager* inputManager_; //!< Interface to OIS
GUIManager* guiManager_; //!< Interface to GUI
Scope<ScopeID::GRAPHICS>* graphicsScope_;
-
bool bGraphicsLoaded_;
- std::string language_; //!< The language
- bool bInitRandomNumberGenerator_; //!< If true, srand(time(0)) is called
- bool bStartIOConsole_; //!< Set to false if you don't want to use the IOConsole
- long long lastLevelTimestamp_; ///< Timestamp when the last level was started
- long long ogreConfigTimestamp_; ///< Timestamp wehen the ogre config level was modified
- bool bDevMode_; //!< Developers bit. If set to false, some options are not available as to not confuse the normal user.
+ /// Helper object that stores the config values
+ CoreConfig* config_;
+
/// Helper object that executes the surrogate destructor destroy()
DestructionHelper<Core> destructionHelper_;
Added: code/branches/core7/src/libraries/core/CoreConfig.cc
===================================================================
--- code/branches/core7/src/libraries/core/CoreConfig.cc (rev 0)
+++ code/branches/core7/src/libraries/core/CoreConfig.cc 2015-05-25 17:20:21 UTC (rev 10479)
@@ -0,0 +1,153 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Fabian 'x3n' Landau
+ * Co-authors:
+ * ...
+ *
+ */
+
+#include "CoreConfig.h"
+
+#include "util/output/LogWriter.h"
+#include "util/output/OutputManager.h"
+#include "core/CoreIncludes.h"
+#include "core/config/ConfigValueIncludes.h"
+#include "core/Language.h"
+#include "core/PathConfig.h"
+
+namespace orxonox
+{
+ RegisterClassNoArgs(CoreConfig);
+
+ CoreConfig::CoreConfig()
+ : bDevMode_(false)
+ , bStartIOConsole_(true)
+ , lastLevelTimestamp_(0)
+ , ogreConfigTimestamp_(0)
+ {
+ RegisterObject(CoreConfig);
+ }
+
+ //! Function to collect the SetConfigValue-macro calls.
+ void CoreConfig::setConfigValues()
+ {
+ SetConfigValueExternal(OutputManager::getInstance().getLogWriter()->configurableMaxLevel_,
+ OutputManager::getInstance().getLogWriter()->getConfigurableSectionName(),
+ OutputManager::getInstance().getLogWriter()->getConfigurableMaxLevelName(),
+ OutputManager::getInstance().getLogWriter()->configurableMaxLevel_)
+ .description("The maximum level of output shown in the log file")
+ .callback(static_cast<BaseWriter*>(OutputManager::getInstance().getLogWriter()), &BaseWriter::changedConfigurableLevel);
+ SetConfigValueExternal(OutputManager::getInstance().getLogWriter()->configurableAdditionalContextsMaxLevel_,
+ OutputManager::getInstance().getLogWriter()->getConfigurableSectionName(),
+ OutputManager::getInstance().getLogWriter()->getConfigurableAdditionalContextsMaxLevelName(),
+ OutputManager::getInstance().getLogWriter()->configurableAdditionalContextsMaxLevel_)
+ .description("The maximum level of output shown in the log file for additional contexts")
+ .callback(static_cast<BaseWriter*>(OutputManager::getInstance().getLogWriter()), &BaseWriter::changedConfigurableAdditionalContextsLevel);
+ SetConfigValueExternal(OutputManager::getInstance().getLogWriter()->configurableAdditionalContexts_,
+ OutputManager::getInstance().getLogWriter()->getConfigurableSectionName(),
+ OutputManager::getInstance().getLogWriter()->getConfigurableAdditionalContextsName(),
+ OutputManager::getInstance().getLogWriter()->configurableAdditionalContexts_)
+ .description("Additional output contexts shown in the log file")
+ .callback(static_cast<BaseWriter*>(OutputManager::getInstance().getLogWriter()), &BaseWriter::changedConfigurableAdditionalContexts);
+
+ SetConfigValue(bDevMode_, PathConfig::buildDirectoryRun())
+ .description("Developer mode. If not set, hides some things from the user to not confuse him.")
+ .callback(this, &CoreConfig::devModeChanged);
+ SetConfigValue(language_, Language::getInstance().defaultLanguage_)
+ .description("The language of the in game text")
+ .callback(this, &CoreConfig::languageChanged);
+ SetConfigValue(bInitRandomNumberGenerator_, true)
+ .description("If true, all random actions are different each time you start the game")
+ .callback(this, &CoreConfig::initRandomNumberGenerator);
+ SetConfigValue(bStartIOConsole_, true)
+ .description("Set to false if you don't want to use the IOConsole (for Lua debugging for instance)");
+ SetConfigValue(lastLevelTimestamp_, 0)
+ .description("Timestamp when the last level was started.");
+ SetConfigValue(ogreConfigTimestamp_, 0)
+ .description("Timestamp when the ogre config file was changed.");
+ }
+
+ /** Callback function for changes in the dev mode that affect debug levels.
+ The function behaves according to these rules:
+ - 'normal' mode is defined based on where the program was launched: if
+ the launch path was the build directory, development mode \c on is
+ normal, otherwise normal means development mode \c off.
+ - Debug levels should not be hard configured (\c config instead of
+ \c tconfig) in non 'normal' mode to avoid strange behaviour.
+ - Changing the development mode from 'normal' to the other state will
+ immediately change the debug levels to predefined values which can be
+ reconfigured with \c tconfig.
+ @note
+ The debug levels for the IOConsole and the InGameConsole can be found
+ in the Shell class. The same rules apply.
+ */
+ void CoreConfig::devModeChanged()
+ {
+ // Inform listeners
+ ObjectList<DevModeListener>::iterator it = ObjectList<DevModeListener>::begin();
+ for (; it != ObjectList<DevModeListener>::end(); ++it)
+ it->devModeChanged(bDevMode_);
+ }
+
+ //! Callback function if the language has changed.
+ void CoreConfig::languageChanged()
+ {
+ // Read the translation file after the language was configured
+ Language::getInstance().readTranslatedLanguageFile();
+ }
+
+ void CoreConfig::initRandomNumberGenerator()
+ {
+ static bool bInitialized = false;
+ if (!bInitialized && this->bInitRandomNumberGenerator_)
+ {
+ srand(static_cast<unsigned int>(time(0)));
+ rand();
+ bInitialized = true;
+ }
+ }
+
+ //! Sets the language in the config-file back to the default.
+ void CoreConfig::resetLanguage()
+ {
+ ResetConfigValue(language_);
+ }
+
+ void CoreConfig::updateLastLevelTimestamp()
+ {
+ ModifyConfigValue(lastLevelTimestamp_, set, static_cast<long long>(time(NULL)));
+ }
+
+ void CoreConfig::updateOgreConfigTimestamp()
+ {
+ ModifyConfigValue(ogreConfigTimestamp_, set, static_cast<long long>(time(NULL)));
+ }
+
+
+ RegisterAbstractClass(DevModeListener).inheritsFrom<Listable>();
+
+ DevModeListener::DevModeListener()
+ {
+ RegisterObject(DevModeListener);
+ }
+}
Added: code/branches/core7/src/libraries/core/CoreConfig.h
===================================================================
--- code/branches/core7/src/libraries/core/CoreConfig.h (rev 0)
+++ code/branches/core7/src/libraries/core/CoreConfig.h 2015-05-25 17:20:21 UTC (rev 10479)
@@ -0,0 +1,88 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Fabian 'x3n' Landau
+ * Co-authors:
+ * ...
+ *
+ */
+
+#ifndef _CoreConfig_H__
+#define _CoreConfig_H__
+
+#include "core/CorePrereqs.h"
+
+#include "core/config/Configurable.h"
+
+namespace orxonox
+{
+ class _CoreExport CoreConfig : virtual public Configurable
+ {
+ public:
+ CoreConfig();
+
+ void setConfigValues();
+
+ //! Developers bit. If returns false, some options are not available as to not confuse the normal user.
+ inline bool inDevMode(void) const
+ { return this->bDevMode_; }
+
+ //! Returns the configured language.
+ const std::string& getLanguage()
+ { return this->language_; }
+ void resetLanguage();
+
+ inline bool getStartIOConsole() const
+ { return this->bStartIOConsole_; }
+
+ void updateLastLevelTimestamp();
+ inline long long getLastLevelTimestamp() const
+ { return this->lastLevelTimestamp_; }
+
+ void updateOgreConfigTimestamp();
+ inline long long getOgreConfigTimestamp() const
+ { return this->ogreConfigTimestamp_; }
+
+ private:
+ void devModeChanged();
+ void languageChanged();
+ void initRandomNumberGenerator();
+
+ bool bDevMode_; //!< Developers bit. If set to false, some options are not available as to not confuse the normal user.
+ std::string language_; //!< The language
+ bool bInitRandomNumberGenerator_; //!< If true, srand(time(0)) is called
+ bool bStartIOConsole_; //!< Set to false if you don't want to use the IOConsole
+ long long lastLevelTimestamp_; ///< Timestamp when the last level was started
+ long long ogreConfigTimestamp_; ///< Timestamp wehen the ogre config level was modified
+ };
+
+ //! Informs about changes in the Development Mode.
+ class DevModeListener : virtual public Listable
+ {
+ public:
+ DevModeListener();
+ virtual ~DevModeListener() {}
+ virtual void devModeChanged(bool value) = 0;
+ };
+}
+
+#endif /* _CoreConfig_H__ */
Modified: code/branches/core7/src/libraries/core/CorePrereqs.h
===================================================================
--- code/branches/core7/src/libraries/core/CorePrereqs.h 2015-05-25 15:37:15 UTC (rev 10478)
+++ code/branches/core7/src/libraries/core/CorePrereqs.h 2015-05-25 17:20:21 UTC (rev 10479)
@@ -154,6 +154,7 @@
class ConfigValueContainer;
class Context;
class Core;
+ class CoreConfig;
class Destroyable;
class DestroyLaterManager;
class DestructionListener;
@@ -163,6 +164,7 @@
class EventState;
class Factory;
class Game;
+ class GameConfig;
class GameState;
struct GameStateInfo;
struct GameStateTreeNode;
Modified: code/branches/core7/src/libraries/core/GUIManager.cc
===================================================================
--- code/branches/core7/src/libraries/core/GUIManager.cc 2015-05-25 15:37:15 UTC (rev 10478)
+++ code/branches/core7/src/libraries/core/GUIManager.cc 2015-05-25 17:20:21 UTC (rev 10479)
@@ -834,7 +834,7 @@
*/
/*static*/ bool GUIManager::inDevMode()
{
- return Core::getInstance().inDevMode();
+ return Core::getInstance().getConfig()->inDevMode();
}
/**
Modified: code/branches/core7/src/libraries/core/Game.cc
===================================================================
--- code/branches/core7/src/libraries/core/Game.cc 2015-05-25 15:37:15 UTC (rev 10478)
+++ code/branches/core7/src/libraries/core/Game.cc 2015-05-25 17:20:21 UTC (rev 10479)
@@ -44,9 +44,8 @@
#include "util/Sleep.h"
#include "util/SubString.h"
#include "Core.h"
-#include "CoreIncludes.h"
#include "commandline/CommandLineParser.h"
-#include "config/ConfigValueIncludes.h"
+#include "GameConfig.h"
#include "GameMode.h"
#include "GameState.h"
#include "GraphicsManager.h"
@@ -76,13 +75,12 @@
std::vector<shared_ptr<GameStateTreeNode> > children_;
};
- RegisterAbstractClass(Game).inheritsFrom<Configurable>();
-
Game::Game(const std::string& cmdLine)
: gameClock_(NULL)
, core_(NULL)
, bChangingState_(false)
, bAbort_(false)
+ , config_(NULL)
, destructionHelper_(this)
{
orxout(internal_status) << "initializing Game object..." << endl;
@@ -113,8 +111,7 @@
this->core_ = new Core(cmdLine);
// Do this after the Core creation!
- RegisterObject(Game);
- this->setConfigValues();
+ this->config_ = new GameConfig();
// After the core has been created, we can safely instantiate the GameStates that don't require graphics
for (std::map<std::string, GameStateInfo>::const_iterator it = gameStateDeclarations_s.begin();
@@ -137,31 +134,18 @@
{
orxout(internal_status) << "destroying Game object..." << endl;
- // Remove us from the object lists again to avoid problems when destroying them
- this->unregisterObject();
-
assert(loadedStates_.size() <= 1); // Just empty root GameState
// Destroy all GameStates (shared_ptrs take care of actual destruction)
constructedStates_.clear();
GameStateFactory::getFactories().clear();
+ safeObjectDelete(&config_);
safeObjectDelete(&core_);
safeObjectDelete(&gameClock_);
orxout(internal_status) << "finished destroying Game object..." << endl;
}
- void Game::setConfigValues()
- {
- SetConfigValue(statisticsRefreshCycle_, 250000)
- .description("Sets the time in microseconds interval at which average fps, etc. get updated.");
- SetConfigValue(statisticsAvgLength_, 1000000)
- .description("Sets the time in microseconds interval at which average fps, etc. gets calculated.");
-
- SetConfigValueExternal(fpsLimit_, "GraphicsSettings", "fpsLimit", 50)
- .description("Sets the desired frame rate (0 for no limit).");
- }
-
/**
@brief
Main loop of the orxonox game.
@@ -230,7 +214,7 @@
// Limit frame rate
static bool hasVSync = GameMode::showsGraphics() && GraphicsManager::getInstance().hasVSyncEnabled(); // can be static since changes of VSync currently require a restart
- if (this->fpsLimit_ > 0 && !hasVSync)
+ if (this->config_->getFpsLimit() > 0 && !hasVSync)
this->updateFPSLimiter();
}
@@ -312,11 +296,11 @@
uint64_t currentRealTime = gameClock_->getRealMicroseconds();
this->statisticsTickTimes_.back().tickLength += (uint32_t)(currentRealTime - currentTime);
this->periodTickTime_ += (uint32_t)(currentRealTime - currentTime);
- if (this->periodTime_ > this->statisticsRefreshCycle_)
+ if (this->periodTime_ > this->config_->getStatisticsRefreshCycle())
{
std::list<StatisticsTickInfo>::iterator it = this->statisticsTickTimes_.begin();
assert(it != this->statisticsTickTimes_.end());
- int64_t lastTime = currentTime - this->statisticsAvgLength_;
+ int64_t lastTime = currentTime - this->config_->getStatisticsAvgLength();
if (static_cast<int64_t>(it->tickTime) < lastTime)
{
do
@@ -334,13 +318,13 @@
this->avgFPS_ = -1 + static_cast<float>(framesPerPeriod) / (currentTime - this->statisticsTickTimes_.front().tickTime) * 1000000.0f;
this->avgTickTime_ = static_cast<float>(this->periodTickTime_) / framesPerPeriod / 1000.0f;
- this->periodTime_ -= this->statisticsRefreshCycle_;
+ this->periodTime_ -= this->config_->getStatisticsRefreshCycle();
}
}
void Game::updateFPSLimiter()
{
- uint64_t nextTime = gameClock_->getMicroseconds() - excessSleepTime_ + static_cast<uint32_t>(1000000.0f / fpsLimit_);
+ uint64_t nextTime = gameClock_->getMicroseconds() - excessSleepTime_ + static_cast<uint32_t>(1000000.0f / this->config_->getFpsLimit());
uint64_t currentRealTime = gameClock_->getRealMicroseconds();
while (currentRealTime < nextTime - minimumSleepTime_)
{
Modified: code/branches/core7/src/libraries/core/Game.h
===================================================================
--- code/branches/core7/src/libraries/core/Game.h 2015-05-25 15:37:15 UTC (rev 10478)
+++ code/branches/core7/src/libraries/core/Game.h 2015-05-25 17:20:21 UTC (rev 10479)
@@ -49,7 +49,6 @@
#include "util/Output.h"
#include "util/DestructionHelper.h"
#include "util/Singleton.h"
-#include "config/Configurable.h"
/**
@brief
@@ -81,7 +80,7 @@
// tolua_begin
class _CoreExport Game
// tolua_end
- : public Singleton<Game>, public Configurable
+ : public Singleton<Game>
{ // tolua_export
friend class Singleton<Game>;
typedef std::vector<shared_ptr<GameState> > GameStateVector;
@@ -96,8 +95,6 @@
/// Destructor that also executes when object fails to construct
void destroy();
- void setConfigValues();
-
void setStateHierarchy(const std::string& str);
shared_ptr<GameState> getState(const std::string& name);
@@ -188,10 +185,8 @@
int excessSleepTime_;
unsigned int minimumSleepTime_;
- // config values
- unsigned int statisticsRefreshCycle_;
- unsigned int statisticsAvgLength_;
- unsigned int fpsLimit_;
+ /// Helper object that stores the config values
+ GameConfig* config_;
/// Helper object that executes the surrogate destructor destroy()
DestructionHelper<Game> destructionHelper_;
Added: code/branches/core7/src/libraries/core/GameConfig.cc
===================================================================
--- code/branches/core7/src/libraries/core/GameConfig.cc (rev 0)
+++ code/branches/core7/src/libraries/core/GameConfig.cc 2015-05-25 17:20:21 UTC (rev 10479)
@@ -0,0 +1,53 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Fabian 'x3n' Landau
+ * Co-authors:
+ * ...
+ *
+ */
+
+#include "GameConfig.h"
+#include "core/CoreIncludes.h"
+#include "core/config/ConfigValueIncludes.h"
+
+namespace orxonox
+{
+ RegisterClassNoArgs(GameConfig);
+
+ GameConfig::GameConfig()
+ {
+ RegisterObject(GameConfig);
+ this->setConfigValues();
+ }
+
+ void GameConfig::setConfigValues()
+ {
+ SetConfigValue(statisticsRefreshCycle_, 250000)
+ .description("Sets the time in microseconds interval at which average fps, etc. get updated.");
+ SetConfigValue(statisticsAvgLength_, 1000000)
+ .description("Sets the time in microseconds interval at which average fps, etc. gets calculated.");
+
+ SetConfigValueExternal(fpsLimit_, "GraphicsSettings", "fpsLimit", 50)
+ .description("Sets the desired frame rate (0 for no limit).");
+ }
+}
Added: code/branches/core7/src/libraries/core/GameConfig.h
===================================================================
--- code/branches/core7/src/libraries/core/GameConfig.h (rev 0)
+++ code/branches/core7/src/libraries/core/GameConfig.h 2015-05-25 17:20:21 UTC (rev 10479)
@@ -0,0 +1,60 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Fabian 'x3n' Landau
+ * Co-authors:
+ * ...
+ *
+ */
+
+#ifndef _GameConfig_H__
+#define _GameConfig_H__
+
+#include "core/CorePrereqs.h"
+
+#include "core/config/Configurable.h"
+
+namespace orxonox
+{
+ class _CoreExport GameConfig : virtual public Configurable
+ {
+ public:
+ GameConfig();
+
+ void setConfigValues();
+
+ inline unsigned int getStatisticsRefreshCycle() const
+ { return this->statisticsRefreshCycle_; }
+ inline unsigned int getStatisticsAvgLength() const
+ { return this->statisticsAvgLength_; }
+ inline unsigned int getFpsLimit() const
+ { return this->fpsLimit_; }
+
+ private:
+ // config values
+ unsigned int statisticsRefreshCycle_;
+ unsigned int statisticsAvgLength_;
+ unsigned int fpsLimit_;
+ };
+}
+
+#endif /* _GameConfig_H__ */
Modified: code/branches/core7/src/libraries/core/GraphicsManager.cc
===================================================================
--- code/branches/core7/src/libraries/core/GraphicsManager.cc 2015-05-25 15:37:15 UTC (rev 10478)
+++ code/branches/core7/src/libraries/core/GraphicsManager.cc 2015-05-25 17:20:21 UTC (rev 10479)
@@ -280,7 +280,7 @@
{
orxout(internal_info) << "GraphicsManager: Configuring Renderer" << endl;
- bool updatedConfig = Core::getInstance().getOgreConfigTimestamp() > Core::getInstance().getLastLevelTimestamp();
+ bool updatedConfig = Core::getInstance().getConfig()->getOgreConfigTimestamp() > Core::getInstance().getConfig()->getLastLevelTimestamp();
if (updatedConfig)
orxout(user_info)<< "Ogre config file has changed, but no level was started since then. Displaying config dialogue again to verify the changes." << endl;
@@ -289,7 +289,7 @@
if (!ogreRoot_->showConfigDialog())
ThrowException(InitialisationFailed, "OGRE graphics configuration dialogue canceled.");
else
- Core::getInstance().updateOgreConfigTimestamp();
+ Core::getInstance().getConfig()->updateOgreConfigTimestamp();
}
orxout(internal_info) << "Creating render window" << endl;
@@ -515,7 +515,7 @@
{
GraphicsManager::getInstance().getRenderWindow()->setFullscreen(fullscreen, width, height);
this->ogreRoot_->saveConfig();
- Core::getInstance().updateOgreConfigTimestamp();
+ Core::getInstance().getConfig()->updateOgreConfigTimestamp();
// Also reload the input devices
InputManager::getInstance().reload();
}
@@ -533,7 +533,7 @@
{
//this->ogreRoot_->getRenderSystem()->reinitialise(); // can't use this that easily, because it recreates the render window, invalidating renderWindow_
this->ogreRoot_->saveConfig();
- Core::getInstance().updateOgreConfigTimestamp();
+ Core::getInstance().getConfig()->updateOgreConfigTimestamp();
}
return validate;
@@ -549,7 +549,7 @@
{
//this->ogreRoot_->getRenderSystem()->reinitialise(); // can't use this that easily, because it recreates the render window, invalidating renderWindow_
this->ogreRoot_->saveConfig();
- Core::getInstance().updateOgreConfigTimestamp();
+ Core::getInstance().getConfig()->updateOgreConfigTimestamp();
}
return validate;
Modified: code/branches/core7/src/libraries/core/Language.cc
===================================================================
--- code/branches/core7/src/libraries/core/Language.cc 2015-05-25 15:37:15 UTC (rev 10478)
+++ code/branches/core7/src/libraries/core/Language.cc 2015-05-25 17:20:21 UTC (rev 10479)
@@ -249,9 +249,9 @@
*/
void Language::readTranslatedLanguageFile()
{
- orxout(internal_info, context::language) << "Read translated language file (" << Core::getInstance().getLanguage() << ")." << endl;
+ orxout(internal_info, context::language) << "Read translated language file (" << Core::getInstance().getConfig()->getLanguage() << ")." << endl;
- const std::string& filepath = PathConfig::getConfigPathString() + getFilename(Core::getInstance().getLanguage());
+ const std::string& filepath = PathConfig::getConfigPathString() + getFilename(Core::getInstance().getConfig()->getLanguage());
// Open the file
std::ifstream file;
@@ -260,8 +260,8 @@
if (!file.is_open())
{
orxout(internal_error, context::language) << "An error occurred in Language.cc:" << endl;
- orxout(internal_error, context::language) << "Couldn't open file " << getFilename(Core::getInstance().getLanguage()) << " to read the translated language entries!" << endl;
- Core::getInstance().resetLanguage();
+ orxout(internal_error, context::language) << "Couldn't open file " << getFilename(Core::getInstance().getConfig()->getLanguage()) << " to read the translated language entries!" << endl;
+ Core::getInstance().getConfig()->resetLanguage();
orxout(internal_info, context::language) << "Reset language to " << this->defaultLanguage_ << '.' << endl;
return;
}
@@ -290,7 +290,7 @@
}
else
{
- orxout(internal_warning, context::language) << "Invalid language entry \"" << lineString << "\" in " << getFilename(Core::getInstance().getLanguage()) << endl;
+ orxout(internal_warning, context::language) << "Invalid language entry \"" << lineString << "\" in " << getFilename(Core::getInstance().getConfig()->getLanguage()) << endl;
}
}
}
Modified: code/branches/core7/src/libraries/core/Language.h
===================================================================
--- code/branches/core7/src/libraries/core/Language.h 2015-05-25 15:37:15 UTC (rev 10478)
+++ code/branches/core7/src/libraries/core/Language.h 2015-05-25 17:20:21 UTC (rev 10479)
@@ -160,7 +160,7 @@
class _CoreExport Language : public Singleton<Language>
{
friend class Singleton<Language>;
- friend class Core;
+ friend class CoreConfig;
public:
Language();
Modified: code/branches/core7/src/libraries/core/class/IdentifierManager.cc
===================================================================
--- code/branches/core7/src/libraries/core/class/IdentifierManager.cc 2015-05-25 15:37:15 UTC (rev 10478)
+++ code/branches/core7/src/libraries/core/class/IdentifierManager.cc 2015-05-25 17:20:21 UTC (rev 10479)
@@ -129,7 +129,7 @@
}
// only check class hierarchy in dev mode because it's an expensive operation and it requires a developer to fix detected problems anyway.
- if (!Core::exists() || Core::getInstance().inDevMode())
+ if (!Core::exists() || Core::getInstance().getConfig()->inDevMode())
this->verifyClassHierarchy();
this->stopCreatingHierarchy();
Modified: code/branches/core7/src/libraries/core/command/Shell.h
===================================================================
--- code/branches/core7/src/libraries/core/command/Shell.h 2015-05-25 15:37:15 UTC (rev 10478)
+++ code/branches/core7/src/libraries/core/command/Shell.h 2015-05-25 17:20:21 UTC (rev 10479)
@@ -48,7 +48,7 @@
#include <vector>
#include "util/output/BaseWriter.h"
-#include "core/Core.h"
+#include "core/CoreConfig.h"
namespace orxonox
{
Modified: code/branches/core7/src/orxonox/gamestates/GSLevel.cc
===================================================================
--- code/branches/core7/src/orxonox/gamestates/GSLevel.cc 2015-05-25 15:37:15 UTC (rev 10478)
+++ code/branches/core7/src/orxonox/gamestates/GSLevel.cc 2015-05-25 17:20:21 UTC (rev 10479)
@@ -169,7 +169,7 @@
startFile_ = new XMLFile(LevelManager::getInstance().getDefaultLevel());
bool loaded = Loader::getInstance().open(startFile_);
- Core::getInstance().updateLastLevelTimestamp();
+ Core::getInstance().getConfig()->updateLastLevelTimestamp();
if(!loaded)
GSRoot::delayedStartMainMenu();
}
Modified: code/branches/core7/src/orxonox/gametypes/Gametype.cc
===================================================================
--- code/branches/core7/src/orxonox/gametypes/Gametype.cc 2015-05-25 15:37:15 UTC (rev 10478)
+++ code/branches/core7/src/orxonox/gametypes/Gametype.cc 2015-05-25 17:20:21 UTC (rev 10479)
@@ -408,7 +408,7 @@
if (allplayersready && hashumanplayers)
{
// If in developer's mode, there is no start countdown.
- if(Core::getInstance().inDevMode())
+ if(Core::getInstance().getConfig()->inDevMode())
this->start();
else
{
More information about the Orxonox-commit
mailing list