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