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