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