]> git.mxchange.org Git - flightgear.git/blob - src/Main/options.cxx
Moved sky code over to simgear.
[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
46 #include <Include/general.hxx>
47 #include <Cockpit/cockpit.hxx>
48 #include <FDM/flight.hxx>
49 #include <FDM/UIUCModel/uiuc_aircraftdir.h>
50 #ifdef FG_NETWORK_OLK
51 #  include <NetworkOLK/network.h>
52 #endif
53 #include <Time/fg_time.hxx>
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=FG_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     FGTime *t = FGTime::cur_time_params;
235     
236     int toggle_pause = t->getPause();
237     
238     if( !toggle_pause )
239         t->togglePauseMode();
240     
241     if( panel_status ) {
242         panel_status = false;
243         if ( current_panel != NULL )
244           current_panel->setVisibility(false);
245     } else {
246         panel_status = true;
247         if ( current_panel != NULL )
248           current_panel->setVisibility(true);
249     }
250     if ( panel_status ) {
251         fov *= 0.4232;
252     } else {
253         fov *= (1.0 / 0.4232);
254     }
255     // fgReshape( xsize, ysize);
256     fgReshape( current_view.get_winWidth(), current_view.get_winHeight() );
257
258     if( !toggle_pause )
259         t->togglePauseMode();
260 }
261
262 double
263 fgOPTIONS::parse_time(const string& time_in) {
264     char *time_str, num[256];
265     double hours, minutes, seconds;
266     double result = 0.0;
267     int sign = 1;
268     int i;
269
270     time_str = (char *)time_in.c_str();
271
272     // printf("parse_time(): %s\n", time_str);
273
274     // check for sign
275     if ( strlen(time_str) ) {
276         if ( time_str[0] == '+' ) {
277             sign = 1;
278             time_str++;
279         } else if ( time_str[0] == '-' ) {
280             sign = -1;
281             time_str++;
282         }
283     }
284     // printf("sign = %d\n", sign);
285
286     // get hours
287     if ( strlen(time_str) ) {
288         i = 0;
289         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
290             num[i] = time_str[0];
291             time_str++;
292             i++;
293         }
294         if ( time_str[0] == ':' ) {
295             time_str++;
296         }
297         num[i] = '\0';
298         hours = atof(num);
299         // printf("hours = %.2lf\n", hours);
300
301         result += hours;
302     }
303
304     // get minutes
305     if ( strlen(time_str) ) {
306         i = 0;
307         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
308             num[i] = time_str[0];
309             time_str++;
310             i++;
311         }
312         if ( time_str[0] == ':' ) {
313             time_str++;
314         }
315         num[i] = '\0';
316         minutes = atof(num);
317         // printf("minutes = %.2lf\n", minutes);
318
319         result += minutes / 60.0;
320     }
321
322     // get seconds
323     if ( strlen(time_str) ) {
324         i = 0;
325         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
326             num[i] = time_str[0];
327             time_str++;
328             i++;
329         }
330         num[i] = '\0';
331         seconds = atof(num);
332         // printf("seconds = %.2lf\n", seconds);
333
334         result += seconds / 3600.0;
335     }
336
337     return(sign * result);
338 }
339
340
341 long int fgOPTIONS::parse_date( const string& date)
342 {
343     struct tm gmt;
344     char * date_str, num[256];
345     int i;
346     // initialize to zero
347     gmt.tm_sec = 0;
348     gmt.tm_min = 0;
349     gmt.tm_hour = 0;
350     gmt.tm_mday = 0;
351     gmt.tm_mon = 0;
352     gmt.tm_year = 0;
353     gmt.tm_isdst = 0; // ignore daylight savings time for the moment
354     date_str = (char *)date.c_str();
355     // get year
356     if ( strlen(date_str) ) {
357         i = 0;
358         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
359             num[i] = date_str[0];
360             date_str++;
361             i++;
362         }
363         if ( date_str[0] == ':' ) {
364             date_str++;
365         }
366         num[i] = '\0';
367         gmt.tm_year = atoi(num) - 1900;
368     }
369     // get month
370     if ( strlen(date_str) ) {
371         i = 0;
372         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
373             num[i] = date_str[0];
374             date_str++;
375             i++;
376         }
377         if ( date_str[0] == ':' ) {
378             date_str++;
379         }
380         num[i] = '\0';
381         gmt.tm_mon = atoi(num) -1;
382     }
383     // get day
384     if ( strlen(date_str) ) {
385         i = 0;
386         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
387             num[i] = date_str[0];
388             date_str++;
389             i++;
390         }
391         if ( date_str[0] == ':' ) {
392             date_str++;
393         }
394         num[i] = '\0';
395         gmt.tm_mday = atoi(num);
396     }
397     // get hour
398     if ( strlen(date_str) ) {
399         i = 0;
400         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
401             num[i] = date_str[0];
402             date_str++;
403             i++;
404         }
405         if ( date_str[0] == ':' ) {
406             date_str++;
407         }
408         num[i] = '\0';
409         gmt.tm_hour = atoi(num);
410     }
411     // get minute
412     if ( strlen(date_str) ) {
413         i = 0;
414         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
415             num[i] = date_str[0];
416             date_str++;
417             i++;
418         }
419         if ( date_str[0] == ':' ) {
420             date_str++;
421         }
422         num[i] = '\0';
423         gmt.tm_min = atoi(num);
424     }
425     // get second
426     if ( strlen(date_str) ) {
427         i = 0;
428         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
429             num[i] = date_str[0];
430             date_str++;
431             i++;
432         }
433         if ( date_str[0] == ':' ) {
434             date_str++;
435         }
436         num[i] = '\0';
437         gmt.tm_sec = atoi(num);
438     }
439     time_t theTime = FGTime::cur_time_params->get_gmt(gmt.tm_year,
440                                                       gmt.tm_mon,
441                                                       gmt.tm_mday,
442                                                       gmt.tm_hour,
443                                                       gmt.tm_min,
444                                                       gmt.tm_sec);
445     //printf ("Date is %s\n", ctime(&theTime));
446     //printf ("in seconds that is %d\n", theTime);
447     //exit(1);
448     return (theTime);
449 }
450
451
452 // parse degree in the form of [+/-]hhh:mm:ss
453 void fgOPTIONS::parse_control( const string& mode ) {
454     if ( mode == "joystick" ) {
455         control_mode = FG_JOYSTICK;
456     } else if ( mode == "mouse" ) {
457         control_mode = FG_MOUSE;
458     } else {
459         control_mode = FG_KEYBOARD;
460     }
461 }
462
463
464 /// parse degree in the form of [+/-]hhh:mm:ss
465 double
466 fgOPTIONS::parse_degree( const string& degree_str) {
467     double result = parse_time( degree_str );
468
469     // printf("Degree = %.4f\n", result);
470
471     return(result);
472 }
473
474
475 // parse time offset command line option
476 int
477 fgOPTIONS::parse_time_offset( const string& time_str) {
478     int result;
479
480     // printf("time offset = %s\n", time_str);
481
482 #ifdef HAVE_RINT
483     result = (int)rint(parse_time(time_str) * 3600.0);
484 #else
485     result = (int)(parse_time(time_str) * 3600.0);
486 #endif
487
488     // printf("parse_time_offset(): %d\n", result);
489
490     return( result );
491 }
492
493
494 // Parse --tile-diameter=n type option 
495
496 int
497 fgOPTIONS::parse_tile_radius( const string& arg ) {
498     int radius = atoi( arg );
499
500     if ( radius < FG_RADIUS_MIN ) { radius = FG_RADIUS_MIN; }
501     if ( radius > FG_RADIUS_MAX ) { radius = FG_RADIUS_MAX; }
502
503     // printf("parse_tile_radius(): radius = %d\n", radius);
504
505     return(radius);
506 }
507
508
509 // Parse --fdm=abcdefg type option 
510 int
511 fgOPTIONS::parse_fdm( const string& fm ) {
512     // cout << "fdm = " << fm << endl;
513
514     if ( fm == "balloon" ) {
515         return FGInterface::FG_BALLOONSIM;
516     } else if ( fm == "external" ) {
517         return FGInterface::FG_EXTERNAL;
518     } else if ( fm == "jsb" ) {
519         return FGInterface::FG_JSBSIM;
520     } else if ( (fm == "larcsim") || (fm == "LaRCsim") ) {
521         return FGInterface::FG_LARCSIM;
522     } else if ( fm == "magic" ) {
523         return FGInterface::FG_MAGICCARPET;
524     } else {
525         FG_LOG( FG_GENERAL, FG_ALERT, "Unknown fdm = " << fm );
526         exit(-1);
527     }
528
529     // we'll never get here, but it makes the compiler happy.
530     return -1;
531 }
532
533
534 // Parse --fov=x.xx type option 
535 double
536 fgOPTIONS::parse_fov( const string& arg ) {
537     double fov = atof(arg);
538
539     if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
540     if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
541
542     // printf("parse_fov(): result = %.4f\n", fov);
543
544     return(fov);
545 }
546
547
548 // Parse I/O channel option
549 //
550 // Format is "--protocol=medium,direction,hz,medium_options,..."
551 //
552 //   protocol = { native, nmea, garmin, fgfs, rul, pve, etc. }
553 //   medium = { serial, socket, file, etc. }
554 //   direction = { in, out, bi }
555 //   hz = number of times to process channel per second (floating
556 //        point values are ok.
557 //
558 // Serial example "--nmea=serial,dir,hz,device,baud" where
559 // 
560 //  device = OS device name of serial line to be open()'ed
561 //  baud = {300, 1200, 2400, ..., 230400}
562 //
563 // Socket exacmple "--native=socket,dir,hz,machine,port" where
564 // 
565 //  machine = machine name or ip address if client (leave empty if server)
566 //  port = port, leave empty to let system choose
567 //
568 // File example "--garmin=file,dir,hz,filename" where
569 // 
570 //  filename = file system file name
571
572 bool 
573 fgOPTIONS::parse_channel( const string& type, const string& channel_str ) {
574     // cout << "Channel string = " << channel_str << endl;
575
576     channel_options_list.push_back( type + "," + channel_str );
577
578     return true;
579 }
580
581
582 // Parse a single option
583 int fgOPTIONS::parse_option( const string& arg ) {
584     // General Options
585     if ( (arg == "--help") || (arg == "-h") ) {
586         // help/usage request
587         return(FG_OPTIONS_HELP);
588     } else if ( arg == "--disable-game-mode") {
589         game_mode = false;
590     } else if ( arg == "--enable-game-mode" ) {
591         game_mode = true;
592     } else if ( arg == "--disable-splash-screen" ) {
593         splash_screen = false;
594     } else if ( arg == "--enable-splash-screen" ) {
595         splash_screen = true;
596     } else if ( arg == "--disable-intro-music" ) {
597         intro_music = false;
598     } else if ( arg == "--enable-intro-music" ) {
599         intro_music = true;
600     } else if ( arg == "--disable-mouse-pointer" ) {
601         mouse_pointer = 1;
602     } else if ( arg == "--enable-mouse-pointer" ) {
603         mouse_pointer = 2;
604     } else if ( arg == "--disable-pause" ) {
605         pause = false;  
606     } else if ( arg == "--enable-pause" ) {
607         pause = true;   
608     } else if ( arg == "--disable-anti-alias-hud" ) {
609         anti_alias_hud = false; 
610     } else if ( arg == "--enable-anti-alias-hud" ) {
611         anti_alias_hud = true;  
612     } else if ( arg.find( "--control=") != string::npos ) {
613         parse_control( arg.substr(10) );
614     } else if ( arg == "--disable-auto-coordination" ) {
615         auto_coordination = FG_AUTO_COORD_DISABLED;     
616     } else if ( arg == "--enable-auto-coordination" ) {
617         auto_coordination = FG_AUTO_COORD_ENABLED;      
618     } else if ( arg == "--disable-hud" ) {
619         hud_status = false;     
620     } else if ( arg == "--enable-hud" ) {
621         hud_status = true;      
622     } else if ( arg == "--disable-panel" ) {
623         panel_status = false;
624         if ( current_panel != NULL )
625           current_panel->setVisibility(false);
626     } else if ( arg == "--enable-panel" ) {
627         panel_status = true;
628         if ( current_panel != NULL )
629           current_panel->setVisibility(true);
630         fov *= 0.4232;
631     } else if ( arg == "--disable-sound" ) {
632         sound = false;
633     } else if ( arg == "--enable-sound" ) {
634         sound = true;
635     } else if ( arg.find( "--airport-id=") != string::npos ) {
636         airport_id = arg.substr( 13 );
637     } else if ( arg.find( "--lon=" ) != string::npos ) {
638         lon = parse_degree( arg.substr(6) );
639     } else if ( arg.find( "--lat=" ) != string::npos ) {
640         lat = parse_degree( arg.substr(6) );
641     } else if ( arg.find( "--altitude=" ) != string::npos ) {
642         if ( units == FG_UNITS_FEET ) {
643             altitude = atof( arg.substr(11) ) * FEET_TO_METER;
644         } else {
645             altitude = atof( arg.substr(11) );
646         }
647     } else if ( arg.find( "--uBody=" ) != string::npos ) {
648         vkcas=mach=-1;
649         if ( units == FG_UNITS_FEET ) {
650             uBody = atof( arg.substr(8) );
651         } else {
652             uBody = atof( arg.substr(8) ) * FEET_TO_METER;
653         }
654     } else if ( arg.find( "--vBody=" ) != string::npos ) {
655         vkcas=mach=-1;
656         if ( units == FG_UNITS_FEET ) {
657             vBody = atof( arg.substr(8) );
658         } else {
659             vBody = atof( arg.substr(8) ) * FEET_TO_METER;
660         }
661     } else if ( arg.find( "--wBody=" ) != string::npos ) {
662         vkcas=mach=-1;
663         if ( units == FG_UNITS_FEET ) {
664             wBody = atof( arg.substr(8) );
665         } else {
666             wBody = atof( arg.substr(8) ) * FEET_TO_METER;
667         }
668     } else if ( arg.find( "--vc=" ) != string::npos) {
669         mach=-1;
670         vkcas=atof( arg.substr(5) );
671         cout << "Got vc: " << vkcas << endl;
672     } else if ( arg.find( "--mach=" ) != string::npos) {
673         vkcas=-1;
674         mach=atof( arg.substr(7) );
675     } else if ( arg.find( "--heading=" ) != string::npos ) {
676         heading = atof( arg.substr(10) );
677     } else if ( arg.find( "--roll=" ) != string::npos ) {
678         roll = atof( arg.substr(7) );
679     } else if ( arg.find( "--pitch=" ) != string::npos ) {
680         pitch = atof( arg.substr(8) );
681     } else if ( arg.find( "--fg-root=" ) != string::npos ) {
682         fg_root = arg.substr( 10 );
683     } else if ( arg.find( "--fdm=" ) != string::npos ) {
684         flight_model = parse_fdm( arg.substr(6) );
685     if((flight_model == FGInterface::FG_JSBSIM) && (get_trim_mode() == 0)) {
686         set_trim_mode(1);
687     } else {
688         set_trim_mode(0);
689     }        
690     } else if ( arg.find( "--aircraft=" ) != string::npos ) {
691         aircraft = arg.substr(11);
692     } else if ( arg.find( "--aircraft-dir=" ) != string::npos ) {
693         aircraft_dir =  arg.substr(15); //  (UIUC)
694     } else if ( arg.find( "--model-hz=" ) != string::npos ) {
695         model_hz = atoi( arg.substr(11) );
696     } else if ( arg.find( "--speed=" ) != string::npos ) {
697         speed_up = atoi( arg.substr(8) );
698     } else if ( arg.find( "--notrim") != string::npos) {
699         trim=-1;
700     } else if ( arg == "--fog-disable" ) {
701         fog = FG_FOG_DISABLED;  
702     } else if ( arg == "--fog-fastest" ) {
703         fog = FG_FOG_FASTEST;   
704     } else if ( arg == "--fog-nicest" ) {
705         fog = FG_FOG_NICEST;    
706     } else if ( arg == "--disable-clouds" ) {
707         clouds = false; 
708     } else if ( arg == "--enable-clouds" ) {
709         clouds = true;  
710     } else if ( arg.find( "--clouds-asl=" ) != string::npos ) {
711         if ( units == FG_UNITS_FEET ) {
712             clouds_asl = atof( arg.substr(13) ) * FEET_TO_METER;
713         } else {
714             clouds_asl = atof( arg.substr(13) );
715         }
716     } else if ( arg.find( "--fov=" ) != string::npos ) {
717         fov = parse_fov( arg.substr(6) );
718     } else if ( arg == "--disable-fullscreen" ) {
719         fullscreen = false;     
720     } else if ( arg== "--enable-fullscreen") {
721         fullscreen = true;      
722     } else if ( arg == "--shading-flat") {
723         shading = 0;    
724     } else if ( arg == "--shading-smooth") {
725         shading = 1;    
726     } else if ( arg == "--disable-skyblend") {
727         skyblend = false;       
728     } else if ( arg== "--enable-skyblend" ) {
729         skyblend = true;        
730     } else if ( arg == "--disable-textures" ) {
731         textures = false;       
732     } else if ( arg == "--enable-textures" ) {
733         textures = true;
734     } else if ( arg == "--disable-wireframe" ) {
735         wireframe = false;      
736     } else if ( arg == "--enable-wireframe" ) {
737         wireframe = true;
738     } else if ( arg.find( "--geometry=" ) != string::npos ) {
739         bool geometry_ok = true;
740         string geometry = arg.substr( 11 );
741         string::size_type i = geometry.find('x');
742
743         if (i != string::npos) {
744             xsize = atoi(geometry.substr(0, i));
745             ysize = atoi(geometry.substr(i+1));
746             // cout << "Geometry is " << xsize << 'x' << ysize << '\n';
747         } else {
748             geometry_ok = false;
749         }
750
751         if ( xsize <= 0 || ysize <= 0 ) {
752             xsize = 640;
753             ysize = 480;
754             geometry_ok = false;
755         }
756
757         if ( !geometry_ok ) {
758             FG_LOG( FG_GENERAL, FG_ALERT, "Unknown geometry: " << geometry );
759             FG_LOG( FG_GENERAL, FG_ALERT,
760                     "Setting geometry to " << xsize << 'x' << ysize << '\n');
761         }
762     } else if ( arg.find( "--bpp=" ) != string::npos ) {
763         string bits_per_pix = arg.substr( 6 );
764         if ( bits_per_pix == "16" ) {
765             bpp = 16;
766         } else if ( bits_per_pix == "24" ) {
767             bpp = 24;
768         } else if ( bits_per_pix == "32" ) {
769             bpp = 32;
770         }
771     } else if ( arg == "--units-feet" ) {
772         units = FG_UNITS_FEET;  
773     } else if ( arg == "--units-meters" ) {
774         units = FG_UNITS_METERS;        
775     } else if ( arg.find( "--tile-radius=" ) != string::npos ) {
776         tile_radius = parse_tile_radius( arg.substr(14) );
777         tile_diameter = tile_radius * 2 + 1;
778     } else if ( arg.find( "--time-offset" ) != string::npos ) {
779         time_offset = parse_time_offset( (arg.substr(14)) );
780         //time_offset_type = FG_TIME_SYS_OFFSET;
781     } else if ( arg.find( "--time-match-real") != string::npos ) {
782       //time_offset = parse_time_offset(arg.substr(18));
783         time_offset_type = FG_TIME_SYS_OFFSET;
784     } else if ( arg.find( "--time-match-local") != string::npos ) {
785       //time_offset = parse_time_offset(arg.substr(18));
786         time_offset_type = FG_TIME_LAT_OFFSET;
787     } else if ( arg.find( "--start-date-sys=") != string::npos ) {
788         time_offset = parse_date( (arg.substr(17)) );
789         time_offset_type = FG_TIME_SYS_ABSOLUTE;
790     } else if ( arg.find( "--start-date-lat=") != string::npos ) {
791         time_offset = parse_date( (arg.substr(17)) );
792         time_offset_type = FG_TIME_LAT_ABSOLUTE;
793     } else if ( arg.find( "--start-date-gmt=") != string::npos ) {
794         time_offset = parse_date( (arg.substr(17)) );
795         time_offset_type = FG_TIME_GMT_ABSOLUTE;
796
797     } else if ( arg == "--hud-tris" ) {
798         tris_or_culled = 0;     
799     } else if ( arg == "--hud-culled" ) {
800         tris_or_culled = 1;
801     } else if ( arg.find( "--native=" ) != string::npos ) {
802         parse_channel( "native", arg.substr(9) );
803     } else if ( arg.find( "--garmin=" ) != string::npos ) {
804         parse_channel( "garmin", arg.substr(9) );
805     } else if ( arg.find( "--nmea=" ) != string::npos ) {
806         parse_channel( "nmea", arg.substr(7) );
807     } else if ( arg.find( "--pve=" ) != string::npos ) {
808         parse_channel( "pve", arg.substr(6) );
809     } else if ( arg.find( "--ray=" ) != string::npos ) {
810         parse_channel( "ray", arg.substr(6) );
811     } else if ( arg.find( "--rul=" ) != string::npos ) {
812         parse_channel( "rul", arg.substr(6) );
813     } else if ( arg.find( "--joyclient=" ) != string::npos ) {
814         parse_channel( "joyclient", arg.substr(12) );
815 #ifdef FG_NETWORK_OLK
816     } else if ( arg == "--disable-network-olk" ) {
817         network_olk = false;    
818     } else if ( arg== "--enable-network-olk") {
819         network_olk = true;     
820     } else if ( arg == "--net-hud" ) {
821         net_hud_display = 1;    
822     } else if ( arg.find( "--net-id=") != string::npos ) {
823         net_id = arg.substr( 9 );
824 #endif
825     } else if ( arg.find( "--prop:" ) == 0 ) {
826         string assign = arg.substr(7);
827         int pos = assign.find('=');
828         if (pos == arg.npos || pos == 0) {
829             FG_LOG(FG_GENERAL, FG_ALERT, "Bad property assignment: " << arg);
830             return FG_OPTIONS_ERROR;
831         }
832         string name = assign.substr(0, pos);
833         string value = assign.substr(pos + 1);
834         current_properties.setStringValue(name.c_str(), value);
835         FG_LOG(FG_GENERAL, FG_INFO, "Setting default value of property "
836                << name << " to \"" << value << '"');
837     } else {
838         FG_LOG( FG_GENERAL, FG_ALERT, "Unknown option '" << arg << "'" );
839         return FG_OPTIONS_ERROR;
840     }
841     
842     return FG_OPTIONS_OK;
843 }
844
845
846 // Parse the command line options
847 int fgOPTIONS::parse_command_line( int argc, char **argv ) {
848     int i = 1;
849     int result;
850
851     FG_LOG(FG_GENERAL, FG_INFO, "Processing command line arguments");
852
853     while ( i < argc ) {
854         FG_LOG( FG_GENERAL, FG_DEBUG, "argv[" << i << "] = " << argv[i] );
855
856         result = parse_option(argv[i]);
857         if ( (result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR) ) {
858             return(result);
859         }
860
861         i++;
862     }
863     
864     return(FG_OPTIONS_OK);
865 }
866
867
868 // Parse config file options
869 int fgOPTIONS::parse_config_file( const string& path ) {
870     fg_gzifstream in( path );
871     if ( !in.is_open() )
872         return(FG_OPTIONS_ERROR);
873
874     FG_LOG( FG_GENERAL, FG_INFO, "Processing config file: " << path );
875
876     in >> skipcomment;
877 #ifndef __MWERKS__
878     while ( ! in.eof() ) {
879 #else
880     char c = '\0';
881     while ( in.get(c) && c != '\0' ) {
882         in.putback(c);
883 #endif
884         string line;
885
886 #ifdef GETLINE_NEEDS_TERMINATOR
887         getline( in, line, '\n' );
888 #elif defined (MACOS)
889         getline( in, line, '\r' );
890 #else
891         getline( in, line );
892 #endif
893
894         if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
895             FG_LOG( FG_GENERAL, FG_ALERT, 
896                     "Config file parse error: " << path << " '" 
897                     << line << "'" );
898             exit(-1);
899         }
900         in >> skipcomment;
901     }
902
903     return FG_OPTIONS_OK;
904 }
905
906
907 // Print usage message
908 void fgOPTIONS::usage ( void ) {
909     cout << "Usage: fg [ options ... ]" << endl;
910     cout << endl;
911
912     cout << "General Options:" << endl;
913     cout << "\t--help -h:  print usage" << endl;
914     cout << "\t--fg-root=path:  specify the root path for all the data files"
915          << endl;
916     cout << "\t--disable-game-mode:  disable full-screen game mode" << endl;
917     cout << "\t--enable-game-mode:  enable full-screen game mode" << endl;
918     cout << "\t--disable-splash-screen:  disable splash screen" << endl;
919     cout << "\t--enable-splash-screen:  enable splash screen" << endl;
920     cout << "\t--disable-intro-music:  disable introduction music" << endl;
921     cout << "\t--enable-intro-music:  enable introduction music" << endl;
922     cout << "\t--disable-mouse-pointer:  disable extra mouse pointer" << endl;
923     cout << "\t--enable-mouse-pointer:  enable extra mouse pointer (i.e. for"
924          << endl;
925     cout << "\t\tfull screen voodoo/voodoo-II based cards.)" << endl;
926     cout << "\t--disable-pause:  start out in an active state" << endl;
927     cout << "\t--enable-pause:  start out in a paused state" << endl;
928     cout << "\t--control=mode:  primary control mode " 
929          << "(joystick, keyboard, mouse)" << endl;
930     cout << endl;
931
932     cout << "Features:" << endl;
933     cout << "\t--disable-hud:  disable heads up display" << endl;
934     cout << "\t--enable-hud:  enable heads up display" << endl;
935     cout << "\t--disable-panel:  disable instrument panel" << endl;
936     cout << "\t--enable-panel:  enable instrumetn panel" << endl;
937     cout << "\t--disable-sound:  disable sound effects" << endl;
938     cout << "\t--enable-sound:  enable sound effects" << endl;
939     cout << "\t--disable-anti-alias-hud:  disable anti aliased hud" << endl;
940     cout << "\t--enable-anti-alias-hud:  enable anti aliased hud" << endl;
941     cout << endl;
942  
943     cout << "Flight Model:" << endl;
944     cout << "\t--fdm=abcd:  selects the core flight model code." << endl;
945     cout << "\t\tcan be one of jsb, larcsim, magic, or external" << endl;
946     cout << "\t--aircraft=abcd:  aircraft model to load" << endl;
947     cout << "\t--model-hz=n:  run the FDM this rate (iterations per second)" 
948          << endl;
949     cout << "\t--speed=n:  run the FDM this much faster than real time" << endl;
950     cout << "\t--notrim:  Do NOT attempt to trim the model when initializing JSBsim" << endl;
951     cout << endl;
952     //(UIUC)
953     cout <<"Aircraft model directory" << endl;
954     cout <<"\t--aircraft-dir=<path> path is relative to the path of the executable" << endl;
955     cout << endl;
956
957     cout << "Initial Position and Orientation:" << endl;
958     cout << "\t--airport-id=ABCD:  specify starting postion by airport id" 
959          << endl;
960     cout << "\t--lon=degrees:  starting longitude in degrees (west = -)" 
961          << endl;
962     cout << "\t--lat=degrees:  starting latitude in degrees (south = -)"
963          << endl;
964     cout << "\t--altitude=feet:  starting altitude in feet" << endl;
965     cout << "\t\t(unless --units-meters specified" << endl;
966     cout << "\t--heading=degrees:  heading (yaw) angle in degress (Psi)"
967          << endl;
968     cout << "\t--roll=degrees:  roll angle in degrees (Phi)" << endl;
969     cout << "\t--pitch=degrees:  pitch angle in degrees (Theta)" << endl;
970     cout << "\t--uBody=feet per second:  velocity along the body X axis"
971          << endl;
972     cout << "\t--vBody=feet per second:  velocity along the body Y axis"
973          << endl;
974     cout << "\t--wBody=feet per second:  velocity along the body Z axis"
975          << endl;
976     cout << "\t\t(unless --units-meters specified" << endl;
977     cout << "\t--vc= initial airspeed in knots (--fdm=jsb only)" << endl;
978     cout << "\t--mach= initial mach number (--fdm=jsb only)" << endl;
979     cout << endl;
980
981     cout << "Rendering Options:" << endl;
982     cout << "\t--fog-disable:  disable fog/haze" << endl;
983     cout << "\t--fog-fastest:  enable fastest fog/haze" << endl;
984     cout << "\t--fog-nicest:  enable nicest fog/haze" << endl;
985     cout << "\t--enable-clouds:  enable demo cloud layer" << endl;
986     cout << "\t--disable-clouds:  disable demo cloud layer" << endl;
987     cout << "\t--clouds-asl=xxx:  specify altitude of cloud layer above sea level" << endl;
988     cout << "\t--fov=xx.x:  specify initial field of view angle in degrees"
989          << endl;
990     cout << "\t--disable-fullscreen:  disable fullscreen mode" << endl;
991     cout << "\t--enable-fullscreen:  enable fullscreen mode" << endl;
992     cout << "\t--shading-flat:  enable flat shading" << endl;
993     cout << "\t--shading-smooth:  enable smooth shading" << endl;
994     cout << "\t--disable-skyblend:  disable sky blending" << endl;
995     cout << "\t--enable-skyblend:  enable sky blending" << endl;
996     cout << "\t--disable-textures:  disable textures" << endl;
997     cout << "\t--enable-textures:  enable textures" << endl;
998     cout << "\t--disable-wireframe:  disable wireframe drawing mode" << endl;
999     cout << "\t--enable-wireframe:  enable wireframe drawing mode" << endl;
1000     cout << "\t--geometry=WWWxHHH:  window geometry: 640x480, 800x600, etc."
1001          << endl;
1002     cout << endl;
1003
1004     cout << "Scenery Options:" << endl;
1005     cout << "\t--tile-radius=n:  specify tile radius, must be 1 - 4" << endl;
1006     cout << endl;
1007
1008     cout << "Hud Options:" << endl;
1009     cout << "\t--units-feet:  Hud displays units in feet" << endl;
1010     cout << "\t--units-meters:  Hud displays units in meters" << endl;
1011     cout << "\t--hud-tris:  Hud displays number of triangles rendered" << endl;
1012     cout << "\t--hud-culled:  Hud displays percentage of triangles culled"
1013          << endl;
1014     cout << endl;
1015         
1016     cout << "Time Options:" << endl;
1017     cout << "\t--time-offset=[+-]hh:mm:ss: add this time offset" << endl;
1018     cout << "\t--time-match-real: Synchronize real-world and FlightGear" << endl
1019          << "\t\ttime. Can be used in combination with --time-offset." << endl;
1020     cout << "\t--time-match-local:Synchronize local real-world and " << endl
1021          << "\t\tFlightGear time" << endl;   
1022     cout << "\t--start-date-sys=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1023          << "\t\tdate/time. Uses your system time " << endl;
1024     cout << "\t--start-date-gmt=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1025          << "\t\tdate/time. Uses Greenwich Mean Time" << endl;
1026     cout << "\t--start-date-lat=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1027          << "\t\tdate/time. Uses Local Aircraft Time" << endl;
1028 #ifdef FG_NETWORK_OLK
1029     cout << "" << endl;
1030
1031     cout << "Network Options:" << endl;
1032     cout << "\t--net-hud:  Hud displays network info" << endl;
1033     cout << "\t--net-id=name:  specify your own callsign" << endl;
1034 #endif
1035 }
1036
1037
1038 // Destructor
1039 fgOPTIONS::~fgOPTIONS( void ) {
1040 }