Changeset 2485 for code/branches/presentation/src/core/Core.cc
- Timestamp:
- Dec 16, 2008, 6:01:13 PM (16 years ago)
- Location:
- code/branches/presentation
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation
-
code/branches/presentation/src/core/Core.cc
r2171 r2485 46 46 bool Core::bIsMaster_s = false; 47 47 48 Core* Core::singletonRef_s = 0; 49 48 50 /** 49 51 @brief Constructor: Registers the object and sets the config-values. … … 53 55 { 54 56 RegisterRootObject(Core); 57 58 assert(Core::singletonRef_s == 0); 59 Core::singletonRef_s = this; 60 this->bInitializeRandomNumberGenerator_ = false; 61 55 62 this->setConfigValues(); 56 isCreatingCoreSettings() = false;57 63 } 58 64 … … 62 68 Core::~Core() 63 69 { 64 isCreatingCoreSettings() = true; 65 } 66 67 /** 68 @brief Returns true if the Core instance is not yet ready and the static functions have to return a default value. 69 */ 70 bool& Core::isCreatingCoreSettings() 71 { 72 static bool bCreatingCoreSettings = true; 73 return bCreatingCoreSettings; 74 } 75 76 /** 77 @brief Returns a unique instance of Core. 78 @return The instance 79 */ 80 Core& Core::getInstance() 81 { 82 // If bCreatingSoftDebugLevelObject is true, we're just about to create an instance of the DebugLevel class 83 //if (Core::isCreatingCoreSettings()) 84 //{ 85 // isCreatingCoreSettings() = false; 86 // //instance.setConfigValues(); 87 //} 88 89 static bool firstTime = true; 90 if (firstTime) 91 isCreatingCoreSettings() = true; 92 93 static Core instance; 94 return instance; 70 assert(Core::singletonRef_s); 71 Core::singletonRef_s = 0; 95 72 } 96 73 … … 104 81 SetConfigValue(softDebugLevelShell_, 1).description("The maximal level of debug output shown in the ingame shell").callback(this, &Core::debugLevelChanged); 105 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); 106 84 } 107 85 … … 140 118 int Core::getSoftDebugLevel(OutputHandler::OutputDevice device) 141 119 { 142 if (!Core::isCreatingCoreSettings())120 switch (device) 143 121 { 144 switch (device) 145 { 146 case OutputHandler::LD_All: 147 return Core::getInstance().softDebugLevel_; 148 case OutputHandler::LD_Console: 149 return Core::getInstance().softDebugLevelConsole_; 150 case OutputHandler::LD_Logfile: 151 return Core::getInstance().softDebugLevelLogfile_; 152 case OutputHandler::LD_Shell: 153 return Core::getInstance().softDebugLevelShell_; 154 default: 155 assert(0); 156 } 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; 157 133 } 158 159 // Return a constant value while we're creating the object160 return 2;161 134 } 162 135 … … 168 141 void Core::setSoftDebugLevel(OutputHandler::OutputDevice device, int level) 169 142 { 170 if (!Core::isCreatingCoreSettings()) 171 { 172 if (device == OutputHandler::LD_All) 173 Core::getInstance().softDebugLevel_ = level; 174 else if (device == OutputHandler::LD_Console) 175 Core::getInstance().softDebugLevelConsole_ = level; 176 else if (device == OutputHandler::LD_Logfile) 177 Core::getInstance().softDebugLevelLogfile_ = level; 178 else if (device == OutputHandler::LD_Shell) 179 Core::getInstance().softDebugLevelShell_ = level; 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; 180 151 181 OutputHandler::setSoftDebugLevel(device, level); 182 } 152 OutputHandler::setSoftDebugLevel(device, level); 183 153 } 184 154 … … 188 158 const std::string& Core::getLanguage() 189 159 { 190 if (!Core::isCreatingCoreSettings()) 191 return Core::getInstance().language_; 192 193 return Language::getLanguage().defaultLanguage_; 160 return Core::getInstance().language_; 194 161 } 195 162 … … 209 176 ResetConfigValue(language_); 210 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 } 211 189 }
Note: See TracChangeset
for help on using the changeset viewer.