1 // options.cxx -- class to handle command line options
3 // Written by Curtis Olson, started April 1998.
5 // Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include <simgear/compiler.h>
29 #include <simgear/misc/exception.hxx>
31 #include <math.h> // rint()
33 #include <stdlib.h> // atof(), atoi()
34 #include <string.h> // strcmp()
38 #include <simgear/misc/sgstream.hxx>
39 #include <simgear/misc/sg_path.hxx>
40 #include <simgear/route/route.hxx>
41 #include <simgear/route/waypoint.hxx>
43 // #include <Include/general.hxx>
44 // #include <Airports/simple.hxx>
45 // #include <Cockpit/cockpit.hxx>
46 // #include <FDM/flight.hxx>
47 // #include <FDM/UIUCModel/uiuc_aircraftdir.h>
49 # include <NetworkOLK/network.h>
54 #include "globals.hxx"
55 #include "fg_init.hxx"
56 #include "fg_props.hxx"
57 #include "options.hxx"
58 #include "viewmgr.hxx"
61 SG_USING_NAMESPACE(std);
64 #define NEW_DEFAULT_MODEL_HZ 120
74 atof( const string& str )
78 // -dw- if ::atof is called, then we get an infinite loop
79 return std::atof( str.c_str() );
81 return ::atof( str.c_str() );
86 atoi( const string& str )
89 // -dw- if ::atoi is called, then we get an infinite loop
90 return std::atoi( str.c_str() );
92 return ::atoi( str.c_str() );
98 * Set a few fail-safe default property values.
100 * These should all be set in $FG_ROOT/preferences.xml, but just
101 * in case, we provide some initial sane values here. This method
102 * should be invoked *before* reading any init files.
107 // set a possibly independent location for scenery data
108 char *envp = ::getenv( "FG_SCENERY" );
110 if ( envp != NULL ) {
111 // fg_root could be anywhere, so default to environmental
112 // variable $FG_ROOT if it is set.
113 globals->set_fg_scenery(envp);
115 // Otherwise, default to Scenery being in $FG_ROOT/Scenery
116 globals->set_fg_scenery("");
118 // Position (deliberately out of range)
119 fgSetDouble("/position/longitude-deg", 9999.0);
120 fgSetDouble("/position/latitude-deg", 9999.0);
121 fgSetDouble("/position/altitude-ft", -9999.0);
124 fgSetDouble("/orientation/heading-deg", 270);
125 fgSetDouble("/orientation/roll-deg", 0);
126 fgSetDouble("/orientation/pitch-deg", 0.424);
129 fgSetString("/sim/startup/speed-set", "knots");
130 fgSetDouble("/velocities/uBody-fps", 0.0);
131 fgSetDouble("/velocities/vBody-fps", 0.0);
132 fgSetDouble("/velocities/wBody-fps", 0.0);
133 fgSetDouble("/velocities/speed-north-fps", 0.0);
134 fgSetDouble("/velocities/speed-east-fps", 0.0);
135 fgSetDouble("/velocities/speed-down-fps", 0.0);
136 fgSetDouble("/velocities/airspeed-kt", 0.0);
137 fgSetDouble("/velocities/mach", 0.0);
140 fgSetBool("/sim/startup/game-mode", false);
141 fgSetBool("/sim/startup/splash-screen", true);
142 fgSetBool("/sim/startup/intro-music", true);
143 // we want mouse-pointer to have an undefined value if nothing is
144 // specified so we can do the right thing for voodoo-1/2 cards.
145 // fgSetString("/sim/startup/mouse-pointer", "disabled");
146 fgSetString("/sim/control-mode", "joystick");
147 fgSetBool("/sim/auto-coordination", false);
149 fgSetString("/sim/startup/browser-app", "netscape");
151 fgSetString("/sim/startup/browser-app", "webrun.bat");
154 fgSetBool("/sim/hud/visibility", false);
155 fgSetBool("/sim/panel/visibility", true);
156 fgSetBool("/sim/sound/audible", true);
157 fgSetBool("/sim/hud/antialiased", false);
159 // Flight Model options
160 fgSetString("/sim/flight-model", "jsb");
161 fgSetString("/sim/aero", "c172");
162 fgSetInt("/sim/model-hz", NEW_DEFAULT_MODEL_HZ);
163 fgSetInt("/sim/speed-up", 1);
164 fgSetBool("/sim/startup/trim", false);
165 fgSetBool("/sim/startup/onground", true);
168 fgSetString("/sim/rendering/fog", "nicest");
169 fgSetBool("/environment/clouds/status", true);
170 fgSetBool("/sim/startup/fullscreen", false);
171 fgSetBool("/sim/rendering/shading", true);
172 fgSetBool("/sim/rendering/skyblend", true);
173 fgSetBool("/sim/rendering/textures", true);
174 fgSetBool("/sim/rendering/wireframe", false);
175 fgSetInt("/sim/startup/xsize", 800);
176 fgSetInt("/sim/startup/ysize", 600);
177 fgSetInt("/sim/rendering/bits-per-pixel", 16);
178 fgSetString("/sim/view-mode", "pilot");
179 fgSetDouble("/sim/current-view/heading-offset-deg", 0);
180 fgSetDouble("/environment/visibility-m", 20000);
183 fgSetString("/sim/startup/units", "feet");
184 fgSetString("/sim/hud/frame-stat-type", "tris");
187 fgSetInt("/sim/startup/time-offset", 0);
188 fgSetString("/sim/startup/time-offset-type", "system-offset");
189 fgSetLong("/sim/time/cur-time-override", 0);
191 fgSetBool("/sim/networking/network-olk", false);
192 fgSetString("/sim/networking/call-sign", "Johnny");
195 fgSetBool("/sim/freeze/master", false);
196 fgSetBool("/sim/freeze/position", false);
197 fgSetBool("/sim/freeze/clock", false);
198 fgSetBool("/sim/freeze/fuel", false);
202 // parse a time string ([+/-]%f[:%f[:%f]]) into hours
204 parse_time(const string& time_in) {
205 char *time_str, num[256];
206 double hours, minutes, seconds;
211 time_str = (char *)time_in.c_str();
213 // printf("parse_time(): %s\n", time_str);
216 if ( strlen(time_str) ) {
217 if ( time_str[0] == '+' ) {
220 } else if ( time_str[0] == '-' ) {
225 // printf("sign = %d\n", sign);
228 if ( strlen(time_str) ) {
230 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
231 num[i] = time_str[0];
235 if ( time_str[0] == ':' ) {
240 // printf("hours = %.2lf\n", hours);
246 if ( strlen(time_str) ) {
248 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
249 num[i] = time_str[0];
253 if ( time_str[0] == ':' ) {
258 // printf("minutes = %.2lf\n", minutes);
260 result += minutes / 60.0;
264 if ( strlen(time_str) ) {
266 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
267 num[i] = time_str[0];
273 // printf("seconds = %.2lf\n", seconds);
275 result += seconds / 3600.0;
278 return(sign * result);
282 // parse a date string (yyyy:mm:dd:hh:mm:ss) into a time_t (seconds)
284 parse_date( const string& date)
287 char * date_str, num[256];
289 // initialize to zero
296 gmt.tm_isdst = 0; // ignore daylight savings time for the moment
297 date_str = (char *)date.c_str();
299 if ( strlen(date_str) ) {
301 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
302 num[i] = date_str[0];
306 if ( date_str[0] == ':' ) {
310 gmt.tm_year = atoi(num) - 1900;
313 if ( strlen(date_str) ) {
315 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
316 num[i] = date_str[0];
320 if ( date_str[0] == ':' ) {
324 gmt.tm_mon = atoi(num) -1;
327 if ( strlen(date_str) ) {
329 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
330 num[i] = date_str[0];
334 if ( date_str[0] == ':' ) {
338 gmt.tm_mday = atoi(num);
341 if ( strlen(date_str) ) {
343 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
344 num[i] = date_str[0];
348 if ( date_str[0] == ':' ) {
352 gmt.tm_hour = atoi(num);
355 if ( strlen(date_str) ) {
357 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
358 num[i] = date_str[0];
362 if ( date_str[0] == ':' ) {
366 gmt.tm_min = atoi(num);
369 if ( strlen(date_str) ) {
371 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
372 num[i] = date_str[0];
376 if ( date_str[0] == ':' ) {
380 gmt.tm_sec = atoi(num);
382 time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
383 gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
384 //printf ("Date is %s\n", ctime(&theTime));
385 //printf ("in seconds that is %d\n", theTime);
391 // parse angle in the form of [+/-]ddd:mm:ss into degrees
393 parse_degree( const string& degree_str) {
394 double result = parse_time( degree_str );
396 // printf("Degree = %.4f\n", result);
402 // parse time offset string into seconds
404 parse_time_offset( const string& time_str) {
407 // printf("time offset = %s\n", time_str);
410 result = (int)rint(parse_time(time_str) * 3600.0);
412 result = (int)(parse_time(time_str) * 3600.0);
415 // printf("parse_time_offset(): %d\n", result);
421 // Parse --fov=x.xx type option
423 parse_fov( const string& arg ) {
424 double fov = atof(arg);
426 if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
427 if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
429 fgSetDouble("/sim/current-view/field-of-view", fov);
431 // printf("parse_fov(): result = %.4f\n", fov);
437 // Parse I/O channel option
439 // Format is "--protocol=medium,direction,hz,medium_options,..."
441 // protocol = { native, nmea, garmin, fgfs, rul, pve, etc. }
442 // medium = { serial, socket, file, etc. }
443 // direction = { in, out, bi }
444 // hz = number of times to process channel per second (floating
445 // point values are ok.
447 // Serial example "--nmea=serial,dir,hz,device,baud" where
449 // device = OS device name of serial line to be open()'ed
450 // baud = {300, 1200, 2400, ..., 230400}
452 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
454 // machine = machine name or ip address if client (leave empty if server)
455 // port = port, leave empty to let system choose
456 // style = tcp or udp
458 // File example "--garmin=file,dir,hz,filename" where
460 // filename = file system file name
463 add_channel( const string& type, const string& channel_str ) {
464 // cout << "Channel string = " << channel_str << endl;
466 globals->get_channel_options_list()->push_back( type + "," + channel_str );
472 // Parse --wp=ID[@alt]
474 parse_wp( const string& arg ) {
478 unsigned int pos = arg.find( "@" );
479 if ( pos != string::npos ) {
480 id = arg.substr( 0, pos );
481 alt_str = arg.substr( pos + 1 );
482 // cout << "id str = " << id << " alt str = " << alt_str << endl;
483 alt = atof( alt_str.c_str() );
484 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") ) {
485 alt *= SG_FEET_TO_METER;
492 if ( fgFindAirportID( id, &a ) ) {
493 SGWayPoint wp( a.longitude, a.latitude, alt, SGWayPoint::WGS84, id );
494 globals->get_route()->add_waypoint( wp );
503 // Parse --flight-plan=[file]
505 parse_flightplan(const string& arg)
507 sg_gzifstream in(arg.c_str());
508 if ( !in.is_open() ) {
514 #if defined( macintosh )
515 getline( in, line, '\r' );
517 getline( in, line, '\n' );
520 // catch extraneous (DOS) line ending character
521 if ( line[line.length() - 1] < 32 ) {
522 line = line.substr( 0, line.length()-1 );
535 // Parse a single option
537 parse_option (const string& arg)
540 if ( (arg == "--help") || (arg == "-h") ) {
541 // help/usage request
542 return(FG_OPTIONS_HELP);
543 } else if ( arg == "--disable-game-mode") {
544 fgSetBool("/sim/startup/game-mode", false);
545 } else if ( arg == "--enable-game-mode" ) {
546 fgSetBool("/sim/startup/game-mode", true);
547 } else if ( arg == "--disable-splash-screen" ) {
548 fgSetBool("/sim/startup/splash-screen", false);
549 } else if ( arg == "--enable-splash-screen" ) {
550 fgSetBool("/sim/startup/splash-screen", true);
551 } else if ( arg == "--disable-intro-music" ) {
552 fgSetBool("/sim/startup/intro-music", false);
553 } else if ( arg == "--enable-intro-music" ) {
554 fgSetBool("/sim/startup/intro-music", true);
555 } else if ( arg == "--disable-mouse-pointer" ) {
556 fgSetString("/sim/startup/mouse-pointer", "disabled");
557 } else if ( arg == "--enable-mouse-pointer" ) {
558 fgSetString("/sim/startup/mouse-pointer", "enabled");
559 } else if ( arg == "--disable-freeze" ) {
560 fgSetBool("/sim/freeze/master", false);
561 } else if ( arg == "--enable-freeze" ) {
562 fgSetBool("/sim/freeze/master", true);
563 } else if ( arg == "--disable-fuel-freeze" ) {
564 fgSetBool("/sim/freeze/fuel", false);
565 } else if ( arg == "--enable-fuel-freeze" ) {
566 fgSetBool("/sim/freeze/fuel", true);
567 } else if ( arg == "--disable-clock-freeze" ) {
568 fgSetBool("/sim/freeze/clock", false);
569 } else if ( arg == "--enable-clock-freeze" ) {
570 fgSetBool("/sim/freeze/clock", true);
571 } else if ( arg == "--disable-anti-alias-hud" ) {
572 fgSetBool("/sim/hud/antialiased", false);
573 } else if ( arg == "--enable-anti-alias-hud" ) {
574 fgSetBool("/sim/hud/antialiased", true);
575 } else if ( arg.find( "--control=") == 0 ) {
576 fgSetString("/sim/control-mode", arg.substr(10).c_str());
577 } else if ( arg == "--disable-auto-coordination" ) {
578 fgSetBool("/sim/auto-coordination", false);
579 } else if ( arg == "--enable-auto-coordination" ) {
580 fgSetBool("/sim/auto-coordination", true);
581 } else if ( arg.find( "--browser-app=") == 0 ) {
582 fgSetString("/sim/startup/browser-app", arg.substr(14).c_str());
583 } else if ( arg == "--disable-hud" ) {
584 fgSetBool("/sim/hud/visibility", false);
585 } else if ( arg == "--enable-hud" ) {
586 fgSetBool("/sim/hud/visibility", true);
587 } else if ( arg == "--disable-panel" ) {
588 fgSetBool("/sim/panel/visibility", false);
589 } else if ( arg == "--enable-panel" ) {
590 fgSetBool("/sim/panel/visibility", true);
591 } else if ( arg == "--disable-sound" ) {
592 fgSetBool("/sim/sound/audible", false);
593 } else if ( arg == "--enable-sound" ) {
594 fgSetBool("/sim/sound/audible", true);
595 } else if ( arg.find( "--airport-id=") == 0 ) {
596 // NB: changed property name!!!
597 fgSetString("/sim/startup/airport-id", arg.substr(13).c_str());
598 } else if ( arg.find( "--offset-distance=") == 0 ) {
599 fgSetDouble("/sim/startup/offset-distance", atof(arg.substr(18)));
600 } else if ( arg.find( "--offset-azimuth=") == 0 ) {
601 fgSetDouble("/sim/startup/offset-azimuth", atof(arg.substr(17)));
602 } else if ( arg.find( "--lon=" ) == 0 ) {
603 fgSetDouble("/position/longitude-deg",
604 parse_degree(arg.substr(6)));
605 fgSetString("/sim/startup/airport-id", "");
606 } else if ( arg.find( "--lat=" ) == 0 ) {
607 fgSetDouble("/position/latitude-deg",
608 parse_degree(arg.substr(6)));
609 fgSetString("/sim/startup/airport-id", "");
610 } else if ( arg.find( "--altitude=" ) == 0 ) {
611 fgSetBool("/sim/startup/onground", false);
612 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
613 fgSetDouble("/position/altitude-ft", atof(arg.substr(11)));
615 fgSetDouble("/position/altitude-ft",
616 atof(arg.substr(11)) * SG_METER_TO_FEET);
617 } else if ( arg.find( "--uBody=" ) == 0 ) {
618 fgSetString("/sim/startup/speed-set", "UVW");
619 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
620 fgSetDouble("/velocities/uBody-fps", atof(arg.substr(8)));
622 fgSetDouble("/velocities/uBody-fps",
623 atof(arg.substr(8)) * SG_METER_TO_FEET);
624 } else if ( arg.find( "--vBody=" ) == 0 ) {
625 fgSetString("/sim/startup/speed-set", "UVW");
626 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
627 fgSetDouble("/velocities/vBody-fps", atof(arg.substr(8)));
629 fgSetDouble("/velocities/vBody-fps",
630 atof(arg.substr(8)) * SG_METER_TO_FEET);
631 } else if ( arg.find( "--wBody=" ) == 0 ) {
632 fgSetString("/sim/startup/speed-set", "UVW");
633 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
634 fgSetDouble("/velocities/wBody-fps", atof(arg.substr(8)));
636 fgSetDouble("/velocities/wBody-fps",
637 atof(arg.substr(8)) * SG_METER_TO_FEET);
638 } else if ( arg.find( "--vNorth=" ) == 0 ) {
639 fgSetString("/sim/startup/speed-set", "NED");
640 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
641 fgSetDouble("/velocities/speed-north-fps", atof(arg.substr(9)));
643 fgSetDouble("/velocities/speed-north-fps",
644 atof(arg.substr(9)) * SG_METER_TO_FEET);
645 } else if ( arg.find( "--vEast=" ) == 0 ) {
646 fgSetString("/sim/startup/speed-set", "NED");
647 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
648 fgSetDouble("/velocities/speed-east-fps", atof(arg.substr(8)));
650 fgSetDouble("/velocities/speed-east-fps",
651 atof(arg.substr(8)) * SG_METER_TO_FEET);
652 } else if ( arg.find( "--vDown=" ) == 0 ) {
653 fgSetString("/sim/startup/speed-set", "NED");
654 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
655 fgSetDouble("/velocities/speed-down-fps", atof(arg.substr(8)));
657 fgSetDouble("/velocities/speed-down-fps",
658 atof(arg.substr(8)) * SG_METER_TO_FEET);
659 } else if ( arg.find( "--vc=" ) == 0) {
660 fgSetString("/sim/startup/speed-set", "knots");
661 fgSetDouble("/velocities/airspeed-kt", atof(arg.substr(5)));
662 } else if ( arg.find( "--mach=" ) == 0) {
663 fgSetString("/sim/startup/speed-set", "mach");
664 fgSetDouble("/velocities/mach", atof(arg.substr(7)));
665 } else if ( arg.find( "--heading=" ) == 0 ) {
666 fgSetDouble("/orientation/heading-deg", atof(arg.substr(10)));
667 } else if ( arg.find( "--roll=" ) == 0 ) {
668 fgSetDouble("/orientation/roll-deg", atof(arg.substr(7)));
669 } else if ( arg.find( "--pitch=" ) == 0 ) {
670 fgSetDouble("/orientation/pitch-deg", atof(arg.substr(8)));
671 } else if ( arg.find( "--glideslope=" ) == 0 ) {
672 fgSetDouble("/velocities/glideslope", atof(arg.substr(13))
673 *SG_DEGREES_TO_RADIANS);
674 } else if ( arg.find( "--roc=" ) == 0 ) {
675 fgSetDouble("/velocities/vertical-speed-fps", atof(arg.substr(6))/60);
676 } else if ( arg.find( "--fg-root=" ) == 0 ) {
677 globals->set_fg_root(arg.substr( 10 ));
678 } else if ( arg.find( "--fg-scenery=" ) == 0 ) {
679 globals->set_fg_scenery(arg.substr( 13 ));
680 } else if ( arg.find( "--fdm=" ) == 0 ) {
681 fgSetString("/sim/flight-model", arg.substr(6).c_str());
682 } else if ( arg.find( "--aero=" ) == 0 ) {
683 fgSetString("/sim/aero", arg.substr(7).c_str());
684 } else if ( arg.find( "--aircraft-dir=" ) == 0 ) {
685 fgSetString("/sim/aircraft-dir", arg.substr(15).c_str());
686 } else if ( arg.find( "--model-hz=" ) == 0 ) {
687 fgSetInt("/sim/model-hz", atoi(arg.substr(11)));
688 } else if ( arg.find( "--speed=" ) == 0 ) {
689 fgSetInt("/sim/speed-up", atoi(arg.substr(8)));
690 } else if ( arg.find( "--trim") == 0) {
691 fgSetBool("/sim/startup/trim", true);
692 } else if ( arg.find( "--notrim") == 0) {
693 fgSetBool("/sim/startup/trim", false);
694 } else if ( arg.find( "--on-ground") == 0) {
695 fgSetBool("/sim/startup/onground", true);
696 } else if ( arg.find( "--in-air") == 0) {
697 fgSetBool("/sim/startup/onground", false);
698 } else if ( arg == "--fog-disable" ) {
699 fgSetString("/sim/rendering/fog", "disabled");
700 } else if ( arg == "--fog-fastest" ) {
701 fgSetString("/sim/rendering/fog", "fastest");
702 } else if ( arg == "--fog-nicest" ) {
703 fgSetString("/sim/fog", "nicest");
704 } else if ( arg == "--disable-clouds" ) {
705 fgSetBool("/environment/clouds/status", false);
706 } else if ( arg == "--enable-clouds" ) {
707 fgSetBool("/environment/clouds/status", true);
708 } else if ( arg.find( "--fov=" ) == 0 ) {
709 parse_fov( arg.substr(6) );
710 } else if ( arg == "--disable-fullscreen" ) {
711 fgSetBool("/sim/startup/fullscreen", false);
712 } else if ( arg== "--enable-fullscreen") {
713 fgSetBool("/sim/startup/fullscreen", true);
714 } else if ( arg == "--shading-flat") {
715 fgSetBool("/sim/rendering/shading", false);
716 } else if ( arg == "--shading-smooth") {
717 fgSetBool("/sim/rendering/shading", true);
718 } else if ( arg == "--disable-skyblend") {
719 fgSetBool("/sim/rendering/skyblend", false);
720 } else if ( arg== "--enable-skyblend" ) {
721 fgSetBool("/sim/rendering/skyblend", true);
722 } else if ( arg == "--disable-textures" ) {
723 fgSetBool("/sim/rendering/textures", false);
724 } else if ( arg == "--enable-textures" ) {
725 fgSetBool("/sim/rendering/textures", true);
726 } else if ( arg == "--disable-wireframe" ) {
727 fgSetBool("/sim/rendering/wireframe", false);
728 } else if ( arg == "--enable-wireframe" ) {
729 fgSetBool("/sim/rendering/wireframe", true);
730 } else if ( arg.find( "--geometry=" ) == 0 ) {
731 bool geometry_ok = true;
732 int xsize = 0, ysize = 0;
733 string geometry = arg.substr( 11 );
734 string::size_type i = geometry.find('x');
736 if (i != string::npos) {
737 xsize = atoi(geometry.substr(0, i));
738 ysize = atoi(geometry.substr(i+1));
743 if ( xsize <= 0 || ysize <= 0 ) {
749 if ( !geometry_ok ) {
750 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown geometry: " << geometry );
751 SG_LOG( SG_GENERAL, SG_ALERT,
752 "Setting geometry to " << xsize << 'x' << ysize << '\n');
754 SG_LOG( SG_GENERAL, SG_INFO,
755 "Setting geometry to " << xsize << 'x' << ysize << '\n');
756 fgSetInt("/sim/startup/xsize", xsize);
757 fgSetInt("/sim/startup/ysize", ysize);
759 } else if ( arg.find( "--bpp=" ) == 0 ) {
760 string bits_per_pix = arg.substr( 6 );
761 if ( bits_per_pix == "16" ) {
762 fgSetInt("/sim/rendering/bits-per-pixel", 16);
763 } else if ( bits_per_pix == "24" ) {
764 fgSetInt("/sim/rendering/bits-per-pixel", 24);
765 } else if ( bits_per_pix == "32" ) {
766 fgSetInt("/sim/rendering/bits-per-pixel", 32);
768 SG_LOG(SG_GENERAL, SG_ALERT, "Unsupported bpp " << bits_per_pix);
770 } else if ( arg == "--units-feet" ) {
771 fgSetString("/sim/startup/units", "feet");
772 } else if ( arg == "--units-meters" ) {
773 fgSetString("/sim/startup/units", "meters");
774 } else if ( arg.find( "--time-offset" ) == 0 ) {
775 fgSetInt("/sim/startup/time-offset",
776 parse_time_offset( (arg.substr(14)) ));
777 fgSetString("/sim/startup/time-offset-type", "system-offset");
778 } else if ( arg.find( "--time-match-real") == 0 ) {
779 fgSetString("/sim/startup/time-offset-type", "system-offset");
780 } else if ( arg.find( "--time-match-local") == 0 ) {
781 fgSetString("/sim/startup/time-offset-type", "latitude-offset");
782 } else if ( arg.find( "--start-date-sys=") == 0 ) {
783 fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
784 fgSetString("/sim/startup/time-offset-type", "system");
785 } else if ( arg.find( "--start-date-lat=") == 0 ) {
786 fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
787 fgSetString("/sim/startup/time-offset-type", "latitude");
788 } else if ( arg.find( "--start-date-gmt=") == 0 ) {
789 fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
790 fgSetString("/sim/startup/time-offset-type", "gmt");
791 } else if ( arg == "--hud-tris" ) {
792 fgSetString("/sim/hud/frame-stat-type", "tris");
793 } else if ( arg == "--hud-culled" ) {
794 fgSetString("/sim/hud/frame-stat-type", "culled");
795 } else if ( arg.find( "--atc610x" ) == 0 ) {
796 add_channel( "atc610x", "dummy" );
797 } else if ( arg.find( "--atlas=" ) == 0 ) {
798 add_channel( "atlas", arg.substr(8) );
799 } else if ( arg.find( "--httpd=" ) == 0 ) {
800 add_channel( "httpd", arg.substr(8) );
801 #ifdef FG_JPEG_SERVER
802 } else if ( arg.find( "--jpg-httpd=" ) == 0 ) {
803 add_channel( "jpg-httpd", arg.substr(12) );
805 } else if ( arg.find( "--native=" ) == 0 ) {
806 add_channel( "native", arg.substr(9) );
807 } else if ( arg.find( "--native-ctrls=" ) == 0 ) {
808 add_channel( "native_ctrls", arg.substr(15) );
809 } else if ( arg.find( "--native-fdm=" ) == 0 ) {
810 add_channel( "native_fdm", arg.substr(13) );
811 } else if ( arg.find( "--opengc=" ) == 0 ) {
813 // cout << "Adding channel for OpenGC Display" << endl; cin >> stop;
814 add_channel( "opengc", arg.substr(9) );
815 } else if ( arg.find( "--garmin=" ) == 0 ) {
816 add_channel( "garmin", arg.substr(9) );
817 } else if ( arg.find( "--nmea=" ) == 0 ) {
818 add_channel( "nmea", arg.substr(7) );
819 } else if ( arg.find( "--props=" ) == 0 ) {
820 add_channel( "props", arg.substr(8) );
821 } else if ( arg.find( "--telnet=" ) == 0 ) {
822 add_channel( "telnet", arg.substr(9) );
823 } else if ( arg.find( "--pve=" ) == 0 ) {
824 add_channel( "pve", arg.substr(6) );
825 } else if ( arg.find( "--ray=" ) == 0 ) {
826 add_channel( "ray", arg.substr(6) );
827 } else if ( arg.find( "--rul=" ) == 0 ) {
828 add_channel( "rul", arg.substr(6) );
829 } else if ( arg.find( "--joyclient=" ) == 0 ) {
830 add_channel( "joyclient", arg.substr(12) );
831 #ifdef FG_NETWORK_OLK
832 } else if ( arg == "--disable-network-olk" ) {
833 fgSetBool("/sim/networking/olk", false);
834 } else if ( arg== "--enable-network-olk") {
835 fgSetBool("/sim/networking/olk", true);
836 } else if ( arg == "--net-hud" ) {
837 fgSetBool("/sim/hud/net-display", true);
838 net_hud_display = 1; // FIXME
839 } else if ( arg.find( "--net-id=") == 0 ) {
840 fgSetString("sim/networking/call-sign", arg.substr(9).c_str());
842 } else if ( arg.find( "--prop:" ) == 0 ) {
843 string assign = arg.substr(7);
844 unsigned int pos = assign.find('=');
845 if ( pos == arg.npos || pos == 0 ) {
846 SG_LOG( SG_GENERAL, SG_ALERT, "Bad property assignment: " << arg );
847 return FG_OPTIONS_ERROR;
849 string name = assign.substr(0, pos);
850 string value = assign.substr(pos + 1);
851 fgSetString(name.c_str(), value.c_str());
852 // SG_LOG(SG_GENERAL, SG_INFO, "Setting default value of property "
853 // << name << " to \"" << value << '"');
854 } else if ( arg.find("--trace-read=") == 0) {
855 string name = arg.substr(13);
856 SG_LOG(SG_GENERAL, SG_INFO, "Tracing reads for property " << name);
857 fgGetNode(name.c_str(), true)
858 ->setAttribute(SGPropertyNode::TRACE_READ, true);
859 } else if ( arg.find("--trace-write=") == 0) {
860 string name = arg.substr(14);
861 SG_LOG(SG_GENERAL, SG_INFO, "Tracing writes for property " << name);
862 fgGetNode(name.c_str(), true)
863 ->setAttribute(SGPropertyNode::TRACE_WRITE, true);
864 } else if ( arg.find( "--view-offset=" ) == 0 ) {
865 // $$$ begin - added VS Renganathan, 14 Oct 2K
866 // for multi-window outside window imagery
867 string woffset = arg.substr( 14 );
868 double default_view_offset = 0.0;
869 if ( woffset == "LEFT" ) {
870 default_view_offset = SGD_PI * 0.25;
871 } else if ( woffset == "RIGHT" ) {
872 default_view_offset = SGD_PI * 1.75;
873 } else if ( woffset == "CENTER" ) {
874 default_view_offset = 0.00;
876 default_view_offset = atof( woffset.c_str() ) * SGD_DEGREES_TO_RADIANS;
878 FGViewer *pilot_view =
879 (FGViewer *)globals->get_viewmgr()->get_view( 0 );
880 // this will work without calls to the viewer...
881 fgSetDouble( "/sim/current-view/heading-offset-deg",
882 default_view_offset * SGD_RADIANS_TO_DEGREES );
883 // $$$ end - added VS Renganathan, 14 Oct 2K
884 } else if ( arg.find( "--visibility=" ) == 0 ) {
885 fgSetDouble("/environment/visibility-m", atof(arg.substr(13)));
886 } else if ( arg.find( "--visibility-miles=" ) == 0 ) {
887 double visibility = atof(arg.substr(19)) * 5280.0 * SG_FEET_TO_METER;
888 fgSetDouble("/environment/visibility-m", visibility);
889 } else if ( arg.find( "--wind=" ) == 0 ) {
890 string val = arg.substr(7);
891 unsigned int pos = val.find('@');
892 if ( pos == string::npos ) {
893 SG_LOG( SG_GENERAL, SG_ALERT, "bad wind value " << val );
894 return FG_OPTIONS_ERROR;
896 double dir = atof(val.substr(0,pos).c_str());
897 double speed = atof(val.substr(pos+1).c_str());
898 SG_LOG(SG_GENERAL, SG_INFO, "WIND: " << dir << '@' <<
899 speed << " knots" << endl);
900 fgSetDouble("/environment/wind-from-heading-deg", dir);
901 fgSetDouble("/environment/wind-speed-kt", speed);
905 speed *= SG_NM_TO_METER * SG_METER_TO_FEET * (1.0/3600);
910 dir *= SGD_DEGREES_TO_RADIANS;
911 fgSetDouble("/environment/wind-from-north-fps",
913 fgSetDouble("/environment/wind-from-east-fps",
915 #endif // FG_WEATHERCM
916 } else if ( arg.find( "--wp=" ) == 0 ) {
917 parse_wp( arg.substr( 5 ) );
918 } else if ( arg.find( "--flight-plan=") == 0) {
919 parse_flightplan ( arg.substr (14) );
920 } else if ( arg.find( "--config=" ) == 0 ) {
921 string file = arg.substr(9);
923 readProperties(file, globals->get_props());
924 } catch (const sg_exception &e) {
925 string message = "Error loading config file: ";
926 message += e.getFormattedMessage();
927 SG_LOG(SG_INPUT, SG_ALERT, message);
930 } else if ( arg.find( "--aircraft=" ) == 0 ) {
931 // read in the top level aircraft definition file
932 SGPath apath( globals->get_fg_root() );
933 apath.append( "Aircraft" );
934 apath.append( arg.substr(11) );
935 apath.concat( "-set.xml" );
936 SG_LOG(SG_INPUT, SG_INFO, "Reading aircraft: " << arg.substr(11)
937 << " from " << apath.str());
938 readProperties( apath.str(), globals->get_props() );
940 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
941 return FG_OPTIONS_ERROR;
944 return FG_OPTIONS_OK;
948 // Scan the command line options for an fg_root definition and set
951 fgScanForRoot (int argc, char **argv)
955 SG_LOG(SG_GENERAL, SG_INFO, "Scanning for root: command line");
958 SG_LOG( SG_GENERAL, SG_DEBUG, "argv[" << i << "] = " << argv[i] );
960 string arg = argv[i];
961 if ( arg.find( "--fg-root=" ) == 0 ) {
962 return arg.substr( 10 );
972 // Scan the config file for an fg_root definition and set just that.
974 fgScanForRoot (const string& path)
976 sg_gzifstream in( path );
980 SG_LOG( SG_GENERAL, SG_INFO, "Scanning for root: " << path );
984 while ( ! in.eof() ) {
987 while ( in.get(c) && c != '\0' ) {
992 #if defined( macintosh )
993 getline( in, line, '\r' );
995 getline( in, line, '\n' );
998 // catch extraneous (DOS) line ending character
999 if ( line[line.length() - 1] < 32 ) {
1000 line = line.substr( 0, line.length()-1 );
1003 if ( line.find( "--fg-root=" ) == 0 ) {
1004 return line.substr( 10 );
1014 // Parse the command line options
1016 fgParseArgs (int argc, char **argv)
1018 bool in_options = true;
1020 SG_LOG(SG_GENERAL, SG_INFO, "Processing command line arguments");
1022 for (int i = 1; i < argc; i++) {
1023 string arg = argv[i];
1025 if (in_options && (arg.find('-') == 0)) {
1029 int result = parse_option(arg);
1030 if ( (result == FG_OPTIONS_HELP) ||
1031 (result == FG_OPTIONS_ERROR) ) {
1038 SG_LOG(SG_GENERAL, SG_INFO,
1039 "Reading command-line property file " << arg);
1040 readProperties(arg, globals->get_props());
1044 SG_LOG(SG_GENERAL, SG_INFO, "Finished command line arguments");
1048 // Parse config file options
1050 fgParseOptions (const string& path) {
1051 sg_gzifstream in( path );
1052 if ( !in.is_open() ) {
1056 SG_LOG( SG_GENERAL, SG_INFO, "Processing config file: " << path );
1060 while ( ! in.eof() ) {
1063 while ( in.get(c) && c != '\0' ) {
1068 #if defined( macintosh )
1069 getline( in, line, '\r' );
1071 getline( in, line, '\n' );
1074 // catch extraneous (DOS) line ending character
1075 if ( line[line.length() - 1] < 32 ) {
1076 line = line.substr( 0, line.length()-1 );
1079 if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
1080 SG_LOG( SG_GENERAL, SG_ALERT,
1081 "Config file parse error: " << path << " '"
1091 // Print usage message
1095 cout << "Usage: fgfs [ option ... ]" << endl
1098 << "General Options:" << endl
1099 << " --help, -h Print usage" << endl
1100 << " --fg-root=path Specify the root data path" << endl
1101 << " --fg-scenery=path Specify the base scenery path;" << endl
1102 << " Defaults to $FG_ROOT/Scenery" << endl
1103 << " --disable-game-mode Disable full-screen game mode" << endl
1104 << " --enable-game-mode Enable full-screen game mode" << endl
1105 << " --disable-splash-screen Disable splash screen" << endl
1106 << " --enable-splash-screen Enable splash screen" << endl
1107 << " --disable-intro-music Disable introduction music" << endl
1108 << " --enable-intro-music Enable introduction music" << endl
1109 << " --disable-mouse-pointer Disable extra mouse pointer" << endl
1110 << " --enable-mouse-pointer Enable extra mouse pointer (i.e. for full-" << endl
1111 << " screen Voodoo based cards)" << endl
1112 << " --disable-freeze Start in a running state" << endl
1113 << " --enable-freeze Start in a frozen state" << endl
1114 << " --disable-fuel-freeze Fuel is consumed normally" << endl
1115 << " --enable-fuel-freeze Fuel tank quantity forced to remain constant" << endl
1116 << " --disable-clock-freeze Clock advances normally" << endl
1117 << " --enable-clock-freeze Do not advance clock" << endl
1118 << " --control=mode Primary control mode (joystick, keyboard," << endl
1119 << " mouse)" << endl
1120 << " --enable-auto-coordination Enable auto coordination" << endl
1121 << " --disable-auto-coordination Disable auto coordination" << endl
1122 << " --browser-app=path Specify path to your web browser" << endl
1123 << " --prop:name=value Set property <name> to <value>" << endl
1124 << " --config=path Load additional properties from path" << endl
1125 << " --units-feet Use feet for distances" << endl
1126 << " --units-meters Use meters for distances" << endl
1129 << "Features:" << endl
1130 << " --disable-hud Disable Heads Up Display (HUD)" << endl
1131 << " --enable-hud Enable Heads Up Display (HUD)" << endl
1132 << " --disable-panel Disable instrument panel" << endl
1133 << " --enable-panel Enable instrument panel" << endl
1134 << " --disable-sound Disable sound effects" << endl
1135 << " --enable-sound Enable sound effects" << endl
1136 << " --disable-anti-alias-hud Disable anti-aliased HUD" << endl
1137 << " --enable-anti-alias-hud Enable anti-aliased HUD" << endl
1140 << "Aircraft:" <<endl
1141 << " --aircraft=name Select an aircraft profile as defined by a" << endl
1142 << " top level <name>-set.xml" << endl
1145 << "Flight Model:" << endl
1146 << " --fdm=name Select the core flight dynamics model" << endl
1147 << " Can be one of jsb, larcsim, yasim, magic," << endl
1148 << " balloon, ada, external, or null" << endl
1149 << " --aero=name Select aircraft aerodynamics model to load" << endl
1150 << " --model-hz=n Run the FDM this rate (iterations per" << endl
1151 << " second)" << endl
1152 << " --speed=n Run the FDM 'n' times faster than real time" << endl
1153 << " --notrim Do NOT attempt to trim the model (only with" << endl
1154 << " fdm=jsbsim)" << endl
1155 << " --on-ground Start at ground level (default)" << endl
1156 << " --in-air Start in air (implied when using --altitude)" << endl
1157 << " --wind=DIR@SPEED Specify wind coming from DIR (degrees) at" << endl
1158 << " SPEED (knots)" << endl
1161 << "Aircraft model directory (UIUC FDM ONLY):" << endl
1162 << " --aircraft-dir=path Aircraft directory relative to the path of" << endl
1163 << " the executable" << endl
1166 << "Initial Position and Orientation:" << endl
1167 << " --airport-id=ID Specify starting position by airport ID" << endl
1168 << " --offset-distance=nm Specify distance to threshold" << endl
1169 << " --offset-azimuth=degrees Specify heading to threshold" << endl
1170 << " --lon=degrees Starting longitude (west = -)" << endl
1171 << " --lat=degrees Starting latitude (south = -)" << endl
1172 << " --altitude=value Starting altitude (in feet unless" << endl
1173 << " --units-meters specified)" << endl
1174 << " --heading=degrees Specify heading (yaw) angle (Psi)" << endl
1175 << " --roll=degrees Specify roll angle (Phi)" << endl
1176 << " --pitch=degrees Specify pitch angle (Theta)" << endl
1177 << " --uBody=units_per_sec Specify velocity along the body X axis" << endl
1178 << " (in feet unless --units-meters specified)" << endl
1179 << " --vBody=units_per_sec Specify velocity along the body Y axis" << endl
1180 << " (in feet unless --units-meters specified)" << endl
1181 << " --wBody=units_per_sec Specify velocity along the body Z axis" << endl
1182 << " (in feet unless --units-meters specified)" << endl
1183 << " --vc=knots Specify initial airspeed" << endl
1184 << " --mach=num Specify initial mach number" << endl
1185 << " --glideslope=degreees Specify flight path angle (can be positive)" << endl
1186 << " --roc=fpm Specify initial climb rate (can be negative)" << endl
1189 << "Rendering Options:" << endl
1190 << " --bpp=depth Specify the bits per pixel" << endl
1191 << " --fog-disable Disable fog/haze" << endl
1192 << " --fog-fastest Enable fastest fog/haze" << endl
1193 << " --fog-nicest Enable nicest fog/haze" << endl
1194 << " --enable-clouds Enable cloud layers" << endl
1195 << " --disable-clouds Disable cloud layers" << endl
1197 << " --fov=degrees Specify field of view angle" << endl
1198 << " --disable-fullscreen Disable fullscreen mode" << endl
1199 << " --enable-fullscreen Enable fullscreen mode" << endl
1200 << " --shading-flat Enable flat shading" << endl
1201 << " --shading-smooth Enable smooth shading" << endl
1202 << " --disable-skyblend Disable sky blending" << endl
1203 << " --enable-skyblend Enable sky blending" << endl
1204 << " --disable-textures Disable textures" << endl
1205 << " --enable-textures Enable textures" << endl
1206 << " --disable-wireframe Disable wireframe drawing mode" << endl
1207 << " --enable-wireframe Enable wireframe drawing mode" << endl
1208 << " --geometry=WxH Specify window geometry (640x480, etc)" << endl
1209 << " --view-offset=value Specify the default forward view direction" << endl
1210 << " as an offset from straight ahead. Allowable" << endl
1211 << " values are LEFT, RIGHT, CENTER, or a specific" << endl
1212 << " number in degrees" << endl
1213 << " --visibility=meters Specify initial visibility" << endl
1214 << " --visibility-miles=miles Specify initial visibility in miles" << endl
1217 << "Hud Options:" << endl
1218 << " --hud-tris Hud displays number of triangles rendered" << endl
1219 << " --hud-culled Hud displays percentage of triangles culled" << endl
1222 << "Time Options:" << endl
1223 << " --time-offset=[+-]hh:mm:ss Add this time offset" << endl
1224 << " --time-match-real Synchronize time with real-world time" << endl
1225 << " --time-match-local Synchronize time with local real-world time" << endl
1226 << " --start-date-sys=yyyy:mm:dd:hh:mm:ss" << endl
1227 << " Specify a starting date/time with respect to" << endl
1228 << " system time" << endl
1229 << " --start-date-gmt=yyyy:mm:dd:hh:mm:ss" << endl
1230 << " Specify a starting date/time with respect to" << endl
1231 << " Greenwich Mean Time" << endl
1232 << " --start-date-lat=yyyy:mm:dd:hh:mm:ss" << endl
1233 << " Specify a starting date/time with respect to" << endl
1234 << " Local Aircraft Time" << endl
1237 << "Network Options:" << endl
1238 << " --httpd=port Enable http server on the specified port" << endl
1239 << " --telnet=port Enable telnet server on the specified port" << endl
1240 #ifdef FG_JPEG_SERVER
1241 << " --jpg-httpd=port Enable screen shot http server on the" << endl
1242 << " specified port" << endl
1244 #ifdef FG_NETWORK_OLK
1245 << " --disable-network-olk Disable Multipilot mode (default)" << endl
1246 << " --enable-network-olk Enable Multipilot mode" << endl
1247 << " --net-hud Hud displays network info" << endl
1248 << " --net-id=name Specify your own callsign" << endl
1252 << "Route/Way Point Options:" << endl
1253 << " --wp=ID[@alt] Specify a waypoint for the GC autopilot;" << endl
1254 << " multiple instances can be used to create a" << endl
1256 << " --flight-plan=file Read all waypoints from a file" << endl
1259 << "IO Options:" << endl
1260 << " --gamin=params Open connection using the Garmin GPS protocol" << endl
1261 << " --joyclient=params Open connection to an Agwagon joystick" << endl
1262 << " --native-ctrls=params Open connection using the FG Native Controls" << endl
1263 << " protocol" << endl
1264 << " --native-fdm=params Open connection using the FG Native FDM" << endl
1265 << " protocol" << endl
1266 << " --native=params Open connection using the FG Native protocol" << endl
1267 << " --nmea=params Open connection using the NMEA protocol" << endl
1268 << " --opengc=params Open connection using the OpenGC protocol" << endl
1269 << " --props=params Open connection using the interactive" << endl
1270 << " property manager" << endl
1271 << " --pve=params Open connection using the PVE protocol" << endl
1272 << " --ray=params Open connection using the RayWoodworth" << endl
1273 << " motion chair protocol" << endl
1274 << " --rul=params Open connection using the RUL protocol" << endl
1276 << " --atc610x Enable atc610x interface." << endl
1279 << "Debugging Options:" << endl
1280 << " --trace-read=property Trace the reads for a property; multiple" << endl
1281 << " instances allowed." << endl
1282 << " --trace-write=property Trace the writes for a property; multiple" << endl
1283 << " instances allowed." << endl