[4982] | 1 | /* |
---|
[1850] | 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
| 10 | |
---|
| 11 | This program is distributed in the hope that it will be useful, |
---|
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 14 | GNU General Public License for more details. |
---|
| 15 | |
---|
| 16 | You should have received a copy of the GNU General Public License |
---|
| 17 | along with this program; if not, write to the Free Software Foundation, |
---|
[4556] | 18 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
[1850] | 19 | |
---|
[1855] | 20 | |
---|
| 21 | ### File Specific: |
---|
| 22 | main-programmer: Patrick Boenzli |
---|
[5303] | 23 | co-programmer: Christian Meyer |
---|
[4054] | 24 | co-programmer: Benjamin Grauer: injected ResourceManager/GraphicsEngine/GUI |
---|
[1850] | 25 | */ |
---|
| 26 | |
---|
[5303] | 27 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ORXONOX |
---|
[2190] | 28 | #include "orxonox.h" |
---|
[3610] | 29 | |
---|
[4054] | 30 | #include "gui.h" |
---|
| 31 | |
---|
[2036] | 32 | #include "world.h" |
---|
[4091] | 33 | #include "ini_parser.h" |
---|
[5165] | 34 | #include "game_loader.h" |
---|
[4786] | 35 | |
---|
| 36 | //ENGINES |
---|
[3610] | 37 | #include "graphics_engine.h" |
---|
[4504] | 38 | #include "sound_engine.h" |
---|
[3655] | 39 | #include "resource_manager.h" |
---|
[4786] | 40 | #include "cd_engine.h" |
---|
[3790] | 41 | #include "text_engine.h" |
---|
[4786] | 42 | #include "event_handler.h" |
---|
[4815] | 43 | #include "garbage_collector.h" |
---|
[4786] | 44 | |
---|
[4010] | 45 | #include "factory.h" |
---|
[4980] | 46 | #include "fast_factory.h" |
---|
| 47 | |
---|
[4131] | 48 | #include "benchmark.h" |
---|
[3610] | 49 | |
---|
[4786] | 50 | #include "class_list.h" |
---|
[5641] | 51 | #include "shell_command_class.h" |
---|
[5165] | 52 | #include "shell_command.h" |
---|
[5175] | 53 | #include "shell_buffer.h" |
---|
[4748] | 54 | |
---|
[5546] | 55 | #include "load_param_description.h" |
---|
[5226] | 56 | |
---|
[2190] | 57 | #include <string.h> |
---|
[4032] | 58 | |
---|
[4885] | 59 | int verbose = 4; |
---|
[2036] | 60 | |
---|
[1803] | 61 | using namespace std; |
---|
| 62 | |
---|
[5207] | 63 | SHELL_COMMAND(restart, Orxonox, restart); |
---|
| 64 | |
---|
[2190] | 65 | /** |
---|
[4836] | 66 | * create a new Orxonox |
---|
[4135] | 67 | |
---|
| 68 | In this funcitons only global values are set. The game will not be started here. |
---|
[2190] | 69 | */ |
---|
| 70 | Orxonox::Orxonox () |
---|
[1872] | 71 | { |
---|
[4445] | 72 | this->setClassID(CL_ORXONOX, "Orxonox"); |
---|
[4766] | 73 | this->setName("orxonox-main"); |
---|
[4059] | 74 | |
---|
[4766] | 75 | this->iniParser = NULL; |
---|
[4135] | 76 | |
---|
| 77 | this->argc = 0; |
---|
| 78 | this->argv = NULL; |
---|
[4782] | 79 | |
---|
[4830] | 80 | this->configFileName = NULL; |
---|
[1872] | 81 | } |
---|
[1803] | 82 | |
---|
[2190] | 83 | /** |
---|
[4836] | 84 | * remove Orxonox from memory |
---|
[2190] | 85 | */ |
---|
[4556] | 86 | Orxonox::~Orxonox () |
---|
[2190] | 87 | { |
---|
[5285] | 88 | // game-specific |
---|
[4815] | 89 | delete GameLoader::getInstance(); |
---|
| 90 | delete GarbageCollector::getInstance(); |
---|
[5285] | 91 | |
---|
| 92 | // class-less services/factories |
---|
| 93 | delete Factory::getFirst(); |
---|
[4980] | 94 | FastFactory::deleteAll(); |
---|
[5171] | 95 | ShellCommandClass::unregisterAllCommands(); |
---|
[5332] | 96 | |
---|
[5226] | 97 | LoadClassDescription::deleteAllDescriptions(); |
---|
| 98 | |
---|
[5285] | 99 | // engines |
---|
| 100 | delete CDEngine::getInstance(); |
---|
| 101 | delete SoundEngine::getInstance(); |
---|
| 102 | delete GraphicsEngine::getInstance(); // deleting the Graphics |
---|
[4817] | 103 | delete EventHandler::getInstance(); |
---|
[5285] | 104 | |
---|
| 105 | // handlers |
---|
| 106 | delete ResourceManager::getInstance(); // deletes the Resource Manager |
---|
| 107 | // output-buffer |
---|
| 108 | delete ShellBuffer::getInstance(); |
---|
| 109 | |
---|
| 110 | // orxonox class-stuff |
---|
[5078] | 111 | delete this->iniParser; |
---|
[5210] | 112 | delete[] this->configFileName; |
---|
[4817] | 113 | |
---|
[5225] | 114 | SDL_QuitSubSystem(SDL_INIT_TIMER); |
---|
[4942] | 115 | ClassList::debug(); |
---|
[1850] | 116 | |
---|
[4833] | 117 | PRINT(3) |
---|
[4981] | 118 | ( |
---|
| 119 | "===================================================\n" \ |
---|
[4766] | 120 | "Thanks for playing orxonox.\n" \ |
---|
[5037] | 121 | "visit: http://www.orxonox.net for new versions.\n" \ |
---|
[4946] | 122 | "===================================================\n" \ |
---|
[4981] | 123 | ORXONOX_LICENSE_SHORT |
---|
| 124 | ); |
---|
[1872] | 125 | |
---|
[4766] | 126 | Orxonox::singletonRef = NULL; |
---|
[1850] | 127 | } |
---|
| 128 | |
---|
[2190] | 129 | /** |
---|
[4836] | 130 | * this is a singleton class to prevent duplicates |
---|
[4766] | 131 | */ |
---|
| 132 | Orxonox* Orxonox::singletonRef = NULL; |
---|
[4556] | 133 | |
---|
[5207] | 134 | // DANGEROUS |
---|
| 135 | void Orxonox::restart() |
---|
| 136 | { |
---|
| 137 | // int argc = this->argc; |
---|
| 138 | // char** argv = this->argv; |
---|
| 139 | // |
---|
| 140 | // Orxonox *orx = Orxonox::getInstance(); |
---|
| 141 | // |
---|
| 142 | // delete orx; |
---|
| 143 | // |
---|
| 144 | // orx = Orxonox::getInstance(); |
---|
| 145 | // |
---|
| 146 | // if((*orx).init(argc, argv) == -1) |
---|
| 147 | // { |
---|
| 148 | // PRINTF(1)("! Orxonox initialization failed\n"); |
---|
| 149 | // return; |
---|
| 150 | // } |
---|
| 151 | // |
---|
| 152 | // printf("finished inizialisation\n"); |
---|
| 153 | // orx->start(); |
---|
| 154 | } |
---|
| 155 | |
---|
[4766] | 156 | /** |
---|
[4836] | 157 | * this finds the config file |
---|
[4766] | 158 | * @returns the new config-fileName |
---|
| 159 | * Since the config file varies from user to user and since one may want to specify different config files |
---|
| 160 | * for certain occasions or platforms this function finds the right config file for every occasion and stores |
---|
| 161 | * it's path and name into configfilename |
---|
[2190] | 162 | */ |
---|
[4830] | 163 | const char* Orxonox::getConfigFile () |
---|
[1850] | 164 | { |
---|
[5424] | 165 | if (ResourceManager::isFile("orxonox.conf")) |
---|
| 166 | { |
---|
| 167 | this->configFileName = new char[strlen("orxonox.conf")+1]; |
---|
| 168 | strcpy(this->configFileName, "orxonox.conf"); |
---|
| 169 | } |
---|
| 170 | else |
---|
| 171 | this->configFileName = ResourceManager::homeDirCheck(DEFAULT_CONFIG_FILE); |
---|
[4766] | 172 | this->iniParser = new IniParser(this->configFileName); |
---|
[5424] | 173 | PRINTF(3)("Parsed Config File: '%s'\n", this->configFileName); |
---|
[1803] | 174 | } |
---|
| 175 | |
---|
[2190] | 176 | /** |
---|
[4833] | 177 | * initialize Orxonox with command line |
---|
| 178 | */ |
---|
[2190] | 179 | int Orxonox::init (int argc, char** argv) |
---|
[1803] | 180 | { |
---|
[4135] | 181 | this->argc = argc; |
---|
| 182 | this->argv = argv; |
---|
[2636] | 183 | // parse command line |
---|
| 184 | // config file |
---|
[4556] | 185 | |
---|
[4766] | 186 | // initialize the Config-file |
---|
[4830] | 187 | this->getConfigFile(); |
---|
[4766] | 188 | |
---|
[4782] | 189 | // initialize everything |
---|
[5227] | 190 | SDL_Init(SDL_INIT_TIMER); |
---|
[5788] | 191 | // windows must not write into stdout.txt and stderr.txt |
---|
| 192 | #ifdef __WIN32__ |
---|
| 193 | freopen( "CON", "w", stdout ); |
---|
| 194 | freopen( "CON", "w", stderr ); |
---|
| 195 | #endif |
---|
| 196 | |
---|
[4113] | 197 | if( initResources () == -1) return -1; |
---|
[3226] | 198 | if( initVideo() == -1) return -1; |
---|
| 199 | if( initSound() == -1) return -1; |
---|
| 200 | if( initInput() == -1) return -1; |
---|
| 201 | if( initNetworking () == -1) return -1; |
---|
[5074] | 202 | if( initMisc () == -1) return -1; |
---|
[4556] | 203 | |
---|
[2636] | 204 | return 0; |
---|
[1850] | 205 | } |
---|
[1849] | 206 | |
---|
[2190] | 207 | /** |
---|
[4833] | 208 | * initializes SDL and OpenGL |
---|
[2190] | 209 | */ |
---|
[4556] | 210 | int Orxonox::initVideo() |
---|
[2190] | 211 | { |
---|
[3611] | 212 | PRINTF(3)("> Initializing video\n"); |
---|
[4556] | 213 | |
---|
[3610] | 214 | GraphicsEngine::getInstance(); |
---|
[4556] | 215 | |
---|
[4784] | 216 | GraphicsEngine::getInstance()->initFromIniFile(this->iniParser); |
---|
[4766] | 217 | |
---|
[5219] | 218 | char* iconName = ResourceManager::getFullName("pictures/fighter-top-32x32.bmp"); |
---|
[5225] | 219 | if (iconName != NULL) |
---|
| 220 | { |
---|
| 221 | GraphicsEngine::getInstance()->setWindowName(PACKAGE_NAME " " PACKAGE_VERSION, iconName); |
---|
| 222 | delete[] iconName; |
---|
| 223 | } |
---|
[2190] | 224 | return 0; |
---|
| 225 | } |
---|
[1850] | 226 | |
---|
[2190] | 227 | /** |
---|
[4833] | 228 | * initializes the sound engine |
---|
| 229 | */ |
---|
[4556] | 230 | int Orxonox::initSound() |
---|
[2190] | 231 | { |
---|
[4504] | 232 | PRINT(3)("> Initializing sound\n"); |
---|
[5225] | 233 | // SDL_InitSubSystem(SDL_INIT_AUDIO); |
---|
[4504] | 234 | SoundEngine::getInstance()->initAudio(); |
---|
[4985] | 235 | |
---|
| 236 | SoundEngine::getInstance()->loadSettings(this->iniParser); |
---|
[2636] | 237 | return 0; |
---|
[2190] | 238 | } |
---|
[1900] | 239 | |
---|
[3214] | 240 | |
---|
[2190] | 241 | /** |
---|
[4833] | 242 | * initializes input functions |
---|
| 243 | */ |
---|
[4556] | 244 | int Orxonox::initInput() |
---|
[2190] | 245 | { |
---|
[4766] | 246 | PRINT(3)("> Initializing input\n"); |
---|
| 247 | |
---|
[4866] | 248 | EventHandler::getInstance()->init(this->iniParser); |
---|
[4833] | 249 | EventHandler::getInstance()->subscribe(GraphicsEngine::getInstance(), ES_ALL, EV_VIDEO_RESIZE); |
---|
[4556] | 250 | |
---|
[2636] | 251 | return 0; |
---|
[1803] | 252 | } |
---|
| 253 | |
---|
[3214] | 254 | |
---|
[2190] | 255 | /** |
---|
[4833] | 256 | * initializes network system |
---|
| 257 | */ |
---|
[4556] | 258 | int Orxonox::initNetworking() |
---|
[1897] | 259 | { |
---|
[4766] | 260 | PRINT(3)("> Initializing networking\n"); |
---|
| 261 | |
---|
| 262 | printf(" ---Not yet implemented-FIXME--\n"); |
---|
[2636] | 263 | return 0; |
---|
[1897] | 264 | } |
---|
| 265 | |
---|
[3214] | 266 | |
---|
[2190] | 267 | /** |
---|
[4833] | 268 | * initializes and loads resource files |
---|
[4766] | 269 | */ |
---|
[4833] | 270 | int Orxonox::initResources() |
---|
[1858] | 271 | { |
---|
[4766] | 272 | PRINTF(3)("> Initializing resources\n"); |
---|
[4091] | 273 | |
---|
[4766] | 274 | PRINT(3)("initializing ResourceManager\n"); |
---|
| 275 | |
---|
[5488] | 276 | // init the resource manager |
---|
[5014] | 277 | const char* dataPath; |
---|
| 278 | if ((dataPath = this->iniParser->getVar(CONFIG_NAME_DATADIR, CONFIG_SECTION_DATA))!= NULL) |
---|
[4766] | 279 | { |
---|
[5480] | 280 | if (!ResourceManager::getInstance()->setDataDir(dataPath) && |
---|
| 281 | !ResourceManager::getInstance()->verifyDataDir(DEFAULT_DATA_DIR_CHECKFILE)) |
---|
[4766] | 282 | { |
---|
[5423] | 283 | PRINTF(1)("Data Could not be located in %s\n", dataPath); |
---|
[4766] | 284 | } |
---|
| 285 | } |
---|
[4556] | 286 | |
---|
[5480] | 287 | if (!ResourceManager::getInstance()->verifyDataDir(DEFAULT_DATA_DIR_CHECKFILE)) |
---|
[4766] | 288 | { |
---|
[5510] | 289 | PRINTF(1)("The DataDirectory %s could not be verified\n\nh" \ |
---|
| 290 | "!!! Please Change in File %s Section %s Entry %s to a suitable value !!!\n", |
---|
[4822] | 291 | ResourceManager::getInstance()->getDataDir(), |
---|
[5424] | 292 | this->configFileName, |
---|
[4766] | 293 | CONFIG_SECTION_DATA, |
---|
[5510] | 294 | CONFIG_NAME_DATADIR ); |
---|
[5479] | 295 | Gui* gui = new Gui(argc, argv); |
---|
| 296 | gui->startGui(); |
---|
| 297 | delete gui; |
---|
[4766] | 298 | exit(-1); |
---|
| 299 | } |
---|
[4836] | 300 | //! @todo this is a hack and should be loadable |
---|
[5335] | 301 | char* imageDir = ResourceManager::getInstance()->getFullName("maps"); |
---|
[5216] | 302 | ResourceManager::getInstance()->addImageDir(imageDir); |
---|
| 303 | delete[] imageDir; |
---|
[4009] | 304 | |
---|
[5488] | 305 | // start the collision detection engine |
---|
[4766] | 306 | CDEngine::getInstance(); |
---|
[5074] | 307 | return 0; |
---|
| 308 | } |
---|
| 309 | |
---|
| 310 | /** |
---|
| 311 | * initializes miscelaneous features |
---|
| 312 | * @return -1 on failure |
---|
| 313 | */ |
---|
| 314 | int Orxonox::initMisc() |
---|
| 315 | { |
---|
[5183] | 316 | ShellBuffer::getInstance(); |
---|
[4766] | 317 | return 0; |
---|
[1858] | 318 | } |
---|
[1849] | 319 | |
---|
[2190] | 320 | /** |
---|
[4836] | 321 | * starts the orxonox game or menu |
---|
[4833] | 322 | * here is the central orxonox state manager. There are currently two states |
---|
| 323 | * - menu |
---|
| 324 | * - game-play |
---|
| 325 | * both states manage their states themselfs again. |
---|
[2190] | 326 | */ |
---|
[2636] | 327 | void Orxonox::start() |
---|
| 328 | { |
---|
[4556] | 329 | |
---|
[2636] | 330 | this->gameLoader = GameLoader::getInstance(); |
---|
[4094] | 331 | this->gameLoader->loadCampaign("worlds/DefaultCampaign.oxc"); |
---|
[4010] | 332 | // this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0); |
---|
[2636] | 333 | this->gameLoader->init(); |
---|
| 334 | this->gameLoader->start(); |
---|
| 335 | } |
---|
| 336 | |
---|
[3214] | 337 | |
---|
[2636] | 338 | /** |
---|
[4833] | 339 | * handles sprecial events from localinput |
---|
| 340 | * @param event: an event not handled by the CommandNode |
---|
| 341 | */ |
---|
[4817] | 342 | // void Orxonox::graphicsHandler(SDL_Event* event) |
---|
| 343 | // { |
---|
| 344 | // // Handle special events such as reshape, quit, focus changes |
---|
| 345 | // switch (event->type) |
---|
| 346 | // { |
---|
| 347 | // case SDL_VIDEORESIZE: |
---|
| 348 | // GraphicsEngine* tmpGEngine = GraphicsEngine::getInstance(); |
---|
| 349 | // tmpGEngine->resolutionChanged(event->resize); |
---|
| 350 | // break; |
---|
| 351 | // } |
---|
| 352 | // } |
---|
[1875] | 353 | |
---|
[4556] | 354 | |
---|
[4408] | 355 | |
---|
[1803] | 356 | |
---|
[3214] | 357 | |
---|
[4782] | 358 | |
---|
[4059] | 359 | bool showGui = false; |
---|
[3648] | 360 | |
---|
[4766] | 361 | |
---|
| 362 | |
---|
| 363 | /********************************** |
---|
| 364 | *** ORXONOX MAIN STARTING POINT *** |
---|
| 365 | **********************************/ |
---|
[3449] | 366 | /** |
---|
[4833] | 367 | * |
---|
[4836] | 368 | * main function |
---|
[4833] | 369 | * |
---|
| 370 | * here the journey begins |
---|
[3449] | 371 | */ |
---|
[4556] | 372 | int main(int argc, char** argv) |
---|
| 373 | { |
---|
[4135] | 374 | // here the pre-arguments are loaded, these are needed to go either to orxonx itself, Help, or Benchmark. |
---|
[3648] | 375 | int i; |
---|
[4032] | 376 | for(i = 1; i < argc; ++i) |
---|
[3648] | 377 | { |
---|
[4135] | 378 | if(! strcmp( "--help", argv[i]) || !strcmp("-h", argv[i])) return startHelp(argc, argv); |
---|
| 379 | else if(!strcmp( "--benchmark", argv[i]) || !strcmp("-b", argv[i])) return startBenchmarks(); |
---|
| 380 | else if(!strcmp( "--gui", argv[i]) || !strcmp("-g", argv[i])) showGui = true; |
---|
| 381 | // else PRINTF(2)("Orxonox does not understand the arguments %s\n", argv[i]); |
---|
[3648] | 382 | } |
---|
| 383 | |
---|
| 384 | return startOrxonox(argc, argv); |
---|
| 385 | } |
---|
| 386 | |
---|
| 387 | |
---|
| 388 | |
---|
[4132] | 389 | int startHelp(int argc, char** argv) |
---|
[3648] | 390 | { |
---|
[4032] | 391 | PRINT(0)("orxonox: starts the orxonox game - rules\n"); |
---|
[4134] | 392 | PRINT(0)("usage: orxonox [arg [arg...]]\n\n"); |
---|
[4032] | 393 | PRINT(0)("valid options:\n"); |
---|
[4132] | 394 | { |
---|
| 395 | Gui* gui = new Gui(argc, argv); |
---|
| 396 | gui->printHelp(); |
---|
| 397 | delete gui; |
---|
| 398 | } |
---|
[4135] | 399 | PRINT(0)(" -b|--benchmark:\t\tstarts the orxonox benchmark\n"); |
---|
| 400 | PRINT(0)(" -h|--help:\t\t\tshows this help\n"); |
---|
[3648] | 401 | } |
---|
| 402 | |
---|
[3649] | 403 | |
---|
[4766] | 404 | |
---|
| 405 | /** |
---|
| 406 | * starts orxonox |
---|
| 407 | * @param argc parameters count given to orxonox |
---|
| 408 | * @param argv parameters given to orxonox |
---|
| 409 | */ |
---|
[3648] | 410 | int startOrxonox(int argc, char** argv) |
---|
| 411 | { |
---|
[4830] | 412 | // checking for existence of the configuration-files, or if the lock file is still used |
---|
[5424] | 413 | if (showGui || (!ResourceManager::isFile("./orxonox.conf") && |
---|
| 414 | !ResourceManager::isFile(DEFAULT_CONFIG_FILE)) |
---|
| 415 | #if DEBUG < 3 // developers do not need to see the GUI, when orxonox fails |
---|
[4981] | 416 | || ResourceManager::isFile(DEFAULT_LOCK_FILE) |
---|
| 417 | #endif |
---|
| 418 | ) |
---|
[4032] | 419 | { |
---|
[4766] | 420 | if (ResourceManager::isFile(DEFAULT_LOCK_FILE)) |
---|
| 421 | ResourceManager::deleteFile(DEFAULT_LOCK_FILE); |
---|
[4556] | 422 | |
---|
[4132] | 423 | // starting the GUI |
---|
[4056] | 424 | Gui* gui = new Gui(argc, argv); |
---|
[4132] | 425 | gui->startGui(); |
---|
| 426 | |
---|
[4054] | 427 | if (! gui->startOrxonox) |
---|
[4556] | 428 | return 0; |
---|
| 429 | |
---|
[4054] | 430 | delete gui; |
---|
[4032] | 431 | } |
---|
[4556] | 432 | |
---|
[4032] | 433 | PRINT(0)(">>> Starting Orxonox <<<\n"); |
---|
[4033] | 434 | |
---|
[4766] | 435 | ResourceManager::touchFile(DEFAULT_LOCK_FILE); |
---|
[4033] | 436 | |
---|
[1850] | 437 | Orxonox *orx = Orxonox::getInstance(); |
---|
[4556] | 438 | |
---|
[5488] | 439 | if(orx->init(argc, argv) == -1) |
---|
[2636] | 440 | { |
---|
[4032] | 441 | PRINTF(1)("! Orxonox initialization failed\n"); |
---|
[2636] | 442 | return -1; |
---|
| 443 | } |
---|
[4556] | 444 | |
---|
[5018] | 445 | printf("finished inizialisation\n"); |
---|
[2636] | 446 | orx->start(); |
---|
[4556] | 447 | |
---|
[3676] | 448 | delete orx; |
---|
[4033] | 449 | ResourceManager::deleteFile("~/.orxonox/orxonox.lock"); |
---|
[1803] | 450 | } |
---|