]> git.mxchange.org Git - flightgear.git/blob - Main/options.cxx
Added "D" key binding to set autopilot heading.
[flightgear.git] / Main / options.cxx
1 //
2 // options.cxx -- class to handle command line options
3 //
4 // Written by Curtis Olson, started April 1998.
5 //
6 // Copyright (C) 1998  Curtis L. Olson  - curt@me.umn.edu
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 //
22 // $Id$
23 // (Log is kept at end of this file)
24
25
26 #ifdef HAVE_CONFIG_H
27 #  include <config.h>
28 #endif
29
30 #include <math.h>            // rint()
31 #include <stdio.h>
32 #include <stdlib.h>          // atof(), atoi()
33 #include <string.h>
34
35 #include <Debug/fg_debug.h>
36
37 #include "options.hxx"
38
39
40 // Defined the shared options class here
41 fgOPTIONS current_options;
42
43
44 // Constructor
45 fgOPTIONS::fgOPTIONS( void ) {
46     // set initial values/defaults
47
48     strcpy(airport_id, "");
49
50     // Features
51     hud_status = 0;
52
53     // Rendering options
54     fog = 1;
55     fullscreen = 0;
56     shading = 1;
57     skyblend = 1;
58     textures = 1;
59     wireframe = 0;
60
61     // Scenery options
62     tile_radius = 7;
63
64     // Time options
65     time_offset = 0;
66 }
67
68
69 // parse time string in the form of [+-]hh:mm:ss, returns the value in seconds
70 static double parse_time(char *time_str) {
71     char num[256];
72     double hours, minutes, seconds;
73     double result = 0.0;
74     int sign = 1;
75     int i;
76
77     // printf("parse_time(): %s\n", time_str);
78
79     // check for sign
80     if ( strlen(time_str) ) {
81         if ( time_str[0] == '+' ) {
82             sign = 1;
83             time_str++;
84         } else if ( time_str[0] == '-' ) {
85             sign = -1;
86             time_str++;
87         }
88     }
89     // printf("sign = %d\n", sign);
90
91     // get hours
92     if ( strlen(time_str) ) {
93         i = 0;
94         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
95             num[i] = time_str[0];
96             time_str++;
97             i++;
98         }
99         if ( time_str[0] == ':' ) {
100             time_str++;
101         }
102         num[i] = '\0';
103         hours = atof(num);
104         // printf("hours = %.2lf\n", hours);
105
106         result += hours * 3600.0;
107     }
108
109     // get minutes
110     if ( strlen(time_str) ) {
111         i = 0;
112         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
113             num[i] = time_str[0];
114             time_str++;
115             i++;
116         }
117         if ( time_str[0] == ':' ) {
118             time_str++;
119         }
120         num[i] = '\0';
121         minutes = atof(num);
122         // printf("minutes = %.2lf\n", minutes);
123
124         result += minutes * 60.0;
125     }
126
127     // get seconds
128     if ( strlen(time_str) ) {
129         i = 0;
130         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
131             num[i] = time_str[0];
132             time_str++;
133             i++;
134         }
135         num[i] = '\0';
136         seconds = atof(num);
137         // printf("seconds = %.2lf\n", seconds);
138
139         result += seconds;
140     }
141
142     return(sign * result);
143 }
144
145
146 // parse time offset command line option
147 static int parse_time_offset(char *time_str) {
148     int result;
149
150     time_str += 14;
151
152     // printf("time offset = %s\n", time_str);
153
154 #ifdef HAVE_RINT
155     result = (int)rint(parse_time(time_str));
156 #else
157     result = (int)parse_time(time_str);
158 #endif
159
160     printf("parse_time_offset(): %d\n", result);
161
162     return( result );
163 }
164
165
166 // Parse an int out of a --foo-bar=n type option 
167 static int parse_int(char *arg, int min, int max) {
168     int result;
169
170     // advance past the '='
171     while ( (arg[0] != '=') && (arg[0] != '\0') ) {
172         arg++;
173     }
174
175     if ( arg[0] == '=' ) {
176         arg++;
177     }
178
179     printf("parse_int(): arg = %s\n", arg);
180
181     result = atoi(arg);
182
183     if ( result < min ) { result = min; }
184     if ( result > max ) { result = max; }
185
186     printf("parse_int(): result = %d\n", result);
187     return(result);
188 }
189
190
191 // Parse the command line options
192 int fgOPTIONS::parse( int argc, char **argv ) {
193     int i = 1;
194
195     fgPrintf(FG_GENERAL, FG_INFO, "Processing arguments\n");
196
197     while ( i < argc ) {
198         fgPrintf(FG_GENERAL, FG_INFO, "argv[%d] = %s\n", i, argv[i]);
199
200         // General Options
201         if ( (strcmp(argv[i], "--help") == 0) ||
202              (strcmp(argv[i], "-h") == 0) ) {
203             // help/usage request
204             return(FG_OPTIONS_HELP);
205         } else if ( strcmp(argv[i], "--disable-hud") == 0 ) {
206             hud_status = 0;     
207         } else if ( strcmp(argv[i], "--enable-hud") == 0 ) {
208             hud_status = 1;     
209         } else if ( strncmp(argv[i], "--airport-id=", 13) == 0 ) {
210             argv[i] += 13;
211             strncpy(airport_id, argv[i], 4);
212         } else if ( strcmp(argv[i], "--disable-fog") == 0 ) {
213             fog = 0;    
214         } else if ( strcmp(argv[i], "--enable-fog") == 0 ) {
215             fog = 1;    
216         } else if ( strcmp(argv[i], "--disable-fullscreen") == 0 ) {
217             fullscreen = 0;     
218         } else if ( strcmp(argv[i], "--enable-fullscreen") == 0 ) {
219             fullscreen = 1;     
220         } else if ( strcmp(argv[i], "--shading-flat") == 0 ) {
221             shading = 0;        
222         } else if ( strcmp(argv[i], "--shading-smooth") == 0 ) {
223             shading = 1;        
224         } else if ( strcmp(argv[i], "--disable-skyblend") == 0 ) {
225             skyblend = 0;       
226         } else if ( strcmp(argv[i], "--enable-skyblend") == 0 ) {
227             skyblend = 1;       
228         } else if ( strcmp(argv[i], "--disable-textures") == 0 ) {
229             textures = 0;       
230         } else if ( strcmp(argv[i], "--enable-textures") == 0 ) {
231             textures = 1;       
232         } else if ( strcmp(argv[i], "--disable-wireframe") == 0 ) {
233             wireframe = 0;      
234         } else if ( strcmp(argv[i], "--enable-wireframe") == 0 ) {
235             wireframe = 1;      
236         } else if ( strncmp(argv[i], "--tile-radius=", 14) == 0 ) {
237             tile_radius = parse_int(argv[i], 3, 9);
238         } else if ( strncmp(argv[i], "--time-offset=", 14) == 0 ) {
239             time_offset = parse_time_offset(argv[i]);
240         } else {
241             return(FG_OPTIONS_ERROR);
242         }
243
244         i++;
245     }
246     
247     return(FG_OPTIONS_OK);
248 }
249
250
251 // Print usage message
252 void fgOPTIONS::usage ( void ) {
253     printf("Usage: fg [ options ... ]\n");
254     printf("\n");
255
256     printf("General Options:\n");
257     printf("\t--help -h:  print usage\n");
258     printf("\n");
259
260     printf("Features:\n");
261     printf("\t--disable-hud:  disable heads up display\n");
262     printf("\t--enable-hud:  enable heads up display\n");
263     printf("\n");
264  
265     printf("Initial Position:\n");
266     printf("\t--airport-id=ABCD:  specify starting postion by airport id\n");
267     printf("\n");
268
269     printf("Rendering Options:\n");
270     printf("\t--disable-fog:  disable fog/haze\n");
271     printf("\t--enable-fog:  enable fog/haze\n");
272     printf("\t--disable-fullscreen:  disable fullscreen mode\n");
273     printf("\t--enable-fullscreen:  enable fullscreen mode\n");
274     printf("\t--shading-flat:  enable flat shading\n");
275     printf("\t--shading-smooth:  enable smooth shading\n");
276     printf("\t--disable-skyblend:  disable sky blending\n");
277     printf("\t--enable-skyblend:  enable sky blending\n");
278     printf("\t--disable-textures:  disable textures\n");
279     printf("\t--enable-textures:  enable textures\n");
280     printf("\t--disable-wireframe:  disable wireframe drawing mode\n");
281     printf("\t--enable-wireframe:  enable wireframe drawing mode\n");
282     printf("\n");
283
284     printf("Scenery Options:\n");
285     printf("\t--tile-radius=n:  specify tile radius, must be odd 3, 5, or 7\n");
286     printf("\n");
287
288     printf("Time Options:\n");
289     printf("\t--time-offset=[+-]hh:mm:ss:  offset local time by this amount\n");
290 }
291
292
293 // Destructor
294 fgOPTIONS::~fgOPTIONS( void ) {
295 }
296
297
298 // $Log$
299 // Revision 1.8  1998/05/07 23:14:16  curt
300 // Added "D" key binding to set autopilot heading.
301 // Made frame rate calculation average out over last 10 frames.
302 // Borland C++ floating point exception workaround.
303 // Added a --tile-radius=n option.
304 //
305 // Revision 1.7  1998/05/06 03:16:25  curt
306 // Added an averaged global frame rate counter.
307 // Added an option to control tile radius.
308 //
309 // Revision 1.6  1998/05/03 00:47:32  curt
310 // Added an option to enable/disable full-screen mode.
311 //
312 // Revision 1.5  1998/04/30 12:34:19  curt
313 // Added command line rendering options:
314 //   enable/disable fog/haze
315 //   specify smooth/flat shading
316 //   disable sky blending and just use a solid color
317 //   enable wireframe drawing mode
318 //
319 // Revision 1.4  1998/04/28 01:20:22  curt
320 // Type-ified fgTIME and fgVIEW.
321 // Added a command line option to disable textures.
322 //
323 // Revision 1.3  1998/04/26 05:01:19  curt
324 // Added an rint() / HAVE_RINT check.
325 //
326 // Revision 1.2  1998/04/25 15:11:12  curt
327 // Added an command line option to set starting position based on airport ID.
328 //
329 // Revision 1.1  1998/04/24 00:49:21  curt
330 // Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
331 // Trying out some different option parsing code.
332 // Some code reorganization.
333 //
334 //