| [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 |  | 
|---|
| [5819] | 30 | #include "globals.h" | 
|---|
|  | 31 |  | 
|---|
| [4054] | 32 | #include "gui.h" | 
|---|
|  | 33 |  | 
|---|
| [5944] | 34 | #include "parser/ini_parser/ini_parser.h" | 
|---|
| [5165] | 35 | #include "game_loader.h" | 
|---|
| [4786] | 36 |  | 
|---|
|  | 37 | //ENGINES | 
|---|
| [3610] | 38 | #include "graphics_engine.h" | 
|---|
| [4504] | 39 | #include "sound_engine.h" | 
|---|
| [3655] | 40 | #include "resource_manager.h" | 
|---|
| [4786] | 41 | #include "cd_engine.h" | 
|---|
| [3790] | 42 | #include "text_engine.h" | 
|---|
| [4786] | 43 | #include "event_handler.h" | 
|---|
|  | 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 |  | 
|---|
| [5996] | 57 | #include "network_manager.h" | 
|---|
|  | 58 |  | 
|---|
| [6695] | 59 | #include "state.h" | 
|---|
|  | 60 |  | 
|---|
| [2190] | 61 | #include <string.h> | 
|---|
| [4032] | 62 |  | 
|---|
| [4885] | 63 | int verbose = 4; | 
|---|
| [2036] | 64 |  | 
|---|
| [1803] | 65 | using namespace std; | 
|---|
|  | 66 |  | 
|---|
| [5207] | 67 | SHELL_COMMAND(restart, Orxonox, restart); | 
|---|
|  | 68 |  | 
|---|
| [2190] | 69 | /** | 
|---|
| [4836] | 70 | *  create a new Orxonox | 
|---|
| [4135] | 71 |  | 
|---|
|  | 72 | In this funcitons only global values are set. The game will not be started here. | 
|---|
| [2190] | 73 | */ | 
|---|
|  | 74 | Orxonox::Orxonox () | 
|---|
| [1872] | 75 | { | 
|---|
| [4445] | 76 | this->setClassID(CL_ORXONOX, "Orxonox"); | 
|---|
| [4766] | 77 | this->setName("orxonox-main"); | 
|---|
| [4059] | 78 |  | 
|---|
| [4766] | 79 | this->iniParser = NULL; | 
|---|
| [4135] | 80 |  | 
|---|
|  | 81 | this->argc = 0; | 
|---|
|  | 82 | this->argv = NULL; | 
|---|
| [4782] | 83 |  | 
|---|
| [5996] | 84 | /* this way, there is no network enabled: */ | 
|---|
|  | 85 | this->serverName = NULL; | 
|---|
|  | 86 | this->port = -1; | 
|---|
|  | 87 |  | 
|---|
| [4830] | 88 | this->configFileName = NULL; | 
|---|
| [1872] | 89 | } | 
|---|
| [1803] | 90 |  | 
|---|
| [2190] | 91 | /** | 
|---|
| [4836] | 92 | *  remove Orxonox from memory | 
|---|
| [2190] | 93 | */ | 
|---|
| [4556] | 94 | Orxonox::~Orxonox () | 
|---|
| [2190] | 95 | { | 
|---|
| [5285] | 96 | // game-specific | 
|---|
| [4815] | 97 | delete GameLoader::getInstance(); | 
|---|
| [5285] | 98 |  | 
|---|
|  | 99 | // class-less services/factories | 
|---|
| [5982] | 100 | Factory::deleteFactories(); | 
|---|
| [4980] | 101 | FastFactory::deleteAll(); | 
|---|
| [5171] | 102 | ShellCommandClass::unregisterAllCommands(); | 
|---|
| [5332] | 103 |  | 
|---|
| [5226] | 104 | LoadClassDescription::deleteAllDescriptions(); | 
|---|
|  | 105 |  | 
|---|
| [5285] | 106 | // engines | 
|---|
|  | 107 | delete CDEngine::getInstance(); | 
|---|
|  | 108 | delete SoundEngine::getInstance(); | 
|---|
|  | 109 | delete GraphicsEngine::getInstance(); // deleting the Graphics | 
|---|
| [4817] | 110 | delete EventHandler::getInstance(); | 
|---|
| [5285] | 111 |  | 
|---|
|  | 112 | // handlers | 
|---|
|  | 113 | delete ResourceManager::getInstance(); // deletes the Resource Manager | 
|---|
|  | 114 | // output-buffer | 
|---|
|  | 115 | delete ShellBuffer::getInstance(); | 
|---|
|  | 116 |  | 
|---|
|  | 117 | // orxonox class-stuff | 
|---|
| [5078] | 118 | delete this->iniParser; | 
|---|
| [5210] | 119 | delete[] this->configFileName; | 
|---|
| [4817] | 120 |  | 
|---|
| [5225] | 121 | SDL_QuitSubSystem(SDL_INIT_TIMER); | 
|---|
| [7126] | 122 | ClassList::debug(); | 
|---|
| [1850] | 123 |  | 
|---|
| [4833] | 124 | PRINT(3) | 
|---|
| [5996] | 125 | ( | 
|---|
|  | 126 | "===================================================\n" \ | 
|---|
|  | 127 | "Thanks for playing orxonox.\n" \ | 
|---|
|  | 128 | "visit: http://www.orxonox.net for new versions.\n" \ | 
|---|
|  | 129 | "===================================================\n" \ | 
|---|
|  | 130 | ORXONOX_LICENSE_SHORT | 
|---|
|  | 131 | ); | 
|---|
| [1872] | 132 |  | 
|---|
| [4766] | 133 | Orxonox::singletonRef = NULL; | 
|---|
| [1850] | 134 | } | 
|---|
|  | 135 |  | 
|---|
| [2190] | 136 | /** | 
|---|
| [4836] | 137 | *  this is a singleton class to prevent duplicates | 
|---|
| [4766] | 138 | */ | 
|---|
|  | 139 | Orxonox* Orxonox::singletonRef = NULL; | 
|---|
| [4556] | 140 |  | 
|---|
| [5207] | 141 | // DANGEROUS | 
|---|
|  | 142 | void Orxonox::restart() | 
|---|
|  | 143 | { | 
|---|
| [5996] | 144 | //   int argc = this->argc; | 
|---|
|  | 145 | //   char** argv = this->argv; | 
|---|
|  | 146 | // | 
|---|
|  | 147 | //   Orxonox *orx = Orxonox::getInstance(); | 
|---|
|  | 148 | // | 
|---|
|  | 149 | //   delete orx; | 
|---|
|  | 150 | // | 
|---|
|  | 151 | //   orx = Orxonox::getInstance(); | 
|---|
|  | 152 | // | 
|---|
|  | 153 | //   if((*orx).init(argc, argv) == -1) | 
|---|
|  | 154 | //   { | 
|---|
|  | 155 | //     PRINTF(1)("! Orxonox initialization failed\n"); | 
|---|
|  | 156 | //     return; | 
|---|
|  | 157 | //   } | 
|---|
|  | 158 | // | 
|---|
|  | 159 | //   printf("finished inizialisation\n"); | 
|---|
|  | 160 | //   orx->start(); | 
|---|
| [5207] | 161 | } | 
|---|
|  | 162 |  | 
|---|
| [4766] | 163 | /** | 
|---|
| [4836] | 164 | *  this finds the config file | 
|---|
| [4766] | 165 | * @returns the new config-fileName | 
|---|
|  | 166 | * Since the config file varies from user to user and since one may want to specify different config files | 
|---|
|  | 167 | * for certain occasions or platforms this function finds the right config file for every occasion and stores | 
|---|
|  | 168 | * it's path and name into configfilename | 
|---|
| [2190] | 169 | */ | 
|---|
| [4830] | 170 | const char* Orxonox::getConfigFile () | 
|---|
| [1850] | 171 | { | 
|---|
| [5424] | 172 | if (ResourceManager::isFile("orxonox.conf")) | 
|---|
|  | 173 | { | 
|---|
|  | 174 | this->configFileName = new char[strlen("orxonox.conf")+1]; | 
|---|
|  | 175 | strcpy(this->configFileName, "orxonox.conf"); | 
|---|
|  | 176 | } | 
|---|
|  | 177 | else | 
|---|
|  | 178 | this->configFileName = ResourceManager::homeDirCheck(DEFAULT_CONFIG_FILE); | 
|---|
| [4766] | 179 | this->iniParser = new IniParser(this->configFileName); | 
|---|
| [5424] | 180 | PRINTF(3)("Parsed Config File: '%s'\n", this->configFileName); | 
|---|
| [1803] | 181 | } | 
|---|
|  | 182 |  | 
|---|
| [2190] | 183 | /** | 
|---|
| [4833] | 184 | * initialize Orxonox with command line | 
|---|
|  | 185 | */ | 
|---|
| [5996] | 186 | int Orxonox::init (int argc, char** argv, const char* name, int port) | 
|---|
| [1803] | 187 | { | 
|---|
| [4135] | 188 | this->argc = argc; | 
|---|
|  | 189 | this->argv = argv; | 
|---|
| [4556] | 190 |  | 
|---|
| [5996] | 191 | this->serverName = name; | 
|---|
|  | 192 | this->port = port; | 
|---|
|  | 193 |  | 
|---|
| [4766] | 194 | // initialize the Config-file | 
|---|
| [4830] | 195 | this->getConfigFile(); | 
|---|
| [4766] | 196 |  | 
|---|
| [5788] | 197 | // windows must not write into stdout.txt and stderr.txt | 
|---|
| [6833] | 198 | /*#ifdef __WIN32__ | 
|---|
| [5788] | 199 | freopen( "CON", "w", stdout ); | 
|---|
|  | 200 | freopen( "CON", "w", stderr ); | 
|---|
| [6833] | 201 | #endif*/ | 
|---|
| [5788] | 202 |  | 
|---|
| [5996] | 203 | // initialize everything | 
|---|
| [6079] | 204 | SDL_Init(0); | 
|---|
| [5996] | 205 | if( initResources () == -1) | 
|---|
|  | 206 | return -1; | 
|---|
|  | 207 | if( initVideo() == -1) | 
|---|
|  | 208 | return -1; | 
|---|
|  | 209 | if( initSound() == -1) | 
|---|
|  | 210 | return -1; | 
|---|
|  | 211 | if( initInput() == -1) | 
|---|
|  | 212 | return -1; | 
|---|
|  | 213 | if( initNetworking () == -1) | 
|---|
|  | 214 | return -1; | 
|---|
|  | 215 | if( initMisc () == -1) | 
|---|
|  | 216 | return -1; | 
|---|
| [4556] | 217 |  | 
|---|
| [2636] | 218 | return 0; | 
|---|
| [1850] | 219 | } | 
|---|
| [1849] | 220 |  | 
|---|
| [5996] | 221 |  | 
|---|
| [2190] | 222 | /** | 
|---|
| [4833] | 223 | * initializes SDL and OpenGL | 
|---|
| [5996] | 224 | */ | 
|---|
| [4556] | 225 | int Orxonox::initVideo() | 
|---|
| [2190] | 226 | { | 
|---|
| [3611] | 227 | PRINTF(3)("> Initializing video\n"); | 
|---|
| [4556] | 228 |  | 
|---|
| [3610] | 229 | GraphicsEngine::getInstance(); | 
|---|
| [4556] | 230 |  | 
|---|
| [4784] | 231 | GraphicsEngine::getInstance()->initFromIniFile(this->iniParser); | 
|---|
| [4766] | 232 |  | 
|---|
| [5219] | 233 | char* iconName = ResourceManager::getFullName("pictures/fighter-top-32x32.bmp"); | 
|---|
| [5225] | 234 | if (iconName != NULL) | 
|---|
|  | 235 | { | 
|---|
|  | 236 | GraphicsEngine::getInstance()->setWindowName(PACKAGE_NAME " " PACKAGE_VERSION, iconName); | 
|---|
|  | 237 | delete[] iconName; | 
|---|
|  | 238 | } | 
|---|
| [2190] | 239 | return 0; | 
|---|
|  | 240 | } | 
|---|
| [1850] | 241 |  | 
|---|
| [5996] | 242 |  | 
|---|
| [2190] | 243 | /** | 
|---|
| [4833] | 244 | * initializes the sound engine | 
|---|
|  | 245 | */ | 
|---|
| [4556] | 246 | int Orxonox::initSound() | 
|---|
| [2190] | 247 | { | 
|---|
| [4504] | 248 | PRINT(3)("> Initializing sound\n"); | 
|---|
| [5225] | 249 | // SDL_InitSubSystem(SDL_INIT_AUDIO); | 
|---|
| [6840] | 250 | SoundEngine::getInstance(); | 
|---|
| [4985] | 251 |  | 
|---|
|  | 252 | SoundEngine::getInstance()->loadSettings(this->iniParser); | 
|---|
| [6840] | 253 | SoundEngine::getInstance()->initAudio(); | 
|---|
| [2636] | 254 | return 0; | 
|---|
| [2190] | 255 | } | 
|---|
| [1900] | 256 |  | 
|---|
| [3214] | 257 |  | 
|---|
| [2190] | 258 | /** | 
|---|
| [4833] | 259 | * initializes input functions | 
|---|
|  | 260 | */ | 
|---|
| [4556] | 261 | int Orxonox::initInput() | 
|---|
| [2190] | 262 | { | 
|---|
| [4766] | 263 | PRINT(3)("> Initializing input\n"); | 
|---|
|  | 264 |  | 
|---|
| [4866] | 265 | EventHandler::getInstance()->init(this->iniParser); | 
|---|
| [4833] | 266 | EventHandler::getInstance()->subscribe(GraphicsEngine::getInstance(), ES_ALL, EV_VIDEO_RESIZE); | 
|---|
| [4556] | 267 |  | 
|---|
| [2636] | 268 | return 0; | 
|---|
| [1803] | 269 | } | 
|---|
|  | 270 |  | 
|---|
| [3214] | 271 |  | 
|---|
| [2190] | 272 | /** | 
|---|
| [4833] | 273 | * initializes network system | 
|---|
|  | 274 | */ | 
|---|
| [4556] | 275 | int Orxonox::initNetworking() | 
|---|
| [1897] | 276 | { | 
|---|
| [4766] | 277 | PRINT(3)("> Initializing networking\n"); | 
|---|
|  | 278 |  | 
|---|
| [5996] | 279 | if( this->serverName != NULL) // we are a client | 
|---|
| [6695] | 280 | { | 
|---|
|  | 281 | State::setOnline(true); | 
|---|
| [5996] | 282 | NetworkManager::getInstance()->establishConnection(this->serverName, port); | 
|---|
| [6695] | 283 | } | 
|---|
| [6139] | 284 | else if( this->port > 0) {    // we are a server | 
|---|
| [6695] | 285 | State::setOnline(true); | 
|---|
| [5996] | 286 | NetworkManager::getInstance()->createServer(port); | 
|---|
| [6139] | 287 | } | 
|---|
| [2636] | 288 | return 0; | 
|---|
| [1897] | 289 | } | 
|---|
|  | 290 |  | 
|---|
| [7167] | 291 | #include "dynamic_loader.h" | 
|---|
| [7169] | 292 | #include <dlfcn.h> | 
|---|
| [3214] | 293 |  | 
|---|
| [2190] | 294 | /** | 
|---|
| [4833] | 295 | * initializes and loads resource files | 
|---|
| [4766] | 296 | */ | 
|---|
| [4833] | 297 | int Orxonox::initResources() | 
|---|
| [1858] | 298 | { | 
|---|
| [4766] | 299 | PRINTF(3)("> Initializing resources\n"); | 
|---|
| [4091] | 300 |  | 
|---|
| [4766] | 301 | PRINT(3)("initializing ResourceManager\n"); | 
|---|
|  | 302 |  | 
|---|
| [5488] | 303 | // init the resource manager | 
|---|
| [5014] | 304 | const char* dataPath; | 
|---|
|  | 305 | if ((dataPath = this->iniParser->getVar(CONFIG_NAME_DATADIR, CONFIG_SECTION_DATA))!= NULL) | 
|---|
| [4766] | 306 | { | 
|---|
| [5480] | 307 | if (!ResourceManager::getInstance()->setDataDir(dataPath) && | 
|---|
| [5996] | 308 | !ResourceManager::getInstance()->verifyDataDir(DEFAULT_DATA_DIR_CHECKFILE)) | 
|---|
| [4766] | 309 | { | 
|---|
| [5423] | 310 | PRINTF(1)("Data Could not be located in %s\n", dataPath); | 
|---|
| [4766] | 311 | } | 
|---|
|  | 312 | } | 
|---|
| [4556] | 313 |  | 
|---|
| [5480] | 314 | if (!ResourceManager::getInstance()->verifyDataDir(DEFAULT_DATA_DIR_CHECKFILE)) | 
|---|
| [4766] | 315 | { | 
|---|
| [5510] | 316 | PRINTF(1)("The DataDirectory %s could not be verified\n\nh" \ | 
|---|
|  | 317 | "!!!  Please Change in File %s Section %s Entry %s to a suitable value !!!\n", | 
|---|
| [4822] | 318 | ResourceManager::getInstance()->getDataDir(), | 
|---|
| [5424] | 319 | this->configFileName, | 
|---|
| [4766] | 320 | CONFIG_SECTION_DATA, | 
|---|
| [5510] | 321 | CONFIG_NAME_DATADIR ); | 
|---|
| [5479] | 322 | Gui* gui = new Gui(argc, argv); | 
|---|
|  | 323 | gui->startGui(); | 
|---|
|  | 324 | delete gui; | 
|---|
| [4766] | 325 | exit(-1); | 
|---|
|  | 326 | } | 
|---|
| [5996] | 327 | //! @todo this is a hack and should be loadable | 
|---|
| [5335] | 328 | char* imageDir = ResourceManager::getInstance()->getFullName("maps"); | 
|---|
| [5216] | 329 | ResourceManager::getInstance()->addImageDir(imageDir); | 
|---|
|  | 330 | delete[] imageDir; | 
|---|
| [7067] | 331 | imageDir = ResourceManager::getInstance()->getFullName("pictures"); | 
|---|
|  | 332 | ResourceManager::getInstance()->addImageDir(imageDir); | 
|---|
|  | 333 | delete[] imageDir; | 
|---|
| [4009] | 334 |  | 
|---|
| [7169] | 335 | //   void* handle; | 
|---|
|  | 336 | //   handle = dlopen("./src/world_entities/.libs/libORXground_turret.so", RTLD_NOW); | 
|---|
|  | 337 | //   if(handle == NULL) | 
|---|
|  | 338 | //   { | 
|---|
|  | 339 | //     PRINTF(1)("unable to load %s\n", dlerror()); | 
|---|
|  | 340 | // | 
|---|
|  | 341 | //     return false; | 
|---|
|  | 342 | //   } | 
|---|
| [7171] | 343 | DynamicLoader::loadDyLib("src/world_entities/.libs/libORXground_turret.so"); | 
|---|
| [7167] | 344 |  | 
|---|
| [5488] | 345 | // start the collision detection engine | 
|---|
| [4766] | 346 | CDEngine::getInstance(); | 
|---|
| [5074] | 347 | return 0; | 
|---|
|  | 348 | } | 
|---|
|  | 349 |  | 
|---|
|  | 350 | /** | 
|---|
|  | 351 | * initializes miscelaneous features | 
|---|
|  | 352 | * @return -1 on failure | 
|---|
|  | 353 | */ | 
|---|
|  | 354 | int Orxonox::initMisc() | 
|---|
|  | 355 | { | 
|---|
| [5183] | 356 | ShellBuffer::getInstance(); | 
|---|
| [4766] | 357 | return 0; | 
|---|
| [1858] | 358 | } | 
|---|
| [1849] | 359 |  | 
|---|
| [2190] | 360 | /** | 
|---|
| [4836] | 361 | *  starts the orxonox game or menu | 
|---|
| [4833] | 362 | * here is the central orxonox state manager. There are currently two states | 
|---|
|  | 363 | * - menu | 
|---|
|  | 364 | * - game-play | 
|---|
|  | 365 | * both states manage their states themselfs again. | 
|---|
| [2190] | 366 | */ | 
|---|
| [2636] | 367 | void Orxonox::start() | 
|---|
|  | 368 | { | 
|---|
| [4556] | 369 |  | 
|---|
| [2636] | 370 | this->gameLoader = GameLoader::getInstance(); | 
|---|
| [5996] | 371 |  | 
|---|
| [6139] | 372 | if( this->port != -1) | 
|---|
|  | 373 | this->gameLoader->loadNetworkCampaign("worlds/DefaultNetworkCampaign.oxc"); | 
|---|
| [5996] | 374 | else | 
|---|
| [6139] | 375 | this->gameLoader->loadCampaign("worlds/DefaultCampaign.oxc");                       /* start orxonox in single player mode */ | 
|---|
| [5996] | 376 |  | 
|---|
| [4010] | 377 | //  this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0); | 
|---|
| [2636] | 378 | this->gameLoader->init(); | 
|---|
|  | 379 | this->gameLoader->start(); | 
|---|
|  | 380 | } | 
|---|
|  | 381 |  | 
|---|
| [3214] | 382 |  | 
|---|
| [2636] | 383 | /** | 
|---|
| [4833] | 384 | * handles sprecial events from localinput | 
|---|
|  | 385 | * @param event: an event not handled by the CommandNode | 
|---|
|  | 386 | */ | 
|---|
| [4817] | 387 | // void Orxonox::graphicsHandler(SDL_Event* event) | 
|---|
|  | 388 | // { | 
|---|
|  | 389 | //   // Handle special events such as reshape, quit, focus changes | 
|---|
|  | 390 | //   switch (event->type) | 
|---|
|  | 391 | //     { | 
|---|
|  | 392 | //     case SDL_VIDEORESIZE: | 
|---|
|  | 393 | //       GraphicsEngine* tmpGEngine = GraphicsEngine::getInstance(); | 
|---|
|  | 394 | //       tmpGEngine->resolutionChanged(event->resize); | 
|---|
|  | 395 | //       break; | 
|---|
|  | 396 | //     } | 
|---|
|  | 397 | // } | 
|---|
| [1875] | 398 |  | 
|---|
| [4556] | 399 |  | 
|---|
| [4408] | 400 |  | 
|---|
| [1803] | 401 |  | 
|---|
| [3214] | 402 |  | 
|---|
| [4782] | 403 |  | 
|---|
| [4059] | 404 | bool showGui = false; | 
|---|
| [3648] | 405 |  | 
|---|
| [4766] | 406 |  | 
|---|
|  | 407 |  | 
|---|
|  | 408 | /********************************** | 
|---|
|  | 409 | *** ORXONOX MAIN STARTING POINT *** | 
|---|
|  | 410 | **********************************/ | 
|---|
| [3449] | 411 | /** | 
|---|
| [4833] | 412 | * | 
|---|
| [4836] | 413 | *  main function | 
|---|
| [4833] | 414 | * | 
|---|
|  | 415 | * here the journey begins | 
|---|
| [3449] | 416 | */ | 
|---|
| [4556] | 417 | int main(int argc, char** argv) | 
|---|
|  | 418 | { | 
|---|
| [3648] | 419 | int i; | 
|---|
| [4032] | 420 | for(i = 1; i < argc; ++i) | 
|---|
| [5996] | 421 | { | 
|---|
|  | 422 | if(     !strcmp( "--help", argv[i])     || !strcmp("-h", argv[i])) | 
|---|
|  | 423 | return showHelp(argc, argv); | 
|---|
|  | 424 | else if(!strcmp( "--gui", argv[i])      || !strcmp("-g", argv[i])) | 
|---|
|  | 425 | showGui = true; | 
|---|
|  | 426 | else if(!strcmp( "--client", argv[i])   || !strcmp("-c", argv[i])) | 
|---|
|  | 427 | return startNetworkOrxonox(argc, argv); | 
|---|
|  | 428 | else if(!strcmp( "--server", argv[i])   || !strcmp("-s", argv[i])) | 
|---|
|  | 429 | return startNetworkOrxonox(argc, argv); | 
|---|
| [6424] | 430 | else if(!strcmp( "--license", argv[i])  || !strcmp("-l", argv[i])) | 
|---|
| [5996] | 431 | return PRINT(0)(ORXONOX_LICENSE_SHORT); | 
|---|
|  | 432 | } | 
|---|
| [3648] | 433 |  | 
|---|
| [5996] | 434 | return startOrxonox(argc, argv, NULL, -1); | 
|---|
| [3648] | 435 | } | 
|---|
|  | 436 |  | 
|---|
|  | 437 |  | 
|---|
|  | 438 |  | 
|---|
| [5996] | 439 | int showHelp(int argc, char** argv) | 
|---|
| [3648] | 440 | { | 
|---|
| [5996] | 441 | PRINT(0)("Orxonox Version %s\n", PACKAGE_VERSION); | 
|---|
|  | 442 | PRINT(0)(" Starts Orxonox - The most furious 3D Action Game :)\n"); | 
|---|
|  | 443 | PRINT(0)("\n"); | 
|---|
|  | 444 | PRINT(0)("Common options:\n"); | 
|---|
|  | 445 | PRINT(0)(" -g, --gui                        starts the orxonox with the configuration GUI \n"); | 
|---|
|  | 446 | PRINT(0)(" -h, --help                       shows this help\n"); | 
|---|
|  | 447 | PRINT(0)("\n"); | 
|---|
|  | 448 | PRINT(0)("Network options:\n"); | 
|---|
|  | 449 | PRINT(0)(" -s, --server [port]              starts Orxonox and listens on the [port] for players\n"); | 
|---|
|  | 450 | PRINT(0)(" -c, --client [hostname] [port]   starts Orxonox as a Client\n"); | 
|---|
|  | 451 | PRINT(0)(" -c, --client [ip address] [port] starts Orxonox as a Client\n"); | 
|---|
|  | 452 | PRINT(0)("\n"); | 
|---|
|  | 453 | PRINT(0)("Other options:\n"); | 
|---|
|  | 454 | PRINT(0)("     --license     prints the licence and exit\n\n"); | 
|---|
|  | 455 | PRINT(0)("\n"); | 
|---|
|  | 456 |  | 
|---|
|  | 457 | //   { | 
|---|
|  | 458 | //     Gui* gui = new Gui(argc, argv); | 
|---|
|  | 459 | //     gui->printHelp(); | 
|---|
|  | 460 | //     delete gui; | 
|---|
|  | 461 | //   } | 
|---|
|  | 462 | } | 
|---|
|  | 463 |  | 
|---|
|  | 464 |  | 
|---|
|  | 465 |  | 
|---|
|  | 466 |  | 
|---|
|  | 467 | /** | 
|---|
|  | 468 | * starts orxonox in network mode | 
|---|
|  | 469 | * @param argc parameters count given to orxonox | 
|---|
|  | 470 | * @param argv parameters given to orxonox | 
|---|
|  | 471 | */ | 
|---|
|  | 472 | int startNetworkOrxonox(int argc, char** argv) | 
|---|
|  | 473 | { | 
|---|
|  | 474 |  | 
|---|
|  | 475 | int i; | 
|---|
|  | 476 | for(i = 0; i < argc; ++i ) | 
|---|
| [4132] | 477 | { | 
|---|
| [5996] | 478 | if( !strcmp( "--client", argv[i]) || !strcmp("-c", argv[i])) | 
|---|
|  | 479 | { | 
|---|
|  | 480 | if( argc <= (i+2)) | 
|---|
|  | 481 | { | 
|---|
|  | 482 | printf(" Wrong arguments try following notations:\n"); | 
|---|
|  | 483 | printf("   --client [server ip address] [port number]\n"); | 
|---|
|  | 484 | printf("   --client [dns name] [port number]\n"); | 
|---|
|  | 485 | return 0; | 
|---|
|  | 486 | } | 
|---|
|  | 487 |  | 
|---|
|  | 488 | const char* name = argv[i+1]; | 
|---|
|  | 489 | int port = atoi(argv[i+2]); | 
|---|
|  | 490 | printf("Starting Orxonox as client: connecting to %s, on port %i\n", name, port); | 
|---|
|  | 491 |  | 
|---|
|  | 492 | startOrxonox(argc, argv, name, port); | 
|---|
|  | 493 | } | 
|---|
|  | 494 | else if( !strcmp( "--server", argv[i]) || !strcmp("-s", argv[i])) | 
|---|
|  | 495 | { | 
|---|
|  | 496 | if( argc <= (i+1)) | 
|---|
|  | 497 | { | 
|---|
|  | 498 | printf(" Wrong arguments try following notations:\n"); | 
|---|
|  | 499 | printf("   --server [port number]\n"); | 
|---|
|  | 500 | return 0; | 
|---|
|  | 501 | } | 
|---|
|  | 502 |  | 
|---|
|  | 503 | int port = atoi(argv[i+1]); | 
|---|
|  | 504 | printf("Starting Orxonox as server, listening on port %i\n", port); | 
|---|
|  | 505 |  | 
|---|
|  | 506 | startOrxonox(argc, argv, NULL, port); | 
|---|
|  | 507 | } | 
|---|
| [4132] | 508 | } | 
|---|
| [3648] | 509 | } | 
|---|
|  | 510 |  | 
|---|
| [3649] | 511 |  | 
|---|
| [4766] | 512 |  | 
|---|
|  | 513 | /** | 
|---|
|  | 514 | * starts orxonox | 
|---|
|  | 515 | * @param argc parameters count given to orxonox | 
|---|
|  | 516 | * @param argv parameters given to orxonox | 
|---|
|  | 517 | */ | 
|---|
| [5996] | 518 | int startOrxonox(int argc, char** argv, const char* name, int port) | 
|---|
| [3648] | 519 | { | 
|---|
| [4830] | 520 | // checking for existence of the configuration-files, or if the lock file is still used | 
|---|
| [5424] | 521 | if (showGui || (!ResourceManager::isFile("./orxonox.conf") && | 
|---|
| [5996] | 522 | !ResourceManager::isFile(DEFAULT_CONFIG_FILE)) | 
|---|
| [5424] | 523 | #if DEBUG < 3 // developers do not need to see the GUI, when orxonox fails | 
|---|
| [5996] | 524 | || ResourceManager::isFile(DEFAULT_LOCK_FILE) | 
|---|
| [4981] | 525 | #endif | 
|---|
|  | 526 | ) | 
|---|
| [5996] | 527 | { | 
|---|
|  | 528 | if (ResourceManager::isFile(DEFAULT_LOCK_FILE)) | 
|---|
|  | 529 | ResourceManager::deleteFile(DEFAULT_LOCK_FILE); | 
|---|
| [4556] | 530 |  | 
|---|
| [5996] | 531 | // starting the GUI | 
|---|
|  | 532 | Gui* gui = new Gui(argc, argv); | 
|---|
|  | 533 | gui->startGui(); | 
|---|
| [4132] | 534 |  | 
|---|
| [5996] | 535 | if (! gui->startOrxonox) | 
|---|
|  | 536 | return 0; | 
|---|
| [4556] | 537 |  | 
|---|
| [5996] | 538 | delete gui; | 
|---|
|  | 539 | } | 
|---|
| [4556] | 540 |  | 
|---|
| [4032] | 541 | PRINT(0)(">>> Starting Orxonox <<<\n"); | 
|---|
| [4033] | 542 |  | 
|---|
| [4766] | 543 | ResourceManager::touchFile(DEFAULT_LOCK_FILE); | 
|---|
| [4033] | 544 |  | 
|---|
| [1850] | 545 | Orxonox *orx = Orxonox::getInstance(); | 
|---|
| [4556] | 546 |  | 
|---|
| [5996] | 547 | if( orx->init(argc, argv, name, port) == -1) | 
|---|
|  | 548 | { | 
|---|
|  | 549 | PRINTF(1)("! Orxonox initialization failed\n"); | 
|---|
|  | 550 | return -1; | 
|---|
|  | 551 | } | 
|---|
| [4556] | 552 |  | 
|---|
| [5996] | 553 | printf("finished inizialisation\n"); | 
|---|
| [2636] | 554 | orx->start(); | 
|---|
| [4556] | 555 |  | 
|---|
| [3676] | 556 | delete orx; | 
|---|
| [4033] | 557 | ResourceManager::deleteFile("~/.orxonox/orxonox.lock"); | 
|---|
| [1803] | 558 | } | 
|---|