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