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