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