]> git.mxchange.org Git - flightgear.git/blob - src/Main/options.cxx
Panel tweaks to support "shaped" panels.
[flightgear.git] / src / Main / options.cxx
1 // options.cxx -- class to handle command line options
2 //
3 // Written by Curtis Olson, started April 1998.
4 //
5 // Copyright (C) 1998  Curtis L. Olson  - curt@me.umn.edu
6 //
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.
11 //
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.
16 //
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.
20 //
21 // $Id$
22
23
24 #ifdef HAVE_CONFIG_H
25 #  include <config.h>
26 #endif
27
28 #if defined(FX) && defined(XMESA)
29 bool global_fullscreen = true;
30 #endif
31
32 #include <simgear/compiler.h>
33
34 #include <math.h>            // rint()
35 #include <stdio.h>
36 #include <stdlib.h>          // atof(), atoi()
37 #include <string.h>
38
39 #include STL_STRING
40
41 #include <simgear/constants.h>
42 #include <simgear/debug/logstream.hxx>
43 #include <simgear/misc/fgstream.hxx>
44 #include <simgear/misc/props.hxx>
45 #include <simgear/timing/sg_time.hxx>
46
47 #include <Include/general.hxx>
48 #include <Airports/simple.hxx>
49 #include <Cockpit/cockpit.hxx>
50 #include <FDM/flight.hxx>
51 #include <FDM/UIUCModel/uiuc_aircraftdir.h>
52 #ifdef FG_NETWORK_OLK
53 #  include <NetworkOLK/network.h>
54 #endif
55
56 #include "fg_init.hxx"
57 #include "globals.hxx"
58 #include "options.hxx"
59 #include "views.hxx"
60
61 FG_USING_STD(string);
62 FG_USING_NAMESPACE(std);
63
64 // from GLUTmain.cxx
65 extern void fgReshape( int width, int height );
66
67 inline double
68 atof( const string& str )
69 {
70
71 #ifdef __MWERKS__ 
72     // -dw- if ::atof is called, then we get an infinite loop
73     return std::atof( str.c_str() );
74 #else
75     return ::atof( str.c_str() );
76 #endif
77 }
78
79 inline int
80 atoi( const string& str )
81 {
82 #ifdef __MWERKS__ 
83     // -dw- if ::atoi is called, then we get an infinite loop
84     return std::atoi( str.c_str() );
85 #else
86     return ::atoi( str.c_str() );
87 #endif
88 }
89
90
91 // Defined the shared options class here
92 fgOPTIONS current_options;
93
94
95 // Constructor
96 fgOPTIONS::fgOPTIONS() :
97     // starting longitude in degrees (west = -)
98     // starting latitude in degrees (south = -)
99
100     // Default initial position is Globe, AZ (P13)
101     lon(-110.6642444),
102     lat(  33.3528917),
103
104     // North of the city of Globe
105     // lon(-110.7),
106     // lat(  33.4),
107
108     // North of the city of Globe
109     // lon(-110.742578),
110     // lat(  33.507122),
111
112     // Near where I used to live in Globe, AZ
113     // lon(-110.766000),
114     // lat(  33.377778),
115
116     // 10125 Jewell St. NE
117     // lon(-93.15),
118     // lat( 45.15),
119
120     // Near KHSP (Hot Springs, VA)
121     // lon(-79.8338964 + 0.01),
122     // lat( 37.9514564 + 0.008),
123
124     // (SEZ) SEDONA airport
125     // lon(-111.7884614 + 0.01),
126     // lat(  34.8486289 - 0.015),
127
128     // Jim Brennon's Kingmont Observatory
129     // lon(-121.1131667),
130     // lat(  38.8293917),
131
132     // Huaras, Peru (S09d 31.871'  W077d 31.498')
133     // lon(-77.5249667),
134     // lat( -9.5311833),
135  
136     // Eclipse Watching w73.5 n10 (approx) 18:00 UT
137     // lon(-73.5),
138     // lat( 10.0),
139
140     // Timms Hill (WI)
141     // lon(-90.1953055556),
142     // lat( 45.4511388889),
143
144     // starting altitude in meters (this will be reset to ground level
145     // if it is lower than the terrain
146     altitude(-9999.0),
147
148     // Initial Orientation
149     heading(270.0),      // heading (yaw) angle in degress (Psi)
150     roll(0.0),           // roll angle in degrees (Phi)
151     pitch(0.424),        // pitch angle in degrees (Theta)
152
153     // Initialize current options velocities to 0.0
154     uBody(0.0), vBody(0.0), wBody(0.0), vkcas(0.0), mach(0.0),
155
156     // Miscellaneous
157     game_mode(0),
158     splash_screen(1),
159     intro_music(1),
160     mouse_pointer(0),
161     control_mode(FG_JOYSTICK),
162     auto_coordination(FG_AUTO_COORD_NOT_SPECIFIED),
163
164     // Features
165     hud_status(0),
166     panel_status(1),
167     sound(1),
168     anti_alias_hud(0),
169
170     // Flight Model options
171     flight_model( FGInterface::FG_LARCSIM ),
172     aircraft( "c172" ),
173     model_hz( NEW_DEFAULT_MODEL_HZ ),
174     speed_up( 1 ),
175     trim(0),
176
177     // Rendering options
178     fog(FG_FOG_NICEST),  // nicest
179     clouds(false),
180     clouds_asl(5000*FEET_TO_METER),
181     fov(55.0),
182     fullscreen(0),
183     shading(1),
184     skyblend(1),
185     textures(1),
186     wireframe(0),
187     xsize(800),
188     ysize(600),
189     bpp(16),
190     view_mode(FG_VIEW_PILOT),
191
192     // Scenery options
193     tile_diameter(5),
194
195     // HUD options
196     units(FG_UNITS_FEET),
197     tris_or_culled(0),
198         
199     // Time options
200     time_offset(0),
201
202     network_olk(false)
203 {
204     // set initial values/defaults
205     time_offset_type = FG_TIME_SYS_OFFSET;
206     char* envp = ::getenv( "FG_ROOT" );
207
208     if ( envp != NULL ) {
209         // fg_root could be anywhere, so default to environmental
210         // variable $FG_ROOT if it is set.
211         fg_root = envp;
212     } else {
213         // Otherwise, default to a random compiled-in location if
214         // $FG_ROOT is not set.  This can still be overridden from the
215         // command line or a config file.
216
217 #if defined( WIN32 )
218         fg_root = "\\FlightGear";
219 #elif defined( macintosh )
220         fg_root = "";
221 #else
222         fg_root = PKGLIBDIR;
223 #endif
224     }
225
226     // set a possibly independent location for scenery data
227     envp = ::getenv( "FG_SCENERY" );
228
229     if ( envp != NULL ) {
230         // fg_root could be anywhere, so default to environmental
231         // variable $FG_ROOT if it is set.
232         fg_scenery = envp;
233     } else {
234         // Otherwise, default to Scenery being in $FG_ROOT/Scenery
235         fg_scenery = "";
236     }
237
238     airport_id = "KPAO";        // default airport id
239     net_id = "Johnney";         // default pilot's name
240
241     // initialize port config string list
242     channel_options_list.clear();
243 }
244
245 void 
246 fgOPTIONS::toggle_panel() {
247     
248     bool freeze = globals->get_freeze();
249
250     if( !freeze )
251         globals->set_freeze(true);
252     
253     if( panel_status ) {
254         panel_status = false;
255         if ( current_panel != NULL )
256           current_panel->setVisibility(false);
257     } else {
258         panel_status = true;
259         if ( current_panel != NULL )
260           current_panel->setVisibility(true);
261     }
262
263     // new rule .. "fov" shouldn't get messed with like this.
264     /* if ( panel_status ) {
265         fov *= 0.4232;
266     } else {
267         fov *= (1.0 / 0.4232);
268     } */
269
270     // fgReshape( xsize, ysize);
271     fgReshape( current_view.get_winWidth(), current_view.get_winHeight() );
272
273     if( !freeze )
274         globals->set_freeze( false );
275 }
276
277 double
278 fgOPTIONS::parse_time(const string& time_in) {
279     char *time_str, num[256];
280     double hours, minutes, seconds;
281     double result = 0.0;
282     int sign = 1;
283     int i;
284
285     time_str = (char *)time_in.c_str();
286
287     // printf("parse_time(): %s\n", time_str);
288
289     // check for sign
290     if ( strlen(time_str) ) {
291         if ( time_str[0] == '+' ) {
292             sign = 1;
293             time_str++;
294         } else if ( time_str[0] == '-' ) {
295             sign = -1;
296             time_str++;
297         }
298     }
299     // printf("sign = %d\n", sign);
300
301     // get hours
302     if ( strlen(time_str) ) {
303         i = 0;
304         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
305             num[i] = time_str[0];
306             time_str++;
307             i++;
308         }
309         if ( time_str[0] == ':' ) {
310             time_str++;
311         }
312         num[i] = '\0';
313         hours = atof(num);
314         // printf("hours = %.2lf\n", hours);
315
316         result += hours;
317     }
318
319     // get minutes
320     if ( strlen(time_str) ) {
321         i = 0;
322         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
323             num[i] = time_str[0];
324             time_str++;
325             i++;
326         }
327         if ( time_str[0] == ':' ) {
328             time_str++;
329         }
330         num[i] = '\0';
331         minutes = atof(num);
332         // printf("minutes = %.2lf\n", minutes);
333
334         result += minutes / 60.0;
335     }
336
337     // get seconds
338     if ( strlen(time_str) ) {
339         i = 0;
340         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
341             num[i] = time_str[0];
342             time_str++;
343             i++;
344         }
345         num[i] = '\0';
346         seconds = atof(num);
347         // printf("seconds = %.2lf\n", seconds);
348
349         result += seconds / 3600.0;
350     }
351
352     return(sign * result);
353 }
354
355
356 long int fgOPTIONS::parse_date( const string& date)
357 {
358     struct tm gmt;
359     char * date_str, num[256];
360     int i;
361     // initialize to zero
362     gmt.tm_sec = 0;
363     gmt.tm_min = 0;
364     gmt.tm_hour = 0;
365     gmt.tm_mday = 0;
366     gmt.tm_mon = 0;
367     gmt.tm_year = 0;
368     gmt.tm_isdst = 0; // ignore daylight savings time for the moment
369     date_str = (char *)date.c_str();
370     // get year
371     if ( strlen(date_str) ) {
372         i = 0;
373         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
374             num[i] = date_str[0];
375             date_str++;
376             i++;
377         }
378         if ( date_str[0] == ':' ) {
379             date_str++;
380         }
381         num[i] = '\0';
382         gmt.tm_year = atoi(num) - 1900;
383     }
384     // get month
385     if ( strlen(date_str) ) {
386         i = 0;
387         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
388             num[i] = date_str[0];
389             date_str++;
390             i++;
391         }
392         if ( date_str[0] == ':' ) {
393             date_str++;
394         }
395         num[i] = '\0';
396         gmt.tm_mon = atoi(num) -1;
397     }
398     // get day
399     if ( strlen(date_str) ) {
400         i = 0;
401         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
402             num[i] = date_str[0];
403             date_str++;
404             i++;
405         }
406         if ( date_str[0] == ':' ) {
407             date_str++;
408         }
409         num[i] = '\0';
410         gmt.tm_mday = atoi(num);
411     }
412     // get hour
413     if ( strlen(date_str) ) {
414         i = 0;
415         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
416             num[i] = date_str[0];
417             date_str++;
418             i++;
419         }
420         if ( date_str[0] == ':' ) {
421             date_str++;
422         }
423         num[i] = '\0';
424         gmt.tm_hour = atoi(num);
425     }
426     // get minute
427     if ( strlen(date_str) ) {
428         i = 0;
429         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
430             num[i] = date_str[0];
431             date_str++;
432             i++;
433         }
434         if ( date_str[0] == ':' ) {
435             date_str++;
436         }
437         num[i] = '\0';
438         gmt.tm_min = atoi(num);
439     }
440     // get second
441     if ( strlen(date_str) ) {
442         i = 0;
443         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
444             num[i] = date_str[0];
445             date_str++;
446             i++;
447         }
448         if ( date_str[0] == ':' ) {
449             date_str++;
450         }
451         num[i] = '\0';
452         gmt.tm_sec = atoi(num);
453     }
454     time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
455                                    gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
456     //printf ("Date is %s\n", ctime(&theTime));
457     //printf ("in seconds that is %d\n", theTime);
458     //exit(1);
459     return (theTime);
460 }
461
462
463 // parse degree in the form of [+/-]hhh:mm:ss
464 void fgOPTIONS::parse_control( const string& mode ) {
465     if ( mode == "joystick" ) {
466         control_mode = FG_JOYSTICK;
467     } else if ( mode == "mouse" ) {
468         control_mode = FG_MOUSE;
469     } else {
470         control_mode = FG_KEYBOARD;
471     }
472 }
473
474
475 /// parse degree in the form of [+/-]hhh:mm:ss
476 double
477 fgOPTIONS::parse_degree( const string& degree_str) {
478     double result = parse_time( degree_str );
479
480     // printf("Degree = %.4f\n", result);
481
482     return(result);
483 }
484
485
486 // parse time offset command line option
487 int
488 fgOPTIONS::parse_time_offset( const string& time_str) {
489     int result;
490
491     // printf("time offset = %s\n", time_str);
492
493 #ifdef HAVE_RINT
494     result = (int)rint(parse_time(time_str) * 3600.0);
495 #else
496     result = (int)(parse_time(time_str) * 3600.0);
497 #endif
498
499     // printf("parse_time_offset(): %d\n", result);
500
501     return( result );
502 }
503
504
505 // Parse --tile-diameter=n type option 
506
507 int
508 fgOPTIONS::parse_tile_radius( const string& arg ) {
509     int radius = atoi( arg );
510
511     if ( radius < FG_RADIUS_MIN ) { radius = FG_RADIUS_MIN; }
512     if ( radius > FG_RADIUS_MAX ) { radius = FG_RADIUS_MAX; }
513
514     // printf("parse_tile_radius(): radius = %d\n", radius);
515
516     return(radius);
517 }
518
519
520 // Parse --fdm=abcdefg type option 
521 int
522 fgOPTIONS::parse_fdm( const string& fm ) {
523     // cout << "fdm = " << fm << endl;
524
525     if ( fm == "balloon" ) {
526         return FGInterface::FG_BALLOONSIM;
527     } else if ( fm == "external" ) {
528         return FGInterface::FG_EXTERNAL;
529     } else if ( fm == "jsb" ) {
530         return FGInterface::FG_JSBSIM;
531     } else if ( (fm == "larcsim") || (fm == "LaRCsim") ) {
532         return FGInterface::FG_LARCSIM;
533     } else if ( fm == "magic" ) {
534         return FGInterface::FG_MAGICCARPET;
535     } else {
536         FG_LOG( FG_GENERAL, FG_ALERT, "Unknown fdm = " << fm );
537         exit(-1);
538     }
539
540     // we'll never get here, but it makes the compiler happy.
541     return -1;
542 }
543
544
545 // Parse --fov=x.xx type option 
546 double
547 fgOPTIONS::parse_fov( const string& arg ) {
548     double fov = atof(arg);
549
550     if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
551     if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
552
553     // printf("parse_fov(): result = %.4f\n", fov);
554
555     return(fov);
556 }
557
558
559 // Parse I/O channel option
560 //
561 // Format is "--protocol=medium,direction,hz,medium_options,..."
562 //
563 //   protocol = { native, nmea, garmin, fgfs, rul, pve, etc. }
564 //   medium = { serial, socket, file, etc. }
565 //   direction = { in, out, bi }
566 //   hz = number of times to process channel per second (floating
567 //        point values are ok.
568 //
569 // Serial example "--nmea=serial,dir,hz,device,baud" where
570 // 
571 //  device = OS device name of serial line to be open()'ed
572 //  baud = {300, 1200, 2400, ..., 230400}
573 //
574 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
575 // 
576 //  machine = machine name or ip address if client (leave empty if server)
577 //  port = port, leave empty to let system choose
578 //  style = tcp or udp
579 //
580 // File example "--garmin=file,dir,hz,filename" where
581 // 
582 //  filename = file system file name
583
584 bool 
585 fgOPTIONS::parse_channel( const string& type, const string& channel_str ) {
586     // cout << "Channel string = " << channel_str << endl;
587
588     channel_options_list.push_back( type + "," + channel_str );
589
590     return true;
591 }
592
593
594 // Parse --wp=ID[,alt]
595 bool fgOPTIONS::parse_wp( const string& arg ) {
596     string id, alt_str;
597     double alt = 0.0;
598
599     int pos = arg.find( "@" );
600     if ( pos != string::npos ) {
601         id = arg.substr( 0, pos );
602         alt_str = arg.substr( pos + 1 );
603         // cout << "id str = " << id << "  alt str = " << alt_str << endl;
604         alt = atof( alt_str.c_str() );
605         if ( units == FG_UNITS_FEET ) {
606             alt *= FEET_TO_METER;
607         }
608     } else {
609         id = arg;
610     }
611
612     FGAirport a;
613     if ( fgFindAirportID( id, &a ) ) {
614         SGWayPoint wp( a.longitude, a.latitude, alt, SGWayPoint::WGS84, id );
615         globals->get_route()->add_waypoint( wp );
616
617         return true;
618     } else {
619         return false;
620     }
621 }
622
623
624 // Parse a single option
625 int fgOPTIONS::parse_option( const string& arg ) {
626     // General Options
627     if ( (arg == "--help") || (arg == "-h") ) {
628         // help/usage request
629         return(FG_OPTIONS_HELP);
630     } else if ( arg == "--disable-game-mode") {
631         game_mode = false;
632     } else if ( arg == "--enable-game-mode" ) {
633         game_mode = true;
634     } else if ( arg == "--disable-splash-screen" ) {
635         splash_screen = false;
636     } else if ( arg == "--enable-splash-screen" ) {
637         splash_screen = true;
638     } else if ( arg == "--disable-intro-music" ) {
639         intro_music = false;
640     } else if ( arg == "--enable-intro-music" ) {
641         intro_music = true;
642     } else if ( arg == "--disable-mouse-pointer" ) {
643         mouse_pointer = 1;
644     } else if ( arg == "--enable-mouse-pointer" ) {
645         mouse_pointer = 2;
646     } else if ( arg == "--disable-freeze" ) {
647         globals->set_freeze( false );
648     } else if ( arg == "--enable-freeze" ) {
649         globals->set_freeze( true );
650     } else if ( arg == "--disable-anti-alias-hud" ) {
651         anti_alias_hud = false; 
652     } else if ( arg == "--enable-anti-alias-hud" ) {
653         anti_alias_hud = true;  
654     } else if ( arg.find( "--control=") != string::npos ) {
655         parse_control( arg.substr(10) );
656     } else if ( arg == "--disable-auto-coordination" ) {
657         auto_coordination = FG_AUTO_COORD_DISABLED;     
658     } else if ( arg == "--enable-auto-coordination" ) {
659         auto_coordination = FG_AUTO_COORD_ENABLED;      
660     } else if ( arg == "--disable-hud" ) {
661         hud_status = false;     
662     } else if ( arg == "--enable-hud" ) {
663         hud_status = true;      
664     } else if ( arg == "--disable-panel" ) {
665         panel_status = false;
666         if ( current_panel != NULL )
667           current_panel->setVisibility(false);
668     } else if ( arg == "--enable-panel" ) {
669         panel_status = true;
670         if ( current_panel != NULL )
671             current_panel->setVisibility(true);
672         // fov *= 0.4232; /* NO!!! */
673     } else if ( arg == "--disable-sound" ) {
674         sound = false;
675     } else if ( arg == "--enable-sound" ) {
676         sound = true;
677     } else if ( arg.find( "--airport-id=") != string::npos ) {
678         airport_id = arg.substr( 13 );
679         current_properties.setStringValue("/position/airport-id", airport_id);
680     } else if ( arg.find( "--lon=" ) != string::npos ) {
681         lon = parse_degree( arg.substr(6) );
682         airport_id = "";
683         current_properties.setDoubleValue("/position/longitude", lon);
684         current_properties.setStringValue("/position/airport-id", airport_id);
685     } else if ( arg.find( "--lat=" ) != string::npos ) {
686         lat = parse_degree( arg.substr(6) );
687         airport_id = "";
688         current_properties.setDoubleValue("/position/latitude", lat);
689         current_properties.setStringValue("/position/airport-id", airport_id);
690     } else if ( arg.find( "--altitude=" ) != string::npos ) {
691         if ( units == FG_UNITS_FEET ) {
692             altitude = atof( arg.substr(11) ) * FEET_TO_METER;
693         } else {
694             altitude = atof( arg.substr(11) );
695         }
696         current_properties.setDoubleValue("/position/altitude", altitude);
697     } else if ( arg.find( "--uBody=" ) != string::npos ) {
698         vkcas=mach=-1;
699         if ( units == FG_UNITS_FEET ) {
700             uBody = atof( arg.substr(8) );
701         } else {
702             uBody = atof( arg.substr(8) ) * FEET_TO_METER;
703         }
704         current_properties.setDoubleValue("/velocities/speed-north", uBody);
705     } else if ( arg.find( "--vBody=" ) != string::npos ) {
706         vkcas=mach=-1;
707         if ( units == FG_UNITS_FEET ) {
708             vBody = atof( arg.substr(8) );
709         } else {
710             vBody = atof( arg.substr(8) ) * FEET_TO_METER;
711         }
712         current_properties.setDoubleValue("/velocities/speed-east", vBody);
713     } else if ( arg.find( "--wBody=" ) != string::npos ) {
714         vkcas=mach=-1;
715         if ( units == FG_UNITS_FEET ) {
716             wBody = atof( arg.substr(8) );
717         } else {
718             wBody = atof( arg.substr(8) ) * FEET_TO_METER;
719         }
720         current_properties.setDoubleValue("/velocities/speed-down", wBody);
721     } else if ( arg.find( "--vc=" ) != string::npos) {
722         mach=-1;
723         vkcas=atof( arg.substr(5) );
724         cout << "Got vc: " << vkcas << endl;
725     } else if ( arg.find( "--mach=" ) != string::npos) {
726         vkcas=-1;
727         mach=atof( arg.substr(7) );
728     } else if ( arg.find( "--heading=" ) != string::npos ) {
729         heading = atof( arg.substr(10) );
730         current_properties.setDoubleValue("/orientation/heading", heading);
731     } else if ( arg.find( "--roll=" ) != string::npos ) {
732         roll = atof( arg.substr(7) );
733         current_properties.setDoubleValue("/orientation/roll", roll);
734     } else if ( arg.find( "--pitch=" ) != string::npos ) {
735         pitch = atof( arg.substr(8) );
736         current_properties.setDoubleValue("/orientation/pitch", pitch);
737     } else if ( arg.find( "--fg-root=" ) != string::npos ) {
738         fg_root = arg.substr( 10 );
739     } else if ( arg.find( "--fg-scenery=" ) != string::npos ) {
740         fg_scenery = arg.substr( 13 );
741     } else if ( arg.find( "--fdm=" ) != string::npos ) {
742         flight_model = parse_fdm( arg.substr(6) );
743         current_properties.setIntValue("/sim/flight-model", flight_model);
744     if((flight_model == FGInterface::FG_JSBSIM) && (get_trim_mode() == 0)) {
745         set_trim_mode(1);
746     } else {
747         set_trim_mode(0);
748     }        
749     } else if ( arg.find( "--aircraft=" ) != string::npos ) {
750         aircraft = arg.substr(11);
751         current_properties.setStringValue("/sim/aircraft", aircraft);
752     } else if ( arg.find( "--aircraft-dir=" ) != string::npos ) {
753         aircraft_dir =  arg.substr(15); //  (UIUC)
754     } else if ( arg.find( "--model-hz=" ) != string::npos ) {
755         model_hz = atoi( arg.substr(11) );
756     } else if ( arg.find( "--speed=" ) != string::npos ) {
757         speed_up = atoi( arg.substr(8) );
758     } else if ( arg.find( "--notrim") != string::npos) {
759         trim=-1;
760     } else if ( arg == "--fog-disable" ) {
761         fog = FG_FOG_DISABLED;  
762     } else if ( arg == "--fog-fastest" ) {
763         fog = FG_FOG_FASTEST;   
764     } else if ( arg == "--fog-nicest" ) {
765         fog = FG_FOG_NICEST;    
766     } else if ( arg == "--disable-clouds" ) {
767         clouds = false; 
768     } else if ( arg == "--enable-clouds" ) {
769         clouds = true;  
770     } else if ( arg.find( "--clouds-asl=" ) != string::npos ) {
771         if ( units == FG_UNITS_FEET ) {
772             clouds_asl = atof( arg.substr(13) ) * FEET_TO_METER;
773         } else {
774             clouds_asl = atof( arg.substr(13) );
775         }
776     } else if ( arg.find( "--fov=" ) != string::npos ) {
777         fov = parse_fov( arg.substr(6) );
778     } else if ( arg == "--disable-fullscreen" ) {
779         fullscreen = false;     
780     } else if ( arg== "--enable-fullscreen") {
781         fullscreen = true;      
782     } else if ( arg == "--shading-flat") {
783         shading = 0;    
784     } else if ( arg == "--shading-smooth") {
785         shading = 1;    
786     } else if ( arg == "--disable-skyblend") {
787         skyblend = false;       
788     } else if ( arg== "--enable-skyblend" ) {
789         skyblend = true;        
790     } else if ( arg == "--disable-textures" ) {
791         textures = false;       
792     } else if ( arg == "--enable-textures" ) {
793         textures = true;
794     } else if ( arg == "--disable-wireframe" ) {
795         wireframe = false;      
796     } else if ( arg == "--enable-wireframe" ) {
797         wireframe = true;
798     } else if ( arg.find( "--geometry=" ) != string::npos ) {
799         bool geometry_ok = true;
800         string geometry = arg.substr( 11 );
801         string::size_type i = geometry.find('x');
802
803         if (i != string::npos) {
804             xsize = atoi(geometry.substr(0, i));
805             ysize = atoi(geometry.substr(i+1));
806             // cout << "Geometry is " << xsize << 'x' << ysize << '\n';
807         } else {
808             geometry_ok = false;
809         }
810
811         if ( xsize <= 0 || ysize <= 0 ) {
812             xsize = 640;
813             ysize = 480;
814             geometry_ok = false;
815         }
816
817         if ( !geometry_ok ) {
818             FG_LOG( FG_GENERAL, FG_ALERT, "Unknown geometry: " << geometry );
819             FG_LOG( FG_GENERAL, FG_ALERT,
820                     "Setting geometry to " << xsize << 'x' << ysize << '\n');
821         }
822     } else if ( arg.find( "--bpp=" ) != string::npos ) {
823         string bits_per_pix = arg.substr( 6 );
824         if ( bits_per_pix == "16" ) {
825             bpp = 16;
826         } else if ( bits_per_pix == "24" ) {
827             bpp = 24;
828         } else if ( bits_per_pix == "32" ) {
829             bpp = 32;
830         }
831     } else if ( arg == "--units-feet" ) {
832         units = FG_UNITS_FEET;  
833     } else if ( arg == "--units-meters" ) {
834         units = FG_UNITS_METERS;        
835     } else if ( arg.find( "--tile-radius=" ) != string::npos ) {
836         tile_radius = parse_tile_radius( arg.substr(14) );
837         tile_diameter = tile_radius * 2 + 1;
838     } else if ( arg.find( "--time-offset" ) != string::npos ) {
839         time_offset = parse_time_offset( (arg.substr(14)) );
840         //time_offset_type = FG_TIME_SYS_OFFSET;
841     } else if ( arg.find( "--time-match-real") != string::npos ) {
842       //time_offset = parse_time_offset(arg.substr(18));
843         time_offset_type = FG_TIME_SYS_OFFSET;
844     } else if ( arg.find( "--time-match-local") != string::npos ) {
845       //time_offset = parse_time_offset(arg.substr(18));
846         time_offset_type = FG_TIME_LAT_OFFSET;
847     } else if ( arg.find( "--start-date-sys=") != string::npos ) {
848         time_offset = parse_date( (arg.substr(17)) );
849         time_offset_type = FG_TIME_SYS_ABSOLUTE;
850     } else if ( arg.find( "--start-date-lat=") != string::npos ) {
851         time_offset = parse_date( (arg.substr(17)) );
852         time_offset_type = FG_TIME_LAT_ABSOLUTE;
853     } else if ( arg.find( "--start-date-gmt=") != string::npos ) {
854         time_offset = parse_date( (arg.substr(17)) );
855         time_offset_type = FG_TIME_GMT_ABSOLUTE;
856
857     } else if ( arg == "--hud-tris" ) {
858         tris_or_culled = 0;     
859     } else if ( arg == "--hud-culled" ) {
860         tris_or_culled = 1;
861     } else if ( arg.find( "--native=" ) != string::npos ) {
862         parse_channel( "native", arg.substr(9) );
863     } else if ( arg.find( "--garmin=" ) != string::npos ) {
864         parse_channel( "garmin", arg.substr(9) );
865     } else if ( arg.find( "--nmea=" ) != string::npos ) {
866         parse_channel( "nmea", arg.substr(7) );
867     } else if ( arg.find( "--props=" ) != string::npos ) {
868         parse_channel( "props", arg.substr(8) );
869     } else if ( arg.find( "--pve=" ) != string::npos ) {
870         parse_channel( "pve", arg.substr(6) );
871     } else if ( arg.find( "--ray=" ) != string::npos ) {
872         parse_channel( "ray", arg.substr(6) );
873     } else if ( arg.find( "--rul=" ) != string::npos ) {
874         parse_channel( "rul", arg.substr(6) );
875     } else if ( arg.find( "--joyclient=" ) != string::npos ) {
876         parse_channel( "joyclient", arg.substr(12) );
877 #ifdef FG_NETWORK_OLK
878     } else if ( arg == "--disable-network-olk" ) {
879         network_olk = false;    
880     } else if ( arg== "--enable-network-olk") {
881         network_olk = true;     
882     } else if ( arg == "--net-hud" ) {
883         net_hud_display = 1;    
884     } else if ( arg.find( "--net-id=") != string::npos ) {
885         net_id = arg.substr( 9 );
886 #endif
887     } else if ( arg.find( "--prop:" ) == 0 ) {
888         string assign = arg.substr(7);
889         int pos = assign.find('=');
890         if (pos == arg.npos || pos == 0) {
891             FG_LOG(FG_GENERAL, FG_ALERT, "Bad property assignment: " << arg);
892             return FG_OPTIONS_ERROR;
893         }
894         string name = assign.substr(0, pos);
895         string value = assign.substr(pos + 1);
896         current_properties.setStringValue(name.c_str(), value);
897         FG_LOG(FG_GENERAL, FG_INFO, "Setting default value of property "
898                << name << " to \"" << value << '"');
899     } else if ( arg.find( "--wp=" ) != string::npos ) {
900         parse_wp( arg.substr( 5 ) );
901     } else {
902         FG_LOG( FG_GENERAL, FG_ALERT, "Unknown option '" << arg << "'" );
903         return FG_OPTIONS_ERROR;
904     }
905     
906     return FG_OPTIONS_OK;
907 }
908
909
910 // Scan the command line options for an fg_root definition and set
911 // just that.
912 int fgOPTIONS::scan_command_line_for_root( int argc, char **argv ) {
913     int i = 1;
914     int result;
915
916     FG_LOG(FG_GENERAL, FG_INFO, "Processing command line arguments");
917
918     while ( i < argc ) {
919         FG_LOG( FG_GENERAL, FG_DEBUG, "argv[" << i << "] = " << argv[i] );
920
921         string arg = argv[i];
922         if ( arg.find( "--fg-root=" ) != string::npos ) {
923             fg_root = arg.substr( 10 );
924         }
925
926         i++;
927     }
928     
929     return FG_OPTIONS_OK;
930 }
931
932
933 // Scan the config file for an fg_root definition and set just that.
934 int fgOPTIONS::scan_config_file_for_root( const string& path ) {
935     fg_gzifstream in( path );
936     if ( !in.is_open() )
937         return(FG_OPTIONS_ERROR);
938
939     FG_LOG( FG_GENERAL, FG_INFO, "Processing config file: " << path );
940
941     in >> skipcomment;
942 #ifndef __MWERKS__
943     while ( ! in.eof() ) {
944 #else
945     char c = '\0';
946     while ( in.get(c) && c != '\0' ) {
947         in.putback(c);
948 #endif
949         string line;
950
951 #ifdef GETLINE_NEEDS_TERMINATOR
952         getline( in, line, '\n' );
953 #elif defined( macintosh )
954         getline( in, line, '\r' );
955 #else
956         getline( in, line );
957 #endif
958
959         if ( line.find( "--fg-root=" ) != string::npos ) {
960             fg_root = line.substr( 10 );
961         }
962
963         in >> skipcomment;
964     }
965
966     return FG_OPTIONS_OK;
967 }
968
969
970 // Parse the command line options
971 int fgOPTIONS::parse_command_line( int argc, char **argv ) {
972     int i = 1;
973     int result;
974
975     FG_LOG(FG_GENERAL, FG_INFO, "Processing command line arguments");
976
977     while ( i < argc ) {
978         FG_LOG( FG_GENERAL, FG_DEBUG, "argv[" << i << "] = " << argv[i] );
979
980         result = parse_option(argv[i]);
981         if ( (result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR) ) {
982             return(result);
983         }
984
985         i++;
986     }
987     
988     return FG_OPTIONS_OK;
989 }
990
991
992 // Parse config file options
993 int fgOPTIONS::parse_config_file( const string& path ) {
994     fg_gzifstream in( path );
995     if ( !in.is_open() )
996         return(FG_OPTIONS_ERROR);
997
998     FG_LOG( FG_GENERAL, FG_INFO, "Processing config file: " << path );
999
1000     in >> skipcomment;
1001 #ifndef __MWERKS__
1002     while ( ! in.eof() ) {
1003 #else
1004     char c = '\0';
1005     while ( in.get(c) && c != '\0' ) {
1006         in.putback(c);
1007 #endif
1008         string line;
1009
1010 #ifdef GETLINE_NEEDS_TERMINATOR
1011         getline( in, line, '\n' );
1012 #elif defined( macintosh )
1013         getline( in, line, '\r' );
1014 #else
1015         getline( in, line );
1016 #endif
1017
1018         if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
1019             FG_LOG( FG_GENERAL, FG_ALERT, 
1020                     "Config file parse error: " << path << " '" 
1021                     << line << "'" );
1022             exit(-1);
1023         }
1024         in >> skipcomment;
1025     }
1026
1027     return FG_OPTIONS_OK;
1028 }
1029
1030
1031 // Print usage message
1032 void fgOPTIONS::usage ( void ) {
1033     cout << "Usage: fg [ options ... ]" << endl;
1034     cout << endl;
1035
1036     cout << "General Options:" << endl;
1037     cout << "\t--help -h:  print usage" << endl;
1038     cout << "\t--fg-root=path:  specify the root path for all the data files"
1039          << endl;
1040     cout << "\t--fg-scenery=path:  specify the base path for all the scenery"
1041          << " data." << endl
1042          << "\t\tdefaults to $FG_ROOT/Scenery" << endl;
1043     cout << "\t--disable-game-mode:  disable full-screen game mode" << endl;
1044     cout << "\t--enable-game-mode:  enable full-screen game mode" << endl;
1045     cout << "\t--disable-splash-screen:  disable splash screen" << endl;
1046     cout << "\t--enable-splash-screen:  enable splash screen" << endl;
1047     cout << "\t--disable-intro-music:  disable introduction music" << endl;
1048     cout << "\t--enable-intro-music:  enable introduction music" << endl;
1049     cout << "\t--disable-mouse-pointer:  disable extra mouse pointer" << endl;
1050     cout << "\t--enable-mouse-pointer:  enable extra mouse pointer (i.e. for"
1051          << endl;
1052     cout << "\t\tfull screen voodoo/voodoo-II based cards.)" << endl;
1053     cout << "\t--disable-freeze:  start out in an running state" << endl;
1054     cout << "\t--enable-freeze:  start out in a frozen state" << endl;
1055     cout << "\t--control=mode:  primary control mode " 
1056          << "(joystick, keyboard, mouse)" << endl;
1057     cout << endl;
1058
1059     cout << "Features:" << endl;
1060     cout << "\t--disable-hud:  disable heads up display" << endl;
1061     cout << "\t--enable-hud:  enable heads up display" << endl;
1062     cout << "\t--disable-panel:  disable instrument panel" << endl;
1063     cout << "\t--enable-panel:  enable instrumetn panel" << endl;
1064     cout << "\t--disable-sound:  disable sound effects" << endl;
1065     cout << "\t--enable-sound:  enable sound effects" << endl;
1066     cout << "\t--disable-anti-alias-hud:  disable anti aliased hud" << endl;
1067     cout << "\t--enable-anti-alias-hud:  enable anti aliased hud" << endl;
1068     cout << endl;
1069  
1070     cout << "Flight Model:" << endl;
1071     cout << "\t--fdm=abcd:  selects the core flight model code." << endl;
1072     cout << "\t\tcan be one of jsb, larcsim, magic, or external" << endl;
1073     cout << "\t--aircraft=abcd:  aircraft model to load" << endl;
1074     cout << "\t--model-hz=n:  run the FDM this rate (iterations per second)" 
1075          << endl;
1076     cout << "\t--speed=n:  run the FDM this much faster than real time" << endl;
1077     cout << "\t--notrim:  Do NOT attempt to trim the model when initializing JSBsim" << endl;
1078     cout << endl;
1079     //(UIUC)
1080     cout <<"Aircraft model directory:" << endl;
1081     cout <<"\t--aircraft-dir=<path> path is relative to the path of the executable" << endl;
1082     cout << endl;
1083
1084     cout << "Initial Position and Orientation:" << endl;
1085     cout << "\t--airport-id=ABCD:  specify starting postion by airport id" 
1086          << endl;
1087     cout << "\t--lon=degrees:  starting longitude in degrees (west = -)" 
1088          << endl;
1089     cout << "\t--lat=degrees:  starting latitude in degrees (south = -)"
1090          << endl;
1091     cout << "\t--altitude=feet:  starting altitude in feet" << endl;
1092     cout << "\t\t(unless --units-meters specified" << endl;
1093     cout << "\t--heading=degrees:  heading (yaw) angle in degress (Psi)"
1094          << endl;
1095     cout << "\t--roll=degrees:  roll angle in degrees (Phi)" << endl;
1096     cout << "\t--pitch=degrees:  pitch angle in degrees (Theta)" << endl;
1097     cout << "\t--uBody=feet per second:  velocity along the body X axis"
1098          << endl;
1099     cout << "\t--vBody=feet per second:  velocity along the body Y axis"
1100          << endl;
1101     cout << "\t--wBody=feet per second:  velocity along the body Z axis"
1102          << endl;
1103     cout << "\t\t(unless --units-meters specified" << endl;
1104     cout << "\t--vc= initial airspeed in knots (--fdm=jsb only)" << endl;
1105     cout << "\t--mach= initial mach number (--fdm=jsb only)" << endl;
1106     cout << endl;
1107
1108     cout << "Rendering Options:" << endl;
1109     cout << "\t--fog-disable:  disable fog/haze" << endl;
1110     cout << "\t--fog-fastest:  enable fastest fog/haze" << endl;
1111     cout << "\t--fog-nicest:  enable nicest fog/haze" << endl;
1112     cout << "\t--enable-clouds:  enable demo cloud layer" << endl;
1113     cout << "\t--disable-clouds:  disable demo cloud layer" << endl;
1114     cout << "\t--clouds-asl=xxx:  specify altitude of cloud layer above sea level" << endl;
1115     cout << "\t--fov=xx.x:  specify initial field of view angle in degrees"
1116          << endl;
1117     cout << "\t--disable-fullscreen:  disable fullscreen mode" << endl;
1118     cout << "\t--enable-fullscreen:  enable fullscreen mode" << endl;
1119     cout << "\t--shading-flat:  enable flat shading" << endl;
1120     cout << "\t--shading-smooth:  enable smooth shading" << endl;
1121     cout << "\t--disable-skyblend:  disable sky blending" << endl;
1122     cout << "\t--enable-skyblend:  enable sky blending" << endl;
1123     cout << "\t--disable-textures:  disable textures" << endl;
1124     cout << "\t--enable-textures:  enable textures" << endl;
1125     cout << "\t--disable-wireframe:  disable wireframe drawing mode" << endl;
1126     cout << "\t--enable-wireframe:  enable wireframe drawing mode" << endl;
1127     cout << "\t--geometry=WWWxHHH:  window geometry: 640x480, 800x600, etc."
1128          << endl;
1129     cout << endl;
1130
1131     cout << "Scenery Options:" << endl;
1132     cout << "\t--tile-radius=n:  specify tile radius, must be 1 - 4" << endl;
1133     cout << endl;
1134
1135     cout << "Hud Options:" << endl;
1136     cout << "\t--units-feet:  Hud displays units in feet" << endl;
1137     cout << "\t--units-meters:  Hud displays units in meters" << endl;
1138     cout << "\t--hud-tris:  Hud displays number of triangles rendered" << endl;
1139     cout << "\t--hud-culled:  Hud displays percentage of triangles culled"
1140          << endl;
1141     cout << endl;
1142         
1143     cout << "Time Options:" << endl;
1144     cout << "\t--time-offset=[+-]hh:mm:ss: add this time offset" << endl;
1145     cout << "\t--time-match-real: Synchronize real-world and FlightGear" << endl
1146          << "\t\ttime. Can be used in combination with --time-offset." << endl;
1147     cout << "\t--time-match-local:Synchronize local real-world and " << endl
1148          << "\t\tFlightGear time" << endl;   
1149     cout << "\t--start-date-sys=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1150          << "\t\tdate/time. Uses your system time " << endl;
1151     cout << "\t--start-date-gmt=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1152          << "\t\tdate/time. Uses Greenwich Mean Time" << endl;
1153     cout << "\t--start-date-lat=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1154          << "\t\tdate/time. Uses Local Aircraft Time" << endl;
1155 #ifdef FG_NETWORK_OLK
1156     cout << endl;
1157
1158     cout << "Network Options:" << endl;
1159     cout << "\t--enable-network-olk:  enable Multipilot mode" << endl;
1160     cout << "\t--disable-network-olk:  disable Multipilot mode (default)" << endl;
1161     cout << "\t--net-hud:  Hud displays network info" << endl;
1162     cout << "\t--net-id=name:  specify your own callsign" << endl;
1163 #endif
1164
1165     cout << endl;
1166     cout << "Route/Way Point Options:" << endl;
1167     cout << "\t--wp=ID[@alt]:  specify a waypoint for the GC autopilot" << endl;
1168     cout << "\t\tYou can specify multiple waypoints (a route) with multiple"
1169          << endl;
1170     cout << "\t\tinstances of --wp=" << endl;
1171 }
1172
1173
1174 // Destructor
1175 fgOPTIONS::~fgOPTIONS( void ) {
1176 }