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>
31 #if defined(FX) && defined(XMESA)
32 bool global_fullscreen = true;
35 #include <math.h> // rint()
37 #include <stdlib.h> // atof(), atoi()
42 #include <simgear/misc/sgstream.hxx>
44 // #include <Include/general.hxx>
45 // #include <Airports/simple.hxx>
46 // #include <Cockpit/cockpit.hxx>
47 // #include <FDM/flight.hxx>
48 // #include <FDM/UIUCModel/uiuc_aircraftdir.h>
50 # include <NetworkOLK/network.h>
53 #include "globals.hxx"
54 #include "fg_init.hxx"
55 #include "fg_props.hxx"
56 #include "options.hxx"
59 SG_USING_NAMESPACE(std);
62 #define NEW_DEFAULT_MODEL_HZ 120
72 atof( const string& str )
76 // -dw- if ::atof is called, then we get an infinite loop
77 return std::atof( str.c_str() );
79 return ::atof( str.c_str() );
84 atoi( const string& str )
87 // -dw- if ::atoi is called, then we get an infinite loop
88 return std::atoi( str.c_str() );
90 return ::atoi( str.c_str() );
96 * Set a few fail-safe default property values.
98 * These should all be set in $FG_ROOT/preferences.xml, but just
99 * in case, we provide some initial sane values here. This method
100 * should be invoked *before* reading any init files.
105 // set a possibly independent location for scenery data
106 char *envp = ::getenv( "FG_SCENERY" );
108 if ( envp != NULL ) {
109 // fg_root could be anywhere, so default to environmental
110 // variable $FG_ROOT if it is set.
111 globals->set_fg_scenery(envp);
113 // Otherwise, default to Scenery being in $FG_ROOT/Scenery
114 globals->set_fg_scenery("");
116 // Position (Globe, AZ)
117 fgSetDouble("/position/longitude", -110.6642444);
118 fgSetDouble("/position/latitude", 33.3528917);
119 fgSetDouble("/position/altitude", -9999.0);
122 fgSetDouble("/orientation/heading", 270);
123 fgSetDouble("/orientation/roll", 0);
124 fgSetDouble("/orientation/pitch", 0.424);
127 fgSetString("/sim/startup/speed-set", "knots");
128 fgSetDouble("/velocities/uBody", 0.0);
129 fgSetDouble("/velocities/vBody", 0.0);
130 fgSetDouble("/velocities/wBody", 0.0);
131 fgSetDouble("/velocities/speed-north", 0.0);
132 fgSetDouble("/velocities/speed-east", 0.0);
133 fgSetDouble("/velocities/speed-down", 0.0);
134 fgSetDouble("/velocities/airspeed", 0.0);
135 fgSetDouble("/velocities/mach", 0.0);
138 fgSetBool("/sim/startup/game-mode", false);
139 fgSetBool("/sim/startup/splash-screen", true);
140 fgSetBool("/sim/startup/intro-music", true);
141 // we want mouse-pointer to have an undefined value if nothing is
142 // specified so we can do the right thing for voodoo-1/2 cards.
143 // fgSetString("/sim/startup/mouse-pointer", "disabled");
144 fgSetString("/sim/control-mode", "joystick");
145 fgSetBool("/sim/auto-coordination", false);
148 fgSetBool("/sim/hud/visibility", false);
149 fgSetBool("/sim/panel/visibility", true);
150 fgSetBool("/sim/sound", true);
151 fgSetBool("/sim/hud/antialiased", false);
153 // Flight Model options
154 fgSetString("/sim/flight-model", "larcsim");
155 fgSetString("/sim/aircraft", "c172");
156 fgSetInt("/sim/model-hz", NEW_DEFAULT_MODEL_HZ);
157 fgSetInt("/sim/speed-up", 1);
158 fgSetBool("/sim/startup/trim", false);
159 fgSetBool("/sim/startup/onground", true);
162 fgSetString("/sim/rendering/fog", "nicest");
163 fgSetBool("/environment/clouds/status", true);
164 fgSetDouble("/environment/clouds/altitude", 5000);
165 fgSetBool("/sim/startup/fullscreen", false);
166 fgSetBool("/sim/rendering/shading", true);
167 fgSetBool("/sim/rendering/skyblend", true);
168 fgSetBool("/sim/rendering/textures", true);
169 fgSetBool("/sim/rendering/wireframe", false);
170 fgSetInt("/sim/startup/xsize", 800);
171 fgSetInt("/sim/startup/ysize", 600);
172 fgSetInt("/sim/rendering/bits-per-pixel", 16);
173 fgSetString("/sim/view-mode", "pilot");
174 fgSetDouble("/sim/startup/view-offset", 0);
175 fgSetDouble("/environment/visibility", 20000);
178 fgSetString("/sim/startup/units", "feet");
179 fgSetString("/sim/hud/frame-stat-type", "tris");
182 fgSetInt("/sim/startup/time-offset", 0);
183 fgSetString("/sim/startup/time-offset-type", "system-offset");
185 fgSetBool("/sim/networking/network-olk", false);
186 fgSetString("/sim/networking/call-sign", "Johnny");
190 // parse a time string ([+/-]%f[:%f[:%f]]) into hours
192 parse_time(const string& time_in) {
193 char *time_str, num[256];
194 double hours, minutes, seconds;
199 time_str = (char *)time_in.c_str();
201 // printf("parse_time(): %s\n", time_str);
204 if ( strlen(time_str) ) {
205 if ( time_str[0] == '+' ) {
208 } else if ( time_str[0] == '-' ) {
213 // printf("sign = %d\n", sign);
216 if ( strlen(time_str) ) {
218 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
219 num[i] = time_str[0];
223 if ( time_str[0] == ':' ) {
228 // printf("hours = %.2lf\n", hours);
234 if ( strlen(time_str) ) {
236 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
237 num[i] = time_str[0];
241 if ( time_str[0] == ':' ) {
246 // printf("minutes = %.2lf\n", minutes);
248 result += minutes / 60.0;
252 if ( strlen(time_str) ) {
254 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
255 num[i] = time_str[0];
261 // printf("seconds = %.2lf\n", seconds);
263 result += seconds / 3600.0;
266 return(sign * result);
270 // parse a date string (yyyy:mm:dd:hh:mm:ss) into a time_t (seconds)
272 parse_date( const string& date)
275 char * date_str, num[256];
277 // initialize to zero
284 gmt.tm_isdst = 0; // ignore daylight savings time for the moment
285 date_str = (char *)date.c_str();
287 if ( strlen(date_str) ) {
289 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
290 num[i] = date_str[0];
294 if ( date_str[0] == ':' ) {
298 gmt.tm_year = atoi(num) - 1900;
301 if ( strlen(date_str) ) {
303 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
304 num[i] = date_str[0];
308 if ( date_str[0] == ':' ) {
312 gmt.tm_mon = atoi(num) -1;
315 if ( strlen(date_str) ) {
317 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
318 num[i] = date_str[0];
322 if ( date_str[0] == ':' ) {
326 gmt.tm_mday = atoi(num);
329 if ( strlen(date_str) ) {
331 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
332 num[i] = date_str[0];
336 if ( date_str[0] == ':' ) {
340 gmt.tm_hour = atoi(num);
343 if ( strlen(date_str) ) {
345 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
346 num[i] = date_str[0];
350 if ( date_str[0] == ':' ) {
354 gmt.tm_min = atoi(num);
357 if ( strlen(date_str) ) {
359 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
360 num[i] = date_str[0];
364 if ( date_str[0] == ':' ) {
368 gmt.tm_sec = atoi(num);
370 time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
371 gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
372 //printf ("Date is %s\n", ctime(&theTime));
373 //printf ("in seconds that is %d\n", theTime);
379 // parse angle in the form of [+/-]ddd:mm:ss into degrees
381 parse_degree( const string& degree_str) {
382 double result = parse_time( degree_str );
384 // printf("Degree = %.4f\n", result);
390 // parse time offset string into seconds
392 parse_time_offset( const string& time_str) {
395 // printf("time offset = %s\n", time_str);
398 result = (int)rint(parse_time(time_str) * 3600.0);
400 result = (int)(parse_time(time_str) * 3600.0);
403 // printf("parse_time_offset(): %d\n", result);
409 // Parse --fov=x.xx type option
411 parse_fov( const string& arg ) {
412 double fov = atof(arg);
414 if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
415 if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
417 fgSetDouble("/sim/field-of-view", fov);
419 // printf("parse_fov(): result = %.4f\n", fov);
425 // Parse I/O channel option
427 // Format is "--protocol=medium,direction,hz,medium_options,..."
429 // protocol = { native, nmea, garmin, fgfs, rul, pve, etc. }
430 // medium = { serial, socket, file, etc. }
431 // direction = { in, out, bi }
432 // hz = number of times to process channel per second (floating
433 // point values are ok.
435 // Serial example "--nmea=serial,dir,hz,device,baud" where
437 // device = OS device name of serial line to be open()'ed
438 // baud = {300, 1200, 2400, ..., 230400}
440 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
442 // machine = machine name or ip address if client (leave empty if server)
443 // port = port, leave empty to let system choose
444 // style = tcp or udp
446 // File example "--garmin=file,dir,hz,filename" where
448 // filename = file system file name
451 parse_channel( const string& type, const string& channel_str ) {
452 // cout << "Channel string = " << channel_str << endl;
454 globals->get_channel_options_list()->push_back( type + "," + channel_str );
460 // Parse --wp=ID[@alt]
462 parse_wp( const string& arg ) {
466 int pos = arg.find( "@" );
467 if ( pos != string::npos ) {
468 id = arg.substr( 0, pos );
469 alt_str = arg.substr( pos + 1 );
470 // cout << "id str = " << id << " alt str = " << alt_str << endl;
471 alt = atof( alt_str.c_str() );
472 if ( fgGetString("/sim/startup/units") == "feet" ) {
473 alt *= SG_FEET_TO_METER;
480 if ( fgFindAirportID( id, &a ) ) {
481 SGWayPoint wp( a.longitude, a.latitude, alt, SGWayPoint::WGS84, id );
482 globals->get_route()->add_waypoint( wp );
491 // Parse --flight-plan=[file]
493 parse_flightplan(const string& arg)
495 sg_gzifstream infile(arg.c_str());
496 if ( !infile.is_open() ) {
501 #ifdef GETLINE_NEEDS_TERMINATOR
502 getline( infile, line, '\n' );
503 #elif defined( macintosh )
504 getline( infile, line, '\r' );
506 getline( infile, line );
508 if ( infile.eof() ) {
518 // Parse a single option
520 parse_option (const string& arg)
523 if ( (arg == "--help") || (arg == "-h") ) {
524 // help/usage request
525 return(FG_OPTIONS_HELP);
526 } else if ( arg == "--disable-game-mode") {
527 fgSetBool("/sim/startup/game-mode", false);
528 } else if ( arg == "--enable-game-mode" ) {
529 fgSetBool("/sim/startup/game-mode", true);
530 } else if ( arg == "--disable-splash-screen" ) {
531 fgSetBool("/sim/startup/splash-screen", false);
532 } else if ( arg == "--enable-splash-screen" ) {
533 fgSetBool("/sim/startup/splash-screen", true);
534 } else if ( arg == "--disable-intro-music" ) {
535 fgSetBool("/sim/startup/intro-music", false);
536 } else if ( arg == "--enable-intro-music" ) {
537 fgSetBool("/sim/startup/intro-music", true);
538 } else if ( arg == "--disable-mouse-pointer" ) {
539 fgSetString("/sim/startup/mouse-pointer", "disabled");
540 } else if ( arg == "--enable-mouse-pointer" ) {
541 fgSetString("/sim/startup/mouse-pointer", "enabled");
542 } else if ( arg == "--disable-freeze" ) {
543 globals->set_freeze(false);
544 } else if ( arg == "--enable-freeze" ) {
545 globals->set_freeze(true);
546 } else if ( arg == "--disable-anti-alias-hud" ) {
547 fgSetBool("/sim/hud/antialiased", false);
548 } else if ( arg == "--enable-anti-alias-hud" ) {
549 fgSetBool("/sim/hud/antialiased", true);
550 } else if ( arg.find( "--control=") == 0 ) {
551 fgSetString("/sim/control-mode", arg.substr(10));
552 } else if ( arg == "--disable-auto-coordination" ) {
553 fgSetBool("/sim/auto-coordination", false);
554 } else if ( arg == "--enable-auto-coordination" ) {
555 fgSetBool("/sim/auto-coordination", true);
556 } else if ( arg == "--disable-hud" ) {
557 fgSetBool("/sim/hud/visibility", false);
558 } else if ( arg == "--enable-hud" ) {
559 fgSetBool("/sim/hud/visibility", true);
560 } else if ( arg == "--disable-panel" ) {
561 fgSetBool("/sim/panel/visibility", false);
562 } else if ( arg == "--enable-panel" ) {
563 fgSetBool("/sim/panel/visibility", true);
564 } else if ( arg == "--disable-sound" ) {
565 fgSetBool("/sim/sound", false);
566 } else if ( arg == "--enable-sound" ) {
567 fgSetBool("/sim/sound", true);
568 } else if ( arg.find( "--airport-id=") == 0 ) {
569 // NB: changed property name!!!
570 fgSetString("/sim/startup/airport-id", arg.substr(13));
571 } else if ( arg.find( "--offset-distance=") == 0 ) {
572 fgSetDouble("/sim/startup/offset-distance", atof(arg.substr(18)));
573 } else if ( arg.find( "--offset-azimuth=") == 0 ) {
574 fgSetDouble("/sim/startup/offset-azimuth", atof(arg.substr(17)));
575 } else if ( arg.find( "--lon=" ) == 0 ) {
576 fgSetDouble("/position/longitude",
577 parse_degree(arg.substr(6)));
578 fgSetString("/sim/startup/airport-id", "");
579 } else if ( arg.find( "--lat=" ) == 0 ) {
580 fgSetDouble("/position/latitude",
581 parse_degree(arg.substr(6)));
582 fgSetString("/sim/startup/airport-id", "");
583 } else if ( arg.find( "--altitude=" ) == 0 ) {
584 fgSetBool("/sim/startup/onground", false);
585 if ( fgGetString("/sim/startup/units") == "feet" )
586 fgSetDouble("/position/altitude", atof(arg.substr(11)));
588 fgSetDouble("/position/altitude",
589 atof(arg.substr(11)) * SG_METER_TO_FEET);
590 } else if ( arg.find( "--uBody=" ) == 0 ) {
591 fgSetString("/sim/startup/speed-set", "UVW");
592 if ( fgGetString("/sim/startup/units") == "feet" )
593 fgSetDouble("/velocities/uBody", atof(arg.substr(8)));
595 fgSetDouble("/velocities/uBody",
596 atof(arg.substr(8)) * SG_METER_TO_FEET);
597 } else if ( arg.find( "--vBody=" ) == 0 ) {
598 fgSetString("/sim/startup/speed-set", "UVW");
599 if ( fgGetString("/sim/startup/units") == "feet" )
600 fgSetDouble("/velocities/vBody", atof(arg.substr(8)));
602 fgSetDouble("/velocities/vBody",
603 atof(arg.substr(8)) * SG_METER_TO_FEET);
604 } else if ( arg.find( "--wBody=" ) == 0 ) {
605 fgSetString("/sim/startup/speed-set", "UVW");
606 if ( fgGetString("/sim/startup/units") == "feet" )
607 fgSetDouble("/velocities/wBody", atof(arg.substr(8)));
609 fgSetDouble("/velocities/wBody",
610 atof(arg.substr(8)) * SG_METER_TO_FEET);
611 } else if ( arg.find( "--vNorth=" ) == 0 ) {
612 fgSetString("/sim/startup/speed-set", "NED");
613 if ( fgGetString("/sim/startup/units") == "feet" )
614 fgSetDouble("/velocities/speed-north", atof(arg.substr(9)));
616 fgSetDouble("/velocities/speed-north",
617 atof(arg.substr(9)) * SG_METER_TO_FEET);
618 } else if ( arg.find( "--vEast=" ) == 0 ) {
619 fgSetString("/sim/startup/speed-set", "NED");
620 if ( fgGetString("/sim/startup/units") == "feet" )
621 fgSetDouble("/velocities/speed-east", atof(arg.substr(8)));
623 fgSetDouble("/velocities/speed-east",
624 atof(arg.substr(8)) * SG_METER_TO_FEET);
625 } else if ( arg.find( "--vDown=" ) == 0 ) {
626 fgSetString("/sim/startup/speed-set", "NED");
627 if ( fgGetString("/sim/startup/units") == "feet" )
628 fgSetDouble("/velocities/speed-down", atof(arg.substr(8)));
630 fgSetDouble("/velocities/speed-down",
631 atof(arg.substr(8)) * SG_METER_TO_FEET);
632 } else if ( arg.find( "--vc=" ) == 0) {
633 fgSetString("/sim/startup/speed-set", "knots");
634 fgSetDouble("/velocities/airspeed", atof(arg.substr(5)));
635 } else if ( arg.find( "--mach=" ) == 0) {
636 fgSetString("/sim/startup/speed-set", "mach");
637 fgSetDouble("/velocities/mach", atof(arg.substr(7)));
638 } else if ( arg.find( "--heading=" ) == 0 ) {
639 fgSetDouble("/orientation/heading", atof(arg.substr(10)));
640 } else if ( arg.find( "--roll=" ) == 0 ) {
641 fgSetDouble("/orientation/roll", atof(arg.substr(7)));
642 } else if ( arg.find( "--pitch=" ) == 0 ) {
643 fgSetDouble("/orientation/pitch", atof(arg.substr(8)));
644 } else if ( arg.find( "--fg-root=" ) == 0 ) {
645 globals->set_fg_root(arg.substr( 10 ));
646 } else if ( arg.find( "--fg-scenery=" ) == 0 ) {
647 globals->set_fg_scenery(arg.substr( 13 ));
648 } else if ( arg.find( "--fdm=" ) == 0 ) {
649 fgSetString("/sim/flight-model", arg.substr(6));
650 } else if ( arg.find( "--aircraft=" ) == 0 ) {
651 fgSetString("/sim/aircraft", arg.substr(11));
652 } else if ( arg.find( "--aircraft-dir=" ) == 0 ) {
653 fgSetString("/sim/aircraft-dir", arg.substr(15));
654 } else if ( arg.find( "--model-hz=" ) == 0 ) {
655 fgSetInt("/sim/model-hz", atoi(arg.substr(11)));
656 } else if ( arg.find( "--speed=" ) == 0 ) {
657 fgSetInt("/sim/speed-up", atoi(arg.substr(8)));
658 } else if ( arg.find( "--trim") == 0) {
659 fgSetBool("/sim/startup/trim", true);
660 } else if ( arg.find( "--notrim") == 0) {
661 fgSetBool("/sim/startup/trim", false);
662 } else if ( arg.find( "--on-ground") == 0) {
663 fgSetBool("/sim/startup/onground", true);
664 } else if ( arg.find( "--in-air") == 0) {
665 fgSetBool("/sim/startup/onground", false);
666 } else if ( arg == "--fog-disable" ) {
667 fgSetString("/sim/rendering/fog", "disabled");
668 } else if ( arg == "--fog-fastest" ) {
669 fgSetString("/sim/rendering/fog", "fastest");
670 } else if ( arg == "--fog-nicest" ) {
671 fgSetString("/sim/fog", "nicest");
672 } else if ( arg == "--disable-clouds" ) {
673 fgSetBool("/environment/clouds/status", false);
674 } else if ( arg == "--enable-clouds" ) {
675 fgSetBool("/environment/clouds/status", true);
676 } else if ( arg.find( "--clouds-asl=" ) == 0 ) {
677 // FIXME: check units
678 if ( fgGetString("/sim/startup/units") == "feet" )
679 fgSetDouble("/environment/clouds/altitude",
680 atof(arg.substr(13)) * SG_FEET_TO_METER);
682 fgSetDouble("/environment/clouds/altitude",
683 atof(arg.substr(13)));
684 } else if ( arg.find( "--fov=" ) == 0 ) {
685 parse_fov( arg.substr(6) );
686 } else if ( arg == "--disable-fullscreen" ) {
687 fgSetBool("/sim/startup/fullscreen", false);
688 } else if ( arg== "--enable-fullscreen") {
689 fgSetBool("/sim/startup/fullscreen", true);
690 } else if ( arg == "--shading-flat") {
691 fgSetBool("/sim/rendering/shading", false);
692 } else if ( arg == "--shading-smooth") {
693 fgSetBool("/sim/rendering/shading", true);
694 } else if ( arg == "--disable-skyblend") {
695 fgSetBool("/sim/rendering/skyblend", false);
696 } else if ( arg== "--enable-skyblend" ) {
697 fgSetBool("/sim/rendering/skyblend", true);
698 } else if ( arg == "--disable-textures" ) {
699 fgSetBool("/sim/rendering/textures", false);
700 } else if ( arg == "--enable-textures" ) {
701 fgSetBool("/sim/rendering/textures", true);
702 } else if ( arg == "--disable-wireframe" ) {
703 fgSetBool("/sim/rendering/wireframe", false);
704 } else if ( arg == "--enable-wireframe" ) {
705 fgSetBool("/sim/rendering/wireframe", true);
706 } else if ( arg.find( "--geometry=" ) == 0 ) {
707 bool geometry_ok = true;
708 int xsize = 0, ysize = 0;
709 string geometry = arg.substr( 11 );
710 string::size_type i = geometry.find('x');
712 if (i != string::npos) {
713 xsize = atoi(geometry.substr(0, i));
714 ysize = atoi(geometry.substr(i+1));
719 if ( xsize <= 0 || ysize <= 0 ) {
725 if ( !geometry_ok ) {
726 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown geometry: " << geometry );
727 SG_LOG( SG_GENERAL, SG_ALERT,
728 "Setting geometry to " << xsize << 'x' << ysize << '\n');
730 SG_LOG( SG_GENERAL, SG_INFO,
731 "Setting geometry to " << xsize << 'x' << ysize << '\n');
732 fgSetInt("/sim/startup/xsize", xsize);
733 fgSetInt("/sim/startup/ysize", ysize);
735 } else if ( arg.find( "--bpp=" ) == 0 ) {
736 string bits_per_pix = arg.substr( 6 );
737 if ( bits_per_pix == "16" ) {
738 fgSetInt("/sim/rendering/bits-per-pixel", 16);
739 } else if ( bits_per_pix == "24" ) {
740 fgSetInt("/sim/rendering/bits-per-pixel", 24);
741 } else if ( bits_per_pix == "32" ) {
742 fgSetInt("/sim/rendering/bits-per-pixel", 32);
744 SG_LOG(SG_GENERAL, SG_ALERT, "Unsupported bpp " << bits_per_pix);
746 } else if ( arg == "--units-feet" ) {
747 fgSetString("/sim/startup/units", "feet");
748 } else if ( arg == "--units-meters" ) {
749 fgSetString("/sim/startup/units", "meters");
750 } else if ( arg.find( "--time-offset" ) == 0 ) {
751 fgSetInt("/sim/startup/time-offset",
752 parse_time_offset( (arg.substr(14)) ));
753 } else if ( arg.find( "--time-match-real") == 0 ) {
754 fgSetString("/sim/startup/time-offset-type",
756 } else if ( arg.find( "--time-match-local") == 0 ) {
757 fgSetString("/sim/startup/time-offset-type",
759 } else if ( arg.find( "--start-date-sys=") == 0 ) {
760 fgSetInt("/sim/startup/time-offset",
761 parse_date((arg.substr(17))));
762 fgSetString("/sim/startup/time-offset-type", "system");
763 } else if ( arg.find( "--start-date-lat=") == 0 ) {
764 fgSetInt("/sim/startup/time-offset",
765 parse_date((arg.substr(17))));
766 fgSetString("/sim/startup/time-offset-type",
768 } else if ( arg.find( "--start-date-gmt=") == 0 ) {
769 fgSetInt("/sim/startup/time-offset",
770 parse_date((arg.substr(17))));
771 fgSetString("/sim/startup/time-offset-type", "gmt");
772 } else if ( arg == "--hud-tris" ) {
773 fgSetString("/sim/hud/frame-stat-type", "tris");
774 } else if ( arg == "--hud-culled" ) {
775 fgSetString("/sim/hud/frame-stat-type", "culled");
776 } else if ( arg.find( "--atlas=" ) == 0 ) {
777 parse_channel( "atlas", arg.substr(8) );
778 } else if ( arg.find( "--native=" ) == 0 ) {
779 parse_channel( "native", arg.substr(9) );
780 } else if ( arg.find( "--garmin=" ) == 0 ) {
781 parse_channel( "garmin", arg.substr(9) );
782 } else if ( arg.find( "--nmea=" ) == 0 ) {
783 parse_channel( "nmea", arg.substr(7) );
784 } else if ( arg.find( "--props=" ) == 0 ) {
785 parse_channel( "props", arg.substr(8) );
786 } else if ( arg.find( "--pve=" ) == 0 ) {
787 parse_channel( "pve", arg.substr(6) );
788 } else if ( arg.find( "--ray=" ) == 0 ) {
789 parse_channel( "ray", arg.substr(6) );
790 } else if ( arg.find( "--rul=" ) == 0 ) {
791 parse_channel( "rul", arg.substr(6) );
792 } else if ( arg.find( "--joyclient=" ) == 0 ) {
793 parse_channel( "joyclient", arg.substr(12) );
794 #ifdef FG_NETWORK_OLK
795 } else if ( arg == "--disable-network-olk" ) {
796 fgSetBool("/sim/networking/olk", false);
797 } else if ( arg== "--enable-network-olk") {
798 fgSetBool("/sim/networking/olk", true);
799 } else if ( arg == "--net-hud" ) {
800 fgSetBool("/sim/hud/net-display", true);
801 net_hud_display = 1; // FIXME
802 } else if ( arg.find( "--net-id=") == 0 ) {
803 fgSetString("sim/networking/call-sign", arg.substr(9));
805 } else if ( arg.find( "--prop:" ) == 0 ) {
806 string assign = arg.substr(7);
807 int pos = assign.find('=');
808 if (pos == arg.npos || pos == 0) {
809 SG_LOG(SG_GENERAL, SG_ALERT, "Bad property assignment: " << arg);
810 return FG_OPTIONS_ERROR;
812 string name = assign.substr(0, pos);
813 string value = assign.substr(pos + 1);
814 fgSetString(name.c_str(), value);
815 // SG_LOG(SG_GENERAL, SG_INFO, "Setting default value of property "
816 // << name << " to \"" << value << '"');
817 // $$$ begin - added VS Renganathan, 14 Oct 2K
818 // for multi-window outside window imagery
819 } else if ( arg.find( "--view-offset=" ) == 0 ) {
820 string woffset = arg.substr( 14 );
821 double default_view_offset = 0.0;
822 if ( woffset == "LEFT" ) {
823 default_view_offset = SGD_PI * 0.25;
824 } else if ( woffset == "RIGHT" ) {
825 default_view_offset = SGD_PI * 1.75;
826 } else if ( woffset == "CENTER" ) {
827 default_view_offset = 0.00;
829 default_view_offset = atof( woffset.c_str() ) * SGD_DEGREES_TO_RADIANS;
831 FGViewerRPH *pilot_view =
832 (FGViewerRPH *)globals->get_viewmgr()->get_view( 0 );
833 pilot_view->set_view_offset( default_view_offset );
834 pilot_view->set_goal_view_offset( default_view_offset );
835 fgSetDouble("/sim/startup/view-offset", default_view_offset);
836 // $$$ end - added VS Renganathan, 14 Oct 2K
837 } else if ( arg.find( "--visibility=" ) == 0 ) {
838 fgSetDouble("/environment/visibility", atof(arg.substr(13)));
839 } else if ( arg.find( "--visibility-miles=" ) == 0 ) {
840 double visibility = atof(arg.substr(19)) * 5280.0 * SG_FEET_TO_METER;
841 fgSetDouble("/environment/visibility", visibility);
842 } else if ( arg.find( "--wind=" ) == 0 ) {
843 string val = arg.substr(7);
844 int pos = val.find('@');
845 if (pos == string::npos) {
846 SG_LOG(SG_GENERAL, SG_ALERT, "bad wind value " << val);
847 return FG_OPTIONS_ERROR;
849 double dir = atof(val.substr(0,pos).c_str());
850 double speed = atof(val.substr(pos+1).c_str());
851 SG_LOG(SG_GENERAL, SG_INFO, "WIND: " << dir << '@' <<
852 speed << " knots" << endl);
854 speed *= SG_NM_TO_METER * SG_METER_TO_FEET * (1.0/3600);
858 dir *= SGD_DEGREES_TO_RADIANS;
859 fgSetDouble("/environment/wind-north",
861 fgSetDouble("/environment/wind-east",
863 } else if ( arg.find( "--wp=" ) == 0 ) {
864 parse_wp( arg.substr( 5 ) );
865 } else if ( arg.find( "--flight-plan=") == 0) {
866 parse_flightplan ( arg.substr (14) );
867 } else if ( arg.find( "--config=" ) == 0 ) {
868 string file = arg.substr(9);
869 if (!readProperties(file, globals->get_props())) {
870 SG_LOG(SG_IO, SG_ALERT,
871 "--config: failed to read properties from " << file);
872 return FG_OPTIONS_ERROR;
875 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
876 return FG_OPTIONS_ERROR;
879 return FG_OPTIONS_OK;
883 // Scan the command line options for an fg_root definition and set
886 fgScanForRoot (int argc, char **argv)
890 SG_LOG(SG_GENERAL, SG_INFO, "Scanning for root: command line");
893 SG_LOG( SG_GENERAL, SG_DEBUG, "argv[" << i << "] = " << argv[i] );
895 string arg = argv[i];
896 if ( arg.find( "--fg-root=" ) == 0 ) {
897 return arg.substr( 10 );
907 // Scan the config file for an fg_root definition and set just that.
909 fgScanForRoot (const string& path)
911 sg_gzifstream in( path );
915 SG_LOG( SG_GENERAL, SG_INFO, "Scanning for root: " << path );
919 while ( ! in.eof() ) {
922 while ( in.get(c) && c != '\0' ) {
927 #ifdef GETLINE_NEEDS_TERMINATOR
928 getline( in, line, '\n' );
929 #elif defined( macintosh )
930 getline( in, line, '\r' );
935 if ( line.find( "--fg-root=" ) == 0 ) {
936 return line.substr( 10 );
946 // Parse the command line options
948 fgParseOptions (int argc, char **argv) {
952 SG_LOG(SG_GENERAL, SG_INFO, "Processing command line arguments");
955 SG_LOG( SG_GENERAL, SG_DEBUG, "argv[" << i << "] = " << argv[i] );
957 result = parse_option(argv[i]);
958 if ( (result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR) ) {
968 // Parse config file options
970 fgParseOptions (const string& path) {
971 sg_gzifstream in( path );
975 SG_LOG( SG_GENERAL, SG_INFO, "Processing config file: " << path );
979 while ( ! in.eof() ) {
982 while ( in.get(c) && c != '\0' ) {
987 #ifdef GETLINE_NEEDS_TERMINATOR
988 getline( in, line, '\n' );
989 #elif defined( macintosh )
990 getline( in, line, '\r' );
995 if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
996 SG_LOG( SG_GENERAL, SG_ALERT,
997 "Config file parse error: " << path << " '"
1007 // Print usage message
1011 cout << "Usage: fgfs [ options ... ]" << endl;
1014 cout << "General Options:" << endl;
1015 cout << "\t--help -h: print usage" << endl;
1016 cout << "\t--fg-root=path: specify the root path for all the data files"
1018 cout << "\t--fg-scenery=path: specify the base path for all the scenery"
1020 << "\t\tdefaults to $FG_ROOT/Scenery" << endl;
1021 cout << "\t--disable-game-mode: disable full-screen game mode" << endl;
1022 cout << "\t--enable-game-mode: enable full-screen game mode" << endl;
1023 cout << "\t--disable-splash-screen: disable splash screen" << endl;
1024 cout << "\t--enable-splash-screen: enable splash screen" << endl;
1025 cout << "\t--disable-intro-music: disable introduction music" << endl;
1026 cout << "\t--enable-intro-music: enable introduction music" << endl;
1027 cout << "\t--disable-mouse-pointer: disable extra mouse pointer" << endl;
1028 cout << "\t--enable-mouse-pointer: enable extra mouse pointer (i.e. for"
1030 cout << "\t\tfull screen voodoo/voodoo-II based cards.)" << endl;
1031 cout << "\t--disable-freeze: start out in an running state" << endl;
1032 cout << "\t--enable-freeze: start out in a frozen state" << endl;
1033 cout << "\t--control=mode: primary control mode "
1034 << "(joystick, keyboard, mouse)" << endl;
1035 cout << "\t--prop:name=value: set property <name> to <value>" << endl;
1036 cout << "\t--file=path: load additional properties from path" << endl;
1039 cout << "Features:" << endl;
1040 cout << "\t--disable-hud: disable heads up display" << endl;
1041 cout << "\t--enable-hud: enable heads up display" << endl;
1042 cout << "\t--disable-panel: disable instrument panel" << endl;
1043 cout << "\t--enable-panel: enable instrumetn panel" << endl;
1044 cout << "\t--disable-sound: disable sound effects" << endl;
1045 cout << "\t--enable-sound: enable sound effects" << endl;
1046 cout << "\t--disable-anti-alias-hud: disable anti aliased hud" << endl;
1047 cout << "\t--enable-anti-alias-hud: enable anti aliased hud" << endl;
1050 cout << "Flight Model:" << endl;
1051 cout << "\t--fdm=abcd: selects the core flight model code." << endl;
1052 cout << "\t\tcan be one of jsb, larcsim, magic, external, balloon, or ada"
1054 cout << "\t--aircraft=abcd: aircraft model to load" << endl;
1055 cout << "\t--model-hz=n: run the FDM this rate (iterations per second)"
1057 cout << "\t--speed=n: run the FDM this much faster than real time" << endl;
1058 cout << "\t--notrim: Do NOT attempt to trim the model when initializing JSBsim" << endl;
1059 cout << "\t--on-ground: Start up at ground level (default)" << endl;
1060 cout << "\t--in-air: Start up in air (implied by specifying an initial"
1061 << " altitude above ground level." << endl;
1062 cout << "\t--wind=DIR@SPEED: specify wind coming from DIR (degrees) at SPEED (knots)" << endl;
1066 cout <<"Aircraft model directory:" << endl;
1067 cout <<"\t--aircraft-dir=<path> path is relative to the path of the executable" << endl;
1070 cout << "Initial Position and Orientation:" << endl;
1071 cout << "\t--airport-id=ABCD: specify starting postion by airport id"
1073 cout << "\t--offset-distance: specify distance to threshhold"
1075 cout << "\t--offset-azimuth: specify heading to threshhold (deg) "
1077 cout << "\t--lon=degrees: starting longitude in degrees (west = -)"
1079 cout << "\t--lat=degrees: starting latitude in degrees (south = -)"
1081 cout << "\t--altitude=feet: starting altitude in feet" << endl;
1082 cout << "\t\t(unless --units-meters specified" << endl;
1083 cout << "\t--heading=degrees: heading (yaw) angle in degress (Psi)"
1085 cout << "\t--roll=degrees: roll angle in degrees (Phi)" << endl;
1086 cout << "\t--pitch=degrees: pitch angle in degrees (Theta)" << endl;
1087 cout << "\t--uBody=feet per second: velocity along the body X axis"
1089 cout << "\t--vBody=feet per second: velocity along the body Y axis"
1091 cout << "\t--wBody=feet per second: velocity along the body Z axis"
1093 cout << "\t\t(unless --units-meters specified" << endl;
1094 cout << "\t--vc= initial airspeed in knots (--fdm=jsb only)" << endl;
1095 cout << "\t--mach= initial mach number (--fdm=jsb only)" << endl;
1098 cout << "Rendering Options:" << endl;
1099 cout << "\t--fog-disable: disable fog/haze" << endl;
1100 cout << "\t--fog-fastest: enable fastest fog/haze" << endl;
1101 cout << "\t--fog-nicest: enable nicest fog/haze" << endl;
1102 cout << "\t--enable-clouds: enable demo cloud layer" << endl;
1103 cout << "\t--disable-clouds: disable demo cloud layer" << endl;
1104 cout << "\t--clouds-asl=xxx: specify altitude of cloud layer above sea level" << endl;
1105 cout << "\t--fov=xx.x: specify initial field of view angle in degrees"
1107 cout << "\t--disable-fullscreen: disable fullscreen mode" << endl;
1108 cout << "\t--enable-fullscreen: enable fullscreen mode" << endl;
1109 cout << "\t--shading-flat: enable flat shading" << endl;
1110 cout << "\t--shading-smooth: enable smooth shading" << endl;
1111 cout << "\t--disable-skyblend: disable sky blending" << endl;
1112 cout << "\t--enable-skyblend: enable sky blending" << endl;
1113 cout << "\t--disable-textures: disable textures" << endl;
1114 cout << "\t--enable-textures: enable textures" << endl;
1115 cout << "\t--disable-wireframe: disable wireframe drawing mode" << endl;
1116 cout << "\t--enable-wireframe: enable wireframe drawing mode" << endl;
1117 cout << "\t--geometry=WWWxHHH: window geometry: 640x480, 800x600, etc."
1119 cout << "\t--view-offset=xxx: set the default forward view direction"
1121 cout << "\t\tas an offset from straight ahead. Allowable values are"
1123 cout << "\t\tLEFT, RIGHT, CENTER, or a specific number of degrees" << endl;
1124 cout << "\t--visibility=xxx: specify initial visibility in meters" << endl;
1125 cout << "\t--visibility-miles=xxx: specify initial visibility in miles"
1129 cout << "Scenery Options:" << endl;
1130 cout << "\t--tile-radius=n: specify tile radius, must be 1 - 4" << endl;
1133 cout << "Hud Options:" << endl;
1134 cout << "\t--units-feet: Hud displays units in feet" << endl;
1135 cout << "\t--units-meters: Hud displays units in meters" << endl;
1136 cout << "\t--hud-tris: Hud displays number of triangles rendered" << endl;
1137 cout << "\t--hud-culled: Hud displays percentage of triangles culled"
1141 cout << "Time Options:" << endl;
1142 cout << "\t--time-offset=[+-]hh:mm:ss: add this time offset" << endl;
1143 cout << "\t--time-match-real: Synchronize real-world and FlightGear" << endl
1144 << "\t\ttime. Can be used in combination with --time-offset." << endl;
1145 cout << "\t--time-match-local:Synchronize local real-world and " << endl
1146 << "\t\tFlightGear time" << endl;
1147 cout << "\t--start-date-sys=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1148 << "\t\tdate/time. Uses your system time " << endl;
1149 cout << "\t--start-date-gmt=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1150 << "\t\tdate/time. Uses Greenwich Mean Time" << endl;
1151 cout << "\t--start-date-lat=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1152 << "\t\tdate/time. Uses Local Aircraft Time" << endl;
1153 #ifdef FG_NETWORK_OLK
1156 cout << "Network Options:" << endl;
1157 cout << "\t--enable-network-olk: enable Multipilot mode" << endl;
1158 cout << "\t--disable-network-olk: disable Multipilot mode (default)" << endl;
1159 cout << "\t--net-hud: Hud displays network info" << endl;
1160 cout << "\t--net-id=name: specify your own callsign" << endl;
1164 cout << "Route/Way Point Options:" << endl;
1165 cout << "\t--wp=ID[@alt]: specify a waypoint for the GC autopilot" << endl;
1166 cout << "\t\tYou can specify multiple waypoints (a route) with multiple"
1168 cout << "\t\tinstances of --wp=" << endl;
1169 cout << "\t--flight-plan=[file]: Read all waypoints from [file]" <<endl;