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