]> git.mxchange.org Git - flightgear.git/blob - Main/options.cxx
Added command line rendering options:
[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()
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     shading = 1;
56     skyblend = 1;
57     textures = 1;
58     wireframe = 0;
59
60     // Time options
61     time_offset = 0;
62 }
63
64
65 // parse time string in the form of [+-]hh:mm:ss, returns the value in seconds
66 static double parse_time(char *time_str) {
67     char num[256];
68     double hours, minutes, seconds;
69     double result = 0.0;
70     int sign = 1;
71     int i;
72
73     // printf("parse_time(): %s\n", time_str);
74
75     // check for sign
76     if ( strlen(time_str) ) {
77         if ( time_str[0] == '+' ) {
78             sign = 1;
79             time_str++;
80         } else if ( time_str[0] == '-' ) {
81             sign = -1;
82             time_str++;
83         }
84     }
85     // printf("sign = %d\n", sign);
86
87     // get hours
88     if ( strlen(time_str) ) {
89         i = 0;
90         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
91             num[i] = time_str[0];
92             time_str++;
93             i++;
94         }
95         if ( time_str[0] == ':' ) {
96             time_str++;
97         }
98         num[i] = '\0';
99         hours = atof(num);
100         // printf("hours = %.2lf\n", hours);
101
102         result += hours * 3600.0;
103     }
104
105     // get minutes
106     if ( strlen(time_str) ) {
107         i = 0;
108         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
109             num[i] = time_str[0];
110             time_str++;
111             i++;
112         }
113         if ( time_str[0] == ':' ) {
114             time_str++;
115         }
116         num[i] = '\0';
117         minutes = atof(num);
118         // printf("minutes = %.2lf\n", minutes);
119
120         result += minutes * 60.0;
121     }
122
123     // get seconds
124     if ( strlen(time_str) ) {
125         i = 0;
126         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
127             num[i] = time_str[0];
128             time_str++;
129             i++;
130         }
131         num[i] = '\0';
132         seconds = atof(num);
133         // printf("seconds = %.2lf\n", seconds);
134
135         result += seconds;
136     }
137
138     return(sign * result);
139 }
140
141
142 // parse time offset command line option
143 static int parse_time_offset(char *time_str) {
144     int result;
145
146     time_str += 14;
147
148     // printf("time offset = %s\n", time_str);
149
150 #ifdef HAVE_RINT
151     result = (int)rint(parse_time(time_str));
152 #else
153     result = (int)parse_time(time_str);
154 #endif
155
156     printf("parse_time_offset(): %d\n", result);
157
158     return( result );
159
160 }
161
162
163 // Parse the command line options
164 int fgOPTIONS::parse( int argc, char **argv ) {
165     int i = 1;
166
167     fgPrintf(FG_GENERAL, FG_INFO, "Processing arguments\n");
168
169     while ( i < argc ) {
170         fgPrintf(FG_GENERAL, FG_INFO, "argv[%d] = %s\n", i, argv[i]);
171
172         // General Options
173         if ( (strcmp(argv[i], "--help") == 0) ||
174              (strcmp(argv[i], "-h") == 0) ) {
175             // help/usage request
176             return(FG_OPTIONS_HELP);
177         } else if ( strcmp(argv[i], "--disable-hud") == 0 ) {
178             hud_status = 0;     
179         } else if ( strcmp(argv[i], "--enable-hud") == 0 ) {
180             hud_status = 1;     
181         } else if ( strncmp(argv[i], "--airport-id=", 13) == 0 ) {
182             argv[i] += 13;
183             strncpy(airport_id, argv[i], 4);
184         } else if ( strcmp(argv[i], "--disable-fog") == 0 ) {
185             fog = 0;    
186         } else if ( strcmp(argv[i], "--enable-fog") == 0 ) {
187             fog = 1;    
188         } else if ( strcmp(argv[i], "--shading-flat") == 0 ) {
189             shading = 0;        
190         } else if ( strcmp(argv[i], "--shading-smooth") == 0 ) {
191             shading = 1;        
192         } else if ( strcmp(argv[i], "--disable-skyblend") == 0 ) {
193             skyblend = 0;       
194         } else if ( strcmp(argv[i], "--enable-skyblend") == 0 ) {
195             skyblend = 1;       
196         } else if ( strcmp(argv[i], "--disable-textures") == 0 ) {
197             textures = 0;       
198         } else if ( strcmp(argv[i], "--enable-textures") == 0 ) {
199             textures = 1;       
200         } else if ( strcmp(argv[i], "--disable-wireframe") == 0 ) {
201             wireframe = 0;      
202         } else if ( strcmp(argv[i], "--enable-wireframe") == 0 ) {
203             wireframe = 1;      
204         } else if ( strncmp(argv[i], "--time-offset=", 14) == 0 ) {
205             time_offset = parse_time_offset(argv[i]);
206         } else {
207             return(FG_OPTIONS_ERROR);
208         }
209
210         i++;
211     }
212     
213     return(FG_OPTIONS_OK);
214 }
215
216
217 // Print usage message
218 void fgOPTIONS::usage ( void ) {
219     printf("Usage: fg [ options ... ]\n");
220     printf("\n");
221
222     printf("General Options:\n");
223     printf("\t--help -h:  print usage\n");
224     printf("\n");
225
226     printf("Features:\n");
227     printf("\t--disable-hud:  disable heads up display\n");
228     printf("\t--enable-hud:  enable heads up display\n");
229     printf("\n");
230  
231     printf("Initial Position:\n");
232     printf("\t--airport-id=ABCD:  specify starting postion by airport id\n");
233     printf("\n");
234
235     printf("Rendering Options:\n");
236     printf("\t--disable-fog:  disable fog/haze\n");
237     printf("\t--enable-fog:  enable fog/haze\n");
238     printf("\t--shading-flat:  enable flat shading\n");
239     printf("\t--shading-smooth:  enable smooth shading\n");
240     printf("\t--disable-skyblend:  disable sky blending\n");
241     printf("\t--enable-skyblend:  enable sky blending\n");
242     printf("\t--disable-textures:  disable textures\n");
243     printf("\t--enable-textures:  enable textures\n");
244     printf("\t--disable-wireframe:  disable wireframe drawing mode\n");
245     printf("\t--enable-wireframe:  enable wireframe drawing mode\n");
246     printf("\n");
247
248     printf("Time Options:\n");
249     printf("\t--time-offset=[+-]hh:mm:ss:  offset local time by this amount\n");
250 }
251
252
253 // Destructor
254 fgOPTIONS::~fgOPTIONS( void ) {
255 }
256
257
258 // $Log$
259 // Revision 1.5  1998/04/30 12:34:19  curt
260 // Added command line rendering options:
261 //   enable/disable fog/haze
262 //   specify smooth/flat shading
263 //   disable sky blending and just use a solid color
264 //   enable wireframe drawing mode
265 //
266 // Revision 1.4  1998/04/28 01:20:22  curt
267 // Type-ified fgTIME and fgVIEW.
268 // Added a command line option to disable textures.
269 //
270 // Revision 1.3  1998/04/26 05:01:19  curt
271 // Added an rint() / HAVE_RINT check.
272 //
273 // Revision 1.2  1998/04/25 15:11:12  curt
274 // Added an command line option to set starting position based on airport ID.
275 //
276 // Revision 1.1  1998/04/24 00:49:21  curt
277 // Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
278 // Trying out some different option parsing code.
279 // Some code reorganization.
280 //
281 //