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>
32 #if defined(FX) && defined(XMESA)
33 bool global_fullscreen = true;
36 #include <math.h> // rint()
38 #include <stdlib.h> // atof(), atoi()
43 #include <simgear/misc/sgstream.hxx>
45 // #include <Include/general.hxx>
46 // #include <Airports/simple.hxx>
47 // #include <Cockpit/cockpit.hxx>
48 // #include <FDM/flight.hxx>
49 // #include <FDM/UIUCModel/uiuc_aircraftdir.h>
51 # include <NetworkOLK/network.h>
56 #include "globals.hxx"
57 #include "fg_init.hxx"
58 #include "fg_props.hxx"
59 #include "options.hxx"
62 SG_USING_NAMESPACE(std);
65 #define NEW_DEFAULT_MODEL_HZ 120
75 atof( const string& str )
79 // -dw- if ::atof is called, then we get an infinite loop
80 return std::atof( str.c_str() );
82 return ::atof( str.c_str() );
87 atoi( const string& str )
90 // -dw- if ::atoi is called, then we get an infinite loop
91 return std::atoi( str.c_str() );
93 return ::atoi( str.c_str() );
99 * Set a few fail-safe default property values.
101 * These should all be set in $FG_ROOT/preferences.xml, but just
102 * in case, we provide some initial sane values here. This method
103 * should be invoked *before* reading any init files.
108 // set a possibly independent location for scenery data
109 char *envp = ::getenv( "FG_SCENERY" );
111 if ( envp != NULL ) {
112 // fg_root could be anywhere, so default to environmental
113 // variable $FG_ROOT if it is set.
114 globals->set_fg_scenery(envp);
116 // Otherwise, default to Scenery being in $FG_ROOT/Scenery
117 globals->set_fg_scenery("");
119 // Position (Globe, AZ)
120 fgSetDouble("/position/longitude-deg", -110.6642444);
121 fgSetDouble("/position/latitude-deg", 33.3528917);
122 fgSetDouble("/position/altitude-ft", -9999.0);
125 fgSetDouble("/orientation/heading-deg", 270);
126 fgSetDouble("/orientation/roll-deg", 0);
127 fgSetDouble("/orientation/pitch-deg", 0.424);
130 fgSetString("/sim/startup/speed-set", "knots");
131 fgSetDouble("/velocities/uBody-fps", 0.0);
132 fgSetDouble("/velocities/vBody-fps", 0.0);
133 fgSetDouble("/velocities/wBody-fps", 0.0);
134 fgSetDouble("/velocities/speed-north-fps", 0.0);
135 fgSetDouble("/velocities/speed-east-fps", 0.0);
136 fgSetDouble("/velocities/speed-down-fps", 0.0);
137 fgSetDouble("/velocities/airspeed-kt", 0.0);
138 fgSetDouble("/velocities/mach", 0.0);
141 fgSetBool("/sim/startup/game-mode", false);
142 fgSetBool("/sim/startup/splash-screen", true);
143 fgSetBool("/sim/startup/intro-music", true);
144 // we want mouse-pointer to have an undefined value if nothing is
145 // specified so we can do the right thing for voodoo-1/2 cards.
146 // fgSetString("/sim/startup/mouse-pointer", "disabled");
147 fgSetString("/sim/control-mode", "joystick");
148 fgSetBool("/sim/auto-coordination", false);
150 fgSetString("/sim/startup/browser-app", "netscape");
152 fgSetString("/sim/startup/browser-app", "webrun.bat");
155 fgSetBool("/sim/hud/visibility", false);
156 fgSetBool("/sim/panel/visibility", true);
157 fgSetBool("/sim/sound", true);
158 fgSetBool("/sim/hud/antialiased", false);
160 // Flight Model options
161 fgSetString("/sim/flight-model", "larcsim");
162 fgSetString("/sim/aircraft", "c172");
163 fgSetInt("/sim/model-hz", NEW_DEFAULT_MODEL_HZ);
164 fgSetInt("/sim/speed-up", 1);
165 fgSetBool("/sim/startup/trim", false);
166 fgSetBool("/sim/startup/onground", true);
169 fgSetString("/sim/rendering/fog", "nicest");
170 fgSetBool("/environment/clouds/status", true);
171 fgSetDouble("/environment/clouds/altitude-ft", 5000);
172 fgSetBool("/sim/startup/fullscreen", false);
173 fgSetBool("/sim/rendering/shading", true);
174 fgSetBool("/sim/rendering/skyblend", true);
175 fgSetBool("/sim/rendering/textures", true);
176 fgSetBool("/sim/rendering/wireframe", false);
177 fgSetInt("/sim/startup/xsize", 800);
178 fgSetInt("/sim/startup/ysize", 600);
179 fgSetInt("/sim/rendering/bits-per-pixel", 16);
180 fgSetString("/sim/view-mode", "pilot");
181 fgSetDouble("/sim/view/offset-deg", 0);
182 fgSetDouble("/environment/visibility-m", 20000);
185 fgSetString("/sim/startup/units", "feet");
186 fgSetString("/sim/hud/frame-stat-type", "tris");
189 fgSetInt("/sim/startup/time-offset", 0);
190 fgSetString("/sim/startup/time-offset-type", "system-offset");
192 fgSetBool("/sim/networking/network-olk", false);
193 fgSetString("/sim/networking/call-sign", "Johnny");
197 // parse a time string ([+/-]%f[:%f[:%f]]) into hours
199 parse_time(const string& time_in) {
200 char *time_str, num[256];
201 double hours, minutes, seconds;
206 time_str = (char *)time_in.c_str();
208 // printf("parse_time(): %s\n", time_str);
211 if ( strlen(time_str) ) {
212 if ( time_str[0] == '+' ) {
215 } else if ( time_str[0] == '-' ) {
220 // printf("sign = %d\n", sign);
223 if ( strlen(time_str) ) {
225 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
226 num[i] = time_str[0];
230 if ( time_str[0] == ':' ) {
235 // printf("hours = %.2lf\n", hours);
241 if ( strlen(time_str) ) {
243 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
244 num[i] = time_str[0];
248 if ( time_str[0] == ':' ) {
253 // printf("minutes = %.2lf\n", minutes);
255 result += minutes / 60.0;
259 if ( strlen(time_str) ) {
261 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
262 num[i] = time_str[0];
268 // printf("seconds = %.2lf\n", seconds);
270 result += seconds / 3600.0;
273 return(sign * result);
277 // parse a date string (yyyy:mm:dd:hh:mm:ss) into a time_t (seconds)
279 parse_date( const string& date)
282 char * date_str, num[256];
284 // initialize to zero
291 gmt.tm_isdst = 0; // ignore daylight savings time for the moment
292 date_str = (char *)date.c_str();
294 if ( strlen(date_str) ) {
296 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
297 num[i] = date_str[0];
301 if ( date_str[0] == ':' ) {
305 gmt.tm_year = atoi(num) - 1900;
308 if ( strlen(date_str) ) {
310 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
311 num[i] = date_str[0];
315 if ( date_str[0] == ':' ) {
319 gmt.tm_mon = atoi(num) -1;
322 if ( strlen(date_str) ) {
324 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
325 num[i] = date_str[0];
329 if ( date_str[0] == ':' ) {
333 gmt.tm_mday = atoi(num);
336 if ( strlen(date_str) ) {
338 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
339 num[i] = date_str[0];
343 if ( date_str[0] == ':' ) {
347 gmt.tm_hour = atoi(num);
350 if ( strlen(date_str) ) {
352 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
353 num[i] = date_str[0];
357 if ( date_str[0] == ':' ) {
361 gmt.tm_min = atoi(num);
364 if ( strlen(date_str) ) {
366 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
367 num[i] = date_str[0];
371 if ( date_str[0] == ':' ) {
375 gmt.tm_sec = atoi(num);
377 time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
378 gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
379 //printf ("Date is %s\n", ctime(&theTime));
380 //printf ("in seconds that is %d\n", theTime);
386 // parse angle in the form of [+/-]ddd:mm:ss into degrees
388 parse_degree( const string& degree_str) {
389 double result = parse_time( degree_str );
391 // printf("Degree = %.4f\n", result);
397 // parse time offset string into seconds
399 parse_time_offset( const string& time_str) {
402 // printf("time offset = %s\n", time_str);
405 result = (int)rint(parse_time(time_str) * 3600.0);
407 result = (int)(parse_time(time_str) * 3600.0);
410 // printf("parse_time_offset(): %d\n", result);
416 // Parse --fov=x.xx type option
418 parse_fov( const string& arg ) {
419 double fov = atof(arg);
421 if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
422 if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
424 fgSetDouble("/sim/field-of-view", fov);
426 // printf("parse_fov(): result = %.4f\n", fov);
432 // Parse I/O channel option
434 // Format is "--protocol=medium,direction,hz,medium_options,..."
436 // protocol = { native, nmea, garmin, fgfs, rul, pve, etc. }
437 // medium = { serial, socket, file, etc. }
438 // direction = { in, out, bi }
439 // hz = number of times to process channel per second (floating
440 // point values are ok.
442 // Serial example "--nmea=serial,dir,hz,device,baud" where
444 // device = OS device name of serial line to be open()'ed
445 // baud = {300, 1200, 2400, ..., 230400}
447 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
449 // machine = machine name or ip address if client (leave empty if server)
450 // port = port, leave empty to let system choose
451 // style = tcp or udp
453 // File example "--garmin=file,dir,hz,filename" where
455 // filename = file system file name
458 parse_channel( const string& type, const string& channel_str ) {
459 // cout << "Channel string = " << channel_str << endl;
461 globals->get_channel_options_list()->push_back( type + "," + channel_str );
467 // Parse --wp=ID[@alt]
469 parse_wp( const string& arg ) {
473 unsigned int pos = arg.find( "@" );
474 if ( pos != string::npos ) {
475 id = arg.substr( 0, pos );
476 alt_str = arg.substr( pos + 1 );
477 // cout << "id str = " << id << " alt str = " << alt_str << endl;
478 alt = atof( alt_str.c_str() );
479 if ( fgGetString("/sim/startup/units") == "feet" ) {
480 alt *= SG_FEET_TO_METER;
487 if ( fgFindAirportID( id, &a ) ) {
488 SGWayPoint wp( a.longitude, a.latitude, alt, SGWayPoint::WGS84, id );
489 globals->get_route()->add_waypoint( wp );
498 // Parse --flight-plan=[file]
500 parse_flightplan(const string& arg)
502 sg_gzifstream in(arg.c_str());
503 if ( !in.is_open() ) {
509 #if defined( macintosh )
510 getline( in, line, '\r' );
512 getline( in, line, '\n' );
515 // catch extraneous (DOS) line ending character
516 if ( line[line.length() - 1] < 32 ) {
517 line = line.substr( 0, line.length()-1 );
530 // Parse a single option
532 parse_option (const string& arg)
535 if ( (arg == "--help") || (arg == "-h") ) {
536 // help/usage request
537 return(FG_OPTIONS_HELP);
538 } else if ( arg == "--disable-game-mode") {
539 fgSetBool("/sim/startup/game-mode", false);
540 } else if ( arg == "--enable-game-mode" ) {
541 fgSetBool("/sim/startup/game-mode", true);
542 } else if ( arg == "--disable-splash-screen" ) {
543 fgSetBool("/sim/startup/splash-screen", false);
544 } else if ( arg == "--enable-splash-screen" ) {
545 fgSetBool("/sim/startup/splash-screen", true);
546 } else if ( arg == "--disable-intro-music" ) {
547 fgSetBool("/sim/startup/intro-music", false);
548 } else if ( arg == "--enable-intro-music" ) {
549 fgSetBool("/sim/startup/intro-music", true);
550 } else if ( arg == "--disable-mouse-pointer" ) {
551 fgSetString("/sim/startup/mouse-pointer", "disabled");
552 } else if ( arg == "--enable-mouse-pointer" ) {
553 fgSetString("/sim/startup/mouse-pointer", "enabled");
554 } else if ( arg == "--disable-freeze" ) {
555 fgSetBool("/sim/freeze", false);
556 } else if ( arg == "--enable-freeze" ) {
557 fgSetBool("/sim/freeze", true);
558 } else if ( arg == "--disable-anti-alias-hud" ) {
559 fgSetBool("/sim/hud/antialiased", false);
560 } else if ( arg == "--enable-anti-alias-hud" ) {
561 fgSetBool("/sim/hud/antialiased", true);
562 } else if ( arg.find( "--control=") == 0 ) {
563 fgSetString("/sim/control-mode", arg.substr(10));
564 } else if ( arg == "--disable-auto-coordination" ) {
565 fgSetBool("/sim/auto-coordination", false);
566 } else if ( arg == "--enable-auto-coordination" ) {
567 fgSetBool("/sim/auto-coordination", true);
568 } else if ( arg.find( "--browser-app=") == 0 ) {
569 fgSetString("/sim/startup/browser-app", arg.substr(14));
570 } else if ( arg == "--disable-hud" ) {
571 fgSetBool("/sim/hud/visibility", false);
572 } else if ( arg == "--enable-hud" ) {
573 fgSetBool("/sim/hud/visibility", true);
574 } else if ( arg == "--disable-panel" ) {
575 fgSetBool("/sim/panel/visibility", false);
576 } else if ( arg == "--enable-panel" ) {
577 fgSetBool("/sim/panel/visibility", true);
578 } else if ( arg == "--disable-sound" ) {
579 fgSetBool("/sim/sound", false);
580 } else if ( arg == "--enable-sound" ) {
581 fgSetBool("/sim/sound", true);
582 } else if ( arg.find( "--airport-id=") == 0 ) {
583 // NB: changed property name!!!
584 fgSetString("/sim/startup/airport-id", arg.substr(13));
585 } else if ( arg.find( "--offset-distance=") == 0 ) {
586 fgSetDouble("/sim/startup/offset-distance", atof(arg.substr(18)));
587 } else if ( arg.find( "--offset-azimuth=") == 0 ) {
588 fgSetDouble("/sim/startup/offset-azimuth", atof(arg.substr(17)));
589 } else if ( arg.find( "--lon=" ) == 0 ) {
590 fgSetDouble("/position/longitude-deg",
591 parse_degree(arg.substr(6)));
592 fgSetString("/sim/startup/airport-id", "");
593 } else if ( arg.find( "--lat=" ) == 0 ) {
594 fgSetDouble("/position/latitude-deg",
595 parse_degree(arg.substr(6)));
596 fgSetString("/sim/startup/airport-id", "");
597 } else if ( arg.find( "--altitude=" ) == 0 ) {
598 fgSetBool("/sim/startup/onground", false);
599 if ( fgGetString("/sim/startup/units") == "feet" )
600 fgSetDouble("/position/altitude-ft", atof(arg.substr(11)));
602 fgSetDouble("/position/altitude-ft",
603 atof(arg.substr(11)) * SG_METER_TO_FEET);
604 } else if ( arg.find( "--uBody=" ) == 0 ) {
605 fgSetString("/sim/startup/speed-set", "UVW");
606 if ( fgGetString("/sim/startup/units") == "feet" )
607 fgSetDouble("/velocities/uBody-fps", atof(arg.substr(8)));
609 fgSetDouble("/velocities/uBody-fps",
610 atof(arg.substr(8)) * SG_METER_TO_FEET);
611 } else if ( arg.find( "--vBody=" ) == 0 ) {
612 fgSetString("/sim/startup/speed-set", "UVW");
613 if ( fgGetString("/sim/startup/units") == "feet" )
614 fgSetDouble("/velocities/vBody-fps", atof(arg.substr(8)));
616 fgSetDouble("/velocities/vBody-fps",
617 atof(arg.substr(8)) * SG_METER_TO_FEET);
618 } else if ( arg.find( "--wBody=" ) == 0 ) {
619 fgSetString("/sim/startup/speed-set", "UVW");
620 if ( fgGetString("/sim/startup/units") == "feet" )
621 fgSetDouble("/velocities/wBody-fps", atof(arg.substr(8)));
623 fgSetDouble("/velocities/wBody-fps",
624 atof(arg.substr(8)) * SG_METER_TO_FEET);
625 } else if ( arg.find( "--vNorth=" ) == 0 ) {
626 fgSetString("/sim/startup/speed-set", "NED");
627 if ( fgGetString("/sim/startup/units") == "feet" )
628 fgSetDouble("/velocities/speed-north-fps", atof(arg.substr(9)));
630 fgSetDouble("/velocities/speed-north-fps",
631 atof(arg.substr(9)) * SG_METER_TO_FEET);
632 } else if ( arg.find( "--vEast=" ) == 0 ) {
633 fgSetString("/sim/startup/speed-set", "NED");
634 if ( fgGetString("/sim/startup/units") == "feet" )
635 fgSetDouble("/velocities/speed-east-fps", atof(arg.substr(8)));
637 fgSetDouble("/velocities/speed-east-fps",
638 atof(arg.substr(8)) * SG_METER_TO_FEET);
639 } else if ( arg.find( "--vDown=" ) == 0 ) {
640 fgSetString("/sim/startup/speed-set", "NED");
641 if ( fgGetString("/sim/startup/units") == "feet" )
642 fgSetDouble("/velocities/speed-down-fps", atof(arg.substr(8)));
644 fgSetDouble("/velocities/speed-down-fps",
645 atof(arg.substr(8)) * SG_METER_TO_FEET);
646 } else if ( arg.find( "--vc=" ) == 0) {
647 fgSetString("/sim/startup/speed-set", "knots");
648 fgSetDouble("/velocities/airspeed-kt", atof(arg.substr(5)));
649 } else if ( arg.find( "--mach=" ) == 0) {
650 fgSetString("/sim/startup/speed-set", "mach");
651 fgSetDouble("/velocities/mach", atof(arg.substr(7)));
652 } else if ( arg.find( "--heading=" ) == 0 ) {
653 fgSetDouble("/orientation/heading-deg", atof(arg.substr(10)));
654 } else if ( arg.find( "--roll=" ) == 0 ) {
655 fgSetDouble("/orientation/roll-deg", atof(arg.substr(7)));
656 } else if ( arg.find( "--pitch=" ) == 0 ) {
657 fgSetDouble("/orientation/pitch-deg", atof(arg.substr(8)));
658 } else if ( arg.find( "--fg-root=" ) == 0 ) {
659 globals->set_fg_root(arg.substr( 10 ));
660 } else if ( arg.find( "--fg-scenery=" ) == 0 ) {
661 globals->set_fg_scenery(arg.substr( 13 ));
662 } else if ( arg.find( "--fdm=" ) == 0 ) {
663 fgSetString("/sim/flight-model", arg.substr(6));
664 } else if ( arg.find( "--aircraft=" ) == 0 ) {
665 fgSetString("/sim/aircraft", arg.substr(11));
666 } else if ( arg.find( "--aircraft-dir=" ) == 0 ) {
667 fgSetString("/sim/aircraft-dir", arg.substr(15));
668 } else if ( arg.find( "--model-hz=" ) == 0 ) {
669 fgSetInt("/sim/model-hz", atoi(arg.substr(11)));
670 } else if ( arg.find( "--speed=" ) == 0 ) {
671 fgSetInt("/sim/speed-up", atoi(arg.substr(8)));
672 } else if ( arg.find( "--trim") == 0) {
673 fgSetBool("/sim/startup/trim", true);
674 } else if ( arg.find( "--notrim") == 0) {
675 fgSetBool("/sim/startup/trim", false);
676 } else if ( arg.find( "--on-ground") == 0) {
677 fgSetBool("/sim/startup/onground", true);
678 } else if ( arg.find( "--in-air") == 0) {
679 fgSetBool("/sim/startup/onground", false);
680 } else if ( arg == "--fog-disable" ) {
681 fgSetString("/sim/rendering/fog", "disabled");
682 } else if ( arg == "--fog-fastest" ) {
683 fgSetString("/sim/rendering/fog", "fastest");
684 } else if ( arg == "--fog-nicest" ) {
685 fgSetString("/sim/fog", "nicest");
686 } else if ( arg == "--disable-clouds" ) {
687 fgSetBool("/environment/clouds/status", false);
688 } else if ( arg == "--enable-clouds" ) {
689 fgSetBool("/environment/clouds/status", true);
690 } else if ( arg.find( "--clouds-asl=" ) == 0 ) {
691 // FIXME: check units
692 if ( fgGetString("/sim/startup/units") == "feet" )
693 fgSetDouble("/environment/clouds/altitude-ft",
694 atof(arg.substr(13)) * SG_FEET_TO_METER);
696 fgSetDouble("/environment/clouds/altitude-ft",
697 atof(arg.substr(13)));
698 } else if ( arg.find( "--fov=" ) == 0 ) {
699 parse_fov( arg.substr(6) );
700 } else if ( arg == "--disable-fullscreen" ) {
701 fgSetBool("/sim/startup/fullscreen", false);
702 } else if ( arg== "--enable-fullscreen") {
703 fgSetBool("/sim/startup/fullscreen", true);
704 } else if ( arg == "--shading-flat") {
705 fgSetBool("/sim/rendering/shading", false);
706 } else if ( arg == "--shading-smooth") {
707 fgSetBool("/sim/rendering/shading", true);
708 } else if ( arg == "--disable-skyblend") {
709 fgSetBool("/sim/rendering/skyblend", false);
710 } else if ( arg== "--enable-skyblend" ) {
711 fgSetBool("/sim/rendering/skyblend", true);
712 } else if ( arg == "--disable-textures" ) {
713 fgSetBool("/sim/rendering/textures", false);
714 } else if ( arg == "--enable-textures" ) {
715 fgSetBool("/sim/rendering/textures", true);
716 } else if ( arg == "--disable-wireframe" ) {
717 fgSetBool("/sim/rendering/wireframe", false);
718 } else if ( arg == "--enable-wireframe" ) {
719 fgSetBool("/sim/rendering/wireframe", true);
720 } else if ( arg.find( "--geometry=" ) == 0 ) {
721 bool geometry_ok = true;
722 int xsize = 0, ysize = 0;
723 string geometry = arg.substr( 11 );
724 string::size_type i = geometry.find('x');
726 if (i != string::npos) {
727 xsize = atoi(geometry.substr(0, i));
728 ysize = atoi(geometry.substr(i+1));
733 if ( xsize <= 0 || ysize <= 0 ) {
739 if ( !geometry_ok ) {
740 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown geometry: " << geometry );
741 SG_LOG( SG_GENERAL, SG_ALERT,
742 "Setting geometry to " << xsize << 'x' << ysize << '\n');
744 SG_LOG( SG_GENERAL, SG_INFO,
745 "Setting geometry to " << xsize << 'x' << ysize << '\n');
746 fgSetInt("/sim/startup/xsize", xsize);
747 fgSetInt("/sim/startup/ysize", ysize);
749 } else if ( arg.find( "--bpp=" ) == 0 ) {
750 string bits_per_pix = arg.substr( 6 );
751 if ( bits_per_pix == "16" ) {
752 fgSetInt("/sim/rendering/bits-per-pixel", 16);
753 } else if ( bits_per_pix == "24" ) {
754 fgSetInt("/sim/rendering/bits-per-pixel", 24);
755 } else if ( bits_per_pix == "32" ) {
756 fgSetInt("/sim/rendering/bits-per-pixel", 32);
758 SG_LOG(SG_GENERAL, SG_ALERT, "Unsupported bpp " << bits_per_pix);
760 } else if ( arg == "--units-feet" ) {
761 fgSetString("/sim/startup/units", "feet");
762 } else if ( arg == "--units-meters" ) {
763 fgSetString("/sim/startup/units", "meters");
764 } else if ( arg.find( "--time-offset" ) == 0 ) {
765 fgSetInt("/sim/startup/time-offset",
766 parse_time_offset( (arg.substr(14)) ));
767 } else if ( arg.find( "--time-match-real") == 0 ) {
768 fgSetString("/sim/startup/time-offset-type",
770 } else if ( arg.find( "--time-match-local") == 0 ) {
771 fgSetString("/sim/startup/time-offset-type",
773 } else if ( arg.find( "--start-date-sys=") == 0 ) {
774 fgSetInt("/sim/startup/time-offset",
775 parse_date((arg.substr(17))));
776 fgSetString("/sim/startup/time-offset-type", "system");
777 } else if ( arg.find( "--start-date-lat=") == 0 ) {
778 fgSetInt("/sim/startup/time-offset",
779 parse_date((arg.substr(17))));
780 fgSetString("/sim/startup/time-offset-type",
782 } else if ( arg.find( "--start-date-gmt=") == 0 ) {
783 fgSetInt("/sim/startup/time-offset",
784 parse_date((arg.substr(17))));
785 fgSetString("/sim/startup/time-offset-type", "gmt");
786 } else if ( arg == "--hud-tris" ) {
787 fgSetString("/sim/hud/frame-stat-type", "tris");
788 } else if ( arg == "--hud-culled" ) {
789 fgSetString("/sim/hud/frame-stat-type", "culled");
790 } else if ( arg.find( "--atlas=" ) == 0 ) {
791 parse_channel( "atlas", arg.substr(8) );
792 } else if ( arg.find( "--native=" ) == 0 ) {
793 parse_channel( "native", arg.substr(9) );
794 } else if ( arg.find( "--garmin=" ) == 0 ) {
795 parse_channel( "garmin", arg.substr(9) );
796 } else if ( arg.find( "--nmea=" ) == 0 ) {
797 parse_channel( "nmea", arg.substr(7) );
798 } else if ( arg.find( "--props=" ) == 0 ) {
799 parse_channel( "props", arg.substr(8) );
800 } else if ( arg.find( "--pve=" ) == 0 ) {
801 parse_channel( "pve", arg.substr(6) );
802 } else if ( arg.find( "--ray=" ) == 0 ) {
803 parse_channel( "ray", arg.substr(6) );
804 } else if ( arg.find( "--rul=" ) == 0 ) {
805 parse_channel( "rul", arg.substr(6) );
806 } else if ( arg.find( "--joyclient=" ) == 0 ) {
807 parse_channel( "joyclient", arg.substr(12) );
808 #ifdef FG_NETWORK_OLK
809 } else if ( arg == "--disable-network-olk" ) {
810 fgSetBool("/sim/networking/olk", false);
811 } else if ( arg== "--enable-network-olk") {
812 fgSetBool("/sim/networking/olk", true);
813 } else if ( arg == "--net-hud" ) {
814 fgSetBool("/sim/hud/net-display", true);
815 net_hud_display = 1; // FIXME
816 } else if ( arg.find( "--net-id=") == 0 ) {
817 fgSetString("sim/networking/call-sign", arg.substr(9));
819 } else if ( arg.find( "--prop:" ) == 0 ) {
820 string assign = arg.substr(7);
821 unsigned int pos = assign.find('=');
822 if ( pos == arg.npos || pos == 0 ) {
823 SG_LOG( SG_GENERAL, SG_ALERT, "Bad property assignment: " << arg );
824 return FG_OPTIONS_ERROR;
826 string name = assign.substr(0, pos);
827 string value = assign.substr(pos + 1);
828 fgSetString(name.c_str(), value);
829 // SG_LOG(SG_GENERAL, SG_INFO, "Setting default value of property "
830 // << name << " to \"" << value << '"');
831 // $$$ begin - added VS Renganathan, 14 Oct 2K
832 // for multi-window outside window imagery
833 } else if ( arg.find( "--view-offset=" ) == 0 ) {
834 string woffset = arg.substr( 14 );
835 double default_view_offset = 0.0;
836 if ( woffset == "LEFT" ) {
837 default_view_offset = SGD_PI * 0.25;
838 } else if ( woffset == "RIGHT" ) {
839 default_view_offset = SGD_PI * 1.75;
840 } else if ( woffset == "CENTER" ) {
841 default_view_offset = 0.00;
843 default_view_offset = atof( woffset.c_str() ) * SGD_DEGREES_TO_RADIANS;
845 FGViewerRPH *pilot_view =
846 (FGViewerRPH *)globals->get_viewmgr()->get_view( 0 );
847 pilot_view->set_view_offset( default_view_offset );
848 pilot_view->set_goal_view_offset( default_view_offset );
849 fgSetDouble("/sim/view/offset-deg", default_view_offset);
850 // $$$ end - added VS Renganathan, 14 Oct 2K
851 } else if ( arg.find( "--visibility=" ) == 0 ) {
852 fgSetDouble("/environment/visibility-m", atof(arg.substr(13)));
853 } else if ( arg.find( "--visibility-miles=" ) == 0 ) {
854 double visibility = atof(arg.substr(19)) * 5280.0 * SG_FEET_TO_METER;
855 fgSetDouble("/environment/visibility-m", visibility);
856 } else if ( arg.find( "--wind=" ) == 0 ) {
857 string val = arg.substr(7);
858 unsigned int pos = val.find('@');
859 if ( pos == string::npos ) {
860 SG_LOG( SG_GENERAL, SG_ALERT, "bad wind value " << val );
861 return FG_OPTIONS_ERROR;
863 double dir = atof(val.substr(0,pos).c_str());
864 double speed = atof(val.substr(pos+1).c_str());
865 SG_LOG(SG_GENERAL, SG_INFO, "WIND: " << dir << '@' <<
866 speed << " knots" << endl);
868 speed *= SG_NM_TO_METER * SG_METER_TO_FEET * (1.0/3600);
872 dir *= SGD_DEGREES_TO_RADIANS;
873 fgSetDouble("/environment/wind-north-fps",
875 fgSetDouble("/environment/wind-east-fps",
877 } else if ( arg.find( "--wp=" ) == 0 ) {
878 parse_wp( arg.substr( 5 ) );
879 } else if ( arg.find( "--flight-plan=") == 0) {
880 parse_flightplan ( arg.substr (14) );
881 } else if ( arg.find( "--config=" ) == 0 ) {
882 string file = arg.substr(9);
884 readProperties(file, globals->get_props());
885 } catch (const sg_io_exception &e) {
886 string message = "Error loading config file: ";
887 message += e.getMessage();
889 message += e.getLocation().asString();
890 SG_LOG(SG_INPUT, SG_ALERT, message);
894 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
895 return FG_OPTIONS_ERROR;
898 return FG_OPTIONS_OK;
902 // Scan the command line options for an fg_root definition and set
905 fgScanForRoot (int argc, char **argv)
909 SG_LOG(SG_GENERAL, SG_INFO, "Scanning for root: command line");
912 SG_LOG( SG_GENERAL, SG_DEBUG, "argv[" << i << "] = " << argv[i] );
914 string arg = argv[i];
915 if ( arg.find( "--fg-root=" ) == 0 ) {
916 return arg.substr( 10 );
926 // Scan the config file for an fg_root definition and set just that.
928 fgScanForRoot (const string& path)
930 sg_gzifstream in( path );
934 SG_LOG( SG_GENERAL, SG_INFO, "Scanning for root: " << path );
938 while ( ! in.eof() ) {
941 while ( in.get(c) && c != '\0' ) {
946 #if defined( macintosh )
947 getline( in, line, '\r' );
949 getline( in, line, '\n' );
952 // catch extraneous (DOS) line ending character
953 if ( line[line.length() - 1] < 32 ) {
954 line = line.substr( 0, line.length()-1 );
957 if ( line.find( "--fg-root=" ) == 0 ) {
958 return line.substr( 10 );
968 // Parse the command line options
970 fgParseOptions (int argc, char **argv) {
974 SG_LOG(SG_GENERAL, SG_INFO, "Processing command line arguments");
977 SG_LOG( SG_GENERAL, SG_DEBUG, "argv[" << i << "] = " << argv[i] );
979 result = parse_option(argv[i]);
980 if ( (result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR) ) {
990 // Parse config file options
992 fgParseOptions (const string& path) {
993 sg_gzifstream in( path );
994 if ( !in.is_open() ) {
998 SG_LOG( SG_GENERAL, SG_INFO, "Processing config file: " << path );
1002 while ( ! in.eof() ) {
1005 while ( in.get(c) && c != '\0' ) {
1010 #if defined( macintosh )
1011 getline( in, line, '\r' );
1013 getline( in, line, '\n' );
1016 // catch extraneous (DOS) line ending character
1017 if ( line[line.length() - 1] < 32 ) {
1018 line = line.substr( 0, line.length()-1 );
1021 if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
1022 SG_LOG( SG_GENERAL, SG_ALERT,
1023 "Config file parse error: " << path << " '"
1033 // Print usage message
1037 cout << "Usage: fgfs [ options ... ]" << endl;
1040 cout << "General Options:" << endl;
1041 cout << "\t--help -h: print usage" << endl;
1042 cout << "\t--fg-root=path: specify the root path for all the data files"
1044 cout << "\t--fg-scenery=path: specify the base path for all the scenery"
1046 << "\t\tdefaults to $FG_ROOT/Scenery" << endl;
1047 cout << "\t--disable-game-mode: disable full-screen game mode" << endl;
1048 cout << "\t--enable-game-mode: enable full-screen game mode" << endl;
1049 cout << "\t--disable-splash-screen: disable splash screen" << endl;
1050 cout << "\t--enable-splash-screen: enable splash screen" << endl;
1051 cout << "\t--disable-intro-music: disable introduction music" << endl;
1052 cout << "\t--enable-intro-music: enable introduction music" << endl;
1053 cout << "\t--disable-mouse-pointer: disable extra mouse pointer" << endl;
1054 cout << "\t--enable-mouse-pointer: enable extra mouse pointer (i.e. for"
1056 cout << "\t\tfull screen voodoo/voodoo-II based cards.)" << endl;
1057 cout << "\t--disable-freeze: start out in an running state" << endl;
1058 cout << "\t--enable-freeze: start out in a frozen state" << endl;
1059 cout << "\t--control=mode: primary control mode "
1060 << "(joystick, keyboard, mouse)" << endl;
1061 cout << "\t--enable-auto-coordination: enable auto coordination" << endl;
1062 cout << "\t--disable-auto-coordination: disable auto coordination" << endl;
1063 cout << "\t--browser-app=/path/to/app: specify location of your web browser" << endl;
1064 cout << "\t--prop:name=value: set property <name> to <value>" << endl;
1065 cout << "\t--config=path: load additional properties from path" << endl;
1068 cout << "Features:" << endl;
1069 cout << "\t--disable-hud: disable heads up display" << endl;
1070 cout << "\t--enable-hud: enable heads up display" << endl;
1071 cout << "\t--disable-panel: disable instrument panel" << endl;
1072 cout << "\t--enable-panel: enable instrumetn panel" << endl;
1073 cout << "\t--disable-sound: disable sound effects" << endl;
1074 cout << "\t--enable-sound: enable sound effects" << endl;
1075 cout << "\t--disable-anti-alias-hud: disable anti aliased hud" << endl;
1076 cout << "\t--enable-anti-alias-hud: enable anti aliased hud" << endl;
1079 cout << "Flight Model:" << endl;
1080 cout << "\t--fdm=abcd: selects the core flight model code." << endl;
1081 cout << "\t\tcan be one of jsb, larcsim, magic, external, balloon, or ada"
1083 cout << "\t--aircraft=abcd: aircraft model to load" << endl;
1084 cout << "\t--model-hz=n: run the FDM this rate (iterations per second)"
1086 cout << "\t--speed=n: run the FDM this much faster than real time" << endl;
1087 cout << "\t--notrim: Do NOT attempt to trim the model when initializing JSBsim" << endl;
1088 cout << "\t--on-ground: Start up at ground level (default)" << endl;
1089 cout << "\t--in-air: Start up in air (implied by specifying an initial"
1090 << " altitude above ground level." << endl;
1091 cout << "\t--wind=DIR@SPEED: specify wind coming from DIR (degrees) at SPEED (knots)" << endl;
1095 cout <<"Aircraft model directory:" << endl;
1096 cout <<"\t--aircraft-dir=<path> path is relative to the path of the executable" << endl;
1099 cout << "Initial Position and Orientation:" << endl;
1100 cout << "\t--airport-id=ABCD: specify starting postion by airport id"
1102 cout << "\t--offset-distance: specify distance to threshhold"
1104 cout << "\t--offset-azimuth: specify heading to threshhold (deg) "
1106 cout << "\t--lon=degrees: starting longitude in degrees (west = -)"
1108 cout << "\t--lat=degrees: starting latitude in degrees (south = -)"
1110 cout << "\t--altitude=feet: starting altitude in feet" << endl;
1111 cout << "\t\t(unless --units-meters specified" << endl;
1112 cout << "\t--heading=degrees: heading (yaw) angle in degress (Psi)"
1114 cout << "\t--roll=degrees: roll angle in degrees (Phi)" << endl;
1115 cout << "\t--pitch=degrees: pitch angle in degrees (Theta)" << endl;
1116 cout << "\t--uBody=feet per second: velocity along the body X axis"
1118 cout << "\t--vBody=feet per second: velocity along the body Y axis"
1120 cout << "\t--wBody=feet per second: velocity along the body Z axis"
1122 cout << "\t\t(unless --units-meters specified" << endl;
1123 cout << "\t--vc= initial airspeed in knots (--fdm=jsb only)" << endl;
1124 cout << "\t--mach= initial mach number (--fdm=jsb only)" << endl;
1127 cout << "Rendering Options:" << endl;
1128 cout << "\t--fog-disable: disable fog/haze" << endl;
1129 cout << "\t--fog-fastest: enable fastest fog/haze" << endl;
1130 cout << "\t--fog-nicest: enable nicest fog/haze" << endl;
1131 cout << "\t--enable-clouds: enable demo cloud layer" << endl;
1132 cout << "\t--disable-clouds: disable demo cloud layer" << endl;
1133 cout << "\t--clouds-asl=xxx: specify altitude of cloud layer above sea level" << endl;
1134 cout << "\t--fov=xx.x: specify initial field of view angle in degrees"
1136 cout << "\t--disable-fullscreen: disable fullscreen mode" << endl;
1137 cout << "\t--enable-fullscreen: enable fullscreen mode" << endl;
1138 cout << "\t--shading-flat: enable flat shading" << endl;
1139 cout << "\t--shading-smooth: enable smooth shading" << endl;
1140 cout << "\t--disable-skyblend: disable sky blending" << endl;
1141 cout << "\t--enable-skyblend: enable sky blending" << endl;
1142 cout << "\t--disable-textures: disable textures" << endl;
1143 cout << "\t--enable-textures: enable textures" << endl;
1144 cout << "\t--disable-wireframe: disable wireframe drawing mode" << endl;
1145 cout << "\t--enable-wireframe: enable wireframe drawing mode" << endl;
1146 cout << "\t--geometry=WWWxHHH: window geometry: 640x480, 800x600, etc."
1148 cout << "\t--view-offset=xxx: set the default forward view direction"
1150 cout << "\t\tas an offset from straight ahead. Allowable values are"
1152 cout << "\t\tLEFT, RIGHT, CENTER, or a specific number of degrees" << endl;
1153 cout << "\t--visibility=xxx: specify initial visibility in meters" << endl;
1154 cout << "\t--visibility-miles=xxx: specify initial visibility in miles"
1158 cout << "Scenery Options:" << endl;
1159 cout << "\t--tile-radius=n: specify tile radius, must be 1 - 4" << endl;
1162 cout << "Hud Options:" << endl;
1163 cout << "\t--units-feet: Hud displays units in feet" << endl;
1164 cout << "\t--units-meters: Hud displays units in meters" << endl;
1165 cout << "\t--hud-tris: Hud displays number of triangles rendered" << endl;
1166 cout << "\t--hud-culled: Hud displays percentage of triangles culled"
1170 cout << "Time Options:" << endl;
1171 cout << "\t--time-offset=[+-]hh:mm:ss: add this time offset" << endl;
1172 cout << "\t--time-match-real: Synchronize real-world and FlightGear" << endl
1173 << "\t\ttime. Can be used in combination with --time-offset." << endl;
1174 cout << "\t--time-match-local:Synchronize local real-world and " << endl
1175 << "\t\tFlightGear time" << endl;
1176 cout << "\t--start-date-sys=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1177 << "\t\tdate/time. Uses your system time " << endl;
1178 cout << "\t--start-date-gmt=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1179 << "\t\tdate/time. Uses Greenwich Mean Time" << endl;
1180 cout << "\t--start-date-lat=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1181 << "\t\tdate/time. Uses Local Aircraft Time" << endl;
1182 #ifdef FG_NETWORK_OLK
1185 cout << "Network Options:" << endl;
1186 cout << "\t--enable-network-olk: enable Multipilot mode" << endl;
1187 cout << "\t--disable-network-olk: disable Multipilot mode (default)" << endl;
1188 cout << "\t--net-hud: Hud displays network info" << endl;
1189 cout << "\t--net-id=name: specify your own callsign" << endl;
1193 cout << "Route/Way Point Options:" << endl;
1194 cout << "\t--wp=ID[@alt]: specify a waypoint for the GC autopilot" << endl;
1195 cout << "\t\tYou can specify multiple waypoints (a route) with multiple"
1197 cout << "\t\tinstances of --wp=" << endl;
1198 cout << "\t--flight-plan=[file]: Read all waypoints from [file]" <<endl;