]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/options.hxx
VS2015 compatability fixes.
[flightgear.git] / src / Main / options.hxx
index 6c2b89528bf410633ab85e2acafbb5c4a5b015ee..4f618213b55c45afc80bca1df8171f012f261e9f 100644 (file)
@@ -2,7 +2,7 @@
 //
 // Written by Curtis Olson, started April 1998.
 //
-// Copyright (C) 1998  Curtis L. Olson  - curt@me.umn.edu
+// Copyright (C) 1998  Curtis L. Olson  - http://www.flightgear.org/~curt
 //
 // This program is free software; you can redistribute it and/or
 // modify it under the terms of the GNU General Public License as
@@ -16,7 +16,7 @@
 //
 // You should have received a copy of the GNU General Public License
 // along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //
 // $Id$
 
 #ifndef _OPTIONS_HXX
 #define _OPTIONS_HXX
 
-
-#ifndef __cplusplus
-# error This library requires C++
-#endif                                   
-
-#ifdef HAVE_CONFIG_H
-#  include <config.h>
-#endif
-
-#include <Include/compiler.h>
-
-#ifdef HAVE_WINDOWS_H
-#  include <windows.h>
-#endif
-
-#include <GL/glut.h>
-#include <XGL/xgl.h>
-
-#if defined(FX) && defined(XMESA)
-extern bool global_fullscreen;
-#endif
-
-#include STL_STRING
-#include <vector>
-
-FG_USING_STD(vector);
-FG_USING_STD(string);
-
-typedef vector < string > str_container;
-typedef str_container::iterator str_iterator;
-typedef str_container::const_iterator const_str_iterator;
-
-
-class fgOPTIONS {
-
-public:
-
-    enum
-    {
-       FG_OPTIONS_OK = 0,
-       FG_OPTIONS_HELP = 1,
-       FG_OPTIONS_ERROR = 2
-    };
-
-    enum
-    {
-       FG_UNITS_FEET = 0,
-       FG_UNITS_METERS = 1
-    };
-
-    enum fgFogKind
-    {
-       FG_FOG_DISABLED = 0,
-       FG_FOG_FASTEST  = 1,
-       FG_FOG_NICEST   = 2
-    };
-
-    enum
-    {
-       FG_RADIUS_MIN = 1,
-       FG_RADIUS_MAX = 4
-    };
-
-    enum
-    {
-      FG_TIME_SYS_OFFSET   = 1,
-      FG_TIME_GMT_OFFSET   = 2,
-      FG_TIME_LAT_OFFSET   = 3,
-      FG_TIME_SYS_ABSOLUTE = 4,
-      FG_TIME_GMT_ABSOLUTE = 5,
-      FG_TIME_LAT_ABSOLUTE = 6
-    };
-
-    enum fgControlMode
-    {
-       FG_JOYSTICK = 0,
-       FG_KEYBOARD = 1,
-       FG_MOUSE = 2
-    };
-
-private:
-
-    // The flight gear "root" directory
-    string fg_root;
-
-    // Starting position and orientation
-    string airport_id;  // ID of initial starting airport
-    double lon;         // starting longitude in degrees (west = -)
-    double lat;         // starting latitude in degrees (south = -)
-    double altitude;    // starting altitude in meters
-    double heading;     // heading (yaw) angle in degress (Psi)
-    double roll;        // roll angle in degrees (Phi)
-    double pitch;       // pitch angle in degrees (Theta)
-    double uBody;       // Body axis X velocity (U)
-    double vBody;       // Body axis Y velocity (V)
-    double wBody;       // Body axis Z velocity (W)
-
-    // Miscellaneous
-    bool game_mode;     // Game mode enabled/disabled
-    bool splash_screen; // show splash screen
-    bool intro_music;   // play introductory music
-    int mouse_pointer;  // show mouse pointer
-    bool pause;         // pause intially enabled/disabled
-    fgControlMode control_mode; // primary control mode
-
-    // Features
-    bool hud_status;    // HUD on/off
-    bool panel_status;  // Panel on/off
-    bool sound;         // play sound effects
-
-    // Flight Model options
-    int flight_model;   // Flight Model:  FG_SLEW, FG_LARCSIM, etc.
-    int model_hz;       // number of FDM iterations per second
-    int speed_up;       // Sim mechanics run this much faster than normal speed
-
-    // Rendering options
-    fgFogKind fog;      // Fog nicest/fastest/disabled
-    double fov;         // Field of View
-    bool fullscreen;    // Full screen mode enabled/disabled
-    int shading;        // shading method, 0 = Flat, 1 = Smooth
-    bool skyblend;      // Blend sky to haze (using polygons) or just clear
-    bool textures;      // Textures enabled/disabled
-    bool wireframe;     // Wireframe mode enabled/disabled
-    int xsize, ysize;   // window size derived from geometry string
-
-    // Scenery options
-    int tile_radius;   // Square radius of rendered tiles (around center 
-                       // square.)
-    int tile_diameter; // Diameter of rendered tiles.  for instance
-                       // if tile_diameter = 3 then a 3 x 3 grid of tiles will 
-                       // be drawn.  Increase this to see terrain that is 
-                       // further away.
-
-    // HUD options
-    int units;         // feet or meters
-    int tris_or_culled;
-
-    // Time options
-    int time_offset;           // Use this value to change time.
-    int time_offset_type;      // Will be set to one of the FG_TIME_* enums,
-                               // To deterine how time_offset should be used 
-
-    // Serial Ports, we currently support up to four channels
-    // fgSerialPortKind port_a_kind;  // Port a kind
-    // fgSerialPortKind port_b_kind;  // Port b kind
-    // fgSerialPortKind port_c_kind;  // Port c kind
-    // fgSerialPortKind port_d_kind;  // Port d kind
-
-    // Serial port configuration strings
-    str_container port_options_list;
-
-    // Network options
-    string net_id;
+#include <memory>
+#include <string>
+
+#include <simgear/misc/strutils.hxx>
+
+// forward decls
+class SGPath;
+
+namespace flightgear
+{
+
+    /**
+     * return the default platform dependant download directory.
+     * This must be a user-writeable location, the question is if it should
+     * be a user visible location. On Windows we default to a subdir of
+     * Documents (FlightGear), on Unixes we default to FG_HOME, which is
+     * typically invisible.
+     */
+    std::string defaultDownloadDir();
+
+/// option processing can have various result values
+/// depending on what the user requested. Note processOptions only
+/// returns a subset of these.
+enum OptionResult
+{
+    FG_OPTIONS_OK = 0,
+    FG_OPTIONS_HELP = 1,
+    FG_OPTIONS_ERROR = 2,
+    FG_OPTIONS_EXIT = 3,
+    FG_OPTIONS_VERBOSE_HELP = 4,
+    FG_OPTIONS_SHOW_AIRCRAFT = 5,
+    FG_OPTIONS_SHOW_SOUND_DEVICES = 6,
+    FG_OPTIONS_NO_DEFAULT_CONFIG = 7
+};
     
+class Options
+{
+private:
+  Options();
+  
 public:
-
-    fgOPTIONS();
-    ~fgOPTIONS();
-
-    // Parse a single option
-    int parse_option( const string& arg );
-
-    // Parse the command line options
-    int parse_command_line( int argc, char **argv );
-
-    // Parse the command line options
-    int parse_config_file( const string& path );
-
-    // Print usage message
-    void usage ( void );
-
-    // Query functions
-    inline string get_fg_root() const { return fg_root; }
-    inline string get_airport_id() const { return airport_id; }
-    inline double get_lon() const { return lon; }
-    inline double get_lat() const { return lat; }
-    inline double get_altitude() const { return altitude; }
-    inline double get_heading() const { return heading; }
-    inline double get_roll() const { return roll; }
-    inline double get_pitch() const { return pitch; }
-    inline double get_uBody() const {return uBody;}
-    inline double get_vBody() const {return vBody;}
-    inline double get_wBody() const {return wBody;}
-    inline bool get_game_mode() const { return game_mode; }
-    inline bool get_splash_screen() const { return splash_screen; }
-    inline bool get_intro_music() const { return intro_music; }
-    inline int get_mouse_pointer() const { return mouse_pointer; }
-    inline bool get_pause() const { return pause; }
-    inline fgControlMode get_control_mode() const { return control_mode; }
-    inline void set_control_mode( fgControlMode mode ) { control_mode = mode; }
-    inline bool get_hud_status() const { return hud_status; }
-    inline bool get_panel_status() const { return panel_status; }
-    inline bool get_sound() const { return sound; }
-    inline int get_flight_model() const { return flight_model; }
-    inline int get_model_hz() const { return model_hz; }
-    inline int get_speed_up() const { return speed_up; }
-    inline void set_speed_up( int speed ) { speed_up = speed; }
-    inline bool fog_enabled() const { return fog != FG_FOG_DISABLED; }
-    inline fgFogKind get_fog() const { return fog; }
-    inline double get_fov() const { return fov; }
-    inline bool get_fullscreen() const { return fullscreen; }
-    inline int get_shading() const { return shading; }
-    inline bool get_skyblend() const { return skyblend; }
-    inline bool get_textures() const { return textures; }
-    inline bool get_wireframe() const { return wireframe; }
-    inline int get_xsize() const { return xsize; }
-    inline int get_ysize() const { return ysize; }
-    inline int get_tile_radius() const { return tile_radius; }
-    inline int get_tile_diameter() const { return tile_diameter; }
-
-    inline int get_units() const { return units; }
-    inline int get_tris_or_culled() const { return tris_or_culled; }
-
-    inline int get_time_offset() const { return time_offset; }
-    inline int get_time_offset_type() const { return time_offset_type; };
-
-    inline str_container get_port_options_list() const { 
-       return port_options_list;
-    }
-    inline string get_net_id() const { return net_id; }
-
-    // Update functions
-    inline void set_airport_id( const string id ) { airport_id = id; }
-    inline void set_hud_status( bool status ) { hud_status = status; }
-    inline void set_fov( double amount ) { fov = amount; }
-    inline void set_textures( bool status ) { textures = status; }
-    inline void cycle_fog( void ) { 
-       if ( fog == FG_FOG_DISABLED ) {
-           fog = FG_FOG_FASTEST;
-       } else if ( fog == FG_FOG_FASTEST ) {
-           fog = FG_FOG_NICEST;
-           xglHint ( GL_FOG_HINT, GL_NICEST );
-       } else if ( fog == FG_FOG_NICEST ) {
-           fog = FG_FOG_DISABLED;
-           xglHint ( GL_FOG_HINT, GL_FASTEST );
-       }
-    }
-    void toggle_panel();
-    inline void set_xsize( int x ) { xsize= x; }
-    inline void set_ysize( int y ) { xsize= y; }
-    inline void set_net_id( const string id ) { net_id = id; }
-
+  static Options* sharedInstance();
+
+  ~Options();
+  
+  /**
+   * pass command line arguments, read default config files
+   */
+  void init(int argc, char* argv[], const SGPath& appDataPath);
+  
+  /**
+    * parse a config file (eg, .fgfsrc) 
+    */
+  void readConfig(const SGPath& path);
+  
+  /**
+    * read the value for an option, if it has been set
+    */
+  std::string valueForOption(const std::string& key, const std::string& defValue = std::string()) const;
+  
+  /**
+    * return all values for a multi-valued option
+    */
+  string_list valuesForOption(const std::string& key) const;
+  
+  /**
+    * check if a particular option has been set (so far)
+    */
+  bool isOptionSet(const std::string& key) const;
+  
+  
+  /**
+    * set an option value, assuming it is not already set (or multiple values
+    * are permitted)
+    * This can be used to inject option values, eg based upon environment variables
+    */
+  int addOption(const std::string& key, const std::string& value);
+
+  /**
+   * set an option, overwriting any existing value which might be set
+   */
+  int setOption(const std::string& key, const std::string& value);
+
+  void clearOption(const std::string& key);
+
+  /**
+   * apply option values to the simulation state
+   * (set properties, etc). 
+   */
+  OptionResult processOptions();
+
+    /**
+     * process command line options relating to scenery / aircraft / data paths
+     */
+    void initPaths();
+
+  /**
+   * init the aircraft options
+   */
+  void initAircraft();
+  
+  /**
+   * should defualt configuration files be loaded and processed or not?
+   * There's many configuration files we have historically read by default
+   * on startup - preferences.xml, fgfs.rc in various places and so on.
+   * --no-default-config allows this behaviour to be changed, so only
+   * expicitly listed files are read - this is useful for testing. Expose
+   * the value of the option here.
+   */
+  bool shouldLoadDefaultConfig() const;
+
+  /**
+   * check if the arguments array contains a particular string (with a '--' or
+   * '-' prefix).
+   * Used by early startup code before Options object is created
+   */
+  static bool checkForArg(int argc, char* argv[], const char* arg);
+
+      std::string platformDefaultRoot() const;
 private:
-
-    void parse_control( const string& mode );
-    double parse_time( const string& time_str );
-    long int parse_date( const string& date_str );
-    double parse_degree( const string& degree_str );
-    int parse_time_offset( const string& time_str );
-    int parse_tile_radius( const string& arg );
-    int parse_fdm( const string& fm );
-    double parse_fov( const string& arg );
-    bool parse_serial( const string& serial_str );
+  void showUsage() const;
+  
+  int parseOption(const std::string& s);
+  
+  void processArgResult(int result);
+
+    /**
+     * Setup the root base, and check it's valid. Bails out with exit(-1) if
+     * the root package was not found or is the incorrect version. Argv/argv
+     * are passed since we might potentially show a GUI dialog at this point
+     * to help the user our (finding a base package), and hence need to init Qt.
+     */
+  void setupRoot(int argc, char **argv);
+
+  
+  class OptionsPrivate;
+  std::auto_ptr<OptionsPrivate> p;
 };
+  
+} // of namespace flightgear
 
-
-extern fgOPTIONS current_options;
-
+void fgSetDefaults();
 
 #endif /* _OPTIONS_HXX */
-
-