Changeset 10479
- Timestamp:
- May 25, 2015, 7:20:21 PM (10 years ago)
- Location:
- code/branches/core7/src
- Files:
-
- 4 added
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core7/src/libraries/core/CMakeLists.txt
r10413 r10479 26 26 Event.cc 27 27 Game.cc 28 GameConfig.cc 28 29 GameMode.cc 29 30 GameState.cc … … 43 44 BaseObject.cc 44 45 Core.cc 46 CoreConfig.cc 45 47 46 48 BUILD_UNIT OgreBuildUnit.cc -
code/branches/core7/src/libraries/core/Core.cc
r10464 r10479 62 62 #include "commandline/CommandLineIncludes.h" 63 63 #include "config/ConfigFileManager.h" 64 #include "config/ConfigValueIncludes.h"65 #include "CoreIncludes.h"66 64 #include "DynLibManager.h" 67 65 #include "GameMode.h" … … 95 93 #endif 96 94 97 // register Core as an abstract class to avoid problems if the class hierarchy is created within Core-constructor98 RegisterAbstractClass(Core).inheritsFrom<Configurable>();99 100 95 Core::Core(const std::string& cmdLine) 101 96 : pathConfig_(NULL) … … 114 109 , graphicsScope_(NULL) 115 110 , bGraphicsLoaded_(false) 116 , bStartIOConsole_(true) 117 , lastLevelTimestamp_(0) 118 , ogreConfigTimestamp_(0) 119 , bDevMode_(false) 111 , config_(NULL) 120 112 , destructionHelper_(this) 121 113 { … … 188 180 // Do this soon after the ConfigFileManager has been created to open up the 189 181 // possibility to configure everything below here 190 RegisterObject(Core);191 182 orxout(internal_info) << "configuring Core" << endl; 192 this->setConfigValues(); 183 this->config_ = new CoreConfig(); 184 this->config_->setConfigValues(); // TODO: move this into CoreConfig constructor (but resolve dependency to Language) 193 185 194 186 // Set the correct log path and rewrite the log file with the correct log levels … … 197 189 #if !defined(ORXONOX_PLATFORM_APPLE) && !defined(ORXONOX_USE_WINMAIN) 198 190 // Create persistent IO console 199 if (CommandLineParser::getValue("noIOConsole").get<bool>()) 200 { 201 ModifyConfigValue(bStartIOConsole_, tset, false); 202 } 203 if (this->bStartIOConsole_) 191 if (CommandLineParser::getValue("noIOConsole").get<bool>() == false && this->config_->getStartIOConsole()) 204 192 { 205 193 orxout(internal_info) << "creating IO console" << endl; … … 248 236 { 249 237 orxout(internal_status) << "destroying Core object..." << endl; 250 251 // Remove us from the object lists again to avoid problems when destroying them252 this->unregisterObject();253 238 254 239 safeObjectDelete(&graphicsScope_); … … 261 246 safeObjectDelete(&ioConsole_); 262 247 safeObjectDelete(&loaderInstance_); 248 safeObjectDelete(&config_); 263 249 safeObjectDelete(&languageInstance_); 264 250 safeObjectDelete(&configFileManager_); … … 271 257 272 258 orxout(internal_status) << "finished destroying Core object" << endl; 273 }274 275 //! Function to collect the SetConfigValue-macro calls.276 void Core::setConfigValues()277 {278 SetConfigValueExternal(OutputManager::getInstance().getLogWriter()->configurableMaxLevel_,279 OutputManager::getInstance().getLogWriter()->getConfigurableSectionName(),280 OutputManager::getInstance().getLogWriter()->getConfigurableMaxLevelName(),281 OutputManager::getInstance().getLogWriter()->configurableMaxLevel_)282 .description("The maximum level of output shown in the log file")283 .callback(static_cast<BaseWriter*>(OutputManager::getInstance().getLogWriter()), &BaseWriter::changedConfigurableLevel);284 SetConfigValueExternal(OutputManager::getInstance().getLogWriter()->configurableAdditionalContextsMaxLevel_,285 OutputManager::getInstance().getLogWriter()->getConfigurableSectionName(),286 OutputManager::getInstance().getLogWriter()->getConfigurableAdditionalContextsMaxLevelName(),287 OutputManager::getInstance().getLogWriter()->configurableAdditionalContextsMaxLevel_)288 .description("The maximum level of output shown in the log file for additional contexts")289 .callback(static_cast<BaseWriter*>(OutputManager::getInstance().getLogWriter()), &BaseWriter::changedConfigurableAdditionalContextsLevel);290 SetConfigValueExternal(OutputManager::getInstance().getLogWriter()->configurableAdditionalContexts_,291 OutputManager::getInstance().getLogWriter()->getConfigurableSectionName(),292 OutputManager::getInstance().getLogWriter()->getConfigurableAdditionalContextsName(),293 OutputManager::getInstance().getLogWriter()->configurableAdditionalContexts_)294 .description("Additional output contexts shown in the log file")295 .callback(static_cast<BaseWriter*>(OutputManager::getInstance().getLogWriter()), &BaseWriter::changedConfigurableAdditionalContexts);296 297 SetConfigValue(bDevMode_, PathConfig::buildDirectoryRun())298 .description("Developer mode. If not set, hides some things from the user to not confuse him.")299 .callback(this, &Core::devModeChanged);300 SetConfigValue(language_, Language::getInstance().defaultLanguage_)301 .description("The language of the in game text")302 .callback(this, &Core::languageChanged);303 SetConfigValue(bInitRandomNumberGenerator_, true)304 .description("If true, all random actions are different each time you start the game")305 .callback(this, &Core::initRandomNumberGenerator);306 SetConfigValue(bStartIOConsole_, true)307 .description("Set to false if you don't want to use the IOConsole (for Lua debugging for instance)");308 SetConfigValue(lastLevelTimestamp_, 0)309 .description("Timestamp when the last level was started.");310 SetConfigValue(ogreConfigTimestamp_, 0)311 .description("Timestamp when the ogre config file was changed.");312 }313 314 /** Callback function for changes in the dev mode that affect debug levels.315 The function behaves according to these rules:316 - 'normal' mode is defined based on where the program was launched: if317 the launch path was the build directory, development mode \c on is318 normal, otherwise normal means development mode \c off.319 - Debug levels should not be hard configured (\c config instead of320 \c tconfig) in non 'normal' mode to avoid strange behaviour.321 - Changing the development mode from 'normal' to the other state will322 immediately change the debug levels to predefined values which can be323 reconfigured with \c tconfig.324 @note325 The debug levels for the IOConsole and the InGameConsole can be found326 in the Shell class. The same rules apply.327 */328 void Core::devModeChanged()329 {330 // Inform listeners331 ObjectList<DevModeListener>::iterator it = ObjectList<DevModeListener>::begin();332 for (; it != ObjectList<DevModeListener>::end(); ++it)333 it->devModeChanged(bDevMode_);334 }335 336 //! Callback function if the language has changed.337 void Core::languageChanged()338 {339 // Read the translation file after the language was configured340 Language::getInstance().readTranslatedLanguageFile();341 }342 343 void Core::initRandomNumberGenerator()344 {345 static bool bInitialized = false;346 if (!bInitialized && this->bInitRandomNumberGenerator_)347 {348 srand(static_cast<unsigned int>(time(0)));349 rand();350 bInitialized = true;351 }352 259 } 353 260 … … 429 336 } 430 337 431 //! Sets the language in the config-file back to the default.432 void Core::resetLanguage()433 {434 ResetConfigValue(language_);435 }436 437 338 /** 438 339 @note … … 511 412 } 512 413 } 513 514 void Core::updateLastLevelTimestamp()515 {516 ModifyConfigValue(lastLevelTimestamp_, set, static_cast<long long>(time(NULL)));517 }518 519 void Core::updateOgreConfigTimestamp()520 {521 ModifyConfigValue(ogreConfigTimestamp_, set, static_cast<long long>(time(NULL)));522 }523 524 525 RegisterAbstractClass(DevModeListener).inheritsFrom<Listable>();526 527 DevModeListener::DevModeListener()528 {529 RegisterObject(DevModeListener);530 }531 414 } -
code/branches/core7/src/libraries/core/Core.h
r10464 r10479 47 47 #include "util/DestructionHelper.h" 48 48 #include "util/Singleton.h" 49 #include " config/Configurable.h"49 #include "CoreConfig.h" 50 50 51 51 namespace orxonox 52 52 { 53 //! Informs about changes in the Development Mode.54 class DevModeListener : virtual public Listable55 {56 public:57 DevModeListener();58 virtual ~DevModeListener() {}59 virtual void devModeChanged(bool value) = 0;60 };61 62 53 /** 63 54 @brief … … 66 57 You should only create this singleton once because it destroys the identifiers! 67 58 */ 68 class _CoreExport Core : public Singleton<Core> , public Configurable59 class _CoreExport Core : public Singleton<Core> 69 60 { 70 61 friend class Singleton<Core>; … … 86 77 void destroy(); 87 78 88 void setConfigValues(); 89 90 //! Returns the configured language. 91 const std::string& getLanguage() 92 { return this->language_; } 93 void resetLanguage(); 94 95 void updateLastLevelTimestamp(); 96 inline long long getLastLevelTimestamp() const 97 { return this->lastLevelTimestamp_; } 98 99 void updateOgreConfigTimestamp(); 100 inline long long getOgreConfigTimestamp() const 101 { return this->ogreConfigTimestamp_; } 102 103 //! Developers bit. If returns false, some options are not available as to not confuse the normal user. 104 inline bool inDevMode(void) const 105 { return this->bDevMode_; } 79 inline CoreConfig* getConfig() const 80 { return this->config_; } 106 81 107 82 private: 108 83 Core(const Core&); //!< Don't use (undefined symbol) 109 110 void devModeChanged();111 void languageChanged();112 void initRandomNumberGenerator();113 84 114 85 void preUpdate(const Clock& time); … … 135 106 GUIManager* guiManager_; //!< Interface to GUI 136 107 Scope<ScopeID::GRAPHICS>* graphicsScope_; 108 bool bGraphicsLoaded_; 137 109 138 bool bGraphicsLoaded_; 139 std::string language_; //!< The language 140 bool bInitRandomNumberGenerator_; //!< If true, srand(time(0)) is called 141 bool bStartIOConsole_; //!< Set to false if you don't want to use the IOConsole 142 long long lastLevelTimestamp_; ///< Timestamp when the last level was started 143 long long ogreConfigTimestamp_; ///< Timestamp wehen the ogre config level was modified 144 bool bDevMode_; //!< Developers bit. If set to false, some options are not available as to not confuse the normal user. 110 /// Helper object that stores the config values 111 CoreConfig* config_; 145 112 146 113 /// Helper object that executes the surrogate destructor destroy() -
code/branches/core7/src/libraries/core/CorePrereqs.h
r10464 r10479 155 155 class Context; 156 156 class Core; 157 class CoreConfig; 157 158 class Destroyable; 158 159 class DestroyLaterManager; … … 164 165 class Factory; 165 166 class Game; 167 class GameConfig; 166 168 class GameState; 167 169 struct GameStateInfo; -
code/branches/core7/src/libraries/core/GUIManager.cc
r10380 r10479 835 835 /*static*/ bool GUIManager::inDevMode() 836 836 { 837 return Core::getInstance(). inDevMode();837 return Core::getInstance().getConfig()->inDevMode(); 838 838 } 839 839 -
code/branches/core7/src/libraries/core/Game.cc
r10380 r10479 45 45 #include "util/SubString.h" 46 46 #include "Core.h" 47 #include "CoreIncludes.h"48 47 #include "commandline/CommandLineParser.h" 49 #include " config/ConfigValueIncludes.h"48 #include "GameConfig.h" 50 49 #include "GameMode.h" 51 50 #include "GameState.h" … … 77 76 }; 78 77 79 RegisterAbstractClass(Game).inheritsFrom<Configurable>();80 81 78 Game::Game(const std::string& cmdLine) 82 79 : gameClock_(NULL) … … 84 81 , bChangingState_(false) 85 82 , bAbort_(false) 83 , config_(NULL) 86 84 , destructionHelper_(this) 87 85 { … … 114 112 115 113 // Do this after the Core creation! 116 RegisterObject(Game); 117 this->setConfigValues(); 114 this->config_ = new GameConfig(); 118 115 119 116 // After the core has been created, we can safely instantiate the GameStates that don't require graphics … … 138 135 orxout(internal_status) << "destroying Game object..." << endl; 139 136 140 // Remove us from the object lists again to avoid problems when destroying them141 this->unregisterObject();142 143 137 assert(loadedStates_.size() <= 1); // Just empty root GameState 144 138 // Destroy all GameStates (shared_ptrs take care of actual destruction) … … 146 140 147 141 GameStateFactory::getFactories().clear(); 142 safeObjectDelete(&config_); 148 143 safeObjectDelete(&core_); 149 144 safeObjectDelete(&gameClock_); 150 145 151 146 orxout(internal_status) << "finished destroying Game object..." << endl; 152 }153 154 void Game::setConfigValues()155 {156 SetConfigValue(statisticsRefreshCycle_, 250000)157 .description("Sets the time in microseconds interval at which average fps, etc. get updated.");158 SetConfigValue(statisticsAvgLength_, 1000000)159 .description("Sets the time in microseconds interval at which average fps, etc. gets calculated.");160 161 SetConfigValueExternal(fpsLimit_, "GraphicsSettings", "fpsLimit", 50)162 .description("Sets the desired frame rate (0 for no limit).");163 147 } 164 148 … … 231 215 // Limit frame rate 232 216 static bool hasVSync = GameMode::showsGraphics() && GraphicsManager::getInstance().hasVSyncEnabled(); // can be static since changes of VSync currently require a restart 233 if (this-> fpsLimit_> 0 && !hasVSync)217 if (this->config_->getFpsLimit() > 0 && !hasVSync) 234 218 this->updateFPSLimiter(); 235 219 } … … 313 297 this->statisticsTickTimes_.back().tickLength += (uint32_t)(currentRealTime - currentTime); 314 298 this->periodTickTime_ += (uint32_t)(currentRealTime - currentTime); 315 if (this->periodTime_ > this-> statisticsRefreshCycle_)299 if (this->periodTime_ > this->config_->getStatisticsRefreshCycle()) 316 300 { 317 301 std::list<StatisticsTickInfo>::iterator it = this->statisticsTickTimes_.begin(); 318 302 assert(it != this->statisticsTickTimes_.end()); 319 int64_t lastTime = currentTime - this-> statisticsAvgLength_;303 int64_t lastTime = currentTime - this->config_->getStatisticsAvgLength(); 320 304 if (static_cast<int64_t>(it->tickTime) < lastTime) 321 305 { … … 335 319 this->avgTickTime_ = static_cast<float>(this->periodTickTime_) / framesPerPeriod / 1000.0f; 336 320 337 this->periodTime_ -= this-> statisticsRefreshCycle_;321 this->periodTime_ -= this->config_->getStatisticsRefreshCycle(); 338 322 } 339 323 } … … 341 325 void Game::updateFPSLimiter() 342 326 { 343 uint64_t nextTime = gameClock_->getMicroseconds() - excessSleepTime_ + static_cast<uint32_t>(1000000.0f / fpsLimit_);327 uint64_t nextTime = gameClock_->getMicroseconds() - excessSleepTime_ + static_cast<uint32_t>(1000000.0f / this->config_->getFpsLimit()); 344 328 uint64_t currentRealTime = gameClock_->getRealMicroseconds(); 345 329 while (currentRealTime < nextTime - minimumSleepTime_) -
code/branches/core7/src/libraries/core/Game.h
r9667 r10479 50 50 #include "util/DestructionHelper.h" 51 51 #include "util/Singleton.h" 52 #include "config/Configurable.h"53 52 54 53 /** … … 82 81 class _CoreExport Game 83 82 // tolua_end 84 : public Singleton<Game> , public Configurable83 : public Singleton<Game> 85 84 { // tolua_export 86 85 friend class Singleton<Game>; … … 96 95 /// Destructor that also executes when object fails to construct 97 96 void destroy(); 98 99 void setConfigValues();100 97 101 98 void setStateHierarchy(const std::string& str); … … 189 186 unsigned int minimumSleepTime_; 190 187 191 // config values 192 unsigned int statisticsRefreshCycle_; 193 unsigned int statisticsAvgLength_; 194 unsigned int fpsLimit_; 188 /// Helper object that stores the config values 189 GameConfig* config_; 195 190 196 191 /// Helper object that executes the surrogate destructor destroy() -
code/branches/core7/src/libraries/core/GraphicsManager.cc
r10392 r10479 281 281 orxout(internal_info) << "GraphicsManager: Configuring Renderer" << endl; 282 282 283 bool updatedConfig = Core::getInstance().get OgreConfigTimestamp() > Core::getInstance().getLastLevelTimestamp();283 bool updatedConfig = Core::getInstance().getConfig()->getOgreConfigTimestamp() > Core::getInstance().getConfig()->getLastLevelTimestamp(); 284 284 if (updatedConfig) 285 285 orxout(user_info)<< "Ogre config file has changed, but no level was started since then. Displaying config dialogue again to verify the changes." << endl; … … 290 290 ThrowException(InitialisationFailed, "OGRE graphics configuration dialogue canceled."); 291 291 else 292 Core::getInstance(). updateOgreConfigTimestamp();292 Core::getInstance().getConfig()->updateOgreConfigTimestamp(); 293 293 } 294 294 … … 516 516 GraphicsManager::getInstance().getRenderWindow()->setFullscreen(fullscreen, width, height); 517 517 this->ogreRoot_->saveConfig(); 518 Core::getInstance(). updateOgreConfigTimestamp();518 Core::getInstance().getConfig()->updateOgreConfigTimestamp(); 519 519 // Also reload the input devices 520 520 InputManager::getInstance().reload(); … … 534 534 //this->ogreRoot_->getRenderSystem()->reinitialise(); // can't use this that easily, because it recreates the render window, invalidating renderWindow_ 535 535 this->ogreRoot_->saveConfig(); 536 Core::getInstance(). updateOgreConfigTimestamp();536 Core::getInstance().getConfig()->updateOgreConfigTimestamp(); 537 537 } 538 538 … … 550 550 //this->ogreRoot_->getRenderSystem()->reinitialise(); // can't use this that easily, because it recreates the render window, invalidating renderWindow_ 551 551 this->ogreRoot_->saveConfig(); 552 Core::getInstance(). updateOgreConfigTimestamp();552 Core::getInstance().getConfig()->updateOgreConfigTimestamp(); 553 553 } 554 554 -
code/branches/core7/src/libraries/core/Language.cc
r8858 r10479 250 250 void Language::readTranslatedLanguageFile() 251 251 { 252 orxout(internal_info, context::language) << "Read translated language file (" << Core::getInstance().get Language() << ")." << endl;253 254 const std::string& filepath = PathConfig::getConfigPathString() + getFilename(Core::getInstance().get Language());252 orxout(internal_info, context::language) << "Read translated language file (" << Core::getInstance().getConfig()->getLanguage() << ")." << endl; 253 254 const std::string& filepath = PathConfig::getConfigPathString() + getFilename(Core::getInstance().getConfig()->getLanguage()); 255 255 256 256 // Open the file … … 261 261 { 262 262 orxout(internal_error, context::language) << "An error occurred in Language.cc:" << endl; 263 orxout(internal_error, context::language) << "Couldn't open file " << getFilename(Core::getInstance().get Language()) << " to read the translated language entries!" << endl;264 Core::getInstance(). resetLanguage();263 orxout(internal_error, context::language) << "Couldn't open file " << getFilename(Core::getInstance().getConfig()->getLanguage()) << " to read the translated language entries!" << endl; 264 Core::getInstance().getConfig()->resetLanguage(); 265 265 orxout(internal_info, context::language) << "Reset language to " << this->defaultLanguage_ << '.' << endl; 266 266 return; … … 291 291 else 292 292 { 293 orxout(internal_warning, context::language) << "Invalid language entry \"" << lineString << "\" in " << getFilename(Core::getInstance().get Language()) << endl;293 orxout(internal_warning, context::language) << "Invalid language entry \"" << lineString << "\" in " << getFilename(Core::getInstance().getConfig()->getLanguage()) << endl; 294 294 } 295 295 } -
code/branches/core7/src/libraries/core/Language.h
r8858 r10479 161 161 { 162 162 friend class Singleton<Language>; 163 friend class Core ;163 friend class CoreConfig; 164 164 165 165 public: -
code/branches/core7/src/libraries/core/class/IdentifierManager.cc
r10403 r10479 130 130 131 131 // only check class hierarchy in dev mode because it's an expensive operation and it requires a developer to fix detected problems anyway. 132 if (!Core::exists() || Core::getInstance(). inDevMode())132 if (!Core::exists() || Core::getInstance().getConfig()->inDevMode()) 133 133 this->verifyClassHierarchy(); 134 134 -
code/branches/core7/src/libraries/core/command/Shell.h
r9667 r10479 49 49 50 50 #include "util/output/BaseWriter.h" 51 #include "core/Core .h"51 #include "core/CoreConfig.h" 52 52 53 53 namespace orxonox -
code/branches/core7/src/orxonox/gamestates/GSLevel.cc
r10392 r10479 170 170 bool loaded = Loader::getInstance().open(startFile_); 171 171 172 Core::getInstance(). updateLastLevelTimestamp();172 Core::getInstance().getConfig()->updateLastLevelTimestamp(); 173 173 if(!loaded) 174 174 GSRoot::delayedStartMainMenu(); -
code/branches/core7/src/orxonox/gametypes/Gametype.cc
r10349 r10479 409 409 { 410 410 // If in developer's mode, there is no start countdown. 411 if(Core::getInstance(). inDevMode())411 if(Core::getInstance().getConfig()->inDevMode()) 412 412 this->start(); 413 413 else
Note: See TracChangeset
for help on using the changeset viewer.