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