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