Changeset 4766 in orxonox.OLD for orxonox/trunk/src/orxonox.cc
- Timestamp:
- Jul 2, 2005, 11:54:41 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/orxonox.cc
r4756 r4766 43 43 #include "cd_engine.h" 44 44 45 #include "substring.h" 45 46 #include "class_list.h" 46 47 … … 59 60 { 60 61 this->setClassID(CL_ORXONOX, "Orxonox"); 61 this->setName("orxonox ");62 this->setName("orxonox-main"); 62 63 63 64 this->resourceManager = NULL; 64 65 this->objectManager = NULL; 65 66 this->eventHandler = NULL; 67 this->iniParser = NULL; 66 68 67 69 this->argc = 0; … … 74 76 Orxonox::~Orxonox () 75 77 { 76 int i = 0;77 Orxonox::singletonRef = NULL; 78 delete this->iniParser; 79 78 80 delete GraphicsEngine::getInstance(); // deleting the Graphics 79 81 delete TextEngine::getInstance(); … … 84 86 delete EventHandler::getInstance(); 85 87 delete Factory::getFirst(); 88 delete SoundEngine::getInstance(); 86 89 87 90 ClassList::debug(0); 88 } 89 90 /** \brief this is a singleton class to prevent duplicates */ 91 Orxonox* Orxonox::singletonRef = 0; 92 93 /** 94 \returns reference or new Object of Orxonox if not existent.95 */ 96 Orxonox* Orxonox::getInstance () 97 { 98 if (singletonRef == NULL)99 singletonRef = new Orxonox();100 return singletonRef;101 } 102 103 /** 104 \brief this finds the config file105 106 Since the config file varies from user to user and since one may want to specify different config files107 for certain occasions or platforms this function finds the right config file for every occasion and stores108 it's path and name into configfilename 109 */ 110 void Orxonox::getConfigFile (int argc, char** argv) 111 { 112 strcpy (configfilename, "~/.orxonox/orxonox.conf");91 92 PRINT(3)("===================================================\n" \ 93 "Thanks for playing orxonox.\n" \ 94 "visit: http://www.orxonox.ethz.ch for new versions.\n" \ 95 "===================================================\n"); 96 97 Orxonox::singletonRef = NULL; 98 } 99 100 /** 101 * @brief this is a singleton class to prevent duplicates 102 */ 103 Orxonox* Orxonox::singletonRef = NULL; 104 105 /** 106 * @brief this finds the config file 107 * @returns the new config-fileName 108 * Since the config file varies from user to user and since one may want to specify different config files 109 * for certain occasions or platforms this function finds the right config file for every occasion and stores 110 * it's path and name into configfilename 111 */ 112 const char* Orxonox::getConfigFile (int argc, char** argv) 113 { 114 strcpy (this->configFileName, DEFAULT_CONFIG_FILE); 115 this->iniParser = new IniParser(this->configFileName); 113 116 } 114 117 … … 123 126 // config file 124 127 125 getConfigFile (argc, argv); 128 // initialize the Config-file 129 this->getConfigFile(argc, argv); 130 131 126 132 SDL_Init (SDL_INIT_TIMER); 127 133 // initialize everything 128 printf("> Initializing resources\n");129 134 if( initResources () == -1) return -1; 130 131 135 if( initVideo() == -1) return -1; 132 136 if( initSound() == -1) return -1; 133 PRINT(3)("> Initializing input\n");134 137 if( initInput() == -1) return -1; 135 PRINT(3)("> Initializing networking\n");136 138 if( initNetworking () == -1) return -1; 137 139 //printf("> Initializing world\n"); … … 149 151 150 152 GraphicsEngine::getInstance(); 151 GraphicsEngine::getInstance()->setWindowName("orxonox " PACKAGE_VERSION, "orxonox " PACKAGE_VERSION); 152 153 return 0; 154 } 155 153 GraphicsEngine::getInstance()->setWindowName(PACKAGE_NAME " " PACKAGE_VERSION, PACKAGE_NAME " " PACKAGE_VERSION); 154 155 156 SubString resolution(this->iniParser->getVar(CONFIG_NAME_RESOLUTION, CONFIG_SECTION_VIDEO, "640x480"), 'x'); 157 GraphicsEngine::getInstance()->setResolution(atoi(resolution.getString(0)), atoi(resolution.getString(1)), 16); 158 159 // const char* fullscreen = this->iniParser->getVar(CONFIG_NAME_FULLSCREEN, CONFIG_SECTION_VIDEO, 0); 160 // GraphicsEngine::getInstance()->setFullscreen(false); 161 162 return 0; 163 } 156 164 157 165 /** … … 168 176 169 177 /** 170 \brief initializes input functions178 * @brief initializes input functions 171 179 */ 172 180 int Orxonox::initInput() 173 181 { 182 PRINT(3)("> Initializing input\n"); 183 174 184 this->eventHandler = EventHandler::getInstance(); 175 185 this->eventHandler->init(); … … 180 190 181 191 /** 182 \brief initializes network system192 * @brief initializes network system 183 193 */ 184 194 int Orxonox::initNetworking() 185 195 { 186 printf("Not yet implemented\n"); 187 return 0; 188 } 189 190 191 /** 192 \brief initializes and loads resource files 193 */ 194 int Orxonox::initResources() 195 { 196 PRINT(3)("initializing ResourceManager\n"); 197 resourceManager = ResourceManager::getInstance(); 196 PRINT(3)("> Initializing networking\n"); 197 198 printf(" ---Not yet implemented-FIXME--\n"); 199 return 0; 200 } 201 202 203 /** 204 * @brief initializes and loads resource files 205 */ 206 int Orxonox::initResources() 207 { 208 PRINTF(3)("> Initializing resources\n"); 209 210 PRINT(3)("initializing ResourceManager\n"); 211 resourceManager = ResourceManager::getInstance(); 198 212 199 213 // create parser 200 IniParser parser (DEFAULT_CONFIG_FILE); 201 if( parser.getSection (CONFIG_SECTION_DATA) == -1) 202 { 203 PRINTF(1)("Could not find Section %s in %s\n", CONFIG_SECTION_DATA, DEFAULT_CONFIG_FILE); 204 return -1; 205 } 206 char namebuf[256]; 207 char valuebuf[256]; 208 memset (namebuf, 0, 256); 209 memset (valuebuf, 0, 256); 210 211 while( parser.nextVar (namebuf, valuebuf) != -1) 212 { 213 if (!strcmp(namebuf, CONFIG_NAME_DATADIR)) 214 { 214 if( this->iniParser->getSection (CONFIG_SECTION_DATA) == -1) 215 { 216 PRINTF(1)("Could not find Section %s in %s\n", CONFIG_SECTION_DATA, DEFAULT_CONFIG_FILE); 217 return -1; 218 } 219 char namebuf[256]; 220 char valuebuf[256]; 221 memset (namebuf, 0, 256); 222 memset (valuebuf, 0, 256); 223 224 while( this->iniParser->nextVar (namebuf, valuebuf) != -1) 225 { 226 if (!strcmp(namebuf, CONFIG_NAME_DATADIR)) 227 { 215 228 // printf("Not yet implemented\n"); 216 if (!resourceManager->setDataDir(valuebuf)) 217 { 218 PRINTF(1)("Data Could not be located\n"); 219 exit(-1); 220 } 221 } 222 223 memset (namebuf, 0, 256); 224 memset (valuebuf, 0, 256); 225 } 226 227 if (!resourceManager->checkDataDir(DEFAULT_DATA_DIR_CHECKFILE)) 228 { 229 PRINTF(1)("The DataDirectory %s could not be verified\nPlease Change in File %s Section %s Entry %s to a suitable value\n", 230 resourceManager->getDataDir(), 231 DEFAULT_CONFIG_FILE, 232 CONFIG_SECTION_DATA, 233 CONFIG_NAME_DATADIR); 234 exit(-1); 235 } 229 if (!resourceManager->setDataDir(valuebuf)) 230 { 231 PRINTF(1)("Data Could not be located\n"); 232 exit(-1); 233 } 234 } 235 236 memset (namebuf, 0, 256); 237 memset (valuebuf, 0, 256); 238 } 239 240 if (!resourceManager->checkDataDir(DEFAULT_DATA_DIR_CHECKFILE)) 241 { 242 PRINTF(1)("The DataDirectory %s could not be verified\n" \ 243 " Please Change in File %s Section %s Entry %s to a suitable value\n", 244 resourceManager->getDataDir(), 245 DEFAULT_CONFIG_FILE, 246 CONFIG_SECTION_DATA, 247 CONFIG_NAME_DATADIR); 248 exit(-1); 249 } 236 250 //! \todo this is a hack and should be loadable 237 resourceManager->addImageDir(ResourceManager::getInstance()->getFullName("maps/")); 238 resourceManager->debug(); 239 240 PRINT(3)("initializing TextEngine\n"); 241 TextEngine::getInstance(); 242 243 PRINT(3)("initializing ObjectManager\n"); 244 this->objectManager = ObjectManager::getInstance(); 245 246 CDEngine::getInstance(); 247 248 return 0; 249 } 250 251 252 251 resourceManager->addImageDir(ResourceManager::getInstance()->getFullName("maps/")); 252 resourceManager->debug(); 253 254 PRINT(3)("initializing TextEngine\n"); 255 TextEngine::getInstance(); 256 257 PRINT(3)("initializing ObjectManager\n"); 258 this->objectManager = ObjectManager::getInstance(); 259 260 CDEngine::getInstance(); 261 262 return 0; 263 } 253 264 254 265 /** … … 299 310 bool showGui = false; 300 311 312 313 314 /********************************** 315 *** ORXONOX MAIN STARTING POINT *** 316 **********************************/ 301 317 /** 302 318 \brief main function … … 306 322 int main(int argc, char** argv) 307 323 { 308 309 324 // here the pre-arguments are loaded, these are needed to go either to orxonx itself, Help, or Benchmark. 310 325 int i; … … 337 352 338 353 354 355 /** 356 * starts orxonox 357 * @param argc parameters count given to orxonox 358 * @param argv parameters given to orxonox 359 */ 339 360 int startOrxonox(int argc, char** argv) 340 361 { 341 362 // checking for existence of the configuration-files 342 363 if (showGui || 343 !ResourceManager::isFile( "~/.orxonox/orxonox.conf") ||344 ResourceManager::isFile( "~/.orxonox/orxonox.lock"))345 { 346 if (ResourceManager::isFile( "~/.orxonox/orxonox.lock"))347 ResourceManager::deleteFile( "~/.orxonox/orxonox.lock");364 !ResourceManager::isFile(DEFAULT_CONFIG_FILE) || 365 ResourceManager::isFile(DEFAULT_LOCK_FILE)) 366 { 367 if (ResourceManager::isFile(DEFAULT_LOCK_FILE)) 368 ResourceManager::deleteFile(DEFAULT_LOCK_FILE); 348 369 349 370 // starting the GUI … … 359 380 PRINT(0)(">>> Starting Orxonox <<<\n"); 360 381 361 ResourceManager::touchFile( "~/.orxonox/orxonox.lock");382 ResourceManager::touchFile(DEFAULT_LOCK_FILE); 362 383 363 384 Orxonox *orx = Orxonox::getInstance();
Note: See TracChangeset
for help on using the changeset viewer.