Changeset 6121 for code/branches/presentation2/src/libraries
- Timestamp:
- Nov 23, 2009, 6:19:58 PM (15 years ago)
- Location:
- code/branches/presentation2/src/libraries/core
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2/src/libraries/core/Core.cc
r6105 r6121 51 51 #include "util/Debug.h" 52 52 #include "util/Exception.h" 53 #include "util/Scope.h" 53 54 #include "util/SignalHandler.h" 54 55 #include "PathConfig.h" … … 81 82 #endif 82 83 83 /**84 @brief85 Helper class for the Core singleton: we cannot derive86 Core from OrxonoxClass because we need to handle the Identifier87 destruction in the Core destructor.88 */89 class CoreConfiguration : public OrxonoxClass90 {91 public:92 CoreConfiguration()93 {94 }95 96 void initialise()97 {98 RegisterRootObject(CoreConfiguration);99 this->setConfigValues();100 }101 102 /**103 @brief Function to collect the SetConfigValue-macro calls.104 */105 void setConfigValues()106 {107 #ifdef ORXONOX_RELEASE108 const unsigned int defaultLevelLogFile = 3;109 #else110 const unsigned int defaultLevelLogFile = 4;111 #endif112 SetConfigValueGeneric(ConfigFileType::Settings, softDebugLevelLogFile_, "softDebugLevelLogFile", "OutputHandler", defaultLevelLogFile)113 .description("The maximum level of debug output shown in the log file");114 OutputHandler::getInstance().setSoftDebugLevel(OutputHandler::logFileOutputListenerName_s, this->softDebugLevelLogFile_);115 116 SetConfigValue(language_, Language::getInstance().defaultLanguage_)117 .description("The language of the in game text")118 .callback(this, &CoreConfiguration::languageChanged);119 SetConfigValue(bInitializeRandomNumberGenerator_, true)120 .description("If true, all random actions are different each time you start the game")121 .callback(this, &CoreConfiguration::initializeRandomNumberGenerator);122 }123 124 /**125 @brief Callback function if the language has changed.126 */127 void languageChanged()128 {129 // Read the translation file after the language was configured130 Language::getInstance().readTranslatedLanguageFile();131 }132 133 /**134 @brief Sets the language in the config-file back to the default.135 */136 void resetLanguage()137 {138 ResetConfigValue(language_);139 }140 141 void initializeRandomNumberGenerator()142 {143 static bool bInitialized = false;144 if (!bInitialized && this->bInitializeRandomNumberGenerator_)145 {146 srand(static_cast<unsigned int>(time(0)));147 rand();148 bInitialized = true;149 }150 }151 152 int softDebugLevelLogFile_; //!< The debug level for the log file (belongs to OutputHandler)153 std::string language_; //!< The language154 bool bInitializeRandomNumberGenerator_; //!< If true, srand(time(0)) is called155 };156 157 158 84 Core::Core(const std::string& cmdLine) 159 85 // Cleanup guard for identifier destruction (incl. XMLPort, configValues, consoleCommands) … … 161 87 // Cleanup guard for external console commands that don't belong to an Identifier 162 88 , consoleCommandDestroyer_(CommandExecutor::destroyExternalCommands) 163 , configuration_(new CoreConfiguration()) // Don't yet create config values!164 89 , bGraphicsLoaded_(false) 165 90 { … … 218 143 this->languageInstance_.reset(new Language()); 219 144 145 // Do this soon after the ConfigFileManager has been created to open up the 146 // possibility to configure everything below here 147 ClassIdentifier<Core>::getIdentifier("Core")->initialiseObject(this, "Core", true); 148 // Remove us from the object lists again to avoid problems when destroying the Core 149 this->unregisterObject(); 150 this->setConfigValues(); 151 220 152 // create persistent io console 221 153 this->ioConsole_.reset(new IOConsole()); … … 223 155 // creates the class hierarchy for all classes with factories 224 156 Identifier::createClassHierarchy(); 225 226 // Do this soon after the ConfigFileManager has been created to open up the227 // possibility to configure everything below here228 this->configuration_->initialise();229 157 230 158 // Load OGRE excluding the renderer and the render window … … 247 175 } 248 176 177 //! Function to collect the SetConfigValue-macro calls. 178 void Core::setConfigValues() 179 { 180 #ifdef ORXONOX_RELEASE 181 const unsigned int defaultLevelLogFile = 3; 182 #else 183 const unsigned int defaultLevelLogFile = 4; 184 #endif 185 SetConfigValueGeneric(ConfigFileType::Settings, softDebugLevelLogFile_, "softDebugLevelLogFile", "OutputHandler", defaultLevelLogFile) 186 .description("The maximum level of debug output shown in the log file"); 187 OutputHandler::getInstance().setSoftDebugLevel(OutputHandler::logFileOutputListenerName_s, this->softDebugLevelLogFile_); 188 189 SetConfigValue(language_, Language::getInstance().defaultLanguage_) 190 .description("The language of the in game text") 191 .callback(this, &Core::languageChanged); 192 SetConfigValue(bInitRandomNumberGenerator_, true) 193 .description("If true, all random actions are different each time you start the game") 194 .callback(this, &Core::initRandomNumberGenerator); 195 } 196 197 //! Callback function if the language has changed. 198 void Core::languageChanged() 199 { 200 // Read the translation file after the language was configured 201 Language::getInstance().readTranslatedLanguageFile(); 202 } 203 204 void Core::initRandomNumberGenerator() 205 { 206 static bool bInitialized = false; 207 if (!bInitialized && this->bInitRandomNumberGenerator_) 208 { 209 srand(static_cast<unsigned int>(time(0))); 210 rand(); 211 bInitialized = true; 212 } 213 } 214 249 215 void Core::loadGraphics() 250 216 { … … 296 262 } 297 263 298 /** 299 @brief Returns the configured language. 300 */ 301 /*static*/ const std::string& Core::getLanguage() 302 { 303 return Core::getInstance().configuration_->language_; 304 } 305 306 /** 307 @brief Sets the language in the config-file back to the default. 308 */ 309 /*static*/ void Core::resetLanguage() 310 { 311 Core::getInstance().configuration_->resetLanguage(); 264 //! Sets the language in the config-file back to the default. 265 void Core::resetLanguage() 266 { 267 ResetConfigValue(language_); 312 268 } 313 269 -
code/branches/presentation2/src/libraries/core/Core.h
r6105 r6121 35 35 #include <cassert> 36 36 #include <boost/scoped_ptr.hpp> 37 #include "util/OutputHandler.h"38 #include "util/Scope.h"39 37 #include "util/ScopeGuard.h" 40 38 #include "util/Singleton.h" 39 #include "core/OrxonoxClass.h" 41 40 42 41 namespace orxonox 43 42 { 44 class CoreConfiguration;45 46 43 /** 47 44 @brief … … 50 47 You should only create this singleton once because it destroys the identifiers! 51 48 */ 52 class _CoreExport Core : public Singleton<Core> 49 class _CoreExport Core : public Singleton<Core>, public OrxonoxClass 53 50 { 54 51 typedef Loki::ScopeGuardImpl0<void (*)()> SimpleScopeGuard; … … 69 66 void setConfigValues(); 70 67 71 static const std::string& getLanguage(); 72 static void resetLanguage(); 68 //! Returns the configured language. 69 const std::string& getLanguage() 70 { return this->language_; } 71 void resetLanguage(); 73 72 74 73 private: 75 74 Core(const Core&); //!< Don't use (undefined symbol) 75 76 void languageChanged(); 77 void initRandomNumberGenerator(); 76 78 77 79 void preUpdate(const Clock& time); … … 82 84 83 85 void setThreadAffinity(int limitToCPU); 84 86 // MANAGED SINGLETONS/OBJECTS 85 87 // Mind the order for the destruction! 86 88 scoped_ptr<PathConfig> pathConfig_; … … 92 94 scoped_ptr<Language> languageInstance_; 93 95 scoped_ptr<IOConsole> ioConsole_; 94 scoped_ptr<CoreConfiguration> configuration_;95 96 scoped_ptr<TclBind> tclBind_; 96 97 scoped_ptr<TclThreadManager> tclThreadManager_; 98 scoped_ptr<Scope<ScopeID::Root> > rootScope_; 97 99 // graphical 98 100 scoped_ptr<GraphicsManager> graphicsManager_; //!< Interface to OGRE 99 101 scoped_ptr<InputManager> inputManager_; //!< Interface to OIS 100 102 scoped_ptr<GUIManager> guiManager_; //!< Interface to GUI 101 scoped_ptr<Scope<ScopeID::Root> > rootScope_;102 103 scoped_ptr<Scope<ScopeID::Graphics> > graphicsScope_; 103 104 104 105 bool bGraphicsLoaded_; 105 static Core* singletonPtr_s; 106 int softDebugLevelLogFile_; //!< The debug level for the log file (belongs to OutputHandler) 107 std::string language_; //!< The language 108 bool bInitRandomNumberGenerator_; //!< If true, srand(time(0)) is called 109 110 static Core* singletonPtr_s; 106 111 }; 107 112 } -
code/branches/presentation2/src/libraries/core/Game.cc
r6021 r6121 67 67 Game* Game::singletonPtr_s = 0; 68 68 69 70 /** 71 @brief 72 Represents one node of the game state tree. 73 */ 69 //! Represents one node of the game state tree. 74 70 struct GameStateTreeNode 75 71 { … … 79 75 }; 80 76 81 82 /**83 @brief84 Another helper class for the Game singleton: we cannot derive85 Game from OrxonoxClass because we need to handle the Identifier86 destruction in the Core destructor.87 */88 class GameConfiguration : public OrxonoxClass89 {90 public:91 GameConfiguration()92 {93 RegisterRootObject(GameConfiguration);94 this->setConfigValues();95 }96 97 void setConfigValues()98 {99 SetConfigValue(statisticsRefreshCycle_, 250000)100 .description("Sets the time in microseconds interval at which average fps, etc. get updated.");101 SetConfigValue(statisticsAvgLength_, 1000000)102 .description("Sets the time in microseconds interval at which average fps, etc. gets calculated.");103 SetConfigValue(fpsLimit_, 50)104 .description("Sets the desired framerate (0 for no limit).");105 }106 107 unsigned int statisticsRefreshCycle_;108 unsigned int statisticsAvgLength_;109 unsigned int fpsLimit_;110 };111 112 113 /**114 @brief115 Non-initialising constructor.116 */117 77 Game::Game(const std::string& cmdLine) 118 78 // Destroy factories before the Core! … … 137 97 this->core_.reset(new Core(cmdLine)); 138 98 99 // Do this after the Core creation! 100 ClassIdentifier<Game>::getIdentifier("Game")->initialiseObject(this, "Game", true); 101 // Remove us from the object lists again to avoid problems when destroying the Game 102 this->unregisterObject(); 103 this->setConfigValues(); 104 139 105 // After the core has been created, we can safely instantiate the GameStates that don't require graphics 140 106 for (std::map<std::string, GameStateInfo>::const_iterator it = gameStateDeclarations_s.begin(); … … 150 116 this->loadedTopStateNode_ = this->rootStateNode_; 151 117 this->loadedStates_.push_back(this->getState(rootStateNode_->name_)); 152 153 // Do this after the Core creation!154 this->configuration_.reset(new GameConfiguration());155 118 } 156 119 … … 161 124 Game::~Game() 162 125 { 126 } 127 128 void Game::setConfigValues() 129 { 130 SetConfigValue(statisticsRefreshCycle_, 250000) 131 .description("Sets the time in microseconds interval at which average fps, etc. get updated."); 132 SetConfigValue(statisticsAvgLength_, 1000000) 133 .description("Sets the time in microseconds interval at which average fps, etc. gets calculated."); 134 SetConfigValue(fpsLimit_, 50) 135 .description("Sets the desired framerate (0 for no limit)."); 163 136 } 164 137 … … 312 285 this->statisticsTickTimes_.back().tickLength += currentRealTime - currentTime; 313 286 this->periodTickTime_ += currentRealTime - currentTime; 314 if (this->periodTime_ > this-> configuration_->statisticsRefreshCycle_)287 if (this->periodTime_ > this->statisticsRefreshCycle_) 315 288 { 316 289 std::list<StatisticsTickInfo>::iterator it = this->statisticsTickTimes_.begin(); 317 290 assert(it != this->statisticsTickTimes_.end()); 318 int64_t lastTime = currentTime - this-> configuration_->statisticsAvgLength_;291 int64_t lastTime = currentTime - this->statisticsAvgLength_; 319 292 if (static_cast<int64_t>(it->tickTime) < lastTime) 320 293 { … … 333 306 this->avgTickTime_ = static_cast<float>(this->periodTickTime_) / framesPerPeriod / 1000.0f; 334 307 335 this->periodTime_ -= this-> configuration_->statisticsRefreshCycle_;308 this->periodTime_ -= this->statisticsRefreshCycle_; 336 309 } 337 310 } … … 339 312 void Game::updateFPSLimiter() 340 313 { 341 // Why configuration_->fpsLimit_ - 1? No idea, but otherwise the fps rate is always (from 10 to 200!) one frame too high342 uint32_t nextTime = gameClock_->getMicroseconds() - excessSleepTime_ + static_cast<uint32_t>(1000000.0f / ( configuration_->fpsLimit_ - 1));314 // Why fpsLimit_ - 1? No idea, but otherwise the fps rate is always (from 10 to 200!) one frame too high 315 uint32_t nextTime = gameClock_->getMicroseconds() - excessSleepTime_ + static_cast<uint32_t>(1000000.0f / (fpsLimit_ - 1)); 343 316 uint64_t currentRealTime = gameClock_->getRealMicroseconds(); 344 317 while (currentRealTime < nextTime - minimumSleepTime_) -
code/branches/presentation2/src/libraries/core/Game.h
r5929 r6121 50 50 #include "util/ScopeGuard.h" 51 51 #include "util/Singleton.h" 52 #include "core/OrxonoxClass.h" 52 53 53 54 /** … … 61 62 namespace orxonox 62 63 { 63 class GameConfiguration;64 65 64 //! Helper object required before GameStates are being constructed 66 65 struct GameStateInfo … … 78 77 You should only create this singleton once because it owns the Core class! (see remark there) 79 78 */ 80 class _CoreExport Game : public Singleton<Game> 79 class _CoreExport Game : public Singleton<Game>, public OrxonoxClass 81 80 { 82 81 friend class Singleton<Game>; … … 88 87 Game(const std::string& cmdLine); 89 88 ~Game(); 89 90 void setConfigValues(); 90 91 91 92 void setStateHierarchy(const std::string& str); … … 160 161 scoped_ptr<Core> core_; 161 162 ObjScopeGuard gsFactoryDestroyer_; 162 scoped_ptr<GameConfiguration> configuration_;163 163 164 164 GameStateMap constructedStates_; … … 181 181 unsigned int minimumSleepTime_; 182 182 183 // config values 184 unsigned int statisticsRefreshCycle_; 185 unsigned int statisticsAvgLength_; 186 unsigned int fpsLimit_; 187 183 188 static std::map<std::string, GameStateInfo> gameStateDeclarations_s; 184 189 static Game* singletonPtr_s; //!< Pointer to the Singleton -
code/branches/presentation2/src/libraries/core/Language.cc
r5929 r6121 246 246 void Language::readTranslatedLanguageFile() 247 247 { 248 COUT(4) << "Read translated language file (" << Core::get Language() << ")." << std::endl;249 250 std::string filepath = PathConfig::getConfigPathString() + getFilename(Core::get Language());248 COUT(4) << "Read translated language file (" << Core::getInstance().getLanguage() << ")." << std::endl; 249 250 std::string filepath = PathConfig::getConfigPathString() + getFilename(Core::getInstance().getLanguage()); 251 251 252 252 // Open the file … … 257 257 { 258 258 COUT(1) << "An error occurred in Language.cc:" << std::endl; 259 COUT(1) << "Error: Couldn't open file " << getFilename(Core::get Language()) << " to read the translated language entries!" << std::endl;260 Core:: resetLanguage();259 COUT(1) << "Error: Couldn't open file " << getFilename(Core::getInstance().getLanguage()) << " to read the translated language entries!" << std::endl; 260 Core::getInstance().resetLanguage(); 261 261 COUT(3) << "Info: Reset language to " << this->defaultLanguage_ << "." << std::endl; 262 262 return; … … 287 287 else 288 288 { 289 COUT(2) << "Warning: Invalid language entry \"" << lineString << "\" in " << getFilename(Core::get Language()) << std::endl;289 COUT(2) << "Warning: Invalid language entry \"" << lineString << "\" in " << getFilename(Core::getInstance().getLanguage()) << std::endl; 290 290 } 291 291 } -
code/branches/presentation2/src/libraries/core/Language.h
r5738 r6121 116 116 { 117 117 friend class Singleton<Language>; 118 friend class Core Configuration;118 friend class Core; 119 119 120 120 public: -
code/branches/presentation2/src/libraries/core/OrxonoxClass.cc
r6105 r6121 59 59 assert(this->referenceCount_ <= 0); 60 60 61 delete this->metaList_;61 this->unregisterObject(); 62 62 63 63 // parents_ exists only if isCreatingHierarchy() of the associated Identifier returned true while creating the class 64 64 if (this->parents_) 65 65 delete this->parents_; 66 66 67 67 // reset all weak pointers pointing to this object 68 68 for (std::set<WeakPtr<OrxonoxClass>*>::iterator it = this->weakPointers_.begin(); it != this->weakPointers_.end(); ) … … 77 77 if (this->referenceCount_ == 0) 78 78 delete this; 79 } 80 81 void OrxonoxClass::unregisterObject() 82 { 83 if (this->metaList_) 84 delete this->metaList_; 85 this->metaList_ = 0; 79 86 } 80 87 -
code/branches/presentation2/src/libraries/core/OrxonoxClass.h
r6105 r6121 73 73 74 74 void destroy(); 75 void unregisterObject(); 75 76 76 77 /** @brief Function to collect the SetConfigValue-macro calls. */
Note: See TracChangeset
for help on using the changeset viewer.