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"
65 SG_USING_NAMESPACE(std);
68 #define NEW_DEFAULT_MODEL_HZ 120
75 FG_OPTIONS_VERBOSE_HELP = 3,
76 FG_OPTIONS_SHOW_AIRCRAFT = 4
80 atof( const string& str )
84 // -dw- if ::atof is called, then we get an infinite loop
85 return std::atof( str.c_str() );
87 return ::atof( str.c_str() );
92 atoi( const string& str )
95 // -dw- if ::atoi is called, then we get an infinite loop
96 return std::atoi( str.c_str() );
98 return ::atoi( str.c_str() );
104 * Set a few fail-safe default property values.
106 * These should all be set in $FG_ROOT/preferences.xml, but just
107 * in case, we provide some initial sane values here. This method
108 * should be invoked *before* reading any init files.
113 // set a possibly independent location for scenery data
114 char *envp = ::getenv( "FG_SCENERY" );
116 if ( envp != NULL ) {
117 // fg_root could be anywhere, so default to environmental
118 // variable $FG_ROOT if it is set.
119 globals->set_fg_scenery(envp);
121 // Otherwise, default to Scenery being in $FG_ROOT/Scenery
122 globals->set_fg_scenery("");
124 // Position (deliberately out of range)
125 fgSetDouble("/position/longitude-deg", 9999.0);
126 fgSetDouble("/position/latitude-deg", 9999.0);
127 fgSetDouble("/position/altitude-ft", -9999.0);
130 fgSetDouble("/orientation/heading-deg", 270);
131 fgSetDouble("/orientation/roll-deg", 0);
132 fgSetDouble("/orientation/pitch-deg", 0.424);
135 fgSetString("/sim/startup/speed-set", "knots");
136 fgSetDouble("/velocities/uBody-fps", 0.0);
137 fgSetDouble("/velocities/vBody-fps", 0.0);
138 fgSetDouble("/velocities/wBody-fps", 0.0);
139 fgSetDouble("/velocities/speed-north-fps", 0.0);
140 fgSetDouble("/velocities/speed-east-fps", 0.0);
141 fgSetDouble("/velocities/speed-down-fps", 0.0);
142 fgSetDouble("/velocities/airspeed-kt", 0.0);
143 fgSetDouble("/velocities/mach", 0.0);
146 fgSetBool("/sim/startup/game-mode", false);
147 fgSetBool("/sim/startup/splash-screen", true);
148 fgSetBool("/sim/startup/intro-music", true);
149 // we want mouse-pointer to have an undefined value if nothing is
150 // specified so we can do the right thing for voodoo-1/2 cards.
151 // fgSetString("/sim/startup/mouse-pointer", "disabled");
152 fgSetString("/sim/control-mode", "joystick");
153 fgSetBool("/sim/auto-coordination", false);
155 fgSetString("/sim/startup/browser-app", "netscape");
157 fgSetString("/sim/startup/browser-app", "webrun.bat");
160 fgSetBool("/sim/hud/visibility", false);
161 fgSetBool("/sim/panel/visibility", true);
162 fgSetBool("/sim/sound/audible", true);
163 fgSetBool("/sim/hud/antialiased", false);
165 // Flight Model options
166 fgSetString("/sim/flight-model", "jsb");
167 fgSetString("/sim/aero", "c172");
168 fgSetInt("/sim/model-hz", NEW_DEFAULT_MODEL_HZ);
169 fgSetInt("/sim/speed-up", 1);
170 fgSetBool("/sim/startup/trim", false);
171 fgSetBool("/sim/startup/onground", true);
174 fgSetString("/sim/rendering/fog", "nicest");
175 fgSetBool("/environment/clouds/status", true);
176 fgSetBool("/sim/startup/fullscreen", false);
177 fgSetBool("/sim/rendering/shading", true);
178 fgSetBool("/sim/rendering/skyblend", true);
179 fgSetBool("/sim/rendering/textures", true);
180 fgSetBool("/sim/rendering/wireframe", false);
181 fgSetInt("/sim/startup/xsize", 800);
182 fgSetInt("/sim/startup/ysize", 600);
183 fgSetInt("/sim/rendering/bits-per-pixel", 16);
184 fgSetString("/sim/view-mode", "pilot");
185 fgSetDouble("/sim/current-view/heading-offset-deg", 0);
186 fgSetDouble("/environment/visibility-m", 20000);
189 fgSetString("/sim/startup/units", "feet");
190 fgSetString("/sim/hud/frame-stat-type", "tris");
193 fgSetInt("/sim/startup/time-offset", 0);
194 fgSetString("/sim/startup/time-offset-type", "system-offset");
195 fgSetLong("/sim/time/cur-time-override", 0);
197 fgSetBool("/sim/networking/network-olk", false);
198 fgSetString("/sim/networking/call-sign", "Johnny");
201 fgSetBool("/sim/freeze/master", false);
202 fgSetBool("/sim/freeze/position", false);
203 fgSetBool("/sim/freeze/clock", false);
204 fgSetBool("/sim/freeze/fuel", false);
209 parse_wind (const string &wind, double * min_hdg, double * max_hdg,
210 double * speed, double * gust)
212 string::size_type pos = wind.find('@');
213 if (pos == string::npos)
215 string dir = wind.substr(0, pos);
216 string spd = wind.substr(pos+1);
218 if (pos == string::npos) {
219 *min_hdg = *max_hdg = atof(dir.c_str());
221 *min_hdg = atof(dir.substr(0,pos).c_str());
222 *max_hdg = atof(dir.substr(pos+1).c_str());
225 if (pos == string::npos) {
226 *speed = *gust = atof(spd.c_str());
228 *speed = atof(spd.substr(0,pos).c_str());
229 *gust = atof(spd.substr(pos+1).c_str());
234 // parse a time string ([+/-]%f[:%f[:%f]]) into hours
236 parse_time(const string& time_in) {
237 char *time_str, num[256];
238 double hours, minutes, seconds;
243 time_str = (char *)time_in.c_str();
245 // printf("parse_time(): %s\n", time_str);
248 if ( strlen(time_str) ) {
249 if ( time_str[0] == '+' ) {
252 } else if ( time_str[0] == '-' ) {
257 // printf("sign = %d\n", sign);
260 if ( strlen(time_str) ) {
262 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
263 num[i] = time_str[0];
267 if ( time_str[0] == ':' ) {
272 // printf("hours = %.2lf\n", hours);
278 if ( strlen(time_str) ) {
280 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
281 num[i] = time_str[0];
285 if ( time_str[0] == ':' ) {
290 // printf("minutes = %.2lf\n", minutes);
292 result += minutes / 60.0;
296 if ( strlen(time_str) ) {
298 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
299 num[i] = time_str[0];
305 // printf("seconds = %.2lf\n", seconds);
307 result += seconds / 3600.0;
310 return(sign * result);
314 // parse a date string (yyyy:mm:dd:hh:mm:ss) into a time_t (seconds)
316 parse_date( const string& date)
319 char * date_str, num[256];
321 // initialize to zero
328 gmt.tm_isdst = 0; // ignore daylight savings time for the moment
329 date_str = (char *)date.c_str();
331 if ( strlen(date_str) ) {
333 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
334 num[i] = date_str[0];
338 if ( date_str[0] == ':' ) {
342 gmt.tm_year = atoi(num) - 1900;
345 if ( strlen(date_str) ) {
347 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
348 num[i] = date_str[0];
352 if ( date_str[0] == ':' ) {
356 gmt.tm_mon = atoi(num) -1;
359 if ( strlen(date_str) ) {
361 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
362 num[i] = date_str[0];
366 if ( date_str[0] == ':' ) {
370 gmt.tm_mday = atoi(num);
373 if ( strlen(date_str) ) {
375 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
376 num[i] = date_str[0];
380 if ( date_str[0] == ':' ) {
384 gmt.tm_hour = atoi(num);
387 if ( strlen(date_str) ) {
389 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
390 num[i] = date_str[0];
394 if ( date_str[0] == ':' ) {
398 gmt.tm_min = atoi(num);
401 if ( strlen(date_str) ) {
403 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
404 num[i] = date_str[0];
408 if ( date_str[0] == ':' ) {
412 gmt.tm_sec = atoi(num);
414 time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
415 gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
416 //printf ("Date is %s\n", ctime(&theTime));
417 //printf ("in seconds that is %d\n", theTime);
423 // parse angle in the form of [+/-]ddd:mm:ss into degrees
425 parse_degree( const string& degree_str) {
426 double result = parse_time( degree_str );
428 // printf("Degree = %.4f\n", result);
434 // parse time offset string into seconds
436 parse_time_offset( const string& time_str) {
439 // printf("time offset = %s\n", time_str);
442 result = (int)rint(parse_time(time_str) * 3600.0);
444 result = (int)(parse_time(time_str) * 3600.0);
447 // printf("parse_time_offset(): %d\n", result);
453 // Parse --fov=x.xx type option
455 parse_fov( const string& arg ) {
456 double fov = atof(arg);
458 if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
459 if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
461 fgSetDouble("/sim/current-view/field-of-view", fov);
463 // printf("parse_fov(): result = %.4f\n", fov);
469 // Parse I/O channel option
471 // Format is "--protocol=medium,direction,hz,medium_options,..."
473 // protocol = { native, nmea, garmin, fgfs, rul, pve, etc. }
474 // medium = { serial, socket, file, etc. }
475 // direction = { in, out, bi }
476 // hz = number of times to process channel per second (floating
477 // point values are ok.
479 // Serial example "--nmea=serial,dir,hz,device,baud" where
481 // device = OS device name of serial line to be open()'ed
482 // baud = {300, 1200, 2400, ..., 230400}
484 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
486 // machine = machine name or ip address if client (leave empty if server)
487 // port = port, leave empty to let system choose
488 // style = tcp or udp
490 // File example "--garmin=file,dir,hz,filename" where
492 // filename = file system file name
495 add_channel( const string& type, const string& channel_str ) {
496 // cout << "Channel string = " << channel_str << endl;
498 globals->get_channel_options_list()->push_back( type + "," + channel_str );
505 setup_wind (double min_hdg, double max_hdg, double speed, double gust)
507 fgSetDouble("/environment/wind-from-heading-deg", min_hdg);
508 fgSetDouble("/environment/params/min-wind-from-heading-deg", min_hdg);
509 fgSetDouble("/environment/params/max-wind-from-heading-deg", max_hdg);
510 fgSetDouble("/environment/wind-speed-kt", speed);
511 fgSetDouble("/environment/params/base-wind-speed-kt", speed);
512 fgSetDouble("/environment/params/gust-wind-speed-kt", gust);
514 SG_LOG(SG_GENERAL, SG_INFO, "WIND: " << min_hdg << '@' <<
515 speed << " knots" << endl);
519 speed *= SG_NM_TO_METER * SG_METER_TO_FEET * (1.0/3600);
520 while (min_hdg > 360)
524 min_hdg *= SGD_DEGREES_TO_RADIANS;
525 fgSetDouble("/environment/wind-from-north-fps", speed * cos(dir));
526 fgSetDouble("/environment/wind-from-east-fps", speed * sin(dir));
527 #endif // FG_WEATHERCM
531 // Parse --wp=ID[@alt]
533 parse_wp( const string& arg ) {
537 string::size_type pos = arg.find( "@" );
538 if ( pos != string::npos ) {
539 id = arg.substr( 0, pos );
540 alt_str = arg.substr( pos + 1 );
541 // cout << "id str = " << id << " alt str = " << alt_str << endl;
542 alt = atof( alt_str.c_str() );
543 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") ) {
544 alt *= SG_FEET_TO_METER;
551 if ( fgFindAirportID( id, &a ) ) {
552 SGWayPoint wp( a.longitude, a.latitude, alt, SGWayPoint::WGS84, id );
553 globals->get_route()->add_waypoint( wp );
562 // Parse --flight-plan=[file]
564 parse_flightplan(const string& arg)
566 sg_gzifstream in(arg.c_str());
567 if ( !in.is_open() ) {
573 #if defined( macintosh )
574 getline( in, line, '\r' );
576 getline( in, line, '\n' );
579 // catch extraneous (DOS) line ending character
580 if ( line[line.length() - 1] < 32 ) {
581 line = line.substr( 0, line.length()-1 );
594 // Parse a single option
596 parse_option (const string& arg)
599 if ( (arg == "--help") || (arg == "-h") ) {
600 // help/usage request
601 return(FG_OPTIONS_HELP);
602 } else if ( (arg == "--verbose") || (arg == "-v") ) {
603 // verbose help/usage request
604 return(FG_OPTIONS_VERBOSE_HELP);
605 } else if ( arg.find( "--language=") == 0 ) {
606 globals->set_locale( fgInitLocale( arg.substr( 11 ).c_str() ) );
607 } else if ( arg == "--disable-game-mode") {
608 fgSetBool("/sim/startup/game-mode", false);
609 } else if ( arg == "--enable-game-mode" ) {
610 fgSetBool("/sim/startup/game-mode", true);
611 } else if ( arg == "--disable-splash-screen" ) {
612 fgSetBool("/sim/startup/splash-screen", false);
613 } else if ( arg == "--enable-splash-screen" ) {
614 fgSetBool("/sim/startup/splash-screen", true);
615 } else if ( arg == "--disable-intro-music" ) {
616 fgSetBool("/sim/startup/intro-music", false);
617 } else if ( arg == "--enable-intro-music" ) {
618 fgSetBool("/sim/startup/intro-music", true);
619 } else if ( arg == "--disable-mouse-pointer" ) {
620 fgSetString("/sim/startup/mouse-pointer", "disabled");
621 } else if ( arg == "--enable-mouse-pointer" ) {
622 fgSetString("/sim/startup/mouse-pointer", "enabled");
623 } else if ( arg == "--disable-random-objects" ) {
624 fgSetBool("/sim/rendering/random-objects", false);
625 } else if ( arg == "--enable-random-objects" ) {
626 fgSetBool("/sim/rendering/random-objects", true);
627 } else if ( arg == "--disable-freeze" ) {
628 fgSetBool("/sim/freeze/master", false);
629 } else if ( arg == "--enable-freeze" ) {
630 fgSetBool("/sim/freeze/master", true);
631 } else if ( arg == "--disable-fuel-freeze" ) {
632 fgSetBool("/sim/freeze/fuel", false);
633 } else if ( arg == "--enable-fuel-freeze" ) {
634 fgSetBool("/sim/freeze/fuel", true);
635 } else if ( arg == "--disable-clock-freeze" ) {
636 fgSetBool("/sim/freeze/clock", false);
637 } else if ( arg == "--enable-clock-freeze" ) {
638 fgSetBool("/sim/freeze/clock", true);
639 } else if ( arg == "--disable-anti-alias-hud" ) {
640 fgSetBool("/sim/hud/antialiased", false);
641 } else if ( arg == "--enable-anti-alias-hud" ) {
642 fgSetBool("/sim/hud/antialiased", true);
643 } else if ( arg.find( "--control=") == 0 ) {
644 fgSetString("/sim/control-mode", arg.substr(10).c_str());
645 } else if ( arg == "--disable-auto-coordination" ) {
646 fgSetBool("/sim/auto-coordination", false);
647 } else if ( arg == "--enable-auto-coordination" ) {
648 fgSetBool("/sim/auto-coordination", true);
649 } else if ( arg.find( "--browser-app=") == 0 ) {
650 fgSetString("/sim/startup/browser-app", arg.substr(14).c_str());
651 } else if ( arg == "--disable-hud" ) {
652 fgSetBool("/sim/hud/visibility", false);
653 } else if ( arg == "--enable-hud" ) {
654 fgSetBool("/sim/hud/visibility", true);
655 } else if ( arg == "--disable-panel" ) {
656 fgSetBool("/sim/panel/visibility", false);
657 } else if ( arg == "--enable-panel" ) {
658 fgSetBool("/sim/panel/visibility", true);
659 } else if ( arg == "--disable-sound" ) {
660 fgSetBool("/sim/sound/audible", false);
661 } else if ( arg == "--enable-sound" ) {
662 fgSetBool("/sim/sound/audible", true);
663 } else if ( arg.find( "--airport-id=") == 0 ) {
664 // NB: changed property name!!!
665 fgSetString("/sim/startup/airport-id", arg.substr(13).c_str());
666 } else if ( arg.find( "--offset-distance=") == 0 ) {
667 fgSetDouble("/sim/startup/offset-distance", atof(arg.substr(18)));
668 } else if ( arg.find( "--offset-azimuth=") == 0 ) {
669 fgSetDouble("/sim/startup/offset-azimuth", atof(arg.substr(17)));
670 } else if ( arg.find( "--lon=" ) == 0 ) {
671 fgSetDouble("/position/longitude-deg",
672 parse_degree(arg.substr(6)));
673 fgSetString("/sim/startup/airport-id", "");
674 } else if ( arg.find( "--lat=" ) == 0 ) {
675 fgSetDouble("/position/latitude-deg",
676 parse_degree(arg.substr(6)));
677 fgSetString("/sim/startup/airport-id", "");
678 } else if ( arg.find( "--altitude=" ) == 0 ) {
679 fgSetBool("/sim/startup/onground", false);
680 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
681 fgSetDouble("/position/altitude-ft", atof(arg.substr(11)));
683 fgSetDouble("/position/altitude-ft",
684 atof(arg.substr(11)) * SG_METER_TO_FEET);
685 } else if ( arg.find( "--uBody=" ) == 0 ) {
686 fgSetString("/sim/startup/speed-set", "UVW");
687 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
688 fgSetDouble("/velocities/uBody-fps", atof(arg.substr(8)));
690 fgSetDouble("/velocities/uBody-fps",
691 atof(arg.substr(8)) * SG_METER_TO_FEET);
692 } else if ( arg.find( "--vBody=" ) == 0 ) {
693 fgSetString("/sim/startup/speed-set", "UVW");
694 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
695 fgSetDouble("/velocities/vBody-fps", atof(arg.substr(8)));
697 fgSetDouble("/velocities/vBody-fps",
698 atof(arg.substr(8)) * SG_METER_TO_FEET);
699 } else if ( arg.find( "--wBody=" ) == 0 ) {
700 fgSetString("/sim/startup/speed-set", "UVW");
701 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
702 fgSetDouble("/velocities/wBody-fps", atof(arg.substr(8)));
704 fgSetDouble("/velocities/wBody-fps",
705 atof(arg.substr(8)) * SG_METER_TO_FEET);
706 } else if ( arg.find( "--vNorth=" ) == 0 ) {
707 fgSetString("/sim/startup/speed-set", "NED");
708 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
709 fgSetDouble("/velocities/speed-north-fps", atof(arg.substr(9)));
711 fgSetDouble("/velocities/speed-north-fps",
712 atof(arg.substr(9)) * SG_METER_TO_FEET);
713 } else if ( arg.find( "--vEast=" ) == 0 ) {
714 fgSetString("/sim/startup/speed-set", "NED");
715 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
716 fgSetDouble("/velocities/speed-east-fps", atof(arg.substr(8)));
718 fgSetDouble("/velocities/speed-east-fps",
719 atof(arg.substr(8)) * SG_METER_TO_FEET);
720 } else if ( arg.find( "--vDown=" ) == 0 ) {
721 fgSetString("/sim/startup/speed-set", "NED");
722 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
723 fgSetDouble("/velocities/speed-down-fps", atof(arg.substr(8)));
725 fgSetDouble("/velocities/speed-down-fps",
726 atof(arg.substr(8)) * SG_METER_TO_FEET);
727 } else if ( arg.find( "--vc=" ) == 0) {
728 fgSetString("/sim/startup/speed-set", "knots");
729 fgSetDouble("/velocities/airspeed-kt", atof(arg.substr(5)));
730 } else if ( arg.find( "--mach=" ) == 0) {
731 fgSetString("/sim/startup/speed-set", "mach");
732 fgSetDouble("/velocities/mach", atof(arg.substr(7)));
733 } else if ( arg.find( "--heading=" ) == 0 ) {
734 fgSetDouble("/orientation/heading-deg", atof(arg.substr(10)));
735 } else if ( arg.find( "--roll=" ) == 0 ) {
736 fgSetDouble("/orientation/roll-deg", atof(arg.substr(7)));
737 } else if ( arg.find( "--pitch=" ) == 0 ) {
738 fgSetDouble("/orientation/pitch-deg", atof(arg.substr(8)));
739 } else if ( arg.find( "--glideslope=" ) == 0 ) {
740 fgSetDouble("/velocities/glideslope", atof(arg.substr(13))
741 *SG_DEGREES_TO_RADIANS);
742 } else if ( arg.find( "--roc=" ) == 0 ) {
743 fgSetDouble("/velocities/vertical-speed-fps", atof(arg.substr(6))/60);
744 } else if ( arg.find( "--fg-root=" ) == 0 ) {
745 globals->set_fg_root(arg.substr( 10 ));
746 } else if ( arg.find( "--fg-scenery=" ) == 0 ) {
747 globals->set_fg_scenery(arg.substr( 13 ));
748 } else if ( arg.find( "--fdm=" ) == 0 ) {
749 fgSetString("/sim/flight-model", arg.substr(6).c_str());
750 } else if ( arg.find( "--aero=" ) == 0 ) {
751 fgSetString("/sim/aero", arg.substr(7).c_str());
752 } else if ( arg.find( "--aircraft-dir=" ) == 0 ) {
753 fgSetString("/sim/aircraft-dir", arg.substr(15).c_str());
754 } else if ( arg.find( "--show-aircraft") == 0) {
755 return(FG_OPTIONS_SHOW_AIRCRAFT);
756 } else if ( arg.find( "--model-hz=" ) == 0 ) {
757 fgSetInt("/sim/model-hz", atoi(arg.substr(11)));
758 } else if ( arg.find( "--speed=" ) == 0 ) {
759 fgSetInt("/sim/speed-up", atoi(arg.substr(8)));
760 } else if ( arg.find( "--trim") == 0) {
761 fgSetBool("/sim/startup/trim", true);
762 } else if ( arg.find( "--notrim") == 0) {
763 fgSetBool("/sim/startup/trim", false);
764 } else if ( arg.find( "--on-ground") == 0) {
765 fgSetBool("/sim/startup/onground", true);
766 } else if ( arg.find( "--in-air") == 0) {
767 fgSetBool("/sim/startup/onground", false);
768 } else if ( arg == "--fog-disable" ) {
769 fgSetString("/sim/rendering/fog", "disabled");
770 } else if ( arg == "--fog-fastest" ) {
771 fgSetString("/sim/rendering/fog", "fastest");
772 } else if ( arg == "--fog-nicest" ) {
773 fgSetString("/sim/fog", "nicest");
774 } else if ( arg == "--disable-clouds" ) {
775 fgSetBool("/environment/clouds/status", false);
776 } else if ( arg == "--enable-clouds" ) {
777 fgSetBool("/environment/clouds/status", true);
778 } else if ( arg == "--disable-clouds3d" ) {
779 fgSetBool("/sim/rendering/clouds3d", false);
780 } else if ( arg == "--enable-clouds3d" ) {
781 fgSetBool("/sim/rendering/clouds3d", true);
782 } else if ( arg.find( "--fov=" ) == 0 ) {
783 parse_fov( arg.substr(6) );
784 } else if ( arg == "--disable-fullscreen" ) {
785 fgSetBool("/sim/startup/fullscreen", false);
786 } else if ( arg== "--enable-fullscreen") {
787 fgSetBool("/sim/startup/fullscreen", true);
788 } else if ( arg == "--shading-flat") {
789 fgSetBool("/sim/rendering/shading", false);
790 } else if ( arg == "--shading-smooth") {
791 fgSetBool("/sim/rendering/shading", true);
792 } else if ( arg == "--disable-skyblend") {
793 fgSetBool("/sim/rendering/skyblend", false);
794 } else if ( arg== "--enable-skyblend" ) {
795 fgSetBool("/sim/rendering/skyblend", true);
796 } else if ( arg == "--disable-textures" ) {
797 fgSetBool("/sim/rendering/textures", false);
798 } else if ( arg == "--enable-textures" ) {
799 fgSetBool("/sim/rendering/textures", true);
800 } else if ( arg == "--disable-wireframe" ) {
801 fgSetBool("/sim/rendering/wireframe", false);
802 } else if ( arg == "--enable-wireframe" ) {
803 fgSetBool("/sim/rendering/wireframe", true);
804 } else if ( arg.find( "--geometry=" ) == 0 ) {
805 bool geometry_ok = true;
806 int xsize = 0, ysize = 0;
807 string geometry = arg.substr( 11 );
808 string::size_type i = geometry.find('x');
810 if (i != string::npos) {
811 xsize = atoi(geometry.substr(0, i));
812 ysize = atoi(geometry.substr(i+1));
817 if ( xsize <= 0 || ysize <= 0 ) {
823 if ( !geometry_ok ) {
824 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown geometry: " << geometry );
825 SG_LOG( SG_GENERAL, SG_ALERT,
826 "Setting geometry to " << xsize << 'x' << ysize << '\n');
828 SG_LOG( SG_GENERAL, SG_INFO,
829 "Setting geometry to " << xsize << 'x' << ysize << '\n');
830 fgSetInt("/sim/startup/xsize", xsize);
831 fgSetInt("/sim/startup/ysize", ysize);
833 } else if ( arg.find( "--bpp=" ) == 0 ) {
834 string bits_per_pix = arg.substr( 6 );
835 if ( bits_per_pix == "16" ) {
836 fgSetInt("/sim/rendering/bits-per-pixel", 16);
837 } else if ( bits_per_pix == "24" ) {
838 fgSetInt("/sim/rendering/bits-per-pixel", 24);
839 } else if ( bits_per_pix == "32" ) {
840 fgSetInt("/sim/rendering/bits-per-pixel", 32);
842 SG_LOG(SG_GENERAL, SG_ALERT, "Unsupported bpp " << bits_per_pix);
844 } else if ( arg == "--units-feet" ) {
845 fgSetString("/sim/startup/units", "feet");
846 } else if ( arg == "--units-meters" ) {
847 fgSetString("/sim/startup/units", "meters");
848 } else if ( arg.find( "--time-offset" ) == 0 ) {
849 fgSetInt("/sim/startup/time-offset",
850 parse_time_offset( (arg.substr(14)) ));
851 fgSetString("/sim/startup/time-offset-type", "system-offset");
852 } else if ( arg.find( "--time-match-real") == 0 ) {
853 fgSetString("/sim/startup/time-offset-type", "system-offset");
854 } else if ( arg.find( "--time-match-local") == 0 ) {
855 fgSetString("/sim/startup/time-offset-type", "latitude-offset");
856 } else if ( arg.find( "--start-date-sys=") == 0 ) {
857 fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
858 fgSetString("/sim/startup/time-offset-type", "system");
859 } else if ( arg.find( "--start-date-lat=") == 0 ) {
860 fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
861 fgSetString("/sim/startup/time-offset-type", "latitude");
862 } else if ( arg.find( "--start-date-gmt=") == 0 ) {
863 fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
864 fgSetString("/sim/startup/time-offset-type", "gmt");
865 } else if ( arg == "--hud-tris" ) {
866 fgSetString("/sim/hud/frame-stat-type", "tris");
867 } else if ( arg == "--hud-culled" ) {
868 fgSetString("/sim/hud/frame-stat-type", "culled");
869 } else if ( arg.find( "--atc610x" ) == 0 ) {
870 add_channel( "atc610x", "dummy" );
871 } else if ( arg.find( "--atlas=" ) == 0 ) {
872 add_channel( "atlas", arg.substr(8) );
873 } else if ( arg.find( "--httpd=" ) == 0 ) {
874 add_channel( "httpd", arg.substr(8) );
875 #ifdef FG_JPEG_SERVER
876 } else if ( arg.find( "--jpg-httpd=" ) == 0 ) {
877 add_channel( "jpg-httpd", arg.substr(12) );
879 } else if ( arg.find( "--native=" ) == 0 ) {
880 add_channel( "native", arg.substr(9) );
881 } else if ( arg.find( "--native-ctrls=" ) == 0 ) {
882 add_channel( "native_ctrls", arg.substr(15) );
883 } else if ( arg.find( "--native-fdm=" ) == 0 ) {
884 add_channel( "native_fdm", arg.substr(13) );
885 } else if ( arg.find( "--opengc=" ) == 0 ) {
887 // cout << "Adding channel for OpenGC Display" << endl; cin >> stop;
888 add_channel( "opengc", arg.substr(9) );
889 } else if ( arg.find( "--garmin=" ) == 0 ) {
890 add_channel( "garmin", arg.substr(9) );
891 } else if ( arg.find( "--nmea=" ) == 0 ) {
892 add_channel( "nmea", arg.substr(7) );
893 } else if ( arg.find( "--props=" ) == 0 ) {
894 add_channel( "props", arg.substr(8) );
895 } else if ( arg.find( "--telnet=" ) == 0 ) {
896 add_channel( "telnet", arg.substr(9) );
897 } else if ( arg.find( "--pve=" ) == 0 ) {
898 add_channel( "pve", arg.substr(6) );
899 } else if ( arg.find( "--ray=" ) == 0 ) {
900 add_channel( "ray", arg.substr(6) );
901 } else if ( arg.find( "--rul=" ) == 0 ) {
902 add_channel( "rul", arg.substr(6) );
903 } else if ( arg.find( "--joyclient=" ) == 0 ) {
904 add_channel( "joyclient", arg.substr(12) );
905 #ifdef FG_NETWORK_OLK
906 } else if ( arg == "--disable-network-olk" ) {
907 fgSetBool("/sim/networking/olk", false);
908 } else if ( arg== "--enable-network-olk") {
909 fgSetBool("/sim/networking/olk", true);
910 } else if ( arg == "--net-hud" ) {
911 fgSetBool("/sim/hud/net-display", true);
912 net_hud_display = 1; // FIXME
913 } else if ( arg.find( "--net-id=") == 0 ) {
914 fgSetString("sim/networking/call-sign", arg.substr(9).c_str());
916 } else if ( arg.find( "--prop:" ) == 0 ) {
917 string assign = arg.substr(7);
918 string::size_type pos = assign.find('=');
919 if ( pos == arg.npos || pos == 0 ) {
920 SG_LOG( SG_GENERAL, SG_ALERT, "Bad property assignment: " << arg );
921 return FG_OPTIONS_ERROR;
923 string name = assign.substr(0, pos);
924 string value = assign.substr(pos + 1);
925 fgSetString(name.c_str(), value.c_str());
926 // SG_LOG(SG_GENERAL, SG_INFO, "Setting default value of property "
927 // << name << " to \"" << value << '"');
928 } else if ( arg.find("--trace-read=") == 0) {
929 string name = arg.substr(13);
930 SG_LOG(SG_GENERAL, SG_INFO, "Tracing reads for property " << name);
931 fgGetNode(name.c_str(), true)
932 ->setAttribute(SGPropertyNode::TRACE_READ, true);
933 } else if ( arg.find("--trace-write=") == 0) {
934 string name = arg.substr(14);
935 SG_LOG(SG_GENERAL, SG_INFO, "Tracing writes for property " << name);
936 fgGetNode(name.c_str(), true)
937 ->setAttribute(SGPropertyNode::TRACE_WRITE, true);
938 } else if ( arg.find( "--view-offset=" ) == 0 ) {
939 // $$$ begin - added VS Renganathan, 14 Oct 2K
940 // for multi-window outside window imagery
941 string woffset = arg.substr( 14 );
942 double default_view_offset = 0.0;
943 if ( woffset == "LEFT" ) {
944 default_view_offset = SGD_PI * 0.25;
945 } else if ( woffset == "RIGHT" ) {
946 default_view_offset = SGD_PI * 1.75;
947 } else if ( woffset == "CENTER" ) {
948 default_view_offset = 0.00;
950 default_view_offset = atof( woffset.c_str() ) * SGD_DEGREES_TO_RADIANS;
952 /* apparently not used (CLO, 11 Jun 2002)
953 FGViewer *pilot_view =
954 (FGViewer *)globals->get_viewmgr()->get_view( 0 ); */
955 // this will work without calls to the viewer...
956 fgSetDouble( "/sim/current-view/heading-offset-deg",
957 default_view_offset * SGD_RADIANS_TO_DEGREES );
958 // $$$ end - added VS Renganathan, 14 Oct 2K
959 } else if ( arg.find( "--visibility=" ) == 0 ) {
960 fgSetDouble("/environment/visibility-m", atof(arg.substr(13)));
961 } else if ( arg.find( "--visibility-miles=" ) == 0 ) {
962 double visibility = atof(arg.substr(19)) * 5280.0 * SG_FEET_TO_METER;
963 fgSetDouble("/environment/visibility-m", visibility);
964 } else if ( arg.find( "--random-wind" ) == 0 ) {
965 double min_hdg = sg_random() * 360.0;
966 double max_hdg = min_hdg + (20 - sqrt(sg_random() * 400));
967 double speed = 40 - sqrt(sg_random() * 1600.0);
968 double gust = speed + (10 - sqrt(sg_random() * 100));
969 setup_wind(min_hdg, max_hdg, speed, gust);
970 } else if ( arg.find( "--wind=" ) == 0 ) {
971 double min_hdg, max_hdg, speed, gust;
972 if (!parse_wind(arg.substr(7), &min_hdg, &max_hdg, &speed, &gust)) {
973 SG_LOG( SG_GENERAL, SG_ALERT, "bad wind value " << arg.substr(7) );
974 return FG_OPTIONS_ERROR;
976 setup_wind(min_hdg, max_hdg, speed, gust);
977 } else if ( arg.find( "--wp=" ) == 0 ) {
978 parse_wp( arg.substr( 5 ) );
979 } else if ( arg.find( "--flight-plan=") == 0) {
980 parse_flightplan ( arg.substr (14) );
981 } else if ( arg.find( "--config=" ) == 0 ) {
982 string file = arg.substr(9);
984 readProperties(file, globals->get_props());
985 } catch (const sg_exception &e) {
986 string message = "Error loading config file: ";
987 message += e.getFormattedMessage();
988 SG_LOG(SG_INPUT, SG_ALERT, message);
991 } else if ( arg.find( "--aircraft=" ) == 0 ) {
992 // read in the top level aircraft definition file
993 SGPath apath( globals->get_fg_root() );
994 apath.append( "Aircraft" );
995 apath.append( arg.substr(11) );
996 apath.concat( "-set.xml" );
997 SG_LOG(SG_INPUT, SG_INFO, "Reading aircraft: " << arg.substr(11)
998 << " from " << apath.str());
999 readProperties( apath.str(), globals->get_props() );
1001 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
1002 return FG_OPTIONS_ERROR;
1005 return FG_OPTIONS_OK;
1009 // Scan the command line options for an fg_root definition and set
1012 fgScanForRoot (int argc, char **argv)
1016 SG_LOG(SG_GENERAL, SG_INFO, "Scanning for root: command line");
1018 while ( i < argc ) {
1019 SG_LOG( SG_GENERAL, SG_DEBUG, "argv[" << i << "] = " << argv[i] );
1021 string arg = argv[i];
1022 if ( arg.find( "--fg-root=" ) == 0 ) {
1023 return arg.substr( 10 );
1033 // Scan the config file for an fg_root definition and set just that.
1035 fgScanForRoot (const string& path)
1037 sg_gzifstream in( path );
1038 if ( !in.is_open() )
1041 SG_LOG( SG_GENERAL, SG_INFO, "Scanning for root: " << path );
1045 while ( ! in.eof() ) {
1048 while ( in.get(c) && c != '\0' ) {
1053 #if defined( macintosh )
1054 getline( in, line, '\r' );
1056 getline( in, line, '\n' );
1059 // catch extraneous (DOS) line ending character
1060 if ( line[line.length() - 1] < 32 ) {
1061 line = line.substr( 0, line.length()-1 );
1064 if ( line.find( "--fg-root=" ) == 0 ) {
1065 return line.substr( 10 );
1075 // Parse the command line options
1077 fgParseArgs (int argc, char **argv)
1079 bool in_options = true;
1080 bool verbose = false;
1083 SG_LOG(SG_GENERAL, SG_INFO, "Processing command line arguments");
1085 for (int i = 1; i < argc; i++) {
1086 string arg = argv[i];
1088 if (in_options && (arg.find('-') == 0)) {
1092 int result = parse_option(arg);
1093 if ((result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR))
1096 else if (result == FG_OPTIONS_VERBOSE_HELP)
1099 else if (result == FG_OPTIONS_SHOW_AIRCRAFT) {
1106 SG_LOG(SG_GENERAL, SG_INFO,
1107 "Reading command-line property file " << arg);
1108 readProperties(arg, globals->get_props());
1117 SG_LOG(SG_GENERAL, SG_INFO, "Finished command line arguments");
1121 // Parse config file options
1123 fgParseOptions (const string& path) {
1124 sg_gzifstream in( path );
1125 if ( !in.is_open() ) {
1129 SG_LOG( SG_GENERAL, SG_INFO, "Processing config file: " << path );
1133 while ( ! in.eof() ) {
1136 while ( in.get(c) && c != '\0' ) {
1141 #if defined( macintosh )
1142 getline( in, line, '\r' );
1144 getline( in, line, '\n' );
1147 // catch extraneous (DOS) line ending character
1148 if ( line[line.length() - 1] < 32 ) {
1149 line = line.substr( 0, line.length()-1 );
1152 if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
1153 cerr << endl << "Config file parse error: " << path << " '"
1154 << line << "'" << endl;
1163 // Print usage message
1165 fgUsage (bool verbose)
1167 SGPropertyNode *locale = globals->get_locale();
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 = locale->getNode(options->getStringValue("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(), ' ');
1234 // There may be more than one <description> tag assosiated
1238 vector<SGPropertyNode_ptr>desc =
1239 option[k]->getChildren("description");
1241 if (desc.size() > 0) {
1242 for ( unsigned int l = 0; l < desc.size(); l++) {
1244 // There may be more than one translation line.
1246 string t = desc[l]->getStringValue();
1247 SGPropertyNode *n = locale->getNode("strings");
1248 vector<SGPropertyNode_ptr>trans_desc =
1249 n->getChildren(t.substr(8).c_str());
1251 for ( unsigned int m = 0; m < trans_desc.size(); m++ ) {
1252 string t_str = trans_desc[m]->getStringValue();
1254 if ((m > 0) || ((l > 0) && m == 0)) {
1255 snprintf(cstr, 96, "%32c", ' ');
1260 // If the string is too large to fit on the screen,
1261 // then split it up in several pieces.
1263 while ( t_str.size() > 47 ) {
1265 unsigned int m = t_str.rfind(' ', 47);
1266 msg += t_str.substr(0, m);
1267 snprintf(cstr, 96, "\n%32c", ' ');
1270 t_str.erase(t_str.begin(), t_str.begin() + m + 1);
1272 msg += t_str + '\n';
1279 SGPropertyNode *name =
1280 locale->getNode(section[j]->getStringValue("name"));
1282 if (!msg.empty() && name) {
1283 cout << endl << name->getStringValue() << ":" << endl;
1291 cout << "For a complete list of options use --help --verbose" << endl;
1295 // Show available aircraft types
1296 void fgShowAircraft(void) {
1297 SGPath path( globals->get_fg_root() );
1298 path.append("Aircraft");
1303 dirp = ulOpenDir(path.c_str());
1305 cerr << "Unable to open aircraft directory." << endl;
1309 cout << "Available aircraft:" << endl;
1310 while ((dire = ulReadDir(dirp)) != NULL) {
1313 if ((ptr = strstr(dire->d_name, "-set.xml")) && ptr[8] == '\0' ) {
1314 SGPath afile = path;
1315 afile.append(dire->d_name);
1319 SGPropertyNode root;
1321 readProperties(afile.str(), &root);
1326 SGPropertyNode *desc, *node = root.getNode("sim");
1328 desc = node->getNode("description");
1331 if (strlen(dire->d_name) <= 27)
1332 snprintf(cstr, 96, " %-27s %s", dire->d_name,
1333 (desc) ? desc->getStringValue() : "" );
1336 snprintf(cstr, 96, " %-27s\n%32c%s", dire->d_name, ' ',
1337 (desc) ? desc->getStringValue() : "" );
1339 cout << cstr << endl;