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()
40 #include <simgear/math/sg_random.h>
41 #include <simgear/misc/sgstream.hxx>
42 #include <simgear/misc/sg_path.hxx>
43 #include <simgear/route/route.hxx>
44 #include <simgear/route/waypoint.hxx>
46 // #include <Include/general.hxx>
47 // #include <Airports/simple.hxx>
48 // #include <Cockpit/cockpit.hxx>
49 // #include <FDM/flight.hxx>
50 // #include <FDM/UIUCModel/uiuc_aircraftdir.h>
52 # include <NetworkOLK/network.h>
57 #include "globals.hxx"
58 #include "fg_init.hxx"
59 #include "fg_props.hxx"
60 #include "options.hxx"
61 #include "viewmgr.hxx"
63 // Hack: from main.cxx
64 extern SGPropertyNode *fgInitLocale(const char *);
67 SG_USING_NAMESPACE(std);
70 #define NEW_DEFAULT_MODEL_HZ 120
77 FG_OPTIONS_VERBOSE_HELP = 3,
78 FG_OPTIONS_SHOW_AIRCRAFT = 4
82 atof( const string& str )
86 // -dw- if ::atof is called, then we get an infinite loop
87 return std::atof( str.c_str() );
89 return ::atof( str.c_str() );
94 atoi( const string& str )
97 // -dw- if ::atoi is called, then we get an infinite loop
98 return std::atoi( str.c_str() );
100 return ::atoi( str.c_str() );
106 * Set a few fail-safe default property values.
108 * These should all be set in $FG_ROOT/preferences.xml, but just
109 * in case, we provide some initial sane values here. This method
110 * should be invoked *before* reading any init files.
115 // set a possibly independent location for scenery data
116 char *envp = ::getenv( "FG_SCENERY" );
118 if ( envp != NULL ) {
119 // fg_root could be anywhere, so default to environmental
120 // variable $FG_ROOT if it is set.
121 globals->set_fg_scenery(envp);
123 // Otherwise, default to Scenery being in $FG_ROOT/Scenery
124 globals->set_fg_scenery("");
126 // Position (deliberately out of range)
127 fgSetDouble("/position/longitude-deg", 9999.0);
128 fgSetDouble("/position/latitude-deg", 9999.0);
129 fgSetDouble("/position/altitude-ft", -9999.0);
132 fgSetDouble("/orientation/heading-deg", 270);
133 fgSetDouble("/orientation/roll-deg", 0);
134 fgSetDouble("/orientation/pitch-deg", 0.424);
137 fgSetString("/sim/startup/speed-set", "knots");
138 fgSetDouble("/velocities/uBody-fps", 0.0);
139 fgSetDouble("/velocities/vBody-fps", 0.0);
140 fgSetDouble("/velocities/wBody-fps", 0.0);
141 fgSetDouble("/velocities/speed-north-fps", 0.0);
142 fgSetDouble("/velocities/speed-east-fps", 0.0);
143 fgSetDouble("/velocities/speed-down-fps", 0.0);
144 fgSetDouble("/velocities/airspeed-kt", 0.0);
145 fgSetDouble("/velocities/mach", 0.0);
148 fgSetBool("/sim/startup/game-mode", false);
149 fgSetBool("/sim/startup/splash-screen", true);
150 fgSetBool("/sim/startup/intro-music", true);
151 // we want mouse-pointer to have an undefined value if nothing is
152 // specified so we can do the right thing for voodoo-1/2 cards.
153 // fgSetString("/sim/startup/mouse-pointer", "disabled");
154 fgSetString("/sim/control-mode", "joystick");
155 fgSetBool("/sim/auto-coordination", false);
157 fgSetString("/sim/startup/browser-app", "netscape");
159 fgSetString("/sim/startup/browser-app", "webrun.bat");
162 fgSetBool("/sim/hud/visibility", false);
163 fgSetBool("/sim/panel/visibility", true);
164 fgSetBool("/sim/sound/audible", true);
165 fgSetBool("/sim/hud/antialiased", false);
167 // Flight Model options
168 fgSetString("/sim/flight-model", "jsb");
169 fgSetString("/sim/aero", "c172");
170 fgSetInt("/sim/model-hz", NEW_DEFAULT_MODEL_HZ);
171 fgSetInt("/sim/speed-up", 1);
172 fgSetBool("/sim/startup/trim", false);
173 fgSetBool("/sim/startup/onground", true);
176 fgSetString("/sim/rendering/fog", "nicest");
177 fgSetBool("/environment/clouds/status", true);
178 fgSetBool("/sim/startup/fullscreen", false);
179 fgSetBool("/sim/rendering/shading", true);
180 fgSetBool("/sim/rendering/skyblend", true);
181 fgSetBool("/sim/rendering/textures", true);
182 fgSetBool("/sim/rendering/wireframe", false);
183 fgSetInt("/sim/startup/xsize", 800);
184 fgSetInt("/sim/startup/ysize", 600);
185 fgSetInt("/sim/rendering/bits-per-pixel", 16);
186 fgSetString("/sim/view-mode", "pilot");
187 fgSetDouble("/sim/current-view/heading-offset-deg", 0);
188 fgSetDouble("/environment/visibility-m", 20000);
191 fgSetString("/sim/startup/units", "feet");
192 fgSetString("/sim/hud/frame-stat-type", "tris");
195 fgSetInt("/sim/startup/time-offset", 0);
196 fgSetString("/sim/startup/time-offset-type", "system-offset");
197 fgSetLong("/sim/time/cur-time-override", 0);
199 fgSetBool("/sim/networking/network-olk", false);
200 fgSetString("/sim/networking/call-sign", "Johnny");
203 fgSetBool("/sim/freeze/master", false);
204 fgSetBool("/sim/freeze/position", false);
205 fgSetBool("/sim/freeze/clock", false);
206 fgSetBool("/sim/freeze/fuel", false);
211 parse_wind (const string &wind, double * min_hdg, double * max_hdg,
212 double * speed, double * gust)
214 string::size_type pos = wind.find('@');
215 if (pos == string::npos)
217 string dir = wind.substr(0, pos);
218 string spd = wind.substr(pos+1);
220 if (pos == string::npos) {
221 *min_hdg = *max_hdg = atof(dir.c_str());
223 *min_hdg = atof(dir.substr(0,pos).c_str());
224 *max_hdg = atof(dir.substr(pos+1).c_str());
227 if (pos == string::npos) {
228 *speed = *gust = atof(spd.c_str());
230 *speed = atof(spd.substr(0,pos).c_str());
231 *gust = atof(spd.substr(pos+1).c_str());
236 // parse a time string ([+/-]%f[:%f[:%f]]) into hours
238 parse_time(const string& time_in) {
239 char *time_str, num[256];
240 double hours, minutes, seconds;
245 time_str = (char *)time_in.c_str();
247 // printf("parse_time(): %s\n", time_str);
250 if ( strlen(time_str) ) {
251 if ( time_str[0] == '+' ) {
254 } else if ( time_str[0] == '-' ) {
259 // printf("sign = %d\n", sign);
262 if ( strlen(time_str) ) {
264 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
265 num[i] = time_str[0];
269 if ( time_str[0] == ':' ) {
274 // printf("hours = %.2lf\n", hours);
280 if ( strlen(time_str) ) {
282 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
283 num[i] = time_str[0];
287 if ( time_str[0] == ':' ) {
292 // printf("minutes = %.2lf\n", minutes);
294 result += minutes / 60.0;
298 if ( strlen(time_str) ) {
300 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
301 num[i] = time_str[0];
307 // printf("seconds = %.2lf\n", seconds);
309 result += seconds / 3600.0;
312 return(sign * result);
316 // parse a date string (yyyy:mm:dd:hh:mm:ss) into a time_t (seconds)
318 parse_date( const string& date)
321 char * date_str, num[256];
323 // initialize to zero
330 gmt.tm_isdst = 0; // ignore daylight savings time for the moment
331 date_str = (char *)date.c_str();
333 if ( strlen(date_str) ) {
335 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
336 num[i] = date_str[0];
340 if ( date_str[0] == ':' ) {
344 gmt.tm_year = atoi(num) - 1900;
347 if ( strlen(date_str) ) {
349 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
350 num[i] = date_str[0];
354 if ( date_str[0] == ':' ) {
358 gmt.tm_mon = atoi(num) -1;
361 if ( strlen(date_str) ) {
363 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
364 num[i] = date_str[0];
368 if ( date_str[0] == ':' ) {
372 gmt.tm_mday = atoi(num);
375 if ( strlen(date_str) ) {
377 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
378 num[i] = date_str[0];
382 if ( date_str[0] == ':' ) {
386 gmt.tm_hour = atoi(num);
389 if ( strlen(date_str) ) {
391 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
392 num[i] = date_str[0];
396 if ( date_str[0] == ':' ) {
400 gmt.tm_min = atoi(num);
403 if ( strlen(date_str) ) {
405 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
406 num[i] = date_str[0];
410 if ( date_str[0] == ':' ) {
414 gmt.tm_sec = atoi(num);
416 time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
417 gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
418 //printf ("Date is %s\n", ctime(&theTime));
419 //printf ("in seconds that is %d\n", theTime);
425 // parse angle in the form of [+/-]ddd:mm:ss into degrees
427 parse_degree( const string& degree_str) {
428 double result = parse_time( degree_str );
430 // printf("Degree = %.4f\n", result);
436 // parse time offset string into seconds
438 parse_time_offset( const string& time_str) {
441 // printf("time offset = %s\n", time_str);
444 result = (int)rint(parse_time(time_str) * 3600.0);
446 result = (int)(parse_time(time_str) * 3600.0);
449 // printf("parse_time_offset(): %d\n", result);
455 // Parse --fov=x.xx type option
457 parse_fov( const string& arg ) {
458 double fov = atof(arg);
460 if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
461 if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
463 fgSetDouble("/sim/current-view/field-of-view", fov);
465 // printf("parse_fov(): result = %.4f\n", fov);
471 // Parse I/O channel option
473 // Format is "--protocol=medium,direction,hz,medium_options,..."
475 // protocol = { native, nmea, garmin, fgfs, rul, pve, etc. }
476 // medium = { serial, socket, file, etc. }
477 // direction = { in, out, bi }
478 // hz = number of times to process channel per second (floating
479 // point values are ok.
481 // Serial example "--nmea=serial,dir,hz,device,baud" where
483 // device = OS device name of serial line to be open()'ed
484 // baud = {300, 1200, 2400, ..., 230400}
486 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
488 // machine = machine name or ip address if client (leave empty if server)
489 // port = port, leave empty to let system choose
490 // style = tcp or udp
492 // File example "--garmin=file,dir,hz,filename" where
494 // filename = file system file name
497 add_channel( const string& type, const string& channel_str ) {
498 // cout << "Channel string = " << channel_str << endl;
500 globals->get_channel_options_list()->push_back( type + "," + channel_str );
507 setup_wind (double min_hdg, double max_hdg, double speed, double gust)
509 fgSetDouble("/environment/wind-from-heading-deg", min_hdg);
510 fgSetDouble("/environment/params/min-wind-from-heading-deg", min_hdg);
511 fgSetDouble("/environment/params/max-wind-from-heading-deg", max_hdg);
512 fgSetDouble("/environment/wind-speed-kt", speed);
513 fgSetDouble("/environment/params/base-wind-speed-kt", speed);
514 fgSetDouble("/environment/params/gust-wind-speed-kt", gust);
516 SG_LOG(SG_GENERAL, SG_INFO, "WIND: " << min_hdg << '@' <<
517 speed << " knots" << endl);
521 speed *= SG_NM_TO_METER * SG_METER_TO_FEET * (1.0/3600);
522 while (min_hdg > 360)
526 min_hdg *= SGD_DEGREES_TO_RADIANS;
527 fgSetDouble("/environment/wind-from-north-fps", speed * cos(dir));
528 fgSetDouble("/environment/wind-from-east-fps", speed * sin(dir));
529 #endif // FG_WEATHERCM
533 // Parse --wp=ID[@alt]
535 parse_wp( const string& arg ) {
539 string::size_type pos = arg.find( "@" );
540 if ( pos != string::npos ) {
541 id = arg.substr( 0, pos );
542 alt_str = arg.substr( pos + 1 );
543 // cout << "id str = " << id << " alt str = " << alt_str << endl;
544 alt = atof( alt_str.c_str() );
545 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") ) {
546 alt *= SG_FEET_TO_METER;
553 if ( fgFindAirportID( id, &a ) ) {
554 SGWayPoint wp( a.longitude, a.latitude, alt, SGWayPoint::WGS84, id );
555 globals->get_route()->add_waypoint( wp );
564 // Parse --flight-plan=[file]
566 parse_flightplan(const string& arg)
568 sg_gzifstream in(arg.c_str());
569 if ( !in.is_open() ) {
575 #if defined( macintosh )
576 getline( in, line, '\r' );
578 getline( in, line, '\n' );
581 // catch extraneous (DOS) line ending character
582 if ( line[line.length() - 1] < 32 ) {
583 line = line.substr( 0, line.length()-1 );
596 // Parse a single option
598 parse_option (const string& arg)
601 if ( (arg == "--help") || (arg == "-h") ) {
602 // help/usage request
603 return(FG_OPTIONS_HELP);
604 } else if ( (arg == "--verbose") || (arg == "-v") ) {
605 // verbose help/usage request
606 return(FG_OPTIONS_VERBOSE_HELP);
607 } else if ( arg.find( "--language=") == 0 ) {
608 globals->set_locale( fgInitLocale( arg.substr( 11 ).c_str() ) );
609 } else if ( arg == "--disable-game-mode") {
610 fgSetBool("/sim/startup/game-mode", false);
611 } else if ( arg == "--enable-game-mode" ) {
612 fgSetBool("/sim/startup/game-mode", true);
613 } else if ( arg == "--disable-splash-screen" ) {
614 fgSetBool("/sim/startup/splash-screen", false);
615 } else if ( arg == "--enable-splash-screen" ) {
616 fgSetBool("/sim/startup/splash-screen", true);
617 } else if ( arg == "--disable-intro-music" ) {
618 fgSetBool("/sim/startup/intro-music", false);
619 } else if ( arg == "--enable-intro-music" ) {
620 fgSetBool("/sim/startup/intro-music", true);
621 } else if ( arg == "--disable-mouse-pointer" ) {
622 fgSetString("/sim/startup/mouse-pointer", "disabled");
623 } else if ( arg == "--enable-mouse-pointer" ) {
624 fgSetString("/sim/startup/mouse-pointer", "enabled");
625 } else if ( arg == "--disable-random-objects" ) {
626 fgSetBool("/sim/rendering/random-objects", false);
627 } else if ( arg == "--enable-random-objects" ) {
628 fgSetBool("/sim/rendering/random-objects", true);
629 } else if ( arg == "--disable-freeze" ) {
630 fgSetBool("/sim/freeze/master", false);
631 } else if ( arg == "--enable-freeze" ) {
632 fgSetBool("/sim/freeze/master", true);
633 } else if ( arg == "--disable-fuel-freeze" ) {
634 fgSetBool("/sim/freeze/fuel", false);
635 } else if ( arg == "--enable-fuel-freeze" ) {
636 fgSetBool("/sim/freeze/fuel", true);
637 } else if ( arg == "--disable-clock-freeze" ) {
638 fgSetBool("/sim/freeze/clock", false);
639 } else if ( arg == "--enable-clock-freeze" ) {
640 fgSetBool("/sim/freeze/clock", true);
641 } else if ( arg == "--disable-anti-alias-hud" ) {
642 fgSetBool("/sim/hud/antialiased", false);
643 } else if ( arg == "--enable-anti-alias-hud" ) {
644 fgSetBool("/sim/hud/antialiased", true);
645 } else if ( arg.find( "--control=") == 0 ) {
646 fgSetString("/sim/control-mode", arg.substr(10).c_str());
647 } else if ( arg == "--disable-auto-coordination" ) {
648 fgSetBool("/sim/auto-coordination", false);
649 } else if ( arg == "--enable-auto-coordination" ) {
650 fgSetBool("/sim/auto-coordination", true);
651 } else if ( arg.find( "--browser-app=") == 0 ) {
652 fgSetString("/sim/startup/browser-app", arg.substr(14).c_str());
653 } else if ( arg == "--disable-hud" ) {
654 fgSetBool("/sim/hud/visibility", false);
655 } else if ( arg == "--enable-hud" ) {
656 fgSetBool("/sim/hud/visibility", true);
657 } else if ( arg == "--disable-panel" ) {
658 fgSetBool("/sim/panel/visibility", false);
659 } else if ( arg == "--enable-panel" ) {
660 fgSetBool("/sim/panel/visibility", true);
661 } else if ( arg == "--disable-sound" ) {
662 fgSetBool("/sim/sound/audible", false);
663 } else if ( arg == "--enable-sound" ) {
664 fgSetBool("/sim/sound/audible", true);
665 } else if ( arg.find( "--airport-id=") == 0 ) {
666 // NB: changed property name!!!
667 fgSetString("/sim/startup/airport-id", arg.substr(13).c_str());
668 } else if ( arg.find( "--offset-distance=") == 0 ) {
669 fgSetDouble("/sim/startup/offset-distance", atof(arg.substr(18)));
670 } else if ( arg.find( "--offset-azimuth=") == 0 ) {
671 fgSetDouble("/sim/startup/offset-azimuth", atof(arg.substr(17)));
672 } else if ( arg.find( "--lon=" ) == 0 ) {
673 fgSetDouble("/position/longitude-deg",
674 parse_degree(arg.substr(6)));
675 fgSetString("/sim/startup/airport-id", "");
676 } else if ( arg.find( "--lat=" ) == 0 ) {
677 fgSetDouble("/position/latitude-deg",
678 parse_degree(arg.substr(6)));
679 fgSetString("/sim/startup/airport-id", "");
680 } else if ( arg.find( "--altitude=" ) == 0 ) {
681 fgSetBool("/sim/startup/onground", false);
682 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
683 fgSetDouble("/position/altitude-ft", atof(arg.substr(11)));
685 fgSetDouble("/position/altitude-ft",
686 atof(arg.substr(11)) * SG_METER_TO_FEET);
687 } else if ( arg.find( "--uBody=" ) == 0 ) {
688 fgSetString("/sim/startup/speed-set", "UVW");
689 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
690 fgSetDouble("/velocities/uBody-fps", atof(arg.substr(8)));
692 fgSetDouble("/velocities/uBody-fps",
693 atof(arg.substr(8)) * SG_METER_TO_FEET);
694 } else if ( arg.find( "--vBody=" ) == 0 ) {
695 fgSetString("/sim/startup/speed-set", "UVW");
696 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
697 fgSetDouble("/velocities/vBody-fps", atof(arg.substr(8)));
699 fgSetDouble("/velocities/vBody-fps",
700 atof(arg.substr(8)) * SG_METER_TO_FEET);
701 } else if ( arg.find( "--wBody=" ) == 0 ) {
702 fgSetString("/sim/startup/speed-set", "UVW");
703 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
704 fgSetDouble("/velocities/wBody-fps", atof(arg.substr(8)));
706 fgSetDouble("/velocities/wBody-fps",
707 atof(arg.substr(8)) * SG_METER_TO_FEET);
708 } else if ( arg.find( "--vNorth=" ) == 0 ) {
709 fgSetString("/sim/startup/speed-set", "NED");
710 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
711 fgSetDouble("/velocities/speed-north-fps", atof(arg.substr(9)));
713 fgSetDouble("/velocities/speed-north-fps",
714 atof(arg.substr(9)) * SG_METER_TO_FEET);
715 } else if ( arg.find( "--vEast=" ) == 0 ) {
716 fgSetString("/sim/startup/speed-set", "NED");
717 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
718 fgSetDouble("/velocities/speed-east-fps", atof(arg.substr(8)));
720 fgSetDouble("/velocities/speed-east-fps",
721 atof(arg.substr(8)) * SG_METER_TO_FEET);
722 } else if ( arg.find( "--vDown=" ) == 0 ) {
723 fgSetString("/sim/startup/speed-set", "NED");
724 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
725 fgSetDouble("/velocities/speed-down-fps", atof(arg.substr(8)));
727 fgSetDouble("/velocities/speed-down-fps",
728 atof(arg.substr(8)) * SG_METER_TO_FEET);
729 } else if ( arg.find( "--vc=" ) == 0) {
730 fgSetString("/sim/startup/speed-set", "knots");
731 fgSetDouble("/velocities/airspeed-kt", atof(arg.substr(5)));
732 } else if ( arg.find( "--mach=" ) == 0) {
733 fgSetString("/sim/startup/speed-set", "mach");
734 fgSetDouble("/velocities/mach", atof(arg.substr(7)));
735 } else if ( arg.find( "--heading=" ) == 0 ) {
736 fgSetDouble("/orientation/heading-deg", atof(arg.substr(10)));
737 } else if ( arg.find( "--roll=" ) == 0 ) {
738 fgSetDouble("/orientation/roll-deg", atof(arg.substr(7)));
739 } else if ( arg.find( "--pitch=" ) == 0 ) {
740 fgSetDouble("/orientation/pitch-deg", atof(arg.substr(8)));
741 } else if ( arg.find( "--glideslope=" ) == 0 ) {
742 fgSetDouble("/velocities/glideslope", atof(arg.substr(13))
743 *SG_DEGREES_TO_RADIANS);
744 } else if ( arg.find( "--roc=" ) == 0 ) {
745 fgSetDouble("/velocities/vertical-speed-fps", atof(arg.substr(6))/60);
746 } else if ( arg.find( "--fg-root=" ) == 0 ) {
747 globals->set_fg_root(arg.substr( 10 ));
748 } else if ( arg.find( "--fg-scenery=" ) == 0 ) {
749 globals->set_fg_scenery(arg.substr( 13 ));
750 } else if ( arg.find( "--fdm=" ) == 0 ) {
751 fgSetString("/sim/flight-model", arg.substr(6).c_str());
752 } else if ( arg.find( "--aero=" ) == 0 ) {
753 fgSetString("/sim/aero", arg.substr(7).c_str());
754 } else if ( arg.find( "--aircraft-dir=" ) == 0 ) {
755 fgSetString("/sim/aircraft-dir", arg.substr(15).c_str());
756 } else if ( arg.find( "--show-aircraft") == 0) {
757 return(FG_OPTIONS_SHOW_AIRCRAFT);
758 } else if ( arg.find( "--model-hz=" ) == 0 ) {
759 fgSetInt("/sim/model-hz", atoi(arg.substr(11)));
760 } else if ( arg.find( "--speed=" ) == 0 ) {
761 fgSetInt("/sim/speed-up", atoi(arg.substr(8)));
762 } else if ( arg.find( "--trim") == 0) {
763 fgSetBool("/sim/startup/trim", true);
764 } else if ( arg.find( "--notrim") == 0) {
765 fgSetBool("/sim/startup/trim", false);
766 } else if ( arg.find( "--on-ground") == 0) {
767 fgSetBool("/sim/startup/onground", true);
768 } else if ( arg.find( "--in-air") == 0) {
769 fgSetBool("/sim/startup/onground", false);
770 } else if ( arg == "--fog-disable" ) {
771 fgSetString("/sim/rendering/fog", "disabled");
772 } else if ( arg == "--fog-fastest" ) {
773 fgSetString("/sim/rendering/fog", "fastest");
774 } else if ( arg == "--fog-nicest" ) {
775 fgSetString("/sim/fog", "nicest");
776 } else if ( arg == "--disable-clouds" ) {
777 fgSetBool("/environment/clouds/status", false);
778 } else if ( arg == "--enable-clouds" ) {
779 fgSetBool("/environment/clouds/status", true);
780 } else if ( arg == "--disable-clouds3d" ) {
781 fgSetBool("/sim/rendering/clouds3d", false);
782 } else if ( arg == "--enable-clouds3d" ) {
783 fgSetBool("/sim/rendering/clouds3d", true);
784 } else if ( arg.find( "--fov=" ) == 0 ) {
785 parse_fov( arg.substr(6) );
786 } else if ( arg == "--disable-fullscreen" ) {
787 fgSetBool("/sim/startup/fullscreen", false);
788 } else if ( arg== "--enable-fullscreen") {
789 fgSetBool("/sim/startup/fullscreen", true);
790 } else if ( arg == "--shading-flat") {
791 fgSetBool("/sim/rendering/shading", false);
792 } else if ( arg == "--shading-smooth") {
793 fgSetBool("/sim/rendering/shading", true);
794 } else if ( arg == "--disable-skyblend") {
795 fgSetBool("/sim/rendering/skyblend", false);
796 } else if ( arg== "--enable-skyblend" ) {
797 fgSetBool("/sim/rendering/skyblend", true);
798 } else if ( arg == "--disable-textures" ) {
799 fgSetBool("/sim/rendering/textures", false);
800 } else if ( arg == "--enable-textures" ) {
801 fgSetBool("/sim/rendering/textures", true);
802 } else if ( arg == "--disable-wireframe" ) {
803 fgSetBool("/sim/rendering/wireframe", false);
804 } else if ( arg == "--enable-wireframe" ) {
805 fgSetBool("/sim/rendering/wireframe", true);
806 } else if ( arg.find( "--geometry=" ) == 0 ) {
807 bool geometry_ok = true;
808 int xsize = 0, ysize = 0;
809 string geometry = arg.substr( 11 );
810 string::size_type i = geometry.find('x');
812 if (i != string::npos) {
813 xsize = atoi(geometry.substr(0, i));
814 ysize = atoi(geometry.substr(i+1));
819 if ( xsize <= 0 || ysize <= 0 ) {
825 if ( !geometry_ok ) {
826 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown geometry: " << geometry );
827 SG_LOG( SG_GENERAL, SG_ALERT,
828 "Setting geometry to " << xsize << 'x' << ysize << '\n');
830 SG_LOG( SG_GENERAL, SG_INFO,
831 "Setting geometry to " << xsize << 'x' << ysize << '\n');
832 fgSetInt("/sim/startup/xsize", xsize);
833 fgSetInt("/sim/startup/ysize", ysize);
835 } else if ( arg.find( "--bpp=" ) == 0 ) {
836 string bits_per_pix = arg.substr( 6 );
837 if ( bits_per_pix == "16" ) {
838 fgSetInt("/sim/rendering/bits-per-pixel", 16);
839 } else if ( bits_per_pix == "24" ) {
840 fgSetInt("/sim/rendering/bits-per-pixel", 24);
841 } else if ( bits_per_pix == "32" ) {
842 fgSetInt("/sim/rendering/bits-per-pixel", 32);
844 SG_LOG(SG_GENERAL, SG_ALERT, "Unsupported bpp " << bits_per_pix);
846 } else if ( arg == "--units-feet" ) {
847 fgSetString("/sim/startup/units", "feet");
848 } else if ( arg == "--units-meters" ) {
849 fgSetString("/sim/startup/units", "meters");
850 } else if ( arg.find( "--time-offset" ) == 0 ) {
851 fgSetInt("/sim/startup/time-offset",
852 parse_time_offset( (arg.substr(14)) ));
853 fgSetString("/sim/startup/time-offset-type", "system-offset");
854 } else if ( arg.find( "--time-match-real") == 0 ) {
855 fgSetString("/sim/startup/time-offset-type", "system-offset");
856 } else if ( arg.find( "--time-match-local") == 0 ) {
857 fgSetString("/sim/startup/time-offset-type", "latitude-offset");
858 } else if ( arg.find( "--start-date-sys=") == 0 ) {
859 fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
860 fgSetString("/sim/startup/time-offset-type", "system");
861 } else if ( arg.find( "--start-date-lat=") == 0 ) {
862 fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
863 fgSetString("/sim/startup/time-offset-type", "latitude");
864 } else if ( arg.find( "--start-date-gmt=") == 0 ) {
865 fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
866 fgSetString("/sim/startup/time-offset-type", "gmt");
867 } else if ( arg == "--hud-tris" ) {
868 fgSetString("/sim/hud/frame-stat-type", "tris");
869 } else if ( arg == "--hud-culled" ) {
870 fgSetString("/sim/hud/frame-stat-type", "culled");
871 } else if ( arg.find( "--atc610x" ) == 0 ) {
872 add_channel( "atc610x", "dummy" );
873 } else if ( arg.find( "--atlas=" ) == 0 ) {
874 add_channel( "atlas", arg.substr(8) );
875 } else if ( arg.find( "--httpd=" ) == 0 ) {
876 add_channel( "httpd", arg.substr(8) );
877 #ifdef FG_JPEG_SERVER
878 } else if ( arg.find( "--jpg-httpd=" ) == 0 ) {
879 add_channel( "jpg-httpd", arg.substr(12) );
881 } else if ( arg.find( "--native=" ) == 0 ) {
882 add_channel( "native", arg.substr(9) );
883 } else if ( arg.find( "--native-ctrls=" ) == 0 ) {
884 add_channel( "native_ctrls", arg.substr(15) );
885 } else if ( arg.find( "--native-fdm=" ) == 0 ) {
886 add_channel( "native_fdm", arg.substr(13) );
887 } else if ( arg.find( "--opengc=" ) == 0 ) {
889 // cout << "Adding channel for OpenGC Display" << endl; cin >> stop;
890 add_channel( "opengc", arg.substr(9) );
891 } else if ( arg.find( "--garmin=" ) == 0 ) {
892 add_channel( "garmin", arg.substr(9) );
893 } else if ( arg.find( "--nmea=" ) == 0 ) {
894 add_channel( "nmea", arg.substr(7) );
895 } else if ( arg.find( "--props=" ) == 0 ) {
896 add_channel( "props", arg.substr(8) );
897 } else if ( arg.find( "--telnet=" ) == 0 ) {
898 add_channel( "telnet", arg.substr(9) );
899 } else if ( arg.find( "--pve=" ) == 0 ) {
900 add_channel( "pve", arg.substr(6) );
901 } else if ( arg.find( "--ray=" ) == 0 ) {
902 add_channel( "ray", arg.substr(6) );
903 } else if ( arg.find( "--rul=" ) == 0 ) {
904 add_channel( "rul", arg.substr(6) );
905 } else if ( arg.find( "--joyclient=" ) == 0 ) {
906 add_channel( "joyclient", arg.substr(12) );
907 #ifdef FG_NETWORK_OLK
908 } else if ( arg == "--disable-network-olk" ) {
909 fgSetBool("/sim/networking/olk", false);
910 } else if ( arg== "--enable-network-olk") {
911 fgSetBool("/sim/networking/olk", true);
912 } else if ( arg == "--net-hud" ) {
913 fgSetBool("/sim/hud/net-display", true);
914 net_hud_display = 1; // FIXME
915 } else if ( arg.find( "--net-id=") == 0 ) {
916 fgSetString("sim/networking/call-sign", arg.substr(9).c_str());
918 } else if ( arg.find( "--prop:" ) == 0 ) {
919 string assign = arg.substr(7);
920 string::size_type pos = assign.find('=');
921 if ( pos == arg.npos || pos == 0 ) {
922 SG_LOG( SG_GENERAL, SG_ALERT, "Bad property assignment: " << arg );
923 return FG_OPTIONS_ERROR;
925 string name = assign.substr(0, pos);
926 string value = assign.substr(pos + 1);
927 fgSetString(name.c_str(), value.c_str());
928 // SG_LOG(SG_GENERAL, SG_INFO, "Setting default value of property "
929 // << name << " to \"" << value << '"');
930 } else if ( arg.find("--trace-read=") == 0) {
931 string name = arg.substr(13);
932 SG_LOG(SG_GENERAL, SG_INFO, "Tracing reads for property " << name);
933 fgGetNode(name.c_str(), true)
934 ->setAttribute(SGPropertyNode::TRACE_READ, true);
935 } else if ( arg.find("--trace-write=") == 0) {
936 string name = arg.substr(14);
937 SG_LOG(SG_GENERAL, SG_INFO, "Tracing writes for property " << name);
938 fgGetNode(name.c_str(), true)
939 ->setAttribute(SGPropertyNode::TRACE_WRITE, true);
940 } else if ( arg.find( "--view-offset=" ) == 0 ) {
941 // $$$ begin - added VS Renganathan, 14 Oct 2K
942 // for multi-window outside window imagery
943 string woffset = arg.substr( 14 );
944 double default_view_offset = 0.0;
945 if ( woffset == "LEFT" ) {
946 default_view_offset = SGD_PI * 0.25;
947 } else if ( woffset == "RIGHT" ) {
948 default_view_offset = SGD_PI * 1.75;
949 } else if ( woffset == "CENTER" ) {
950 default_view_offset = 0.00;
952 default_view_offset = atof( woffset.c_str() ) * SGD_DEGREES_TO_RADIANS;
954 /* apparently not used (CLO, 11 Jun 2002)
955 FGViewer *pilot_view =
956 (FGViewer *)globals->get_viewmgr()->get_view( 0 ); */
957 // this will work without calls to the viewer...
958 fgSetDouble( "/sim/current-view/heading-offset-deg",
959 default_view_offset * SGD_RADIANS_TO_DEGREES );
960 // $$$ end - added VS Renganathan, 14 Oct 2K
961 } else if ( arg.find( "--visibility=" ) == 0 ) {
962 fgSetDouble("/environment/visibility-m", atof(arg.substr(13)));
963 } else if ( arg.find( "--visibility-miles=" ) == 0 ) {
964 double visibility = atof(arg.substr(19)) * 5280.0 * SG_FEET_TO_METER;
965 fgSetDouble("/environment/visibility-m", visibility);
966 } else if ( arg.find( "--random-wind" ) == 0 ) {
967 double min_hdg = sg_random() * 360.0;
968 double max_hdg = min_hdg + (20 - sqrt(sg_random() * 400));
969 double speed = 40 - sqrt(sg_random() * 1600.0);
970 double gust = speed + (10 - sqrt(sg_random() * 100));
971 setup_wind(min_hdg, max_hdg, speed, gust);
972 } else if ( arg.find( "--wind=" ) == 0 ) {
973 double min_hdg, max_hdg, speed, gust;
974 if (!parse_wind(arg.substr(7), &min_hdg, &max_hdg, &speed, &gust)) {
975 SG_LOG( SG_GENERAL, SG_ALERT, "bad wind value " << arg.substr(7) );
976 return FG_OPTIONS_ERROR;
978 setup_wind(min_hdg, max_hdg, speed, gust);
979 } else if ( arg.find( "--wp=" ) == 0 ) {
980 parse_wp( arg.substr( 5 ) );
981 } else if ( arg.find( "--flight-plan=") == 0) {
982 parse_flightplan ( arg.substr (14) );
983 } else if ( arg.find( "--config=" ) == 0 ) {
984 string file = arg.substr(9);
986 readProperties(file, globals->get_props());
987 } catch (const sg_exception &e) {
988 string message = "Error loading config file: ";
989 message += e.getFormattedMessage();
990 SG_LOG(SG_INPUT, SG_ALERT, message);
993 } else if ( arg.find( "--aircraft=" ) == 0 ) {
994 // read in the top level aircraft definition file
995 SGPath apath( globals->get_fg_root() );
996 apath.append( "Aircraft" );
997 apath.append( arg.substr(11) );
998 apath.concat( "-set.xml" );
999 SG_LOG(SG_INPUT, SG_INFO, "Reading aircraft: " << arg.substr(11)
1000 << " from " << apath.str());
1001 readProperties( apath.str(), globals->get_props() );
1003 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
1004 return FG_OPTIONS_ERROR;
1007 return FG_OPTIONS_OK;
1011 // Scan the command line options for an fg_root definition and set
1014 fgScanForRoot (int argc, char **argv)
1018 SG_LOG(SG_GENERAL, SG_INFO, "Scanning for root: command line");
1020 while ( i < argc ) {
1021 SG_LOG( SG_GENERAL, SG_DEBUG, "argv[" << i << "] = " << argv[i] );
1023 string arg = argv[i];
1024 if ( arg.find( "--fg-root=" ) == 0 ) {
1025 return arg.substr( 10 );
1035 // Scan the config file for an fg_root definition and set just that.
1037 fgScanForRoot (const string& path)
1039 sg_gzifstream in( path );
1040 if ( !in.is_open() )
1043 SG_LOG( SG_GENERAL, SG_INFO, "Scanning for root: " << path );
1047 while ( ! in.eof() ) {
1050 while ( in.get(c) && c != '\0' ) {
1055 #if defined( macintosh )
1056 getline( in, line, '\r' );
1058 getline( in, line, '\n' );
1061 // catch extraneous (DOS) line ending character
1062 if ( line[line.length() - 1] < 32 ) {
1063 line = line.substr( 0, line.length()-1 );
1066 if ( line.find( "--fg-root=" ) == 0 ) {
1067 return line.substr( 10 );
1077 // Parse the command line options
1079 fgParseArgs (int argc, char **argv)
1081 bool in_options = true;
1082 bool verbose = false;
1085 SG_LOG(SG_GENERAL, SG_INFO, "Processing command line arguments");
1087 for (int i = 1; i < argc; i++) {
1088 string arg = argv[i];
1090 if (in_options && (arg.find('-') == 0)) {
1094 int result = parse_option(arg);
1095 if ((result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR))
1098 else if (result == FG_OPTIONS_VERBOSE_HELP)
1101 else if (result == FG_OPTIONS_SHOW_AIRCRAFT) {
1108 SG_LOG(SG_GENERAL, SG_INFO,
1109 "Reading command-line property file " << arg);
1110 readProperties(arg, globals->get_props());
1119 SG_LOG(SG_GENERAL, SG_INFO, "Finished command line arguments");
1123 // Parse config file options
1125 fgParseOptions (const string& path) {
1126 sg_gzifstream in( path );
1127 if ( !in.is_open() ) {
1131 SG_LOG( SG_GENERAL, SG_INFO, "Processing config file: " << path );
1135 while ( ! in.eof() ) {
1138 while ( in.get(c) && c != '\0' ) {
1143 #if defined( macintosh )
1144 getline( in, line, '\r' );
1146 getline( in, line, '\n' );
1149 // catch extraneous (DOS) line ending character
1150 if ( line[line.length() - 1] < 32 ) {
1151 line = line.substr( 0, line.length()-1 );
1154 if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
1155 cerr << endl << "Config file parse error: " << path << " '"
1156 << line << "'" << endl;
1165 // Print usage message
1167 fgUsage (bool verbose)
1169 SGPropertyNode options_root;
1170 SGPath opath( globals->get_fg_root() );
1171 opath.append( "options.xml" );
1176 readProperties(opath.c_str(), &options_root);
1177 } catch (const sg_exception &ex) {
1178 cout << "Unable to read the help file." << endl;
1179 cout << "Make sure the file options.xml is located in the FlightGear base directory," << endl;
1180 cout << "and the location of the base directory is specified by setting $FG_ROOT or" << endl;
1181 cout << "by adding --fg-root=path as a program argument." << endl;
1186 SGPropertyNode *options = options_root.getNode("options");
1188 SG_LOG( SG_GENERAL, SG_ALERT,
1189 "Error reading options.xml: <options> directive not found." );
1193 SGPropertyNode *usage = options->getNode("usage");
1195 cout << "Usage: " << usage->getStringValue() << endl;
1198 vector<SGPropertyNode_ptr>section = options->getChildren("section");
1199 for (unsigned int j = 0; j < section.size(); j++) {
1202 vector<SGPropertyNode_ptr>option = section[j]->getChildren("option");
1203 for (unsigned int k = 0; k < option.size(); k++) {
1205 SGPropertyNode *name = option[k]->getNode("name");
1206 SGPropertyNode *short_name = option[k]->getNode("short");
1207 SGPropertyNode *key = option[k]->getNode("key");
1208 SGPropertyNode *arg = option[k]->getNode("arg");
1209 bool brief = option[k]->getNode("brief");
1211 if ((brief || verbose) && name) {
1212 string tmp = name->getStringValue();
1216 tmp.append(key->getStringValue());
1220 tmp.append(arg->getStringValue());
1224 tmp.append(short_name->getStringValue());
1228 if (tmp.size() <= 25) {
1229 snprintf(cstr, 96, " --%-27s", tmp.c_str());
1231 snprintf(cstr, 96, "\n --%s\n%32c", tmp.c_str(), ' ');
1235 SGPropertyNode *desc = option[k]->getNode("description");
1237 msg += desc->getStringValue();
1239 for ( unsigned int l = 1;
1240 (desc = option[k]->getNode("description", l, false));
1243 snprintf(cstr, 96, "\n%32c%s", ' ',
1244 desc->getStringValue());
1252 SGPropertyNode *name = section[j]->getNode("name");
1253 if (!msg.empty() && name) {
1254 cout << endl << name->getStringValue() << ":" << endl;
1262 cout << "For a complete list of options use --help --verbose" << endl;
1266 // Show available aircraft types
1267 void fgShowAircraft(void) {
1268 SGPath path( globals->get_fg_root() );
1269 path.append("Aircraft");
1274 dirp = ulOpenDir(path.c_str());
1276 cerr << "Unable to open aircraft directory." << endl;
1280 cout << "Available aircraft:" << endl;
1281 while ((dire = ulReadDir(dirp)) != NULL) {
1284 if ((ptr = strstr(dire->d_name, "-set.xml")) && ptr[8] == '\0' ) {
1285 SGPath afile = path;
1286 afile.append(dire->d_name);
1290 SGPropertyNode root;
1292 readProperties(afile.str(), &root);
1297 SGPropertyNode *desc, *node = root.getNode("sim");
1299 desc = node->getNode("description");
1302 if (strlen(dire->d_name) <= 27)
1303 snprintf(cstr, 96, " %-27s %s", dire->d_name,
1304 (desc) ? desc->getStringValue() : "" );
1307 snprintf(cstr, 96, " %-27s\n%32c%s", dire->d_name, ' ',
1308 (desc) ? desc->getStringValue() : "" );
1310 cout << cstr << endl;