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