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-deg", -110.6642444);
118 fgSetDouble("/position/latitude-deg", 33.3528917);
119 fgSetDouble("/position/altitude-ft", -9999.0);
122 fgSetDouble("/orientation/heading-deg", 270);
123 fgSetDouble("/orientation/roll-deg", 0);
124 fgSetDouble("/orientation/pitch-deg", 0.424);
127 fgSetString("/sim/startup/speed-set", "knots");
128 fgSetDouble("/velocities/uBody-fps", 0.0);
129 fgSetDouble("/velocities/vBody-fps", 0.0);
130 fgSetDouble("/velocities/wBody-fps", 0.0);
131 fgSetDouble("/velocities/speed-north-fps", 0.0);
132 fgSetDouble("/velocities/speed-east-fps", 0.0);
133 fgSetDouble("/velocities/speed-down-fps", 0.0);
134 fgSetDouble("/velocities/airspeed-kt", 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);
147 fgSetString("/sim/startup/browser-app", "netscape");
149 fgSetString("/sim/startup/browser-app", "webrun.bat");
152 fgSetBool("/sim/hud/visibility", false);
153 fgSetBool("/sim/panel/visibility", true);
154 fgSetBool("/sim/sound", true);
155 fgSetBool("/sim/hud/antialiased", false);
157 // Flight Model options
158 fgSetString("/sim/flight-model", "larcsim");
159 fgSetString("/sim/aircraft", "c172");
160 fgSetInt("/sim/model-hz", NEW_DEFAULT_MODEL_HZ);
161 fgSetInt("/sim/speed-up", 1);
162 fgSetBool("/sim/startup/trim", false);
163 fgSetBool("/sim/startup/onground", true);
166 fgSetString("/sim/rendering/fog", "nicest");
167 fgSetBool("/environment/clouds/status", true);
168 fgSetDouble("/environment/clouds/altitude-ft", 5000);
169 fgSetBool("/sim/startup/fullscreen", false);
170 fgSetBool("/sim/rendering/shading", true);
171 fgSetBool("/sim/rendering/skyblend", true);
172 fgSetBool("/sim/rendering/textures", true);
173 fgSetBool("/sim/rendering/wireframe", false);
174 fgSetInt("/sim/startup/xsize", 800);
175 fgSetInt("/sim/startup/ysize", 600);
176 fgSetInt("/sim/rendering/bits-per-pixel", 16);
177 fgSetString("/sim/view-mode", "pilot");
178 fgSetDouble("/sim/view/offset-deg", 0);
179 fgSetDouble("/environment/visibility-m", 20000);
182 fgSetString("/sim/startup/units", "feet");
183 fgSetString("/sim/hud/frame-stat-type", "tris");
186 fgSetInt("/sim/startup/time-offset", 0);
187 fgSetString("/sim/startup/time-offset-type", "system-offset");
189 fgSetBool("/sim/networking/network-olk", false);
190 fgSetString("/sim/networking/call-sign", "Johnny");
194 // parse a time string ([+/-]%f[:%f[:%f]]) into hours
196 parse_time(const string& time_in) {
197 char *time_str, num[256];
198 double hours, minutes, seconds;
203 time_str = (char *)time_in.c_str();
205 // printf("parse_time(): %s\n", time_str);
208 if ( strlen(time_str) ) {
209 if ( time_str[0] == '+' ) {
212 } else if ( time_str[0] == '-' ) {
217 // printf("sign = %d\n", sign);
220 if ( strlen(time_str) ) {
222 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
223 num[i] = time_str[0];
227 if ( time_str[0] == ':' ) {
232 // printf("hours = %.2lf\n", hours);
238 if ( strlen(time_str) ) {
240 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
241 num[i] = time_str[0];
245 if ( time_str[0] == ':' ) {
250 // printf("minutes = %.2lf\n", minutes);
252 result += minutes / 60.0;
256 if ( strlen(time_str) ) {
258 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
259 num[i] = time_str[0];
265 // printf("seconds = %.2lf\n", seconds);
267 result += seconds / 3600.0;
270 return(sign * result);
274 // parse a date string (yyyy:mm:dd:hh:mm:ss) into a time_t (seconds)
276 parse_date( const string& date)
279 char * date_str, num[256];
281 // initialize to zero
288 gmt.tm_isdst = 0; // ignore daylight savings time for the moment
289 date_str = (char *)date.c_str();
291 if ( strlen(date_str) ) {
293 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
294 num[i] = date_str[0];
298 if ( date_str[0] == ':' ) {
302 gmt.tm_year = atoi(num) - 1900;
305 if ( strlen(date_str) ) {
307 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
308 num[i] = date_str[0];
312 if ( date_str[0] == ':' ) {
316 gmt.tm_mon = atoi(num) -1;
319 if ( strlen(date_str) ) {
321 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
322 num[i] = date_str[0];
326 if ( date_str[0] == ':' ) {
330 gmt.tm_mday = atoi(num);
333 if ( strlen(date_str) ) {
335 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
336 num[i] = date_str[0];
340 if ( date_str[0] == ':' ) {
344 gmt.tm_hour = atoi(num);
347 if ( strlen(date_str) ) {
349 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
350 num[i] = date_str[0];
354 if ( date_str[0] == ':' ) {
358 gmt.tm_min = atoi(num);
361 if ( strlen(date_str) ) {
363 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
364 num[i] = date_str[0];
368 if ( date_str[0] == ':' ) {
372 gmt.tm_sec = atoi(num);
374 time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
375 gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
376 //printf ("Date is %s\n", ctime(&theTime));
377 //printf ("in seconds that is %d\n", theTime);
383 // parse angle in the form of [+/-]ddd:mm:ss into degrees
385 parse_degree( const string& degree_str) {
386 double result = parse_time( degree_str );
388 // printf("Degree = %.4f\n", result);
394 // parse time offset string into seconds
396 parse_time_offset( const string& time_str) {
399 // printf("time offset = %s\n", time_str);
402 result = (int)rint(parse_time(time_str) * 3600.0);
404 result = (int)(parse_time(time_str) * 3600.0);
407 // printf("parse_time_offset(): %d\n", result);
413 // Parse --fov=x.xx type option
415 parse_fov( const string& arg ) {
416 double fov = atof(arg);
418 if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
419 if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
421 fgSetDouble("/sim/field-of-view", fov);
423 // printf("parse_fov(): result = %.4f\n", fov);
429 // Parse I/O channel option
431 // Format is "--protocol=medium,direction,hz,medium_options,..."
433 // protocol = { native, nmea, garmin, fgfs, rul, pve, etc. }
434 // medium = { serial, socket, file, etc. }
435 // direction = { in, out, bi }
436 // hz = number of times to process channel per second (floating
437 // point values are ok.
439 // Serial example "--nmea=serial,dir,hz,device,baud" where
441 // device = OS device name of serial line to be open()'ed
442 // baud = {300, 1200, 2400, ..., 230400}
444 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
446 // machine = machine name or ip address if client (leave empty if server)
447 // port = port, leave empty to let system choose
448 // style = tcp or udp
450 // File example "--garmin=file,dir,hz,filename" where
452 // filename = file system file name
455 parse_channel( const string& type, const string& channel_str ) {
456 // cout << "Channel string = " << channel_str << endl;
458 globals->get_channel_options_list()->push_back( type + "," + channel_str );
464 // Parse --wp=ID[@alt]
466 parse_wp( const string& arg ) {
470 unsigned int pos = arg.find( "@" );
471 if ( pos != string::npos ) {
472 id = arg.substr( 0, pos );
473 alt_str = arg.substr( pos + 1 );
474 // cout << "id str = " << id << " alt str = " << alt_str << endl;
475 alt = atof( alt_str.c_str() );
476 if ( fgGetString("/sim/startup/units") == "feet" ) {
477 alt *= SG_FEET_TO_METER;
484 if ( fgFindAirportID( id, &a ) ) {
485 SGWayPoint wp( a.longitude, a.latitude, alt, SGWayPoint::WGS84, id );
486 globals->get_route()->add_waypoint( wp );
495 // Parse --flight-plan=[file]
497 parse_flightplan(const string& arg)
499 sg_gzifstream in(arg.c_str());
500 if ( !in.is_open() ) {
506 #if defined( macintosh )
507 getline( in, line, '\r' );
509 getline( in, line, '\n' );
512 // catch extraneous (DOS) line ending character
513 if ( line[line.length() - 1] < 32 ) {
514 line = line.substr( 0, line.length()-1 );
527 // Parse a single option
529 parse_option (const string& arg)
532 if ( (arg == "--help") || (arg == "-h") ) {
533 // help/usage request
534 return(FG_OPTIONS_HELP);
535 } else if ( arg == "--disable-game-mode") {
536 fgSetBool("/sim/startup/game-mode", false);
537 } else if ( arg == "--enable-game-mode" ) {
538 fgSetBool("/sim/startup/game-mode", true);
539 } else if ( arg == "--disable-splash-screen" ) {
540 fgSetBool("/sim/startup/splash-screen", false);
541 } else if ( arg == "--enable-splash-screen" ) {
542 fgSetBool("/sim/startup/splash-screen", true);
543 } else if ( arg == "--disable-intro-music" ) {
544 fgSetBool("/sim/startup/intro-music", false);
545 } else if ( arg == "--enable-intro-music" ) {
546 fgSetBool("/sim/startup/intro-music", true);
547 } else if ( arg == "--disable-mouse-pointer" ) {
548 fgSetString("/sim/startup/mouse-pointer", "disabled");
549 } else if ( arg == "--enable-mouse-pointer" ) {
550 fgSetString("/sim/startup/mouse-pointer", "enabled");
551 } else if ( arg == "--disable-freeze" ) {
552 fgSetBool("/sim/freeze", false);
553 } else if ( arg == "--enable-freeze" ) {
554 fgSetBool("/sim/freeze", true);
555 } else if ( arg == "--disable-anti-alias-hud" ) {
556 fgSetBool("/sim/hud/antialiased", false);
557 } else if ( arg == "--enable-anti-alias-hud" ) {
558 fgSetBool("/sim/hud/antialiased", true);
559 } else if ( arg.find( "--control=") == 0 ) {
560 fgSetString("/sim/control-mode", arg.substr(10));
561 } else if ( arg == "--disable-auto-coordination" ) {
562 fgSetBool("/sim/auto-coordination", false);
563 } else if ( arg == "--enable-auto-coordination" ) {
564 fgSetBool("/sim/auto-coordination", true);
565 } else if ( arg.find( "--browser-app=") == 0 ) {
566 fgSetString("/sim/startup/browser-app", arg.substr(14));
567 } else if ( arg == "--disable-hud" ) {
568 fgSetBool("/sim/hud/visibility", false);
569 } else if ( arg == "--enable-hud" ) {
570 fgSetBool("/sim/hud/visibility", true);
571 } else if ( arg == "--disable-panel" ) {
572 fgSetBool("/sim/panel/visibility", false);
573 } else if ( arg == "--enable-panel" ) {
574 fgSetBool("/sim/panel/visibility", true);
575 } else if ( arg == "--disable-sound" ) {
576 fgSetBool("/sim/sound", false);
577 } else if ( arg == "--enable-sound" ) {
578 fgSetBool("/sim/sound", true);
579 } else if ( arg.find( "--airport-id=") == 0 ) {
580 // NB: changed property name!!!
581 fgSetString("/sim/startup/airport-id", arg.substr(13));
582 } else if ( arg.find( "--offset-distance=") == 0 ) {
583 fgSetDouble("/sim/startup/offset-distance", atof(arg.substr(18)));
584 } else if ( arg.find( "--offset-azimuth=") == 0 ) {
585 fgSetDouble("/sim/startup/offset-azimuth", atof(arg.substr(17)));
586 } else if ( arg.find( "--lon=" ) == 0 ) {
587 fgSetDouble("/position/longitude-deg",
588 parse_degree(arg.substr(6)));
589 fgSetString("/sim/startup/airport-id", "");
590 } else if ( arg.find( "--lat=" ) == 0 ) {
591 fgSetDouble("/position/latitude-deg",
592 parse_degree(arg.substr(6)));
593 fgSetString("/sim/startup/airport-id", "");
594 } else if ( arg.find( "--altitude=" ) == 0 ) {
595 fgSetBool("/sim/startup/onground", false);
596 if ( fgGetString("/sim/startup/units") == "feet" )
597 fgSetDouble("/position/altitude-ft", atof(arg.substr(11)));
599 fgSetDouble("/position/altitude-ft",
600 atof(arg.substr(11)) * SG_METER_TO_FEET);
601 } else if ( arg.find( "--uBody=" ) == 0 ) {
602 fgSetString("/sim/startup/speed-set", "UVW");
603 if ( fgGetString("/sim/startup/units") == "feet" )
604 fgSetDouble("/velocities/uBody-fps", atof(arg.substr(8)));
606 fgSetDouble("/velocities/uBody-fps",
607 atof(arg.substr(8)) * SG_METER_TO_FEET);
608 } else if ( arg.find( "--vBody=" ) == 0 ) {
609 fgSetString("/sim/startup/speed-set", "UVW");
610 if ( fgGetString("/sim/startup/units") == "feet" )
611 fgSetDouble("/velocities/vBody-fps", atof(arg.substr(8)));
613 fgSetDouble("/velocities/vBody-fps",
614 atof(arg.substr(8)) * SG_METER_TO_FEET);
615 } else if ( arg.find( "--wBody=" ) == 0 ) {
616 fgSetString("/sim/startup/speed-set", "UVW");
617 if ( fgGetString("/sim/startup/units") == "feet" )
618 fgSetDouble("/velocities/wBody-fps", atof(arg.substr(8)));
620 fgSetDouble("/velocities/wBody-fps",
621 atof(arg.substr(8)) * SG_METER_TO_FEET);
622 } else if ( arg.find( "--vNorth=" ) == 0 ) {
623 fgSetString("/sim/startup/speed-set", "NED");
624 if ( fgGetString("/sim/startup/units") == "feet" )
625 fgSetDouble("/velocities/speed-north-fps", atof(arg.substr(9)));
627 fgSetDouble("/velocities/speed-north-fps",
628 atof(arg.substr(9)) * SG_METER_TO_FEET);
629 } else if ( arg.find( "--vEast=" ) == 0 ) {
630 fgSetString("/sim/startup/speed-set", "NED");
631 if ( fgGetString("/sim/startup/units") == "feet" )
632 fgSetDouble("/velocities/speed-east-fps", atof(arg.substr(8)));
634 fgSetDouble("/velocities/speed-east-fps",
635 atof(arg.substr(8)) * SG_METER_TO_FEET);
636 } else if ( arg.find( "--vDown=" ) == 0 ) {
637 fgSetString("/sim/startup/speed-set", "NED");
638 if ( fgGetString("/sim/startup/units") == "feet" )
639 fgSetDouble("/velocities/speed-down-fps", atof(arg.substr(8)));
641 fgSetDouble("/velocities/speed-down-fps",
642 atof(arg.substr(8)) * SG_METER_TO_FEET);
643 } else if ( arg.find( "--vc=" ) == 0) {
644 fgSetString("/sim/startup/speed-set", "knots");
645 fgSetDouble("/velocities/airspeed-kt", atof(arg.substr(5)));
646 } else if ( arg.find( "--mach=" ) == 0) {
647 fgSetString("/sim/startup/speed-set", "mach");
648 fgSetDouble("/velocities/mach", atof(arg.substr(7)));
649 } else if ( arg.find( "--heading=" ) == 0 ) {
650 fgSetDouble("/orientation/heading-deg", atof(arg.substr(10)));
651 } else if ( arg.find( "--roll=" ) == 0 ) {
652 fgSetDouble("/orientation/roll-deg", atof(arg.substr(7)));
653 } else if ( arg.find( "--pitch=" ) == 0 ) {
654 fgSetDouble("/orientation/pitch-deg", atof(arg.substr(8)));
655 } else if ( arg.find( "--fg-root=" ) == 0 ) {
656 globals->set_fg_root(arg.substr( 10 ));
657 } else if ( arg.find( "--fg-scenery=" ) == 0 ) {
658 globals->set_fg_scenery(arg.substr( 13 ));
659 } else if ( arg.find( "--fdm=" ) == 0 ) {
660 fgSetString("/sim/flight-model", arg.substr(6));
661 } else if ( arg.find( "--aircraft=" ) == 0 ) {
662 fgSetString("/sim/aircraft", arg.substr(11));
663 } else if ( arg.find( "--aircraft-dir=" ) == 0 ) {
664 fgSetString("/sim/aircraft-dir", arg.substr(15));
665 } else if ( arg.find( "--model-hz=" ) == 0 ) {
666 fgSetInt("/sim/model-hz", atoi(arg.substr(11)));
667 } else if ( arg.find( "--speed=" ) == 0 ) {
668 fgSetInt("/sim/speed-up", atoi(arg.substr(8)));
669 } else if ( arg.find( "--trim") == 0) {
670 fgSetBool("/sim/startup/trim", true);
671 } else if ( arg.find( "--notrim") == 0) {
672 fgSetBool("/sim/startup/trim", false);
673 } else if ( arg.find( "--on-ground") == 0) {
674 fgSetBool("/sim/startup/onground", true);
675 } else if ( arg.find( "--in-air") == 0) {
676 fgSetBool("/sim/startup/onground", false);
677 } else if ( arg == "--fog-disable" ) {
678 fgSetString("/sim/rendering/fog", "disabled");
679 } else if ( arg == "--fog-fastest" ) {
680 fgSetString("/sim/rendering/fog", "fastest");
681 } else if ( arg == "--fog-nicest" ) {
682 fgSetString("/sim/fog", "nicest");
683 } else if ( arg == "--disable-clouds" ) {
684 fgSetBool("/environment/clouds/status", false);
685 } else if ( arg == "--enable-clouds" ) {
686 fgSetBool("/environment/clouds/status", true);
687 } else if ( arg.find( "--clouds-asl=" ) == 0 ) {
688 // FIXME: check units
689 if ( fgGetString("/sim/startup/units") == "feet" )
690 fgSetDouble("/environment/clouds/altitude-ft",
691 atof(arg.substr(13)) * SG_FEET_TO_METER);
693 fgSetDouble("/environment/clouds/altitude-ft",
694 atof(arg.substr(13)));
695 } else if ( arg.find( "--fov=" ) == 0 ) {
696 parse_fov( arg.substr(6) );
697 } else if ( arg == "--disable-fullscreen" ) {
698 fgSetBool("/sim/startup/fullscreen", false);
699 } else if ( arg== "--enable-fullscreen") {
700 fgSetBool("/sim/startup/fullscreen", true);
701 } else if ( arg == "--shading-flat") {
702 fgSetBool("/sim/rendering/shading", false);
703 } else if ( arg == "--shading-smooth") {
704 fgSetBool("/sim/rendering/shading", true);
705 } else if ( arg == "--disable-skyblend") {
706 fgSetBool("/sim/rendering/skyblend", false);
707 } else if ( arg== "--enable-skyblend" ) {
708 fgSetBool("/sim/rendering/skyblend", true);
709 } else if ( arg == "--disable-textures" ) {
710 fgSetBool("/sim/rendering/textures", false);
711 } else if ( arg == "--enable-textures" ) {
712 fgSetBool("/sim/rendering/textures", true);
713 } else if ( arg == "--disable-wireframe" ) {
714 fgSetBool("/sim/rendering/wireframe", false);
715 } else if ( arg == "--enable-wireframe" ) {
716 fgSetBool("/sim/rendering/wireframe", true);
717 } else if ( arg.find( "--geometry=" ) == 0 ) {
718 bool geometry_ok = true;
719 int xsize = 0, ysize = 0;
720 string geometry = arg.substr( 11 );
721 string::size_type i = geometry.find('x');
723 if (i != string::npos) {
724 xsize = atoi(geometry.substr(0, i));
725 ysize = atoi(geometry.substr(i+1));
730 if ( xsize <= 0 || ysize <= 0 ) {
736 if ( !geometry_ok ) {
737 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown geometry: " << geometry );
738 SG_LOG( SG_GENERAL, SG_ALERT,
739 "Setting geometry to " << xsize << 'x' << ysize << '\n');
741 SG_LOG( SG_GENERAL, SG_INFO,
742 "Setting geometry to " << xsize << 'x' << ysize << '\n');
743 fgSetInt("/sim/startup/xsize", xsize);
744 fgSetInt("/sim/startup/ysize", ysize);
746 } else if ( arg.find( "--bpp=" ) == 0 ) {
747 string bits_per_pix = arg.substr( 6 );
748 if ( bits_per_pix == "16" ) {
749 fgSetInt("/sim/rendering/bits-per-pixel", 16);
750 } else if ( bits_per_pix == "24" ) {
751 fgSetInt("/sim/rendering/bits-per-pixel", 24);
752 } else if ( bits_per_pix == "32" ) {
753 fgSetInt("/sim/rendering/bits-per-pixel", 32);
755 SG_LOG(SG_GENERAL, SG_ALERT, "Unsupported bpp " << bits_per_pix);
757 } else if ( arg == "--units-feet" ) {
758 fgSetString("/sim/startup/units", "feet");
759 } else if ( arg == "--units-meters" ) {
760 fgSetString("/sim/startup/units", "meters");
761 } else if ( arg.find( "--time-offset" ) == 0 ) {
762 fgSetInt("/sim/startup/time-offset",
763 parse_time_offset( (arg.substr(14)) ));
764 } else if ( arg.find( "--time-match-real") == 0 ) {
765 fgSetString("/sim/startup/time-offset-type",
767 } else if ( arg.find( "--time-match-local") == 0 ) {
768 fgSetString("/sim/startup/time-offset-type",
770 } else if ( arg.find( "--start-date-sys=") == 0 ) {
771 fgSetInt("/sim/startup/time-offset",
772 parse_date((arg.substr(17))));
773 fgSetString("/sim/startup/time-offset-type", "system");
774 } else if ( arg.find( "--start-date-lat=") == 0 ) {
775 fgSetInt("/sim/startup/time-offset",
776 parse_date((arg.substr(17))));
777 fgSetString("/sim/startup/time-offset-type",
779 } else if ( arg.find( "--start-date-gmt=") == 0 ) {
780 fgSetInt("/sim/startup/time-offset",
781 parse_date((arg.substr(17))));
782 fgSetString("/sim/startup/time-offset-type", "gmt");
783 } else if ( arg == "--hud-tris" ) {
784 fgSetString("/sim/hud/frame-stat-type", "tris");
785 } else if ( arg == "--hud-culled" ) {
786 fgSetString("/sim/hud/frame-stat-type", "culled");
787 } else if ( arg.find( "--atlas=" ) == 0 ) {
788 parse_channel( "atlas", arg.substr(8) );
789 } else if ( arg.find( "--native=" ) == 0 ) {
790 parse_channel( "native", arg.substr(9) );
791 } else if ( arg.find( "--garmin=" ) == 0 ) {
792 parse_channel( "garmin", arg.substr(9) );
793 } else if ( arg.find( "--nmea=" ) == 0 ) {
794 parse_channel( "nmea", arg.substr(7) );
795 } else if ( arg.find( "--props=" ) == 0 ) {
796 parse_channel( "props", arg.substr(8) );
797 } else if ( arg.find( "--pve=" ) == 0 ) {
798 parse_channel( "pve", arg.substr(6) );
799 } else if ( arg.find( "--ray=" ) == 0 ) {
800 parse_channel( "ray", arg.substr(6) );
801 } else if ( arg.find( "--rul=" ) == 0 ) {
802 parse_channel( "rul", arg.substr(6) );
803 } else if ( arg.find( "--joyclient=" ) == 0 ) {
804 parse_channel( "joyclient", arg.substr(12) );
805 #ifdef FG_NETWORK_OLK
806 } else if ( arg == "--disable-network-olk" ) {
807 fgSetBool("/sim/networking/olk", false);
808 } else if ( arg== "--enable-network-olk") {
809 fgSetBool("/sim/networking/olk", true);
810 } else if ( arg == "--net-hud" ) {
811 fgSetBool("/sim/hud/net-display", true);
812 net_hud_display = 1; // FIXME
813 } else if ( arg.find( "--net-id=") == 0 ) {
814 fgSetString("sim/networking/call-sign", arg.substr(9));
816 } else if ( arg.find( "--prop:" ) == 0 ) {
817 string assign = arg.substr(7);
818 unsigned int pos = assign.find('=');
819 if ( pos == arg.npos || pos == 0 ) {
820 SG_LOG( SG_GENERAL, SG_ALERT, "Bad property assignment: " << arg );
821 return FG_OPTIONS_ERROR;
823 string name = assign.substr(0, pos);
824 string value = assign.substr(pos + 1);
825 fgSetString(name.c_str(), value);
826 // SG_LOG(SG_GENERAL, SG_INFO, "Setting default value of property "
827 // << name << " to \"" << value << '"');
828 // $$$ begin - added VS Renganathan, 14 Oct 2K
829 // for multi-window outside window imagery
830 } else if ( arg.find( "--view-offset=" ) == 0 ) {
831 string woffset = arg.substr( 14 );
832 double default_view_offset = 0.0;
833 if ( woffset == "LEFT" ) {
834 default_view_offset = SGD_PI * 0.25;
835 } else if ( woffset == "RIGHT" ) {
836 default_view_offset = SGD_PI * 1.75;
837 } else if ( woffset == "CENTER" ) {
838 default_view_offset = 0.00;
840 default_view_offset = atof( woffset.c_str() ) * SGD_DEGREES_TO_RADIANS;
842 FGViewerRPH *pilot_view =
843 (FGViewerRPH *)globals->get_viewmgr()->get_view( 0 );
844 pilot_view->set_view_offset( default_view_offset );
845 pilot_view->set_goal_view_offset( default_view_offset );
846 fgSetDouble("/sim/view/offset-deg", default_view_offset);
847 // $$$ end - added VS Renganathan, 14 Oct 2K
848 } else if ( arg.find( "--visibility=" ) == 0 ) {
849 fgSetDouble("/environment/visibility-m", atof(arg.substr(13)));
850 } else if ( arg.find( "--visibility-miles=" ) == 0 ) {
851 double visibility = atof(arg.substr(19)) * 5280.0 * SG_FEET_TO_METER;
852 fgSetDouble("/environment/visibility-m", visibility);
853 } else if ( arg.find( "--wind=" ) == 0 ) {
854 string val = arg.substr(7);
855 unsigned int pos = val.find('@');
856 if ( pos == string::npos ) {
857 SG_LOG( SG_GENERAL, SG_ALERT, "bad wind value " << val );
858 return FG_OPTIONS_ERROR;
860 double dir = atof(val.substr(0,pos).c_str());
861 double speed = atof(val.substr(pos+1).c_str());
862 SG_LOG(SG_GENERAL, SG_INFO, "WIND: " << dir << '@' <<
863 speed << " knots" << endl);
865 speed *= SG_NM_TO_METER * SG_METER_TO_FEET * (1.0/3600);
869 dir *= SGD_DEGREES_TO_RADIANS;
870 fgSetDouble("/environment/wind-north-fps",
872 fgSetDouble("/environment/wind-east-fps",
874 } else if ( arg.find( "--wp=" ) == 0 ) {
875 parse_wp( arg.substr( 5 ) );
876 } else if ( arg.find( "--flight-plan=") == 0) {
877 parse_flightplan ( arg.substr (14) );
878 } else if ( arg.find( "--config=" ) == 0 ) {
879 string file = arg.substr(9);
880 if (!readProperties(file, globals->get_props())) {
881 SG_LOG(SG_IO, SG_ALERT,
882 "--config: failed to read properties from " << file);
883 return FG_OPTIONS_ERROR;
886 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
887 return FG_OPTIONS_ERROR;
890 return FG_OPTIONS_OK;
894 // Scan the command line options for an fg_root definition and set
897 fgScanForRoot (int argc, char **argv)
901 SG_LOG(SG_GENERAL, SG_INFO, "Scanning for root: command line");
904 SG_LOG( SG_GENERAL, SG_DEBUG, "argv[" << i << "] = " << argv[i] );
906 string arg = argv[i];
907 if ( arg.find( "--fg-root=" ) == 0 ) {
908 return arg.substr( 10 );
918 // Scan the config file for an fg_root definition and set just that.
920 fgScanForRoot (const string& path)
922 sg_gzifstream in( path );
926 SG_LOG( SG_GENERAL, SG_INFO, "Scanning for root: " << path );
930 while ( ! in.eof() ) {
933 while ( in.get(c) && c != '\0' ) {
938 #if defined( macintosh )
939 getline( in, line, '\r' );
941 getline( in, line, '\n' );
944 // catch extraneous (DOS) line ending character
945 if ( line[line.length() - 1] < 32 ) {
946 line = line.substr( 0, line.length()-1 );
949 if ( line.find( "--fg-root=" ) == 0 ) {
950 return line.substr( 10 );
960 // Parse the command line options
962 fgParseOptions (int argc, char **argv) {
966 SG_LOG(SG_GENERAL, SG_INFO, "Processing command line arguments");
969 SG_LOG( SG_GENERAL, SG_DEBUG, "argv[" << i << "] = " << argv[i] );
971 result = parse_option(argv[i]);
972 if ( (result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR) ) {
982 // Parse config file options
984 fgParseOptions (const string& path) {
985 sg_gzifstream in( path );
986 if ( !in.is_open() ) {
990 SG_LOG( SG_GENERAL, SG_INFO, "Processing config file: " << path );
994 while ( ! in.eof() ) {
997 while ( in.get(c) && c != '\0' ) {
1002 #if defined( macintosh )
1003 getline( in, line, '\r' );
1005 getline( in, line, '\n' );
1008 // catch extraneous (DOS) line ending character
1009 if ( line[line.length() - 1] < 32 ) {
1010 line = line.substr( 0, line.length()-1 );
1013 if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
1014 SG_LOG( SG_GENERAL, SG_ALERT,
1015 "Config file parse error: " << path << " '"
1025 // Print usage message
1029 cout << "Usage: fgfs [ options ... ]" << endl;
1032 cout << "General Options:" << endl;
1033 cout << "\t--help -h: print usage" << endl;
1034 cout << "\t--fg-root=path: specify the root path for all the data files"
1036 cout << "\t--fg-scenery=path: specify the base path for all the scenery"
1038 << "\t\tdefaults to $FG_ROOT/Scenery" << endl;
1039 cout << "\t--disable-game-mode: disable full-screen game mode" << endl;
1040 cout << "\t--enable-game-mode: enable full-screen game mode" << endl;
1041 cout << "\t--disable-splash-screen: disable splash screen" << endl;
1042 cout << "\t--enable-splash-screen: enable splash screen" << endl;
1043 cout << "\t--disable-intro-music: disable introduction music" << endl;
1044 cout << "\t--enable-intro-music: enable introduction music" << endl;
1045 cout << "\t--disable-mouse-pointer: disable extra mouse pointer" << endl;
1046 cout << "\t--enable-mouse-pointer: enable extra mouse pointer (i.e. for"
1048 cout << "\t\tfull screen voodoo/voodoo-II based cards.)" << endl;
1049 cout << "\t--disable-freeze: start out in an running state" << endl;
1050 cout << "\t--enable-freeze: start out in a frozen state" << endl;
1051 cout << "\t--control=mode: primary control mode "
1052 << "(joystick, keyboard, mouse)" << endl;
1053 cout << "\t--enable-auto-coordination: enable auto coordination" << endl;
1054 cout << "\t--disable-auto-coordination: disable auto coordination" << endl;
1055 cout << "\t--browser-app=/path/to/app: specify location of your web browser" << endl;
1056 cout << "\t--prop:name=value: set property <name> to <value>" << endl;
1057 cout << "\t--config=path: load additional properties from path" << endl;
1060 cout << "Features:" << endl;
1061 cout << "\t--disable-hud: disable heads up display" << endl;
1062 cout << "\t--enable-hud: enable heads up display" << endl;
1063 cout << "\t--disable-panel: disable instrument panel" << endl;
1064 cout << "\t--enable-panel: enable instrumetn panel" << endl;
1065 cout << "\t--disable-sound: disable sound effects" << endl;
1066 cout << "\t--enable-sound: enable sound effects" << endl;
1067 cout << "\t--disable-anti-alias-hud: disable anti aliased hud" << endl;
1068 cout << "\t--enable-anti-alias-hud: enable anti aliased hud" << endl;
1071 cout << "Flight Model:" << endl;
1072 cout << "\t--fdm=abcd: selects the core flight model code." << endl;
1073 cout << "\t\tcan be one of jsb, larcsim, magic, external, balloon, or ada"
1075 cout << "\t--aircraft=abcd: aircraft model to load" << endl;
1076 cout << "\t--model-hz=n: run the FDM this rate (iterations per second)"
1078 cout << "\t--speed=n: run the FDM this much faster than real time" << endl;
1079 cout << "\t--notrim: Do NOT attempt to trim the model when initializing JSBsim" << endl;
1080 cout << "\t--on-ground: Start up at ground level (default)" << endl;
1081 cout << "\t--in-air: Start up in air (implied by specifying an initial"
1082 << " altitude above ground level." << endl;
1083 cout << "\t--wind=DIR@SPEED: specify wind coming from DIR (degrees) at SPEED (knots)" << endl;
1087 cout <<"Aircraft model directory:" << endl;
1088 cout <<"\t--aircraft-dir=<path> path is relative to the path of the executable" << endl;
1091 cout << "Initial Position and Orientation:" << endl;
1092 cout << "\t--airport-id=ABCD: specify starting postion by airport id"
1094 cout << "\t--offset-distance: specify distance to threshhold"
1096 cout << "\t--offset-azimuth: specify heading to threshhold (deg) "
1098 cout << "\t--lon=degrees: starting longitude in degrees (west = -)"
1100 cout << "\t--lat=degrees: starting latitude in degrees (south = -)"
1102 cout << "\t--altitude=feet: starting altitude in feet" << endl;
1103 cout << "\t\t(unless --units-meters specified" << endl;
1104 cout << "\t--heading=degrees: heading (yaw) angle in degress (Psi)"
1106 cout << "\t--roll=degrees: roll angle in degrees (Phi)" << endl;
1107 cout << "\t--pitch=degrees: pitch angle in degrees (Theta)" << endl;
1108 cout << "\t--uBody=feet per second: velocity along the body X axis"
1110 cout << "\t--vBody=feet per second: velocity along the body Y axis"
1112 cout << "\t--wBody=feet per second: velocity along the body Z axis"
1114 cout << "\t\t(unless --units-meters specified" << endl;
1115 cout << "\t--vc= initial airspeed in knots (--fdm=jsb only)" << endl;
1116 cout << "\t--mach= initial mach number (--fdm=jsb only)" << endl;
1119 cout << "Rendering Options:" << endl;
1120 cout << "\t--fog-disable: disable fog/haze" << endl;
1121 cout << "\t--fog-fastest: enable fastest fog/haze" << endl;
1122 cout << "\t--fog-nicest: enable nicest fog/haze" << endl;
1123 cout << "\t--enable-clouds: enable demo cloud layer" << endl;
1124 cout << "\t--disable-clouds: disable demo cloud layer" << endl;
1125 cout << "\t--clouds-asl=xxx: specify altitude of cloud layer above sea level" << endl;
1126 cout << "\t--fov=xx.x: specify initial field of view angle in degrees"
1128 cout << "\t--disable-fullscreen: disable fullscreen mode" << endl;
1129 cout << "\t--enable-fullscreen: enable fullscreen mode" << endl;
1130 cout << "\t--shading-flat: enable flat shading" << endl;
1131 cout << "\t--shading-smooth: enable smooth shading" << endl;
1132 cout << "\t--disable-skyblend: disable sky blending" << endl;
1133 cout << "\t--enable-skyblend: enable sky blending" << endl;
1134 cout << "\t--disable-textures: disable textures" << endl;
1135 cout << "\t--enable-textures: enable textures" << endl;
1136 cout << "\t--disable-wireframe: disable wireframe drawing mode" << endl;
1137 cout << "\t--enable-wireframe: enable wireframe drawing mode" << endl;
1138 cout << "\t--geometry=WWWxHHH: window geometry: 640x480, 800x600, etc."
1140 cout << "\t--view-offset=xxx: set the default forward view direction"
1142 cout << "\t\tas an offset from straight ahead. Allowable values are"
1144 cout << "\t\tLEFT, RIGHT, CENTER, or a specific number of degrees" << endl;
1145 cout << "\t--visibility=xxx: specify initial visibility in meters" << endl;
1146 cout << "\t--visibility-miles=xxx: specify initial visibility in miles"
1150 cout << "Scenery Options:" << endl;
1151 cout << "\t--tile-radius=n: specify tile radius, must be 1 - 4" << endl;
1154 cout << "Hud Options:" << endl;
1155 cout << "\t--units-feet: Hud displays units in feet" << endl;
1156 cout << "\t--units-meters: Hud displays units in meters" << endl;
1157 cout << "\t--hud-tris: Hud displays number of triangles rendered" << endl;
1158 cout << "\t--hud-culled: Hud displays percentage of triangles culled"
1162 cout << "Time Options:" << endl;
1163 cout << "\t--time-offset=[+-]hh:mm:ss: add this time offset" << endl;
1164 cout << "\t--time-match-real: Synchronize real-world and FlightGear" << endl
1165 << "\t\ttime. Can be used in combination with --time-offset." << endl;
1166 cout << "\t--time-match-local:Synchronize local real-world and " << endl
1167 << "\t\tFlightGear time" << endl;
1168 cout << "\t--start-date-sys=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1169 << "\t\tdate/time. Uses your system time " << endl;
1170 cout << "\t--start-date-gmt=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1171 << "\t\tdate/time. Uses Greenwich Mean Time" << endl;
1172 cout << "\t--start-date-lat=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1173 << "\t\tdate/time. Uses Local Aircraft Time" << endl;
1174 #ifdef FG_NETWORK_OLK
1177 cout << "Network Options:" << endl;
1178 cout << "\t--enable-network-olk: enable Multipilot mode" << endl;
1179 cout << "\t--disable-network-olk: disable Multipilot mode (default)" << endl;
1180 cout << "\t--net-hud: Hud displays network info" << endl;
1181 cout << "\t--net-id=name: specify your own callsign" << endl;
1185 cout << "Route/Way Point Options:" << endl;
1186 cout << "\t--wp=ID[@alt]: specify a waypoint for the GC autopilot" << endl;
1187 cout << "\t\tYou can specify multiple waypoints (a route) with multiple"
1189 cout << "\t\tinstances of --wp=" << endl;
1190 cout << "\t--flight-plan=[file]: Read all waypoints from [file]" <<endl;