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_gui/qt_gui.h" |
---|
33 | |
---|
34 | #include "file.h" |
---|
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 | #include "cd_engine.h" |
---|
44 | #include "text_engine.h" |
---|
45 | #include "event_handler.h" |
---|
46 | |
---|
47 | #include "util/loading/factory.h" |
---|
48 | #include "fast_factory.h" |
---|
49 | |
---|
50 | #include "benchmark.h" |
---|
51 | |
---|
52 | #include "class_list.h" |
---|
53 | #include "shell_command_class.h" |
---|
54 | #include "shell_command.h" |
---|
55 | #include "shell_buffer.h" |
---|
56 | |
---|
57 | #include "util/loading/load_param_description.h" |
---|
58 | |
---|
59 | #include "network_manager.h" |
---|
60 | |
---|
61 | #include "state.h" |
---|
62 | #include "lib/parser/preferences/cmd_line_prefs_reader.h" |
---|
63 | #include "lib/parser/preferences/ini_file_prefs_reader.h" |
---|
64 | #include <string.h> |
---|
65 | |
---|
66 | int verbose = 5; |
---|
67 | |
---|
68 | using namespace std; |
---|
69 | |
---|
70 | SHELL_COMMAND(restart, Orxonox, restart); |
---|
71 | |
---|
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"); |
---|
78 | |
---|
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 | |
---|
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 | |
---|
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 | |
---|
94 | /** |
---|
95 | * create a new Orxonox |
---|
96 | |
---|
97 | In this funcitons only global values are set. The game will not be started here. |
---|
98 | */ |
---|
99 | Orxonox::Orxonox () |
---|
100 | { |
---|
101 | this->setClassID(CL_ORXONOX, "Orxonox"); |
---|
102 | this->setName("orxonox-main"); |
---|
103 | |
---|
104 | this->argc = 0; |
---|
105 | this->argv = NULL; |
---|
106 | |
---|
107 | /* this way, there is no network enabled: */ |
---|
108 | this->serverName = ""; |
---|
109 | this->port = -1; |
---|
110 | |
---|
111 | this->configFileName = ""; |
---|
112 | } |
---|
113 | |
---|
114 | /** |
---|
115 | * remove Orxonox from memory |
---|
116 | */ |
---|
117 | Orxonox::~Orxonox () |
---|
118 | { |
---|
119 | // game-specific |
---|
120 | delete GameLoader::getInstance(); |
---|
121 | |
---|
122 | // class-less services/factories |
---|
123 | Factory::deleteFactories(); |
---|
124 | FastFactory::deleteAll(); |
---|
125 | OrxShell::ShellCommandClass::unregisterAllCommands(); |
---|
126 | |
---|
127 | LoadClassDescription::deleteAllDescriptions(); |
---|
128 | |
---|
129 | // handlers |
---|
130 | delete ResourceManager::getInstance(); // deletes the Resource Manager |
---|
131 | |
---|
132 | // engines |
---|
133 | delete CDEngine::getInstance(); |
---|
134 | delete OrxSound::SoundEngine::getInstance(); |
---|
135 | delete GraphicsEngine::getInstance(); // deleting the Graphics |
---|
136 | delete EventHandler::getInstance(); |
---|
137 | |
---|
138 | // output-buffer |
---|
139 | delete OrxShell::ShellBuffer::getInstance(); |
---|
140 | |
---|
141 | SDL_QuitSubSystem(SDL_INIT_TIMER); |
---|
142 | ClassList::debug(); |
---|
143 | |
---|
144 | PRINT(3) |
---|
145 | ( |
---|
146 | "===================================================\n" \ |
---|
147 | "Thanks for playing orxonox.\n" \ |
---|
148 | "visit: http://www.orxonox.net for new versions.\n" \ |
---|
149 | "===================================================\n" \ |
---|
150 | ORXONOX_LICENSE_SHORT |
---|
151 | ); |
---|
152 | |
---|
153 | Orxonox::singletonRef = NULL; |
---|
154 | } |
---|
155 | |
---|
156 | /** |
---|
157 | * this is a singleton class to prevent duplicates |
---|
158 | */ |
---|
159 | Orxonox* Orxonox::singletonRef = NULL; |
---|
160 | |
---|
161 | // DANGEROUS |
---|
162 | void Orxonox::restart() |
---|
163 | { |
---|
164 | // int argc = this->argc; |
---|
165 | // char** argv = this->argv; |
---|
166 | // |
---|
167 | // Orxonox *orx = Orxonox::getInstance(); |
---|
168 | // |
---|
169 | // delete orx; |
---|
170 | // |
---|
171 | // orx = Orxonox::getInstance(); |
---|
172 | // |
---|
173 | // if((*orx).init(argc, argv) == -1) |
---|
174 | // { |
---|
175 | // PRINTF(1)("! Orxonox initialization failed\n"); |
---|
176 | // return; |
---|
177 | // } |
---|
178 | // |
---|
179 | // printf("finished inizialisation\n"); |
---|
180 | // orx->start(); |
---|
181 | } |
---|
182 | |
---|
183 | /** |
---|
184 | * @brief this finds the config file |
---|
185 | * @returns the new config-fileName |
---|
186 | * Since the config file varies from user to user and since one may want to specify different config files |
---|
187 | * for certain occasions or platforms this function finds the right config file for every occasion and stores |
---|
188 | * it's path and name into configfilename |
---|
189 | */ |
---|
190 | const std::string& Orxonox::getConfigFile () |
---|
191 | { |
---|
192 | File orxConfFile("orxonox.conf"); |
---|
193 | if (orxConfFile.isFile()) |
---|
194 | { |
---|
195 | this->configFileName = "orxonox.conf"; |
---|
196 | } |
---|
197 | else |
---|
198 | this->configFileName = File(DEFAULT_CONFIG_FILE).name(); |
---|
199 | |
---|
200 | PRINTF(3)("Parsed Config File: '%s'\n", this->configFileName.c_str()); |
---|
201 | } |
---|
202 | |
---|
203 | /** |
---|
204 | * initialize Orxonox with command line |
---|
205 | */ |
---|
206 | int Orxonox::init (int argc, char** argv, const std::string & name, int port) |
---|
207 | { |
---|
208 | this->argc = argc; |
---|
209 | this->argv = argv; |
---|
210 | |
---|
211 | this->serverName = name; |
---|
212 | this->port = port; |
---|
213 | |
---|
214 | // initialize the Config-file |
---|
215 | this->getConfigFile(); |
---|
216 | |
---|
217 | // windows must not write into stdout.txt and stderr.txt |
---|
218 | /*#ifdef __WIN32__ |
---|
219 | freopen( "CON", "w", stdout ); |
---|
220 | freopen( "CON", "w", stderr ); |
---|
221 | #endif*/ |
---|
222 | |
---|
223 | // initialize everything |
---|
224 | SDL_Init(0); |
---|
225 | if( initResources () == -1) |
---|
226 | return -1; |
---|
227 | if( initVideo() == -1) |
---|
228 | return -1; |
---|
229 | if( initSound() == -1) |
---|
230 | return -1; |
---|
231 | if( initInput() == -1) |
---|
232 | return -1; |
---|
233 | if( initNetworking () == -1) |
---|
234 | return -1; |
---|
235 | if( initMisc () == -1) |
---|
236 | return -1; |
---|
237 | |
---|
238 | return 0; |
---|
239 | } |
---|
240 | |
---|
241 | |
---|
242 | /** |
---|
243 | * initializes SDL and OpenGL |
---|
244 | */ |
---|
245 | int Orxonox::initVideo() |
---|
246 | { |
---|
247 | PRINTF(3)("> Initializing video\n"); |
---|
248 | |
---|
249 | GraphicsEngine::getInstance(); |
---|
250 | |
---|
251 | GraphicsEngine::getInstance()->initFromPreferences(); |
---|
252 | |
---|
253 | std::string iconName = ResourceManager::getFullName("pictures/fighter-top-32x32.bmp"); |
---|
254 | if (!iconName.empty()) |
---|
255 | { |
---|
256 | GraphicsEngine::getInstance()->setWindowName(PACKAGE_NAME " " PACKAGE_VERSION, iconName); |
---|
257 | } |
---|
258 | return 0; |
---|
259 | } |
---|
260 | |
---|
261 | |
---|
262 | /** |
---|
263 | * initializes the sound engine |
---|
264 | */ |
---|
265 | int Orxonox::initSound() |
---|
266 | { |
---|
267 | PRINT(3)("> Initializing sound\n"); |
---|
268 | // SDL_InitSubSystem(SDL_INIT_AUDIO); |
---|
269 | OrxSound::SoundEngine::getInstance(); |
---|
270 | |
---|
271 | OrxSound::SoundEngine::getInstance()->loadSettings(); |
---|
272 | OrxSound::SoundEngine::getInstance()->initAudio(); |
---|
273 | return 0; |
---|
274 | } |
---|
275 | |
---|
276 | |
---|
277 | /** |
---|
278 | * initializes input functions |
---|
279 | */ |
---|
280 | int Orxonox::initInput() |
---|
281 | { |
---|
282 | PRINT(3)("> Initializing input\n"); |
---|
283 | |
---|
284 | EventHandler::getInstance()-> |
---|
285 | EventHandler::getInstance()->init(); |
---|
286 | EventHandler::getInstance()->subscribe(GraphicsEngine::getInstance(), ES_ALL, EV_VIDEO_RESIZE); |
---|
287 | |
---|
288 | return 0; |
---|
289 | } |
---|
290 | |
---|
291 | |
---|
292 | /** |
---|
293 | * initializes network system |
---|
294 | */ |
---|
295 | int Orxonox::initNetworking() |
---|
296 | { |
---|
297 | PRINT(3)("> Initializing networking\n"); |
---|
298 | |
---|
299 | if( this->serverName != "") // we are a client |
---|
300 | { |
---|
301 | State::setOnline(true); |
---|
302 | NetworkManager::getInstance()->establishConnection(this->serverName, port); |
---|
303 | } |
---|
304 | else if( this->port > 0) |
---|
305 | { // we are a server |
---|
306 | State::setOnline(true); |
---|
307 | NetworkManager::getInstance()->createServer(port); |
---|
308 | } |
---|
309 | return 0; |
---|
310 | } |
---|
311 | |
---|
312 | //#include "util/loading/dynamic_loader.h" |
---|
313 | |
---|
314 | /** |
---|
315 | * initializes and loads resource files |
---|
316 | */ |
---|
317 | int Orxonox::initResources() |
---|
318 | { |
---|
319 | PRINTF(3)("> Initializing resources\n"); |
---|
320 | |
---|
321 | PRINT(3)("initializing ResourceManager\n"); |
---|
322 | |
---|
323 | // init the resource manager |
---|
324 | std::string dataPath; |
---|
325 | if ((dataPath = Preferences::getInstance()->getString(CONFIG_SECTION_GENERAL, CONFIG_NAME_DATADIR, ""))!= "") |
---|
326 | { |
---|
327 | if (!ResourceManager::getInstance()->setDataDir(dataPath) && |
---|
328 | !ResourceManager::getInstance()->verifyDataDir(DEFAULT_DATA_DIR_CHECKFILE)) |
---|
329 | { |
---|
330 | PRINTF(1)("Data Could not be located in %s\n", dataPath.c_str()); |
---|
331 | } |
---|
332 | } |
---|
333 | |
---|
334 | if (!ResourceManager::getInstance()->verifyDataDir(DEFAULT_DATA_DIR_CHECKFILE)) |
---|
335 | { |
---|
336 | PRINTF(1)("The DataDirectory %s could not be verified\n\nh" \ |
---|
337 | "!!! Please Change in File %s Section %s Entry %s to a suitable value !!!\n", |
---|
338 | ResourceManager::getInstance()->getDataDir().c_str(), |
---|
339 | this->configFileName.c_str(), |
---|
340 | CONFIG_SECTION_GENERAL, |
---|
341 | CONFIG_NAME_DATADIR ); |
---|
342 | OrxGui::Gui* gui = new OrxGui::QtGui(argc, argv); |
---|
343 | gui->startGui(); |
---|
344 | delete gui; |
---|
345 | exit(-1); |
---|
346 | } |
---|
347 | //! @todo this is a hack and should be loadable |
---|
348 | std::string imageDir = ResourceManager::getInstance()->getFullName("maps"); |
---|
349 | ResourceManager::getInstance()->addImageDir(imageDir); |
---|
350 | imageDir = ResourceManager::getInstance()->getFullName("pictures"); |
---|
351 | ResourceManager::getInstance()->addImageDir(imageDir); |
---|
352 | |
---|
353 | // DynamicLoader::loadDyLib("libtest.so"); |
---|
354 | |
---|
355 | // start the collision detection engine |
---|
356 | CDEngine::getInstance(); |
---|
357 | return 0; |
---|
358 | } |
---|
359 | |
---|
360 | /** |
---|
361 | * initializes miscelaneous features |
---|
362 | * @return -1 on failure |
---|
363 | */ |
---|
364 | int Orxonox::initMisc() |
---|
365 | { |
---|
366 | OrxShell::ShellBuffer::getInstance(); |
---|
367 | return 0; |
---|
368 | } |
---|
369 | |
---|
370 | /** |
---|
371 | * starts the orxonox game or menu |
---|
372 | * here is the central orxonox state manager. There are currently two states |
---|
373 | * - menu |
---|
374 | * - game-play |
---|
375 | * both states manage their states themselfs again. |
---|
376 | */ |
---|
377 | void Orxonox::start() |
---|
378 | { |
---|
379 | |
---|
380 | this->gameLoader = GameLoader::getInstance(); |
---|
381 | |
---|
382 | if( this->port != -1) |
---|
383 | this->gameLoader->loadNetworkCampaign("worlds/DefaultNetworkCampaign.oxc"); |
---|
384 | else |
---|
385 | this->gameLoader->loadCampaign("worlds/DefaultCampaign.oxc"); /* start orxonox in single player mode */ |
---|
386 | |
---|
387 | // this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0); |
---|
388 | this->gameLoader->init(); |
---|
389 | this->gameLoader->start(); |
---|
390 | } |
---|
391 | |
---|
392 | |
---|
393 | /** |
---|
394 | * handles sprecial events from localinput |
---|
395 | * @param event: an event not handled by the CommandNode |
---|
396 | */ |
---|
397 | // void Orxonox::graphicsHandler(SDL_Event* event) |
---|
398 | // { |
---|
399 | // // Handle special events such as reshape, quit, focus changes |
---|
400 | // switch (event->type) |
---|
401 | // { |
---|
402 | // case SDL_VIDEORESIZE: |
---|
403 | // GraphicsEngine* tmpGEngine = GraphicsEngine::getInstance(); |
---|
404 | // tmpGEngine->resolutionChanged(event->resize); |
---|
405 | // break; |
---|
406 | // } |
---|
407 | // } |
---|
408 | |
---|
409 | |
---|
410 | |
---|
411 | |
---|
412 | |
---|
413 | |
---|
414 | bool showGui = false; |
---|
415 | |
---|
416 | /// HACK HACK TEST |
---|
417 | |
---|
418 | |
---|
419 | template<typename type> MT_Type ExecutorParamType() { return MT_EXT1; }; |
---|
420 | template<> MT_Type ExecutorParamType<bool>() { return MT_EXT1; }; |
---|
421 | template<> MT_Type ExecutorParamType<int>() { return MT_INT; }; |
---|
422 | template<> MT_Type ExecutorParamType<unsigned int>() { return MT_UINT; }; |
---|
423 | template<> MT_Type ExecutorParamType<float>() { return MT_FLOAT; }; |
---|
424 | template<> MT_Type ExecutorParamType<char>() { return MT_CHAR; }; |
---|
425 | template<> MT_Type ExecutorParamType<const std::string&>() { return MT_STRING; }; |
---|
426 | |
---|
427 | template<typename type> type fromString(const std::string& input, type defaultValue) {return defaultValue; }; |
---|
428 | template<> bool fromString<bool>(const std::string& input, bool defaultValue) { return isBool(input, defaultValue); }; |
---|
429 | template<> int fromString<int>(const std::string& input, int defaultValue) { return isInt(input, defaultValue); }; |
---|
430 | template<> unsigned int fromString<unsigned int>(const std::string& input, unsigned int defaultValue) { return isInt(input, defaultValue); }; |
---|
431 | template<> float fromString<float>(const std::string& input, float defaultValue) { return isFloat(input, defaultValue); }; |
---|
432 | template<> char fromString<char>(const std::string& input, char defaultValue) { return isInt(input, defaultValue); }; |
---|
433 | template<> const std::string& fromString<const std::string&>(const std::string& input, const std::string& defaultValue) { return isString(input, defaultValue); }; |
---|
434 | |
---|
435 | template<typename type> type getDefault(const MultiType* const defaultValues, unsigned int i) { return (type)0; }; |
---|
436 | template<> bool getDefault<bool>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getBool(); }; |
---|
437 | template<> int getDefault<int>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getInt(); }; |
---|
438 | template<> unsigned int getDefault<unsigned int>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getInt(); }; |
---|
439 | template<> float getDefault<float>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getFloat(); }; |
---|
440 | template<> char getDefault<char>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getChar(); }; |
---|
441 | template<> std::string getDefault<std::string>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getString(); }; |
---|
442 | |
---|
443 | |
---|
444 | template<class T> class Executor0Params : public Executor |
---|
445 | { |
---|
446 | private: |
---|
447 | void (T::*functionPointer)(); |
---|
448 | |
---|
449 | public: |
---|
450 | Executor0Params (void (T::*functionPointer)()) |
---|
451 | : Executor() |
---|
452 | { |
---|
453 | this->functorType = Executor_Objective; |
---|
454 | this->functionPointer = functionPointer; |
---|
455 | } |
---|
456 | virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const |
---|
457 | { |
---|
458 | (dynamic_cast<T*>(object)->*functionPointer)(); |
---|
459 | }; |
---|
460 | |
---|
461 | Executor* clone() const {}; |
---|
462 | }; |
---|
463 | |
---|
464 | |
---|
465 | template<class T, typename type0> class Executor1Params : public Executor |
---|
466 | { |
---|
467 | private: |
---|
468 | void (T::*functionPointer)(type0); |
---|
469 | |
---|
470 | public: |
---|
471 | Executor1Params (void (T::*functionPointer)(type0)) |
---|
472 | : Executor(ExecutorParamType<type0>()) |
---|
473 | { |
---|
474 | this->functorType = Executor_Objective; |
---|
475 | this->functionPointer = functionPointer; |
---|
476 | } |
---|
477 | virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const |
---|
478 | { |
---|
479 | |
---|
480 | /* // THE VERY COOL DEBUG |
---|
481 | printf("SUB[0] : %s\n", sub[0].c_str()); |
---|
482 | printf("getDefault<type0>(this->defaultValue, 0):::: %d\n", getDefault<type0>(this->defaultValue, 0)); |
---|
483 | printf("VALUE: %d\n", fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0))); |
---|
484 | */ |
---|
485 | (dynamic_cast<T*>(object)->*functionPointer)( fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)) ); |
---|
486 | }; |
---|
487 | |
---|
488 | virtual Executor* clone() const {}; |
---|
489 | }; |
---|
490 | |
---|
491 | /// DOUBLE PENETRATION |
---|
492 | template<class T, typename type0, typename type1> class Executor2Params : public Executor |
---|
493 | { |
---|
494 | private: |
---|
495 | void (T::*functionPointer)(type0, type1); |
---|
496 | |
---|
497 | public: |
---|
498 | Executor2Params (void (T::*functionPointer)(type0, type1)) |
---|
499 | : Executor(ExecutorParamType<type0>(), ExecutorParamType<type1>()) |
---|
500 | { |
---|
501 | this->functorType = Executor_Objective; |
---|
502 | this->functionPointer = functionPointer; |
---|
503 | } |
---|
504 | virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const |
---|
505 | { |
---|
506 | (dynamic_cast<T*>(object)->*functionPointer)( |
---|
507 | fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)), |
---|
508 | fromString<type1>(sub[1], getDefault<type1>(this->defaultValue, 1))); |
---|
509 | }; |
---|
510 | |
---|
511 | virtual Executor* clone() const {}; |
---|
512 | }; |
---|
513 | |
---|
514 | class TestClass : public BaseObject |
---|
515 | { |
---|
516 | public: |
---|
517 | TestClass() {}; |
---|
518 | |
---|
519 | void printTest() { printf ("TEST\n"); }; |
---|
520 | void printTestInt(int i) { printf ("%d\n", i); }; |
---|
521 | void printTestBool(bool b) { printf("%d\n", (int)b); }; |
---|
522 | void printTwoVals(bool b, int i) { printf ("%d %d\n", b, i); }; |
---|
523 | }; |
---|
524 | |
---|
525 | void TEST() |
---|
526 | { |
---|
527 | TestClass test; |
---|
528 | SubString testStrings("1, 2, 3", ",", SubString::WhiteSpaces, false); |
---|
529 | (Executor0Params<TestClass>(&TestClass::printTest))(&test, testStrings); |
---|
530 | (Executor1Params<TestClass,int>(&TestClass::printTestInt))(&test, testStrings); |
---|
531 | (Executor1Params<TestClass,bool>(&TestClass::printTestBool))(&test, testStrings); |
---|
532 | (Executor2Params<TestClass,bool, int>(&TestClass::printTwoVals))(&test, testStrings); |
---|
533 | |
---|
534 | } |
---|
535 | |
---|
536 | //// HACK HACK |
---|
537 | |
---|
538 | /********************************** |
---|
539 | *** ORXONOX MAIN STARTING POINT *** |
---|
540 | **********************************/ |
---|
541 | /** |
---|
542 | * |
---|
543 | * main function |
---|
544 | * |
---|
545 | * here the journey begins |
---|
546 | */ |
---|
547 | int main(int argc, char** argv) |
---|
548 | { |
---|
549 | TEST(); |
---|
550 | CmdLinePrefsReader prefs; |
---|
551 | |
---|
552 | IniFilePrefsReader ini(File(DEFAULT_CONFIG_FILE).name()); |
---|
553 | Preferences::getInstance()->setUserIni(File(DEFAULT_CONFIG_FILE).name()); |
---|
554 | |
---|
555 | prefs.parse(argc, argv); |
---|
556 | |
---|
557 | if ( Preferences::getInstance()->getString("misc", "showLicenseAndExit", "") == "1" ) |
---|
558 | { |
---|
559 | PRINT(0)(ORXONOX_LICENSE_SHORT); |
---|
560 | return 0; |
---|
561 | } |
---|
562 | |
---|
563 | if ( Preferences::getInstance()->getString("misc", "start-gdb", "0") == "1" ) |
---|
564 | { |
---|
565 | SignalHandler::getInstance()->doCatch( argv[0], GDB_RUN_IN_FOREGROUND ); |
---|
566 | } |
---|
567 | else if ( Preferences::getInstance()->getString("misc", "bt-to-file", "1") == "1" ) |
---|
568 | { |
---|
569 | SignalHandler::getInstance()->doCatch( argv[0], GDB_RUN_WRITE_TO_FILE ); |
---|
570 | |
---|
571 | } |
---|
572 | |
---|
573 | if( Preferences::getInstance()->getString("game", "showGui", "") == "1" ) |
---|
574 | showGui = true; |
---|
575 | else if( Preferences::getInstance()->getString( "game", "gameType", "" ) == "multiplayer_server" || |
---|
576 | Preferences::getInstance()->getString( "game", "gameType", "" ) == "multiplayer_client" ) |
---|
577 | return startNetworkOrxonox(argc, argv); |
---|
578 | |
---|
579 | return startOrxonox(argc, argv, "", -1); |
---|
580 | return 0; |
---|
581 | } |
---|
582 | |
---|
583 | |
---|
584 | |
---|
585 | /** |
---|
586 | * starts orxonox in network mode |
---|
587 | * @param argc parameters count given to orxonox |
---|
588 | * @param argv parameters given to orxonox |
---|
589 | */ |
---|
590 | int startNetworkOrxonox(int argc, char** argv) |
---|
591 | { |
---|
592 | |
---|
593 | std::string gameType = Preferences::getInstance()->getString( "game", "gameType", "" ); |
---|
594 | |
---|
595 | if ( gameType == "multiplayer_client" ) |
---|
596 | { |
---|
597 | int port = Preferences::getInstance()->getInt( "game", "port", DEFAULT_ORXONOX_PORT ); |
---|
598 | std::string host = Preferences::getInstance()->getString( "game", "host", "" ); |
---|
599 | |
---|
600 | if ( host == "" ) |
---|
601 | { |
---|
602 | printf("You need to specify a host to connect to ( -H <host> )\n"); |
---|
603 | return 1; |
---|
604 | } |
---|
605 | |
---|
606 | printf("Starting Orxonox as client: connecting to %s, on port %i\n", host.c_str(), port); |
---|
607 | |
---|
608 | startOrxonox(argc, argv, host.c_str(), port); |
---|
609 | } |
---|
610 | else if ( gameType == "multiplayer_server" ) |
---|
611 | { |
---|
612 | int port = Preferences::getInstance()->getInt( "game", "port", DEFAULT_ORXONOX_PORT ); |
---|
613 | |
---|
614 | printf("Starting Orxonox as server: listening on port %i\n", port); |
---|
615 | |
---|
616 | startOrxonox(argc, argv, "", port); |
---|
617 | } |
---|
618 | } |
---|
619 | |
---|
620 | |
---|
621 | |
---|
622 | /** |
---|
623 | * starts orxonox |
---|
624 | * @param argc parameters count given to orxonox |
---|
625 | * @param argv parameters given to orxonox |
---|
626 | */ |
---|
627 | int startOrxonox(int argc, char** argv, const std::string & name, int port) |
---|
628 | { |
---|
629 | // checking for existence of the configuration-files, or if the lock file is still used |
---|
630 | if (showGui || (!File("./orxonox.conf").isFile() && |
---|
631 | !File(DEFAULT_CONFIG_FILE).isFile()) |
---|
632 | #if DEBUG < 3 // developers do not need to see the GUI, when orxonox fails |
---|
633 | || ResourceManager::isFile(DEFAULT_LOCK_FILE) |
---|
634 | #endif |
---|
635 | ) |
---|
636 | { |
---|
637 | File lockFile(DEFAULT_LOCK_FILE); |
---|
638 | if (lockFile.isFile()) |
---|
639 | lockFile.remove(); |
---|
640 | |
---|
641 | // starting the GUI |
---|
642 | OrxGui::QtGui gui(argc, argv); |
---|
643 | gui.startGui(); |
---|
644 | |
---|
645 | if (gui.getState() & OrxGui::Gui::Quitting) |
---|
646 | return 0; |
---|
647 | |
---|
648 | } |
---|
649 | |
---|
650 | PRINT(0)(">>> Starting Orxonox <<<\n"); |
---|
651 | |
---|
652 | File(DEFAULT_LOCK_FILE).touch(); |
---|
653 | |
---|
654 | Orxonox *orx = Orxonox::getInstance(); |
---|
655 | |
---|
656 | if( orx->init(argc, argv, name, port) == -1) |
---|
657 | { |
---|
658 | PRINTF(1)("! Orxonox initialization failed\n"); |
---|
659 | return -1; |
---|
660 | } |
---|
661 | |
---|
662 | printf("finished inizialisation\n"); |
---|
663 | orx->start(); |
---|
664 | |
---|
665 | delete orx; |
---|
666 | File("~/.orxonox/orxonox.lock").remove(); |
---|
667 | } |
---|