[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 | |
---|
[8145] | 32 | #include "gui/qt/qt_gui.h" |
---|
[8749] | 33 | #include "gui/qt/qt_gui_datadir_fallback.h" |
---|
[4054] | 34 | |
---|
[5944] | 35 | #include "parser/ini_parser/ini_parser.h" |
---|
[7193] | 36 | #include "util/loading/game_loader.h" |
---|
[7440] | 37 | #include "util/signal_handler.h" |
---|
[4786] | 38 | |
---|
| 39 | //ENGINES |
---|
[3610] | 40 | #include "graphics_engine.h" |
---|
[4504] | 41 | #include "sound_engine.h" |
---|
[7193] | 42 | #include "util/loading/resource_manager.h" |
---|
[9869] | 43 | |
---|
[4786] | 44 | #include "cd_engine.h" |
---|
| 45 | #include "event_handler.h" |
---|
| 46 | |
---|
[9869] | 47 | #include "loading/fast_factory.h" |
---|
[4980] | 48 | |
---|
[9869] | 49 | #include "subprojects/benchmark.h" |
---|
[3610] | 50 | |
---|
[5641] | 51 | #include "shell_command_class.h" |
---|
[5165] | 52 | #include "shell_command.h" |
---|
[4748] | 53 | |
---|
[5996] | 54 | #include "network_manager.h" |
---|
[9406] | 55 | #include "shared_network_data.h" |
---|
[5996] | 56 | |
---|
[6695] | 57 | #include "state.h" |
---|
[7256] | 58 | #include "lib/parser/preferences/cmd_line_prefs_reader.h" |
---|
| 59 | #include "lib/parser/preferences/ini_file_prefs_reader.h" |
---|
[2190] | 60 | #include <string.h> |
---|
[4032] | 61 | |
---|
[7711] | 62 | int verbose = 5; |
---|
[2036] | 63 | |
---|
[1803] | 64 | |
---|
[9406] | 65 | |
---|
[5207] | 66 | SHELL_COMMAND(restart, Orxonox, restart); |
---|
| 67 | |
---|
[7258] | 68 | REGISTER_ARG_FLAG( l, license, "misc", "showLicenseAndExit", "Prints the license and exit", "1" ); |
---|
| 69 | REGISTER_ARG_FLAG( c, client, "game", "gameType", "Connect to Server (-H)", "multiplayer_client" ); |
---|
[9406] | 70 | REGISTER_ARG_FLAG( s, server, "game", "gameType", "Start Orxonox as Game Server", "multiplayer_master_server" ); |
---|
| 71 | REGISTER_ARG_FLAG( x, proxy, "game", "gameType", "Start Orxonox as Proxy Server", "multiplayer_proxy_server" ); |
---|
[7258] | 72 | REGISTER_ARG_ARG( H, host, "game", "host", "Host to connect to", "host"); |
---|
| 73 | REGISTER_ARG_ARG( p, port, "game", "port", "Port to use", "port" ); |
---|
| 74 | REGISTER_ARG_FLAG( g, gui, "game", "showGui", "starts the orxonox with the configuration GUI", "1"); |
---|
[7256] | 75 | |
---|
[7258] | 76 | REGISTER_ARG_FLAG( f, fullscreen, "video", "Fullscreen-mode", "start Orxonox in fullscreen mode", "1"); |
---|
| 77 | REGISTER_ARG_FLAG( w, windowed, "video", "Fullscreen-mode", "start Orxonox in windowed mode", "0"); |
---|
[9406] | 78 | REGISTER_ARG_ARG( r, resolution, "video", "Resolution", "sets resolution / window size", "res"); |
---|
| 79 | REGISTER_ARG_FLAG( d, dedicated, "video", "Norender-mode", "the scene is not rendered", "1" ); |
---|
[7258] | 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 | |
---|
[7440] | 87 | #ifndef __WIN32__ |
---|
| 88 | REGISTER_ARG_FLAG( _, write_bt_to_file, "misc", "bt-to-file", "Write backtrace to file", "1"); |
---|
[10114] | 89 | REGISTER_ARG_FLAG( _, dont_catch_signals, "misc", "bt-to-file", "Write backtrace to file", "0"); |
---|
[7440] | 90 | #endif |
---|
| 91 | |
---|
[7954] | 92 | REGISTER_ARG_ARG( t, telnetport, "network","telnetport", "Port to use for network debug output", "port" ); |
---|
| 93 | REGISTER_ARG_ARG( _, write_dict, "compression", "writedict", "write packets to DATA/dicts/newdict", "numBytes" ); |
---|
| 94 | |
---|
[9869] | 95 | ObjectListDefinition(Orxonox); |
---|
[7954] | 96 | |
---|
[2190] | 97 | /** |
---|
[4836] | 98 | * create a new Orxonox |
---|
[4135] | 99 | |
---|
| 100 | In this funcitons only global values are set. The game will not be started here. |
---|
[2190] | 101 | */ |
---|
| 102 | Orxonox::Orxonox () |
---|
[1872] | 103 | { |
---|
[9869] | 104 | this->registerObject(this, Orxonox::_objectList); |
---|
[4766] | 105 | this->setName("orxonox-main"); |
---|
[4059] | 106 | |
---|
[4135] | 107 | this->argc = 0; |
---|
| 108 | this->argv = NULL; |
---|
[4782] | 109 | |
---|
[5996] | 110 | /* this way, there is no network enabled: */ |
---|
[7256] | 111 | this->serverName = ""; |
---|
[5996] | 112 | this->port = -1; |
---|
| 113 | |
---|
[7221] | 114 | this->configFileName = ""; |
---|
[1872] | 115 | } |
---|
[1803] | 116 | |
---|
[2190] | 117 | /** |
---|
[4836] | 118 | * remove Orxonox from memory |
---|
[2190] | 119 | */ |
---|
[4556] | 120 | Orxonox::~Orxonox () |
---|
[2190] | 121 | { |
---|
[5285] | 122 | // game-specific |
---|
[4815] | 123 | delete GameLoader::getInstance(); |
---|
[5285] | 124 | |
---|
| 125 | // class-less services/factories |
---|
[4980] | 126 | FastFactory::deleteAll(); |
---|
[7374] | 127 | OrxShell::ShellCommandClass::unregisterAllCommands(); |
---|
[5332] | 128 | |
---|
[7427] | 129 | // handlers |
---|
[9869] | 130 | Resources::ResourceManager::deleteInstance(); // deletes the Resource Manager |
---|
[7427] | 131 | |
---|
[5285] | 132 | // engines |
---|
| 133 | delete CDEngine::getInstance(); |
---|
[7460] | 134 | delete OrxSound::SoundEngine::getInstance(); |
---|
[5285] | 135 | delete GraphicsEngine::getInstance(); // deleting the Graphics |
---|
[4817] | 136 | delete EventHandler::getInstance(); |
---|
[5285] | 137 | |
---|
[9869] | 138 | Resources::ResourceManager::deleteInstance(); |
---|
[5285] | 139 | // output-buffer |
---|
[9869] | 140 | delete DebugBuffer::getInstance(); |
---|
[5285] | 141 | |
---|
[5225] | 142 | SDL_QuitSubSystem(SDL_INIT_TIMER); |
---|
[9406] | 143 | |
---|
[9869] | 144 | |
---|
| 145 | ObjectListBase::debugAll(1); |
---|
| 146 | |
---|
[9235] | 147 | Preferences::getInstance()->save(); |
---|
[1850] | 148 | |
---|
[4833] | 149 | PRINT(3) |
---|
[5996] | 150 | ( |
---|
| 151 | "===================================================\n" \ |
---|
| 152 | "Thanks for playing orxonox.\n" \ |
---|
| 153 | "visit: http://www.orxonox.net for new versions.\n" \ |
---|
| 154 | "===================================================\n" \ |
---|
| 155 | ORXONOX_LICENSE_SHORT |
---|
| 156 | ); |
---|
[1872] | 157 | |
---|
[4766] | 158 | Orxonox::singletonRef = NULL; |
---|
[1850] | 159 | } |
---|
| 160 | |
---|
[2190] | 161 | /** |
---|
[4836] | 162 | * this is a singleton class to prevent duplicates |
---|
[4766] | 163 | */ |
---|
| 164 | Orxonox* Orxonox::singletonRef = NULL; |
---|
[4556] | 165 | |
---|
[5207] | 166 | // DANGEROUS |
---|
| 167 | void Orxonox::restart() |
---|
| 168 | { |
---|
[5996] | 169 | // int argc = this->argc; |
---|
| 170 | // char** argv = this->argv; |
---|
| 171 | // |
---|
| 172 | // Orxonox *orx = Orxonox::getInstance(); |
---|
| 173 | // |
---|
| 174 | // delete orx; |
---|
| 175 | // |
---|
| 176 | // orx = Orxonox::getInstance(); |
---|
| 177 | // |
---|
| 178 | // if((*orx).init(argc, argv) == -1) |
---|
| 179 | // { |
---|
| 180 | // PRINTF(1)("! Orxonox initialization failed\n"); |
---|
| 181 | // return; |
---|
| 182 | // } |
---|
| 183 | // |
---|
| 184 | // printf("finished inizialisation\n"); |
---|
| 185 | // orx->start(); |
---|
[5207] | 186 | } |
---|
| 187 | |
---|
[4766] | 188 | /** |
---|
[7221] | 189 | * @brief this finds the config file |
---|
[4766] | 190 | * @returns the new config-fileName |
---|
| 191 | * Since the config file varies from user to user and since one may want to specify different config files |
---|
| 192 | * for certain occasions or platforms this function finds the right config file for every occasion and stores |
---|
| 193 | * it's path and name into configfilename |
---|
[2190] | 194 | */ |
---|
[7221] | 195 | const std::string& Orxonox::getConfigFile () |
---|
[1850] | 196 | { |
---|
[7661] | 197 | File orxConfFile("orxonox.conf"); |
---|
| 198 | if (orxConfFile.isFile()) |
---|
[5424] | 199 | { |
---|
[7221] | 200 | this->configFileName = "orxonox.conf"; |
---|
[5424] | 201 | } |
---|
| 202 | else |
---|
[7661] | 203 | this->configFileName = File(DEFAULT_CONFIG_FILE).name(); |
---|
[7256] | 204 | |
---|
[7677] | 205 | PRINTF(3)("Parsed Config File: '%s'\n", this->configFileName.c_str()); |
---|
[8316] | 206 | return this->configFileName; |
---|
[1803] | 207 | } |
---|
| 208 | |
---|
[2190] | 209 | /** |
---|
[4833] | 210 | * initialize Orxonox with command line |
---|
| 211 | */ |
---|
[7256] | 212 | int Orxonox::init (int argc, char** argv, const std::string & name, int port) |
---|
[1803] | 213 | { |
---|
[4135] | 214 | this->argc = argc; |
---|
| 215 | this->argv = argv; |
---|
[4556] | 216 | |
---|
[5996] | 217 | this->serverName = name; |
---|
| 218 | this->port = port; |
---|
| 219 | |
---|
[4766] | 220 | // initialize the Config-file |
---|
[4830] | 221 | this->getConfigFile(); |
---|
[4766] | 222 | |
---|
[5788] | 223 | // windows must not write into stdout.txt and stderr.txt |
---|
[6833] | 224 | /*#ifdef __WIN32__ |
---|
[5788] | 225 | freopen( "CON", "w", stdout ); |
---|
| 226 | freopen( "CON", "w", stderr ); |
---|
[6833] | 227 | #endif*/ |
---|
[5788] | 228 | |
---|
[5996] | 229 | // initialize everything |
---|
[6079] | 230 | SDL_Init(0); |
---|
[8749] | 231 | if( initVideo() == -1) |
---|
| 232 | return -1; |
---|
[5996] | 233 | if( initResources () == -1) |
---|
| 234 | return -1; |
---|
| 235 | if( initSound() == -1) |
---|
| 236 | return -1; |
---|
| 237 | if( initInput() == -1) |
---|
| 238 | return -1; |
---|
| 239 | if( initNetworking () == -1) |
---|
| 240 | return -1; |
---|
| 241 | if( initMisc () == -1) |
---|
| 242 | return -1; |
---|
[4556] | 243 | |
---|
[2636] | 244 | return 0; |
---|
[1850] | 245 | } |
---|
[1849] | 246 | |
---|
[5996] | 247 | |
---|
[2190] | 248 | /** |
---|
[4833] | 249 | * initializes SDL and OpenGL |
---|
[5996] | 250 | */ |
---|
[4556] | 251 | int Orxonox::initVideo() |
---|
[2190] | 252 | { |
---|
[3611] | 253 | PRINTF(3)("> Initializing video\n"); |
---|
[4556] | 254 | |
---|
[3610] | 255 | GraphicsEngine::getInstance(); |
---|
[4556] | 256 | |
---|
[7256] | 257 | GraphicsEngine::getInstance()->initFromPreferences(); |
---|
[4766] | 258 | |
---|
[9869] | 259 | std::string iconName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath("pictures/fighter-top-32x32.bmp"); |
---|
[7221] | 260 | if (!iconName.empty()) |
---|
[5225] | 261 | { |
---|
| 262 | GraphicsEngine::getInstance()->setWindowName(PACKAGE_NAME " " PACKAGE_VERSION, iconName); |
---|
| 263 | } |
---|
[2190] | 264 | return 0; |
---|
| 265 | } |
---|
[1850] | 266 | |
---|
[5996] | 267 | |
---|
[2190] | 268 | /** |
---|
[4833] | 269 | * initializes the sound engine |
---|
| 270 | */ |
---|
[4556] | 271 | int Orxonox::initSound() |
---|
[2190] | 272 | { |
---|
[4504] | 273 | PRINT(3)("> Initializing sound\n"); |
---|
[5225] | 274 | // SDL_InitSubSystem(SDL_INIT_AUDIO); |
---|
[7460] | 275 | OrxSound::SoundEngine::getInstance(); |
---|
[4985] | 276 | |
---|
[7460] | 277 | OrxSound::SoundEngine::getInstance()->loadSettings(); |
---|
| 278 | OrxSound::SoundEngine::getInstance()->initAudio(); |
---|
[2636] | 279 | return 0; |
---|
[2190] | 280 | } |
---|
[1900] | 281 | |
---|
[3214] | 282 | |
---|
[2190] | 283 | /** |
---|
[4833] | 284 | * initializes input functions |
---|
| 285 | */ |
---|
[4556] | 286 | int Orxonox::initInput() |
---|
[2190] | 287 | { |
---|
[4766] | 288 | PRINT(3)("> Initializing input\n"); |
---|
| 289 | |
---|
[7256] | 290 | EventHandler::getInstance()->init(); |
---|
[4833] | 291 | EventHandler::getInstance()->subscribe(GraphicsEngine::getInstance(), ES_ALL, EV_VIDEO_RESIZE); |
---|
[4556] | 292 | |
---|
[2636] | 293 | return 0; |
---|
[1803] | 294 | } |
---|
| 295 | |
---|
[3214] | 296 | |
---|
[2190] | 297 | /** |
---|
[4833] | 298 | * initializes network system |
---|
| 299 | */ |
---|
[4556] | 300 | int Orxonox::initNetworking() |
---|
[1897] | 301 | { |
---|
[4766] | 302 | PRINT(3)("> Initializing networking\n"); |
---|
[9406] | 303 | std::string gameType = Preferences::getInstance()->getString( "game", "gameType", "" ); |
---|
[4766] | 304 | |
---|
[9406] | 305 | if( gameType == "multiplayer_client") |
---|
| 306 | { // we are a client |
---|
[6695] | 307 | State::setOnline(true); |
---|
[9406] | 308 | SharedNetworkData::getInstance()->setNodeType(NET_CLIENT); |
---|
| 309 | NetworkManager::getInstance()->createClient(this->serverName, port); |
---|
[6695] | 310 | } |
---|
[9406] | 311 | else if( gameType == "multiplayer_master_server") |
---|
| 312 | { // we are a master server |
---|
[6695] | 313 | State::setOnline(true); |
---|
[9406] | 314 | SharedNetworkData::getInstance()->setNodeType(NET_MASTER_SERVER); |
---|
| 315 | |
---|
| 316 | NetworkManager::getInstance()->createMasterServer(port); |
---|
[6139] | 317 | } |
---|
[9406] | 318 | else if( gameType == "multiplayer_proxy_server") |
---|
| 319 | { // we are a proxy server |
---|
| 320 | State::setOnline(true); |
---|
| 321 | SharedNetworkData::getInstance()->setNodeType(NET_PROXY_SERVER_ACTIVE); |
---|
| 322 | NetworkManager::getInstance()->createProxyServer(port); |
---|
| 323 | } |
---|
| 324 | |
---|
[2636] | 325 | return 0; |
---|
[9406] | 326 | |
---|
[1897] | 327 | } |
---|
| 328 | |
---|
[7355] | 329 | //#include "util/loading/dynamic_loader.h" |
---|
[2190] | 330 | /** |
---|
[4833] | 331 | * initializes and loads resource files |
---|
[4766] | 332 | */ |
---|
[4833] | 333 | int Orxonox::initResources() |
---|
[1858] | 334 | { |
---|
[4766] | 335 | PRINTF(3)("> Initializing resources\n"); |
---|
[4091] | 336 | |
---|
[4766] | 337 | PRINT(3)("initializing ResourceManager\n"); |
---|
| 338 | |
---|
[5488] | 339 | // init the resource manager |
---|
[9880] | 340 | std::string dataPath = Preferences::getInstance()->getString(CONFIG_SECTION_GENERAL, CONFIG_NAME_DATADIR, ""); |
---|
| 341 | if (dataPath!= "") |
---|
[4766] | 342 | { |
---|
[9869] | 343 | Resources::ResourceManager::getInstance()->setMainGlobalPath(dataPath) ; |
---|
| 344 | if(!Resources::ResourceManager::getInstance()->checkFileInMainPath(File(DEFAULT_DATA_DIR_CHECKFILE))) |
---|
[4766] | 345 | { |
---|
[7221] | 346 | PRINTF(1)("Data Could not be located in %s\n", dataPath.c_str()); |
---|
[4766] | 347 | } |
---|
| 348 | } |
---|
[9869] | 349 | while (!Resources::ResourceManager::getInstance()->checkFileInMainPath(File(DEFAULT_DATA_DIR_CHECKFILE))) |
---|
[4766] | 350 | { |
---|
[8749] | 351 | |
---|
[5510] | 352 | PRINTF(1)("The DataDirectory %s could not be verified\n\nh" \ |
---|
| 353 | "!!! Please Change in File %s Section %s Entry %s to a suitable value !!!\n", |
---|
[9869] | 354 | Resources::ResourceManager::getInstance()->mainGlobalPath().name().c_str(), |
---|
[7714] | 355 | this->configFileName.c_str(), |
---|
[7661] | 356 | CONFIG_SECTION_GENERAL, |
---|
[5510] | 357 | CONFIG_NAME_DATADIR ); |
---|
[8749] | 358 | OrxGui::Gui* gui = new OrxGui::QtGuiDataDirFallback(argc, argv); |
---|
[5479] | 359 | gui->startGui(); |
---|
[8750] | 360 | if (gui->getState() == OrxGui::Gui::Quitting) |
---|
| 361 | return(-1); |
---|
[5479] | 362 | delete gui; |
---|
[9869] | 363 | Resources::ResourceManager::getInstance()->setMainGlobalPath(Preferences::getInstance()->getString(CONFIG_SECTION_GENERAL, CONFIG_NAME_DATADIR, "")); |
---|
[4766] | 364 | } |
---|
[8749] | 365 | |
---|
[5996] | 366 | //! @todo this is a hack and should be loadable |
---|
[9869] | 367 | Resources::ResourceManager::getInstance()->addResourceSubPath("Texture", "maps"); |
---|
| 368 | Resources::ResourceManager::getInstance()->addResourceSubPath("Texture", "pictures"); |
---|
[4009] | 369 | |
---|
[9869] | 370 | Resources::ResourceManager::getInstance()->addResourceSubPath("SoundBuffer", "sound"); |
---|
| 371 | Resources::ResourceManager::getInstance()->addResourceSubPath("SoundBuffer", "music"); |
---|
| 372 | |
---|
| 373 | Resources::ResourceManager::getInstance()->addResourceSubPath("Shader", "shaders"); |
---|
| 374 | Resources::ResourceManager::getInstance()->addResourceSubPath("OBJ", "models"); |
---|
| 375 | |
---|
| 376 | Resources::ResourceManager::getInstance()->addKeepLevelName("Imediately"); |
---|
| 377 | Resources::ResourceManager::getInstance()->addKeepLevelName("LevelEnd"); |
---|
| 378 | Resources::ResourceManager::getInstance()->addKeepLevelName("CampaignEnd"); |
---|
| 379 | Resources::ResourceManager::getInstance()->addKeepLevelName("GameEnd"); |
---|
| 380 | Resources::ResourceManager::getInstance()->setDefaultKeepLevel(std::string("GameEnd")); |
---|
| 381 | |
---|
[5074] | 382 | return 0; |
---|
| 383 | } |
---|
| 384 | |
---|
| 385 | /** |
---|
| 386 | * initializes miscelaneous features |
---|
| 387 | * @return -1 on failure |
---|
| 388 | */ |
---|
| 389 | int Orxonox::initMisc() |
---|
| 390 | { |
---|
[9869] | 391 | DebugBuffer::getInstance(); |
---|
[8749] | 392 | |
---|
| 393 | // start the collision detection engine |
---|
| 394 | CDEngine::getInstance(); |
---|
| 395 | |
---|
[4766] | 396 | return 0; |
---|
[1858] | 397 | } |
---|
[1849] | 398 | |
---|
[2190] | 399 | /** |
---|
[4836] | 400 | * starts the orxonox game or menu |
---|
[4833] | 401 | * here is the central orxonox state manager. There are currently two states |
---|
| 402 | * - menu |
---|
| 403 | * - game-play |
---|
| 404 | * both states manage their states themselfs again. |
---|
[2190] | 405 | */ |
---|
[2636] | 406 | void Orxonox::start() |
---|
| 407 | { |
---|
[4556] | 408 | |
---|
[2636] | 409 | this->gameLoader = GameLoader::getInstance(); |
---|
[5996] | 410 | |
---|
[6139] | 411 | if( this->port != -1) |
---|
| 412 | this->gameLoader->loadNetworkCampaign("worlds/DefaultNetworkCampaign.oxc"); |
---|
[5996] | 413 | else |
---|
[6139] | 414 | this->gameLoader->loadCampaign("worlds/DefaultCampaign.oxc"); /* start orxonox in single player mode */ |
---|
[5996] | 415 | |
---|
[4010] | 416 | // this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0); |
---|
[2636] | 417 | this->gameLoader->init(); |
---|
| 418 | this->gameLoader->start(); |
---|
| 419 | } |
---|
| 420 | |
---|
[3214] | 421 | |
---|
[2636] | 422 | /** |
---|
[4833] | 423 | * handles sprecial events from localinput |
---|
| 424 | * @param event: an event not handled by the CommandNode |
---|
| 425 | */ |
---|
[4817] | 426 | // void Orxonox::graphicsHandler(SDL_Event* event) |
---|
| 427 | // { |
---|
| 428 | // // Handle special events such as reshape, quit, focus changes |
---|
| 429 | // switch (event->type) |
---|
| 430 | // { |
---|
| 431 | // case SDL_VIDEORESIZE: |
---|
| 432 | // GraphicsEngine* tmpGEngine = GraphicsEngine::getInstance(); |
---|
| 433 | // tmpGEngine->resolutionChanged(event->resize); |
---|
| 434 | // break; |
---|
| 435 | // } |
---|
| 436 | // } |
---|
[1875] | 437 | |
---|
[4556] | 438 | |
---|
[4408] | 439 | |
---|
[1803] | 440 | |
---|
[3214] | 441 | |
---|
[4782] | 442 | |
---|
[4059] | 443 | bool showGui = false; |
---|
[3648] | 444 | |
---|
[4766] | 445 | /********************************** |
---|
| 446 | *** ORXONOX MAIN STARTING POINT *** |
---|
| 447 | **********************************/ |
---|
[3449] | 448 | /** |
---|
[4833] | 449 | * |
---|
[4836] | 450 | * main function |
---|
[4833] | 451 | * |
---|
| 452 | * here the journey begins |
---|
[3449] | 453 | */ |
---|
[4556] | 454 | int main(int argc, char** argv) |
---|
| 455 | { |
---|
[7256] | 456 | CmdLinePrefsReader prefs; |
---|
[7374] | 457 | |
---|
[10015] | 458 | // create the ~/.orxonox directory if there is not already one |
---|
| 459 | Directory home("~/.orxonox"); |
---|
[10141] | 460 | if (!home.exists()) |
---|
| 461 | home.create(); |
---|
[10015] | 462 | |
---|
[7661] | 463 | IniFilePrefsReader ini(File(DEFAULT_CONFIG_FILE).name()); |
---|
| 464 | Preferences::getInstance()->setUserIni(File(DEFAULT_CONFIG_FILE).name()); |
---|
[7374] | 465 | |
---|
[7256] | 466 | prefs.parse(argc, argv); |
---|
[7374] | 467 | |
---|
[7256] | 468 | if ( Preferences::getInstance()->getString("misc", "showLicenseAndExit", "") == "1" ) |
---|
[5996] | 469 | { |
---|
[7256] | 470 | PRINT(0)(ORXONOX_LICENSE_SHORT); |
---|
| 471 | return 0; |
---|
[5996] | 472 | } |
---|
[7374] | 473 | |
---|
[9240] | 474 | if ( Preferences::getInstance()->getString("misc", "bt-to-file", "1") == "1" ) |
---|
[7440] | 475 | { |
---|
[9406] | 476 | SignalHandler::getInstance()->doCatch( argv[0], "orxonox.backtrace" ); |
---|
| 477 | SignalHandler::getInstance()->registerCallback( EventHandler::releaseMouse, NULL ); |
---|
[7440] | 478 | } |
---|
[7460] | 479 | |
---|
[7256] | 480 | if( Preferences::getInstance()->getString("game", "showGui", "") == "1" ) |
---|
| 481 | showGui = true; |
---|
[9406] | 482 | else if( Preferences::getInstance()->getString( "game", "gameType", "" ) == "multiplayer_master_server" || |
---|
| 483 | Preferences::getInstance()->getString( "game", "gameType", "" ) == "multiplayer_proxy_server" || |
---|
[7256] | 484 | Preferences::getInstance()->getString( "game", "gameType", "" ) == "multiplayer_client" ) |
---|
| 485 | return startNetworkOrxonox(argc, argv); |
---|
[7374] | 486 | |
---|
[7256] | 487 | return startOrxonox(argc, argv, "", -1); |
---|
[3648] | 488 | } |
---|
| 489 | |
---|
| 490 | |
---|
| 491 | |
---|
[5996] | 492 | /** |
---|
| 493 | * starts orxonox in network mode |
---|
| 494 | * @param argc parameters count given to orxonox |
---|
| 495 | * @param argv parameters given to orxonox |
---|
| 496 | */ |
---|
| 497 | int startNetworkOrxonox(int argc, char** argv) |
---|
| 498 | { |
---|
| 499 | |
---|
[7256] | 500 | std::string gameType = Preferences::getInstance()->getString( "game", "gameType", "" ); |
---|
[7374] | 501 | |
---|
[7256] | 502 | if ( gameType == "multiplayer_client" ) |
---|
[4132] | 503 | { |
---|
[7256] | 504 | int port = Preferences::getInstance()->getInt( "game", "port", DEFAULT_ORXONOX_PORT ); |
---|
| 505 | std::string host = Preferences::getInstance()->getString( "game", "host", "" ); |
---|
[7374] | 506 | |
---|
[7256] | 507 | if ( host == "" ) |
---|
[5996] | 508 | { |
---|
[7256] | 509 | printf("You need to specify a host to connect to ( -H <host> )\n"); |
---|
| 510 | return 1; |
---|
[5996] | 511 | } |
---|
[7374] | 512 | |
---|
[7256] | 513 | printf("Starting Orxonox as client: connecting to %s, on port %i\n", host.c_str(), port); |
---|
[7374] | 514 | |
---|
[7256] | 515 | startOrxonox(argc, argv, host.c_str(), port); |
---|
[4132] | 516 | } |
---|
[9406] | 517 | else if ( gameType == "multiplayer_master_server" ) |
---|
[7256] | 518 | { |
---|
| 519 | int port = Preferences::getInstance()->getInt( "game", "port", DEFAULT_ORXONOX_PORT ); |
---|
[7374] | 520 | |
---|
[7256] | 521 | printf("Starting Orxonox as server: listening on port %i\n", port); |
---|
[7374] | 522 | |
---|
[7256] | 523 | startOrxonox(argc, argv, "", port); |
---|
| 524 | } |
---|
[9406] | 525 | else if ( gameType == "multiplayer_proxy_server" ) |
---|
| 526 | { |
---|
| 527 | int port = Preferences::getInstance()->getInt( "game", "port", DEFAULT_ORXONOX_PORT ); |
---|
| 528 | |
---|
| 529 | printf("Starting Orxonox as proxy server: listening on port %i\n", port); |
---|
| 530 | |
---|
| 531 | startOrxonox(argc, argv, "", port); |
---|
| 532 | } |
---|
[8316] | 533 | return 1; |
---|
[3648] | 534 | } |
---|
| 535 | |
---|
[3649] | 536 | |
---|
[4766] | 537 | |
---|
| 538 | /** |
---|
| 539 | * starts orxonox |
---|
| 540 | * @param argc parameters count given to orxonox |
---|
| 541 | * @param argv parameters given to orxonox |
---|
| 542 | */ |
---|
[7256] | 543 | int startOrxonox(int argc, char** argv, const std::string & name, int port) |
---|
[3648] | 544 | { |
---|
[4830] | 545 | // checking for existence of the configuration-files, or if the lock file is still used |
---|
[7661] | 546 | if (showGui || (!File("./orxonox.conf").isFile() && |
---|
[7714] | 547 | !File(DEFAULT_CONFIG_FILE).isFile()) |
---|
[7729] | 548 | #if DEBUG_LEVEL <= 3 // developers do not need to see the GUI, when orxonox fails |
---|
[5996] | 549 | || ResourceManager::isFile(DEFAULT_LOCK_FILE) |
---|
[4981] | 550 | #endif |
---|
| 551 | ) |
---|
[5996] | 552 | { |
---|
[7661] | 553 | File lockFile(DEFAULT_LOCK_FILE); |
---|
| 554 | if (lockFile.isFile()) |
---|
| 555 | lockFile.remove(); |
---|
[4556] | 556 | |
---|
[5996] | 557 | // starting the GUI |
---|
[7661] | 558 | OrxGui::QtGui gui(argc, argv); |
---|
| 559 | gui.startGui(); |
---|
[4132] | 560 | |
---|
[7661] | 561 | if (gui.getState() & OrxGui::Gui::Quitting) |
---|
[5996] | 562 | return 0; |
---|
[4556] | 563 | |
---|
[5996] | 564 | } |
---|
[4556] | 565 | |
---|
[4032] | 566 | PRINT(0)(">>> Starting Orxonox <<<\n"); |
---|
[4033] | 567 | |
---|
[7661] | 568 | File(DEFAULT_LOCK_FILE).touch(); |
---|
[4033] | 569 | |
---|
[1850] | 570 | Orxonox *orx = Orxonox::getInstance(); |
---|
[4556] | 571 | |
---|
[5996] | 572 | if( orx->init(argc, argv, name, port) == -1) |
---|
| 573 | { |
---|
| 574 | PRINTF(1)("! Orxonox initialization failed\n"); |
---|
| 575 | return -1; |
---|
| 576 | } |
---|
[4556] | 577 | |
---|
[9869] | 578 | PRINTF(5)("finished inizialisation\n"); |
---|
[2636] | 579 | orx->start(); |
---|
[4556] | 580 | |
---|
[3676] | 581 | delete orx; |
---|
[7661] | 582 | File("~/.orxonox/orxonox.lock").remove(); |
---|
[8363] | 583 | return 0; |
---|
[1803] | 584 | } |
---|